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