LCOV - code coverage report
Current view: top level - sw/source/core/uibase/sidebar - PagePropertyPanel.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 331 0.0 %
Date: 2014-04-14 Functions: 0 37 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10