LibreOffice Module sd (master) 1
slidelayoutcontroller.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
24
27#include <vcl/toolbox.hxx>
28
29#include <svl/cjkoptions.hxx>
30
32#include <svtools/valueset.hxx>
33
34#include <xmloff/autolayout.hxx>
35
36#include <strings.hrc>
37
38#include <bitmaps.hlst>
39#include <sdresid.hxx>
41
42using namespace ::com::sun::star;
43using namespace ::com::sun::star::uno;
44using namespace ::com::sun::star::lang;
45using namespace ::com::sun::star::frame;
46using namespace ::com::sun::star::drawing;
47using namespace ::com::sun::star::beans;
48
49namespace sd
50{
51
52namespace {
53
54class LayoutToolbarMenu : public WeldToolbarPopup
55{
56public:
57 LayoutToolbarMenu(SlideLayoutController* pController, weld::Widget* pParent, const bool bInsertPage, const OUString& rCommand);
58 virtual void GrabFocus() override
59 {
60 mxLayoutSet1->GrabFocus();
61 }
62
63protected:
64 DECL_LINK(SelectToolbarMenuHdl, weld::Button&, void);
65 DECL_LINK(SelectValueSetHdl, ValueSet*, void);
66 void SelectHdl(AutoLayout eLayout);
67private:
69 bool const mbInsertPage;
70 std::unique_ptr<weld::Frame> mxFrame1;
71 std::unique_ptr<ValueSet> mxLayoutSet1;
72 std::unique_ptr<weld::CustomWeld> mxLayoutSetWin1;
73 std::unique_ptr<weld::Frame> mxFrame2;
74 std::unique_ptr<ValueSet> mxLayoutSet2;
75 std::unique_ptr<weld::CustomWeld> mxLayoutSetWin2;
76 std::unique_ptr<weld::Button> mxMoreButton;
77};
78
79struct snew_slide_value_info_layout
80{
81 rtl::OUStringConstExpr msBmpResId;
84};
85
86}
87
88constexpr OUStringLiteral EMPTY = u"";
89
90const snew_slide_value_info_layout notes[] =
91{
92 {BMP_SLIDEN_01, STR_AUTOLAYOUT_NOTES, AUTOLAYOUT_NOTES},
94};
95
96const snew_slide_value_info_layout handout[] =
97{
98 {BMP_SLIDEH_01, STR_AUTOLAYOUT_HANDOUT1, AUTOLAYOUT_HANDOUT1},
99 {BMP_SLIDEH_02, STR_AUTOLAYOUT_HANDOUT2, AUTOLAYOUT_HANDOUT2},
100 {BMP_SLIDEH_03, STR_AUTOLAYOUT_HANDOUT3, AUTOLAYOUT_HANDOUT3},
101 {BMP_SLIDEH_04, STR_AUTOLAYOUT_HANDOUT4, AUTOLAYOUT_HANDOUT4},
102 {BMP_SLIDEH_06, STR_AUTOLAYOUT_HANDOUT6, AUTOLAYOUT_HANDOUT6},
103 {BMP_SLIDEH_09, STR_AUTOLAYOUT_HANDOUT9, AUTOLAYOUT_HANDOUT9},
104 {EMPTY, {}, AUTOLAYOUT_NONE},
105};
106
107const snew_slide_value_info_layout standard[] =
108{
109 {BMP_LAYOUT_EMPTY, STR_AUTOLAYOUT_NONE, AUTOLAYOUT_NONE },
110 {BMP_LAYOUT_HEAD03, STR_AUTOLAYOUT_TITLE, AUTOLAYOUT_TITLE },
111 {BMP_LAYOUT_HEAD02, STR_AUTOLAYOUT_CONTENT, AUTOLAYOUT_TITLE_CONTENT },
112 {BMP_LAYOUT_HEAD02A, STR_AUTOLAYOUT_2CONTENT, AUTOLAYOUT_TITLE_2CONTENT },
113 {BMP_LAYOUT_HEAD01, STR_AUTOLAYOUT_ONLY_TITLE, AUTOLAYOUT_TITLE_ONLY },
114 {BMP_LAYOUT_TEXTONLY, STR_AUTOLAYOUT_ONLY_TEXT, AUTOLAYOUT_ONLY_TEXT },
115 {BMP_LAYOUT_HEAD03B, STR_AUTOLAYOUT_2CONTENT_CONTENT, AUTOLAYOUT_TITLE_2CONTENT_CONTENT },
116 {BMP_LAYOUT_HEAD03C, STR_AUTOLAYOUT_CONTENT_2CONTENT, AUTOLAYOUT_TITLE_CONTENT_2CONTENT },
117 {BMP_LAYOUT_HEAD03A, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT,AUTOLAYOUT_TITLE_2CONTENT_OVER_CONTENT },
118 {BMP_LAYOUT_HEAD02B, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT, AUTOLAYOUT_TITLE_CONTENT_OVER_CONTENT },
119 {BMP_LAYOUT_HEAD04, STR_AUTOLAYOUT_4CONTENT, AUTOLAYOUT_TITLE_4CONTENT },
120 {BMP_LAYOUT_HEAD06, STR_AUTOLAYOUT_6CONTENT, AUTOLAYOUT_TITLE_6CONTENT },
122};
123
124const snew_slide_value_info_layout v_standard[] =
125{
126 // vertical
127 {BMP_LAYOUT_VERTICAL02, STR_AL_VERT_TITLE_TEXT_CHART, AUTOLAYOUT_VTITLE_VCONTENT_OVER_VCONTENT },
128 {BMP_LAYOUT_VERTICAL01, STR_AL_VERT_TITLE_VERT_OUTLINE, AUTOLAYOUT_VTITLE_VCONTENT },
129 {BMP_LAYOUT_HEAD02, STR_AL_TITLE_VERT_OUTLINE, AUTOLAYOUT_TITLE_VCONTENT },
130 {BMP_LAYOUT_HEAD02A, STR_AL_TITLE_VERT_OUTLINE_CLIPART, AUTOLAYOUT_TITLE_2VTEXT },
132};
133
134static void fillLayoutValueSet( ValueSet* pValue, const snew_slide_value_info_layout* pInfo )
135{
136 Size aLayoutItemSize;
137 for( ; pInfo->mpStrResId; pInfo++ )
138 {
139 OUString aText(SdResId(pInfo->mpStrResId));
140 Image aImg(StockImage::Yes, pInfo->msBmpResId);
141 pValue->InsertItem(static_cast<sal_uInt16>(pInfo->maAutoLayout)+1, aImg, aText);
142 aLayoutItemSize.setWidth( std::max( aLayoutItemSize.Width(), aImg.GetSizePixel().Width() ) );
143 aLayoutItemSize.setHeight( std::max( aLayoutItemSize.Height(), aImg.GetSizePixel().Height() ) );
144 }
145
146 aLayoutItemSize = pValue->CalcItemSizePixel( aLayoutItemSize );
147 Size aSize(pValue->CalcWindowSizePixel(aLayoutItemSize));
148
149 const sal_Int32 LAYOUT_BORDER_PIX = 7;
150
151 aSize.AdjustWidth((pValue->GetColCount() + 1) * LAYOUT_BORDER_PIX);
152 aSize.AdjustHeight((pValue->GetLineCount() +1) * LAYOUT_BORDER_PIX);
153
154 pValue->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
155 pValue->SetOutputSizePixel(aSize);
156}
157
158LayoutToolbarMenu::LayoutToolbarMenu(SlideLayoutController* pControl, weld::Widget* pParent, const bool bInsertPage, const OUString& rCommand)
159 : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "modules/simpress/ui/layoutwindow.ui", "LayoutWindow")
160 , mxControl(pControl)
161 , mbInsertPage(bInsertPage)
162 , mxFrame1(m_xBuilder->weld_frame("horiframe"))
163 , mxLayoutSet1(new ValueSet(nullptr))
164 , mxLayoutSetWin1(new weld::CustomWeld(*m_xBuilder, "valueset1", *mxLayoutSet1))
165 , mxFrame2(m_xBuilder->weld_frame("vertframe"))
166 , mxLayoutSet2(new ValueSet(nullptr))
167 , mxLayoutSetWin2(new weld::CustomWeld(*m_xBuilder, "valueset2", *mxLayoutSet2))
168 , mxMoreButton(m_xBuilder->weld_button("more"))
169{
170 mxLayoutSet1->SetStyle(WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT);
171 mxLayoutSet2->SetStyle(WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT);
172
173 DrawViewMode eMode = DrawViewMode_DRAW;
174
175 // find out which view is running
176 if( m_xFrame.is() ) try
177 {
178 Reference< XPropertySet > xControllerSet( m_xFrame->getController(), UNO_QUERY_THROW );
179 xControllerSet->getPropertyValue( "DrawViewMode" ) >>= eMode;
180 }
181 catch( Exception& )
182 {
183 OSL_ASSERT(false);
184 }
185
186 const bool bVerticalEnabled = SvtCJKOptions::IsVerticalTextEnabled();
187
188 mxLayoutSet1->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectValueSetHdl ) );
189
190 const snew_slide_value_info_layout* pInfo = nullptr;
191 sal_Int16 nColCount = 4;
192 switch( eMode )
193 {
194 case DrawViewMode_DRAW: pInfo = &standard[0]; break;
195 case DrawViewMode_HANDOUT: pInfo = &handout[0]; nColCount = 2; break;
196 case DrawViewMode_NOTES: pInfo = &notes[0]; nColCount = 1; break;
197 default: assert(false); // can't happen, will crash later otherwise
198 }
199
200 mxLayoutSet1->SetColCount( nColCount );
201
202 fillLayoutValueSet( mxLayoutSet1.get(), pInfo );
203
204 bool bUseUILabel = (bVerticalEnabled && eMode == DrawViewMode_DRAW);
205 if (!bUseUILabel)
206 {
207 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(rCommand, mxControl->getModuleName());
208 mxFrame1->set_label(vcl::CommandInfoProvider::GetLabelForCommand(aProperties));
209 }
210
211 if (bVerticalEnabled && eMode == DrawViewMode_DRAW)
212 {
213 mxLayoutSet2->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectValueSetHdl ) );
214 mxLayoutSet2->SetColCount( 4 );
215 mxLayoutSet2->EnableFullItemMode( false );
216
217 fillLayoutValueSet( mxLayoutSet2.get(), &v_standard[0] );
218
219 mxFrame2->show();
220 }
221
222 if( eMode != DrawViewMode_DRAW )
223 return;
224
225 if( !m_xFrame.is() )
226 return;
227
228 OUString sSlotStr;
229
230 if( bInsertPage )
231 sSlotStr = ".uno:DuplicatePage";
232 else
233 sSlotStr = ".uno:Undo";
234
235 css::uno::Reference<css::graphic::XGraphic> xSlotImage = vcl::CommandInfoProvider::GetXGraphicForCommand(sSlotStr, m_xFrame);
236
237 OUString sSlotTitle;
238 if( bInsertPage )
239 {
240 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(sSlotStr, mxControl->getModuleName());
241 sSlotTitle = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
242 }
243 else
244 sSlotTitle = SdResId( STR_RESET_LAYOUT );
245
246 mxMoreButton->set_label(sSlotTitle);
247 mxMoreButton->set_image(xSlotImage);
248 mxMoreButton->connect_clicked(LINK(this, LayoutToolbarMenu, SelectToolbarMenuHdl));
249 mxMoreButton->show();
250}
251
252IMPL_LINK(LayoutToolbarMenu, SelectValueSetHdl, ValueSet*, pLayoutSet, void)
253{
254 SelectHdl(static_cast<AutoLayout>(pLayoutSet->GetSelectedItemId()-1));
255}
256
257IMPL_LINK_NOARG(LayoutToolbarMenu, SelectToolbarMenuHdl, weld::Button&, void)
258{
259 SelectHdl(AUTOLAYOUT_END);
260}
261
262void LayoutToolbarMenu::SelectHdl(AutoLayout eLayout)
263{
264 Sequence< PropertyValue > aArgs;
265
266 OUString sCommandURL( mxControl->getCommandURL() );
267
268 if( eLayout != AUTOLAYOUT_END )
269 {
270 aArgs = { comphelper::makePropertyValue("WhatLayout", static_cast<sal_Int32>(eLayout)) };
271 }
272 else if( mbInsertPage )
273 {
274 sCommandURL = ".uno:DuplicatePage";
275 }
276
277 mxControl->dispatchCommand( sCommandURL, aArgs );
278
279 mxControl->EndPopupMode();
280}
281
282
285{
286 return "com.sun.star.comp.sd.SlideLayoutController";
287}
288
291{
292 Sequence<OUString> aSNS { "com.sun.star.frame.ToolbarController" };
293 return aSNS;
294}
295
298{
299 return "com.sun.star.comp.sd.InsertSlideController";
300}
301
304{
305 Sequence<OUString> aSNS { "com.sun.star.frame.ToolbarController" };
306 return aSNS;
307}
308
309SlideLayoutController::SlideLayoutController(const Reference< uno::XComponentContext >& rxContext, bool bInsertPage)
310 : svt::PopupWindowController(rxContext, nullptr, OUString())
311 , mbInsertPage(bInsertPage)
312{
313}
314
315void SAL_CALL SlideLayoutController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
316{
317 svt::PopupWindowController::initialize( aArguments );
318
319 ToolBox* pToolBox = nullptr;
321 if ( getToolboxId( nId, &pToolBox ) )
322 {
323 if ( mbInsertPage )
324 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWN );
325 else
326 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
327 }
328}
329
330std::unique_ptr<WeldToolbarPopup> SlideLayoutController::weldPopupWindow()
331{
332 return std::make_unique<sd::LayoutToolbarMenu>(this, m_pToolbar, mbInsertPage, m_aCommandURL);
333}
334
336{
337 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
338 std::make_unique<sd::LayoutToolbarMenu>(this, pParent->GetFrameWeld(), mbInsertPage, m_aCommandURL));
339
340 mxInterimPopover->Show();
341
342 return mxInterimPopover;
343}
344
345// XServiceInfo
346
348{
349 if( mbInsertPage )
351 else
353}
354
356{
357 if( mbInsertPage )
359 else
361}
362
363}
364
365extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
367 css::uno::Sequence<css::uno::Any> const &)
368{
369 return cppu::acquire(new sd::SlideLayoutController(context, false));
370}
371
372extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
374 css::uno::Sequence<css::uno::Any> const &)
375{
376 return cppu::acquire(new sd::SlideLayoutController(context, true));
377}
378
379
380/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AutoLayout maAutoLayout
Definition: LayoutMenu.cxx:79
rtl::OUStringConstExpr msBmpResId
Definition: LayoutMenu.cxx:76
TranslateId mpStrResId
Definition: LayoutMenu.cxx:77
PropertiesInfo aProperties
css::uno::Reference< css::lang::XComponent > m_xFrame
AutoLayout
AUTOLAYOUT_TITLE_2CONTENT_OVER_CONTENT
AUTOLAYOUT_TITLE
AUTOLAYOUT_HANDOUT1
AUTOLAYOUT_TITLE_CONTENT_OVER_CONTENT
AUTOLAYOUT_TITLE_2VTEXT
AUTOLAYOUT_VTITLE_VCONTENT_OVER_VCONTENT
AUTOLAYOUT_VTITLE_VCONTENT
AUTOLAYOUT_TITLE_ONLY
AUTOLAYOUT_TITLE_2CONTENT
AUTOLAYOUT_ONLY_TEXT
AUTOLAYOUT_TITLE_6CONTENT
AUTOLAYOUT_HANDOUT9
AUTOLAYOUT_TITLE_2CONTENT_CONTENT
AUTOLAYOUT_HANDOUT2
AUTOLAYOUT_TITLE_CONTENT_2CONTENT
AUTOLAYOUT_HANDOUT4
AUTOLAYOUT_NONE
AUTOLAYOUT_END
AUTOLAYOUT_HANDOUT6
AUTOLAYOUT_NOTES
AUTOLAYOUT_TITLE_CONTENT
AUTOLAYOUT_HANDOUT3
AUTOLAYOUT_TITLE_VCONTENT
AUTOLAYOUT_TITLE_4CONTENT
Size GetSizePixel() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
ToolBoxItemBits GetItemBits(ToolBoxItemId nItemId) const
void SetItemBits(ToolBoxItemId nItemId, ToolBoxItemBits nBits)
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
Size CalcWindowSizePixel(const Size &rItemSize, sal_uInt16 nCalcCols=0, sal_uInt16 nCalcLines=0) const
Size CalcItemSizePixel(const Size &rSize) const
sal_uInt16 GetColCount() const
sal_uInt16 GetLineCount() const
static VclPtr< reference_type > Create(Arg &&... arg)
virtual OUString SAL_CALL getImplementationName() override
virtual std::unique_ptr< WeldToolbarPopup > weldPopupWindow() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual VclPtr< vcl::Window > createVclPopupWindow(vcl::Window *pParent) override
VclPtr< InterimToolbarPopup > mxInterimPopover
weld::Window * GetFrameWeld() const
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
float u
Sequence< PropertyValue > aArguments
Mode eMode
bool IsVerticalTextEnabled()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
IMPL_LINK(LayoutToolbarMenu, SelectValueSetHdl, ValueSet *, pLayoutSet, void)
IMPL_LINK_NOARG(LayoutToolbarMenu, SelectToolbarMenuHdl, weld::Button &, void)
const snew_slide_value_info_layout v_standard[]
static OUString SlideLayoutController_getImplementationName()
static Sequence< OUString > SlideLayoutController_getSupportedServiceNames()
const snew_slide_value_info_layout standard[]
static Sequence< OUString > InsertSlideController_getSupportedServiceNames()
const snew_slide_value_info_layout handout[]
const snew_slide_value_info_layout notes[]
constexpr OUStringLiteral EMPTY
static OUString InsertSlideController_getImplementationName()
static void fillLayoutValueSet(ValueSet *pValue, const snew_slide_value_info *pInfo)
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
OUString GetLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
sal_Int16 nId
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sd_SlideLayoutController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sd_InsertSlideController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)