/src/libreoffice/include/vcl/toolkit/lstbox.hxx
Line | Count | Source |
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 | 0 | #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 | | |
47 | | enum class ListBoxEntryFlags |
48 | | { |
49 | | NONE = 0x0000, |
50 | | /** this flag disables a selection of an entry completely. It is not |
51 | | possible to select such entries either from the user interface |
52 | | nor from the ListBox methods. Cursor traveling is handled correctly. |
53 | | This flag can be used to add titles to a ListBox. |
54 | | */ |
55 | | DisableSelection = 0x0001, |
56 | | |
57 | | /** this flag can be used to make an entry multiline capable |
58 | | A normal entry is single line and will therefore be clipped |
59 | | at the right listbox border. Setting this flag enables |
60 | | word breaks for the entry text. |
61 | | */ |
62 | | MultiLine = 0x0002, |
63 | | |
64 | | /** this flags lets the item be drawn disabled (e.g. in grey text) |
65 | | usage only guaranteed with ListBoxEntryFlags::DisableSelection |
66 | | */ |
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; |
76 | | class ImplListBoxFloatingWindow; |
77 | | class ImplBtn; |
78 | | class ImplWin; |
79 | | class ImplListBoxWindow; |
80 | | |
81 | | /// A widget used to choose from a list of items and which has no entry. |
82 | | class VCL_DLLPUBLIC ListBox : public Control |
83 | | { |
84 | | private: |
85 | | VclPtr<ImplListBox> mpImplLB; |
86 | | VclPtr<ImplListBoxFloatingWindow> mpFloatWin; |
87 | | VclPtr<ImplWin> mpImplWin; |
88 | | VclPtr<ImplBtn> mpBtn; |
89 | | sal_uInt16 mnDDHeight; |
90 | | sal_Int32 m_nMaxWidthChars; |
91 | | Link<ListBox&,void> maSelectHdl; |
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 | 0 | bool IsDropDownBox() const { return mpFloatWin != nullptr; } |
115 | | |
116 | | protected: |
117 | | SAL_DLLPRIVATE explicit ListBox( WindowType eType ); |
118 | | |
119 | | SAL_DLLPRIVATE virtual void FillLayoutData() const override; |
120 | | |
121 | | public: |
122 | | explicit ListBox( vcl::Window* pParent, WinBits nStyle = WB_BORDER ); |
123 | | SAL_DLLPRIVATE virtual ~ListBox() override; |
124 | | SAL_DLLPRIVATE virtual void dispose() override; |
125 | | |
126 | | virtual rtl::Reference<comphelper::OAccessible> CreateAccessible() override; |
127 | | |
128 | | SAL_DLLPRIVATE virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; |
129 | | SAL_DLLPRIVATE virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override; |
130 | | SAL_DLLPRIVATE virtual void Resize() override; |
131 | | SAL_DLLPRIVATE virtual bool PreNotify( NotifyEvent& rNEvt ) override; |
132 | | SAL_DLLPRIVATE virtual void StateChanged( StateChangedType nType ) override; |
133 | | SAL_DLLPRIVATE virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; |
134 | | |
135 | | void Select(); |
136 | | SAL_DLLPRIVATE void DoubleClick(); |
137 | | SAL_DLLPRIVATE virtual void GetFocus() override; |
138 | | SAL_DLLPRIVATE virtual void LoseFocus() override; |
139 | | |
140 | | SAL_DLLPRIVATE virtual const Wallpaper& GetDisplayBackground() const override; |
141 | | |
142 | | SAL_DLLPRIVATE virtual void setPosSizePixel( tools::Long nX, tools::Long nY, |
143 | | tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) override; |
144 | | |
145 | | tools::Rectangle GetDropDownPosSizePixel() const; |
146 | | |
147 | | SAL_DLLPRIVATE void AdaptDropDownLineCountToMaximum(); |
148 | | void SetDropDownLineCount( sal_uInt16 nLines ); |
149 | | sal_uInt16 GetDropDownLineCount() const; |
150 | | |
151 | | void EnableAutoSize( bool bAuto ); |
152 | 0 | bool IsAutoSizeEnabled() const { return mbDDAutoSize; } |
153 | | |
154 | | sal_Int32 InsertEntry( const OUString& rStr, sal_Int32 nPos = LISTBOX_APPEND ); |
155 | | sal_Int32 InsertEntry( const OUString& rStr, const Image& rImage, sal_Int32 nPos = LISTBOX_APPEND ); |
156 | | void RemoveEntry( sal_Int32 nPos ); |
157 | | |
158 | | void Clear(); |
159 | | |
160 | | sal_Int32 GetEntryPos( std::u16string_view rStr ) const; |
161 | | Image GetEntryImage( sal_Int32 nPos ) const; |
162 | | OUString GetEntry( sal_Int32 nPos ) const; |
163 | | sal_Int32 GetEntryCount() const; |
164 | | |
165 | | SAL_DLLPRIVATE void SelectEntry( std::u16string_view rStr, bool bSelect = true ); |
166 | | void SelectEntryPos( sal_Int32 nPos, bool bSelect = true ); |
167 | | void SelectEntriesPos( const std::vector<sal_Int32>& rPositions, bool bSelect = true ); |
168 | | |
169 | | sal_Int32 GetSelectedEntryCount() const; |
170 | | OUString GetSelectedEntry( sal_Int32 nSelIndex = 0 ) const; |
171 | | sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const; |
172 | | |
173 | | bool IsEntryPosSelected( sal_Int32 nPos ) const; |
174 | | void SetNoSelection(); |
175 | | |
176 | | SAL_DLLPRIVATE void SetEntryData(sal_Int32 nPos, OUString* pNewData); |
177 | | SAL_DLLPRIVATE OUString* GetEntryData(sal_Int32 nPos) const; |
178 | | |
179 | | /** this methods stores a combination of flags from the |
180 | | ListBoxEntryFlags::* defines at the given entry. |
181 | | See description of the possible ListBoxEntryFlags::* flags |
182 | | for details. |
183 | | Do not use these flags for user data as they are reserved |
184 | | to change the internal behaviour of the ListBox implementation |
185 | | for specific entries. |
186 | | */ |
187 | | SAL_DLLPRIVATE void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags ); |
188 | | |
189 | | void SetTopEntry( sal_Int32 nPos ); |
190 | | sal_Int32 GetTopEntry() const; |
191 | | |
192 | | /** |
193 | | * Removes existing separators, and sets the position of the |
194 | | * one and only separator. |
195 | | */ |
196 | | void SetSeparatorPos( sal_Int32 n ); |
197 | | /** |
198 | | * Gets the position of the separator which was added first. |
199 | | * Returns LISTBOX_ENTRY_NOTFOUND if there is no separator. |
200 | | */ |
201 | | sal_Int32 GetSeparatorPos() const; |
202 | | |
203 | | /** |
204 | | * Adds a new separator at the given position n. |
205 | | */ |
206 | | SAL_DLLPRIVATE void AddSeparator( sal_Int32 n ); |
207 | | |
208 | | SAL_DLLPRIVATE bool IsTravelSelect() const; |
209 | | bool IsInDropDown() const; |
210 | | void ToggleDropDown(); |
211 | | |
212 | | void EnableMultiSelection( bool bMulti ); |
213 | | bool IsMultiSelectionEnabled() const; |
214 | | void SetHighlightColor(const Color& rColor); |
215 | | void SetHighlightTextColor(const Color& rColor); |
216 | | |
217 | | void SetReadOnly( bool bReadOnly = true ); |
218 | | bool IsReadOnly() const; |
219 | | |
220 | | tools::Rectangle GetBoundingRectangle( sal_Int32 nItem ) const; |
221 | | |
222 | 0 | void SetSelectHdl( const Link<ListBox&,void>& rLink ) { maSelectHdl = rLink; } |
223 | | |
224 | | SAL_DLLPRIVATE Size CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown |
225 | | Size CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown |
226 | | SAL_DLLPRIVATE virtual Size GetOptimalSize() const override; |
227 | | Size CalcAdjustedSize( const Size& rPrefSize ) const; |
228 | | Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const; |
229 | | void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const; |
230 | | |
231 | | sal_uInt16 GetDisplayLineCount() const; |
232 | | |
233 | | /** checks whether a certain point lies within the bounds of |
234 | | a listbox item and returns the item as well as the character position |
235 | | the point is at. |
236 | | |
237 | | <p>If the point is inside an item the item pos is put into <code>rPos</code> and |
238 | | the item-relative character index is returned. If the point is not inside |
239 | | an item -1 is returned and rPos is unchanged.</p> |
240 | | |
241 | | @param rPoint |
242 | | tells the point for which an item is requested. |
243 | | |
244 | | @param rPos |
245 | | gets the item at the specified point <code>rPoint</code> |
246 | | |
247 | | @returns |
248 | | the item-relative character index at point <code>rPos</code> or -1 |
249 | | if no item is at that point. |
250 | | */ |
251 | | using Control::GetIndexForPoint; |
252 | | tools::Long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const; |
253 | | |
254 | | SAL_DLLPRIVATE void setMaxWidthChars(sal_Int32 nWidth); |
255 | | |
256 | | SAL_DLLPRIVATE virtual bool set_property(const OUString &rKey, const OUString &rValue) override; |
257 | | |
258 | | SAL_DLLPRIVATE virtual FactoryFunction GetUITestFactory() const override; |
259 | | |
260 | | SAL_DLLPRIVATE virtual void DumpAsPropertyTree(tools::JsonWriter&) override; |
261 | | }; |
262 | | |
263 | | class UNLESS_MERGELIBS(VCL_DLLPUBLIC) MultiListBox final : public ListBox |
264 | | { |
265 | | public: |
266 | | explicit MultiListBox( vcl::Window* pParent, WinBits nStyle ); |
267 | | |
268 | | }; |
269 | | |
270 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |