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/beans/PropertyValue.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/drawing/DrawViewMode.hpp>
25 #include <comphelper/propertyvalue.hxx>
26 #include <vcl/commandinfoprovider.hxx>
27 #include <vcl/toolbox.hxx>
29 #include <svl/cjkoptions.hxx>
31 #include <svtools/toolbarmenu.hxx>
32 #include <svtools/valueset.hxx>
34 #include <xmloff/autolayout.hxx>
36 #include <strings.hrc>
38 #include <bitmaps.hlst>
39 #include <sdresid.hxx>
40 #include "slidelayoutcontroller.hxx"
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::frame
;
45 using namespace ::com::sun::star::drawing
;
46 using namespace ::com::sun::star::beans
;
53 class LayoutToolbarMenu
: public WeldToolbarPopup
56 LayoutToolbarMenu(SlideLayoutController
* pController
, weld::Widget
* pParent
, const bool bInsertPage
, const OUString
& rCommand
);
57 virtual void GrabFocus() override
59 mxLayoutSet1
->GrabFocus();
63 DECL_LINK(SelectToolbarMenuHdl
, weld::Button
&, void);
64 DECL_LINK(SelectValueSetHdl
, ValueSet
*, void);
65 void SelectHdl(AutoLayout eLayout
);
67 rtl::Reference
<SlideLayoutController
> mxControl
;
68 bool const mbInsertPage
;
69 std::unique_ptr
<weld::Frame
> mxFrame1
;
70 std::unique_ptr
<ValueSet
> mxLayoutSet1
;
71 std::unique_ptr
<weld::CustomWeld
> mxLayoutSetWin1
;
72 std::unique_ptr
<weld::Frame
> mxFrame2
;
73 std::unique_ptr
<ValueSet
> mxLayoutSet2
;
74 std::unique_ptr
<weld::CustomWeld
> mxLayoutSetWin2
;
75 std::unique_ptr
<weld::Button
> mxMoreButton
;
78 struct snew_slide_value_info_layout
81 TranslateId mpStrResId
;
82 AutoLayout maAutoLayout
;
87 constexpr OUString EMPTY
= u
""_ustr
;
89 constexpr snew_slide_value_info_layout notes
[] =
91 {BMP_SLIDEN_01
, STR_AUTOLAYOUT_NOTES
, AUTOLAYOUT_NOTES
},
92 {EMPTY
, {}, AUTOLAYOUT_NONE
},
95 constexpr snew_slide_value_info_layout handout
[] =
97 {BMP_SLIDEH_01
, STR_AUTOLAYOUT_HANDOUT1
, AUTOLAYOUT_HANDOUT1
},
98 {BMP_SLIDEH_02
, STR_AUTOLAYOUT_HANDOUT2
, AUTOLAYOUT_HANDOUT2
},
99 {BMP_SLIDEH_03
, STR_AUTOLAYOUT_HANDOUT3
, AUTOLAYOUT_HANDOUT3
},
100 {BMP_SLIDEH_04
, STR_AUTOLAYOUT_HANDOUT4
, AUTOLAYOUT_HANDOUT4
},
101 {BMP_SLIDEH_06
, STR_AUTOLAYOUT_HANDOUT6
, AUTOLAYOUT_HANDOUT6
},
102 {BMP_SLIDEH_09
, STR_AUTOLAYOUT_HANDOUT9
, AUTOLAYOUT_HANDOUT9
},
103 {EMPTY
, {}, AUTOLAYOUT_NONE
},
106 constexpr snew_slide_value_info_layout standard
[] =
108 {BMP_LAYOUT_EMPTY
, STR_AUTOLAYOUT_NONE
, AUTOLAYOUT_NONE
},
109 {BMP_LAYOUT_HEAD03
, STR_AUTOLAYOUT_TITLE
, AUTOLAYOUT_TITLE
},
110 {BMP_LAYOUT_HEAD02
, STR_AUTOLAYOUT_CONTENT
, AUTOLAYOUT_TITLE_CONTENT
},
111 {BMP_LAYOUT_HEAD02A
, STR_AUTOLAYOUT_2CONTENT
, AUTOLAYOUT_TITLE_2CONTENT
},
112 {BMP_LAYOUT_HEAD01
, STR_AUTOLAYOUT_ONLY_TITLE
, AUTOLAYOUT_TITLE_ONLY
},
113 {BMP_LAYOUT_TEXTONLY
, STR_AUTOLAYOUT_ONLY_TEXT
, AUTOLAYOUT_ONLY_TEXT
},
114 {BMP_LAYOUT_HEAD03B
, STR_AUTOLAYOUT_2CONTENT_CONTENT
, AUTOLAYOUT_TITLE_2CONTENT_CONTENT
},
115 {BMP_LAYOUT_HEAD03C
, STR_AUTOLAYOUT_CONTENT_2CONTENT
, AUTOLAYOUT_TITLE_CONTENT_2CONTENT
},
116 {BMP_LAYOUT_HEAD03A
, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT
,AUTOLAYOUT_TITLE_2CONTENT_OVER_CONTENT
},
117 {BMP_LAYOUT_HEAD02B
, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT
, AUTOLAYOUT_TITLE_CONTENT_OVER_CONTENT
},
118 {BMP_LAYOUT_HEAD04
, STR_AUTOLAYOUT_4CONTENT
, AUTOLAYOUT_TITLE_4CONTENT
},
119 {BMP_LAYOUT_HEAD06
, STR_AUTOLAYOUT_6CONTENT
, AUTOLAYOUT_TITLE_6CONTENT
},
120 {EMPTY
, {}, AUTOLAYOUT_NONE
}
123 constexpr snew_slide_value_info_layout v_standard
[] =
126 {BMP_LAYOUT_VERTICAL02
, STR_AL_VERT_TITLE_TEXT_CHART
, AUTOLAYOUT_VTITLE_VCONTENT_OVER_VCONTENT
},
127 {BMP_LAYOUT_VERTICAL01
, STR_AL_VERT_TITLE_VERT_OUTLINE
, AUTOLAYOUT_VTITLE_VCONTENT
},
128 {BMP_LAYOUT_HEAD02
, STR_AL_TITLE_VERT_OUTLINE
, AUTOLAYOUT_TITLE_VCONTENT
},
129 {BMP_LAYOUT_HEAD02A
, STR_AL_TITLE_VERT_OUTLINE_CLIPART
, AUTOLAYOUT_TITLE_2VTEXT
},
130 {EMPTY
, {}, AUTOLAYOUT_NONE
}
133 static void fillLayoutValueSet( ValueSet
* pValue
, const snew_slide_value_info_layout
* pInfo
)
135 Size aLayoutItemSize
;
136 for( ; pInfo
->mpStrResId
; pInfo
++ )
138 OUString
aText(SdResId(pInfo
->mpStrResId
));
139 Image
aImg(StockImage::Yes
, pInfo
->msBmpResId
);
140 pValue
->InsertItem(static_cast<sal_uInt16
>(pInfo
->maAutoLayout
)+1, aImg
, aText
);
141 aLayoutItemSize
.setWidth( std::max( aLayoutItemSize
.Width(), aImg
.GetSizePixel().Width() ) );
142 aLayoutItemSize
.setHeight( std::max( aLayoutItemSize
.Height(), aImg
.GetSizePixel().Height() ) );
145 aLayoutItemSize
= pValue
->CalcItemSizePixel( aLayoutItemSize
);
146 Size
aSize(pValue
->CalcWindowSizePixel(aLayoutItemSize
));
148 const sal_Int32 LAYOUT_BORDER_PIX
= 7;
150 aSize
.AdjustWidth((pValue
->GetColCount() + 1) * LAYOUT_BORDER_PIX
);
151 aSize
.AdjustHeight((pValue
->GetLineCount() +1) * LAYOUT_BORDER_PIX
);
153 pValue
->GetDrawingArea()->set_size_request(aSize
.Width(), aSize
.Height());
154 pValue
->SetOutputSizePixel(aSize
);
157 LayoutToolbarMenu::LayoutToolbarMenu(SlideLayoutController
* pControl
, weld::Widget
* pParent
, const bool bInsertPage
, const OUString
& rCommand
)
158 : WeldToolbarPopup(pControl
->getFrameInterface(), pParent
, u
"modules/simpress/ui/layoutwindow.ui"_ustr
, u
"LayoutWindow"_ustr
)
159 , mxControl(pControl
)
160 , mbInsertPage(bInsertPage
)
161 , mxFrame1(m_xBuilder
->weld_frame(u
"horiframe"_ustr
))
162 , mxLayoutSet1(new ValueSet(nullptr))
163 , mxLayoutSetWin1(new weld::CustomWeld(*m_xBuilder
, u
"valueset1"_ustr
, *mxLayoutSet1
))
164 , mxFrame2(m_xBuilder
->weld_frame(u
"vertframe"_ustr
))
165 , mxLayoutSet2(new ValueSet(nullptr))
166 , mxLayoutSetWin2(new weld::CustomWeld(*m_xBuilder
, u
"valueset2"_ustr
, *mxLayoutSet2
))
167 , mxMoreButton(m_xBuilder
->weld_button(u
"more"_ustr
))
169 mxLayoutSet1
->SetStyle(WB_TABSTOP
| WB_MENUSTYLEVALUESET
| WB_FLATVALUESET
| WB_NOBORDER
| WB_NO_DIRECTSELECT
);
170 mxLayoutSet2
->SetStyle(WB_TABSTOP
| WB_MENUSTYLEVALUESET
| WB_FLATVALUESET
| WB_NOBORDER
| WB_NO_DIRECTSELECT
);
172 DrawViewMode eMode
= DrawViewMode_DRAW
;
174 // find out which view is running
175 if( m_xFrame
.is() ) try
177 Reference
< XPropertySet
> xControllerSet( m_xFrame
->getController(), UNO_QUERY_THROW
);
178 xControllerSet
->getPropertyValue( u
"DrawViewMode"_ustr
) >>= eMode
;
185 const bool bVerticalEnabled
= SvtCJKOptions::IsVerticalTextEnabled();
187 mxLayoutSet1
->SetSelectHdl( LINK( this, LayoutToolbarMenu
, SelectValueSetHdl
) );
189 const snew_slide_value_info_layout
* pInfo
= nullptr;
190 sal_Int16 nColCount
= 4;
193 case DrawViewMode_DRAW
: pInfo
= &standard
[0]; break;
194 case DrawViewMode_HANDOUT
: pInfo
= &handout
[0]; nColCount
= 2; break;
195 case DrawViewMode_NOTES
: pInfo
= ¬es
[0]; nColCount
= 1; break;
196 default: assert(false); // can't happen, will crash later otherwise
199 mxLayoutSet1
->SetColCount( nColCount
);
201 fillLayoutValueSet( mxLayoutSet1
.get(), pInfo
);
203 bool bUseUILabel
= (bVerticalEnabled
&& eMode
== DrawViewMode_DRAW
);
206 auto aProperties
= vcl::CommandInfoProvider::GetCommandProperties(rCommand
, mxControl
->getModuleName());
207 mxFrame1
->set_label(vcl::CommandInfoProvider::GetLabelForCommand(aProperties
));
210 if (bVerticalEnabled
&& eMode
== DrawViewMode_DRAW
)
212 mxLayoutSet2
->SetSelectHdl( LINK( this, LayoutToolbarMenu
, SelectValueSetHdl
) );
213 mxLayoutSet2
->SetColCount( 4 );
214 mxLayoutSet2
->EnableFullItemMode( false );
216 fillLayoutValueSet( mxLayoutSet2
.get(), &v_standard
[0] );
221 if( eMode
!= DrawViewMode_DRAW
)
230 sSlotStr
= ".uno:DuplicatePage";
232 sSlotStr
= ".uno:Undo";
234 css::uno::Reference
<css::graphic::XGraphic
> xSlotImage
= vcl::CommandInfoProvider::GetXGraphicForCommand(sSlotStr
, m_xFrame
);
239 auto aProperties
= vcl::CommandInfoProvider::GetCommandProperties(sSlotStr
, mxControl
->getModuleName());
240 sSlotTitle
= vcl::CommandInfoProvider::GetLabelForCommand(aProperties
);
243 sSlotTitle
= SdResId( STR_RESET_LAYOUT
);
245 mxMoreButton
->set_label(sSlotTitle
);
246 mxMoreButton
->set_image(xSlotImage
);
247 mxMoreButton
->connect_clicked(LINK(this, LayoutToolbarMenu
, SelectToolbarMenuHdl
));
248 mxMoreButton
->show();
251 IMPL_LINK(LayoutToolbarMenu
, SelectValueSetHdl
, ValueSet
*, pLayoutSet
, void)
253 SelectHdl(static_cast<AutoLayout
>(pLayoutSet
->GetSelectedItemId()-1));
256 IMPL_LINK_NOARG(LayoutToolbarMenu
, SelectToolbarMenuHdl
, weld::Button
&, void)
258 SelectHdl(AUTOLAYOUT_END
);
261 void LayoutToolbarMenu::SelectHdl(AutoLayout eLayout
)
263 Sequence
< PropertyValue
> aArgs
;
265 OUString
sCommandURL( mxControl
->getCommandURL() );
267 if( eLayout
!= AUTOLAYOUT_END
)
269 aArgs
= { comphelper::makePropertyValue(u
"WhatLayout"_ustr
, static_cast<sal_Int32
>(eLayout
)) };
271 else if( mbInsertPage
)
273 sCommandURL
= ".uno:DuplicatePage";
276 mxControl
->dispatchCommand( sCommandURL
, aArgs
);
278 mxControl
->EndPopupMode();
282 /// @throws css::uno::RuntimeException
283 static OUString
SlideLayoutController_getImplementationName()
285 return u
"com.sun.star.comp.sd.SlideLayoutController"_ustr
;
288 /// @throws RuntimeException
289 static Sequence
< OUString
> SlideLayoutController_getSupportedServiceNames()
291 Sequence
<OUString
> aSNS
{ u
"com.sun.star.frame.ToolbarController"_ustr
};
295 /// @throws css::uno::RuntimeException
296 static OUString
InsertSlideController_getImplementationName()
298 return u
"com.sun.star.comp.sd.InsertSlideController"_ustr
;
301 /// @throws RuntimeException
302 static Sequence
< OUString
> InsertSlideController_getSupportedServiceNames()
304 Sequence
<OUString
> aSNS
{ u
"com.sun.star.frame.ToolbarController"_ustr
};
308 SlideLayoutController::SlideLayoutController(const Reference
< uno::XComponentContext
>& rxContext
, bool bInsertPage
)
309 : svt::PopupWindowController(rxContext
, nullptr, OUString())
310 , mbInsertPage(bInsertPage
)
314 void SAL_CALL
SlideLayoutController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
316 svt::PopupWindowController::initialize( aArguments
);
318 ToolBox
* pToolBox
= nullptr;
320 if ( getToolboxId( nId
, &pToolBox
) )
323 pToolBox
->SetItemBits( nId
, pToolBox
->GetItemBits( nId
) | ToolBoxItemBits::DROPDOWN
);
325 pToolBox
->SetItemBits( nId
, pToolBox
->GetItemBits( nId
) | ToolBoxItemBits::DROPDOWNONLY
);
329 std::unique_ptr
<WeldToolbarPopup
> SlideLayoutController::weldPopupWindow()
331 return std::make_unique
<sd::LayoutToolbarMenu
>(this, m_pToolbar
, mbInsertPage
, m_aCommandURL
);
334 VclPtr
<vcl::Window
> SlideLayoutController::createVclPopupWindow( vcl::Window
* pParent
)
336 mxInterimPopover
= VclPtr
<InterimToolbarPopup
>::Create(getFrameInterface(), pParent
,
337 std::make_unique
<sd::LayoutToolbarMenu
>(this, pParent
->GetFrameWeld(), mbInsertPage
, m_aCommandURL
));
339 mxInterimPopover
->Show();
341 return mxInterimPopover
;
346 OUString SAL_CALL
SlideLayoutController::getImplementationName()
349 return InsertSlideController_getImplementationName();
351 return SlideLayoutController_getImplementationName();
354 Sequence
< OUString
> SAL_CALL
SlideLayoutController::getSupportedServiceNames( )
357 return InsertSlideController_getSupportedServiceNames();
359 return SlideLayoutController_getSupportedServiceNames();
364 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
365 com_sun_star_comp_sd_SlideLayoutController_get_implementation(css::uno::XComponentContext
* context
,
366 css::uno::Sequence
<css::uno::Any
> const &)
368 return cppu::acquire(new sd::SlideLayoutController(context
, false));
371 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
372 com_sun_star_comp_sd_InsertSlideController_get_implementation(css::uno::XComponentContext
* context
,
373 css::uno::Sequence
<css::uno::Any
> const &)
375 return cppu::acquire(new sd::SlideLayoutController(context
, true));
379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */