LibreOffice Module sd (master) 1
displaymodecontroller.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
12#include <svtools/valueset.hxx>
13#include <vcl/toolbox.hxx>
14
15#include <strings.hrc>
16
17#include <bitmaps.hlst>
18#include <sdresid.hxx>
19
20using namespace ::com::sun::star;
21using namespace ::com::sun::star::uno;
22using namespace ::com::sun::star::frame;
23using namespace ::com::sun::star::beans;
24
25namespace sd
26{
27
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
31
32namespace {
33
34class DisplayModeController : public svt::PopupWindowController
35{
36public:
37 explicit DisplayModeController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
38
39 virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
40 virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
41
42 // XInitialization
43 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
44
45 // XServiceInfo
46 virtual OUString SAL_CALL getImplementationName() override;
47 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
48
49 void setToolboxItemImage(const OUString& rImage);
50};
51
52class DisplayModeToolbarMenu final : public WeldToolbarPopup
53{
54public:
55 DisplayModeToolbarMenu(DisplayModeController* pControl, weld::Widget* pParent);
56 virtual void GrabFocus() override
57 {
58 mxDisplayModeSet1->GrabFocus();
59 }
60
61private:
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;
69
70 DECL_LINK(SelectValueSetHdl, ValueSet*, void);
71};
72
73struct snew_slide_value_info
74{
75 sal_uInt16 mnId;
76 OUString msBmpResId;
78 const char* msUnoCommand;
79};
80
81}
82
83const snew_slide_value_info editmodes[] =
84{
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, "", {}, "" }
102};
103
104const snew_slide_value_info mastermodes[] =
105{
106 {5,
107 BMP_DISPLAYMODE_SLIDE_MASTER,
108 STR_SLIDE_MASTER_MODE,
109 ".uno:SlideMasterPage" },
110 {6,
111 BMP_DISPLAYMODE_NOTES_MASTER,
112 STR_NOTES_MASTER_MODE,
113 ".uno:NotesMasterPage" },
114 {7,
115 BMP_DISPLAYMODE_HANDOUT_MASTER,
116 STR_HANDOUT_MASTER_MODE,
117 ".uno:HandoutMode" },
118 {0, "", {}, "" }
119};
120
121
122static void fillLayoutValueSet(ValueSet* pValue, const snew_slide_value_info* pInfo)
123{
124 Size aLayoutItemSize;
125 for( ; pInfo->mnId; pInfo++ )
126 {
127 OUString aText(SdResId(pInfo->mpStrResId));
128 BitmapEx aBmp(pInfo->msBmpResId);
129
130 pValue->InsertItem(pInfo->mnId, Image(aBmp), aText);
131
132 aLayoutItemSize.setWidth( std::max( aLayoutItemSize.Width(), aBmp.GetSizePixel().Width() ) );
133 aLayoutItemSize.setHeight( std::max( aLayoutItemSize.Height(), aBmp.GetSizePixel().Height() ) );
134 }
135
136 aLayoutItemSize = pValue->CalcItemSizePixel( aLayoutItemSize );
137 Size aSize(pValue->CalcWindowSizePixel(aLayoutItemSize));
138
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 );
142
143 pValue->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
144 pValue->SetOutputSizePixel(aSize);
145}
146
147DisplayModeToolbarMenu::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))
156{
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);
159
160 mxDisplayModeSet1->SetSelectHdl( LINK( this, DisplayModeToolbarMenu, SelectValueSetHdl ) );
161 mxDisplayModeSet2->SetSelectHdl( LINK( this, DisplayModeToolbarMenu, SelectValueSetHdl ) );
162
163 sal_Int16 nColCount = 2;
164
165 mxDisplayModeSet1->SetColCount( nColCount );
166 fillLayoutValueSet( mxDisplayModeSet1.get(), &editmodes[0] );
167
168 mxDisplayModeSet2->SetColCount( nColCount );
169 fillLayoutValueSet( mxDisplayModeSet2.get(), &mastermodes[0] );
170}
171
172IMPL_LINK( DisplayModeToolbarMenu, SelectValueSetHdl, ValueSet*, pControl, void )
173{
174 OUString sCommandURL;
175 OUString sImage;
176
177 if( pControl == mxDisplayModeSet1.get() ) {
178 sCommandURL = OUString::createFromAscii(editmodes[mxDisplayModeSet1->GetSelectedItemId() - 1 ].msUnoCommand);
179 sImage = editmodes[mxDisplayModeSet1->GetSelectedItemId() - 1 ].msBmpResId;
180 }
181 else if( pControl == mxDisplayModeSet2.get() ) {
182 sCommandURL = OUString::createFromAscii(mastermodes[mxDisplayModeSet2->GetSelectedItemId() - 5 ].msUnoCommand);
183 sImage = mastermodes[mxDisplayModeSet2->GetSelectedItemId() - 5 ].msBmpResId;
184 }
185
186 if (!sCommandURL.isEmpty())
187 mxControl->dispatchCommand( sCommandURL, Sequence< PropertyValue >() );
188
189 mxControl->setToolboxItemImage(sImage);
190 mxControl->EndPopupMode();
191}
192
193DisplayModeController::DisplayModeController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
194: svt::PopupWindowController( rxContext, Reference< frame::XFrame >(), OUString() )
195{
196}
197
198void SAL_CALL DisplayModeController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
199{
200 svt::PopupWindowController::initialize( aArguments );
201 ToolBox* pToolBox = nullptr;
203 if ( getToolboxId( nId, &pToolBox ) )
204 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
205 setToolboxItemImage(BMP_DISPLAYMODE_SLIDE);
206}
207
208std::unique_ptr<WeldToolbarPopup> DisplayModeController::weldPopupWindow()
209{
210 return std::make_unique<sd::DisplayModeToolbarMenu>(this, m_pToolbar);
211}
212
213VclPtr<vcl::Window> DisplayModeController::createVclPopupWindow( vcl::Window* pParent )
214{
215 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
216 std::make_unique<sd::DisplayModeToolbarMenu>(this, pParent->GetFrameWeld()));
217
218 mxInterimPopover->Show();
219
220 return mxInterimPopover;
221}
222
223void DisplayModeController::setToolboxItemImage(const OUString& rImage)
224{
226 ToolBox* pToolBox = nullptr;
227 if (!getToolboxId( nId, &pToolBox ))
228 return;
229
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 ) );
240}
241
242// XServiceInfo
243
244OUString SAL_CALL DisplayModeController::getImplementationName()
245{
246 return "com.sun.star.comp.sd.DisplayModeController";
247}
248
249Sequence< OUString > SAL_CALL DisplayModeController::getSupportedServiceNames( )
250{
251 css::uno::Sequence<OUString> aRet { "com.sun.star.frame.ToolbarController" };
252 return aRet;
253}
254
255}
256
257extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface*
259 css::uno::Sequence<css::uno::Any> const &)
260{
261 return cppu::acquire(new sd::DisplayModeController(context));
262}
263
264/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::OUStringConstExpr msBmpResId
Definition: LayoutMenu.cxx:76
TranslateId mpStrResId
Definition: LayoutMenu.cxx:77
const 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
ToolBoxButtonSize GetToolboxButtonSize() const
void SetItemImage(ToolBoxItemId nItemId, const Image &rImage)
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)
weld::Window * GetFrameWeld() const
sal_uInt16 mnId
SAL_DLLPUBLIC_EXPORT::com::sun::star::uno::XInterface * com_sun_star_comp_sd_DisplayModeController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
size
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
Reference
const snew_slide_value_info editmodes[]
IMPL_LINK(DisplayModeToolbarMenu, SelectValueSetHdl, ValueSet *, pControl, void)
const snew_slide_value_info mastermodes[]
static void fillLayoutValueSet(ValueSet *pValue, const snew_slide_value_info *pInfo)
sal_Int16 nId
sal_Int32 scale
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83