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