sc: filter: rtf: add method "AddFont"
[LibreOffice.git] / include / sfx2 / thumbnailview.hxx
blob1922270f413fbcb97de3329ec9c0c66fab3870be
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_THUMBNAILVIEW_HXX
11 #define INCLUDED_SFX2_THUMBNAILVIEW_HXX
13 #include <sfx2/dllapi.h>
15 #include <functional>
16 #include <memory>
17 #include <vector>
19 #include <vcl/customweld.hxx>
21 class BitmapEx;
22 class MouseEvent;
23 class KeyEvent;
24 class DataChangedEvent;
25 class ScrollBar;
26 class ThumbnailViewItem;
27 typedef ::std::vector< ThumbnailViewItem* > ThumbnailValueItemList;
30 struct ThumbnailItemAttributes;
32 /*************************************************************************
34 Description
35 ============
37 class ThumbnailView
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.
50 Cross references
52 class ListBox
54 --------------------------------------------------------------------------
56 WinBits
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 --------------------------------------------------------------------------
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.
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
88 measured in pixels.
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.
146 class ViewFilterAll
148 public:
150 bool operator () (const ThumbnailViewItem*) const
152 return true;
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;
167 public:
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 sal_uInt16 getNextItemId () const;
194 virtual bool renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle);
196 bool isDrawMnemonic() const { return mbDrawMnemonics; }
198 void setItemMaxTextLength (sal_uInt32 nLength);
200 void setItemDimensions (tools::Long ItemWidth, tools::Long ThumbnailHeight,
201 tools::Long DisplayHeight, int itemPadding);
203 void SelectItem( sal_uInt16 nItemId );
205 bool IsItemSelected( sal_uInt16 nItemId ) const;
209 * @brief deselect all current selected items.
213 void deselectItems ();
215 void ShowTooltips( bool bShowTooltips );
217 void DrawMnemonics( bool bDrawMnemonics );
219 void filterItems (const std::function<bool (const ThumbnailViewItem*) > &func);
221 void setItemStateHdl (const Link<const ThumbnailViewItem*,void> &aLink) { maItemStateHdl = aLink; }
223 virtual void Resize() override;
225 virtual void Show() override
227 mxScrolledWindow->show();
228 CustomWidgetController::Show();
231 virtual void Hide() override
233 mxScrolledWindow->hide();
234 CustomWidgetController::Hide();
237 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
239 static BitmapEx readThumbnail(const OUString &msURL);
241 tools::Long ItemHeight() const { return mnItemHeight; };
243 protected:
245 virtual bool KeyInput( const KeyEvent& rKEvt ) override;
247 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
249 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
251 virtual void GetFocus() override;
253 virtual void LoseFocus() override;
255 virtual OUString RequestHelp(tools::Rectangle& rRect) override;
257 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
259 css::uno::Reference<css::accessibility::XAccessible> getAccessible() const;
261 protected:
263 // Drawing item related functions, override them to make your own custom ones.
265 void DrawItem (ThumbnailViewItem const *pItem);
267 virtual void OnItemDblClicked (ThumbnailViewItem *pItem);
269 // Set Item colors from the ThumbnailView colors
270 void UpdateColors();
272 protected:
274 friend class ThumbnailViewAcc;
275 friend class ThumbnailViewItemAcc;
277 void CalculateItemPositions (bool bScrollBarUsed = false);
278 void MakeItemVisible( sal_uInt16 nId );
280 void ImplInit();
282 void ImplDeleteItems();
283 size_t ImplGetItem( const Point& rPoint ) const;
284 ThumbnailViewItem* ImplGetItem( size_t nPos );
285 sal_uInt16 ImplGetVisibleItemCount() const;
286 ThumbnailViewItem* ImplGetVisibleItem(sal_uInt16 nVisiblePos);
287 void ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
288 bool ImplHasAccessibleListeners() const;
289 DECL_DLLPRIVATE_LINK( ImplScrollHdl, weld::ScrolledWindow&, void );
291 protected:
293 std::vector< std::unique_ptr<ThumbnailViewItem> > mItemList;
294 css::uno::Reference<css::accessibility::XAccessible> mxAccessible;
295 ThumbnailValueItemList mFilteredItemList; ///< Cache to store the filtered items
296 ThumbnailValueItemList::iterator mpStartSelRange;
297 tools::Long mnItemWidth;
298 tools::Long mnItemHeight;
299 tools::Long mnItemPadding;
300 tools::Long mnThumbnailHeight; // Maximum height of the thumbnail
301 tools::Long mnDisplayHeight; // Height of the data display box (name, etc)
302 tools::Long mnVItemSpace; // Vertical spacing between rows, -1 to use excess unused height split up between items
303 tools::Long mnVisLines;
304 tools::Long mnLines;
306 sal_uInt16 mnCols;
307 sal_uInt16 mnFirstLine;
308 bool mbScroll : 1; // Whether we need to scroll
309 bool mbAllowVScrollBar : 1; // Whether to show a visible scrollbar
310 bool mbHasVisibleItems : 1;
311 bool mbShowTooltips : 1;
312 bool mbDrawMnemonics : 1;
313 bool mbSelectOnFocus : 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 Color maSelectHighlightColor; ///< Color of the highlight (background) of the selected and hovered item.
319 Color maSelectHighlightTextColor; ///< Color of the text of the selected and hovered item.
320 double mfHighlightTransparence; ///< Transparence of the highlight.
322 Link<const ThumbnailViewItem*, void> maItemStateHdl;
323 std::unique_ptr<ThumbnailItemAttributes> mpItemAttrs;
324 std::unique_ptr<weld::ScrolledWindow> mxScrolledWindow;
325 std::unique_ptr<weld::Menu> mxContextMenu;
327 std::function<bool (const ThumbnailViewItem*)> maFilterFunc;
331 #endif // INCLUDED_SFX2_THUMBNAILVIEW_HXX
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */