xref: /aoo42x/main/sw/source/ui/fldui/fldvar.cxx (revision 0d473b4a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #ifdef SW_DLLIMPLEMENTATION
27 #undef SW_DLLIMPLEMENTATION
28 #endif
29 
30 
31 #include <swtypes.hxx>
32 #include <sfx2/linkmgr.hxx>
33 #include <usrfld.hxx>
34 #include <docufld.hxx>
35 #include <expfld.hxx>
36 #include <ddefld.hxx>
37 #include <view.hxx>
38 #include <wrtsh.hxx>
39 #include <doc.hxx>
40 #include <docary.hxx>
41 #include <swmodule.hxx>
42 #include <fldvar.hxx>
43 #include <calc.hxx>
44 #include <svl/zformat.hxx>
45 #include <globals.hrc>
46 #include <fldui.hrc>
47 #include <fldtdlg.hrc>
48 
49 #define USER_DATA_VERSION_1 "1"
50 #define USER_DATA_VERSION USER_DATA_VERSION_1
51 /*--------------------------------------------------------------------
52 	Beschreibung:
53  --------------------------------------------------------------------*/
54 
SwFldVarPage(Window * pParent,const SfxItemSet & rCoreSet)55 SwFldVarPage::SwFldVarPage(Window* pParent, const SfxItemSet& rCoreSet ) :
56 	SwFldPage		( pParent, SW_RES( TP_FLD_VAR ), rCoreSet ),
57 	aTypeFT			(this, SW_RES(FT_VARTYPE)),
58 	aTypeLB			(this, SW_RES(LB_VARTYPE)),
59 	aSelectionFT	(this, SW_RES(FT_VARSELECTION)),
60 	aSelectionLB	(this, SW_RES(LB_VARSELECTION)),
61 	aNameFT			(this, SW_RES(FT_VARNAME)),
62 	aNameED			(this, SW_RES(ED_VARNAME)),
63 	aValueFT		(this, SW_RES(FT_VARVALUE)),
64 	aValueED		(this, SW_RES(ED_VARVALUE)),
65 	aFormatFT		(this, SW_RES(FT_VARFORMAT)),
66 	aNumFormatLB	(this, SW_RES(LB_VARNUMFORMAT)),
67 	aFormatLB		(this, SW_RES(LB_VARFORMAT)),
68 	aChapterHeaderFT(this, SW_RES(FT_VARCHAPTERHEADER)),
69 	aChapterLevelFT	(this, SW_RES(FT_VARCHAPTERLEVEL)),
70 	aChapterLevelLB	(this, SW_RES(LB_VARCHAPTERLEVEL)),
71 	aInvisibleCB	(this, SW_RES(CB_VARINVISIBLE)),
72 	aSeparatorFT	(this, SW_RES(FT_VARSEPARATOR)),
73 	aSeparatorED	(this, SW_RES(ED_VARSEPARATOR)),
74 	aNewDelTBX		(this, SW_RES(TBX_VARNEWDEL)),
75 	bInit			(sal_True)
76 {
77 	FreeResource();
78 
79 	aNewDelTBX.SetSizePixel( aNewDelTBX.CalcWindowSizePixel() );
80 
81 	long nDelta = ( aValueED.GetSizePixel().Height() -
82 					aNewDelTBX.GetSizePixel().Height() ) / 2;
83 	Point aNewPnt = aNewDelTBX.GetPosPixel();
84 	aNewPnt.Y() += nDelta;
85 	aNewDelTBX.SetPosPixel( aNewPnt );
86 
87 	sOldValueFT = aValueFT.GetText();
88 	sOldNameFT = aNameFT.GetText();
89 
90 	for (sal_uInt16 i = 1; i <= MAXLEVEL; i++)
91 		aChapterLevelLB.InsertEntry(String::CreateFromInt32(i));
92 
93 	aChapterLevelLB.SelectEntryPos(0);
94     //enable 'active' language selection
95     aNumFormatLB.SetShowLanguageControl(sal_True);
96 }
97 
98 /*--------------------------------------------------------------------
99 	Beschreibung:
100  --------------------------------------------------------------------*/
101 
~SwFldVarPage()102 SwFldVarPage::~SwFldVarPage()
103 {
104 }
105 
106 /*--------------------------------------------------------------------
107 	Beschreibung:
108  --------------------------------------------------------------------*/
109 
Reset(const SfxItemSet &)110 void SwFldVarPage::Reset(const SfxItemSet& )
111 {
112 	SavePos(&aTypeLB);
113 
114 	Init();	// Allgemeine initialisierung
115 
116 	aTypeLB.SetUpdateMode(sal_False);
117 	aTypeLB.Clear();
118 
119 	sal_uInt16 nPos, nTypeId;
120 
121 	if (!IsFldEdit())
122 	{
123 		// TypeListBox initialisieren
124 		const SwFldGroupRgn& rRg = GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
125 
126 		for (short i = rRg.nStart; i < rRg.nEnd; ++i)
127 		{
128 			nTypeId = GetFldMgr().GetTypeId(i);
129 			nPos = aTypeLB.InsertEntry(GetFldMgr().GetTypeStr(i));
130 			aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
131 		}
132 	}
133 	else
134 	{
135         const SwField* pCurField = GetCurField();
136         ASSERT( pCurField != NULL,
137                 "<SwFldVarPage::Reset(..)> - <SwField> instance missing!" );
138         nTypeId = pCurField->GetTypeId();
139         if ( nTypeId == TYP_SETINPFLD )
140             nTypeId = TYP_INPUTFLD;
141         nPos = aTypeLB.InsertEntry( GetFldMgr().GetTypeStr( GetFldMgr().GetPos( nTypeId ) ) );
142         aTypeLB.SetEntryData( nPos, reinterpret_cast< void* >( nTypeId ) );
143         aNumFormatLB.SetAutomaticLanguage( pCurField->IsAutomaticLanguage() );
144         SwWrtShell *pSh = GetWrtShell();
145         if ( !pSh )
146             pSh = ::GetActiveWrtShell();
147         if ( pSh )
148         {
149             const SvNumberformat* pFormat = pSh->GetNumberFormatter()->GetEntry( pCurField->GetFormat() );
150             if ( pFormat )
151                 aNumFormatLB.SetLanguage( pFormat->GetLanguage() );
152         }
153     }
154 
155 	// alte Pos selektieren
156 	RestorePos(&aTypeLB);
157 
158 	aTypeLB.SetDoubleClickHdl		(LINK(this, SwFldVarPage, InsertHdl));
159 	aTypeLB.SetSelectHdl			(LINK(this, SwFldVarPage, TypeHdl));
160 	aSelectionLB.SetSelectHdl		(LINK(this, SwFldVarPage, SubTypeHdl));
161 	aSelectionLB.SetDoubleClickHdl	(LINK(this, SwFldVarPage, InsertHdl));
162 	aFormatLB.SetDoubleClickHdl		(LINK(this, SwFldVarPage, InsertHdl));
163 	aNumFormatLB.SetDoubleClickHdl	(LINK(this, SwFldVarPage, InsertHdl));
164 	aNameED.SetModifyHdl			(LINK(this, SwFldVarPage, ModifyHdl));
165 	aValueED.SetModifyHdl			(LINK(this, SwFldVarPage, ModifyHdl));
166 	aNewDelTBX.SetClickHdl			(LINK(this, SwFldVarPage, TBClickHdl));
167 	aChapterLevelLB.SetSelectHdl	(LINK(this, SwFldVarPage, ChapterHdl));
168 	aSeparatorED.SetModifyHdl		(LINK(this, SwFldVarPage, SeparatorHdl));
169 
170 	if( !IsRefresh() )
171 	{
172 		String sUserData = GetUserData();
173 		if(!IsRefresh() && sUserData.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1))
174 		{
175 			String sVal = sUserData.GetToken(1, ';');
176 			sal_uInt16 nVal = (sal_uInt16)sVal.ToInt32();
177 			if( USHRT_MAX != nVal )
178 			{
179 				for(sal_uInt16 i = 0; i < aTypeLB.GetEntryCount(); i++)
180 					if(nVal == (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(i))
181 					{
182 						aTypeLB.SelectEntryPos(i);
183 						break;
184 					}
185 			}
186 		}
187 	}
188 	TypeHdl(0);
189 
190 	aTypeLB.SetUpdateMode(sal_True);
191 
192 	if (IsFldEdit())
193 	{
194 		aSelectionLB.SaveValue();
195 		aFormatLB.SaveValue();
196 		nOldFormat = aNumFormatLB.GetFormat();
197 		aNameED.SaveValue();
198 		aValueED.SaveValue();
199 		aInvisibleCB.SaveValue();
200 		aChapterLevelLB.SaveValue();
201 		aSeparatorED.SaveValue();
202 	}
203 }
204 
205 /*--------------------------------------------------------------------
206 	Beschreibung:
207  --------------------------------------------------------------------*/
208 
IMPL_LINK(SwFldVarPage,TypeHdl,ListBox *,EMPTYARG)209 IMPL_LINK( SwFldVarPage, TypeHdl, ListBox *, EMPTYARG )
210 {
211 	// Alte ListBoxPos sichern
212 	const sal_uInt16 nOld = GetTypeSel();
213 
214 	// Aktuelle ListBoxPos
215 	SetTypeSel(aTypeLB.GetSelectEntryPos());
216 
217 	if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND)
218 	{
219 		SetTypeSel(0);
220 		aTypeLB.SelectEntryPos(0);
221 	}
222 
223 	if (nOld != GetTypeSel() || nOld == LISTBOX_ENTRY_NOTFOUND)
224 	{
225 		bInit = sal_True;
226 		if (nOld != LISTBOX_ENTRY_NOTFOUND)
227 		{
228 			aNameED.SetText(aEmptyStr);
229 			aValueED.SetText(aEmptyStr);
230 		}
231 
232 		aValueED.SetDropEnable(sal_False);
233 		UpdateSubType();	// Auswahl-Listboxen initialisieren
234 	}
235 
236 	bInit = sal_False;
237 
238 	return 0;
239 }
240 
241 /*--------------------------------------------------------------------
242 	Beschreibung:
243  --------------------------------------------------------------------*/
244 
IMPL_LINK(SwFldVarPage,SubTypeHdl,ListBox *,pBox)245 IMPL_LINK( SwFldVarPage, SubTypeHdl, ListBox *, pBox )
246 {
247 	sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
248 	sal_uInt16 nSelPos = aSelectionLB.GetSelectEntryPos();
249 
250 	if (nSelPos != LISTBOX_ENTRY_NOTFOUND)
251 		nSelPos = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nSelPos);
252 
253 	if (IsFldEdit() && (!pBox || bInit))
254 	{
255 		if (nTypeId != TYP_FORMELFLD)
256 			aNameED.SetText(GetFldMgr().GetCurFldPar1());
257 
258 		aValueED.SetText(GetFldMgr().GetCurFldPar2());
259 	}
260 
261 	if (aNameFT.GetText() != sOldNameFT)
262 		aNameFT.SetText(sOldNameFT);
263 	if (aValueFT.GetText() != sOldValueFT)
264 		aValueFT.SetText(sOldValueFT);
265 
266 	aNumFormatLB.SetUpdateMode(sal_False);
267 	aFormatLB.SetUpdateMode(sal_False);
268 	FillFormatLB(nTypeId);
269 
270 	sal_uInt16 nSize = aFormatLB.GetEntryCount();
271 
272 	sal_Bool bValue = sal_False, bName = sal_False, bNumFmt = sal_False,
273 			bInvisible = sal_False, bSeparator = sal_False, bChapterLevel = sal_False;
274 	sal_Bool bFormat = nSize != 0;
275 
276     switch ( nTypeId )
277     {
278     case TYP_USERFLD:
279         {
280             // Benutzertyp aendern oder anlegen
281             SwUserFieldType* pType = (SwUserFieldType*)
282                     GetFldMgr().GetFldType( RES_USERFLD, nSelPos );
283 
284             if ( pType )
285             {
286                 if ( !IsFldEdit() )
287                 {
288                     if ( pBox || ( bInit && !IsRefresh() ) )	// Nur bei Interaktion mit Maus
289                     {
290                         aNameED.SetText( pType->GetName() );
291 
292                         if ( pType->GetType() == UF_STRING )
293                         {
294                             aValueED.SetText( pType->GetContent() );
295                             aNumFormatLB.SelectEntryPos( 0 );
296                         }
297                         else
298                             aValueED.SetText( pType->GetContent() );
299 //							aValueED.SetText(pType->GetContent(aNumFormatLB.GetFormat()));
300                     }
301                 }
302                 else
303                     aValueED.SetText( pType->GetContent() );
304             }
305             else
306             {
307                 if ( pBox )	// Nur bei Interaktion mit Maus
308                 {
309                     aNameED.SetText( aEmptyStr );
310                     aValueED.SetText( aEmptyStr );
311                 }
312             }
313             bValue = bName = bNumFmt = bInvisible = sal_True;
314 
315             aValueED.SetDropEnable( sal_True );
316             break;
317         }
318 
319     case TYP_SETFLD:
320         bValue = sal_True;
321 
322         bNumFmt = bInvisible = sal_True;
323 
324         if ( !IsFldDlgHtmlMode() )
325             bName = sal_True;
326         else
327         {
328             aNumFormatLB.Clear();
329             sal_uInt16 nPos = aNumFormatLB.InsertEntry( SW_RESSTR( FMT_SETVAR_TEXT ), 0 );
330             aNumFormatLB.SetEntryData( nPos, (void *) ULONG_MAX );
331             aNumFormatLB.SelectEntryPos( 0 );
332         }
333         // gibt es ein entprechendes SetField
334         if ( IsFldEdit() || pBox )	// Nur bei Interaktion mit Maus
335         {
336             if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
337             {
338                 String sName( aSelectionLB.GetSelectEntry() );
339                 aNameED.SetText( sName );
340 
341                 if ( !IsFldDlgHtmlMode() )
342                 {
343                     SwWrtShell *pSh = GetWrtShell();
344                     if ( !pSh )
345                         pSh = ::GetActiveWrtShell();
346                     if ( pSh )
347                     {
348                         SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
349                                 pSh->GetFldType( RES_SETEXPFLD, sName );
350 
351                         if ( pSetTyp && pSetTyp->GetType() == nsSwGetSetExpType::GSE_STRING )
352                             aNumFormatLB.SelectEntryPos( 0 ); // Textuell
353                     }
354                 }
355             }
356         }
357         if ( GetCurField() != NULL && IsFldEdit() )
358         {
359             // GetFormula fuehrt bei Datumsformaten zu Problemen,
360             // da nur der numerische Wert ohne Formatierung returned wird.
361             // Muss aber verwendet werden, da sonst bei GetPar2 nur der vom
362             // Kalkulator errechnete Wert angezeigt werden wuerde
363             // (statt test2 = test + 1)
364             aValueED.SetText( ( (SwSetExpField*) GetCurField() )->GetFormula() );
365         }
366         aValueED.SetDropEnable( sal_True );
367         break;
368 
369     case TYP_FORMELFLD:
370         {
371             bValue = sal_True;
372             bNumFmt = sal_True;
373             aValueFT.SetText( SW_RESSTR( STR_FORMULA ) );
374             aValueED.SetDropEnable( sal_True );
375         }
376         break;
377 
378     case TYP_GETFLD:
379         {
380             if ( !IsFldEdit() )
381             {
382                 aNameED.SetText( aEmptyStr );
383                 aValueED.SetText( aEmptyStr );
384             }
385 
386             if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
387             {
388                 String sName( aSelectionLB.GetSelectEntry() );
389                 if ( !IsFldEdit() )
390                     aNameED.SetText( sName );
391 
392                 // gibt es ein entprechendes SetField
393                 SwWrtShell *pSh = GetWrtShell();
394                 if ( !pSh )
395                     pSh = ::GetActiveWrtShell();
396                 if ( pSh )
397                 {
398                     SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
399                             pSh->GetFldType( RES_SETEXPFLD, sName );
400 
401                     if ( pSetTyp )
402                     {
403                         if ( pSetTyp->GetType() & nsSwGetSetExpType::GSE_STRING )    // Textuell?
404                             bFormat = sal_True;
405                         else
406                             // Numerisch
407                             bNumFmt = sal_True;
408                     }
409                 }
410             }
411             else
412                 bFormat = sal_False;
413 
414             EnableInsert( bFormat | bNumFmt );
415         }
416         break;
417 
418     case TYP_INPUTFLD:
419         aValueFT.SetText( SW_RESSTR( STR_PROMPT ) );
420 
421         if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
422         {
423             bValue = bNumFmt = sal_True;
424 
425             String sName;
426 
427             sName = aSelectionLB.GetSelectEntry();
428             aNameED.SetText( sName );
429 
430             // User- oder SetField ?
431             sal_uInt16 nInpType = 0;
432             nInpType = static_cast< sal_uInt16 >( GetFldMgr().GetFldType( RES_USERFLD, sName ) ? 0 : TYP_SETINPFLD );
433 
434             if ( nInpType )	// SETEXPFLD
435             {
436                 // gibt es ein entprechendes SetField
437                 SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
438                         GetFldMgr().GetFldType( RES_SETEXPFLD, sName );
439 
440                 if ( pSetTyp )
441                 {
442                     if ( pSetTyp->GetType() == nsSwGetSetExpType::GSE_STRING )	// Textuell?
443                     {
444                         aNumFormatLB.Clear();
445 
446                         sal_uInt16 nPos = aNumFormatLB.InsertEntry( SW_RESSTR( FMT_USERVAR_TEXT ), 0 );
447                         aNumFormatLB.SetEntryData( nPos, (void *) ULONG_MAX );
448                         aNumFormatLB.SelectEntryPos( 0 );
449                     }
450                 }
451                 if ( GetCurField() != NULL
452                      && IsFldEdit() && ( !pBox || bInit ) )
453                 {
454                     aValueED.SetText( ( (SwSetExpField*) GetCurField() )->GetPromptText() );
455                 }
456             }
457             else
458                 // USERFLD
459                 bFormat = bNumFmt = sal_False;
460         }
461         break;
462 
463     case TYP_DDEFLD:
464         aValueFT.SetText( SW_RESSTR( STR_DDE_CMD ) );
465 
466         if ( IsFldEdit() || pBox )	// Nur bei Interaktion mit Maus
467         {
468             if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
469             {
470                 SwDDEFieldType* pType =
471                         (SwDDEFieldType*) GetFldMgr().GetFldType( RES_DDEFLD, nSelPos );
472 
473                 if ( pType )
474                 {
475                     aNameED.SetText( pType->GetName() );
476 
477                     //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
478                     //				Namen haben! Wird hier noch nicht beachtet
479                     String sCmd( pType->GetCmd() );
480                     sal_uInt16 nTmpPos = sCmd.SearchAndReplace( sfx2::cTokenSeperator, ' ' );
481                     sCmd.SearchAndReplace( sfx2::cTokenSeperator, ' ', nTmpPos );
482 
483                     aValueED.SetText( sCmd );
484                     aFormatLB.SelectEntryPos( pType->GetType() );
485                 }
486             }
487         }
488         bName = bValue = sal_True;
489         break;
490 
491     case TYP_SEQFLD:
492         {
493             // aNumRB.Check(sal_True);
494             bName = bValue = bSeparator = bChapterLevel = sal_True;
495 
496             SwFieldType* pFldTyp;
497             if ( GetCurField() != NULL && IsFldEdit() )
498                 pFldTyp = GetCurField()->GetTyp();
499             else
500             {
501                 String sFldTypeName( aSelectionLB.GetEntry( nSelPos ) );
502                 if ( sFldTypeName.Len() )
503                     pFldTyp = GetFldMgr().GetFldType( RES_SETEXPFLD, sFldTypeName );
504                 else
505                     pFldTyp = 0;
506             }
507 
508             if ( GetCurField() != NULL && IsFldEdit() )
509                 aValueED.SetText( ( (SwSetExpField*) GetCurField() )-> GetFormula() );
510 
511             if ( IsFldEdit() || pBox )	// Nur bei Interaktion mit Maus
512                 aNameED.SetText( aSelectionLB.GetSelectEntry() );
513 
514             if ( pFldTyp )
515             {
516                 sal_uInt8 nLevel = ( (SwSetExpFieldType*) pFldTyp )->GetOutlineLvl();
517                 if ( 0x7f == nLevel )
518                     aChapterLevelLB.SelectEntryPos( 0 );
519                 else
520                     aChapterLevelLB.SelectEntryPos( nLevel + 1 );
521                 String sDelim = ( (SwSetExpFieldType*) pFldTyp )->GetDelimiter();
522                 aSeparatorED.SetText( sDelim );
523                 ChapterHdl();
524             }
525         }
526         break;
527 
528     case TYP_SETREFPAGEFLD:
529         {
530             bValue = sal_False;
531             aValueFT.SetText( SW_RESSTR( STR_OFFSET ) );
532 
533             if ( IsFldEdit() || pBox )	// Nur bei Interaktion mit Maus
534                 aNameED.SetText( aEmptyStr );
535 
536             if ( nSelPos != 0 && nSelPos != LISTBOX_ENTRY_NOTFOUND )
537             {
538                 bValue = sal_True;		// SubType OFF - kennt keinen Offset
539                 if ( GetCurField() != NULL && IsFldEdit() )
540                     aValueED.SetText( String::CreateFromInt32( ( (SwRefPageSetField*) GetCurField() )->GetOffset() ) );
541             }
542         }
543         break;
544 
545     case TYP_GETREFPAGEFLD:
546         aNameED.SetText( aEmptyStr );
547         aValueED.SetText( aEmptyStr );
548         break;
549     }
550 
551     aNumFormatLB.Show( bNumFmt );
552     aFormatLB.Show( !bNumFmt );
553 
554     if ( IsFldEdit() )
555         bName = sal_False;
556 
557     aFormatLB.Enable( bFormat );
558     aFormatFT.Enable( bFormat | bNumFmt );
559     aNameFT.Enable( bName );
560     aNameED.Enable( bName );
561     aValueFT.Enable( bValue );
562     aValueED.Enable( bValue );
563 
564     Size aSz( aFormatLB.GetSizePixel() );
565     if ( bChapterLevel )
566         aSz.Height() = aFormatLB.LogicToPixel( Size( 1, 94 ), MAP_APPFONT ).Height();
567     else
568         aSz.Height() = aFormatLB.LogicToPixel( Size( 1, 123 ), MAP_APPFONT ).Height();
569     aFormatLB.SetSizePixel( aSz );
570 
571     aInvisibleCB.Show( !bSeparator );
572     aSeparatorFT.Show( bSeparator );
573     aSeparatorED.Show( bSeparator );
574     aChapterHeaderFT.Show( bChapterLevel );
575     aChapterLevelFT.Show( bChapterLevel );
576     aChapterLevelLB.Show( bChapterLevel );
577     aInvisibleCB.Enable( bInvisible );
578 
579     ModifyHdl();	// Anwenden/Einfuegen/Loeschen Status update
580 
581     aNumFormatLB.SetUpdateMode( sal_True );
582     aFormatLB.SetUpdateMode( sal_True );
583 
584     if ( aSelectionLB.IsCallAddSelection() )
585     {
586         nTypeId = (sal_uInt16) (sal_uLong) aTypeLB.GetEntryData( GetTypeSel() );
587 
588         switch ( nTypeId )
589         {
590         case TYP_FORMELFLD:
591             {
592                 nSelPos = aSelectionLB.GetSelectEntryPos();
593 
594                 if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
595                     nSelPos = (sal_uInt16) (sal_uLong) aSelectionLB.GetEntryData( nSelPos );
596 
597                 if ( nSelPos != LISTBOX_ENTRY_NOTFOUND && pBox && !bInit )
598                 {
599                     aValueED.ReplaceSelected( aSelectionLB.GetSelectEntry() );
600                     ModifyHdl();
601                 }
602             }
603             break;
604         }
605         aSelectionLB.ResetCallAddSelection();
606     }
607     return 0;
608 }
609 
610 /*--------------------------------------------------------------------
611 	 Beschreibung: Typen in der SelectionBox erneuern
612  --------------------------------------------------------------------*/
613 
UpdateSubType()614 void SwFldVarPage::UpdateSubType()
615 {
616     SetSelectionSel( aSelectionLB.GetSelectEntryPos() );
617 
618     String sOldSel;
619     if ( GetSelectionSel() != LISTBOX_ENTRY_NOTFOUND )
620         sOldSel = aSelectionLB.GetEntry( GetSelectionSel() );
621 
622     // Auswahl-Listbox fuellen
623     aSelectionLB.SetUpdateMode( sal_False );
624     aSelectionLB.Clear();
625 
626     const sal_uInt16 nTypeId = (sal_uInt16) (sal_uLong) aTypeLB.GetEntryData( GetTypeSel() );
627     SvStringsDtor aList;
628     GetFldMgr().GetSubTypes( nTypeId, aList );
629     const sal_uInt16 nCount = aList.Count();
630     for ( sal_uInt16 i = 0; i < nCount; ++i )
631     {
632         if ( nTypeId != TYP_INPUTFLD || i )
633         {
634             if ( !IsFldEdit() )
635             {
636                 const sal_uInt16 nPos = aSelectionLB.InsertEntry( *aList[i] );
637                 aSelectionLB.SetEntryData( nPos, reinterpret_cast< void* >( i ) );
638             }
639             else
640             {
641                 sal_Bool bInsert = sal_False;
642 
643                 switch ( nTypeId )
644                 {
645                 case TYP_INPUTFLD:
646                     if ( GetCurField() != NULL && *aList[i] == GetCurField()->GetPar1() )
647                         bInsert = sal_True;
648                     break;
649 
650                 case TYP_FORMELFLD:
651                     bInsert = sal_True;
652                     break;
653 
654                 case TYP_GETFLD:
655                     if ( GetCurField() != NULL && *aList[i] == ( (SwFormulaField*) GetCurField() )->GetFormula() )
656                         bInsert = sal_True;
657                     break;
658 
659                 case TYP_SETFLD:
660                 case TYP_USERFLD:
661                     if ( GetCurField() != NULL && *aList[i] == GetCurField()->GetTyp()->GetName() )
662                     {
663                         bInsert = sal_True;
664                         if ( GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE )
665                             aInvisibleCB.Check();
666                     }
667                     break;
668 
669                 case TYP_SETREFPAGEFLD:
670                     {
671                         if ( GetCurField() != NULL
672                              && ( ( ( (SwRefPageSetField*) GetCurField() )->IsOn() && i )
673                                   || ( !( (SwRefPageSetField*) GetCurField() )->IsOn() && !i ) ) )
674                         {
675                             sOldSel = *aList[i];
676                         }
677 
678                         // Alle Eintr?ge zur Auswahl zulassen:
679                         const sal_uInt16 nPos = aSelectionLB.InsertEntry( *aList[i] );
680                         aSelectionLB.SetEntryData( nPos, reinterpret_cast< void* >( i ) );
681                     }
682                     break;
683 
684                 default:
685                     if ( GetCurField() != NULL && *aList[i] == GetCurField()->GetPar1() )
686                         bInsert = sal_True;
687                     break;
688                 }
689 
690                 if ( bInsert )
691                 {
692                     const sal_uInt16 nPos = aSelectionLB.InsertEntry( *aList[i] );
693                     aSelectionLB.SetEntryData( nPos, reinterpret_cast< void* >( i ) );
694                     if ( nTypeId != TYP_FORMELFLD )
695                         break;
696                 }
697             }
698         }
699     }
700 
701     const sal_Bool bEnable = aSelectionLB.GetEntryCount() != 0;
702     ListBox *pLB = 0;
703 
704     if ( bEnable )
705     {
706         aSelectionLB.SelectEntry( sOldSel );
707         if ( !aSelectionLB.GetSelectEntryCount() )
708         {
709             aSelectionLB.SelectEntryPos( 0 );
710             pLB = &aSelectionLB;	// Alle Controls neu initialisieren
711         }
712     }
713 
714     aSelectionLB.Enable( bEnable );
715     aSelectionFT.Enable( bEnable );
716 
717     SubTypeHdl( pLB );
718     aSelectionLB.SetUpdateMode( sal_True );
719 }
720 
721 /*--------------------------------------------------------------------
722 	Beschreibung:
723  --------------------------------------------------------------------*/
724 
FillFormatLB(sal_uInt16 nTypeId)725 sal_uInt16 SwFldVarPage::FillFormatLB(sal_uInt16 nTypeId)
726 {
727     String sOldSel;
728     const sal_uInt16 nFormatSel = aFormatLB.GetSelectEntryPos();
729     if ( nFormatSel != LISTBOX_ENTRY_NOTFOUND )
730         sOldSel = aFormatLB.GetEntry( nFormatSel );
731 
732     String sOldNumSel;
733     sal_uLong nOldNumFormat = 0;
734     sal_uInt16 nNumFormatSel = aNumFormatLB.GetSelectEntryPos();
735     if ( nNumFormatSel != LISTBOX_ENTRY_NOTFOUND )
736     {
737         sOldNumSel = aNumFormatLB.GetEntry( nNumFormatSel );
738         nOldNumFormat = aNumFormatLB.GetFormat();
739     }
740 
741     // Format-Listbox fuellen
742     aFormatLB.Clear();
743     aNumFormatLB.Clear();
744     bool bSpecialFmt = false;
745 
746     if ( TYP_GETREFPAGEFLD != nTypeId )
747     {
748         if ( GetCurField() != NULL && IsFldEdit() )
749         {
750             bSpecialFmt = GetCurField()->GetFormat() == SAL_MAX_UINT32;
751 
752             if ( !bSpecialFmt )
753             {
754                 aNumFormatLB.SetDefFormat( GetCurField()->GetFormat() );
755                 sOldNumSel = aEmptyStr;
756             }
757             else if ( nTypeId == TYP_GETFLD || nTypeId == TYP_FORMELFLD )
758             {
759                 aNumFormatLB.SetFormatType( NUMBERFORMAT_NUMBER );
760             }
761         }
762         else
763         {
764             if ( nOldNumFormat && nOldNumFormat != ULONG_MAX )
765                 aNumFormatLB.SetDefFormat( nOldNumFormat );
766             else
767                 aNumFormatLB.SetFormatType( NUMBERFORMAT_NUMBER );
768         }
769     }
770 
771     switch ( nTypeId )
772     {
773         case TYP_USERFLD:
774         {
775             if ( !IsFldEdit() || bSpecialFmt )
776             {
777                 sal_uInt16 nPos = aNumFormatLB.InsertEntry( SW_RESSTR( FMT_MARK_TEXT ), 0 );
778                 aNumFormatLB.SetEntryData( nPos, (void *) ULONG_MAX );
779                 nPos = aNumFormatLB.InsertEntry( SW_RESSTR( FMT_USERVAR_CMD ), 1 );
780                 aNumFormatLB.SetEntryData( nPos, (void *) ULONG_MAX );
781             }
782         }
783         break;
784 
785         case TYP_SETFLD:
786         {
787             if ( !IsFldEdit() || bSpecialFmt )
788             {
789                 sal_uInt16 nPos = aNumFormatLB.InsertEntry( SW_RESSTR( FMT_SETVAR_TEXT ), 0 );
790                 aNumFormatLB.SetEntryData( nPos, (void *) ULONG_MAX );
791             }
792         }
793         break;
794 
795         case TYP_FORMELFLD:
796         {
797             sal_uInt16 nPos = aNumFormatLB.InsertEntry( SW_RESSTR( FMT_GETVAR_NAME ), 0 );
798             aNumFormatLB.SetEntryData( nPos, (void *) ULONG_MAX );
799         }
800         break;
801 
802         case TYP_GETFLD:
803         {
804             sal_uInt16 nPos = aNumFormatLB.InsertEntry( SW_RESSTR( FMT_GETVAR_NAME ), 0 );
805             aNumFormatLB.SetEntryData( nPos, (void *) ULONG_MAX );
806         }
807         break;
808     }
809 
810     if ( IsFldEdit() && bSpecialFmt )
811     {
812         if ( nTypeId == TYP_USERFLD && ( GetCurField()->GetSubType() & nsSwExtendedSubType::SUB_CMD ) )
813             aNumFormatLB.SelectEntryPos( 1 );
814         else
815             aNumFormatLB.SelectEntryPos( 0 );
816     }
817     else
818     {
819         if ( !nOldNumFormat && ( nNumFormatSel = aNumFormatLB.GetEntryPos( sOldNumSel ) ) != LISTBOX_ENTRY_NOTFOUND )
820             aNumFormatLB.SelectEntryPos( nNumFormatSel );
821         else if ( nOldNumFormat && nOldNumFormat == ULONG_MAX )
822             aNumFormatLB.SelectEntry( sOldSel );
823     }
824 
825     const sal_uInt16 nSize = GetFldMgr().GetFormatCount(nTypeId, sal_False, IsFldDlgHtmlMode());
826 
827     for ( sal_uInt16 i = 0; i < nSize; i++ )
828     {
829         const sal_uInt16 nPos = aFormatLB.InsertEntry( GetFldMgr().GetFormatStr( nTypeId, i ) );
830         const sal_uInt16 nFldId = GetFldMgr().GetFormatId( nTypeId, i );
831         aFormatLB.SetEntryData( nPos, reinterpret_cast< void* >( nFldId ) );
832         if ( IsFldEdit()
833              && GetCurField() != NULL
834              && nFldId == GetCurField()->GetFormat() )
835         {
836             aFormatLB.SelectEntryPos( nPos );
837         }
838     }
839 
840     if ( nSize && ( !IsFldEdit() || !aFormatLB.GetSelectEntryCount() ) )
841     {
842         aFormatLB.SelectEntry( sOldSel );
843 
844         if ( !aFormatLB.GetSelectEntryCount() )
845         {
846             aFormatLB.SelectEntry( SW_RESSTR( FMT_NUM_PAGEDESC ) );
847             if ( !aFormatLB.GetSelectEntryCount() )
848             {
849                 aFormatLB.SelectEntry( SW_RESSTR( FMT_NUM_ARABIC ) );
850                 if ( !aFormatLB.GetSelectEntryCount() )
851                     aFormatLB.SelectEntryPos( 0 );
852             }
853         }
854     }
855 
856     return nSize;
857 }
858 
859 /*--------------------------------------------------------------------
860 	Beschreibung: Modify
861  --------------------------------------------------------------------*/
862 
IMPL_LINK(SwFldVarPage,ModifyHdl,Edit *,EMPTYARG)863 IMPL_LINK( SwFldVarPage, ModifyHdl, Edit *, EMPTYARG )
864 {
865 	String sValue(aValueED.GetText());
866 	sal_Bool bHasValue = sValue.Len() != 0;
867 	sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
868 	sal_Bool bInsert = sal_False, bApply = sal_False, bDelete = sal_False;
869 
870 	String sName( aNameED.GetText() );
871 	xub_StrLen nLen = sName.Len();
872 
873 	switch( nTypeId )
874 	{
875 	case TYP_DDEFLD:
876 	case TYP_USERFLD:
877 	case TYP_SETFLD:
878 	case TYP_SEQFLD:
879 		SwCalc::IsValidVarName( sName, &sName );
880 		if( sName.Len() != nLen )
881 		{
882 			nLen = sName.Len();
883 			Selection aSel(aNameED.GetSelection());
884 			aNameED.SetText( sName );
885 			aNameED.SetSelection( aSel );	// Cursorpos restaurieren
886 		}
887 		break;
888 	}
889 
890 
891 	// Buttons ueberpruefen
892 	switch (nTypeId)
893 	{
894 	case TYP_DDEFLD:
895 		if( nLen )
896 		{
897 			// Gibts schon einen entsprechenden Type
898 			bInsert = bApply = sal_True;
899 
900 			SwFieldType* pType = GetFldMgr().GetFldType(RES_DDEFLD, sName);
901 
902             SwWrtShell *pSh = GetWrtShell();
903             if(!pSh)
904                 pSh = ::GetActiveWrtShell();
905             if(pSh && pType)
906                 bDelete = !pSh->IsUsed( *pType );
907 		}
908 		break;
909 
910 	case TYP_USERFLD:
911 		if( nLen )
912 		{
913 			// Gibts schon einen entsprechenden Type
914 			SwFieldType* pType = GetFldMgr().GetFldType(RES_USERFLD, sName);
915 
916             SwWrtShell *pSh = GetWrtShell();
917             if(!pSh)
918                 pSh = ::GetActiveWrtShell();
919             if(pSh && pType)
920                 bDelete = !pSh->IsUsed( *pType );
921 
922 			pType = GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
923 			if (!pType)	// Kein Namenskonflikt mit Variablen
924 			{
925 				// Benutzerfelder duerfen auch ohne Inhalt eingefuegt werden!
926 				// Bug #56845
927 				bInsert = bApply = sal_True;
928 			}
929 		}
930 		break;
931 
932 	default:
933 		bInsert = sal_True;
934 
935 		if (nTypeId == TYP_SETFLD || nTypeId == TYP_SEQFLD)
936 		{
937 			SwSetExpFieldType* pFldType = (SwSetExpFieldType*)
938 				GetFldMgr().GetFldType(RES_SETEXPFLD, sName);
939 
940 			if (pFldType)
941 			{
942 
943                 SwWrtShell *pSh = GetWrtShell();
944                 if(!pSh)
945                     pSh = ::GetActiveWrtShell();
946                 if(pSh)
947                 {
948                     const SwFldTypes* p = pSh->GetDoc()->GetFldTypes();
949                     sal_uInt16 i;
950 
951                     for (i = 0; i < INIT_FLDTYPES; i++)
952                     {
953                         SwFieldType* pType = (*p)[ i ];
954                         if (pType == pFldType)
955                             break;
956                     }
957 
958                     if (i >= INIT_FLDTYPES && !pSh->IsUsed(*pFldType))
959                         bDelete = sal_True;
960 
961                     if (nTypeId == TYP_SEQFLD && !(pFldType->GetType() & nsSwGetSetExpType::GSE_SEQ))
962                         bInsert = sal_False;
963 
964                     if (nTypeId == TYP_SETFLD && (pFldType->GetType() & nsSwGetSetExpType::GSE_SEQ))
965                         bInsert = sal_False;
966                 }
967 			}
968 			if (GetFldMgr().GetFldType(RES_USERFLD, sName))
969 				bInsert = sal_False;
970 		}
971 
972 		if( !nLen && ( nTypeId == TYP_SETFLD ||
973 						(!IsFldEdit() && nTypeId == TYP_GETFLD ) ) )
974 			bInsert = sal_False;
975 
976 		if( (nTypeId == TYP_SETFLD || nTypeId == TYP_FORMELFLD) &&
977 			!bHasValue )
978 			bInsert = sal_False;
979 		break;
980 	}
981 
982 	aNewDelTBX.EnableItem(BT_VARAPPLY, bApply);
983 	aNewDelTBX.EnableItem(BT_VARDELETE, bDelete);
984 	EnableInsert(bInsert);
985 
986 	return 0;
987 }
988 
989 /*--------------------------------------------------------------------
990 	Beschreibung:
991  --------------------------------------------------------------------*/
992 
IMPL_LINK(SwFldVarPage,TBClickHdl,ToolBox *,pBox)993 IMPL_LINK( SwFldVarPage, TBClickHdl, ToolBox *, pBox )
994 {
995 	sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
996 
997 	switch (pBox->GetCurItemId())
998 	{
999 		case BT_VARDELETE:
1000 		{
1001 			if( nTypeId == TYP_USERFLD )
1002 				GetFldMgr().RemoveFldType(RES_USERFLD, aSelectionLB.GetSelectEntry());
1003 			else
1004 			{
1005 				sal_uInt16 nWhich;
1006 
1007 				switch(nTypeId)
1008 				{
1009 					case TYP_SETFLD:
1010 					case TYP_SEQFLD:
1011 						nWhich = RES_SETEXPFLD;
1012 						break;
1013 					default:
1014 						nWhich = RES_DDEFLD;
1015 						break;
1016 				}
1017 
1018 				GetFldMgr().RemoveFldType(nWhich, aSelectionLB.GetSelectEntry());
1019 			}
1020 
1021 			UpdateSubType();
1022             SwWrtShell *pSh = GetWrtShell();
1023             if(!pSh)
1024                 pSh = ::GetActiveWrtShell();
1025             if(pSh)
1026             {
1027                 pSh->SetModified();
1028             }
1029 		}
1030 		break;
1031 
1032 		case BT_VARAPPLY:
1033 		{
1034 			String sName(aNameED.GetText()), sValue(aValueED.GetText());
1035 			SwFieldType* pType = 0;
1036             sal_uInt16 nId = 0;
1037 			sal_uInt16 nNumFormatPos = aNumFormatLB.GetSelectEntryPos();
1038 
1039 			switch (nTypeId)
1040 			{
1041 				case TYP_USERFLD:	nId = RES_USERFLD;	break;
1042 				case TYP_DDEFLD:	nId = RES_DDEFLD;	break;
1043 				case TYP_SETFLD:	nId = RES_SETEXPFLD;break;
1044 			}
1045 			pType = GetFldMgr().GetFldType(nId, sName);
1046 
1047 			sal_uLong nFormat = aFormatLB.GetSelectEntryPos();
1048 			if (nFormat != LISTBOX_ENTRY_NOTFOUND)
1049 				nFormat = (sal_uLong)aFormatLB.GetEntryData((sal_uInt16)nFormat);
1050 
1051 			if (pType)	// Aendern
1052 			{
1053                 SwWrtShell *pSh = GetWrtShell();
1054                 if(!pSh)
1055                     pSh = ::GetActiveWrtShell();
1056                 if(pSh)
1057                 {
1058                     pSh->StartAllAction();
1059 
1060                     if (nTypeId == TYP_USERFLD)
1061                     {
1062                         if (nNumFormatPos != LISTBOX_ENTRY_NOTFOUND)
1063                         {
1064                             sal_uLong nFmt = nNumFormatPos == 0 ? 0 : aNumFormatLB.GetFormat();
1065                             if (nFmt)
1066                             {   // Sprache auf Office-Sprache umstellen, da String im Office
1067                                 // Format vom Kalkulator erwartet wird und so in den Dlg
1068                                 // eingegeben werden sollte
1069                                 nFmt = SwValueField::GetSystemFormat(pSh->GetNumberFormatter(), nFmt);
1070                             }
1071                             ((SwUserFieldType*)pType)->SetContent(aValueED.GetText(), nFmt);
1072                             ((SwUserFieldType*)pType)->SetType(
1073                                 nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR );
1074                         }
1075                     }
1076                     else
1077                     {
1078                         if (nFormat != LISTBOX_ENTRY_NOTFOUND)
1079                         {
1080                             //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1081                             //              Namen haben! Wird hier noch nicht beachtet.
1082                             sal_uInt16 nTmpPos = sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1083                             sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1084                             ((SwDDEFieldType*)pType)->SetCmd(sValue);
1085                             ((SwDDEFieldType*)pType)->SetType((sal_uInt16)nFormat);
1086                         }
1087                     }
1088                     pType->UpdateFlds();
1089 
1090                     pSh->EndAllAction();
1091                 }
1092 			}
1093 			else		// Neu
1094 			{
1095 				if(nTypeId == TYP_USERFLD)
1096 				{
1097                     SwWrtShell *pSh = GetWrtShell();
1098                     if(!pSh)
1099                         pSh = ::GetActiveWrtShell();
1100                     if(pSh)
1101                     {
1102                         SwUserFieldType aType( pSh->GetDoc(), sName );
1103 
1104                         if (nNumFormatPos != LISTBOX_ENTRY_NOTFOUND)
1105                         {
1106                             aType.SetType(nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR);
1107                             aType.SetContent( sValue, nNumFormatPos == 0 ? 0 : aNumFormatLB.GetFormat() );
1108                             aSelectionLB.InsertEntry(sName);
1109                             aSelectionLB.SelectEntry(sName);
1110                             GetFldMgr().InsertFldType( aType ); // Userfld Neu
1111                         }
1112                     }
1113 				}
1114 				else
1115 				{
1116 					if (nFormat != LISTBOX_ENTRY_NOTFOUND)
1117 					{
1118 						//JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1119 						//				Namen haben! Wird hier noch nicht beachtet.
1120                         sal_uInt16 nTmpPos = sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1121                         sValue.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1122 
1123 						SwDDEFieldType aType(sName, sValue, (sal_uInt16)nFormat);
1124 						aSelectionLB.InsertEntry(sName);
1125 						aSelectionLB.SelectEntry(sName);
1126 						GetFldMgr().InsertFldType(aType);	// DDE-Feld Neu
1127 					}
1128 				}
1129 			}
1130 			if (IsFldEdit())
1131 				GetFldMgr().GetCurFld();	// FieldManager Updaten
1132 
1133 			UpdateSubType();
1134 		}
1135 		break;
1136 	}
1137 
1138 	return sal_True;
1139 }
1140 
1141 /*--------------------------------------------------------------------
1142 	Beschreibung:
1143  --------------------------------------------------------------------*/
1144 
IMPL_LINK(SwFldVarPage,ChapterHdl,ListBox *,EMPTYARG)1145 IMPL_LINK( SwFldVarPage, ChapterHdl, ListBox *, EMPTYARG )
1146 {
1147 	sal_Bool bEnable = aChapterLevelLB.GetSelectEntryPos() != 0;
1148 
1149 	aSeparatorED.Enable(bEnable);
1150 	aSeparatorFT.Enable(bEnable);
1151 	SeparatorHdl();
1152 
1153 	return 0;
1154 }
1155 
1156 /*--------------------------------------------------------------------
1157 	Beschreibung:
1158  --------------------------------------------------------------------*/
1159 
IMPL_LINK(SwFldVarPage,SeparatorHdl,Edit *,EMPTYARG)1160 IMPL_LINK( SwFldVarPage, SeparatorHdl, Edit *, EMPTYARG )
1161 {
1162 	sal_Bool bEnable = aSeparatorED.GetText().Len() != 0 ||
1163 					aChapterLevelLB.GetSelectEntryPos() == 0;
1164 	EnableInsert(bEnable);
1165 
1166 	return 0;
1167 }
1168 
1169 /*--------------------------------------------------------------------
1170 	Beschreibung:
1171  --------------------------------------------------------------------*/
1172 
FillItemSet(SfxItemSet &)1173 sal_Bool SwFldVarPage::FillItemSet(SfxItemSet& )
1174 {
1175 	sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
1176 
1177 	String aVal(aValueED.GetText());
1178 	String aName(aNameED.GetText());
1179 
1180 	sal_uInt16 nSubType = aSelectionLB.GetSelectEntryPos();
1181 	if(nSubType == LISTBOX_ENTRY_NOTFOUND)
1182 		nSubType = 0;
1183 	else
1184 		nSubType = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nSubType);
1185 
1186 	sal_uLong nFormat;
1187 
1188 	if (!aNumFormatLB.IsVisible())
1189 	{
1190 		nFormat = aFormatLB.GetSelectEntryPos();
1191 
1192 		if(nFormat == LISTBOX_ENTRY_NOTFOUND)
1193 			nFormat = 0;
1194 		else
1195 			nFormat = (sal_uLong)aFormatLB.GetEntryData((sal_uInt16)nFormat);
1196 	}
1197 	else
1198 	{
1199 		nFormat = aNumFormatLB.GetFormat();
1200 
1201 		if (nFormat && nFormat != ULONG_MAX && aNumFormatLB.IsAutomaticLanguage())
1202 		{
1203 			// Sprache auf Office-Sprache umstellen, da String im Office-
1204 			// Format vom Kalkulator erwartet wird und so in den Dlg
1205 			// eingegeben werden sollte
1206             SwWrtShell *pSh = GetWrtShell();
1207             if(!pSh)
1208                 pSh = ::GetActiveWrtShell();
1209             if(pSh)
1210             {
1211                 nFormat = SwValueField::GetSystemFormat(pSh->GetNumberFormatter(), nFormat);
1212             }
1213 		}
1214 	}
1215 	sal_Unicode cSeparator = ' ';
1216 	switch (nTypeId)
1217 	{
1218 		case TYP_USERFLD:
1219 		{
1220 			nSubType = (nFormat == ULONG_MAX) ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR;
1221 
1222 			if (nFormat == ULONG_MAX && aNumFormatLB.GetSelectEntry() == SW_RESSTR(FMT_USERVAR_CMD))
1223 				nSubType |= nsSwExtendedSubType::SUB_CMD;
1224 
1225 			if (aInvisibleCB.IsChecked())
1226 				nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1227 			break;
1228 		}
1229 		case TYP_FORMELFLD:
1230 		{
1231 			nSubType = nsSwGetSetExpType::GSE_FORMULA;
1232 			if (aNumFormatLB.IsVisible() && nFormat == ULONG_MAX)
1233 				nSubType |= nsSwExtendedSubType::SUB_CMD;
1234 			break;
1235 		}
1236 		case TYP_GETFLD:
1237 		{
1238 			nSubType &= 0xff00;
1239 			if (aNumFormatLB.IsVisible() && nFormat == ULONG_MAX)
1240 				nSubType |= nsSwExtendedSubType::SUB_CMD;
1241 			break;
1242 		}
1243 		case TYP_INPUTFLD:
1244 		{
1245 			SwFieldType* pType = GetFldMgr().GetFldType(RES_USERFLD, aName);
1246             nSubType = static_cast< sal_uInt16 >((nSubType & 0xff00) | ((pType) ? INP_USR : INP_VAR));
1247 			break;
1248 		}
1249 
1250 		case TYP_SETFLD:
1251 		{
1252 			if (IsFldDlgHtmlMode())
1253 			{
1254 				nSubType = 0x0100;
1255 				nSubType = (nSubType & 0xff00) | nsSwGetSetExpType::GSE_STRING;
1256 			}
1257 			else
1258 				nSubType = (nSubType & 0xff00) | ((nFormat == ULONG_MAX) ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR);
1259 
1260 			if (aInvisibleCB.IsChecked())
1261 				nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
1262 			break;
1263 		}
1264 		case TYP_SEQFLD:
1265 		{
1266 			// nSubType = nsSwGetSetExpType::GSE_SEQ;	// nsSwGetSetExpType::GSE_SEQ wird im Fldmgr fest gesetzt, kann also entfallen
1267 			nSubType = aChapterLevelLB.GetSelectEntryPos();
1268 			if (nSubType == 0)
1269 				nSubType = 0x7f;
1270 			else
1271 			{
1272 				nSubType--;
1273 				String sSeparator(aSeparatorED.GetText().GetChar(0));
1274 				cSeparator = sSeparator.Len() ? sSeparator.GetChar(0) : ' ';
1275 				//nSubType |= (sal_uInt16)(((sal_uInt8)) << 8);
1276 			}
1277 			break;
1278 		}
1279 		case TYP_GETREFPAGEFLD:
1280 			if( SVX_NUM_CHAR_SPECIAL == nFormat )
1281 				aVal = aValueED.GetText();
1282 			break;
1283 	}
1284 
1285 	if (!IsFldEdit() ||
1286 		aNameED.GetSavedValue() != aNameED.GetText() ||
1287 		aValueED.GetSavedValue() != aValueED.GetText() ||
1288 		aSelectionLB.GetSavedValue() != aSelectionLB.GetSelectEntryPos() ||
1289 		aFormatLB.GetSavedValue() != aFormatLB.GetSelectEntryPos() ||
1290 		nOldFormat != aNumFormatLB.GetFormat() ||
1291 		aInvisibleCB.GetState() != aInvisibleCB.GetSavedValue() ||
1292 		aChapterLevelLB.GetSavedValue() != aChapterLevelLB.GetSelectEntryPos() ||
1293 		aSeparatorED.GetSavedValue() != aSeparatorED.GetText())
1294 	{
1295         InsertFld( nTypeId, nSubType, aName, aVal, nFormat,
1296                     cSeparator, aNumFormatLB.IsAutomaticLanguage() );
1297 	}
1298 
1299 	UpdateSubType();
1300 
1301 	return sal_False;
1302 }
1303 
1304 
1305 /*--------------------------------------------------------------------
1306 	Beschreibung:
1307  --------------------------------------------------------------------*/
1308 
Create(Window * pParent,const SfxItemSet & rAttrSet)1309 SfxTabPage* SwFldVarPage::Create( 	Window* pParent,
1310 						const SfxItemSet& rAttrSet )
1311 {
1312 	return ( new SwFldVarPage( pParent, rAttrSet ) );
1313 }
1314 
1315 /*--------------------------------------------------------------------
1316 	Beschreibung:
1317  --------------------------------------------------------------------*/
1318 
GetGroup()1319 sal_uInt16 SwFldVarPage::GetGroup()
1320 {
1321 	return GRP_VAR;
1322 }
1323 
1324 /*--------------------------------------------------------------------
1325 	Beschreibung:
1326  --------------------------------------------------------------------*/
1327 
SelectionListBox(SwFldVarPage * pDialog,const ResId & rResId)1328 SelectionListBox::SelectionListBox( SwFldVarPage* pDialog, const ResId& rResId ) :
1329 	ListBox	(pDialog, rResId),
1330 	pDlg	(pDialog),
1331 	bCallAddSelection(sal_False)
1332 {
1333 }
1334 
1335 /*--------------------------------------------------------------------
1336 	Beschreibung:
1337  --------------------------------------------------------------------*/
1338 
PreNotify(NotifyEvent & rNEvt)1339 long SelectionListBox::PreNotify( NotifyEvent& rNEvt )
1340 {
1341 	long nHandled = ListBox::PreNotify( rNEvt );
1342 	//sal_Bool bAddSel = sal_False;
1343 	if ( rNEvt.GetType() == EVENT_KEYUP )
1344 	{
1345 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1346 		const KeyCode aKeyCode = pKEvt->GetKeyCode();
1347 		const sal_uInt16 nModifier = aKeyCode.GetModifier();
1348 		if( aKeyCode.GetCode() == KEY_SPACE && !nModifier)
1349 //			bAddSel = sal_True;
1350 			bCallAddSelection = sal_True;
1351 	}
1352 	if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
1353 	{
1354 		const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
1355 
1356 		if (pMEvt && (pMEvt->IsMod1() || pMEvt->IsMod2()))	// Alt oder Ctrl
1357 			//bAddSel = sal_True;
1358 			bCallAddSelection = sal_True;
1359 	}
1360 
1361 //	if (bAddSel)
1362 //		pDlg->AddSelection(this);
1363 
1364 	return nHandled;
1365 }
1366 /* -----------------12.01.99 11:14-------------------
1367  *
1368  * --------------------------------------------------*/
FillUserData()1369 void SwFldVarPage::FillUserData()
1370 {
1371 	String sData(String::CreateFromAscii(USER_DATA_VERSION));
1372 	sData += ';';
1373 	sal_uInt16 nTypeSel = aTypeLB.GetSelectEntryPos();
1374 	if( LISTBOX_ENTRY_NOTFOUND == nTypeSel )
1375 		nTypeSel = USHRT_MAX;
1376 	else
1377 		nTypeSel = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData( nTypeSel );
1378 	sData += String::CreateFromInt32( nTypeSel );
1379 	SetUserData(sData);
1380 }
1381 
1382