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