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