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>
16 #include <boost/function.hpp>
18 #include <comphelper/processfactory.hxx>
19 #include <unotools/ucbstreamhelper.hxx>
20 #include <sfx2/thumbnailviewitem.hxx>
21 #include <vcl/ctrl.hxx>
22 #include <vcl/timer.hxx>
23 #include <vcl/pngread.hxx>
25 #include <com/sun/star/embed/ElementModes.hpp>
26 #include <com/sun/star/embed/XStorage.hpp>
27 #include <com/sun/star/embed/StorageFactory.hpp>
34 class DataChangedEvent
;
36 typedef ::std::vector
< ThumbnailViewItem
* > ThumbnailValueItemList
;
38 struct ThumbnailItemAttributes
;
39 class ThumbnailViewAcc
;
40 class ThumbnailViewItemAcc
;
42 namespace drawinglayer
{
43 namespace processor2d
{
44 class BaseProcessor2D
;
48 /*************************************************************************
55 This class allows the selection of an item. In the process items are
56 drawn side by side. The selection of items can be more clear than in a
57 ListBox shape for example in case of colors or samples.
58 The amount of columns drawn by the control and whether the items
59 should be encircled can be specified. Optional a NoSelection or name
60 field could be shown. By default image and color items are supported.
61 Items could be drawn by oneself if InsertItem() is only called with
62 an ID. To achieve this the UserDraw handler needs to be overloaded. The
63 description text could be specified afterwards in case of UserDraw
70 --------------------------------------------------------------------------
74 WB_VSCROLL A scroolbar will be always shown. The visible number of
75 lines have to be specified with SetLineCount() if this
77 WB_TABSTOP It is possible to jump into the ValueSet with the tab key.
78 WB_NOTABSTOP It is not possible to jump into the ValueSet with the
80 --------------------------------------------------------------------------
82 The number of columns must be either set with SetColCount() or
83 SetItemWidth(). If the number of colums is specified by SetColCount()
84 the width of the items will be calculated by the visible range.
85 If the items should have a static width, it has to be specified
86 with SetItemWidth(). In this case the number of columns will be calculated
89 The number of rows is given by the number of items / number of columns. The
90 number of visible rows must either specified by SetLineCount() or
91 SetItemWidth(). If the number of visible rows is specified by SetLineCount(),
92 the height of the items will be calculated from the visible height. If the
93 items should have a fixed height it has to be specified with SetItemHeight().
94 In this case the number of visible rows is then calculated from the visible
95 height. If the number of visible rows is neither specified by SetLineCount()
96 nor by SetItemHeight() all rows will be shown. The height of the items will
97 be calculated by the visible height. If the number of visible rows is
98 specified by SetLineCount() or SetItemHeight() ValueSet does scroll
99 automatically when more lines are available, as are visible. If scrolling
100 should be also possible with a ScrollBar WB_VSCROLL needs to be set.
102 The distance between the items can be increased by SetExtraSpacing(). The
103 distance, which will be shown between two items (both in x and in y), is
106 The exact window size for a specific item size can be calculated by
107 CalcWindowSizePixel(). To do this all relevant data (number of columns/...)
108 have to be specified and if no number of rows was set, all items need to
109 be inserted. If the window was created with WB_BORDER/Border=sal_True the
110 size has to be specified with SetOutputSizePixel(). In other cases different
111 size-methods can be used. With CalcItemSize() the inner and outer size of
112 an item could be calculated (for this the free space defined by
113 SetExtraSpacing() will not be included).
115 The background color could be specified by SetColor(), with which the image
116 or UserDraw items will be underlayed. If no color is specified the color
117 of other windows (WindowColor) will be used for the background.
119 --------------------------------------------------------------------------
121 At first all items should be inserted and only then Show() should be called
122 since the output area will be precomputed. If this is not done the first
123 Paint will appear a little bit slower. Therefore the Control, if it is loaded
124 from the resource and only supplied with items during runtime, should be
125 loaded with Hide = sal_True and then displayed with Show().
127 In case of a visible Control the creation of the new output area could be
128 activated before Paint by calling Format().
130 --------------------------------------------------------------------------
132 If Drag and Drop will be called from the ValueSet the Command-Handler has to
133 be overloaded. From this StartDrag needs to be called. If this method returns
134 sal_True the drag-process could be initiated by ExecuteDrag(), otherwise no
135 processing will take place. This method makes sure that ValueSet stops its
136 processing and as appropriate selects the entry. Therefore the calling of
137 Select-Handler within this function must be expected.
139 For dropping QueryDrop() and Drop() need to be overloaded and ShowDropPos()
140 and HideDropPos() should be called within these methods.
141 To show the insertion point ShowDropPos() has to be called within the
142 QueryDrop-Handler. ShowDropPos() also scrolls the ValueSet if the passed
143 position is located at the window border. Furthermore ShowDropPos() returns
144 the position, at which the item should be inserted respectively which
145 insertion point was shown. If no insertion point was determined
146 VALUESET_ITEM_NOTFOUND will be returned. If the window was left during dragging
147 or the drag process is terminated HideDropPos() should be called in any case.
149 --------------------------------------------------------------------------
151 This class is currently still in the SV-Tools. That's why the ValueSet needs
152 to be loaded as a Control out of the resource and the desired WinBits have
153 to be set (before Show) with SetStyle().
155 *************************************************************************/
157 /* ThumbnailView types */
159 #define THUMBNAILVIEW_APPEND ((sal_uInt16)-1)
160 #define THUMBNAILVIEW_ITEM_NOTFOUND ((sal_uInt16)-1)
162 // Display all the available items in the thumbnail.
167 bool operator () (const ThumbnailViewItem
*) const
175 * Class to display thumbnails with their names below their respective icons
179 class SFX2_DLLPUBLIC ThumbnailView
: public Control
183 ThumbnailView ( Window
* pParent
, WinBits nWinStyle
= WB_TABSTOP
, bool bDisableTransientChildren
= false );
185 ThumbnailView ( Window
* pParent
, const ResId
& rResId
, bool bDisableTransientChildren
= false );
187 virtual ~ThumbnailView ();
189 virtual void MouseMove( const MouseEvent
& rMEvt
);
191 void AppendItem (ThumbnailViewItem
*pItem
);
193 void RemoveItem( sal_uInt16 nItemId
);
197 // Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item)
198 void updateItems(const std::vector
<ThumbnailViewItem
*> &items
);
200 size_t GetItemPos( sal_uInt16 nItemId
) const;
202 sal_uInt16
GetItemId( size_t nPos
) const;
204 sal_uInt16
GetItemId( const Point
& rPos
) const;
206 sal_uInt16
getNextItemId () const;
208 long GetItemWidth() const { return mnItemWidth
; }
210 long GetItemHeight() const { return mnItemHeight
; }
212 void setItemMaxTextLength (sal_uInt32 nLength
);
214 void setItemDimensions (long ItemWidth
, long ThumbnailHeight
,
215 long DisplayHeight
, int itemPadding
);
217 sal_uInt16
GetFirstLine() const { return mnFirstLine
; }
219 void SelectItem( sal_uInt16 nItemId
);
221 void DeselectItem( sal_uInt16 nItemId
);
223 bool IsItemSelected( sal_uInt16 nItemId
) const;
227 * @brief deselect all current selected items.
231 void deselectItems ();
233 OUString
GetItemText( sal_uInt16 nItemId
) const;
235 void ShowTooltips( bool bShowTooltips
);
237 void SetColor( const Color
& rColor
);
239 void SetColor() { SetColor( Color( COL_TRANSPARENT
) ); }
241 Color
GetColor() const { return maColor
; }
243 bool IsColor() const { return maColor
.GetTransparency() == 0; }
245 void filterItems (const boost::function
<bool (const ThumbnailViewItem
*) > &func
);
247 void sortItems (const boost::function
<bool (const ThumbnailViewItem
*,
248 const ThumbnailViewItem
*) > &func
);
250 void setItemStateHdl (const Link
&aLink
) { maItemStateHdl
= aLink
; }
252 virtual void Resize();
254 virtual bool renameItem(ThumbnailViewItem
* pItem
, OUString sNewTitle
);
256 static BitmapEx
readThumbnail(const OUString
&msURL
);
260 virtual void KeyInput( const KeyEvent
& rKEvt
);
262 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
264 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
266 virtual void Command( const CommandEvent
& rCEvt
);
268 virtual void Paint( const Rectangle
& rRect
);
270 virtual void GetFocus();
272 virtual void LoseFocus();
274 virtual void StateChanged( StateChangedType nStateChange
);
276 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
278 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> CreateAccessible();
282 // Drawing item related functions, override them to make your own custom ones.
284 virtual void DrawItem (ThumbnailViewItem
*pItem
);
286 virtual void OnItemDblClicked (ThumbnailViewItem
*pItem
);
290 friend class ThumbnailViewAcc
;
291 friend class ThumbnailViewItemAcc
;
292 using Control::ImplInitSettings
;
293 using Window::ImplInit
;
295 void CalculateItemPositions ();
296 void MakeItemVisible( sal_uInt16 nId
);
298 SFX2_DLLPRIVATE
void ImplInit();
299 SFX2_DLLPRIVATE
void ImplInitSettings( bool bFont
, bool bForeground
, bool bBackground
);
300 SFX2_DLLPRIVATE
void ImplInitScrollBar();
301 SFX2_DLLPRIVATE
void ImplDeleteItems();
302 SFX2_DLLPRIVATE
void ImplDraw();
303 SFX2_DLLPRIVATE
size_t ImplGetItem( const Point
& rPoint
, bool bMove
= false ) const;
304 SFX2_DLLPRIVATE ThumbnailViewItem
* ImplGetItem( size_t nPos
);
305 SFX2_DLLPRIVATE sal_uInt16
ImplGetVisibleItemCount() const;
306 SFX2_DLLPRIVATE ThumbnailViewItem
* ImplGetVisibleItem( sal_uInt16 nVisiblePos
);
307 SFX2_DLLPRIVATE
void ImplFireAccessibleEvent( short nEventId
, const ::com::sun::star::uno::Any
& rOldValue
, const ::com::sun::star::uno::Any
& rNewValue
);
308 SFX2_DLLPRIVATE
bool ImplHasAccessibleListeners();
309 DECL_DLLPRIVATE_LINK( ImplScrollHdl
, ScrollBar
* );
311 DECL_LINK(OnItemSelected
, ThumbnailViewItem
*);
315 ThumbnailValueItemList mItemList
;
316 ThumbnailValueItemList mFilteredItemList
; ///< Cache to store the filtered items
317 ThumbnailValueItemList::iterator mpStartSelRange
;
319 Rectangle maItemListRect
;
324 long mnThumbnailHeight
; // Maximum height of the thumbnail
325 long mnDisplayHeight
; // Height of the data display box (name, etc)
331 sal_uInt16 mnHighItemId
;
333 sal_uInt16 mnFirstLine
;
334 sal_uInt16 mnSpacing
;
336 bool mbIsTransientChildrenDisabled
: 1;
337 bool mbHasVisibleItems
: 1;
338 bool mbShowTooltips
: 1;
342 ThumbnailItemAttributes
*mpItemAttrs
;
343 drawinglayer::processor2d::BaseProcessor2D
*mpProcessor
;
344 boost::function
<bool (const ThumbnailViewItem
*) > maFilterFunc
;
347 #endif // INCLUDED_SFX2_THUMBNAILVIEW_HXX
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */