xref: /aoo42x/main/sw/source/ui/fldui/fldmgr.cxx (revision 870262e3)
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 
27 #include <cmdid.h>
28 #include <hintids.hxx>
29 #include <svl/stritem.hxx>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/container/XNameAccess.hpp>
32 #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
33 #include <com/sun/star/text/XNumberingTypeInfo.hpp>
34 #include <com/sun/star/style/NumberingType.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/sdbc/XConnection.hpp>
37 #include <com/sun/star/sdbc/XDataSource.hpp>
38 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
39 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
40 #include <comphelper/processfactory.hxx>
41 #include <editeng/unolingu.hxx>
42 #include <unotools/localedatawrapper.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <sfx2/objsh.hxx>
45 #include <sfx2/linkmgr.hxx>
46 #include <sfx2/app.hxx>
47 #include <basic/basmgr.hxx>
48 #include <editeng/langitem.hxx>
49 #include <svl/macitem.hxx>
50 #include <basic/sbmod.hxx>
51 #include <fmtrfmrk.hxx>
52 #include <basic/sbmeth.hxx>
53 #include <basic/sbx.hxx>
54 #include <svl/zforlist.hxx>
55 #include <svl/zformat.hxx>
56 #include <vcl/mnemonic.hxx>
57 #include <view.hxx>
58 #include <wrtsh.hxx>		// Actives Fenster
59 #include <doc.hxx>		// Actives Fenster
60 #include <docsh.hxx>		// Actives Fenster
61 #include <swmodule.hxx>
62 #include <charatr.hxx>
63 #include <fmtinfmt.hxx>
64 #include <cellatr.hxx>
65 #include <dbmgr.hxx>
66 #include <shellres.hxx>
67 #include <fldbas.hxx>
68 #include <docufld.hxx>
69 #include <chpfld.hxx>
70 #include <ddefld.hxx>
71 #include <expfld.hxx>
72 #include <reffld.hxx>
73 #include <usrfld.hxx>
74 #include <dbfld.hxx>
75 #include <authfld.hxx>
76 #include <flddat.hxx>
77 #include <fldmgr.hxx>
78 #include <crsskip.hxx>
79 #include <flddropdown.hxx>
80 #include <fldui.hrc>
81 #include <tox.hxx>
82 
83 using rtl::OUString;
84 using namespace com::sun::star::uno;
85 using namespace com::sun::star::container;
86 using namespace com::sun::star::lang;
87 using namespace com::sun::star::beans;
88 using namespace com::sun::star::text;
89 using namespace com::sun::star::style;
90 using namespace com::sun::star::sdbc;
91 using namespace ::com::sun::star;
92 using namespace nsSwDocInfoSubType;
93 
94 /*--------------------------------------------------------------------
95 	Beschreibung: Gruppen der Felder
96  --------------------------------------------------------------------*/
97 enum
98 {
99 	GRP_DOC_BEGIN	=  0,
100 	GRP_DOC_END   	=  GRP_DOC_BEGIN + 11,
101 
102 	GRP_FKT_BEGIN 	=  GRP_DOC_END,
103     GRP_FKT_END     =  GRP_FKT_BEGIN + 8,
104 
105 	GRP_REF_BEGIN 	=  GRP_FKT_END,
106 	GRP_REF_END   	=  GRP_REF_BEGIN + 2,
107 
108 	GRP_REG_BEGIN 	=  GRP_REF_END,
109 	GRP_REG_END     =  GRP_REG_BEGIN + 1,
110 
111 	GRP_DB_BEGIN  	=  GRP_REG_END,
112 	GRP_DB_END    	=  GRP_DB_BEGIN  + 5,
113 
114 	GRP_VAR_BEGIN 	=  GRP_DB_END,
115 	GRP_VAR_END   	=  GRP_VAR_BEGIN + 9
116 };
117 
118 enum
119 {
120 	GRP_WEB_DOC_BEGIN	=  0,
121 	GRP_WEB_DOC_END   	=  GRP_WEB_DOC_BEGIN + 9,
122 
123 	GRP_WEB_FKT_BEGIN 	=  GRP_WEB_DOC_END + 2,
124 	GRP_WEB_FKT_END   	=  GRP_WEB_FKT_BEGIN + 0,	// Die Gruppe ist leer!
125 
126 	GRP_WEB_REF_BEGIN 	=  GRP_WEB_FKT_END + 6,		// Die Gruppe ist leer!
127 	GRP_WEB_REF_END   	=  GRP_WEB_REF_BEGIN + 0,
128 
129 	GRP_WEB_REG_BEGIN 	=  GRP_WEB_REF_END + 2,
130 	GRP_WEB_REG_END     =  GRP_WEB_REG_BEGIN + 1,
131 
132 	GRP_WEB_DB_BEGIN  	=  GRP_WEB_REG_END,			// Die Gruppe ist leer!
133 	GRP_WEB_DB_END    	=  GRP_WEB_DB_BEGIN  + 0,
134 
135 	GRP_WEB_VAR_BEGIN 	=  GRP_WEB_DB_END + 5,
136 	GRP_WEB_VAR_END   	=  GRP_WEB_VAR_BEGIN + 1
137 };
138 
139 /*--------------------------------------------------------------------
140 	Beschreibung: Formate in der richtigen Reihenfolge
141  --------------------------------------------------------------------*/
142 static const sal_uInt16 __FAR_DATA aSetFmt[] =
143 {
144 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_SETVAR_???
145 // uebereinstimmen
146 	0,
147 	0
148 };
149 
150 static const sal_uInt16 __FAR_DATA aGetFmt[] =
151 {
152 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_GETVAR_???
153 // uebereinstimmen
154 	0
155 };
156 
157 static const sal_uInt16 __FAR_DATA aUsrFmt[] =
158 {
159 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_SETVAR_???
160 // uebereinstimmen
161 	0,
162 	nsSwExtendedSubType::SUB_CMD
163 };
164 
165 static const sal_uInt16 __FAR_DATA aDBFmt[] =
166 {
167 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_DBFLD_???
168 // uebereinstimmen
169 	nsSwExtendedSubType::SUB_OWN_FMT
170 };
171 
172 static const sal_uInt16 VF_COUNT		= sizeof(aGetFmt) / sizeof(sal_uInt16);
173 static const sal_uInt16 VF_USR_COUNT	= sizeof(aUsrFmt) / sizeof(sal_uInt16);
174 static const sal_uInt16 VF_DB_COUNT		= sizeof(aDBFmt)  / sizeof(sal_uInt16);
175 
176 /*--------------------------------------------------------------------
177 	Beschreibung: Feldtypen und Subtypes
178  --------------------------------------------------------------------*/
179 struct SwFldPack
180 {
181 	sal_uInt16  nTypeId;
182 
183 	sal_uInt16	nSubTypeStart;
184 	sal_uInt16  nSubTypeEnd;
185 
186 	sal_uLong	nFmtBegin;
187 	sal_uLong	nFmtEnd;
188 };
189 
190 /*--------------------------------------------------------------------
191 	Beschreibung: Strings und Formate
192  --------------------------------------------------------------------*/
193 static const SwFldPack __FAR_DATA aSwFlds[] =
194 {
195 	// Dokument
196 	{ TYP_EXTUSERFLD,	 	FLD_EU_BEGIN,	 	FLD_EU_END,	    0,     				0 },
197 	{ TYP_AUTHORFLD,	 	0,					0,				FMT_AUTHOR_BEGIN,	FMT_AUTHOR_END },
198 	{ TYP_DATEFLD,			FLD_DATE_BEGIN,		FLD_DATE_END,	0,					0 },
199 	{ TYP_TIMEFLD,			FLD_TIME_BEGIN,		FLD_TIME_END,	0,					0 },
200 	{ TYP_PAGENUMBERFLD,	0,					0,				FMT_NUM_BEGIN,   	FMT_NUM_END-1 },
201 	{ TYP_NEXTPAGEFLD,		0,					0,				FMT_NUM_BEGIN,		FMT_NUM_END },
202 	{ TYP_PREVPAGEFLD,		0,					0,				FMT_NUM_BEGIN,		FMT_NUM_END },
203 	{ TYP_FILENAMEFLD,		0,					0,				FMT_FF_BEGIN,    	FMT_FF_END },
204 	{ TYP_DOCSTATFLD,	 	FLD_STAT_BEGIN,		FLD_STAT_END,	FMT_NUM_BEGIN,		FMT_NUM_END-1 },
205 
206 	{ TYP_CHAPTERFLD,	 	0,					0,				FMT_CHAPTER_BEGIN, 	FMT_CHAPTER_END },
207 	{ TYP_TEMPLNAMEFLD,		0,					0,				FMT_FF_BEGIN,    	FMT_FF_END },
208 
209 	// Funktion
210 	{ TYP_CONDTXTFLD,	 	0,					0,				0,					0 },
211     { TYP_DROPDOWN,       	0,                  0,              0,                  0 },
212 	{ TYP_INPUTFLD,			FLD_INPUT_BEGIN,	FLD_INPUT_END,	0,   				0 },
213 	{ TYP_MACROFLD,			0,					0,				0,					0 },
214 	{ TYP_JUMPEDITFLD, 		0,					0,				FMT_MARK_BEGIN,		FMT_MARK_END },
215 	{ TYP_COMBINED_CHARS,	0,					0,				0,					0 },
216 	{ TYP_HIDDENTXTFLD,		0,					0,				0,					0 },
217 	{ TYP_HIDDENPARAFLD, 	0,			   		0,				0,					0 },
218 
219 	// Referenzen
220 	{ TYP_SETREFFLD,	 	0,					0,				0,					0 },
221 	{ TYP_GETREFFLD,	 	0,					0,				FMT_REF_BEGIN,		FMT_REF_END },
222 
223 	// Ablage
224 	{ TYP_DOCINFOFLD,	 	0,					0,				FMT_REG_BEGIN, 		FMT_REG_END },
225 
226 	// Datenbank
227 	{ TYP_DBFLD,		 	0,					0,				FMT_DBFLD_BEGIN,	FMT_DBFLD_END },
228 	{ TYP_DBNEXTSETFLD,		0,					0,				0,					0 },
229 	{ TYP_DBNUMSETFLD,		0,					0,				0,					0 },
230 	{ TYP_DBSETNUMBERFLD, 	0,					0,				FMT_NUM_BEGIN,	    FMT_NUM_END-2 },
231 	{ TYP_DBNAMEFLD, 	 	0,					0,				0,					0 },
232 
233 	// Variablen
234 	{ TYP_SETFLD,		 	0,					0,				FMT_SETVAR_BEGIN,   FMT_SETVAR_END },
235 
236 	{ TYP_GETFLD,		 	0,					0, 				FMT_GETVAR_BEGIN,	FMT_GETVAR_END },
237 	{ TYP_DDEFLD,		 	0,					0,				FMT_DDE_BEGIN, 		FMT_DDE_END },
238 	{ TYP_FORMELFLD,  		0,					0,				FMT_GETVAR_BEGIN,	FMT_GETVAR_END },
239 	{ TYP_INPUTFLD,			FLD_INPUT_BEGIN,	FLD_INPUT_END,	0,   				0 },
240 	{ TYP_SEQFLD,		 	0,					0,				FMT_NUM_BEGIN,		FMT_NUM_END-2 },
241 	{ TYP_SETREFPAGEFLD,	FLD_PAGEREF_BEGIN,	FLD_PAGEREF_END,0,   				0 },
242 	{ TYP_GETREFPAGEFLD,	0,					0,				FMT_NUM_BEGIN,   	FMT_NUM_END-1 },
243 	{ TYP_USERFLD,			0,					0,				FMT_USERVAR_BEGIN,	FMT_USERVAR_END }
244 };
245 
246 /*--------------------------------------------------------------------
247 	Beschreibung: Zugriff auf die Shell
248  --------------------------------------------------------------------*/
249 
lcl_GetShell()250 static SwWrtShell* lcl_GetShell()
251 {
252 	SwView* pView;
253 	if ( 0 != (pView = ::GetActiveView()) )
254 		return pView->GetWrtShellPtr();
255 	DBG_ERROR("no current shell found!");
256 	return 0;
257 }
258 
GetPackCount()259 inline sal_uInt16 GetPackCount() {	return sizeof(aSwFlds) / sizeof(SwFldPack); }
260 
261 /*--------------------------------------------------------------------
262 	Beschreibung: FieldManager regelt das Einfuegen und Updaten
263 				  von Feldern
264  --------------------------------------------------------------------*/
265 
SwFldMgr(SwWrtShell * pSh)266 SwFldMgr::SwFldMgr(SwWrtShell* pSh ) :
267 	pModule(0),
268 	pMacroItem(0),
269     pWrtShell(pSh),
270     bEvalExp(sal_True)
271 {
272 	// aktuelles Feld ermitteln falls vorhanden
273 	GetCurFld();
274 }
275 
276 
~SwFldMgr()277 SwFldMgr::~SwFldMgr()
278 {
279 }
280 
281 /*--------------------------------------------------------------------
282 	Beschreibung: RefMark ueber Namen organisieren
283  --------------------------------------------------------------------*/
284 
CanInsertRefMark(const String & rStr)285 sal_Bool  SwFldMgr::CanInsertRefMark( const String& rStr )
286 {
287     sal_Bool bRet = sal_False;
288     SwWrtShell *pSh = pWrtShell ? pWrtShell : lcl_GetShell();
289     DBG_ASSERT(pSh, "no SwWrtShell found");
290     if(pSh)
291     {
292         sal_uInt16 nCnt = pSh->GetCrsrCnt();
293 
294         // der letzte Crsr muss keine aufgespannte Selektion
295         if( 1 < nCnt && !pSh->SwCrsrShell::HasSelection() )
296             --nCnt;
297 
298         bRet =  2 > nCnt && 0 == pSh->GetRefMark( rStr );
299     }
300     return bRet;
301 }
302 
303 /*--------------------------------------------------------------------
304 	Beschreibung: Zugriff ueber ResIds
305  --------------------------------------------------------------------*/
306 
RemoveFldType(sal_uInt16 nResId,const String & rName)307 void SwFldMgr::RemoveFldType(sal_uInt16 nResId, const String& rName )
308 {
309     SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell();
310     DBG_ASSERT(pSh, "no SwWrtShell found");
311     if( pSh )
312         pSh->RemoveFldType(nResId, rName);
313 }
314 
GetFldTypeCount(sal_uInt16 nResId) const315 sal_uInt16 SwFldMgr::GetFldTypeCount(sal_uInt16 nResId) const
316 {
317     SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell();
318     DBG_ASSERT(pSh, "no SwWrtShell found");
319     return pSh ? pSh->GetFldTypeCount(nResId) : 0;
320 }
321 
322 
GetFldType(sal_uInt16 nResId,sal_uInt16 nId) const323 SwFieldType* SwFldMgr::GetFldType(sal_uInt16 nResId, sal_uInt16 nId) const
324 {
325     SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell();
326     DBG_ASSERT(pSh, "no SwWrtShell found");
327     return pSh ? pSh->GetFldType(nId, nResId) : 0;
328 }
329 
330 
GetFldType(sal_uInt16 nResId,const String & rName) const331 SwFieldType* SwFldMgr::GetFldType(sal_uInt16 nResId, const String& rName) const
332 {
333     SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell();
334     DBG_ASSERT(pSh, "no SwWrtShell found");
335     return pSh ? pSh->GetFldType(nResId, rName) : 0;
336 }
337 
338 
339 /*--------------------------------------------------------------------
340 	Beschreibung: Aktuelles Feld ermitteln
341  --------------------------------------------------------------------*/
GetCurFld()342 SwField* SwFldMgr::GetCurFld()
343 {
344 	SwWrtShell *pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
345 	if ( pSh )
346 		pCurFld = pSh->GetCurFld( true );
347 	else
348 		pCurFld = NULL;
349 
350 	// Strings und Format initialisieren
351 	//
352 	aCurPar1.Erase();
353 	aCurPar2.Erase();
354 	sCurFrame.Erase();
355 	nCurFmt = 0;
356 
357 	if(!pCurFld)
358 		return 0;
359 
360 	// Aktuelle Werte aufbereiten Parameter 1 und Parameter 2
361 	// als auch das Format ermitteln
362 	//
363 	const sal_uInt16 nTypeId = pCurFld->GetTypeId();
364 
365 	nCurFmt  	= pCurFld->GetFormat();
366 	aCurPar1 	= pCurFld->GetPar1();
367 	aCurPar2 	= pCurFld->GetPar2();
368 
369 	switch( nTypeId )
370 	{
371 		case TYP_PAGENUMBERFLD:
372 		case TYP_NEXTPAGEFLD:
373 		case TYP_PREVPAGEFLD:
374 		case TYP_GETREFPAGEFLD:
375 			if( nCurFmt == SVX_NUM_PAGEDESC )
376 				nCurFmt -= 2;
377 			break;
378 	}
379 	return pCurFld;
380 }
381 
382 /*--------------------------------------------------------------------
383 	Beschreibung: Gruppen-Bereich liefern
384  --------------------------------------------------------------------*/
385 
386 
GetGroupRange(sal_Bool bHtmlMode,sal_uInt16 nGrpId) const387 const SwFldGroupRgn& SwFldMgr::GetGroupRange(sal_Bool bHtmlMode, sal_uInt16 nGrpId) const
388 {
389 static SwFldGroupRgn __READONLY_DATA aRanges[] =
390 {
391 	{ /* Dokument	*/ 	GRP_DOC_BEGIN, 	GRP_DOC_END },
392 	{ /* Funktionen	*/ 	GRP_FKT_BEGIN,  GRP_FKT_END },
393 	{ /* Referenzen	*/ 	GRP_REF_BEGIN,  GRP_REF_END },
394 	{ /* Ablage		*/ 	GRP_REG_BEGIN,  GRP_REG_END },
395 	{ /* DB			*/	GRP_DB_BEGIN,	GRP_DB_END },
396 	{ /* User		*/	GRP_VAR_BEGIN,	GRP_VAR_END }
397 };
398 static SwFldGroupRgn __READONLY_DATA aWebRanges[] =
399 {
400 	{ /* Dokument	*/ 	GRP_WEB_DOC_BEGIN, 	GRP_WEB_DOC_END },
401 	{ /* Funktionen	*/ 	GRP_WEB_FKT_BEGIN,  GRP_WEB_FKT_END },
402 	{ /* Referenzen	*/ 	GRP_WEB_REF_BEGIN,  GRP_WEB_REF_END },
403 	{ /* Ablage		*/ 	GRP_WEB_REG_BEGIN,  GRP_WEB_REG_END },
404 	{ /* DB			*/	GRP_WEB_DB_BEGIN,	GRP_WEB_DB_END },
405 	{ /* User		*/	GRP_WEB_VAR_BEGIN,	GRP_WEB_VAR_END }
406 };
407 
408 	if (bHtmlMode)
409 		return aWebRanges[(sal_uInt16)nGrpId];
410 	else
411 		return aRanges[(sal_uInt16)nGrpId];
412 }
413 
414 /*--------------------------------------------------------------------
415 	Beschreibung: GroupId bestimmen
416  --------------------------------------------------------------------*/
417 
GetGroup(sal_Bool bHtmlMode,sal_uInt16 nTypeId,sal_uInt16 nSubType) const418 sal_uInt16 SwFldMgr::GetGroup(sal_Bool bHtmlMode, sal_uInt16 nTypeId, sal_uInt16 nSubType) const
419 {
420 	if (nTypeId == TYP_SETINPFLD)
421 		nTypeId = TYP_SETFLD;
422 
423 	if (nTypeId == TYP_INPUTFLD && (nSubType & INP_USR))
424 		nTypeId = TYP_USERFLD;
425 
426 	if (nTypeId == TYP_FIXDATEFLD)
427 		nTypeId = TYP_DATEFLD;
428 
429 	if (nTypeId == TYP_FIXTIMEFLD)
430 		nTypeId = TYP_TIMEFLD;
431 
432 	for (sal_uInt16 i = GRP_DOC; i <= GRP_VAR; i++)
433 	{
434 		const SwFldGroupRgn& rRange = GetGroupRange(bHtmlMode, i);
435 		for (sal_uInt16 nPos = rRange.nStart; nPos < rRange.nEnd; nPos++)
436 		{
437 			if (aSwFlds[nPos].nTypeId == nTypeId)
438 				return i;
439 		}
440 	}
441 	return USHRT_MAX;
442 }
443 
444 /*--------------------------------------------------------------------
445 	Beschreibung: Namen zur TypeId ermitteln
446 				  ZUGRIFF ueber TYP_....
447  --------------------------------------------------------------------*/
448 
449 
GetTypeId(sal_uInt16 nPos)450 sal_uInt16 SwFldMgr::GetTypeId(sal_uInt16 nPos)
451 {
452 	ASSERT(nPos < ::GetPackCount(), "unzulaessige Pos");
453 	return aSwFlds[ nPos ].nTypeId;
454 }
455 
456 
GetTypeStr(sal_uInt16 nPos)457 const String& SwFldMgr::GetTypeStr(sal_uInt16 nPos)
458 {
459 	ASSERT(nPos < ::GetPackCount(), "unzulaessige TypeId");
460 
461 	sal_uInt16 nFldWh = aSwFlds[ nPos ].nTypeId;
462 
463 	// Sonderbehandlung fuer Datum/Zeit Felder (ohne var/fix)
464 	if( TYP_DATEFLD == nFldWh )
465 	{
466 		static String g_aDate( SW_RES( STR_DATEFLD ) );
467 		return g_aDate;
468 	}
469 	if( TYP_TIMEFLD == nFldWh )
470 	{
471 		static String g_aTime( SW_RES( STR_TIMEFLD ) );
472 		return g_aTime;
473 	}
474 
475 	return SwFieldType::GetTypeStr( nFldWh );
476 }
477 
478 /*--------------------------------------------------------------------
479 	Beschreibung: Pos in der Liste bestimmen
480  --------------------------------------------------------------------*/
481 
482 
GetPos(sal_uInt16 nTypeId)483 sal_uInt16 SwFldMgr::GetPos(sal_uInt16 nTypeId)
484 {
485 	switch( nTypeId )
486 	{
487 		case TYP_FIXDATEFLD:		nTypeId = TYP_DATEFLD;		break;
488 		case TYP_FIXTIMEFLD:      	nTypeId = TYP_TIMEFLD;		break;
489 		case TYP_SETINPFLD:      	nTypeId = TYP_SETFLD;		break;
490 		case TYP_USRINPFLD:      	nTypeId = TYP_USERFLD;		break;
491 	}
492 
493 	for(sal_uInt16 i = 0; i < GetPackCount(); i++)
494 		if(aSwFlds[i].nTypeId == nTypeId)
495 			return i;
496 
497 	return USHRT_MAX;
498 }
499 
500 /*--------------------------------------------------------------------
501 	Beschreibung: Subtypen eines Feldes lokalisieren
502  --------------------------------------------------------------------*/
503 
GetSubTypes(sal_uInt16 nTypeId,SvStringsDtor & rToFill)504 sal_Bool SwFldMgr::GetSubTypes(sal_uInt16 nTypeId, SvStringsDtor& rToFill)
505 {
506     sal_Bool bRet = sal_False;
507     SwWrtShell *pSh = pWrtShell ? pWrtShell : lcl_GetShell();
508     DBG_ASSERT(pSh, "no SwWrtShell found");
509     if(pSh)
510     {
511         const sal_uInt16 nPos = GetPos(nTypeId);
512 
513         switch(nTypeId)
514         {
515             case TYP_SETREFFLD:
516             case TYP_GETREFFLD:
517             {
518                 // Referenzen sind keine Felder
519                 pSh->GetRefMarks( &rToFill );
520                 break;
521             }
522             case TYP_MACROFLD:
523             {
524                 break;
525             }
526             case TYP_INPUTFLD:
527             {   String* pNew = new SW_RESSTR(aSwFlds[nPos].nSubTypeStart);
528                 rToFill.Insert(pNew, rToFill.Count());
529                 // Weiter bei generischen Typen
530             }
531             case TYP_DDEFLD:
532             case TYP_SEQFLD:
533             case TYP_FORMELFLD:
534             case TYP_GETFLD:
535             case TYP_SETFLD:
536             case TYP_USERFLD:
537             {
538 
539                 const sal_uInt16 nCount = pSh->GetFldTypeCount();
540                 for(sal_uInt16 i = 0; i < nCount; ++i)
541                 {
542                     SwFieldType* pFldType = pSh->GetFldType( i );
543                     const sal_uInt16 nWhich = pFldType->Which();
544 
545                     if((nTypeId == TYP_DDEFLD && pFldType->Which() == RES_DDEFLD) ||
546 
547                        (nTypeId == TYP_USERFLD && nWhich == RES_USERFLD) ||
548 
549                        (nTypeId == TYP_GETFLD && nWhich == RES_SETEXPFLD &&
550                         !(((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ)) ||
551 
552                        (nTypeId == TYP_SETFLD && nWhich == RES_SETEXPFLD &&
553                         !(((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ)) ||
554 
555                        (nTypeId == TYP_SEQFLD && nWhich == RES_SETEXPFLD  &&
556                        (((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ)) ||
557 
558                        ((nTypeId == TYP_INPUTFLD || nTypeId == TYP_FORMELFLD) &&
559                          (nWhich == RES_USERFLD ||
560                           (nWhich == RES_SETEXPFLD &&
561                           !(((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ))) ) )
562                     {
563                         String* pNew = new String(pFldType->GetName());
564                         rToFill.Insert(pNew, rToFill.Count());
565                     }
566                 }
567                 break;
568             }
569             case TYP_DBNEXTSETFLD:
570             case TYP_DBNUMSETFLD:
571             case TYP_DBNAMEFLD:
572             case TYP_DBSETNUMBERFLD:
573                 break;
574 
575             default:
576             {
577                 // statische SubTypes
578                 if(nPos != USHRT_MAX)
579                 {
580                     sal_uInt16 nCount;
581                     if (nTypeId == TYP_DOCINFOFLD)
582                         nCount = DI_SUBTYPE_END - DI_SUBTYPE_BEGIN;
583                     else
584                         nCount = aSwFlds[nPos].nSubTypeEnd - aSwFlds[nPos].nSubTypeStart;
585 
586                     for(sal_uInt16 i = 0; i < nCount; ++i)
587                     {
588                         String* pNew;
589                         if (nTypeId == TYP_DOCINFOFLD)
590                         {
591                             if ( i == DI_CUSTOM )
592                                 pNew = new String( String(SW_RES( STR_CUSTOM )) );
593 							else
594                                 pNew = new String(*ViewShell::GetShellRes()->aDocInfoLst[i]);
595                         }
596                         else
597                             pNew = new SW_RESSTR(aSwFlds[nPos].nSubTypeStart + i);
598 
599                         rToFill.Insert(pNew, rToFill.Count());
600                     }
601                 }
602             }
603         }
604         bRet = sal_True;
605     }
606     return bRet;
607 }
608 
609 /*--------------------------------------------------------------------
610 	Beschreibung: Format ermitteln
611 				  ZUGRIFF ueber TYP_....
612  --------------------------------------------------------------------*/
613 
614 
GetFormatCount(sal_uInt16 nTypeId,sal_Bool bIsText,sal_Bool bHtmlMode) const615 sal_uInt16 SwFldMgr::GetFormatCount(sal_uInt16 nTypeId, sal_Bool bIsText, sal_Bool bHtmlMode) const
616 {
617 	ASSERT(nTypeId < TYP_END, "unzulaessige TypeId");
618 
619 	{
620 		const sal_uInt16 nPos = GetPos(nTypeId);
621 
622 		if(nPos == USHRT_MAX || (bHtmlMode && nTypeId == TYP_SETFLD))
623 			return 0;
624 
625 		sal_uLong nStart = aSwFlds[nPos].nFmtBegin;
626 		sal_uLong nEnd   = aSwFlds[nPos].nFmtEnd;
627 
628 		if (bIsText && nEnd - nStart >= 2)
629 			return 2;
630 
631 		if (nTypeId == TYP_FILENAMEFLD)
632 			nEnd -= 2;	// Kein Bereich oder Vorlage
633 
634 		switch(nStart)
635 		{
636 			case FMT_GETVAR_BEGIN:
637 			case FMT_SETVAR_BEGIN:	return VF_COUNT;
638 			case FMT_USERVAR_BEGIN:	return VF_USR_COUNT;
639 			case FMT_DBFLD_BEGIN:	return VF_DB_COUNT;
640 			case FMT_NUM_BEGIN:
641 			{
642 				sal_uInt16 nCount = (sal_uInt16)(nEnd - nStart);
643 				GetNumberingInfo();
644                 if(xNumberingInfo.is())
645 				{
646 					Sequence<sal_Int16> aTypes = xNumberingInfo->getSupportedNumberingTypes();
647 					const sal_Int16* pTypes = aTypes.getConstArray();
648 					for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
649 					{
650 						sal_Int16 nCurrent = pTypes[nType];
651 						//skip all values below or equal to CHARS_LOWER_LETTER_N
652 						if(nCurrent > NumberingType::CHARS_LOWER_LETTER_N)
653 						{
654                             // #i28073# it's not necessarily a sorted sequence
655                             ++nCount;
656 						}
657 					}
658 				}
659 				return nCount;
660 			}
661 
662 		}
663 		return (sal_uInt16)(nEnd - nStart);
664 	}
665 }
666 
667 /*--------------------------------------------------------------------
668 	Beschreibung:	FormatString zu einem Typ ermitteln
669  --------------------------------------------------------------------*/
670 
671 
GetFormatStr(sal_uInt16 nTypeId,sal_uLong nFormatId) const672 String SwFldMgr::GetFormatStr(sal_uInt16 nTypeId, sal_uLong nFormatId) const
673 {
674 	String aRet;
675 	ASSERT(nTypeId < TYP_END, "unzulaessige TypeId");
676 
677 	const sal_uInt16 nPos = GetPos(nTypeId);
678 
679 	if(nPos == USHRT_MAX)
680 		return aRet;
681 
682 	sal_uLong nStart;
683 
684 	nStart = aSwFlds[nPos].nFmtBegin;
685 
686 	if (TYP_AUTHORFLD == nTypeId|| TYP_FILENAMEFLD == nTypeId)
687 		nFormatId &= ~FF_FIXED;		// Fixed-Flag ausmaskieren
688 
689 	if((nStart + nFormatId) < aSwFlds[nPos].nFmtEnd)
690 		aRet = SW_RESSTR((sal_uInt16)(nStart + nFormatId));
691 	else if( FMT_NUM_BEGIN == nStart)
692 	{
693 		if(xNumberingInfo.is())
694 		{
695 			Sequence<sal_Int16> aTypes = xNumberingInfo->getSupportedNumberingTypes();
696 			const sal_Int16* pTypes = aTypes.getConstArray();
697             sal_Int32 nOffset = aSwFlds[nPos].nFmtEnd - nStart;
698             sal_Int32 nValidEntry = 0;
699             for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
700 			{
701 				sal_Int16 nCurrent = pTypes[nType];
702 				if(nCurrent > NumberingType::CHARS_LOWER_LETTER_N)
703 				{
704                     if(nValidEntry == ((sal_Int32)nFormatId) - nOffset)
705                     {
706                         aRet = xNumberingInfo->getNumberingIdentifier( pTypes[nType] );
707                         break;
708                     }
709                     ++nValidEntry;
710 				}
711 			}
712 		}
713 	}
714 
715 	return aRet;
716 }
717 
718 /*--------------------------------------------------------------------
719 	Beschreibung:	FormatId aus Pseudo-ID ermitteln
720  --------------------------------------------------------------------*/
721 
GetFormatId(sal_uInt16 nTypeId,sal_uLong nFormatId) const722 sal_uInt16 SwFldMgr::GetFormatId(sal_uInt16 nTypeId, sal_uLong nFormatId) const
723 {
724 	sal_uInt16 nId = (sal_uInt16)nFormatId;
725 
726 	switch( nTypeId )
727 	{
728 	case TYP_DOCINFOFLD:
729 		switch( aSwFlds[ GetPos( nTypeId ) ].nFmtBegin + nFormatId )
730 		{
731 		case FMT_REG_AUTHOR:	nId = DI_SUB_AUTHOR;	break;
732 		case FMT_REG_TIME:		nId = DI_SUB_TIME;		break;
733 		case FMT_REG_DATE:		nId = DI_SUB_DATE;		break;
734 		}
735 		break;
736 
737 	case TYP_PAGENUMBERFLD:
738 	case TYP_NEXTPAGEFLD:
739 	case TYP_PREVPAGEFLD:
740 	case TYP_DOCSTATFLD:
741 	case TYP_DBSETNUMBERFLD:
742 	case TYP_SEQFLD:
743 	case TYP_GETREFPAGEFLD:
744 	{
745 		sal_uInt16 nPos = GetPos( nTypeId );
746 		sal_uLong nBegin = aSwFlds[ nPos ].nFmtBegin;
747 		sal_uLong nEnd = aSwFlds[nPos].nFmtEnd;
748 		if((nBegin + nFormatId) < nEnd)
749 		{
750 			switch( nBegin + nFormatId )
751 			{
752 			case FMT_NUM_ABC:				nId = SVX_NUM_CHARS_UPPER_LETTER;	break;
753 			case FMT_NUM_SABC:				nId = SVX_NUM_CHARS_LOWER_LETTER;	break;
754 			case FMT_NUM_ROMAN:             nId = SVX_NUM_ROMAN_UPPER;			break;
755 			case FMT_NUM_SROMAN:			nId = SVX_NUM_ROMAN_LOWER;			break;
756 			case FMT_NUM_ARABIC:            nId = SVX_NUM_ARABIC;				break;
757 			case FMT_NUM_PAGEDESC: 			nId = SVX_NUM_PAGEDESC; 			break;
758 			case FMT_NUM_PAGESPECIAL:		nId = SVX_NUM_CHAR_SPECIAL;			break;
759 			case FMT_NUM_ABC_N:				nId = SVX_NUM_CHARS_UPPER_LETTER_N; break;
760 			case FMT_NUM_SABC_N:			nId = SVX_NUM_CHARS_LOWER_LETTER_N;	break;
761 			}
762 		}
763 		else if(xNumberingInfo.is())
764 		{
765 			Sequence<sal_Int16> aTypes = xNumberingInfo->getSupportedNumberingTypes();
766 			const sal_Int16* pTypes = aTypes.getConstArray();
767             sal_Int32 nOffset = nEnd - nBegin;
768             sal_Int32 nValidEntry = 0;
769             for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
770             {
771                 sal_Int16 nCurrent = pTypes[nType];
772                 if(nCurrent > NumberingType::CHARS_LOWER_LETTER_N)
773                 {
774                     if(nValidEntry == ((sal_Int32)nFormatId) - nOffset)
775                     {
776                         nId = pTypes[nType];
777                         break;
778                     }
779                     ++nValidEntry;
780                 }
781             }
782         }
783 	}
784 	break;
785 	case TYP_DDEFLD:
786 		switch ( aSwFlds[ GetPos( nTypeId ) ].nFmtBegin + nFormatId )
787 		{
788         case FMT_DDE_NORMAL:    nId = sfx2::LINKUPDATE_ONCALL; break;
789         case FMT_DDE_HOT:       nId = sfx2::LINKUPDATE_ALWAYS; break;
790 		}
791 		break;
792 	}
793 
794 	return nId;
795 
796 }
797 
798 /*--------------------------------------------------------------------
799 	Beschreibung: Traveling
800  --------------------------------------------------------------------*/
801 
802 
GoNextPrev(sal_Bool bNext,SwFieldType * pTyp)803 sal_Bool SwFldMgr::GoNextPrev( sal_Bool bNext, SwFieldType* pTyp )
804 {
805 	SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
806     if(!pSh)
807         return sal_False;
808 
809 	if( !pTyp && pCurFld )
810 	{
811 		const sal_uInt16 nTypeId = pCurFld->GetTypeId();
812 		if( TYP_SETINPFLD == nTypeId || TYP_USRINPFLD == nTypeId )
813 			pTyp = pSh->GetFldType( 0, RES_INPUTFLD );
814 		else
815 			pTyp = pCurFld->GetTyp();
816 	}
817 
818 	if (pTyp && pTyp->Which() == RES_DBFLD)
819 	{
820 		// Fuer Feldbefehl-bearbeiten (alle DB-Felder anspringen)
821 		return pSh->MoveFldType( 0, (bNext ? true : false), RES_DBFLD );
822 	}
823 
824     return (pTyp && pSh)
825            ? pSh->MoveFldType( pTyp, (bNext ? true : false) )
826            : sal_False;
827 }
828 
829 /*--------------------------------------------------------------------
830 	Beschreibung: Feldtypen einfuegen
831  --------------------------------------------------------------------*/
832 
833 
InsertFldType(SwFieldType & rType)834 void SwFldMgr::InsertFldType(SwFieldType& rType)
835 {
836     SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
837     DBG_ASSERT(pSh, "no SwWrtShell found");
838     if(pSh)
839         pSh->InsertFldType(rType);
840 }
841 
842 /*--------------------------------------------------------------------
843 	Beschreibung: Aktuelle TypeId ermitteln
844  --------------------------------------------------------------------*/
845 
846 
GetCurTypeId() const847 sal_uInt16 SwFldMgr::GetCurTypeId() const
848 {
849     return pCurFld ? pCurFld->GetTypeId() : USHRT_MAX;
850 }
851 
852 /*--------------------------------------------------------------------
853 	Beschreibung: Ueber String  Feld einfuegen oder Update
854  --------------------------------------------------------------------*/
855 
856 
InsertFld(const SwInsertFld_Data & rData)857 sal_Bool SwFldMgr::InsertFld(
858     const SwInsertFld_Data& rData )
859 {
860     SwField* pFld   = 0;
861     sal_Bool bExp = sal_False;
862     sal_Bool bTbl = sal_False;
863     sal_Bool bPageVar = sal_False;
864     sal_uLong nFormatId = rData.nFormatId;
865     sal_uInt16 nSubType = rData.nSubType;
866     sal_Unicode cSeparator = rData.cSeparator;
867     SwWrtShell* pCurShell = rData.pSh;
868     if(!pCurShell)
869         pCurShell = pWrtShell ? pWrtShell : ::lcl_GetShell();
870     DBG_ASSERT(pCurShell, "no SwWrtShell found");
871     if(!pCurShell)
872         return sal_False;
873 
874     switch(rData.nTypeId)
875     {
876     case TYP_POSTITFLD:
877         {
878             SwPostItFieldType* pType = (SwPostItFieldType*)pCurShell->GetFldType(0, RES_POSTITFLD);
879             SwPostItField* pPostItField =
880                 new SwPostItField(
881                     pType,
882                     rData.sPar2, // content
883                     rData.sPar1, // author
884                     aEmptyStr, // author's initials
885                     aEmptyStr, // name
886                     DateTime() );
887             pFld = pPostItField;
888         }
889         break;
890 
891     case TYP_SCRIPTFLD:
892         {
893             SwScriptFieldType* pType =
894                 (SwScriptFieldType*)pCurShell->GetFldType(0, RES_SCRIPTFLD);
895             pFld = new SwScriptField(pType, rData.sPar1, rData.sPar2, (sal_Bool)nFormatId);
896             break;
897         }
898 
899     case TYP_COMBINED_CHARS:
900         {
901             SwCombinedCharFieldType* pType = (SwCombinedCharFieldType*)
902                 pCurShell->GetFldType( 0, RES_COMBINED_CHARS );
903             pFld = new SwCombinedCharField( pType, rData.sPar1 );
904         }
905         break;
906 
907     case TYP_AUTHORITY:
908         {
909             SwAuthorityFieldType* pType =
910                 (SwAuthorityFieldType*)pCurShell->GetFldType(0, RES_AUTHORITY);
911             if(!pType)
912             {
913                 pType =
914                     (SwAuthorityFieldType*)pCurShell->InsertFldType(
915                     SwAuthorityFieldType(pCurShell->GetDoc()));
916             }
917             pFld = new SwAuthorityField(pType, rData.sPar1);
918         }
919         break;
920 
921     case TYP_DATEFLD:
922     case TYP_TIMEFLD:
923         {
924             sal_uInt16 nSub = static_cast< sal_uInt16 >(rData.nTypeId == TYP_DATEFLD ? DATEFLD : TIMEFLD);
925             nSub |= nSubType == DATE_VAR ? 0 : FIXEDFLD;
926 
927             SwDateTimeFieldType* pTyp =
928                 (SwDateTimeFieldType*)pCurShell->GetFldType(0, RES_DATETIMEFLD);
929             pFld = new SwDateTimeField(pTyp, nSub, nFormatId);
930             pFld->SetPar2(rData.sPar2);
931             break;
932         }
933 
934     case TYP_FILENAMEFLD:
935         {
936             SwFileNameFieldType* pTyp =
937                 (SwFileNameFieldType*)pCurShell->GetFldType(0, RES_FILENAMEFLD);
938             pFld = new SwFileNameField(pTyp, nFormatId);
939             break;
940         }
941 
942     case TYP_TEMPLNAMEFLD:
943         {
944             SwTemplNameFieldType* pTyp =
945                 (SwTemplNameFieldType*)pCurShell->GetFldType(0, RES_TEMPLNAMEFLD);
946             pFld = new SwTemplNameField(pTyp, nFormatId);
947             break;
948         }
949 
950     case TYP_CHAPTERFLD:
951         {
952             sal_uInt16 nByte = (sal_uInt16)rData.sPar2.ToInt32();
953             SwChapterFieldType* pTyp =
954                 (SwChapterFieldType*)pCurShell->GetFldType(0, RES_CHAPTERFLD);
955             pFld = new SwChapterField(pTyp, nFormatId);
956             nByte = Max(sal_uInt16(1), nByte);
957             nByte = Min(nByte, sal_uInt16(MAXLEVEL));
958             nByte -= 1;
959             ((SwChapterField*)pFld)->SetLevel((sal_uInt8)nByte);
960             break;
961         }
962 
963     case TYP_NEXTPAGEFLD:
964     case TYP_PREVPAGEFLD:
965     case TYP_PAGENUMBERFLD:
966         {
967             short nOff  = (short)rData.sPar2.ToInt32();
968 
969             if(rData.nTypeId == TYP_NEXTPAGEFLD)
970             {
971                 if( SVX_NUM_CHAR_SPECIAL == nFormatId )
972                     nOff = 1;
973                 else
974                     nOff += 1;
975                 nSubType = PG_NEXT;
976             }
977             else if(rData.nTypeId == TYP_PREVPAGEFLD)
978             {
979                 if( SVX_NUM_CHAR_SPECIAL == nFormatId )
980                     nOff = -1;
981                 else
982                     nOff -= 1;
983                 nSubType =  PG_PREV;
984             }
985             else
986                 nSubType = PG_RANDOM;
987 
988             SwPageNumberFieldType* pTyp =
989                 (SwPageNumberFieldType*)pCurShell->GetFldType(0, RES_PAGENUMBERFLD);
990             pFld = new SwPageNumberField(pTyp, nSubType, nFormatId, nOff);
991 
992             if( SVX_NUM_CHAR_SPECIAL == nFormatId &&
993                 ( PG_PREV == nSubType || PG_NEXT == nSubType ) )
994                 ((SwPageNumberField*)pFld)->SetUserString( rData.sPar2 );
995             break;
996         }
997 
998     case TYP_DOCSTATFLD:
999         {
1000             SwDocStatFieldType* pTyp =
1001                 (SwDocStatFieldType*)pCurShell->GetFldType(0, RES_DOCSTATFLD);
1002             pFld = new SwDocStatField(pTyp, nSubType, nFormatId);
1003             break;
1004         }
1005 
1006     case TYP_AUTHORFLD:
1007         {
1008             SwAuthorFieldType* pTyp =
1009                 (SwAuthorFieldType*)pCurShell->GetFldType(0, RES_AUTHORFLD);
1010             pFld = new SwAuthorField(pTyp, nFormatId);
1011             break;
1012         }
1013 
1014     case TYP_CONDTXTFLD:
1015     case TYP_HIDDENTXTFLD:
1016         {
1017             SwHiddenTxtFieldType* pTyp =
1018                 (SwHiddenTxtFieldType*)pCurShell->GetFldType(0, RES_HIDDENTXTFLD);
1019             pFld = new SwHiddenTxtField(pTyp, sal_True, rData.sPar1, rData.sPar2, sal_False, rData.nTypeId);
1020             bExp = sal_True;
1021             break;
1022         }
1023 
1024     case TYP_HIDDENPARAFLD:
1025         {
1026             SwHiddenParaFieldType* pTyp =
1027                 (SwHiddenParaFieldType*)pCurShell->GetFldType(0, RES_HIDDENPARAFLD);
1028             pFld = new SwHiddenParaField(pTyp, rData.sPar1);
1029             bExp = sal_True;
1030             break;
1031         }
1032 
1033     case TYP_SETREFFLD:
1034         {
1035             if( rData.sPar1.Len() > 0 && CanInsertRefMark( rData.sPar1 ) )
1036             {
1037                 pCurShell->SetAttrItem( SwFmtRefMark( rData.sPar1 ) );
1038                 return sal_True;
1039             }
1040             return sal_False;
1041         }
1042 
1043     case TYP_GETREFFLD:
1044         {
1045             SwGetRefFieldType* pTyp =
1046                 (SwGetRefFieldType*)pCurShell->GetFldType(0, RES_GETREFFLD);
1047             sal_uInt16 nSeqNo = (sal_uInt16)rData.sPar2.ToInt32();
1048             pFld = new SwGetRefField(pTyp, rData.sPar1, nSubType, nSeqNo, nFormatId);
1049             bExp = sal_True;
1050             break;
1051         }
1052 
1053     case TYP_DDEFLD:
1054         {
1055             //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1056             //				Namen haben! Wird hier noch nicht beachtet.
1057             String sCmd( rData.sPar2 );
1058             sal_uInt16 nTmpPos = sCmd.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1059             sCmd.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1060 
1061             SwDDEFieldType aType( rData.sPar1, sCmd, (sal_uInt16) nFormatId );
1062             SwDDEFieldType* pTyp = (SwDDEFieldType*) pCurShell->InsertFldType( aType );
1063             pFld = new SwDDEField( pTyp );
1064             break;
1065         }
1066 
1067     case TYP_MACROFLD:
1068         {
1069             SwMacroFieldType* pTyp =
1070                 (SwMacroFieldType*)pCurShell->GetFldType(0, RES_MACROFLD);
1071 
1072             pFld = new SwMacroField(pTyp, rData.sPar1, rData.sPar2);
1073 
1074             break;
1075         }
1076 
1077     case TYP_INTERNETFLD:
1078         {
1079             SwFmtINetFmt aFmt( rData.sPar1, sCurFrame );
1080             if( pMacroItem )
1081                 aFmt.SetMacroTbl( &pMacroItem->GetMacroTable() );
1082             return pCurShell->InsertURL( aFmt, rData.sPar2 );
1083         }
1084 
1085     case TYP_JUMPEDITFLD:
1086         {
1087             SwJumpEditFieldType* pTyp =
1088                 (SwJumpEditFieldType*)pCurShell->GetFldType(0, RES_JUMPEDITFLD);
1089 
1090             pFld = new SwJumpEditField(pTyp, nFormatId, rData.sPar1, rData.sPar2 );
1091             break;
1092         }
1093 
1094     case TYP_DOCINFOFLD:
1095         {
1096             SwDocInfoFieldType* pTyp = (SwDocInfoFieldType*)pCurShell->GetFldType(
1097                 0, RES_DOCINFOFLD );
1098             pFld = new SwDocInfoField(pTyp, nSubType, rData.sPar1, nFormatId);
1099             break;
1100         }
1101 
1102     case TYP_EXTUSERFLD:
1103         {
1104             SwExtUserFieldType* pTyp = (SwExtUserFieldType*)pCurShell->GetFldType(
1105                 0, RES_EXTUSERFLD);
1106             pFld = new SwExtUserField(pTyp, nSubType, nFormatId);
1107             break;
1108         }
1109 
1110     case TYP_DBFLD:
1111         {
1112             SwDBData aDBData;
1113             String sPar1;
1114 
1115             if (rData.sPar1.Search(DB_DELIM) == STRING_NOTFOUND)
1116             {
1117                 aDBData = pCurShell->GetDBData();
1118                 sPar1 = rData.sPar1;
1119             }
1120             else
1121             {
1122                 aDBData.sDataSource = rData.sPar1.GetToken(0, DB_DELIM);
1123                 aDBData.sCommand = rData.sPar1.GetToken(1, DB_DELIM);
1124                 aDBData.nCommandType = rData.sPar1.GetToken(2, DB_DELIM).ToInt32();
1125                 sPar1 = rData.sPar1.GetToken(3, DB_DELIM);
1126             }
1127 
1128             if(aDBData.sDataSource.getLength() && pCurShell->GetDBData() != aDBData)
1129                 pCurShell->ChgDBData(aDBData);
1130 
1131             SwDBFieldType* pTyp = (SwDBFieldType*)pCurShell->InsertFldType(
1132                 SwDBFieldType(pCurShell->GetDoc(), sPar1, aDBData) );
1133             pFld = new SwDBField(pTyp);
1134             pFld->SetSubType(nSubType);
1135 
1136             if( !(nSubType & nsSwExtendedSubType::SUB_OWN_FMT) ) // Datenbankformat ermitteln
1137             {
1138                 Reference< XDataSource> xSource;
1139                 rData.aDBDataSource >>= xSource;
1140                 Reference<XConnection> xConnection;
1141                 rData.aDBConnection >>= xConnection;
1142                 Reference<XPropertySet> xColumn;
1143                 rData.aDBColumn >>= xColumn;
1144                 if(xColumn.is())
1145                 {
1146                     nFormatId = pCurShell->GetNewDBMgr()->GetColumnFmt(xSource, xConnection, xColumn,
1147                         pCurShell->GetNumberFormatter(), GetCurrLanguage() );
1148                 }
1149                 else
1150                     nFormatId = pCurShell->GetNewDBMgr()->GetColumnFmt(
1151                     aDBData.sDataSource, aDBData.sCommand, sPar1,
1152                     pCurShell->GetNumberFormatter(), GetCurrLanguage() );
1153             }
1154             pFld->ChangeFormat( nFormatId );
1155 
1156             bExp = sal_True;
1157             break;
1158         }
1159 
1160     case TYP_DBSETNUMBERFLD:
1161     case TYP_DBNUMSETFLD:
1162     case TYP_DBNEXTSETFLD:
1163     case TYP_DBNAMEFLD:
1164         {
1165             sal_uInt16 nPos, nTablePos, nCmdTypePos, nExpPos;
1166             String sPar1;
1167             SwDBData aDBData;
1168 
1169             // DBName aus rData.sPar1 extrahieren. Format: DBName.TableName.CommandType.ExpStrg
1170             if ((nTablePos = rData.sPar1.Search(DB_DELIM)) != STRING_NOTFOUND)
1171                 aDBData.sDataSource = rData.sPar1.Copy(0, nTablePos++);
1172             if ((nCmdTypePos = rData.sPar1.Search(DB_DELIM, nTablePos)) != STRING_NOTFOUND)
1173             {
1174                 aDBData.sCommand = rData.sPar1.Copy(nTablePos, nCmdTypePos++ - nTablePos);
1175             }
1176             if ((nExpPos = rData.sPar1.Search(DB_DELIM, nCmdTypePos)) != STRING_NOTFOUND)
1177             {
1178                 aDBData.nCommandType = rData.sPar1.Copy(nCmdTypePos, nExpPos++ - nCmdTypePos).ToInt32();
1179             }
1180             if (nExpPos != STRING_NOTFOUND)
1181                 nPos = nExpPos;
1182             else if (nTablePos != STRING_NOTFOUND)
1183                 nPos = nTablePos;
1184             else
1185                 nPos = 0;
1186             sPar1 = rData.sPar1.Copy(nPos);
1187 
1188             if (aDBData.sDataSource.getLength() && pCurShell->GetDBData() != aDBData)
1189                 pCurShell->ChgDBData(aDBData);
1190 
1191             switch(rData.nTypeId)
1192             {
1193             case TYP_DBNAMEFLD:
1194                 {
1195                     SwDBNameFieldType* pTyp =
1196                         (SwDBNameFieldType*)pCurShell->GetFldType(0, RES_DBNAMEFLD);
1197                     pFld = new SwDBNameField(pTyp, aDBData);
1198 
1199                     break;
1200                 }
1201             case TYP_DBNEXTSETFLD:
1202                 {
1203                     SwDBNextSetFieldType* pTyp = (SwDBNextSetFieldType*)pCurShell->GetFldType(
1204                         0, RES_DBNEXTSETFLD);
1205                     pFld = new SwDBNextSetField(pTyp, sPar1, rData.sPar2, aDBData);
1206                     bExp = sal_True;
1207                     break;
1208                 }
1209             case TYP_DBNUMSETFLD:
1210                 {
1211                     SwDBNumSetFieldType* pTyp = (SwDBNumSetFieldType*)pCurShell->GetFldType(
1212                         0, RES_DBNUMSETFLD);
1213                     pFld = new SwDBNumSetField( pTyp, sPar1, rData.sPar2, aDBData);
1214                     bExp = sal_True;
1215                     break;
1216                 }
1217             case TYP_DBSETNUMBERFLD:
1218                 {
1219                     SwDBSetNumberFieldType* pTyp = (SwDBSetNumberFieldType*)
1220                         pCurShell->GetFldType(0, RES_DBSETNUMBERFLD);
1221                     pFld = new SwDBSetNumberField( pTyp, aDBData, nFormatId);
1222                     bExp = sal_True;
1223                     break;
1224                 }
1225             }
1226             break;
1227         }
1228 
1229     case TYP_USERFLD:
1230         {
1231             SwUserFieldType* pTyp =
1232                 (SwUserFieldType*)pCurShell->GetFldType(RES_USERFLD, rData.sPar1);
1233 
1234             // nur wenn vorhanden
1235             if(!pTyp)
1236             {
1237                 pTyp = (SwUserFieldType*)pCurShell->InsertFldType(
1238                     SwUserFieldType(pCurShell->GetDoc(), rData.sPar1));
1239             }
1240             if (pTyp->GetContent(nFormatId) != rData.sPar2)
1241                 pTyp->SetContent(rData.sPar2, nFormatId);
1242             pFld = new SwUserField(pTyp, 0, nFormatId);
1243             if (pFld->GetSubType() != nSubType)
1244                 pFld->SetSubType(nSubType);
1245             bTbl = sal_True;
1246             break;
1247         }
1248 
1249     case TYP_INPUTFLD:
1250         {
1251             if ((nSubType & 0x00ff) == INP_VAR)
1252             {
1253                 SwSetExpFieldType* pTyp = (SwSetExpFieldType*)
1254                     pCurShell->GetFldType(RES_SETEXPFLD, rData.sPar1);
1255 
1256                 // kein Experssion Type mit dem Namen vorhanden -> anlegen
1257                 if(pTyp)
1258                 {
1259                     SwSetExpField* pExpFld =
1260                         new SwSetExpField(pTyp, aEmptyStr, nFormatId);
1261 
1262                     // Typ vom SwSetExpFieldType nicht veraendern:
1263                     sal_uInt16 nOldSubType = pExpFld->GetSubType();
1264                     pExpFld->SetSubType(nOldSubType | (nSubType & 0xff00));
1265 
1266                     pExpFld->SetPromptText(rData.sPar2);
1267                     pExpFld->SetInputFlag(sal_True) ;
1268                     bExp = sal_True;
1269                     pFld = pExpFld;
1270                 }
1271                 else
1272                     return sal_False;
1273             }
1274             else
1275             {
1276                 SwInputFieldType* pTyp =
1277                     (SwInputFieldType*)pCurShell->GetFldType(0, RES_INPUTFLD);
1278 
1279                 SwInputField* pInpFld =
1280                     new SwInputField( pTyp, rData.sPar1, rData.sPar2, nSubType|nsSwExtendedSubType::SUB_INVISIBLE, nFormatId);
1281                 pFld = pInpFld;
1282             }
1283 
1284             // Dialog starten
1285             //
1286             pCurShell->StartInputFldDlg(pFld, sal_False, rData.pParent);
1287             break;
1288         }
1289 
1290     case TYP_SETFLD:
1291         {
1292             if (!rData.sPar2.Len())   // Leere Variablen sind nicht erlaubt
1293                 return sal_False;
1294 
1295             SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pCurShell->InsertFldType(
1296                 SwSetExpFieldType(pCurShell->GetDoc(), rData.sPar1) );
1297 
1298             SwSetExpField* pExpFld = new SwSetExpField( pTyp, rData.sPar2, nFormatId);
1299             pExpFld->SetSubType(nSubType);
1300             pExpFld->SetPar2(rData.sPar2);
1301             bExp = sal_True;
1302             pFld = pExpFld;
1303             break;
1304         }
1305 
1306     case TYP_SEQFLD:
1307         {
1308             SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pCurShell->InsertFldType(
1309                 SwSetExpFieldType(pCurShell->GetDoc(), rData.sPar1, nsSwGetSetExpType::GSE_SEQ));
1310 
1311             sal_uInt8 nLevel = static_cast< sal_uInt8 >(nSubType & 0xff);
1312 
1313             pTyp->SetOutlineLvl(nLevel);
1314             if (nLevel != 0x7f && cSeparator == 0)
1315                 cSeparator = '.';
1316 
1317             pTyp->SetDelimiter(cSeparator);
1318             SwSetExpField* pExpFld = new SwSetExpField(pTyp, rData.sPar2, nFormatId);
1319             bExp = sal_True;
1320             pFld = pExpFld;
1321             nSubType = nsSwGetSetExpType::GSE_SEQ;
1322             break;
1323         }
1324 
1325     case TYP_GETFLD:
1326         {
1327             // gibt es ein entprechendes SetField
1328             SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
1329                 pCurShell->GetFldType(RES_SETEXPFLD, rData.sPar1);
1330 
1331             if(pSetTyp)
1332             {
1333                 SwGetExpFieldType* pTyp = (SwGetExpFieldType*)pCurShell->GetFldType(
1334                     0, RES_GETEXPFLD);
1335                 pFld = new SwGetExpField(pTyp, rData.sPar1, pSetTyp->GetType(), nFormatId);
1336                 pFld->SetSubType(nSubType | pSetTyp->GetType());
1337                 bExp = sal_True;
1338             }
1339             else
1340                 return sal_False;
1341             break;
1342         }
1343 
1344     case TYP_FORMELFLD:
1345         {
1346             if(pCurShell->GetFrmType(0,sal_False) & FRMTYPE_TABLE)
1347             {
1348                 pCurShell->StartAllAction();
1349 
1350                 SvNumberFormatter* pFormatter = pCurShell->GetDoc()->GetNumberFormatter();
1351                 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormatId);
1352 
1353                 if (pEntry)
1354                 {
1355                     SfxStringItem aFormat(FN_NUMBER_FORMAT, pEntry->GetFormatstring());
1356                     pCurShell->GetView().GetViewFrame()->GetDispatcher()->
1357                         Execute(FN_NUMBER_FORMAT, SFX_CALLMODE_SYNCHRON, &aFormat, 0L);
1358                 }
1359 
1360                 SfxItemSet aBoxSet( pCurShell->GetAttrPool(),
1361                     RES_BOXATR_FORMULA, RES_BOXATR_FORMULA );
1362 
1363                 String sFml( rData.sPar2 );
1364                 if( sFml.EraseLeadingChars().Len() &&
1365                     '=' == sFml.GetChar( 0 ) )
1366                     sFml.Erase( 0, 1 );
1367 
1368                 aBoxSet.Put( SwTblBoxFormula( sFml ));
1369                 pCurShell->SetTblBoxFormulaAttrs( aBoxSet );
1370                 pCurShell->UpdateTable();
1371 
1372                 pCurShell->EndAllAction();
1373                 return sal_True;
1374 
1375                 /*				// In der Tabelle Tabellenformeln einfuegen
1376                 SwTblFieldType* pTyp = (SwTblFieldType*)pCurShell->GetFldType(
1377                 0, RES_TABLEFLD);
1378                 pFld = new SwTblField(pTyp, rData.sPar2, nsSwGetSetExpType::GSE_EXPR, nFormatId);
1379                 bTbl = sal_True;*/
1380             }
1381             else
1382             {
1383                 SwGetExpFieldType* pTyp = (SwGetExpFieldType*)
1384                     pCurShell->GetFldType(0, RES_GETEXPFLD);
1385                 pFld = new SwGetExpField(pTyp, rData.sPar2, nsSwGetSetExpType::GSE_FORMULA, nFormatId);
1386                 pFld->SetSubType(nSubType);
1387                 bExp = sal_True;
1388             }
1389             break;
1390         }
1391 
1392     case TYP_SETREFPAGEFLD:
1393         pFld = new SwRefPageSetField( (SwRefPageSetFieldType*)
1394             pCurShell->GetFldType( 0, RES_REFPAGESETFLD ),
1395             (short)rData.sPar2.ToInt32(), 0 != nSubType  );
1396         bPageVar = sal_True;
1397         break;
1398 
1399     case TYP_GETREFPAGEFLD:
1400         pFld = new SwRefPageGetField( (SwRefPageGetFieldType*)
1401             pCurShell->GetFldType( 0, RES_REFPAGEGETFLD ), nFormatId );
1402         bPageVar = sal_True;
1403         break;
1404 
1405     case TYP_DROPDOWN :
1406         {
1407             pFld = new SwDropDownField(pCurShell->GetFldType( 0, RES_DROPDOWN ));
1408             xub_StrLen nTokenCount = rData.sPar2.Len() ? rData.sPar2.GetTokenCount(DB_DELIM) : 0;
1409             Sequence<OUString> aEntries(nTokenCount);
1410             OUString* pArray = aEntries.getArray();
1411             for(xub_StrLen nToken = 0; nToken < nTokenCount; nToken++)
1412                 pArray[nToken] = rData.sPar2.GetToken(nToken, DB_DELIM);
1413             ((SwDropDownField*)pFld)->SetItems(aEntries);
1414             ((SwDropDownField*)pFld)->SetName(rData.sPar1);
1415         }
1416         break;
1417 
1418     default:
1419         {
1420             ASSERT(sal_False, "Wrong field type");
1421             return sal_False;
1422         }
1423     }
1424     ASSERT(pFld, "Feld nicht vorhanden");
1425 
1426 
1427     //the auto language flag has to be set prior to the language!
1428     pFld->SetAutomaticLanguage(rData.bIsAutomaticLanguage);
1429     sal_uInt16 nLang = GetCurrLanguage();
1430     pFld->SetLanguage(nLang);
1431 
1432     // Einfuegen
1433     pCurShell->StartAllAction();
1434 
1435     pCurShell->Insert( *pFld );
1436 
1437     if(bExp && bEvalExp)
1438         pCurShell->UpdateExpFlds(sal_True);
1439 
1440     if(bTbl)
1441     {
1442         pCurShell->Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
1443         pCurShell->UpdateFlds(*pFld);
1444         pCurShell->Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
1445     }
1446     else if( bPageVar )
1447         ((SwRefPageGetFieldType*)pCurShell->GetFldType( 0, RES_REFPAGEGETFLD ))->UpdateFlds();
1448     else if( TYP_GETREFFLD == rData.nTypeId )
1449         pFld->GetTyp()->ModifyNotification( 0, 0 );
1450 
1451     // temporaeres Feld loeschen
1452     delete pFld;
1453 
1454     pCurShell->EndAllAction();
1455     return sal_True;
1456 }
1457 
1458 /*--------------------------------------------------------------------
1459 	Beschreibung: Felder Update
1460  --------------------------------------------------------------------*/
1461 
1462 
UpdateCurFld(sal_uLong nFormat,const String & rPar1,const String & rPar2,SwField * _pTmpFld)1463 void SwFldMgr::UpdateCurFld(sal_uLong nFormat,
1464 							const String& rPar1,
1465 							const String& rPar2,
1466                             SwField * _pTmpFld) // #111840#
1467 {
1468 	// Format aendern
1469 	ASSERT(pCurFld, "kein Feld an der CursorPos");
1470 
1471     bool bDelete = false;
1472     SwField *pTmpFld;		// mb: fixed memory leak
1473     if (NULL != _pTmpFld)
1474     {
1475         pTmpFld = _pTmpFld;
1476     }
1477     else
1478     {
1479         pTmpFld = pCurFld->CopyField();
1480         bDelete = true;
1481     }
1482 
1483 	SwFieldType* pType   = pTmpFld->GetTyp();
1484 	const sal_uInt16 nTypeId = pTmpFld->GetTypeId();
1485 
1486     SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
1487     DBG_ASSERT(pSh, "no SwWrtShell found");
1488     if(!pSh)
1489         return;
1490     pSh->StartAllAction();
1491 
1492 	sal_Bool bSetPar2 = sal_True;
1493 	sal_Bool bSetPar1 = sal_True;
1494 	String sPar1( rPar1 );
1495 	String sPar2( rPar2 );
1496 
1497 	// Order to Format
1498 	switch( nTypeId )
1499 	{
1500 		case TYP_DDEFLD:
1501 		{
1502 			//JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1503 			//				Namen haben! Wird hier noch nicht beachtet.
1504             sal_uInt16 nTmpPos = sPar2.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1505             sPar2.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1506 			break;
1507 		}
1508 
1509 		case TYP_CHAPTERFLD:
1510 		{
1511             sal_uInt16 nByte = (sal_uInt16)rPar2.ToInt32();
1512 			nByte = Max(sal_uInt16(1), nByte);
1513 			nByte = Min(nByte, sal_uInt16(MAXLEVEL));
1514 			nByte -= 1;
1515 			((SwChapterField*)pTmpFld)->SetLevel((sal_uInt8)nByte);
1516 			bSetPar2 = sal_False;
1517 			break;
1518 		}
1519 
1520 		case TYP_SCRIPTFLD:
1521 			((SwScriptField*)pTmpFld)->SetCodeURL((sal_Bool)nFormat);
1522 			break;
1523 
1524 		case TYP_NEXTPAGEFLD:
1525 			if( SVX_NUM_CHAR_SPECIAL == nFormat )
1526 			{
1527 				((SwPageNumberField*)pCurFld)->SetUserString( sPar2 );
1528 				sPar2 = '1';
1529 			}
1530 			else
1531 			{
1532 				if( nFormat + 2 == SVX_NUM_PAGEDESC )
1533 					nFormat = SVX_NUM_PAGEDESC;
1534                 short nOff = (short)sPar2.ToInt32();
1535 				nOff += 1;
1536 				sPar2 = String::CreateFromInt32(nOff);
1537 			}
1538 			break;
1539 
1540 		case TYP_PREVPAGEFLD:
1541 			if( SVX_NUM_CHAR_SPECIAL == nFormat )
1542 			{
1543 				((SwPageNumberField*)pCurFld)->SetUserString( sPar2 );
1544 				sPar2 = String::CreateFromAscii(
1545                     RTL_CONSTASCII_STRINGPARAM("-1"));
1546 			}
1547 			else
1548 			{
1549 				if( nFormat + 2 == SVX_NUM_PAGEDESC )
1550 					nFormat = SVX_NUM_PAGEDESC;
1551                 short nOff = (short)sPar2.ToInt32();
1552 				nOff -= 1;
1553 				sPar2 = String::CreateFromInt32(nOff);
1554 			}
1555 			break;
1556 
1557 		case TYP_PAGENUMBERFLD:
1558 		case TYP_GETREFPAGEFLD:
1559 			if( nFormat + 2 == SVX_NUM_PAGEDESC )
1560 				nFormat = SVX_NUM_PAGEDESC;
1561 			break;
1562 
1563 		case TYP_GETREFFLD:
1564 			{
1565 				bSetPar2 = sal_False;
1566                 ((SwGetRefField*)pTmpFld)->SetSubType( (sal_uInt16)rPar2.ToInt32() );
1567 				sal_uInt16 nPos = rPar2.Search( '|' );
1568 				if( STRING_NOTFOUND != nPos )
1569                     ((SwGetRefField*)pTmpFld)->SetSeqNo( (sal_uInt16)rPar2.Copy( nPos + 1 ).ToInt32());
1570 			}
1571 			break;
1572 		case TYP_DROPDOWN:
1573 		{
1574             xub_StrLen nTokenCount = sPar2.Len() ? sPar2.GetTokenCount(DB_DELIM) : 0;
1575             Sequence<OUString> aEntries(nTokenCount);
1576             OUString* pArray = aEntries.getArray();
1577             for(xub_StrLen nToken = 0; nToken < nTokenCount; nToken++)
1578                 pArray[nToken] = sPar2.GetToken(nToken, DB_DELIM);
1579             ((SwDropDownField*)pTmpFld)->SetItems(aEntries);
1580             ((SwDropDownField*)pTmpFld)->SetName(sPar1);
1581 			bSetPar1 = bSetPar2 = sal_False;
1582 		}
1583 		break;
1584         case TYP_AUTHORITY :
1585         {
1586             //#i99069# changes to a bibliography field should change the field type
1587             SwAuthorityField* pAuthorityField = static_cast<SwAuthorityField*>(pTmpFld);
1588             SwAuthorityFieldType* pAuthorityType = static_cast<SwAuthorityFieldType*>(pType);
1589             SwAuthEntry aTempEntry;
1590             for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i )
1591                 aTempEntry.SetAuthorField( (ToxAuthorityField)i,
1592                                 rPar1.GetToken( i, TOX_STYLE_DELIMITER ));
1593             if( pAuthorityType->ChangeEntryContent( &aTempEntry ) )
1594             {
1595                 pType->UpdateFlds();
1596                 pSh->SetModified();
1597             }
1598 
1599             if( aTempEntry.GetAuthorField( AUTH_FIELD_IDENTIFIER ) ==
1600                 pAuthorityField->GetFieldText( AUTH_FIELD_IDENTIFIER ) )
1601                 bSetPar1 = sal_False; //otherwise it's a new or changed entry, the field needs to be updated
1602             bSetPar2 = sal_False;
1603         }
1604         break;
1605 	}
1606 
1607 	// Format setzen
1608 	// Format wegen NumberFormatter vor SetPar2 einstellen!
1609 	pTmpFld->ChangeFormat(nFormat);
1610 
1611 	if(bSetPar1)
1612 		pTmpFld->SetPar1( sPar1 );
1613 	if( bSetPar2 )
1614 		pTmpFld->SetPar2( sPar2 );
1615 
1616 	// Update anschmeissen
1617 	if(nTypeId == TYP_DDEFLD ||
1618 	   nTypeId == TYP_USERFLD ||
1619 	   nTypeId == TYP_USRINPFLD)
1620 	{
1621 		pType->UpdateFlds();
1622         pSh->SetModified();
1623 	}
1624 	else {
1625 		// mb: #32157
1626         pSh->SwEditShell::UpdateFlds(*pTmpFld);
1627 		GetCurFld();
1628 	}
1629 
1630     if (bDelete)
1631         delete pTmpFld;
1632 
1633     pSh->EndAllAction();
1634 }
1635 
1636 /*--------------------------------------------------------------------
1637 	Beschreibung: ExpressionFields explizit evaluieren
1638  --------------------------------------------------------------------*/
EvalExpFlds(SwWrtShell * pSh)1639 void SwFldMgr::EvalExpFlds(SwWrtShell* pSh)
1640 {
1641 	if (pSh == NULL)
1642 		pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
1643 
1644 	if(pSh)
1645 	{
1646 		pSh->StartAllAction();
1647 		pSh->UpdateExpFlds(sal_True);
1648 		pSh->EndAllAction();
1649 	}
1650 }
GetCurrLanguage() const1651 sal_uInt16 SwFldMgr::GetCurrLanguage() const
1652 {
1653 	SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
1654 	if( pSh )
1655 		return pSh->GetCurLang();
1656 	return SvxLocaleToLanguage( SvtSysLocale().GetLocaleData().getLocale() );
1657 }
1658 
_GetFldName()1659 void SwFieldType::_GetFldName()
1660 {
1661 	// mba: this is an awful mess; a fix is available, but too much for 3.4 -> applay plaster
1662 	static const sal_uInt16 coFldCnt = 43;
1663 
1664 	static sal_uInt16 __READONLY_DATA coFldNms[ coFldCnt ] = {
1665 		FLD_DATE_STD,
1666 		FLD_TIME_STD,
1667 		STR_FILENAMEFLD,
1668 		STR_DBNAMEFLD,
1669 		STR_CHAPTERFLD,
1670 		STR_PAGENUMBERFLD,
1671 		STR_DOCSTATFLD,
1672 		STR_AUTHORFLD,
1673 		STR_SETFLD,
1674 		STR_GETFLD,
1675 		STR_FORMELFLD,
1676 		STR_HIDDENTXTFLD,
1677 		STR_SETREFFLD,
1678 		STR_GETREFFLD,
1679 		STR_DDEFLD,
1680 		STR_MACROFLD,
1681 		STR_INPUTFLD,
1682 		STR_HIDDENPARAFLD,
1683 		STR_DOCINFOFLD,
1684 		STR_DBFLD,
1685 		STR_USERFLD,
1686 		STR_POSTITFLD,
1687 		STR_TEMPLNAMEFLD,
1688 		STR_SEQFLD,
1689 		STR_DBNEXTSETFLD,
1690 		STR_DBNUMSETFLD,
1691 		STR_DBSETNUMBERFLD,
1692 		STR_CONDTXTFLD,
1693 		STR_NEXTPAGEFLD,
1694 		STR_PREVPAGEFLD,
1695 		STR_EXTUSERFLD,
1696 		FLD_DATE_FIX,
1697 		FLD_TIME_FIX,
1698 		STR_SETINPUTFLD,
1699 		STR_USRINPUTFLD,
1700 		STR_SETREFPAGEFLD,
1701 		STR_GETREFPAGEFLD,
1702 		STR_INTERNETFLD,
1703 		STR_JUMPEDITFLD,
1704 		STR_SCRIPTFLD,
1705 		STR_AUTHORITY,
1706         STR_COMBINED_CHARS,
1707         STR_DROPDOWN
1708 	};
1709 
1710 	// Infos fuer Felder einfuegen
1711 	SwFieldType::pFldNames = new SvStringsDtor( (sal_uInt8)coFldCnt, 2 );
1712 	for( sal_uInt16 nIdx = 0; nIdx < coFldCnt; ++nIdx )
1713 	{
1714 		String* pTmp = new SW_RESSTR( coFldNms[ nIdx ] );
1715         pTmp->Assign( MnemonicGenerator::EraseAllMnemonicChars( *pTmp ) );
1716 		SwFieldType::pFldNames->Insert(pTmp, nIdx );
1717 	}
1718 }
1719 
1720 /*--------------------------------------------------------------------
1721 	Beschreibung:
1722  --------------------------------------------------------------------*/
1723 
ChooseMacro(const String &)1724 sal_Bool SwFldMgr::ChooseMacro(const String&)
1725 {
1726     sal_Bool bRet = sal_False;
1727 
1728     // choose script dialog
1729     ::rtl::OUString aScriptURL = SfxApplication::ChooseScript();
1730 
1731     // the script selector dialog returns a valid script URL
1732     if ( aScriptURL.getLength() != 0 )
1733     {
1734         SetMacroPath( aScriptURL );
1735         bRet = sal_True;
1736     }
1737 
1738     return bRet;
1739 }
1740 
SetMacroPath(const String & rPath)1741 void SwFldMgr::SetMacroPath(const String& rPath)
1742 {
1743     sMacroPath = rPath;
1744     sMacroName = rPath;
1745 
1746     // try to set sMacroName member variable by parsing the macro path
1747     // using the new URI parsing services
1748 
1749     Reference< XMultiServiceFactory > xSMgr =
1750         ::comphelper::getProcessServiceFactory();
1751 
1752     Reference< uri::XUriReferenceFactory >
1753         xFactory( xSMgr->createInstance(
1754             ::rtl::OUString::createFromAscii(
1755                 "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY );
1756 
1757     if ( xFactory.is() )
1758     {
1759         Reference< uri::XVndSunStarScriptUrl >
1760             xUrl( xFactory->parse( sMacroPath ), UNO_QUERY );
1761 
1762         if ( xUrl.is() )
1763         {
1764             sMacroName = xUrl->getName();
1765         }
1766     }
1767 }
1768 
1769 /*--------------------------------------------------------------------
1770 	Beschreibung:
1771  --------------------------------------------------------------------*/
1772 
GetDefaultFormat(sal_uInt16 nTypeId,sal_Bool bIsText,SvNumberFormatter * pFormatter,double * pVal)1773 sal_uLong SwFldMgr::GetDefaultFormat(sal_uInt16 nTypeId, sal_Bool bIsText, SvNumberFormatter* pFormatter, double* pVal)
1774 {
1775 	double fValue;
1776 	short  nDefFormat;
1777 
1778 	switch (nTypeId)
1779 	{
1780 		case TYP_TIMEFLD:
1781 		case TYP_DATEFLD:
1782 		{
1783 			Date aDate;
1784 			Date* pNullDate = pFormatter->GetNullDate();
1785 
1786 			fValue = aDate - *pNullDate;
1787 
1788 			Time aTime;
1789 
1790 			sal_uLong nNumFmtTime = (sal_uLong)aTime.GetSec() + (sal_uLong)aTime.GetMin() * 60L +
1791 						  (sal_uLong)aTime.GetHour() * 3600L;
1792 
1793 			fValue += (double)nNumFmtTime / 86400.0;
1794 
1795 			nDefFormat = (nTypeId == TYP_DATEFLD) ? NUMBERFORMAT_DATE : NUMBERFORMAT_TIME;
1796 		}
1797 		break;
1798 
1799 		default:
1800 			if (bIsText)
1801 			{
1802 				fValue = 0.0;
1803 				nDefFormat = NUMBERFORMAT_TEXT;
1804 			}
1805 			else
1806 			{
1807 				fValue = 0.0;
1808 				nDefFormat = NUMBERFORMAT_ALL;
1809 			}
1810 			break;
1811 	}
1812 
1813 	if (pVal)
1814 		*pVal = fValue;
1815 
1816 	return pFormatter->GetStandardFormat(nDefFormat, GetCurrLanguage());
1817 }
1818 
1819 /* -----------------------------01.03.01 16:46--------------------------------
1820 
1821  ---------------------------------------------------------------------------*/
GetNumberingInfo() const1822 Reference<XNumberingTypeInfo> SwFldMgr::GetNumberingInfo() const
1823 {
1824 	if(!xNumberingInfo.is())
1825 	{
1826 		Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
1827 		Reference < XInterface > xI = xMSF->createInstance(
1828 			::rtl::OUString::createFromAscii(
1829 							"com.sun.star.text.DefaultNumberingProvider" ));
1830 		Reference<XDefaultNumberingProvider> xDefNum(xI, UNO_QUERY);
1831 		DBG_ASSERT(xDefNum.is(), "service missing: \"com.sun.star.text.DefaultNumberingProvider\"");
1832 		((SwFldMgr*)this)->xNumberingInfo = Reference<XNumberingTypeInfo>(xDefNum, UNO_QUERY);
1833 	}
1834 	return xNumberingInfo;
1835 }
1836