LCOV - code coverage report
Current view: top level - sw/source/core/unocore - unofield.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 973 1512 64.4 %
Date: 2014-04-11 Functions: 83 109 76.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 "sal/config.h"
      21             : 
      22             : #include <algorithm>
      23             : 
      24             : #include <unofield.hxx>
      25             : #include <unofieldcoll.hxx>
      26             : #include <swtypes.hxx>
      27             : #include <cmdid.h>
      28             : #include <doc.hxx>
      29             : #include <hints.hxx>
      30             : #include <fmtfld.hxx>
      31             : #include <txtfld.hxx>
      32             : #include <ndtxt.hxx>
      33             : #include <unomap.hxx>
      34             : #include <unoprnms.hxx>
      35             : #include <unotextrange.hxx>
      36             : #include <unotextcursor.hxx>
      37             : #include <unocoll.hxx>
      38             : #include <sfx2/linkmgr.hxx>
      39             : #include <docstat.hxx>
      40             : #include <editsh.hxx>
      41             : #include <viewsh.hxx>
      42             : #include <comphelper/processfactory.hxx>
      43             : #include <comphelper/servicehelper.hxx>
      44             : #include <comphelper/string.hxx>
      45             : #include <comphelper/types.hxx>
      46             : #include <cppuhelper/supportsservice.hxx>
      47             : #include <com/sun/star/util/Time.hpp>
      48             : #include <com/sun/star/util/DateTime.hpp>
      49             : #include <com/sun/star/util/Date.hpp>
      50             : #include <com/sun/star/beans/XFastPropertySet.hpp>
      51             : #include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
      52             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      53             : #include <com/sun/star/beans/XPropertyContainer.hpp>
      54             : 
      55             : //undef to prevent error (from sfx2/docfile.cxx)
      56             : #undef SEQUENCE
      57             : #include <com/sun/star/text/SetVariableType.hpp>
      58             : #include <com/sun/star/text/WrapTextMode.hpp>
      59             : #include <com/sun/star/text/TextContentAnchorType.hpp>
      60             : #include <com/sun/star/text/PageNumberType.hpp>
      61             : #include <unocrsr.hxx>
      62             : #include <authfld.hxx>
      63             : #include <flddat.hxx>
      64             : #include <dbfld.hxx>
      65             : #include <usrfld.hxx>
      66             : #include <docufld.hxx>
      67             : #include <expfld.hxx>
      68             : #include <chpfld.hxx>
      69             : #include <flddropdown.hxx>
      70             : #include <poolfmt.hxx>
      71             : #include <poolfmt.hrc>
      72             : #include <pagedesc.hxx>
      73             : #include <docary.hxx>
      74             : #include <reffld.hxx>
      75             : #include <ddefld.hxx>
      76             : #include <SwStyleNameMapper.hxx>
      77             : #include <swunohelper.hxx>
      78             : #include <unofldmid.h>
      79             : #include <scriptinfo.hxx>
      80             : #include <tools/datetime.hxx>
      81             : #include <tools/urlobj.hxx>
      82             : #include <svx/dataaccessdescriptor.hxx>
      83             : #include <osl/mutex.hxx>
      84             : #include <vcl/svapp.hxx>
      85             : #include <textapi.hxx>
      86             : #include <editeng/outliner.hxx>
      87             : #include <docsh.hxx>
      88             : #include <fmtmeta.hxx>
      89             : #include <switerator.hxx>
      90             : #include <rtl/strbuf.hxx>
      91             : #include <vector>
      92             : 
      93             : using namespace ::com::sun::star;
      94             : using namespace nsSwDocInfoSubType;
      95             : 
      96             : // case-corrected version of the first part for the service names (see #i67811)
      97             : #define COM_TEXT_FLDMASTER_CC   "com.sun.star.text.fieldmaster."
      98             : 
      99             : // note: this thing is indexed as an array, so do not insert/remove entries!
     100             : static const sal_uInt16 aDocInfoSubTypeFromService[] =
     101             : {
     102             :     DI_CHANGE | DI_SUB_AUTHOR,  //PROPERTY_MAP_FLDTYP_DOCINFO_CHANGE_AUTHOR
     103             :     DI_CHANGE | DI_SUB_DATE,    //PROPERTY_MAP_FLDTYP_DOCINFO_CHANGE_DATE_TIME
     104             :     DI_EDIT | DI_SUB_TIME,      //PROPERTY_MAP_FLDTYP_DOCINFO_EDIT_TIME
     105             :     DI_COMMENT,                 //PROPERTY_MAP_FLDTYP_DOCINFO_DESCRIPTION
     106             :     DI_CREATE | DI_SUB_AUTHOR,  //PROPERTY_MAP_FLDTYP_DOCINFO_CREATE_AUTHOR
     107             :     DI_CREATE | DI_SUB_DATE,    //PROPERTY_MAP_FLDTYP_DOCINFO_CREATE_DATE_TIME
     108             :     0,                          //DUMMY
     109             :     0,                          //DUMMY
     110             :     0,                          //DUMMY
     111             :     0,                          //DUMMY
     112             :     DI_CUSTOM,                  //PROPERTY_MAP_FLDTYP_DOCINFO_CUSTOM
     113             :     DI_PRINT | DI_SUB_AUTHOR,   //PROPERTY_MAP_FLDTYP_DOCINFO_PRINT_AUTHOR
     114             :     DI_PRINT | DI_SUB_DATE,     //PROPERTY_MAP_FLDTYP_DOCINFO_PRINT_DATE_TIME
     115             :     DI_KEYS,                    //PROPERTY_MAP_FLDTYP_DOCINFO_KEY_WORDS
     116             :     DI_THEMA,                   //PROPERTY_MAP_FLDTYP_DOCINFO_SUBJECT
     117             :     DI_TITEL,                   //PROPERTY_MAP_FLDTYP_DOCINFO_TITLE
     118             :     DI_DOCNO                    //PROPERTY_MAP_FLDTYP_DOCINFO_REVISION
     119             : };
     120             : 
     121             : struct ServiceIdResId
     122             : {
     123             :     sal_uInt16 nResId;
     124             :     sal_uInt16 nServiceId;
     125             : };
     126             : 
     127             : static const ServiceIdResId aServiceToRes[] =
     128             : {
     129             :     {RES_DATETIMEFLD,   SW_SERVICE_FIELDTYPE_DATETIME               },
     130             :     {RES_USERFLD,       SW_SERVICE_FIELDTYPE_USER                   },
     131             :     {RES_SETEXPFLD,         SW_SERVICE_FIELDTYPE_SET_EXP            }    ,
     132             :     {RES_GETEXPFLD,         SW_SERVICE_FIELDTYPE_GET_EXP            }    ,
     133             :     {RES_FILENAMEFLD,   SW_SERVICE_FIELDTYPE_FILE_NAME              },
     134             :     {RES_PAGENUMBERFLD,     SW_SERVICE_FIELDTYPE_PAGE_NUM           }    ,
     135             :     {RES_AUTHORFLD,         SW_SERVICE_FIELDTYPE_AUTHOR             }    ,
     136             :     {RES_CHAPTERFLD,    SW_SERVICE_FIELDTYPE_CHAPTER                },
     137             :     {RES_GETREFFLD,         SW_SERVICE_FIELDTYPE_GET_REFERENCE      }    ,
     138             :     {RES_HIDDENTXTFLD,  SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT       },
     139             :     {RES_POSTITFLD,         SW_SERVICE_FIELDTYPE_ANNOTATION         }    ,
     140             :     {RES_INPUTFLD,      SW_SERVICE_FIELDTYPE_INPUT                  },
     141             :     {RES_MACROFLD,      SW_SERVICE_FIELDTYPE_MACRO                  },
     142             :     {RES_DDEFLD,        SW_SERVICE_FIELDTYPE_DDE                    },
     143             :     {RES_HIDDENPARAFLD,     SW_SERVICE_FIELDTYPE_HIDDEN_PARA        }    ,
     144             :     {RES_DOCINFOFLD,    SW_SERVICE_FIELDTYPE_DOC_INFO               },
     145             :     {RES_TEMPLNAMEFLD,  SW_SERVICE_FIELDTYPE_TEMPLATE_NAME          },
     146             :     {RES_EXTUSERFLD,    SW_SERVICE_FIELDTYPE_USER_EXT               },
     147             :     {RES_REFPAGESETFLD,     SW_SERVICE_FIELDTYPE_REF_PAGE_SET       }    ,
     148             :     {RES_REFPAGEGETFLD,     SW_SERVICE_FIELDTYPE_REF_PAGE_GET       }    ,
     149             :     {RES_JUMPEDITFLD,   SW_SERVICE_FIELDTYPE_JUMP_EDIT              },
     150             :     {RES_SCRIPTFLD,         SW_SERVICE_FIELDTYPE_SCRIPT             }    ,
     151             :     {RES_DBNEXTSETFLD,  SW_SERVICE_FIELDTYPE_DATABASE_NEXT_SET      },
     152             :     {RES_DBNUMSETFLD,   SW_SERVICE_FIELDTYPE_DATABASE_NUM_SET       },
     153             :     {RES_DBSETNUMBERFLD, SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM      } ,
     154             :     {RES_DBFLD,             SW_SERVICE_FIELDTYPE_DATABASE           }    ,
     155             :     {RES_DBNAMEFLD,     SW_SERVICE_FIELDTYPE_DATABASE_NAME          },
     156             :     {RES_DOCSTATFLD,    SW_SERVICE_FIELDTYPE_PAGE_COUNT             },
     157             :     {RES_DOCSTATFLD,    SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT        },
     158             :     {RES_DOCSTATFLD,    SW_SERVICE_FIELDTYPE_WORD_COUNT             },
     159             :     {RES_DOCSTATFLD,    SW_SERVICE_FIELDTYPE_CHARACTER_COUNT        },
     160             :     {RES_DOCSTATFLD,    SW_SERVICE_FIELDTYPE_TABLE_COUNT            },
     161             :     {RES_DOCSTATFLD,    SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT   },
     162             :     {RES_DOCSTATFLD,    SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT  },
     163             :     {RES_DOCINFOFLD,    SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR  },
     164             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME},
     165             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME       },
     166             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION     },
     167             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR   },
     168             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME},
     169             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM          },
     170             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR    },
     171             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME },
     172             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS       },
     173             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT         },
     174             :     {RES_DOCINFOFLD,        SW_SERVICE_FIELDTYPE_DOCINFO_TITLE           },
     175             :     {RES_INPUTFLD,      SW_SERVICE_FIELDTYPE_INPUT_USER                  },
     176             :     {RES_HIDDENTXTFLD,  SW_SERVICE_FIELDTYPE_HIDDEN_TEXT                 },
     177             :     {RES_AUTHORITY,     SW_SERVICE_FIELDTYPE_BIBLIOGRAPHY                },
     178             :     {RES_COMBINED_CHARS,    SW_SERVICE_FIELDTYPE_COMBINED_CHARACTERS     },
     179             :     {RES_DROPDOWN,  SW_SERVICE_FIELDTYPE_DROPDOWN                        },
     180             :     {RES_TABLEFLD,      SW_SERVICE_FIELDTYPE_TABLE_FORMULA              },
     181             :     {USHRT_MAX,         USHRT_MAX                                        }
     182             : };
     183             : 
     184          49 : static sal_uInt16 lcl_ServiceIdToResId(sal_uInt16 nServiceId)
     185             : {
     186          49 :     const ServiceIdResId* pMap = aServiceToRes;
     187         263 :     while( USHRT_MAX != pMap->nServiceId && nServiceId != pMap->nServiceId )
     188         165 :             ++pMap;
     189             : #if OSL_DEBUG_LEVEL > 0
     190             :     if( USHRT_MAX == pMap->nServiceId )
     191             :         OSL_FAIL("service id not found");
     192             : #endif
     193          49 :     return pMap->nResId;
     194             : }
     195             : 
     196         768 : static sal_uInt16 lcl_GetServiceForField( const SwField& rFld )
     197             : {
     198         768 :     sal_uInt16 nWhich = rFld.Which(), nSrvId = USHRT_MAX;
     199             :     //special handling for some fields
     200         768 :     switch( nWhich )
     201             :     {
     202             :     case RES_INPUTFLD:
     203           0 :         if( INP_USR == (rFld.GetSubType() & 0x00ff) )
     204           0 :             nSrvId = SW_SERVICE_FIELDTYPE_INPUT_USER;
     205           0 :         break;
     206             : 
     207             :     case RES_DOCINFOFLD:
     208             :         {
     209          12 :             sal_uInt16 nSubType = rFld.GetSubType();
     210          12 :             switch( (nSubType & 0xff))
     211             :             {
     212             :             case DI_CHANGE:
     213           6 :                 nSrvId = ((nSubType&0x300) == DI_SUB_AUTHOR)
     214             :                         ? SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR
     215           6 :                         : SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME;
     216           6 :                 break;
     217             :             case DI_CREATE:
     218           0 :                 nSrvId = ((nSubType&0x300) == DI_SUB_AUTHOR)
     219             :                         ? SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR
     220           0 :                         : SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME;
     221           0 :                 break;
     222             :             case DI_PRINT:
     223           0 :                 nSrvId = ((nSubType&0x300) == DI_SUB_AUTHOR)
     224             :                         ? SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR
     225           0 :                         : SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME;
     226           0 :                 break;
     227           0 :             case DI_EDIT:   nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME;break;
     228           0 :             case DI_COMMENT:nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION;break;
     229           0 :             case DI_KEYS:   nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS;break;
     230           0 :             case DI_THEMA:  nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT;  break;
     231           0 :             case DI_TITEL:  nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_TITLE;    break;
     232           6 :             case DI_DOCNO:  nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_REVISION; break;
     233           0 :             case DI_CUSTOM: nSrvId = SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM;   break;
     234             :             }
     235             :         }
     236          12 :         break;
     237             : 
     238             :     case RES_HIDDENTXTFLD:
     239           0 :         nSrvId = TYP_CONDTXTFLD == rFld.GetSubType()
     240             :                         ? SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT
     241           0 :                         : SW_SERVICE_FIELDTYPE_HIDDEN_TEXT;
     242           0 :         break;
     243             : 
     244             :     case RES_DOCSTATFLD:
     245             :         {
     246          56 :             switch( rFld.GetSubType() )
     247             :             {
     248          56 :             case DS_PAGE: nSrvId = SW_SERVICE_FIELDTYPE_PAGE_COUNT; break;
     249           0 :             case DS_PARA: nSrvId = SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT; break;
     250           0 :             case DS_WORD: nSrvId = SW_SERVICE_FIELDTYPE_WORD_COUNT     ; break;
     251           0 :             case DS_CHAR: nSrvId = SW_SERVICE_FIELDTYPE_CHARACTER_COUNT; break;
     252           0 :             case DS_TBL:  nSrvId = SW_SERVICE_FIELDTYPE_TABLE_COUNT    ; break;
     253           0 :             case DS_GRF:  nSrvId = SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT; break;
     254           0 :             case DS_OLE:  nSrvId = SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT; break;
     255             :             }
     256             :         }
     257          56 :         break;
     258             :     }
     259         768 :     if( USHRT_MAX == nSrvId )
     260             :     {
     261       12154 :         for( const ServiceIdResId* pMap = aServiceToRes;
     262        6077 :                 USHRT_MAX != pMap->nResId; ++pMap )
     263        6077 :             if( nWhich == pMap->nResId )
     264             :             {
     265         700 :                 nSrvId = pMap->nServiceId;
     266         700 :                 break;
     267             :             }
     268             :     }
     269             : #if OSL_DEBUG_LEVEL > 0
     270             :     if( USHRT_MAX == nSrvId )
     271             :         OSL_FAIL("resid not found");
     272             : #endif
     273         768 :     return nSrvId;
     274             : }
     275             : 
     276        1183 : static sal_uInt16 lcl_GetPropMapIdForFieldType( sal_uInt16 nWhich )
     277             : {
     278             :     sal_uInt16 nId;
     279        1183 :     switch( nWhich )
     280             :     {
     281          45 :     case RES_USERFLD:   nId = PROPERTY_MAP_FLDMSTR_USER;            break;
     282          18 :     case RES_DBFLD:     nId = PROPERTY_MAP_FLDMSTR_DATABASE;        break;
     283        1099 :     case RES_SETEXPFLD: nId = PROPERTY_MAP_FLDMSTR_SET_EXP;         break;
     284           0 :     case RES_DDEFLD:    nId = PROPERTY_MAP_FLDMSTR_DDE;             break;
     285          21 :     case RES_AUTHORITY: nId = PROPERTY_MAP_FLDMSTR_BIBLIOGRAPHY;    break;
     286           0 :     default:            nId = PROPERTY_MAP_FLDMSTR_DUMMY0;
     287             :     }
     288        1183 :     return nId;
     289             : }
     290             : 
     291        1181 : sal_uInt16 GetFieldTypeMId( const OUString& rProperty, const SwFieldType& rTyp )
     292             : {
     293        1181 :     sal_uInt16 nId = lcl_GetPropMapIdForFieldType( rTyp.Which() );
     294        1181 :     const SfxItemPropertySet* pSet = aSwMapProvider.GetPropertySet( nId );
     295        1181 :     if( !pSet )
     296           0 :         nId = USHRT_MAX;
     297             :     else
     298             :     {
     299        1181 :         const SfxItemPropertySimpleEntry* pEntry = pSet->getPropertyMap().getByName(rProperty);
     300        1181 :         nId = pEntry ? pEntry->nWID : USHRT_MAX;
     301             :     }
     302        1181 :     return nId;
     303             : }
     304             : 
     305        1874 : static sal_uInt16 lcl_GetPropertyMapOfService( sal_uInt16 nServiceId )
     306             : {
     307             :     sal_uInt16 nRet;
     308        1874 :     switch ( nServiceId)
     309             :     {
     310          87 :     case SW_SERVICE_FIELDTYPE_DATETIME: nRet = PROPERTY_MAP_FLDTYP_DATETIME; break;
     311           2 :     case SW_SERVICE_FIELDTYPE_USER: nRet = PROPERTY_MAP_FLDTYP_USER; break;
     312         317 :     case SW_SERVICE_FIELDTYPE_SET_EXP: nRet = PROPERTY_MAP_FLDTYP_SET_EXP; break;
     313          24 :     case SW_SERVICE_FIELDTYPE_GET_EXP: nRet = PROPERTY_MAP_FLDTYP_GET_EXP; break;
     314          48 :     case SW_SERVICE_FIELDTYPE_FILE_NAME: nRet = PROPERTY_MAP_FLDTYP_FILE_NAME; break;
     315         628 :     case SW_SERVICE_FIELDTYPE_PAGE_NUM: nRet = PROPERTY_MAP_FLDTYP_PAGE_NUM; break;
     316          97 :     case SW_SERVICE_FIELDTYPE_AUTHOR: nRet = PROPERTY_MAP_FLDTYP_AUTHOR; break;
     317           0 :     case SW_SERVICE_FIELDTYPE_CHAPTER: nRet = PROPERTY_MAP_FLDTYP_CHAPTER; break;
     318         195 :     case SW_SERVICE_FIELDTYPE_GET_REFERENCE: nRet = PROPERTY_MAP_FLDTYP_GET_REFERENCE; break;
     319           0 :     case SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT: nRet = PROPERTY_MAP_FLDTYP_CONDITIONED_TEXT; break;
     320         217 :     case SW_SERVICE_FIELDTYPE_ANNOTATION: nRet = PROPERTY_MAP_FLDTYP_ANNOTATION; break;
     321             :     case SW_SERVICE_FIELDTYPE_INPUT_USER:
     322           4 :     case SW_SERVICE_FIELDTYPE_INPUT: nRet = PROPERTY_MAP_FLDTYP_INPUT; break;
     323          10 :     case SW_SERVICE_FIELDTYPE_MACRO: nRet = PROPERTY_MAP_FLDTYP_MACRO; break;
     324           0 :     case SW_SERVICE_FIELDTYPE_DDE: nRet = PROPERTY_MAP_FLDTYP_DDE; break;
     325           0 :     case SW_SERVICE_FIELDTYPE_HIDDEN_PARA: nRet = PROPERTY_MAP_FLDTYP_HIDDEN_PARA; break;
     326           0 :     case SW_SERVICE_FIELDTYPE_DOC_INFO: nRet = PROPERTY_MAP_FLDTYP_DOC_INFO; break;
     327           0 :     case SW_SERVICE_FIELDTYPE_TEMPLATE_NAME: nRet = PROPERTY_MAP_FLDTYP_TEMPLATE_NAME; break;
     328           0 :     case SW_SERVICE_FIELDTYPE_USER_EXT: nRet = PROPERTY_MAP_FLDTYP_USER_EXT; break;
     329           0 :     case SW_SERVICE_FIELDTYPE_REF_PAGE_SET: nRet = PROPERTY_MAP_FLDTYP_REF_PAGE_SET; break;
     330           0 :     case SW_SERVICE_FIELDTYPE_REF_PAGE_GET: nRet = PROPERTY_MAP_FLDTYP_REF_PAGE_GET; break;
     331          31 :     case SW_SERVICE_FIELDTYPE_JUMP_EDIT: nRet = PROPERTY_MAP_FLDTYP_JUMP_EDIT; break;
     332           0 :     case SW_SERVICE_FIELDTYPE_SCRIPT: nRet = PROPERTY_MAP_FLDTYP_SCRIPT; break;
     333           0 :     case SW_SERVICE_FIELDTYPE_DATABASE_NEXT_SET: nRet = PROPERTY_MAP_FLDTYP_DATABASE_NEXT_SET; break;
     334           0 :     case SW_SERVICE_FIELDTYPE_DATABASE_NUM_SET: nRet = PROPERTY_MAP_FLDTYP_DATABASE_NUM_SET; break;
     335           0 :     case SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM: nRet = PROPERTY_MAP_FLDTYP_DATABASE_SET_NUM; break;
     336          58 :     case SW_SERVICE_FIELDTYPE_DATABASE: nRet = PROPERTY_MAP_FLDTYP_DATABASE; break;
     337           0 :     case SW_SERVICE_FIELDTYPE_DATABASE_NAME: nRet = PROPERTY_MAP_FLDTYP_DATABASE_NAME; break;
     338           0 :     case SW_SERVICE_FIELDTYPE_TABLE_FORMULA: nRet = PROPERTY_MAP_FLDTYP_TABLE_FORMULA; break;
     339             :     case SW_SERVICE_FIELDTYPE_PAGE_COUNT:
     340             :     case SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT:
     341             :     case SW_SERVICE_FIELDTYPE_WORD_COUNT:
     342             :     case SW_SERVICE_FIELDTYPE_CHARACTER_COUNT:
     343             :     case SW_SERVICE_FIELDTYPE_TABLE_COUNT:
     344             :     case SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT:
     345          70 :     case SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT: nRet = PROPERTY_MAP_FLDTYP_DOCSTAT; break;
     346             :     case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR:
     347             :     case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR:
     348           6 :     case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_AUTHOR; break;
     349             :     case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME:
     350             :     case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME:
     351           0 :     case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_DATE_TIME; break;
     352           0 :     case SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_EDIT_TIME; break;
     353           0 :     case SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_CUSTOM; break;
     354             :     case SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION:
     355             :     case SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS:
     356             :     case SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT:
     357           4 :     case SW_SERVICE_FIELDTYPE_DOCINFO_TITLE: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_MISC; break;
     358           6 :     case SW_SERVICE_FIELDTYPE_DOCINFO_REVISION: nRet = PROPERTY_MAP_FLDTYP_DOCINFO_REVISION; break;
     359          70 :     case SW_SERVICE_FIELDTYPE_BIBLIOGRAPHY: nRet = PROPERTY_MAP_FLDTYP_BIBLIOGRAPHY; break;
     360             :     case SW_SERVICE_FIELDTYPE_DUMMY_0:
     361           0 :     case SW_SERVICE_FIELDTYPE_COMBINED_CHARACTERS: nRet = PROPERTY_MAP_FLDTYP_COMBINED_CHARACTERS; break;
     362           0 :     case SW_SERVICE_FIELDTYPE_DROPDOWN: nRet = PROPERTY_MAP_FLDTYP_DROPDOWN; break;
     363             :     case SW_SERVICE_FIELDTYPE_DUMMY_4:
     364             :     case SW_SERVICE_FIELDTYPE_DUMMY_5:
     365             :     case SW_SERVICE_FIELDTYPE_DUMMY_6:
     366             :     case SW_SERVICE_FIELDTYPE_DUMMY_7:
     367           0 :                 nRet = PROPERTY_MAP_FLDTYP_DUMMY_0; break;
     368           0 :     case SW_SERVICE_FIELDMASTER_USER: nRet = PROPERTY_MAP_FLDMSTR_USER; break;
     369           0 :     case SW_SERVICE_FIELDMASTER_DDE: nRet = PROPERTY_MAP_FLDMSTR_DDE; break;
     370           0 :     case SW_SERVICE_FIELDMASTER_SET_EXP: nRet = PROPERTY_MAP_FLDMSTR_SET_EXP; break;
     371           0 :     case SW_SERVICE_FIELDMASTER_DATABASE: nRet = PROPERTY_MAP_FLDMSTR_DATABASE; break;
     372           0 :     case SW_SERVICE_FIELDMASTER_BIBLIOGRAPHY: nRet = PROPERTY_MAP_FLDMSTR_BIBLIOGRAPHY; break;
     373             :     case SW_SERVICE_FIELDMASTER_DUMMY2:
     374             :     case SW_SERVICE_FIELDMASTER_DUMMY3:
     375             :     case SW_SERVICE_FIELDMASTER_DUMMY4:
     376           0 :     case SW_SERVICE_FIELDMASTER_DUMMY5: nRet = PROPERTY_MAP_FLDMSTR_DUMMY0; break;
     377           0 :     case SW_SERVICE_FIELDTYPE_HIDDEN_TEXT: nRet = PROPERTY_MAP_FLDTYP_HIDDEN_TEXT; break;
     378             :     default:
     379             :         OSL_FAIL( "wrong service id" );
     380           0 :         nRet = USHRT_MAX;
     381             :     }
     382        1874 :     return nRet;
     383             : }
     384             : 
     385             : /******************************************************************
     386             :  * SwXFieldMaster
     387             :  ******************************************************************/
     388             : 
     389        1400 : class SwXFieldMaster::Impl
     390             :     : public SwClient
     391             : {
     392             : private:
     393             :     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
     394             :     SwXFieldMaster & m_rThis;
     395             : 
     396             : public:
     397             :     ::cppu::OInterfaceContainerHelper m_EventListeners;
     398             : 
     399             :     SwDoc*          m_pDoc;
     400             : 
     401             :     bool            m_bIsDescriptor;
     402             : 
     403             :     sal_uInt16      m_nResTypeId;
     404             : 
     405             :     OUString        m_sParam1;  // Content / Database / NumberingSeparator
     406             :     OUString        m_sParam2;  // -    /DataTablename
     407             :     OUString        m_sParam3;  // -    /DataFieldName
     408             :     OUString        m_sParam4;
     409             :     OUString        m_sParam5;  // -    /DataBaseURL
     410             :     OUString        m_sParam6;  // -    /DataBaseResource
     411             :     double          m_fParam1;  // Value / -
     412             :     sal_Int8        m_nParam1;  // ChapterNumberingLevel
     413             :     sal_Bool        m_bParam1;  // IsExpression
     414             :     sal_Int32       m_nParam2;
     415             : 
     416         700 :     Impl(SwXFieldMaster & rThis, SwModify *const pModify,
     417             :             SwDoc & rDoc, sal_uInt16 const nResId, bool const bIsDescriptor)
     418             :         : SwClient(pModify)
     419             :         , m_rThis(rThis)
     420             :         , m_EventListeners(m_Mutex)
     421             :         , m_pDoc(& rDoc)
     422             :         , m_bIsDescriptor(bIsDescriptor)
     423             :         , m_nResTypeId(nResId)
     424             :         , m_fParam1(0.0)
     425             :         , m_nParam1(-1)
     426             :         , m_bParam1(sal_False)
     427         700 :         , m_nParam2(0)
     428         700 :     { }
     429             : 
     430             : protected:
     431             :     // SwClient
     432             :     virtual void Modify(SfxPoolItem const* pOld, SfxPoolItem const* pNew) SAL_OVERRIDE;
     433             : };
     434             : 
     435             : namespace
     436             : {
     437             :     class theSwXFieldMasterUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXFieldMasterUnoTunnelId > {};
     438             : }
     439             : 
     440          99 : const uno::Sequence< sal_Int8 > & SwXFieldMaster::getUnoTunnelId()
     441             : {
     442          99 :     return theSwXFieldMasterUnoTunnelId::get().getSeq();
     443             : }
     444             : 
     445             : sal_Int64 SAL_CALL
     446          50 : SwXFieldMaster::getSomething(const uno::Sequence< sal_Int8 >& rId)
     447             : throw (uno::RuntimeException, std::exception)
     448             : {
     449          50 :     return ::sw::UnoTunnelImpl<SwXFieldMaster>(rId, this);
     450             : }
     451             : 
     452             : OUString SAL_CALL
     453           0 : SwXFieldMaster::getImplementationName()
     454             : throw (uno::RuntimeException, std::exception)
     455             : {
     456           0 :     return OUString("SwXFieldMaster");
     457             : }
     458             : 
     459             : namespace
     460             : {
     461             : 
     462           0 : OUString getServiceName(const sal_uInt16 aId)
     463             : {
     464             :     const sal_Char* pEntry;
     465           0 :     switch (aId)
     466             :     {
     467             :         case RES_USERFLD:
     468           0 :             pEntry = "User";
     469           0 :             break;
     470             :         case RES_DBFLD:
     471           0 :             pEntry = "Database";
     472           0 :             break;
     473             :         case RES_SETEXPFLD:
     474           0 :             pEntry = "SetExpression";
     475           0 :             break;
     476             :         case RES_DDEFLD:
     477           0 :             pEntry = "DDE";
     478           0 :             break;
     479             :         case RES_AUTHORITY:
     480           0 :             pEntry = "Bibliography";
     481           0 :             break;
     482             :         default:
     483           0 :             return OUString();
     484             :     }
     485             : 
     486           0 :     return "com.sun.star.text.fieldmaster." + OUString::createFromAscii(pEntry);
     487             : }
     488             : 
     489             : }
     490             : 
     491           0 : sal_Bool SAL_CALL SwXFieldMaster::supportsService(const OUString& rServiceName)
     492             : throw (uno::RuntimeException, std::exception)
     493             : {
     494           0 :     return cppu::supportsService(this, rServiceName);
     495             : }
     496             : 
     497             : uno::Sequence< OUString > SAL_CALL
     498           0 : SwXFieldMaster::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
     499             : {
     500           0 :     uno::Sequence< OUString > aRet(2);
     501           0 :     OUString* pArray = aRet.getArray();
     502           0 :     pArray[0] = "com.sun.star.text.TextFieldMaster";
     503           0 :     pArray[1] = getServiceName(m_pImpl->m_nResTypeId);
     504           0 :     return aRet;
     505             : }
     506             : 
     507          42 : SwXFieldMaster::SwXFieldMaster(SwDoc *const pDoc, sal_uInt16 const nResId)
     508          42 :     : m_pImpl(new Impl(*this, pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD),
     509          84 :                 *pDoc, nResId, true))
     510             : {
     511          42 : }
     512             : 
     513         658 : SwXFieldMaster::SwXFieldMaster(SwFieldType& rType, SwDoc & rDoc)
     514         658 :     : m_pImpl(new Impl(*this, &rType, rDoc, rType.Which(), false))
     515             : {
     516         658 : }
     517             : 
     518        1400 : SwXFieldMaster::~SwXFieldMaster()
     519             : {
     520        1400 : }
     521             : 
     522             : uno::Reference<beans::XPropertySet>
     523         658 : SwXFieldMaster::CreateXFieldMaster(SwDoc & rDoc, SwFieldType & rType)
     524             : {
     525             :     // re-use existing SwXFieldMaster
     526         658 :     uno::Reference<beans::XPropertySet> xFM(rType.GetXObject());
     527         658 :     if (!xFM.is())
     528             :     {
     529         658 :         SwXFieldMaster *const pFM(new SwXFieldMaster(rType, rDoc));
     530         658 :         xFM.set(pFM);
     531         658 :         rType.SetXObject(xFM);
     532             :     }
     533         658 :     return xFM;
     534             : }
     535             : 
     536             : uno::Reference<beans::XPropertySetInfo> SAL_CALL
     537           2 : SwXFieldMaster::getPropertySetInfo()
     538             : throw (uno::RuntimeException, std::exception)
     539             : {
     540           2 :     SolarMutexGuard aGuard;
     541             :     uno::Reference< beans::XPropertySetInfo >  aRef =
     542             :                         aSwMapProvider.GetPropertySet(
     543           2 :             lcl_GetPropMapIdForFieldType(m_pImpl->m_nResTypeId))->getPropertySetInfo();
     544           2 :     return aRef;
     545             : }
     546             : 
     547         606 : void SAL_CALL SwXFieldMaster::setPropertyValue(
     548             :         const OUString& rPropertyName, const uno::Any& rValue)
     549             : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
     550             :        lang::IllegalArgumentException, lang::WrappedTargetException,
     551             :        uno::RuntimeException, std::exception)
     552             : {
     553         606 :     SolarMutexGuard aGuard;
     554         606 :     SwFieldType* pType = GetFldType(true);
     555         606 :     if(pType)
     556             :     {
     557         555 :         bool bSetValue = true;
     558         555 :         if( rPropertyName == UNO_NAME_SUB_TYPE )
     559             :         {
     560             :             const ::std::vector<OUString>& rExtraArr(
     561          43 :                     SwStyleNameMapper::GetExtraUINameArray());
     562          43 :             OUString sTypeName = pType->GetName();
     563             :             static sal_uInt16 nIds[] =
     564             :             {
     565             :                 RES_POOLCOLL_LABEL_DRAWING - RES_POOLCOLL_EXTRA_BEGIN,
     566             :                 RES_POOLCOLL_LABEL_ABB - RES_POOLCOLL_EXTRA_BEGIN,
     567             :                 RES_POOLCOLL_LABEL_TABLE - RES_POOLCOLL_EXTRA_BEGIN,
     568             :                 RES_POOLCOLL_LABEL_FRAME- RES_POOLCOLL_EXTRA_BEGIN,
     569             :                 0
     570             :             };
     571         179 :             for(const sal_uInt16 * pIds = nIds; *pIds; ++pIds)
     572             :             {
     573         151 :                 if(sTypeName == rExtraArr[ *pIds ] )
     574             :                 {
     575          15 :                     bSetValue = false;
     576          15 :                     break;
     577             :                 }
     578          43 :             }
     579             :         }
     580         555 :         if ( bSetValue )
     581             :         {
     582             :             // nothing special to be done here for the properties
     583             :             // UNO_NAME_DATA_BASE_NAME and UNO_NAME_DATA_BASE_URL.
     584             :             // We just call PutValue (empty string is allowed).
     585             :             // Thus the last property set will be used as Data Source.
     586             : 
     587         540 :             const sal_uInt16 nMemberValueId = GetFieldTypeMId( rPropertyName, *pType );
     588         540 :             if ( USHRT_MAX != nMemberValueId )
     589             :             {
     590         540 :                 pType->PutValue( rValue, nMemberValueId );
     591         540 :                 if ( pType->Which() == RES_USERFLD )
     592             :                 {
     593             :                     // trigger update of User field in order to get depending Input Fields updated.
     594          45 :                     pType->UpdateFlds();
     595             :                 }
     596             :             }
     597             :             else
     598             :             {
     599             :                 throw beans::UnknownPropertyException(
     600           0 :                     OUString( "Unknown property: " ) + rPropertyName,
     601           0 :                     static_cast< cppu::OWeakObject * >( this ) );
     602             :             }
     603             :         }
     604             :     }
     605          51 :     else if (!pType && m_pImpl->m_pDoc && rPropertyName == UNO_NAME_NAME)
     606             :     {
     607          38 :         OUString uTmp;
     608          38 :         rValue >>= uTmp;
     609          76 :         OUString sTypeName(uTmp);
     610          38 :         SwFieldType * pType2 = m_pImpl->m_pDoc->GetFldType(
     611          38 :                 m_pImpl->m_nResTypeId, sTypeName, false);
     612             : 
     613          76 :         OUString sTable(SW_RES(STR_POOLCOLL_LABEL_TABLE));
     614          76 :         OUString sDrawing(SW_RES(STR_POOLCOLL_LABEL_DRAWING));
     615          76 :         OUString sFrame(SW_RES(STR_POOLCOLL_LABEL_FRAME));
     616          76 :         OUString sIllustration(SW_RES(STR_POOLCOLL_LABEL_ABB));
     617             : 
     618          76 :         if(pType2 ||
     619          53 :             (RES_SETEXPFLD == m_pImpl->m_nResTypeId &&
     620          45 :             ( sTypeName == sTable || sTypeName == sDrawing ||
     621          30 :               sTypeName == sFrame || sTypeName == sIllustration )))
     622             :         {
     623           0 :             throw lang::IllegalArgumentException();
     624             :         }
     625             : 
     626          38 :         switch (m_pImpl->m_nResTypeId)
     627             :         {
     628             :             case RES_USERFLD :
     629             :             {
     630          23 :                 SwUserFieldType aType(m_pImpl->m_pDoc, sTypeName);
     631          23 :                 pType2 = m_pImpl->m_pDoc->InsertFldType(aType);
     632          23 :                 static_cast<SwUserFieldType*>(pType2)->SetContent(m_pImpl->m_sParam1);
     633          23 :                 static_cast<SwUserFieldType*>(pType2)->SetValue(m_pImpl->m_fParam1);
     634          23 :                 static_cast<SwUserFieldType*>(pType2)->SetType(m_pImpl->m_bParam1
     635          23 :                     ? nsSwGetSetExpType::GSE_EXPR : nsSwGetSetExpType::GSE_STRING);
     636             :             }
     637          23 :             break;
     638             :             case RES_DDEFLD :
     639             :             {
     640           0 :                 SwDDEFieldType aType(sTypeName, m_pImpl->m_sParam1,
     641           0 :                     sal::static_int_cast<sal_uInt16>((m_pImpl->m_bParam1)
     642           0 :                         ? sfx2::LINKUPDATE_ALWAYS : sfx2::LINKUPDATE_ONCALL));
     643           0 :                 pType2 = m_pImpl->m_pDoc->InsertFldType(aType);
     644             :             }
     645           0 :             break;
     646             :             case RES_SETEXPFLD :
     647             :             {
     648          15 :                 SwSetExpFieldType aType(m_pImpl->m_pDoc, sTypeName);
     649          15 :                 if (!m_pImpl->m_sParam1.isEmpty())
     650           0 :                     aType.SetDelimiter(OUString(m_pImpl->m_sParam1[0]));
     651          15 :                 if (m_pImpl->m_nParam1 > -1 && m_pImpl->m_nParam1 < MAXLEVEL)
     652           0 :                     aType.SetOutlineLvl(m_pImpl->m_nParam1);
     653          15 :                 pType2 = m_pImpl->m_pDoc->InsertFldType(aType);
     654             :             }
     655          15 :             break;
     656             :             case RES_DBFLD :
     657             :             {
     658           0 :                 rValue >>= m_pImpl->m_sParam3;
     659           0 :                 pType2 = GetFldType();
     660             :             }
     661           0 :             break;
     662             :         }
     663          38 :         if (!pType2)
     664             :         {
     665           0 :             throw uno::RuntimeException("no field type found!", *this);
     666             :         }
     667          38 :         pType2->Add(m_pImpl.get());
     668          76 :         m_pImpl->m_bIsDescriptor = false;
     669             :     }
     670             :     else
     671             :     {
     672          13 :         switch (m_pImpl->m_nResTypeId)
     673             :         {
     674             :         case RES_USERFLD:
     675           0 :             if(rPropertyName == UNO_NAME_CONTENT)
     676           0 :                 rValue >>= m_pImpl->m_sParam1;
     677           0 :             else if(rPropertyName == UNO_NAME_VALUE)
     678             :             {
     679           0 :                 if(rValue.getValueType() != ::getCppuType(static_cast<const double*>(0)))
     680           0 :                     throw lang::IllegalArgumentException();
     681           0 :                 rValue >>= m_pImpl->m_fParam1;
     682             :             }
     683           0 :             else if(rPropertyName == UNO_NAME_IS_EXPRESSION)
     684             :             {
     685           0 :                 if(rValue.getValueType() != ::getBooleanCppuType())
     686           0 :                     throw lang::IllegalArgumentException();
     687           0 :                 rValue >>= m_pImpl->m_bParam1;
     688             :             }
     689             : 
     690           0 :             break;
     691             :         case RES_DBFLD:
     692          13 :             if(rPropertyName == UNO_NAME_DATA_BASE_NAME)
     693           4 :                 rValue >>= m_pImpl->m_sParam1;
     694           9 :             else if(rPropertyName == UNO_NAME_DATA_TABLE_NAME)
     695           4 :                 rValue >>= m_pImpl->m_sParam2;
     696           5 :             else if(rPropertyName == UNO_NAME_DATA_COLUMN_NAME)
     697           4 :                 rValue >>= m_pImpl->m_sParam3;
     698           1 :             else if(rPropertyName == UNO_NAME_DATA_COMMAND_TYPE)
     699           1 :                 rValue >>= m_pImpl->m_nParam2;
     700          13 :             if(rPropertyName == UNO_NAME_DATA_BASE_URL)
     701           0 :                 rValue >>= m_pImpl->m_sParam5;
     702             : 
     703          26 :             if (  (   !m_pImpl->m_sParam1.isEmpty()
     704           3 :                    || !m_pImpl->m_sParam5.isEmpty())
     705          10 :                 && !m_pImpl->m_sParam2.isEmpty()
     706          20 :                 && !m_pImpl->m_sParam3.isEmpty())
     707             :             {
     708           4 :                 GetFldType();
     709             :             }
     710          13 :             break;
     711             :         case  RES_SETEXPFLD:
     712           0 :             if(rPropertyName == UNO_NAME_NUMBERING_SEPARATOR)
     713           0 :                 rValue >>= m_pImpl->m_sParam1;
     714           0 :             else if(rPropertyName == UNO_NAME_CHAPTER_NUMBERING_LEVEL)
     715           0 :                 rValue >>= m_pImpl->m_nParam1;
     716           0 :             break;
     717             :         case RES_DDEFLD:
     718             :             {
     719           0 :                 sal_uInt16 nPart = rPropertyName == UNO_NAME_DDE_COMMAND_TYPE ? 0 :
     720           0 :                         rPropertyName == UNO_NAME_DDE_COMMAND_FILE ? 1 :
     721           0 :                         rPropertyName == UNO_NAME_DDE_COMMAND_ELEMENT ? 2 :
     722           0 :                         rPropertyName == UNO_NAME_IS_AUTOMATIC_UPDATE ? 3 : USHRT_MAX;
     723           0 :                 if(nPart  < 3 )
     724             :                 {
     725           0 :                     if (m_pImpl->m_sParam1.isEmpty())
     726             :                     {
     727           0 :                         m_pImpl->m_sParam1 = OUString(sfx2::cTokenSeparator)
     728           0 :                                 + OUString(sfx2::cTokenSeparator);
     729             :                     }
     730           0 :                     OUString sTmp;
     731           0 :                     rValue >>= sTmp;
     732           0 :                     sal_Int32 nIndex(0);
     733           0 :                     sal_Int32 nStart(0);
     734           0 :                     while (nIndex < m_pImpl->m_sParam1.getLength())
     735             :                     {
     736           0 :                         if (m_pImpl->m_sParam1[nIndex] == sfx2::cTokenSeparator)
     737             :                         {
     738           0 :                             if (0 == nPart)
     739           0 :                                 break;
     740           0 :                             nStart = nIndex + 1;
     741           0 :                             --nPart;
     742             :                         }
     743           0 :                         ++nIndex;
     744             :                     }
     745             :                     assert(0 == nPart);
     746           0 :                     m_pImpl->m_sParam1 = m_pImpl->m_sParam1.replaceAt(
     747           0 :                             nStart, nIndex - nStart, sTmp);
     748             :                 }
     749           0 :                 else if(3 == nPart)
     750             :                 {
     751           0 :                     rValue >>= m_pImpl->m_bParam1;
     752             :                 }
     753             :             }
     754           0 :             break;
     755             :         default:
     756           0 :             throw beans::UnknownPropertyException(OUString( "Unknown property: " ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     757             :         }
     758         606 :     }
     759         606 : }
     760             : 
     761        1309 : SwFieldType* SwXFieldMaster::GetFldType(bool const bDontCreate) const
     762             : {
     763        2671 :     if (!bDontCreate && RES_DBFLD == m_pImpl->m_nResTypeId
     764        1316 :         && m_pImpl->m_bIsDescriptor && m_pImpl->m_pDoc)
     765             :     {
     766           4 :         SwDBData aData;
     767             : 
     768             :         // set DataSource
     769           8 :         svx::ODataAccessDescriptor aAcc;
     770           4 :         if (!m_pImpl->m_sParam1.isEmpty())
     771           4 :             aAcc[svx::daDataSource]        <<= m_pImpl->m_sParam1; // DataBaseName
     772           0 :         else if (!m_pImpl->m_sParam5.isEmpty())
     773           0 :             aAcc[svx::daDatabaseLocation]  <<= m_pImpl->m_sParam5; // DataBaseURL
     774           4 :         aData.sDataSource = aAcc.getDataSource();
     775             : 
     776           4 :         aData.sCommand = m_pImpl->m_sParam2;
     777           4 :         aData.nCommandType = m_pImpl->m_nParam2;
     778           8 :         SwDBFieldType aType(m_pImpl->m_pDoc, m_pImpl->m_sParam3, aData);
     779           4 :         SwFieldType *const pType = m_pImpl->m_pDoc->InsertFldType(aType);
     780           4 :         pType->Add(m_pImpl.get());
     781           8 :         const_cast<SwXFieldMaster*>(this)->m_pImpl->m_bIsDescriptor = false;
     782             :     }
     783        1309 :     if (m_pImpl->m_bIsDescriptor)
     784          58 :         return 0;
     785             :     else
     786        1251 :         return static_cast<SwFieldType*>(const_cast<SwModify*>(m_pImpl->GetRegisteredIn()));
     787             : }
     788             : 
     789             : typedef std::vector<SwFmtFld*> SwDependentFields;
     790             : 
     791             : uno::Any SAL_CALL
     792         650 : SwXFieldMaster::getPropertyValue(const OUString& rPropertyName)
     793             : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
     794             :         uno::RuntimeException, std::exception)
     795             : {
     796         650 :     SolarMutexGuard aGuard;
     797         650 :     uno::Any aRet;
     798         650 :     SwFieldType* pType = GetFldType(true);
     799         650 :     if( rPropertyName == UNO_NAME_INSTANCE_NAME )
     800             :     {
     801           0 :         OUString sName;
     802           0 :         if(pType)
     803           0 :             SwXTextFieldMasters::getInstanceName(*pType, sName);
     804           0 :         aRet <<= sName;
     805             :     }
     806         650 :     else if(pType)
     807             :     {
     808         643 :         if(rPropertyName == UNO_NAME_NAME)
     809             :         {
     810           1 :             aRet <<= SwXFieldMaster::GetProgrammaticName(*pType, *m_pImpl->m_pDoc);
     811             :         }
     812         642 :         else if(rPropertyName == UNO_NAME_DEPENDENT_TEXT_FIELDS)
     813             :         {
     814             :             //fill all text fields into a sequence
     815           1 :             SwDependentFields aFldArr;
     816           2 :             SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
     817           1 :             SwFmtFld* pFld = aIter.First();
     818           4 :             while(pFld)
     819             :             {
     820           2 :                 if(pFld->IsFldInDoc())
     821           1 :                     aFldArr.push_back(pFld);
     822           2 :                 pFld = aIter.Next();
     823             :             }
     824             : 
     825           2 :             uno::Sequence<uno::Reference <text::XDependentTextField> > aRetSeq(aFldArr.size());
     826           1 :             uno::Reference<text::XDependentTextField>* pRetSeq = aRetSeq.getArray();
     827           2 :             for(sal_uInt16 i = 0; i < aFldArr.size(); i++)
     828             :             {
     829           1 :                 pFld = aFldArr[i];
     830             :                 uno::Reference<text::XTextField> const xField =
     831           1 :                     SwXTextField::CreateXTextField(*m_pImpl->m_pDoc, *pFld);
     832             : 
     833           2 :                 pRetSeq[i] = uno::Reference<text::XDependentTextField>(xField,
     834           1 :                         uno::UNO_QUERY);
     835           1 :             }
     836           2 :             aRet <<= aRetSeq;
     837             :         }
     838         641 :         else if(pType)
     839             :         {
     840             :             //TODO: Properties fuer die uebrigen Feldtypen einbauen
     841         641 :             sal_uInt16 nMId = GetFieldTypeMId( rPropertyName, *pType );
     842         641 :             if (USHRT_MAX == nMId)
     843             :             {
     844             :                 throw beans::UnknownPropertyException(
     845           0 :                         "Unknown property: " + rPropertyName,
     846           0 :                         static_cast<cppu::OWeakObject *>(this));
     847             :             }
     848         641 :             pType->QueryValue( aRet, nMId );
     849             : 
     850        1278 :             if (rPropertyName == UNO_NAME_DATA_BASE_NAME ||
     851         637 :                 rPropertyName == UNO_NAME_DATA_BASE_URL)
     852             :             {
     853           4 :                 OUString aDataSource;
     854           4 :                 aRet >>= aDataSource;
     855           4 :                 aRet <<= OUString();
     856             : 
     857           4 :                 OUString *pStr = 0;     // only one of this properties will return
     858             :                                         // a non-empty string.
     859           8 :                 INetURLObject aObj;
     860           4 :                 aObj.SetURL( aDataSource );
     861           4 :                 bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
     862           4 :                 if (bIsURL && rPropertyName == UNO_NAME_DATA_BASE_URL)
     863           0 :                     pStr = &aDataSource;        // DataBaseURL
     864           4 :                 else if (!bIsURL && rPropertyName == UNO_NAME_DATA_BASE_NAME)
     865           4 :                     pStr = &aDataSource;        // DataBaseName
     866             : 
     867           4 :                 if (pStr)
     868           8 :                     aRet <<= *pStr;
     869             :             }
     870             :         }
     871             :         else
     872             :         {
     873           0 :             if(rPropertyName == UNO_NAME_DATA_COMMAND_TYPE)
     874           0 :                 aRet <<= m_pImpl->m_nParam2;
     875             :         }
     876             :     }
     877             :     else
     878             :     {
     879           7 :         if(rPropertyName == UNO_NAME_DATA_COMMAND_TYPE)
     880           2 :             aRet <<= m_pImpl->m_nParam2;
     881           5 :         else if(rPropertyName == UNO_NAME_DEPENDENT_TEXT_FIELDS )
     882             :         {
     883           0 :             uno::Sequence<uno::Reference <text::XDependentTextField> > aRetSeq(0);
     884           0 :             aRet <<= aRetSeq;
     885             :         }
     886             :         else
     887             :         {
     888           5 :             switch (m_pImpl->m_nResTypeId)
     889             :             {
     890             :             case RES_USERFLD:
     891           0 :                 if( rPropertyName == UNO_NAME_CONTENT )
     892           0 :                     aRet <<= m_pImpl->m_sParam1;
     893           0 :                 else if(rPropertyName == UNO_NAME_VALUE)
     894           0 :                     aRet <<= m_pImpl->m_fParam1;
     895           0 :                 else if(rPropertyName == UNO_NAME_IS_EXPRESSION)
     896           0 :                     aRet.setValue(&m_pImpl->m_bParam1, ::getBooleanCppuType());
     897           0 :                 break;
     898             :             case RES_DBFLD:
     899           9 :                 if(rPropertyName == UNO_NAME_DATA_BASE_NAME ||
     900           4 :                    rPropertyName == UNO_NAME_DATA_BASE_URL)
     901             :                 {
     902             :                      // only one of these properties returns a non-empty string.
     903           1 :                     INetURLObject aObj;
     904           1 :                     aObj.SetURL(m_pImpl->m_sParam5); // SetSmartURL
     905           1 :                     bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
     906           1 :                     if (bIsURL && rPropertyName == UNO_NAME_DATA_BASE_URL)
     907           0 :                         aRet <<= m_pImpl->m_sParam5; // DataBaseURL
     908           1 :                     else if ( rPropertyName == UNO_NAME_DATA_BASE_NAME)
     909           1 :                         aRet <<= m_pImpl->m_sParam1; // DataBaseName
     910             :                 }
     911           4 :                 else if(rPropertyName == UNO_NAME_DATA_TABLE_NAME)
     912           2 :                     aRet <<= m_pImpl->m_sParam2;
     913           2 :                 else if(rPropertyName == UNO_NAME_DATA_COLUMN_NAME)
     914           2 :                     aRet <<= m_pImpl->m_sParam3;
     915           5 :                 break;
     916             :             case RES_SETEXPFLD:
     917           0 :                 if(rPropertyName == UNO_NAME_NUMBERING_SEPARATOR)
     918           0 :                     aRet <<= m_pImpl->m_sParam1;
     919           0 :                 else if(rPropertyName == UNO_NAME_CHAPTER_NUMBERING_LEVEL)
     920           0 :                     aRet <<= m_pImpl->m_nParam1;
     921           0 :                 break;
     922             :             case RES_DDEFLD:
     923             :                 {
     924           0 :                     sal_uInt16 nPart = rPropertyName == UNO_NAME_DDE_COMMAND_TYPE  ? 0 :
     925           0 :                         rPropertyName == UNO_NAME_DDE_COMMAND_FILE ? 1 :
     926           0 :                             rPropertyName == UNO_NAME_DDE_COMMAND_ELEMENT  ? 2 :
     927           0 :                             rPropertyName == UNO_NAME_IS_AUTOMATIC_UPDATE ? 3 : USHRT_MAX;
     928           0 :                     if(nPart  < 3 )
     929           0 :                         aRet <<= m_pImpl->m_sParam1.getToken(nPart, sfx2::cTokenSeparator);
     930           0 :                     else if(3 == nPart)
     931           0 :                         aRet.setValue(&m_pImpl->m_bParam1, ::getBooleanCppuType());
     932             :                 }
     933           0 :                 break;
     934             :             default:
     935           0 :                 throw beans::UnknownPropertyException(OUString( "Unknown property: " ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
     936             :             }
     937             :         }
     938             :     }
     939         650 :     return aRet;
     940             : }
     941             : 
     942           0 : void SwXFieldMaster::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     943             : {
     944             :     OSL_FAIL("not implemented");
     945           0 : }
     946             : 
     947           0 : void SwXFieldMaster::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     948             : {
     949             :     OSL_FAIL("not implemented");
     950           0 : }
     951             : 
     952           0 : void SwXFieldMaster::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     953             : {
     954             :     OSL_FAIL("not implemented");
     955           0 : }
     956             : 
     957           0 : void SwXFieldMaster::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     958             : {
     959             :     OSL_FAIL("not implemented");
     960           0 : }
     961             : 
     962           0 : void SAL_CALL SwXFieldMaster::dispose()
     963             : throw (uno::RuntimeException, std::exception)
     964             : {
     965           0 :     SolarMutexGuard aGuard;
     966           0 :     SwFieldType *const pFldType = GetFldType(true);
     967           0 :     if (!pFldType)
     968           0 :         throw uno::RuntimeException();
     969           0 :     sal_uInt16 nTypeIdx = USHRT_MAX;
     970           0 :     const SwFldTypes* pTypes = m_pImpl->m_pDoc->GetFldTypes();
     971           0 :     for( sal_uInt16 i = 0; i < pTypes->size(); i++ )
     972             :     {
     973           0 :         if((*pTypes)[i] == pFldType)
     974           0 :             nTypeIdx = i;
     975             :     }
     976             : 
     977             :     // zuerst alle Felder loeschen
     978           0 :     SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
     979           0 :     SwFmtFld* pFld = aIter.First();
     980           0 :     while(pFld)
     981             :     {
     982             :         // Feld im Undo?
     983           0 :         SwTxtFld *pTxtFld = pFld->GetTxtFld();
     984           0 :         if(pTxtFld && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
     985             :         {
     986           0 :             SwTxtNode& rTxtNode = (SwTxtNode&)*pTxtFld->GetpTxtNode();
     987           0 :             SwPaM aPam(rTxtNode, *pTxtFld->GetStart());
     988           0 :             aPam.SetMark();
     989           0 :             aPam.Move();
     990           0 :             m_pImpl->m_pDoc->DeleteAndJoin(aPam);
     991             :         }
     992           0 :         pFld = aIter.Next();
     993             :     }
     994             :     // dann den FieldType loeschen
     995           0 :     m_pImpl->m_pDoc->RemoveFldType(nTypeIdx);
     996           0 : }
     997             : 
     998           0 : void SAL_CALL SwXFieldMaster::addEventListener(
     999             :         const uno::Reference<lang::XEventListener> & xListener)
    1000             : throw (uno::RuntimeException, std::exception)
    1001             : {
    1002             :     // no need to lock here as m_pImpl is const and container threadsafe
    1003           0 :     m_pImpl->m_EventListeners.addInterface(xListener);
    1004           0 : }
    1005             : 
    1006           0 : void SAL_CALL SwXFieldMaster::removeEventListener(
    1007             :         const uno::Reference<lang::XEventListener> & xListener)
    1008             : throw (uno::RuntimeException, std::exception)
    1009             : {
    1010             :     // no need to lock here as m_pImpl is const and container threadsafe
    1011           0 :     m_pImpl->m_EventListeners.removeInterface(xListener);
    1012           0 : }
    1013             : 
    1014          51 : void SwXFieldMaster::Impl::Modify(
    1015             :         SfxPoolItem const*const pOld, SfxPoolItem const*const pNew)
    1016             : {
    1017          51 :     ClientModify(this, pOld, pNew);
    1018          51 :     if(!GetRegisteredIn())
    1019             :     {
    1020           5 :         m_pDoc = 0;
    1021           5 :         lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis));
    1022           5 :         m_EventListeners.disposeAndClear(ev);
    1023             :     }
    1024          51 : }
    1025             : 
    1026           1 : OUString SwXFieldMaster::GetProgrammaticName(const SwFieldType& rType, SwDoc& rDoc)
    1027             : {
    1028           1 :     OUString sRet(rType.GetName());
    1029           1 :     if(RES_SETEXPFLD == rType.Which())
    1030             :     {
    1031           1 :         const SwFldTypes* pTypes = rDoc.GetFldTypes();
    1032          33 :         for( sal_uInt16 i = 0; i <= INIT_FLDTYPES; i++ )
    1033             :         {
    1034          33 :             if((*pTypes)[i] == &rType)
    1035             :             {
    1036           1 :                 sRet = SwStyleNameMapper::GetProgName ( sRet, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
    1037           1 :                 break;
    1038             :             }
    1039             :         }
    1040             :     }
    1041           1 :     return sRet;
    1042             : }
    1043             : 
    1044          13 : OUString SwXFieldMaster::LocalizeFormula(
    1045             :     const SwSetExpField& rFld,
    1046             :     const OUString& rFormula,
    1047             :     sal_Bool bQuery)
    1048             : {
    1049          13 :     const OUString sTypeName(rFld.GetTyp()->GetName());
    1050          26 :     OUString sProgName = SwStyleNameMapper::GetProgName(sTypeName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
    1051          13 :     if(sProgName != sTypeName)
    1052             :     {
    1053           0 :         OUString sSource = bQuery ? sTypeName : sProgName;
    1054           0 :         OUString sDest = bQuery ? sProgName : sTypeName;
    1055           0 :         if(rFormula.startsWith(sSource))
    1056             :         {
    1057           0 :             OUString sTmpFormula = sDest;
    1058           0 :             sTmpFormula += rFormula.copy(sSource.getLength());
    1059           0 :             return sTmpFormula;
    1060           0 :         }
    1061             :     }
    1062          26 :     return rFormula;
    1063             : }
    1064             : 
    1065             : /******************************************************************
    1066             :  * SwXTextField
    1067             :  ******************************************************************/
    1068             : 
    1069             : uno::Reference<text::XTextField>
    1070         779 : SwXTextField::CreateXTextField(SwDoc & rDoc, SwFmtFld const& rFmt)
    1071             : {
    1072             :     // re-use existing SwXTextField
    1073         779 :     uno::Reference<text::XTextField> xField(rFmt.GetXTextField());
    1074         779 :     if (!xField.is())
    1075             :     {
    1076         768 :         SwXTextField *const pField(new SwXTextField(rFmt, rDoc));
    1077         768 :         xField.set(pField);
    1078         768 :         const_cast<SwFmtFld &>(rFmt).SetXTextField(xField);
    1079             :     }
    1080         779 :     return xField;
    1081             : }
    1082             : 
    1083             : struct SwFieldProperties_Impl
    1084             : {
    1085             :     OUString    sPar1;
    1086             :     OUString    sPar2;
    1087             :     OUString    sPar3;
    1088             :     OUString    sPar4;
    1089             :     OUString    sPar5;
    1090             :     OUString    sPar6;
    1091             :     Date            aDate;
    1092             :     double          fDouble;
    1093             :     uno::Sequence<beans::PropertyValue> aPropSeq;
    1094             :     uno::Sequence<OUString> aStrings;
    1095             :     util::DateTime* pDateTime;
    1096             : 
    1097             :     sal_Int32       nSubType;
    1098             :     sal_Int32       nFormat;
    1099             :     sal_uInt16      nUSHORT1;
    1100             :     sal_uInt16      nUSHORT2;
    1101             :     sal_Int16       nSHORT1;
    1102             :     sal_Int8        nByte1;
    1103             :     bool            bFormatIsDefault;
    1104             :     sal_Bool        bBool1;
    1105             :     sal_Bool        bBool2;
    1106             :     sal_Bool        bBool3;
    1107             :     sal_Bool        bBool4;
    1108             : 
    1109         378 :     SwFieldProperties_Impl():
    1110             :         aDate( Date::EMPTY ),
    1111             :         fDouble(0.),
    1112             :         pDateTime(0),
    1113             :         nSubType(0),
    1114             :         nFormat(0),
    1115             :         nUSHORT1(0),
    1116             :         nUSHORT2(0),
    1117             :         nSHORT1(0),
    1118             :         nByte1(0),
    1119             :         bFormatIsDefault(true),
    1120             :         bBool1(sal_False),
    1121             :         bBool2(sal_False),
    1122             :         bBool3(sal_False),
    1123         378 :         bBool4(sal_True) //Automatic language
    1124         378 :         {}
    1125         378 :     ~SwFieldProperties_Impl()
    1126         378 :         {delete pDateTime;}
    1127             : 
    1128             : };
    1129             : 
    1130             : class SwXTextField::Impl
    1131             :     : public SwClient
    1132             : {
    1133             : private:
    1134             :     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
    1135             :     SwXTextField & m_rThis;
    1136             : 
    1137             : public:
    1138             :     ::cppu::OInterfaceContainerHelper m_EventListeners;
    1139             : 
    1140             :     SwFmtFld const*     m_pFmtFld;
    1141             :     SwDoc *             m_pDoc;
    1142             :     SwTextAPIObject *   m_pTextObject;
    1143             : 
    1144             :     bool                m_bIsDescriptor;
    1145             :     // required to access field master of not yet inserted fields
    1146             :     SwClient            m_FieldTypeClient;
    1147             :     bool                m_bCallUpdate;
    1148             :     sal_uInt16          m_nServiceId;
    1149             :     OUString            m_sTypeName;
    1150             :     boost::scoped_ptr<SwFieldProperties_Impl> m_pProps;
    1151             : 
    1152        1146 :     Impl(SwXTextField & rThis, SwDoc *const pDoc, SwFmtFld const*const pFmt,
    1153             :             sal_uInt16 const nServiceId)
    1154             :         : SwClient((pFmt) ? pDoc->GetUnoCallBack() : 0)
    1155             :         , m_rThis(rThis)
    1156             :         , m_EventListeners(m_Mutex)
    1157             :         , m_pFmtFld(pFmt)
    1158             :         , m_pDoc(pDoc)
    1159             :         , m_pTextObject(0)
    1160        1146 :         , m_bIsDescriptor(pFmt == 0)
    1161             :         , m_bCallUpdate(false)
    1162             :         , m_nServiceId((pFmt)
    1163         768 :                 ? lcl_GetServiceForField(*pFmt->GetField())
    1164             :                 : nServiceId)
    1165        3060 :         , m_pProps((pFmt) ? 0 : new SwFieldProperties_Impl)
    1166        1146 :     { }
    1167             : 
    1168        2292 :     virtual ~Impl()
    1169        2292 :     {
    1170        1146 :         if (m_pTextObject)
    1171             :         {
    1172          33 :             m_pTextObject->DisposeEditSource();
    1173          33 :             m_pTextObject->release();
    1174             :         }
    1175        2292 :     }
    1176             : 
    1177             :     void Invalidate();
    1178             : 
    1179             :     const SwField*      GetField() const;
    1180             : 
    1181             : protected:
    1182             :     // SwClient
    1183             :     virtual void Modify(SfxPoolItem const* pOld, SfxPoolItem const* pNew) SAL_OVERRIDE;
    1184             : };
    1185             : 
    1186             : namespace
    1187             : {
    1188             :     class theSwXTextFieldUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextFieldUnoTunnelId > {};
    1189             : }
    1190             : 
    1191        9574 : const uno::Sequence< sal_Int8 > & SwXTextField::getUnoTunnelId()
    1192             : {
    1193        9574 :     return theSwXTextFieldUnoTunnelId::get().getSeq();
    1194             : }
    1195             : 
    1196             : sal_Int64 SAL_CALL
    1197        2361 : SwXTextField::getSomething(const uno::Sequence< sal_Int8 >& rId)
    1198             : throw (uno::RuntimeException, std::exception)
    1199             : {
    1200        2361 :     return ::sw::UnoTunnelImpl<SwXTextField>(rId, this);
    1201             : }
    1202             : 
    1203         378 : SwXTextField::SwXTextField(
    1204             :     sal_uInt16 nServiceId,
    1205             :     SwDoc* pDoc)
    1206         378 :     : m_pImpl(new Impl(*this, pDoc, 0, nServiceId))
    1207             : {
    1208             :     //Set visible as default!
    1209         378 :     if ( SW_SERVICE_FIELDTYPE_SET_EXP == nServiceId
    1210         333 :          || SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM == nServiceId
    1211         333 :          || SW_SERVICE_FIELDTYPE_DATABASE == nServiceId
    1212         330 :          || SW_SERVICE_FIELDTYPE_DATABASE_NAME == nServiceId )
    1213             :     {
    1214          48 :         m_pImpl->m_pProps->bBool2 = sal_True;
    1215             :     }
    1216         330 :     else if(SW_SERVICE_FIELDTYPE_TABLE_FORMULA == nServiceId)
    1217             :     {
    1218           0 :         m_pImpl->m_pProps->bBool1 = sal_True;
    1219             :     }
    1220         378 :     if(SW_SERVICE_FIELDTYPE_SET_EXP == nServiceId)
    1221             :     {
    1222          45 :         m_pImpl->m_pProps->nUSHORT2 = USHRT_MAX;
    1223             :     }
    1224         378 : }
    1225             : 
    1226         768 : SwXTextField::SwXTextField(
    1227             :     const SwFmtFld& rFmt,
    1228             :     SwDoc & rDoc)
    1229         768 :     : m_pImpl(new Impl(*this, &rDoc, &rFmt, USHRT_MAX))
    1230             : {
    1231         768 : }
    1232             : 
    1233        2292 : SwXTextField::~SwXTextField()
    1234             : {
    1235        2292 : }
    1236             : 
    1237         391 : sal_uInt16 SwXTextField::GetServiceId() const
    1238             : {
    1239         391 :     return m_pImpl->m_nServiceId;
    1240             : }
    1241             : 
    1242          49 : void SAL_CALL SwXTextField::attachTextFieldMaster(
    1243             :         const uno::Reference< beans::XPropertySet > & xFieldMaster)
    1244             : throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
    1245             : {
    1246          49 :     SolarMutexGuard aGuard;
    1247             : 
    1248          49 :     if (!m_pImpl->m_bIsDescriptor)
    1249           0 :         throw uno::RuntimeException();
    1250          98 :     uno::Reference< lang::XUnoTunnel > xMasterTunnel(xFieldMaster, uno::UNO_QUERY);
    1251          49 :     if (!xMasterTunnel.is())
    1252           0 :         throw lang::IllegalArgumentException();
    1253             :     SwXFieldMaster* pMaster = reinterpret_cast< SwXFieldMaster * >(
    1254          49 :             sal::static_int_cast< sal_IntPtr >( xMasterTunnel->getSomething( SwXFieldMaster::getUnoTunnelId()) ));
    1255             : 
    1256          49 :     SwFieldType* pFieldType = pMaster ? pMaster->GetFldType() : 0;
    1257          98 :     if (!pFieldType ||
    1258          49 :         pFieldType->Which() != lcl_ServiceIdToResId(m_pImpl->m_nServiceId))
    1259             :     {
    1260           0 :         throw lang::IllegalArgumentException();
    1261             :     }
    1262          49 :     m_pImpl->m_sTypeName = pFieldType->GetName();
    1263          98 :     pFieldType->Add( &m_pImpl->m_FieldTypeClient );
    1264          49 : }
    1265             : 
    1266             : uno::Reference< beans::XPropertySet > SAL_CALL
    1267           3 : SwXTextField::getTextFieldMaster() throw (uno::RuntimeException, std::exception)
    1268             : {
    1269           3 :     SolarMutexGuard aGuard;
    1270           3 :     SwFieldType* pType = 0;
    1271           3 :     if (m_pImpl->m_bIsDescriptor && m_pImpl->m_FieldTypeClient.GetRegisteredIn())
    1272             :     {
    1273             :         pType = static_cast<SwFieldType*>(const_cast<SwModify*>(
    1274           2 :                     m_pImpl->m_FieldTypeClient.GetRegisteredIn()));
    1275             :     }
    1276             :     else
    1277             :     {
    1278           1 :         if (!m_pImpl->GetRegisteredIn())
    1279           0 :             throw uno::RuntimeException();
    1280           1 :         pType = m_pImpl->m_pFmtFld->GetField()->GetTyp();
    1281             :     }
    1282             : 
    1283             :     uno::Reference<beans::XPropertySet> const xRet(
    1284           3 :             SwXFieldMaster::CreateXFieldMaster(*m_pImpl->m_pDoc, *pType));
    1285           3 :     return xRet;
    1286             : }
    1287             : 
    1288          43 : OUString SAL_CALL SwXTextField::getPresentation(sal_Bool bShowCommand)
    1289             : throw (uno::RuntimeException, std::exception)
    1290             : {
    1291          43 :     SolarMutexGuard aGuard;
    1292             : 
    1293          43 :     SwField const*const pField = m_pImpl->GetField();
    1294          43 :     if (!pField)
    1295             :     {
    1296           0 :         throw uno::RuntimeException();
    1297             :     }
    1298             :     OUString const ret( (bShowCommand)
    1299           1 :             ? pField->GetFieldName()
    1300          44 :             : pField->ExpandField(true) );
    1301          43 :     return ret;
    1302             : }
    1303             : 
    1304         400 : void SAL_CALL SwXTextField::attach(
    1305             :         const uno::Reference< text::XTextRange > & xTextRange)
    1306             : throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
    1307             : {
    1308         400 :     SolarMutexGuard aGuard;
    1309         400 :     if (m_pImpl->m_bIsDescriptor)
    1310             :     {
    1311         371 :     uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
    1312         371 :     SwXTextRange* pRange = 0;
    1313         371 :     OTextCursorHelper* pCursor = 0;
    1314         371 :     if(xRangeTunnel.is())
    1315             :     {
    1316             :         pRange  = reinterpret_cast< SwXTextRange * >(
    1317         371 :                 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
    1318             :         pCursor = reinterpret_cast< OTextCursorHelper * >(
    1319         371 :                 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
    1320             :     }
    1321             : 
    1322         371 :     SwDoc* pDoc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
    1323             :     //wurde ein FieldMaster attached, dann ist das Dokument schon festgelegt!
    1324         371 :     if (!pDoc || (m_pImpl->m_pDoc && m_pImpl->m_pDoc != pDoc))
    1325           0 :         throw lang::IllegalArgumentException();
    1326             : 
    1327         742 :     SwUnoInternalPaM aPam(*pDoc);
    1328             :     //das muss jetzt sal_True liefern
    1329         371 :     ::sw::XTextRangeToSwPaM(aPam, xTextRange);
    1330         371 :     SwField* pFld = 0;
    1331         371 :     switch (m_pImpl->m_nServiceId)
    1332             :     {
    1333             :         case SW_SERVICE_FIELDTYPE_ANNOTATION:
    1334             :             {
    1335          33 :                 SwFieldType* pFldType = pDoc->GetSysFldType(RES_POSTITFLD);
    1336             : 
    1337          33 :                 DateTime aDateTime( DateTime::EMPTY );
    1338          33 :                 if (m_pImpl->m_pProps->pDateTime)
    1339             :                 {
    1340          31 :                     aDateTime.SetYear(m_pImpl->m_pProps->pDateTime->Year);
    1341          31 :                     aDateTime.SetMonth(m_pImpl->m_pProps->pDateTime->Month);
    1342          31 :                     aDateTime.SetDay(m_pImpl->m_pProps->pDateTime->Day);
    1343          31 :                     aDateTime.SetHour(m_pImpl->m_pProps->pDateTime->Hours);
    1344          31 :                     aDateTime.SetMin(m_pImpl->m_pProps->pDateTime->Minutes);
    1345          31 :                     aDateTime.SetSec(m_pImpl->m_pProps->pDateTime->Seconds);
    1346             :                 }
    1347             :                 SwPostItField* pPostItField = new SwPostItField(
    1348             :                     (SwPostItFieldType*)pFldType,
    1349          33 :                     m_pImpl->m_pProps->sPar1, // author
    1350          33 :                     m_pImpl->m_pProps->sPar2, // content
    1351          33 :                     m_pImpl->m_pProps->sPar3, // author's initials
    1352          33 :                     m_pImpl->m_pProps->sPar4, // name
    1353         132 :                     aDateTime );
    1354          33 :                 if ( m_pImpl->m_pTextObject )
    1355             :                 {
    1356          33 :                     pPostItField->SetTextObject( m_pImpl->m_pTextObject->CreateText() );
    1357          33 :                     pPostItField->SetPar2(m_pImpl->m_pTextObject->GetText());
    1358             :                 }
    1359          33 :                 pFld = pPostItField;
    1360             :             }
    1361          33 :             break;
    1362             :         case SW_SERVICE_FIELDTYPE_SCRIPT:
    1363             :         {
    1364           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_SCRIPTFLD);
    1365             :             pFld = new SwScriptField((SwScriptFieldType*)pFldType,
    1366           0 :                     m_pImpl->m_pProps->sPar1, m_pImpl->m_pProps->sPar2,
    1367           0 :                     m_pImpl->m_pProps->bBool1);
    1368             :         }
    1369           0 :         break;
    1370             :         case SW_SERVICE_FIELDTYPE_DATETIME:
    1371             :         {
    1372          18 :             sal_uInt16 nSub = 0;
    1373          18 :             if (m_pImpl->m_pProps->bBool1)
    1374           0 :                 nSub |= FIXEDFLD;
    1375          18 :             if (m_pImpl->m_pProps->bBool2)
    1376          16 :                 nSub |= DATEFLD;
    1377             :             else
    1378           2 :                 nSub |= TIMEFLD;
    1379          18 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_DATETIMEFLD);
    1380             :             SwDateTimeField *const pDTField = new SwDateTimeField(
    1381             :                     static_cast<SwDateTimeFieldType*>(pFldType),
    1382          18 :                         nSub, m_pImpl->m_pProps->nFormat);
    1383          18 :             pFld = pDTField;
    1384          18 :             if (m_pImpl->m_pProps->fDouble > 0.)
    1385             :             {
    1386           0 :                 pDTField->SetValue(m_pImpl->m_pProps->fDouble);
    1387             :             }
    1388          18 :             if (m_pImpl->m_pProps->pDateTime)
    1389             :             {
    1390           0 :                 uno::Any aVal; aVal <<= *m_pImpl->m_pProps->pDateTime;
    1391           0 :                 pFld->PutValue( aVal, FIELD_PROP_DATE_TIME );
    1392             :             }
    1393          18 :             pDTField->SetOffset(m_pImpl->m_pProps->nSubType);
    1394             :         }
    1395          18 :         break;
    1396             :         case SW_SERVICE_FIELDTYPE_FILE_NAME:
    1397             :         {
    1398          12 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_FILENAMEFLD);
    1399          12 :             sal_Int32 nFormat = m_pImpl->m_pProps->nFormat;
    1400          12 :             if (m_pImpl->m_pProps->bBool2)
    1401           0 :                 nFormat |= FF_FIXED;
    1402             :             SwFileNameField *const pFNField = new SwFileNameField(
    1403          12 :                     static_cast<SwFileNameFieldType*>(pFldType), nFormat);
    1404          12 :             pFld = pFNField;
    1405          12 :             if (!m_pImpl->m_pProps->sPar3.isEmpty())
    1406          12 :                 pFNField->SetExpansion(m_pImpl->m_pProps->sPar3);
    1407          12 :             uno::Any aFormat;
    1408          12 :             aFormat <<= m_pImpl->m_pProps->nFormat;
    1409          12 :             pFld->PutValue( aFormat, FIELD_PROP_FORMAT );
    1410             :         }
    1411          12 :         break;
    1412             :         case SW_SERVICE_FIELDTYPE_TEMPLATE_NAME:
    1413             :         {
    1414           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_TEMPLNAMEFLD);
    1415             :             pFld = new SwTemplNameField((SwTemplNameFieldType*)pFldType,
    1416           0 :                                         m_pImpl->m_pProps->nFormat);
    1417           0 :             uno::Any aFormat;
    1418           0 :             aFormat <<= m_pImpl->m_pProps->nFormat;
    1419           0 :             pFld->PutValue(aFormat, FIELD_PROP_FORMAT);
    1420             :         }
    1421           0 :         break;
    1422             :         case SW_SERVICE_FIELDTYPE_CHAPTER:
    1423             :         {
    1424           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_CHAPTERFLD);
    1425             :             SwChapterField *const pChapterField = new SwChapterField(
    1426             :                     static_cast<SwChapterFieldType*>(pFldType),
    1427           0 :                     m_pImpl->m_pProps->nUSHORT1);
    1428           0 :             pFld = pChapterField;
    1429           0 :             pChapterField->SetLevel(m_pImpl->m_pProps->nByte1);
    1430           0 :             uno::Any aVal;
    1431           0 :             aVal <<= static_cast<sal_Int16>(m_pImpl->m_pProps->nUSHORT1);
    1432           0 :             pFld->PutValue(aVal, FIELD_PROP_USHORT1 );
    1433             :         }
    1434           0 :         break;
    1435             :         case SW_SERVICE_FIELDTYPE_AUTHOR:
    1436             :         {
    1437          19 :             long nFormat = m_pImpl->m_pProps->bBool1 ? AF_NAME : AF_SHORTCUT;
    1438          19 :             if (m_pImpl->m_pProps->bBool2)
    1439          19 :                 nFormat |= AF_FIXED;
    1440             : 
    1441          19 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_AUTHORFLD);
    1442             :             SwAuthorField *const pAuthorField = new SwAuthorField(
    1443          19 :                     static_cast<SwAuthorFieldType*>(pFldType), nFormat);
    1444          19 :             pFld = pAuthorField;
    1445          19 :             pAuthorField->SetExpansion(m_pImpl->m_pProps->sPar1);
    1446             :         }
    1447          19 :         break;
    1448             :         case SW_SERVICE_FIELDTYPE_CONDITIONED_TEXT:
    1449             :         case SW_SERVICE_FIELDTYPE_HIDDEN_TEXT:
    1450             :         {
    1451           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_HIDDENTXTFLD);
    1452             :             SwHiddenTxtField *const pHTField = new SwHiddenTxtField(
    1453             :                     static_cast<SwHiddenTxtFieldType*>(pFldType),
    1454           0 :                     m_pImpl->m_pProps->sPar1,
    1455           0 :                     m_pImpl->m_pProps->sPar2, m_pImpl->m_pProps->sPar3,
    1456           0 :                     static_cast<sal_uInt16>(SW_SERVICE_FIELDTYPE_HIDDEN_TEXT == m_pImpl->m_nServiceId ?
    1457           0 :                          TYP_HIDDENTXTFLD : TYP_CONDTXTFLD));
    1458           0 :             pFld = pHTField;
    1459           0 :             pHTField->SetValue(m_pImpl->m_pProps->bBool1);
    1460           0 :             uno::Any aVal;
    1461           0 :             aVal <<= m_pImpl->m_pProps->sPar4;
    1462           0 :             pFld->PutValue(aVal, FIELD_PROP_PAR4 );
    1463             :         }
    1464           0 :         break;
    1465             :         case SW_SERVICE_FIELDTYPE_HIDDEN_PARA:
    1466             :         {
    1467           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_HIDDENPARAFLD);
    1468             :             SwHiddenParaField *const pHPField = new SwHiddenParaField(
    1469             :                     static_cast<SwHiddenParaFieldType*>(pFldType),
    1470           0 :                     m_pImpl->m_pProps->sPar1);
    1471           0 :             pFld = pHPField;
    1472           0 :             pHPField->SetHidden(m_pImpl->m_pProps->bBool1);
    1473             :         }
    1474           0 :         break;
    1475             :         case SW_SERVICE_FIELDTYPE_GET_REFERENCE:
    1476             :         {
    1477          31 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_GETREFFLD);
    1478             :             pFld = new SwGetRefField((SwGetRefFieldType*)pFldType,
    1479          31 :                         m_pImpl->m_pProps->sPar1,
    1480             :                         0,
    1481             :                         0,
    1482          31 :                         0);
    1483          31 :             if (!m_pImpl->m_pProps->sPar3.isEmpty())
    1484          30 :                 static_cast<SwGetRefField*>(pFld)->SetExpand(m_pImpl->m_pProps->sPar3);
    1485          31 :             uno::Any aVal;
    1486          31 :             aVal <<= static_cast<sal_Int16>(m_pImpl->m_pProps->nUSHORT1);
    1487          31 :             pFld->PutValue(aVal, FIELD_PROP_USHORT1 );
    1488          31 :             aVal <<= static_cast<sal_Int16>(m_pImpl->m_pProps->nUSHORT2);
    1489          31 :             pFld->PutValue(aVal, FIELD_PROP_USHORT2 );
    1490          31 :             aVal <<= m_pImpl->m_pProps->nSHORT1;
    1491          31 :             pFld->PutValue(aVal, FIELD_PROP_SHORT1 );
    1492             :         }
    1493          31 :         break;
    1494             :         case SW_SERVICE_FIELDTYPE_JUMP_EDIT:
    1495             :         {
    1496           8 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_JUMPEDITFLD);
    1497             :             pFld = new SwJumpEditField((SwJumpEditFieldType*)pFldType,
    1498          16 :                     m_pImpl->m_pProps->nUSHORT1, m_pImpl->m_pProps->sPar2,
    1499          16 :                     m_pImpl->m_pProps->sPar1);
    1500             :         }
    1501           8 :         break;
    1502             :         case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR     :
    1503             :         case SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME  :
    1504             :         case SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME         :
    1505             :         case SW_SERVICE_FIELDTYPE_DOCINFO_DESCRIPTION       :
    1506             :         case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_AUTHOR     :
    1507             :         case SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME  :
    1508             :         case SW_SERVICE_FIELDTYPE_DOCINFO_CUSTOM            :
    1509             :         case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_AUTHOR      :
    1510             :         case SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME   :
    1511             :         case SW_SERVICE_FIELDTYPE_DOCINFO_KEY_WORDS         :
    1512             :         case SW_SERVICE_FIELDTYPE_DOCINFO_SUBJECT           :
    1513             :         case SW_SERVICE_FIELDTYPE_DOCINFO_TITLE             :
    1514             :         case SW_SERVICE_FIELDTYPE_DOCINFO_REVISION          :
    1515             :         case SW_SERVICE_FIELDTYPE_DOC_INFO:
    1516             :         {
    1517           8 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_DOCINFOFLD);
    1518             :             sal_uInt16 nSubType = aDocInfoSubTypeFromService[
    1519           8 :                     m_pImpl->m_nServiceId - SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_AUTHOR];
    1520          24 :             if (SW_SERVICE_FIELDTYPE_DOCINFO_CHANGE_DATE_TIME == m_pImpl->m_nServiceId ||
    1521          16 :                 SW_SERVICE_FIELDTYPE_DOCINFO_CREATE_DATE_TIME == m_pImpl->m_nServiceId ||
    1522          24 :                 SW_SERVICE_FIELDTYPE_DOCINFO_PRINT_DATE_TIME == m_pImpl->m_nServiceId ||
    1523           8 :                 SW_SERVICE_FIELDTYPE_DOCINFO_EDIT_TIME == m_pImpl->m_nServiceId)
    1524             :             {
    1525           0 :                 if (m_pImpl->m_pProps->bBool2) //IsDate
    1526             :                 {
    1527           0 :                     nSubType &= 0xf0ff;
    1528           0 :                     nSubType |= DI_SUB_DATE;
    1529             :                 }
    1530             :                 else
    1531             :                 {
    1532           0 :                     nSubType &= 0xf0ff;
    1533           0 :                     nSubType |= DI_SUB_TIME;
    1534             :                 }
    1535             :             }
    1536           8 :             if (m_pImpl->m_pProps->bBool1)
    1537           0 :                 nSubType |= DI_SUB_FIXED;
    1538             :             pFld = new SwDocInfoField(
    1539             :                     static_cast<SwDocInfoFieldType*>(pFldType), nSubType,
    1540           8 :                     m_pImpl->m_pProps->sPar4, m_pImpl->m_pProps->nFormat);
    1541           8 :             if (!m_pImpl->m_pProps->sPar3.isEmpty())
    1542           6 :                 static_cast<SwDocInfoField*>(pFld)->SetExpansion(m_pImpl->m_pProps->sPar3);
    1543             :         }
    1544           8 :         break;
    1545             :         case SW_SERVICE_FIELDTYPE_USER_EXT:
    1546             :         {
    1547           0 :             sal_Int32 nFormat = 0;
    1548           0 :             if (m_pImpl->m_pProps->bBool1)
    1549           0 :                 nFormat = AF_FIXED;
    1550             : 
    1551           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_EXTUSERFLD);
    1552             :             SwExtUserField *const pEUField = new SwExtUserField(
    1553             :                 static_cast<SwExtUserFieldType*>(pFldType),
    1554           0 :                 m_pImpl->m_pProps->nUSHORT1, nFormat);
    1555           0 :             pFld = pEUField;
    1556           0 :             pEUField->SetExpansion(m_pImpl->m_pProps->sPar1);
    1557             :         }
    1558           0 :         break;
    1559             :         case SW_SERVICE_FIELDTYPE_USER:
    1560             :         {
    1561             :             SwFieldType* pFldType =
    1562           2 :                 pDoc->GetFldType(RES_USERFLD, m_pImpl->m_sTypeName, true);
    1563           2 :             if (!pFldType)
    1564           0 :                 throw uno::RuntimeException();
    1565           2 :             sal_uInt16 nUserSubType = (m_pImpl->m_pProps->bBool1)
    1566           2 :                 ? nsSwExtendedSubType::SUB_INVISIBLE : 0;
    1567           2 :             if (m_pImpl->m_pProps->bBool2)
    1568           0 :                 nUserSubType |= nsSwExtendedSubType::SUB_CMD;
    1569           4 :             if (m_pImpl->m_pProps->bFormatIsDefault &&
    1570           2 :                 nsSwGetSetExpType::GSE_STRING == ((SwUserFieldType*)pFldType)->GetType())
    1571             :             {
    1572           2 :                 m_pImpl->m_pProps->nFormat = -1;
    1573             :             }
    1574             :             pFld = new SwUserField((SwUserFieldType*)pFldType,
    1575             :                                 nUserSubType,
    1576           2 :                                 m_pImpl->m_pProps->nFormat);
    1577             :         }
    1578           2 :         break;
    1579             :         case SW_SERVICE_FIELDTYPE_REF_PAGE_SET:
    1580             :         {
    1581           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_REFPAGESETFLD);
    1582             :             pFld = new SwRefPageSetField( (SwRefPageSetFieldType*)pFldType,
    1583           0 :                                 m_pImpl->m_pProps->nUSHORT1,
    1584           0 :                                 m_pImpl->m_pProps->bBool1 );
    1585             :         }
    1586           0 :         break;
    1587             :         case SW_SERVICE_FIELDTYPE_REF_PAGE_GET:
    1588             :         {
    1589           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_REFPAGEGETFLD);
    1590             :             SwRefPageGetField *const pRGField = new SwRefPageGetField(
    1591             :                     static_cast<SwRefPageGetFieldType*>(pFldType),
    1592           0 :                     m_pImpl->m_pProps->nUSHORT1 );
    1593           0 :             pFld = pRGField;
    1594           0 :             pRGField->SetText(m_pImpl->m_pProps->sPar1);
    1595             :         }
    1596           0 :         break;
    1597             :         case SW_SERVICE_FIELDTYPE_PAGE_NUM:
    1598             :         {
    1599         149 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_PAGENUMBERFLD);
    1600             :             SwPageNumberField *const pPNField = new SwPageNumberField(
    1601             :                 static_cast<SwPageNumberFieldType*>(pFldType), PG_RANDOM,
    1602         149 :                 m_pImpl->m_pProps->nFormat,
    1603         149 :                 m_pImpl->m_pProps->nUSHORT1);
    1604         149 :             pFld = pPNField;
    1605         149 :             pPNField->SetUserString(m_pImpl->m_pProps->sPar1);
    1606         149 :             uno::Any aVal;
    1607         149 :             aVal <<= m_pImpl->m_pProps->nSubType;
    1608         149 :             pFld->PutValue( aVal, FIELD_PROP_SUBTYPE );
    1609             :         }
    1610         149 :         break;
    1611             :         case SW_SERVICE_FIELDTYPE_DDE:
    1612             :         {
    1613             :             SwFieldType* pFldType =
    1614           0 :                 pDoc->GetFldType(RES_DDEFLD, m_pImpl->m_sTypeName, true);
    1615           0 :             if (!pFldType)
    1616           0 :                 throw uno::RuntimeException();
    1617           0 :             pFld = new SwDDEField( (SwDDEFieldType*)pFldType );
    1618             :         }
    1619           0 :         break;
    1620             :         case SW_SERVICE_FIELDTYPE_DATABASE_NAME:
    1621             :         {
    1622           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_DBNAMEFLD);
    1623           0 :             SwDBData aData;
    1624           0 :             aData.sDataSource = m_pImpl->m_pProps->sPar1;
    1625           0 :             aData.sCommand = m_pImpl->m_pProps->sPar2;
    1626           0 :             aData.nCommandType = m_pImpl->m_pProps->nSHORT1;
    1627           0 :             pFld = new SwDBNameField((SwDBNameFieldType*)pFldType, aData);
    1628           0 :             sal_uInt16  nSubType = pFld->GetSubType();
    1629           0 :             if (m_pImpl->m_pProps->bBool2)
    1630           0 :                 nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
    1631             :             else
    1632           0 :                 nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
    1633           0 :             pFld->SetSubType(nSubType);
    1634             :         }
    1635           0 :         break;
    1636             :         case SW_SERVICE_FIELDTYPE_DATABASE_NEXT_SET:
    1637             :         {
    1638           0 :             SwDBData aData;
    1639           0 :             aData.sDataSource = m_pImpl->m_pProps->sPar1;
    1640           0 :             aData.sCommand = m_pImpl->m_pProps->sPar2;
    1641           0 :             aData.nCommandType = m_pImpl->m_pProps->nSHORT1;
    1642           0 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_DBNEXTSETFLD);
    1643             :             pFld = new SwDBNextSetField((SwDBNextSetFieldType*)pFldType,
    1644           0 :                     m_pImpl->m_pProps->sPar3, OUString(), aData);
    1645             :         }
    1646           0 :         break;
    1647             :         case SW_SERVICE_FIELDTYPE_DATABASE_NUM_SET:
    1648             :         {
    1649           0 :             SwDBData aData;
    1650           0 :             aData.sDataSource = m_pImpl->m_pProps->sPar1;
    1651           0 :             aData.sCommand = m_pImpl->m_pProps->sPar2;
    1652           0 :             aData.nCommandType = m_pImpl->m_pProps->nSHORT1;
    1653             :             pFld = new SwDBNumSetField( (SwDBNumSetFieldType*)
    1654           0 :                 pDoc->GetSysFldType(RES_DBNUMSETFLD),
    1655           0 :                 m_pImpl->m_pProps->sPar3,
    1656           0 :                 OUString::number(m_pImpl->m_pProps->nFormat),
    1657           0 :                 aData );
    1658             :         }
    1659           0 :         break;
    1660             :         case SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM:
    1661             :         {
    1662           0 :             SwDBData aData;
    1663           0 :             aData.sDataSource = m_pImpl->m_pProps->sPar1;
    1664           0 :             aData.sCommand = m_pImpl->m_pProps->sPar2;
    1665           0 :             aData.nCommandType = m_pImpl->m_pProps->nSHORT1;
    1666             :             SwDBSetNumberField *const pDBSNField =
    1667             :                 new SwDBSetNumberField(static_cast<SwDBSetNumberFieldType*>(
    1668           0 :                         pDoc->GetSysFldType(RES_DBSETNUMBERFLD)), aData,
    1669           0 :                     m_pImpl->m_pProps->nUSHORT1);
    1670           0 :             pFld = pDBSNField;
    1671           0 :             pDBSNField->SetSetNumber(m_pImpl->m_pProps->nFormat);
    1672           0 :             sal_uInt16  nSubType = pFld->GetSubType();
    1673           0 :             if (m_pImpl->m_pProps->bBool2)
    1674           0 :                 nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
    1675             :             else
    1676           0 :                 nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
    1677           0 :             pFld->SetSubType(nSubType);
    1678             :         }
    1679           0 :         break;
    1680             :         case SW_SERVICE_FIELDTYPE_DATABASE:
    1681             :         {
    1682             :             SwFieldType* pFldType =
    1683           3 :                 pDoc->GetFldType(RES_DBFLD, m_pImpl->m_sTypeName, false);
    1684           3 :             if (!pFldType)
    1685           0 :                 throw uno::RuntimeException();
    1686             :             pFld = new SwDBField(static_cast<SwDBFieldType*>(pFldType),
    1687           3 :                     m_pImpl->m_pProps->nFormat);
    1688           3 :             ((SwDBField*)pFld)->InitContent(m_pImpl->m_pProps->sPar1);
    1689           3 :             sal_uInt16  nSubType = pFld->GetSubType();
    1690           3 :             if (m_pImpl->m_pProps->bBool2)
    1691           3 :                 nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
    1692             :             else
    1693           0 :                 nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
    1694           3 :             pFld->SetSubType(nSubType);
    1695             :         }
    1696           3 :         break;
    1697             :         case SW_SERVICE_FIELDTYPE_SET_EXP:
    1698             :         {
    1699             :             SwFieldType* pFldType =
    1700          44 :                 pDoc->GetFldType(RES_SETEXPFLD, m_pImpl->m_sTypeName, true);
    1701          44 :             if (!pFldType)
    1702           0 :                 throw uno::RuntimeException();
    1703             :             // detect the field type's sub type and set an appropriate number format
    1704          88 :             if (m_pImpl->m_pProps->bFormatIsDefault &&
    1705          44 :                 nsSwGetSetExpType::GSE_STRING == ((SwSetExpFieldType*)pFldType)->GetType())
    1706             :             {
    1707           2 :                 m_pImpl->m_pProps->nFormat = -1;
    1708             :             }
    1709             :             SwSetExpField *const pSEField = new SwSetExpField(
    1710             :                 static_cast<SwSetExpFieldType*>(pFldType),
    1711          44 :                 m_pImpl->m_pProps->sPar2,
    1712          44 :                 m_pImpl->m_pProps->nUSHORT2 != USHRT_MAX ?  //#i79471# the field can have a number format or a number_ing_ format
    1713          88 :                 m_pImpl->m_pProps->nUSHORT2 : m_pImpl->m_pProps->nFormat);
    1714          44 :             pFld = pSEField;
    1715             : 
    1716          44 :             sal_uInt16  nSubType = pFld->GetSubType();
    1717          44 :             if (m_pImpl->m_pProps->bBool2)
    1718          43 :                 nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
    1719             :             else
    1720           1 :                 nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
    1721          44 :             if (m_pImpl->m_pProps->bBool3)
    1722           0 :                 nSubType |= nsSwExtendedSubType::SUB_CMD;
    1723             :             else
    1724          44 :                 nSubType &= ~nsSwExtendedSubType::SUB_CMD;
    1725          44 :             pFld->SetSubType(nSubType);
    1726          44 :             pSEField->SetSeqNumber(m_pImpl->m_pProps->nUSHORT1);
    1727          44 :             pSEField->SetInputFlag(m_pImpl->m_pProps->bBool1);
    1728          44 :             pSEField->SetPromptText(m_pImpl->m_pProps->sPar3);
    1729          44 :             if (!m_pImpl->m_pProps->sPar4.isEmpty())
    1730          39 :                 pSEField->ChgExpStr(m_pImpl->m_pProps->sPar4);
    1731             : 
    1732             :         }
    1733          44 :         break;
    1734             :         case SW_SERVICE_FIELDTYPE_GET_EXP:
    1735             :         {
    1736             :             sal_uInt16 nSubType;
    1737           1 :             switch (m_pImpl->m_pProps->nSubType)
    1738             :             {
    1739           1 :                 case text::SetVariableType::STRING: nSubType = nsSwGetSetExpType::GSE_STRING;   break;
    1740           0 :                 case text::SetVariableType::VAR:        nSubType = nsSwGetSetExpType::GSE_EXPR;  break;
    1741             :                 //case text::SetVariableType::SEQUENCE:   nSubType = nsSwGetSetExpType::GSE_SEQ;  break;
    1742           0 :                 case text::SetVariableType::FORMULA:    nSubType = nsSwGetSetExpType::GSE_FORMULA; break;
    1743             :                 default:
    1744             :                     OSL_FAIL("wrong value");
    1745           0 :                     nSubType = nsSwGetSetExpType::GSE_EXPR;
    1746             :             }
    1747             :             //make sure the SubType matches the field type
    1748             :             SwFieldType* pSetExpFld = pDoc->GetFldType(
    1749           1 :                     RES_SETEXPFLD, m_pImpl->m_pProps->sPar1, false);
    1750           1 :             bool bSetGetExpFieldUninitialized = false;
    1751           1 :             if (pSetExpFld)
    1752             :             {
    1753           1 :                 if (nSubType != nsSwGetSetExpType::GSE_STRING &&
    1754           0 :                     static_cast< SwSetExpFieldType* >(pSetExpFld)->GetType() == nsSwGetSetExpType::GSE_STRING)
    1755           0 :                 nSubType = nsSwGetSetExpType::GSE_STRING;
    1756             :             }
    1757             :             else
    1758           0 :                 bSetGetExpFieldUninitialized = true; // #i82544#
    1759             : 
    1760           1 :             if (m_pImpl->m_pProps->bBool2)
    1761           0 :                 nSubType |= nsSwExtendedSubType::SUB_CMD;
    1762             :             else
    1763           1 :                 nSubType &= ~nsSwExtendedSubType::SUB_CMD;
    1764             :             SwGetExpField *const pGEField = new SwGetExpField(
    1765             :                     static_cast<SwGetExpFieldType*>(
    1766           1 :                         pDoc->GetSysFldType(RES_GETEXPFLD)),
    1767           1 :                     m_pImpl->m_pProps->sPar1, nSubType,
    1768           2 :                     m_pImpl->m_pProps->nFormat);
    1769           1 :             pFld = pGEField;
    1770             :             //TODO: SubType auswerten!
    1771           1 :             if (!m_pImpl->m_pProps->sPar4.isEmpty())
    1772           1 :                 pGEField->ChgExpStr(m_pImpl->m_pProps->sPar4);
    1773             :             // #i82544#
    1774           1 :             if (bSetGetExpFieldUninitialized)
    1775           0 :                 pGEField->SetLateInitialization();
    1776             :         }
    1777           1 :         break;
    1778             :         case SW_SERVICE_FIELDTYPE_INPUT_USER:
    1779             :         case SW_SERVICE_FIELDTYPE_INPUT:
    1780             :         {
    1781             :             SwFieldType* pFldType =
    1782           1 :                 pDoc->GetFldType(RES_INPUTFLD, m_pImpl->m_sTypeName, true);
    1783           1 :             if (!pFldType)
    1784           0 :                 throw uno::RuntimeException();
    1785             :             sal_uInt16 nInpSubType =
    1786             :                 sal::static_int_cast<sal_uInt16>(
    1787           1 :                     SW_SERVICE_FIELDTYPE_INPUT_USER == m_pImpl->m_nServiceId
    1788           1 :                         ? INP_USR : INP_TXT);
    1789             :             SwInputField * pTxtField =
    1790             :                 new SwInputField(static_cast<SwInputFieldType*>(pFldType),
    1791           1 :                                  m_pImpl->m_pProps->sPar1,
    1792           1 :                                  m_pImpl->m_pProps->sPar2,
    1793           2 :                                  nInpSubType);
    1794           1 :             pTxtField->SetHelp(m_pImpl->m_pProps->sPar3);
    1795           1 :             pTxtField->SetToolTip(m_pImpl->m_pProps->sPar4);
    1796             : 
    1797           1 :             pFld = pTxtField;
    1798             :         }
    1799           1 :         break;
    1800             :         case SW_SERVICE_FIELDTYPE_MACRO:
    1801             :         {
    1802           3 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_MACROFLD);
    1803           3 :             OUString aName;
    1804             : 
    1805             :             // support for Scripting Framework macros
    1806           3 :             if (!m_pImpl->m_pProps->sPar4.isEmpty())
    1807             :             {
    1808           0 :                 aName = m_pImpl->m_pProps->sPar4;
    1809             :             }
    1810             :             else
    1811             :             {
    1812             :                 SwMacroField::CreateMacroString(aName,
    1813           3 :                     m_pImpl->m_pProps->sPar1, m_pImpl->m_pProps->sPar3);
    1814             :             }
    1815             :             pFld = new SwMacroField((SwMacroFieldType*)pFldType, aName,
    1816           3 :                                     m_pImpl->m_pProps->sPar2);
    1817             :         }
    1818           3 :         break;
    1819             :         case SW_SERVICE_FIELDTYPE_PAGE_COUNT            :
    1820             :         case SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT       :
    1821             :         case SW_SERVICE_FIELDTYPE_WORD_COUNT            :
    1822             :         case SW_SERVICE_FIELDTYPE_CHARACTER_COUNT       :
    1823             :         case SW_SERVICE_FIELDTYPE_TABLE_COUNT           :
    1824             :         case SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT  :
    1825             :         case SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT :
    1826             :         {
    1827          21 :             sal_uInt16 nSubType = DS_PAGE;
    1828          21 :             switch (m_pImpl->m_nServiceId)
    1829             :             {
    1830             : //                  case SW_SERVICE_FIELDTYPE_PAGE_COUNT            : break;
    1831           0 :                 case SW_SERVICE_FIELDTYPE_PARAGRAPH_COUNT       : nSubType = DS_PARA; break;
    1832           0 :                 case SW_SERVICE_FIELDTYPE_WORD_COUNT            : nSubType = DS_WORD; break;
    1833           0 :                 case SW_SERVICE_FIELDTYPE_CHARACTER_COUNT       : nSubType = DS_CHAR; break;
    1834           0 :                 case SW_SERVICE_FIELDTYPE_TABLE_COUNT           : nSubType = DS_TBL;  break;
    1835           0 :                 case SW_SERVICE_FIELDTYPE_GRAPHIC_OBJECT_COUNT  : nSubType = DS_GRF;  break;
    1836           0 :                 case SW_SERVICE_FIELDTYPE_EMBEDDED_OBJECT_COUNT : nSubType = DS_OLE;  break;
    1837             :             }
    1838          21 :             SwFieldType* pFldType = pDoc->GetSysFldType(RES_DOCSTATFLD);
    1839             :             pFld = new SwDocStatField(
    1840             :                     static_cast<SwDocStatFieldType*>(pFldType),
    1841          21 :                     nSubType, m_pImpl->m_pProps->nUSHORT2);
    1842             :         }
    1843          21 :         break;
    1844             :         case SW_SERVICE_FIELDTYPE_BIBLIOGRAPHY:
    1845             :         {
    1846          18 :             SwAuthorityFieldType const type(pDoc);
    1847             :             pFld = new SwAuthorityField(static_cast<SwAuthorityFieldType*>(
    1848          18 :                         pDoc->InsertFldType(type)),
    1849          18 :                     OUString());
    1850          18 :             if (m_pImpl->m_pProps->aPropSeq.getLength())
    1851             :             {
    1852          16 :                 uno::Any aVal;
    1853          16 :                 aVal <<= m_pImpl->m_pProps->aPropSeq;
    1854          16 :                 pFld->PutValue( aVal, FIELD_PROP_PROP_SEQ );
    1855          18 :             }
    1856             :         }
    1857          18 :         break;
    1858             :         case SW_SERVICE_FIELDTYPE_COMBINED_CHARACTERS:
    1859             :             // create field
    1860             :             pFld = new SwCombinedCharField( (SwCombinedCharFieldType*)
    1861           0 :                         pDoc->GetSysFldType(RES_COMBINED_CHARS),
    1862           0 :                         m_pImpl->m_pProps->sPar1);
    1863           0 :             break;
    1864             :         case SW_SERVICE_FIELDTYPE_DROPDOWN:
    1865             :         {
    1866             :             SwDropDownField *const pDDField = new SwDropDownField(
    1867             :                 static_cast<SwDropDownFieldType *>(
    1868           0 :                     pDoc->GetSysFldType(RES_DROPDOWN)));
    1869           0 :             pFld = pDDField;
    1870             : 
    1871           0 :             pDDField->SetItems(m_pImpl->m_pProps->aStrings);
    1872           0 :             pDDField->SetSelectedItem(m_pImpl->m_pProps->sPar1);
    1873           0 :             pDDField->SetName(m_pImpl->m_pProps->sPar2);
    1874           0 :             pDDField->SetHelp(m_pImpl->m_pProps->sPar3);
    1875           0 :             pDDField->SetToolTip(m_pImpl->m_pProps->sPar4);
    1876             :         }
    1877           0 :         break;
    1878             : 
    1879             :         case SW_SERVICE_FIELDTYPE_TABLE_FORMULA :
    1880             :         {
    1881             :             // create field
    1882           0 :             sal_uInt16 nType = nsSwGetSetExpType::GSE_FORMULA;
    1883           0 :             if (m_pImpl->m_pProps->bBool1)
    1884             :             {
    1885           0 :                 nType |= nsSwExtendedSubType::SUB_CMD;
    1886           0 :                 if (m_pImpl->m_pProps->bFormatIsDefault)
    1887           0 :                     m_pImpl->m_pProps->nFormat = -1;
    1888             :             }
    1889             :             pFld = new SwTblField( (SwTblFieldType*)
    1890           0 :                 pDoc->GetSysFldType(RES_TABLEFLD),
    1891           0 :                 m_pImpl->m_pProps->sPar2,
    1892             :                 nType,
    1893           0 :                 m_pImpl->m_pProps->nFormat);
    1894           0 :            ((SwTblField*)pFld)->ChgExpStr(m_pImpl->m_pProps->sPar1);
    1895             :         }
    1896           0 :         break;
    1897             :         default: OSL_FAIL("was ist das fuer ein Typ?");
    1898             :     }
    1899         371 :     if (pFld)
    1900             :     {
    1901         371 :         pFld->SetAutomaticLanguage(!m_pImpl->m_pProps->bBool4);
    1902         371 :         SwFmtFld aFmt( *pFld );
    1903             : 
    1904         742 :         UnoActionContext aCont(pDoc);
    1905         389 :         if (aPam.HasMark() &&
    1906          18 :             m_pImpl->m_nServiceId != SW_SERVICE_FIELDTYPE_ANNOTATION)
    1907             :         {
    1908           2 :             pDoc->DeleteAndJoin(aPam);
    1909             :         }
    1910             : 
    1911         371 :         SwXTextCursor const*const pTextCursor(dynamic_cast<SwXTextCursor*>(pCursor));
    1912             :         const bool bForceExpandHints(
    1913             :             (pTextCursor)
    1914             :             ? pTextCursor->IsAtEndOfMeta()
    1915         371 :             : false );
    1916             :         const SetAttrMode nInsertFlags =
    1917             :             (bForceExpandHints)
    1918             :             ? nsSetAttrMode::SETATTR_FORCEHINTEXPAND
    1919         371 :             : nsSetAttrMode::SETATTR_DEFAULT;
    1920             : 
    1921         387 :         if (*aPam.GetPoint() != *aPam.GetMark() &&
    1922          16 :             m_pImpl->m_nServiceId == SW_SERVICE_FIELDTYPE_ANNOTATION)
    1923             :         {
    1924             :             // Make sure we always insert the field at the end
    1925          16 :             SwPaM aEnd(*aPam.End(), *aPam.End());
    1926          16 :             pDoc->InsertPoolItem(aEnd, aFmt, nInsertFlags);
    1927             :         }
    1928             :         else
    1929         355 :             pDoc->InsertPoolItem(aPam, aFmt, nInsertFlags);
    1930             : 
    1931         371 :         SwTxtAttr* pTxtAttr = aPam.GetNode()->GetTxtNode()->GetFldTxtAttrAt( aPam.GetPoint()->nContent.GetIndex()-1, true );
    1932             : 
    1933             :         // was passiert mit dem Update der Felder ? (siehe fldmgr.cxx)
    1934         371 :         if (pTxtAttr)
    1935             :         {
    1936         371 :             const SwFmtFld& rFld = pTxtAttr->GetFmtFld();
    1937         371 :             m_pImpl->m_pFmtFld = &rFld;
    1938             : 
    1939         742 :             if ( pTxtAttr->Which() == RES_TXTATR_ANNOTATION
    1940         371 :                  && *aPam.GetPoint() != *aPam.GetMark() )
    1941             :             {
    1942             :                 // create annotation mark
    1943          16 :                 const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTxtAttr->GetFmtFld().GetField());
    1944             :                 OSL_ENSURE( pPostItField != NULL, "<SwXTextField::attachToRange(..)> - annotation field missing!" );
    1945          16 :                 if ( pPostItField != NULL )
    1946             :                 {
    1947          16 :                     IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
    1948          16 :                     pMarksAccess->makeAnnotationMark( aPam, pPostItField->GetName() );
    1949             :                 }
    1950             :             }
    1951         371 :         }
    1952             :     }
    1953         371 :     delete pFld;
    1954             : 
    1955         371 :     m_pImpl->m_pDoc = pDoc;
    1956         371 :     m_pImpl->m_pDoc->GetUnoCallBack()->Add(m_pImpl.get());
    1957         371 :     m_pImpl->m_bIsDescriptor = false;
    1958         371 :     if (m_pImpl->m_FieldTypeClient.GetRegisteredIn())
    1959             :     {
    1960          49 :         const_cast<SwModify*>(m_pImpl->m_FieldTypeClient.GetRegisteredIn())
    1961          98 :             ->Remove(&m_pImpl->m_FieldTypeClient);
    1962             :     }
    1963         371 :     m_pImpl->m_pProps.reset();
    1964         371 :     if (m_pImpl->m_bCallUpdate)
    1965         371 :         update();
    1966             :     }
    1967          58 :     else if ( m_pImpl->m_pFmtFld != NULL
    1968          29 :               && m_pImpl->m_pDoc != NULL
    1969          58 :               && m_pImpl->m_nServiceId == SW_SERVICE_FIELDTYPE_ANNOTATION )
    1970             :     {
    1971          11 :         SwUnoInternalPaM aIntPam( *m_pImpl->m_pDoc );
    1972          11 :         if ( ::sw::XTextRangeToSwPaM( aIntPam, xTextRange ) )
    1973             :         {
    1974             :             // nothing to do, if the text range only covers the former annotation field
    1975          22 :             if ( aIntPam.Start()->nNode != aIntPam.End()->nNode
    1976          11 :                  || aIntPam.Start()->nContent.GetIndex() != aIntPam.End()->nContent.GetIndex()-1 )
    1977             :             {
    1978          11 :                 UnoActionContext aCont( m_pImpl->m_pDoc );
    1979             :                 // insert copy of annotation at new text range
    1980          11 :                 SwPostItField* pPostItField = static_cast< SwPostItField* >(m_pImpl->m_pFmtFld->GetField()->CopyField());
    1981          22 :                 SwFmtFld aFmtFld( *pPostItField );
    1982          11 :                 delete pPostItField;
    1983          22 :                 SwPaM aEnd( *aIntPam.End(), *aIntPam.End() );
    1984          11 :                 m_pImpl->m_pDoc->InsertPoolItem( aEnd, aFmtFld, nsSetAttrMode::SETATTR_DEFAULT );
    1985             :                 // delete former annotation
    1986             :                 {
    1987          11 :                     const SwTxtFld* pTxtFld = m_pImpl->m_pFmtFld->GetTxtFld();
    1988          11 :                     SwTxtNode& rTxtNode = (SwTxtNode&)*pTxtFld->GetpTxtNode();
    1989          11 :                     SwPaM aPam( rTxtNode, *pTxtFld->GetStart() );
    1990          11 :                     aPam.SetMark();
    1991          11 :                     aPam.Move();
    1992          11 :                     m_pImpl->m_pDoc->DeleteAndJoin(aPam);
    1993             :                 }
    1994             :                 // keep inserted annotation
    1995             :                 {
    1996          11 :                     SwTxtFld* pTxtAttr = aEnd.GetNode()->GetTxtNode()->GetFldTxtAttrAt( aEnd.End()->nContent.GetIndex()-1, true );
    1997          11 :                     if ( pTxtAttr != NULL )
    1998             :                     {
    1999          11 :                         m_pImpl->m_pFmtFld = &pTxtAttr->GetFmtFld();
    2000             : 
    2001          11 :                         if ( *aIntPam.GetPoint() != *aIntPam.GetMark() )
    2002             :                         {
    2003             :                             // create annotation mark
    2004          11 :                             const SwPostItField* pField = dynamic_cast< const SwPostItField* >(pTxtAttr->GetFmtFld().GetField());
    2005             :                             OSL_ENSURE( pField != NULL, "<SwXTextField::attach(..)> - annotation field missing!" );
    2006          11 :                             if ( pField != NULL )
    2007             :                             {
    2008          11 :                                 IDocumentMarkAccess* pMarksAccess = aIntPam.GetDoc()->getIDocumentMarkAccess();
    2009          11 :                                 pMarksAccess->makeAnnotationMark( aIntPam, pField->GetName() );
    2010             :                             }
    2011             :                         }
    2012             :                     }
    2013          11 :                 }
    2014             :             }
    2015             :         }
    2016             :         else
    2017           0 :             throw lang::IllegalArgumentException();
    2018             :     }
    2019             :     else
    2020          18 :         throw lang::IllegalArgumentException();
    2021         382 : }
    2022             : 
    2023             : uno::Reference< text::XTextRange > SAL_CALL
    2024         135 : SwXTextField::getAnchor() throw (uno::RuntimeException, std::exception)
    2025             : {
    2026         135 :     SolarMutexGuard aGuard;
    2027             : 
    2028         135 :     SwField const*const pField = m_pImpl->GetField();
    2029         135 :     if (!pField)
    2030           0 :         return 0;
    2031             : 
    2032         135 :     const SwTxtFld* pTxtFld = m_pImpl->m_pFmtFld->GetTxtFld();
    2033         135 :     if (!pTxtFld)
    2034           0 :         throw uno::RuntimeException();
    2035         135 :     const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
    2036             : 
    2037         270 :     SwPaM aPam(rTxtNode, *pTxtFld->GetStart() + 1, rTxtNode, *pTxtFld->GetStart());
    2038             : 
    2039             :     uno::Reference<text::XTextRange> xRange = SwXTextRange::CreateXTextRange(
    2040         270 :             *m_pImpl->m_pDoc, *aPam.GetPoint(), aPam.GetMark());
    2041         270 :     return xRange;
    2042             : }
    2043             : 
    2044           3 : void SAL_CALL SwXTextField::dispose() throw (uno::RuntimeException, std::exception)
    2045             : {
    2046           3 :     SolarMutexGuard aGuard;
    2047           3 :     SwField const*const pField = m_pImpl->GetField();
    2048           3 :     if(pField)
    2049             :     {
    2050           3 :         UnoActionContext aContext(m_pImpl->m_pDoc);
    2051           3 :         const SwTxtFld* pTxtFld = m_pImpl->m_pFmtFld->GetTxtFld();
    2052           3 :         SwTxtNode& rTxtNode = (SwTxtNode&)*pTxtFld->GetpTxtNode();
    2053           6 :         SwPaM aPam(rTxtNode, *pTxtFld->GetStart());
    2054           3 :         aPam.SetMark();
    2055           3 :         aPam.Move();
    2056           6 :         m_pImpl->m_pDoc->DeleteAndJoin(aPam);
    2057             :     }
    2058             : 
    2059           3 :     if (m_pImpl->m_pTextObject)
    2060             :     {
    2061           0 :         m_pImpl->m_pTextObject->DisposeEditSource();
    2062           0 :         m_pImpl->m_pTextObject->release();
    2063           0 :         m_pImpl->m_pTextObject = 0;
    2064           3 :     }
    2065           3 : }
    2066             : 
    2067           2 : void SAL_CALL SwXTextField::addEventListener(
    2068             :         const uno::Reference<lang::XEventListener> & xListener)
    2069             : throw (uno::RuntimeException, std::exception)
    2070             : {
    2071             :     // no need to lock here as m_pImpl is const and container threadsafe
    2072           2 :     m_pImpl->m_EventListeners.addInterface(xListener);
    2073           2 : }
    2074             : 
    2075           1 : void SAL_CALL SwXTextField::removeEventListener(
    2076             :         const uno::Reference<lang::XEventListener> & xListener)
    2077             : throw (uno::RuntimeException, std::exception)
    2078             : {
    2079             :     // no need to lock here as m_pImpl is const and container threadsafe
    2080           1 :     m_pImpl->m_EventListeners.removeInterface(xListener);
    2081           1 : }
    2082             : 
    2083             : uno::Reference< beans::XPropertySetInfo > SAL_CALL
    2084          77 : SwXTextField::getPropertySetInfo()
    2085             : throw (uno::RuntimeException, std::exception)
    2086             : {
    2087          77 :     SolarMutexGuard aGuard;
    2088             :     //kein static
    2089          77 :     uno::Reference< beans::XPropertySetInfo >  aRef;
    2090          77 :     if (m_pImpl->m_nServiceId == USHRT_MAX)
    2091             :     {
    2092           0 :         throw uno::RuntimeException();
    2093             :     }
    2094             :     const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(
    2095          77 :                     lcl_GetPropertyMapOfService(m_pImpl->m_nServiceId));
    2096         154 :     uno::Reference<beans::XPropertySetInfo> xInfo = pPropSet->getPropertySetInfo();
    2097             :     // extend PropertySetInfo!
    2098         154 :     const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
    2099         154 :     aRef = new SfxExtItemPropertySetInfo(
    2100             :         aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_PARAGRAPH_EXTENSIONS),
    2101         154 :         aPropSeq );
    2102         154 :     return aRef;
    2103             : }
    2104             : 
    2105             : void SAL_CALL
    2106        1177 : SwXTextField::setPropertyValue(
    2107             :         const OUString& rPropertyName, const uno::Any& rValue)
    2108             : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
    2109             :     lang::IllegalArgumentException, lang::WrappedTargetException,
    2110             :     uno::RuntimeException, std::exception)
    2111             : {
    2112        1177 :     SolarMutexGuard aGuard;
    2113        1177 :     SwField const*const pField = m_pImpl->GetField();
    2114             :     const SfxItemPropertySet* _pPropSet = aSwMapProvider.GetPropertySet(
    2115        1177 :                 lcl_GetPropertyMapOfService(m_pImpl->m_nServiceId));
    2116        1177 :     const SfxItemPropertySimpleEntry*   pEntry = _pPropSet->getPropertyMap().getByName(rPropertyName);
    2117             : 
    2118        1177 :     if (!pEntry)
    2119         152 :         throw beans::UnknownPropertyException(OUString( "Unknown property: " ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
    2120        1025 :     if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
    2121           1 :         throw beans::PropertyVetoException ("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
    2122             : 
    2123        1024 :     if(pField)
    2124             :     {
    2125             :         // special treatment for mail merge fields
    2126          83 :         sal_uInt16 nWhich = pField->Which();
    2127          95 :         if( RES_DBFLD == nWhich &&
    2128          24 :             (rPropertyName == UNO_NAME_DATA_BASE_NAME ||
    2129          24 :             rPropertyName == UNO_NAME_DATA_BASE_URL||
    2130          24 :             rPropertyName == UNO_NAME_DATA_TABLE_NAME||
    2131          12 :             rPropertyName == UNO_NAME_DATA_COLUMN_NAME))
    2132             :         {
    2133             :             // here a new field type must be created and the field must
    2134             :             // be registered at the new type
    2135             :             OSL_FAIL("not implemented");
    2136             :         }
    2137             :         else
    2138             :         {
    2139          83 :             SwDoc * pDoc = m_pImpl->m_pDoc;
    2140             :             assert(pDoc);
    2141          83 :             const SwTxtFld* pTxtFld = m_pImpl->m_pFmtFld->GetTxtFld();
    2142          83 :             if(!pTxtFld)
    2143           0 :                 throw uno::RuntimeException();
    2144          83 :             SwPosition aPosition( pTxtFld->GetTxtNode() );
    2145          83 :             aPosition.nContent = *pTxtFld->GetStart();
    2146          83 :             pDoc->PutValueToField( aPosition, rValue, pEntry->nWID);
    2147             :         }
    2148             : 
    2149             :         //#i100374# notify SwPostIt about new field content
    2150          83 :         if (RES_POSTITFLD == nWhich && m_pImpl->m_pFmtFld)
    2151             :         {
    2152           0 :             const_cast<SwFmtFld*>(m_pImpl->m_pFmtFld)->Broadcast(
    2153           0 :                     SwFmtFldHint( 0, SWFMTFLD_CHANGED ));
    2154             :         }
    2155             : 
    2156             :         // fdo#42073 notify SwTxtFld about changes of the expanded string
    2157          83 :         if (m_pImpl->m_pFmtFld->GetTxtFld())
    2158             :         {
    2159          83 :             m_pImpl->m_pFmtFld->GetTxtFld()->ExpandTxtFld();
    2160             :         }
    2161             : 
    2162             :         //#i100374# changing a document field should set the modify flag
    2163          83 :         SwDoc* pDoc = m_pImpl->m_pDoc;
    2164          83 :         if (pDoc)
    2165          83 :             pDoc->SetModified();
    2166             : 
    2167             :     }
    2168         941 :     else if (m_pImpl->m_pProps)
    2169             :     {
    2170         941 :         sal_Bool* pBool = 0;
    2171         941 :         switch(pEntry->nWID)
    2172             :         {
    2173             :         case FIELD_PROP_PAR1:
    2174          95 :             rValue >>= m_pImpl->m_pProps->sPar1;
    2175          95 :             break;
    2176             :         case FIELD_PROP_PAR2:
    2177          53 :             rValue >>= m_pImpl->m_pProps->sPar2;
    2178          53 :             break;
    2179             :         case FIELD_PROP_PAR3:
    2180          81 :             rValue >>= m_pImpl->m_pProps->sPar3;
    2181          81 :             break;
    2182             :         case FIELD_PROP_PAR4:
    2183          53 :             rValue >>= m_pImpl->m_pProps->sPar4;
    2184          53 :             break;
    2185             :         case FIELD_PROP_FORMAT:
    2186         174 :             rValue >>= m_pImpl->m_pProps->nFormat;
    2187         174 :             m_pImpl->m_pProps->bFormatIsDefault = false;
    2188         174 :             break;
    2189             :         case FIELD_PROP_SUBTYPE:
    2190         157 :             m_pImpl->m_pProps->nSubType = SWUnoHelper::GetEnumAsInt32(rValue);
    2191         157 :             break;
    2192             :         case FIELD_PROP_BYTE1 :
    2193           0 :             rValue >>= m_pImpl->m_pProps->nByte1;
    2194           0 :             break;
    2195             :         case FIELD_PROP_BOOL1 :
    2196          39 :             pBool = &m_pImpl->m_pProps->bBool1;
    2197          39 :             break;
    2198             :         case FIELD_PROP_BOOL2 :
    2199          43 :             pBool = &m_pImpl->m_pProps->bBool2;
    2200          43 :             break;
    2201             :         case FIELD_PROP_BOOL3 :
    2202           1 :             pBool = &m_pImpl->m_pProps->bBool3;
    2203           1 :             break;
    2204             :         case FIELD_PROP_BOOL4:
    2205           4 :             pBool = &m_pImpl->m_pProps->bBool4;
    2206           4 :         break;
    2207             :         case FIELD_PROP_DATE :
    2208             :         {
    2209           0 :             if(rValue.getValueType() != ::getCppuType(static_cast<const util::Date*>(0)))
    2210           0 :                 throw lang::IllegalArgumentException();
    2211             : 
    2212           0 :             util::Date aTemp = *(const util::Date*)rValue.getValue();
    2213           0 :             m_pImpl->m_pProps->aDate = Date(aTemp.Day, aTemp.Month, aTemp.Year);
    2214             :         }
    2215           0 :         break;
    2216             :         case FIELD_PROP_USHORT1:
    2217             :         case FIELD_PROP_USHORT2:
    2218             :             {
    2219         192 :                  sal_Int16 nVal = 0;
    2220         192 :                 rValue >>= nVal;
    2221         192 :                 if( FIELD_PROP_USHORT1 == pEntry->nWID)
    2222          61 :                     m_pImpl->m_pProps->nUSHORT1 = nVal;
    2223             :                 else
    2224         131 :                     m_pImpl->m_pProps->nUSHORT2 = nVal;
    2225             :             }
    2226         192 :             break;
    2227             :         case FIELD_PROP_SHORT1:
    2228           0 :             rValue >>= m_pImpl->m_pProps->nSHORT1;
    2229           0 :             break;
    2230             :         case FIELD_PROP_DOUBLE:
    2231           2 :             if(rValue.getValueType() != ::getCppuType(static_cast<const double*>(0)))
    2232           0 :                 throw lang::IllegalArgumentException();
    2233           2 :             rValue >>= m_pImpl->m_pProps->fDouble;
    2234           2 :             break;
    2235             : 
    2236             :         case FIELD_PROP_DATE_TIME :
    2237          31 :             if (!m_pImpl->m_pProps->pDateTime)
    2238          31 :                 m_pImpl->m_pProps->pDateTime = new util::DateTime;
    2239          31 :             rValue >>= (*m_pImpl->m_pProps->pDateTime);
    2240          31 :             break;
    2241             :         case FIELD_PROP_PROP_SEQ:
    2242          16 :             rValue >>= m_pImpl->m_pProps->aPropSeq;
    2243          16 :             break;
    2244             :         case FIELD_PROP_STRINGS:
    2245           0 :             rValue >>= m_pImpl->m_pProps->aStrings;
    2246           0 :             break;
    2247             :         }
    2248         941 :         if (pBool)
    2249             :         {
    2250          87 :             if( rValue.getValueType() == getCppuBooleanType() )
    2251          87 :                 *pBool = *(sal_Bool*)rValue.getValue();
    2252             :             else
    2253           0 :                 throw lang::IllegalArgumentException();
    2254             :         }
    2255             :     }
    2256             :     else
    2257           0 :         throw uno::RuntimeException();
    2258        1024 : }
    2259             : 
    2260         620 : uno::Any SAL_CALL SwXTextField::getPropertyValue(const OUString& rPropertyName)
    2261             : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
    2262             :     uno::RuntimeException, std::exception)
    2263             : {
    2264         620 :     SolarMutexGuard aGuard;
    2265         620 :     uno::Any aRet;
    2266         620 :     SwField const*const pField = m_pImpl->GetField();
    2267             :     const SfxItemPropertySet* _pPropSet = aSwMapProvider.GetPropertySet(
    2268         620 :                 lcl_GetPropertyMapOfService(m_pImpl->m_nServiceId));
    2269         620 :     const SfxItemPropertySimpleEntry*   pEntry = _pPropSet->getPropertyMap().getByName(rPropertyName);
    2270         620 :     if(!pEntry )
    2271             :     {
    2272         319 :         const SfxItemPropertySet* _pParaPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH_EXTENSIONS);
    2273         319 :         pEntry = _pParaPropSet->getPropertyMap().getByName(rPropertyName);
    2274             :     }
    2275         620 :     if (!pEntry)
    2276         313 :         throw beans::UnknownPropertyException(OUString( "Unknown property: " ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
    2277             : 
    2278         307 :     switch( pEntry->nWID )
    2279             :     {
    2280             :     case FN_UNO_TEXT_WRAP:
    2281           2 :         aRet <<= text::WrapTextMode_NONE;
    2282           2 :         break;
    2283             :     case FN_UNO_ANCHOR_TYPE:
    2284           2 :         aRet <<= text::TextContentAnchorType_AS_CHARACTER;
    2285           2 :         break;
    2286             :     case FN_UNO_ANCHOR_TYPES:
    2287             :         {
    2288           2 :             uno::Sequence<text::TextContentAnchorType> aTypes(1);
    2289           2 :             text::TextContentAnchorType* pArray = aTypes.getArray();
    2290           2 :             pArray[0] = text::TextContentAnchorType_AS_CHARACTER;
    2291           2 :             aRet.setValue(&aTypes, ::getCppuType(static_cast<uno::Sequence<text::TextContentAnchorType>*>(0)));
    2292             :         }
    2293           2 :         break;
    2294             : 
    2295             :     default:
    2296         301 :         if( pField )
    2297             :         {
    2298         404 :             if (FIELD_PROP_IS_FIELD_USED      == pEntry->nWID ||
    2299         202 :                 FIELD_PROP_IS_FIELD_DISPLAYED == pEntry->nWID)
    2300             :             {
    2301           0 :                 sal_Bool bIsFieldUsed       = sal_False;
    2302           0 :                 sal_Bool bIsFieldDisplayed  = sal_False;
    2303             : 
    2304             :                 // in order to have the information about fields
    2305             :                 // correctly evaluated the document needs a layout
    2306             :                 // (has to be already formatted)
    2307           0 :                 SwDoc *pDoc = m_pImpl->m_pDoc;
    2308           0 :                 SwViewShell *pViewShell = 0;
    2309           0 :                 SwEditShell *pEditShell = pDoc ? pDoc->GetEditShell( &pViewShell ) : 0;
    2310           0 :                 if (pEditShell)
    2311           0 :                     pEditShell->CalcLayout();
    2312           0 :                 else if (pViewShell) // a page preview has no SwEditShell it should only have a view shell
    2313           0 :                     pViewShell->CalcLayout();
    2314             :                 else
    2315           0 :                     throw uno::RuntimeException();
    2316             : 
    2317             :                 // get text node for the text field
    2318             :                 const SwFmtFld *pFldFmt =
    2319           0 :                     (m_pImpl->GetField()) ? m_pImpl->m_pFmtFld : 0;
    2320             :                 const SwTxtFld* pTxtFld = (pFldFmt)
    2321           0 :                     ? m_pImpl->m_pFmtFld->GetTxtFld() : 0;
    2322           0 :                 if(!pTxtFld)
    2323           0 :                     throw uno::RuntimeException();
    2324           0 :                 const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
    2325             : 
    2326             :                 // skip fields that are currently not in the document
    2327             :                 // e.g. fields in undo or redo array
    2328           0 :                 if (rTxtNode.GetNodes().IsDocNodes())
    2329             :                 {
    2330           0 :                     sal_Bool bFrame = 0 != rTxtNode.FindLayoutRect().Width(); // oder so
    2331           0 :                     sal_Bool bHidden = rTxtNode.IsHidden();
    2332           0 :                     if ( !bHidden )
    2333             :                     {
    2334             :                         sal_Int32 nHiddenStart;
    2335             :                         sal_Int32 nHiddenEnd;
    2336             : 
    2337           0 :                         SwPosition aPosition( pTxtFld->GetTxtNode() );
    2338           0 :                         aPosition.nContent = *pTxtFld->GetStart();
    2339             : 
    2340           0 :                         bHidden = SwScriptInfo::GetBoundsOfHiddenRange( pTxtFld->GetTxtNode(),
    2341           0 :                                         *pTxtFld->GetStart(),
    2342           0 :                                         nHiddenStart, nHiddenEnd );
    2343             :                     }
    2344             : 
    2345             :                     // !bFrame && !bHidden: aller Wahrscheinlichkeit handelt es
    2346             :                     // sich um ein Feld in einem unbenutzten Seitenstyle
    2347             : 
    2348             :                     // bHidden: Feld ist versteckt
    2349             :                     // FME: Problem: Verstecktes Feld in unbenutzter Seitenvorlage =>
    2350             :                     // bIsFieldUsed = true
    2351             :                     // bIsFieldDisplayed = false
    2352           0 :                     bIsFieldUsed       = bFrame || bHidden;
    2353           0 :                     bIsFieldDisplayed  = bIsFieldUsed && !bHidden;
    2354             :                 }
    2355           0 :                 sal_Bool bRetVal = (FIELD_PROP_IS_FIELD_USED == pEntry->nWID) ?
    2356           0 :                                             bIsFieldUsed : bIsFieldDisplayed;
    2357           0 :                 aRet.setValue( &bRetVal, ::getCppuBooleanType() );
    2358             :             }
    2359             :             else
    2360         202 :                 pField->QueryValue( aRet, pEntry->nWID );
    2361             :         }
    2362          99 :         else if (m_pImpl->m_pProps)     // currently just a descriptor...
    2363             :         {
    2364          99 :             switch(pEntry->nWID)
    2365             :             {
    2366             :             case FIELD_PROP_TEXT:
    2367             :                 {
    2368          33 :                     if (!m_pImpl->m_pTextObject)
    2369             :                     {
    2370             :                         SwTextAPIEditSource* pObj =
    2371          33 :                             new SwTextAPIEditSource(m_pImpl->m_pDoc);
    2372          33 :                         m_pImpl->m_pTextObject = new SwTextAPIObject( pObj );
    2373          33 :                         m_pImpl->m_pTextObject->acquire();
    2374             :                     }
    2375             : 
    2376          33 :                     uno::Reference<text::XText> xText(m_pImpl->m_pTextObject);
    2377          33 :                     aRet <<= xText;
    2378          33 :                     break;
    2379             :                 }
    2380             :             case FIELD_PROP_PAR1:
    2381           1 :                 aRet <<= m_pImpl->m_pProps->sPar1;
    2382           1 :                 break;
    2383             :             case FIELD_PROP_PAR2:
    2384          41 :                 aRet <<= m_pImpl->m_pProps->sPar2;
    2385          41 :                 break;
    2386             :             case FIELD_PROP_PAR3:
    2387           0 :                 aRet <<= m_pImpl->m_pProps->sPar3;
    2388           0 :                 break;
    2389             :             case FIELD_PROP_PAR4:
    2390           2 :                 aRet <<= m_pImpl->m_pProps->sPar4;
    2391           2 :                 break;
    2392             :             case FIELD_PROP_FORMAT:
    2393          10 :                 aRet <<= m_pImpl->m_pProps->nFormat;
    2394          10 :                 break;
    2395             :             case FIELD_PROP_SUBTYPE:
    2396           2 :                 aRet <<= m_pImpl->m_pProps->nSubType;
    2397           2 :                 break;
    2398             :             case FIELD_PROP_BYTE1 :
    2399           0 :                 aRet <<= m_pImpl->m_pProps->nByte1;
    2400           0 :                 break;
    2401             :             case FIELD_PROP_BOOL1 :
    2402           1 :                 aRet.setValue(&m_pImpl->m_pProps->bBool1, ::getCppuBooleanType());
    2403           1 :                 break;
    2404             :             case FIELD_PROP_BOOL2 :
    2405           2 :                 aRet.setValue(&m_pImpl->m_pProps->bBool2, ::getCppuBooleanType());
    2406           2 :                 break;
    2407             :             case FIELD_PROP_BOOL3 :
    2408           1 :                 aRet.setValue(&m_pImpl->m_pProps->bBool3, ::getCppuBooleanType());
    2409           1 :                 break;
    2410             :             case FIELD_PROP_BOOL4 :
    2411           2 :                 aRet.setValue(&m_pImpl->m_pProps->bBool4, ::getCppuBooleanType());
    2412           2 :                 break;
    2413             :             case FIELD_PROP_DATE :
    2414           0 :                 aRet.setValue(&m_pImpl->m_pProps->aDate, ::getCppuType(static_cast<const util::Date*>(0)));
    2415           0 :                 break;
    2416             :             case FIELD_PROP_USHORT1:
    2417           2 :                 aRet <<= static_cast<sal_Int16>(m_pImpl->m_pProps->nUSHORT1);
    2418           2 :                 break;
    2419             :             case FIELD_PROP_USHORT2:
    2420           1 :                 aRet <<= static_cast<sal_Int16>(m_pImpl->m_pProps->nUSHORT2);
    2421           1 :                 break;
    2422             :             case FIELD_PROP_SHORT1:
    2423           0 :                 aRet <<= m_pImpl->m_pProps->nSHORT1;
    2424           0 :                 break;
    2425             :             case FIELD_PROP_DOUBLE:
    2426           1 :                 aRet <<= m_pImpl->m_pProps->fDouble;
    2427           1 :                 break;
    2428             :             case FIELD_PROP_DATE_TIME :
    2429           0 :                 if (m_pImpl->m_pProps->pDateTime)
    2430           0 :                     aRet <<= (*m_pImpl->m_pProps->pDateTime);
    2431           0 :                 break;
    2432             :             case FIELD_PROP_PROP_SEQ:
    2433           0 :                 aRet <<= m_pImpl->m_pProps->aPropSeq;
    2434           0 :                 break;
    2435             :             case FIELD_PROP_STRINGS:
    2436           0 :                 aRet <<= m_pImpl->m_pProps->aStrings;
    2437           0 :                 break;
    2438             :             case FIELD_PROP_IS_FIELD_USED:
    2439             :             case FIELD_PROP_IS_FIELD_DISPLAYED:
    2440           0 :                 aRet <<= false;
    2441           0 :                 break;
    2442             :             }
    2443             :         }
    2444             :         else
    2445           0 :             throw uno::RuntimeException();
    2446             :     }
    2447         620 :     return aRet;
    2448             : }
    2449             : 
    2450           0 : void SwXTextField::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
    2451             : {
    2452             :     OSL_FAIL("not implemented");
    2453           0 : }
    2454             : 
    2455           0 : void SwXTextField::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
    2456             : {
    2457             :     OSL_FAIL("not implemented");
    2458           0 : }
    2459             : 
    2460           0 : void SwXTextField::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
    2461             : {
    2462             :     OSL_FAIL("not implemented");
    2463           0 : }
    2464             : 
    2465           0 : void SwXTextField::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
    2466             : {
    2467             :     OSL_FAIL("not implemented");
    2468           0 : }
    2469             : 
    2470           0 : void SAL_CALL SwXTextField::update() throw (uno::RuntimeException, std::exception)
    2471             : {
    2472           0 :     SolarMutexGuard aGuard;
    2473           0 :     SwField const*const pFld = m_pImpl->GetField();
    2474           0 :     if (pFld)
    2475             :     {
    2476           0 :         switch(pFld->Which())
    2477             :         {
    2478             :             case RES_DATETIMEFLD:
    2479           0 :             ((SwDateTimeField*)pFld)->SetDateTime( ::DateTime( ::DateTime::SYSTEM ) );
    2480           0 :             break;
    2481             : 
    2482             :             case RES_EXTUSERFLD:
    2483             :             {
    2484           0 :                 SwExtUserField* pExtUserFld = (SwExtUserField*)pFld;
    2485           0 :                 pExtUserFld->SetExpansion( ((SwExtUserFieldType*)pFld->GetTyp())->Expand(
    2486           0 :                                             pExtUserFld->GetSubType(),
    2487           0 :                                             pExtUserFld->GetFormat() ) );
    2488             :             }
    2489           0 :             break;
    2490             : 
    2491             :             case RES_AUTHORFLD:
    2492             :             {
    2493           0 :                 SwAuthorField* pAuthorFld = (SwAuthorField*)pFld;
    2494           0 :                 pAuthorFld->SetExpansion( ((SwAuthorFieldType*)pFld->GetTyp())->Expand(
    2495           0 :                                             pAuthorFld->GetFormat() ) );
    2496             :             }
    2497           0 :             break;
    2498             : 
    2499             :             case RES_FILENAMEFLD:
    2500             :             {
    2501           0 :                 SwFileNameField* pFileNameFld = (SwFileNameField*)pFld;
    2502           0 :                 pFileNameFld->SetExpansion( ((SwFileNameFieldType*)pFld->GetTyp())->Expand(
    2503           0 :                                             pFileNameFld->GetFormat() ) );
    2504             :             }
    2505           0 :             break;
    2506             : 
    2507             :             case RES_DOCINFOFLD:
    2508             :             {
    2509           0 :                     SwDocInfoField* pDocInfFld = (SwDocInfoField*)pFld;
    2510           0 :                     pDocInfFld->SetExpansion( ((SwDocInfoFieldType*)pFld->GetTyp())->Expand(
    2511           0 :                                                 pDocInfFld->GetSubType(),
    2512             :                                                 pDocInfFld->GetFormat(),
    2513           0 :                                                 pDocInfFld->GetLanguage(),
    2514           0 :                                                 pDocInfFld->GetName() ) );
    2515             :             }
    2516           0 :             break;
    2517             :         }
    2518             :         // Text formatting has to be triggered.
    2519           0 :         const_cast<SwFmtFld*>(m_pImpl->m_pFmtFld)->ModifyNotification(0, 0);
    2520             :     }
    2521             :     else
    2522           0 :         m_pImpl->m_bCallUpdate = true;
    2523           0 : }
    2524             : 
    2525           0 : OUString SAL_CALL SwXTextField::getImplementationName()
    2526             : throw (uno::RuntimeException, std::exception)
    2527             : {
    2528           0 :     return OUString("SwXTextField");
    2529             : }
    2530             : 
    2531         279 : static OUString OldNameToNewName_Impl( const OUString &rOld )
    2532             : {
    2533         279 :     static OUString aOldNamePart1(".TextField.DocInfo.");
    2534         279 :     static OUString aOldNamePart2(".TextField.");
    2535         279 :     static OUString aNewNamePart1(".textfield.docinfo.");
    2536         279 :     static OUString aNewNamePart2(".textfield.");
    2537         279 :     OUString sServiceNameCC( rOld );
    2538         279 :     sal_Int32 nIdx = sServiceNameCC.indexOf( aOldNamePart1 );
    2539         279 :     if (nIdx >= 0)
    2540           6 :         sServiceNameCC = sServiceNameCC.replaceAt( nIdx, aOldNamePart1.getLength(), aNewNamePart1 );
    2541         279 :     nIdx = sServiceNameCC.indexOf( aOldNamePart2 );
    2542         279 :     if (nIdx >= 0)
    2543         273 :         sServiceNameCC = sServiceNameCC.replaceAt( nIdx, aOldNamePart2.getLength(), aNewNamePart2 );
    2544         279 :     return sServiceNameCC;
    2545             : }
    2546             : 
    2547         273 : sal_Bool SAL_CALL SwXTextField::supportsService(const OUString& rServiceName)
    2548             : throw (uno::RuntimeException, std::exception)
    2549             : {
    2550         273 :     return cppu::supportsService(this, rServiceName);
    2551             : }
    2552             : 
    2553         279 : uno::Sequence< OUString > SAL_CALL SwXTextField::getSupportedServiceNames()
    2554             : throw (uno::RuntimeException, std::exception)
    2555             : {
    2556             :     OUString sServiceName =
    2557         279 :         SwXServiceProvider::GetProviderName(m_pImpl->m_nServiceId);
    2558             : 
    2559             :     // case-corected version of service-name (see #i67811)
    2560             :     // (need to supply both because of compatibility to older versions)
    2561         558 :     OUString sServiceNameCC(  OldNameToNewName_Impl( sServiceName ) );
    2562         279 :     sal_Int32 nLen = sServiceName == sServiceNameCC ? 2 : 3;
    2563             : 
    2564         279 :     uno::Sequence< OUString > aRet( nLen );
    2565         279 :     OUString* pArray = aRet.getArray();
    2566         279 :     *pArray++ = sServiceName;
    2567         279 :     if (nLen == 3)
    2568         279 :         *pArray++ = sServiceNameCC;
    2569         279 :     *pArray++ = "com.sun.star.text.TextContent";
    2570         558 :     return aRet;
    2571             : }
    2572             : 
    2573          68 : void SwXTextField::Impl::Invalidate()
    2574             : {
    2575          68 :     if (GetRegisteredIn())
    2576             :     {
    2577          68 :         GetRegisteredInNonConst()->Remove(this);
    2578          68 :         m_pFmtFld = 0;
    2579          68 :         m_pDoc = 0;
    2580          68 :         lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis));
    2581          68 :         m_EventListeners.disposeAndClear(ev);
    2582             :     }
    2583          68 : }
    2584             : 
    2585          85 : void SwXTextField::Impl::Modify(
    2586             :         SfxPoolItem const*const pOld, SfxPoolItem const*const pNew)
    2587             : {
    2588          85 :     switch( pOld ? pOld->Which() : 0 )
    2589             :     {
    2590             :     case RES_REMOVE_UNO_OBJECT:
    2591             :     case RES_OBJECTDYING:
    2592          27 :         if( (void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
    2593          27 :             Invalidate();
    2594          27 :         break;
    2595             : 
    2596             :     case RES_FMT_CHG:
    2597             :         // wurden wir an das neue umgehaengt und wird das alte geloscht?
    2598           0 :         if( ((SwFmtChg*)pNew)->pChangedFmt == GetRegisteredIn() &&
    2599           0 :             ((SwFmtChg*)pOld)->pChangedFmt->IsFmtInDTOR() )
    2600           0 :             Invalidate();
    2601           0 :         break;
    2602             :     case RES_FIELD_DELETED:
    2603          58 :         if ((void*)m_pFmtFld == ((SwPtrMsgPoolItem *)pOld)->pObject)
    2604          41 :             Invalidate();
    2605          58 :         break;
    2606             :     }
    2607          85 : }
    2608             : 
    2609        1978 : const SwField*  SwXTextField::Impl::GetField() const
    2610             : {
    2611        1978 :     if (GetRegisteredIn() && m_pFmtFld)
    2612             :     {
    2613         788 :         return m_pFmtFld->GetField();
    2614             :     }
    2615        1190 :     return 0;
    2616             : }
    2617             : 
    2618             : /******************************************************************
    2619             :  * SwXTextFieldMasters
    2620             :  ******************************************************************/
    2621           0 : OUString SwXTextFieldMasters::getImplementationName(void) throw( uno::RuntimeException, std::exception )
    2622             : {
    2623           0 :     return OUString("SwXTextFieldMasters");
    2624             : }
    2625             : 
    2626           0 : sal_Bool SwXTextFieldMasters::supportsService(const OUString& rServiceName) throw( uno::RuntimeException, std::exception )
    2627             : {
    2628           0 :     return cppu::supportsService(this, rServiceName);
    2629             : }
    2630             : 
    2631           0 : uno::Sequence< OUString > SwXTextFieldMasters::getSupportedServiceNames(void) throw( uno::RuntimeException, std::exception )
    2632             : {
    2633           0 :     uno::Sequence< OUString > aRet(1);
    2634           0 :     OUString* pArray = aRet.getArray();
    2635           0 :     pArray[0] = "com.sun.star.text.TextFieldMasters";
    2636           0 :     return aRet;
    2637             : }
    2638             : 
    2639         140 : SwXTextFieldMasters::SwXTextFieldMasters(SwDoc* _pDoc) :
    2640         140 :     SwUnoCollection(_pDoc)
    2641             : {
    2642         140 : }
    2643             : 
    2644         278 : SwXTextFieldMasters::~SwXTextFieldMasters()
    2645             : {
    2646             : 
    2647         278 : }
    2648             : 
    2649             : /*-----------------------------------------------------------------------
    2650             :     Iteration ueber nicht-Standard Feldtypen
    2651             :     USER/SETEXP/DDE/DATABASE
    2652             :     Der Name ist demnach:
    2653             :     "com.sun.star.text.fieldmaster.User" + <Feltypname>
    2654             :     "com.sun.star.text.fieldmaster.DDE" + <Feltypname>
    2655             :     "com.sun.star.text.fieldmaster.SetExpression" + <Feltypname>
    2656             :     "com.sun.star.text.fieldmaster.DataBase" + <Feltypname>
    2657             : 
    2658             :     Falls wir grosszuegig werden wollen, dann koennte man com.sun.star.text
    2659             :     auch optional weglassen
    2660             :   -----------------------------------------------------------------------*/
    2661        1235 : static sal_uInt16 lcl_GetIdByName( OUString& rName, OUString& rTypeName )
    2662             : {
    2663        1235 :     if (rName.startsWithIgnoreAsciiCase(COM_TEXT_FLDMASTER_CC))
    2664        1233 :         rName = rName.copy(30);
    2665             : 
    2666        1235 :     sal_uInt16 nResId = USHRT_MAX;
    2667        1235 :     sal_Int32 nFound = 0;
    2668        1235 :     rTypeName = rName.getToken( 0, '.', nFound );
    2669        1235 :     if (rTypeName == "User")
    2670          26 :         nResId = RES_USERFLD;
    2671        1209 :     else if (rTypeName == "DDE")
    2672           0 :         nResId = RES_DDEFLD;
    2673        1209 :     else if (rTypeName == "SetExpression")
    2674             :     {
    2675        1185 :         nResId = RES_SETEXPFLD;
    2676             : 
    2677        1185 :         OUString sFldTypName( rName.getToken( 1, '.' ));
    2678        2370 :         OUString sUIName( SwStyleNameMapper::GetSpecialExtraUIName( sFldTypName ) );
    2679             : 
    2680        1185 :         if( sUIName != sFldTypName )
    2681        1185 :             rName = comphelper::string::setToken(rName, 1, '.', sUIName);
    2682             :     }
    2683          24 :     else if (rTypeName == "DataBase")
    2684             :     {
    2685           0 :         rName = rName.copy(RTL_CONSTASCII_LENGTH("DataBase."));
    2686           0 :         sal_uInt16 nDotCount = comphelper::string::getTokenCount(rName, '.');
    2687           0 :         if( 2 <= nDotCount )
    2688             :         {
    2689             :             // #i51815#
    2690           0 :             rName = "DataBase." + rName;
    2691           0 :             nResId = RES_DBFLD;
    2692             :         }
    2693             :     }
    2694          24 :     else if (rTypeName == "Bibliography")
    2695          22 :         nResId = RES_AUTHORITY;
    2696        1235 :     return nResId;
    2697             : }
    2698             : 
    2699         654 : uno::Any SwXTextFieldMasters::getByName(const OUString& rName)
    2700             :     throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
    2701             : {
    2702         654 :     SolarMutexGuard aGuard;
    2703         654 :     if(!GetDoc())
    2704           0 :         throw uno::RuntimeException();
    2705             : 
    2706        1308 :     OUString sName(rName), sTypeName;
    2707         654 :     sal_uInt16 nResId = lcl_GetIdByName( sName, sTypeName );
    2708         654 :     if( USHRT_MAX == nResId )
    2709             :         throw container::NoSuchElementException(
    2710           2 :             "SwXTextFieldMasters::getByName(" + rName + ")",
    2711           3 :             css::uno::Reference<css::uno::XInterface>());
    2712             : 
    2713         653 :     sName = sName.copy(std::min(sTypeName.getLength()+1, sName.getLength()));
    2714         653 :     SwFieldType* pType = GetDoc()->GetFldType(nResId, sName, true);
    2715         653 :     if(!pType)
    2716             :         throw container::NoSuchElementException(
    2717           0 :             "SwXTextFieldMasters::getByName(" + rName + ")",
    2718           0 :             css::uno::Reference<css::uno::XInterface>());
    2719             : 
    2720             :     uno::Reference<beans::XPropertySet> const xRet(
    2721        1306 :             SwXFieldMaster::CreateXFieldMaster(*GetDoc(), *pType));
    2722        1307 :     return uno::makeAny(xRet);
    2723             : }
    2724             : 
    2725         706 : sal_Bool SwXTextFieldMasters::getInstanceName(
    2726             :     const SwFieldType& rFldType, OUString& rName)
    2727             : {
    2728         706 :     OUString sField;
    2729             : 
    2730         706 :     switch( rFldType.Which() )
    2731             :     {
    2732             :     case RES_USERFLD:
    2733           0 :         sField = "User." + rFldType.GetName();
    2734           0 :         break;
    2735             :     case RES_DDEFLD:
    2736           0 :         sField = "DDE." + rFldType.GetName();
    2737           0 :         break;
    2738             : 
    2739             :     case RES_SETEXPFLD:
    2740          89 :         sField = "SetExpression." + SwStyleNameMapper::GetSpecialExtraProgName( rFldType.GetName() );
    2741          89 :         break;
    2742             : 
    2743             :     case RES_DBFLD:
    2744           0 :         sField = "DataBase." + rFldType.GetName().replaceAll(OUString(DB_DELIM), ".");
    2745           0 :         break;
    2746             : 
    2747             :     case RES_AUTHORITY:
    2748           1 :         sField = "Bibliography";
    2749           1 :         break;
    2750             : 
    2751             :     default:
    2752         616 :         return sal_False;
    2753             :     }
    2754             : 
    2755          90 :     rName += COM_TEXT_FLDMASTER_CC + sField;
    2756          90 :     return sal_True;
    2757             : }
    2758             : 
    2759          22 : uno::Sequence< OUString > SwXTextFieldMasters::getElementNames(void)
    2760             :     throw( uno::RuntimeException, std::exception )
    2761             : {
    2762          22 :     SolarMutexGuard aGuard;
    2763          22 :     if(!GetDoc())
    2764           0 :         throw uno::RuntimeException();
    2765             : 
    2766          22 :     const SwFldTypes* pFldTypes = GetDoc()->GetFldTypes();
    2767          22 :     const size_t nCount = pFldTypes->size();
    2768             : 
    2769          44 :     std::vector<OUString> aFldNames;
    2770         728 :     for( size_t i = 0; i < nCount; ++i )
    2771             :     {
    2772         706 :         SwFieldType& rFldType = *((*pFldTypes)[i]);
    2773             : 
    2774         706 :         OUString sFldName;
    2775         706 :         if (SwXTextFieldMasters::getInstanceName(rFldType, sFldName))
    2776             :         {
    2777          90 :             aFldNames.push_back(sFldName);
    2778             :         }
    2779         706 :     }
    2780             : 
    2781          22 :     uno::Sequence< OUString > aSeq( static_cast<sal_Int32>(aFldNames.size()) );
    2782          22 :     OUString* pArray = aSeq.getArray();
    2783         112 :     for (size_t i = 0; i<aFldNames.size(); ++i)
    2784             :     {
    2785          90 :         pArray[i] = aFldNames[i];
    2786             :     }
    2787             : 
    2788          44 :     return aSeq;
    2789             : }
    2790             : 
    2791         581 : sal_Bool SwXTextFieldMasters::hasByName(const OUString& rName) throw( uno::RuntimeException, std::exception )
    2792             : {
    2793         581 :     SolarMutexGuard aGuard;
    2794         581 :     if(!GetDoc())
    2795           0 :         throw uno::RuntimeException();
    2796             : 
    2797        1162 :     OUString sName(rName), sTypeName;
    2798         581 :     sal_uInt16 nResId = lcl_GetIdByName( sName, sTypeName );
    2799         581 :     sal_Bool bRet = sal_False;
    2800         581 :     if( USHRT_MAX != nResId )
    2801             :     {
    2802         580 :         sName = sName.copy(std::min(sTypeName.getLength()+1, sName.getLength()));
    2803         580 :         bRet = USHRT_MAX != nResId && 0 != GetDoc()->GetFldType(nResId, sName, true);
    2804             :     }
    2805        1162 :     return bRet;
    2806             : }
    2807             : 
    2808           1 : uno::Type  SwXTextFieldMasters::getElementType(void) throw( uno::RuntimeException, std::exception )
    2809             : {
    2810           1 :     return ::getCppuType(static_cast<const uno::Reference<beans::XPropertySet>*>(0));
    2811             : 
    2812             : }
    2813             : 
    2814           1 : sal_Bool SwXTextFieldMasters::hasElements(void) throw( uno::RuntimeException, std::exception )
    2815             : {
    2816           1 :     SolarMutexGuard aGuard;
    2817           1 :     if(!IsValid())
    2818           0 :         throw uno::RuntimeException();
    2819           1 :     return sal_True;
    2820             : }
    2821             : 
    2822             : /******************************************************************
    2823             :  * SwXFieldTypes
    2824             :  ******************************************************************/
    2825             : 
    2826        1205 : class SwXTextFieldTypes::Impl
    2827             : {
    2828             : private:
    2829             :     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
    2830             : 
    2831             : public:
    2832             :     ::cppu::OInterfaceContainerHelper m_RefreshListeners;
    2833             : 
    2834        1206 :     Impl() : m_RefreshListeners(m_Mutex) { }
    2835             : };
    2836             : 
    2837           0 : OUString SwXTextFieldTypes::getImplementationName(void) throw( uno::RuntimeException, std::exception )
    2838             : {
    2839           0 :     return OUString("SwXTextFieldTypes");
    2840             : }
    2841             : 
    2842           0 : sal_Bool SwXTextFieldTypes::supportsService(const OUString& rServiceName) throw( uno::RuntimeException, std::exception )
    2843             : {
    2844           0 :     return cppu::supportsService(this, rServiceName);
    2845             : }
    2846             : 
    2847           0 : uno::Sequence< OUString > SwXTextFieldTypes::getSupportedServiceNames(void) throw( uno::RuntimeException, std::exception )
    2848             : {
    2849           0 :     uno::Sequence< OUString > aRet(1);
    2850           0 :     OUString* pArray = aRet.getArray();
    2851           0 :     pArray[0] = "com.sun.star.text.TextFields";
    2852           0 :     return aRet;
    2853             : }
    2854             : 
    2855        1206 : SwXTextFieldTypes::SwXTextFieldTypes(SwDoc* _pDoc)
    2856             :     : SwUnoCollection (_pDoc)
    2857        1206 :     , m_pImpl(new Impl)
    2858             : {
    2859        1206 : }
    2860             : 
    2861        2410 : SwXTextFieldTypes::~SwXTextFieldTypes()
    2862             : {
    2863        2410 : }
    2864             : 
    2865        1205 : void SwXTextFieldTypes::Invalidate()
    2866             : {
    2867        1205 :     SwUnoCollection::Invalidate();
    2868        1205 :     lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this));
    2869        1205 :     m_pImpl->m_RefreshListeners.disposeAndClear(ev);
    2870        1205 : }
    2871             : 
    2872        1413 : uno::Reference< container::XEnumeration >  SwXTextFieldTypes::createEnumeration(void)
    2873             :     throw( uno::RuntimeException, std::exception )
    2874             : {
    2875        1413 :     SolarMutexGuard aGuard;
    2876        1413 :     if(!IsValid())
    2877           0 :         throw uno::RuntimeException();
    2878        1413 :     return new SwXFieldEnumeration(*GetDoc());
    2879             : }
    2880             : 
    2881           1 : uno::Type  SwXTextFieldTypes::getElementType(void) throw( uno::RuntimeException, std::exception )
    2882             : {
    2883           1 :     return ::getCppuType(static_cast<const uno::Reference<text::XDependentTextField>*>(0));
    2884             : }
    2885             : 
    2886           1 : sal_Bool SwXTextFieldTypes::hasElements(void) throw( uno::RuntimeException, std::exception )
    2887             : {
    2888           1 :     SolarMutexGuard aGuard;
    2889           1 :     if(!IsValid())
    2890           0 :         throw uno::RuntimeException();
    2891           1 :     return sal_True; // they always exist
    2892             : }
    2893             : 
    2894          44 : void SAL_CALL SwXTextFieldTypes::refresh() throw (uno::RuntimeException, std::exception)
    2895             : {
    2896             :     {
    2897          44 :         SolarMutexGuard aGuard;
    2898          44 :         if (!IsValid())
    2899           0 :             throw uno::RuntimeException();
    2900          88 :         UnoActionContext aContext(GetDoc());
    2901          44 :         GetDoc()->UpdateDocStat();
    2902          88 :         GetDoc()->UpdateFlds(0, false);
    2903             :     }
    2904             :     // call refresh listeners (without SolarMutex locked)
    2905          44 :     lang::EventObject const event(static_cast< ::cppu::OWeakObject*>(this));
    2906          44 :     m_pImpl->m_RefreshListeners.notifyEach(
    2907          88 :             & util::XRefreshListener::refreshed, event);
    2908          44 : }
    2909             : 
    2910           1 : void SAL_CALL SwXTextFieldTypes::addRefreshListener(
    2911             :         const uno::Reference<util::XRefreshListener> & xListener)
    2912             : throw (uno::RuntimeException, std::exception)
    2913             : {
    2914             :     // no need to lock here as m_pImpl is const and container threadsafe
    2915           1 :     m_pImpl->m_RefreshListeners.addInterface(xListener);
    2916           1 : }
    2917             : 
    2918           1 : void SAL_CALL SwXTextFieldTypes::removeRefreshListener(
    2919             :         const uno::Reference<util::XRefreshListener> & xListener)
    2920             : throw (uno::RuntimeException, std::exception)
    2921             : {
    2922             :     // no need to lock here as m_pImpl is const and container threadsafe
    2923           1 :     m_pImpl->m_RefreshListeners.removeInterface(xListener);
    2924           1 : }
    2925             : 
    2926             : /******************************************************************
    2927             :  * SwXFieldEnumeration
    2928             :  ******************************************************************/
    2929             : 
    2930        2826 : class SwXFieldEnumeration::Impl
    2931             :     : public SwClient
    2932             : {
    2933             : 
    2934             : public:
    2935             :     SwDoc * m_pDoc;
    2936             : 
    2937             :     uno::Sequence< uno::Reference<text::XTextField> > m_Items;
    2938             :     sal_Int32       m_nNextIndex;  ///< index of next element to be returned
    2939             : 
    2940        1413 :     Impl(SwDoc & rDoc)
    2941        1413 :         : SwClient(rDoc.GetPageDescFromPool(RES_POOLPAGE_STANDARD))
    2942             :         , m_pDoc(& rDoc)
    2943        1413 :         , m_nNextIndex(0)
    2944        1413 :     { }
    2945             : 
    2946             : protected:
    2947             :     // SwClient
    2948             :     virtual void Modify(SfxPoolItem const* pOld, SfxPoolItem const* pNew) SAL_OVERRIDE;
    2949             : };
    2950             : 
    2951             : OUString SAL_CALL
    2952           0 : SwXFieldEnumeration::getImplementationName() throw (uno::RuntimeException, std::exception)
    2953             : {
    2954           0 :     return OUString("SwXFieldEnumeration");
    2955             : }
    2956             : 
    2957           0 : sal_Bool SAL_CALL SwXFieldEnumeration::supportsService(const OUString& rServiceName)
    2958             : throw (uno::RuntimeException, std::exception)
    2959             : {
    2960           0 :     return cppu::supportsService(this, rServiceName);
    2961             : }
    2962             : 
    2963             : uno::Sequence< OUString > SAL_CALL
    2964           0 : SwXFieldEnumeration::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
    2965             : {
    2966           0 :     uno::Sequence< OUString > aRet(1);
    2967           0 :     OUString* pArray = aRet.getArray();
    2968           0 :     pArray[0] = "com.sun.star.text.FieldEnumeration";
    2969           0 :     return aRet;
    2970             : }
    2971             : 
    2972        1413 : SwXFieldEnumeration::SwXFieldEnumeration(SwDoc & rDoc)
    2973        1413 :     : m_pImpl(new Impl(rDoc))
    2974             : {
    2975             :     // build sequence
    2976        1413 :     sal_Int32 nSize = 32;
    2977        1413 :     m_pImpl->m_Items.realloc( nSize );
    2978        1413 :     uno::Reference< text::XTextField > *pItems = m_pImpl->m_Items.getArray();
    2979        1413 :     sal_Int32 nFillPos = 0;
    2980             : 
    2981        1413 :     const SwFldTypes* pFldTypes = m_pImpl->m_pDoc->GetFldTypes();
    2982        1413 :     sal_uInt16 nCount = pFldTypes->size();
    2983       46693 :     for(sal_uInt16 nType = 0;  nType < nCount;  ++nType)
    2984             :     {
    2985       45280 :         const SwFieldType *pCurType = (*pFldTypes)[nType];
    2986       45280 :         SwIterator<SwFmtFld,SwFieldType> aIter( *pCurType );
    2987       45280 :         const SwFmtFld* pCurFldFmt = aIter.First();
    2988       91269 :         while (pCurFldFmt)
    2989             :         {
    2990         709 :             const SwTxtFld *pTxtFld = pCurFldFmt->GetTxtFld();
    2991             :             // skip fields that are currently not in the document
    2992             :             // e.g. fields in undo or redo array
    2993        1414 :             bool bSkip = !pTxtFld ||
    2994        1414 :                          !pTxtFld->GetpTxtNode()->GetNodes().IsDocNodes();
    2995         709 :             if (!bSkip)
    2996        1410 :                 pItems[ nFillPos++ ] = SwXTextField::CreateXTextField(
    2997        1410 :                         *m_pImpl->m_pDoc, *pCurFldFmt);
    2998         709 :             pCurFldFmt = aIter.Next();
    2999             : 
    3000             :             // enlarge sequence if necessary
    3001         709 :             if (m_pImpl->m_Items.getLength() == nFillPos)
    3002             :             {
    3003           2 :                 m_pImpl->m_Items.realloc( 2 * m_pImpl->m_Items.getLength() );
    3004           2 :                 pItems = m_pImpl->m_Items.getArray();
    3005             :             }
    3006             :         }
    3007       45280 :     }
    3008             :     // now handle meta-fields, which are not SwFields
    3009             :     const ::std::vector< uno::Reference<text::XTextField> > MetaFields(
    3010        1413 :            m_pImpl->m_pDoc->GetMetaFieldManager().getMetaFields() );
    3011        1423 :     for (size_t i = 0; i < MetaFields.size(); ++i)
    3012             :     {
    3013          10 :         pItems[ nFillPos ] = MetaFields[i];
    3014          10 :         nFillPos++;
    3015             : 
    3016             :         //FIXME UGLY
    3017             :         // enlarge sequence if necessary
    3018          10 :         if (m_pImpl->m_Items.getLength() == nFillPos)
    3019             :         {
    3020           0 :             m_pImpl->m_Items.realloc( 2 * m_pImpl->m_Items.getLength() );
    3021           0 :             pItems = m_pImpl->m_Items.getArray();
    3022             :         }
    3023             :     }
    3024             :     // resize sequence to actual used size
    3025        1413 :     m_pImpl->m_Items.realloc( nFillPos );
    3026        1413 : }
    3027             : 
    3028        2826 : SwXFieldEnumeration::~SwXFieldEnumeration()
    3029             : {
    3030        2826 : }
    3031             : 
    3032        2088 : sal_Bool SAL_CALL SwXFieldEnumeration::hasMoreElements()
    3033             : throw (uno::RuntimeException, std::exception)
    3034             : {
    3035        2088 :     SolarMutexGuard aGuard;
    3036             : 
    3037        2088 :     return m_pImpl->m_nNextIndex < m_pImpl->m_Items.getLength();
    3038             : }
    3039             : 
    3040         712 : uno::Any SAL_CALL SwXFieldEnumeration::nextElement()
    3041             : throw (container::NoSuchElementException, lang::WrappedTargetException,
    3042             :         uno::RuntimeException, std::exception)
    3043             : {
    3044         712 :     SolarMutexGuard aGuard;
    3045             : 
    3046         712 :     if (!(m_pImpl->m_nNextIndex < m_pImpl->m_Items.getLength()))
    3047             :         throw container::NoSuchElementException(
    3048             :             "SwXFieldEnumeration::nextElement",
    3049           1 :             css::uno::Reference<css::uno::XInterface>());
    3050             : 
    3051             : #if OSL_DEBUG_LEVEL > 1
    3052             :     uno::Reference< text::XTextField > *pItems = m_pImpl->m_Items.getArray();
    3053             :     (void)pItems;
    3054             : #endif
    3055             :     uno::Reference< text::XTextField >  &rxFld =
    3056         711 :         m_pImpl->m_Items.getArray()[ m_pImpl->m_nNextIndex++ ];
    3057         711 :     uno::Any aRet;
    3058         711 :     aRet <<= rxFld;
    3059         711 :     rxFld = 0;  // free memory for item that is not longer used
    3060         712 :     return aRet;
    3061             : }
    3062             : 
    3063           3 : void SwXFieldEnumeration::Impl::Modify(
    3064             :         SfxPoolItem const*const pOld, SfxPoolItem const*const pNew)
    3065             : {
    3066           3 :     ClientModify(this, pOld, pNew);
    3067           3 :     if(!GetRegisteredIn())
    3068           3 :         m_pDoc = 0;
    3069           3 : }
    3070             : 
    3071             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10