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 INCLUDED_VCL_COMBOBOX_HXX
21 : #define INCLUDED_VCL_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 : bool mbDDAutoSize : 1;
48 : bool mbSyntheticModify : 1;
49 : bool mbMatchCase : 1;
50 : sal_Int32 m_nMaxWidthChars;
51 : Link maSelectHdl;
52 : Link maDoubleClickHdl;
53 :
54 0 : 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 : DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl , void* );
78 :
79 : protected:
80 : using Window::ImplInit;
81 : SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
82 : SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
83 : SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
84 : SAL_DLLPRIVATE void ImplCalcEditHeight();
85 : SAL_DLLPRIVATE long getMaxWidthScrollBarAndDownButton() const;
86 :
87 : protected:
88 : explicit ComboBox( WindowType nType );
89 0 : bool IsDropDownBox() const { return mpFloatWin ? true : false; }
90 :
91 : virtual void FillLayoutData() const SAL_OVERRIDE;
92 : public:
93 : explicit ComboBox( Window* pParent, WinBits nStyle = 0 );
94 : explicit ComboBox( Window* pParent, const ResId& );
95 : virtual ~ComboBox();
96 :
97 : virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) SAL_OVERRIDE;
98 : virtual void Resize() SAL_OVERRIDE;
99 : virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
100 : virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
101 : virtual void StateChanged( StateChangedType nType ) SAL_OVERRIDE;
102 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
103 :
104 : virtual void UserDraw( const UserDrawEvent& rUDEvt );
105 : virtual void Select();
106 : virtual void DoubleClick();
107 :
108 : virtual void Modify() SAL_OVERRIDE;
109 :
110 : virtual const Wallpaper& GetDisplayBackground() const SAL_OVERRIDE;
111 :
112 : virtual void setPosSizePixel( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags = WINDOW_POSSIZE_ALL ) SAL_OVERRIDE;
113 0 : void SetPosSizePixel( const Point& rNewPos, const Size& rNewSize ) SAL_OVERRIDE
114 0 : { Edit::SetPosSizePixel( rNewPos, rNewSize ); }
115 0 : void SetDropDownSizePixel( const Size& rNewSize )
116 0 : { if( IsDropDownBox() ) setPosSizePixel( 0, 0, rNewSize.Width(), rNewSize.Height(), WINDOW_POSSIZE_SIZE | WINDOW_POSSIZE_DROPDOWN ); }
117 :
118 : Rectangle GetDropDownPosSizePixel() const;
119 :
120 : void AdaptDropDownLineCountToMaximum();
121 : void SetDropDownLineCount( sal_uInt16 nLines );
122 : sal_uInt16 GetDropDownLineCount() const;
123 :
124 : void EnableAutoSize( bool bAuto );
125 0 : bool IsAutoSizeEnabled() const { return mbDDAutoSize; }
126 :
127 : void EnableDDAutoWidth( bool b );
128 :
129 : virtual void SetText( const OUString& rStr ) SAL_OVERRIDE;
130 : virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) SAL_OVERRIDE;
131 :
132 : virtual sal_Int32 InsertEntry(const OUString& rStr, sal_Int32 nPos = COMBOBOX_APPEND);
133 : void InsertEntryWithImage( const OUString& rStr, const Image& rImage, sal_Int32 nPos = COMBOBOX_APPEND );
134 :
135 : void RemoveEntry( const OUString& rStr );
136 : virtual void RemoveEntryAt(sal_Int32 nPos);
137 :
138 : void Clear();
139 :
140 : sal_Int32 GetEntryPos( const OUString& rStr ) const;
141 : Image GetEntryImage( sal_Int32 nPos ) const;
142 : OUString GetEntry( sal_Int32 nPos ) const;
143 : sal_Int32 GetEntryCount() const;
144 :
145 : bool IsTravelSelect() const;
146 : bool IsInDropDown() const;
147 : void ToggleDropDown();
148 :
149 : long CalcWindowSizePixel( sal_uInt16 nLines ) const;
150 :
151 : void SetUserItemSize( const Size& rSz );
152 : void EnableUserDraw( bool bUserDraw );
153 :
154 : void DrawEntry( const UserDrawEvent& rEvt, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos = false );
155 : void SetBorderStyle( sal_uInt16 nBorderStyle );
156 :
157 : void SetSeparatorPos( sal_Int32 n = LISTBOX_ENTRY_NOTFOUND );
158 :
159 : void EnableAutocomplete( bool bEnable, bool bMatchCase = false );
160 : bool IsAutocompleteEnabled() const;
161 :
162 : void EnableMultiSelection( bool bMulti );
163 : bool IsMultiSelectionEnabled() const;
164 : void SetMultiSelectionSeparator( sal_Unicode cSep ) { mcMultiSep = cSep; }
165 0 : sal_Unicode GetMultiSelectionSeparator() const { return mcMultiSep; }
166 :
167 0 : void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
168 0 : const Link& GetSelectHdl() const { return maSelectHdl; }
169 0 : void SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; }
170 0 : const Link& GetDoubleClickHdl() const { return maDoubleClickHdl; }
171 :
172 : Size CalcMinimumSize() const SAL_OVERRIDE;
173 : virtual Size GetOptimalSize() const SAL_OVERRIDE;
174 : Size CalcAdjustedSize( const Size& rPrefSize ) const;
175 : Size CalcBlockSize( 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_Int32 n );
181 : sal_Int32 GetMaxMRUCount() const;
182 : void SetEntryData( sal_Int32 nPos, void* pNewData );
183 : void* GetEntryData( sal_Int32 nPos ) const;
184 :
185 : sal_Int32 GetTopEntry() const;
186 :
187 : void SetProminentEntryType( ProminentEntry eType );
188 :
189 : sal_uInt16 GetDisplayLineCount() const;
190 :
191 : sal_Int32 GetSelectEntryCount() const;
192 : sal_Int32 GetSelectEntryPos( sal_Int32 nSelIndex = 0 ) const;
193 : bool IsEntryPosSelected( sal_Int32 nPos ) const;
194 : void SelectEntryPos( sal_Int32 nPos, bool bSelect = true );
195 : void SetNoSelection();
196 : Rectangle GetBoundingRectangle( sal_Int32 nItem ) const;
197 :
198 : /** checks whether a certain point lies within the bounds of
199 : a list item and returns the item as well as the character position
200 : the point is at.
201 :
202 : <p>If the point is inside an item the item pos is put into <code>rPos</code> and
203 : the item-relative character index is returned. If the point is not inside
204 : an item -1 is returned and rPos is unchanged.</p>
205 :
206 : @param rPoint
207 : tells the point for which an item is requested.
208 :
209 : @param rPos
210 : gets the item at the specified point <code>rPoint</code>
211 :
212 : @returns
213 : the item-relative character index at point <code>rPos</code> or -1
214 : if no item is at that point.
215 : */
216 : using Control::GetIndexForPoint;
217 : long GetIndexForPoint( const Point& rPoint, sal_Int32 & rPos ) const;
218 :
219 : sal_Int32 getMaxWidthChars() const { return m_nMaxWidthChars; }
220 : void setMaxWidthChars(sal_Int32 nWidth);
221 :
222 : virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
223 : };
224 :
225 : #endif // _COMBOBOX_HXX
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|