1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <com/sun/star/frame/XFrame.hpp>
21 #include <com/sun/star/text/WritingMode.hpp>
22 #include <com/sun/star/frame/XDispatchProvider.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/drawing/DrawViewMode.hpp>
27 #include <osl/mutex.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/toolbox.hxx>
32 #include <svl/languageoptions.hxx>
34 #include <svtools/ctrltool.hxx>
35 #include <svtools/ctrlbox.hxx>
36 #include <svtools/toolbarmenu.hxx>
37 #include <svtools/valueset.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <comphelper/processfactory.hxx>
42 #include <sfx2/imagemgr.hxx>
47 #include "strings.hrc"
48 #include "res_bmp.hrc"
49 #include "sdresid.hxx"
51 #include "slidelayoutcontroller.hxx"
52 #include "ViewShellBase.hxx"
54 using namespace ::com::sun::star
;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::lang
;
57 using namespace ::com::sun::star::text
;
58 using namespace ::com::sun::star::frame
;
59 using namespace ::com::sun::star::drawing
;
60 using namespace ::com::sun::star::beans
;
65 class LayoutToolbarMenu
: public svtools::ToolbarMenu
68 LayoutToolbarMenu( SlideLayoutController
& rController
, const Reference
< XFrame
>& xFrame
, vcl::Window
* pParent
, const bool bInsertPage
);
69 virtual ~LayoutToolbarMenu();
70 virtual void dispose() SAL_OVERRIDE
;
73 DECL_LINK( SelectHdl
, void * );
76 SlideLayoutController
& mrController
;
77 Reference
< XFrame
> mxFrame
;
79 VclPtr
<ValueSet
> mpLayoutSet1
;
80 VclPtr
<ValueSet
> mpLayoutSet2
;
83 struct snewfoil_value_info
85 sal_uInt16 mnBmpResId
;
86 sal_uInt16 mnStrResId
;
87 WritingMode meWritingMode
;
88 AutoLayout maAutoLayout
;
91 static const snewfoil_value_info notes
[] =
93 {BMP_FOILN_01
, STR_AUTOLAYOUT_NOTES
, WritingMode_LR_TB
, AUTOLAYOUT_NOTES
},
94 {0, 0, WritingMode_LR_TB
, AUTOLAYOUT_NONE
},
97 static const snewfoil_value_info handout
[] =
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
},
108 static const snewfoil_value_info standard
[] =
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
}
125 static const snewfoil_value_info v_standard
[] =
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
}
135 static void fillLayoutValueSet( ValueSet
* pValue
, const snewfoil_value_info
* pInfo
)
137 Size aLayoutItemSize
;
138 for( ; pInfo
->mnBmpResId
; pInfo
++ )
140 OUString
aText( SD_RESSTR( pInfo
->mnStrResId
) );
141 BitmapEx
aBmp( SdResId( pInfo
->mnBmpResId
) );
143 pValue
->InsertItem(static_cast<sal_uInt16
>(pInfo
->maAutoLayout
)+1,
146 aLayoutItemSize
.Width() = std::max( aLayoutItemSize
.Width(), aBmp
.GetSizePixel().Width() );
147 aLayoutItemSize
.Height() = std::max( aLayoutItemSize
.Height(), aBmp
.GetSizePixel().Height() );
150 aLayoutItemSize
= pValue
->CalcItemSizePixel( aLayoutItemSize
);
151 pValue
->SetSizePixel( pValue
->CalcWindowSizePixel( aLayoutItemSize
) );
154 LayoutToolbarMenu::LayoutToolbarMenu( SlideLayoutController
& rController
, const Reference
< XFrame
>& xFrame
, vcl::Window
* pParent
, const bool bInsertPage
)
155 : svtools::ToolbarMenu(xFrame
, pParent
, WB_CLIPCHILDREN
)
156 , mrController( rController
)
158 , mbInsertPage( bInsertPage
)
162 DrawViewMode eMode
= DrawViewMode_DRAW
;
164 // find out which view is running
165 if( xFrame
.is() ) try
167 Reference
< XPropertySet
> xControllerSet( xFrame
->getController(), UNO_QUERY_THROW
);
168 xControllerSet
->getPropertyValue( "DrawViewMode" ) >>= eMode
;
170 catch( Exception
& e
)
176 const sal_Int32 LAYOUT_BORDER_PIX
= 7;
178 OUString
aTitle1( SD_RESSTR( STR_GLUE_ESCDIR_HORZ
) );
179 OUString
aTitle2( SD_RESSTR( STR_GLUE_ESCDIR_VERT
) );
181 SvtLanguageOptions aLanguageOptions
;
182 const bool bVerticalEnabled
= aLanguageOptions
.IsVerticalTextEnabled();
184 SetSelectHdl( LINK( this, LayoutToolbarMenu
, SelectHdl
) );
186 mpLayoutSet1
= createEmptyValueSetControl();
187 mpLayoutSet1
->SetSelectHdl( LINK( this, LayoutToolbarMenu
, SelectHdl
) );
189 const snewfoil_value_info
* pInfo
= 0;
190 sal_Int16 nColCount
= 4;
193 default: assert(false); // can't happen, will crash later otherwise
194 case DrawViewMode_DRAW
: pInfo
= &standard
[0]; break;
195 case DrawViewMode_HANDOUT
: pInfo
= &handout
[0]; nColCount
= 2; break;
196 case DrawViewMode_NOTES
: pInfo
= ¬es
[0]; nColCount
= 1; break;
199 mpLayoutSet1
->SetColCount( nColCount
);
201 fillLayoutValueSet( mpLayoutSet1
, pInfo
);
203 Size
aSize( mpLayoutSet1
->GetOutputSizePixel() );
204 aSize
.Width() += (mpLayoutSet1
->GetColCount() + 1) * LAYOUT_BORDER_PIX
;
205 aSize
.Height() += (mpLayoutSet1
->GetLineCount() +1) * LAYOUT_BORDER_PIX
;
206 mpLayoutSet1
->SetOutputSizePixel( aSize
);
208 if( bVerticalEnabled
&& (eMode
== DrawViewMode_DRAW
) )
209 appendEntry( -1, aTitle1
);
210 appendEntry( 0, mpLayoutSet1
);
212 if( bVerticalEnabled
&& (eMode
== DrawViewMode_DRAW
) )
214 mpLayoutSet2
= VclPtr
<ValueSet
>::Create( this, WB_TABSTOP
| WB_MENUSTYLEVALUESET
| WB_FLATVALUESET
| WB_NOBORDER
| WB_NO_DIRECTSELECT
);
216 mpLayoutSet2
->SetSelectHdl( LINK( this, LayoutToolbarMenu
, SelectHdl
) );
217 mpLayoutSet2
->SetColCount( 4 );
218 mpLayoutSet2
->EnableFullItemMode( false );
219 mpLayoutSet2
->SetColor( GetControlBackground() );
221 fillLayoutValueSet( mpLayoutSet2
, &v_standard
[0] );
223 aSize
= mpLayoutSet2
->GetOutputSizePixel();
224 aSize
.Width() += (mpLayoutSet2
->GetColCount() + 1) * LAYOUT_BORDER_PIX
;
225 aSize
.Height() += (mpLayoutSet2
->GetLineCount() + 1) * LAYOUT_BORDER_PIX
;
226 mpLayoutSet2
->SetOutputSizePixel( aSize
);
228 appendEntry( -1, aTitle2
);
229 appendEntry( 1, mpLayoutSet2
);
232 if( eMode
== DrawViewMode_DRAW
)
241 sSlotStr
= ".uno:DuplicatePage";
243 sSlotStr
= ".uno:Undo";
244 aSlotImage
= ::GetImage( mxFrame
, sSlotStr
, false );
248 sSlotTitle
= ImplRetrieveLabelFromCommand( mxFrame
, sSlotStr
);
250 sSlotTitle
= SD_RESSTR( STR_RESET_LAYOUT
);
251 appendEntry( 2, sSlotTitle
, aSlotImage
);
255 SetOutputSizePixel( getMenuSize() );
258 LayoutToolbarMenu::~LayoutToolbarMenu()
263 void LayoutToolbarMenu::dispose()
265 mpLayoutSet1
.clear();
266 mpLayoutSet2
.clear();
267 svtools::ToolbarMenu::dispose();
270 IMPL_LINK( LayoutToolbarMenu
, SelectHdl
, void *, pControl
)
272 if ( IsInPopupMode() )
275 Sequence
< PropertyValue
> aArgs
;
277 AutoLayout eLayout
= AUTOLAYOUT__END
;
279 OUString
sCommandURL( mrController
.getCommandURL() );
281 if( pControl
== mpLayoutSet1
)
283 eLayout
= static_cast< AutoLayout
>(mpLayoutSet1
->GetSelectItemId()-1);
285 else if( pControl
== mpLayoutSet2
)
287 eLayout
= static_cast< AutoLayout
>(mpLayoutSet2
->GetSelectItemId()-1);
290 if( eLayout
!= AUTOLAYOUT__END
)
292 aArgs
= Sequence
< PropertyValue
>(1);
293 aArgs
[0].Name
= "WhatLayout";
294 aArgs
[0].Value
<<= (sal_Int32
)eLayout
;
296 else if( mbInsertPage
)
298 sCommandURL
= ".uno:DuplicatePage";
301 mrController
.dispatchCommand( sCommandURL
, aArgs
);
306 OUString
SlideLayoutController_getImplementationName() throw (css::uno::RuntimeException
)
308 return OUString( "com.sun.star.comp.sd.SlideLayoutController" );
311 Sequence
< OUString
> SlideLayoutController_getSupportedServiceNames() throw( RuntimeException
)
313 Sequence
< OUString
> aSNS( 1 );
314 aSNS
.getArray()[0] = "com.sun.star.frame.ToolbarController";
318 OUString
InsertSlideController_getImplementationName() throw (css::uno::RuntimeException
)
320 return OUString( "com.sun.star.comp.sd.InsertSlideController" );
323 Sequence
< OUString
> InsertSlideController_getSupportedServiceNames() throw( RuntimeException
)
325 Sequence
< OUString
> aSNS( 1 );
326 aSNS
.getArray()[0] = "com.sun.star.frame.ToolbarController";
330 // class SlideLayoutController
332 SlideLayoutController::SlideLayoutController( const Reference
< uno::XComponentContext
>& rxContext
, const OUString
& sCommandURL
, bool bInsertPage
)
333 : svt::PopupWindowController( rxContext
, Reference
< frame::XFrame
>(), sCommandURL
)
334 , mbInsertPage( bInsertPage
)
338 void SAL_CALL
SlideLayoutController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
339 throw ( css::uno::Exception
, css::uno::RuntimeException
, std::exception
)
341 svt::PopupWindowController::initialize( aArguments
);
343 ToolBox
* pToolBox
= 0;
345 if ( getToolboxId( nId
, &pToolBox
) )
348 pToolBox
->SetItemBits( nId
, pToolBox
->GetItemBits( nId
) | ToolBoxItemBits::DROPDOWN
);
350 pToolBox
->SetItemBits( nId
, pToolBox
->GetItemBits( nId
) | ToolBoxItemBits::DROPDOWNONLY
);
354 VclPtr
<vcl::Window
> SlideLayoutController::createPopupWindow( vcl::Window
* pParent
)
356 return VclPtr
<sd::LayoutToolbarMenu
>::Create( *this, m_xFrame
, pParent
, mbInsertPage
);
361 OUString SAL_CALL
SlideLayoutController::getImplementationName() throw( RuntimeException
, std::exception
)
364 return InsertSlideController_getImplementationName();
366 return SlideLayoutController_getImplementationName();
369 Sequence
< OUString
> SAL_CALL
SlideLayoutController::getSupportedServiceNames( ) throw( RuntimeException
, std::exception
)
372 return InsertSlideController_getSupportedServiceNames();
374 return SlideLayoutController_getSupportedServiceNames();
380 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
381 com_sun_star_comp_sd_SlideLayoutController_get_implementation(::com::sun::star::uno::XComponentContext
* context
,
382 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
384 return cppu::acquire(new sd::SlideLayoutController(context
, ".uno:AssignLayout", false));
387 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
388 com_sun_star_comp_sd_InsertSlideController_get_implementation(::com::sun::star::uno::XComponentContext
* context
,
389 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
391 return cppu::acquire(new sd::SlideLayoutController(context
, ".uno:InsertPage", true));
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */