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_THUMBNAILVIEW_HXX
11 #define INCLUDED_SFX2_THUMBNAILVIEW_HXX
13 #include <sfx2/dllapi.h>
19 #include <vcl/customweld.hxx>
24 class DataChangedEvent
;
26 class ThumbnailViewItem
;
27 typedef ::std::vector
< ThumbnailViewItem
* > ThumbnailValueItemList
;
30 struct ThumbnailItemAttributes
;
32 /*************************************************************************
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
54 --------------------------------------------------------------------------
58 WB_VSCROLL A scrollbar will be always shown. The visible number of
59 lines have to be specified with SetLineCount() if this
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
64 --------------------------------------------------------------------------
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
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.
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
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).
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.
103 --------------------------------------------------------------------------
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().
111 In case of a visible Control the creation of the new output area could be
112 activated before Paint by calling Format().
114 --------------------------------------------------------------------------
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.
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.
133 --------------------------------------------------------------------------
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().
139 *************************************************************************/
141 /* ThumbnailView types */
143 #define THUMBNAILVIEW_ITEM_NOTFOUND (sal_uInt16(-1))
145 // Display all the available items in the thumbnail.
150 bool operator () (const ThumbnailViewItem
*) const
158 * Class to display thumbnails with their names below their respective icons
162 class SFX2_DLLPUBLIC ThumbnailView
: public weld::CustomWidgetController
164 friend class ThumbnailViewAcc
;
165 friend class ThumbnailViewItemAcc
;
168 ThumbnailView(std::unique_ptr
<weld::ScrolledWindow
> xWindow
, std::unique_ptr
<weld::Menu
> xMenu
);
170 virtual ~ThumbnailView() override
;
172 virtual bool MouseMove(const MouseEvent
& rMEvt
) override
;
174 /// Updates information in the view; used only in RecentDocsView ATM.
175 virtual void Reload() {}
177 void AppendItem(std::unique_ptr
<ThumbnailViewItem
> pItem
);
179 void RemoveItem(sal_uInt16 nItemId
);
181 virtual void Clear();
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
);
186 size_t GetItemPos( sal_uInt16 nItemId
) const;
188 sal_uInt16
GetItemId( size_t nPos
) const;
190 sal_uInt16
GetItemId( const Point
& rPos
) const;
192 virtual bool renameItem(ThumbnailViewItem
* pItem
, const OUString
& sNewTitle
);
194 bool isDrawMnemonic() const { return mbDrawMnemonics
; }
196 void setItemMaxTextLength (sal_uInt32 nLength
);
198 void setItemDimensions (tools::Long ItemWidth
, tools::Long ThumbnailHeight
,
199 tools::Long DisplayHeight
, int itemPadding
);
201 void SelectItem( sal_uInt16 nItemId
);
203 bool IsItemSelected( sal_uInt16 nItemId
) const;
207 * @brief deselect all current selected items.
211 void deselectItems ();
213 void ShowTooltips( bool bShowTooltips
);
215 void DrawMnemonics( bool bDrawMnemonics
);
217 void filterItems (const std::function
<bool (const ThumbnailViewItem
*) > &func
);
219 void setItemStateHdl (const Link
<const ThumbnailViewItem
*,void> &aLink
) { maItemStateHdl
= aLink
; }
221 virtual void Resize() override
;
223 virtual void Show() override
225 mxScrolledWindow
->show();
226 CustomWidgetController::Show();
229 virtual void Hide() override
231 mxScrolledWindow
->hide();
232 CustomWidgetController::Hide();
235 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
237 static BitmapEx
readThumbnail(const OUString
&msURL
);
241 virtual bool KeyInput( const KeyEvent
& rKEvt
) override
;
243 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
245 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
247 virtual void GetFocus() override
;
249 virtual void LoseFocus() override
;
251 virtual OUString
RequestHelp(tools::Rectangle
& rRect
) override
;
253 virtual css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessible() override
;
255 const css::uno::Reference
<css::accessibility::XAccessible
> & getAccessible() const;
259 // Drawing item related functions, override them to make your own custom ones.
261 void DrawItem (ThumbnailViewItem
const *pItem
);
263 virtual void OnItemDblClicked (ThumbnailViewItem
*pItem
);
265 // Set Item colors from the ThumbnailView colors
270 friend class ThumbnailViewAcc
;
271 friend class ThumbnailViewItemAcc
;
273 void CalculateItemPositions (bool bScrollBarUsed
= false);
274 void MakeItemVisible( sal_uInt16 nId
);
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;
285 DECL_DLLPRIVATE_LINK( ImplScrollHdl
, weld::ScrolledWindow
&, void );
289 std::vector
< std::unique_ptr
<ThumbnailViewItem
> > mItemList
;
290 css::uno::Reference
<css::accessibility::XAccessible
> mxAccessible
;
291 ThumbnailValueItemList mFilteredItemList
; ///< Cache to store the filtered items
292 ThumbnailValueItemList::iterator mpStartSelRange
;
293 tools::Long mnItemWidth
;
294 tools::Long mnItemHeight
;
295 tools::Long mnItemPadding
;
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
299 tools::Long mnVisLines
;
303 sal_uInt16 mnFirstLine
;
304 bool mbScroll
: 1; // Whether we need to scroll
305 bool mbAllowVScrollBar
: 1; // Whether to show a visible scrollbar
306 bool mbHasVisibleItems
: 1;
307 bool mbShowTooltips
: 1;
308 bool mbDrawMnemonics
: 1;
309 bool mbSelectOnFocus
: 1;
310 Color maFillColor
; ///< Background color of the thumbnail view widget.
311 Color maTextColor
; ///< Text color.
312 Color maHighlightColor
; ///< Color of the highlight (background) of the hovered item.
313 Color maHighlightTextColor
; ///< Color of the text for the highlighted item.
314 Color maSelectHighlightColor
; ///< Color of the highlight (background) of the selected and hovered item.
315 Color maSelectHighlightTextColor
; ///< Color of the text of the selected and hovered item.
316 double mfHighlightTransparence
; ///< Transparence of the highlight.
318 Link
<const ThumbnailViewItem
*, void> maItemStateHdl
;
319 std::unique_ptr
<ThumbnailItemAttributes
> mpItemAttrs
;
320 std::unique_ptr
<weld::ScrolledWindow
> mxScrolledWindow
;
321 std::unique_ptr
<weld::Menu
> mxContextMenu
;
323 std::function
<bool (const ThumbnailViewItem
*)> maFilterFunc
;
327 #endif // INCLUDED_SFX2_THUMBNAILVIEW_HXX
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */