Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / include / sfx2 / templatelocalview.hxx
blob098ffa33e6dcf03a3b3a573745a7e95feb99d66b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
11 #define INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
13 #include <sfx2/thumbnailview.hxx>
14 #include <sfx2/templateproperties.hxx>
15 #include <functional>
16 #include <memory>
17 #include <set>
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
26 //template thumbnail height with a subtitle
27 #define TEMPLATE_ITEM_MAX_HEIGHT_SUB 160
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
33 class SfxDocumentTemplates;
34 class TemplateContainerItem;
35 class TemplateViewItem;
37 enum class FILTER_APPLICATION
39 NONE,
40 WRITER,
41 CALC,
42 IMPRESS,
43 DRAW
46 // Display template items depending on the generator application
47 class ViewFilter_Application final
49 public:
51 ViewFilter_Application (FILTER_APPLICATION App)
52 : mApp(App)
55 bool operator () (const ThumbnailViewItem *pItem);
57 static bool isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt);
58 bool isValid (const OUString& rPath) const;
60 private:
62 FILTER_APPLICATION const mApp;
66 class TemplateLocalView : public ThumbnailView
68 typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*);
70 public:
72 TemplateLocalView ( vcl::Window* pParent );
74 virtual ~TemplateLocalView () override;
75 virtual void dispose() override;
77 // Fill view with new item list
78 void insertItems (const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected = true, bool bShowCategoryInTooltip = false);
80 // Fill view with template folders thumbnails
81 void Populate ();
83 virtual void reload ();
85 virtual void showAllTemplates ();
87 void showRegion (TemplateContainerItem const *pItem);
89 DECL_LINK(ContextMenuSelectHdl, Menu*, bool);
91 virtual bool renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle) override;
93 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
95 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
97 virtual void Command( const CommandEvent& rCEvt ) override;
99 virtual void KeyInput( const KeyEvent& rKEvt ) override;
101 void setCreateContextMenuHdl(const Link<ThumbnailViewItem*,void> &rLink);
103 void setOpenTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
105 void setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
107 void updateThumbnailDimensions(long itemMaxSize);
109 static BitmapEx scaleImg (const BitmapEx &rImg, long width, long height);
111 static BitmapEx getDefaultThumbnail( const OUString& rPath );
113 static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height);
115 static bool IsDefaultTemplate(const OUString& rPath);
117 protected:
118 virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override;
120 protected:
121 sal_uInt16 mnCurRegionId;
123 TemplateViewItem *maSelectedItem;
125 long mnThumbnailWidth;
126 long mnThumbnailHeight;
128 Point maPosition; //store the point of click event
130 Link<ThumbnailViewItem*,void> maCreateContextMenuHdl;
131 Link<ThumbnailViewItem*,void> maOpenTemplateHdl;
132 Link<ThumbnailViewItem*,void> maEditTemplateHdl;
134 std::unique_ptr<SfxDocumentTemplates> mpDocTemplates;
135 std::vector<std::unique_ptr<TemplateContainerItem> > maRegions;
136 std::vector<TemplateItemProperties > maAllTemplates;
139 class SfxTemplateLocalView final : public SfxThumbnailView
141 typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*);
143 public:
145 SfxTemplateLocalView(std::unique_ptr<weld::ScrolledWindow> xWindow,
146 std::unique_ptr<weld::Menu> xMenu);
148 virtual ~SfxTemplateLocalView () override;
150 // Fill view with new item list
151 void insertItems (const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected = true, bool bShowCategoryInTooltip = false);
153 // Fill view with template folders thumbnails
154 void Populate ();
156 void reload ();
158 void showAllTemplates ();
160 void showRegion (TemplateContainerItem const *pItem);
162 void showRegion (const OUString &rName);
164 void createContextMenu(const bool bIsDefault );
166 void ContextMenuSelectHdl(const OString& rIdent);
168 TemplateContainerItem* getRegion(OUString const & sStr);
170 sal_uInt16 getRegionId (size_t pos) const;
172 sal_uInt16 getRegionId (OUString const & sRegionName) const;
174 OUString getRegionName(const sal_uInt16 nRegionId) const;
176 OUString getRegionItemName(const sal_uInt16 nItemId) const;
178 std::vector<OUString> getFolderNames ();
180 std::vector<TemplateItemProperties>
181 getFilteredItems (const std::function<bool (const TemplateItemProperties&) > &rFunc) const;
183 sal_uInt16 createRegion (const OUString &rName);
185 bool renameRegion(const OUString &rTitle, const OUString &rNewTitle);
187 bool removeRegion (const sal_uInt16 nItemId);
189 bool removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId);
191 bool moveTemplate (const ThumbnailViewItem* pItem, const sal_uInt16 nSrcItem,
192 const sal_uInt16 nTargetItem);
194 void moveTemplates (const std::set<const ThumbnailViewItem*,selection_cmp_fn> &rItems, const sal_uInt16 nTargetItem);
196 bool copyFrom(TemplateContainerItem *pItem, const OUString &rPath);
198 bool exportTo (const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, const OUString &rName);
200 virtual bool renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle) override;
202 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
204 virtual bool Command(const CommandEvent& rPos) override;
206 virtual bool KeyInput( const KeyEvent& rKEvt ) override;
208 sal_uInt16 getCurRegionId () const { return mnCurRegionId;}
210 void setOpenRegionHdl(const Link<void*,void> &rLink);
212 void setCreateContextMenuHdl(const Link<ThumbnailViewItem*,void> &rLink);
214 void setOpenTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
216 void setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
218 void setDeleteTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
220 void setDefaultTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
222 void RemoveDefaultTemplateIcon( const OUString& rPath);
224 static BitmapEx scaleImg (const BitmapEx &rImg, long width, long height);
226 static BitmapEx getDefaultThumbnail( const OUString& rPath );
228 static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height);
230 static bool IsDefaultTemplate(const OUString& rPath);
232 private:
233 virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override;
235 sal_uInt16 mnCurRegionId;
237 TemplateViewItem *maSelectedItem;
239 Point maPosition; //store the point of click event
241 Link<void*,void> maOpenRegionHdl;
242 Link<ThumbnailViewItem*,void> maCreateContextMenuHdl;
243 Link<ThumbnailViewItem*,void> maOpenTemplateHdl;
244 Link<ThumbnailViewItem*,void> maEditTemplateHdl;
245 Link<ThumbnailViewItem*,void> maDeleteTemplateHdl;
246 Link<ThumbnailViewItem*,void> maDefaultTemplateHdl;
248 std::unique_ptr<SfxDocumentTemplates> mpDocTemplates;
249 std::vector<std::unique_ptr<TemplateContainerItem> > maRegions;
250 std::vector<TemplateItemProperties > maAllTemplates;
254 #endif // INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */