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