Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/controller/displaymodecontroller.cxx
Line
Count
Source
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
10
#include <svtools/popupwindowcontroller.hxx>
11
#include <svtools/toolbarmenu.hxx>
12
#include <vcl/image.hxx>
13
#include <vcl/toolbox.hxx>
14
#include <vcl/weld/Builder.hxx>
15
#include <vcl/weld/Frame.hxx>
16
#include <vcl/weld/IconView.hxx>
17
#include <vcl/weld/Toolbar.hxx>
18
#include <vcl/weld/Window.hxx>
19
20
#include <strings.hrc>
21
22
#include <bitmaps.hlst>
23
#include <sdresid.hxx>
24
25
using namespace ::com::sun::star;
26
using namespace ::com::sun::star::uno;
27
using namespace ::com::sun::star::frame;
28
using namespace ::com::sun::star::beans;
29
30
namespace sd
31
{
32
33
// Component to select which display mode has to be used.
34
// Composed of a dropdown button in the toolbar and a
35
// popup menu to select the value
36
37
namespace {
38
39
class DisplayModeController : public svt::PopupWindowController
40
{
41
public:
42
    explicit DisplayModeController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
43
44
    virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
45
    virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
46
47
    // XInitialization
48
    virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
49
50
    // XServiceInfo
51
    virtual OUString SAL_CALL getImplementationName() override;
52
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
53
54
    void setToolboxItemImage(const OUString& rImage);
55
};
56
57
class DisplayModeToolbarMenu final : public WeldToolbarPopup
58
{
59
public:
60
    DisplayModeToolbarMenu(DisplayModeController* pControl, weld::Widget* pParent);
61
0
    virtual void GrabFocus() override { mxDisplayModeIconView1->grab_focus(); }
62
63
private:
64
    rtl::Reference<DisplayModeController> mxControl;
65
    std::unique_ptr<weld::Frame> mxFrame1;
66
    std::unique_ptr<weld::IconView> mxDisplayModeIconView1;
67
    std::unique_ptr<weld::Frame> mxFrame2;
68
    std::unique_ptr<weld::IconView> mxDisplayModeIconView2;
69
70
    DECL_LINK(ItemActivatedHdl, const weld::TreeIter&, bool);
71
};
72
73
struct snew_slide_value_info
74
{
75
    OUString msBmpResId;
76
    TranslateId mpStrResId;
77
    OUString msUnoCommand;
78
};
79
}
80
81
constexpr snew_slide_value_info editmodes[]
82
    = { { BMP_DISPLAYMODE_SLIDE, STR_NORMAL_MODE, u".uno:NormalMultiPaneGUI"_ustr },
83
        { BMP_DISPLAYMODE_OUTLINE, STR_OUTLINE_MODE, u".uno:OutlineMode"_ustr },
84
        { BMP_DISPLAYMODE_NOTES, STR_NOTES_MODE, u".uno:NotesMode"_ustr },
85
        { BMP_DISPLAYMODE_SLIDE_SORTER, STR_SLIDE_SORTER_MODE, u".uno:DiaMode"_ustr } };
86
87
constexpr snew_slide_value_info mastermodes[]
88
    = { { BMP_DISPLAYMODE_SLIDE_MASTER, STR_SLIDE_MASTER_MODE, u".uno:SlideMasterPage"_ustr },
89
        { BMP_DISPLAYMODE_NOTES_MASTER, STR_NOTES_MASTER_MODE, u".uno:NotesMasterPage"_ustr },
90
        { BMP_DISPLAYMODE_HANDOUT_MASTER, STR_HANDOUT_MASTER_MODE, u".uno:HandoutMode"_ustr } };
91
92
static void fillLayoutIconView(weld::IconView& rIconView,
93
                               std::span<const snew_slide_value_info> aInfos)
94
0
{
95
0
    int nIndex = 0;
96
0
    for (const snew_slide_value_info& rInfo : aInfos)
97
0
    {
98
0
        OUString aText(SdResId(rInfo.mpStrResId));
99
0
        Bitmap aBmp(rInfo.msBmpResId);
100
101
0
        rIconView.insert(nIndex, nullptr, nullptr, &aBmp, nullptr);
102
0
        rIconView.set_item_accessible_name(nIndex, aText);
103
0
        rIconView.set_item_tooltip_text(nIndex, aText);
104
105
0
        ++nIndex;
106
0
    }
107
0
}
108
109
DisplayModeToolbarMenu::DisplayModeToolbarMenu(DisplayModeController* pControl, weld::Widget* pParent)
110
0
    : WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"modules/simpress/ui/displaywindow.ui"_ustr, u"DisplayWindow"_ustr)
111
0
    , mxControl(pControl)
112
0
    , mxFrame1(m_xBuilder->weld_frame(u"editframe"_ustr))
113
0
    , mxDisplayModeIconView1(m_xBuilder->weld_icon_view(u"iconview1"_ustr))
114
0
    , mxFrame2(m_xBuilder->weld_frame(u"masterframe"_ustr))
