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

Generated by: LCOV version 1.10