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/.
10 #include <svtools/popupwindowcontroller.hxx>
11 #include <svtools/toolbarmenu.hxx>
12 #include <svtools/valueset.hxx>
13 #include <vcl/toolbox.hxx>
15 #include <strings.hrc>
17 #include <bitmaps.hlst>
18 #include <sdresid.hxx>
20 using namespace ::com::sun::star
;
21 using namespace ::com::sun::star::uno
;
22 using namespace ::com::sun::star::frame
;
23 using namespace ::com::sun::star::beans
;
28 // Component to select which display mode has to be used.
29 // Composed of a dropdown button in the toolbar and a
30 // popup menu to select the value
32 class DisplayModeController
: public svt::PopupWindowController
35 explicit DisplayModeController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
37 virtual VclPtr
<vcl::Window
> createPopupWindow( vcl::Window
* pParent
) override
;
40 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
43 virtual OUString SAL_CALL
getImplementationName() override
;
44 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
46 void setToolboxItemImage(const OUString
& rImage
);
48 using svt::PopupWindowController::createPopupWindow
;
51 class DisplayModeToolbarMenu
: public svtools::ToolbarMenu
54 DisplayModeToolbarMenu( DisplayModeController
& rController
, vcl::Window
* pParent
);
55 virtual ~DisplayModeToolbarMenu() override
;
56 virtual void dispose() override
;
59 DECL_LINK( SelectToolbarMenuHdl
, ToolbarMenu
*, void );
60 DECL_LINK( SelectValueSetHdl
, ValueSet
*, void );
61 void SelectHdl(void const *);
64 DisplayModeController
& mrController
;
65 VclPtr
<ValueSet
> mpDisplayModeSet1
;
66 VclPtr
<ValueSet
> mpDisplayModeSet2
;
69 struct snewfoil_value_info
71 sal_uInt16
const mnId
;
72 const char* msBmpResId
;
73 const char* mpStrResId
;
74 const char* msUnoCommand
;
77 static const snewfoil_value_info editmodes
[] =
80 BMP_DISPLAYMODE_SLIDE
,
82 ".uno:NormalMultiPaneGUI" },
84 BMP_DISPLAYMODE_OUTLINE
,
88 BMP_DISPLAYMODE_NOTES
,
92 BMP_DISPLAYMODE_SLIDE_SORTER
,
93 STR_SLIDE_SORTER_MODE
,
98 static const snewfoil_value_info mastermodes
[] =
101 BMP_DISPLAYMODE_SLIDE_MASTER
,
102 STR_SLIDE_MASTER_MODE
,
103 ".uno:SlideMasterPage" },
105 BMP_DISPLAYMODE_NOTES_MASTER
,
106 STR_NOTES_MASTER_MODE
,
107 ".uno:NotesMasterPage" },
109 BMP_DISPLAYMODE_HANDOUT_MASTER
,
110 STR_HANDOUT_MASTER_MODE
,
111 ".uno:HandoutMode" },
112 {0, "", nullptr, "" }
116 static void fillLayoutValueSet( ValueSet
* pValue
, const snewfoil_value_info
* pInfo
)
118 Size aLayoutItemSize
;
119 for( ; pInfo
->mnId
; pInfo
++ )
121 OUString
aText(SdResId(pInfo
->mpStrResId
));
122 BitmapEx
aBmp(OUString::createFromAscii(pInfo
->msBmpResId
));
124 pValue
->InsertItem(pInfo
->mnId
, Image(aBmp
), aText
);
126 aLayoutItemSize
.setWidth( std::max( aLayoutItemSize
.Width(), aBmp
.GetSizePixel().Width() ) );
127 aLayoutItemSize
.setHeight( std::max( aLayoutItemSize
.Height(), aBmp
.GetSizePixel().Height() ) );
130 aLayoutItemSize
= pValue
->CalcItemSizePixel( aLayoutItemSize
);
131 pValue
->SetSizePixel( pValue
->CalcWindowSizePixel( aLayoutItemSize
) );
134 DisplayModeToolbarMenu::DisplayModeToolbarMenu( DisplayModeController
& rController
, vcl::Window
* pParent
)
135 : svtools::ToolbarMenu( rController
.getFrameInterface(), pParent
, WB_CLIPCHILDREN
)
136 , mrController( rController
)
137 , mpDisplayModeSet1( nullptr )
138 , mpDisplayModeSet2( nullptr )
140 const sal_Int32 LAYOUT_BORDER_PIX
= 7;
142 OUString
aTitle1( SdResId( STR_DISPLAYMODE_EDITMODES
) );
143 OUString
aTitle2( SdResId( STR_DISPLAYMODE_MASTERMODES
) );
145 SetSelectHdl( LINK( this, DisplayModeToolbarMenu
, SelectToolbarMenuHdl
) );
147 mpDisplayModeSet1
= createEmptyValueSetControl();
148 mpDisplayModeSet1
->SetSelectHdl( LINK( this, DisplayModeToolbarMenu
, SelectValueSetHdl
) );
150 sal_Int16 nColCount
= 2;
151 mpDisplayModeSet1
->SetColCount( nColCount
);
152 fillLayoutValueSet( mpDisplayModeSet1
, &editmodes
[0] );
154 Size
aSize( mpDisplayModeSet1
->GetOutputSizePixel() );
155 aSize
.AdjustWidth((mpDisplayModeSet1
->GetColCount() + 1) * LAYOUT_BORDER_PIX
);
156 aSize
.AdjustHeight((mpDisplayModeSet1
->GetLineCount() +1) * LAYOUT_BORDER_PIX
);
157 mpDisplayModeSet1
->SetOutputSizePixel( aSize
);
159 appendEntry( -1, aTitle1
);
160 appendEntry( 1, mpDisplayModeSet1
);
162 mpDisplayModeSet2
= createEmptyValueSetControl();
164 mpDisplayModeSet2
->SetSelectHdl( LINK( this, DisplayModeToolbarMenu
, SelectValueSetHdl
) );
165 mpDisplayModeSet2
->SetColCount( nColCount
);
167 fillLayoutValueSet( mpDisplayModeSet2
, &mastermodes
[0] );
169 aSize
= mpDisplayModeSet2
->GetOutputSizePixel();
170 aSize
.AdjustWidth((mpDisplayModeSet2
->GetColCount() + 1) * LAYOUT_BORDER_PIX
);
171 aSize
.AdjustHeight((mpDisplayModeSet2
->GetLineCount() + 1) * LAYOUT_BORDER_PIX
);
172 mpDisplayModeSet2
->SetOutputSizePixel( aSize
);
174 appendEntry( -1, aTitle2
);
175 appendEntry( 2, mpDisplayModeSet2
);
177 SetOutputSizePixel( getMenuSize() );
180 DisplayModeToolbarMenu::~DisplayModeToolbarMenu()
185 void DisplayModeToolbarMenu::dispose()
187 mpDisplayModeSet1
.clear();
188 mpDisplayModeSet2
.clear();
189 svtools::ToolbarMenu::dispose();
192 IMPL_LINK( DisplayModeToolbarMenu
, SelectValueSetHdl
, ValueSet
*, pControl
, void )
196 IMPL_LINK( DisplayModeToolbarMenu
, SelectToolbarMenuHdl
, ToolbarMenu
*, pControl
, void )
201 void DisplayModeToolbarMenu::SelectHdl(void const * pControl
)
203 if ( IsInPopupMode() )
206 OUString sCommandURL
;
209 if( pControl
== mpDisplayModeSet1
) {
210 sCommandURL
= OUString::createFromAscii(editmodes
[mpDisplayModeSet1
->GetSelectedItemId() - 1 ].msUnoCommand
);
211 sImage
= OUString::createFromAscii(editmodes
[mpDisplayModeSet1
->GetSelectedItemId() - 1 ].msBmpResId
);
213 else if( pControl
== mpDisplayModeSet2
) {
214 sCommandURL
= OUString::createFromAscii(mastermodes
[mpDisplayModeSet2
->GetSelectedItemId() - 5 ].msUnoCommand
);
215 sImage
= OUString::createFromAscii(mastermodes
[mpDisplayModeSet2
->GetSelectedItemId() - 5 ].msBmpResId
);
218 if (!sCommandURL
.isEmpty())
219 mrController
.dispatchCommand( sCommandURL
, Sequence
< PropertyValue
>() );
221 mrController
.setToolboxItemImage(sImage
);
224 DisplayModeController::DisplayModeController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
225 : svt::PopupWindowController( rxContext
, Reference
< frame::XFrame
>(), OUString() )
229 void SAL_CALL
DisplayModeController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
231 svt::PopupWindowController::initialize( aArguments
);
232 ToolBox
* pToolBox
= nullptr;
234 if ( getToolboxId( nId
, &pToolBox
) )
235 pToolBox
->SetItemBits( nId
, pToolBox
->GetItemBits( nId
) | ToolBoxItemBits::DROPDOWNONLY
);
236 setToolboxItemImage(BMP_DISPLAYMODE_SLIDE
);
239 VclPtr
<vcl::Window
> DisplayModeController::createPopupWindow( vcl::Window
* pParent
)
241 return VclPtr
<sd::DisplayModeToolbarMenu
>::Create( *this, pParent
);
244 void DisplayModeController::setToolboxItemImage(const OUString
& rImage
)
247 ToolBox
* pToolBox
= nullptr;
248 if (!getToolboxId( nId
, &pToolBox
))
251 BitmapEx
aBmp(rImage
);
252 int targetSize
= (pToolBox
->GetToolboxButtonSize() == ToolBoxButtonSize::Large
) ? 32 : 16;
254 Size size
= aBmp
.GetSizePixel();
255 if (size
.Width() > targetSize
)
256 scale
= static_cast<double>(targetSize
) / static_cast<double>(size
.Width());
257 if (size
.Height() > targetSize
)
258 scale
= ::std::min( scale
, static_cast<double>(targetSize
) / static_cast<double>(size
.Height()) );
259 aBmp
.Scale( scale
, scale
);
260 pToolBox
->SetItemImage( nId
, Image( aBmp
) );
265 OUString SAL_CALL
DisplayModeController::getImplementationName()
267 return OUString( "com.sun.star.comp.sd.DisplayModeController" );
270 Sequence
< OUString
> SAL_CALL
DisplayModeController::getSupportedServiceNames( )
272 css::uno::Sequence
<OUString
> aRet
{ "com.sun.star.frame.ToolbarController" };
278 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
*
279 com_sun_star_comp_sd_DisplayModeController_get_implementation( css::uno::XComponentContext
* context
,
280 css::uno::Sequence
<css::uno::Any
> const &)
282 return cppu::acquire(new sd::DisplayModeController(context
));
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */