Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _VALUESET_HXX
30 : : #define _VALUESET_HXX
31 : :
32 : : #include "svtools/svtdllapi.h"
33 : :
34 : : #include <vcl/ctrl.hxx>
35 : : #include <vcl/virdev.hxx>
36 : : #include <vcl/timer.hxx>
37 : : #include <vector>
38 : :
39 : : class MouseEvent;
40 : : class TrackingEvent;
41 : : class HelpEvent;
42 : : class KeyEvent;
43 : : class DataChangedEvent;
44 : : class ScrollBar;
45 : :
46 : : struct ValueSetItem;
47 : : typedef ::std::vector< ValueSetItem* > ValueItemList;
48 : :
49 : : #ifdef _SV_VALUESET_CXX
50 : : class ValueSetAcc;
51 : : class ValueItemAcc;
52 : : #endif
53 : :
54 : : /*************************************************************************
55 : :
56 : : Description
57 : : ============
58 : :
59 : : class ValueSet
60 : :
61 : : This class allows the selection of an item. In the process items are
62 : : drawn side by side. The selection of items can be more clear than in a
63 : : ListBox shape for example in case of colors or samples.
64 : : The amount of columns drawn by the control and whether the items
65 : : should be encircled can be specified. Optional a NoSelection or name
66 : : field could be shown. By default image and color items are supported.
67 : : Items could be drawn by oneself if InsertItem() is only called with
68 : : an ID. To achieve this the UserDraw handler needs to be overloaded. The
69 : : description text could be specified afterwards in case of UserDraw
70 : : and any other items.
71 : :
72 : : Cross references
73 : :
74 : : class ListBox
75 : :
76 : : --------------------------------------------------------------------------
77 : :
78 : : WinBits
79 : :
80 : : WB_RADIOSEL If set the selection will be drawn like an
81 : : ImageRadioButton. This does only make sense if the image
82 : : is at least 8 pixel smaller on each side than the item
83 : : and also WB_DOUBLEBORDER is set and as color
84 : : COL_WINDOWWORKSPACE is specified.
85 : : WB_FLATVALUESET Flat Look (if you set WB_ITEMBORDER or WB_DOUBLEBORDER,
86 : : then you get extra border space, but the Borders
87 : : aren't painted),
88 : : WB_ITEMBORDER Items will be bordered
89 : : WB_DOUBLEBORDER Items will be bordered twice. Additionally WB_ITEMBORDER
90 : : has to be set, as otherwise this WinBit wouldn't have any
91 : : effect. It is needed if there are items with a white
92 : : background, since otherwise the 3D effect wouldn't be
93 : : recognizable.
94 : : WB_NAMEFIELD There is a namefield, where the name of an item will be
95 : : shown.
96 : : WB_NONEFIELD There is a NoSelection field which can be selected if
97 : : 0 is passed along with SelectItem. Respectively
98 : : GetSelectItemId() returns 0 if this field or nothing
99 : : is selected. This field shows the text which is specified
100 : : by SetText() respectively no one, if no text was set. With
101 : : SetNoSelection() the selection can be disabled.
102 : : WB_VSCROLL A scroolbar will be always shown. The visible number of
103 : : lines have to be specified with SetLineCount() if this
104 : : flag is set.
105 : : WB_BORDER A border will be drawn around the window.
106 : : WB_NOPOINTERFOCUS The focus won't be gathered, if the control was pressed by
107 : : the mouse.
108 : : WB_TABSTOP It is possible to jump into the ValueSet with the tab key.
109 : : WB_NOTABSTOP It is not possible to jump into the ValueSet with the
110 : : tab key.
111 : : WB_NO_DIRECTSELECT Cursor travelling doesn't call select immediately. To
112 : : execute the selection <RETURN> has to be pressed.
113 : : --------------------------------------------------------------------------
114 : :
115 : : The number of columns must be either set with SetColCount() or
116 : : SetItemWidth(). If the number of colums is specified by SetColCount()
117 : : the width of the items will be calculated by the visible range.
118 : : If the items should have a static width, it has to be specified
119 : : with SetItemWidth(). In this case the number of columns will be calculated
120 : : by the visible range.
121 : :
122 : : The number of rows is given by the number of items / number of columns. The
123 : : number of visible rows must either specified by SetLineCount() or
124 : : SetItemWidth(). If the number of visible rows is specified by SetLineCount(),
125 : : the height of the items will be calculated from the visible height. If the
126 : : items should have a fixed height it has to be specified with SetItemHeight().
127 : : In this case the number of visible rows is then calculated from the visible
128 : : height. If the number of visible rows is neither specified by SetLineCount()
129 : : nor by SetItemHeight() all rows will be shown. The height of the items will
130 : : be calculated by the visible height. If the number of visible rows is
131 : : specified by SetLineCount() or SetItemHeight() ValueSet does scroll
132 : : automatically when more lines are available, as are visible. If scrolling
133 : : should be also possible with a ScrollBar WB_VSCROLL needs to be set.
134 : :
135 : : The distance between the items can be increased by SetExtraSpacing(). The
136 : : distance, which will be shown between two items (both in x and in y), is
137 : : measured in pixels.
138 : :
139 : : The exact window size for a specific item size can be calculated by
140 : : CalcWindowSizePixel(). To do this all relevant data (number of columns/...)
141 : : have to be specified and if no number of rows was set, all items need to
142 : : be inserted. If the window was created with WB_BORDER/Border=sal_True the
143 : : size has to be specified with SetOutputSizePixel(). In other cases different
144 : : size-methods can be used. With CalcItemSize() the inner and outer size of
145 : : an item could be calculated (for this the free space defined by
146 : : SetExtraSpacing() will not be included).
147 : :
148 : : The background color could be specified by SetColor(), with which the image
149 : : or UserDraw items will be underlayed. If no color is specified the the color
150 : : of other windows (WindowColor) will be used for the background.
151 : :
152 : : --------------------------------------------------------------------------
153 : :
154 : : At first all items should be inserted and only then Show() should be called
155 : : since the output area will be precomputed. If this is not done the first
156 : : Paint will appear a little bit slower. Therefore the Control, if it is loaded
157 : : from the resource and only supplied with items during runtime, should be
158 : : loaded with Hide = sal_True and then displayed with Show().
159 : :
160 : : In case of a visible Control the creation of the new output area could be
161 : : activated before Paint by calling Format().
162 : :
163 : : --------------------------------------------------------------------------
164 : :
165 : : If Drag and Drop will be called from the ValueSet the Command-Handler has to
166 : : be overloaded. From this StartDrag needs to be called. If this method returns
167 : : sal_True the drag-process could be initiated by ExecuteDrag(), otherwise no
168 : : processing will take place. This method makes sure that ValueSet stops its
169 : : processing and as appropriate selects the entry. Therefore the calling of
170 : : Select-Handler within this function must be expected.
171 : :
172 : : For dropping QueryDrop() and Drop() need to be overloaded and ShowDropPos()
173 : : and HideDropPos() should be called within these methods.
174 : : To show the insertion point ShowDropPos() has to be called within the
175 : : QueryDrop-Handler. ShowDropPos() also scrolls the ValueSet if the passed
176 : : position is located at the window border. Furthermore ShowDropPos() returns
177 : : the position, at which the item should be inserted respectively which
178 : : insertion point was shown. If no insertion point was determined
179 : : VALUESET_ITEM_NOTFOUND will be returned. If the window was left during dragging
180 : : or the drag process is terminated HideDropPos() should be called in any case.
181 : :
182 : : --------------------------------------------------------------------------
183 : :
184 : : This class is currently still in the SV-Tools. That's why the ValueSet needs
185 : : to be loaded as a Control out of the resource and the desired WinBits have
186 : : to be set (before Show) with SetStyle().
187 : :
188 : : *************************************************************************/
189 : :
190 : : // ------------------
191 : : // - ValueSet types -
192 : : // ------------------
193 : :
194 : : #define WB_RADIOSEL ((WinBits)0x00008000)
195 : : #define WB_ITEMBORDER ((WinBits)0x00010000)
196 : : #define WB_DOUBLEBORDER ((WinBits)0x00020000)
197 : : #define WB_NAMEFIELD ((WinBits)0x00040000)
198 : : #define WB_NONEFIELD ((WinBits)0x00080000)
199 : : #define WB_FLATVALUESET ((WinBits)0x02000000)
200 : : #define WB_NO_DIRECTSELECT ((WinBits)0x04000000)
201 : : #define WB_MENUSTYLEVALUESET ((WinBits)0x08000000)
202 : :
203 : : // ------------
204 : : // - ValueSet -
205 : : // ------------
206 : :
207 : : #define VALUESET_APPEND ((sal_uInt16)-1)
208 : : #define VALUESET_ITEM_NOTFOUND ((sal_uInt16)-1)
209 : :
210 : : class SVT_DLLPUBLIC ValueSet : public Control
211 : : {
212 : : private:
213 : :
214 : : VirtualDevice maVirDev;
215 : : Timer maTimer;
216 : : ValueItemList mItemList;
217 : : ValueSetItem* mpNoneItem;
218 : : ScrollBar* mpScrBar;
219 : : Rectangle maNoneItemRect;
220 : : Rectangle maItemListRect;
221 : : long mnItemWidth;
222 : : long mnItemHeight;
223 : : long mnTextOffset;
224 : : long mnVisLines;
225 : : long mnLines;
226 : : long mnUserItemWidth;
227 : : long mnUserItemHeight;
228 : : sal_uInt16 mnSelItemId;
229 : : sal_uInt16 mnHighItemId;
230 : : sal_uInt16 mnCols;
231 : : sal_uInt16 mnCurCol;
232 : : sal_uInt16 mnUserCols;
233 : : sal_uInt16 mnUserVisLines;
234 : : sal_uInt16 mnFirstLine;
235 : : sal_uInt16 mnSpacing;
236 : : sal_uInt16 mnFrameStyle;
237 : : bool mbFormat : 1;
238 : : bool mbHighlight : 1;
239 : : bool mbSelection : 1;
240 : : bool mbNoSelection : 1;
241 : : bool mbDrawSelection : 1;
242 : : bool mbBlackSel : 1;
243 : : bool mbDoubleSel : 1;
244 : : bool mbScroll : 1;
245 : : bool mbFullMode : 1;
246 : : bool mbIsTransientChildrenDisabled : 1;
247 : : bool mbHasVisibleItems : 1;
248 : : Color maColor;
249 : : Link maDoubleClickHdl;
250 : : Link maSelectHdl;
251 : : Link maHighlightHdl;
252 : :
253 : : #ifdef _SV_VALUESET_CXX
254 : : friend class ValueSetAcc;
255 : : friend class ValueItemAcc;
256 : : using Control::ImplInitSettings;
257 : : using Window::ImplInit;
258 : : SVT_DLLPRIVATE void ImplInit();
259 : : SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
260 : : SVT_DLLPRIVATE void ImplInitScrollBar();
261 : : SVT_DLLPRIVATE void ImplDeleteItems();
262 : : SVT_DLLPRIVATE void ImplFormatItem( ValueSetItem* pItem, Rectangle aRect );
263 : : SVT_DLLPRIVATE void ImplDrawItemText( const XubString& rStr );
264 : : SVT_DLLPRIVATE void ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel );
265 : : SVT_DLLPRIVATE void ImplDrawSelect();
266 : : SVT_DLLPRIVATE void ImplHideSelect( sal_uInt16 nItemId );
267 : : SVT_DLLPRIVATE void ImplHighlightItem( sal_uInt16 nItemId, bool bIsSelection = true );
268 : : SVT_DLLPRIVATE void ImplDraw();
269 : : using Window::ImplScroll;
270 : : SVT_DLLPRIVATE bool ImplScroll( const Point& rPos );
271 : : SVT_DLLPRIVATE size_t ImplGetItem( const Point& rPoint, bool bMove = false ) const;
272 : : SVT_DLLPRIVATE ValueSetItem* ImplGetItem( size_t nPos );
273 : : SVT_DLLPRIVATE ValueSetItem* ImplGetFirstItem();
274 : : SVT_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const;
275 : : SVT_DLLPRIVATE ValueSetItem* ImplGetVisibleItem( sal_uInt16 nVisiblePos );
276 : : SVT_DLLPRIVATE void ImplInsertItem( ValueSetItem *const pItem, const size_t nPos );
277 : : SVT_DLLPRIVATE Rectangle ImplGetItemRect( size_t nPos ) const;
278 : : SVT_DLLPRIVATE void ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
279 : : SVT_DLLPRIVATE bool ImplHasAccessibleListeners();
280 : : SVT_DLLPRIVATE void ImplTracking( const Point& rPos, bool bRepeat );
281 : : SVT_DLLPRIVATE void ImplEndTracking( const Point& rPos, bool bCancel );
282 : : DECL_DLLPRIVATE_LINK( ImplScrollHdl, ScrollBar* );
283 : : DECL_DLLPRIVATE_LINK( ImplTimerHdl, void* );
284 : : #endif
285 : :
286 : : // Forbidden and not implemented.
287 : : ValueSet (const ValueSet &);
288 : : ValueSet & operator= (const ValueSet &);
289 : :
290 : : protected:
291 : :
292 : : bool StartDrag( const CommandEvent& rCEvt, Region& rRegion );
293 : :
294 : : protected:
295 : :
296 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
297 : :
298 : : public:
299 : : ValueSet( Window* pParent, WinBits nWinStyle = WB_ITEMBORDER, bool bDisableTransientChildren = false );
300 : : ValueSet( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false );
301 : : ~ValueSet();
302 : :
303 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
304 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
305 : : virtual void MouseMove( const MouseEvent& rMEvt );
306 : : virtual void Tracking( const TrackingEvent& rMEvt );
307 : : virtual void KeyInput( const KeyEvent& rKEvt );
308 : : virtual void Command( const CommandEvent& rCEvt );
309 : : virtual void Paint( const Rectangle& rRect );
310 : : virtual void GetFocus();
311 : : virtual void LoseFocus();
312 : : virtual void Resize();
313 : : virtual void RequestHelp( const HelpEvent& rHEvt );
314 : : virtual void StateChanged( StateChangedType nStateChange );
315 : : virtual void DataChanged( const DataChangedEvent& rDCEvt );
316 : :
317 : : virtual void Select();
318 : : virtual void DoubleClick();
319 : : virtual void UserDraw( const UserDrawEvent& rUDEvt );
320 : :
321 : : void InsertItem( sal_uInt16 nItemId, const Image& rImage,
322 : : size_t nPos = VALUESET_APPEND );
323 : : void InsertItem( sal_uInt16 nItemId, const Color& rColor,
324 : : size_t nPos = VALUESET_APPEND );
325 : : void InsertItem( sal_uInt16 nItemId,
326 : : const Image& rImage, const XubString& rStr,
327 : : size_t nPos = VALUESET_APPEND );
328 : : void InsertItem( sal_uInt16 nItemId,
329 : : const Color& rColor, const XubString& rStr,
330 : : size_t nPos = VALUESET_APPEND );
331 : : void InsertItem( sal_uInt16 nItemId,
332 : : size_t nPos = VALUESET_APPEND );
333 : : void RemoveItem( sal_uInt16 nItemId );
334 : :
335 : : void Clear();
336 : :
337 : : size_t GetItemCount() const;
338 : : size_t GetItemPos( sal_uInt16 nItemId ) const;
339 : : sal_uInt16 GetItemId( size_t nPos ) const;
340 : : sal_uInt16 GetItemId( const Point& rPos ) const;
341 : : Rectangle GetItemRect( sal_uInt16 nItemId ) const;
342 : :
343 : : void EnableFullItemMode( bool bFullMode = true );
344 : : bool IsFullItemModeEnabled() const { return mbFullMode; }
345 : : void SetColCount( sal_uInt16 nNewCols = 1 );
346 : 0 : sal_uInt16 GetColCount() const { return mnUserCols; }
347 : : void SetLineCount( sal_uInt16 nNewLines = 0 );
348 : 0 : sal_uInt16 GetLineCount() const { return mnUserVisLines; }
349 : : void SetItemWidth( long nItemWidth = 0 );
350 : : long GetItemWidth() const { return mnUserItemWidth; }
351 : : void SetItemHeight( long nLineHeight = 0 );
352 : : long GetItemHeight() const { return mnUserItemHeight; }
353 : : sal_uInt16 GetFirstLine() const { return mnFirstLine; }
354 : :
355 : : void SelectItem( sal_uInt16 nItemId );
356 : 17 : sal_uInt16 GetSelectItemId() const { return mnSelItemId; }
357 : 0 : bool IsItemSelected( sal_uInt16 nItemId ) const
358 [ # # ][ # # ]: 0 : { return !mbNoSelection && (nItemId == mnSelItemId); }
359 : : void SetNoSelection();
360 : 0 : bool IsNoSelection() const { return mbNoSelection; }
361 : :
362 : : void SetItemImage( sal_uInt16 nItemId, const Image& rImage );
363 : : Image GetItemImage( sal_uInt16 nItemId ) const;
364 : : void SetItemColor( sal_uInt16 nItemId, const Color& rColor );
365 : : Color GetItemColor( sal_uInt16 nItemId ) const;
366 : : void SetItemData( sal_uInt16 nItemId, void* pData );
367 : : void* GetItemData( sal_uInt16 nItemId ) const;
368 : : void SetItemText( sal_uInt16 nItemId, const XubString& rStr );
369 : : XubString GetItemText( sal_uInt16 nItemId ) const;
370 : : void SetColor( const Color& rColor );
371 [ + - ]: 17 : void SetColor() { SetColor( Color( COL_TRANSPARENT ) ); }
372 : : Color GetColor() const { return maColor; }
373 : 636 : bool IsColor() const { return maColor.GetTransparency() == 0; }
374 : :
375 : : void SetExtraSpacing( sal_uInt16 nNewSpacing );
376 : : sal_uInt16 GetExtraSpacing() { return mnSpacing; }
377 : :
378 : : void Format();
379 : :
380 : : void StartSelection();
381 : : void EndSelection();
382 : :
383 : : Size CalcWindowSizePixel( const Size& rItemSize,
384 : : sal_uInt16 nCalcCols = 0,
385 : : sal_uInt16 nCalcLines = 0 );
386 : : Size CalcItemSizePixel( const Size& rSize, bool bOut = true ) const;
387 : : long GetScrollWidth() const;
388 : :
389 : 32 : void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
390 : : const Link& GetSelectHdl() const { return maSelectHdl; }
391 : 0 : void SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; }
392 : : const Link& GetDoubleClickHdl() const { return maDoubleClickHdl; }
393 : :
394 : : void SetHighlightHdl( const Link& rLink );
395 : : };
396 : :
397 : : #endif // _VALUESET_HXX
398 : :
399 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|