Update git submodules
[LibreOffice.git] / sd / source / ui / controller / displaymodecontroller.cxx
blob81ad2d19e4770bec9cf6564f6394447aebcddf1a
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/.
8 */
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;
25 namespace sd
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 namespace {
34 class DisplayModeController : public svt::PopupWindowController
36 public:
37 explicit DisplayModeController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
39 virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
40 virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
42 // XInitialization
43 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
45 // XServiceInfo
46 virtual OUString SAL_CALL getImplementationName() override;
47 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
49 void setToolboxItemImage(const OUString& rImage);
52 class DisplayModeToolbarMenu final : public WeldToolbarPopup
54 public:
55 DisplayModeToolbarMenu(DisplayModeController* pControl, weld::Widget* pParent);
56 virtual void GrabFocus() override
58 mxDisplayModeSet1->GrabFocus();
61 private:
62 rtl::Reference<DisplayModeController> mxControl;
63 std::unique_ptr<weld::Frame> mxFrame1;
64 std::unique_ptr<ValueSet> mxDisplayModeSet1;
65 std::unique_ptr<weld::CustomWeld> mxDisplayModeSetWin1;
66 std::unique_ptr<weld::Frame> mxFrame2;
67 std::unique_ptr<ValueSet> mxDisplayModeSet2;
68 std::unique_ptr<weld::CustomWeld> mxDisplayModeSetWin2;
70 DECL_LINK(SelectValueSetHdl, ValueSet*, void);
73 struct snew_slide_value_info
75 sal_uInt16 mnId;
76 OUString msBmpResId;
77 TranslateId mpStrResId;
78 const char* msUnoCommand;
83 const snew_slide_value_info editmodes[] =
85 {1,
86 BMP_DISPLAYMODE_SLIDE,
87 STR_NORMAL_MODE,
88 ".uno:NormalMultiPaneGUI" },
89 {2,
90 BMP_DISPLAYMODE_OUTLINE,
91 STR_OUTLINE_MODE,
92 ".uno:OutlineMode" },
93 {3,
94 BMP_DISPLAYMODE_NOTES,
95 STR_NOTES_MODE,
96 ".uno:NotesMode" },
97 {4,
98 BMP_DISPLAYMODE_SLIDE_SORTER,
99 STR_SLIDE_SORTER_MODE,
100 ".uno:DiaMode" },
101 {0, "", {}, "" }
104 const snew_slide_value_info mastermodes[] =
107 BMP_DISPLAYMODE_SLIDE_MASTER,
108 STR_SLIDE_MASTER_MODE,
109 ".uno:SlideMasterPage" },
111 BMP_DISPLAYMODE_NOTES_MASTER,
112 STR_NOTES_MASTER_MODE,
113 ".uno:NotesMasterPage" },
115 BMP_DISPLAYMODE_HANDOUT_MASTER,
116 STR_HANDOUT_MASTER_MODE,
117 ".uno:HandoutMode" },
118 {0, "", {}, "" }
122 static void fillLayoutValueSet(ValueSet* pValue, const snew_slide_value_info* pInfo)
124 Size aLayoutItemSize;
125 for( ; pInfo->mnId; pInfo++ )
127 OUString aText(SdResId(pInfo->mpStrResId));
128 BitmapEx aBmp(pInfo->msBmpResId);
130 pValue->InsertItem(pInfo->mnId, Image(aBmp), aText);
132 aLayoutItemSize.setWidth( std::max( aLayoutItemSize.Width(), aBmp.GetSizePixel().Width() ) );
133 aLayoutItemSize.setHeight( std::max( aLayoutItemSize.Height(), aBmp.GetSizePixel().Height() ) );
136 aLayoutItemSize = pValue->CalcItemSizePixel( aLayoutItemSize );
137 Size aSize(pValue->CalcWindowSizePixel(aLayoutItemSize));
139 const sal_Int32 LAYOUT_BORDER_PIX = 7;
140 aSize.AdjustWidth((pValue->GetColCount() + 1) * LAYOUT_BORDER_PIX );
141 aSize.AdjustHeight((pValue->GetLineCount() +1) * LAYOUT_BORDER_PIX );
143 pValue->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
144 pValue->SetOutputSizePixel(aSize);
147 DisplayModeToolbarMenu::DisplayModeToolbarMenu(DisplayModeController* pControl, weld::Widget* pParent)
148 : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "modules/simpress/ui/displaywindow.ui", "DisplayWindow")
149 , mxControl(pControl)
150 , mxFrame1(m_xBuilder->weld_frame("editframe"))
151 , mxDisplayModeSet1(new ValueSet(nullptr))
152 , mxDisplayModeSetWin1(new weld::CustomWeld(*m_xBuilder, "valueset1", *mxDisplayModeSet1))
153 , mxFrame2(m_xBuilder->weld_frame("masterframe"))
154 , mxDisplayModeSet2(new ValueSet(nullptr))
155 , mxDisplayModeSetWin2(new weld::CustomWeld(*m_xBuilder, "valueset2", *mxDisplayModeSet2))
157 mxDisplayModeSet1->SetStyle(WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT);
158 mxDisplayModeSet1->SetStyle(WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT);
160 mxDisplayModeSet1->SetSelectHdl( LINK( this, DisplayModeToolbarMenu, SelectValueSetHdl ) );
161 mxDisplayModeSet2->SetSelectHdl( LINK( this, DisplayModeToolbarMenu, SelectValueSetHdl ) );
163 sal_Int16 nColCount = 2;
165 mxDisplayModeSet1->SetColCount( nColCount );
166 fillLayoutValueSet( mxDisplayModeSet1.get(), &editmodes[0] );
168 mxDisplayModeSet2->SetColCount( nColCount );
169 fillLayoutValueSet( mxDisplayModeSet2.get(), &mastermodes[0] );
172 IMPL_LINK( DisplayModeToolbarMenu, SelectValueSetHdl, ValueSet*, pControl, void )
174 OUString sCommandURL;
175 OUString sImage;
177 if( pControl == mxDisplayModeSet1.get() ) {
178 sCommandURL = OUString::createFromAscii(editmodes[mxDisplayModeSet1->GetSelectedItemId() - 1 ].msUnoCommand);
179 sImage = editmodes[mxDisplayModeSet1->GetSelectedItemId() - 1 ].msBmpResId;
181 else if( pControl == mxDisplayModeSet2.get() ) {
182 sCommandURL = OUString::createFromAscii(mastermodes[mxDisplayModeSet2->GetSelectedItemId() - 5 ].msUnoCommand);
183 sImage = mastermodes[mxDisplayModeSet2->GetSelectedItemId() - 5 ].msBmpResId;
186 if (!sCommandURL.isEmpty())
187 mxControl->dispatchCommand( sCommandURL, Sequence< PropertyValue >() );
189 mxControl->setToolboxItemImage(sImage);
190 mxControl->EndPopupMode();
193 DisplayModeController::DisplayModeController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
194 : svt::PopupWindowController( rxContext, Reference< frame::XFrame >(), OUString() )
198 void SAL_CALL DisplayModeController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
200 svt::PopupWindowController::initialize( aArguments );
201 ToolBox* pToolBox = nullptr;
202 ToolBoxItemId nId;
203 if ( getToolboxId( nId, &pToolBox ) )
204 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
205 setToolboxItemImage(BMP_DISPLAYMODE_SLIDE);
208 std::unique_ptr<WeldToolbarPopup> DisplayModeController::weldPopupWindow()
210 return std::make_unique<sd::DisplayModeToolbarMenu>(this, m_pToolbar);
213 VclPtr<vcl::Window> DisplayModeController::createVclPopupWindow( vcl::Window* pParent )
215 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
216 std::make_unique<sd::DisplayModeToolbarMenu>(this, pParent->GetFrameWeld()));
218 mxInterimPopover->Show();
220 return mxInterimPopover;
223 void DisplayModeController::setToolboxItemImage(const OUString& rImage)
225 ToolBoxItemId nId;
226 ToolBox* pToolBox = nullptr;
227 if (!getToolboxId( nId, &pToolBox ))
228 return;
230 BitmapEx aBmp(rImage);
231 int targetSize = (pToolBox->GetToolboxButtonSize() == ToolBoxButtonSize::Large) ? 32 : 16;
232 double scale = 1.0f;
233 Size size = aBmp.GetSizePixel();
234 if (size.Width() > targetSize)
235 scale = static_cast<double>(targetSize) / static_cast<double>(size.Width());
236 if (size.Height() > targetSize)
237 scale = ::std::min( scale, static_cast<double>(targetSize) / static_cast<double>(size.Height()) );
238 aBmp.Scale( scale, scale );
239 pToolBox->SetItemImage( nId, Image( aBmp ) );
242 // XServiceInfo
244 OUString SAL_CALL DisplayModeController::getImplementationName()
246 return "com.sun.star.comp.sd.DisplayModeController";
249 Sequence< OUString > SAL_CALL DisplayModeController::getSupportedServiceNames( )
251 css::uno::Sequence<OUString> aRet { "com.sun.star.frame.ToolbarController" };
252 return aRet;
257 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface*
258 com_sun_star_comp_sd_DisplayModeController_get_implementation( css::uno::XComponentContext* context,
259 css::uno::Sequence<css::uno::Any> const &)
261 return cppu::acquire(new sd::DisplayModeController(context));
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */