Line data Source code
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 _SV_LSTBOX_HXX
21 : #define _SV_LSTBOX_HXX
22 :
23 : #include <vcl/dllapi.h>
24 : #include <vcl/ctrl.hxx>
25 : #include <vcl/lstbox.h>
26 :
27 : class Image;
28 : class ImplListBox;
29 : class ImplListBoxFloatingWindow;
30 : class ImplBtn;
31 : class ImplWin;
32 :
33 : // --------------------------------------------------------------------
34 : // - ListBox -
35 : // --------------------------------------------------------------------
36 :
37 : class VCL_DLLPUBLIC ListBox : public Control
38 : {
39 : private:
40 : ImplListBox* mpImplLB;
41 : ImplListBoxFloatingWindow* mpFloatWin;
42 : ImplWin* mpImplWin;
43 : ImplBtn* mpBtn;
44 : sal_uInt16 mnDDHeight;
45 : sal_uInt16 mnSaveValue;
46 : sal_Bool mbDDAutoSize;
47 : Link maSelectHdl;
48 : Link maDoubleClickHdl;
49 : sal_uInt16 mnLineCount;
50 :
51 : private:
52 : SAL_DLLPRIVATE void ImplInitListBoxData();
53 :
54 : DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* );
55 : DECL_DLLPRIVATE_LINK( ImplScrollHdl, void* );
56 : DECL_DLLPRIVATE_LINK( ImplCancelHdl, void* );
57 : DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, void* );
58 : DECL_DLLPRIVATE_LINK( ImplClickBtnHdl, void* );
59 : DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, void* );
60 : DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, void* );
61 : DECL_DLLPRIVATE_LINK( ImplUserDrawHdl, UserDrawEvent* );
62 :
63 : protected:
64 : using Window::ImplInit;
65 : SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
66 : SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
67 : SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
68 0 : sal_Bool IsDropDownBox() const { return mpFloatWin ? sal_True : sal_False; }
69 :
70 : protected:
71 : ListBox( WindowType nType );
72 :
73 : virtual void FillLayoutData() const;
74 :
75 : public:
76 : ListBox( Window* pParent, WinBits nStyle = WB_BORDER );
77 : ListBox( Window* pParent, const ResId& rResId );
78 : ~ListBox();
79 :
80 : virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
81 : virtual void Resize();
82 : virtual long PreNotify( NotifyEvent& rNEvt );
83 : virtual void StateChanged( StateChangedType nType );
84 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
85 : virtual void UserDraw( const UserDrawEvent& rUDEvt );
86 :
87 : virtual void Select();
88 : virtual void DoubleClick();
89 : virtual void GetFocus();
90 : virtual void LoseFocus();
91 : virtual Window* GetPreferredKeyInputWindow();
92 :
93 : virtual const Wallpaper& GetDisplayBackground() const;
94 :
95 : virtual void setPosSizePixel( long nX, long nY,
96 : long nWidth, long nHeight, sal_uInt16 nFlags = WINDOW_POSSIZE_ALL );
97 0 : void SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
98 0 : { Control::SetPosSizePixel( rNewPos, rNewSize ); }
99 0 : void SetDropDownSizePixel( const Size& rNewSize )
100 0 : { if( IsDropDownBox() ) setPosSizePixel( 0, 0, rNewSize.Width(), rNewSize.Height(), WINDOW_POSSIZE_SIZE | WINDOW_POSSIZE_DROPDOWN ); }
101 :
102 : Rectangle GetDropDownPosSizePixel() const;
103 :
104 : void SetDropDownLineCount( sal_uInt16 nLines );
105 : sal_uInt16 GetDropDownLineCount() const;
106 :
107 : void EnableAutoSize( sal_Bool bAuto );
108 0 : sal_Bool IsAutoSizeEnabled() const { return mbDDAutoSize; }
109 :
110 : void EnableDDAutoWidth( sal_Bool b );
111 :
112 : virtual sal_uInt16 InsertEntry( const XubString& rStr, sal_uInt16 nPos = LISTBOX_APPEND );
113 : virtual sal_uInt16 InsertEntry( const Image& rImage, sal_uInt16 nPos = LISTBOX_APPEND );
114 : virtual sal_uInt16 InsertEntry( const XubString& rStr, const Image& rImage, sal_uInt16 nPos = LISTBOX_APPEND );
115 : virtual void RemoveEntry( const XubString& rStr );
116 : virtual void RemoveEntry( sal_uInt16 nPos );
117 :
118 : virtual void Clear();
119 :
120 : virtual sal_uInt16 GetEntryPos( const XubString& rStr ) const;
121 : virtual sal_uInt16 GetEntryPos( const void* pData ) const;
122 : Image GetEntryImage( sal_uInt16 nPos ) const;
123 : virtual XubString GetEntry( sal_uInt16 nPos ) const;
124 : virtual sal_uInt16 GetEntryCount() const;
125 :
126 : virtual void SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True );
127 : virtual void SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect = sal_True );
128 :
129 : virtual sal_uInt16 GetSelectEntryCount() const;
130 : virtual XubString GetSelectEntry( sal_uInt16 nSelIndex = 0 ) const;
131 : virtual sal_uInt16 GetSelectEntryPos( sal_uInt16 nSelIndex = 0 ) const;
132 :
133 : virtual sal_Bool IsEntrySelected( const XubString& rStr ) const;
134 : virtual sal_Bool IsEntryPosSelected( sal_uInt16 nPos ) const;
135 : virtual void SetNoSelection();
136 :
137 : void SetEntryData( sal_uInt16 nPos, void* pNewData );
138 : void* GetEntryData( sal_uInt16 nPos ) const;
139 :
140 : /** this methods stores a combination of flags from the
141 : LISTBOX_ENTRY_FLAG_* defines at the given entry.
142 : See description of the possible LISTBOX_ENTRY_FLAG_* flags
143 : for details.
144 : Do not use these flags for user data as they are reserved
145 : to change the internal behaviour of the ListBox implementation
146 : for specific entries.
147 : */
148 : void SetEntryFlags( sal_uInt16 nPos, long nFlags );
149 :
150 : /** this methods gets the current combination of flags from the
151 : LISTBOX_ENTRY_FLAG_* defines from the given entry.
152 : See description of the possible LISTBOX_ENTRY_FLAG_* flags
153 : for details.
154 : */
155 : long GetEntryFlags( sal_uInt16 nPos ) const;
156 :
157 : void SetTopEntry( sal_uInt16 nPos );
158 : sal_uInt16 GetTopEntry() const;
159 :
160 0 : void SaveValue() { mnSaveValue = GetSelectEntryPos(); }
161 0 : sal_uInt16 GetSavedValue() const { return mnSaveValue; }
162 :
163 : void SetSeparatorPos( sal_uInt16 n = LISTBOX_ENTRY_NOTFOUND );
164 : sal_uInt16 GetSeparatorPos() const;
165 :
166 : sal_Bool IsTravelSelect() const;
167 : sal_Bool IsInDropDown() const;
168 : void ToggleDropDown();
169 :
170 : void EnableMultiSelection( sal_Bool bMulti, sal_Bool bStackSelection );
171 : void EnableMultiSelection( sal_Bool bMulti );
172 : sal_Bool IsMultiSelectionEnabled() const;
173 :
174 : void SetReadOnly( sal_Bool bReadOnly = sal_True );
175 : sal_Bool IsReadOnly() const;
176 :
177 : Rectangle GetBoundingRectangle( sal_uInt16 nItem ) const;
178 :
179 : void SetUserItemSize( const Size& rSz );
180 :
181 : void EnableUserDraw( sal_Bool bUserDraw );
182 :
183 : void DrawEntry( const UserDrawEvent& rEvt, sal_Bool bDrawImage, sal_Bool bDrawText, sal_Bool bDrawTextAtImagePos = sal_False );
184 :
185 0 : void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
186 0 : const Link& GetSelectHdl() const { return maSelectHdl; }
187 0 : void SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; }
188 0 : const Link& GetDoubleClickHdl() const { return maDoubleClickHdl; }
189 :
190 : Size CalcSubEditSize() const; //size of area inside lstbox, i.e. no scrollbar/dropdown
191 : Size CalcMinimumSize() const; //size of lstbox area, i.e. including scrollbar/dropdown
192 : virtual Size GetOptimalSize(WindowSizeType eType) const;
193 : Size CalcAdjustedSize( const Size& rPrefSize ) const;
194 : Size CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
195 : void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
196 :
197 : sal_uInt16 GetDisplayLineCount() const;
198 :
199 : void EnableMirroring();
200 :
201 : /** checks whether a certain point lies within the bounds of
202 : a listbox item and returns the item as well as the character position
203 : the point is at.
204 :
205 : <p>If the point is inside an item the item pos is put into <code>rPos</code> and
206 : the item-relative character index is returned. If the point is not inside
207 : an item -1 is returned and rPos is unchanged.</p>
208 :
209 : @param rPoint
210 : tells the point for which an item is requested.
211 :
212 : @param rPos
213 : gets the item at the specified point <code>rPoint</code>
214 :
215 : @returns
216 : the item-relative character index at point <code>rPos</code> or -1
217 : if no item is at that point.
218 : */
219 : using Control::GetIndexForPoint;
220 : long GetIndexForPoint( const Point& rPoint, sal_uInt16& rPos ) const;
221 :
222 : virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue);
223 : };
224 :
225 : // ----------------
226 : // - MultiListBox -
227 : // ----------------
228 :
229 0 : class VCL_DLLPUBLIC MultiListBox : public ListBox
230 : {
231 : public:
232 : using ListBox::SaveValue;
233 : using ListBox::GetSavedValue;
234 : private:
235 : // Bei MultiListBox nicht erlaubt...
236 : void SaveValue();
237 : sal_uInt16 GetSavedValue();
238 :
239 : public:
240 : MultiListBox( Window* pParent, WinBits nStyle = 0 );
241 : MultiListBox( Window* pParent, const ResId& rResId );
242 : };
243 :
244 : #endif // _SV_LSTBOX_HXX
245 :
246 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|