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