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