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 <swtypes.hxx>
30 : : #include <sfx2/linkmgr.hxx>
31 : : #include <usrfld.hxx>
32 : : #include <docufld.hxx>
33 : : #include <expfld.hxx>
34 : : #include <ddefld.hxx>
35 : : #include <view.hxx>
36 : : #include <wrtsh.hxx>
37 : : #include <doc.hxx>
38 : : #include <docary.hxx>
39 : : #include <swmodule.hxx>
40 : : #include <fldvar.hxx>
41 : : #include <calc.hxx>
42 : : #include <svl/zformat.hxx>
43 : : #include <globals.hrc>
44 : : #include <fldui.hrc>
45 : : #include <fldtdlg.hrc>
46 : :
47 : : #define USER_DATA_VERSION_1 "1"
48 : : #define USER_DATA_VERSION USER_DATA_VERSION_1
49 : :
50 : 0 : SwFldVarPage::SwFldVarPage(Window* pParent, const SfxItemSet& rCoreSet ) :
51 : : SwFldPage ( pParent, SW_RES( TP_FLD_VAR ), rCoreSet ),
52 : : aTypeFT (this, SW_RES(FT_VARTYPE)),
53 : : aTypeLB (this, SW_RES(LB_VARTYPE)),
54 : : aSelectionFT (this, SW_RES(FT_VARSELECTION)),
55 : : aSelectionLB (this, SW_RES(LB_VARSELECTION)),
56 : : aNameFT (this, SW_RES(FT_VARNAME)),
57 : : aNameED (this, SW_RES(ED_VARNAME)),
58 : : aValueFT (this, SW_RES(FT_VARVALUE)),
59 : : aValueED (this, SW_RES(ED_VARVALUE)),
60 : : aFormatFT (this, SW_RES(FT_VARFORMAT)),
61 : : aNumFormatLB (this, SW_RES(LB_VARNUMFORMAT)),
62 : : aFormatLB (this, SW_RES(LB_VARFORMAT)),
63 : : aChapterHeaderFT(this, SW_RES(FT_VARCHAPTERHEADER)),
64 : : aChapterLevelFT (this, SW_RES(FT_VARCHAPTERLEVEL)),
65 : : aChapterLevelLB (this, SW_RES(LB_VARCHAPTERLEVEL)),
66 : : aInvisibleCB (this, SW_RES(CB_VARINVISIBLE)),
67 : : aSeparatorFT (this, SW_RES(FT_VARSEPARATOR)),
68 : : aSeparatorED (this, SW_RES(ED_VARSEPARATOR)),
69 : : aNewDelTBX (this, SW_RES(TBX_VARNEWDEL)),
70 : 0 : bInit (sal_True)
71 : : {
72 : 0 : FreeResource();
73 : :
74 : 0 : aNewDelTBX.SetSizePixel( aNewDelTBX.CalcWindowSizePixel() );
75 : :
76 : 0 : long nDelta = ( aValueED.GetSizePixel().Height() -
77 : 0 : aNewDelTBX.GetSizePixel().Height() ) / 2;
78 : 0 : Point aNewPnt = aNewDelTBX.GetPosPixel();
79 : 0 : aNewPnt.Y() += nDelta;
80 : 0 : aNewDelTBX.SetPosPixel( aNewPnt );
81 : :
82 : 0 : sOldValueFT = aValueFT.GetText();
83 : 0 : sOldNameFT = aNameFT.GetText();
84 : :
85 : 0 : for (sal_uInt16 i = 1; i <= MAXLEVEL; i++)
86 : 0 : aChapterLevelLB.InsertEntry(String::CreateFromInt32(i));
87 : :
88 : 0 : aChapterLevelLB.SelectEntryPos(0);
89 : : //enable 'active' language selection
90 : 0 : aNumFormatLB.SetShowLanguageControl(sal_True);
91 : 0 : }
92 : :
93 : 0 : SwFldVarPage::~SwFldVarPage()
94 : : {
95 : 0 : }
96 : :
97 : 0 : void SwFldVarPage::Reset(const SfxItemSet& )
98 : : {
99 : 0 : SavePos(&aTypeLB);
100 : :
101 : 0 : Init(); // general initialisation
102 : :
103 : 0 : aTypeLB.SetUpdateMode(sal_False);
104 : 0 : aTypeLB.Clear();
105 : :
106 : : sal_uInt16 nPos, nTypeId;
107 : :
108 : 0 : if (!IsFldEdit())
109 : : {
110 : : // initialise TypeListBox
111 : 0 : const SwFldGroupRgn& rRg = GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
112 : :
113 : 0 : for (short i = rRg.nStart; i < rRg.nEnd; ++i)
114 : : {
115 : 0 : nTypeId = GetFldMgr().GetTypeId(i);
116 : 0 : nPos = aTypeLB.InsertEntry(GetFldMgr().GetTypeStr(i));
117 : 0 : aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
118 : : }
119 : : }
120 : : else
121 : : {
122 : 0 : SwField* pCurField = GetCurField();
123 : 0 : nTypeId = pCurField->GetTypeId();
124 : 0 : if (nTypeId == TYP_SETINPFLD)
125 : 0 : nTypeId = TYP_INPUTFLD;
126 : 0 : nPos = aTypeLB.InsertEntry(GetFldMgr().GetTypeStr(GetFldMgr().GetPos(nTypeId)));
127 : 0 : aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
128 : 0 : aNumFormatLB.SetAutomaticLanguage(pCurField->IsAutomaticLanguage());
129 : 0 : SwWrtShell *pSh = GetWrtShell();
130 : 0 : if(!pSh)
131 : 0 : pSh = ::GetActiveWrtShell();
132 : 0 : if(pSh)
133 : : {
134 : 0 : const SvNumberformat* pFormat = pSh->GetNumberFormatter()->GetEntry(pCurField->GetFormat());
135 : 0 : if(pFormat)
136 : 0 : aNumFormatLB.SetLanguage(pFormat->GetLanguage());
137 : : }
138 : : }
139 : :
140 : : // select old Pos
141 : 0 : RestorePos(&aTypeLB);
142 : :
143 : 0 : aTypeLB.SetDoubleClickHdl (LINK(this, SwFldVarPage, InsertHdl));
144 : 0 : aTypeLB.SetSelectHdl (LINK(this, SwFldVarPage, TypeHdl));
145 : 0 : aSelectionLB.SetSelectHdl (LINK(this, SwFldVarPage, SubTypeHdl));
146 : 0 : aSelectionLB.SetDoubleClickHdl (LINK(this, SwFldVarPage, InsertHdl));
147 : 0 : aFormatLB.SetDoubleClickHdl (LINK(this, SwFldVarPage, InsertHdl));
148 : 0 : aNumFormatLB.SetDoubleClickHdl (LINK(this, SwFldVarPage, InsertHdl));
149 : 0 : aNameED.SetModifyHdl (LINK(this, SwFldVarPage, ModifyHdl));
150 : 0 : aValueED.SetModifyHdl (LINK(this, SwFldVarPage, ModifyHdl));
151 : 0 : aNewDelTBX.SetClickHdl (LINK(this, SwFldVarPage, TBClickHdl));
152 : 0 : aChapterLevelLB.SetSelectHdl (LINK(this, SwFldVarPage, ChapterHdl));
153 : 0 : aSeparatorED.SetModifyHdl (LINK(this, SwFldVarPage, SeparatorHdl));
154 : :
155 : 0 : if( !IsRefresh() )
156 : : {
157 : 0 : String sUserData = GetUserData();
158 : 0 : if(!IsRefresh() && sUserData.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1))
159 : : {
160 : 0 : String sVal = sUserData.GetToken(1, ';');
161 : 0 : sal_uInt16 nVal = (sal_uInt16)sVal.ToInt32();
162 : 0 : if( USHRT_MAX != nVal )
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 : aSelectionLB.SaveValue();
180 : 0 : aFormatLB.SaveValue();
181 : 0 : nOldFormat = aNumFormatLB.GetFormat();
182 : 0 : aNameED.SaveValue();
183 : 0 : aValueED.SaveValue();
184 : 0 : aInvisibleCB.SaveValue();
185 : 0 : aChapterLevelLB.SaveValue();
186 : 0 : aSeparatorED.SaveValue();
187 : : }
188 : 0 : }
189 : :
190 : 0 : IMPL_LINK_NOARG(SwFldVarPage, TypeHdl)
191 : : {
192 : : // save old ListBoxPos
193 : 0 : const sal_uInt16 nOld = GetTypeSel();
194 : :
195 : : // current ListBoxPos
196 : 0 : SetTypeSel(aTypeLB.GetSelectEntryPos());
197 : :
198 : 0 : if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND)
199 : : {
200 : 0 : SetTypeSel(0);
201 : 0 : aTypeLB.SelectEntryPos(0);
202 : : }
203 : :
204 : 0 : if (nOld != GetTypeSel() || nOld == LISTBOX_ENTRY_NOTFOUND)
205 : : {
206 : 0 : bInit = sal_True;
207 : 0 : if (nOld != LISTBOX_ENTRY_NOTFOUND)
208 : : {
209 : 0 : aNameED.SetText(aEmptyStr);
210 : 0 : aValueED.SetText(aEmptyStr);
211 : : }
212 : :
213 : 0 : aValueED.SetDropEnable(sal_False);
214 : 0 : UpdateSubType(); // initialise selection-listboxes
215 : : }
216 : :
217 : 0 : bInit = sal_False;
218 : :
219 : 0 : return 0;
220 : : }
221 : :
222 : 0 : IMPL_LINK( SwFldVarPage, SubTypeHdl, ListBox *, pBox )
223 : : {
224 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
225 : 0 : sal_uInt16 nSelPos = aSelectionLB.GetSelectEntryPos();
226 : :
227 : 0 : if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
228 : 0 : nSelPos = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nSelPos);
229 : :
230 : 0 : if (IsFldEdit() && (!pBox || bInit))
231 : : {
232 : 0 : if (nTypeId != TYP_FORMELFLD)
233 : 0 : aNameED.SetText(GetFldMgr().GetCurFldPar1());
234 : :
235 : 0 : aValueED.SetText(GetFldMgr().GetCurFldPar2());
236 : : }
237 : :
238 : 0 : if (aNameFT.GetText() != sOldNameFT)
239 : 0 : aNameFT.SetText(sOldNameFT);
240 : 0 : if (aValueFT.GetText() != sOldValueFT)
241 : 0 : aValueFT.SetText(sOldValueFT);
242 : :
243 : 0 : aNumFormatLB.SetUpdateMode(sal_False);
244 : 0 : aFormatLB.SetUpdateMode(sal_False);
245 : 0 : FillFormatLB(nTypeId);
246 : :
247 : 0 : sal_uInt16 nSize = aFormatLB.GetEntryCount();
248 : :
249 : 0 : sal_Bool bValue = sal_False, bName = sal_False, bNumFmt = sal_False,
250 : 0 : bInvisible = sal_False, bSeparator = sal_False, bChapterLevel = sal_False;
251 : 0 : sal_Bool bFormat = nSize != 0;
252 : :
253 : 0 : switch (nTypeId)
254 : : {
255 : : case TYP_USERFLD:
256 : : {
257 : : // change or create user type
258 : : SwUserFieldType* pType = (SwUserFieldType*)
259 : 0 : GetFldMgr().GetFldType(RES_USERFLD, nSelPos);
260 : :
261 : 0 : if (pType)
262 : : {
263 : 0 : if (!IsFldEdit())
264 : : {
265 : 0 : if (pBox || (bInit && !IsRefresh())) // only when interacting via mouse
266 : : {
267 : 0 : aNameED.SetText(pType->GetName());
268 : :
269 : 0 : if (pType->GetType() == UF_STRING)
270 : : {
271 : 0 : aValueED.SetText(pType->GetContent());
272 : 0 : aNumFormatLB.SelectEntryPos(0);
273 : : }
274 : : else
275 : 0 : aValueED.SetText(pType->GetContent());
276 : : }
277 : : }
278 : : else
279 : 0 : aValueED.SetText(pType->GetContent());
280 : : }
281 : : else
282 : : {
283 : 0 : if (pBox) // only when interacting via mouse
284 : : {
285 : 0 : aNameED.SetText(aEmptyStr);
286 : 0 : aValueED.SetText(aEmptyStr);
287 : : }
288 : : }
289 : 0 : bValue = bName = bNumFmt = bInvisible = sal_True;
290 : :
291 : 0 : aValueED.SetDropEnable(sal_True);
292 : 0 : break;
293 : : }
294 : :
295 : : case TYP_SETFLD:
296 : 0 : bValue = sal_True;
297 : :
298 : 0 : bNumFmt = bInvisible = sal_True;
299 : :
300 : 0 : if (!IsFldDlgHtmlMode())
301 : 0 : bName = sal_True;
302 : : else
303 : : {
304 : 0 : aNumFormatLB.Clear();
305 : 0 : sal_uInt16 nPos = aNumFormatLB.InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT), 0);
306 : 0 : aNumFormatLB.SetEntryData(nPos, (void *)ULONG_MAX);
307 : 0 : aNumFormatLB.SelectEntryPos(0);
308 : : }
309 : : // is there a corresponding SetField
310 : 0 : if (IsFldEdit() || pBox) // only when interacting via mouse
311 : : {
312 : 0 : if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
313 : : {
314 : 0 : String sName(aSelectionLB.GetSelectEntry());
315 : 0 : aNameED.SetText(sName);
316 : :
317 : 0 : if (!IsFldDlgHtmlMode())
318 : : {
319 : 0 : SwWrtShell *pSh = GetWrtShell();
320 : 0 : if(!pSh)
321 : 0 : pSh = ::GetActiveWrtShell();
322 : 0 : if(pSh)
323 : : {
324 : : SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
325 : 0 : pSh->GetFldType(RES_SETEXPFLD, sName);
326 : :
327 : 0 : if (pSetTyp && pSetTyp->GetType() == nsSwGetSetExpType::GSE_STRING)
328 : 0 : aNumFormatLB.SelectEntryPos(0); // textual
329 : : }
330 : 0 : }
331 : : }
332 : : }
333 : 0 : if (IsFldEdit())
334 : : {
335 : : // GetFormula leads to problems with date formats because
336 : : // only the numeric value without formating is returned.
337 : : // It must be used though because otherwise in GetPar2 only
338 : : // the value calculated by Kalkulator would be displayed
339 : : // (instead of test2 = test + 1)
340 : 0 : aValueED.SetText(((SwSetExpField*)GetCurField())->GetFormula());
341 : : }
342 : 0 : aValueED.SetDropEnable(sal_True);
343 : 0 : break;
344 : :
345 : : case TYP_FORMELFLD:
346 : : {
347 : 0 : bValue = sal_True;
348 : 0 : bNumFmt = sal_True;
349 : 0 : aValueFT.SetText(SW_RESSTR(STR_FORMULA));
350 : 0 : aValueED.SetDropEnable(sal_True);
351 : : }
352 : 0 : break;
353 : :
354 : : case TYP_GETFLD:
355 : : {
356 : 0 : if (!IsFldEdit())
357 : : {
358 : 0 : aNameED.SetText(aEmptyStr);
359 : 0 : aValueED.SetText(aEmptyStr);
360 : : }
361 : :
362 : 0 : if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
363 : : {
364 : 0 : String sName(aSelectionLB.GetSelectEntry());
365 : 0 : if (!IsFldEdit())
366 : 0 : aNameED.SetText(sName);
367 : :
368 : : // is there a corresponding SetField
369 : 0 : SwWrtShell *pSh = GetWrtShell();
370 : 0 : if(!pSh)
371 : 0 : pSh = ::GetActiveWrtShell();
372 : 0 : if(pSh)
373 : : {
374 : : SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
375 : 0 : pSh->GetFldType(RES_SETEXPFLD, sName);
376 : :
377 : 0 : if(pSetTyp)
378 : : {
379 : 0 : if (pSetTyp->GetType() & nsSwGetSetExpType::GSE_STRING) // textual?
380 : 0 : bFormat = sal_True;
381 : : else // numeric
382 : 0 : bNumFmt = sal_True;
383 : : }
384 : 0 : }
385 : : }
386 : : else
387 : 0 : bFormat = sal_False;
388 : :
389 : 0 : EnableInsert(bFormat|bNumFmt);
390 : : }
391 : 0 : break;
392 : :
393 : : case TYP_INPUTFLD:
394 : 0 : aValueFT.SetText(SW_RESSTR(STR_PROMPT));
395 : :
396 : 0 : if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
397 : : {
398 : 0 : bValue = bNumFmt = sal_True;
399 : :
400 : 0 : String sName;
401 : :
402 : 0 : sName = aSelectionLB.GetSelectEntry();
403 : 0 : aNameED.SetText( sName );
404 : :
405 : : // User- or SetField ?
406 : 0 : sal_uInt16 nInpType = 0;
407 : 0 : nInpType = static_cast< sal_uInt16 >(GetFldMgr().GetFldType(RES_USERFLD, sName) ? 0 : TYP_SETINPFLD);
408 : :
409 : 0 : if (nInpType) // SETEXPFLD
410 : : {
411 : : // is there a corresponding SetField
412 : : SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
413 : 0 : GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
414 : :
415 : 0 : if(pSetTyp)
416 : : {
417 : 0 : if (pSetTyp->GetType() == nsSwGetSetExpType::GSE_STRING) // textual?
418 : : {
419 : 0 : aNumFormatLB.Clear();
420 : :
421 : 0 : sal_uInt16 nPos = aNumFormatLB.InsertEntry(SW_RESSTR(FMT_USERVAR_TEXT), 0);
422 : 0 : aNumFormatLB.SetEntryData(nPos, (void *)ULONG_MAX);
423 : 0 : aNumFormatLB.SelectEntryPos(0);
424 : : }
425 : : }
426 : 0 : if (IsFldEdit() && (!pBox || bInit) )
427 : 0 : aValueED.SetText(((SwSetExpField*)GetCurField())->GetPromptText());
428 : : }
429 : : else // USERFLD
430 : 0 : bFormat = bNumFmt = sal_False;
431 : : }
432 : 0 : break;
433 : :
434 : : case TYP_DDEFLD:
435 : 0 : aValueFT.SetText(SW_RESSTR(STR_DDE_CMD));
436 : :
437 : 0 : if (IsFldEdit() || pBox) // only when interacting via mouse
438 : : {
439 : 0 : if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
440 : : {
441 : : SwDDEFieldType* pType =
442 : 0 : (SwDDEFieldType*) GetFldMgr().GetFldType(RES_DDEFLD, nSelPos);
443 : :
444 : 0 : if(pType)
445 : : {
446 : 0 : aNameED.SetText(pType->GetName());
447 : :
448 : : //JP 28.08.95: DDE-Topics/-Items can have blanks in their names!
449 : : // That's not considered here yet
450 : 0 : String sCmd( pType->GetCmd() );
451 : 0 : sal_uInt16 nTmpPos = sCmd.SearchAndReplace( sfx2::cTokenSeperator, ' ' );
452 : 0 : sCmd.SearchAndReplace( sfx2::cTokenSeperator, ' ', nTmpPos );
453 : :
454 : 0 : aValueED.SetText( sCmd );
455 : 0 : aFormatLB.SelectEntryPos(pType->GetType());
456 : : }
457 : : }
458 : : }
459 : 0 : bName = bValue = sal_True;
460 : 0 : break;
461 : :
462 : : case TYP_SEQFLD:
463 : : {
464 : 0 : bName = bValue = bSeparator = bChapterLevel = sal_True;
465 : :
466 : : SwFieldType* pFldTyp;
467 : 0 : if( IsFldEdit() )
468 : 0 : pFldTyp = GetCurField()->GetTyp();
469 : : else
470 : : {
471 : 0 : String sFldTypeName( aSelectionLB.GetEntry( nSelPos ));
472 : 0 : if( sFldTypeName.Len() )
473 : 0 : pFldTyp = GetFldMgr().GetFldType( RES_SETEXPFLD,
474 : 0 : sFldTypeName );
475 : : else
476 : 0 : pFldTyp = 0;
477 : : }
478 : :
479 : 0 : if( IsFldEdit() )
480 : 0 : aValueED.SetText( ((SwSetExpField*)GetCurField())->
481 : 0 : GetFormula() );
482 : :
483 : 0 : if( IsFldEdit() || pBox ) // only when interacting via mouse
484 : 0 : aNameED.SetText( aSelectionLB.GetSelectEntry() );
485 : :
486 : 0 : if( pFldTyp )
487 : : {
488 : 0 : sal_uInt8 nLevel = ((SwSetExpFieldType*)pFldTyp)->GetOutlineLvl();
489 : 0 : if( 0x7f == nLevel )
490 : 0 : aChapterLevelLB.SelectEntryPos( 0 );
491 : : else
492 : 0 : aChapterLevelLB.SelectEntryPos( nLevel + 1 );
493 : 0 : String sDelim = ((SwSetExpFieldType*)pFldTyp)->GetDelimiter();
494 : 0 : aSeparatorED.SetText( sDelim );
495 : 0 : ChapterHdl();
496 : : }
497 : : }
498 : 0 : break;
499 : :
500 : : case TYP_SETREFPAGEFLD:
501 : : {
502 : 0 : bValue = sal_False;
503 : 0 : aValueFT.SetText( SW_RESSTR( STR_OFFSET ));
504 : :
505 : 0 : if (IsFldEdit() || pBox) // only when interacting via mouse
506 : 0 : aNameED.SetText(aEmptyStr);
507 : :
508 : 0 : if (nSelPos != 0 && nSelPos != LISTBOX_ENTRY_NOTFOUND)
509 : : {
510 : 0 : bValue = sal_True; // SubType OFF - knows no Offset
511 : 0 : if (IsFldEdit())
512 : 0 : aValueED.SetText(String::CreateFromInt32(((SwRefPageSetField*)GetCurField())->GetOffset()));
513 : : }
514 : : }
515 : 0 : break;
516 : :
517 : : case TYP_GETREFPAGEFLD:
518 : 0 : aNameED.SetText(aEmptyStr);
519 : 0 : aValueED.SetText(aEmptyStr);
520 : 0 : break;
521 : : }
522 : :
523 : 0 : aNumFormatLB.Show(bNumFmt);
524 : 0 : aFormatLB.Show(!bNumFmt);
525 : :
526 : 0 : if (IsFldEdit())
527 : 0 : bName = sal_False;
528 : :
529 : 0 : aFormatLB.Enable(bFormat);
530 : 0 : aFormatFT.Enable(bFormat|bNumFmt);
531 : 0 : aNameFT.Enable(bName);
532 : 0 : aNameED.Enable(bName);
533 : 0 : aValueFT.Enable(bValue);
534 : 0 : aValueED.Enable(bValue);
535 : :
536 : 0 : Size aSz(aFormatLB.GetSizePixel());
537 : :
538 : 0 : if (bChapterLevel)
539 : 0 : aSz.Height() = aFormatLB.LogicToPixel(Size(1, 94), MAP_APPFONT).Height();
540 : : else
541 : 0 : aSz.Height() = aFormatLB.LogicToPixel(Size(1, 123), MAP_APPFONT).Height();
542 : :
543 : 0 : aFormatLB.SetSizePixel(aSz);
544 : :
545 : 0 : aInvisibleCB.Show(!bSeparator);
546 : 0 : aSeparatorFT.Show(bSeparator);
547 : 0 : aSeparatorED.Show(bSeparator);
548 : 0 : aChapterHeaderFT.Show(bChapterLevel);
549 : 0 : aChapterLevelFT.Show(bChapterLevel);
550 : 0 : aChapterLevelLB.Show(bChapterLevel);
551 : 0 : aInvisibleCB.Enable(bInvisible);
552 : :
553 : 0 : ModifyHdl(); // apply/insert/delete status update
554 : :
555 : 0 : aNumFormatLB.SetUpdateMode(sal_True);
556 : 0 : aFormatLB.SetUpdateMode(sal_True);
557 : :
558 : 0 : if(aSelectionLB.IsCallAddSelection())
559 : : {
560 : 0 : nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
561 : :
562 : 0 : switch (nTypeId)
563 : : {
564 : : case TYP_FORMELFLD:
565 : : {
566 : 0 : nSelPos = aSelectionLB.GetSelectEntryPos();
567 : :
568 : 0 : if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
569 : 0 : nSelPos = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nSelPos);
570 : :
571 : 0 : if (nSelPos != LISTBOX_ENTRY_NOTFOUND && pBox && !bInit)
572 : : {
573 : 0 : aValueED.ReplaceSelected(aSelectionLB.GetSelectEntry());
574 : 0 : ModifyHdl();
575 : : }
576 : : }
577 : 0 : break;
578 : : }
579 : 0 : aSelectionLB.ResetCallAddSelection();
580 : : }
581 : 0 : return 0;
582 : : }
583 : :
584 : : /*--------------------------------------------------------------------
585 : : Description: renew types in SelectionBox
586 : : --------------------------------------------------------------------*/
587 : 0 : void SwFldVarPage::UpdateSubType()
588 : : {
589 : 0 : String sOldSel;
590 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
591 : :
592 : 0 : SetSelectionSel(aSelectionLB.GetSelectEntryPos());
593 : 0 : if(GetSelectionSel() != LISTBOX_ENTRY_NOTFOUND)
594 : 0 : sOldSel = aSelectionLB.GetEntry(GetSelectionSel());
595 : :
596 : : // fill Selection-Listbox
597 : 0 : aSelectionLB.SetUpdateMode(sal_False);
598 : 0 : aSelectionLB.Clear();
599 : :
600 : 0 : std::vector<rtl::OUString> aList;
601 : 0 : GetFldMgr().GetSubTypes(nTypeId, aList);
602 : 0 : size_t nCount = aList.size();
603 : : size_t nPos;
604 : :
605 : 0 : for(size_t i = 0; i < nCount; ++i)
606 : : {
607 : 0 : if (nTypeId != TYP_INPUTFLD || i)
608 : : {
609 : 0 : if (!IsFldEdit())
610 : : {
611 : 0 : nPos = aSelectionLB.InsertEntry(aList[i]);
612 : 0 : aSelectionLB.SetEntryData(nPos, reinterpret_cast<void*>(i));
613 : : }
614 : : else
615 : : {
616 : 0 : sal_Bool bInsert = sal_False;
617 : :
618 : 0 : switch (nTypeId)
619 : : {
620 : : case TYP_INPUTFLD:
621 : 0 : if (aList[i] == GetCurField()->GetPar1())
622 : 0 : bInsert = sal_True;
623 : 0 : break;
624 : :
625 : : case TYP_FORMELFLD:
626 : 0 : bInsert = sal_True;
627 : 0 : break;
628 : :
629 : : case TYP_GETFLD:
630 : 0 : if (aList[i].equals(((const SwFormulaField*)GetCurField())->GetFormula()))
631 : 0 : bInsert = sal_True;
632 : 0 : break;
633 : :
634 : : case TYP_SETFLD:
635 : : case TYP_USERFLD:
636 : 0 : if (aList[i] == GetCurField()->GetTyp()->GetName())
637 : : {
638 : 0 : bInsert = sal_True;
639 : 0 : if (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE)
640 : 0 : aInvisibleCB.Check();
641 : : }
642 : 0 : break;
643 : :
644 : : case TYP_SETREFPAGEFLD:
645 : 0 : if ((((SwRefPageSetField*)GetCurField())->IsOn() && i) ||
646 : 0 : (!((SwRefPageSetField*)GetCurField())->IsOn() && !i))
647 : 0 : sOldSel = aList[i];
648 : :
649 : : // allow all entries for selection:
650 : 0 : nPos = aSelectionLB.InsertEntry(aList[i]);
651 : 0 : aSelectionLB.SetEntryData(nPos, reinterpret_cast<void*>(i));
652 : 0 : break;
653 : :
654 : : default:
655 : 0 : if (aList[i] == GetCurField()->GetPar1())
656 : 0 : bInsert = sal_True;
657 : 0 : break;
658 : : }
659 : 0 : if (bInsert)
660 : : {
661 : 0 : nPos = aSelectionLB.InsertEntry(aList[i]);
662 : 0 : aSelectionLB.SetEntryData(nPos, reinterpret_cast<void*>(i));
663 : 0 : if (nTypeId != TYP_FORMELFLD)
664 : 0 : break;
665 : : }
666 : : }
667 : : }
668 : : }
669 : :
670 : 0 : sal_Bool bEnable = aSelectionLB.GetEntryCount() != 0;
671 : 0 : ListBox *pLB = 0;
672 : :
673 : 0 : if (bEnable)
674 : : {
675 : 0 : aSelectionLB.SelectEntry(sOldSel);
676 : 0 : if (!aSelectionLB.GetSelectEntryCount())
677 : : {
678 : 0 : aSelectionLB.SelectEntryPos(0);
679 : 0 : pLB = &aSelectionLB; // newly initialise all controls
680 : : }
681 : : }
682 : :
683 : 0 : aSelectionLB.Enable( bEnable );
684 : 0 : aSelectionFT.Enable( bEnable );
685 : :
686 : 0 : SubTypeHdl(pLB);
687 : 0 : aSelectionLB.SetUpdateMode(sal_True);
688 : 0 : }
689 : :
690 : 0 : sal_uInt16 SwFldVarPage::FillFormatLB(sal_uInt16 nTypeId)
691 : : {
692 : 0 : String sOldSel, sOldNumSel;
693 : 0 : sal_uLong nOldNumFormat = 0;
694 : :
695 : 0 : sal_uInt16 nFormatSel = aFormatLB.GetSelectEntryPos();
696 : 0 : if (nFormatSel != LISTBOX_ENTRY_NOTFOUND)
697 : 0 : sOldSel = aFormatLB.GetEntry(nFormatSel);
698 : :
699 : 0 : sal_uInt16 nNumFormatSel = aNumFormatLB.GetSelectEntryPos();
700 : 0 : if (nNumFormatSel != LISTBOX_ENTRY_NOTFOUND)
701 : : {
702 : 0 : sOldNumSel = aNumFormatLB.GetEntry(nNumFormatSel);
703 : 0 : nOldNumFormat = aNumFormatLB.GetFormat();
704 : : }
705 : :
706 : : // fill Format-Listbox
707 : 0 : aFormatLB.Clear();
708 : 0 : aNumFormatLB.Clear();
709 : 0 : sal_Bool bSpecialFmt = sal_False;
710 : :
711 : 0 : if( TYP_GETREFPAGEFLD != nTypeId )
712 : : {
713 : 0 : if (IsFldEdit())
714 : : {
715 : 0 : bSpecialFmt = GetCurField()->GetFormat() == SAL_MAX_UINT32;
716 : :
717 : 0 : if (!bSpecialFmt)
718 : : {
719 : 0 : aNumFormatLB.SetDefFormat(GetCurField()->GetFormat());
720 : 0 : sOldNumSel = aEmptyStr;
721 : : }
722 : : else
723 : 0 : if (nTypeId == TYP_GETFLD || nTypeId == TYP_FORMELFLD)
724 : 0 : aNumFormatLB.SetFormatType(NUMBERFORMAT_NUMBER);
725 : : }
726 : : else
727 : : {
728 : 0 : if (nOldNumFormat && nOldNumFormat != ULONG_MAX)
729 : 0 : aNumFormatLB.SetDefFormat(nOldNumFormat);
730 : : else
731 : 0 : aNumFormatLB.SetFormatType(NUMBERFORMAT_NUMBER);
732 : : }
733 : : }
734 : :
735 : 0 : switch (nTypeId)
736 : : {
737 : : case TYP_USERFLD:
738 : : {
739 : 0 : if (!IsFldEdit() || bSpecialFmt)
740 : : {
741 : 0 : sal_uInt16 nPos = aNumFormatLB.InsertEntry(SW_RESSTR(FMT_MARK_TEXT), 0);
742 : 0 : aNumFormatLB.SetEntryData(nPos, (void *)ULONG_MAX);
743 : 0 : nPos = aNumFormatLB.InsertEntry(SW_RESSTR(FMT_USERVAR_CMD), 1);
744 : 0 : aNumFormatLB.SetEntryData(nPos, (void *)ULONG_MAX);
745 : : }
746 : : }
747 : 0 : break;
748 : :
749 : : case TYP_SETFLD:
750 : : {
751 : 0 : if (!IsFldEdit() || bSpecialFmt)
752 : : {
753 : 0 : sal_uInt16 nPos = aNumFormatLB.InsertEntry(SW_RESSTR(FMT_SETVAR_TEXT), 0);
754 : 0 : aNumFormatLB.SetEntryData(nPos, (void *)ULONG_MAX);
755 : : }
756 : : }
757 : 0 : break;
758 : :
759 : : case TYP_FORMELFLD:
760 : : {
761 : 0 : sal_uInt16 nPos = aNumFormatLB.InsertEntry(SW_RESSTR(FMT_GETVAR_NAME), 0);
762 : 0 : aNumFormatLB.SetEntryData(nPos, (void *)ULONG_MAX);
763 : : }
764 : 0 : break;
765 : :
766 : : case TYP_GETFLD:
767 : : {
768 : 0 : sal_uInt16 nPos = aNumFormatLB.InsertEntry(SW_RESSTR(FMT_GETVAR_NAME), 0);
769 : 0 : aNumFormatLB.SetEntryData(nPos, (void *)ULONG_MAX);
770 : : }
771 : 0 : break;
772 : : }
773 : :
774 : 0 : if (IsFldEdit() && bSpecialFmt)
775 : : {
776 : 0 : if (nTypeId == TYP_USERFLD && (GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_CMD))
777 : 0 : aNumFormatLB.SelectEntryPos(1);
778 : : else
779 : 0 : aNumFormatLB.SelectEntryPos(0);
780 : : }
781 : : else
782 : : {
783 : 0 : if (!nOldNumFormat && (nNumFormatSel = aNumFormatLB.GetEntryPos(sOldNumSel)) != LISTBOX_ENTRY_NOTFOUND)
784 : 0 : aNumFormatLB.SelectEntryPos(nNumFormatSel);
785 : 0 : else if (nOldNumFormat && nOldNumFormat == ULONG_MAX)
786 : 0 : aNumFormatLB.SelectEntry(sOldSel);
787 : : }
788 : :
789 : 0 : sal_uInt16 nSize = GetFldMgr().GetFormatCount(nTypeId, sal_False, IsFldDlgHtmlMode());
790 : :
791 : 0 : for (sal_uInt16 i = 0; i < nSize; i++)
792 : : {
793 : 0 : sal_uInt16 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
794 : 0 : sal_uInt16 nFldId = GetFldMgr().GetFormatId( nTypeId, i );
795 : 0 : aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(nFldId) );
796 : 0 : if (IsFldEdit() && nFldId == GetCurField()->GetFormat())
797 : 0 : aFormatLB.SelectEntryPos( nPos );
798 : : }
799 : :
800 : 0 : if (nSize && (!IsFldEdit() || !aFormatLB.GetSelectEntryCount()))
801 : : {
802 : 0 : aFormatLB.SelectEntry(sOldSel);
803 : :
804 : 0 : if (!aFormatLB.GetSelectEntryCount())
805 : : {
806 : 0 : aFormatLB.SelectEntry(SW_RESSTR(FMT_NUM_PAGEDESC));
807 : 0 : if (!aFormatLB.GetSelectEntryCount())
808 : : {
809 : 0 : aFormatLB.SelectEntry(SW_RESSTR(FMT_NUM_ARABIC));
810 : 0 : if (!aFormatLB.GetSelectEntryCount())
811 : 0 : aFormatLB.SelectEntryPos(0);
812 : : }
813 : : }
814 : : }
815 : :
816 : 0 : return nSize;
817 : : }
818 : :
819 : : /*--------------------------------------------------------------------
820 : : Description: Modify
821 : : --------------------------------------------------------------------*/
822 : 0 : IMPL_LINK_NOARG(SwFldVarPage, ModifyHdl)
823 : : {
824 : 0 : String sValue(aValueED.GetText());
825 : 0 : sal_Bool bHasValue = sValue.Len() != 0;
826 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
827 : 0 : sal_Bool bInsert = sal_False, bApply = sal_False, bDelete = sal_False;
828 : :
829 : 0 : String sName( aNameED.GetText() );
830 : 0 : xub_StrLen nLen = sName.Len();
831 : :
832 : 0 : switch( nTypeId )
833 : : {
834 : : case TYP_DDEFLD:
835 : : case TYP_USERFLD:
836 : : case TYP_SETFLD:
837 : : case TYP_SEQFLD:
838 : 0 : SwCalc::IsValidVarName( sName, &sName );
839 : 0 : if( sName.Len() != nLen )
840 : : {
841 : 0 : nLen = sName.Len();
842 : 0 : Selection aSel(aNameED.GetSelection());
843 : 0 : aNameED.SetText( sName );
844 : 0 : aNameED.SetSelection( aSel ); // restore Cursorpos
845 : : }
846 : 0 : break;
847 : : }
848 : :
849 : :
850 : : // check buttons
851 : 0 : switch (nTypeId)
852 : : {
853 : : case TYP_DDEFLD:
854 : 0 : if( nLen )
855 : : {
856 : : // is there already a corrensponding type
857 : 0 : bInsert = bApply = sal_True;
858 : :
859 : 0 : SwFieldType* pType = GetFldMgr().GetFldType(RES_DDEFLD, sName);
860 : :
861 : 0 : SwWrtShell *pSh = GetWrtShell();
862 : 0 : if(!pSh)
863 : 0 : pSh = ::GetActiveWrtShell();
864 : 0 : if(pSh && pType)
865 : 0 : bDelete = !pSh->IsUsed( *pType );
866 : : }
867 : 0 : break;
868 : :
869 : : case TYP_USERFLD:
870 : 0 : if( nLen )
871 : : {
872 : : // is there already a corresponding type
873 : 0 : SwFieldType* pType = GetFldMgr().GetFldType(RES_USERFLD, sName);
874 : :
875 : 0 : SwWrtShell *pSh = GetWrtShell();
876 : 0 : if(!pSh)
877 : 0 : pSh = ::GetActiveWrtShell();
878 : 0 : if(pSh && pType)
879 : 0 : bDelete = !pSh->IsUsed( *pType );
880 : :
881 : 0 : pType = GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
882 : 0 : if (!pType) // no name conflict with variables
883 : : {
884 : : // user fields can also be inserted without content!
885 : : // Bug #56845
886 : 0 : bInsert = bApply = sal_True;
887 : : }
888 : : }
889 : 0 : break;
890 : :
891 : : default:
892 : 0 : bInsert = sal_True;
893 : :
894 : 0 : if (nTypeId == TYP_SETFLD || nTypeId == TYP_SEQFLD)
895 : : {
896 : : SwSetExpFieldType* pFldType = (SwSetExpFieldType*)
897 : 0 : GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
898 : :
899 : 0 : if (pFldType)
900 : : {
901 : :
902 : 0 : SwWrtShell *pSh = GetWrtShell();
903 : 0 : if(!pSh)
904 : 0 : pSh = ::GetActiveWrtShell();
905 : 0 : if(pSh)
906 : : {
907 : 0 : const SwFldTypes* p = pSh->GetDoc()->GetFldTypes();
908 : : sal_uInt16 i;
909 : :
910 : 0 : for (i = 0; i < INIT_FLDTYPES; i++)
911 : : {
912 : 0 : SwFieldType* pType = (*p)[ i ];
913 : 0 : if (pType == pFldType)
914 : 0 : break;
915 : : }
916 : :
917 : 0 : if (i >= INIT_FLDTYPES && !pSh->IsUsed(*pFldType))
918 : 0 : bDelete = sal_True;
919 : :
920 : 0 : if (nTypeId == TYP_SEQFLD && !(pFldType->GetType() & nsSwGetSetExpType::GSE_SEQ))
921 : 0 : bInsert = sal_False;
922 : :
923 : 0 : if (nTypeId == TYP_SETFLD && (pFldType->GetType() & nsSwGetSetExpType::GSE_SEQ))
924 : 0 : bInsert = sal_False;
925 : : }
926 : : }
927 : 0 : if (GetFldMgr().GetFldType(RES_USERFLD, sName))
928 : 0 : bInsert = sal_False;
929 : : }
930 : :
931 : 0 : if( !nLen && ( nTypeId == TYP_SETFLD ||
932 : 0 : (!IsFldEdit() && nTypeId == TYP_GETFLD ) ) )
933 : 0 : bInsert = sal_False;
934 : :
935 : 0 : if( (nTypeId == TYP_SETFLD || nTypeId == TYP_FORMELFLD) &&
936 : : !bHasValue )
937 : 0 : bInsert = sal_False;
938 : 0 : break;
939 : : }
940 : :
941 : 0 : aNewDelTBX.EnableItem(BT_VARAPPLY, bApply);
942 : 0 : aNewDelTBX.EnableItem(BT_VARDELETE, bDelete);
943 : 0 : EnableInsert(bInsert);
944 : :
945 : 0 : return 0;
946 : : }
947 : :
948 : 0 : IMPL_LINK( SwFldVarPage, TBClickHdl, ToolBox *, pBox )
949 : : {
950 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
951 : :
952 : 0 : switch (pBox->GetCurItemId())
953 : : {
954 : : case BT_VARDELETE:
955 : : {
956 : 0 : if( nTypeId == TYP_USERFLD )
957 : 0 : GetFldMgr().RemoveFldType(RES_USERFLD, aSelectionLB.GetSelectEntry());
958 : : else
959 : : {
960 : : sal_uInt16 nWhich;
961 : :
962 : 0 : switch(nTypeId)
963 : : {
964 : : case TYP_SETFLD:
965 : : case TYP_SEQFLD:
966 : 0 : nWhich = RES_SETEXPFLD;
967 : 0 : break;
968 : : default:
969 : 0 : nWhich = RES_DDEFLD;
970 : 0 : break;
971 : : }
972 : :
973 : 0 : GetFldMgr().RemoveFldType(nWhich, aSelectionLB.GetSelectEntry());
974 : : }
975 : :
976 : 0 : UpdateSubType();
977 : 0 : SwWrtShell *pSh = GetWrtShell();
978 : 0 : if(!pSh)
979 : 0 : pSh = ::GetActiveWrtShell();
980 : 0 : if(pSh)
981 : : {
982 : 0 : pSh->SetModified();
983 : : }
984 : : }
985 : 0 : break;
986 : :
987 : : case BT_VARAPPLY:
988 : : {
989 : 0 : String sName(aNameED.GetText()), sValue(aValueED.GetText());
990 : 0 : SwFieldType* pType = 0;
991 : 0 : sal_uInt16 nId = 0;
992 : 0 : sal_uInt16 nNumFormatPos = aNumFormatLB.GetSelectEntryPos();
993 : :
994 : 0 : switch (nTypeId)
995 : : {
996 : 0 : case TYP_USERFLD: nId = RES_USERFLD; break;
997 : 0 : case TYP_DDEFLD: nId = RES_DDEFLD; break;
998 : 0 : case TYP_SETFLD: nId = RES_SETEXPFLD;break;
999 : : }
1000 : 0 : pType = GetFldMgr().GetFldType(nId, sName);
1001 : :
1002 : 0 : sal_uLong nFormat = aFormatLB.GetSelectEntryPos();
1003 : 0 : if (nFormat != LISTBOX_ENTRY_NOTFOUND)
1004 : 0 : nFormat = (sal_uLong)aFormatLB.GetEntryData((sal_uInt16)nFormat);
1005 : :
1006 : 0 : if (pType) // change
1007 : : {
1008 : 0 : SwWrtShell *pSh = GetWrtShell();
1009 : 0 : if(!pSh)
1010 : 0 : pSh = ::GetActiveWrtShell();
1011 : 0 : if(pSh)
1012 : : {
1013 : 0 : pSh->StartAllAction();
1014 : :
1015 : 0 : if (nTypeId == TYP_USERFLD)
1016 : : {
1017 : 0 : if (nNumFormatPos != LISTBOX_ENTRY_NOTFOUND)
1018 : : {
1019 : 0 : sal_uLong nFmt = nNumFormatPos == 0 ? 0 : aNumFormatLB.GetFormat();
1020 : 0 : if (nFmt)
1021 : : { // Switch language to office-language because Kalkulator expects
1022 : : // String in office format and it should be fed into dialog like
1023 : : // that
1024 : 0 : nFmt = SwValueField::GetSystemFormat(pSh->GetNumberFormatter(), nFmt);
1025 : : }
1026 : 0 : ((SwUserFieldType*)pType)->SetContent(aValueED.GetText(), nFmt);
1027 : : ((SwUserFieldType*)pType)->SetType(
1028 : 0 : nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR );
1029 : : }
1030 : : }
1031 : : else
1032 : : {
1033 : 0 : if (nFormat != LISTBOX_ENTRY_NOTFOUND)
1034 : : {
1035 : : // DDE-Topics/-Items can have blanks in their names!
1036 : : // That's not being considered here yet.
1037 : 0 : sal_uInt16 nTmpPos = sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1038 : 0 : sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1039 : 0 : ((SwDDEFieldType*)pType)->SetCmd(sValue);
1040 : 0 : ((SwDDEFieldType*)pType)->SetType((sal_uInt16)nFormat);
1041 : : }
1042 : : }
1043 : 0 : pType->UpdateFlds();
1044 : :
1045 : 0 : pSh->EndAllAction();
1046 : : }
1047 : : }
1048 : : else // new
1049 : : {
1050 : 0 : if(nTypeId == TYP_USERFLD)
1051 : : {
1052 : 0 : SwWrtShell *pSh = GetWrtShell();
1053 : 0 : if(!pSh)
1054 : 0 : pSh = ::GetActiveWrtShell();
1055 : 0 : if(pSh)
1056 : : {
1057 : 0 : SwUserFieldType aType( pSh->GetDoc(), sName );
1058 : :
1059 : 0 : if (nNumFormatPos != LISTBOX_ENTRY_NOTFOUND)
1060 : : {
1061 : 0 : aType.SetType(nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR);
1062 : 0 : aType.SetContent( sValue, nNumFormatPos == 0 ? 0 : aNumFormatLB.GetFormat() );
1063 : 0 : aSelectionLB.InsertEntry(sName);
1064 : 0 : aSelectionLB.SelectEntry(sName);
1065 : 0 : GetFldMgr().InsertFldType( aType ); // Userfld new
1066 : 0 : }
1067 : : }
1068 : : }
1069 : : else
1070 : : {
1071 : 0 : if (nFormat != LISTBOX_ENTRY_NOTFOUND)
1072 : : {
1073 : : // DDE-Topics/-Items can have blanks in their names!
1074 : : // That's not being considered here yet.
1075 : 0 : sal_uInt16 nTmpPos = sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1076 : 0 : sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1077 : :
1078 : 0 : SwDDEFieldType aType(sName, sValue, (sal_uInt16)nFormat);
1079 : 0 : aSelectionLB.InsertEntry(sName);
1080 : 0 : aSelectionLB.SelectEntry(sName);
1081 : 0 : GetFldMgr().InsertFldType(aType); // DDE-Field new
1082 : : }
1083 : : }
1084 : : }
1085 : 0 : if (IsFldEdit())
1086 : 0 : GetFldMgr().GetCurFld(); // update FieldManager
1087 : :
1088 : 0 : UpdateSubType();
1089 : : }
1090 : 0 : break;
1091 : : }
1092 : :
1093 : 0 : return sal_True;
1094 : : }
1095 : :
1096 : 0 : IMPL_LINK_NOARG(SwFldVarPage, ChapterHdl)
1097 : : {
1098 : 0 : sal_Bool bEnable = aChapterLevelLB.GetSelectEntryPos() != 0;
1099 : :
1100 : 0 : aSeparatorED.Enable(bEnable);
1101 : 0 : aSeparatorFT.Enable(bEnable);
1102 : 0 : SeparatorHdl();
1103 : :
1104 : 0 : return 0;
1105 : : }
1106 : :
1107 : 0 : IMPL_LINK_NOARG(SwFldVarPage, SeparatorHdl)
1108 : : {
1109 : 0 : sal_Bool bEnable = aSeparatorED.GetText().Len() != 0 ||
1110 : 0 : aChapterLevelLB.GetSelectEntryPos() == 0;
1111 : 0 : EnableInsert(bEnable);
1112 : :
1113 : 0 : return 0;
1114 : : }
1115 : :
1116 : 0 : sal_Bool SwFldVarPage::FillItemSet(SfxItemSet& )
1117 : : {
1118 : 0 : sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
1119 : :
1120 : 0 : String aVal(aValueED.GetText());
1121 : 0 : String aName(aNameED.GetText());
1122 : :
1123 : 0 : sal_uInt16 nSubType = aSelectionLB.GetSelectEntryPos();
1124 : 0 : if(nSubType == LISTBOX_ENTRY_NOTFOUND)
1125 : 0 : nSubType = 0;
1126 : : else
1127 : 0 : nSubType = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nSubType);
1128 : :
1129 : : sal_uLong nFormat;
1130 : :
1131 : 0 : if (!aNumFormatLB.IsVisible())
1132 : : {
1133 : 0 : nFormat = aFormatLB.GetSelectEntryPos();
1134 : :
1135 : 0 : if(nFormat == LISTBOX_ENTRY_NOTFOUND)
1136 : 0 : nFormat = 0;
1137 : : else
1138 : 0 : nFormat = (sal_uLong)aFormatLB.GetEntryData((sal_uInt16)nFormat);
1139 : : }
1140 : : else
1141 : : {
1142 : 0 : nFormat = aNumFormatLB.GetFormat();
1143 : :
1144 : 0 : if (nFormat && nFormat != ULONG_MAX && aNumFormatLB.IsAutomaticLanguage())
1145 : : {
1146 : : // Switch language to office language because Kalkulator expects
1147 : : // String in office format and it should be fed into the dialog
1148 : : // like that
1149 : 0 : SwWrtShell *pSh = GetWrtShell();
1150 : 0 : if(!pSh)
1151 : 0 : pSh = ::GetActiveWrtShell();
1152 : 0 : if(pSh)
1153 : : {
1154 : 0 : nFormat = SwValueField::GetSystemFormat(pSh->GetNumberFormatter(), nFormat);
1155 : : }
1156 : : }
1157 : : }
1158 : 0 : sal_Unicode cSeparator = ' ';
1159 : 0 : switch (nTypeId)
1160 : : {
1161 : : case TYP_USERFLD:
1162 : : {
1163 : 0 : nSubType = (nFormat == ULONG_MAX) ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR;
1164 : :
1165 : 0 : if (nFormat == ULONG_MAX && aNumFormatLB.GetSelectEntry().Equals(SW_RESSTR(FMT_USERVAR_CMD)))
1166 : 0 : nSubType |= nsSwExtendedSubType::SUB_CMD;
1167 : :
1168 : 0 : if (aInvisibleCB.IsChecked())
1169 : 0 : nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1170 : 0 : break;
1171 : : }
1172 : : case TYP_FORMELFLD:
1173 : : {
1174 : 0 : nSubType = nsSwGetSetExpType::GSE_FORMULA;
1175 : 0 : if (aNumFormatLB.IsVisible() && nFormat == ULONG_MAX)
1176 : 0 : nSubType |= nsSwExtendedSubType::SUB_CMD;
1177 : 0 : break;
1178 : : }
1179 : : case TYP_GETFLD:
1180 : : {
1181 : 0 : nSubType &= 0xff00;
1182 : 0 : if (aNumFormatLB.IsVisible() && nFormat == ULONG_MAX)
1183 : 0 : nSubType |= nsSwExtendedSubType::SUB_CMD;
1184 : 0 : break;
1185 : : }
1186 : : case TYP_INPUTFLD:
1187 : : {
1188 : 0 : SwFieldType* pType = GetFldMgr().GetFldType(RES_USERFLD, aName);
1189 : 0 : nSubType = static_cast< sal_uInt16 >((nSubType & 0xff00) | ((pType) ? INP_USR : INP_VAR));
1190 : 0 : break;
1191 : : }
1192 : :
1193 : : case TYP_SETFLD:
1194 : : {
1195 : 0 : if (IsFldDlgHtmlMode())
1196 : : {
1197 : 0 : nSubType = 0x0100;
1198 : 0 : nSubType = (nSubType & 0xff00) | nsSwGetSetExpType::GSE_STRING;
1199 : : }
1200 : : else
1201 : 0 : nSubType = (nSubType & 0xff00) | ((nFormat == ULONG_MAX) ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR);
1202 : :
1203 : 0 : if (aInvisibleCB.IsChecked())
1204 : 0 : nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1205 : 0 : break;
1206 : : }
1207 : : case TYP_SEQFLD:
1208 : : {
1209 : 0 : nSubType = aChapterLevelLB.GetSelectEntryPos();
1210 : 0 : if (nSubType == 0)
1211 : 0 : nSubType = 0x7f;
1212 : : else
1213 : : {
1214 : 0 : nSubType--;
1215 : 0 : String sSeparator = rtl::OUString(aSeparatorED.GetText().GetChar(0));
1216 : 0 : cSeparator = sSeparator.Len() ? sSeparator.GetChar(0) : ' ';
1217 : : }
1218 : 0 : break;
1219 : : }
1220 : : case TYP_GETREFPAGEFLD:
1221 : 0 : if( SVX_NUM_CHAR_SPECIAL == nFormat )
1222 : 0 : aVal = aValueED.GetText();
1223 : 0 : break;
1224 : : }
1225 : :
1226 : 0 : if (!IsFldEdit() ||
1227 : 0 : aNameED.GetSavedValue() != aNameED.GetText() ||
1228 : 0 : aValueED.GetSavedValue() != aValueED.GetText() ||
1229 : 0 : aSelectionLB.GetSavedValue() != aSelectionLB.GetSelectEntryPos() ||
1230 : 0 : aFormatLB.GetSavedValue() != aFormatLB.GetSelectEntryPos() ||
1231 : 0 : nOldFormat != aNumFormatLB.GetFormat() ||
1232 : 0 : aInvisibleCB.GetState() != aInvisibleCB.GetSavedValue() ||
1233 : 0 : aChapterLevelLB.GetSavedValue() != aChapterLevelLB.GetSelectEntryPos() ||
1234 : 0 : aSeparatorED.GetSavedValue() != aSeparatorED.GetText())
1235 : : {
1236 : : InsertFld( nTypeId, nSubType, aName, aVal, nFormat,
1237 : 0 : cSeparator, aNumFormatLB.IsAutomaticLanguage() );
1238 : : }
1239 : :
1240 : 0 : UpdateSubType();
1241 : :
1242 : 0 : return sal_False;
1243 : : }
1244 : :
1245 : 0 : SfxTabPage* SwFldVarPage::Create( Window* pParent,
1246 : : const SfxItemSet& rAttrSet )
1247 : : {
1248 : 0 : return ( new SwFldVarPage( pParent, rAttrSet ) );
1249 : : }
1250 : :
1251 : 0 : sal_uInt16 SwFldVarPage::GetGroup()
1252 : : {
1253 : 0 : return GRP_VAR;
1254 : : }
1255 : :
1256 : 0 : SelectionListBox::SelectionListBox( SwFldVarPage* pDialog, const ResId& rResId ) :
1257 : : ListBox (pDialog, rResId),
1258 : : pDlg (pDialog),
1259 : 0 : bCallAddSelection(sal_False)
1260 : : {
1261 : 0 : }
1262 : :
1263 : 0 : long SelectionListBox::PreNotify( NotifyEvent& rNEvt )
1264 : : {
1265 : 0 : long nHandled = ListBox::PreNotify( rNEvt );
1266 : 0 : if ( rNEvt.GetType() == EVENT_KEYUP )
1267 : : {
1268 : 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1269 : 0 : const KeyCode aKeyCode = pKEvt->GetKeyCode();
1270 : 0 : const sal_uInt16 nModifier = aKeyCode.GetModifier();
1271 : 0 : if( aKeyCode.GetCode() == KEY_SPACE && !nModifier)
1272 : 0 : bCallAddSelection = sal_True;
1273 : : }
1274 : 0 : if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
1275 : : {
1276 : 0 : const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
1277 : :
1278 : 0 : if (pMEvt && (pMEvt->IsMod1() || pMEvt->IsMod2())) // Alt or Ctrl
1279 : 0 : bCallAddSelection = sal_True;
1280 : : }
1281 : :
1282 : 0 : return nHandled;
1283 : : }
1284 : :
1285 : 0 : void SwFldVarPage::FillUserData()
1286 : : {
1287 : 0 : String sData(rtl::OUString(USER_DATA_VERSION));
1288 : 0 : sData += ';';
1289 : 0 : sal_uInt16 nTypeSel = aTypeLB.GetSelectEntryPos();
1290 : 0 : if( LISTBOX_ENTRY_NOTFOUND == nTypeSel )
1291 : 0 : nTypeSel = USHRT_MAX;
1292 : : else
1293 : 0 : nTypeSel = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData( nTypeSel );
1294 : 0 : sData += String::CreateFromInt32( nTypeSel );
1295 : 0 : SetUserData(sData);
1296 : 0 : }
1297 : :
1298 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|