1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fldvar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
38 #include <swtypes.hxx>
39 #include <sfx2/linkmgr.hxx>
41 #include <docufld.hxx>
50 #include <swmodule.hxx>
55 #include <svtools/zformat.hxx>
57 #include <globals.hrc>
63 #include <fldtdlg.hrc>
66 #define USER_DATA_VERSION_1 "1"
67 #define USER_DATA_VERSION USER_DATA_VERSION_1
68 /*--------------------------------------------------------------------
70 --------------------------------------------------------------------*/
72 SwFldVarPage::SwFldVarPage(Window
* pParent
, const SfxItemSet
& rCoreSet
) :
73 SwFldPage ( pParent
, SW_RES( TP_FLD_VAR
), rCoreSet
),
74 aTypeFT (this, SW_RES(FT_VARTYPE
)),
75 aTypeLB (this, SW_RES(LB_VARTYPE
)),
76 aSelectionFT (this, SW_RES(FT_VARSELECTION
)),
77 aSelectionLB (this, SW_RES(LB_VARSELECTION
)),
78 aNameFT (this, SW_RES(FT_VARNAME
)),
79 aNameED (this, SW_RES(ED_VARNAME
)),
80 aValueFT (this, SW_RES(FT_VARVALUE
)),
81 aValueED (this, SW_RES(ED_VARVALUE
)),
82 aFormatFT (this, SW_RES(FT_VARFORMAT
)),
83 aNumFormatLB (this, SW_RES(LB_VARNUMFORMAT
)),
84 aFormatLB (this, SW_RES(LB_VARFORMAT
)),
85 aChapterHeaderFT(this, SW_RES(FT_VARCHAPTERHEADER
)),
86 aChapterLevelFT (this, SW_RES(FT_VARCHAPTERLEVEL
)),
87 aChapterLevelLB (this, SW_RES(LB_VARCHAPTERLEVEL
)),
88 aInvisibleCB (this, SW_RES(CB_VARINVISIBLE
)),
89 aSeparatorFT (this, SW_RES(FT_VARSEPARATOR
)),
90 aSeparatorED (this, SW_RES(ED_VARSEPARATOR
)),
91 aNewDelTBX (this, SW_RES(TBX_VARNEWDEL
)),
96 aNewDelTBX
.SetSizePixel( aNewDelTBX
.CalcWindowSizePixel() );
98 long nDelta
= ( aValueED
.GetSizePixel().Height() -
99 aNewDelTBX
.GetSizePixel().Height() ) / 2;
100 Point aNewPnt
= aNewDelTBX
.GetPosPixel();
101 aNewPnt
.Y() += nDelta
;
102 aNewDelTBX
.SetPosPixel( aNewPnt
);
104 sOldValueFT
= aValueFT
.GetText();
105 sOldNameFT
= aNameFT
.GetText();
107 for (USHORT i
= 1; i
<= MAXLEVEL
; i
++)
108 aChapterLevelLB
.InsertEntry(String::CreateFromInt32(i
));
110 aChapterLevelLB
.SelectEntryPos(0);
111 //enable 'active' language selection
112 aNumFormatLB
.SetShowLanguageControl(TRUE
);
115 /*--------------------------------------------------------------------
117 --------------------------------------------------------------------*/
119 SwFldVarPage::~SwFldVarPage()
123 /*--------------------------------------------------------------------
125 --------------------------------------------------------------------*/
127 void SwFldVarPage::Reset(const SfxItemSet
& )
131 Init(); // Allgemeine initialisierung
133 aTypeLB
.SetUpdateMode(FALSE
);
136 USHORT nPos
, nTypeId
;
140 // TypeListBox initialisieren
141 const SwFldGroupRgn
& rRg
= GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
143 for (short i
= rRg
.nStart
; i
< rRg
.nEnd
; ++i
)
145 nTypeId
= GetFldMgr().GetTypeId(i
);
146 nPos
= aTypeLB
.InsertEntry(GetFldMgr().GetTypeStr(i
));
147 aTypeLB
.SetEntryData(nPos
, reinterpret_cast<void*>(nTypeId
));
152 SwField
* pCurField
= GetCurField();
153 nTypeId
= pCurField
->GetTypeId();
154 if (nTypeId
== TYP_SETINPFLD
)
155 nTypeId
= TYP_INPUTFLD
;
156 nPos
= aTypeLB
.InsertEntry(GetFldMgr().GetTypeStr(GetFldMgr().GetPos(nTypeId
)));
157 aTypeLB
.SetEntryData(nPos
, reinterpret_cast<void*>(nTypeId
));
158 aNumFormatLB
.SetAutomaticLanguage(pCurField
->IsAutomaticLanguage());
159 SwWrtShell
*pSh
= GetWrtShell();
161 pSh
= ::GetActiveWrtShell();
164 const SvNumberformat
* pFormat
= pSh
->GetNumberFormatter()->GetEntry(pCurField
->GetFormat());
166 aNumFormatLB
.SetLanguage(pFormat
->GetLanguage());
170 // alte Pos selektieren
171 RestorePos(&aTypeLB
);
173 aTypeLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
174 aTypeLB
.SetSelectHdl (LINK(this, SwFldVarPage
, TypeHdl
));
175 aSelectionLB
.SetSelectHdl (LINK(this, SwFldVarPage
, SubTypeHdl
));
176 aSelectionLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
177 aFormatLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
178 aNumFormatLB
.SetDoubleClickHdl (LINK(this, SwFldVarPage
, InsertHdl
));
179 aNameED
.SetModifyHdl (LINK(this, SwFldVarPage
, ModifyHdl
));
180 aValueED
.SetModifyHdl (LINK(this, SwFldVarPage
, ModifyHdl
));
181 aNewDelTBX
.SetClickHdl (LINK(this, SwFldVarPage
, TBClickHdl
));
182 aChapterLevelLB
.SetSelectHdl (LINK(this, SwFldVarPage
, ChapterHdl
));
183 aSeparatorED
.SetModifyHdl (LINK(this, SwFldVarPage
, SeparatorHdl
));
187 String sUserData
= GetUserData();
188 if(!IsRefresh() && sUserData
.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1
))
190 String sVal
= sUserData
.GetToken(1, ';');
191 USHORT nVal
= (USHORT
)sVal
.ToInt32();
192 if( USHRT_MAX
!= nVal
)
194 for(USHORT i
= 0; i
< aTypeLB
.GetEntryCount(); i
++)
195 if(nVal
== (USHORT
)(ULONG
)aTypeLB
.GetEntryData(i
))
197 aTypeLB
.SelectEntryPos(i
);
205 aTypeLB
.SetUpdateMode(TRUE
);
209 aSelectionLB
.SaveValue();
210 aFormatLB
.SaveValue();
211 nOldFormat
= aNumFormatLB
.GetFormat();
213 aValueED
.SaveValue();
214 aInvisibleCB
.SaveValue();
215 aChapterLevelLB
.SaveValue();
216 aSeparatorED
.SaveValue();
220 /*--------------------------------------------------------------------
222 --------------------------------------------------------------------*/
224 IMPL_LINK( SwFldVarPage
, TypeHdl
, ListBox
*, EMPTYARG
)
226 // Alte ListBoxPos sichern
227 const USHORT nOld
= GetTypeSel();
229 // Aktuelle ListBoxPos
230 SetTypeSel(aTypeLB
.GetSelectEntryPos());
232 if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND
)
235 aTypeLB
.SelectEntryPos(0);
238 if (nOld
!= GetTypeSel() || nOld
== LISTBOX_ENTRY_NOTFOUND
)
241 if (nOld
!= LISTBOX_ENTRY_NOTFOUND
)
243 aNameED
.SetText(aEmptyStr
);
244 aValueED
.SetText(aEmptyStr
);
247 aValueED
.SetDropEnable(FALSE
);
248 UpdateSubType(); // Auswahl-Listboxen initialisieren
256 /*--------------------------------------------------------------------
258 --------------------------------------------------------------------*/
260 IMPL_LINK( SwFldVarPage
, SubTypeHdl
, ListBox
*, pBox
)
262 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
263 USHORT nSelPos
= aSelectionLB
.GetSelectEntryPos();
265 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
266 nSelPos
= (USHORT
)(ULONG
)aSelectionLB
.GetEntryData(nSelPos
);
268 if (IsFldEdit() && (!pBox
|| bInit
))
270 if (nTypeId
!= TYP_FORMELFLD
)
271 aNameED
.SetText(GetFldMgr().GetCurFldPar1());
273 aValueED
.SetText(GetFldMgr().GetCurFldPar2());
276 if (aNameFT
.GetText() != sOldNameFT
)
277 aNameFT
.SetText(sOldNameFT
);
278 if (aValueFT
.GetText() != sOldValueFT
)
279 aValueFT
.SetText(sOldValueFT
);
281 aNumFormatLB
.SetUpdateMode(FALSE
);
282 aFormatLB
.SetUpdateMode(FALSE
);
283 FillFormatLB(nTypeId
);
285 USHORT nSize
= aFormatLB
.GetEntryCount();
287 BOOL bValue
= FALSE
, bName
= FALSE
, bNumFmt
= FALSE
,
288 bInvisible
= FALSE
, bSeparator
= FALSE
, bChapterLevel
= FALSE
;
289 BOOL bFormat
= nSize
!= 0;
295 // Benutzertyp aendern oder anlegen
296 SwUserFieldType
* pType
= (SwUserFieldType
*)
297 GetFldMgr().GetFldType(RES_USERFLD
, nSelPos
);
303 if (pBox
|| (bInit
&& !IsRefresh())) // Nur bei Interaktion mit Maus
305 aNameED
.SetText(pType
->GetName());
307 if (pType
->GetType() == UF_STRING
)
309 aValueED
.SetText(pType
->GetContent());
310 aNumFormatLB
.SelectEntryPos(0);
313 aValueED
.SetText(pType
->GetContent());
314 // aValueED.SetText(pType->GetContent(aNumFormatLB.GetFormat()));
318 aValueED
.SetText(pType
->GetContent());
322 if (pBox
) // Nur bei Interaktion mit Maus
324 aNameED
.SetText(aEmptyStr
);
325 aValueED
.SetText(aEmptyStr
);
328 bValue
= bName
= bNumFmt
= bInvisible
= TRUE
;
330 aValueED
.SetDropEnable(TRUE
);
337 bNumFmt
= bInvisible
= TRUE
;
339 if (!IsFldDlgHtmlMode())
343 aNumFormatLB
.Clear();
344 USHORT nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT
), 0);
345 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
346 aNumFormatLB
.SelectEntryPos(0);
348 // gibt es ein entprechendes SetField
349 if (IsFldEdit() || pBox
) // Nur bei Interaktion mit Maus
351 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
353 String
sName(aSelectionLB
.GetSelectEntry());
354 aNameED
.SetText(sName
);
356 if (!IsFldDlgHtmlMode())
358 SwWrtShell
*pSh
= GetWrtShell();
360 pSh
= ::GetActiveWrtShell();
363 SwSetExpFieldType
* pSetTyp
= (SwSetExpFieldType
*)
364 pSh
->GetFldType(RES_SETEXPFLD
, sName
);
366 if (pSetTyp
&& pSetTyp
->GetType() == nsSwGetSetExpType::GSE_STRING
)
367 aNumFormatLB
.SelectEntryPos(0); // Textuell
374 // GetFormula fuehrt bei Datumsformaten zu Problemen,
375 // da nur der numerische Wert ohne Formatierung returned wird.
376 // Muss aber verwendet werden, da sonst bei GetPar2 nur der vom
377 // Kalkulator errechnete Wert angezeigt werden wuerde
378 // (statt test2 = test + 1)
379 aValueED
.SetText(((SwSetExpField
*)GetCurField())->GetFormula());
381 aValueED
.SetDropEnable(TRUE
);
388 aValueFT
.SetText(SW_RESSTR(STR_FORMULA
));
389 aValueED
.SetDropEnable(TRUE
);
397 aNameED
.SetText(aEmptyStr
);
398 aValueED
.SetText(aEmptyStr
);
401 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
403 String
sName(aSelectionLB
.GetSelectEntry());
405 aNameED
.SetText(sName
);
407 // gibt es ein entprechendes SetField
408 SwWrtShell
*pSh
= GetWrtShell();
410 pSh
= ::GetActiveWrtShell();
413 SwSetExpFieldType
* pSetTyp
= (SwSetExpFieldType
*)
414 pSh
->GetFldType(RES_SETEXPFLD
, sName
);
418 if (pSetTyp
->GetType() & nsSwGetSetExpType::GSE_STRING
) // Textuell?
428 EnableInsert(bFormat
|bNumFmt
);
433 aValueFT
.SetText(SW_RESSTR(STR_PROMPT
));
435 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
437 bValue
= bNumFmt
= TRUE
;
441 sName
= aSelectionLB
.GetSelectEntry();
442 aNameED
.SetText( sName
);
444 // User- oder SetField ?
446 nInpType
= static_cast< USHORT
>(GetFldMgr().GetFldType(RES_USERFLD
, sName
) ? 0 : TYP_SETINPFLD
);
448 if (nInpType
) // SETEXPFLD
450 // gibt es ein entprechendes SetField
451 SwSetExpFieldType
* pSetTyp
= (SwSetExpFieldType
*)
452 GetFldMgr().GetFldType(RES_SETEXPFLD
, sName
);
456 if (pSetTyp
->GetType() == nsSwGetSetExpType::GSE_STRING
) // Textuell?
458 aNumFormatLB
.Clear();
460 USHORT nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_USERVAR_TEXT
), 0);
461 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
462 aNumFormatLB
.SelectEntryPos(0);
465 if (IsFldEdit() && (!pBox
|| bInit
) )
466 aValueED
.SetText(((SwSetExpField
*)GetCurField())->GetPromptText());
469 bFormat
= bNumFmt
= FALSE
;
474 aValueFT
.SetText(SW_RESSTR(STR_DDE_CMD
));
476 if (IsFldEdit() || pBox
) // Nur bei Interaktion mit Maus
478 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
480 SwDDEFieldType
* pType
=
481 (SwDDEFieldType
*) GetFldMgr().GetFldType(RES_DDEFLD
, nSelPos
);
485 aNameED
.SetText(pType
->GetName());
487 //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
488 // Namen haben! Wird hier noch nicht beachtet
489 String
sCmd( pType
->GetCmd() );
490 USHORT nTmpPos
= sCmd
.SearchAndReplace( sfx2::cTokenSeperator
, ' ' );
491 sCmd
.SearchAndReplace( sfx2::cTokenSeperator
, ' ', nTmpPos
);
493 aValueED
.SetText( sCmd
);
494 aFormatLB
.SelectEntryPos(pType
->GetType());
498 bName
= bValue
= TRUE
;
503 // aNumRB.Check(TRUE);
504 bName
= bValue
= bSeparator
= bChapterLevel
= TRUE
;
506 SwFieldType
* pFldTyp
;
508 pFldTyp
= GetCurField()->GetTyp();
511 String
sFldTypeName( aSelectionLB
.GetEntry( nSelPos
));
512 if( sFldTypeName
.Len() )
513 pFldTyp
= GetFldMgr().GetFldType( RES_SETEXPFLD
,
520 aValueED
.SetText( ((SwSetExpField
*)GetCurField())->
523 if( IsFldEdit() || pBox
) // Nur bei Interaktion mit Maus
524 aNameED
.SetText( aSelectionLB
.GetSelectEntry() );
528 BYTE nLevel
= ((SwSetExpFieldType
*)pFldTyp
)->GetOutlineLvl();
530 aChapterLevelLB
.SelectEntryPos( 0 );
532 aChapterLevelLB
.SelectEntryPos( nLevel
+ 1 );
533 String sDelim
= ((SwSetExpFieldType
*)pFldTyp
)->GetDelimiter();
534 aSeparatorED
.SetText( sDelim
);
540 case TYP_SETREFPAGEFLD
:
543 aValueFT
.SetText( SW_RESSTR( STR_OFFSET
));
545 if (IsFldEdit() || pBox
) // Nur bei Interaktion mit Maus
546 aNameED
.SetText(aEmptyStr
);
548 if (nSelPos
!= 0 && nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
550 bValue
= TRUE
; // SubType OFF - kennt keinen Offset
552 aValueED
.SetText(String::CreateFromInt32(((SwRefPageSetField
*)GetCurField())->GetOffset()));
557 case TYP_GETREFPAGEFLD
:
558 aNameED
.SetText(aEmptyStr
);
559 aValueED
.SetText(aEmptyStr
);
563 aNumFormatLB
.Show(bNumFmt
);
564 aFormatLB
.Show(!bNumFmt
);
569 aFormatLB
.Enable(bFormat
);
570 aFormatFT
.Enable(bFormat
|bNumFmt
);
571 aNameFT
.Enable(bName
);
572 aNameED
.Enable(bName
);
573 aValueFT
.Enable(bValue
);
574 aValueED
.Enable(bValue
);
576 Size
aSz(aFormatLB
.GetSizePixel());
579 aSz
.Height() = aFormatLB
.LogicToPixel(Size(1, 94), MAP_APPFONT
).Height();
581 aSz
.Height() = aFormatLB
.LogicToPixel(Size(1, 123), MAP_APPFONT
).Height();
583 aFormatLB
.SetSizePixel(aSz
);
585 aInvisibleCB
.Show(!bSeparator
);
586 aSeparatorFT
.Show(bSeparator
);
587 aSeparatorED
.Show(bSeparator
);
588 aChapterHeaderFT
.Show(bChapterLevel
);
589 aChapterLevelFT
.Show(bChapterLevel
);
590 aChapterLevelLB
.Show(bChapterLevel
);
591 aInvisibleCB
.Enable(bInvisible
);
593 ModifyHdl(); // Anwenden/Einfuegen/Loeschen Status update
595 aNumFormatLB
.SetUpdateMode(TRUE
);
596 aFormatLB
.SetUpdateMode(TRUE
);
598 if(aSelectionLB
.IsCallAddSelection())
600 nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
606 nSelPos
= aSelectionLB
.GetSelectEntryPos();
608 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
609 nSelPos
= (USHORT
)(ULONG
)aSelectionLB
.GetEntryData(nSelPos
);
611 if (nSelPos
!= LISTBOX_ENTRY_NOTFOUND
&& pBox
&& !bInit
)
613 aValueED
.ReplaceSelected(aSelectionLB
.GetSelectEntry());
619 aSelectionLB
.ResetCallAddSelection();
624 /*--------------------------------------------------------------------
625 Beschreibung: Typen in der SelectionBox erneuern
626 --------------------------------------------------------------------*/
628 void SwFldVarPage::UpdateSubType()
631 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
633 SetSelectionSel(aSelectionLB
.GetSelectEntryPos());
634 if(GetSelectionSel() != LISTBOX_ENTRY_NOTFOUND
)
635 sOldSel
= aSelectionLB
.GetEntry(GetSelectionSel());
637 // Auswahl-Listbox fuellen
638 aSelectionLB
.SetUpdateMode(FALSE
);
639 aSelectionLB
.Clear();
642 GetFldMgr().GetSubTypes(nTypeId
, aList
);
643 USHORT nCount
= aList
.Count();
646 for (USHORT i
= 0; i
< nCount
; ++i
)
648 if (nTypeId
!= TYP_INPUTFLD
|| i
)
652 nPos
= aSelectionLB
.InsertEntry(*aList
[i
]);
653 aSelectionLB
.SetEntryData(nPos
, reinterpret_cast<void*>(i
));
657 BOOL bInsert
= FALSE
;
662 if (*aList
[i
] == GetCurField()->GetPar1())
671 if (*aList
[i
] == ((SwFormulaField
*)GetCurField())->GetFormula())
677 if (*aList
[i
] == GetCurField()->GetTyp()->GetName())
680 if (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE
)
681 aInvisibleCB
.Check();
685 case TYP_SETREFPAGEFLD
:
686 if ((((SwRefPageSetField
*)GetCurField())->IsOn() && i
) ||
687 (!((SwRefPageSetField
*)GetCurField())->IsOn() && !i
))
690 // Alle Eintr?ge zur Auswahl zulassen:
691 nPos
= aSelectionLB
.InsertEntry(*aList
[i
]);
692 aSelectionLB
.SetEntryData(nPos
, reinterpret_cast<void*>(i
));
696 if (*aList
[i
] == GetCurField()->GetPar1())
702 nPos
= aSelectionLB
.InsertEntry(*aList
[i
]);
703 aSelectionLB
.SetEntryData(nPos
, reinterpret_cast<void*>(i
));
704 if (nTypeId
!= TYP_FORMELFLD
)
711 BOOL bEnable
= aSelectionLB
.GetEntryCount() != 0;
716 aSelectionLB
.SelectEntry(sOldSel
);
717 if (!aSelectionLB
.GetSelectEntryCount())
719 aSelectionLB
.SelectEntryPos(0);
720 pLB
= &aSelectionLB
; // Alle Controls neu initialisieren
724 aSelectionLB
.Enable( bEnable
);
725 aSelectionFT
.Enable( bEnable
);
728 aSelectionLB
.SetUpdateMode(TRUE
);
731 /*--------------------------------------------------------------------
733 --------------------------------------------------------------------*/
735 USHORT
SwFldVarPage::FillFormatLB(USHORT nTypeId
)
737 String sOldSel
, sOldNumSel
;
738 ULONG nOldNumFormat
= 0;
740 USHORT nFormatSel
= aFormatLB
.GetSelectEntryPos();
741 if (nFormatSel
!= LISTBOX_ENTRY_NOTFOUND
)
742 sOldSel
= aFormatLB
.GetEntry(nFormatSel
);
744 USHORT nNumFormatSel
= aNumFormatLB
.GetSelectEntryPos();
745 if (nNumFormatSel
!= LISTBOX_ENTRY_NOTFOUND
)
747 sOldNumSel
= aNumFormatLB
.GetEntry(nNumFormatSel
);
748 nOldNumFormat
= aNumFormatLB
.GetFormat();
751 // Format-Listbox fuellen
753 aNumFormatLB
.Clear();
754 BOOL bSpecialFmt
= FALSE
;
756 if( TYP_GETREFPAGEFLD
!= nTypeId
)
760 bSpecialFmt
= GetCurField()->GetFormat() == SAL_MAX_UINT32
;
764 aNumFormatLB
.SetDefFormat(GetCurField()->GetFormat());
765 sOldNumSel
= aEmptyStr
;
768 if (nTypeId
== TYP_GETFLD
|| nTypeId
== TYP_FORMELFLD
)
769 aNumFormatLB
.SetFormatType(NUMBERFORMAT_NUMBER
);
773 if (nOldNumFormat
&& nOldNumFormat
!= ULONG_MAX
)
774 aNumFormatLB
.SetDefFormat(nOldNumFormat
);
776 aNumFormatLB
.SetFormatType(NUMBERFORMAT_NUMBER
);
784 if (!IsFldEdit() || bSpecialFmt
)
786 USHORT nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_MARK_TEXT
), 0);
787 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
788 nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_USERVAR_CMD
), 1);
789 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
796 if (!IsFldEdit() || bSpecialFmt
)
798 USHORT nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT
), 0);
799 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
806 USHORT nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_GETVAR_NAME
), 0);
807 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
813 USHORT nPos
= aNumFormatLB
.InsertEntry(SW_RESSTR(FMT_GETVAR_NAME
), 0);
814 aNumFormatLB
.SetEntryData(nPos
, (void *)ULONG_MAX
);
819 if (IsFldEdit() && bSpecialFmt
)
821 if (nTypeId
== TYP_USERFLD
&& (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_CMD
))
822 aNumFormatLB
.SelectEntryPos(1);
824 aNumFormatLB
.SelectEntryPos(0);
828 if (!nOldNumFormat
&& (nNumFormatSel
= aNumFormatLB
.GetEntryPos(sOldNumSel
)) != LISTBOX_ENTRY_NOTFOUND
)
829 aNumFormatLB
.SelectEntryPos(nNumFormatSel
);
830 else if (nOldNumFormat
&& nOldNumFormat
== ULONG_MAX
)
831 aNumFormatLB
.SelectEntry(sOldSel
);
834 USHORT nSize
= GetFldMgr().GetFormatCount(nTypeId
, FALSE
, IsFldDlgHtmlMode());
836 for (USHORT i
= 0; i
< nSize
; i
++)
838 USHORT nPos
= aFormatLB
.InsertEntry(GetFldMgr().GetFormatStr(nTypeId
, i
));
839 USHORT nFldId
= GetFldMgr().GetFormatId( nTypeId
, i
);
840 aFormatLB
.SetEntryData( nPos
, reinterpret_cast<void*>(nFldId
) );
841 if (IsFldEdit() && nFldId
== GetCurField()->GetFormat())
842 aFormatLB
.SelectEntryPos( nPos
);
845 if (nSize
&& (!IsFldEdit() || !aFormatLB
.GetSelectEntryCount()))
847 aFormatLB
.SelectEntry(sOldSel
);
849 if (!aFormatLB
.GetSelectEntryCount())
851 aFormatLB
.SelectEntry(SW_RESSTR(FMT_NUM_PAGEDESC
));
852 if (!aFormatLB
.GetSelectEntryCount())
854 aFormatLB
.SelectEntry(SW_RESSTR(FMT_NUM_ARABIC
));
855 if (!aFormatLB
.GetSelectEntryCount())
856 aFormatLB
.SelectEntryPos(0);
864 /*--------------------------------------------------------------------
866 --------------------------------------------------------------------*/
868 IMPL_LINK( SwFldVarPage
, ModifyHdl
, Edit
*, EMPTYARG
)
870 String
sValue(aValueED
.GetText());
871 BOOL bHasValue
= sValue
.Len() != 0;
872 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
873 BOOL bInsert
= FALSE
, bApply
= FALSE
, bDelete
= FALSE
;
875 String
sName( aNameED
.GetText() );
876 xub_StrLen nLen
= sName
.Len();
884 SwCalc::IsValidVarName( sName
, &sName
);
885 if( sName
.Len() != nLen
)
888 Selection
aSel(aNameED
.GetSelection());
889 aNameED
.SetText( sName
);
890 aNameED
.SetSelection( aSel
); // Cursorpos restaurieren
896 // Buttons ueberpruefen
902 // Gibts schon einen entsprechenden Type
903 bInsert
= bApply
= TRUE
;
905 SwFieldType
* pType
= GetFldMgr().GetFldType(RES_DDEFLD
, sName
);
907 SwWrtShell
*pSh
= GetWrtShell();
909 pSh
= ::GetActiveWrtShell();
911 bDelete
= !pSh
->IsUsed( *pType
);
918 // Gibts schon einen entsprechenden Type
919 SwFieldType
* pType
= GetFldMgr().GetFldType(RES_USERFLD
, sName
);
921 SwWrtShell
*pSh
= GetWrtShell();
923 pSh
= ::GetActiveWrtShell();
925 bDelete
= !pSh
->IsUsed( *pType
);
927 pType
= GetFldMgr().GetFldType(RES_SETEXPFLD
, sName
);
928 if (!pType
) // Kein Namenskonflikt mit Variablen
930 // Benutzerfelder duerfen auch ohne Inhalt eingefuegt werden!
932 bInsert
= bApply
= TRUE
;
940 if (nTypeId
== TYP_SETFLD
|| nTypeId
== TYP_SEQFLD
)
942 SwSetExpFieldType
* pFldType
= (SwSetExpFieldType
*)
943 GetFldMgr().GetFldType(RES_SETEXPFLD
, sName
);
948 SwWrtShell
*pSh
= GetWrtShell();
950 pSh
= ::GetActiveWrtShell();
953 const SwFldTypes
* p
= pSh
->GetDoc()->GetFldTypes();
956 for (i
= 0; i
< INIT_FLDTYPES
; i
++)
958 SwFieldType
* pType
= (*p
)[ i
];
959 if (pType
== pFldType
)
963 if (i
>= INIT_FLDTYPES
&& !pSh
->IsUsed(*pFldType
))
966 if (nTypeId
== TYP_SEQFLD
&& !(pFldType
->GetType() & nsSwGetSetExpType::GSE_SEQ
))
969 if (nTypeId
== TYP_SETFLD
&& (pFldType
->GetType() & nsSwGetSetExpType::GSE_SEQ
))
973 if (GetFldMgr().GetFldType(RES_USERFLD
, sName
))
977 if( !nLen
&& ( nTypeId
== TYP_SETFLD
||
978 (!IsFldEdit() && nTypeId
== TYP_GETFLD
) ) )
981 if( (nTypeId
== TYP_SETFLD
|| nTypeId
== TYP_FORMELFLD
) &&
987 aNewDelTBX
.EnableItem(BT_VARAPPLY
, bApply
);
988 aNewDelTBX
.EnableItem(BT_VARDELETE
, bDelete
);
989 EnableInsert(bInsert
);
994 /*--------------------------------------------------------------------
996 --------------------------------------------------------------------*/
998 IMPL_LINK( SwFldVarPage
, TBClickHdl
, ToolBox
*, pBox
)
1000 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
1002 switch (pBox
->GetCurItemId())
1006 if( nTypeId
== TYP_USERFLD
)
1007 GetFldMgr().RemoveFldType(RES_USERFLD
, aSelectionLB
.GetSelectEntry());
1016 nWhich
= RES_SETEXPFLD
;
1019 nWhich
= RES_DDEFLD
;
1023 GetFldMgr().RemoveFldType(nWhich
, aSelectionLB
.GetSelectEntry());
1027 SwWrtShell
*pSh
= GetWrtShell();
1029 pSh
= ::GetActiveWrtShell();
1039 String
sName(aNameED
.GetText()), sValue(aValueED
.GetText());
1040 SwFieldType
* pType
= 0;
1042 USHORT nNumFormatPos
= aNumFormatLB
.GetSelectEntryPos();
1046 case TYP_USERFLD
: nId
= RES_USERFLD
; break;
1047 case TYP_DDEFLD
: nId
= RES_DDEFLD
; break;
1048 case TYP_SETFLD
: nId
= RES_SETEXPFLD
;break;
1050 pType
= GetFldMgr().GetFldType(nId
, sName
);
1052 ULONG nFormat
= aFormatLB
.GetSelectEntryPos();
1053 if (nFormat
!= LISTBOX_ENTRY_NOTFOUND
)
1054 nFormat
= (ULONG
)aFormatLB
.GetEntryData((USHORT
)nFormat
);
1056 if (pType
) // Aendern
1058 SwWrtShell
*pSh
= GetWrtShell();
1060 pSh
= ::GetActiveWrtShell();
1063 pSh
->StartAllAction();
1065 if (nTypeId
== TYP_USERFLD
)
1067 if (nNumFormatPos
!= LISTBOX_ENTRY_NOTFOUND
)
1069 ULONG nFmt
= nNumFormatPos
== 0 ? 0 : aNumFormatLB
.GetFormat();
1071 { // Sprache auf Office-Sprache umstellen, da String im Office
1072 // Format vom Kalkulator erwartet wird und so in den Dlg
1073 // eingegeben werden sollte
1074 nFmt
= SwValueField::GetSystemFormat(pSh
->GetNumberFormatter(), nFmt
);
1076 ((SwUserFieldType
*)pType
)->SetContent(aValueED
.GetText(), nFmt
);
1077 ((SwUserFieldType
*)pType
)->SetType(
1078 nNumFormatPos
== 0 ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
);
1083 if (nFormat
!= LISTBOX_ENTRY_NOTFOUND
)
1085 //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1086 // Namen haben! Wird hier noch nicht beachtet.
1087 USHORT nTmpPos
= sValue
.SearchAndReplace( ' ', sfx2::cTokenSeperator
);
1088 sValue
.SearchAndReplace( ' ', sfx2::cTokenSeperator
, nTmpPos
);
1089 ((SwDDEFieldType
*)pType
)->SetCmd(sValue
);
1090 ((SwDDEFieldType
*)pType
)->SetType((USHORT
)nFormat
);
1093 pType
->UpdateFlds();
1095 pSh
->EndAllAction();
1100 if(nTypeId
== TYP_USERFLD
)
1102 SwWrtShell
*pSh
= GetWrtShell();
1104 pSh
= ::GetActiveWrtShell();
1107 SwUserFieldType
aType( pSh
->GetDoc(), sName
);
1109 if (nNumFormatPos
!= LISTBOX_ENTRY_NOTFOUND
)
1111 aType
.SetType(nNumFormatPos
== 0 ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
);
1112 aType
.SetContent( sValue
, nNumFormatPos
== 0 ? 0 : aNumFormatLB
.GetFormat() );
1113 aSelectionLB
.InsertEntry(sName
);
1114 aSelectionLB
.SelectEntry(sName
);
1115 GetFldMgr().InsertFldType( aType
); // Userfld Neu
1121 if (nFormat
!= LISTBOX_ENTRY_NOTFOUND
)
1123 //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1124 // Namen haben! Wird hier noch nicht beachtet.
1125 USHORT nTmpPos
= sValue
.SearchAndReplace( ' ', sfx2::cTokenSeperator
);
1126 sValue
.SearchAndReplace( ' ', sfx2::cTokenSeperator
, nTmpPos
);
1128 SwDDEFieldType
aType(sName
, sValue
, (USHORT
)nFormat
);
1129 aSelectionLB
.InsertEntry(sName
);
1130 aSelectionLB
.SelectEntry(sName
);
1131 GetFldMgr().InsertFldType(aType
); // DDE-Feld Neu
1136 GetFldMgr().GetCurFld(); // FieldManager Updaten
1146 /*--------------------------------------------------------------------
1148 --------------------------------------------------------------------*/
1150 IMPL_LINK( SwFldVarPage
, ChapterHdl
, ListBox
*, EMPTYARG
)
1152 BOOL bEnable
= aChapterLevelLB
.GetSelectEntryPos() != 0;
1154 aSeparatorED
.Enable(bEnable
);
1155 aSeparatorFT
.Enable(bEnable
);
1161 /*--------------------------------------------------------------------
1163 --------------------------------------------------------------------*/
1165 IMPL_LINK( SwFldVarPage
, SeparatorHdl
, Edit
*, EMPTYARG
)
1167 BOOL bEnable
= aSeparatorED
.GetText().Len() != 0 ||
1168 aChapterLevelLB
.GetSelectEntryPos() == 0;
1169 EnableInsert(bEnable
);
1174 /*--------------------------------------------------------------------
1176 --------------------------------------------------------------------*/
1178 BOOL
SwFldVarPage::FillItemSet(SfxItemSet
& )
1180 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
1182 String
aVal(aValueED
.GetText());
1183 String
aName(aNameED
.GetText());
1185 USHORT nSubType
= aSelectionLB
.GetSelectEntryPos();
1186 if(nSubType
== LISTBOX_ENTRY_NOTFOUND
)
1189 nSubType
= (USHORT
)(ULONG
)aSelectionLB
.GetEntryData(nSubType
);
1193 if (!aNumFormatLB
.IsVisible())
1195 nFormat
= aFormatLB
.GetSelectEntryPos();
1197 if(nFormat
== LISTBOX_ENTRY_NOTFOUND
)
1200 nFormat
= (ULONG
)aFormatLB
.GetEntryData((USHORT
)nFormat
);
1204 nFormat
= aNumFormatLB
.GetFormat();
1206 if (nFormat
&& nFormat
!= ULONG_MAX
&& aNumFormatLB
.IsAutomaticLanguage())
1208 // Sprache auf Office-Sprache umstellen, da String im Office-
1209 // Format vom Kalkulator erwartet wird und so in den Dlg
1210 // eingegeben werden sollte
1211 SwWrtShell
*pSh
= GetWrtShell();
1213 pSh
= ::GetActiveWrtShell();
1216 nFormat
= SwValueField::GetSystemFormat(pSh
->GetNumberFormatter(), nFormat
);
1220 sal_Unicode cSeparator
= ' ';
1225 nSubType
= (nFormat
== ULONG_MAX
) ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
;
1227 if (nFormat
== ULONG_MAX
&& aNumFormatLB
.GetSelectEntry() == SW_RESSTR(FMT_USERVAR_CMD
))
1228 nSubType
|= nsSwExtendedSubType::SUB_CMD
;
1230 if (aInvisibleCB
.IsChecked())
1231 nSubType
|= nsSwExtendedSubType::SUB_INVISIBLE
;
1236 nSubType
= nsSwGetSetExpType::GSE_FORMULA
;
1237 if (aNumFormatLB
.IsVisible() && nFormat
== ULONG_MAX
)
1238 nSubType
|= nsSwExtendedSubType::SUB_CMD
;
1244 if (aNumFormatLB
.IsVisible() && nFormat
== ULONG_MAX
)
1245 nSubType
|= nsSwExtendedSubType::SUB_CMD
;
1250 SwFieldType
* pType
= GetFldMgr().GetFldType(RES_USERFLD
, aName
);
1251 nSubType
= static_cast< USHORT
>((nSubType
& 0xff00) | ((pType
) ? INP_USR
: INP_VAR
));
1257 if (IsFldDlgHtmlMode())
1260 nSubType
= (nSubType
& 0xff00) | nsSwGetSetExpType::GSE_STRING
;
1263 nSubType
= (nSubType
& 0xff00) | ((nFormat
== ULONG_MAX
) ? nsSwGetSetExpType::GSE_STRING
: nsSwGetSetExpType::GSE_EXPR
);
1265 if (aInvisibleCB
.IsChecked())
1266 nSubType
|= nsSwExtendedSubType::SUB_INVISIBLE
;
1271 // nSubType = nsSwGetSetExpType::GSE_SEQ; // nsSwGetSetExpType::GSE_SEQ wird im Fldmgr fest gesetzt, kann also entfallen
1272 nSubType
= aChapterLevelLB
.GetSelectEntryPos();
1278 String
sSeparator(aSeparatorED
.GetText().GetChar(0));
1279 cSeparator
= sSeparator
.Len() ? sSeparator
.GetChar(0) : ' ';
1280 //nSubType |= (USHORT)(((BYTE)) << 8);
1284 case TYP_GETREFPAGEFLD
:
1285 if( SVX_NUM_CHAR_SPECIAL
== nFormat
)
1286 aVal
= aValueED
.GetText();
1291 aNameED
.GetSavedValue() != aNameED
.GetText() ||
1292 aValueED
.GetSavedValue() != aValueED
.GetText() ||
1293 aSelectionLB
.GetSavedValue() != aSelectionLB
.GetSelectEntryPos() ||
1294 aFormatLB
.GetSavedValue() != aFormatLB
.GetSelectEntryPos() ||
1295 nOldFormat
!= aNumFormatLB
.GetFormat() ||
1296 aInvisibleCB
.GetState() != aInvisibleCB
.GetSavedValue() ||
1297 aChapterLevelLB
.GetSavedValue() != aChapterLevelLB
.GetSelectEntryPos() ||
1298 aSeparatorED
.GetSavedValue() != aSeparatorED
.GetText())
1300 InsertFld( nTypeId
, nSubType
, aName
, aVal
, nFormat
,
1301 cSeparator
, aNumFormatLB
.IsAutomaticLanguage() );
1310 /*--------------------------------------------------------------------
1312 --------------------------------------------------------------------*/
1314 SfxTabPage
* SwFldVarPage::Create( Window
* pParent
,
1315 const SfxItemSet
& rAttrSet
)
1317 return ( new SwFldVarPage( pParent
, rAttrSet
) );
1320 /*--------------------------------------------------------------------
1322 --------------------------------------------------------------------*/
1324 USHORT
SwFldVarPage::GetGroup()
1329 /*--------------------------------------------------------------------
1331 --------------------------------------------------------------------*/
1333 SelectionListBox::SelectionListBox( SwFldVarPage
* pDialog
, const ResId
& rResId
) :
1334 ListBox (pDialog
, rResId
),
1336 bCallAddSelection(FALSE
)
1340 /*--------------------------------------------------------------------
1342 --------------------------------------------------------------------*/
1344 long SelectionListBox::PreNotify( NotifyEvent
& rNEvt
)
1346 long nHandled
= ListBox::PreNotify( rNEvt
);
1347 //BOOL bAddSel = FALSE;
1348 if ( rNEvt
.GetType() == EVENT_KEYUP
)
1350 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
1351 const KeyCode aKeyCode
= pKEvt
->GetKeyCode();
1352 const USHORT nModifier
= aKeyCode
.GetModifier();
1353 if( aKeyCode
.GetCode() == KEY_SPACE
&& !nModifier
)
1355 bCallAddSelection
= TRUE
;
1357 if ( rNEvt
.GetType() == EVENT_MOUSEBUTTONDOWN
)
1359 const MouseEvent
* pMEvt
= rNEvt
.GetMouseEvent();
1361 if (pMEvt
&& (pMEvt
->IsMod1() || pMEvt
->IsMod2())) // Alt oder Ctrl
1363 bCallAddSelection
= TRUE
;
1367 // pDlg->AddSelection(this);
1371 /* -----------------12.01.99 11:14-------------------
1373 * --------------------------------------------------*/
1374 void SwFldVarPage::FillUserData()
1376 String
sData(String::CreateFromAscii(USER_DATA_VERSION
));
1378 USHORT nTypeSel
= aTypeLB
.GetSelectEntryPos();
1379 if( LISTBOX_ENTRY_NOTFOUND
== nTypeSel
)
1380 nTypeSel
= USHRT_MAX
;
1382 nTypeSel
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData( nTypeSel
);
1383 sData
+= String::CreateFromInt32( nTypeSel
);