android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / controller / slidelayoutcontroller.cxx
blob251548a223535bfffa6e96ea5f264e86a236a633
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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::lang;
45 using namespace ::com::sun::star::frame;
46 using namespace ::com::sun::star::drawing;
47 using namespace ::com::sun::star::beans;
49 namespace sd
52 namespace {
54 class LayoutToolbarMenu : public WeldToolbarPopup
56 public:
57 LayoutToolbarMenu(SlideLayoutController* pController, weld::Widget* pParent, const bool bInsertPage, const OUString& rCommand);
58 virtual void GrabFocus() override
60 mxLayoutSet1->GrabFocus();
63 protected:
64 DECL_LINK(SelectToolbarMenuHdl, weld::Button&, void);
65 DECL_LINK(SelectValueSetHdl, ValueSet*, void);
66 void SelectHdl(AutoLayout eLayout);
67 private:
68 rtl::Reference<SlideLayoutController> mxControl;
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;
79 struct snew_slide_value_info_layout
81 rtl::OUStringConstExpr msBmpResId;
82 TranslateId mpStrResId;
83 AutoLayout maAutoLayout;
88 constexpr OUStringLiteral EMPTY = u"";
90 const snew_slide_value_info_layout notes[] =
92 {BMP_SLIDEN_01, STR_AUTOLAYOUT_NOTES, AUTOLAYOUT_NOTES},
93 {EMPTY, {}, AUTOLAYOUT_NONE},
96 const snew_slide_value_info_layout handout[] =
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},
107 const snew_slide_value_info_layout standard[] =
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 },
121 {EMPTY, {}, AUTOLAYOUT_NONE}
124 const snew_slide_value_info_layout v_standard[] =
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 },
131 {EMPTY, {}, AUTOLAYOUT_NONE}
134 static void fillLayoutValueSet( ValueSet* pValue, const snew_slide_value_info_layout* pInfo )
136 Size aLayoutItemSize;
137 for( ; pInfo->mpStrResId; pInfo++ )
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() ) );
146 aLayoutItemSize = pValue->CalcItemSizePixel( aLayoutItemSize );
147 Size aSize(pValue->CalcWindowSizePixel(aLayoutItemSize));
149 const sal_Int32 LAYOUT_BORDER_PIX = 7;
151 aSize.AdjustWidth((pValue->GetColCount() + 1) * LAYOUT_BORDER_PIX);
152 aSize.AdjustHeight((pValue->GetLineCount() +1) * LAYOUT_BORDER_PIX);
154 pValue->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
155 pValue->SetOutputSizePixel(aSize);
158 LayoutToolbarMenu::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"))
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);
173 DrawViewMode eMode = DrawViewMode_DRAW;
175 // find out which view is running
176 if( m_xFrame.is() ) try
178 Reference< XPropertySet > xControllerSet( m_xFrame->getController(), UNO_QUERY_THROW );
179 xControllerSet->getPropertyValue( "DrawViewMode" ) >>= eMode;
181 catch( Exception& )
183 OSL_ASSERT(false);
186 const bool bVerticalEnabled = SvtCJKOptions::IsVerticalTextEnabled();
188 mxLayoutSet1->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectValueSetHdl ) );
190 const snew_slide_value_info_layout* pInfo = nullptr;
191 sal_Int16 nColCount = 4;
192 switch( eMode )
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
200 mxLayoutSet1->SetColCount( nColCount );
202 fillLayoutValueSet( mxLayoutSet1.get(), pInfo );
204 bool bUseUILabel = (bVerticalEnabled && eMode == DrawViewMode_DRAW);
205 if (!bUseUILabel)
207 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(rCommand, mxControl->getModuleName());
208 mxFrame1->set_label(vcl::CommandInfoProvider::GetLabelForCommand(aProperties));
211 if (bVerticalEnabled && eMode == DrawViewMode_DRAW)
213 mxLayoutSet2->SetSelectHdl( LINK( this, LayoutToolbarMenu, SelectValueSetHdl ) );
214 mxLayoutSet2->SetColCount( 4 );
215 mxLayoutSet2->EnableFullItemMode( false );
217 fillLayoutValueSet( mxLayoutSet2.get(), &v_standard[0] );
219 mxFrame2->show();
222 if( eMode != DrawViewMode_DRAW )
223 return;
225 if( !m_xFrame.is() )
226 return;
228 OUString sSlotStr;
230 if( bInsertPage )
231 sSlotStr = ".uno:DuplicatePage";
232 else
233 sSlotStr = ".uno:Undo";
235 css::uno::Reference<css::graphic::XGraphic> xSlotImage = vcl::CommandInfoProvider::GetXGraphicForCommand(sSlotStr, m_xFrame);
237 OUString sSlotTitle;
238 if( bInsertPage )
240 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(sSlotStr, mxControl->getModuleName());
241 sSlotTitle = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
243 else
244 sSlotTitle = SdResId( STR_RESET_LAYOUT );
246 mxMoreButton->set_label(sSlotTitle);
247 mxMoreButton->set_image(xSlotImage);
248 mxMoreButton->connect_clicked(LINK(this, LayoutToolbarMenu, SelectToolbarMenuHdl));
249 mxMoreButton->show();
252 IMPL_LINK(LayoutToolbarMenu, SelectValueSetHdl, ValueSet*, pLayoutSet, void)
254 SelectHdl(static_cast<AutoLayout>(pLayoutSet->GetSelectedItemId()-1));
257 IMPL_LINK_NOARG(LayoutToolbarMenu, SelectToolbarMenuHdl, weld::Button&, void)
259 SelectHdl(AUTOLAYOUT_END);
262 void LayoutToolbarMenu::SelectHdl(AutoLayout eLayout)
264 Sequence< PropertyValue > aArgs;
266 OUString sCommandURL( mxControl->getCommandURL() );
268 if( eLayout != AUTOLAYOUT_END )
270 aArgs = { comphelper::makePropertyValue("WhatLayout", static_cast<sal_Int32>(eLayout)) };
272 else if( mbInsertPage )
274 sCommandURL = ".uno:DuplicatePage";
277 mxControl->dispatchCommand( sCommandURL, aArgs );
279 mxControl->EndPopupMode();
283 /// @throws css::uno::RuntimeException
284 static OUString SlideLayoutController_getImplementationName()
286 return "com.sun.star.comp.sd.SlideLayoutController";
289 /// @throws RuntimeException
290 static Sequence< OUString > SlideLayoutController_getSupportedServiceNames()
292 Sequence<OUString> aSNS { "com.sun.star.frame.ToolbarController" };
293 return aSNS;
296 /// @throws css::uno::RuntimeException
297 static OUString InsertSlideController_getImplementationName()
299 return "com.sun.star.comp.sd.InsertSlideController";
302 /// @throws RuntimeException
303 static Sequence< OUString > InsertSlideController_getSupportedServiceNames()
305 Sequence<OUString> aSNS { "com.sun.star.frame.ToolbarController" };
306 return aSNS;
309 SlideLayoutController::SlideLayoutController(const Reference< uno::XComponentContext >& rxContext, bool bInsertPage)
310 : svt::PopupWindowController(rxContext, nullptr, OUString())
311 , mbInsertPage(bInsertPage)
315 void SAL_CALL SlideLayoutController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
317 svt::PopupWindowController::initialize( aArguments );
319 ToolBox* pToolBox = nullptr;
320 ToolBoxItemId nId;
321 if ( getToolboxId( nId, &pToolBox ) )
323 if ( mbInsertPage )
324 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWN );
325 else
326 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
330 std::unique_ptr<WeldToolbarPopup> SlideLayoutController::weldPopupWindow()
332 return std::make_unique<sd::LayoutToolbarMenu>(this, m_pToolbar, mbInsertPage, m_aCommandURL);
335 VclPtr<vcl::Window> SlideLayoutController::createVclPopupWindow( vcl::Window* pParent )
337 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
338 std::make_unique<sd::LayoutToolbarMenu>(this, pParent->GetFrameWeld(), mbInsertPage, m_aCommandURL));
340 mxInterimPopover->Show();
342 return mxInterimPopover;
345 // XServiceInfo
347 OUString SAL_CALL SlideLayoutController::getImplementationName()
349 if( mbInsertPage )
350 return InsertSlideController_getImplementationName();
351 else
352 return SlideLayoutController_getImplementationName();
355 Sequence< OUString > SAL_CALL SlideLayoutController::getSupportedServiceNames( )
357 if( mbInsertPage )
358 return InsertSlideController_getSupportedServiceNames();
359 else
360 return SlideLayoutController_getSupportedServiceNames();
365 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
366 com_sun_star_comp_sd_SlideLayoutController_get_implementation(css::uno::XComponentContext* context,
367 css::uno::Sequence<css::uno::Any> const &)
369 return cppu::acquire(new sd::SlideLayoutController(context, false));
372 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
373 com_sun_star_comp_sd_InsertSlideController_get_implementation(css::uno::XComponentContext* context,
374 css::uno::Sequence<css::uno::Any> const &)
376 return cppu::acquire(new sd::SlideLayoutController(context, true));
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */