fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / controller / slidelayoutcontroller.cxx
bloba2e83d38726122c20be3a807282f5ff1620a8db8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
29 #include <memory>
30 #include <boost/scoped_ptr.hpp>
32 #include <osl/mutex.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/toolbox.hxx>
37 #include <svl/languageoptions.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <svtools/ctrlbox.hxx>
41 #include <svtools/toolbarmenu.hxx>
42 #include <svtools/valueset.hxx>
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <comphelper/processfactory.hxx>
47 #include <sfx2/imagemgr.hxx>
49 #include "app.hrc"
50 #include "glob.hrc"
51 #include "strings.hrc"
52 #include "res_bmp.hrc"
53 #include "sdresid.hxx"
54 #include "pres.hxx"
55 #include "slidelayoutcontroller.hxx"
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;
66 namespace sd
69 extern OUString ImplRetrieveLabelFromCommand( const Reference< XFrame >& xFrame, const OUString& aCmdURL );
71 // -----------------------------------------------------------------------
73 class LayoutToolbarMenu : public svtools::ToolbarMenu
75 public:
76 LayoutToolbarMenu( SlideLayoutController& rController, const Reference< XFrame >& xFrame, ::Window* pParent, const bool bInsertPage );
77 virtual ~LayoutToolbarMenu();
79 protected:
80 DECL_LINK( SelectHdl, void * );
82 private:
83 SlideLayoutController& mrController;
84 Reference< XFrame > mxFrame;
85 bool mbInsertPage;
86 ValueSet* mpLayoutSet1;
87 ValueSet* mpLayoutSet2;
90 // -----------------------------------------------------------------------
92 struct snewfoil_value_info
94 sal_uInt16 mnBmpResId;
95 sal_uInt16 mnStrResId;
96 WritingMode meWritingMode;
97 AutoLayout maAutoLayout;
100 static snewfoil_value_info notes[] =
102 {BMP_FOILN_01, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB, AUTOLAYOUT_NOTES},
103 {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
106 static snewfoil_value_info handout[] =
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},
117 static snewfoil_value_info standard[] =
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}
134 static snewfoil_value_info v_standard[] =
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}
144 // -----------------------------------------------------------------------
146 static void fillLayoutValueSet( ValueSet* pValue, snewfoil_value_info* pInfo )
148 Size aLayoutItemSize;
149 for( ; pInfo->mnBmpResId; pInfo++ )
151 String aText( SdResId( pInfo->mnStrResId ) );
152 BitmapEx aBmp( SdResId( pInfo->mnBmpResId ) );
154 pValue->InsertItem( static_cast<sal_uInt16>(pInfo->maAutoLayout)+1, aBmp, aText );
156 aLayoutItemSize.Width() = std::max( aLayoutItemSize.Width(), aBmp.GetSizePixel().Width() );
157 aLayoutItemSize.Height() = std::max( aLayoutItemSize.Height(), aBmp.GetSizePixel().Height() );
160 aLayoutItemSize = pValue->CalcItemSizePixel( aLayoutItemSize );
161 pValue->SetSizePixel( pValue->CalcWindowSizePixel( aLayoutItemSize ) );
164 // -----------------------------------------------------------------------
166 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 , mpLayoutSet2( 0 )
174 DrawViewMode eMode = DrawViewMode_DRAW;
176 // find out which view is running
177 if( xFrame.is() ) try
179 Reference< XPropertySet > xControllerSet( xFrame->getController(), UNO_QUERY_THROW );
180 xControllerSet->getPropertyValue( "DrawViewMode" ) >>= eMode;
182 catch( Exception& e )
184 (void)e;
185 OSL_ASSERT(false);
188 const sal_Int32 LAYOUT_BORDER_PIX = 7;
190 String aTitle1( SdResId( STR_GLUE_ESCDIR_HORZ ) );
191 String aTitle2( SdResId( STR_GLUE_ESCDIR_VERT ) );
193 SvtLanguageOptions aLanguageOptions;
194 const bool bVerticalEnabled = aLanguageOptions.IsVerticalTextEnabled();
196 SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectHdl ) );
198 mpLayoutSet1 = createEmptyValueSetControl();
199 mpLayoutSet1->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectHdl ) );
201 snewfoil_value_info* pInfo = 0;
202 sal_Int16 nColCount = 4;
203 switch( eMode )
205 case DrawViewMode_DRAW: pInfo = &standard[0]; break;
206 case DrawViewMode_HANDOUT: pInfo = &handout[0]; nColCount = 2; break;
207 case DrawViewMode_NOTES: pInfo = &notes[0]; nColCount = 1; break;
208 default: assert(false); // can't happen, will crash later otherwise
211 mpLayoutSet1->SetColCount( nColCount );
213 fillLayoutValueSet( mpLayoutSet1, pInfo );
215 Size aSize( mpLayoutSet1->GetOutputSizePixel() );
216 aSize.Width() += (mpLayoutSet1->GetColCount() + 1) * LAYOUT_BORDER_PIX;
217 aSize.Height() += (mpLayoutSet1->GetLineCount() +1) * LAYOUT_BORDER_PIX;
218 mpLayoutSet1->SetOutputSizePixel( aSize );
220 if( bVerticalEnabled && (eMode == DrawViewMode_DRAW) )
221 appendEntry( -1, aTitle1 );
222 appendEntry( 0, mpLayoutSet1 );
224 if( bVerticalEnabled && (eMode == DrawViewMode_DRAW) )
226 mpLayoutSet2 = new ValueSet( this, WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT );
228 mpLayoutSet2->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectHdl ) );
229 mpLayoutSet2->SetColCount( 4 );
230 mpLayoutSet2->EnableFullItemMode( sal_False );
231 mpLayoutSet2->SetColor( GetControlBackground() );
233 fillLayoutValueSet( mpLayoutSet2, &v_standard[0] );
235 aSize = mpLayoutSet2->GetOutputSizePixel();
236 aSize.Width() += (mpLayoutSet2->GetColCount() + 1) * LAYOUT_BORDER_PIX;
237 aSize.Height() += (mpLayoutSet2->GetLineCount() + 1) * LAYOUT_BORDER_PIX;
238 mpLayoutSet2->SetOutputSizePixel( aSize );
240 appendEntry( -1, aTitle2 );
241 appendEntry( 1, mpLayoutSet2 );
244 if( eMode == DrawViewMode_DRAW )
246 appendSeparator();
248 OUString sSlotStr;
249 Image aSlotImage;
250 if( mxFrame.is() )
252 if( bInsertPage )
253 sSlotStr = ".uno:DuplicatePage";
254 else
255 sSlotStr = ".uno:Undo";
256 aSlotImage = ::GetImage( mxFrame, sSlotStr, sal_False );
258 String sSlotTitle;
259 if( bInsertPage )
260 sSlotTitle = ImplRetrieveLabelFromCommand( mxFrame, sSlotStr );
261 else
262 sSlotTitle = String( SdResId( STR_RESET_LAYOUT ) );
263 appendEntry( 2, sSlotTitle, aSlotImage);
267 SetOutputSizePixel( getMenuSize() );
270 // -----------------------------------------------------------------------
272 LayoutToolbarMenu::~LayoutToolbarMenu()
276 // -----------------------------------------------------------------------
278 IMPL_LINK( LayoutToolbarMenu, SelectHdl, void *, pControl )
280 if ( IsInPopupMode() )
281 EndPopupMode();
283 Sequence< PropertyValue > aArgs;
285 AutoLayout eLayout = AUTOLAYOUT__END;
287 OUString sCommandURL( mrController.getCommandURL() );
289 if( pControl == mpLayoutSet1 )
291 eLayout = static_cast< AutoLayout >(mpLayoutSet1->GetSelectItemId()-1);
293 else if( pControl == mpLayoutSet2 )
295 eLayout = static_cast< AutoLayout >(mpLayoutSet2->GetSelectItemId()-1);
298 if( eLayout != AUTOLAYOUT__END )
300 aArgs = Sequence< PropertyValue >(1);
301 aArgs[0].Name = "WhatLayout";
302 aArgs[0].Value <<= (sal_Int32)eLayout;
304 else if( mbInsertPage )
306 sCommandURL = ".uno:DuplicatePage";
309 mrController.dispatchCommand( sCommandURL, aArgs );
311 return 0;
314 // ====================================================================
316 OUString SlideLayoutController_getImplementationName()
318 return OUString( "com.sun.star.comp.sd.SlideLayoutController" );
321 // --------------------------------------------------------------------
323 Sequence< OUString > SlideLayoutController_getSupportedServiceNames() throw( RuntimeException )
325 Sequence< OUString > aSNS( 1 );
326 aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
327 return aSNS;
330 // --------------------------------------------------------------------
332 Reference< XInterface > SAL_CALL SlideLayoutController_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
334 return static_cast< cppu::OWeakObject * >(
335 new SlideLayoutController( comphelper::getComponentContext(rSMgr), ".uno:AssignLayout", false ));
338 // --------------------------------------------------------------------
340 OUString InsertSlideController_getImplementationName()
342 return OUString( "com.sun.star.comp.sd.InsertSlideController" );
345 // --------------------------------------------------------------------
347 Sequence< OUString > InsertSlideController_getSupportedServiceNames() throw( RuntimeException )
349 Sequence< OUString > aSNS( 1 );
350 aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
351 return aSNS;
354 // --------------------------------------------------------------------
356 Reference< XInterface > SAL_CALL InsertSlideController_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
358 return static_cast< cppu::OWeakObject * >(
359 new SlideLayoutController( comphelper::getComponentContext(rSMgr), ".uno:InsertPage" , true ) );
362 //========================================================================
363 // class SlideLayoutController
364 //========================================================================
366 SlideLayoutController::SlideLayoutController( const Reference< uno::XComponentContext >& rxContext, const OUString& sCommandURL, bool bInsertPage )
367 : svt::PopupWindowController( rxContext, Reference< frame::XFrame >(), sCommandURL )
368 , mbInsertPage( bInsertPage )
372 // --------------------------------------------------------------------
374 ::Window* SlideLayoutController::createPopupWindow( ::Window* pParent )
376 return new sd::LayoutToolbarMenu( *this, m_xFrame, pParent, mbInsertPage );
379 // --------------------------------------------------------------------
380 // XServiceInfo
381 // --------------------------------------------------------------------
383 OUString SAL_CALL SlideLayoutController::getImplementationName() throw( RuntimeException )
385 if( mbInsertPage )
386 return InsertSlideController_getImplementationName();
387 else
388 return SlideLayoutController_getImplementationName();
391 // --------------------------------------------------------------------
393 Sequence< OUString > SAL_CALL SlideLayoutController::getSupportedServiceNames( ) throw( RuntimeException )
395 if( mbInsertPage )
396 return InsertSlideController_getSupportedServiceNames();
397 else
398 return SlideLayoutController_getSupportedServiceNames();
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */