LibreOffice Module sfx2 (master) 1
thumbnailview.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_THUMBNAILVIEW_HXX
11#define INCLUDED_SFX2_THUMBNAILVIEW_HXX
12
13#include <sfx2/dllapi.h>
14
15#include <functional>
16#include <memory>
17#include <vector>
18
19#include <vcl/customweld.hxx>
20
21class BitmapEx;
22class MouseEvent;
23class KeyEvent;
25class ScrollBar;
27typedef ::std::vector< ThumbnailViewItem* > ThumbnailValueItemList;
28
29
31
32/*************************************************************************
33
34 Description
35 ============
36
37 class ThumbnailView
38
39 This class allows the selection of an item. In the process items are
40 drawn side by side. The selection of items can be more clear than in a
41 ListBox shape for example in case of colors or samples.
42 The amount of columns drawn by the control and whether the items
43 should be encircled can be specified. Optional a NoSelection or name
44 field could be shown. By default image and color items are supported.
45 Items could be drawn by oneself if InsertItem() is only called with
46 an ID. To achieve this the UserDraw handler needs to be overridden. The
47 description text could be specified afterwards in case of UserDraw
48 and any other items.
49
50 Cross references
51
52 class ListBox
53
54 --------------------------------------------------------------------------
55
56 WinBits
57
58 WB_VSCROLL A scrollbar will be always shown. The visible number of
59 lines have to be specified with SetLineCount() if this
60 flag is set.
61 WB_TABSTOP It is possible to jump into the ValueSet with the tab key.
62 WB_NOTABSTOP It is not possible to jump into the ValueSet with the
63 tab key.
64 --------------------------------------------------------------------------
65
66 The number of columns must be either set with SetColCount() or
67 SetItemWidth(). If the number of columns is specified by SetColCount()
68 the width of the items will be calculated by the visible range.
69 If the items should have a static width, it has to be specified
70 with SetItemWidth(). In this case the number of columns will be calculated
71 by the visible range.
72
73 The number of rows is given by the number of items / number of columns. The
74 number of visible rows must either specified by SetLineCount() or
75 SetItemWidth(). If the number of visible rows is specified by SetLineCount(),
76 the height of the items will be calculated from the visible height. If the
77 items should have a fixed height it has to be specified with SetItemHeight().
78 In this case the number of visible rows is then calculated from the visible
79 height. If the number of visible rows is neither specified by SetLineCount()
80 nor by SetItemHeight() all rows will be shown. The height of the items will
81 be calculated by the visible height. If the number of visible rows is
82 specified by SetLineCount() or SetItemHeight() ValueSet does scroll
83 automatically when more lines are available, as are visible. If scrolling
84 should be also possible with a ScrollBar WB_VSCROLL needs to be set.
85
86 The distance between the items can be increased by SetExtraSpacing(). The
87 distance, which will be shown between two items (both in x and in y), is
88 measured in pixels.
89
90 The exact window size for a specific item size can be calculated by
91 CalcWindowSizePixel(). To do this all relevant data (number of columns/...)
92 have to be specified and if no number of rows was set, all items need to
93 be inserted. If the window was created with WB_BORDER/Border=sal_True the
94 size has to be specified with SetOutputSizePixel(). In other cases different
95 size-methods can be used. With CalcItemSize() the inner and outer size of
96 an item could be calculated (for this the free space defined by
97 SetExtraSpacing() will not be included).
98
99 The background color could be specified by SetColor(), with which the image
100 or UserDraw items will be underlaid. If no color is specified the color
101 of other windows (WindowColor) will be used for the background.
102
103 --------------------------------------------------------------------------
104
105 At first all items should be inserted and only then Show() should be called
106 since the output area will be precomputed. If this is not done the first
107 Paint will appear a little bit slower. Therefore the Control, if it is loaded
108 from the resource and only supplied with items during runtime, should be
109 loaded with Hide = sal_True and then displayed with Show().
110
111 In case of a visible Control the creation of the new output area could be
112 activated before Paint by calling Format().
113
114 --------------------------------------------------------------------------
115
116 If Drag and Drop will be called from the ValueSet the Command-Handler has to
117 be overridden. From this StartDrag needs to be called. If this method returns
118 sal_True the drag-process could be initiated by ExecuteDrag(), otherwise no
119 processing will take place. This method makes sure that ValueSet stops its
120 processing and as appropriate selects the entry. Therefore the calling of
121 Select-Handler within this function must be expected.
122
123 For dropping QueryDrop() and Drop() need to be overridden and ShowDropPos()
124 and HideDropPos() should be called within these methods.
125 To show the insertion point ShowDropPos() has to be called within the
126 QueryDrop-Handler. ShowDropPos() also scrolls the ValueSet if the passed
127 position is located at the window border. Furthermore ShowDropPos() returns
128 the position, at which the item should be inserted respectively which
129 insertion point was shown. If no insertion point was determined
130 VALUESET_ITEM_NOTFOUND will be returned. If the window was left during dragging
131 or the drag process is terminated HideDropPos() should be called in any case.
132
133 --------------------------------------------------------------------------
134
135 This class is currently still in the SV-Tools. That's why the ValueSet needs
136 to be loaded as a Control out of the resource and the desired WinBits have
137 to be set (before Show) with SetStyle().
138
139*************************************************************************/
140
141/* ThumbnailView types */
142
143#define THUMBNAILVIEW_ITEM_NOTFOUND (sal_uInt16(-1))
144
145// Display all the available items in the thumbnail.
147{
148public:
149
151 {
152 return true;
153 }
154};
155
163{
164 friend class ThumbnailViewAcc;
166
167public:
168 ThumbnailView(std::unique_ptr<weld::ScrolledWindow> xWindow, std::unique_ptr<weld::Menu> xMenu);
169
170 virtual ~ThumbnailView() override;
171
172 virtual bool MouseMove(const MouseEvent& rMEvt) override;
173
175 virtual void Reload() {}
176
177 void AppendItem(std::unique_ptr<ThumbnailViewItem> pItem);
178
179 void RemoveItem(sal_uInt16 nItemId);
180
181 virtual void Clear();
182
183 // Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item)
184 void updateItems(std::vector<std::unique_ptr<ThumbnailViewItem>> items);
185
186 size_t GetItemPos( sal_uInt16 nItemId ) const;
187
188 sal_uInt16 GetItemId( size_t nPos ) const;
189
190 sal_uInt16 GetItemId( const Point& rPos ) const;
191
192 virtual bool renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle);
193
194 bool isDrawMnemonic() const { return mbDrawMnemonics; }
195
196 void setItemMaxTextLength (sal_uInt32 nLength);
197
198 void setItemDimensions (tools::Long ItemWidth, tools::Long ThumbnailHeight,
199 tools::Long DisplayHeight, int itemPadding);
200
201 void SelectItem( sal_uInt16 nItemId );
202
203 bool IsItemSelected( sal_uInt16 nItemId ) const;
204
211 void deselectItems ();
212
213 void ShowTooltips( bool bShowTooltips );
214
215 void DrawMnemonics( bool bDrawMnemonics );
216
217 void filterItems (const std::function<bool (const ThumbnailViewItem*) > &func);
218
219 void setItemStateHdl (const Link<const ThumbnailViewItem*,void> &aLink) { maItemStateHdl = aLink; }
220
221 virtual void Resize() override;
222
223 virtual void Show() override
224 {
225 mxScrolledWindow->show();
227 }
228
229 virtual void Hide() override
230 {
231 mxScrolledWindow->hide();
233 }
234
235 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
236
237 static BitmapEx readThumbnail(const OUString &msURL);
238
239protected:
240
241 virtual bool KeyInput( const KeyEvent& rKEvt ) override;
242
243 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
244
245 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
246
247 virtual void GetFocus() override;
248
249 virtual void LoseFocus() override;
250
251 virtual OUString RequestHelp(tools::Rectangle& rRect) override;
252
253 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
254
255 const css::uno::Reference<css::accessibility::XAccessible> & getAccessible() const;
256
257protected:
258
259 // Drawing item related functions, override them to make your own custom ones.
260
261 void DrawItem (ThumbnailViewItem const *pItem);
262
263 virtual void OnItemDblClicked (ThumbnailViewItem *pItem);
264
265 // Set Item colors from the ThumbnailView colors
266 void UpdateColors();
267
268protected:
269
270 friend class ThumbnailViewAcc;
271 friend class ThumbnailViewItemAcc;
272
273 void CalculateItemPositions (bool bScrollBarUsed = false);
274 void MakeItemVisible( sal_uInt16 nId );
275
276 void ImplInit();
277
278 void ImplDeleteItems();
279 size_t ImplGetItem( const Point& rPoint ) const;
280 ThumbnailViewItem* ImplGetItem( size_t nPos );
281 sal_uInt16 ImplGetVisibleItemCount() const;
282 ThumbnailViewItem* ImplGetVisibleItem(sal_uInt16 nVisiblePos);
283 void ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
284 bool ImplHasAccessibleListeners() const;
286
287protected:
288
289 std::vector< std::unique_ptr<ThumbnailViewItem> > mItemList;
290 css::uno::Reference<css::accessibility::XAccessible> mxAccessible;
292 ThumbnailValueItemList::iterator mpStartSelRange;
296 tools::Long mnThumbnailHeight; // Maximum height of the thumbnail
297 tools::Long mnDisplayHeight; // Height of the data display box (name, etc)
298 tools::Long mnVItemSpace; // Vertical spacing between rows, -1 to use excess unused height split up between items
301
302 sal_uInt16 mnCols;
303 sal_uInt16 mnFirstLine;
304 bool mbScroll : 1; // Whether we need to scroll
305 bool mbAllowVScrollBar : 1; // Whether to show a visible scrollbar
317
319 std::unique_ptr<ThumbnailItemAttributes> mpItemAttrs;
320 std::unique_ptr<weld::ScrolledWindow> mxScrolledWindow;
321 std::unique_ptr<weld::Menu> mxContextMenu;
322
323 std::function<bool (const ThumbnailViewItem*)> maFilterFunc;
324};
325
326
327#endif // INCLUDED_SFX2_THUMBNAILVIEW_HXX
328
329/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Class to display thumbnails with their names below their respective icons.
sal_uInt16 mnCols
tools::Long mnThumbnailHeight
tools::Long mnVisLines
tools::Long mnVItemSpace
Link< const ThumbnailViewItem *, void > maItemStateHdl
tools::Long mnDisplayHeight
tools::Long mnLines
Color maHighlightColor
Color of the highlight (background) of the hovered item.
ThumbnailValueItemList::iterator mpStartSelRange
tools::Long mnItemPadding
std::unique_ptr< weld::Menu > mxContextMenu
tools::Long mnItemHeight
double mfHighlightTransparence
Transparence of the highlight.
void setItemStateHdl(const Link< const ThumbnailViewItem *, void > &aLink)
sal_uInt16 mnFirstLine
Color maHighlightTextColor
Color of the text for the highlighted item.
std::unique_ptr< weld::ScrolledWindow > mxScrolledWindow
Color maTextColor
Text color.
css::uno::Reference< css::accessibility::XAccessible > mxAccessible
virtual void Reload()
Updates information in the view; used only in RecentDocsView ATM.
std::unique_ptr< ThumbnailItemAttributes > mpItemAttrs
std::function< bool(const ThumbnailViewItem *)> maFilterFunc
virtual void Show() override
Color maSelectHighlightTextColor
Color of the text of the selected and hovered item.
tools::Long mnItemWidth
DECL_DLLPRIVATE_LINK(ImplScrollHdl, weld::ScrolledWindow &, void)
Color maSelectHighlightColor
Color of the highlight (background) of the selected and hovered item.
std::vector< std::unique_ptr< ThumbnailViewItem > > mItemList
Color maFillColor
Background color of the thumbnail view widget.
ThumbnailValueItemList mFilteredItemList
Cache to store the filtered items.
bool isDrawMnemonic() const
virtual void Hide() override
bool operator()(const ThumbnailViewItem *) const
virtual bool KeyInput(const KeyEvent &)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)=0
virtual bool MouseMove(const MouseEvent &)
virtual bool MouseButtonDown(const MouseEvent &)
virtual OUString RequestHelp(tools::Rectangle &)
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
#define SFX2_DLLPUBLIC
Definition: dllapi.h:29
sal_uInt16 nPos
Definition: linksrc.cxx:118
void Clear(EHistoryType eHistory)
UNOTOOLS_DLLPUBLIC void AppendItem(EHistoryType eHistory, const OUString &sURL, const OUString &sFilter, const OUString &sTitle, const std::optional< OUString > &sThumbnail, std::optional< bool > oIsReadOnly)
long Long
::std::vector< ThumbnailViewItem * > ThumbnailValueItemList