Coverage Report

Created: 2025-07-07 10:01

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