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