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_chart2.hxx" 30 #include "CharacterPropertyItemConverter.hxx" 31 #include "SchWhichPairs.hxx" 32 #include "macros.hxx" 33 #include "ItemPropertyMap.hxx" 34 #include "RelativeSizeHelper.hxx" 35 #include <editeng/memberids.hrc> 36 #include <editeng/eeitem.hxx> 37 #include <editeng/udlnitem.hxx> 38 #include <editeng/fontitem.hxx> 39 #include <editeng/crsditem.hxx> 40 #include <editeng/postitem.hxx> 41 #include <editeng/wghtitem.hxx> 42 #include <editeng/fhgtitem.hxx> 43 #include <svl/stritem.hxx> 44 45 #include <com/sun/star/beans/XPropertyState.hpp> 46 #include <com/sun/star/chart2/XFormattedString.hpp> 47 48 using namespace ::com::sun::star; 49 50 namespace 51 { 52 ::comphelper::ItemPropertyMapType & lcl_GetCharacterPropertyPropertyMap() 53 { 54 static ::comphelper::ItemPropertyMapType aCharacterPropertyMap( 55 ::comphelper::MakeItemPropertyMap 56 IPM_MAP_ENTRY( EE_CHAR_COLOR, "CharColor", 0 ) 57 IPM_MAP_ENTRY( EE_CHAR_LANGUAGE, "CharLocale", MID_LANG_LOCALE ) 58 IPM_MAP_ENTRY( EE_CHAR_LANGUAGE_CJK, "CharLocaleAsian", MID_LANG_LOCALE ) 59 IPM_MAP_ENTRY( EE_CHAR_LANGUAGE_CTL, "CharLocaleComplex", MID_LANG_LOCALE ) 60 // IPM_MAP_ENTRY( EE_CHAR_FONTHEIGHT, "CharHeight", 0 ) 61 // IPM_MAP_ENTRY( EE_CHAR_ITALIC, "CharPosture", 0 ) 62 // IPM_MAP_ENTRY( EE_CHAR_WEIGHT, "CharWeight", 0 ) 63 64 IPM_MAP_ENTRY( EE_CHAR_STRIKEOUT, "CharStrikeout", MID_CROSS_OUT ) 65 IPM_MAP_ENTRY( EE_CHAR_WLM, "CharWordMode", 0 ) 66 IPM_MAP_ENTRY( EE_CHAR_SHADOW, "CharShadowed", 0 ) 67 IPM_MAP_ENTRY( EE_CHAR_RELIEF, "CharRelief", 0 ) 68 IPM_MAP_ENTRY( EE_CHAR_OUTLINE, "CharContoured", 0 ) 69 IPM_MAP_ENTRY( EE_CHAR_EMPHASISMARK, "CharEmphasis", 0 ) 70 71 IPM_MAP_ENTRY( EE_PARA_WRITINGDIR, "WritingMode", 0 ) 72 73 // IPM_MAP_ENTRY( EE_CHAR_FONTHEIGHT_CJK, "CharHeightAsian", 0 ) 74 // IPM_MAP_ENTRY( EE_CHAR_FONTHEIGHT_CTL, "CharHeightComplex", 0 ) 75 // IPM_MAP_ENTRY( EE_CHAR_WEIGHT_CJK, "CharWeightAsian", 0 ) 76 // IPM_MAP_ENTRY( EE_CHAR_WEIGHT_CTL, "CharWeightComplex", 0 ) 77 // IPM_MAP_ENTRY( EE_CHAR_ITALIC_CJK, "CharPostureAsian", 0 ) 78 // IPM_MAP_ENTRY( EE_CHAR_ITALIC_CTL, "CharPostureComplex", 0 ) 79 IPM_MAP_ENTRY( EE_PARA_ASIANCJKSPACING, "ParaIsCharacterDistance", 0 ) 80 ); 81 82 return aCharacterPropertyMap; 83 } 84 } // anonymous namespace 85 86 // ======================================== 87 88 namespace chart 89 { 90 namespace wrapper 91 { 92 93 CharacterPropertyItemConverter::CharacterPropertyItemConverter( 94 const uno::Reference< beans::XPropertySet > & rPropertySet, 95 SfxItemPool& rItemPool ) : 96 ItemConverter( rPropertySet, rItemPool ) 97 {} 98 99 CharacterPropertyItemConverter::CharacterPropertyItemConverter( 100 const uno::Reference< beans::XPropertySet > & rPropertySet, 101 SfxItemPool& rItemPool, 102 ::std::auto_ptr< awt::Size > pRefSize, 103 const ::rtl::OUString & rRefSizePropertyName, 104 const uno::Reference< beans::XPropertySet > & rRefSizePropSet ) : 105 ItemConverter( rPropertySet, rItemPool ), 106 m_pRefSize( pRefSize ), 107 m_aRefSizePropertyName( rRefSizePropertyName ), 108 m_xRefSizePropSet( rRefSizePropSet.is() ? rRefSizePropSet : rPropertySet ) 109 {} 110 111 CharacterPropertyItemConverter::~CharacterPropertyItemConverter() 112 {} 113 114 const sal_uInt16 * CharacterPropertyItemConverter::GetWhichPairs() const 115 { 116 return nCharacterPropertyWhichPairs; 117 } 118 119 bool CharacterPropertyItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const 120 { 121 ::comphelper::ItemPropertyMapType & rMap( lcl_GetCharacterPropertyPropertyMap()); 122 ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId )); 123 124 if( aIt == rMap.end()) 125 return false; 126 127 rOutProperty =(*aIt).second; 128 return true; 129 } 130 131 void CharacterPropertyItemConverter::FillSpecialItem( 132 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const 133 throw( uno::Exception ) 134 { 135 switch( nWhichId ) 136 { 137 case EE_CHAR_FONTINFO: 138 case EE_CHAR_FONTINFO_CJK: 139 case EE_CHAR_FONTINFO_CTL: 140 { 141 ::rtl::OUString aPostfix; 142 if( nWhichId == EE_CHAR_FONTINFO_CJK ) 143 aPostfix = C2U( "Asian" ); 144 else if( nWhichId == EE_CHAR_FONTINFO_CTL ) 145 aPostfix = C2U( "Complex" ); 146 147 SvxFontItem aItem( nWhichId ); 148 149 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontName" ) + aPostfix), 150 MID_FONT_FAMILY_NAME ); 151 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontFamily" ) + aPostfix), 152 MID_FONT_FAMILY ); 153 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontStyleName" ) + aPostfix), 154 MID_FONT_STYLE_NAME ); 155 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontCharSet" ) + aPostfix), 156 MID_FONT_CHAR_SET ); 157 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontPitch" ) + aPostfix), 158 MID_FONT_PITCH ); 159 160 rOutItemSet.Put( aItem ); 161 } 162 break; 163 164 case EE_CHAR_UNDERLINE: 165 { 166 SvxUnderlineItem aItem(UNDERLINE_NONE, EE_CHAR_UNDERLINE); 167 bool bModified = false; 168 169 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharUnderline" ))); 170 if( aValue.hasValue()) 171 { 172 aItem.PutValue( aValue, MID_TL_STYLE ); 173 bModified = true; 174 } 175 176 aValue = GetPropertySet()->getPropertyValue( C2U( "CharUnderlineHasColor" )); 177 if( aValue.hasValue() && 178 ( *reinterpret_cast< const sal_Bool * >( aValue.getValue()) != sal_False )) 179 { 180 aItem.PutValue( aValue, MID_TL_HASCOLOR ); 181 bModified = true; 182 } 183 184 aValue = GetPropertySet()->getPropertyValue( C2U( "CharUnderlineColor" )); 185 if( aValue.hasValue()) 186 { 187 aItem.PutValue( aValue, MID_TL_COLOR ); 188 bModified = true; 189 } 190 191 if( bModified ) 192 rOutItemSet.Put( aItem ); 193 } 194 break; 195 196 case EE_CHAR_OVERLINE: 197 { 198 SvxOverlineItem aItem( UNDERLINE_NONE, EE_CHAR_OVERLINE ); 199 bool bModified = false; 200 201 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharOverline" ) ) ); 202 if ( aValue.hasValue() ) 203 { 204 aItem.PutValue( aValue, MID_TL_STYLE ); 205 bModified = true; 206 } 207 208 aValue = GetPropertySet()->getPropertyValue( C2U( "CharOverlineHasColor" ) ); 209 if ( aValue.hasValue() && 210 ( *reinterpret_cast< const sal_Bool* >( aValue.getValue() ) != sal_False ) ) 211 { 212 aItem.PutValue( aValue, MID_TL_HASCOLOR ); 213 bModified = true; 214 } 215 216 aValue = GetPropertySet()->getPropertyValue( C2U( "CharOverlineColor" ) ); 217 if ( aValue.hasValue() ) 218 { 219 aItem.PutValue( aValue, MID_TL_COLOR ); 220 bModified = true; 221 } 222 223 if ( bModified ) 224 { 225 rOutItemSet.Put( aItem ); 226 } 227 } 228 break; 229 230 case EE_CHAR_ITALIC: 231 case EE_CHAR_ITALIC_CJK: 232 case EE_CHAR_ITALIC_CTL: 233 { 234 ::rtl::OUString aPostfix; 235 if( nWhichId == EE_CHAR_ITALIC_CJK ) 236 aPostfix = C2U( "Asian" ); 237 else if( nWhichId == EE_CHAR_ITALIC_CTL ) 238 aPostfix = C2U( "Complex" ); 239 240 SvxPostureItem aItem( ITALIC_NONE, nWhichId ); 241 242 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharPosture" ) + aPostfix)); 243 if( aValue.hasValue()) 244 { 245 aItem.PutValue( aValue, MID_POSTURE ); 246 rOutItemSet.Put( aItem ); 247 } 248 } 249 break; 250 251 case EE_CHAR_WEIGHT: 252 case EE_CHAR_WEIGHT_CJK: 253 case EE_CHAR_WEIGHT_CTL: 254 { 255 ::rtl::OUString aPostfix; 256 if( nWhichId == EE_CHAR_WEIGHT_CJK ) 257 aPostfix = C2U( "Asian" ); 258 else if( nWhichId == EE_CHAR_WEIGHT_CTL ) 259 aPostfix = C2U( "Complex" ); 260 261 SvxWeightItem aItem( WEIGHT_NORMAL, nWhichId ); 262 263 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharWeight" ) + aPostfix)); 264 if( aValue.hasValue()) 265 { 266 aItem.PutValue( aValue, MID_WEIGHT ); 267 rOutItemSet.Put( aItem ); 268 } 269 } 270 break; 271 272 case EE_CHAR_FONTHEIGHT: 273 case EE_CHAR_FONTHEIGHT_CJK: 274 case EE_CHAR_FONTHEIGHT_CTL: 275 { 276 ::rtl::OUString aPostfix; 277 if( nWhichId == EE_CHAR_FONTHEIGHT_CJK ) 278 aPostfix = C2U( "Asian" ); 279 else if( nWhichId == EE_CHAR_FONTHEIGHT_CTL ) 280 aPostfix = C2U( "Complex" ); 281 282 SvxFontHeightItem aItem( 240, 100, nWhichId ); 283 284 try 285 { 286 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharHeight" ) + aPostfix )); 287 float fHeight; 288 if( aValue >>= fHeight ) 289 { 290 if( m_pRefSize.get()) 291 { 292 awt::Size aOldRefSize; 293 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ) >>= aOldRefSize ) 294 { 295 // calculate font height in view 296 fHeight = static_cast< float >( 297 RelativeSizeHelper::calculate( fHeight, aOldRefSize, *m_pRefSize )); 298 aValue <<= fHeight; 299 } 300 } 301 302 aItem.PutValue( aValue, MID_FONTHEIGHT ); 303 rOutItemSet.Put( aItem ); 304 } 305 } 306 catch( uno::Exception & ex ) 307 { 308 ASSERT_EXCEPTION( ex ); 309 } 310 } 311 break; 312 313 case SID_CHAR_DLG_PREVIEW_STRING: 314 { 315 uno::Reference< chart2::XFormattedString > xFormattedString( GetPropertySet(), uno::UNO_QUERY ); 316 if( xFormattedString.is() ) 317 { 318 ::rtl::OUString aString = xFormattedString->getString(); 319 rOutItemSet.Put( SfxStringItem( nWhichId, aString ) ); 320 } 321 else 322 rOutItemSet.Put( SfxStringItem( nWhichId, C2U( "" ) ) ); 323 } 324 break; 325 326 case EE_PARA_FORBIDDENRULES: 327 case EE_PARA_HANGINGPUNCTUATION: 328 rOutItemSet.DisableItem( nWhichId ); 329 break; 330 } 331 } 332 333 bool CharacterPropertyItemConverter::ApplySpecialItem( 334 sal_uInt16 nWhichId, const SfxItemSet & rItemSet ) 335 throw( uno::Exception ) 336 { 337 bool bChanged = false; 338 uno::Any aValue; 339 340 switch( nWhichId ) 341 { 342 case EE_CHAR_FONTINFO: 343 case EE_CHAR_FONTINFO_CJK: 344 case EE_CHAR_FONTINFO_CTL: 345 { 346 ::rtl::OUString aPostfix; 347 if( nWhichId == EE_CHAR_FONTINFO_CJK ) 348 aPostfix = C2U( "Asian" ); 349 else if( nWhichId == EE_CHAR_FONTINFO_CTL ) 350 aPostfix = C2U( "Complex" ); 351 352 const SvxFontItem & rItem = 353 static_cast< const SvxFontItem & >( 354 rItemSet.Get( nWhichId )); 355 356 if( rItem.QueryValue( aValue, MID_FONT_FAMILY_NAME )) 357 { 358 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontName" ) + aPostfix )) 359 { 360 GetPropertySet()->setPropertyValue( C2U( "CharFontName" ) + aPostfix, aValue ); 361 bChanged = true; 362 } 363 } 364 if( rItem.QueryValue( aValue, MID_FONT_FAMILY )) 365 { 366 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontFamily" ) + aPostfix )) 367 { 368 GetPropertySet()->setPropertyValue( C2U( "CharFontFamily" ) + aPostfix, aValue ); 369 bChanged = true; 370 } 371 } 372 if( rItem.QueryValue( aValue, MID_FONT_STYLE_NAME )) 373 { 374 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontStyleName" ) + aPostfix )) 375 { 376 GetPropertySet()->setPropertyValue( C2U( "CharFontStyleName" ) + aPostfix, aValue ); 377 bChanged = true; 378 } 379 } 380 if( rItem.QueryValue( aValue, MID_FONT_CHAR_SET )) 381 { 382 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontCharSet" ) + aPostfix )) 383 { 384 GetPropertySet()->setPropertyValue( C2U( "CharFontCharSet" ) + aPostfix, aValue ); 385 bChanged = true; 386 } 387 } 388 if( rItem.QueryValue( aValue, MID_FONT_PITCH )) 389 { 390 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontPitch" ) + aPostfix )) 391 { 392 GetPropertySet()->setPropertyValue( C2U( "CharFontPitch" ) + aPostfix, aValue ); 393 bChanged = true; 394 } 395 } 396 } 397 break; 398 399 case EE_CHAR_UNDERLINE: 400 { 401 const SvxUnderlineItem & rItem = 402 static_cast< const SvxUnderlineItem & >( 403 rItemSet.Get( nWhichId )); 404 405 if( rItem.QueryValue( aValue, MID_TL_STYLE )) 406 { 407 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharUnderline" ) )) 408 { 409 GetPropertySet()->setPropertyValue( C2U( "CharUnderline" ), aValue ); 410 bChanged = true; 411 } 412 } 413 414 if( rItem.QueryValue( aValue, MID_TL_COLOR )) 415 { 416 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharUnderlineColor" ) )) 417 { 418 GetPropertySet()->setPropertyValue( C2U( "CharUnderlineColor" ), aValue ); 419 bChanged = true; 420 } 421 } 422 423 if( rItem.QueryValue( aValue, MID_TL_HASCOLOR )) 424 { 425 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharUnderlineHasColor" ) )) 426 { 427 GetPropertySet()->setPropertyValue( C2U( "CharUnderlineHasColor" ), aValue ); 428 bChanged = true; 429 } 430 } 431 } 432 break; 433 434 case EE_CHAR_OVERLINE: 435 { 436 const SvxOverlineItem& rItem = static_cast< const SvxOverlineItem & >( rItemSet.Get( nWhichId ) ); 437 438 if ( rItem.QueryValue( aValue, MID_TL_STYLE ) ) 439 { 440 if ( aValue != GetPropertySet()->getPropertyValue( C2U( "CharOverline" ) ) ) 441 { 442 GetPropertySet()->setPropertyValue( C2U( "CharOverline" ), aValue ); 443 bChanged = true; 444 } 445 } 446 447 if ( rItem.QueryValue( aValue, MID_TL_COLOR ) ) 448 { 449 if ( aValue != GetPropertySet()->getPropertyValue( C2U( "CharOverlineColor" ) ) ) 450 { 451 GetPropertySet()->setPropertyValue( C2U( "CharOverlineColor" ), aValue ); 452 bChanged = true; 453 } 454 } 455 456 if ( rItem.QueryValue( aValue, MID_TL_HASCOLOR ) ) 457 { 458 if ( aValue != GetPropertySet()->getPropertyValue( C2U( "CharOverlineHasColor" ) ) ) 459 { 460 GetPropertySet()->setPropertyValue( C2U( "CharOverlineHasColor" ), aValue ); 461 bChanged = true; 462 } 463 } 464 } 465 break; 466 467 case EE_CHAR_ITALIC: 468 case EE_CHAR_ITALIC_CJK: 469 case EE_CHAR_ITALIC_CTL: 470 { 471 ::rtl::OUString aPostfix; 472 if( nWhichId == EE_CHAR_ITALIC_CJK ) 473 aPostfix = C2U( "Asian" ); 474 else if( nWhichId == EE_CHAR_ITALIC_CTL ) 475 aPostfix = C2U( "Complex" ); 476 477 const SvxPostureItem & rItem = 478 static_cast< const SvxPostureItem & >( 479 rItemSet.Get( nWhichId )); 480 481 if( rItem.QueryValue( aValue, MID_POSTURE )) 482 { 483 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharPosture" ) + aPostfix)) 484 { 485 GetPropertySet()->setPropertyValue( C2U( "CharPosture" ) + aPostfix, aValue ); 486 bChanged = true; 487 } 488 } 489 } 490 break; 491 492 case EE_CHAR_WEIGHT: 493 case EE_CHAR_WEIGHT_CJK: 494 case EE_CHAR_WEIGHT_CTL: 495 { 496 ::rtl::OUString aPostfix; 497 if( nWhichId == EE_CHAR_WEIGHT_CJK ) 498 aPostfix = C2U( "Asian" ); 499 else if( nWhichId == EE_CHAR_WEIGHT_CTL ) 500 aPostfix = C2U( "Complex" ); 501 502 const SvxWeightItem & rItem = 503 static_cast< const SvxWeightItem & >( 504 rItemSet.Get( nWhichId )); 505 506 if( rItem.QueryValue( aValue, MID_WEIGHT )) 507 { 508 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharWeight" ) + aPostfix)) 509 { 510 GetPropertySet()->setPropertyValue( C2U( "CharWeight" ) + aPostfix, aValue ); 511 bChanged = true; 512 } 513 } 514 } 515 break; 516 517 case EE_CHAR_FONTHEIGHT: 518 case EE_CHAR_FONTHEIGHT_CJK: 519 case EE_CHAR_FONTHEIGHT_CTL: 520 { 521 ::rtl::OUString aPostfix; 522 if( nWhichId == EE_CHAR_FONTHEIGHT_CJK ) 523 aPostfix = C2U( "Asian" ); 524 else if( nWhichId == EE_CHAR_FONTHEIGHT_CTL ) 525 aPostfix = C2U( "Complex" ); 526 527 const SvxFontHeightItem & rItem = 528 static_cast< const SvxFontHeightItem & >( 529 rItemSet.Get( nWhichId )); 530 531 try 532 { 533 if( rItem.QueryValue( aValue, MID_FONTHEIGHT ) ) 534 { 535 bool bSetValue = false; 536 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharHeight" ) + aPostfix )) 537 bSetValue = true; 538 else 539 { 540 if( m_pRefSize.get() ) 541 { 542 awt::Size aNewRefSize = *m_pRefSize; 543 awt::Size aOldRefSize; 544 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ) >>= aOldRefSize ) 545 { 546 if( aNewRefSize.Width != aOldRefSize.Width 547 || aNewRefSize.Height != aOldRefSize.Height ) 548 bSetValue = true; 549 } 550 } 551 } 552 if( bSetValue ) 553 { 554 // set new reference size only if there was a reference size before (auto-scaling on) 555 if( m_pRefSize.get() && 556 GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ).hasValue()) 557 { 558 GetRefSizePropertySet()->setPropertyValue( m_aRefSizePropertyName, 559 uno::makeAny( *m_pRefSize )); 560 } 561 562 GetPropertySet()->setPropertyValue( C2U( "CharHeight" ) + aPostfix, aValue ); 563 bChanged = true; 564 } 565 } 566 } 567 catch( uno::Exception & ex ) 568 { 569 ASSERT_EXCEPTION( ex ); 570 } 571 } 572 break; 573 } 574 575 return bChanged; 576 } 577 578 uno::Reference< beans::XPropertySet > 579 CharacterPropertyItemConverter::GetRefSizePropertySet() const 580 { 581 return m_xRefSizePropSet; 582 } 583 584 } // namespace wrapper 585 } // namespace chart 586