LCOV - code coverage report
Current view: top level - sw/source/core/unocore - unofield.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 1512 0.0 %
Date: 2014-04-14 Functions: 0 109 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10