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     mpOrientationPopup.reset( 0 );
362 }
363 
364 
365 
366 
367 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageMarginControl( ::svx::sidebar::PopupContainer* pParent )
368 {
369     return new PageMarginControl(
370         pParent,
371         *this,
372         *mpPageLRMarginItem.get(),
373         *mpPageULMarginItem.get(),
374         mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR,
375         mpPageSizeItem->GetSize(),
376         mpPageItem->IsLandscape(),
377         meFUnit,
378         meUnit );
379 }
380 
381 
382 void PagePropertyPanel::ExecuteMarginLRChange(
383     const long nPageLeftMargin,
384     const long nPageRightMargin )
385 {
386     mpPageLRMarginItem->SetLeft( nPageLeftMargin );
387     mpPageLRMarginItem->SetRight( nPageRightMargin );
388     GetBindings()->GetDispatcher()->Execute( SID_ATTR_LONG_LRSPACE, SFX_CALLMODE_RECORD, mpPageLRMarginItem.get(),  0L );
389 }
390 
391 void PagePropertyPanel::ExecuteMarginULChange(
392     const long nPageTopMargin,
393     const long nPageBottomMargin )
394 {
395     mpPageULMarginItem->SetUpper( nPageTopMargin );
396     mpPageULMarginItem->SetLower( nPageBottomMargin );
397     GetBindings()->GetDispatcher()->Execute( SID_ATTR_LONG_ULSPACE, SFX_CALLMODE_RECORD, mpPageULMarginItem.get(),  0L );
398 }
399 
400 
401 void PagePropertyPanel::ExecutePageLayoutChange( const bool bMirrored )
402 {
403     mpPageItem->SetPageUsage( bMirrored ? SVX_PAGE_MIRROR : SVX_PAGE_ALL );
404     GetBindings()->GetDispatcher()->Execute( SID_ATTR_PAGE, SFX_CALLMODE_RECORD, mpPageItem.get(),  0L );
405 }
406 
407 
408 IMPL_LINK( PagePropertyPanel, ClickMarginHdl, ToolBox*, pToolBox )
409 {
410     mpMarginPopup.reset(
411         new ::svx::sidebar::Popup(
412             this,
413             ::boost::bind(&PagePropertyPanel::CreatePageMarginControl, this, _1),
414             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page margins")) ) );
415     mpMarginPopup->Show( *pToolBox );
416 
417     return 0L;
418 }
419 
420 
421 void PagePropertyPanel::ClosePageMarginPopup()
422 {
423     mpMarginPopup->Hide();
424     mpMarginPopup.reset( 0 );
425 }
426 
427 
428 
429 
430 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageSizeControl( ::svx::sidebar::PopupContainer* pParent )
431 {
432     return new PageSizeControl(
433         pParent,
434         *this,
435         mePaper,
436         mpPageItem->IsLandscape(),
437         meFUnit );
438 }
439 
440 
441 void PagePropertyPanel::ExecuteSizeChange( const Paper ePaper )
442 {
443     Size aPageSize = SvxPaperInfo::GetPaperSize( ePaper, (MapUnit)(meUnit) );
444     if ( mpPageItem->IsLandscape() )
445     {
446         Swap( aPageSize );
447     }
448     mpPageSizeItem->SetSize( aPageSize );
449 
450     mpBindings->GetDispatcher()->Execute(SID_ATTR_PAGE_SIZE, SFX_CALLMODE_RECORD, mpPageSizeItem.get(),  0L );
451 }
452 
453 
454 IMPL_LINK( PagePropertyPanel, ClickSizeHdl, ToolBox*, pToolBox )
455 {
456     mpSizePopup.reset(
457         new ::svx::sidebar::Popup(
458             this,
459             ::boost::bind(&PagePropertyPanel::CreatePageSizeControl, this, _1),
460             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page size")) ) );
461     mpSizePopup->Show( *pToolBox );
462 
463     return 0L;
464 }
465 
466 
467 void PagePropertyPanel::ClosePageSizePopup()
468 {
469     mpSizePopup->Hide();
470     mpSizePopup.reset( 0 );
471 }
472 
473 
474 
475 
476 ::svx::sidebar::PopupControl* PagePropertyPanel::CreatePageColumnControl( ::svx::sidebar::PopupContainer* pParent )
477 {
478     return new PageColumnControl(
479         pParent,
480         *this,
481         mpPageColumnTypeItem->GetValue(),
482         mpPageItem->IsLandscape() );
483 }
484 
485 
486 void PagePropertyPanel::ExecuteColumnChange( const sal_uInt16 nColumnType )
487 {
488     mpPageColumnTypeItem->SetValue( nColumnType );
489     mpBindings->GetDispatcher()->Execute(SID_ATTR_SWPAGE_COLUMN, SFX_CALLMODE_RECORD, mpPageColumnTypeItem.get(),  0L );
490 }
491 
492 
493 IMPL_LINK( PagePropertyPanel, ClickColumnHdl, ToolBox*, pToolBox )
494 {
495     mpColumnPopup.reset(
496         new ::svx::sidebar::Popup(
497             this,
498             ::boost::bind(&PagePropertyPanel::CreatePageColumnControl, this, _1),
499             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Page columns")) ) );
500     mpColumnPopup->Show( *pToolBox );
501 
502     return 0L;
503 }
504 
505 
506 void PagePropertyPanel::ClosePageColumnPopup()
507 {
508     mpColumnPopup->Hide();
509     mpColumnPopup.reset( 0 );
510 }
511 
512 
513 
514 
515 void PagePropertyPanel::NotifyItemUpdate(
516     const sal_uInt16 nSId,
517     const SfxItemState eState,
518     const SfxPoolItem* pState)
519 {
520     switch( nSId )
521     {
522     case SID_ATTR_SWPAGE_COLUMN:
523         {
524             if ( eState >= SFX_ITEM_AVAILABLE &&
525                  pState && pState->ISA(SfxInt16Item) )
526             {
527                 mpPageColumnTypeItem.reset( static_cast<SfxInt16Item*>(pState->Clone()) );
528                 ChangeColumnImage( mpPageColumnTypeItem->GetValue() );
529             }
530         }
531         break;
532     case SID_ATTR_LONG_LRSPACE:
533         if ( eState >= SFX_ITEM_AVAILABLE &&
534              pState && pState->ISA(SvxLongLRSpaceItem) )
535         {
536             mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
537             ChangeMarginImage();
538         }
539         break;
540 
541     case SID_ATTR_LONG_ULSPACE:
542         if ( eState >= SFX_ITEM_AVAILABLE &&
543              pState && pState->ISA(SvxLongULSpaceItem) )
544         {
545             mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
546             ChangeMarginImage();
547         }
548         break;
549 
550     case SID_ATTR_PAGE:
551         if ( eState >= SFX_ITEM_AVAILABLE &&
552              pState && pState->ISA(SvxPageItem) )
553         {
554             mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) );
555             if ( mpPageItem->IsLandscape() )
556             {
557                 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgLandscape);
558             }
559             else
560             {
561                 mpToolBoxOrientation->SetItemImage(TBI_ORIENTATION, mImgPortrait);
562             }
563             ChangeMarginImage();
564             ChangeSizeImage();
565             ChangeColumnImage( mpPageColumnTypeItem->GetValue() );
566         }
567         break;
568 
569     case SID_ATTR_PAGE_SIZE:
570         mpBindings->Invalidate( SID_ATTR_PAGE, sal_True, sal_False );
571         if ( eState >= SFX_ITEM_AVAILABLE &&
572              pState && pState->ISA(SvxSizeItem) )
573         {
574             mpPageSizeItem.reset( static_cast<SvxSizeItem*>(pState->Clone()) );
575             ChangeSizeImage();
576         }
577         break;
578     case SID_ATTR_METRIC:
579         MetricState( eState, pState );
580         break;
581     }
582 }
583 
584 
585 void PagePropertyPanel::MetricState( SfxItemState eState, const SfxPoolItem* pState )
586 {
587     meFUnit = FUNIT_NONE;
588     if ( pState && eState >= SFX_ITEM_DEFAULT )
589     {
590         meFUnit = (FieldUnit)( (const SfxUInt16Item*)pState )->GetValue();
591     }
592     else
593     {
594         SfxViewFrame* pFrame = SfxViewFrame::Current();
595         SfxObjectShell* pSh = NULL;
596         if ( pFrame )
597             pSh = pFrame->GetObjectShell();
598         if ( pSh )
599         {
600             SfxModule* pModule = pSh->GetModule();
601             if ( pModule )
602             {
603                 const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
604                 if ( pItem )
605                     meFUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
606             }
607             else
608             {
609                 DBG_ERRORFILE( "<PagePropertyPanel::MetricState(..)>: no module found" );
610             }
611         }
612     }
613 }
614 
615 
616 
617 
618 void PagePropertyPanel::ChangeMarginImage()
619 {
620     if ( mpPageLRMarginItem.get() == 0 ||
621          mpPageULMarginItem.get() == 0 ||
622          mpPageItem.get() == 0 )
623     {
624         return;
625     }
626 
627     const long cTolerance = 5;
628 
629     if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NARROW_VALUE) <= cTolerance &&
630         abs(mpPageLRMarginItem->GetRight() - SWPAGE_NARROW_VALUE) <= cTolerance &&
631         abs(mpPageULMarginItem->GetUpper() - SWPAGE_NARROW_VALUE) <= cTolerance &&
632         abs(mpPageULMarginItem->GetLower() - SWPAGE_NARROW_VALUE) <= cTolerance &&
633         mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR )
634         mpToolBoxMargin->SetItemImage( TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNarrow_L : mImgNarrow );
635 
636     else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NORMAL_VALUE) <= cTolerance &&
637         abs(mpPageLRMarginItem->GetRight() - SWPAGE_NORMAL_VALUE) <= cTolerance &&
638         abs(mpPageULMarginItem->GetUpper() - SWPAGE_NORMAL_VALUE) <= cTolerance &&
639         abs(mpPageULMarginItem->GetLower() - SWPAGE_NORMAL_VALUE) <= cTolerance &&
640         mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR )
641         mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgNormal_L : mImgNormal );
642 
643     else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE2) <= cTolerance &&
644         abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE2) <= cTolerance &&
645         abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance &&
646         abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance &&
647         mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR )
648         mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgWide_L : mImgWide );
649 
650     else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE3) <= cTolerance &&
651         abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE1) <= cTolerance &&
652         abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance &&
653         abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance &&
654         mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR )
655         mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMirrored_L : mImgMirrored );
656 
657     else
658         mpToolBoxMargin->SetItemImage(TBI_MARGIN, mpPageItem->IsLandscape() ? mImgMarginCustom_L : mImgMarginCustom );
659 }
660 
661 
662 void PagePropertyPanel::ChangeSizeImage()
663 {
664     if ( mpPageSizeItem.get() == 0 ||
665          mpPageItem.get() == 0 )
666     {
667         return;
668     }
669 
670     Size aTmpPaperSize = mpPageSizeItem->GetSize();
671     if ( mpPageItem->IsLandscape() )
672     {
673         Swap( aTmpPaperSize ); // Swap(..) defined in editeng/paperinf.hxx
674     }
675 
676     mePaper = SvxPaperInfo::GetSvxPaper( aTmpPaperSize, static_cast<MapUnit>(meUnit), sal_True );
677 
678     sal_uInt16 nImageIdx = 0;
679     switch ( mePaper )
680     {
681     case PAPER_A3:
682         nImageIdx = 1;
683         break;
684     case PAPER_A4:
685         nImageIdx = 2;
686         break;
687     case PAPER_A5:
688         nImageIdx = 3;
689         break;
690     case PAPER_B4_ISO:
691         nImageIdx = 4;
692         break;
693     case PAPER_B5_ISO:
694         nImageIdx = 5;
695         break;
696     case PAPER_ENV_C5:
697         nImageIdx = 6;
698         break;
699     case PAPER_LETTER:
700         nImageIdx = 7;
701         break;
702     case PAPER_LEGAL:
703         nImageIdx = 8;
704         break;
705     default:
706         nImageIdx = 0;
707         mePaper = PAPER_USER;
708         break;
709     }
710 
711     if ( nImageIdx == 0 )
712     {
713         mpToolBoxSize->SetItemImage( TBI_SIZE,
714                                      ( mpPageItem->IsLandscape() ? mImgSizeNone_L : mImgSizeNone  ) );
715     }
716     else
717     {
718         mpToolBoxSize->SetItemImage( TBI_SIZE,
719                                      ( mpPageItem->IsLandscape() ? maImgSize_L[nImageIdx-1] : maImgSize[nImageIdx-1] ) );
720     }
721 }
722 
723 
724 void PagePropertyPanel::ChangeColumnImage( const sal_uInt16 nColumnType )
725 {
726     if ( mpPageItem.get() == 0 )
727     {
728         return;
729     }
730 
731     if ( !mpPageItem->IsLandscape() )
732     {
733         switch( nColumnType )
734         {
735         case 1:
736             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1);
737             break;
738         case 2:
739             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2);
740             break;
741         case 3:
742             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3);
743             break;
744         case 4:
745             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft);
746             break;
747         case 5:
748             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight);
749             break;
750         default:
751             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone);
752         }
753     }
754     else
755     {
756         switch( nColumnType )
757         {
758         case 1:
759             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn1_L);
760             break;
761         case 2:
762             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn2_L);
763             break;
764         case 3:
765             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumn3_L);
766             break;
767         case 4:
768             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgLeft_L);
769             break;
770         case 5:
771             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgRight_L);
772             break;
773         default:
774             mpToolBoxColumn->SetItemImage(TBI_COLUMN, mImgColumnNone_L);
775         }
776     }
777 }
778 
779 } } // end of namespace ::sw::sidebar
780