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/status/FontHeight.hpp>
23 : #include <com/sun/star/frame/XDispatchProvider.hpp>
24 : #include <com/sun/star/beans/PropertyValue.hpp>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/drawing/DrawViewMode.hpp>
27 :
28 : #include <osl/mutex.hxx>
29 :
30 : #include <vcl/svapp.hxx>
31 : #include <vcl/toolbox.hxx>
32 :
33 : #include <svl/languageoptions.hxx>
34 :
35 : #include <svtools/ctrltool.hxx>
36 : #include <svtools/ctrlbox.hxx>
37 : #include <svtools/toolbarmenu.hxx>
38 : #include <svtools/valueset.hxx>
39 :
40 : #include <toolkit/helper/vclunohelper.hxx>
41 : #include <comphelper/processfactory.hxx>
42 :
43 : #include <sfx2/imagemgr.hxx>
44 :
45 : #include "app.hrc"
46 : #include "facreg.hxx"
47 : #include "glob.hrc"
48 : #include "strings.hrc"
49 : #include "res_bmp.hrc"
50 : #include "sdresid.hxx"
51 : #include "pres.hxx"
52 : #include "slidelayoutcontroller.hxx"
53 : #include "ViewShellBase.hxx"
54 :
55 : using namespace ::com::sun::star;
56 : using namespace ::com::sun::star::uno;
57 : using namespace ::com::sun::star::lang;
58 : using namespace ::com::sun::star::text;
59 : using namespace ::com::sun::star::frame;
60 : using namespace ::com::sun::star::drawing;
61 : using namespace ::com::sun::star::beans;
62 :
63 : namespace sd
64 : {
65 :
66 : class LayoutToolbarMenu : public svtools::ToolbarMenu
67 : {
68 : public:
69 : LayoutToolbarMenu( SlideLayoutController& rController, const Reference< XFrame >& xFrame, vcl::Window* pParent, const bool bInsertPage );
70 : virtual ~LayoutToolbarMenu();
71 :
72 : protected:
73 : DECL_LINK( SelectHdl, void * );
74 :
75 : private:
76 : SlideLayoutController& mrController;
77 : Reference< XFrame > mxFrame;
78 : bool mbInsertPage;
79 : ValueSet* mpLayoutSet1;
80 : 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 = ¬es[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 = new ValueSet( 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 : }
261 :
262 0 : IMPL_LINK( LayoutToolbarMenu, SelectHdl, void *, pControl )
263 : {
264 0 : if ( IsInPopupMode() )
265 0 : EndPopupMode();
266 :
267 0 : Sequence< PropertyValue > aArgs;
268 :
269 0 : AutoLayout eLayout = AUTOLAYOUT__END;
270 :
271 0 : OUString sCommandURL( mrController.getCommandURL() );
272 :
273 0 : if( pControl == mpLayoutSet1 )
274 : {
275 0 : eLayout = static_cast< AutoLayout >(mpLayoutSet1->GetSelectItemId()-1);
276 : }
277 0 : else if( pControl == mpLayoutSet2 )
278 : {
279 0 : eLayout = static_cast< AutoLayout >(mpLayoutSet2->GetSelectItemId()-1);
280 : }
281 :
282 0 : if( eLayout != AUTOLAYOUT__END )
283 : {
284 0 : aArgs = Sequence< PropertyValue >(1);
285 0 : aArgs[0].Name = "WhatLayout";
286 0 : aArgs[0].Value <<= (sal_Int32)eLayout;
287 : }
288 0 : else if( mbInsertPage )
289 : {
290 0 : sCommandURL = ".uno:DuplicatePage";
291 : }
292 :
293 0 : mrController.dispatchCommand( sCommandURL, aArgs );
294 :
295 0 : return 0;
296 : }
297 :
298 42 : OUString SlideLayoutController_getImplementationName() throw (css::uno::RuntimeException)
299 : {
300 42 : return OUString( "com.sun.star.comp.sd.SlideLayoutController" );
301 : }
302 :
303 8 : Sequence< OUString > SlideLayoutController_getSupportedServiceNames() throw( RuntimeException )
304 : {
305 8 : Sequence< OUString > aSNS( 1 );
306 8 : aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
307 8 : return aSNS;
308 : }
309 :
310 24 : Reference< XInterface > SAL_CALL SlideLayoutController_createInstance( const Reference< XMultiServiceFactory >& rSMgr )
311 : {
312 : return static_cast< cppu::OWeakObject * >(
313 24 : new SlideLayoutController( comphelper::getComponentContext(rSMgr), ".uno:AssignLayout", false ));
314 : }
315 :
316 42 : OUString InsertSlideController_getImplementationName() throw (css::uno::RuntimeException)
317 : {
318 42 : return OUString( "com.sun.star.comp.sd.InsertSlideController" );
319 : }
320 :
321 8 : Sequence< OUString > InsertSlideController_getSupportedServiceNames() throw( RuntimeException )
322 : {
323 8 : Sequence< OUString > aSNS( 1 );
324 8 : aSNS.getArray()[0] = "com.sun.star.frame.ToolbarController";
325 8 : return aSNS;
326 : }
327 :
328 24 : Reference< XInterface > SAL_CALL InsertSlideController_createInstance( const Reference< XMultiServiceFactory >& rSMgr )
329 : {
330 : return static_cast< cppu::OWeakObject * >(
331 24 : new SlideLayoutController( comphelper::getComponentContext(rSMgr), ".uno:InsertPage" , true ) );
332 : }
333 :
334 : // class SlideLayoutController
335 :
336 48 : SlideLayoutController::SlideLayoutController( const Reference< uno::XComponentContext >& rxContext, const OUString& sCommandURL, bool bInsertPage )
337 : : svt::PopupWindowController( rxContext, Reference< frame::XFrame >(), sCommandURL )
338 48 : , mbInsertPage( bInsertPage )
339 : {
340 48 : }
341 :
342 48 : void SAL_CALL SlideLayoutController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
343 : throw ( css::uno::Exception, css::uno::RuntimeException, std::exception )
344 : {
345 48 : svt::PopupWindowController::initialize( aArguments );
346 :
347 48 : ToolBox* pToolBox = 0;
348 48 : sal_uInt16 nId = 0;
349 48 : if ( getToolboxId( nId, &pToolBox ) )
350 : {
351 48 : if ( mbInsertPage )
352 24 : pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWN );
353 : else
354 24 : pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
355 : }
356 48 : }
357 :
358 0 : ::vcl::Window* SlideLayoutController::createPopupWindow( ::vcl::Window* pParent )
359 : {
360 0 : return new sd::LayoutToolbarMenu( *this, m_xFrame, pParent, mbInsertPage );
361 : }
362 :
363 : // XServiceInfo
364 :
365 0 : OUString SAL_CALL SlideLayoutController::getImplementationName() throw( RuntimeException, std::exception )
366 : {
367 0 : if( mbInsertPage )
368 0 : return InsertSlideController_getImplementationName();
369 : else
370 0 : return SlideLayoutController_getImplementationName();
371 : }
372 :
373 0 : Sequence< OUString > SAL_CALL SlideLayoutController::getSupportedServiceNames( ) throw( RuntimeException, std::exception )
374 : {
375 0 : if( mbInsertPage )
376 0 : return InsertSlideController_getSupportedServiceNames();
377 : else
378 0 : return SlideLayoutController_getSupportedServiceNames();
379 : }
380 :
381 114 : }
382 :
383 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|