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 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
24 #error "don't use this in new code"
25 #endif
26 
27 #include <config_options.h>
28 #include <sal/types.h>
29 #include <o3tl/typed_flags_set.hxx>
30 #include <vcl/dllapi.h>
31 #include <vcl/ctrl.hxx>
32 
33 class DataChangedEvent;
34 class NotifyEvent;
35 class UserDrawEvent;
36 
37 #define LISTBOX_APPEND (SAL_MAX_INT32)
38 #define LISTBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
39 #define LISTBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
40 
41 // the following defines can be used for the SetEntryFlags()
42 // and GetEntryFlags() methods
43 
44 // !! Do not use these flags for user data as they are reserved !!
45 // !! to change the internal behaviour of the ListBox implementation !!
46 // !! for specific entries. !!
47 
49 {
50  NONE = 0x0000,
56  DisableSelection = 0x0001,
57 
63  MultiLine = 0x0002,
64 
68  DrawDisabled = 0x0004,
69 };
70 namespace o3tl
71 {
72  template<> struct typed_flags<ListBoxEntryFlags> : is_typed_flags<ListBoxEntryFlags, 0x0007> {};
73 }
74 
75 class Image;
76 class ImplListBox;
78 class ImplBtn;
79 class ImplWin;
80 class ImplListBoxWindow;
81 
84 {
85 private:
90  sal_uInt16 mnDDHeight;
91  sal_Int32 m_nMaxWidthChars;
93  sal_uInt16 mnLineCount;
94 
95  bool mbDDAutoSize : 1;
96 
97 private:
98  SAL_DLLPRIVATE void ImplInitListBoxData();
99 
100  DECL_DLLPRIVATE_LINK( ImplSelectHdl, LinkParamNone*, void );
101  DECL_DLLPRIVATE_LINK( ImplScrollHdl, ImplListBox*, void );
102  DECL_DLLPRIVATE_LINK( ImplCancelHdl, LinkParamNone*, void );
103  DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, ImplListBoxWindow*, void );
104  DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, FloatingWindow*, void );
105  DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, sal_Int32, void );
106  DECL_DLLPRIVATE_LINK( ImplFocusHdl, sal_Int32, void );
107  DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl, LinkParamNone*, void );
108 
109  DECL_DLLPRIVATE_LINK( ImplClickBtnHdl, void*, void );
110 
111 protected:
112  using Window::ImplInit;
113  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
114  SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
115  bool IsDropDownBox() const { return mpFloatWin != nullptr; }
116 
117 protected:
118  explicit ListBox( WindowType nType );
119 
120  virtual void FillLayoutData() const override;
121 
122 public:
123  explicit ListBox( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
124  virtual ~ListBox() override;
125  virtual void dispose() override;
126 
127  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
128  virtual void Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags ) override;
129  virtual void Resize() override;
130  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
131  virtual void StateChanged( StateChangedType nType ) override;
132  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
133 
134  void Select();
135  void DoubleClick();
136  virtual void GetFocus() override;
137  virtual void LoseFocus() override;
138 
139  virtual const Wallpaper& GetDisplayBackground() const override;
140 
141  virtual void setPosSizePixel( long nX, long nY,
142  long nWidth, long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override;
143 
144  tools::Rectangle GetDropDownPosSizePixel() const;
145 
146  void AdaptDropDownLineCountToMaximum();
147  void SetDropDownLineCount( sal_uInt16 nLines );
148  sal_uInt16 GetDropDownLineCount() const;
149 
150  void EnableAutoSize( bool bAuto );
151  bool IsAutoSizeEnabled() const { return mbDDAutoSize; }
152 
153  sal_Int32 InsertEntry( const OUString& rStr, sal_Int32 nPos = LISTBOX_APPEND );
154  sal_Int32 InsertEntry( const OUString& rStr, const Image& rImage, sal_Int32 nPos = LISTBOX_APPEND );
155  void RemoveEntry( sal_Int32 nPos );
156 
157  void Clear();
158 
159  sal_Int32 GetEntryPos( const OUString& rStr ) const;
160  Image GetEntryImage( sal_Int32 nPos ) const;
161  OUString GetEntry( sal_Int32 nPos ) const;
162  sal_Int32 GetEntryCount() const;
163 
164  void SelectEntry( const OUString& rStr, bool bSelect = true );
165  void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
166  void SelectEntriesPos( const std::vector<sal_Int32>& rPositions, 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 IsEntryPosSelected( sal_Int32 nPos ) const;
173  void SetNoSelection();
174 
175  void SetEntryData( sal_Int32 nPos, void* pNewData );
176  void* GetEntryData( sal_Int32 nPos ) const;
177 
186  void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags );
187 
188  void SetTopEntry( sal_Int32 nPos );
189  sal_Int32 GetTopEntry() const;
190 
195  void SetSeparatorPos( sal_Int32 n );
200  sal_Int32 GetSeparatorPos() const;
201 
205  void AddSeparator( sal_Int32 n );
206 
207  bool IsTravelSelect() const;
208  bool IsInDropDown() const;
209  void ToggleDropDown();
210 
211  void EnableMultiSelection( bool bMulti );
212  bool IsMultiSelectionEnabled() const;
213 
214  void SetReadOnly( bool bReadOnly = true );
215  bool IsReadOnly() const;
216 
217  tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
218 
219  void SetSelectHdl( const Link<ListBox&,void>& rLink ) { maSelectHdl = rLink; }
220 
221  Size CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown
222  Size CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown
223  virtual Size GetOptimalSize() const override;
224  Size CalcAdjustedSize( const Size& rPrefSize ) const;
225  Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
226  void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
227 
228  sal_uInt16 GetDisplayLineCount() const;
229 
249  long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
250 
251  void setMaxWidthChars(sal_Int32 nWidth);
252 
253  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
254 
255  virtual FactoryFunction GetUITestFactory() const override;
256 
257  virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
258 };
259 
260 class UNLESS_MERGELIBS(VCL_DLLPUBLIC) MultiListBox final : public ListBox
261 {
262 public:
263  explicit MultiListBox( vcl::Window* pParent, WinBits nStyle );
264 
265 };
266 
267 #endif // INCLUDED_VCL_LSTBOX_HXX
268 
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nMaxWidthChars
Definition: lstbox.hxx:91
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3097
bool IsDropDownBox() const
Definition: lstbox.hxx:115
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3910
const OUStringLiteral IsReadOnly("IsReadOnly")
sal_uInt16 mnDDHeight
Definition: lstbox.hxx:90
DECL_DLLPRIVATE_LINK(ImplHandlePaintHdl, Timer *, void)
VclPtr< ImplBtn > mpBtn
Definition: lstbox.hxx:89
A widget used to choose from a list of items and which has no entry.
Definition: lstbox.hxx:83
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
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
PosSizeFlags
Definition: window.hxx:140
VclPtr< ImplListBox > mpImplLB
Definition: lstbox.hxx:86
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: ctrl.cxx:418
StateChangedType
Definition: window.hxx:310
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2713
sal_Int64 WinBits
this flags lets the item be drawn disabled (e.g.
virtual void DumpAsPropertyTree(tools::JsonWriter &)
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: window.cxx:3380
this flag disables a selection of an entry completely.
bool IsAutoSizeEnabled() const
Definition: lstbox.hxx:151
this flag can be used to make an entry multiline capable A normal entry is single line and will there...
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
DrawFlags
Definition: window.hxx:353
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
virtual void Draw(::OutputDevice *pDev, const Point &rPos, DrawFlags nFlags)
Definition: window.cxx:1824
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:1431
void SetSelectHdl(const Link< ListBox &, void > &rLink)
Definition: lstbox.hxx:219
virtual void LoseFocus()
Definition: window.cxx:1850
long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:134
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:936
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
virtual void Resize() override
Definition: ctrl.cxx:74
sal_uInt16 mnLineCount
Definition: lstbox.hxx:93
WindowType
VclPtr< ImplListBoxFloatingWindow > mpFloatWin
Definition: lstbox.hxx:87
Definition: ctrl.hxx:33
ListBoxEntryFlags
Definition: lstbox.hxx:48
virtual void GetFocus()
Definition: window.cxx:1836
Definition: image.hxx:40
#define LISTBOX_APPEND
Definition: lstbox.hxx:37
VclPtr< ImplWin > mpImplWin
Definition: lstbox.hxx:88
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:218
Link< ListBox &, void > maSelectHdl
Definition: lstbox.hxx:92
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35