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