1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_LSTBOX_HXX
21 #define INCLUDED_VCL_LSTBOX_HXX
23 #include <sal/types.h>
24 #include <o3tl/typed_flags_set.hxx>
25 #include <vcl/dllapi.h>
26 #include <vcl/ctrl.hxx>
28 #define LISTBOX_APPEND (SAL_MAX_INT32)
29 #define LISTBOX_ENTRY_NOTFOUND (SAL_MAX_INT32)
30 #define LISTBOX_ERROR (SAL_MAX_INT32)
31 #define LISTBOX_MAX_ENTRIES (SAL_MAX_INT32 - 1)
33 // the following defines can be used for the SetEntryFlags()
34 // and GetEntryFlags() methods
36 // !! Do not use these flags for user data as they are reserved !!
37 // !! to change the internal behaviour of the ListBox implementation !!
38 // !! for specific entries. !!
40 enum class ListBoxEntryFlags
43 /** this flag disables a selection of an entry completely. It is not
44 possible to select such entries either from the user interface
45 nor from the ListBox methods. Cursor traveling is handled correctly.
46 This flag can be used to add titles to a ListBox.
48 DisableSelection
= 0x0001,
50 /** this flag can be used to make an entry multiline capable
51 A normal entry is single line and will therefore be clipped
52 at the right listbox border. Setting this flag enables
53 word breaks for the entry text.
57 /** this flags lets the item be drawn disabled (e.g. in grey text)
58 usage only guaranteed with ListBoxEntryFlags::DisableSelection
60 DrawDisabled
= 0x0004,
64 template<> struct typed_flags
<ListBoxEntryFlags
> : is_typed_flags
<ListBoxEntryFlags
, 0x0007> {};
69 class ImplListBoxFloatingWindow
;
72 class ImplListBoxWindow
;
74 class VCL_DLLPUBLIC ListBox
: public Control
77 VclPtr
<ImplListBox
> mpImplLB
;
78 VclPtr
<ImplListBoxFloatingWindow
> mpFloatWin
;
79 VclPtr
<ImplWin
> mpImplWin
;
80 VclPtr
<ImplBtn
> mpBtn
;
81 sal_uInt16 mnDDHeight
;
82 sal_Int32 mnSaveValue
;
83 sal_Int32 m_nMaxWidthChars
;
84 Link
<ListBox
&,void> maSelectHdl
;
85 Link
<ListBox
&,void> maDoubleClickHdl
;
86 sal_uInt16 mnLineCount
;
88 bool mbDDAutoSize
: 1;
89 bool mbEdgeBlending
: 1;
92 SAL_DLLPRIVATE
void ImplInitListBoxData();
94 DECL_DLLPRIVATE_LINK( ImplSelectHdl
, LinkParamNone
*, void );
95 DECL_DLLPRIVATE_LINK( ImplScrollHdl
, ImplListBox
*, void );
96 DECL_DLLPRIVATE_LINK( ImplCancelHdl
, LinkParamNone
*, void );
97 DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl
, ImplListBoxWindow
*, void );
98 DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl
, FloatingWindow
*, void );
99 DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl
, sal_Int32
, void );
100 DECL_DLLPRIVATE_LINK( ImplUserDrawHdl
, UserDrawEvent
*, void );
101 DECL_DLLPRIVATE_LINK( ImplFocusHdl
, sal_Int32
, void );
102 DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl
, LinkParamNone
*, void );
104 DECL_DLLPRIVATE_LINK( ImplClickBtnHdl
, void*, void );
107 using Window::ImplInit
;
108 SAL_DLLPRIVATE
void ImplInit( vcl::Window
* pParent
, WinBits nStyle
);
109 SAL_DLLPRIVATE
static WinBits
ImplInitStyle( WinBits nStyle
);
110 bool IsDropDownBox() const { return mpFloatWin
!= nullptr; }
113 explicit ListBox( WindowType nType
);
115 virtual void FillLayoutData() const override
;
118 explicit ListBox( vcl::Window
* pParent
, WinBits nStyle
= WB_BORDER
);
119 virtual ~ListBox() override
;
120 virtual void dispose() override
;
122 virtual void ApplySettings(vcl::RenderContext
& rRenderContext
) override
;
123 virtual void Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
, DrawFlags nFlags
) override
;
124 virtual void Resize() override
;
125 virtual bool PreNotify( NotifyEvent
& rNEvt
) override
;
126 virtual void StateChanged( StateChangedType nType
) override
;
127 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
128 virtual void UserDraw( const UserDrawEvent
& rUDEvt
);
130 virtual void Select();
131 virtual void DoubleClick();
132 virtual void GetFocus() override
;
133 virtual void LoseFocus() override
;
135 virtual const Wallpaper
& GetDisplayBackground() const override
;
137 virtual void setPosSizePixel( long nX
, long nY
,
138 long nWidth
, long nHeight
, PosSizeFlags nFlags
= PosSizeFlags::All
) override
;
140 tools::Rectangle
GetDropDownPosSizePixel() const;
142 void AdaptDropDownLineCountToMaximum();
143 void SetDropDownLineCount( sal_uInt16 nLines
);
144 sal_uInt16
GetDropDownLineCount() const;
146 void EnableAutoSize( bool bAuto
);
147 bool IsAutoSizeEnabled() const { return mbDDAutoSize
; }
149 void EnableDDAutoWidth( bool b
);
151 sal_Int32
InsertEntry( const OUString
& rStr
, sal_Int32 nPos
= LISTBOX_APPEND
);
152 sal_Int32
InsertEntry( const OUString
& rStr
, const Image
& rImage
, sal_Int32 nPos
= LISTBOX_APPEND
);
153 void RemoveEntry( const OUString
& rStr
);
154 void RemoveEntry( sal_Int32 nPos
);
158 sal_Int32
GetEntryPos( const OUString
& rStr
) const;
159 sal_Int32
GetEntryPos( const void* pData
) const;
160 Image
GetEntryImage( sal_Int32 nPos
) const;
161 OUString
GetEntry( sal_Int32 nPos
) const;
162 sal_Int32
GetEntryCount() const;
164 void SelectEntry( const OUString
& rStr
, bool bSelect
= true );
165 void SelectEntryPos( sal_Int32 nPos
, bool bSelect
= true );
167 sal_Int32
GetSelectEntryCount() const;
168 OUString
GetSelectEntry( sal_Int32 nSelIndex
= 0 ) const;
169 sal_Int32
GetSelectEntryPos( sal_Int32 nSelIndex
= 0 ) const;
171 bool IsEntrySelected(const OUString
& rStr
) const;
172 bool IsEntryPosSelected( sal_Int32 nPos
) const;
173 void SetNoSelection();
175 void SetEntryData( sal_Int32 nPos
, void* pNewData
);
176 void* GetEntryData( sal_Int32 nPos
) const;
177 void* GetSelectEntryData() const { return GetEntryData(GetSelectEntryPos()); }
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
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.
187 void SetEntryFlags( sal_Int32 nPos
, ListBoxEntryFlags nFlags
);
189 /** this methods gets the current combination of flags from the
190 ListBoxEntryFlags::* defines from the given entry.
191 See description of the possible ListBoxEntryFlags::* flags
194 ListBoxEntryFlags
GetEntryFlags( sal_Int32 nPos
) const;
196 void SetTopEntry( sal_Int32 nPos
);
197 sal_Int32
GetTopEntry() const;
199 void SaveValue() { mnSaveValue
= GetSelectEntryPos(); }
200 sal_Int32
GetSavedValue() const { return mnSaveValue
; }
201 bool IsValueChangedFromSaved() const { return mnSaveValue
!= GetSelectEntryPos(); }
203 void SetSeparatorPos( sal_Int32 n
);
204 sal_Int32
GetSeparatorPos() const;
206 bool IsTravelSelect() const;
207 bool IsInDropDown() const;
208 void ToggleDropDown();
210 void EnableMultiSelection( bool bMulti
, bool bStackSelection
);
211 void EnableMultiSelection( bool bMulti
);
212 bool IsMultiSelectionEnabled() const;
214 void SetReadOnly( bool bReadOnly
= true );
215 bool IsReadOnly() const;
217 tools::Rectangle
GetBoundingRectangle( sal_Int32 nItem
) const;
219 void EnableUserDraw( bool bUserDraw
);
221 void DrawEntry( const UserDrawEvent
& rEvt
);
223 void SetSelectHdl( const Link
<ListBox
&,void>& rLink
) { maSelectHdl
= rLink
; }
224 const Link
<ListBox
&,void>& GetSelectHdl() const { return maSelectHdl
; }
225 void SetDoubleClickHdl( const Link
<ListBox
&,void>& rLink
) { maDoubleClickHdl
= rLink
; }
226 const Link
<ListBox
&,void>& GetDoubleClickHdl() const { return maDoubleClickHdl
; }
228 Size
CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown
229 Size
CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown
230 virtual Size
GetOptimalSize() const override
;
231 Size
CalcAdjustedSize( const Size
& rPrefSize
) const;
232 Size
CalcBlockSize( sal_uInt16 nColumns
, sal_uInt16 nLines
) const;
233 void GetMaxVisColumnsAndLines( sal_uInt16
& rnCols
, sal_uInt16
& rnLines
) const;
235 sal_uInt16
GetDisplayLineCount() const;
237 void EnableMirroring();
239 bool GetEdgeBlending() const { return mbEdgeBlending
; }
240 void SetEdgeBlending(bool bNew
);
242 /** checks whether a certain point lies within the bounds of
243 a listbox item and returns the item as well as the character position
246 <p>If the point is inside an item the item pos is put into <code>rPos</code> and
247 the item-relative character index is returned. If the point is not inside
248 an item -1 is returned and rPos is unchanged.</p>
251 tells the point for which an item is requested.
254 gets the item at the specified point <code>rPoint</code>
257 the item-relative character index at point <code>rPos</code> or -1
258 if no item is at that point.
260 using Control::GetIndexForPoint
;
261 long GetIndexForPoint( const Point
& rPoint
, sal_Int32
& rPos
) const;
263 void setMaxWidthChars(sal_Int32 nWidth
);
265 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
267 void EnableQuickSelection( bool b
);
269 static sal_Int32
NaturalSortCompare(const OUString
&rA
, const OUString
&rB
);
271 virtual FactoryFunction
GetUITestFactory() const override
;
274 class VCL_DLLPUBLIC MultiListBox
: public ListBox
277 explicit MultiListBox( vcl::Window
* pParent
, WinBits nStyle
);
281 #endif // INCLUDED_VCL_LSTBOX_HXX
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */