LibreOffice Module vcl (master)  1
lstbox.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 #ifndef INCLUDED_VCL_LSTBOX_HXX
21 #define INCLUDED_VCL_LSTBOX_HXX
22 
23 #include <sal/types.h>
24 #include <o3tl/typed_flags_set.hxx>
25 #include <vcl/dllapi.h>
26 #include <vcl/ctrl.hxx>
27 
28 class DataChangedEvent;
29 class NotifyEvent;
30 class UserDrawEvent;
31 
32 #define LISTBOX_APPEND (SAL_MAX_INT32)
33 #define LISTBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
34 #define LISTBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
35 
36 // the following defines can be used for the SetEntryFlags()
37 // and GetEntryFlags() methods
38 
39 // !! Do not use these flags for user data as they are reserved !!
40 // !! to change the internal behaviour of the ListBox implementation !!
41 // !! for specific entries. !!
42 
44 {
45  NONE = 0x0000,
51  DisableSelection = 0x0001,
52 
58  MultiLine = 0x0002,
59 
63  DrawDisabled = 0x0004,
64 };
65 namespace o3tl
66 {
67  template<> struct typed_flags<ListBoxEntryFlags> : is_typed_flags<ListBoxEntryFlags, 0x0007> {};
68 }
69 
70 class Image;
71 class ImplListBox;
73 class ImplBtn;
74 class ImplWin;
75 class ImplListBoxWindow;
76 
79 {
80 private:
85  sal_uInt16 mnDDHeight;
86  sal_Int32 mnSaveValue;
87  sal_Int32 m_nMaxWidthChars;
90  sal_uInt16 mnLineCount;
91 
92  bool mbDDAutoSize : 1;
93 
94 private:
95  SAL_DLLPRIVATE void ImplInitListBoxData();
96 
97  DECL_DLLPRIVATE_LINK( ImplSelectHdl, LinkParamNone*, void );
98  DECL_DLLPRIVATE_LINK( ImplScrollHdl, ImplListBox*, void );
99  DECL_DLLPRIVATE_LINK( ImplCancelHdl, LinkParamNone*, void );
100  DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, ImplListBoxWindow*, void );
101  DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, FloatingWindow*, void );
102  DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, sal_Int32, void );
103  DECL_DLLPRIVATE_LINK( ImplUserDrawHdl, UserDrawEvent*, void );
104  DECL_DLLPRIVATE_LINK( ImplFocusHdl, sal_Int32, void );
105  DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl, LinkParamNone*, void );
106 
107  DECL_DLLPRIVATE_LINK( ImplClickBtnHdl, void*, void );
108 
109 protected:
110  using Window::ImplInit;
111  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
112  SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
113  bool IsDropDownBox() const { return mpFloatWin != nullptr; }
114 
115 protected:
116  explicit ListBox( WindowType nType );
117 
118  virtual void FillLayoutData() const override;
119 
120 public:
121  explicit ListBox( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
122  virtual ~ListBox() override;
123  virtual void dispose() override;
124 
125  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
126  virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
127  virtual void Resize() override;
128  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
129  virtual void StateChanged( StateChangedType nType ) override;
130  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
131  virtual void UserDraw( const UserDrawEvent& rUDEvt );
132 
133  virtual void Select();
134  virtual void DoubleClick();
135  virtual void GetFocus() override;
136  virtual void LoseFocus() override;
137 
138  virtual const Wallpaper& GetDisplayBackground() const override;
139 
140  virtual void setPosSizePixel( long nX, long nY,
141  long nWidth, long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override;
142 
143  tools::Rectangle GetDropDownPosSizePixel() const;
144 
145  void AdaptDropDownLineCountToMaximum();
146  void SetDropDownLineCount( sal_uInt16 nLines );
147  sal_uInt16 GetDropDownLineCount() const;
148 
149  void EnableAutoSize( bool bAuto );
150  bool IsAutoSizeEnabled() const { return mbDDAutoSize; }
151 
152  sal_Int32 InsertEntry( const OUString& rStr, sal_Int32 nPos = LISTBOX_APPEND );
153  sal_Int32 InsertEntry( const OUString& rStr, const Image& rImage, sal_Int32 nPos = LISTBOX_APPEND );
154  void RemoveEntry( const OUString& rStr );
155  void RemoveEntry( sal_Int32 nPos );
156 
157  void Clear();
158 
159  sal_Int32 GetEntryPos( const OUString& rStr ) const;
160  sal_Int32 GetEntryPos( const void* pData ) const;
161  Image GetEntryImage( sal_Int32 nPos ) const;
162  OUString GetEntry( sal_Int32 nPos ) const;
163  sal_Int32 GetEntryCount() const;
164 
165  void SelectEntry( const OUString& rStr, bool bSelect = true );
166  void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
167 
168  sal_Int32 GetSelectedEntryCount() const;
169  OUString GetSelectedEntry( sal_Int32 nSelIndex = 0 ) const;
170  sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const;
171 
172  bool IsEntrySelected(const OUString& rStr) const;
173  bool IsEntryPosSelected( sal_Int32 nPos ) const;
174  void SetNoSelection();
175 
176  void SetEntryData( sal_Int32 nPos, void* pNewData );
177  void* GetEntryData( sal_Int32 nPos ) const;
178  void* GetSelectedEntryData() const { return GetEntryData(GetSelectedEntryPos()); }
179 
188  void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags );
189 
195  ListBoxEntryFlags GetEntryFlags( sal_Int32 nPos ) const;
196 
197  void SetTopEntry( sal_Int32 nPos );
198  sal_Int32 GetTopEntry() const;
199 
200  void SaveValue() { mnSaveValue = GetSelectedEntryPos(); }
201  sal_Int32 GetSavedValue() const { return mnSaveValue; }
202  bool IsValueChangedFromSaved() const { return mnSaveValue != GetSelectedEntryPos(); }
203 
208  void SetSeparatorPos( sal_Int32 n );
213  sal_Int32 GetSeparatorPos() const;
214 
218  void AddSeparator( sal_Int32 n );
219 
220  bool IsTravelSelect() const;
221  bool IsInDropDown() const;
222  void ToggleDropDown();
223 
224  void EnableMultiSelection( bool bMulti, bool bStackSelection );
225  void EnableMultiSelection( bool bMulti );
226  bool IsMultiSelectionEnabled() const;
227 
228  void SetReadOnly( bool bReadOnly = true );
229  bool IsReadOnly() const;
230 
231  tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
232 
233  void EnableUserDraw( bool bUserDraw );
234 
235  void DrawEntry( const UserDrawEvent& rEvt );
236 
237  void SetSelectHdl( const Link<ListBox&,void>& rLink ) { maSelectHdl = rLink; }
238  const Link<ListBox&,void>& GetSelectHdl() const { return maSelectHdl; }
239  void SetDoubleClickHdl( const Link<ListBox&,void>& rLink ) { maDoubleClickHdl = rLink; }
240  const Link<ListBox&,void>& GetDoubleClickHdl() const { return maDoubleClickHdl; }
241 
242  Size CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown
243  Size CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown
244  virtual Size GetOptimalSize() const override;
245  Size CalcAdjustedSize( const Size& rPrefSize ) const;
246  Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
247  void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
248 
249  sal_uInt16 GetDisplayLineCount() const;
250 
251  void EnableMirroring();
252 
272  long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
273 
274  void setMaxWidthChars(sal_Int32 nWidth);
275 
276  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
277 
278  void EnableQuickSelection( bool b );
279 
280  static sal_Int32 NaturalSortCompare(const OUString &rA, const OUString &rB);
281 
282  virtual FactoryFunction GetUITestFactory() const override;
283 
284  virtual boost::property_tree::ptree DumpAsPropertyTree() override;
285 };
286 
287 class VCL_DLLPUBLIC MultiListBox final : public ListBox
288 {
289 public:
290  explicit MultiListBox( vcl::Window* pParent, WinBits nStyle );
291 
292 };
293 
294 #endif // INCLUDED_VCL_LSTBOX_HXX
295 
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nMaxWidthChars
Definition: lstbox.hxx:87
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3072
bool IsDropDownBox() const
Definition: lstbox.hxx:113
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3889
sal_uInt16 mnDDHeight
Definition: lstbox.hxx:85
DECL_DLLPRIVATE_LINK(ImplHandlePaintHdl, Timer *, void)
VclPtr< ImplBtn > mpBtn
Definition: lstbox.hxx:84
A widget used to choose from a list of items and which has no entry.
Definition: lstbox.hxx:78
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
bool IsReadOnly(const OUString &rURL, bool *pbExist)
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
void SaveValue()
Definition: lstbox.hxx:200
sal_Int32 GetSavedValue() const
Definition: lstbox.hxx:201
PosSizeFlags
Definition: window.hxx:141
VclPtr< ImplListBox > mpImplLB
Definition: lstbox.hxx:81
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: ctrl.cxx:418
StateChangedType
Definition: window.hxx:311
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2686
sal_Int64 WinBits
this flags lets the item be drawn disabled (e.g.
bool IsValueChangedFromSaved() const
Definition: lstbox.hxx:202
virtual void Draw(::OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags)
Definition: window.cxx:1793
this flag disables a selection of an entry completely.
bool IsAutoSizeEnabled() const
Definition: lstbox.hxx:150
this flag can be used to make an entry multiline capable A normal entry is single line and will there...
virtual boost::property_tree::ptree DumpAsPropertyTree()
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: window.cxx:3355
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
sal_Int32 mnSaveValue
Definition: lstbox.hxx:86
DrawFlags
Definition: window.hxx:354
Link< ListBox &, void > maDoubleClickHdl
Definition: lstbox.hxx:89
void SetDoubleClickHdl(const Link< ListBox &, void > &rLink)
Definition: lstbox.hxx:239
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
virtual bool set_property(const OString &rKey, const OUString &rValue)
Definition: window2.cxx:1420
void SetSelectHdl(const Link< ListBox &, void > &rLink)
Definition: lstbox.hxx:237
virtual void LoseFocus()
Definition: window.cxx:1819
long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:134
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:932
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
virtual void Resize() override
Definition: ctrl.cxx:74
sal_uInt16 mnLineCount
Definition: lstbox.hxx:90
WindowType
VclPtr< ImplListBoxFloatingWindow > mpFloatWin
Definition: lstbox.hxx:82
Definition: ctrl.hxx:33
ListBoxEntryFlags
Definition: lstbox.hxx:43
virtual void GetFocus()
Definition: window.cxx:1805
Definition: image.hxx:40
const Link< ListBox &, void > & GetDoubleClickHdl() const
Definition: lstbox.hxx:240
#define LISTBOX_APPEND
Definition: lstbox.hxx:32
VclPtr< ImplWin > mpImplWin
Definition: lstbox.hxx:83
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:205
const Link< ListBox &, void > & GetSelectHdl() const
Definition: lstbox.hxx:238
void * GetSelectedEntryData() const
Definition: lstbox.hxx:178
Link< ListBox &, void > maSelectHdl
Definition: lstbox.hxx:88
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35