LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/controller - slidelayoutcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 122 3.3 %
Date: 2012-12-27 Functions: 2 16 12.5 %
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             : 
      21             : #include <com/sun/star/frame/XFrame.hpp>
      22             : #include <com/sun/star/text/WritingMode.hpp>
      23             : #include <com/sun/star/frame/status/FontHeight.hpp>
      24             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/drawing/DrawViewMode.hpp>
      28             : 
      29             : #include <memory>
      30             : #include <boost/scoped_ptr.hpp>
      31             : 
      32             : #include <osl/mutex.hxx>
      33             : 
      34             : #include <vcl/svapp.hxx>
      35             : #include <vcl/toolbox.hxx>
      36             : 
      37             : #include <svl/languageoptions.hxx>
      38             : 
      39             : #include <svtools/ctrltool.hxx>
      40             : #include <svtools/ctrlbox.hxx>
      41             : #include <svtools/toolbarmenu.hxx>
      42             : #include <svtools/valueset.hxx>
      43             : 
      44             : #include <toolkit/helper/vclunohelper.hxx>
      45             : 
      46             : #include <sfx2/imagemgr.hxx>
      47             : 
      48             : #include "app.hrc"
      49             : #include "glob.hrc"
      50             : #include "strings.hrc"
      51             : #include "res_bmp.hrc"
      52             : #include "sdresid.hxx"
      53             : #include "pres.hxx"
      54             : #include "slidelayoutcontroller.hxx"
      55             : 
      56             : using rtl::OUString;
      57             : 
      58             : using namespace ::com::sun::star;
      59             : using namespace ::com::sun::star::uno;
      60             : using namespace ::com::sun::star::lang;
      61             : using namespace ::com::sun::star::text;
      62             : using namespace ::com::sun::star::frame;
      63             : using namespace ::com::sun::star::drawing;
      64             : using namespace ::com::sun::star::beans;
      65             : 
      66             : namespace sd
      67             : {
      68             : 
      69             : extern ::rtl::OUString ImplRetrieveLabelFromCommand( const Reference< XFrame >& xFrame, const OUString& aCmdURL );
      70             : 
      71             : // -----------------------------------------------------------------------
      72             : 
      73             : class LayoutToolbarMenu : public svtools::ToolbarMenu
      74             : {
      75             : public:
      76             :     LayoutToolbarMenu( SlideLayoutController& rController, const Reference< XFrame >& xFrame, ::Window* pParent, const bool bInsertPage );
      77             :     virtual ~LayoutToolbarMenu();
      78             : 
      79             : protected:
      80             :     DECL_LINK( SelectHdl, void * );
      81             : 
      82             : private:
      83             :     SlideLayoutController& mrController;
      84             :     Reference< XFrame > mxFrame;
      85             :     bool mbInsertPage;
      86             :     ValueSet* mpLayoutSet1;
      87             :     ValueSet* mpLayoutSet2;
      88             : };
      89             : 
      90             : // -----------------------------------------------------------------------
      91             : 
      92             : struct snewfoil_value_info
      93             : {
      94             :     sal_uInt16 mnBmpResId;
      95             :     sal_uInt16 mnStrResId;
      96             :     WritingMode meWritingMode;
      97             :     AutoLayout maAutoLayout;
      98             : };
      99             : 
     100             : static snewfoil_value_info notes[] =
     101             : {
     102             :     {BMP_FOILN_01, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB, AUTOLAYOUT_NOTES},
     103             :     {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
     104             : };
     105             : 
     106             : static snewfoil_value_info handout[] =
     107             : {
     108             :     {BMP_FOILH_01, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB, AUTOLAYOUT_HANDOUT1},
     109             :     {BMP_FOILH_02, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB, AUTOLAYOUT_HANDOUT2},
     110             :     {BMP_FOILH_03, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB, AUTOLAYOUT_HANDOUT3},
     111             :     {BMP_FOILH_04, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB, AUTOLAYOUT_HANDOUT4},
     112             :     {BMP_FOILH_06, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB, AUTOLAYOUT_HANDOUT6},
     113             :     {BMP_FOILH_09, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB, AUTOLAYOUT_HANDOUT9},
     114             :     {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
     115             : };
     116             : 
     117             : static snewfoil_value_info standard[] =
     118             : {
     119             :     {BMP_LAYOUT_EMPTY,    STR_AUTOLAYOUT_NONE,                 WritingMode_LR_TB, AUTOLAYOUT_NONE         },
     120             :     {BMP_LAYOUT_HEAD03,   STR_AUTOLAYOUT_TITLE,                WritingMode_LR_TB, AUTOLAYOUT_TITLE        },
     121             :     {BMP_LAYOUT_HEAD02,   STR_AUTOLAYOUT_CONTENT,              WritingMode_LR_TB, AUTOLAYOUT_ENUM         },
     122             :     {BMP_LAYOUT_HEAD02A,  STR_AUTOLAYOUT_2CONTENT,             WritingMode_LR_TB, AUTOLAYOUT_2TEXT        },
     123             :     {BMP_LAYOUT_HEAD01,   STR_AUTOLAYOUT_ONLY_TITLE,           WritingMode_LR_TB, AUTOLAYOUT_ONLY_TITLE   },
     124             :     {BMP_LAYOUT_TEXTONLY, STR_AUTOLAYOUT_ONLY_TEXT,            WritingMode_LR_TB, AUTOLAYOUT_ONLY_TEXT    },
     125             :     {BMP_LAYOUT_HEAD03B,  STR_AUTOLAYOUT_2CONTENT_CONTENT,     WritingMode_LR_TB, AUTOLAYOUT_2OBJTEXT     },
     126             :     {BMP_LAYOUT_HEAD03C,  STR_AUTOLAYOUT_CONTENT_2CONTENT,     WritingMode_LR_TB, AUTOLAYOUT_TEXT2OBJ     },
     127             :     {BMP_LAYOUT_HEAD03A,  STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT,WritingMode_LR_TB, AUTOLAYOUT_2OBJOVERTEXT },
     128             :     {BMP_LAYOUT_HEAD02B,  STR_AUTOLAYOUT_CONTENT_OVER_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_OBJOVERTEXT  },
     129             :     {BMP_LAYOUT_HEAD04,   STR_AUTOLAYOUT_4CONTENT,             WritingMode_LR_TB, AUTOLAYOUT_4OBJ         },
     130             :     {BMP_LAYOUT_HEAD06,   STR_AUTOLAYOUT_6CONTENT,             WritingMode_LR_TB, AUTOLAYOUT_6CLIPART     },
     131             :     {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
     132             : };
     133             : 
     134             : static snewfoil_value_info v_standard[] =
     135             : {
     136             :     // vertical
     137             :     {BMP_LAYOUT_VERTICAL02, STR_AL_VERT_TITLE_TEXT_CHART,      WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART       },
     138             :     {BMP_LAYOUT_VERTICAL01, STR_AL_VERT_TITLE_VERT_OUTLINE,    WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE },
     139             :     {BMP_LAYOUT_HEAD02,     STR_AL_TITLE_VERT_OUTLINE,         WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE          },
     140             :     {BMP_LAYOUT_HEAD02A,    STR_AL_TITLE_VERT_OUTLINE_CLIPART, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART  },
     141             :     {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
     142             : };
     143             : 
     144             : // -----------------------------------------------------------------------
     145             : 
     146           0 : static void fillLayoutValueSet( ValueSet* pValue, snewfoil_value_info* pInfo )
     147             : {
     148           0 :     Size aLayoutItemSize;
     149           0 :     for( ; pInfo->mnBmpResId; pInfo++ )
     150             :     {
     151           0 :         String   aText( SdResId( pInfo->mnStrResId ) );
     152           0 :         BitmapEx aBmp(  SdResId( pInfo->mnBmpResId ) );
     153             : 
     154           0 :         pValue->InsertItem( static_cast<sal_uInt16>(pInfo->maAutoLayout)+1, aBmp, aText );
     155             : 
     156           0 :         aLayoutItemSize.Width()  = std::max( aLayoutItemSize.Width(),  aBmp.GetSizePixel().Width()  );
     157           0 :         aLayoutItemSize.Height() = std::max( aLayoutItemSize.Height(), aBmp.GetSizePixel().Height() );
     158           0 :     }
     159             : 
     160           0 :     aLayoutItemSize = pValue->CalcItemSizePixel( aLayoutItemSize );
     161           0 :     pValue->SetSizePixel( pValue->CalcWindowSizePixel( aLayoutItemSize ) );
     162           0 : }
     163             : 
     164             : // -----------------------------------------------------------------------
     165             : 
     166           0 : LayoutToolbarMenu::LayoutToolbarMenu( SlideLayoutController& rController, const Reference< XFrame >& xFrame, ::Window* pParent, const bool bInsertPage )
     167             : : svtools::ToolbarMenu(xFrame, pParent, WB_CLIPCHILDREN )
     168             : , mrController( rController )
     169             : , mxFrame(xFrame)
     170             : , mbInsertPage( bInsertPage )
     171             : , mpLayoutSet1( 0 )
     172           0 : , mpLayoutSet2( 0 )
     173             : {
     174           0 :     DrawViewMode eMode = DrawViewMode_DRAW;
     175             : 
     176             :     // find out which view is running
     177           0 :     if( xFrame.is() ) try
     178             :     {
     179           0 :         Reference< XPropertySet > xControllerSet( xFrame->getController(), UNO_QUERY_THROW );
     180           0 :         xControllerSet->getPropertyValue( "DrawViewMode" ) >>= eMode;
     181             :     }
     182           0 :     catch( Exception& e )
     183             :     {
     184             :         (void)e;
     185             :         OSL_ASSERT(false);
     186             :     }
     187             : 
     188           0 :     const sal_Int32 LAYOUT_BORDER_PIX = 7;
     189             : 
     190           0 :     String aTitle1( SdResId( STR_GLUE_ESCDIR_HORZ ) );
     191           0 :     String aTitle2( SdResId( STR_GLUE_ESCDIR_VERT ) );
     192             : 
     193           0 :     SvtLanguageOptions aLanguageOptions;
     194           0 :     const bool bVerticalEnabled = aLanguageOptions.IsVerticalTextEnabled();
     195             : 
     196           0 :     SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectHdl ) );
     197             : 
     198           0 :     mpLayoutSet1 = createEmptyValueSetControl();
     199           0 :     mpLayoutSet1->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectHdl ) );
     200             : 
     201           0 :     snewfoil_value_info* pInfo = 0;
     202           0 :     sal_Int16 nColCount = 4;
     203           0 :     switch( eMode )
     204             :     {
     205           0 :     case DrawViewMode_DRAW: pInfo = &standard[0]; break;
     206           0 :     case DrawViewMode_HANDOUT: pInfo = &handout[0]; nColCount = 2; break;
     207           0 :     case DrawViewMode_NOTES: pInfo = &notes[0]; nColCount = 1; break;
     208           0 :     default: break;
     209             :     }
     210             : 
     211           0 :     mpLayoutSet1->SetColCount( nColCount );
     212             : 
     213           0 :     fillLayoutValueSet( mpLayoutSet1, pInfo );
     214             : 
     215           0 :     Size aSize( mpLayoutSet1->GetOutputSizePixel() );
     216           0 :     aSize.Width() += (mpLayoutSet1->GetColCount() + 1) * LAYOUT_BORDER_PIX;
     217           0 :     aSize.Height() += (mpLayoutSet1->GetLineCount() +1) * LAYOUT_BORDER_PIX;
     218           0 :     mpLayoutSet1->SetOutputSizePixel( aSize );
     219             : 
     220           0 :     if( bVerticalEnabled && (eMode == DrawViewMode_DRAW) )
     221           0 :         appendEntry( -1, aTitle1 );
     222           0 :     appendEntry( 0, mpLayoutSet1 );
     223             : 
     224           0 :     if( bVerticalEnabled && (eMode == DrawViewMode_DRAW) )
     225             :     {
     226           0 :         mpLayoutSet2 = new ValueSet( this, WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT );
     227             : 
     228           0 :         mpLayoutSet2->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectHdl ) );
     229           0 :         mpLayoutSet2->SetColCount( 4 );
     230           0 :         mpLayoutSet2->EnableFullItemMode( sal_False );
     231           0 :         mpLayoutSet2->SetColor( GetControlBackground() );
     232             : 
     233           0 :         fillLayoutValueSet( mpLayoutSet2, &v_standard[0] );
     234             : 
     235           0 :         aSize = mpLayoutSet2->GetOutputSizePixel();
     236           0 :         aSize.Width() += (mpLayoutSet2->GetColCount() + 1) * LAYOUT_BORDER_PIX;
     237           0 :         aSize.Height() += (mpLayoutSet2->GetLineCount() + 1) * LAYOUT_BORDER_PIX;
     238           0 :         mpLayoutSet2->SetOutputSizePixel( aSize );
     239             : 
     240           0 :         appendEntry( -1, aTitle2 );
     241           0 :         appendEntry( 1, mpLayoutSet2 );
     242             :     }
     243             : 
     244           0 :     if( eMode == DrawViewMode_DRAW )
     245             :     {
     246           0 :         appendSeparator();
     247             : 
     248           0 :         OUString sSlotStr;
     249           0 :         Image aSlotImage;
     250           0 :         if( mxFrame.is() )
     251             :         {
     252           0 :             if( bInsertPage )
     253           0 :                 sSlotStr = ".uno:DuplicatePage";
     254             :             else
     255           0 :                 sSlotStr = ".uno:Undo";
     256           0 :             aSlotImage = ::GetImage( mxFrame, sSlotStr, sal_False );
     257             : 
     258           0 :             String sSlotTitle;
     259           0 :             if( bInsertPage )
     260           0 :                 sSlotTitle = ImplRetrieveLabelFromCommand( mxFrame, sSlotStr );
     261             :             else
     262           0 :                 sSlotTitle = String( SdResId( STR_RESET_LAYOUT ) );
     263           0 :             appendEntry( 2, sSlotTitle, aSlotImage);
     264           0 :         }
     265             :     }
     266             : 
     267           0 :     SetOutputSizePixel( getMenuSize() );
     268           0 : }
     269             : 
     270             : // -----------------------------------------------------------------------
     271             : 
     272           0 : LayoutToolbarMenu::~LayoutToolbarMenu()
     273             : {
     274           0 : }
     275             : 
     276             : // -----------------------------------------------------------------------
     277             : 
     278           0 : IMPL_LINK( LayoutToolbarMenu, SelectHdl, void *, pControl )
     279             : {
     280           0 :     if ( IsInPopupMode() )
     281           0 :         EndPopupMode();
     282             : 
     283           0 :     Sequence< PropertyValue > aArgs;
     284             : 
     285           0 :     AutoLayout eLayout = AUTOLAYOUT__END;
     286             : 
     287           0 :     OUString sCommandURL( mrController.getCommandURL() );
     288             : 
     289           0 :     if( pControl == mpLayoutSet1 )
     290             :     {
     291           0 :         eLayout = static_cast< AutoLayout >(mpLayoutSet1->GetSelectItemId()-1);
     292             :     }
     293           0 :     else if( pControl == mpLayoutSet2 )
     294             :     {
     295           0 :         eLayout = static_cast< AutoLayout >(mpLayoutSet2->GetSelectItemId()-1);
     296             :     }
     297             : 
     298           0 :     if( eLayout != AUTOLAYOUT__END )
     299             :     {
     300           0 :         aArgs = Sequence< PropertyValue >(1);
     301           0 :         aArgs[0].Name = "WhatLayout";
     302           0 :         aArgs[0].Value <<= (sal_Int32)eLayout;
     303             :     }
     304           0 :     else if( mbInsertPage )
     305             :     {
     306           0 :         sCommandURL = ".uno:DuplicatePage";
     307             :     }
     308             : 
     309           0 :     mrController.dispatchCommand( sCommandURL, aArgs );
     310             : 
     311           0 :     return 0;
     312             : }
     313             : 
     314             : // ====================================================================
     315             : 
     316           2 : OUString SlideLayoutController_getImplementationName()
     317             : {
     318           2 :     return OUString( "com.sun.star.comp.sd.SlideLayoutController" );
     319             : }
     320             : 
     321             : // --------------------------------------------------------------------
     322             : 
     323           0 : Sequence< OUString >  SlideLayoutController_getSupportedServiceNames() throw( RuntimeException )
     324             : {
     325           0 :     Sequence< OUString > aSNS( 1 );
     326           0 :     aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
     327           0 :     return aSNS;
     328             : }
     329             : 
     330             : // --------------------------------------------------------------------
     331             : 
     332           0 : Reference< XInterface > SAL_CALL SlideLayoutController_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
     333             : {
     334           0 :     return *new SlideLayoutController( rSMgr, ".uno:AssignLayout", false );
     335             : }
     336             : 
     337             : // --------------------------------------------------------------------
     338             : 
     339           2 : OUString InsertSlideController_getImplementationName()
     340             : {
     341           2 :     return OUString( "com.sun.star.comp.sd.InsertSlideController" );
     342             : }
     343             : 
     344             : // --------------------------------------------------------------------
     345             : 
     346           0 : Sequence< OUString >  InsertSlideController_getSupportedServiceNames() throw( RuntimeException )
     347             : {
     348           0 :     Sequence< OUString > aSNS( 1 );
     349           0 :     aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
     350           0 :     return aSNS;
     351             : }
     352             : 
     353             : // --------------------------------------------------------------------
     354             : 
     355           0 : Reference< XInterface > SAL_CALL InsertSlideController_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
     356             : {
     357           0 :     return *new SlideLayoutController( rSMgr, ".uno:InsertPage" , true );
     358             : }
     359             : 
     360             : //========================================================================
     361             : // class SlideLayoutController
     362             : //========================================================================
     363             : 
     364           0 : SlideLayoutController::SlideLayoutController( const Reference< lang::XMultiServiceFactory >& rServiceManager, const rtl::OUString& sCommandURL, bool bInsertPage )
     365             : : svt::PopupWindowController( rServiceManager, Reference< frame::XFrame >(), sCommandURL )
     366           0 : , mbInsertPage( bInsertPage )
     367             : {
     368           0 : }
     369             : 
     370             : // --------------------------------------------------------------------
     371             : 
     372           0 : ::Window* SlideLayoutController::createPopupWindow( ::Window* pParent )
     373             : {
     374           0 :     return new sd::LayoutToolbarMenu( *this, m_xFrame, pParent, mbInsertPage );
     375             : }
     376             : 
     377             : // --------------------------------------------------------------------
     378             : // XServiceInfo
     379             : // --------------------------------------------------------------------
     380             : 
     381           0 : OUString SAL_CALL SlideLayoutController::getImplementationName() throw( RuntimeException )
     382             : {
     383           0 :     if( mbInsertPage )
     384           0 :         return InsertSlideController_getImplementationName();
     385             :     else
     386           0 :         return SlideLayoutController_getImplementationName();
     387             : }
     388             : 
     389             : // --------------------------------------------------------------------
     390             : 
     391           0 : Sequence< OUString > SAL_CALL SlideLayoutController::getSupportedServiceNames(  ) throw( RuntimeException )
     392             : {
     393           0 :     if( mbInsertPage )
     394           0 :         return InsertSlideController_getSupportedServiceNames();
     395             :     else
     396           0 :         return SlideLayoutController_getSupportedServiceNames();
     397             : }
     398             : 
     399             : }
     400             : 
     401             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10