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