Coverage Report

Created: 2025-12-31 10:39

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