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 maFtOrientation.SetBackground(Wallpaper()); 189 maFtMargin.SetBackground(Wallpaper()); 190 maFtSize.SetBackground(Wallpaper()); 191 maFtColumn.SetBackground(Wallpaper()); 192 193 // popup for page orientation 194 Link aLink = LINK( this, PagePropertyPanel, ClickOrientationHdl ); 195 mpToolBoxOrientation->SetDropdownClickHdl( aLink ); 196 mpToolBoxOrientation->SetSelectHdl( aLink ); 197 mpToolBoxOrientation->SetItemImage( TBI_ORIENTATION, mImgPortrait); 198 mpToolBoxOrientation->SetItemBits( TBI_ORIENTATION, mpToolBoxOrientation->GetItemBits( TBI_ORIENTATION ) | TIB_DROPDOWNONLY ); 199 mpToolBoxOrientation->SetQuickHelpText(TBI_ORIENTATION,String(SW_RES(STR_QHELP_TB_ORIENTATION))); 200 mpToolBoxOrientation->SetOutputSizePixel( mpToolBoxOrientation->CalcWindowSizePixel() ); 201 mpToolBoxOrientation->SetBackground( Wallpaper() ); 202 mpToolBoxOrientation->SetPaintTransparent( sal_True ); 203 204 // popup for page margins 205 aLink = LINK( this, PagePropertyPanel, ClickMarginHdl ); 206 mpToolBoxMargin->SetDropdownClickHdl( aLink ); 207 mpToolBoxMargin->SetSelectHdl( aLink ); 208 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mImgNormal); 209 mpToolBoxMargin->SetItemBits( TBI_MARGIN, mpToolBoxMargin->GetItemBits( TBI_MARGIN ) | TIB_DROPDOWNONLY ); 210 mpToolBoxMargin->SetQuickHelpText(TBI_MARGIN,String(SW_RES(STR_QHELP_TB_MARGIN))); 211 mpToolBoxMargin->SetOutputSizePixel( mpToolBoxMargin->CalcWindowSizePixel() ); 212 mpToolBoxMargin->SetBackground(Wallpaper()); 213 mpToolBoxMargin->SetPaintTransparent( sal_True ); 214 215 // popup for page size 216 aLink = LINK( this, PagePropertyPanel, ClickSizeHdl ); 217 mpToolBoxSize->SetDropdownClickHdl( aLink ); 218 mpToolBoxSize->SetSelectHdl( aLink ); 219 mpToolBoxSize->SetItemImage(TBI_SIZE, mImgLetter); 220 mpToolBoxSize->SetItemBits( TBI_SIZE, mpToolBoxSize->GetItemBits( TBI_SIZE ) | TIB_DROPDOWNONLY ); 221 mpToolBoxSize->SetQuickHelpText(TBI_SIZE,String(SW_RES(STR_QHELP_TB_SIZE))); 222 mpToolBoxSize->SetOutputSizePixel( mpToolBoxSize->CalcWindowSizePixel() ); 223 mpToolBoxSize->SetBackground(Wallpaper()); 224 mpToolBoxSize->SetPaintTransparent( sal_True ); 225 maImgSize = new Image[8]; 226 maImgSize[0] = mImgA3; 227 maImgSize[1] = mImgA4; 228 maImgSize[2] = mImgA5; 229 maImgSize[3] = mImgB4; 230 maImgSize[4] = mImgB5; 231 maImgSize[5] = mImgC5; 232 maImgSize[6] = mImgLetter; 233 maImgSize[7] = mImgLegal; 234 maImgSize_L = new Image[8]; 235 maImgSize_L[0] = mImgA3_L; 236 maImgSize_L[1] = mImgA4_L; 237 maImgSize_L[2] = mImgA5_L; 238 maImgSize_L[3] = mImgB4_L; 239 maImgSize_L[4] = mImgB5_L; 240 maImgSize_L[5] = mImgC5_L; 241 maImgSize_L[6] = mImgLetter_L; 242 maImgSize_L[7] = mImgLegal_L; 243 244 // popup for page column property 245 aLink = LINK( this, PagePropertyPanel, ClickColumnHdl ); 246 mpToolBoxColumn->SetDropdownClickHdl( aLink ); 247 mpToolBoxColumn->SetSelectHdl( aLink ); 248 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1); 249 mpToolBoxColumn->SetItemBits( TBI_COLUMN, mpToolBoxColumn->GetItemBits( TBI_COLUMN ) | TIB_DROPDOWNONLY ); 250 mpToolBoxColumn->SetQuickHelpText(TBI_COLUMN,String(SW_RES(STR_QHELP_TB_COLUMN))); 251 mpToolBoxColumn->SetOutputSizePixel( mpToolBoxColumn->CalcWindowSizePixel() ); 252 mpToolBoxColumn->SetBackground(Wallpaper()); 253 mpToolBoxColumn->SetPaintTransparent( sal_True ); 254 255 meFUnit = GetModuleFieldUnit(); 256 meUnit = m_aSwPagePgSizeControl.GetCoreMetric(); 257 258 // 'pull' for page style's attribute values 259 mpBindings->Update( SID_ATTR_PAGE_LRSPACE ); 260 mpBindings->Update( SID_ATTR_PAGE_ULSPACE ); 261 mpBindings->Update( SID_ATTR_PAGE ); 262 mpBindings->Update( SID_ATTR_PAGE_SIZE ); 263 } 264 265 266 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageOrientationControl( ::svx::sidebar::PopupContainer* pParent ) 267 { 268 return new PageOrientationControl( pParent, *this , mpPageItem->IsLandscape() ); 269 } 270 271 272 IMPL_LINK( PagePropertyPanel, ClickOrientationHdl, ToolBox*, pToolBox ) 273 { 274 if ( ! mpOrientationPopup) 275 { 276 mpOrientationPopup.reset( 277 new ::svx::sidebar::Popup( 278 this, 279 ::boost::bind(&PagePropertyPanel::CreatePageOrientationControl, this, _1), 280 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page orientation")) ) ); 281 } 282 mpOrientationPopup->Show( *pToolBox ); 283 284 return 0L; 285 } 286 287 288 void PagePropertyPanel::ExecuteOrientationChange( const sal_Bool bLandscape ) 289 { 290 { 291 // set new page orientation 292 mpPageItem->SetLandscape( bLandscape ); 293 294 // swap the width and height of the page size 295 mpPageSizeItem->SetSize( Size( mpPageSizeItem->GetSize().Height(), mpPageSizeItem->GetSize().Width() ) ); 296 297 // apply changed attributes 298 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE_SIZE, SFX_CALLMODE_RECORD, mpPageSizeItem.get(), mpPageItem.get(), 0L ); 299 } 300 301 // check, if margin values still fit to the changed page size. 302 // if not, adjust margin values 303 { 304 const long nML = mpPageLRMarginItem->GetLeft(); 305 const long nMR = mpPageLRMarginItem->GetRight(); 306 const long nTmpPW = nML + nMR + MINBODY; 307 308 const long nPW = mpPageSizeItem->GetSize().Width(); 309 310 if ( nTmpPW > nPW ) 311 { 312 if ( nML <= nMR ) 313 { 314 ExecuteMarginLRChange( mpPageLRMarginItem->GetLeft(), nMR - (nTmpPW - nPW ) ); 315 } 316 else 317 { 318 ExecuteMarginLRChange( nML - (nTmpPW - nPW ), mpPageLRMarginItem->GetRight() ); 319 } 320 } 321 322 const long nMT = mpPageULMarginItem->GetUpper(); 323 const long nMB = mpPageULMarginItem->GetLower(); 324 const long nTmpPH = nMT + nMB + MINBODY; 325 326 const long nPH = mpPageSizeItem->GetSize().Height(); 327 328 if ( nTmpPH > nPH ) 329 { 330 if ( nMT <= nMB ) 331 { 332 ExecuteMarginULChange( mpPageULMarginItem->GetUpper(), nMB - ( nTmpPH - nPH ) ); 333 } 334 else 335 { 336 ExecuteMarginULChange( nMT - ( nTmpPH - nPH ), mpPageULMarginItem->GetLower() ); 337 } 338 } 339 } 340 } 341 342 343 void PagePropertyPanel::ClosePageOrientationPopup() 344 { 345 mpOrientationPopup->Hide(); 346 } 347 348 349 350 351 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageMarginControl( ::svx::sidebar::PopupContainer* pParent ) 352 { 353 return new PageMarginControl( 354 pParent, 355 *this, 356 *mpPageLRMarginItem.get(), 357 *mpPageULMarginItem.get(), 358 mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR, 359 mpPageSizeItem->GetSize(), 360 mpPageItem->IsLandscape(), 361 meFUnit, 362 meUnit ); 363 } 364 365 366 void PagePropertyPanel::ExecuteMarginLRChange( 367 const long nPageLeftMargin, 368 const long nPageRightMargin ) 369 { 370 mpPageLRMarginItem->SetLeft( nPageLeftMargin ); 371 mpPageLRMarginItem->SetRight( nPageRightMargin ); 372 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE_LRSPACE, SFX_CALLMODE_RECORD, mpPageLRMarginItem.get(), 0L ); 373 } 374 375 void PagePropertyPanel::ExecuteMarginULChange( 376 const long nPageTopMargin, 377 const long nPageBottomMargin ) 378 { 379 mpPageULMarginItem->SetUpper( nPageTopMargin ); 380 mpPageULMarginItem->SetLower( nPageBottomMargin ); 381 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE_ULSPACE, SFX_CALLMODE_RECORD, mpPageULMarginItem.get(), 0L ); 382 } 383 384 385 void PagePropertyPanel::ExecutePageLayoutChange( const bool bMirrored ) 386 { 387 mpPageItem->SetPageUsage( bMirrored ? SVX_PAGE_MIRROR : SVX_PAGE_ALL ); 388 GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE, SFX_CALLMODE_RECORD, mpPageItem.get(), 0L ); 389 } 390 391 392 IMPL_LINK( PagePropertyPanel, ClickMarginHdl, ToolBox*, pToolBox ) 393 { 394 if ( ! mpMarginPopup) 395 mpMarginPopup.reset( 396 new ::svx::sidebar::Popup( 397 this, 398 ::boost::bind(&PagePropertyPanel::CreatePageMarginControl, this, _1), 399 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page margins")) ) ); 400 mpMarginPopup->Show( *pToolBox ); 401 402 return 0L; 403 } 404 405 406 void PagePropertyPanel::ClosePageMarginPopup() 407 { 408 mpMarginPopup->Hide(); 409 } 410 411 412 413 414 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageSizeControl( ::svx::sidebar::PopupContainer* pParent ) 415 { 416 return new PageSizeControl( 417 pParent, 418 *this, 419 mePaper, 420 mpPageItem->IsLandscape(), 421 meFUnit ); 422 } 423 424 425 void PagePropertyPanel::ExecuteSizeChange( const Paper ePaper ) 426 { 427 Size aPageSize = SvxPaperInfo::GetPaperSize( ePaper, (MapUnit)(meUnit) ); 428 if ( mpPageItem->IsLandscape() ) 429 { 430 Swap( aPageSize ); 431 } 432 mpPageSizeItem->SetSize( aPageSize ); 433 434 mpBindings->GetDispatcher()->Execute(SID_ATTR_PAGE_SIZE, SFX_CALLMODE_RECORD, mpPageSizeItem.get(), 0L ); 435 } 436 437 438 IMPL_LINK( PagePropertyPanel, ClickSizeHdl, ToolBox*, pToolBox ) 439 { 440 if ( ! mpSizePopup) 441 mpSizePopup.reset( 442 new ::svx::sidebar::Popup( 443 this, 444 ::boost::bind(&PagePropertyPanel::CreatePageSizeControl, this, _1), 445 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page size")) ) ); 446 mpSizePopup->Show( *pToolBox ); 447 448 return 0L; 449 } 450 451 452 void PagePropertyPanel::ClosePageSizePopup() 453 { 454 mpSizePopup->Hide(); 455 } 456 457 458 459 460 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageColumnControl( ::svx::sidebar::PopupContainer* pParent ) 461 { 462 return new PageColumnControl( 463 pParent, 464 *this, 465 mpPageColumnTypeItem->GetValue(), 466 mpPageItem->IsLandscape() ); 467 } 468 469 470 void PagePropertyPanel::ExecuteColumnChange( const sal_uInt16 nColumnType ) 471 { 472 mpPageColumnTypeItem->SetValue( nColumnType ); 473 mpBindings->GetDispatcher()->Execute(SID_ATTR_PAGE_COLUMN, SFX_CALLMODE_RECORD, mpPageColumnTypeItem.get(), 0L ); 474 } 475 476 477 IMPL_LINK( PagePropertyPanel, ClickColumnHdl, ToolBox*, pToolBox ) 478 { 479 if ( ! mpColumnPopup) 480 mpColumnPopup.reset( 481 new ::svx::sidebar::Popup( 482 this, 483 ::boost::bind(&PagePropertyPanel::CreatePageColumnControl, this, _1), 484 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page columns")) ) ); 485 mpColumnPopup->Show( *pToolBox ); 486 487 return 0L; 488 } 489 490 491 void PagePropertyPanel::ClosePageColumnPopup() 492 { 493 mpColumnPopup->Hide(); 494 } 495 496 497 498 499 void PagePropertyPanel::NotifyItemUpdate( 500 const sal_uInt16 nSId, 501 const SfxItemState eState, 502 const SfxPoolItem* pState, 503 const bool bIsEnabled) 504 { 505 (void)bIsEnabled; 506 507 switch( nSId ) 508 { 509 case SID_ATTR_PAGE_COLUMN: 510 { 511 if ( eState >= SFX_ITEM_AVAILABLE && 512 pState && pState->ISA(SfxInt16Item) ) 513 { 514 mpPageColumnTypeItem.reset( static_cast<SfxInt16Item*>(pState->Clone()) ); 515 ChangeColumnImage( mpPageColumnTypeItem->GetValue() ); 516 } 517 } 518 break; 519 case SID_ATTR_PAGE_LRSPACE: 520 if ( eState >= SFX_ITEM_AVAILABLE && 521 pState && pState->ISA(SvxLongLRSpaceItem) ) 522 { 523 mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) ); 524 ChangeMarginImage(); 525 } 526 break; 527 528 case SID_ATTR_PAGE_ULSPACE: 529 if ( eState >= SFX_ITEM_AVAILABLE && 530 pState && pState->ISA(SvxLongULSpaceItem) ) 531 { 532 mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) ); 533 ChangeMarginImage(); 534 } 535 break; 536 537 case SID_ATTR_PAGE: 538 if ( eState >= SFX_ITEM_AVAILABLE && 539 pState && pState->ISA(SvxPageItem) ) 540 { 541 mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) ); 542 if ( mpPageItem->IsLandscape() ) 543 { 544 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgLandscape); 545 } 546 else 547 { 548 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgPortrait); 549 } 550 ChangeMarginImage(); 551 ChangeSizeImage(); 552 ChangeColumnImage( mpPageColumnTypeItem->GetValue() ); 553 } 554 break; 555 556 case SID_ATTR_PAGE_SIZE: 557 if ( mbInvalidateSIDAttrPageOnSIDAttrPageSizeNotify ) 558 { 559 mpBindings->Invalidate( SID_ATTR_PAGE, sal_True, sal_False ); 560 } 561 if ( eState >= SFX_ITEM_AVAILABLE && 562 pState && pState->ISA(SvxSizeItem) ) 563 { 564 mpPageSizeItem.reset( static_cast<SvxSizeItem*>(pState->Clone()) ); 565 ChangeSizeImage(); 566 } 567 break; 568 case SID_ATTR_METRIC: 569 MetricState( eState, pState ); 570 break; 571 } 572 } 573 574 575 void PagePropertyPanel::MetricState( SfxItemState eState, const SfxPoolItem* pState ) 576 { 577 meFUnit = FUNIT_NONE; 578 if ( pState && eState >= SFX_ITEM_DEFAULT ) 579 { 580 meFUnit = (FieldUnit)( (const SfxUInt16Item*)pState )->GetValue(); 581 } 582 else 583 { 584 SfxViewFrame* pFrame = SfxViewFrame::Current(); 585 SfxObjectShell* pSh = NULL; 586 if ( pFrame ) 587 pSh = pFrame->GetObjectShell(); 588 if ( pSh ) 589 { 590 SfxModule* pModule = pSh->GetModule(); 591 if ( pModule ) 592 { 593 const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC ); 594 if ( pItem ) 595 meFUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue(); 596 } 597 else 598 { 599 DBG_ERRORFILE( "<PagePropertyPanel::MetricState(..)>: no module found" ); 600 } 601 } 602 } 603 } 604 605 606 607 608 void PagePropertyPanel::ChangeMarginImage() 609 { 610 if ( mpPageLRMarginItem.get() == 0 || 611 mpPageULMarginItem.get() == 0 || 612 mpPageItem.get() == 0 ) 613 { 614 return; 615 } 616 617 const long cTolerance = 5; 618 619 if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NARROW_VALUE) <= cTolerance && 620 abs(mpPageLRMarginItem->GetRight() - SWPAGE_NARROW_VALUE) <= cTolerance && 621 abs(mpPageULMarginItem->GetUpper() - SWPAGE_NARROW_VALUE) <= cTolerance && 622 abs(mpPageULMarginItem->GetLower() - SWPAGE_NARROW_VALUE) <= cTolerance && 623 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 624 mpToolBoxMargin->SetItemImage( TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNarrow_L : mImgNarrow ); 625 626 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NORMAL_VALUE) <= cTolerance && 627 abs(mpPageLRMarginItem->GetRight() - SWPAGE_NORMAL_VALUE) <= cTolerance && 628 abs(mpPageULMarginItem->GetUpper() - SWPAGE_NORMAL_VALUE) <= cTolerance && 629 abs(mpPageULMarginItem->GetLower() - SWPAGE_NORMAL_VALUE) <= cTolerance && 630 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 631 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNormal_L : mImgNormal ); 632 633 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE2) <= cTolerance && 634 abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE2) <= cTolerance && 635 abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && 636 abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && 637 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 638 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgWide_L : mImgWide ); 639 640 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE3) <= cTolerance && 641 abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE1) <= cTolerance && 642 abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && 643 abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && 644 mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR ) 645 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMirrored_L : mImgMirrored ); 646 647 else 648 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMarginCustom_L : mImgMarginCustom ); 649 } 650 651 652 void PagePropertyPanel::ChangeSizeImage() 653 { 654 if ( mpPageSizeItem.get() == 0 || 655 mpPageItem.get() == 0 ) 656 { 657 return; 658 } 659 660 Size aTmpPaperSize = mpPageSizeItem->GetSize(); 661 if ( mpPageItem->IsLandscape() ) 662 { 663 Swap( aTmpPaperSize ); // Swap(..) defined in editeng/paperinf.hxx 664 } 665 666 mePaper = SvxPaperInfo::GetSvxPaper( aTmpPaperSize, static_cast<MapUnit>(meUnit), sal_True ); 667 668 sal_uInt16 nImageIdx = 0; 669 switch ( mePaper ) 670 { 671 case PAPER_A3: 672 nImageIdx = 1; 673 break; 674 case PAPER_A4: 675 nImageIdx = 2; 676 break; 677 case PAPER_A5: 678 nImageIdx = 3; 679 break; 680 case PAPER_B4_ISO: 681 nImageIdx = 4; 682 break; 683 case PAPER_B5_ISO: 684 nImageIdx = 5; 685 break; 686 case PAPER_ENV_C5: 687 nImageIdx = 6; 688 break; 689 case PAPER_LETTER: 690 nImageIdx = 7; 691 break; 692 case PAPER_LEGAL: 693 nImageIdx = 8; 694 break; 695 default: 696 nImageIdx = 0; 697 mePaper = PAPER_USER; 698 break; 699 } 700 701 if ( nImageIdx == 0 ) 702 { 703 mpToolBoxSize->SetItemImage( TBI_SIZE, 704 ( mpPageItem->IsLandscape() ? mImgSizeNone_L : mImgSizeNone ) ); 705 } 706 else 707 { 708 mpToolBoxSize->SetItemImage( TBI_SIZE, 709 ( mpPageItem->IsLandscape() ? maImgSize_L[nImageIdx-1] : maImgSize[nImageIdx-1] ) ); 710 } 711 } 712 713 714 void PagePropertyPanel::ChangeColumnImage( const sal_uInt16 nColumnType ) 715 { 716 if ( mpPageItem.get() == 0 ) 717 { 718 return; 719 } 720 721 if ( !mpPageItem->IsLandscape() ) 722 { 723 switch( nColumnType ) 724 { 725 case 1: 726 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1); 727 break; 728 case 2: 729 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2); 730 break; 731 case 3: 732 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3); 733 break; 734 case 4: 735 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft); 736 break; 737 case 5: 738 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight); 739 break; 740 default: 741 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone); 742 } 743 } 744 else 745 { 746 switch( nColumnType ) 747 { 748 case 1: 749 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1_L); 750 break; 751 case 2: 752 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2_L); 753 break; 754 case 3: 755 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3_L); 756 break; 757 case 4: 758 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft_L); 759 break; 760 case 5: 761 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight_L); 762 break; 763 default: 764 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone_L); 765 } 766 } 767 } 768 769 } } // end of namespace ::sw::sidebar 770