xref: /trunk/main/sw/source/ui/fldui/fldmgr.cxx (revision 3b32dd21b48084cc91e8cdf23382ce990aee2296)
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 
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 
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 
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 
277 SwFldMgr::~SwFldMgr()
278 {
279 }
280 
281 /*--------------------------------------------------------------------
282     Beschreibung: RefMark ueber Namen organisieren
283  --------------------------------------------------------------------*/
284 
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 
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 
315 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 
323 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 
331 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  --------------------------------------------------------------------*/
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 
387 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 
418 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 
450 sal_uInt16 SwFldMgr::GetTypeId(sal_uInt16 nPos)
451 {
452     ASSERT(nPos < ::GetPackCount(), "unzulaessige Pos");
453     return aSwFlds[ nPos ].nTypeId;
454 }
455 
456 
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 
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 
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 
615 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 
672 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 
722 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 
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 
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 
847 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 
857 sal_Bool SwFldMgr::InsertFld(
858     const SwInsertFld_Data& rData,
859     const SwPaM *pPam )
860 {
861     SwField* pFld   = 0;
862     sal_Bool bExp = sal_False;
863     sal_Bool bTbl = sal_False;
864     sal_Bool bPageVar = sal_False;
865     sal_uLong nFormatId = rData.nFormatId;
866     sal_uInt16 nSubType = rData.nSubType;
867     sal_Unicode cSeparator = rData.cSeparator;
868     SwWrtShell* pCurShell = rData.pSh;
869     if(!pCurShell)
870         pCurShell = pWrtShell ? pWrtShell : ::lcl_GetShell();
871     DBG_ASSERT(pCurShell, "no SwWrtShell found");
872     if(!pCurShell)
873         return sal_False;
874 
875     switch(rData.nTypeId)
876     {
877     case TYP_POSTITFLD:
878         {
879             SwPostItFieldType* pType = (SwPostItFieldType*)pCurShell->GetFldType(0, RES_POSTITFLD);
880             pFld = new SwPostItField(
881                 pType,
882                 rData.sPar2, // content
883                 rData.sPar1, // author
884                 aEmptyStr, // author's initials
885                 aEmptyStr, // name
886                 DateTime() );
887             break;
888         }
889 
890         case TYP_SCRIPTFLD:
891         {
892             SwScriptFieldType* pType =
893                 (SwScriptFieldType*)pCurShell->GetFldType(0, RES_SCRIPTFLD);
894             pFld = new SwScriptField(pType, rData.sPar1, rData.sPar2, (sal_Bool)nFormatId);
895             break;
896         }
897         case TYP_COMBINED_CHARS:
898         {
899             SwCombinedCharFieldType* pType = (SwCombinedCharFieldType*)
900                                 pCurShell->GetFldType( 0, RES_COMBINED_CHARS );
901             pFld = new SwCombinedCharField( pType, rData.sPar1 );
902         }
903         break;
904         case TYP_AUTHORITY:
905         {
906             SwAuthorityFieldType* pType =
907                 (SwAuthorityFieldType*)pCurShell->GetFldType(0, RES_AUTHORITY);
908             if(!pType)
909             {
910                 pType =
911                     (SwAuthorityFieldType*)pCurShell->InsertFldType(
912                                     SwAuthorityFieldType(pCurShell->GetDoc()));
913             }
914             pFld = new SwAuthorityField(pType, rData.sPar1);
915         }
916         break;
917         case TYP_DATEFLD:
918         case TYP_TIMEFLD:
919         {
920             sal_uInt16 nSub = static_cast< sal_uInt16 >(rData.nTypeId == TYP_DATEFLD ? DATEFLD : TIMEFLD);
921             nSub |= nSubType == DATE_VAR ? 0 : FIXEDFLD;
922 
923             SwDateTimeFieldType* pTyp =
924                 (SwDateTimeFieldType*)pCurShell->GetFldType(0, RES_DATETIMEFLD);
925             pFld = new SwDateTimeField(pTyp, nSub, nFormatId);
926             pFld->SetPar2(rData.sPar2);
927             break;
928         }
929         case TYP_FILENAMEFLD:
930         {
931             SwFileNameFieldType* pTyp =
932                 (SwFileNameFieldType*)pCurShell->GetFldType(0, RES_FILENAMEFLD);
933             pFld = new SwFileNameField(pTyp, nFormatId);
934             break;
935         }
936         case TYP_TEMPLNAMEFLD:
937         {
938             SwTemplNameFieldType* pTyp =
939                 (SwTemplNameFieldType*)pCurShell->GetFldType(0, RES_TEMPLNAMEFLD);
940             pFld = new SwTemplNameField(pTyp, nFormatId);
941             break;
942         }
943         case TYP_CHAPTERFLD:
944         {
945             sal_uInt16 nByte = (sal_uInt16)rData.sPar2.ToInt32();
946             SwChapterFieldType* pTyp =
947                 (SwChapterFieldType*)pCurShell->GetFldType(0, RES_CHAPTERFLD);
948             pFld = new SwChapterField(pTyp, nFormatId);
949             nByte = Max(sal_uInt16(1), nByte);
950             nByte = Min(nByte, sal_uInt16(MAXLEVEL));
951             nByte -= 1;
952             ((SwChapterField*)pFld)->SetLevel((sal_uInt8)nByte);
953             break;
954         }
955         case TYP_NEXTPAGEFLD:
956         case TYP_PREVPAGEFLD:
957         case TYP_PAGENUMBERFLD:
958         {
959             short nOff  = (short)rData.sPar2.ToInt32();
960 
961             if(rData.nTypeId == TYP_NEXTPAGEFLD)
962             {
963                 if( SVX_NUM_CHAR_SPECIAL == nFormatId )
964                     nOff = 1;
965                 else
966                     nOff += 1;
967                 nSubType = PG_NEXT;
968             }
969             else if(rData.nTypeId == TYP_PREVPAGEFLD)
970             {
971                 if( SVX_NUM_CHAR_SPECIAL == nFormatId )
972                     nOff = -1;
973                 else
974                     nOff -= 1;
975                 nSubType =  PG_PREV;
976             }
977             else
978                 nSubType = PG_RANDOM;
979 
980             SwPageNumberFieldType* pTyp =
981                 (SwPageNumberFieldType*)pCurShell->GetFldType(0, RES_PAGENUMBERFLD);
982             pFld = new SwPageNumberField(pTyp, nSubType, nFormatId, nOff);
983 
984             if( SVX_NUM_CHAR_SPECIAL == nFormatId &&
985                 ( PG_PREV == nSubType || PG_NEXT == nSubType ) )
986                 ((SwPageNumberField*)pFld)->SetUserString( rData.sPar2 );
987             break;
988         }
989         case TYP_DOCSTATFLD:
990         {   SwDocStatFieldType* pTyp =
991                 (SwDocStatFieldType*)pCurShell->GetFldType(0, RES_DOCSTATFLD);
992             pFld = new SwDocStatField(pTyp, nSubType, nFormatId);
993             break;
994         }
995         case TYP_AUTHORFLD:
996         {   SwAuthorFieldType* pTyp =
997                 (SwAuthorFieldType*)pCurShell->GetFldType(0, RES_AUTHORFLD);
998             pFld = new SwAuthorField(pTyp, nFormatId);
999             break;
1000         }
1001         case TYP_CONDTXTFLD:
1002         case TYP_HIDDENTXTFLD:
1003         {
1004             SwHiddenTxtFieldType* pTyp =
1005                 (SwHiddenTxtFieldType*)pCurShell->GetFldType(0, RES_HIDDENTXTFLD);
1006             pFld = new SwHiddenTxtField(pTyp, sal_True, rData.sPar1, rData.sPar2, sal_False, rData.nTypeId);
1007             bExp = sal_True;
1008             break;
1009         }
1010         case TYP_HIDDENPARAFLD:
1011         {
1012             SwHiddenParaFieldType* pTyp =
1013                 (SwHiddenParaFieldType*)pCurShell->GetFldType(0, RES_HIDDENPARAFLD);
1014             pFld = new SwHiddenParaField(pTyp, rData.sPar1);
1015             bExp = sal_True;
1016             break;
1017         }
1018         case TYP_SETREFFLD:
1019         {
1020             if( rData.sPar1.Len() > 0 && CanInsertRefMark( rData.sPar1 ) )
1021             {
1022                 pCurShell->SetAttrItem( SwFmtRefMark( rData.sPar1 ) );
1023                 return sal_True;
1024             }
1025             return sal_False;
1026         }
1027         case TYP_GETREFFLD:
1028         {
1029             SwGetRefFieldType* pTyp =
1030                 (SwGetRefFieldType*)pCurShell->GetFldType(0, RES_GETREFFLD);
1031             sal_uInt16 nSeqNo = (sal_uInt16)rData.sPar2.ToInt32();
1032             pFld = new SwGetRefField(pTyp, rData.sPar1, nSubType, nSeqNo, nFormatId);
1033             bExp = sal_True;
1034             break;
1035         }
1036         case TYP_DDEFLD:
1037         {
1038             //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1039             //              Namen haben! Wird hier noch nicht beachtet.
1040             String sCmd( rData.sPar2 );
1041             sal_uInt16 nTmpPos = sCmd.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1042             sCmd.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1043 
1044             SwDDEFieldType aType( rData.sPar1, sCmd, (sal_uInt16) nFormatId );
1045             SwDDEFieldType* pTyp = (SwDDEFieldType*) pCurShell->InsertFldType( aType );
1046             pFld = new SwDDEField( pTyp );
1047             break;
1048         }
1049         case TYP_MACROFLD:
1050         {
1051             SwMacroFieldType* pTyp =
1052                 (SwMacroFieldType*)pCurShell->GetFldType(0, RES_MACROFLD);
1053 
1054             pFld = new SwMacroField(pTyp, rData.sPar1, rData.sPar2);
1055 
1056             break;
1057         }
1058         case TYP_INTERNETFLD:
1059         {
1060             SwFmtINetFmt aFmt( rData.sPar1, sCurFrame );
1061             if( pMacroItem )
1062                 aFmt.SetMacroTbl( &pMacroItem->GetMacroTable() );
1063             return pCurShell->InsertURL( aFmt, rData.sPar2 );
1064         }
1065         case TYP_JUMPEDITFLD:
1066         {
1067             SwJumpEditFieldType* pTyp =
1068                 (SwJumpEditFieldType*)pCurShell->GetFldType(0, RES_JUMPEDITFLD);
1069 
1070             pFld = new SwJumpEditField(pTyp, nFormatId, rData.sPar1, rData.sPar2 );
1071             break;
1072         }
1073         case TYP_DOCINFOFLD:
1074         {
1075             SwDocInfoFieldType* pTyp = (SwDocInfoFieldType*)pCurShell->GetFldType(
1076                                             0, RES_DOCINFOFLD );
1077             pFld = new SwDocInfoField(pTyp, nSubType, rData.sPar1, nFormatId);
1078             break;
1079         }
1080         case TYP_EXTUSERFLD:
1081         {
1082             SwExtUserFieldType* pTyp = (SwExtUserFieldType*)pCurShell->GetFldType(
1083                                             0, RES_EXTUSERFLD);
1084             pFld = new SwExtUserField(pTyp, nSubType, nFormatId);
1085             break;
1086         }
1087         case TYP_DBFLD:
1088         {
1089             SwDBData aDBData;
1090             String sPar1;
1091 
1092             if (rData.sPar1.Search(DB_DELIM) == STRING_NOTFOUND)
1093             {
1094                 aDBData = pCurShell->GetDBData();
1095                 sPar1 = rData.sPar1;
1096             }
1097             else
1098             {
1099                 aDBData.sDataSource = rData.sPar1.GetToken(0, DB_DELIM);
1100                 aDBData.sCommand = rData.sPar1.GetToken(1, DB_DELIM);
1101                 aDBData.nCommandType = rData.sPar1.GetToken(2, DB_DELIM).ToInt32();
1102                 sPar1 = rData.sPar1.GetToken(3, DB_DELIM);
1103             }
1104 
1105             if(aDBData.sDataSource.getLength() && pCurShell->GetDBData() != aDBData)
1106                 pCurShell->ChgDBData(aDBData);
1107 
1108             SwDBFieldType* pTyp = (SwDBFieldType*)pCurShell->InsertFldType(
1109                     SwDBFieldType(pCurShell->GetDoc(), sPar1, aDBData) );
1110             pFld = new SwDBField(pTyp);
1111             pFld->SetSubType(nSubType);
1112 
1113             if( !(nSubType & nsSwExtendedSubType::SUB_OWN_FMT) ) // Datenbankformat ermitteln
1114             {
1115                 Reference< XDataSource> xSource;
1116                 rData.aDBDataSource >>= xSource;
1117                 Reference<XConnection> xConnection;
1118                 rData.aDBConnection >>= xConnection;
1119                 Reference<XPropertySet> xColumn;
1120                 rData.aDBColumn >>= xColumn;
1121                 if(xColumn.is())
1122                 {
1123                     nFormatId = pCurShell->GetNewDBMgr()->GetColumnFmt(xSource, xConnection, xColumn,
1124                                         pCurShell->GetNumberFormatter(), GetCurrLanguage() );
1125                 }
1126                 else
1127                     nFormatId = pCurShell->GetNewDBMgr()->GetColumnFmt(
1128                                         aDBData.sDataSource, aDBData.sCommand, sPar1,
1129                                         pCurShell->GetNumberFormatter(), GetCurrLanguage() );
1130             }
1131             pFld->ChangeFormat( nFormatId );
1132 
1133             bExp = sal_True;
1134             break;
1135         }
1136         case TYP_DBSETNUMBERFLD:
1137         case TYP_DBNUMSETFLD:
1138         case TYP_DBNEXTSETFLD:
1139         case TYP_DBNAMEFLD:
1140         {
1141             sal_uInt16 nPos, nTablePos, nCmdTypePos, nExpPos;
1142             String sPar1;
1143             SwDBData aDBData;
1144 
1145             // DBName aus rData.sPar1 extrahieren. Format: DBName.TableName.CommandType.ExpStrg
1146             if ((nTablePos = rData.sPar1.Search(DB_DELIM)) != STRING_NOTFOUND)
1147                 aDBData.sDataSource = rData.sPar1.Copy(0, nTablePos++);
1148             if ((nCmdTypePos = rData.sPar1.Search(DB_DELIM, nTablePos)) != STRING_NOTFOUND)
1149             {
1150                 aDBData.sCommand = rData.sPar1.Copy(nTablePos, nCmdTypePos++ - nTablePos);
1151             }
1152             if ((nExpPos = rData.sPar1.Search(DB_DELIM, nCmdTypePos)) != STRING_NOTFOUND)
1153             {
1154                 aDBData.nCommandType = rData.sPar1.Copy(nCmdTypePos, nExpPos++ - nCmdTypePos).ToInt32();
1155             }
1156             if (nExpPos != STRING_NOTFOUND)
1157                 nPos = nExpPos;
1158             else if (nTablePos != STRING_NOTFOUND)
1159                 nPos = nTablePos;
1160             else
1161                 nPos = 0;
1162             sPar1 = rData.sPar1.Copy(nPos);
1163 
1164             if (aDBData.sDataSource.getLength() && pCurShell->GetDBData() != aDBData)
1165                 pCurShell->ChgDBData(aDBData);
1166 
1167             switch(rData.nTypeId)
1168             {
1169                 case TYP_DBNAMEFLD:
1170                 {
1171                     SwDBNameFieldType* pTyp =
1172                         (SwDBNameFieldType*)pCurShell->GetFldType(0, RES_DBNAMEFLD);
1173                     pFld = new SwDBNameField(pTyp, aDBData);
1174 
1175                     break;
1176                 }
1177                 case TYP_DBNEXTSETFLD:
1178                 {
1179                     SwDBNextSetFieldType* pTyp = (SwDBNextSetFieldType*)pCurShell->GetFldType(
1180                                                     0, RES_DBNEXTSETFLD);
1181                     pFld = new SwDBNextSetField(pTyp, sPar1, rData.sPar2, aDBData);
1182                     bExp = sal_True;
1183                     break;
1184                 }
1185                 case TYP_DBNUMSETFLD:
1186                 {
1187                     SwDBNumSetFieldType* pTyp = (SwDBNumSetFieldType*)pCurShell->GetFldType(
1188                                                     0, RES_DBNUMSETFLD);
1189                     pFld = new SwDBNumSetField( pTyp, sPar1, rData.sPar2, aDBData);
1190                     bExp = sal_True;
1191                     break;
1192                 }
1193                 case TYP_DBSETNUMBERFLD:
1194                 {
1195                     SwDBSetNumberFieldType* pTyp = (SwDBSetNumberFieldType*)
1196                                                 pCurShell->GetFldType(0, RES_DBSETNUMBERFLD);
1197                     pFld = new SwDBSetNumberField( pTyp, aDBData, nFormatId);
1198                     bExp = sal_True;
1199                     break;
1200                 }
1201             }
1202             break;
1203         }
1204         case TYP_USERFLD:
1205         {
1206             SwUserFieldType* pTyp =
1207                 (SwUserFieldType*)pCurShell->GetFldType(RES_USERFLD, rData.sPar1);
1208 
1209             // nur wenn vorhanden
1210             if(!pTyp)
1211             {
1212                 pTyp = (SwUserFieldType*)pCurShell->InsertFldType(
1213                         SwUserFieldType(pCurShell->GetDoc(), rData.sPar1));
1214             }
1215             if (pTyp->GetContent(nFormatId) != rData.sPar2)
1216                 pTyp->SetContent(rData.sPar2, nFormatId);
1217             pFld = new SwUserField(pTyp, 0, nFormatId);
1218             if (pFld->GetSubType() != nSubType)
1219                 pFld->SetSubType(nSubType);
1220             bTbl = sal_True;
1221             break;
1222         }
1223         case TYP_INPUTFLD:
1224         {
1225             if ((nSubType & 0x00ff) == INP_VAR)
1226             {
1227                 SwSetExpFieldType* pTyp = (SwSetExpFieldType*)
1228                                     pCurShell->GetFldType(RES_SETEXPFLD, rData.sPar1);
1229 
1230                 // kein Experssion Type mit dem Namen vorhanden -> anlegen
1231                 if(pTyp)
1232                 {
1233                     SwSetExpField* pExpFld =
1234                         new SwSetExpField(pTyp, aEmptyStr, nFormatId);
1235 
1236                     // Typ vom SwSetExpFieldType nicht veraendern:
1237                     sal_uInt16 nOldSubType = pExpFld->GetSubType();
1238                     pExpFld->SetSubType(nOldSubType | (nSubType & 0xff00));
1239 
1240                     pExpFld->SetPromptText(rData.sPar2);
1241                     pExpFld->SetInputFlag(sal_True) ;
1242                     bExp = sal_True;
1243                     pFld = pExpFld;
1244                 }
1245                 else
1246                     return sal_False;
1247             }
1248             else
1249             {
1250                 SwInputFieldType* pTyp =
1251                     (SwInputFieldType*)pCurShell->GetFldType(0, RES_INPUTFLD);
1252 
1253                 SwInputField* pInpFld =
1254                     new SwInputField( pTyp, rData.sPar1, rData.sPar2, nSubType|nsSwExtendedSubType::SUB_INVISIBLE, nFormatId);
1255                 pFld = pInpFld;
1256             }
1257 
1258             // Dialog starten
1259             //
1260             pCurShell->StartInputFldDlg(pFld, sal_False, rData.pParent);
1261             break;
1262         }
1263         case TYP_SETFLD:
1264         {
1265             if (!rData.sPar2.Len())   // Leere Variablen sind nicht erlaubt
1266                 return sal_False;
1267 
1268             SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pCurShell->InsertFldType(
1269                     SwSetExpFieldType(pCurShell->GetDoc(), rData.sPar1) );
1270 
1271             SwSetExpField* pExpFld = new SwSetExpField( pTyp, rData.sPar2, nFormatId);
1272             pExpFld->SetSubType(nSubType);
1273             pExpFld->SetPar2(rData.sPar2);
1274             bExp = sal_True;
1275             pFld = pExpFld;
1276             break;
1277         }
1278         case TYP_SEQFLD:
1279         {
1280             SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pCurShell->InsertFldType(
1281                     SwSetExpFieldType(pCurShell->GetDoc(), rData.sPar1, nsSwGetSetExpType::GSE_SEQ));
1282 
1283             sal_uInt8 nLevel = static_cast< sal_uInt8 >(nSubType & 0xff);
1284 
1285             pTyp->SetOutlineLvl(nLevel);
1286             if (nLevel != 0x7f && cSeparator == 0)
1287                 cSeparator = '.';
1288 
1289             pTyp->SetDelimiter(cSeparator);
1290             SwSetExpField* pExpFld = new SwSetExpField(pTyp, rData.sPar2, nFormatId);
1291             bExp = sal_True;
1292             pFld = pExpFld;
1293             nSubType = nsSwGetSetExpType::GSE_SEQ;
1294             break;
1295         }
1296         case TYP_GETFLD:
1297         {
1298             // gibt es ein entprechendes SetField
1299             SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*)
1300                                     pCurShell->GetFldType(RES_SETEXPFLD, rData.sPar1);
1301 
1302             if(pSetTyp)
1303             {
1304                 SwGetExpFieldType* pTyp = (SwGetExpFieldType*)pCurShell->GetFldType(
1305                                                 0, RES_GETEXPFLD);
1306                 pFld = new SwGetExpField(pTyp, rData.sPar1, pSetTyp->GetType(), nFormatId);
1307                 pFld->SetSubType(nSubType | pSetTyp->GetType());
1308                 bExp = sal_True;
1309             }
1310             else
1311                 return sal_False;
1312             break;
1313         }
1314         case TYP_FORMELFLD:
1315         {
1316             if(pCurShell->GetFrmType(0,sal_False) & FRMTYPE_TABLE)
1317             {
1318                 pCurShell->StartAllAction();
1319 
1320                 SvNumberFormatter* pFormatter = pCurShell->GetDoc()->GetNumberFormatter();
1321                 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormatId);
1322 
1323                 if (pEntry)
1324                 {
1325                     SfxStringItem aFormat(FN_NUMBER_FORMAT, pEntry->GetFormatstring());
1326                     pCurShell->GetView().GetViewFrame()->GetDispatcher()->
1327                         Execute(FN_NUMBER_FORMAT, SFX_CALLMODE_SYNCHRON, &aFormat, 0L);
1328                 }
1329 
1330                 SfxItemSet aBoxSet( pCurShell->GetAttrPool(),
1331                                 RES_BOXATR_FORMULA, RES_BOXATR_FORMULA );
1332 
1333                 String sFml( rData.sPar2 );
1334                 if( sFml.EraseLeadingChars().Len() &&
1335                     '=' == sFml.GetChar( 0 ) )
1336                     sFml.Erase( 0, 1 );
1337 
1338                 aBoxSet.Put( SwTblBoxFormula( sFml ));
1339                 pCurShell->SetTblBoxFormulaAttrs( aBoxSet );
1340                 pCurShell->UpdateTable();
1341 
1342                 pCurShell->EndAllAction();
1343                 return sal_True;
1344 
1345 /*              // In der Tabelle Tabellenformeln einfuegen
1346                 SwTblFieldType* pTyp = (SwTblFieldType*)pCurShell->GetFldType(
1347                                                         0, RES_TABLEFLD);
1348                 pFld = new SwTblField(pTyp, rData.sPar2, nsSwGetSetExpType::GSE_EXPR, nFormatId);
1349                 bTbl = sal_True;*/
1350             }
1351             else
1352             {
1353                 SwGetExpFieldType* pTyp = (SwGetExpFieldType*)
1354                                             pCurShell->GetFldType(0, RES_GETEXPFLD);
1355                 pFld = new SwGetExpField(pTyp, rData.sPar2, nsSwGetSetExpType::GSE_FORMULA, nFormatId);
1356                 pFld->SetSubType(nSubType);
1357                 bExp = sal_True;
1358             }
1359             break;
1360         }
1361         case TYP_SETREFPAGEFLD:
1362             pFld = new SwRefPageSetField( (SwRefPageSetFieldType*)
1363                                 pCurShell->GetFldType( 0, RES_REFPAGESETFLD ),
1364                                 (short)rData.sPar2.ToInt32(), 0 != nSubType  );
1365             bPageVar = sal_True;
1366             break;
1367 
1368         case TYP_GETREFPAGEFLD:
1369             pFld = new SwRefPageGetField( (SwRefPageGetFieldType*)
1370                             pCurShell->GetFldType( 0, RES_REFPAGEGETFLD ), nFormatId );
1371             bPageVar = sal_True;
1372             break;
1373         case TYP_DROPDOWN :
1374         {
1375             pFld = new SwDropDownField(pCurShell->GetFldType( 0, RES_DROPDOWN ));
1376             xub_StrLen nTokenCount = rData.sPar2.Len() ? rData.sPar2.GetTokenCount(DB_DELIM) : 0;
1377             Sequence<OUString> aEntries(nTokenCount);
1378             OUString* pArray = aEntries.getArray();
1379             for(xub_StrLen nToken = 0; nToken < nTokenCount; nToken++)
1380                 pArray[nToken] = rData.sPar2.GetToken(nToken, DB_DELIM);
1381             ((SwDropDownField*)pFld)->SetItems(aEntries);
1382             ((SwDropDownField*)pFld)->SetName(rData.sPar1);
1383         }
1384         break;
1385         default:
1386         {   ASSERT(!this, "Falscher Feldtyp");
1387             return sal_False;
1388         }
1389     }
1390     ASSERT(pFld, "Feld nicht vorhanden");
1391 
1392 
1393      //the auto language flag has to be set prior to the language!
1394      pFld->SetAutomaticLanguage(rData.bIsAutomaticLanguage);
1395      sal_uInt16 nLang = GetCurrLanguage();
1396      pFld->SetLanguage(nLang);
1397 
1398     // Einfuegen
1399     pCurShell->StartAllAction();
1400 
1401     const SwPaM* pCommentRange = NULL;
1402     if (pPam && *pPam->GetPoint() != *pPam->GetMark() && rData.nTypeId == TYP_POSTITFLD)
1403     {
1404         pCommentRange = pPam;
1405     }
1406 
1407     pCurShell->Insert( *pFld, pCommentRange );
1408 
1409     if(bExp && bEvalExp)
1410         pCurShell->UpdateExpFlds(sal_True);
1411 
1412     if(bTbl)
1413     {
1414         pCurShell->Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
1415         pCurShell->UpdateFlds(*pFld);
1416         pCurShell->Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
1417     }
1418     else if( bPageVar )
1419         ((SwRefPageGetFieldType*)pCurShell->GetFldType( 0, RES_REFPAGEGETFLD ))->UpdateFlds();
1420     else if( TYP_GETREFFLD == rData.nTypeId )
1421         pFld->GetTyp()->ModifyNotification( 0, 0 );
1422 
1423     // temporaeres Feld loeschen
1424     delete pFld;
1425 
1426     pCurShell->EndAllAction();
1427     return sal_True;
1428 }
1429 
1430 /*--------------------------------------------------------------------
1431     Beschreibung: Felder Update
1432  --------------------------------------------------------------------*/
1433 
1434 
1435 void SwFldMgr::UpdateCurFld(sal_uLong nFormat,
1436                             const String& rPar1,
1437                             const String& rPar2,
1438                             SwField * _pTmpFld) // #111840#
1439 {
1440     // Format aendern
1441     ASSERT(pCurFld, "kein Feld an der CursorPos");
1442 
1443     bool bDelete = false;
1444     SwField *pTmpFld;       // mb: fixed memory leak
1445     if (NULL != _pTmpFld)
1446     {
1447         pTmpFld = _pTmpFld;
1448     }
1449     else
1450     {
1451         pTmpFld = pCurFld->CopyField();
1452         bDelete = true;
1453     }
1454 
1455     SwFieldType* pType   = pTmpFld->GetTyp();
1456     const sal_uInt16 nTypeId = pTmpFld->GetTypeId();
1457 
1458     SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
1459     DBG_ASSERT(pSh, "no SwWrtShell found");
1460     if(!pSh)
1461         return;
1462     pSh->StartAllAction();
1463 
1464     sal_Bool bSetPar2 = sal_True;
1465     sal_Bool bSetPar1 = sal_True;
1466     String sPar1( rPar1 );
1467     String sPar2( rPar2 );
1468 
1469     // Order to Format
1470     switch( nTypeId )
1471     {
1472         case TYP_DDEFLD:
1473         {
1474             //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren
1475             //              Namen haben! Wird hier noch nicht beachtet.
1476             sal_uInt16 nTmpPos = sPar2.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1477             sPar2.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos );
1478             break;
1479         }
1480 
1481         case TYP_CHAPTERFLD:
1482         {
1483             sal_uInt16 nByte = (sal_uInt16)rPar2.ToInt32();
1484             nByte = Max(sal_uInt16(1), nByte);
1485             nByte = Min(nByte, sal_uInt16(MAXLEVEL));
1486             nByte -= 1;
1487             ((SwChapterField*)pTmpFld)->SetLevel((sal_uInt8)nByte);
1488             bSetPar2 = sal_False;
1489             break;
1490         }
1491 
1492         case TYP_SCRIPTFLD:
1493             ((SwScriptField*)pTmpFld)->SetCodeURL((sal_Bool)nFormat);
1494             break;
1495 
1496         case TYP_NEXTPAGEFLD:
1497             if( SVX_NUM_CHAR_SPECIAL == nFormat )
1498             {
1499                 ((SwPageNumberField*)pCurFld)->SetUserString( sPar2 );
1500                 sPar2 = '1';
1501             }
1502             else
1503             {
1504                 if( nFormat + 2 == SVX_NUM_PAGEDESC )
1505                     nFormat = SVX_NUM_PAGEDESC;
1506                 short nOff = (short)sPar2.ToInt32();
1507                 nOff += 1;
1508                 sPar2 = String::CreateFromInt32(nOff);
1509             }
1510             break;
1511 
1512         case TYP_PREVPAGEFLD:
1513             if( SVX_NUM_CHAR_SPECIAL == nFormat )
1514             {
1515                 ((SwPageNumberField*)pCurFld)->SetUserString( sPar2 );
1516                 sPar2 = String::CreateFromAscii(
1517                     RTL_CONSTASCII_STRINGPARAM("-1"));
1518             }
1519             else
1520             {
1521                 if( nFormat + 2 == SVX_NUM_PAGEDESC )
1522                     nFormat = SVX_NUM_PAGEDESC;
1523                 short nOff = (short)sPar2.ToInt32();
1524                 nOff -= 1;
1525                 sPar2 = String::CreateFromInt32(nOff);
1526             }
1527             break;
1528 
1529         case TYP_PAGENUMBERFLD:
1530         case TYP_GETREFPAGEFLD:
1531             if( nFormat + 2 == SVX_NUM_PAGEDESC )
1532                 nFormat = SVX_NUM_PAGEDESC;
1533             break;
1534 
1535         case TYP_GETREFFLD:
1536             {
1537                 bSetPar2 = sal_False;
1538                 ((SwGetRefField*)pTmpFld)->SetSubType( (sal_uInt16)rPar2.ToInt32() );
1539                 sal_uInt16 nPos = rPar2.Search( '|' );
1540                 if( STRING_NOTFOUND != nPos )
1541                     ((SwGetRefField*)pTmpFld)->SetSeqNo( (sal_uInt16)rPar2.Copy( nPos + 1 ).ToInt32());
1542             }
1543             break;
1544         case TYP_DROPDOWN:
1545         {
1546             xub_StrLen nTokenCount = sPar2.Len() ? sPar2.GetTokenCount(DB_DELIM) : 0;
1547             Sequence<OUString> aEntries(nTokenCount);
1548             OUString* pArray = aEntries.getArray();
1549             for(xub_StrLen nToken = 0; nToken < nTokenCount; nToken++)
1550                 pArray[nToken] = sPar2.GetToken(nToken, DB_DELIM);
1551             ((SwDropDownField*)pTmpFld)->SetItems(aEntries);
1552             ((SwDropDownField*)pTmpFld)->SetName(sPar1);
1553             bSetPar1 = bSetPar2 = sal_False;
1554         }
1555         break;
1556         case TYP_AUTHORITY :
1557         {
1558             //#i99069# changes to a bibliography field should change the field type
1559             SwAuthorityField* pAuthorityField = static_cast<SwAuthorityField*>(pTmpFld);
1560             SwAuthorityFieldType* pAuthorityType = static_cast<SwAuthorityFieldType*>(pType);
1561             SwAuthEntry aTempEntry;
1562             for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i )
1563                 aTempEntry.SetAuthorField( (ToxAuthorityField)i,
1564                                 rPar1.GetToken( i, TOX_STYLE_DELIMITER ));
1565             if( pAuthorityType->ChangeEntryContent( &aTempEntry ) )
1566             {
1567                 pType->UpdateFlds();
1568                 pSh->SetModified();
1569             }
1570 
1571             if( aTempEntry.GetAuthorField( AUTH_FIELD_IDENTIFIER ) ==
1572                 pAuthorityField->GetFieldText( AUTH_FIELD_IDENTIFIER ) )
1573                 bSetPar1 = sal_False; //otherwise it's a new or changed entry, the field needs to be updated
1574             bSetPar2 = sal_False;
1575         }
1576         break;
1577     }
1578 
1579     // Format setzen
1580     // Format wegen NumberFormatter vor SetPar2 einstellen!
1581     pTmpFld->ChangeFormat(nFormat);
1582 
1583     if(bSetPar1)
1584         pTmpFld->SetPar1( sPar1 );
1585     if( bSetPar2 )
1586         pTmpFld->SetPar2( sPar2 );
1587 
1588     // Update anschmeissen
1589     if(nTypeId == TYP_DDEFLD ||
1590        nTypeId == TYP_USERFLD ||
1591        nTypeId == TYP_USRINPFLD)
1592     {
1593         pType->UpdateFlds();
1594         pSh->SetModified();
1595     }
1596     else {
1597         // mb: #32157
1598         pSh->SwEditShell::UpdateFlds(*pTmpFld);
1599         GetCurFld();
1600     }
1601 
1602     if (bDelete)
1603         delete pTmpFld;
1604 
1605     pSh->EndAllAction();
1606 }
1607 
1608 /*--------------------------------------------------------------------
1609     Beschreibung: ExpressionFields explizit evaluieren
1610  --------------------------------------------------------------------*/
1611 void SwFldMgr::EvalExpFlds(SwWrtShell* pSh)
1612 {
1613     if (pSh == NULL)
1614         pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
1615 
1616     if(pSh)
1617     {
1618         pSh->StartAllAction();
1619         pSh->UpdateExpFlds(sal_True);
1620         pSh->EndAllAction();
1621     }
1622 }
1623 sal_uInt16 SwFldMgr::GetCurrLanguage() const
1624 {
1625     SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell();
1626     if( pSh )
1627         return pSh->GetCurLang();
1628     return SvxLocaleToLanguage( SvtSysLocale().GetLocaleData().getLocale() );
1629 }
1630 
1631 void SwFieldType::_GetFldName()
1632 {
1633     // mba: this is an awful mess; a fix is available, but too much for 3.4 -> applay plaster
1634     static const sal_uInt16 coFldCnt = 43;
1635 
1636     static sal_uInt16 __READONLY_DATA coFldNms[ coFldCnt ] = {
1637         FLD_DATE_STD,
1638         FLD_TIME_STD,
1639         STR_FILENAMEFLD,
1640         STR_DBNAMEFLD,
1641         STR_CHAPTERFLD,
1642         STR_PAGENUMBERFLD,
1643         STR_DOCSTATFLD,
1644         STR_AUTHORFLD,
1645         STR_SETFLD,
1646         STR_GETFLD,
1647         STR_FORMELFLD,
1648         STR_HIDDENTXTFLD,
1649         STR_SETREFFLD,
1650         STR_GETREFFLD,
1651         STR_DDEFLD,
1652         STR_MACROFLD,
1653         STR_INPUTFLD,
1654         STR_HIDDENPARAFLD,
1655         STR_DOCINFOFLD,
1656         STR_DBFLD,
1657         STR_USERFLD,
1658         STR_POSTITFLD,
1659         STR_TEMPLNAMEFLD,
1660         STR_SEQFLD,
1661         STR_DBNEXTSETFLD,
1662         STR_DBNUMSETFLD,
1663         STR_DBSETNUMBERFLD,
1664         STR_CONDTXTFLD,
1665         STR_NEXTPAGEFLD,
1666         STR_PREVPAGEFLD,
1667         STR_EXTUSERFLD,
1668         FLD_DATE_FIX,
1669         FLD_TIME_FIX,
1670         STR_SETINPUTFLD,
1671         STR_USRINPUTFLD,
1672         STR_SETREFPAGEFLD,
1673         STR_GETREFPAGEFLD,
1674         STR_INTERNETFLD,
1675         STR_JUMPEDITFLD,
1676         STR_SCRIPTFLD,
1677         STR_AUTHORITY,
1678         STR_COMBINED_CHARS,
1679         STR_DROPDOWN
1680     };
1681 
1682     // Infos fuer Felder einfuegen
1683     SwFieldType::pFldNames = new SvStringsDtor( (sal_uInt8)coFldCnt, 2 );
1684     for( sal_uInt16 nIdx = 0; nIdx < coFldCnt; ++nIdx )
1685     {
1686         String* pTmp = new SW_RESSTR( coFldNms[ nIdx ] );
1687         pTmp->Assign( MnemonicGenerator::EraseAllMnemonicChars( *pTmp ) );
1688         SwFieldType::pFldNames->Insert(pTmp, nIdx );
1689     }
1690 }
1691 
1692 /*--------------------------------------------------------------------
1693     Beschreibung:
1694  --------------------------------------------------------------------*/
1695 
1696 sal_Bool SwFldMgr::ChooseMacro(const String&)
1697 {
1698     sal_Bool bRet = sal_False;
1699 
1700     // choose script dialog
1701     ::rtl::OUString aScriptURL = SfxApplication::ChooseScript();
1702 
1703     // the script selector dialog returns a valid script URL
1704     if ( aScriptURL.getLength() != 0 )
1705     {
1706         SetMacroPath( aScriptURL );
1707         bRet = sal_True;
1708     }
1709 
1710     return bRet;
1711 }
1712 
1713 void SwFldMgr::SetMacroPath(const String& rPath)
1714 {
1715     sMacroPath = rPath;
1716     sMacroName = rPath;
1717 
1718     // try to set sMacroName member variable by parsing the macro path
1719     // using the new URI parsing services
1720 
1721     Reference< XMultiServiceFactory > xSMgr =
1722         ::comphelper::getProcessServiceFactory();
1723 
1724     Reference< uri::XUriReferenceFactory >
1725         xFactory( xSMgr->createInstance(
1726             ::rtl::OUString::createFromAscii(
1727                 "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY );
1728 
1729     if ( xFactory.is() )
1730     {
1731         Reference< uri::XVndSunStarScriptUrl >
1732             xUrl( xFactory->parse( sMacroPath ), UNO_QUERY );
1733 
1734         if ( xUrl.is() )
1735         {
1736             sMacroName = xUrl->getName();
1737         }
1738     }
1739 }
1740 
1741 /*--------------------------------------------------------------------
1742     Beschreibung:
1743  --------------------------------------------------------------------*/
1744 
1745 sal_uLong SwFldMgr::GetDefaultFormat(sal_uInt16 nTypeId, sal_Bool bIsText, SvNumberFormatter* pFormatter, double* pVal)
1746 {
1747     double fValue;
1748     short  nDefFormat;
1749 
1750     switch (nTypeId)
1751     {
1752         case TYP_TIMEFLD:
1753         case TYP_DATEFLD:
1754         {
1755             Date aDate;
1756             Date* pNullDate = pFormatter->GetNullDate();
1757 
1758             fValue = aDate - *pNullDate;
1759 
1760             Time aTime;
1761 
1762             sal_uLong nNumFmtTime = (sal_uLong)aTime.GetSec() + (sal_uLong)aTime.GetMin() * 60L +
1763                           (sal_uLong)aTime.GetHour() * 3600L;
1764 
1765             fValue += (double)nNumFmtTime / 86400.0;
1766 
1767             nDefFormat = (nTypeId == TYP_DATEFLD) ? NUMBERFORMAT_DATE : NUMBERFORMAT_TIME;
1768         }
1769         break;
1770 
1771         default:
1772             if (bIsText)
1773             {
1774                 fValue = 0.0;
1775                 nDefFormat = NUMBERFORMAT_TEXT;
1776             }
1777             else
1778             {
1779                 fValue = 0.0;
1780                 nDefFormat = NUMBERFORMAT_ALL;
1781             }
1782             break;
1783     }
1784 
1785     if (pVal)
1786         *pVal = fValue;
1787 
1788     return pFormatter->GetStandardFormat(nDefFormat, GetCurrLanguage());
1789 }
1790 
1791 /* -----------------------------01.03.01 16:46--------------------------------
1792 
1793  ---------------------------------------------------------------------------*/
1794 Reference<XNumberingTypeInfo> SwFldMgr::GetNumberingInfo() const
1795 {
1796     if(!xNumberingInfo.is())
1797     {
1798         Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
1799         Reference < XInterface > xI = xMSF->createInstance(
1800             ::rtl::OUString::createFromAscii(
1801                             "com.sun.star.text.DefaultNumberingProvider" ));
1802         Reference<XDefaultNumberingProvider> xDefNum(xI, UNO_QUERY);
1803         DBG_ASSERT(xDefNum.is(), "service missing: \"com.sun.star.text.DefaultNumberingProvider\"");
1804         ((SwFldMgr*)this)->xNumberingInfo = Reference<XNumberingTypeInfo>(xDefNum, UNO_QUERY);
1805     }
1806     return xNumberingInfo;
1807 }
1808