1 /************************************************************************ 2 * 3 * Licensed Materials - Property of IBM. 4 * (C) Copyright IBM Corporation 2003, 2012. All Rights Reserved. 5 * U.S. Government Users Restricted Rights: 6 * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 7 * 8 ************************************************************************/ 9 10 #include "precompiled_sw.hxx" 11 12 #include "PagePropertyPanel.hxx" 13 #include "PagePropertyPanel.hrc" 14 15 #include "PropertyPanel.hrc" 16 17 #include <svx/sidebar/PopupContainer.hxx> 18 #include "PageOrientationControl.hxx" 19 #include "PageMarginControl.hxx" 20 #include "PageSizeControl.hxx" 21 #include "PageColumnControl.hxx" 22 23 #include <swtypes.hxx> 24 #include <cmdid.h> 25 #include <errhdl.hxx> 26 27 #include <svl/intitem.hxx> 28 #include <editeng/sizeitem.hxx> 29 #include <editeng/paperinf.hxx> 30 #include <svx/svxids.hrc> 31 #include <svx/dlgutil.hxx> 32 #include <svx/rulritem.hxx> 33 34 #include <sfx2/sidebar/ControlFactory.hxx> 35 #include <sfx2/dispatch.hxx> 36 #include <sfx2/bindings.hxx> 37 #include <sfx2/viewsh.hxx> 38 #include <sfx2/objsh.hxx> 39 40 #include <boost/bind.hpp> 41 42 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 43 44 #define SetFldVal(rField, lValue) (rField).SetValue((rField).Normalize(lValue), FUNIT_TWIP) 45 46 47 namespace sw { namespace sidebar { 48 49 PagePropertyPanel* PagePropertyPanel::Create ( 50 Window* pParent, 51 SfxBindings* pBindings) 52 { 53 if (pParent == NULL) 54 throw ::com::sun::star::lang::IllegalArgumentException(A2S("no parent Window given to PagePropertyPanel::Create"), NULL, 0); 55 if (pBindings == NULL) 56 throw ::com::sun::star::lang::IllegalArgumentException(A2S("no SfxBindings given to PagePropertyPanel::Create"), NULL, 2); 57 58 return new PagePropertyPanel( 59 pParent, 60 pBindings); 61 } 62 63 PagePropertyPanel::PagePropertyPanel( 64 Window* pParent, 65 SfxBindings* pBindings) 66 : Control(pParent, SW_RES(RID_PROPERTYPANEL_SWPAGE)) 67 , mpBindings(pBindings) 68 // visible controls 69 , maFtOrientation( this, SW_RES(FT_ORIENTATION) ) 70 , mpToolBoxOrientationBackground( ::sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this) ) 71 , mpToolBoxOrientation( ::sfx2::sidebar::ControlFactory::CreateToolBox( mpToolBoxOrientationBackground.get(), SW_RES(TB_ORIENTATION)) ) 72 , maFtMargin( this, SW_RES(FT_MARGIN) ) 73 , mpToolBoxMarginBackground( ::sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this) ) 74 , mpToolBoxMargin( ::sfx2::sidebar::ControlFactory::CreateToolBox( mpToolBoxMarginBackground.get(), SW_RES(TB_MARGIN)) ) 75 , maFtSize( this, SW_RES(FT_SIZE) ) 76 , mpToolBoxSizeBackground( ::sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this) ) 77 , mpToolBoxSize( ::sfx2::sidebar::ControlFactory::CreateToolBox( mpToolBoxSizeBackground.get(), SW_RES(TB_SIZE)) ) 78 , maFtColumn( this, SW_RES(FT_COLUMN) ) 79 , mpToolBoxColumnBackground( ::sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this) ) 80 , mpToolBoxColumn( ::sfx2::sidebar::ControlFactory::CreateToolBox( mpToolBoxColumnBackground.get(), SW_RES(TB_COLUMN)) ) 81 // image resources 82 , maImgSize (NULL) 83 , maImgSize_L (NULL) 84 , mImgPortrait (SW_RES(IMG_PAGE_PORTRAIT)) 85 , mImgLandscape (SW_RES(IMG_PAGE_LANDSCAPE)) 86 , mImgNarrow (SW_RES(IMG_PAGE_NARROW)) 87 , mImgNormal (SW_RES(IMG_PAGE_NORMAL)) 88 , mImgWide (SW_RES(IMG_PAGE_WIDE)) 89 , mImgMirrored (SW_RES(IMG_PAGE_MIRRORED)) 90 , mImgMarginCustom (SW_RES(IMG_PAGE_MARGIN_CUSTOM)) 91 , mImgNarrow_L (SW_RES(IMG_PAGE_NARROW_L)) 92 , mImgNormal_L (SW_RES(IMG_PAGE_NORMAL_L)) 93 , mImgWide_L (SW_RES(IMG_PAGE_WIDE_L)) 94 , mImgMirrored_L (SW_RES(IMG_PAGE_MIRRORED_L)) 95 , mImgMarginCustom_L (SW_RES(IMG_PAGE_MARGIN_CUSTOM_L)) 96 , mImgA3 (SW_RES(IMG_PAGE_A3)) 97 , mImgA4 (SW_RES(IMG_PAGE_A4)) 98 , mImgA5 (SW_RES(IMG_PAGE_A5)) 99 , mImgB4 (SW_RES(IMG_PAGE_B4)) 100 , mImgB5 (SW_RES(IMG_PAGE_B5)) 101 , mImgC5 (SW_RES(IMG_PAGE_C5)) 102 , mImgLetter (SW_RES(IMG_PAGE_LETTER)) 103 , mImgLegal (SW_RES(IMG_PAGE_LEGAL)) 104 , mImgSizeNone (SW_RES(IMG_PAGE_SIZE_NONE)) 105 , mImgA3_L (SW_RES(IMG_PAGE_A3_L)) 106 , mImgA4_L (SW_RES(IMG_PAGE_A4_L)) 107 , mImgA5_L (SW_RES(IMG_PAGE_A5_L)) 108 , mImgB4_L (SW_RES(IMG_PAGE_B4_L)) 109 , mImgB5_L (SW_RES(IMG_PAGE_B5_L)) 110 , mImgC5_L (SW_RES(IMG_PAGE_C5_L)) 111 , mImgLetter_L (SW_RES(IMG_PAGE_LETTER_L)) 112 , mImgLegal_L (SW_RES(IMG_PAGE_LEGAL_L)) 113 , mImgSizeNone_L (SW_RES(IMG_PAGE_SIZE_NONE_L)) 114 , mImgColumn1 (SW_RES(IMG_PAGE_COLUMN_1)) 115 , mImgColumn2 (SW_RES(IMG_PAGE_COLUMN_2)) 116 , mImgColumn3 (SW_RES(IMG_PAGE_COLUMN_3)) 117 , mImgLeft (SW_RES(IMG_PAGE_COLUMN_LEFT)) 118 , mImgRight (SW_RES(IMG_PAGE_COLUMN_RIGHT)) 119 , mImgColumnNone (SW_RES(IMG_PAGE_COLUMN_NONE)) 120 , mImgColumn1_L (SW_RES(IMG_PAGE_COLUMN_1_L)) 121 , mImgColumn2_L (SW_RES(IMG_PAGE_COLUMN_2_L)) 122 , mImgColumn3_L (SW_RES(IMG_PAGE_COLUMN_3_L)) 123 , mImgLeft_L (SW_RES(IMG_PAGE_COLUMN_LEFT_L)) 124 , mImgRight_L (SW_RES(IMG_PAGE_COLUMN_RIGHT_L)) 125 , mImgColumnNone_L (SW_RES(IMG_PAGE_COLUMN_NONE_L)) 126 127 , mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ) 128 , mpPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ) 129 , mpPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ) 130 , mpPageSizeItem( new SvxSizeItem(SID_ATTR_PAGE_SIZE) ) 131 , mePaper( PAPER_USER ) 132 , mpPageColumnTypeItem( new SfxInt16Item(SID_ATTR_PAGE_COLUMN) ) 133 134 , meFUnit() 135 , meUnit() 136 137 , m_aSwPagePgULControl(SID_ATTR_PAGE_ULSPACE, *pBindings, *this) 138 , m_aSwPagePgLRControl(SID_ATTR_PAGE_LRSPACE, *pBindings, *this) 139 , m_aSwPagePgSizeControl(SID_ATTR_PAGE_SIZE, *pBindings, *this) 140 , m_aSwPagePgControl(SID_ATTR_PAGE, *pBindings, *this) 141 , m_aSwPageColControl(SID_ATTR_PAGE_COLUMN, *pBindings, *this) 142 , m_aSwPagePgMetricControl(SID_ATTR_METRIC, *pBindings, *this) 143 144 , mpOrientationPopup() 145 , mpMarginPopup() 146 , mpSizePopup() 147 , mpColumnPopup() 148 149 , mbInvalidateSIDAttrPageOnSIDAttrPageSizeNotify( false ) 150 { 151 Initialize(); 152 mbInvalidateSIDAttrPageOnSIDAttrPageSizeNotify = true; 153 FreeResource(); 154 } 155 156 PagePropertyPanel::~PagePropertyPanel() 157 { 158 delete[] maImgSize; 159 delete[] maImgSize_L; 160 161 // destroy the toolbox windows. 162 mpToolBoxOrientation.reset(); 163 mpToolBoxMargin.reset(); 164 mpToolBoxSize.reset(); 165 mpToolBoxColumn.reset(); 166 167 // destroy the background windows of the toolboxes. 168 mpToolBoxOrientationBackground.reset(); 169 mpToolBoxMarginBackground.reset(); 170 mpToolBoxSizeBackground.reset(); 171 mpToolBoxColumnBackground.reset(); 172 } 173 174 void PagePropertyPanel::Initialize() 175 { 176 // popup for page orientation 177 Link aLink = LINK( this, PagePropertyPanel, ClickOrientationHdl ); 178 mpToolBoxOrientation->SetDropdownClickHdl( aLink ); 179 mpToolBoxOrientation->SetSelectHdl( aLink ); 180 mpToolBoxOrientation->SetItemImage( TBI_ORIENTATION, mImgPortrait); 181 mpToolBoxOrientation->SetItemBits( TBI_ORIENTATION, mpToolBoxOrientation->GetItemBits( TBI_ORIENTATION ) | TIB_DROPDOWNONLY ); 182 mpToolBoxOrientation->SetQuickHelpText(TBI_ORIENTATION,String(SW_RES(STR_QHELP_TB_ORIENTATION))); 183 mpToolBoxOrientation->SetOutputSizePixel( mpToolBoxOrientation->CalcWindowSizePixel() ); 184 mpToolBoxOrientation->SetBackground( Wallpaper() ); 185 mpToolBoxOrientation->SetPaintTransparent( sal_True ); 186 187 // popup for page margins 188 aLink = LINK( this, PagePropertyPanel, ClickMarginHdl ); 189 mpToolBoxMargin->SetDropdownClickHdl( aLink ); 190 mpToolBoxMargin->SetSelectHdl( aLink ); 191 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mImgNormal); 192 mpToolBoxMargin->SetItemBits( TBI_MARGIN, mpToolBoxMargin->GetItemBits( TBI_MARGIN ) | TIB_DROPDOWNONLY ); 193 mpToolBoxMargin->SetQuickHelpText(TBI_MARGIN,String(SW_RES(STR_QHELP_TB_MARGIN))); 194 mpToolBoxMargin->SetOutputSizePixel( mpToolBoxMargin->CalcWindowSizePixel() ); 195 mpToolBoxMargin->SetBackground(Wallpaper()); 196 mpToolBoxMargin->SetPaintTransparent( sal_True ); 197 198 // popup for page size 199 aLink = LINK( this, PagePropertyPanel, ClickSizeHdl ); 200 mpToolBoxSize->SetDropdownClickHdl( aLink ); 201 mpToolBoxSize->SetSelectHdl( aLink ); 202 mpToolBoxSize->SetItemImage(TBI_SIZE, mImgLetter); 203 mpToolBoxSize->SetItemBits( TBI_SIZE, mpToolBoxSize->GetItemBits( TBI_SIZE ) | TIB_DROPDOWNONLY ); 204 mpToolBoxSize->SetQuickHelpText(TBI_SIZE,String(SW_RES(STR_QHELP_TB_SIZE))); 205 mpToolBoxSize->SetOutputSizePixel( mpToolBoxSize->CalcWindowSizePixel() ); 206 mpToolBoxSize->SetBackground(Wallpaper()); 207 mpToolBoxSize->SetPaintTransparent( sal_True ); 208 maImgSize = new Image[8]; 209 maImgSize[0] = mImgA3; 210 maImgSize[1] = mImgA4; 211 maImgSize[2] = mImgA5; 212 maImgSize[3] = mImgB4; 213 maImgSize[4] = mImgB5; 214 maImgSize[5] = mImgC5; 215 maImgSize[6] = mImgLetter; 216 maImgSize[7] = mImgLegal; 217 maImgSize_L = new Image[8]; 218 maImgSize_L[0] = mImgA3_L; 219 maImgSize_L[1] = mImgA4_L; 220 maImgSize_L[2] = mImgA5_L; 221 maImgSize_L[3] = mImgB4_L; 222 maImgSize_L[4] = mImgB5_L; 223 maImgSize_L[5] = mImgC5_L; 224 maImgSize_L[6] = mImgLetter_L; 225 maImgSize_L[7] = mImgLegal_L; 226 227 // popup for page column property 228 aLink = LINK( this, PagePropertyPanel, ClickColumnHdl ); 229 mpToolBoxColumn->SetDropdownClickHdl( aLink ); 230 mpToolBoxColumn->SetSelectHdl( aLink ); 231 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1); 232 mpToolBoxColumn->SetItemBits( TBI_COLUMN, mpToolBoxColumn->GetItemBits( TBI_COLUMN ) | TIB_DROPDOWNONLY ); 233 mpToolBoxColumn->SetQuickHelpText(TBI_COLUMN,String(SW_RES(STR_QHELP_TB_COLUMN))); 234 mpToolBoxColumn->SetOutputSizePixel( mpToolBoxColumn->CalcWindowSizePixel() ); 235 mpToolBoxColumn->SetBackground(Wallpaper()); 236 mpToolBoxColumn->SetPaintTransparent( sal_True ); 237 238 meFUnit = GetModuleFieldUnit(); 239 meUnit = m_aSwPagePgSizeControl.GetCoreMetric(); 240 241 // 'pull' for page style's attribute values 242 mpBindings->Update( SID_ATTR_PAGE_LRSPACE ); 243 mpBindings->Update( SID_ATTR_PAGE_ULSPACE ); 244 mpBindings->Update( SID_ATTR_PAGE ); 245 mpBindings->Update( SID_ATTR_PAGE_SIZE ); 246 } 247 248 249 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageOrientationControl( ::svx::sidebar::PopupContainer* pParent ) 250 { 251 return new PageOrientationControl( pParent, *this , mpPageItem->IsLandscape() ); 252 } 253 254 255 IMPL_LINK( PagePropertyPanel, ClickOrientationHdl, ToolBox*, pToolBox ) 256 { 257 mpOrientationPopup.reset( 258 new ::svx::sidebar::Popup( 259 this, 260 ::boost::bind(&PagePropertyPanel::CreatePageOrientationControl, this, _1), 261 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page orientation")) ) ); 262 mpOrientationPopup->Show( *pToolBox ); 263 264 return 0L; 265 } 266 267 268 void PagePropertyPanel::ExecuteOrientationChange( const sal_Bool bLandscape ) 269 { 270 { 271 // set new page orientation 272 mpPageItem->SetLandscape( bLandscape ); 273 274 // swap the width and height of the page size 275 mpPageSizeItem->SetSize( Size( mpPageSizeItem->GetSize().Height(), mpPageSizeItem->GetSize().Width() ) ); 276 277 // apply changed attributes 278 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE_SIZE, SFX_CALLMODE_RECORD, mpPageSizeItem.get(), mpPageItem.get(), 0L ); 279 } 280 281 // check, if margin values still fit to the changed page size. 282 // if not, adjust margin values 283 { 284 const long nML = mpPageLRMarginItem->GetLeft(); 285 const long nMR = mpPageLRMarginItem->GetRight(); 286 const long nTmpPW = nML + nMR + MINBODY; 287 288 const long nPW = mpPageSizeItem->GetSize().Width(); 289 290 if ( nTmpPW > nPW ) 291 { 292 if ( nML <= nMR ) 293 { 294 ExecuteMarginLRChange( mpPageLRMarginItem->GetLeft(), nMR - (nTmpPW - nPW ) ); 295 } 296 else 297 { 298 ExecuteMarginLRChange( nML - (nTmpPW - nPW ), mpPageLRMarginItem->GetRight() ); 299 } 300 } 301 302 const long nMT = mpPageULMarginItem->GetUpper(); 303 const long nMB = mpPageULMarginItem->GetLower(); 304 const long nTmpPH = nMT + nMB + MINBODY; 305 306 const long nPH = mpPageSizeItem->GetSize().Height(); 307 308 if ( nTmpPH > nPH ) 309 { 310 if ( nMT <= nMB ) 311 { 312 ExecuteMarginULChange( mpPageULMarginItem->GetUpper(), nMB - ( nTmpPH - nPH ) ); 313 } 314 else 315 { 316 ExecuteMarginULChange( nMT - ( nTmpPH - nPH ), mpPageULMarginItem->GetLower() ); 317 } 318 } 319 } 320 } 321 322 323 void PagePropertyPanel::ClosePageOrientationPopup() 324 { 325 mpOrientationPopup->Hide(); 326 } 327 328 329 330 331 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageMarginControl( ::svx::sidebar::PopupContainer* pParent ) 332 { 333 return new PageMarginControl( 334 pParent, 335 *this, 336 *mpPageLRMarginItem.get(), 337 *mpPageULMarginItem.get(), 338 mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR, 339 mpPageSizeItem->GetSize(), 340 mpPageItem->IsLandscape(), 341 meFUnit, 342 meUnit ); 343 } 344 345 346 void PagePropertyPanel::ExecuteMarginLRChange( 347 const long nPageLeftMargin, 348 const long nPageRightMargin ) 349 { 350 mpPageLRMarginItem->SetLeft( nPageLeftMargin ); 351 mpPageLRMarginItem->SetRight( nPageRightMargin ); 352 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE_LRSPACE, SFX_CALLMODE_RECORD, mpPageLRMarginItem.get(), 0L ); 353 } 354 355 void PagePropertyPanel::ExecuteMarginULChange( 356 const long nPageTopMargin, 357 const long nPageBottomMargin ) 358 { 359 mpPageULMarginItem->SetUpper( nPageTopMargin ); 360 mpPageULMarginItem->SetLower( nPageBottomMargin ); 361 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE_ULSPACE, SFX_CALLMODE_RECORD, mpPageULMarginItem.get(), 0L ); 362 } 363 364 365 void PagePropertyPanel::ExecutePageLayoutChange( const bool bMirrored ) 366 { 367 mpPageItem->SetPageUsage( bMirrored ? SVX_PAGE_MIRROR : SVX_PAGE_ALL ); 368 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE, SFX_CALLMODE_RECORD, mpPageItem.get(), 0L ); 369 } 370 371 372 IMPL_LINK( PagePropertyPanel, ClickMarginHdl, ToolBox*, pToolBox ) 373 { 374 mpMarginPopup.reset( 375 new ::svx::sidebar::Popup( 376 this, 377 ::boost::bind(&PagePropertyPanel::CreatePageMarginControl, this, _1), 378 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page margins")) ) ); 379 mpMarginPopup->Show( *pToolBox ); 380 381 return 0L; 382 } 383 384 385 void PagePropertyPanel::ClosePageMarginPopup() 386 { 387 mpMarginPopup->Hide(); 388 } 389 390 391 392 393 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageSizeControl( ::svx::sidebar::PopupContainer* pParent ) 394 { 395 return new PageSizeControl( 396 pParent, 397 *this, 398 mePaper, 399 mpPageItem->IsLandscape(), 400 meFUnit ); 401 } 402 403 404 void PagePropertyPanel::ExecuteSizeChange( const Paper ePaper ) 405 { 406 Size aPageSize = SvxPaperInfo::GetPaperSize( ePaper, (MapUnit)(meUnit) ); 407 if ( mpPageItem->IsLandscape() ) 408 { 409 Swap( aPageSize ); 410 } 411 mpPageSizeItem->SetSize( aPageSize ); 412 413 mpBindings->GetDispatcher()->Execute(SID_ATTR_PAGE_SIZE, SFX_CALLMODE_RECORD, mpPageSizeItem.get(), 0L ); 414 } 415 416 417 IMPL_LINK( PagePropertyPanel, ClickSizeHdl, ToolBox*, pToolBox ) 418 { 419 mpSizePopup.reset( 420 new ::svx::sidebar::Popup( 421 this, 422 ::boost::bind(&PagePropertyPanel::CreatePageSizeControl, this, _1), 423 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page size")) ) ); 424 mpSizePopup->Show( *pToolBox ); 425 426 return 0L; 427 } 428 429 430 void PagePropertyPanel::ClosePageSizePopup() 431 { 432 mpSizePopup->Hide(); 433 } 434 435 436 437 438 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageColumnControl( ::svx::sidebar::PopupContainer* pParent ) 439 { 440 return new PageColumnControl( 441 pParent, 442 *this, 443 mpPageColumnTypeItem->GetValue(), 444 mpPageItem->IsLandscape() ); 445 } 446 447 448 void PagePropertyPanel::ExecuteColumnChange( const sal_uInt16 nColumnType ) 449 { 450 mpPageColumnTypeItem->SetValue( nColumnType ); 451 mpBindings->GetDispatcher()->Execute(SID_ATTR_PAGE_COLUMN, SFX_CALLMODE_RECORD, mpPageColumnTypeItem.get(), 0L ); 452 } 453 454 455 IMPL_LINK( PagePropertyPanel, ClickColumnHdl, ToolBox*, pToolBox ) 456 { 457 mpColumnPopup.reset( 458 new ::svx::sidebar::Popup( 459 this, 460 ::boost::bind(&PagePropertyPanel::CreatePageColumnControl, this, _1), 461 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page columns")) ) ); 462 mpColumnPopup->Show( *pToolBox ); 463 464 return 0L; 465 } 466 467 468 void PagePropertyPanel::ClosePageColumnPopup() 469 { 470 mpColumnPopup->Hide(); 471 } 472 473 474 475 476 void PagePropertyPanel::NotifyItemUpdate( 477 const sal_uInt16 nSId, 478 const SfxItemState eState, 479 const SfxPoolItem* pState) 480 { 481 switch( nSId ) 482 { 483 case SID_ATTR_PAGE_COLUMN: 484 { 485 if ( eState >= SFX_ITEM_AVAILABLE && 486 pState && pState->ISA(SfxInt16Item) ) 487 { 488 mpPageColumnTypeItem.reset( static_cast<SfxInt16Item*>(pState->Clone()) ); 489 ChangeColumnImage( mpPageColumnTypeItem->GetValue() ); 490 } 491 } 492 break; 493 case SID_ATTR_PAGE_LRSPACE: 494 if ( eState >= SFX_ITEM_AVAILABLE && 495 pState && pState->ISA(SvxLongLRSpaceItem) ) 496 { 497 mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) ); 498 ChangeMarginImage(); 499 } 500 break; 501 502 case SID_ATTR_PAGE_ULSPACE: 503 if ( eState >= SFX_ITEM_AVAILABLE && 504 pState && pState->ISA(SvxLongULSpaceItem) ) 505 { 506 mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) ); 507 ChangeMarginImage(); 508 } 509 break; 510 511 case SID_ATTR_PAGE: 512 if ( eState >= SFX_ITEM_AVAILABLE && 513 pState && pState->ISA(SvxPageItem) ) 514 { 515 mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) ); 516 if ( mpPageItem->IsLandscape() ) 517 { 518 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgLandscape); 519 } 520 else 521 { 522 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgPortrait); 523 } 524 ChangeMarginImage(); 525 ChangeSizeImage(); 526 ChangeColumnImage( mpPageColumnTypeItem->GetValue() ); 527 } 528 break; 529 530 case SID_ATTR_PAGE_SIZE: 531 if ( mbInvalidateSIDAttrPageOnSIDAttrPageSizeNotify ) 532 { 533 mpBindings->Invalidate( SID_ATTR_PAGE, sal_True, sal_False ); 534 } 535 if ( eState >= SFX_ITEM_AVAILABLE && 536 pState && pState->ISA(SvxSizeItem) ) 537 { 538 mpPageSizeItem.reset( static_cast<SvxSizeItem*>(pState->Clone()) ); 539 ChangeSizeImage(); 540 } 541 break; 542 case SID_ATTR_METRIC: 543 MetricState( eState, pState ); 544 break; 545 } 546 } 547 548 549 void PagePropertyPanel::MetricState( SfxItemState eState, const SfxPoolItem* pState ) 550 { 551 meFUnit = FUNIT_NONE; 552 if ( pState && eState >= SFX_ITEM_DEFAULT ) 553 { 554 meFUnit = (FieldUnit)( (const SfxUInt16Item*)pState )->GetValue(); 555 } 556 else 557 { 558 SfxViewFrame* pFrame = SfxViewFrame::Current(); 559 SfxObjectShell* pSh = NULL; 560 if ( pFrame ) 561 pSh = pFrame->GetObjectShell(); 562 if ( pSh ) 563 { 564 SfxModule* pModule = pSh->GetModule(); 565 if ( pModule ) 566 { 567 const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC ); 568 if ( pItem ) 569 meFUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue(); 570 } 571 else 572 { 573 DBG_ERRORFILE( "<PagePropertyPanel::MetricState(..)>: no module found" ); 574 } 575 } 576 } 577 } 578 579 580 581 582 void PagePropertyPanel::ChangeMarginImage() 583 { 584 if ( mpPageLRMarginItem.get() == 0 || 585 mpPageULMarginItem.get() == 0 || 586 mpPageItem.get() == 0 ) 587 { 588 return; 589 } 590 591 const long cTolerance = 5; 592 593 if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NARROW_VALUE) <= cTolerance && 594 abs(mpPageLRMarginItem->GetRight() - SWPAGE_NARROW_VALUE) <= cTolerance && 595 abs(mpPageULMarginItem->GetUpper() - SWPAGE_NARROW_VALUE) <= cTolerance && 596 abs(mpPageULMarginItem->GetLower() - SWPAGE_NARROW_VALUE) <= cTolerance && 597 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 598 mpToolBoxMargin->SetItemImage( TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNarrow_L : mImgNarrow ); 599 600 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NORMAL_VALUE) <= cTolerance && 601 abs(mpPageLRMarginItem->GetRight() - SWPAGE_NORMAL_VALUE) <= cTolerance && 602 abs(mpPageULMarginItem->GetUpper() - SWPAGE_NORMAL_VALUE) <= cTolerance && 603 abs(mpPageULMarginItem->GetLower() - SWPAGE_NORMAL_VALUE) <= cTolerance && 604 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 605 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNormal_L : mImgNormal ); 606 607 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE2) <= cTolerance && 608 abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE2) <= cTolerance && 609 abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && 610 abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && 611 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 612 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgWide_L : mImgWide ); 613 614 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE3) <= cTolerance && 615 abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE1) <= cTolerance && 616 abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && 617 abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && 618 mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR ) 619 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMirrored_L : mImgMirrored ); 620 621 else 622 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMarginCustom_L : mImgMarginCustom ); 623 } 624 625 626 void PagePropertyPanel::ChangeSizeImage() 627 { 628 if ( mpPageSizeItem.get() == 0 || 629 mpPageItem.get() == 0 ) 630 { 631 return; 632 } 633 634 Size aTmpPaperSize = mpPageSizeItem->GetSize(); 635 if ( mpPageItem->IsLandscape() ) 636 { 637 Swap( aTmpPaperSize ); // Swap(..) defined in editeng/paperinf.hxx 638 } 639 640 mePaper = SvxPaperInfo::GetSvxPaper( aTmpPaperSize, static_cast<MapUnit>(meUnit), sal_True ); 641 642 sal_uInt16 nImageIdx = 0; 643 switch ( mePaper ) 644 { 645 case PAPER_A3: 646 nImageIdx = 1; 647 break; 648 case PAPER_A4: 649 nImageIdx = 2; 650 break; 651 case PAPER_A5: 652 nImageIdx = 3; 653 break; 654 case PAPER_B4_ISO: 655 nImageIdx = 4; 656 break; 657 case PAPER_B5_ISO: 658 nImageIdx = 5; 659 break; 660 case PAPER_ENV_C5: 661 nImageIdx = 6; 662 break; 663 case PAPER_LETTER: 664 nImageIdx = 7; 665 break; 666 case PAPER_LEGAL: 667 nImageIdx = 8; 668 break; 669 default: 670 nImageIdx = 0; 671 mePaper = PAPER_USER; 672 break; 673 } 674 675 if ( nImageIdx == 0 ) 676 { 677 mpToolBoxSize->SetItemImage( TBI_SIZE, 678 ( mpPageItem->IsLandscape() ? mImgSizeNone_L : mImgSizeNone ) ); 679 } 680 else 681 { 682 mpToolBoxSize->SetItemImage( TBI_SIZE, 683 ( mpPageItem->IsLandscape() ? maImgSize_L[nImageIdx-1] : maImgSize[nImageIdx-1] ) ); 684 } 685 } 686 687 688 void PagePropertyPanel::ChangeColumnImage( const sal_uInt16 nColumnType ) 689 { 690 if ( mpPageItem.get() == 0 ) 691 { 692 return; 693 } 694 695 if ( !mpPageItem->IsLandscape() ) 696 { 697 switch( nColumnType ) 698 { 699 case 1: 700 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1); 701 break; 702 case 2: 703 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2); 704 break; 705 case 3: 706 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3); 707 break; 708 case 4: 709 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft); 710 break; 711 case 5: 712 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight); 713 break; 714 default: 715 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone); 716 } 717 } 718 else 719 { 720 switch( nColumnType ) 721 { 722 case 1: 723 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1_L); 724 break; 725 case 2: 726 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2_L); 727 break; 728 case 3: 729 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3_L); 730 break; 731 case 4: 732 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft_L); 733 break; 734 case 5: 735 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight_L); 736 break; 737 default: 738 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone_L); 739 } 740 } 741 } 742 743 } } // end of namespace ::sw::sidebar 744