1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <swtypes.hxx>
21 #include <sfx2/linkmgr.hxx>
23 #include <docufld.hxx>
30 #include <swmodule.hxx>
33 #include <svl/zformat.hxx>
34 #include <globals.hrc>
36 #include <fldtdlg.hrc>
38 #define USER_DATA_VERSION_1 "1"
39 #define USER_DATA_VERSION USER_DATA_VERSION_1
41 SwFldVarPage::SwFldVarPage(Window
* pParent
, const SfxItemSet
& rCoreSet
) :
42 SwFldPage ( pParent
, SW_RES( TP_FLD_VAR
), rCoreSet
),
43 aTypeFT (this, SW_RES(FT_VARTYPE
)),
44 aTypeLB (this, SW_RES(LB_VARTYPE
)),
45 aSelectionFT (this, SW_RES(FT_VARSELECTION
)),
46 aSelectionLB (this, SW_RES(LB_VARSELECTION
)),
47 aNameFT (this, SW_RES(FT_VARNAME
)),
48 aNameED (this, SW_RES(ED_VARNAME
)),
49 aValueFT (this, SW_RES(FT_VARVALUE
)),
50 aValueED (this, SW_RES(ED_VARVALUE
)),
51 aFormatFT (this, SW_RES(FT_VARFORMAT
)),
52 aNumFormatLB (this, SW_RES(LB_VARNUMFORMAT
)),
53 aFormatLB (this, SW_RES(LB_VARFORMAT
)),
54 aChapterHeaderFT(this, SW_RES(FT_VARCHAPTERHEADER
)),
55 aChapterLevelFT (this, SW_RES(FT_VARCHAPTERLEVEL
)),
56 aChapterLevelLB (this, SW_RES(LB_VARCHAPTERLEVEL
)),
57 aInvisibleCB (this, SW_RES(CB_VARINVISIBLE
)),
58 aSeparatorFT (this, SW_RES(FT_VARSEPARATOR
)),
59 aSeparatorED (this, SW_RES(ED_VARSEPARATOR
)),
60 aNewDelTBX (this, SW_RES(TBX_VARNEWDEL
)),
65 aNewDelTBX
.SetSizePixel( aNewDelTBX
.CalcWindowSizePixel() );
67 long nDelta
= ( aValueED
.GetSizePixel().Height() -
68 aNewDelTBX
.GetSizePixel().Height() ) / 2;
69 Point aNewPnt
= aNewDelTBX
.GetPosPixel();
70 aNewPnt
.Y() += nDelta
;
71 aNewDelTBX
.SetPosPixel( aNewPnt
);
73 sOldValueFT
= aValueFT
.GetText();
74 sOldNameFT
= aNameFT
.GetText();
76 for (sal_uInt16 i
= 1; i
<= MAXLEVEL
; i
++)
77 aChapterLevelLB
.InsertEntry(OUString::number(i
));
79 aChapterLevelLB
.SelectEntryPos(0);
80 //enable 'active' language selection
81 aNumFormatLB
.SetShowLanguageControl(sal_True
);
84 SwFldVarPage::~SwFldVarPage()
88 void SwFldVarPage::Reset(const SfxItemSet
& )
92 Init(); // general initialisation
94 aTypeLB
.SetUpdateMode(sal_False
);
97 sal_uInt16 nPos
, nTypeId
;
101 // initialise TypeListBox
102 const SwFldGroupRgn
& rRg
= GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
104 for (short i
= rRg
.nStart
; i
< rRg
.nEnd
; ++i
)
106 nTypeId
= GetFldMgr().GetTypeId(i
);
107 nPos
= aTypeLB
.InsertEntry(GetFldMgr().GetTypeStr(i
));
108 aTypeLB
.SetEntryData(nPos
, reinterpret_cast<void*>(nTypeId
));
113 SwField
* pCurField
= GetCurField();
114 nTypeId
= pCurField
->GetTypeId();
115 if (nTypeId
== TYP_SETINPFLD
)
116 nTypeId
= TYP_INPUTFLD
;
117 nPos
= aTypeLB
.InsertEntry(GetFldMgr().GetTypeStr(GetFldMgr().GetPos(nTypeId
)));
118 aTypeLB
.SetEntryData(nPos
, reinterpret_cast<void*>(nTypeId
));
119 aNumFormatLB
.SetAutomaticLanguage(pCurField
->IsAutomaticLanguage());
120 SwWrtShell
*pSh
= GetWrtShell();
122 pSh
= ::GetActiveWrtShell();
125 const SvNumberformat
* pFormat
= pSh
->GetNumberFormatter()->GetEntry(pCurField
->GetFormat());
127 aNumFormatLB
.SetLanguage(pFormat
->GetLanguage());
132 RestorePos(&aTypeLB
);
134 aTypeLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
135 aTypeLB
.SetSelectHdl (LINK(this, SwFldVarPage
, TypeHdl
));
136 aSelectionLB
.SetSelectHdl (LINK(this, SwFldVarPage
, SubTypeHdl
));
137 aSelectionLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
138 aFormatLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
139 aNumFormatLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
140 aNameED
.SetModifyHdl (LINK(this, SwFldVarPage
, ModifyHdl
));
141 aValueED
.SetModifyHdl (LINK(this, SwFldVarPage
, ModifyHdl
));
142 aNewDelTBX
.SetClickHdl (LINK(this, SwFldVarPage
, TBClickHdl
));
143 aChapterLevelLB
.SetSelectHdl (LINK(this, SwFldVarPage
, ChapterHdl
));
144 aSeparatorED
.SetModifyHdl (LINK(this, SwFldVarPage
, SeparatorHdl
));
148 String sUserData
= GetUserData();
149 if(!IsRefresh() && sUserData
.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1
))
151 String sVal
= sUserData
.GetToken(1, ';');
152 sal_uInt16 nVal
= (sal_uInt16
)sVal
.ToInt32();
153 if( USHRT_MAX
!= nVal
)
155 for(sal_uInt16 i
= 0; i
< aTypeLB
.GetEntryCount(); i
++)
156 if(nVal
== (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData(i
))
158 aTypeLB
.SelectEntryPos(i
);
166 aTypeLB
.SetUpdateMode(sal_True
);
170 aSelectionLB
.SaveValue();
171 aFormatLB
.SaveValue();
172 nOldFormat
= aNumFormatLB
.GetFormat();
174 aValueED
.SaveValue();
175 aInvisibleCB
.SaveValue();
176 aChapterLevelLB
.SaveValue();
177 aSeparatorED
.SaveValue();
181 IMPL_LINK_NOARG(SwFldVarPage
, TypeHdl
)
183 // save old ListBoxPos
184 const sal_uInt16 nOld
= GetTypeSel();
186 // current ListBoxPos
187 SetTypeSel(aTypeLB
.GetSelectEntryPos());
189 if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND
)
192 aTypeLB
.SelectEntryPos(0);
195 if (nOld
!= GetTypeSel() || nOld
== LISTBOX_ENTRY_NOTFOUND
)
198 if (nOld
!= LISTBOX_ENTRY_NOTFOUND
)
200 aNameED
.SetText(aEmptyStr
);
201 aValueED
.SetText(aEmptyStr
);
204 aValueED
.SetDropEnable(false);
205 UpdateSubType(); // initialise selection-listboxes
213 IMPL_LINK( SwFldVarPage
, SubTypeHdl
, ListBox
*, pBox
)
215 sal_uInt16 nTypeId
= (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData(GetTypeSel());
216 sal_uInt16 nSelPos
= aSelectionLB
.GetSelectEntryPos();
218 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
219 nSelPos
= (sal_uInt16
)(sal_uLong
)aSelectionLB
.GetEntryData(nSelPos
);
221 if (IsFldEdit() && (!pBox
|| bInit
))
223 if (nTypeId
!= TYP_FORMELFLD
)
224 aNameED
.SetText(GetFldMgr().GetCurFldPar1());
226 aValueED
.SetText(GetFldMgr().GetCurFldPar2());
229 if (aNameFT
.GetText() != OUString(sOldNameFT
))
230 aNameFT
.SetText(sOldNameFT
);
231 if (aValueFT
.GetText() != OUString(sOldValueFT
))
232 aValueFT
.SetText(sOldValueFT
);
234 aNumFormatLB
.SetUpdateMode(sal_False
);
235 aFormatLB
.SetUpdateMode(sal_False
);
236 FillFormatLB(nTypeId
);
238 sal_uInt16 nSize
= aFormatLB
.GetEntryCount();
240 sal_Bool bValue
= sal_False
, bName
= sal_False
, bNumFmt
= sal_False
,
241 bInvisible
= sal_False
, bSeparator
= sal_False
, bChapterLevel
= sal_False
;
242 sal_Bool bFormat
= nSize
!= 0;
248 // change or create user type
249 SwUserFieldType
* pType
= (SwUserFieldType
*)
250 GetFldMgr().GetFldType(RES_USERFLD
, nSelPos
);
256 if (pBox
|| (bInit
&& !IsRefresh())) // only when interacting via mouse
258 aNameED
.SetText(pType
->GetName());
260 if (pType
->GetType() == UF_STRING
)
262 aValueED
.SetText(pType
->GetContent());
263 aNumFormatLB
.SelectEntryPos(0);
266 aValueED
.SetText(pType
->GetContent());
270 aValueED
.SetText(pType
->GetContent());
274 if (pBox
) // only when interacting via mouse
276 aNameED
.SetText(aEmptyStr
);
277 aValueED
.SetText(aEmptyStr
);
280 bValue
= bName
= bNumFmt
= bInvisible
= sal_True
;
282 aValueED
.SetDropEnable(true);
289 bNumFmt
= bInvisible
= sal_True
;
291 if (!IsFldDlgHtmlMode())
295 aNumFormatLB
.Clear();
296 sal_uInt16 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT
), 0);
297 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
298 aNumFormatLB
.SelectEntryPos(0);
300 // is there a corresponding SetField
301 if (IsFldEdit() || pBox
) // only when interacting via mouse
303 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
305 String
sName(aSelectionLB
.GetSelectEntry());
306 aNameED
.SetText(sName
);
308 if (!IsFldDlgHtmlMode())
310 SwWrtShell
*pSh
= GetWrtShell();
312 pSh
= ::GetActiveWrtShell();
315 SwSetExpFieldType
* pSetTyp
= (SwSetExpFieldType
*)
316 pSh
->GetFldType(RES_SETEXPFLD
, sName
);
318 if (pSetTyp
&& pSetTyp
->GetType() == nsSwGetSetExpType::GSE_STRING
)
319 aNumFormatLB
.SelectEntryPos(0); // textual
326 // GetFormula leads to problems with date formats because
327 // only the numeric value without formating is returned.
328 // It must be used though because otherwise in GetPar2 only
329 // the value calculated by Kalkulator would be displayed
330 // (instead of test2 = test + 1)
331 aValueED
.SetText(((SwSetExpField
*)GetCurField())->GetFormula());
333 aValueED
.SetDropEnable(true);
340 aValueFT
.SetText(SW_RESSTR(STR_FORMULA
));
341 aValueED
.SetDropEnable(true);
349 aNameED
.SetText(aEmptyStr
);
350 aValueED
.SetText(aEmptyStr
);
353 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
355 String
sName(aSelectionLB
.GetSelectEntry());
357 aNameED
.SetText(sName
);
359 // is there a corresponding SetField
360 SwWrtShell
*pSh
= GetWrtShell();
362 pSh
= ::GetActiveWrtShell();
365 SwSetExpFieldType
* pSetTyp
= (SwSetExpFieldType
*)
366 pSh
->GetFldType(RES_SETEXPFLD
, sName
);
370 if (pSetTyp
->GetType() & nsSwGetSetExpType::GSE_STRING
) // textual?
380 EnableInsert(bFormat
|bNumFmt
);
385 aValueFT
.SetText(SW_RESSTR(STR_PROMPT
));
387 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
389 bValue
= bNumFmt
= sal_True
;
393 sName
= aSelectionLB
.GetSelectEntry();
394 aNameED
.SetText( sName
);
396 // User- or SetField ?
397 sal_uInt16 nInpType
= 0;
398 nInpType
= static_cast< sal_uInt16
>(GetFldMgr().GetFldType(RES_USERFLD
, sName
) ? 0 : TYP_SETINPFLD
);
400 if (nInpType
) // SETEXPFLD
402 // is there a corresponding SetField
403 SwSetExpFieldType
* pSetTyp
= (SwSetExpFieldType
*)
404 GetFldMgr().GetFldType(RES_SETEXPFLD
, sName
);
408 if (pSetTyp
->GetType() == nsSwGetSetExpType::GSE_STRING
) // textual?
410 aNumFormatLB
.Clear();
412 sal_uInt16 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_USERVAR_TEXT
), 0);
413 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
414 aNumFormatLB
.SelectEntryPos(0);
417 if (IsFldEdit() && (!pBox
|| bInit
) )
418 aValueED
.SetText(((SwSetExpField
*)GetCurField())->GetPromptText());
421 bFormat
= bNumFmt
= sal_False
;
426 aValueFT
.SetText(SW_RESSTR(STR_DDE_CMD
));
428 if (IsFldEdit() || pBox
) // only when interacting via mouse
430 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
432 SwDDEFieldType
* pType
=
433 (SwDDEFieldType
*) GetFldMgr().GetFldType(RES_DDEFLD
, nSelPos
);
437 aNameED
.SetText(pType
->GetName());
439 //JP 28.08.95: DDE-Topics/-Items can have blanks in their names!
440 // That's not considered here yet
441 String
sCmd( pType
->GetCmd() );
442 sal_uInt16 nTmpPos
= sCmd
.SearchAndReplace( sfx2::cTokenSeparator
, ' ' );
443 sCmd
.SearchAndReplace( sfx2::cTokenSeparator
, ' ', nTmpPos
);
445 aValueED
.SetText( sCmd
);
446 aFormatLB
.SelectEntryPos(pType
->GetType());
450 bName
= bValue
= sal_True
;
455 bName
= bValue
= bSeparator
= bChapterLevel
= sal_True
;
457 SwFieldType
* pFldTyp
;
459 pFldTyp
= GetCurField()->GetTyp();
462 String
sFldTypeName( aSelectionLB
.GetEntry( nSelPos
));
463 if( sFldTypeName
.Len() )
464 pFldTyp
= GetFldMgr().GetFldType( RES_SETEXPFLD
,
471 aValueED
.SetText( ((SwSetExpField
*)GetCurField())->
474 if( IsFldEdit() || pBox
) // only when interacting via mouse
475 aNameED
.SetText( aSelectionLB
.GetSelectEntry() );
479 sal_uInt8 nLevel
= ((SwSetExpFieldType
*)pFldTyp
)->GetOutlineLvl();
481 aChapterLevelLB
.SelectEntryPos( 0 );
483 aChapterLevelLB
.SelectEntryPos( nLevel
+ 1 );
484 String sDelim
= ((SwSetExpFieldType
*)pFldTyp
)->GetDelimiter();
485 aSeparatorED
.SetText( sDelim
);
491 case TYP_SETREFPAGEFLD
:
494 aValueFT
.SetText( SW_RESSTR( STR_OFFSET
));
496 if (IsFldEdit() || pBox
) // only when interacting via mouse
497 aNameED
.SetText(aEmptyStr
);
499 if (nSelPos
!= 0 && nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
501 bValue
= sal_True
; // SubType OFF - knows no Offset
503 aValueED
.SetText(OUString::number(((SwRefPageSetField
*)GetCurField())->GetOffset()));
508 case TYP_GETREFPAGEFLD
:
509 aNameED
.SetText(aEmptyStr
);
510 aValueED
.SetText(aEmptyStr
);
514 aNumFormatLB
.Show(bNumFmt
);
515 aFormatLB
.Show(!bNumFmt
);
520 aFormatLB
.Enable(bFormat
);
521 aFormatFT
.Enable(bFormat
|bNumFmt
);
522 aNameFT
.Enable(bName
);
523 aNameED
.Enable(bName
);
524 aValueFT
.Enable(bValue
);
525 aValueED
.Enable(bValue
);
527 Size
aSz(aFormatLB
.GetSizePixel());
530 aSz
.Height() = aFormatLB
.LogicToPixel(Size(1, 94), MAP_APPFONT
).Height();
532 aSz
.Height() = aFormatLB
.LogicToPixel(Size(1, 123), MAP_APPFONT
).Height();
534 aFormatLB
.SetSizePixel(aSz
);
536 aInvisibleCB
.Show(!bSeparator
);
537 aSeparatorFT
.Show(bSeparator
);
538 aSeparatorED
.Show(bSeparator
);
539 aChapterHeaderFT
.Show(bChapterLevel
);
540 aChapterLevelFT
.Show(bChapterLevel
);
541 aChapterLevelLB
.Show(bChapterLevel
);
542 aInvisibleCB
.Enable(bInvisible
);
544 ModifyHdl(); // apply/insert/delete status update
546 aNumFormatLB
.SetUpdateMode(sal_True
);
547 aFormatLB
.SetUpdateMode(sal_True
);
549 if(aSelectionLB
.IsCallAddSelection())
551 nTypeId
= (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData(GetTypeSel());
557 nSelPos
= aSelectionLB
.GetSelectEntryPos();
559 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
560 nSelPos
= (sal_uInt16
)(sal_uLong
)aSelectionLB
.GetEntryData(nSelPos
);
562 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
&& pBox
&& !bInit
)
564 aValueED
.ReplaceSelected(aSelectionLB
.GetSelectEntry());
570 aSelectionLB
.ResetCallAddSelection();
575 /*--------------------------------------------------------------------
576 Description: renew types in SelectionBox
577 --------------------------------------------------------------------*/
578 void SwFldVarPage::UpdateSubType()
581 sal_uInt16 nTypeId
= (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData(GetTypeSel());
583 SetSelectionSel(aSelectionLB
.GetSelectEntryPos());
584 if(GetSelectionSel() != LISTBOX_ENTRY_NOTFOUND
)
585 sOldSel
= aSelectionLB
.GetEntry(GetSelectionSel());
587 // fill Selection-Listbox
588 aSelectionLB
.SetUpdateMode(sal_False
);
589 aSelectionLB
.Clear();
591 std::vector
<OUString
> aList
;
592 GetFldMgr().GetSubTypes(nTypeId
, aList
);
593 size_t nCount
= aList
.size();
596 for(size_t i
= 0; i
< nCount
; ++i
)
598 if (nTypeId
!= TYP_INPUTFLD
|| i
)
602 nPos
= aSelectionLB
.InsertEntry(aList
[i
]);
603 aSelectionLB
.SetEntryData(nPos
, reinterpret_cast<void*>(i
));
607 sal_Bool bInsert
= sal_False
;
612 if (aList
[i
] == GetCurField()->GetPar1())
621 if (aList
[i
].equals(((const SwFormulaField
*)GetCurField())->GetFormula()))
627 if (aList
[i
] == GetCurField()->GetTyp()->GetName())
630 if (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE
)
631 aInvisibleCB
.Check();
635 case TYP_SETREFPAGEFLD
:
636 if ((((SwRefPageSetField
*)GetCurField())->IsOn() && i
) ||
637 (!((SwRefPageSetField
*)GetCurField())->IsOn() && !i
))
640 // allow all entries for selection:
641 nPos
= aSelectionLB
.InsertEntry(aList
[i
]);
642 aSelectionLB
.SetEntryData(nPos
, reinterpret_cast<void*>(i
));
646 if (aList
[i
] == GetCurField()->GetPar1())
652 nPos
= aSelectionLB
.InsertEntry(aList
[i
]);
653 aSelectionLB
.SetEntryData(nPos
, reinterpret_cast<void*>(i
));
654 if (nTypeId
!= TYP_FORMELFLD
)
661 sal_Bool bEnable
= aSelectionLB
.GetEntryCount() != 0;
666 aSelectionLB
.SelectEntry(sOldSel
);
667 if (!aSelectionLB
.GetSelectEntryCount())
669 aSelectionLB
.SelectEntryPos(0);
670 pLB
= &aSelectionLB
; // newly initialise all controls
674 aSelectionLB
.Enable( bEnable
);
675 aSelectionFT
.Enable( bEnable
);
678 aSelectionLB
.SetUpdateMode(sal_True
);
681 sal_uInt16
SwFldVarPage::FillFormatLB(sal_uInt16 nTypeId
)
683 String sOldSel
, sOldNumSel
;
684 sal_uLong nOldNumFormat
= 0;
686 sal_uInt16 nFormatSel
= aFormatLB
.GetSelectEntryPos();
687 if (nFormatSel
!= LISTBOX_ENTRY_NOTFOUND
)
688 sOldSel
= aFormatLB
.GetEntry(nFormatSel
);
690 sal_uInt16 nNumFormatSel
= aNumFormatLB
.GetSelectEntryPos();
691 if (nNumFormatSel
!= LISTBOX_ENTRY_NOTFOUND
)
693 sOldNumSel
= aNumFormatLB
.GetEntry(nNumFormatSel
);
694 nOldNumFormat
= aNumFormatLB
.GetFormat();
697 // fill Format-Listbox
699 aNumFormatLB
.Clear();
700 sal_Bool bSpecialFmt
= sal_False
;
702 if( TYP_GETREFPAGEFLD
!= nTypeId
)
706 bSpecialFmt
= GetCurField()->GetFormat() == SAL_MAX_UINT32
;
710 aNumFormatLB
.SetDefFormat(GetCurField()->GetFormat());
711 sOldNumSel
= aEmptyStr
;
714 if (nTypeId
== TYP_GETFLD
|| nTypeId
== TYP_FORMELFLD
)
715 aNumFormatLB
.SetFormatType(NUMBERFORMAT_NUMBER
);
719 if (nOldNumFormat
&& nOldNumFormat
!= ULONG_MAX
)
720 aNumFormatLB
.SetDefFormat(nOldNumFormat
);
722 aNumFormatLB
.SetFormatType(NUMBERFORMAT_NUMBER
);
730 if (!IsFldEdit() || bSpecialFmt
)
732 sal_uInt16 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_MARK_TEXT
), 0);
733 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
734 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_USERVAR_CMD
), 1);
735 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
742 if (!IsFldEdit() || bSpecialFmt
)
744 sal_uInt16 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT
), 0);
745 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
752 sal_uInt16 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_GETVAR_NAME
), 0);
753 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
759 sal_uInt16 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_GETVAR_NAME
), 0);
760 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
765 if (IsFldEdit() && bSpecialFmt
)
767 if (nTypeId
== TYP_USERFLD
&& (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_CMD
))
768 aNumFormatLB
.SelectEntryPos(1);
770 aNumFormatLB
.SelectEntryPos(0);
774 if (!nOldNumFormat
&& (nNumFormatSel
= aNumFormatLB
.GetEntryPos(sOldNumSel
)) != LISTBOX_ENTRY_NOTFOUND
)
775 aNumFormatLB
.SelectEntryPos(nNumFormatSel
);
776 else if (nOldNumFormat
&& nOldNumFormat
== ULONG_MAX
)
777 aNumFormatLB
.SelectEntry(sOldSel
);
780 sal_uInt16 nSize
= GetFldMgr().GetFormatCount(nTypeId
, false, IsFldDlgHtmlMode());
782 for (sal_uInt16 i
= 0; i
< nSize
; i
++)
784 sal_uInt16 nPos
= aFormatLB
.InsertEntry(GetFldMgr().GetFormatStr(nTypeId
, i
));
785 sal_uInt16 nFldId
= GetFldMgr().GetFormatId( nTypeId
, i
);
786 aFormatLB
.SetEntryData( nPos
, reinterpret_cast<void*>(nFldId
) );
787 if (IsFldEdit() && nFldId
== GetCurField()->GetFormat())
788 aFormatLB
.SelectEntryPos( nPos
);
791 if (nSize
&& (!IsFldEdit() || !aFormatLB
.GetSelectEntryCount()))
793 aFormatLB
.SelectEntry(sOldSel
);
795 if (!aFormatLB
.GetSelectEntryCount())
797 aFormatLB
.SelectEntry(SW_RESSTR(FMT_NUM_PAGEDESC
));
798 if (!aFormatLB
.GetSelectEntryCount())
800 aFormatLB
.SelectEntry(SW_RESSTR(FMT_NUM_ARABIC
));
801 if (!aFormatLB
.GetSelectEntryCount())
802 aFormatLB
.SelectEntryPos(0);
810 /*--------------------------------------------------------------------
812 --------------------------------------------------------------------*/
813 IMPL_LINK_NOARG(SwFldVarPage
, ModifyHdl
)
815 String
sValue(aValueED
.GetText());
816 sal_Bool bHasValue
= sValue
.Len() != 0;
817 sal_uInt16 nTypeId
= (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData(GetTypeSel());
818 bool bInsert
= false, bApply
= false, bDelete
= false;
820 String
sName( aNameED
.GetText() );
821 xub_StrLen nLen
= sName
.Len();
829 SwCalc::IsValidVarName( sName
, &sName
);
830 if( sName
.Len() != nLen
)
833 Selection
aSel(aNameED
.GetSelection());
834 aNameED
.SetText( sName
);
835 aNameED
.SetSelection( aSel
); // restore Cursorpos
847 // is there already a corrensponding type
848 bInsert
= bApply
= true;
850 SwFieldType
* pType
= GetFldMgr().GetFldType(RES_DDEFLD
, sName
);
852 SwWrtShell
*pSh
= GetWrtShell();
854 pSh
= ::GetActiveWrtShell();
856 bDelete
= !pSh
->IsUsed( *pType
);
863 // is there already a corresponding type
864 SwFieldType
* pType
= GetFldMgr().GetFldType(RES_USERFLD
, sName
);
866 SwWrtShell
*pSh
= GetWrtShell();
868 pSh
= ::GetActiveWrtShell();
870 bDelete
= !pSh
->IsUsed( *pType
);
872 pType
= GetFldMgr().GetFldType(RES_SETEXPFLD
, sName
);
873 if (!pType
) // no name conflict with variables
875 // user fields can also be inserted without content!
877 bInsert
= bApply
= true;
885 if (nTypeId
== TYP_SETFLD
|| nTypeId
== TYP_SEQFLD
)
887 SwSetExpFieldType
* pFldType
= (SwSetExpFieldType
*)
888 GetFldMgr().GetFldType(RES_SETEXPFLD
, sName
);
893 SwWrtShell
*pSh
= GetWrtShell();
895 pSh
= ::GetActiveWrtShell();
898 const SwFldTypes
* p
= pSh
->GetDoc()->GetFldTypes();
901 for (i
= 0; i
< INIT_FLDTYPES
; i
++)
903 SwFieldType
* pType
= (*p
)[ i
];
904 if (pType
== pFldType
)
908 if (i
>= INIT_FLDTYPES
&& !pSh
->IsUsed(*pFldType
))
911 if (nTypeId
== TYP_SEQFLD
&& !(pFldType
->GetType() & nsSwGetSetExpType::GSE_SEQ
))
914 if (nTypeId
== TYP_SETFLD
&& (pFldType
->GetType() & nsSwGetSetExpType::GSE_SEQ
))
918 if (GetFldMgr().GetFldType(RES_USERFLD
, sName
))
922 if( !nLen
&& ( nTypeId
== TYP_SETFLD
||
923 (!IsFldEdit() && nTypeId
== TYP_GETFLD
) ) )
926 if( (nTypeId
== TYP_SETFLD
|| nTypeId
== TYP_FORMELFLD
) &&
932 aNewDelTBX
.EnableItem(BT_VARAPPLY
, bApply
);
933 aNewDelTBX
.EnableItem(BT_VARDELETE
, bDelete
);
934 EnableInsert(bInsert
);
939 IMPL_LINK( SwFldVarPage
, TBClickHdl
, ToolBox
*, pBox
)
941 sal_uInt16 nTypeId
= (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData(GetTypeSel());
943 switch (pBox
->GetCurItemId())
947 if( nTypeId
== TYP_USERFLD
)
948 GetFldMgr().RemoveFldType(RES_USERFLD
, aSelectionLB
.GetSelectEntry());
957 nWhich
= RES_SETEXPFLD
;
964 GetFldMgr().RemoveFldType(nWhich
, aSelectionLB
.GetSelectEntry());
968 SwWrtShell
*pSh
= GetWrtShell();
970 pSh
= ::GetActiveWrtShell();
980 String
sName(aNameED
.GetText()), sValue(aValueED
.GetText());
981 SwFieldType
* pType
= 0;
983 sal_uInt16 nNumFormatPos
= aNumFormatLB
.GetSelectEntryPos();
987 case TYP_USERFLD
: nId
= RES_USERFLD
; break;
988 case TYP_DDEFLD
: nId
= RES_DDEFLD
; break;
989 case TYP_SETFLD
: nId
= RES_SETEXPFLD
;break;
991 pType
= GetFldMgr().GetFldType(nId
, sName
);
993 sal_uLong nFormat
= aFormatLB
.GetSelectEntryPos();
994 if (nFormat
!= LISTBOX_ENTRY_NOTFOUND
)
995 nFormat
= (sal_uLong
)aFormatLB
.GetEntryData((sal_uInt16
)nFormat
);
999 SwWrtShell
*pSh
= GetWrtShell();
1001 pSh
= ::GetActiveWrtShell();
1004 pSh
->StartAllAction();
1006 if (nTypeId
== TYP_USERFLD
)
1008 if (nNumFormatPos
!= LISTBOX_ENTRY_NOTFOUND
)
1010 sal_uLong nFmt
= nNumFormatPos
== 0 ? 0 : aNumFormatLB
.GetFormat();
1012 { // Switch language to office-language because Kalkulator expects
1013 // String in office format and it should be fed into dialog like
1015 nFmt
= SwValueField::GetSystemFormat(pSh
->GetNumberFormatter(), nFmt
);
1017 ((SwUserFieldType
*)pType
)->SetContent(aValueED
.GetText(), nFmt
);
1018 ((SwUserFieldType
*)pType
)->SetType(
1019 nNumFormatPos
== 0 ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
);
1024 if (nFormat
!= LISTBOX_ENTRY_NOTFOUND
)
1026 // DDE-Topics/-Items can have blanks in their names!
1027 // That's not being considered here yet.
1028 sal_uInt16 nTmpPos
= sValue
.SearchAndReplace( ' ', sfx2::cTokenSeparator
);
1029 sValue
.SearchAndReplace( ' ', sfx2::cTokenSeparator
, nTmpPos
);
1030 ((SwDDEFieldType
*)pType
)->SetCmd(sValue
);
1031 ((SwDDEFieldType
*)pType
)->SetType((sal_uInt16
)nFormat
);
1034 pType
->UpdateFlds();
1036 pSh
->EndAllAction();
1041 if(nTypeId
== TYP_USERFLD
)
1043 SwWrtShell
*pSh
= GetWrtShell();
1045 pSh
= ::GetActiveWrtShell();
1048 SwUserFieldType
aType( pSh
->GetDoc(), sName
);
1050 if (nNumFormatPos
!= LISTBOX_ENTRY_NOTFOUND
)
1052 aType
.SetType(nNumFormatPos
== 0 ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
);
1053 aType
.SetContent( sValue
, nNumFormatPos
== 0 ? 0 : aNumFormatLB
.GetFormat() );
1054 aSelectionLB
.InsertEntry(sName
);
1055 aSelectionLB
.SelectEntry(sName
);
1056 GetFldMgr().InsertFldType( aType
); // Userfld new
1062 if (nFormat
!= LISTBOX_ENTRY_NOTFOUND
)
1064 // DDE-Topics/-Items can have blanks in their names!
1065 // That's not being considered here yet.
1066 sal_uInt16 nTmpPos
= sValue
.SearchAndReplace( ' ', sfx2::cTokenSeparator
);
1067 sValue
.SearchAndReplace( ' ', sfx2::cTokenSeparator
, nTmpPos
);
1069 SwDDEFieldType
aType(sName
, sValue
, (sal_uInt16
)nFormat
);
1070 aSelectionLB
.InsertEntry(sName
);
1071 aSelectionLB
.SelectEntry(sName
);
1072 GetFldMgr().InsertFldType(aType
); // DDE-Field new
1077 GetFldMgr().GetCurFld(); // update FieldManager
1087 IMPL_LINK_NOARG(SwFldVarPage
, ChapterHdl
)
1089 sal_Bool bEnable
= aChapterLevelLB
.GetSelectEntryPos() != 0;
1091 aSeparatorED
.Enable(bEnable
);
1092 aSeparatorFT
.Enable(bEnable
);
1098 IMPL_LINK_NOARG(SwFldVarPage
, SeparatorHdl
)
1100 sal_Bool bEnable
= !aSeparatorED
.GetText().isEmpty() ||
1101 aChapterLevelLB
.GetSelectEntryPos() == 0;
1102 EnableInsert(bEnable
);
1107 sal_Bool
SwFldVarPage::FillItemSet(SfxItemSet
& )
1109 sal_uInt16 nTypeId
= (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData(GetTypeSel());
1111 String
aVal(aValueED
.GetText());
1112 String
aName(aNameED
.GetText());
1114 sal_uInt16 nSubType
= aSelectionLB
.GetSelectEntryPos();
1115 if(nSubType
== LISTBOX_ENTRY_NOTFOUND
)
1118 nSubType
= (sal_uInt16
)(sal_uLong
)aSelectionLB
.GetEntryData(nSubType
);
1122 if (!aNumFormatLB
.IsVisible())
1124 nFormat
= aFormatLB
.GetSelectEntryPos();
1126 if(nFormat
== LISTBOX_ENTRY_NOTFOUND
)
1129 nFormat
= (sal_uLong
)aFormatLB
.GetEntryData((sal_uInt16
)nFormat
);
1133 nFormat
= aNumFormatLB
.GetFormat();
1135 if (nFormat
&& nFormat
!= ULONG_MAX
&& aNumFormatLB
.IsAutomaticLanguage())
1137 // Switch language to office language because Kalkulator expects
1138 // String in office format and it should be fed into the dialog
1140 SwWrtShell
*pSh
= GetWrtShell();
1142 pSh
= ::GetActiveWrtShell();
1145 nFormat
= SwValueField::GetSystemFormat(pSh
->GetNumberFormatter(), nFormat
);
1149 sal_Unicode cSeparator
= ' ';
1154 nSubType
= (nFormat
== ULONG_MAX
) ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
;
1156 if (nFormat
== ULONG_MAX
&& aNumFormatLB
.GetSelectEntry().Equals(SW_RESSTR(FMT_USERVAR_CMD
)))
1157 nSubType
|= nsSwExtendedSubType::SUB_CMD
;
1159 if (aInvisibleCB
.IsChecked())
1160 nSubType
|= nsSwExtendedSubType::SUB_INVISIBLE
;
1165 nSubType
= nsSwGetSetExpType::GSE_FORMULA
;
1166 if (aNumFormatLB
.IsVisible() && nFormat
== ULONG_MAX
)
1167 nSubType
|= nsSwExtendedSubType::SUB_CMD
;
1173 if (aNumFormatLB
.IsVisible() && nFormat
== ULONG_MAX
)
1174 nSubType
|= nsSwExtendedSubType::SUB_CMD
;
1179 SwFieldType
* pType
= GetFldMgr().GetFldType(RES_USERFLD
, aName
);
1180 nSubType
= static_cast< sal_uInt16
>((nSubType
& 0xff00) | ((pType
) ? INP_USR
: INP_VAR
));
1186 if (IsFldDlgHtmlMode())
1189 nSubType
= (nSubType
& 0xff00) | nsSwGetSetExpType::GSE_STRING
;
1192 nSubType
= (nSubType
& 0xff00) | ((nFormat
== ULONG_MAX
) ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
);
1194 if (aInvisibleCB
.IsChecked())
1195 nSubType
|= nsSwExtendedSubType::SUB_INVISIBLE
;
1200 nSubType
= aChapterLevelLB
.GetSelectEntryPos();
1206 OUString sSeparator
= OUString(aSeparatorED
.GetText()[0]);
1207 cSeparator
= !sSeparator
.isEmpty() ? sSeparator
[0] : ' ';
1211 case TYP_GETREFPAGEFLD
:
1212 if( SVX_NUM_CHAR_SPECIAL
== nFormat
)
1213 aVal
= aValueED
.GetText();
1218 aNameED
.GetSavedValue() != aNameED
.GetText() ||
1219 aValueED
.GetSavedValue() != aValueED
.GetText() ||
1220 aSelectionLB
.GetSavedValue() != aSelectionLB
.GetSelectEntryPos() ||
1221 aFormatLB
.GetSavedValue() != aFormatLB
.GetSelectEntryPos() ||
1222 nOldFormat
!= aNumFormatLB
.GetFormat() ||
1223 aInvisibleCB
.GetState() != aInvisibleCB
.GetSavedValue() ||
1224 aChapterLevelLB
.GetSavedValue() != aChapterLevelLB
.GetSelectEntryPos() ||
1225 aSeparatorED
.GetSavedValue() != aSeparatorED
.GetText())
1227 InsertFld( nTypeId
, nSubType
, aName
, aVal
, nFormat
,
1228 cSeparator
, aNumFormatLB
.IsAutomaticLanguage() );
1236 SfxTabPage
* SwFldVarPage::Create( Window
* pParent
,
1237 const SfxItemSet
& rAttrSet
)
1239 return ( new SwFldVarPage( pParent
, rAttrSet
) );
1242 sal_uInt16
SwFldVarPage::GetGroup()
1247 SelectionListBox::SelectionListBox( SwFldVarPage
* pDialog
, const ResId
& rResId
) :
1248 ListBox (pDialog
, rResId
),
1249 bCallAddSelection(false)
1253 long SelectionListBox::PreNotify( NotifyEvent
& rNEvt
)
1255 long nHandled
= ListBox::PreNotify( rNEvt
);
1256 if ( rNEvt
.GetType() == EVENT_KEYUP
)
1258 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
1259 const KeyCode aKeyCode
= pKEvt
->GetKeyCode();
1260 const sal_uInt16 nModifier
= aKeyCode
.GetModifier();
1261 if( aKeyCode
.GetCode() == KEY_SPACE
&& !nModifier
)
1262 bCallAddSelection
= true;
1264 if ( rNEvt
.GetType() == EVENT_MOUSEBUTTONDOWN
)
1266 const MouseEvent
* pMEvt
= rNEvt
.GetMouseEvent();
1268 if (pMEvt
&& (pMEvt
->IsMod1() || pMEvt
->IsMod2())) // Alt or Ctrl
1269 bCallAddSelection
= true;
1275 void SwFldVarPage::FillUserData()
1277 String
sData(OUString(USER_DATA_VERSION
));
1279 sal_uInt16 nTypeSel
= aTypeLB
.GetSelectEntryPos();
1280 if( LISTBOX_ENTRY_NOTFOUND
== nTypeSel
)
1281 nTypeSel
= USHRT_MAX
;
1283 nTypeSel
= (sal_uInt16
)(sal_uLong
)aTypeLB
.GetEntryData( nTypeSel
);
1284 sData
+= OUString::number( nTypeSel
);
1288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */