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

Generated by: LCOV version 1.11