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 #pragma once
21 
22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
24 #endif
25 
26 #include <config_options.h>
27 #include <sal/types.h>
28 #include <o3tl/typed_flags_set.hxx>
29 #include <vcl/dllapi.h>
30 #include <vcl/ctrl.hxx>
31 
32 class DataChangedEvent;
33 class NotifyEvent;
34 class UserDrawEvent;
35 
36 #define LISTBOX_APPEND (SAL_MAX_INT32)
37 #define LISTBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
38 #define LISTBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
39 
40 // the following defines can be used for the SetEntryFlags()
41 // and GetEntryFlags() methods
42 
43 // !! Do not use these flags for user data as they are reserved !!
44 // !! to change the internal behaviour of the ListBox implementation !!
45 // !! for specific entries. !!
46 
48 {
49  NONE = 0x0000,
55  DisableSelection = 0x0001,
56 
62  MultiLine = 0x0002,
63 
67  DrawDisabled = 0x0004,
68 };
69 namespace o3tl
70 {
71  template<> struct typed_flags<ListBoxEntryFlags> : is_typed_flags<ListBoxEntryFlags, 0x0007> {};
72 }
73 
74 class Image;
75 class ImplListBox;
77 class ImplBtn;
78 class ImplWin;
79 class ImplListBoxWindow;
80 
83 {
84 private:
89  sal_uInt16 mnDDHeight;
90  sal_Int32 m_nMaxWidthChars;
92  sal_uInt16 mnLineCount;
93 
94  bool mbDDAutoSize : 1;
95 
96 private:
97  SAL_DLLPRIVATE void ImplInitListBoxData();
98 
99  DECL_DLLPRIVATE_LINK( ImplSelectHdl, LinkParamNone*, void );
100  DECL_DLLPRIVATE_LINK( ImplScrollHdl, ImplListBox*, void );
101  DECL_DLLPRIVATE_LINK( ImplCancelHdl, LinkParamNone*, void );
102  DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, ImplListBoxWindow*, void );
103  DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, FloatingWindow*, void );
104  DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, sal_Int32, void );
105  DECL_DLLPRIVATE_LINK( ImplFocusHdl, sal_Int32, void );
106  DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl, LinkParamNone*, void );
107 
108  DECL_DLLPRIVATE_LINK( ImplClickBtnHdl, void*, void );
109 
110 protected:
111  using Window::ImplInit;
112  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
113  SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
114  bool IsDropDownBox() const { return mpFloatWin != nullptr; }
115 
116 protected:
117  explicit ListBox( WindowType nType );
118 
119  virtual void FillLayoutData() const override;
120 
121 public:
122  explicit ListBox( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
123  virtual ~ListBox() override;
124  virtual void dispose() override;
125 
126  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
127  virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override;
128  virtual void Resize() override;
129  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
130  virtual void StateChanged( StateChangedType nType ) override;
131  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
132 
133  void Select();
134  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( tools::Long nX, tools::Long nY,
141  tools::Long nWidth, tools::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( sal_Int32 nPos );
155 
156  void Clear();
157 
158  sal_Int32 GetEntryPos( std::u16string_view rStr ) const;
159  Image GetEntryImage( sal_Int32 nPos ) const;
160  OUString GetEntry( sal_Int32 nPos ) const;
161  sal_Int32 GetEntryCount() const;
162 
163  void SelectEntry( std::u16string_view rStr, bool bSelect = true );
164  void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
165  void SelectEntriesPos( const std::vector<sal_Int32>& rPositions, bool bSelect = true );
166 
167  sal_Int32 GetSelectedEntryCount() const;
168  OUString GetSelectedEntry( sal_Int32 nSelIndex = 0 ) const;
169  sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const;
170 
171  bool IsEntryPosSelected( sal_Int32 nPos ) const;
172  void SetNoSelection();
173 
174  void SetEntryData( sal_Int32 nPos, void* pNewData );
175  void* GetEntryData( sal_Int32 nPos ) const;
176 
185  void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags );
186 
187  void SetTopEntry( sal_Int32 nPos );
188  sal_Int32 GetTopEntry() const;
189 
194  void SetSeparatorPos( sal_Int32 n );
199  sal_Int32 GetSeparatorPos() const;
200 
204  void AddSeparator( sal_Int32 n );
205 
206  bool IsTravelSelect() const;
207  bool IsInDropDown() const;
208  void ToggleDropDown();
209 
210  void EnableMultiSelection( bool bMulti );
211  bool IsMultiSelectionEnabled() const;
212 
213  void SetReadOnly( bool bReadOnly = true );
214  bool IsReadOnly() const;
215 
216  tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
217 
218  void SetSelectHdl( const Link<ListBox&,void>& rLink ) { maSelectHdl = rLink; }
219 
220  Size CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown
221  Size CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown
222  virtual Size GetOptimalSize() const override;
223  Size CalcAdjustedSize( const Size& rPrefSize ) const;
224  Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
225  void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
226 
227  sal_uInt16 GetDisplayLineCount() const;
228 
248  tools::Long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
249 
250  void setMaxWidthChars(sal_Int32 nWidth);
251 
252  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
253 
254  virtual FactoryFunction GetUITestFactory() const override;
255 
256  virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
257 };
258 
259 class UNLESS_MERGELIBS(VCL_DLLPUBLIC) MultiListBox final : public ListBox
260 {
261 public:
262  explicit MultiListBox( vcl::Window* pParent, WinBits nStyle );
263 
264 };
265 
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nMaxWidthChars
Definition: lstbox.hxx:90
virtual const Wallpaper & GetDisplayBackground() const
Definition: window.cxx:3067
bool IsDropDownBox() const
Definition: lstbox.hxx:114
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3934
sal_uInt16 mnDDHeight
Definition: lstbox.hxx:89
DECL_DLLPRIVATE_LINK(ImplHandlePaintHdl, Timer *, void)
VclPtr< ImplBtn > mpBtn
Definition: lstbox.hxx:88
A widget used to choose from a list of items and which has no entry.
Definition: lstbox.hxx:82
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:255
virtual void FillLayoutData() const
Definition: ctrl.cxx:79
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
PosSizeFlags
Definition: window.hxx:125
VclPtr< ImplListBox > mpImplLB
Definition: lstbox.hxx:85
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: ctrl.cxx:412
StateChangedType
Definition: window.hxx:289
virtual void Draw(::OutputDevice *pDev, const Point &rPos, SystemTextColorFlags nFlags)
Definition: window.cxx:1829
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:3358
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
SystemTextColorFlags
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 bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:52
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:57
virtual bool set_property(const OString &rKey, const OUString &rValue)
Definition: window2.cxx:1439
void SetSelectHdl(const Link< ListBox &, void > &rLink)
Definition: lstbox.hxx:218
virtual void LoseFocus()
Definition: window.cxx:1855
void Clear(EHistoryType eHistory)
virtual void setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
Definition: window.cxx:2666
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:938
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:368
virtual void Resize() override
Definition: ctrl.cxx:73
sal_uInt16 mnLineCount
Definition: lstbox.hxx:92
tools::Long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:133
WindowType
VclPtr< ImplListBoxFloatingWindow > mpFloatWin
Definition: lstbox.hxx:86
Definition: ctrl.hxx:81
ListBoxEntryFlags
Definition: lstbox.hxx:47
virtual void GetFocus()
Definition: window.cxx:1841
Definition: image.hxx:39
#define LISTBOX_APPEND
Definition: lstbox.hxx:36
VclPtr< ImplWin > mpImplWin
Definition: lstbox.hxx:87
Event to pass information for UserDraw() handling eg. in comboboxes.
Definition: event.hxx:221
Link< ListBox &, void > maSelectHdl
Definition: lstbox.hxx:91
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:36