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 { 504 switch( nSId ) 505 { 506 case SID_ATTR_PAGE_COLUMN: 507 { 508 if ( eState >= SFX_ITEM_AVAILABLE && 509 pState && pState->ISA(SfxInt16Item) ) 510 { 511 mpPageColumnTypeItem.reset( static_cast<SfxInt16Item*>(pState->Clone()) ); 512 ChangeColumnImage( mpPageColumnTypeItem->GetValue() ); 513 } 514 } 515 break; 516 case SID_ATTR_PAGE_LRSPACE: 517 if ( eState >= SFX_ITEM_AVAILABLE && 518 pState && pState->ISA(SvxLongLRSpaceItem) ) 519 { 520 mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) ); 521 ChangeMarginImage(); 522 } 523 break; 524 525 case SID_ATTR_PAGE_ULSPACE: 526 if ( eState >= SFX_ITEM_AVAILABLE && 527 pState && pState->ISA(SvxLongULSpaceItem) ) 528 { 529 mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) ); 530 ChangeMarginImage(); 531 } 532 break; 533 534 case SID_ATTR_PAGE: 535 if ( eState >= SFX_ITEM_AVAILABLE && 536 pState && pState->ISA(SvxPageItem) ) 537 { 538 mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) ); 539 if ( mpPageItem->IsLandscape() ) 540 { 541 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgLandscape); 542 } 543 else 544 { 545 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgPortrait); 546 } 547 ChangeMarginImage(); 548 ChangeSizeImage(); 549 ChangeColumnImage( mpPageColumnTypeItem->GetValue() ); 550 } 551 break; 552 553 case SID_ATTR_PAGE_SIZE: 554 if ( mbInvalidateSIDAttrPageOnSIDAttrPageSizeNotify ) 555 { 556 mpBindings->Invalidate( SID_ATTR_PAGE, sal_True, sal_False ); 557 } 558 if ( eState >= SFX_ITEM_AVAILABLE && 559 pState && pState->ISA(SvxSizeItem) ) 560 { 561 mpPageSizeItem.reset( static_cast<SvxSizeItem*>(pState->Clone()) ); 562 ChangeSizeImage(); 563 } 564 break; 565 case SID_ATTR_METRIC: 566 MetricState( eState, pState ); 567 break; 568 } 569 } 570 571 572 void PagePropertyPanel::MetricState( SfxItemState eState, const SfxPoolItem* pState ) 573 { 574 meFUnit = FUNIT_NONE; 575 if ( pState && eState >= SFX_ITEM_DEFAULT ) 576 { 577 meFUnit = (FieldUnit)( (const SfxUInt16Item*)pState )->GetValue(); 578 } 579 else 580 { 581 SfxViewFrame* pFrame = SfxViewFrame::Current(); 582 SfxObjectShell* pSh = NULL; 583 if ( pFrame ) 584 pSh = pFrame->GetObjectShell(); 585 if ( pSh ) 586 { 587 SfxModule* pModule = pSh->GetModule(); 588 if ( pModule ) 589 { 590 const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC ); 591 if ( pItem ) 592 meFUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue(); 593 } 594 else 595 { 596 DBG_ERRORFILE( "<PagePropertyPanel::MetricState(..)>: no module found" ); 597 } 598 } 599 } 600 } 601 602 603 604 605 void PagePropertyPanel::ChangeMarginImage() 606 { 607 if ( mpPageLRMarginItem.get() == 0 || 608 mpPageULMarginItem.get() == 0 || 609 mpPageItem.get() == 0 ) 610 { 611 return; 612 } 613 614 const long cTolerance = 5; 615 616 if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NARROW_VALUE) <= cTolerance && 617 abs(mpPageLRMarginItem->GetRight() - SWPAGE_NARROW_VALUE) <= cTolerance && 618 abs(mpPageULMarginItem->GetUpper() - SWPAGE_NARROW_VALUE) <= cTolerance && 619 abs(mpPageULMarginItem->GetLower() - SWPAGE_NARROW_VALUE) <= cTolerance && 620 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 621 mpToolBoxMargin->SetItemImage( TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNarrow_L : mImgNarrow ); 622 623 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NORMAL_VALUE) <= cTolerance && 624 abs(mpPageLRMarginItem->GetRight() - SWPAGE_NORMAL_VALUE) <= cTolerance && 625 abs(mpPageULMarginItem->GetUpper() - SWPAGE_NORMAL_VALUE) <= cTolerance && 626 abs(mpPageULMarginItem->GetLower() - SWPAGE_NORMAL_VALUE) <= cTolerance && 627 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 628 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNormal_L : mImgNormal ); 629 630 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE2) <= cTolerance && 631 abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE2) <= cTolerance && 632 abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && 633 abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && 634 mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) 635 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgWide_L : mImgWide ); 636 637 else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE3) <= cTolerance && 638 abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE1) <= cTolerance && 639 abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && 640 abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && 641 mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR ) 642 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMirrored_L : mImgMirrored ); 643 644 else 645 mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMarginCustom_L : mImgMarginCustom ); 646 } 647 648 649 void PagePropertyPanel::ChangeSizeImage() 650 { 651 if ( mpPageSizeItem.get() == 0 || 652 mpPageItem.get() == 0 ) 653 { 654 return; 655 } 656 657 Size aTmpPaperSize = mpPageSizeItem->GetSize(); 658 if ( mpPageItem->IsLandscape() ) 659 { 660 Swap( aTmpPaperSize ); // Swap(..) defined in editeng/paperinf.hxx 661 } 662 663 mePaper = SvxPaperInfo::GetSvxPaper( aTmpPaperSize, static_cast<MapUnit>(meUnit), sal_True ); 664 665 sal_uInt16 nImageIdx = 0; 666 switch ( mePaper ) 667 { 668 case PAPER_A3: 669 nImageIdx = 1; 670 break; 671 case PAPER_A4: 672 nImageIdx = 2; 673 break; 674 case PAPER_A5: 675 nImageIdx = 3; 676 break; 677 case PAPER_B4_ISO: 678 nImageIdx = 4; 679 break; 680 case PAPER_B5_ISO: 681 nImageIdx = 5; 682 break; 683 case PAPER_ENV_C5: 684 nImageIdx = 6; 685 break; 686 case PAPER_LETTER: 687 nImageIdx = 7; 688 break; 689 case PAPER_LEGAL: 690 nImageIdx = 8; 691 break; 692 default: 693 nImageIdx = 0; 694 mePaper = PAPER_USER; 695 break; 696 } 697 698 if ( nImageIdx == 0 ) 699 { 700 mpToolBoxSize->SetItemImage( TBI_SIZE, 701 ( mpPageItem->IsLandscape() ? mImgSizeNone_L : mImgSizeNone ) ); 702 } 703 else 704 { 705 mpToolBoxSize->SetItemImage( TBI_SIZE, 706 ( mpPageItem->IsLandscape() ? maImgSize_L[nImageIdx-1] : maImgSize[nImageIdx-1] ) ); 707 } 708 } 709 710 711 void PagePropertyPanel::ChangeColumnImage( const sal_uInt16 nColumnType ) 712 { 713 if ( mpPageItem.get() == 0 ) 714 { 715 return; 716 } 717 718 if ( !mpPageItem->IsLandscape() ) 719 { 720 switch( nColumnType ) 721 { 722 case 1: 723 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1); 724 break; 725 case 2: 726 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2); 727 break; 728 case 3: 729 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3); 730 break; 731 case 4: 732 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft); 733 break; 734 case 5: 735 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight); 736 break; 737 default: 738 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone); 739 } 740 } 741 else 742 { 743 switch( nColumnType ) 744 { 745 case 1: 746 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1_L); 747 break; 748 case 2: 749 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2_L); 750 break; 751 case 3: 752 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3_L); 753 break; 754 case 4: 755 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft_L); 756 break; 757 case 5: 758 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight_L); 759 break; 760 default: 761 mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone_L); 762 } 763 } 764 } 765 766 } } // end of namespace ::sw::sidebar 767