115
0
    , mxDisplayModeIconView2(m_xBuilder->weld_icon_view(u"iconview2"_ustr))
116
0
{
117
0
    mxDisplayModeIconView1->connect_item_activated(
118
0
        LINK(this, DisplayModeToolbarMenu, ItemActivatedHdl));
119
0
    mxDisplayModeIconView2->connect_item_activated(
120
0
        LINK(this, DisplayModeToolbarMenu, ItemActivatedHdl));
121
122
0
    fillLayoutIconView(*mxDisplayModeIconView1, editmodes);
123
0
    fillLayoutIconView(*mxDisplayModeIconView2, mastermodes);
124
0
}
125
126
IMPL_LINK(DisplayModeToolbarMenu, ItemActivatedHdl, const weld::TreeIter&, rIter, bool)
127
0
{
128
0
    OUString sCommandURL;
129
0
    OUString sImage;
130
131
0
    const weld::ItemView& rItemView = rIter.getItemView();
132
0
    const int nIndex = rItemView.get_iter_index_in_parent(rIter);
133
0
    if (&rItemView == mxDisplayModeIconView1.get())
134
0
    {
135
0
        sCommandURL = editmodes[nIndex].msUnoCommand;
136
0
        sImage = editmodes[nIndex].msBmpResId;
137
0
    }
138
0
    else if (&rItemView == mxDisplayModeIconView2.get())
139
0
    {
140
0
        sCommandURL = mastermodes[nIndex].msUnoCommand;
141
0
        sImage = mastermodes[nIndex].msBmpResId;
142
0
    }
143
144
0
    if (!sCommandURL.isEmpty())
145
0
        mxControl->dispatchCommand( sCommandURL, Sequence< PropertyValue >() );
146
147
0
    mxControl->setToolboxItemImage(sImage);
148
0
    mxControl->EndPopupMode();
149
150
0
    return true;
151
0
}
152
153
DisplayModeController::DisplayModeController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
154
0
: svt::PopupWindowController( rxContext, Reference< frame::XFrame >(), OUString() )
155
0
{
156
0
}
157
158
void SAL_CALL DisplayModeController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
159
0
{
160
0
    svt::PopupWindowController::initialize( aArguments );
161
0
    ToolBox* pToolBox = nullptr;
162
0
    ToolBoxItemId nId;
163
0
    if ( getToolboxId( nId, &pToolBox ) )
164
0
        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
165
0
    setToolboxItemImage(BMP_DISPLAYMODE_SLIDE);
166
0
}
167
168
std::unique_ptr<WeldToolbarPopup> DisplayModeController::weldPopupWindow()
169
0
{
170
0
    return std::make_unique<sd::DisplayModeToolbarMenu>(this, m_pToolbar);
171
0
}
172
173
VclPtr<vcl::Window> DisplayModeController::createVclPopupWindow( vcl::Window* pParent )
174
0
{
175
0
    mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
176
0
        std::make_unique<sd::DisplayModeToolbarMenu>(this, pParent->GetFrameWeld()));
177
178
0
    mxInterimPopover->Show();
179
180
0
    return mxInterimPopover;
181
0
}
182
183
void DisplayModeController::setToolboxItemImage(const OUString& rImage)
184
0
{
185
0
    ToolBoxItemId nId;
186
0
    ToolBox* pToolBox = nullptr;
187
0
    if (!getToolboxId( nId, &pToolBox ))
188
0
        return;
189
190
0
    Bitmap aBmp(rImage);
191
0
    int targetSize = (pToolBox->GetToolboxButtonSize() == ToolBoxButtonSize::Large) ? 32 : 16;
192
0
    double scale = 1.0f;
193
0
    Size size = aBmp.GetSizePixel();
194
0
    if (size.Width() > targetSize)
195
0
        scale = static_cast<double>(targetSize) / static_cast<double>(size.Width());
196
0
    if (size.Height() > targetSize)
197
0
        scale = ::std::min( scale, static_cast<double>(targetSize) / static_cast<double>(size.Height()) );
198
0
    aBmp.Scale( scale, scale );
199
0
    pToolBox->SetItemImage( nId, Image( aBmp ) );
200
0
}
201
202
// XServiceInfo
203
204
OUString SAL_CALL DisplayModeController::getImplementationName()
205
0
{
206
0
    return u"com.sun.star.comp.sd.DisplayModeController"_ustr;
207
0
}
208
209
Sequence< OUString > SAL_CALL DisplayModeController::getSupportedServiceNames(  )
210
0
{
211
0
    css::uno::Sequence<OUString> aRet { u"com.sun.star.frame.ToolbarController"_ustr };
212
0
    return aRet;
213
0
}
214
215
}
216
217
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
218
com_sun_star_comp_sd_DisplayModeController_get_implementation( css::uno::XComponentContext* context,
219
                                                               css::uno::Sequence<css::uno::Any> const &)
220
0
{
221
0
    return cppu::acquire(new sd::DisplayModeController(context));
222
0
}
223
224
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */