Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sfx2/app.hxx>
30 : : #include <basic/basmgr.hxx>
31 : : #include <basic/sbmod.hxx>
32 : : #include <docsh.hxx>
33 : : #include <swtypes.hxx>
34 : : #include <globals.hrc>
35 : : #include <fldbas.hxx>
36 : : #include <docufld.hxx>
37 : : #include <view.hxx>
38 : : #include <wrtsh.hxx>
39 : : #include <swmodule.hxx>
40 : : #include <fldfunc.hxx>
41 : : #include <flddropdown.hxx>
42 : : #include <fldui.hrc>
43 : : #include <fldtdlg.hrc>
44 : :
45 : : #define USER_DATA_VERSION_1 "1"
46 : : #define USER_DATA_VERSION USER_DATA_VERSION_1
47 : :
48 : : using namespace ::com::sun::star;
49 : :
50 : : using rtl::OUString;
51 : :
52 : 0 : SwFldFuncPage::SwFldFuncPage(Window* pParent, const SfxItemSet& rCoreSet ) :
53 : : SwFldPage( pParent, SW_RES( TP_FLD_FUNC ), rCoreSet ),
54 : :
55 : : aTypeFT (this, SW_RES(FT_FUNCTYPE)),
56 : : aTypeLB (this, SW_RES(LB_FUNCTYPE)),
57 : : aSelectionFT(this, SW_RES(FT_FUNCSELECTION)),
58 : : aSelectionLB(this, SW_RES(LB_FUNCSELECTION)),
59 : : aFormatFT (this, SW_RES(FT_FUNCFORMAT)),
60 : : aFormatLB (this, SW_RES(LB_FUNCFORMAT)),
61 : : aNameFT (this, SW_RES(FT_FUNCNAME)),
62 : : aNameED (this, SW_RES(ED_FUNCNAME)),
63 : : aValueFT (this, SW_RES(FT_FUNCVALUE)),
64 : : aValueED (this, SW_RES(ED_FUNCVALUE)),
65 : : aCond1FT (this, SW_RES(FT_FUNCCOND1)),
66 : : aCond1ED (this, SW_RES(ED_FUNCCOND1)),
67 : : aCond2FT (this, SW_RES(FT_FUNCCOND2)),
68 : : aCond2ED (this, SW_RES(ED_FUNCCOND2)),
69 : : aMacroBT (this, SW_RES(BT_FUNCMACRO)),
70 : : aListItemFT( this, SW_RES( FT_LISTITEM )),
71 : : aListItemED( this, SW_RES( ED_LISTITEM )),
72 : : aListAddPB( this, SW_RES( PB_LISTADD )),
73 : : aListItemsFT( this, SW_RES( FT_LISTITEMS )),
74 : : aListItemsLB( this, SW_RES( LB_LISTITEMS )),
75 : : aListRemovePB( this, SW_RES( PB_LISTREMOVE )),
76 : : aListUpPB( this, SW_RES( PB_LISTUP )),
77 : : aListDownPB( this, SW_RES( PB_LISTDOWN )),
78 : : aListNameFT( this, SW_RES( FT_LISTNAME )),
79 : : aListNameED( this, SW_RES( ED_LISTNAME )),
80 : 0 : bDropDownLBChanged(false)
81 : : {
82 : 0 : FreeResource();
83 : :
84 : 0 : aNameED.SetPosPixel(Point(aNameED.GetPosPixel().X(), aFormatLB.GetPosPixel().Y()));
85 : :
86 : 0 : aNameED.SetModifyHdl(LINK(this, SwFldFuncPage, ModifyHdl));
87 : :
88 : 0 : sOldValueFT = aValueFT.GetText();
89 : 0 : sOldNameFT = aNameFT.GetText();
90 : :
91 : 0 : aCond1ED.ShowBrackets(sal_False);
92 : 0 : aCond2ED.ShowBrackets(sal_False);
93 : :
94 : 0 : }
95 : :
96 : 0 : SwFldFuncPage::~SwFldFuncPage()
97 : : {
98 : 0 : }
99 : :
100 : 0 : void SwFldFuncPage::Reset(const SfxItemSet& )
101 : : {
102 : 0 : SavePos(&aTypeLB);
103 : 0 : Init(); // general initialisation
104 : :
105 : 0 : aTypeLB.SetUpdateMode(sal_False);
106 : 0 : aTypeLB.Clear();
107 : :
108 : : sal_uInt16 nPos, nTypeId;
109 : :
110 : 0 : if (!IsFldEdit())
111 : : {
112 : : // initialise TypeListBox
113 : 0 : const SwFldGroupRgn& rRg = GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
114 : :
115 : : // fill Typ-Listbox
116 : 0 : for(short i = rRg.nStart; i < rRg.nEnd; ++i)
117 : : {
118 : 0 : nTypeId = GetFldMgr().GetTypeId(i);
119 : 0 : nPos = aTypeLB.InsertEntry(GetFldMgr().GetTypeStr(i));
120 : 0 : aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
121 : : }
122 : : }
123 : : else
124 : : {
125 : 0 : nTypeId = GetCurField()->GetTypeId();
126 : 0 : nPos = aTypeLB.InsertEntry(GetFldMgr().GetTypeStr(GetFldMgr().GetPos(nTypeId)));
127 : 0 : aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
128 : :
129 : 0 : if (nTypeId == TYP_MACROFLD)
130 : : {
131 : 0 : String sName(GetCurField()->GetPar1());
132 : 0 : GetFldMgr().SetMacroPath(sName);
133 : : }
134 : : }
135 : :
136 : : // select old Pos
137 : 0 : RestorePos(&aTypeLB);
138 : :
139 : 0 : aTypeLB.SetDoubleClickHdl (LINK(this, SwFldFuncPage, InsertHdl));
140 : 0 : aTypeLB.SetSelectHdl (LINK(this, SwFldFuncPage, TypeHdl));
141 : 0 : aSelectionLB.SetSelectHdl (LINK(this, SwFldFuncPage, SelectHdl));
142 : 0 : aSelectionLB.SetDoubleClickHdl (LINK(this, SwFldFuncPage, InsertMacroHdl));
143 : 0 : aFormatLB.SetDoubleClickHdl (LINK(this, SwFldFuncPage, InsertHdl));
144 : 0 : aMacroBT.SetClickHdl (LINK(this, SwFldFuncPage, MacroHdl));
145 : 0 : Link aListModifyLk( LINK(this, SwFldFuncPage, ListModifyHdl));
146 : 0 : aListAddPB.SetClickHdl(aListModifyLk);
147 : 0 : aListRemovePB.SetClickHdl(aListModifyLk);
148 : 0 : aListUpPB.SetClickHdl(aListModifyLk);
149 : 0 : aListDownPB.SetClickHdl(aListModifyLk);
150 : 0 : aListItemED.SetReturnActionLink(aListModifyLk);
151 : 0 : Link aListEnableLk = LINK(this, SwFldFuncPage, ListEnableHdl);
152 : 0 : aListItemED.SetModifyHdl(aListEnableLk);
153 : 0 : aListItemsLB.SetSelectHdl(aListEnableLk);
154 : :
155 : 0 : if( !IsRefresh() )
156 : : {
157 : 0 : String sUserData = GetUserData();
158 : 0 : if(sUserData.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1))
159 : : {
160 : 0 : String sVal = sUserData.GetToken(1, ';');
161 : 0 : sal_uInt16 nVal = static_cast< sal_uInt16 >(sVal.ToInt32());
162 : 0 : if(nVal != USHRT_MAX)
163 : : {
164 : 0 : for(sal_uInt16 i = 0; i < aTypeLB.GetEntryCount(); i++)
165 : 0 : if(nVal == (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(i))
166 : : {
167 : 0 : aTypeLB.SelectEntryPos(i);
168 : 0 : break;
169 : : }
170 : 0 : }
171 : 0 : }
172 : : }
173 : 0 : TypeHdl(0);
174 : :
175 : 0 : aTypeLB.SetUpdateMode(sal_True);
176 : :
177 : 0 : if (IsFldEdit())
178 : : {
179 : 0 : aNameED.SaveValue();
180 : 0 : aValueED.SaveValue();
181 : 0 : aCond1ED.SaveValue();
182 : 0 : aCond2ED.SaveValue();
183 : 0 : nOldFormat = GetCurField()->GetFormat();
184 : : }
185 : 0 : }
186 : :
187 : 0 : IMPL_LINK_NOARG(SwFldFuncPage, TypeHdl)
188 : : {
189 : : // save old ListBoxPos
190 : 0 : const sal_uInt16 nOld = GetTypeSel();
191 : :
192 : : // current ListBoxPos
193 : 0 : SetTypeSel(aTypeLB.GetSelectEntryPos());
194 : :
195 : 0 : if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND)
196 : : {
197 : 0 : SetTypeSel(0);
198 : 0 : aTypeLB.SelectEntryPos(0);
199 : : }
200 : :
201 : 0 : if (nOld != GetTypeSel())
202 : : {
203 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
204 : :
205 : : // fill Selection-Listbox
206 : 0 : UpdateSubType();
207 : :
208 : : // fill Format-Listbox
209 : 0 : aFormatLB.Clear();
210 : :
211 : 0 : sal_uInt16 nSize = GetFldMgr().GetFormatCount(nTypeId, sal_False, IsFldDlgHtmlMode());
212 : :
213 : 0 : for (sal_uInt16 i = 0; i < nSize; i++)
214 : : {
215 : 0 : sal_uInt16 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
216 : 0 : aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, i )) );
217 : : }
218 : :
219 : 0 : if (nSize)
220 : : {
221 : 0 : if (IsFldEdit() && nTypeId == TYP_JUMPEDITFLD)
222 : 0 : aFormatLB.SelectEntry(SW_RESSTR(FMT_MARK_BEGIN + (sal_uInt16)GetCurField()->GetFormat()));
223 : :
224 : 0 : if (!aFormatLB.GetSelectEntryCount())
225 : 0 : aFormatLB.SelectEntryPos(0);
226 : : }
227 : :
228 : 0 : sal_Bool bValue = sal_False, bName = sal_False, bMacro = sal_False, bInsert = sal_True;
229 : 0 : sal_Bool bShowSelection = sal_False;
230 : 0 : sal_Bool bFormat = nSize != 0;
231 : :
232 : : // two controls for conditional text
233 : 0 : sal_Bool bDropDown = TYP_DROPDOWN == nTypeId;
234 : 0 : sal_Bool bCondTxtFld = TYP_CONDTXTFLD == nTypeId;
235 : :
236 : 0 : aCond1FT.Show(!bDropDown && bCondTxtFld);
237 : 0 : aCond1ED.Show(!bDropDown && bCondTxtFld);
238 : 0 : aCond2FT.Show(!bDropDown && bCondTxtFld);
239 : 0 : aCond2ED.Show(!bDropDown && bCondTxtFld);
240 : 0 : aValueFT.Show(!bDropDown && !bCondTxtFld);
241 : 0 : aValueED.Show(!bDropDown && !bCondTxtFld);
242 : 0 : aMacroBT.Show(!bDropDown);
243 : 0 : aNameED.Show(!bDropDown);
244 : 0 : aNameFT.Show(!bDropDown);
245 : :
246 : 0 : aListItemFT.Show(bDropDown);
247 : 0 : aListItemED.Show(bDropDown);
248 : 0 : aListAddPB.Show(bDropDown);
249 : 0 : aListItemsFT.Show(bDropDown);
250 : 0 : aListItemsLB.Show(bDropDown);
251 : 0 : aListRemovePB.Show(bDropDown);
252 : 0 : aListUpPB.Show(bDropDown);
253 : 0 : aListDownPB.Show(bDropDown);
254 : 0 : aListNameFT.Show(bDropDown);
255 : 0 : aListNameED.Show(bDropDown);
256 : :
257 : 0 : aNameED.SetDropEnable(sal_False);
258 : :
259 : 0 : if (IsFldEdit())
260 : : {
261 : 0 : if(bDropDown)
262 : : {
263 : 0 : const SwDropDownField* pDrop = (const SwDropDownField*)GetCurField();
264 : 0 : uno::Sequence<OUString> aItems = pDrop->GetItemSequence();
265 : 0 : const OUString* pArray = aItems.getConstArray();
266 : 0 : aListItemsLB.Clear();
267 : 0 : for(sal_Int32 i = 0; i < aItems.getLength(); i++)
268 : 0 : aListItemsLB.InsertEntry(pArray[i]);
269 : 0 : aListItemsLB.SelectEntry(pDrop->GetSelectedItem());
270 : 0 : aListNameED.SetText(pDrop->GetPar2());
271 : 0 : aListNameED.SaveValue();
272 : 0 : bDropDownLBChanged = false;
273 : : }
274 : : else
275 : : {
276 : 0 : aNameED.SetText(GetCurField()->GetPar1());
277 : 0 : aValueED.SetText(GetCurField()->GetPar2());
278 : : }
279 : : }
280 : : else
281 : : {
282 : 0 : aNameED.SetText(aEmptyStr);
283 : 0 : aValueED.SetText(aEmptyStr);
284 : : }
285 : 0 : if(bDropDown)
286 : 0 : ListEnableHdl(0);
287 : :
288 : 0 : if( aNameFT.GetText() != sOldNameFT )
289 : 0 : aNameFT.SetText(sOldNameFT);
290 : 0 : if (aValueFT.GetText() != sOldValueFT)
291 : 0 : aValueFT.SetText(sOldValueFT);
292 : :
293 : 0 : switch (nTypeId)
294 : : {
295 : : case TYP_MACROFLD:
296 : 0 : bMacro = sal_True;
297 : 0 : if (GetFldMgr().GetMacroPath().Len())
298 : 0 : bValue = sal_True;
299 : : else
300 : 0 : bInsert = sal_False;
301 : :
302 : 0 : aNameFT.SetText(SW_RESSTR(STR_MACNAME));
303 : 0 : aValueFT.SetText(SW_RESSTR(STR_PROMPT));
304 : 0 : aNameED.SetText(GetFldMgr().GetMacroName());
305 : 0 : aNameED.SetAccessibleName(aNameFT.GetText());
306 : 0 : aValueED.SetAccessibleName(aValueFT.GetText());
307 : 0 : break;
308 : :
309 : : case TYP_HIDDENPARAFLD:
310 : 0 : aNameFT.SetText(SW_RESSTR(STR_COND));
311 : 0 : aNameED.SetDropEnable(sal_True);
312 : 0 : bName = sal_True;
313 : 0 : aNameED.SetAccessibleName(aNameFT.GetText());
314 : 0 : aValueED.SetAccessibleName(aValueFT.GetText());
315 : 0 : break;
316 : :
317 : : case TYP_HIDDENTXTFLD:
318 : : {
319 : 0 : aNameFT.SetText(SW_RESSTR(STR_COND));
320 : 0 : aNameED.SetDropEnable(sal_True);
321 : 0 : aValueFT.SetText(SW_RESSTR(STR_INSTEXT));
322 : 0 : SwWrtShell* pSh = GetActiveWrtShell();
323 : 0 : if (!IsFldEdit() && pSh )
324 : 0 : aValueED.SetText(pSh->GetSelTxt());
325 : 0 : bName = bValue = sal_True;
326 : 0 : aNameED.SetAccessibleName(aNameFT.GetText());
327 : 0 : aValueED.SetAccessibleName(aValueFT.GetText());
328 : : }
329 : 0 : break;
330 : :
331 : : case TYP_CONDTXTFLD:
332 : 0 : aNameFT.SetText(SW_RESSTR(STR_COND));
333 : 0 : aNameED.SetDropEnable(sal_True);
334 : 0 : if (IsFldEdit())
335 : : {
336 : 0 : aCond1ED.SetText(GetCurField()->GetPar2().getToken(0, '|'));
337 : 0 : aCond2ED.SetText(GetCurField()->GetPar2().getToken(1, '|'));
338 : : }
339 : :
340 : 0 : bName = bValue = sal_True;
341 : 0 : aNameED.SetAccessibleName(aNameFT.GetText());
342 : 0 : aValueED.SetAccessibleName(aValueFT.GetText());
343 : 0 : break;
344 : :
345 : : case TYP_JUMPEDITFLD:
346 : 0 : aNameFT.SetText(SW_RESSTR(STR_JUMPEDITFLD));
347 : 0 : aValueFT.SetText(SW_RESSTR(STR_PROMPT));
348 : 0 : bName = bValue = sal_True;
349 : 0 : aNameED.SetAccessibleName(aNameFT.GetText());
350 : 0 : aValueED.SetAccessibleName(aValueFT.GetText());
351 : 0 : break;
352 : :
353 : : case TYP_INPUTFLD:
354 : 0 : aValueFT.SetText(SW_RESSTR(STR_PROMPT));
355 : 0 : bValue = sal_True;
356 : 0 : aNameED.SetAccessibleName(aNameFT.GetText());
357 : 0 : aValueED.SetAccessibleName(aValueFT.GetText());
358 : 0 : break;
359 : :
360 : : case TYP_COMBINED_CHARS:
361 : : {
362 : 0 : aNameFT.SetText(SW_RESSTR(STR_COMBCHRS_FT));
363 : 0 : aNameED.SetDropEnable(sal_True);
364 : 0 : bName = sal_True;
365 : :
366 : 0 : const sal_uInt16 nLen = aNameED.GetText().Len();
367 : 0 : if( !nLen || nLen > MAX_COMBINED_CHARACTERS )
368 : 0 : bInsert = sal_False;
369 : 0 : aNameED.SetAccessibleName(aNameFT.GetText());
370 : 0 : aValueED.SetAccessibleName(aValueFT.GetText());
371 : : }
372 : 0 : break;
373 : : case TYP_DROPDOWN :
374 : 0 : break;
375 : : default:
376 : 0 : break;
377 : : }
378 : :
379 : 0 : if (bShowSelection)
380 : : {
381 : 0 : aSelectionLB.Show();
382 : 0 : aSelectionFT.Show();
383 : 0 : aFormatLB.Hide();
384 : 0 : aFormatFT.Hide();
385 : : }
386 : : else
387 : : {
388 : 0 : aFormatLB.Show();
389 : 0 : aFormatFT.Show();
390 : 0 : aSelectionLB.Hide();
391 : 0 : aSelectionFT.Hide();
392 : : }
393 : :
394 : 0 : aFormatLB.Enable(bFormat);
395 : 0 : aFormatFT.Enable(bFormat);
396 : 0 : aNameFT.Enable(bName);
397 : 0 : aNameED.Enable(bName);
398 : 0 : aValueFT.Enable(bValue);
399 : 0 : aValueED.Enable(bValue);
400 : 0 : aMacroBT.Enable(bMacro);
401 : :
402 : 0 : EnableInsert( bInsert );
403 : : }
404 : :
405 : 0 : return 0;
406 : : }
407 : :
408 : 0 : IMPL_LINK_NOARG(SwFldFuncPage, SelectHdl)
409 : : {
410 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
411 : :
412 : 0 : if( TYP_MACROFLD == nTypeId )
413 : 0 : aNameED.SetText( aSelectionLB.GetSelectEntry() );
414 : :
415 : 0 : return 0;
416 : : }
417 : :
418 : 0 : IMPL_LINK_NOARG(SwFldFuncPage, InsertMacroHdl)
419 : : {
420 : 0 : SelectHdl();
421 : 0 : InsertHdl();
422 : :
423 : 0 : return 0;
424 : : }
425 : :
426 : 0 : IMPL_LINK( SwFldFuncPage, ListModifyHdl, Control*, pControl)
427 : : {
428 : 0 : aListItemsLB.SetUpdateMode(sal_False);
429 : 0 : if(pControl == &aListAddPB ||
430 : 0 : (pControl == &aListItemED && aListAddPB.IsEnabled()))
431 : : {
432 : 0 : String sEntry(aListItemED.GetText());
433 : 0 : aListItemsLB.InsertEntry(sEntry);
434 : 0 : aListItemsLB.SelectEntry(sEntry);
435 : : }
436 : 0 : else if(aListItemsLB.GetSelectEntryCount())
437 : : {
438 : 0 : sal_uInt16 nSelPos = aListItemsLB.GetSelectEntryPos();
439 : 0 : if(pControl == &aListRemovePB)
440 : : {
441 : 0 : aListItemsLB.RemoveEntry(nSelPos);
442 : 0 : aListItemsLB.SelectEntryPos(nSelPos ? nSelPos - 1 : 0);
443 : : }
444 : 0 : else if(pControl == &aListUpPB)
445 : : {
446 : 0 : if(nSelPos)
447 : : {
448 : 0 : String sEntry = aListItemsLB.GetSelectEntry();
449 : 0 : aListItemsLB.RemoveEntry(nSelPos);
450 : 0 : nSelPos--;
451 : 0 : aListItemsLB.InsertEntry(sEntry, nSelPos);
452 : 0 : aListItemsLB.SelectEntryPos(nSelPos);
453 : : }
454 : : }
455 : 0 : else if(pControl == &aListDownPB)
456 : : {
457 : 0 : if(nSelPos < aListItemsLB.GetEntryCount() - 1)
458 : : {
459 : 0 : String sEntry = aListItemsLB.GetSelectEntry();
460 : 0 : aListItemsLB.RemoveEntry(nSelPos);
461 : 0 : nSelPos++;
462 : 0 : aListItemsLB.InsertEntry(sEntry, nSelPos);
463 : 0 : aListItemsLB.SelectEntryPos(nSelPos);
464 : : }
465 : : }
466 : : }
467 : 0 : bDropDownLBChanged = true;
468 : 0 : aListItemsLB.SetUpdateMode(sal_True);
469 : 0 : ListEnableHdl(0);
470 : 0 : return 0;
471 : : }
472 : :
473 : 0 : IMPL_LINK_NOARG(SwFldFuncPage, ListEnableHdl)
474 : : {
475 : : //enable "Add" button when text is in the Edit that's not already member of the box
476 : 0 : aListAddPB.Enable(aListItemED.GetText().Len() &&
477 : 0 : LISTBOX_ENTRY_NOTFOUND == aListItemsLB.GetEntryPos(aListItemED.GetText()));
478 : 0 : sal_Bool bEnableButtons = aListItemsLB.GetSelectEntryCount() > 0;
479 : 0 : aListRemovePB.Enable(bEnableButtons);
480 : 0 : aListUpPB.Enable(bEnableButtons && (aListItemsLB.GetSelectEntryPos() > 0));
481 : : aListDownPB.Enable(bEnableButtons &&
482 : 0 : (aListItemsLB.GetSelectEntryPos() < (aListItemsLB.GetEntryCount() - 1)));
483 : :
484 : 0 : return 0;
485 : : }
486 : :
487 : : /*--------------------------------------------------------------------
488 : : Description: renew types in SelectionBox
489 : : --------------------------------------------------------------------*/
490 : 0 : void SwFldFuncPage::UpdateSubType()
491 : : {
492 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
493 : :
494 : : // fill Selction-Listbox
495 : 0 : aSelectionLB.SetUpdateMode(sal_False);
496 : 0 : aSelectionLB.Clear();
497 : :
498 : 0 : std::vector<rtl::OUString> aLst;
499 : 0 : GetFldMgr().GetSubTypes(nTypeId, aLst);
500 : 0 : size_t nCount = aLst.size();
501 : :
502 : 0 : for(size_t i = 0; i < nCount; ++i)
503 : : {
504 : 0 : size_t nPos = aSelectionLB.InsertEntry(aLst[i]);
505 : 0 : aSelectionLB.SetEntryData(nPos, reinterpret_cast<void*>(i));
506 : : }
507 : :
508 : 0 : sal_Bool bEnable = nCount != 0;
509 : :
510 : 0 : aSelectionLB.Enable( bEnable );
511 : 0 : aSelectionFT.Enable( bEnable );
512 : :
513 : 0 : if (bEnable)
514 : : {
515 : 0 : aSelectionLB.SelectEntryPos(0);
516 : : }
517 : :
518 : 0 : if (nTypeId == TYP_MACROFLD)
519 : : {
520 : 0 : sal_Bool bHasMacro = GetFldMgr().GetMacroPath().Len() != 0;
521 : :
522 : 0 : if (bHasMacro)
523 : : {
524 : 0 : aNameED.SetText(GetFldMgr().GetMacroName());
525 : 0 : aValueFT.Enable();
526 : 0 : aValueED.Enable();
527 : : }
528 : 0 : EnableInsert(bHasMacro);
529 : : }
530 : :
531 : 0 : aSelectionLB.SetUpdateMode(sal_True);
532 : 0 : }
533 : :
534 : : /*--------------------------------------------------------------------
535 : : Description: call MacroBrowser, fill Listbox with Macros
536 : : --------------------------------------------------------------------*/
537 : 0 : IMPL_LINK( SwFldFuncPage, MacroHdl, Button *, pBtn )
538 : : {
539 : 0 : Window* pDefModalDlgParent = Application::GetDefDialogParent();
540 : 0 : Application::SetDefDialogParent( pBtn );
541 : :
542 : 0 : String sMacro(TurnMacroString(aNameED.GetText()));
543 : 0 : while (sMacro.SearchAndReplace('.', ';') != STRING_NOTFOUND) ;
544 : :
545 : 0 : if (GetFldMgr().ChooseMacro(sMacro))
546 : 0 : UpdateSubType();
547 : :
548 : 0 : Application::SetDefDialogParent( pDefModalDlgParent );
549 : :
550 : 0 : return 0;
551 : : }
552 : :
553 : 0 : sal_Bool SwFldFuncPage::FillItemSet(SfxItemSet& )
554 : : {
555 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
556 : :
557 : 0 : sal_uInt16 nSubType = 0;
558 : :
559 : 0 : sal_uLong nFormat = aFormatLB.GetSelectEntryPos();
560 : :
561 : 0 : if(nFormat == LISTBOX_ENTRY_NOTFOUND)
562 : 0 : nFormat = 0;
563 : : else
564 : 0 : nFormat = (sal_uLong)aFormatLB.GetEntryData((sal_uInt16)nFormat);
565 : :
566 : 0 : String aVal(aValueED.GetText());
567 : 0 : String aName(aNameED.GetText());
568 : :
569 : 0 : switch(nTypeId)
570 : : {
571 : : case TYP_INPUTFLD:
572 : 0 : nSubType = INP_TXT;
573 : : // to prevent removal of CR/LF restore old content
574 : 0 : if(!aNameED.IsModified() && IsFldEdit())
575 : 0 : aName = GetCurField()->GetPar1();
576 : :
577 : 0 : break;
578 : :
579 : : case TYP_MACROFLD:
580 : : // use the full script URL, not the name in the Edit control
581 : 0 : aName = GetFldMgr().GetMacroPath();
582 : 0 : break;
583 : :
584 : : case TYP_CONDTXTFLD:
585 : 0 : aVal = aCond1ED.GetText();
586 : 0 : aVal += '|';
587 : 0 : aVal += aCond2ED.GetText();
588 : 0 : break;
589 : : case TYP_DROPDOWN :
590 : : {
591 : 0 : aName = aListNameED.GetText();
592 : 0 : for(sal_uInt16 i = 0; i < aListItemsLB.GetEntryCount(); i++)
593 : : {
594 : 0 : if(i)
595 : 0 : aVal += DB_DELIM;
596 : 0 : aVal += aListItemsLB.GetEntry(i);
597 : : }
598 : : }
599 : 0 : break;
600 : : default:
601 : 0 : break;
602 : : }
603 : :
604 : 0 : if (!IsFldEdit() ||
605 : 0 : aNameED.GetSavedValue() != aNameED.GetText() ||
606 : 0 : aValueED.GetSavedValue() != aValueED.GetText() ||
607 : 0 : aCond1ED.GetSavedValue() != aCond1ED.GetText() ||
608 : 0 : aCond2ED.GetSavedValue() != aCond2ED.GetText() ||
609 : 0 : aListNameED.GetSavedValue() != aListNameED.GetText() ||
610 : : bDropDownLBChanged ||
611 : : nOldFormat != nFormat)
612 : : {
613 : 0 : InsertFld( nTypeId, nSubType, aName, aVal, nFormat );
614 : : }
615 : :
616 : 0 : ModifyHdl(); // enable/disable Insert if applicable
617 : :
618 : 0 : return sal_False;
619 : : }
620 : :
621 : 0 : String SwFldFuncPage::TurnMacroString(const String &rMacro)
622 : : {
623 : 0 : if (rMacro.Len())
624 : : {
625 : : // reverse content of aName
626 : 0 : String sTmp, sBuf;
627 : 0 : sal_uInt16 nPos = 0;
628 : :
629 : 0 : for (sal_uInt16 i = 0; i < 4 && nPos != STRING_NOTFOUND; i++)
630 : : {
631 : 0 : if (i == 3)
632 : 0 : sTmp = rMacro.Copy(nPos);
633 : : else
634 : 0 : sTmp = rMacro.GetToken(0, '.', nPos);
635 : :
636 : 0 : if( sBuf.Len() )
637 : 0 : sTmp += '.';
638 : 0 : sBuf.Insert( sTmp, 0 );
639 : : }
640 : 0 : return sBuf;
641 : : }
642 : :
643 : 0 : return rMacro;
644 : : }
645 : :
646 : 0 : SfxTabPage* SwFldFuncPage::Create( Window* pParent,
647 : : const SfxItemSet& rAttrSet )
648 : : {
649 : 0 : return ( new SwFldFuncPage( pParent, rAttrSet ) );
650 : : }
651 : :
652 : 0 : sal_uInt16 SwFldFuncPage::GetGroup()
653 : : {
654 : 0 : return GRP_FKT;
655 : : }
656 : :
657 : 0 : void SwFldFuncPage::FillUserData()
658 : : {
659 : 0 : String sData(rtl::OUString(USER_DATA_VERSION));
660 : 0 : sData += ';';
661 : 0 : sal_uInt16 nTypeSel = aTypeLB.GetSelectEntryPos();
662 : 0 : if( LISTBOX_ENTRY_NOTFOUND == nTypeSel )
663 : 0 : nTypeSel = USHRT_MAX;
664 : : else
665 : 0 : nTypeSel = sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(aTypeLB.GetEntryData( nTypeSel )));
666 : 0 : sData += String::CreateFromInt32( nTypeSel );
667 : 0 : SetUserData(sData);
668 : 0 : }
669 : :
670 : 0 : IMPL_LINK_NOARG(SwFldFuncPage, ModifyHdl)
671 : : {
672 : 0 : String aName(aNameED.GetText());
673 : 0 : const sal_uInt16 nLen = aName.Len();
674 : :
675 : 0 : sal_Bool bEnable = sal_True;
676 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
677 : :
678 : 0 : if( TYP_COMBINED_CHARS == nTypeId &&
679 : : (!nLen || nLen > MAX_COMBINED_CHARACTERS ))
680 : 0 : bEnable = sal_False;
681 : :
682 : 0 : EnableInsert( bEnable );
683 : :
684 : 0 : return 0;
685 : : }
686 : :
687 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|