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