Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/sfx2/templatelocalview.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
10
#ifndef INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
11
#define INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
12
13
#include <sfx2/thumbnailview.hxx>
14
#include <functional>
15
#include <memory>
16
#include <set>
17
18
//template thumbnail item defines
19
0
#define TEMPLATE_ITEM_MAX_WIDTH 160
20
0
#define TEMPLATE_ITEM_MAX_HEIGHT 148
21
0
#define TEMPLATE_ITEM_PADDING 5
22
0
#define TEMPLATE_ITEM_MAX_TEXT_LENGTH 20
23
0
#define TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT 96
24
25
//template thumbnail height with a subtitle
26
0
#define TEMPLATE_ITEM_MAX_HEIGHT_SUB 160
27
28
//template thumbnail image defines
29
0
#define TEMPLATE_THUMBNAIL_MAX_HEIGHT TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT - 2*TEMPLATE_ITEM_PADDING
30
0
#define TEMPLATE_THUMBNAIL_MAX_WIDTH TEMPLATE_ITEM_MAX_WIDTH - 2*TEMPLATE_ITEM_PADDING
31
32
class SfxDocumentTemplates;
33
class TemplateContainerItem;
34
class TemplateViewItem;
35
struct TemplateItemProperties;
36
37
namespace weld { class Menu; }
38
39
enum class FILTER_APPLICATION
40
{
41
    NONE,
42
    WRITER,
43
    CALC,
44
    IMPRESS,
45
    DRAW
46
};
47
48
// Display template items depending on the generator application
49
class ViewFilter_Application final
50
{
51
public:
52
53
    ViewFilter_Application (FILTER_APPLICATION App)
54
0
        : mApp(App)
55
0
    {}
56
57
    bool operator () (const ThumbnailViewItem *pItem);
58
59
    static bool isFilteredExtension(FILTER_APPLICATION filter, std::u16string_view rExt);
60
    bool isValid (std::u16string_view rPath) const;
61
62
private:
63
64
    FILTER_APPLICATION mApp;
65
};
66
67
class TemplateLocalView : public ThumbnailView
68
{
69
    typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*);
70
71
public:
72
73
    TemplateLocalView(std::unique_ptr<weld::ScrolledWindow> xWindow,
74
                         std::unique_ptr<weld::Menu> xMenu);
75
76
    virtual ~TemplateLocalView () override;
77
78
    // Fill view with new item list
79
    void insertItems (const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected = true, bool bShowCategoryInTooltip = false);
80
81
    // Fill view with template folders thumbnails
82
    void Populate ();
83
84
    void reload ();
85
86
    virtual void showAllTemplates ();
87
88
    void showRegion (TemplateContainerItem const *pItem);
89
90
    void ContextMenuSelectHdl(std::u16string_view  rIdent);
91
92
    TemplateContainerItem* getRegion(std::u16string_view sStr);
93
94
    sal_uInt16 getRegionId (size_t pos) const;
95
96
    sal_uInt16 getRegionId (std::u16string_view sRegionName) const;
97
98
    OUString getRegionName(const sal_uInt16 nRegionId) const;
99
100
    OUString getRegionItemName(const sal_uInt16 nItemId) const;
101
102
    std::vector<OUString> getFolderNames ();
103
104
    std::vector<TemplateItemProperties>
105
        getFilteredItems (const std::function<bool (const TemplateItemProperties&) > &rFunc) const;
106
107
    sal_uInt16 createRegion (const OUString &rName);
108
109
    bool renameRegion(std::u16string_view rTitle, const OUString &rNewTitle);
110
111
    bool removeRegion (const sal_uInt16 nItemId);
112
113
    bool removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId);
114
115
    void moveTemplates(const std::set<const TemplateViewItem*, selection_cmp_fn>& rItems,
116
                       const sal_uInt16 nTargetItem);
117
118
    bool copyFrom(TemplateContainerItem *pItem, const OUString &rPath);
119
120
    bool exportTo (const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, std::u16string_view rName);
121
122
    virtual bool renameItem(ThumbnailViewItem& rItem, const OUString& sNewTitle) override;
123
124
    virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
125
126
    virtual bool Command(const CommandEvent& rPos) override;
127
128
    virtual bool KeyInput( const KeyEvent& rKEvt ) override;
129
130
0
    sal_uInt16 getCurRegionId () const { return mnCurRegionId;}
131
132
0
    void setCurRegionId (sal_uInt16 nCurRegionId) { mnCurRegionId = nCurRegionId;}
133
134
    void setOpenRegionHdl(const Link<void*,void> &rLink);
135
136
    void setCreateContextMenuHdl(const Link<TemplateViewItem*, void>& rLink);
137
138
    void setOpenTemplateHdl(const Link<const OUString&, void>& rLink);
139
140
    void setEditTemplateHdl(const Link<const OUString&, void>& rLink);
141
142
    void setDeleteTemplateHdl(const Link<void*,void> &rLink);
143
144
    void setDefaultTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
145
146
    void setMoveTemplateHdl(const Link<void*,void> &rLink);
147
148
    void setExportTemplateHdl(const Link<void*,void> &rLink);
149
150
    void updateThumbnailDimensions(tools::Long itemMaxSize);
151
152
    void RemoveDefaultTemplateIcon( std::u16string_view rPath);
153
154
    bool IsBuiltInRegion(const OUString& rRegionName);
155
156
    static Bitmap scaleImg (const Bitmap &rImg, tools::Long width, tools::Long height);
157
158
    static Bitmap getDefaultThumbnail( std::u16string_view rPath );
159
160
    static Bitmap fetchThumbnail (const OUString &msURL, tools::Long width, tools::Long height);
161
162
    static bool IsDefaultTemplate(const OUString& rPath);
163
164
    static bool IsInternalTemplate(const OUString& rPath);
165
166
protected:
167
    virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override;
168
169
    sal_uInt16 mnCurRegionId;
170
171
    TemplateViewItem* mpSelectedItem;
172
173
    tools::Long mnThumbnailWidth;
174
    tools::Long mnThumbnailHeight;
175
176
    Point maPosition; //store the point of click event
177
178
    Link<void*,void>              maOpenRegionHdl;
179
    Link<TemplateViewItem*, void> maCreateContextMenuHdl;
180
    Link<const OUString&, void> maOpenTemplateHdl;
181
    Link<const OUString&, void> maEditTemplateHdl;
182
    Link<void*,void> maDeleteTemplateHdl;
183
    Link<ThumbnailViewItem*,void> maDefaultTemplateHdl;
184
    Link<void*,void> maMoveTemplateHdl;
185
    Link<void*,void> maExportTemplateHdl;
186
187
    std::unique_ptr<SfxDocumentTemplates> mpDocTemplates;
188
    std::vector<std::unique_ptr<TemplateContainerItem> > maRegions;
189
    std::vector<TemplateItemProperties > maAllTemplates;
190
191
    std::unique_ptr<weld::Menu> mxContextMenu;
192
};
193
194
195
#endif // INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
196
197
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */