1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
11 #define INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
13 #include <sfx2/thumbnailview.hxx>
14 #include <sfx2/templateproperties.hxx>
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
46 // Display template items depending on the generator application
47 class ViewFilter_Application final
51 ViewFilter_Application (FILTER_APPLICATION App
)
55 bool operator () (const ThumbnailViewItem
*pItem
);
57 static bool isFilteredExtension(FILTER_APPLICATION filter
, std::u16string_view rExt
);
58 bool isValid (const OUString
& rPath
) const;
62 FILTER_APPLICATION mApp
;
65 class TemplateLocalView
: public ThumbnailView
67 typedef bool (*selection_cmp_fn
)(const ThumbnailViewItem
*,const ThumbnailViewItem
*);
71 TemplateLocalView(std::unique_ptr
<weld::ScrolledWindow
> xWindow
,
72 std::unique_ptr
<weld::Menu
> xMenu
);
74 virtual ~TemplateLocalView () override
;
76 // Fill view with new item list
77 void insertItems (const std::vector
<TemplateItemProperties
> &rTemplates
, bool isRegionSelected
= true, bool bShowCategoryInTooltip
= false);
79 // Fill view with template folders thumbnails
84 virtual void showAllTemplates ();
86 void showRegion (TemplateContainerItem
const *pItem
);
88 void ContextMenuSelectHdl(std::string_view rIdent
);
90 TemplateContainerItem
* getRegion(std::u16string_view sStr
);
92 sal_uInt16
getRegionId (size_t pos
) const;
94 sal_uInt16
getRegionId (std::u16string_view sRegionName
) const;
96 OUString
getRegionName(const sal_uInt16 nRegionId
) const;
98 OUString
getRegionItemName(const sal_uInt16 nItemId
) const;
100 std::vector
<OUString
> getFolderNames ();
102 std::vector
<TemplateItemProperties
>
103 getFilteredItems (const std::function
<bool (const TemplateItemProperties
&) > &rFunc
) const;
105 sal_uInt16
createRegion (const OUString
&rName
);
107 bool renameRegion(std::u16string_view rTitle
, const OUString
&rNewTitle
);
109 bool removeRegion (const sal_uInt16 nItemId
);
111 bool removeTemplate (const sal_uInt16 nItemId
, const sal_uInt16 nSrcItemId
);
113 void moveTemplates (const std::set
<const ThumbnailViewItem
*,selection_cmp_fn
> &rItems
, const sal_uInt16 nTargetItem
);
115 bool copyFrom(TemplateContainerItem
*pItem
, const OUString
&rPath
);
117 bool exportTo (const sal_uInt16 nItemId
, const sal_uInt16 nRegionItemId
, const OUString
&rName
);
119 virtual bool renameItem(ThumbnailViewItem
* pItem
, const OUString
& sNewTitle
) override
;
121 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
123 virtual bool Command(const CommandEvent
& rPos
) override
;
125 virtual bool KeyInput( const KeyEvent
& rKEvt
) override
;
127 sal_uInt16
getCurRegionId () const { return mnCurRegionId
;}
129 void setCurRegionId (sal_uInt16 nCurRegionId
) { mnCurRegionId
= nCurRegionId
;}
131 void setOpenRegionHdl(const Link
<void*,void> &rLink
);
133 void setCreateContextMenuHdl(const Link
<ThumbnailViewItem
*,void> &rLink
);
135 void setOpenTemplateHdl(const Link
<ThumbnailViewItem
*,void> &rLink
);
137 void setEditTemplateHdl(const Link
<ThumbnailViewItem
*,void> &rLink
);
139 void setDeleteTemplateHdl(const Link
<void*,void> &rLink
);
141 void setDefaultTemplateHdl(const Link
<ThumbnailViewItem
*,void> &rLink
);
143 void setMoveTemplateHdl(const Link
<void*,void> &rLink
);
145 void setExportTemplateHdl(const Link
<void*,void> &rLink
);
147 void updateThumbnailDimensions(tools::Long itemMaxSize
);
149 void RemoveDefaultTemplateIcon( std::u16string_view rPath
);
151 bool IsBuiltInRegion(const OUString
& rRegionName
);
153 static BitmapEx
scaleImg (const BitmapEx
&rImg
, tools::Long width
, tools::Long height
);
155 static BitmapEx
getDefaultThumbnail( const OUString
& rPath
);
157 static BitmapEx
fetchThumbnail (const OUString
&msURL
, tools::Long width
, tools::Long height
);
159 static bool IsDefaultTemplate(const OUString
& rPath
);
161 static bool IsInternalTemplate(const OUString
& rPath
);
164 virtual void OnItemDblClicked(ThumbnailViewItem
*pItem
) override
;
166 sal_uInt16 mnCurRegionId
;
168 TemplateViewItem
*maSelectedItem
;
170 tools::Long mnThumbnailWidth
;
171 tools::Long mnThumbnailHeight
;
173 Point maPosition
; //store the point of click event
175 Link
<void*,void> maOpenRegionHdl
;
176 Link
<ThumbnailViewItem
*,void> maCreateContextMenuHdl
;
177 Link
<ThumbnailViewItem
*,void> maOpenTemplateHdl
;
178 Link
<ThumbnailViewItem
*,void> maEditTemplateHdl
;
179 Link
<void*,void> maDeleteTemplateHdl
;
180 Link
<ThumbnailViewItem
*,void> maDefaultTemplateHdl
;
181 Link
<void*,void> maMoveTemplateHdl
;
182 Link
<void*,void> maExportTemplateHdl
;
184 std::unique_ptr
<SfxDocumentTemplates
> mpDocTemplates
;
185 std::vector
<std::unique_ptr
<TemplateContainerItem
> > maRegions
;
186 std::vector
<TemplateItemProperties
> maAllTemplates
;
190 #endif // INCLUDED_SFX2_TEMPLATELOCALVIEW_HXX
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */