LCOV - code coverage report
Current view: top level - sw/source/core/uibase/fldui - fldmgr.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 9 705 1.3 %
Date: 2014-04-11 Functions: 3 33 9.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10