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