1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30
31 #include <wrtsh.hxx>
32 #include <fldbas.hxx>
33 #include <fldmgr.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <DropDownFieldDialog.hxx>
36 #include <flddropdown.hxx>
37 #include <fldui.hrc>
38 #include <DropDownFieldDialog.hrc>
39
40 using namespace ::com::sun::star;
41
42
43 /*--------------------------------------------------------------------
44 Beschreibung: Feldeinfuegen bearbeiten
45 --------------------------------------------------------------------*/
46
DropDownFieldDialog(Window * pParent,SwWrtShell & rS,SwField * pField,sal_Bool bNextButton)47 sw::DropDownFieldDialog::DropDownFieldDialog( Window *pParent, SwWrtShell &rS,
48 SwField* pField, sal_Bool bNextButton ) :
49
50 SvxStandardDialog(pParent, SW_RES(DLG_FLD_DROPDOWN)),
51 aItemsFL( this, SW_RES( FL_ITEMS )),
52 aListItemsLB( this, SW_RES( LB_LISTITEMS )),
53
54 aOKPB( this, SW_RES( PB_OK )),
55 aCancelPB( this, SW_RES( PB_CANCEL )),
56 aNextPB( this, SW_RES( PB_NEXT )),
57 aHelpPB( this, SW_RES( PB_HELP )),
58
59 aEditPB( this, SW_RES( PB_EDIT )),
60
61 rSh( rS ),
62 pDropField(0)
63 {
64 Link aButtonLk = LINK(this, DropDownFieldDialog, ButtonHdl);
65 aEditPB.SetClickHdl(aButtonLk);
66 if( bNextButton )
67 {
68 aNextPB.Show();
69 aNextPB.SetClickHdl(aButtonLk);
70 }
71 else
72 {
73 long nDiff = aCancelPB.GetPosPixel().Y() - aOKPB.GetPosPixel().Y();
74 Point aPos = aHelpPB.GetPosPixel();
75 aPos.Y() -= nDiff;
76 aHelpPB.SetPosPixel(aPos);
77 }
78 if( RES_DROPDOWN == pField->GetTyp()->Which() )
79 {
80 //
81 pDropField = (SwDropDownField*)pField;
82 String sTitle = GetText();
83 sTitle += pDropField->GetPar2();
84 SetText(sTitle);
85 uno::Sequence< rtl::OUString > aItems = pDropField->GetItemSequence();
86 const rtl::OUString* pArray = aItems.getConstArray();
87 for(sal_Int32 i = 0; i < aItems.getLength(); i++)
88 aListItemsLB.InsertEntry(pArray[i]);
89 aListItemsLB.SelectEntry(pDropField->GetSelectedItem());
90 }
91
92 sal_Bool bEnable = !rSh.IsCrsrReadonly();
93 aOKPB.Enable( bEnable );
94
95 aListItemsLB.GrabFocus();
96 FreeResource();
97 }
98
~DropDownFieldDialog()99 sw::DropDownFieldDialog::~DropDownFieldDialog()
100 {
101 }
102
103 /*--------------------------------------------------------------------
104
105 --------------------------------------------------------------------*/
106
Apply()107 void sw::DropDownFieldDialog::Apply()
108 {
109 if(pDropField)
110 {
111 String sSelect = aListItemsLB.GetSelectEntry();
112 if(pDropField->GetPar1() != sSelect)
113 {
114 rSh.StartAllAction();
115
116 ::std::auto_ptr<SwDropDownField> const pCopy(
117 static_cast<SwDropDownField *>( pDropField->CopyField() ) );
118
119 pCopy->SetPar1(sSelect);
120 rSh.SwEditShell::UpdateFlds(*pCopy);
121
122 rSh.SetUndoNoResetModified();
123 rSh.EndAllAction();
124 }
125 }
126 }
127 /* -----------------17.06.2003 10:50-----------------
128
129 --------------------------------------------------*/
IMPL_LINK(sw::DropDownFieldDialog,ButtonHdl,PushButton *,pButton)130 IMPL_LINK(sw::DropDownFieldDialog, ButtonHdl, PushButton*, pButton)
131 {
132 EndDialog(&aNextPB == pButton ? RET_OK : RET_YES );
133 return 0;
134 }
135
136