Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / lstbox.hxx
blob8a5efc5bc85348d912e8d899c7b5af6dfbcc5dda
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <vcl/dllapi.h>
24 #include <vcl/ctrl.hxx>
25 #include <vcl/lstbox.h>
27 class Image;
28 class ImplListBox;
29 class ImplListBoxFloatingWindow;
30 class ImplBtn;
31 class ImplWin;
34 // - ListBox -
37 class VCL_DLLPUBLIC ListBox : public Control
39 private:
40 VclPtr<ImplListBox> mpImplLB;
41 VclPtr<ImplListBoxFloatingWindow> mpFloatWin;
42 VclPtr<ImplWin> mpImplWin;
43 VclPtr<ImplBtn> mpBtn;
44 sal_uInt16 mnDDHeight;
45 sal_Int32 mnSaveValue;
46 sal_Int32 m_nMaxWidthChars;
47 Link<> maSelectHdl;
48 Link<> maDoubleClickHdl;
49 sal_uInt16 mnLineCount;
51 /// bitfield
52 bool mbDDAutoSize : 1;
53 bool mbEdgeBlending : 1;
55 private:
56 SAL_DLLPRIVATE void ImplInitListBoxData();
58 DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* );
59 DECL_DLLPRIVATE_LINK( ImplScrollHdl, void* );
60 DECL_DLLPRIVATE_LINK( ImplCancelHdl, void* );
61 DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, void* );
62 DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, void* );
63 DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, void* );
64 DECL_DLLPRIVATE_LINK( ImplFocusHdl, void* );
65 DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl, void* );
67 SAL_DLLPRIVATE void ImplClickButtonHandler( Control* );
68 SAL_DLLPRIVATE void ImplUserDrawHandler( UserDrawEvent* );
70 protected:
71 using Window::ImplInit;
72 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
73 SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
74 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
75 bool IsDropDownBox() const { return mpFloatWin != nullptr; }
77 protected:
78 explicit ListBox( WindowType nType );
80 virtual void FillLayoutData() const SAL_OVERRIDE;
82 public:
83 explicit ListBox( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
84 explicit ListBox( vcl::Window* pParent, const ResId& );
85 virtual ~ListBox();
86 virtual void dispose() SAL_OVERRIDE;
88 virtual void ApplySettings(vcl::RenderContext& rRenderContext) SAL_OVERRIDE;
89 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) SAL_OVERRIDE;
90 virtual void Resize() SAL_OVERRIDE;
91 virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
92 virtual void StateChanged( StateChangedType nType ) SAL_OVERRIDE;
93 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
94 virtual void UserDraw( const UserDrawEvent& rUDEvt );
96 virtual void Select();
97 virtual void DoubleClick();
98 virtual void GetFocus() SAL_OVERRIDE;
99 virtual void LoseFocus() SAL_OVERRIDE;
100 virtual vcl::Window* GetPreferredKeyInputWindow() SAL_OVERRIDE;
102 virtual const Wallpaper& GetDisplayBackground() const SAL_OVERRIDE;
104 virtual void setPosSizePixel( long nX, long nY,
105 long nWidth, long nHeight, PosSizeFlags nFlags = PosSizeFlags::All ) SAL_OVERRIDE;
106 void SetPosSizePixel( const Point& rNewPos, const Size& rNewSize ) SAL_OVERRIDE
107 { Control::SetPosSizePixel( rNewPos, rNewSize ); }
109 Rectangle GetDropDownPosSizePixel() const;
111 void AdaptDropDownLineCountToMaximum();
112 void SetDropDownLineCount( sal_uInt16 nLines );
113 sal_uInt16 GetDropDownLineCount() const;
115 void EnableAutoSize( bool bAuto );
116 bool IsAutoSizeEnabled() const { return mbDDAutoSize; }
118 void EnableDDAutoWidth( bool b );
120 sal_Int32 InsertEntry( const OUString& rStr, sal_Int32 nPos = LISTBOX_APPEND );
121 sal_Int32 InsertEntry( const OUString& rStr, const Image& rImage, sal_Int32 nPos = LISTBOX_APPEND );
122 void RemoveEntry( const OUString& rStr );
123 void RemoveEntry( sal_Int32 nPos );
125 void Clear();
127 sal_Int32 GetEntryPos( const OUString& rStr ) const;
128 sal_Int32 GetEntryPos( const void* pData ) const;
129 Image GetEntryImage( sal_Int32 nPos ) const;
130 OUString GetEntry( sal_Int32 nPos ) const;
131 sal_Int32 GetEntryCount() const;
133 void SelectEntry( const OUString& rStr, bool bSelect = true );
134 void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
136 sal_Int32 GetSelectEntryCount() const;
137 OUString GetSelectEntry( sal_Int32 nSelIndex = 0 ) const;
138 sal_Int32 GetSelectEntryPos( sal_Int32 nSelIndex = 0 ) const;
140 bool IsEntrySelected(const OUString& rStr) const;
141 bool IsEntryPosSelected( sal_Int32 nPos ) const;
142 void SetNoSelection();
144 void SetEntryData( sal_Int32 nPos, void* pNewData );
145 void* GetEntryData( sal_Int32 nPos ) const;
146 void* GetSelectEntryData() const { return GetEntryData(GetSelectEntryPos()); }
148 /** this methods stores a combination of flags from the
149 ListBoxEntryFlags::* defines at the given entry.
150 See description of the possible ListBoxEntryFlags::* flags
151 for details.
152 Do not use these flags for user data as they are reserved
153 to change the internal behaviour of the ListBox implementation
154 for specific entries.
156 void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags );
158 /** this methods gets the current combination of flags from the
159 ListBoxEntryFlags::* defines from the given entry.
160 See description of the possible ListBoxEntryFlags::* flags
161 for details.
163 ListBoxEntryFlags GetEntryFlags( sal_Int32 nPos ) const;
165 void SetTopEntry( sal_Int32 nPos );
166 sal_Int32 GetTopEntry() const;
168 void SaveValue() { mnSaveValue = GetSelectEntryPos(); }
169 sal_Int32 GetSavedValue() const { return mnSaveValue; }
170 bool IsValueChangedFromSaved() const { return mnSaveValue != GetSelectEntryPos(); }
172 void SetSeparatorPos( sal_Int32 n = LISTBOX_ENTRY_NOTFOUND );
173 sal_Int32 GetSeparatorPos() const;
175 bool IsTravelSelect() const;
176 bool IsInDropDown() const;
177 void ToggleDropDown();
179 void EnableMultiSelection( bool bMulti, bool bStackSelection );
180 void EnableMultiSelection( bool bMulti );
181 bool IsMultiSelectionEnabled() const;
183 void SetReadOnly( bool bReadOnly = true );
184 bool IsReadOnly() const;
186 Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
188 void SetUserItemSize( const Size& rSz );
190 void EnableUserDraw( bool bUserDraw );
192 void DrawEntry( const UserDrawEvent& rEvt, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos = false );
194 void SetSelectHdl( const Link<>& rLink ) { maSelectHdl = rLink; }
195 const Link<>& GetSelectHdl() const { return maSelectHdl; }
196 void SetDoubleClickHdl( const Link<>& rLink ) { maDoubleClickHdl = rLink; }
197 const Link<>& GetDoubleClickHdl() const { return maDoubleClickHdl; }
199 Size CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown
200 Size CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown
201 virtual Size GetOptimalSize() const SAL_OVERRIDE;
202 Size CalcAdjustedSize( const Size& rPrefSize ) const;
203 Size CalcBlockSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
204 void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
206 sal_uInt16 GetDisplayLineCount() const;
208 void EnableMirroring();
210 bool GetEdgeBlending() const { return mbEdgeBlending; }
211 void SetEdgeBlending(bool bNew);
213 /** checks whether a certain point lies within the bounds of
214 a listbox item and returns the item as well as the character position
215 the point is at.
217 <p>If the point is inside an item the item pos is put into <code>rPos</code> and
218 the item-relative character index is returned. If the point is not inside
219 an item -1 is returned and rPos is unchanged.</p>
221 @param rPoint
222 tells the point for which an item is requested.
224 @param rPos
225 gets the item at the specified point <code>rPoint</code>
227 @returns
228 the item-relative character index at point <code>rPos</code> or -1
229 if no item is at that point.
231 using Control::GetIndexForPoint;
232 long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
234 sal_Int32 getMaxWidthChars() const { return m_nMaxWidthChars; }
235 void setMaxWidthChars(sal_Int32 nWidth);
237 virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
239 void EnableQuickSelection( const bool& b );
243 // - MultiListBox -
246 class VCL_DLLPUBLIC MultiListBox : public ListBox
248 public:
249 using ListBox::SaveValue;
250 using ListBox::GetSavedValue;
251 using ListBox::IsValueChangedFromSaved;
252 private:
253 // Bei MultiListBox nicht erlaubt...
254 void SaveValue();
255 sal_Int32 GetSavedValue();
256 bool IsValueChangedFromSaved() const;
258 public:
259 explicit MultiListBox( vcl::Window* pParent, WinBits nStyle = 0 );
263 #endif // INCLUDED_VCL_LSTBOX_HXX
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */