Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/inc/galbrws1.hxx
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
 * 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
#pragma once
21
22
#include <svl/lstner.hxx>
23
#include <vcl/transfer.hxx>
24
#include <vcl/weld/Button.hxx>
25
#include <vcl/weld/Entry.hxx>
26
#include <vcl/weld/Label.hxx>
27
#include <vcl/weld/ToggleButton.hxx>
28
#include <vcl/weld/TreeView.hxx>
29
#include <vcl/weld/customweld.hxx>
30
#include <svx/galmisc.hxx>
31
#include <svx/galctrl.hxx>
32
#include <unotools/charclass.hxx>
33
#include <vector>
34
#include <com/sun/star/util/XURLTransformer.hpp>
35
#include <com/sun/star/frame/XDispatch.hpp>
36
#include <com/sun/star/frame/XFrame.hpp>
37
#include <com/sun/star/uno/XComponentContext.hpp>
38
39
class Gallery;
40
class GalleryThemeEntry;
41
class GalleryTheme;
42
struct ExchangeData;
43
class SfxItemSet;
44
class GalleryDragDrop;
45
class GalleryIconView;
46
class GalleryPreview;
47
class SgaObject;
48
49
enum GalleryBrowserMode
50
{
51
    GALLERYBROWSERMODE_NONE = 0,
52
    GALLERYBROWSERMODE_ICON = 1,
53
    GALLERYBROWSERMODE_LIST = 2,
54
    GALLERYBROWSERMODE_PREVIEW = 3
55
};
56
57
enum class GalleryBrowserTravel
58
{
59
    First,
60
    Last,
61
    Previous,
62
    Next
63
};
64
65
enum class GalleryItemFlags
66
{
67
    Title = 0x0002,
68
    Path = 0x0004
69
};
70
namespace o3tl
71
{
72
template <> struct typed_flags<GalleryItemFlags> : is_typed_flags<GalleryItemFlags, 0x0006>
73
{
74
};
75
}
76
77
namespace svx::sidebar
78
{
79
class GalleryControl;
80
}
81
82
struct ThemeEntry
83
{
84
    OUString maThemeName;
85
    OUString maEntryTitle;
86
    size_t mnIdInTheme;
87
88
    ThemeEntry(const OUString& rThemeName, const OUString& rEntryTitle, size_t nId)
89
0
        : maThemeName(rThemeName)
90
0
        , maEntryTitle(rEntryTitle)
91
0
        , mnIdInTheme(nId)
92
0
    {
93
0
    }
94
};
95
typedef ::std::vector<ThemeEntry> GalleryThemeEntries;
96
97
class GalleryBrowser final : public SfxListener
98
{
99
    friend class svx::sidebar::GalleryControl;
100
101
private:
102
    std::unique_ptr<weld::Button> mxNewTheme;
103
    std::unique_ptr<weld::TreeView> mxThemes;
104
    std::unique_ptr<weld::Button> mxMoreGalleries;
105
    Gallery* mpGallery;
106
    std::unique_ptr<ExchangeData> mpExchangeData;
107
    std::unique_ptr<SfxItemSet> mpThemePropsDlgItemSet;
108
109
    OUString aImgNormal;
110
    OUString aImgDefault;
111
    OUString aImgReadOnly;
112
113
    GalleryTheme* mpCurTheme;
114
    std::unique_ptr<GalleryIconView> mxIconView;
115
    std::unique_ptr<weld::CustomWeld> mxIconViewWin;
116
    std::unique_ptr<weld::TreeView> mxListView;
117
    std::unique_ptr<GalleryDragDrop> mxDragDropTargetHelper;
118
    std::unique_ptr<GalleryPreview> mxPreview;
119
    std::unique_ptr<weld::CustomWeld> mxPreviewWin;
120
    std::unique_ptr<weld::ToggleButton> mxIconButton;
121
    std::unique_ptr<weld::ToggleButton> mxListButton;
122
    std::unique_ptr<weld::Entry> mxSearchField;
123
    std::unique_ptr<weld::Label> mxInfoBar;
124
    Size maPreviewSize;
125
    rtl::Reference<GalleryTransferable> m_xHelper;
126
    sal_uInt32 mnCurActionPos;
127
    GalleryBrowserMode meMode;
128
    GalleryBrowserMode meLastMode;
129
130
    GalleryThemeEntries maAllThemeEntries;
131
    GalleryThemeEntries maFoundThemeEntries;
132
133
    css::uno::Reference<css::uno::XComponentContext> m_xContext;
134
    css::uno::Reference<css::util::XURLTransformer> m_xTransformer;
135
136
    CharClass m_aCharacterClassficator;
137
    SfxListener maLocalListener;
138
139
    void ImplInsertThemeEntry(const GalleryThemeEntry* pEntry);
140
    static void ImplFillExchangeData(const GalleryTheme& rThm, ExchangeData& rData);
141
    void ImplGetExecuteVector(std::vector<OUString>& o_aExec);
142
    void ImplExecute(std::u16string_view rIdent);
143
    void ImplGalleryThemeProperties(std::u16string_view rThemeName, bool bCreateNew);
144
    void EndNewThemePropertiesDlgHdl(sal_Int32 nResult);
145
    void EndThemePropertiesDlgHdl(sal_Int32 nResult);
146
    void ImplEndGalleryThemeProperties(bool bCreateNew, sal_Int32 nResult);
147
148
    void ImplUpdateViews(sal_uInt16 nSelectionId);
149
    void ImplUpdateInfoBar();
150
    sal_uInt32 ImplGetSelectedItemId(const Point* pSelPosPixel, Point& rSelPos);
151
    void ImplSelectItemId(sal_uInt32 nItemId);
152
    void ImplUpdateSelection();
153
    void UpdateRows(bool bVisibleOnly);
154
    void FillThemeEntries();
155
156
    // SfxListener
157
    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
158
159
    DECL_LINK(ClickNewThemeHdl, weld::Button&, void);
160
    DECL_LINK(SelectThemeHdl, weld::ItemView&, void);
161
    DECL_LINK(PopupMenuHdl1, const CommandEvent&, bool);
162
    DECL_LINK(KeyInputHdl1, const KeyEvent&, bool);
163
    DECL_STATIC_LINK(GalleryBrowser, OnMoreGalleriesClick, weld::Button&, void);
164
165
    DECL_LINK(SelectObjectHdl, weld::ItemView&, void);
166
    DECL_LINK(SelectObjectValueSetHdl, ValueSet*, void);
167
    DECL_LINK(SelectTbxHdl, weld::Toggleable&, void);
168
    DECL_LINK(PopupMenuHdl2, const CommandEvent&, bool);
169
    DECL_LINK(KeyInputHdl2, const KeyEvent&, bool);
170
    DECL_LINK(RowActivatedHdl, const weld::TreeIter&, bool);
171
    DECL_LINK(DragBeginHdl, bool&, bool);
172
    DECL_LINK(VisRowsScrolledHdl, weld::TreeView&, void);
173
    DECL_LINK(SizeAllocHdl, const Size&, void);
174
    DECL_LINK(SearchHdl, weld::Entry&, void);
175
176
    static GalleryBrowserMode meInitMode;
177
178
public:
179
    GalleryBrowser(weld::Builder& rBuilder, Gallery* pGallery);
180
181
    ~GalleryBrowser();
182
183
    void SelectTheme(sal_uInt16 nThemePos)
184
0
    {
185
0
        mxThemes->select(nThemePos);
186
0
        SelectThemeHdl(*mxThemes);
187
0
    }
188
0
    OUString GetSelectedTheme() const { return mxThemes->get_selected_text(); }
189
190
    static OUString GetItemText(const SgaObject& rObj, GalleryItemFlags nItemTextFlags);
191
192
public:
193
    void SelectTheme(std::u16string_view rThemeName);
194
195
0
    GalleryBrowserMode GetMode() const { return meMode; }
196
    void SetMode(GalleryBrowserMode eMode);
197
198
    weld::Widget* GetViewWindow() const;
199
200
    void Travel(GalleryBrowserTravel eTravel);
201
202
    INetURLObject GetURL() const;
203
    OUString GetFilterName() const;
204
205
    sal_Int8 AcceptDrop(const DropTargetHelper& rTarget);
206
    sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt);
207
    bool StartDrag();
208
    void TogglePreview();
209
    bool ShowContextMenu(const CommandEvent& rCEvt);
210
    bool KeyInput(const KeyEvent& rEvt);
211
    bool ViewBoxHasFocus() const;
212
213
    static css::uno::Reference<css::frame::XFrame> GetFrame();
214
    const css::uno::Reference<css::util::XURLTransformer>& GetURLTransformer() const
215
0
    {
216
0
        return m_xTransformer;
217
0
    }
218
219
    void Execute(std::u16string_view rIdent);
220
    void DispatchAdd(const css::uno::Reference<css::frame::XDispatch>& rxDispatch,
221
                     const css::util::URL& rURL);
222
223
    DECL_STATIC_LINK(GalleryBrowser, AsyncDispatch_Impl, void*, void);
224
};
225
226
class GalleryDragDrop final : public DropTargetHelper
227
{
228
private:
229
    GalleryBrowser* m_pParent;
230
231
    virtual sal_Int8 AcceptDrop(const AcceptDropEvent& /*rEvt*/) override
232
0
    {
233
0
        return m_pParent->AcceptDrop(*this);
234
0
    }
235
236
    virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override
237
0
    {
238
0
        return m_pParent->ExecuteDrop(rEvt);
239
0
    }
240
241
public:
242
    GalleryDragDrop(GalleryBrowser* pParent,
243
                    const css::uno::Reference<css::datatransfer::dnd::XDropTarget>& rDropTarget)
244
0
        : DropTargetHelper(rDropTarget)
245
0
        , m_pParent(pParent)
246
0
    {
247
0
    }
248
};
249
250
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */