Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <wrtsh.hxx>
21 : #include <fldbas.hxx>
22 : #include <fldmgr.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <DropDownFieldDialog.hxx>
25 : #include <flddropdown.hxx>
26 : #include <fldui.hrc>
27 :
28 : #include <boost/scoped_ptr.hpp>
29 :
30 : using namespace ::com::sun::star;
31 :
32 : // edit insert-field
33 0 : sw::DropDownFieldDialog::DropDownFieldDialog(vcl::Window *pParent, SwWrtShell &rS,
34 : SwField* pField, bool bNextButton)
35 : : SvxStandardDialog(pParent, "DropdownFieldDialog",
36 : "modules/swriter/ui/dropdownfielddialog.ui")
37 : , rSh( rS )
38 0 : , pDropField(0)
39 : {
40 0 : get(m_pListItemsLB, "list");
41 0 : m_pListItemsLB->SetDropDownLineCount(12);
42 0 : m_pListItemsLB->set_width_request(m_pListItemsLB->approximate_char_width()*32);
43 0 : get(m_pOKPB, "ok");
44 0 : get(m_pNextPB, "next");
45 0 : get(m_pEditPB, "edit");
46 :
47 0 : Link<> aButtonLk = LINK(this, DropDownFieldDialog, ButtonHdl);
48 0 : m_pEditPB->SetClickHdl(aButtonLk);
49 0 : if( bNextButton )
50 : {
51 0 : m_pNextPB->Show();
52 0 : m_pNextPB->SetClickHdl(aButtonLk);
53 : }
54 0 : if( RES_DROPDOWN == pField->GetTyp()->Which() )
55 : {
56 :
57 0 : pDropField = static_cast<SwDropDownField*>(pField);
58 0 : OUString sTitle = GetText();
59 0 : sTitle += pDropField->GetPar2();
60 0 : SetText(sTitle);
61 0 : uno::Sequence< OUString > aItems = pDropField->GetItemSequence();
62 0 : const OUString* pArray = aItems.getConstArray();
63 0 : for(sal_Int32 i = 0; i < aItems.getLength(); i++)
64 0 : m_pListItemsLB->InsertEntry(pArray[i]);
65 0 : m_pListItemsLB->SelectEntry(pDropField->GetSelectedItem());
66 : }
67 :
68 0 : bool bEnable = !rSh.IsCrsrReadonly();
69 0 : m_pOKPB->Enable( bEnable );
70 :
71 0 : m_pListItemsLB->GrabFocus();
72 0 : }
73 :
74 0 : sw::DropDownFieldDialog::~DropDownFieldDialog()
75 : {
76 0 : disposeOnce();
77 0 : }
78 :
79 0 : void sw::DropDownFieldDialog::dispose()
80 : {
81 0 : m_pListItemsLB.clear();
82 0 : m_pOKPB.clear();
83 0 : m_pNextPB.clear();
84 0 : m_pEditPB.clear();
85 0 : SvxStandardDialog::dispose();
86 0 : }
87 :
88 0 : void sw::DropDownFieldDialog::Apply()
89 : {
90 0 : if(pDropField)
91 : {
92 0 : OUString sSelect = m_pListItemsLB->GetSelectEntry();
93 0 : if(pDropField->GetPar1() != sSelect)
94 : {
95 0 : rSh.StartAllAction();
96 :
97 : boost::scoped_ptr<SwDropDownField> const pCopy(
98 0 : static_cast<SwDropDownField *>( pDropField->CopyField() ) );
99 :
100 0 : pCopy->SetPar1(sSelect);
101 0 : rSh.SwEditShell::UpdateFields(*pCopy);
102 :
103 0 : rSh.SetUndoNoResetModified();
104 0 : rSh.EndAllAction();
105 0 : }
106 : }
107 0 : }
108 :
109 0 : IMPL_LINK(sw::DropDownFieldDialog, ButtonHdl, PushButton*, pButton)
110 : {
111 0 : EndDialog(m_pNextPB == pButton ? RET_OK : RET_YES );
112 0 : return 0;
113 0 : }
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|