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_COMBOBOX_HXX
21 : #define _SV_COMBOBOX_HXX
22 :
23 : #include <vcl/dllapi.h>
24 : #include <vcl/ctrl.hxx>
25 : #include <vcl/combobox.h>
26 : #include <vcl/edit.hxx>
27 :
28 : class UserDrawEvent;
29 :
30 : class ImplListBoxFloatingWindow;
31 : class ImplListBox;
32 : class ImplBtn;
33 :
34 : // ------------
35 : // - ComboBox -
36 : // ------------
37 :
38 : class VCL_DLLPUBLIC ComboBox : public Edit
39 : {
40 : private:
41 : Edit* mpSubEdit;
42 : ImplListBox* mpImplLB;
43 : ImplBtn* mpBtn;
44 : ImplListBoxFloatingWindow* mpFloatWin;
45 : sal_uInt16 mnDDHeight;
46 : sal_Unicode mcMultiSep;
47 : sal_Bool mbDDAutoSize : 1;
48 : sal_Bool mbSyntheticModify : 1;
49 : sal_Bool mbMatchCase : 1;
50 : sal_Int32 m_nMaxWidthChars;
51 : Link maSelectHdl;
52 : Link maDoubleClickHdl;
53 :
54 1899 : struct ComboBoxBounds
55 : {
56 : Point aSubEditPos;
57 : Size aSubEditSize;
58 :
59 : Point aButtonPos;
60 : Size aButtonSize;
61 : };
62 :
63 : private:
64 : SAL_DLLPRIVATE void ImplInitComboBoxData();
65 : SAL_DLLPRIVATE void ImplUpdateFloatSelection();
66 : SAL_DLLPRIVATE ComboBoxBounds calcComboBoxDropDownComponentBounds(
67 : const Size &rOutSize, const Size &rBorderOutSize) const;
68 :
69 : DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* );
70 : DECL_DLLPRIVATE_LINK( ImplCancelHdl, void* );
71 : DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, void* );
72 : DECL_DLLPRIVATE_LINK( ImplClickBtnHdl, void* );
73 : DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, void* );
74 : DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, void* );
75 : DECL_DLLPRIVATE_LINK( ImplUserDrawHdl, UserDrawEvent* );
76 : DECL_DLLPRIVATE_LINK( ImplAutocompleteHdl, Edit* );
77 :
78 : protected:
79 : using Window::ImplInit;
80 : SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
81 : SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
82 : SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
83 : SAL_DLLPRIVATE void ImplCalcEditHeight();
84 : SAL_DLLPRIVATE long getMaxWidthScrollBarAndDownButton() const;
85 :
86 : protected:
87 : explicit ComboBox( WindowType nType );
88 11244 : sal_Bool IsDropDownBox() const { return mpFloatWin ? sal_True : sal_False; }
89 :
90 : virtual void FillLayoutData() const;
91 : public:
92 : explicit ComboBox( Window* pParent, WinBits nStyle = 0 );
93 : explicit ComboBox( Window* pParent, const ResId& );
94 : virtual ~ComboBox();
95 :
96 : virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
97 : virtual void Resize();
98 : virtual long PreNotify( NotifyEvent& rNEvt );
99 : virtual long Notify( NotifyEvent& rNEvt );
100 : virtual void StateChanged( StateChangedType nType );
101 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
102 :
103 : virtual void UserDraw( const UserDrawEvent& rUDEvt );
104 : virtual void Select();
105 : virtual void DoubleClick();
106 :
107 : virtual void Modify();
108 :
109 : virtual const Wallpaper& GetDisplayBackground() const;
110 :
111 : virtual void setPosSizePixel( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags = WINDOW_POSSIZE_ALL );
112 22 : void SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
113 22 : { Edit::SetPosSizePixel( rNewPos, rNewSize ); }
114 0 : void SetDropDownSizePixel( const Size& rNewSize )
115 0 : { if( IsDropDownBox() ) setPosSizePixel( 0, 0, rNewSize.Width(), rNewSize.Height(), WINDOW_POSSIZE_SIZE | WINDOW_POSSIZE_DROPDOWN ); }
116 :
117 : Rectangle GetDropDownPosSizePixel() const;
118 :
119 : void AdaptDropDownLineCountToMaximum();
120 : void SetDropDownLineCount( sal_uInt16 nLines );
121 : sal_uInt16 GetDropDownLineCount() const;
122 :
123 : void EnableAutoSize( bool bAuto );
124 1815 : sal_Bool IsAutoSizeEnabled() const { return mbDDAutoSize; }
125 :
126 : void EnableDDAutoWidth( sal_Bool b );
127 :
128 : virtual void SetText( const OUString& rStr );
129 : virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
130 :
131 : sal_uInt16 InsertEntry( const OUString& rStr, sal_uInt16 nPos = COMBOBOX_APPEND );
132 : sal_uInt16 InsertEntry( const OUString& rStr, const Image& rImage, sal_uInt16 nPos = COMBOBOX_APPEND );
133 :
134 : void RemoveEntry( const OUString& rStr );
135 : void RemoveEntry( sal_uInt16 nPos );
136 :
137 : void Clear();
138 :
139 : sal_uInt16 GetEntryPos( const OUString& rStr ) const;
140 : Image GetEntryImage( sal_uInt16 nPos ) const;
141 : OUString GetEntry( sal_uInt16 nPos ) const;
142 : sal_uInt16 GetEntryCount() const;
143 :
144 : sal_Bool IsTravelSelect() const;
145 : sal_Bool IsInDropDown() const;
146 : void ToggleDropDown();
147 :
148 : long CalcWindowSizePixel( sal_uInt16 nLines ) const;
149 :
150 : void SetUserItemSize( const Size& rSz );
151 : void EnableUserDraw( sal_Bool bUserDraw );
152 :
153 : void DrawEntry( const UserDrawEvent& rEvt, sal_Bool bDrawImage, sal_Bool bDrawText, sal_Bool bDrawTextAtImagePos = sal_False );
154 : void SetBorderStyle( sal_uInt16 nBorderStyle );
155 :
156 : void SetSeparatorPos( sal_uInt16 n = LISTBOX_ENTRY_NOTFOUND );
157 :
158 : void EnableAutocomplete( sal_Bool bEnable, sal_Bool bMatchCase = sal_False );
159 : sal_Bool IsAutocompleteEnabled() const;
160 :
161 : void EnableMultiSelection( sal_Bool bMulti );
162 : sal_Bool IsMultiSelectionEnabled() const;
163 : void SetMultiSelectionSeparator( sal_Unicode cSep ) { mcMultiSep = cSep; }
164 0 : sal_Unicode GetMultiSelectionSeparator() const { return mcMultiSep; }
165 :
166 0 : void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
167 0 : const Link& GetSelectHdl() const { return maSelectHdl; }
168 0 : void SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; }
169 0 : const Link& GetDoubleClickHdl() const { return maDoubleClickHdl; }
170 :
171 : Size CalcMinimumSize() const;
172 : virtual Size GetOptimalSize() const;
173 : Size CalcAdjustedSize( const Size& rPrefSize ) const;
174 : using Edit::CalcSize;
175 : Size CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
176 : void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
177 :
178 : void SetMRUEntries( const OUString& rEntries, sal_Unicode cSep = ';' );
179 : OUString GetMRUEntries( sal_Unicode cSep = ';' ) const;
180 : void SetMaxMRUCount( sal_uInt16 n );
181 : sal_uInt16 GetMaxMRUCount() const;
182 :
183 : void SetEntryData( sal_uInt16 nPos, void* pNewData );
184 : void* GetEntryData( sal_uInt16 nPos ) const;
185 :
186 : sal_uInt16 GetTopEntry() const;
187 :
188 : void SetProminentEntryType( ProminentEntry eType );
189 :
190 : sal_uInt16 GetDisplayLineCount() const;
191 :
192 : sal_uInt16 GetSelectEntryCount() const;
193 : sal_uInt16 GetSelectEntryPos( sal_uInt16 nSelIndex = 0 ) const;
194 : sal_Bool IsEntryPosSelected( sal_uInt16 nPos ) const;
195 : void SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect = sal_True );
196 : void SetNoSelection();
197 : Rectangle GetBoundingRectangle( sal_uInt16 nItem ) const;
198 :
199 : /** checks whether a certain point lies within the bounds of
200 : a list item and returns the item as well as the character position
201 : the point is at.
202 :
203 : <p>If the point is inside an item the item pos is put into <code>rPos</code> and
204 : the item-relative character index is returned. If the point is not inside
205 : an item -1 is returned and rPos is unchanged.</p>
206 :
207 : @param rPoint
208 : tells the point for which an item is requested.
209 :
210 : @param rPos
211 : gets the item at the specified point <code>rPoint</code>
212 :
213 : @returns
214 : the item-relative character index at point <code>rPos</code> or -1
215 : if no item is at that point.
216 : */
217 : using Control::GetIndexForPoint;
218 : long GetIndexForPoint( const Point& rPoint, sal_uInt16& rPos ) const;
219 :
220 : sal_Int32 getMaxWidthChars() const { return m_nMaxWidthChars; }
221 : void setMaxWidthChars(sal_Int32 nWidth);
222 :
223 : virtual bool set_property(const OString &rKey, const OString &rValue);
224 : };
225 :
226 : #endif // _COMBOBOX_HXX
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|