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