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