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