LibreOffice Module svtools (master) 1
valueset.hxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <svtools/svtdllapi.h>
23#include <vcl/wintypes.hxx>
24#include <vcl/customweld.hxx>
25#include <vcl/image.hxx>
26#include <memory>
27#include <vector>
28
29class MouseEvent;
30class TrackingEvent;
31class HelpEvent;
32class KeyEvent;
34class ScrollBar;
35class UserDrawEvent;
36class VirtualDevice;
37
38struct ValueSetItem;
39
40enum class DrawFrameStyle;
41
42/*************************************************************************
43
44Description
45============
46
47class ValueSet
48
49This class allows the selection of an item. In the process items are
50drawn side by side. The selection of items can be more clear than in a
51ListBox shape for example in case of colors or samples.
52The amount of columns drawn by the control and whether the items
53should be encircled can be specified. Optional a NoSelection or name
54field could be shown. By default image and color items are supported.
55Items could be drawn by oneself if InsertItem() is only called with
56an ID. To achieve this the UserDraw handler needs to be overridden. The
57description text could be specified afterwards in case of UserDraw
58and any other items.
59
60Cross references
61
62class ListBox
63
64--------------------------------------------------------------------------
65
66WinBits
67
68WB_FLATVALUESET Flat Look (if you set WB_ITEMBORDER or WB_DOUBLEBORDER,
69 then you get extra border space, but the Borders
70 aren't painted),
71WB_ITEMBORDER Items will be bordered
72WB_DOUBLEBORDER Items will be bordered twice. Additionally WB_ITEMBORDER
73 has to be set, as otherwise this WinBit wouldn't have any
74 effect. It is needed if there are items with a white
75 background, since otherwise the 3D effect wouldn't be
76 recognizable.
77WB_NAMEFIELD There is a namefield, where the name of an item will be
78 shown.
79WB_NONEFIELD There is a NoSelection field which can be selected if
80 0 is passed along with SelectItem. Respectively
81 GetSelectedItemId() returns 0 if this field or nothing
82 is selected. This field shows the text which is specified
83 by SetText() respectively no one, if no text was set. With
84 SetNoSelection() the selection can be disabled.
85WB_VSCROLL A scrollbar will be always shown. The visible number of
86 lines have to be specified with SetLineCount() if this
87 flag is set.
88WB_BORDER A border will be drawn around the window.
89WB_TABSTOP It is possible to jump into the ValueSet with the tab key.
90WB_NOTABSTOP It is not possible to jump into the ValueSet with the
91 tab key.
92WB_NO_DIRECTSELECT Cursor travelling doesn't call select immediately. To
93 execute the selection <RETURN> has to be pressed.
94--------------------------------------------------------------------------
95
96The number of columns must be either set with SetColCount() or
97SetItemWidth(). If the number of columns is specified by SetColCount()
98the width of the items will be calculated by the visible range.
99If the items should have a static width, it has to be specified
100with SetItemWidth(). In this case the number of columns will be calculated
101by the visible range.
102
103The number of rows is given by the number of items / number of columns. The
104number of visible rows must either specified by SetLineCount() or
105SetItemWidth(). If the number of visible rows is specified by SetLineCount(),
106the height of the items will be calculated from the visible height. If the
107items should have a fixed height it has to be specified with SetItemHeight().
108In this case the number of visible rows is then calculated from the visible
109height. If the number of visible rows is neither specified by SetLineCount()
110nor by SetItemHeight() all rows will be shown. The height of the items will
111be calculated by the visible height. If the number of visible rows is
112specified by SetLineCount() or SetItemHeight() ValueSet does scroll
113automatically when more lines are available, as are visible. If scrolling
114should be also possible with a ScrollBar WB_VSCROLL needs to be set.
115
116The distance between the items can be increased by SetExtraSpacing(). The
117distance, which will be shown between two items (both in x and in y), is
118measured in pixels.
119
120The exact window size for a specific item size can be calculated by
121CalcWindowSizePixel(). To do this all relevant data (number of columns/...)
122have to be specified and if no number of rows was set, all items need to
123be inserted. If the window was created with WB_BORDER/Border=sal_True the
124size has to be specified with SetOutputSizePixel(). In other cases different
125size-methods can be used. With CalcItemSize() the inner and outer size of
126an item could be calculated (for this the free space defined by
127SetExtraSpacing() will not be included).
128
129The background color could be specified by SetColor(), with which the image
130or UserDraw items will be underlaid. If no color is specified the color
131of other windows (WindowColor) will be used for the background.
132
133--------------------------------------------------------------------------
134
135At first all items should be inserted and only then Show() should be called
136since the output area will be precomputed. If this is not done the first
137Paint will appear a little bit slower. Therefore the Control, if it is loaded
138from the resource and only supplied with items during runtime, should be
139loaded with Hide = sal_True and then displayed with Show().
140
141In case of a visible Control the creation of the new output area could be
142activated before Paint by calling Format().
143
144--------------------------------------------------------------------------
145
146If Drag and Drop will be called from the ValueSet the Command-Handler has to
147be overridden. From this StartDrag needs to be called. If this method returns
148sal_True the drag-process could be initiated by ExecuteDrag(), otherwise no
149processing will take place. This method makes sure that ValueSet stops its
150processing and as appropriate selects the entry. Therefore the calling of
151Select-Handler within this function must be expected.
152
153For dropping QueryDrop() and Drop() need to be overridden and ShowDropPos()
154and HideDropPos() should be called within these methods.
155To show the insertion point ShowDropPos() has to be called within the
156QueryDrop-Handler. ShowDropPos() also scrolls the ValueSet if the passed
157position is located at the window border. Furthermore ShowDropPos() returns
158the position, at which the item should be inserted respectively which
159insertion point was shown. If no insertion point was determined
160VALUESET_ITEM_NOTFOUND will be returned. If the window was left during dragging
161or the drag process is terminated HideDropPos() should be called in any case.
162
163--------------------------------------------------------------------------
164
165This class is currently still in the SV-Tools. That's why the ValueSet needs
166to be loaded as a Control out of the resource and the desired WinBits have
167to be set (before Show) with SetStyle().
168
169*************************************************************************/
170
171typedef std::vector<std::unique_ptr<ValueSetItem>> ValueItemList;
172
173#define WB_ITEMBORDER (WinBits(0x00010000))
174#define WB_DOUBLEBORDER (WinBits(0x00020000))
175#define WB_NAMEFIELD (WinBits(0x00040000))
176#define WB_NONEFIELD (WinBits(0x00080000))
177#define WB_FLATVALUESET (WinBits(0x02000000))
178#define WB_NO_DIRECTSELECT (WinBits(0x04000000))
179#define WB_MENUSTYLEVALUESET (WinBits(0x08000000))
180
181#define VALUESET_APPEND (size_t(-1))
182#define VALUESET_ITEM_NOTFOUND (size_t(-1))
183
185{
186private:
188 css::uno::Reference<css::accessibility::XAccessible> mxAccessible;
190 std::unique_ptr<ValueSetItem> mpNoneItem;
191 std::unique_ptr<weld::ScrolledWindow> mxScrolledWindow;
201 sal_uInt16 mnSelItemId;
203 sal_uInt16 mnHighItemId;
204 sal_uInt16 mnCols;
205 sal_uInt16 mnCurCol;
206 sal_uInt16 mnUserCols;
207 sal_uInt16 mnUserVisLines;
208 sal_uInt16 mnFirstLine;
209 sal_uInt16 mnSpacing;
212 OUString maText;
216
217 bool mbFormat : 1;
218 bool mbHighlight : 1;
220 bool mbDoubleSel : 1;
221 bool mbScroll : 1;
222 bool mbFullMode : 1;
225
226 friend class ValueItemAcc;
227 friend class ValueSetAcc;
228
229 SVT_DLLPRIVATE void ImplDeleteItems();
230 SVT_DLLPRIVATE void ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem* pItem, tools::Rectangle aRect);
231 SVT_DLLPRIVATE void ImplDrawItemText(vcl::RenderContext& rRenderContext, const OUString& rStr);
232 // nItemId is the item to draw selected, but if nothing is selected something else may be drawn as selected instead, the item to draw
233 // selected is returned
234 SVT_DLLPRIVATE ValueSetItem* ImplGetDrawSelectItem(sal_uInt16 nItemId, const bool bFocus, tools::Rectangle& rRect);
235 SVT_DLLPRIVATE void ImplDrawSelect(vcl::RenderContext& rRenderContext,
236 const tools::Rectangle& rRect, const ValueSetItem* pItem,
237 const bool bFocus, const bool bDrawSel,
238 const bool bSelected, const bool bHover);
239 SVT_DLLPRIVATE void ImplDrawSelect(vcl::RenderContext& rRenderContext);
240 SVT_DLLPRIVATE void ImplHighlightItem(sal_uInt16 nItemId);
241 SVT_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext);
242 SVT_DLLPRIVATE size_t ImplGetItem( const Point& rPoint ) const;
243 SVT_DLLPRIVATE ValueSetItem* ImplGetItem( size_t nPos );
244 SVT_DLLPRIVATE ValueSetItem* ImplGetFirstItem();
245 SVT_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const;
246 SVT_DLLPRIVATE void ImplInsertItem( std::unique_ptr<ValueSetItem> pItem, const size_t nPos );
247 SVT_DLLPRIVATE tools::Rectangle ImplGetItemRect( size_t nPos ) const;
248 SVT_DLLPRIVATE void ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
249 SVT_DLLPRIVATE bool ImplHasAccessibleListeners() const;
250 SVT_DLLPRIVATE void ImplTracking(bool bLeaveWindow, const Point& rPos);
251 SVT_DLLPRIVATE void QueueReformat();
252 SVT_DLLPRIVATE void SetFirstLine(sal_uInt16 nNewFirstLine); // set mnFirstLine and update scrollbar to match
253 SVT_DLLPRIVATE void RecalcScrollBar();
254 SVT_DLLPRIVATE bool TurnOffScrollBar();
255 SVT_DLLPRIVATE void TurnOnScrollBar();
257
258 Size GetLargestItemSize();
259
260 ValueSet (const ValueSet &) = delete;
261 ValueSet & operator= (const ValueSet &) = delete;
262
263protected:
264 virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
265 weld::ScrolledWindow* GetScrollBar() const { return mxScrolledWindow.get(); }
266
267public:
268 ValueSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow);
269 virtual ~ValueSet() override;
270
271 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
272
273 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
274 virtual bool MouseButtonUp( const MouseEvent& rMEvt ) override;
275 virtual bool MouseMove( const MouseEvent& rMEvt ) override;
276 virtual bool KeyInput( const KeyEvent& rKEvt ) override;
277 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
278 virtual void GetFocus() override;
279 virtual void LoseFocus() override;
280 virtual void Resize() override;
281 virtual void StyleUpdated() override;
282 virtual void Show() override;
283 virtual void Hide() override;
284 virtual OUString RequestHelp(tools::Rectangle& rHelpRect) override;
285
286 virtual void Select();
287 virtual void UserDraw( const UserDrawEvent& rUDEvt );
288
289 OUString const & GetText() const { return maText; }
290 void SetText(const OUString& rText) { maText = rText; }
291 void SetStyle(WinBits nStyle);
292 WinBits GetStyle() const { return mnStyle; }
293
294 void SetOptimalSize();
295
297 void InsertItem(sal_uInt16 nItemId, const Image& rImage);
299 void InsertItem(sal_uInt16 nItemId, const Image& rImage,
300 const OUString& rStr, size_t nPos = VALUESET_APPEND, bool bShowLegend = false);
302 void InsertItem(sal_uInt16 nItemId, const Color& rColor,
303 const OUString& rStr);
305 void InsertItem(sal_uInt16 nItemId, size_t nPos = VALUESET_APPEND);
307 void InsertItem(sal_uInt16 nItemId, const OUString& rStr, size_t nPos);
308 void RemoveItem(sal_uInt16 nItemId);
309
310 void Clear();
311
312 size_t GetItemCount() const;
313 size_t GetItemPos( sal_uInt16 nItemId ) const;
314 sal_uInt16 GetItemId( size_t nPos ) const;
315 sal_uInt16 GetItemId( const Point& rPos ) const;
316 tools::Rectangle GetItemRect( sal_uInt16 nItemId ) const;
317 void EnableFullItemMode( bool bFullMode );
318
319 void SetColCount( sal_uInt16 nNewCols = 1 );
320 sal_uInt16 GetColCount() const
321 {
322 return mnUserCols;
323 }
324 void SetLineCount( sal_uInt16 nNewLines = 0 );
325 sal_uInt16 GetLineCount() const
326 {
327 return mnUserVisLines;
328 }
329 void SetItemWidth( tools::Long nItemWidth );
330 void SetItemHeight( tools::Long nLineHeight );
331
332 void SelectItem( sal_uInt16 nItemId );
333 sal_uInt16 GetSelectedItemId() const
334 {
335 return mnSelItemId;
336 }
337 size_t GetSelectItemPos() const
338 {
339 return GetItemPos( mnSelItemId );
340 }
341 bool IsItemSelected( sal_uInt16 nItemId ) const
342 {
343 return !mbNoSelection && (nItemId == mnSelItemId);
344 }
345 void SetNoSelection();
346 bool IsNoSelection() const
347 {
348 return mbNoSelection;
349 }
350
351 void RecalculateItemSizes();
352
353 void SetItemImage( sal_uInt16 nItemId, const Image& rImage );
354 Image GetItemImage( sal_uInt16 nItemId ) const;
355 void SetItemColor( sal_uInt16 nItemId, const Color& rColor );
356 Color GetItemColor( sal_uInt16 nItemId ) const;
357 void SetItemData( sal_uInt16 nItemId, void* pData );
358 void* GetItemData( sal_uInt16 nItemId ) const;
359 void SetItemText( sal_uInt16 nItemId, const OUString& rStr );
360 OUString GetItemText( sal_uInt16 nItemId ) const;
361 void SetColor( const Color& rColor );
362 void SetColor()
363 {
364 SetColor(COL_TRANSPARENT);
365 }
366 bool IsColor() const
367 {
368 return !maColor.IsTransparent();
369 }
370
371 void SetExtraSpacing( sal_uInt16 nNewSpacing );
372
373 void Format(vcl::RenderContext const & rRenderContext);
374 void SetFormat();
375
376 Size CalcWindowSizePixel(const Size& rItemSize,
377 sal_uInt16 nCalcCols = 0,
378 sal_uInt16 nCalcLines = 0) const;
379 Size CalcItemSizePixel(const Size& rSize) const;
380 int GetScrollWidth() const;
381
383 {
384 maSelectHdl = rLink;
385 }
386
388 {
389 maDoubleClickHdl = rLink;
390 }
391
392 bool GetEdgeBlending() const
393 {
394 return mbEdgeBlending;
395 }
396 void SetEdgeBlending(bool bNew);
397
399 {
400 mnSavedItemId = IsNoSelection() ? -1 : GetSelectedItemId();
401 }
402
404 {
405 int nItemId = IsNoSelection() ? -1 : GetSelectedItemId();
406 return mnSavedItemId != nItemId;
407 }
408
409 virtual FactoryFunction GetUITestFactory() const override;
410};
411
412/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::BColor maColor
Text maText
void SetSelectHdl(const Link< ValueSet *, void > &rLink)
Definition: valueset.hxx:382
tools::Long mnUserItemWidth
Definition: valueset.hxx:199
tools::Long mnLines
Definition: valueset.hxx:198
Link< ValueSet *, void > maSelectHdl
Definition: valueset.hxx:215
bool mbHasVisibleItems
Definition: valueset.hxx:224
tools::Rectangle maNoneItemRect
Definition: valueset.hxx:192
sal_uInt16 mnSelItemId
Definition: valueset.hxx:201
bool IsNoSelection() const
Definition: valueset.hxx:346
OUString const & GetText() const
Definition: valueset.hxx:289
void SaveValue()
Definition: valueset.hxx:398
bool mbFormat
Definition: valueset.hxx:217
sal_uInt16 mnUserCols
Definition: valueset.hxx:206
tools::Long mnItemWidth
Definition: valueset.hxx:194
void SetDoubleClickHdl(const Link< ValueSet *, void > &rLink)
Definition: valueset.hxx:387
sal_uInt16 GetSelectedItemId() const
Definition: valueset.hxx:333
css::uno::Reference< css::accessibility::XAccessible > mxAccessible
Definition: valueset.hxx:188
std::unique_ptr< ValueSetItem > mpNoneItem
Definition: valueset.hxx:190
WinBits mnStyle
Definition: valueset.hxx:213
int mnSavedItemId
Definition: valueset.hxx:202
tools::Long mnTextOffset
Definition: valueset.hxx:196
tools::Long mnUserItemHeight
Definition: valueset.hxx:200
bool mbNoSelection
Definition: valueset.hxx:219
void SetColor()
Definition: valueset.hxx:362
ScopedVclPtr< VirtualDevice > maVirDev
Definition: valueset.hxx:187
WinBits GetStyle() const
Definition: valueset.hxx:292
sal_uInt16 mnHighItemId
Definition: valueset.hxx:203
bool mbScroll
Definition: valueset.hxx:221
DECL_DLLPRIVATE_LINK(ImplScrollHdl, weld::ScrolledWindow &, void)
bool GetEdgeBlending() const
Definition: valueset.hxx:392
sal_uInt16 GetColCount() const
Definition: valueset.hxx:320
sal_uInt16 GetLineCount() const
Definition: valueset.hxx:325
bool mbHighlight
Definition: valueset.hxx:218
ValueItemList mItemList
Definition: valueset.hxx:189
OUString maText
Definition: valueset.hxx:212
bool mbDoubleSel
Definition: valueset.hxx:220
bool mbFullMode
Definition: valueset.hxx:222
sal_uInt16 mnCols
Definition: valueset.hxx:204
bool IsItemSelected(sal_uInt16 nItemId) const
Definition: valueset.hxx:341
sal_uInt16 mnSpacing
Definition: valueset.hxx:209
size_t GetSelectItemPos() const
Definition: valueset.hxx:337
weld::ScrolledWindow * GetScrollBar() const
Definition: valueset.hxx:265
Link< ValueSet *, void > maDoubleClickHdl
Definition: valueset.hxx:214
bool IsValueChangedFromSaved() const
Definition: valueset.hxx:403
ValueSet(const ValueSet &)=delete
tools::Long mnItemHeight
Definition: valueset.hxx:195
sal_uInt16 mnUserVisLines
Definition: valueset.hxx:207
tools::Rectangle maItemListRect
Definition: valueset.hxx:193
void SetText(const OUString &rText)
Definition: valueset.hxx:290
bool mbEdgeBlending
Definition: valueset.hxx:223
tools::Long mnVisLines
Definition: valueset.hxx:197
Color maColor
Definition: valueset.hxx:211
std::unique_ptr< weld::ScrolledWindow > mxScrolledWindow
Definition: valueset.hxx:191
DrawFrameStyle mnFrameStyle
Definition: valueset.hxx:210
bool IsColor() const
Definition: valueset.hxx:366
sal_uInt16 mnCurCol
Definition: valueset.hxx:205
sal_uInt16 mnFirstLine
Definition: valueset.hxx:208
virtual bool KeyInput(const KeyEvent &)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)=0
virtual bool MouseMove(const MouseEvent &)
virtual FactoryFunction GetUITestFactory() const
virtual bool MouseButtonDown(const MouseEvent &)
virtual OUString RequestHelp(tools::Rectangle &)
virtual bool MouseButtonUp(const MouseEvent &)
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
CustomWidgetController & operator=(CustomWidgetController const &)=default
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
std::function< std::unique_ptr< UIObject >(vcl::Window *)> FactoryFunction
void Clear(EHistoryType eHistory)
long Long
#define SVT_DLLPUBLIC
Definition: svtdllapi.h:27
#define SVT_DLLPRIVATE
Definition: svtdllapi.h:29
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
std::vector< std::unique_ptr< ValueSetItem > > ValueItemList
Definition: valueset.hxx:40
#define VALUESET_APPEND
Definition: valueset.hxx:181
DrawFrameStyle
sal_Int64 WinBits