1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_editeng.hxx" 26 #include <com/sun/star/util/DateTime.hpp> 27 #include <com/sun/star/text/FilenameDisplayFormat.hpp> 28 #include <com/sun/star/lang/NoSupportException.hpp> 29 #include <com/sun/star/beans/PropertyAttribute.hpp> 30 #include <vcl/svapp.hxx> 31 #include <vos/mutex.hxx> 32 33 #include <rtl/uuid.h> 34 #include <rtl/memory.h> 35 36 #include <editeng/eeitem.hxx> 37 #include <editeng/flditem.hxx> 38 #include <editeng/measfld.hxx> 39 #include <editeng/unofield.hxx> 40 #include <editeng/unotext.hxx> 41 #include <comphelper/serviceinfohelper.hxx> 42 43 using namespace ::rtl; 44 using namespace ::vos; 45 using namespace ::cppu; 46 using namespace ::com::sun::star; 47 48 #define QUERYINT( xint ) \ 49 if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \ 50 aAny <<= uno::Reference< xint >(this) 51 52 53 #define WID_DATE 0 54 #define WID_BOOL1 1 55 #define WID_BOOL2 2 56 #define WID_INT32 3 57 #define WID_INT16 4 58 #define WID_STRING1 5 59 #define WID_STRING2 6 60 #define WID_STRING3 7 61 62 class SvxUnoFieldData_Impl 63 { 64 public: 65 sal_Bool mbBoolean1; 66 sal_Bool mbBoolean2; 67 sal_Int32 mnInt32; 68 sal_Int16 mnInt16; 69 OUString msString1; 70 OUString msString2; 71 OUString msString3; 72 util::DateTime maDateTime; 73 74 OUString msPresentation; 75 }; 76 77 const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId ) 78 { 79 static SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] = 80 { 81 { MAP_CHAR_LEN("DateTime"), WID_DATE, &::getCppuType((const util::DateTime*)0), 0, 0 }, 82 { MAP_CHAR_LEN("IsFixed"), WID_BOOL1, &::getBooleanCppuType(), 0, 0 }, 83 { MAP_CHAR_LEN("IsDate"), WID_BOOL2, &::getBooleanCppuType(), 0, 0 }, 84 { MAP_CHAR_LEN("NumberFormat"), WID_INT32, &::getCppuType((const sal_Int16*)0), 0, 0 }, 85 {0,0,0,0,0,0} 86 }; 87 static SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl); 88 89 static SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] = 90 { 91 { MAP_CHAR_LEN("IsDate"), WID_BOOL2, &::getBooleanCppuType(), 0, 0 }, 92 {0,0,0,0,0,0} 93 }; 94 static SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl); 95 96 static SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] = 97 { 98 99 { MAP_CHAR_LEN("Format"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, 100 { MAP_CHAR_LEN("Representation"), WID_STRING1, &::getCppuType((const OUString*)0), 0, 0 }, 101 { MAP_CHAR_LEN("TargetFrame"), WID_STRING2, &::getCppuType((const OUString*)0), 0, 0 }, 102 { MAP_CHAR_LEN("URL"), WID_STRING3, &::getCppuType((const OUString*)0), 0, 0 }, 103 {0,0,0,0,0,0} 104 }; 105 static SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl); 106 107 static SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] = 108 { 109 {0,0,0,0,0,0} 110 }; 111 static SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl); 112 113 static SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] = 114 { 115 { MAP_CHAR_LEN("IsFixed"), WID_BOOL1, &::getBooleanCppuType(), 0, 0 }, 116 { MAP_CHAR_LEN("FileFormat"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, 117 { MAP_CHAR_LEN("CurrentPresentation"), WID_STRING1,&::getCppuType((const OUString*)0), 0, 0 }, 118 {0,0,0,0,0,0} 119 }; 120 static SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl); 121 122 static SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] = 123 { 124 { MAP_CHAR_LEN("IsFixed"), WID_BOOL1, &::getBooleanCppuType(), 0, 0 }, 125 { MAP_CHAR_LEN("CurrentPresentation"), WID_STRING1,&::getCppuType((const OUString*)0), 0, 0 }, 126 { MAP_CHAR_LEN("Content"), WID_STRING2,&::getCppuType((const OUString*)0), 0, 0 }, 127 { MAP_CHAR_LEN("AuthorFormat"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, 128 { MAP_CHAR_LEN("FullName"), WID_BOOL2, &::getBooleanCppuType(), 0, 0 }, 129 {0,0,0,0,0,0} 130 }; 131 static SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl); 132 133 static SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] = 134 { 135 { MAP_CHAR_LEN("Kind"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, 136 {0,0,0,0,0,0} 137 }; 138 static SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl); 139 140 switch( mnId ) 141 { 142 case ID_EXT_DATEFIELD: 143 case ID_EXT_TIMEFIELD: 144 return &aExDateTimeFieldPropertySet_Impl; 145 case ID_URLFIELD: 146 return &aUrlFieldPropertySet_Impl; 147 case ID_DATEFIELD: 148 case ID_TIMEFIELD: 149 return &aDateTimeFieldPropertySet_Impl; 150 case ID_EXT_FILEFIELD: 151 return &aExtFileFieldPropertySet_Impl; 152 case ID_AUTHORFIELD: 153 return &aAuthorFieldPropertySet_Impl; 154 case ID_MEASUREFIELD: 155 return &aMeasureFieldPropertySet_Impl; 156 // case ID_PAGEFIELD: 157 // case ID_PAGESFIELD: 158 // case ID_FILEFIELD: 159 // case ID_TABLEFIELD: 160 // case ID_HEADERFIELD: 161 // case ID_FOOTERFIELD: 162 // case ID_DATETIMEFIELD:: 163 default: 164 return &aEmptyPropertySet_Impl; 165 } 166 } 167 168 static sal_Char const* aFieldItemNameMap_Impl[] = 169 { 170 "Date", 171 "URL", 172 "Page", 173 "Pages", 174 "Time", 175 "File", 176 "Table", 177 "ExtTime", 178 "ExtFile", 179 "Author", 180 "Measure", 181 "ExtDate", 182 "Header", 183 "Footer", 184 "DateTime", 185 "Unknown" 186 }; 187 188 /* conversion routines */ 189 190 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat ) 191 { 192 switch( nFormat ) 193 { 194 case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT; 195 case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL; 196 case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH; 197 // case SVXFILEFORMAT_NAME: 198 default: return text::FilenameDisplayFormat::NAME; 199 } 200 } 201 202 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat ) 203 { 204 switch( nFormat ) 205 { 206 case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH; 207 case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH; 208 case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME; 209 // case text::FilenameDisplayFormat::NAME_AND_EXT: 210 default: 211 return SVXFILEFORMAT_NAME_EXT; 212 } 213 } 214 215 static util::DateTime getDate( sal_uLong nDate ) 216 { 217 util::DateTime aDate; 218 memset( &aDate, 0, sizeof( util::DateTime ) ); 219 220 Date aTempDate( nDate ); 221 222 aDate.Day = aTempDate.GetDay(); 223 aDate.Month = aTempDate.GetMonth(); 224 aDate.Year = aTempDate.GetYear(); 225 226 return aDate; 227 } 228 229 inline Date setDate( util::DateTime& rDate ) 230 { 231 return Date( rDate.Day, rDate.Month, rDate.Year ); 232 } 233 234 static util::DateTime getTime( long nTime ) 235 { 236 util::DateTime aTime; 237 memset( &aTime, 0, sizeof( util::DateTime ) ); 238 239 Time aTempTime( nTime ); 240 241 aTime.HundredthSeconds = aTempTime.Get100Sec(); 242 aTime.Seconds = aTempTime.GetSec(); 243 aTime.Minutes = aTempTime.GetMin(); 244 aTime.Hours = aTempTime.GetHour(); 245 246 return aTime; 247 } 248 249 inline Time setTime( util::DateTime& rDate ) 250 { 251 return Time( rDate.Hours, rDate.Minutes, rDate.Seconds, rDate.HundredthSeconds ); 252 } 253 254 // ==================================================================== 255 // class SvxUnoTextField 256 // ==================================================================== 257 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextField ); 258 259 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw() 260 : OComponentHelper( getMutex() ) 261 , mpPropSet(NULL) 262 , mnServiceId(nServiceId) 263 , mpImpl( new SvxUnoFieldData_Impl ) 264 { 265 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId); 266 267 memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) ); 268 269 switch( nServiceId ) 270 { 271 case ID_EXT_DATEFIELD: 272 case ID_DATEFIELD: 273 mpImpl->mbBoolean2 = sal_True; 274 mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL; 275 mpImpl->mbBoolean1 = sal_False; 276 break; 277 278 case ID_EXT_TIMEFIELD: 279 case ID_TIMEFIELD: 280 mpImpl->mbBoolean2 = sal_False; 281 mpImpl->mbBoolean1 = sal_False; 282 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD; 283 break; 284 285 case ID_URLFIELD: 286 mpImpl->mnInt16 = SVXURLFORMAT_REPR; 287 break; 288 289 case ID_EXT_FILEFIELD: 290 mpImpl->mbBoolean1 = sal_False; 291 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL; 292 break; 293 294 case ID_AUTHORFIELD: 295 mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME; 296 mpImpl->mbBoolean1 = sal_False; 297 mpImpl->mbBoolean2 = sal_True; 298 break; 299 300 case ID_MEASUREFIELD: 301 mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE; 302 break; 303 304 default: 305 mpImpl->mbBoolean1 = sal_False; 306 mpImpl->mbBoolean2 = sal_False; 307 mpImpl->mnInt32 = 0; 308 mpImpl->mnInt16 = 0; 309 310 } 311 } 312 313 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw() 314 : OComponentHelper( getMutex() ) 315 , mxAnchor( xAnchor ) 316 , mpPropSet(NULL) 317 , mnServiceId(ID_UNKNOWN) 318 , mpImpl( new SvxUnoFieldData_Impl ) 319 { 320 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" ); 321 322 mpImpl->msPresentation = rPresentation; 323 324 if(pData) 325 { 326 mnServiceId = GetFieldId(pData); 327 DBG_ASSERT(mnServiceId != ID_UNKNOWN, "unknown SvxFieldData! [CL]"); 328 if(mnServiceId != ID_UNKNOWN) 329 { 330 // extract field properties from data class 331 switch( mnServiceId ) 332 { 333 case ID_DATEFIELD: 334 case ID_EXT_DATEFIELD: 335 { 336 mpImpl->mbBoolean2 = sal_True; 337 // #i35416# for variable date field, don't use invalid "0000-00-00" date, 338 // use current date instead 339 sal_Bool bFixed = ((SvxDateField*)pData)->GetType() == SVXDATETYPE_FIX; 340 mpImpl->maDateTime = getDate( bFixed ? 341 ((SvxDateField*)pData)->GetFixDate() : 342 Date().GetDate() ); 343 mpImpl->mnInt32 = ((SvxDateField*)pData)->GetFormat(); 344 mpImpl->mbBoolean1 = bFixed; 345 } 346 break; 347 348 case ID_TIMEFIELD: 349 mpImpl->mbBoolean2 = sal_False; 350 mpImpl->mbBoolean1 = sal_False; 351 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD; 352 break; 353 354 case ID_EXT_TIMEFIELD: 355 mpImpl->mbBoolean2 = sal_False; 356 mpImpl->maDateTime = getTime( ((SvxExtTimeField*)pData)->GetFixTime() ); 357 mpImpl->mbBoolean1 = ((SvxExtTimeField*)pData)->GetType() == SVXTIMETYPE_FIX; 358 mpImpl->mnInt32 = ((SvxExtTimeField*)pData)->GetFormat(); 359 break; 360 361 case ID_URLFIELD: 362 mpImpl->msString1 = ((SvxURLField*)pData)->GetRepresentation(); 363 mpImpl->msString2 = ((SvxURLField*)pData)->GetTargetFrame(); 364 mpImpl->msString3 = ((SvxURLField*)pData)->GetURL(); 365 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >( 366 ((SvxURLField*)pData)->GetFormat()); 367 break; 368 369 case ID_EXT_FILEFIELD: 370 mpImpl->msString1 = ((SvxExtFileField*)pData)->GetFile(); 371 mpImpl->mbBoolean1 = ((SvxExtFileField*)pData)->GetType() == SVXFILETYPE_FIX; 372 mpImpl->mnInt16 = getFileNameDisplayFormat(((SvxExtFileField*)pData)->GetFormat()); 373 break; 374 375 case ID_AUTHORFIELD: 376 mpImpl->msString1 = ((SvxAuthorField*)pData)->GetFormatted(); 377 mpImpl->msString2 = ((SvxAuthorField*)pData)->GetFormatted(); 378 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >( 379 ((SvxAuthorField*)pData)->GetFormat()); 380 mpImpl->mbBoolean1 = ((SvxAuthorField*)pData)->GetType() == SVXAUTHORTYPE_FIX; 381 mpImpl->mbBoolean2 = ((SvxAuthorField*)pData)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME; 382 break; 383 384 case ID_MEASUREFIELD: 385 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(((SdrMeasureField*)pData)->GetMeasureFieldKind()); 386 break; 387 } 388 } 389 } 390 391 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId); 392 } 393 394 SvxUnoTextField::~SvxUnoTextField() throw() 395 { 396 delete mpImpl; 397 } 398 399 SvxFieldData* SvxUnoTextField::CreateFieldData() const throw() 400 { 401 SvxFieldData* pData = NULL; 402 403 switch( mnServiceId ) 404 { 405 case ID_TIMEFIELD: 406 case ID_EXT_TIMEFIELD: 407 case ID_DATEFIELD: 408 case ID_EXT_DATEFIELD: 409 { 410 if( mpImpl->mbBoolean2 ) // IsDate? 411 { 412 Date aDate( setDate( mpImpl->maDateTime ) ); 413 pData = new SvxDateField( aDate, mpImpl->mbBoolean1?SVXDATETYPE_FIX:SVXDATETYPE_VAR ); 414 if( mpImpl->mnInt32 >= SVXDATEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXDATEFORMAT_F ) 415 ((SvxDateField*)pData)->SetFormat( (SvxDateFormat)mpImpl->mnInt32 ); 416 } 417 else 418 { 419 if( mnServiceId != ID_TIMEFIELD && mnServiceId != ID_DATEFIELD ) 420 { 421 Time aTime( setTime( mpImpl->maDateTime ) ); 422 pData = new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR ); 423 424 if( mpImpl->mnInt32 >= SVXTIMEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXTIMEFORMAT_AM_HMSH ) 425 ((SvxExtTimeField*)pData)->SetFormat( (SvxTimeFormat)mpImpl->mnInt32 ); 426 } 427 else 428 { 429 pData = new SvxTimeField(); 430 } 431 } 432 433 } 434 break; 435 436 case ID_URLFIELD: 437 pData = new SvxURLField( mpImpl->msString3, mpImpl->msString1, mpImpl->msString1.getLength() ? SVXURLFORMAT_REPR : SVXURLFORMAT_URL ); 438 ((SvxURLField*)pData)->SetTargetFrame( mpImpl->msString2 ); 439 if( mpImpl->mnInt16 >= SVXURLFORMAT_APPDEFAULT && mpImpl->mnInt16 <= SVXURLFORMAT_REPR ) 440 ((SvxURLField*)pData)->SetFormat( (SvxURLFormat)mpImpl->mnInt16 ); 441 break; 442 443 case ID_PAGEFIELD: 444 pData = new SvxPageField(); 445 break; 446 447 case ID_PAGESFIELD: 448 pData = new SvxPagesField(); 449 break; 450 451 case ID_FILEFIELD: 452 pData = new SvxFileField(); 453 break; 454 455 case ID_TABLEFIELD: 456 pData = new SvxTableField(); 457 break; 458 459 case ID_EXT_FILEFIELD: 460 { 461 // #92009# pass fixed attribute to constructor 462 pData = new SvxExtFileField( mpImpl->msString1, 463 mpImpl->mbBoolean1 ? SVXFILETYPE_FIX : SVXFILETYPE_VAR, 464 setFileNameDisplayFormat(mpImpl->mnInt16 ) ); 465 break; 466 } 467 468 case ID_AUTHORFIELD: 469 { 470 ::rtl::OUString aContent; 471 String aFirstName; 472 String aLastName; 473 String aEmpty; 474 475 // do we have CurrentPresentation given? 476 // mimic behaviour of writer, which means: 477 // prefer CurrentPresentation over Content 478 // if both are given. 479 if( mpImpl->msString1.getLength() ) 480 aContent = mpImpl->msString1; 481 else 482 aContent = mpImpl->msString2; 483 484 sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 ); 485 if( nPos > 0 ) 486 { 487 aFirstName = aContent.copy( 0, nPos ); 488 aLastName = aContent.copy( nPos + 1 ); 489 } 490 else 491 { 492 aLastName = aContent; 493 } 494 495 // #92009# pass fixed attribute to constructor 496 pData = new SvxAuthorField( aFirstName, aLastName, aEmpty, 497 mpImpl->mbBoolean1 ? SVXAUTHORTYPE_FIX : SVXAUTHORTYPE_VAR ); 498 499 if( !mpImpl->mbBoolean2 ) 500 { 501 ((SvxAuthorField*)pData)->SetFormat( SVXAUTHORFORMAT_SHORTNAME ); 502 } 503 else if( mpImpl->mnInt16 >= SVXAUTHORFORMAT_FULLNAME || mpImpl->mnInt16 <= SVXAUTHORFORMAT_SHORTNAME ) 504 { 505 ((SvxAuthorField*)pData)->SetFormat( (SvxAuthorFormat) mpImpl->mnInt16 ); 506 } 507 508 break; 509 } 510 511 case ID_MEASUREFIELD: 512 { 513 SdrMeasureFieldKind eKind = SDRMEASUREFIELD_VALUE; 514 if( mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_UNIT || mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_ROTA90BLANCS ) 515 eKind = (SdrMeasureFieldKind) mpImpl->mnInt16; 516 pData = new SdrMeasureField( eKind); 517 break; 518 } 519 case ID_HEADERFIELD: 520 pData = new SvxHeaderField(); 521 break; 522 case ID_FOOTERFIELD: 523 pData = new SvxFooterField(); 524 break; 525 case ID_DATETIMEFIELD: 526 pData = new SvxDateTimeField(); 527 break; 528 }; 529 530 return pData; 531 } 532 533 // uno::XInterface 534 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType ) 535 { 536 uno::Any aAny; 537 538 QUERYINT( beans::XPropertySet ); 539 else QUERYINT( text::XTextContent ); 540 else QUERYINT( text::XTextField ); 541 else QUERYINT( lang::XServiceInfo ); 542 else QUERYINT( lang::XUnoTunnel ); 543 else 544 return OComponentHelper::queryAggregation( rType ); 545 546 return aAny; 547 } 548 549 // XTypeProvider 550 551 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes() 552 { 553 if( maTypeSequence.getLength() == 0 ) 554 { 555 maTypeSequence = OComponentHelper::getTypes(); 556 sal_Int32 nOldCount = maTypeSequence.getLength(); 557 558 maTypeSequence.realloc( nOldCount + 4 ); // !DANGER! keep this updated 559 uno::Type* pTypes = &maTypeSequence.getArray()[nOldCount]; 560 561 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextField >*)0); 562 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0); 563 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0); 564 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0); 565 } 566 return maTypeSequence; 567 } 568 569 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId() 570 { 571 static uno::Sequence< sal_Int8 > aId; 572 if( aId.getLength() == 0 ) 573 { 574 aId.realloc( 16 ); 575 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); 576 } 577 return aId; 578 } 579 580 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType ) 581 { 582 return OComponentHelper::queryInterface(rType); 583 } 584 585 void SAL_CALL SvxUnoTextField::acquire() throw( ) 586 { 587 OComponentHelper::acquire(); 588 } 589 590 void SAL_CALL SvxUnoTextField::release() throw( ) 591 { 592 OComponentHelper::release(); 593 } 594 595 // Interface text::XTextField 596 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand ) 597 { 598 OGuard aGuard( Application::GetSolarMutex() ); 599 600 if(bShowCommand) 601 { 602 DBG_ASSERT( ((sal_uInt32)mnServiceId) < ID_UNKNOWN, "Unknown field type" ); 603 return OUString::createFromAscii( aFieldItemNameMap_Impl[(((sal_uInt32)mnServiceId) > ID_UNKNOWN)? ID_UNKNOWN : mnServiceId ] ); 604 } 605 else 606 { 607 return mpImpl->msPresentation; 608 } 609 } 610 611 // Interface text::XTextContent 612 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange ) 613 { 614 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xTextRange ); 615 if(pRange == NULL) 616 throw lang::IllegalArgumentException(); 617 618 SvxFieldData* pData = CreateFieldData(); 619 if( pData ) 620 pRange->attachField( pData ); 621 622 delete pData; 623 } 624 625 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor() 626 { 627 return mxAnchor; 628 } 629 630 // lang::XComponent 631 void SAL_CALL SvxUnoTextField::dispose() 632 { 633 OComponentHelper::dispose(); 634 } 635 636 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) 637 { 638 OComponentHelper::addEventListener(xListener); 639 } 640 641 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener ) 642 { 643 OComponentHelper::removeEventListener(aListener); 644 } 645 646 647 // Interface beans::XPropertySet 648 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( ) 649 { 650 OGuard aGuard( Application::GetSolarMutex() ); 651 return mpPropSet->getPropertySetInfo(); 652 } 653 654 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) 655 { 656 OGuard aGuard( Application::GetSolarMutex() ); 657 658 if( mpImpl == NULL ) 659 throw uno::RuntimeException(); 660 661 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( aPropertyName ); 662 if ( !pMap ) 663 throw beans::UnknownPropertyException(); 664 665 switch( pMap->nWID ) 666 { 667 case WID_DATE: 668 if(aValue >>= mpImpl->maDateTime) 669 return; 670 break; 671 case WID_BOOL1: 672 if(aValue >>= mpImpl->mbBoolean1) 673 return; 674 break; 675 case WID_BOOL2: 676 if(aValue >>= mpImpl->mbBoolean2) 677 return; 678 break; 679 case WID_INT16: 680 if(aValue >>= mpImpl->mnInt16) 681 return; 682 break; 683 case WID_INT32: 684 if(aValue >>= mpImpl->mnInt32) 685 return; 686 break; 687 case WID_STRING1: 688 if(aValue >>= mpImpl->msString1) 689 return; 690 break; 691 case WID_STRING2: 692 if(aValue >>= mpImpl->msString2) 693 return; 694 break; 695 case WID_STRING3: 696 if(aValue >>= mpImpl->msString3) 697 return; 698 break; 699 } 700 701 throw lang::IllegalArgumentException(); 702 703 /* 704 case WID_FORMAT: 705 { 706 sal_Int32 nFormat; 707 708 switch( mnId ) 709 { 710 case ID_DATEFIELD: 711 { 712 SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() ); 713 if(pDate) 714 pDate->SetFormat( (SvxDateFormat)nFormat ); 715 break; 716 } 717 case ID_URLFIELD: 718 { 719 SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() ); 720 if(pURL) 721 pURL->SetFormat( (SvxURLFormat)nFormat ); 722 break; 723 } 724 case ID_EXT_TIMEFIELD: 725 { 726 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() ); 727 if(pTime) 728 pTime->SetFormat( (SvxTimeFormat)nFormat ); 729 break; 730 } 731 case ID_EXT_FILEFIELD: 732 { 733 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() ); 734 if(pFile) 735 pFile->SetFormat( (SvxFileFormat)nFormat ); 736 break; 737 } 738 case ID_AUTHORFIELD: 739 { 740 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() ); 741 if(pAuthor) 742 pAuthor->SetFormat( (SvxAuthorFormat)nFormat ); 743 break; 744 } 745 default: 746 throw beans::UnknownPropertyException(); 747 } 748 } 749 break; 750 case WID_FIX: 751 { 752 if( aValue.hasValue() || aValue.getValueType() != ::getCppuBooleanType() ) 753 throw lang::IllegalArgumentException(); 754 sal_Bool bFix( *(sal_Bool*)aValue.getValue() ); 755 switch( mnId ) 756 { 757 case ID_EXT_TIMEFIELD: 758 { 759 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() ); 760 if(pTime) 761 pTime->SetType( (SvxTimeType)bFix?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR ); 762 break; 763 } 764 case ID_DATEFIELD: 765 { 766 SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() ); 767 if(pDate) 768 pDate->SetType( (SvxDateType)bFix?SVXDATETYPE_FIX:SVXDATETYPE_VAR ); 769 break; 770 } 771 case ID_EXT_FILEFIELD: 772 { 773 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() ); 774 if(pFile) 775 pFile->SetType( (SvxFileType)bFix?SVXFILETYPE_FIX:SVXFILETYPE_VAR ); 776 break; 777 } 778 case ID_AUTHORFIELD: 779 { 780 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() ); 781 if(pAuthor) 782 pAuthor->SetType( (SvxAuthorType)bFix?SVXAUTHORTYPE_FIX:SVXAUTHORTYPE_VAR ); 783 break; 784 } 785 default: 786 throw beans::UnknownPropertyException(); 787 } 788 } 789 break; 790 case WID_PRES: 791 case WID_URL: 792 case WID_TARGET: 793 { 794 SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() ); 795 if(pURL) 796 { 797 OUString aUnoStr; 798 if(!(aValue >>= aUnoStr)) 799 throw lang::IllegalArgumentException(); 800 801 switch( pMap->nWID ) 802 { 803 case WID_PRES: 804 pURL->SetRepresentation( aUnoStr ); 805 break; 806 case WID_URL: 807 pURL->SetURL( aUnoStr ); 808 break; 809 case WID_TARGET: 810 pURL->SetTargetFrame( aUnoStr ); 811 break; 812 } 813 } 814 break; 815 } 816 } 817 818 SfxItemSet aSet = pForwarder->GetAttribs( GetSelection() ); 819 aSet.Put( aFieldItem ); 820 */ 821 } 822 823 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName ) 824 { 825 OGuard aGuard( Application::GetSolarMutex() ); 826 827 uno::Any aValue; 828 829 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( PropertyName ); 830 if ( !pMap ) 831 throw beans::UnknownPropertyException(); 832 833 switch( pMap->nWID ) 834 { 835 case WID_DATE: 836 aValue <<= mpImpl->maDateTime; 837 break; 838 case WID_BOOL1: 839 aValue <<= mpImpl->mbBoolean1; 840 break; 841 case WID_BOOL2: 842 aValue <<= mpImpl->mbBoolean2; 843 break; 844 case WID_INT16: 845 aValue <<= mpImpl->mnInt16; 846 break; 847 case WID_INT32: 848 aValue <<= mpImpl->mnInt32; 849 break; 850 case WID_STRING1: 851 aValue <<= mpImpl->msString1; 852 break; 853 case WID_STRING2: 854 aValue <<= mpImpl->msString2; 855 break; 856 case WID_STRING3: 857 aValue <<= mpImpl->msString3; 858 break; 859 } 860 861 return aValue; 862 863 /* 864 switch(pMap->nWID) 865 { 866 case WID_FORMAT: 867 switch( mnId ) 868 { 869 case ID_DATEFIELD: 870 { 871 SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() ); 872 if(pDate) 873 aValue <<= (sal_Int32)pDate->GetFormat(); 874 break; 875 } 876 case ID_URLFIELD: 877 { 878 SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() ); 879 if(pURL) 880 aValue <<= (sal_Int32)pURL->GetFormat(); 881 break; 882 } 883 case ID_EXT_TIMEFIELD: 884 { 885 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() ); 886 if(pTime) 887 aValue <<= (sal_Int32)pTime->GetFormat(); 888 break; 889 } 890 case ID_EXT_FILEFIELD: 891 { 892 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() ); 893 if(pFile) 894 aValue <<= (sal_Int32)pFile->GetFormat(); 895 break; 896 } 897 case ID_AUTHORFIELD: 898 { 899 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() ); 900 if(pAuthor) 901 aValue <<= (sal_Int32)pAuthor->GetFormat(); 902 break; 903 } 904 default: 905 throw beans::UnknownPropertyException(); 906 } 907 break; 908 case WID_FIX: 909 { 910 sal_Bool bFix = sal_False; 911 switch( mnId ) 912 { 913 case ID_EXT_TIMEFIELD: 914 { 915 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() ); 916 if(pTime) 917 bFix = pTime->GetType() == SVXTIMETYPE_FIX; 918 break; 919 } 920 case ID_DATEFIELD: 921 { 922 SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() ); 923 if(pDate) 924 bFix = pDate->GetType() == SVXDATETYPE_FIX; 925 break; 926 } 927 case ID_EXT_FILEFIELD: 928 { 929 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() ); 930 if(pFile) 931 bFix = pFile->GetType() == SVXFILETYPE_FIX; 932 break; 933 } 934 case ID_AUTHORFIELD: 935 { 936 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() ); 937 if(pAuthor) 938 bFix = pAuthor->GetType() == SVXAUTHORTYPE_FIX; 939 break; 940 } 941 default: 942 throw beans::UnknownPropertyException(); 943 } 944 aValue.setValue( &bFix, ::getCppuBooleanType() ); 945 } 946 break; 947 case WID_PRES: 948 case WID_URL: 949 case WID_TARGET: 950 { 951 SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() ); 952 if(pURL) 953 { 954 OUString aStr; 955 switch( pMap->nWID ) 956 { 957 case WID_PRES: 958 aStr = pURL->GetRepresentation(); 959 break; 960 case WID_URL: 961 aStr = pURL->GetURL(); 962 break; 963 case WID_TARGET: 964 aStr = pURL->GetTargetFrame(); 965 break; 966 } 967 aValue <<= aStr; 968 } 969 break; 970 } 971 case WID_FCOLOR: 972 case WID_TCOLOR: 973 { 974 Color* pFColor = NULL; 975 Color* pTColor = NULL; 976 const ESelection aSel = GetSelection(); 977 978 pForwarder->CalcFieldValue( *pFieldItem, aSel.nStartPara, aSel.nStartPos, pTColor, pFColor ); 979 980 if( pMap->nWID == WID_FCOLOR ) 981 aValue <<= (sal_Int32)pFColor->GetColor(); 982 else 983 aValue <<= (sal_Int32)pTColor->GetColor(); 984 break; 985 986 delete pTColor; 987 delete pFColor; 988 } 989 } 990 return aValue; 991 */ 992 } 993 994 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {} 995 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {} 996 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {} 997 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {} 998 999 // OComponentHelper 1000 void SvxUnoTextField::disposing() 1001 { 1002 // nothing to do 1003 } 1004 1005 sal_Int32 SvxUnoTextField::GetFieldId( const SvxFieldData* pFieldData ) const throw() 1006 { 1007 if( pFieldData->ISA( SvxURLField ) ) 1008 return ID_URLFIELD; 1009 else if( pFieldData->ISA( SvxPageField ) ) 1010 return ID_PAGEFIELD; 1011 else if( pFieldData->ISA( SvxPagesField ) ) 1012 return ID_PAGESFIELD; 1013 else if( pFieldData->ISA( SvxTimeField ) ) 1014 return ID_TIMEFIELD; 1015 else if( pFieldData->ISA( SvxFileField ) ) 1016 return ID_FILEFIELD; 1017 else if( pFieldData->ISA( SvxTableField ) ) 1018 return ID_TABLEFIELD; 1019 else if( pFieldData->ISA( SvxExtTimeField ) ) 1020 return ID_EXT_TIMEFIELD; 1021 else if( pFieldData->ISA( SvxExtFileField ) ) 1022 return ID_EXT_FILEFIELD; 1023 else if( pFieldData->ISA( SvxAuthorField ) ) 1024 return ID_AUTHORFIELD; 1025 else if( pFieldData->ISA( SvxDateField ) ) 1026 return ID_EXT_DATEFIELD; 1027 else if( pFieldData->ISA( SdrMeasureField ) ) 1028 return ID_MEASUREFIELD; 1029 else if( pFieldData->ISA( SvxHeaderField ) ) 1030 return ID_HEADERFIELD; 1031 else if( pFieldData->ISA( SvxFooterField ) ) 1032 return ID_FOOTERFIELD; 1033 else if( pFieldData->ISA( SvxDateTimeField ) ) 1034 return ID_DATETIMEFIELD; 1035 1036 return ID_UNKNOWN; 1037 } 1038 1039 // lang::XServiceInfo 1040 OUString SAL_CALL SvxUnoTextField::getImplementationName() 1041 { 1042 return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextField")); 1043 } 1044 1045 static const sal_Char* pOldServiceNames[] = 1046 { 1047 "com.sun.star.text.TextField.DateTime", 1048 "com.sun.star.text.TextField.URL", 1049 "com.sun.star.text.TextField.PageNumber", 1050 "com.sun.star.text.TextField.PageCount", 1051 "com.sun.star.text.TextField.DateTime", 1052 "com.sun.star.text.TextField.DocInfo.Title", // SvxFileField is used for title 1053 "com.sun.star.text.TextField.SheetName", 1054 "com.sun.star.text.TextField.DateTime", 1055 "com.sun.star.text.TextField.FileName", 1056 "com.sun.star.text.TextField.Author", 1057 "com.sun.star.text.TextField.Measure", 1058 "com.sun.star.text.TextField.DateTime", 1059 "com.sun.star.presentation.TextField.Header", 1060 "com.sun.star.presentation.TextField.Footer", 1061 "com.sun.star.presentation.TextField.DateTime" 1062 }; 1063 1064 static const sal_Char* pNewServiceNames[] = 1065 { 1066 "com.sun.star.text.textfield.DateTime", 1067 "com.sun.star.text.textfield.URL", 1068 "com.sun.star.text.textfield.PageNumber", 1069 "com.sun.star.text.textfield.PageCount", 1070 "com.sun.star.text.textfield.DateTime", 1071 "com.sun.star.text.textfield.docinfo.Title", // SvxFileField is used for title 1072 "com.sun.star.text.textfield.SheetName", 1073 "com.sun.star.text.textfield.DateTime", 1074 "com.sun.star.text.textfield.FileName", 1075 "com.sun.star.text.textfield.Author", 1076 "com.sun.star.text.textfield.Measure", 1077 "com.sun.star.text.textfield.DateTime", 1078 "com.sun.star.presentation.textfield.Header", 1079 "com.sun.star.presentation.textfield.Footer", 1080 "com.sun.star.presentation.textfield.DateTime" 1081 }; 1082 1083 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames() 1084 { 1085 uno::Sequence< OUString > aSeq( 4 ); 1086 OUString* pServices = aSeq.getArray(); 1087 pServices[0] = OUString::createFromAscii( pNewServiceNames[mnServiceId] ); 1088 pServices[1] = OUString::createFromAscii( pOldServiceNames[mnServiceId] ); 1089 pServices[2] = OUString::createFromAscii( "com.sun.star.text.TextContent" ), 1090 pServices[3] = OUString::createFromAscii( "com.sun.star.text.TextField" ); 1091 1092 return aSeq; 1093 } 1094 1095 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) 1096 { 1097 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() ); 1098 } 1099 1100 uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const ::rtl::OUString& ServiceSpecifier ) 1101 { 1102 uno::Reference< uno::XInterface > xRet; 1103 1104 const OUString aTextFieldPrexit( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.") ); 1105 1106 // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is 1107 // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation. 1108 const OUString aTextFieldPrexit2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.") ); 1109 1110 if( (ServiceSpecifier.compareTo( aTextFieldPrexit, aTextFieldPrexit.getLength() ) == 0) || 1111 (ServiceSpecifier.compareTo( aTextFieldPrexit2, aTextFieldPrexit2.getLength() ) == 0) ) 1112 { 1113 OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) ); 1114 1115 sal_Int32 nId = ID_UNKNOWN; 1116 1117 if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DateTime") ) ) 1118 { 1119 nId = ID_DATEFIELD; 1120 } 1121 else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("URL") ) ) 1122 { 1123 nId = ID_URLFIELD; 1124 } 1125 else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("PageNumber") ) ) 1126 { 1127 nId = ID_PAGEFIELD; 1128 } 1129 else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("PageCount") ) ) 1130 { 1131 nId = ID_PAGESFIELD; 1132 } 1133 else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SheetName") ) ) 1134 { 1135 nId = ID_TABLEFIELD; 1136 } 1137 else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("FileName") ) ) 1138 { 1139 nId = ID_EXT_FILEFIELD; 1140 } 1141 else if (aFieldType.equalsAsciiL( 1142 RTL_CONSTASCII_STRINGPARAM("docinfo.Title") ) || 1143 aFieldType.equalsAsciiL( 1144 RTL_CONSTASCII_STRINGPARAM("DocInfo.Title") ) ) 1145 { 1146 nId = ID_FILEFIELD; 1147 } 1148 else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Author") ) ) 1149 { 1150 nId = ID_AUTHORFIELD; 1151 } 1152 else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Measure") ) ) 1153 { 1154 nId = ID_MEASUREFIELD; 1155 } 1156 1157 if( nId != ID_UNKNOWN ) 1158 xRet = (::cppu::OWeakObject * )new SvxUnoTextField( nId ); 1159 } 1160 1161 return xRet; 1162 } 1163