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