]>
Commit | Line | Data |
---|---|---|
a340b80d | 1 | ///////////////////////////////////////////////////////////////////////////// |
b61f4f77 | 2 | // Name: src/common/combocmn.cpp |
a57d600f | 3 | // Purpose: wxComboCtrlBase |
a340b80d VZ |
4 | // Author: Jaakko Salli |
5 | // Modified by: | |
6 | // Created: Apr-30-2006 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2005 Jaakko Salli | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
f313deaa | 26 | #if wxUSE_COMBOBOX |
a5bbd1cc | 27 | #include "wx/combobox.h" |
f313deaa PC |
28 | extern WXDLLEXPORT_DATA(const char) wxComboBoxNameStr[] = "comboBox"; |
29 | #endif | |
30 | ||
31 | #if wxUSE_COMBOCTRL | |
a5bbd1cc | 32 | |
a340b80d | 33 | #ifndef WX_PRECOMP |
46beb2e9 | 34 | #include "wx/app.h" |
a340b80d | 35 | #include "wx/log.h" |
a340b80d VZ |
36 | #include "wx/dcclient.h" |
37 | #include "wx/settings.h" | |
c0badb70 | 38 | #include "wx/timer.h" |
0ec1179b | 39 | #include "wx/textctrl.h" |
a340b80d VZ |
40 | #endif |
41 | ||
a340b80d | 42 | #include "wx/tooltip.h" |
a340b80d VZ |
43 | |
44 | #include "wx/combo.h" | |
45 | ||
46 | ||
28953245 SC |
47 | // ---------------------------------------------------------------------------- |
48 | // XTI | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | wxDEFINE_FLAGS( wxComboBoxStyle ) | |
52 | wxBEGIN_FLAGS( wxComboBoxStyle ) | |
53 | // new style border flags, we put them first to | |
54 | // use them for streaming out | |
55 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) | |
56 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
57 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
58 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
59 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
60 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
61 | ||
62 | // old style border flags | |
63 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) | |
64 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
65 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
66 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
67 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
68 | wxFLAGS_MEMBER(wxBORDER) | |
69 | ||
70 | // standard window styles | |
71 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
72 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
73 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
74 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
75 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
76 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
77 | wxFLAGS_MEMBER(wxVSCROLL) | |
78 | wxFLAGS_MEMBER(wxHSCROLL) | |
79 | ||
80 | wxFLAGS_MEMBER(wxCB_SIMPLE) | |
81 | wxFLAGS_MEMBER(wxCB_SORT) | |
82 | wxFLAGS_MEMBER(wxCB_READONLY) | |
83 | wxFLAGS_MEMBER(wxCB_DROPDOWN) | |
84 | ||
85 | wxEND_FLAGS( wxComboBoxStyle ) | |
86 | ||
72259abb | 87 | wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxControl, "wx/combobox.h") |
28953245 SC |
88 | |
89 | wxBEGIN_PROPERTIES_TABLE(wxComboBox) | |
90 | wxEVENT_PROPERTY( Select, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent ) | |
91 | wxEVENT_PROPERTY( TextEnter, wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent ) | |
92 | ||
93 | // TODO DELEGATES | |
94 | wxPROPERTY( Font, wxFont, SetFont, GetFont, wxEMPTY_PARAMETER_VALUE, \ | |
95 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
96 | wxPROPERTY_COLLECTION( Choices, wxArrayString, wxString, AppendString, \ | |
97 | GetStrings, 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
98 | wxPROPERTY( Value,wxString, SetValue, GetValue, wxEMPTY_PARAMETER_VALUE, \ | |
99 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
100 | wxPROPERTY( Selection,int, SetSelection, GetSelection, wxEMPTY_PARAMETER_VALUE, \ | |
101 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
102 | ||
103 | wxPROPERTY_FLAGS( WindowStyle, wxComboBoxStyle, long, SetWindowStyleFlag, \ | |
104 | GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \ | |
105 | wxT("Helpstring"), wxT("group")) // style | |
106 | wxEND_PROPERTIES_TABLE() | |
107 | ||
108 | wxEMPTY_HANDLERS_TABLE(wxComboBox) | |
109 | ||
110 | wxCONSTRUCTOR_5( wxComboBox, wxWindow*, Parent, wxWindowID, Id, \ | |
111 | wxString, Value, wxPoint, Position, wxSize, Size ) | |
a340b80d VZ |
112 | |
113 | // constants | |
114 | // ---------------------------------------------------------------------------- | |
115 | ||
a340b80d VZ |
116 | #define DEFAULT_DROPBUTTON_WIDTH 19 |
117 | ||
118 | #define BMP_BUTTON_MARGIN 4 | |
119 | ||
7962f85a | 120 | #define DEFAULT_POPUP_HEIGHT 400 |
a340b80d VZ |
121 | |
122 | #define DEFAULT_TEXT_INDENT 3 | |
123 | ||
124 | #define COMBO_MARGIN 2 // spacing right of wxTextCtrl | |
125 | ||
126 | ||
127 | #if defined(__WXMSW__) | |
128 | ||
fd5b4315 JS |
129 | // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow |
130 | #include "wx/frame.h" | |
131 | #define wxCC_GENERIC_TLW_IS_FRAME | |
132 | #define wxComboCtrlGenericTLW wxFrame | |
133 | ||
a340b80d | 134 | #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform) |
06077aaf VZ |
135 | #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common |
136 | // native controls work on it like normal. | |
137 | #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window. | |
7e4545b8 | 138 | #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered |
2dfa37d6 | 139 | #define FOCUS_RING 0 // No focus ring on wxMSW |
a340b80d VZ |
140 | |
141 | //#undef wxUSE_POPUPWIN | |
142 | //#define wxUSE_POPUPWIN 0 | |
143 | ||
144 | #elif defined(__WXGTK__) | |
145 | ||
06077aaf VZ |
146 | // NB: It is not recommended to use wxDialog as popup on wxGTK, because of |
147 | // this bug: If wxDialog is hidden, its position becomes corrupt | |
148 | // between hide and next show, but without internal coordinates being | |
149 | // reflected (or something like that - atleast commenting out ->Hide() | |
150 | // seemed to eliminate the position change). | |
151 | ||
fd5b4315 JS |
152 | #include "wx/dialog.h" |
153 | #define wxCC_GENERIC_TLW_IS_DIALOG | |
154 | #define wxComboCtrlGenericTLW wxDialog | |
155 | ||
b9d0da6f JJ |
156 | #if defined(__WXGTK20__) |
157 | # include "wx/gtk/private.h" | |
158 | #else | |
159 | # include "wx/gtk1/private.h" | |
160 | #endif | |
fd5b4315 | 161 | |
d42b8621 JS |
162 | // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a |
163 | // 'perfect' popup, as it can succesfully host child controls even in | |
164 | // popups that are shown in modal dialogs. | |
165 | ||
a340b80d | 166 | #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform) |
d42b8621 | 167 | #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common |
06077aaf VZ |
168 | // native controls work on it like normal. |
169 | #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window. | |
7e4545b8 | 170 | #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered |
2dfa37d6 | 171 | #define FOCUS_RING 0 // No focus ring on wxGTK |
a340b80d VZ |
172 | |
173 | #elif defined(__WXMAC__) | |
174 | ||
fd5b4315 JS |
175 | #include "wx/nonownedwnd.h" |
176 | #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW | |
177 | #define wxComboCtrlGenericTLW wxNonOwnedWindow | |
178 | ||
b48eedfc RR |
179 | #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform) |
180 | #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common | |
06077aaf | 181 | // native controls work on it like normal. |
b48eedfc | 182 | #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window. |
7e4545b8 | 183 | #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered |
2dfa37d6 RD |
184 | #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display |
185 | ||
186 | #undef DEFAULT_DROPBUTTON_WIDTH | |
187 | #define DEFAULT_DROPBUTTON_WIDTH 22 | |
188 | #undef COMBO_MARGIN | |
189 | #define COMBO_MARGIN FOCUS_RING | |
a340b80d VZ |
190 | |
191 | #else | |
192 | ||
fd5b4315 JS |
193 | #include "wx/dialog.h" |
194 | #define wxCC_GENERIC_TLW_IS_DIALOG | |
195 | #define wxComboCtrlGenericTLW wxDialog | |
196 | ||
a340b80d | 197 | #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform) |
06077aaf VZ |
198 | #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common |
199 | // native controls work on it like normal. | |
200 | #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window. | |
7e4545b8 | 201 | #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered |
2dfa37d6 | 202 | #define FOCUS_RING 0 |
f3fcecd6 | 203 | |
a340b80d VZ |
204 | #endif |
205 | ||
206 | ||
207 | // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless | |
208 | // what the wxUSE_POPUPWIN says. | |
209 | // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2) | |
b48eedfc | 210 | #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__) |
a340b80d VZ |
211 | #undef wxUSE_POPUPWIN |
212 | #define wxUSE_POPUPWIN 0 | |
213 | #endif | |
214 | ||
215 | ||
216 | #if wxUSE_POPUPWIN | |
217 | #include "wx/popupwin.h" | |
218 | #else | |
219 | #undef USE_TRANSIENT_POPUP | |
220 | #define USE_TRANSIENT_POPUP 0 | |
221 | #endif | |
222 | ||
223 | ||
06077aaf VZ |
224 | // Define different types of popup windows |
225 | enum | |
226 | { | |
227 | POPUPWIN_NONE = 0, | |
228 | POPUPWIN_WXPOPUPTRANSIENTWINDOW = 1, | |
229 | POPUPWIN_WXPOPUPWINDOW = 2, | |
fd5b4315 | 230 | POPUPWIN_GENERICTLW = 3 |
06077aaf | 231 | }; |
a340b80d | 232 | |
06077aaf VZ |
233 | |
234 | #if USE_TRANSIENT_POPUP | |
235 | // wxPopupTransientWindow is implemented | |
236 | ||
237 | #define wxComboPopupWindowBase wxPopupTransientWindow | |
238 | #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW | |
239 | #define USES_WXPOPUPTRANSIENTWINDOW 1 | |
240 | ||
241 | #if TRANSIENT_POPUPWIN_IS_PERFECT | |
242 | // | |
243 | #elif POPUPWIN_IS_PERFECT | |
244 | #define wxComboPopupWindowBase2 wxPopupWindow | |
245 | #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW | |
246 | #define USES_WXPOPUPWINDOW 1 | |
247 | #else | |
fd5b4315 JS |
248 | #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW |
249 | #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW | |
250 | #define USES_GENERICTLW 1 | |
06077aaf | 251 | #endif |
a340b80d VZ |
252 | |
253 | #elif wxUSE_POPUPWIN | |
06077aaf | 254 | // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented |
a340b80d | 255 | |
06077aaf VZ |
256 | #define wxComboPopupWindowBase wxPopupWindow |
257 | #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW | |
258 | #define USES_WXPOPUPWINDOW 1 | |
259 | ||
260 | #if !POPUPWIN_IS_PERFECT | |
fd5b4315 JS |
261 | #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW |
262 | #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW | |
263 | #define USES_GENERICTLW 1 | |
06077aaf | 264 | #endif |
a340b80d VZ |
265 | |
266 | #else | |
06077aaf VZ |
267 | // wxPopupWindow is not implemented |
268 | ||
fd5b4315 JS |
269 | #define wxComboPopupWindowBase wxComboCtrlGenericTLW |
270 | #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW | |
271 | #define USES_GENERICTLW 1 | |
06077aaf VZ |
272 | |
273 | #endif | |
274 | ||
275 | ||
276 | #ifndef USES_WXPOPUPTRANSIENTWINDOW | |
277 | #define USES_WXPOPUPTRANSIENTWINDOW 0 | |
278 | #endif | |
a340b80d | 279 | |
06077aaf VZ |
280 | #ifndef USES_WXPOPUPWINDOW |
281 | #define USES_WXPOPUPWINDOW 0 | |
282 | #endif | |
a340b80d | 283 | |
fd5b4315 JS |
284 | #ifndef USES_GENERICTLW |
285 | #define USES_GENERICTLW 0 | |
a340b80d VZ |
286 | #endif |
287 | ||
288 | ||
06077aaf VZ |
289 | #if USES_WXPOPUPWINDOW |
290 | #define INSTALL_TOPLEV_HANDLER 1 | |
291 | #else | |
292 | #define INSTALL_TOPLEV_HANDLER 0 | |
293 | #endif | |
294 | ||
a340b80d | 295 | |
52999871 JS |
296 | // Returns true if given popup window type can be classified as perfect |
297 | // on this platform. | |
298 | static inline bool IsPopupWinTypePerfect( wxByte popupWinType ) | |
299 | { | |
300 | #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT | |
301 | wxUnusedVar(popupWinType); | |
302 | return true; | |
303 | #else | |
304 | return ( popupWinType == POPUPWIN_GENERICTLW | |
305 | #if POPUPWIN_IS_PERFECT | |
ce00f59b | 306 | || popupWinType == POPUPWIN_WXPOPUPWINDOW |
52999871 JS |
307 | #endif |
308 | #if TRANSIENT_POPUPWIN_IS_PERFECT | |
ce00f59b | 309 | || popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW |
52999871 JS |
310 | #endif |
311 | ); | |
312 | #endif | |
313 | } | |
314 | ||
315 | ||
a340b80d VZ |
316 | // |
317 | // ** TODO ** | |
318 | // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow) | |
319 | // | |
320 | ||
321 | ||
322 | // ---------------------------------------------------------------------------- | |
323 | // wxComboFrameEventHandler takes care of hiding the popup when events happen | |
324 | // in its top level parent. | |
325 | // ---------------------------------------------------------------------------- | |
326 | ||
327 | #if INSTALL_TOPLEV_HANDLER | |
328 | ||
329 | // | |
330 | // This will no longer be necessary after wxTransientPopupWindow | |
331 | // works well on all platforms. | |
332 | // | |
333 | ||
334 | class wxComboFrameEventHandler : public wxEvtHandler | |
335 | { | |
336 | public: | |
a57d600f | 337 | wxComboFrameEventHandler( wxComboCtrlBase* pCb ); |
d3c7fc99 | 338 | virtual ~wxComboFrameEventHandler(); |
a340b80d VZ |
339 | |
340 | void OnPopup(); | |
341 | ||
342 | void OnIdle( wxIdleEvent& event ); | |
343 | void OnMouseEvent( wxMouseEvent& event ); | |
344 | void OnActivate( wxActivateEvent& event ); | |
345 | void OnResize( wxSizeEvent& event ); | |
346 | void OnMove( wxMoveEvent& event ); | |
347 | void OnMenuEvent( wxMenuEvent& event ); | |
348 | void OnClose( wxCloseEvent& event ); | |
349 | ||
350 | protected: | |
351 | wxWindow* m_focusStart; | |
a57d600f | 352 | wxComboCtrlBase* m_combo; |
a340b80d VZ |
353 | |
354 | private: | |
355 | DECLARE_EVENT_TABLE() | |
356 | }; | |
357 | ||
358 | BEGIN_EVENT_TABLE(wxComboFrameEventHandler, wxEvtHandler) | |
359 | EVT_IDLE(wxComboFrameEventHandler::OnIdle) | |
360 | EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent) | |
361 | EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent) | |
362 | EVT_SIZE(wxComboFrameEventHandler::OnResize) | |
363 | EVT_MOVE(wxComboFrameEventHandler::OnMove) | |
364 | EVT_MENU_HIGHLIGHT(wxID_ANY,wxComboFrameEventHandler::OnMenuEvent) | |
365 | EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent) | |
366 | EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate) | |
367 | EVT_CLOSE(wxComboFrameEventHandler::OnClose) | |
368 | END_EVENT_TABLE() | |
369 | ||
a57d600f | 370 | wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase* combo ) |
a340b80d VZ |
371 | : wxEvtHandler() |
372 | { | |
373 | m_combo = combo; | |
374 | } | |
375 | ||
376 | wxComboFrameEventHandler::~wxComboFrameEventHandler() | |
377 | { | |
378 | } | |
379 | ||
380 | void wxComboFrameEventHandler::OnPopup() | |
381 | { | |
382 | m_focusStart = ::wxWindow::FindFocus(); | |
383 | } | |
384 | ||
385 | void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event ) | |
386 | { | |
387 | wxWindow* winFocused = ::wxWindow::FindFocus(); | |
388 | ||
c667b518 | 389 | wxWindow* popup = m_combo->GetPopupControl()->GetControl(); |
a340b80d VZ |
390 | wxWindow* winpopup = m_combo->GetPopupWindow(); |
391 | ||
392 | if ( | |
393 | winFocused != m_focusStart && | |
394 | winFocused != popup && | |
395 | winFocused->GetParent() != popup && | |
396 | winFocused != winpopup && | |
397 | winFocused->GetParent() != winpopup && | |
398 | winFocused != m_combo && | |
399 | winFocused != m_combo->GetButton() // GTK (atleast) requires this | |
400 | ) | |
401 | { | |
a1d5aa93 | 402 | m_combo->HidePopup(true); |
a340b80d VZ |
403 | } |
404 | ||
405 | event.Skip(); | |
406 | } | |
407 | ||
408 | void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event ) | |
409 | { | |
a1d5aa93 | 410 | m_combo->HidePopup(true); |
a340b80d VZ |
411 | event.Skip(); |
412 | } | |
413 | ||
414 | void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event ) | |
415 | { | |
a1d5aa93 | 416 | m_combo->HidePopup(true); |
a340b80d VZ |
417 | event.Skip(); |
418 | } | |
419 | ||
420 | void wxComboFrameEventHandler::OnClose( wxCloseEvent& event ) | |
421 | { | |
a1d5aa93 | 422 | m_combo->HidePopup(true); |
a340b80d VZ |
423 | event.Skip(); |
424 | } | |
425 | ||
426 | void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event ) | |
427 | { | |
a1d5aa93 | 428 | m_combo->HidePopup(true); |
a340b80d VZ |
429 | event.Skip(); |
430 | } | |
431 | ||
432 | void wxComboFrameEventHandler::OnResize( wxSizeEvent& event ) | |
433 | { | |
a1d5aa93 | 434 | m_combo->HidePopup(true); |
a340b80d VZ |
435 | event.Skip(); |
436 | } | |
437 | ||
438 | void wxComboFrameEventHandler::OnMove( wxMoveEvent& event ) | |
439 | { | |
a1d5aa93 | 440 | m_combo->HidePopup(true); |
a340b80d VZ |
441 | event.Skip(); |
442 | } | |
443 | ||
444 | #endif // INSTALL_TOPLEV_HANDLER | |
445 | ||
446 | // ---------------------------------------------------------------------------- | |
06077aaf | 447 | // wxComboPopupWindow is, in essence, wxPopupWindow customized for |
a57d600f | 448 | // wxComboCtrl. |
a340b80d VZ |
449 | // ---------------------------------------------------------------------------- |
450 | ||
451 | class wxComboPopupWindow : public wxComboPopupWindowBase | |
452 | { | |
453 | public: | |
454 | ||
06077aaf VZ |
455 | wxComboPopupWindow( wxComboCtrlBase *parent, |
456 | int style ) | |
457 | #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW | |
458 | : wxComboPopupWindowBase(parent,style) | |
459 | #else | |
460 | : wxComboPopupWindowBase(parent, | |
461 | wxID_ANY, | |
462 | wxEmptyString, | |
463 | wxPoint(-21,-21), | |
464 | wxSize(20,20), | |
465 | style) | |
466 | #endif | |
467 | { | |
974a12f8 | 468 | m_inShow = 0; |
06077aaf | 469 | } |
a340b80d | 470 | |
06077aaf | 471 | #if USES_WXPOPUPTRANSIENTWINDOW |
974a12f8 | 472 | virtual bool Show( bool show ); |
a340b80d | 473 | virtual bool ProcessLeftDown(wxMouseEvent& event); |
d7e15728 | 474 | protected: |
06077aaf | 475 | virtual void OnDismiss(); |
a340b80d VZ |
476 | #endif |
477 | ||
974a12f8 RR |
478 | private: |
479 | wxByte m_inShow; | |
06077aaf | 480 | }; |
a340b80d | 481 | |
a340b80d | 482 | |
06077aaf | 483 | #if USES_WXPOPUPTRANSIENTWINDOW |
974a12f8 | 484 | bool wxComboPopupWindow::Show( bool show ) |
06077aaf | 485 | { |
974a12f8 RR |
486 | // Guard against recursion |
487 | if ( m_inShow ) | |
488 | return wxComboPopupWindowBase::Show(show); | |
489 | ||
490 | m_inShow++; | |
491 | ||
492 | wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow)) ); | |
493 | ||
494 | wxPopupTransientWindow* ptw = (wxPopupTransientWindow*) this; | |
974a12f8 RR |
495 | |
496 | if ( show != ptw->IsShown() ) | |
497 | { | |
498 | if ( show ) | |
c905c0d6 VZ |
499 | // We used to do wxPopupTransientWindow::Popup here, |
500 | // but this would hide normal Show, which we are | |
501 | // also going to need. | |
502 | ptw->Show(); | |
974a12f8 RR |
503 | else |
504 | ptw->Dismiss(); | |
505 | } | |
506 | ||
507 | m_inShow--; | |
508 | ||
509 | return true; | |
510 | } | |
511 | ||
512 | bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event) | |
513 | { | |
514 | return wxPopupTransientWindow::ProcessLeftDown(event); | |
06077aaf | 515 | } |
a340b80d | 516 | |
06077aaf VZ |
517 | // First thing that happens when a transient popup closes is that this method gets called. |
518 | void wxComboPopupWindow::OnDismiss() | |
519 | { | |
520 | wxComboCtrlBase* combo = (wxComboCtrlBase*) GetParent(); | |
521 | wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)), | |
522 | wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") ); | |
523 | ||
a1d5aa93 | 524 | combo->OnPopupDismiss(true); |
06077aaf VZ |
525 | } |
526 | #endif // USES_WXPOPUPTRANSIENTWINDOW | |
527 | ||
528 | ||
529 | // ---------------------------------------------------------------------------- | |
530 | // wxComboPopupWindowEvtHandler does bulk of the custom event handling | |
531 | // of a popup window. It is separate so we can have different types | |
532 | // of popup windows. | |
533 | // ---------------------------------------------------------------------------- | |
534 | ||
535 | class wxComboPopupWindowEvtHandler : public wxEvtHandler | |
536 | { | |
537 | public: | |
538 | ||
539 | wxComboPopupWindowEvtHandler( wxComboCtrlBase *parent ) | |
540 | { | |
541 | m_combo = parent; | |
542 | } | |
543 | ||
974a12f8 | 544 | void OnSizeEvent( wxSizeEvent& event ); |
06077aaf | 545 | void OnKeyEvent(wxKeyEvent& event); |
fd5b4315 | 546 | #if USES_GENERICTLW |
06077aaf | 547 | void OnActivate( wxActivateEvent& event ); |
a340b80d VZ |
548 | #endif |
549 | ||
550 | private: | |
06077aaf VZ |
551 | wxComboCtrlBase* m_combo; |
552 | ||
a340b80d VZ |
553 | DECLARE_EVENT_TABLE() |
554 | }; | |
555 | ||
556 | ||
06077aaf VZ |
557 | BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler, wxEvtHandler) |
558 | EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent) | |
559 | EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent) | |
c765e6fb | 560 | EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent) |
fd5b4315 | 561 | #if USES_GENERICTLW |
06077aaf | 562 | EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate) |
a340b80d | 563 | #endif |
974a12f8 | 564 | EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent) |
a340b80d VZ |
565 | END_EVENT_TABLE() |
566 | ||
567 | ||
974a12f8 RR |
568 | void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent& WXUNUSED(event) ) |
569 | { | |
570 | // Block the event so that the popup control does not get auto-resized. | |
571 | } | |
572 | ||
06077aaf | 573 | void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event ) |
a340b80d VZ |
574 | { |
575 | // Relay keyboard event to the main child controls | |
06077aaf | 576 | wxWindowList children = m_combo->GetPopupWindow()->GetChildren(); |
a340b80d VZ |
577 | wxWindowList::iterator node = children.begin(); |
578 | wxWindow* child = (wxWindow*)*node; | |
174b5c87 | 579 | child->GetEventHandler()->ProcessEvent(event); |
a340b80d VZ |
580 | } |
581 | ||
fd5b4315 | 582 | #if USES_GENERICTLW |
06077aaf | 583 | void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event ) |
a340b80d VZ |
584 | { |
585 | if ( !event.GetActive() ) | |
586 | { | |
587 | // Tell combo control that we are dismissed. | |
a1d5aa93 | 588 | m_combo->HidePopup(true); |
a340b80d VZ |
589 | |
590 | event.Skip(); | |
591 | } | |
592 | } | |
593 | #endif | |
594 | ||
a340b80d VZ |
595 | |
596 | // ---------------------------------------------------------------------------- | |
597 | // wxComboPopup | |
598 | // | |
599 | // ---------------------------------------------------------------------------- | |
600 | ||
601 | wxComboPopup::~wxComboPopup() | |
602 | { | |
603 | } | |
604 | ||
605 | void wxComboPopup::OnPopup() | |
606 | { | |
607 | } | |
608 | ||
609 | void wxComboPopup::OnDismiss() | |
610 | { | |
611 | } | |
612 | ||
8c61a9ea JS |
613 | wxComboCtrl* wxComboPopup::GetComboCtrl() const |
614 | { | |
615 | return wxStaticCast(m_combo, wxComboCtrl); | |
616 | } | |
617 | ||
a340b80d VZ |
618 | wxSize wxComboPopup::GetAdjustedSize( int minWidth, |
619 | int prefHeight, | |
620 | int WXUNUSED(maxHeight) ) | |
621 | { | |
622 | return wxSize(minWidth,prefHeight); | |
623 | } | |
624 | ||
a57d600f | 625 | void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo, |
6d0ce565 | 626 | wxDC& dc, const wxRect& rect ) |
a340b80d | 627 | { |
6d0ce565 | 628 | if ( combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl |
a340b80d | 629 | { |
118f5fbd | 630 | combo->PrepareBackground(dc,rect,0); |
a340b80d | 631 | |
6d0ce565 | 632 | dc.DrawText( combo->GetValue(), |
0847e36e | 633 | rect.x + combo->m_marginLeft, |
6d0ce565 | 634 | (rect.height-dc.GetCharHeight())/2 + rect.y ); |
a340b80d VZ |
635 | } |
636 | } | |
637 | ||
6d0ce565 VZ |
638 | void wxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect ) |
639 | { | |
640 | DefaultPaintComboControl(m_combo,dc,rect); | |
641 | } | |
642 | ||
a340b80d VZ |
643 | void wxComboPopup::OnComboKeyEvent( wxKeyEvent& event ) |
644 | { | |
645 | event.Skip(); | |
646 | } | |
647 | ||
c765e6fb VS |
648 | void wxComboPopup::OnComboCharEvent( wxKeyEvent& event ) |
649 | { | |
650 | event.Skip(); | |
651 | } | |
652 | ||
a340b80d VZ |
653 | void wxComboPopup::OnComboDoubleClick() |
654 | { | |
655 | } | |
656 | ||
657 | void wxComboPopup::SetStringValue( const wxString& WXUNUSED(value) ) | |
658 | { | |
659 | } | |
660 | ||
238b33ab JS |
661 | bool wxComboPopup::FindItem(const wxString& WXUNUSED(item), |
662 | wxString* WXUNUSED(trueItem)) | |
663 | { | |
664 | return true; | |
665 | } | |
666 | ||
a340b80d VZ |
667 | bool wxComboPopup::LazyCreate() |
668 | { | |
669 | return false; | |
670 | } | |
671 | ||
672 | void wxComboPopup::Dismiss() | |
673 | { | |
a1d5aa93 | 674 | m_combo->HidePopup(true); |
a340b80d VZ |
675 | } |
676 | ||
677 | // ---------------------------------------------------------------------------- | |
678 | // input handling | |
679 | // ---------------------------------------------------------------------------- | |
680 | ||
681 | // | |
b445b6a7 | 682 | // This is pushed to the event handler queue of the child textctrl. |
a340b80d VZ |
683 | // |
684 | class wxComboBoxExtraInputHandler : public wxEvtHandler | |
685 | { | |
686 | public: | |
687 | ||
a57d600f | 688 | wxComboBoxExtraInputHandler( wxComboCtrlBase* combo ) |
a340b80d VZ |
689 | : wxEvtHandler() |
690 | { | |
691 | m_combo = combo; | |
692 | } | |
d3c7fc99 | 693 | virtual ~wxComboBoxExtraInputHandler() { } |
a340b80d VZ |
694 | void OnKey(wxKeyEvent& event); |
695 | void OnFocus(wxFocusEvent& event); | |
696 | ||
697 | protected: | |
a57d600f | 698 | wxComboCtrlBase* m_combo; |
a340b80d VZ |
699 | |
700 | private: | |
701 | DECLARE_EVENT_TABLE() | |
702 | }; | |
703 | ||
704 | ||
705 | BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler, wxEvtHandler) | |
706 | EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey) | |
df6007a5 JS |
707 | EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey) |
708 | EVT_CHAR(wxComboBoxExtraInputHandler::OnKey) | |
a340b80d | 709 | EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus) |
c905c0d6 | 710 | EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus) |
a340b80d VZ |
711 | END_EVENT_TABLE() |
712 | ||
713 | ||
714 | void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event) | |
715 | { | |
b445b6a7 VZ |
716 | // Let the wxComboCtrl event handler have a go first. |
717 | wxComboCtrlBase* combo = m_combo; | |
a340b80d | 718 | |
110d27b3 JS |
719 | wxKeyEvent redirectedEvent(event); |
720 | redirectedEvent.SetId(combo->GetId()); | |
721 | redirectedEvent.SetEventObject(combo); | |
a340b80d | 722 | |
110d27b3 JS |
723 | if ( !combo->GetEventHandler()->ProcessEvent(redirectedEvent) ) |
724 | { | |
725 | // Don't let TAB through to the text ctrl - looks ugly | |
726 | if ( event.GetKeyCode() != WXK_TAB ) | |
727 | event.Skip(); | |
728 | } | |
a340b80d VZ |
729 | } |
730 | ||
a340b80d VZ |
731 | void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent& event) |
732 | { | |
733 | // FIXME: This code does run when control is clicked, | |
734 | // yet on Windows it doesn't select all the text. | |
c905c0d6 VZ |
735 | if ( event.GetEventType() == wxEVT_SET_FOCUS && |
736 | !(m_combo->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT) ) | |
a340b80d VZ |
737 | { |
738 | if ( m_combo->GetTextCtrl() ) | |
739 | m_combo->GetTextCtrl()->SelectAll(); | |
740 | else | |
741 | m_combo->SetSelection(-1,-1); | |
742 | } | |
743 | ||
b445b6a7 VZ |
744 | // Send focus indication to parent. |
745 | // NB: This is needed for cases where the textctrl gets focus | |
746 | // instead of its parent. While this may trigger multiple | |
747 | // wxEVT_SET_FOCUSes (since m_text->SetFocus is called | |
748 | // from combo's focus event handler), they should be quite | |
749 | // harmless. | |
81ebc041 VZ |
750 | wxFocusEvent evt2(event); |
751 | evt2.SetId(m_combo->GetId()); | |
b445b6a7 VZ |
752 | evt2.SetEventObject(m_combo); |
753 | m_combo->GetEventHandler()->ProcessEvent(evt2); | |
6d0ce565 | 754 | |
a340b80d VZ |
755 | event.Skip(); |
756 | } | |
757 | ||
758 | ||
759 | // | |
760 | // This is pushed to the event handler queue of the control in popup. | |
761 | // | |
762 | ||
06315578 | 763 | class wxComboPopupEvtHandler : public wxEvtHandler |
a340b80d VZ |
764 | { |
765 | public: | |
766 | ||
06315578 | 767 | wxComboPopupEvtHandler( wxComboCtrlBase* combo ) |
a340b80d VZ |
768 | : wxEvtHandler() |
769 | { | |
770 | m_combo = combo; | |
771 | m_beenInside = false; | |
4794626d JS |
772 | |
773 | // Let's make it so that the popup control will not receive mouse | |
774 | // events until mouse left button has been up. | |
775 | m_blockEventsToPopup = true; | |
a340b80d | 776 | } |
06315578 | 777 | virtual ~wxComboPopupEvtHandler() { } |
a340b80d VZ |
778 | |
779 | void OnMouseEvent( wxMouseEvent& event ); | |
780 | ||
a57d600f | 781 | // Called from wxComboCtrlBase::OnPopupDismiss |
a340b80d VZ |
782 | void OnPopupDismiss() |
783 | { | |
784 | m_beenInside = false; | |
4794626d | 785 | m_blockEventsToPopup = true; |
a340b80d VZ |
786 | } |
787 | ||
788 | protected: | |
a57d600f | 789 | wxComboCtrlBase* m_combo; |
a340b80d | 790 | |
4794626d JS |
791 | bool m_beenInside; |
792 | bool m_blockEventsToPopup; | |
a340b80d VZ |
793 | |
794 | private: | |
795 | DECLARE_EVENT_TABLE() | |
796 | }; | |
797 | ||
798 | ||
06315578 JS |
799 | BEGIN_EVENT_TABLE(wxComboPopupEvtHandler, wxEvtHandler) |
800 | EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent) | |
a340b80d VZ |
801 | END_EVENT_TABLE() |
802 | ||
803 | ||
06315578 | 804 | void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent& event ) |
a340b80d VZ |
805 | { |
806 | wxPoint pt = event.GetPosition(); | |
6d0ce565 | 807 | wxSize sz = m_combo->GetPopupControl()->GetControl()->GetClientSize(); |
a340b80d VZ |
808 | int evtType = event.GetEventType(); |
809 | bool isInside = pt.x >= 0 && pt.y >= 0 && pt.x < sz.x && pt.y < sz.y; | |
c905c0d6 VZ |
810 | bool relayToButton = false; |
811 | ||
812 | event.Skip(); | |
a340b80d | 813 | |
4794626d | 814 | if ( !isInside || !m_combo->IsPopupShown() ) |
a340b80d | 815 | { |
4794626d JS |
816 | // Mouse is outside the popup or popup is not actually shown (yet) |
817 | ||
818 | if ( evtType == wxEVT_MOTION || | |
819 | evtType == wxEVT_LEFT_DOWN || | |
820 | evtType == wxEVT_LEFT_UP || | |
821 | evtType == wxEVT_RIGHT_DOWN ) | |
a340b80d | 822 | { |
4794626d | 823 | // Block motion and click events outside the popup |
974a12f8 | 824 | event.Skip(false); |
a340b80d | 825 | } |
4794626d JS |
826 | } |
827 | else | |
828 | { | |
829 | // Mouse is inside the popup, which is fully shown | |
830 | ||
831 | m_beenInside = true; | |
832 | ||
833 | // Do not let the popup control respond to mouse events until | |
834 | // mouse press used to display the popup has been lifted. This | |
835 | // is important for users with slower mouse fingers or mouse | |
836 | // drivers. Note that we have some redundancy here, just in | |
837 | // case the popup is some native control that does not emit all | |
838 | // mouse event types. | |
839 | if ( evtType == wxEVT_MOTION ) | |
a340b80d | 840 | { |
4794626d | 841 | if ( m_blockEventsToPopup ) |
a340b80d | 842 | { |
4794626d JS |
843 | if ( event.LeftIsDown() ) |
844 | event.Skip(false); | |
845 | else | |
846 | m_blockEventsToPopup = false; | |
a340b80d | 847 | } |
4794626d JS |
848 | } |
849 | else if ( evtType == wxEVT_LEFT_DOWN ) | |
850 | { | |
851 | if ( m_blockEventsToPopup ) | |
852 | m_blockEventsToPopup = false; | |
853 | } | |
854 | else if ( evtType == wxEVT_LEFT_UP ) | |
855 | { | |
856 | if ( m_blockEventsToPopup ) | |
a340b80d | 857 | { |
4794626d JS |
858 | // On first left up, stop blocking mouse events (but still |
859 | // block this one) | |
860 | m_blockEventsToPopup = false; | |
861 | event.Skip(false); | |
db3d7543 JS |
862 | |
863 | // Also, this button press was (probably) used to display | |
864 | // the popup, so relay it back to the drop-down button | |
865 | // (which supposedly originated it). This is necessary to | |
866 | // refresh it properly. | |
867 | relayToButton = true; | |
a340b80d | 868 | } |
a340b80d | 869 | } |
4794626d JS |
870 | else if ( m_blockEventsToPopup ) |
871 | { | |
872 | event.Skip(false); | |
873 | } | |
874 | } | |
875 | ||
876 | // | |
877 | // Some mouse events to popup that happen outside it, before cursor | |
878 | // has been inside the popup, need to be ignored by it but relayed to | |
879 | // the dropbutton. | |
880 | // | |
881 | if ( evtType == wxEVT_LEFT_UP ) | |
882 | { | |
883 | if ( !m_combo->IsPopupShown() ) | |
884 | { | |
885 | event.Skip(false); | |
886 | relayToButton = true; | |
887 | } | |
888 | else if ( !isInside && !m_beenInside ) | |
889 | { | |
890 | // Popup is shown but the cursor is not inside, nor it has been | |
891 | relayToButton = true; | |
892 | } | |
a340b80d VZ |
893 | } |
894 | ||
c905c0d6 VZ |
895 | if ( relayToButton ) |
896 | { | |
c905c0d6 VZ |
897 | wxWindow* btn = m_combo->GetButton(); |
898 | if ( btn ) | |
db3d7543 JS |
899 | btn->GetEventHandler()->ProcessEvent(event); |
900 | else | |
901 | // Bypass the event handling mechanism. Using it would be | |
902 | // confusing for the platform-specific wxComboCtrl | |
903 | // implementations. | |
904 | m_combo->HandleButtonMouseEvent(event, 0); | |
c905c0d6 | 905 | } |
a340b80d VZ |
906 | } |
907 | ||
c905c0d6 VZ |
908 | // ---------------------------------------------------------------------------- |
909 | // wxComboCtrlTextCtrl | |
910 | // ---------------------------------------------------------------------------- | |
911 | ||
912 | class wxComboCtrlTextCtrl : public wxTextCtrl | |
913 | { | |
914 | public: | |
915 | wxComboCtrlTextCtrl() : wxTextCtrl() { } | |
916 | virtual ~wxComboCtrlTextCtrl() { } | |
917 | ||
918 | virtual wxWindow *GetMainWindowOfCompositeControl() | |
919 | { | |
920 | wxComboCtrl* combo = (wxComboCtrl*) GetParent(); | |
921 | ||
922 | // Returning this instead of just 'parent' lets FindFocus work | |
923 | // correctly even when parent control is a child of a composite | |
924 | // generic control (as is case with wxGenericDatePickerCtrl). | |
925 | return combo->GetMainWindowOfCompositeControl(); | |
926 | } | |
927 | }; | |
928 | ||
a340b80d | 929 | // ---------------------------------------------------------------------------- |
a57d600f | 930 | // wxComboCtrlBase |
a340b80d VZ |
931 | // ---------------------------------------------------------------------------- |
932 | ||
933 | ||
a57d600f VZ |
934 | BEGIN_EVENT_TABLE(wxComboCtrlBase, wxControl) |
935 | EVT_TEXT(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent) | |
936 | EVT_SIZE(wxComboCtrlBase::OnSizeEvent) | |
937 | EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent) | |
938 | EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent) | |
2dfa37d6 | 939 | EVT_IDLE(wxComboCtrlBase::OnIdleEvent) |
a57d600f | 940 | //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent) |
b445b6a7 | 941 | EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent) |
c765e6fb | 942 | EVT_CHAR(wxComboCtrlBase::OnCharEvent) |
a57d600f VZ |
943 | EVT_TEXT_ENTER(wxID_ANY,wxComboCtrlBase::OnTextCtrlEvent) |
944 | EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged) | |
a340b80d VZ |
945 | END_EVENT_TABLE() |
946 | ||
947 | ||
a57d600f | 948 | IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl) |
a340b80d | 949 | |
a57d600f | 950 | void wxComboCtrlBase::Init() |
a340b80d | 951 | { |
d3b9f782 VZ |
952 | m_winPopup = NULL; |
953 | m_popup = NULL; | |
974a12f8 | 954 | m_popupWinState = Hidden; |
d3b9f782 VZ |
955 | m_btn = NULL; |
956 | m_text = NULL; | |
957 | m_popupInterface = NULL; | |
a340b80d | 958 | |
06315578 | 959 | m_popupEvtHandler = NULL; |
d3b9f782 | 960 | m_textEvtHandler = NULL; |
a340b80d VZ |
961 | |
962 | #if INSTALL_TOPLEV_HANDLER | |
d3b9f782 | 963 | m_toplevEvtHandler = NULL; |
a340b80d VZ |
964 | #endif |
965 | ||
4427c0a3 RR |
966 | m_mainCtrlWnd = this; |
967 | ||
a340b80d VZ |
968 | m_heightPopup = -1; |
969 | m_widthMinPopup = -1; | |
970 | m_anchorSide = 0; | |
971 | m_widthCustomPaint = 0; | |
972 | m_widthCustomBorder = 0; | |
973 | ||
974 | m_btnState = 0; | |
975 | m_btnWidDefault = 0; | |
976 | m_blankButtonBg = false; | |
ce968519 | 977 | m_ignoreEvtText = 0; |
06077aaf | 978 | m_popupWinType = POPUPWIN_NONE; |
7dc234d6 | 979 | m_btnWid = m_btnHei = -1; |
a340b80d VZ |
980 | m_btnSide = wxRIGHT; |
981 | m_btnSpacingX = 0; | |
982 | ||
983 | m_extLeft = 0; | |
984 | m_extRight = 0; | |
0847e36e | 985 | m_marginLeft = -1; |
a340b80d | 986 | m_iFlags = 0; |
1ac5cfc7 | 987 | m_textCtrlStyle = 0; |
a340b80d | 988 | m_timeCanAcceptClick = 0; |
2dfa37d6 RD |
989 | |
990 | m_resetFocus = false; | |
bed867e3 | 991 | m_hasTcBgCol = false; |
a340b80d VZ |
992 | } |
993 | ||
a57d600f | 994 | bool wxComboCtrlBase::Create(wxWindow *parent, |
b61f4f77 WS |
995 | wxWindowID id, |
996 | const wxString& value, | |
997 | const wxPoint& pos, | |
998 | const wxSize& size, | |
999 | long style, | |
1000 | const wxValidator& validator, | |
1001 | const wxString& name) | |
a340b80d VZ |
1002 | { |
1003 | if ( !wxControl::Create(parent, | |
1004 | id, | |
1005 | pos, | |
1006 | size, | |
1007 | style | wxWANTS_CHARS, | |
1008 | validator, | |
1009 | name) ) | |
1010 | return false; | |
1011 | ||
1012 | m_valueString = value; | |
1013 | ||
1014 | // Get colours | |
1015 | OnThemeChange(); | |
0847e36e | 1016 | m_marginLeft = GetNativeTextIndent(); |
a340b80d | 1017 | |
a9e8bf2d WS |
1018 | m_iFlags |= wxCC_IFLAG_CREATED; |
1019 | ||
1020 | // If x and y indicate valid size, wxSizeEvent won't be | |
1021 | // emitted automatically, so we need to add artifical one. | |
1022 | if ( size.x > 0 && size.y > 0 ) | |
1023 | { | |
1024 | wxSizeEvent evt(size,GetId()); | |
1025 | GetEventHandler()->AddPendingEvent(evt); | |
1026 | } | |
1027 | ||
a340b80d VZ |
1028 | return true; |
1029 | } | |
1030 | ||
b445b6a7 | 1031 | void wxComboCtrlBase::InstallInputHandlers() |
a340b80d | 1032 | { |
b445b6a7 | 1033 | if ( m_text ) |
a340b80d VZ |
1034 | { |
1035 | m_textEvtHandler = new wxComboBoxExtraInputHandler(this); | |
1036 | m_text->PushEventHandler(m_textEvtHandler); | |
1037 | } | |
a340b80d VZ |
1038 | } |
1039 | ||
42a3ecf5 | 1040 | void |
fda62793 | 1041 | wxComboCtrlBase::CreateTextCtrl(int style) |
a340b80d VZ |
1042 | { |
1043 | if ( !(m_windowStyle & wxCB_READONLY) ) | |
1044 | { | |
8e9ec723 RR |
1045 | if ( m_text ) |
1046 | m_text->Destroy(); | |
1047 | ||
42a3ecf5 VZ |
1048 | // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is |
1049 | // not used by the wxPropertyGrid and therefore the tab is processed by | |
1050 | // looking at ancestors to see if they have wxTAB_TRAVERSAL. The | |
1051 | // navigation event is then sent to the wrong window. | |
1ac5cfc7 | 1052 | style |= wxTE_PROCESS_TAB | m_textCtrlStyle; |
42a3ecf5 | 1053 | |
5d95cab8 | 1054 | if ( HasFlag(wxTE_PROCESS_ENTER) ) |
42a3ecf5 VZ |
1055 | style |= wxTE_PROCESS_ENTER; |
1056 | ||
ce968519 RR |
1057 | // Ignore EVT_TEXT generated by the constructor (but only |
1058 | // if the event redirector already exists) | |
1059 | // NB: This must be " = 1" instead of "++"; | |
1060 | if ( m_textEvtHandler ) | |
1061 | m_ignoreEvtText = 1; | |
1062 | else | |
1063 | m_ignoreEvtText = 0; | |
1064 | ||
c905c0d6 VZ |
1065 | m_text = new wxComboCtrlTextCtrl(); |
1066 | m_text->Create(this, wxID_ANY, m_valueString, | |
1067 | wxDefaultPosition, wxSize(10,-1), | |
fda62793 | 1068 | style); |
107defe3 | 1069 | m_text->SetHint(m_hintText); |
a340b80d VZ |
1070 | } |
1071 | } | |
1072 | ||
a57d600f | 1073 | void wxComboCtrlBase::OnThemeChange() |
a340b80d | 1074 | { |
10ba2677 JS |
1075 | // Because wxComboCtrl has transparent parts on most platforms, we |
1076 | // don't want to touch the actual background colour. Instead, we just | |
1077 | // usually re-obtain m_tcBgCol here. | |
1078 | ||
1079 | #if defined(__WXMSW__) || defined(__WXGTK__) | |
2ec335db | 1080 | wxVisualAttributes vattrs = wxComboBox::GetClassDefaultAttributes(); |
10ba2677 | 1081 | #else |
2ec335db JS |
1082 | wxVisualAttributes vattrs; |
1083 | vattrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
1084 | vattrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
10ba2677 JS |
1085 | #endif |
1086 | ||
bed867e3 | 1087 | if ( !m_hasTcBgCol ) |
10ba2677 | 1088 | m_tcBgCol = vattrs.colBg; |
2ec335db | 1089 | |
10ba2677 | 1090 | #ifndef __WXMAC__ |
2ec335db JS |
1091 | // Only change the colours if application has not specified |
1092 | // custom ones. | |
1093 | if ( !m_hasFgCol ) | |
1094 | { | |
1095 | SetOwnForegroundColour(vattrs.colFg); | |
2ec335db | 1096 | } |
10ba2677 | 1097 | if ( !HasTransparentBackground() ) |
3b9ba64c | 1098 | { |
10ba2677 | 1099 | SetOwnBackgroundColour(GetParent()->GetBackgroundColour()); |
3b9ba64c | 1100 | } |
2ec335db | 1101 | #endif // !__WXMAC__ |
a340b80d VZ |
1102 | } |
1103 | ||
a57d600f | 1104 | wxComboCtrlBase::~wxComboCtrlBase() |
a340b80d VZ |
1105 | { |
1106 | if ( HasCapture() ) | |
1107 | ReleaseMouse(); | |
1108 | ||
a340b80d VZ |
1109 | #if INSTALL_TOPLEV_HANDLER |
1110 | delete ((wxComboFrameEventHandler*)m_toplevEvtHandler); | |
d3b9f782 | 1111 | m_toplevEvtHandler = NULL; |
a340b80d VZ |
1112 | #endif |
1113 | ||
7ca4ac63 | 1114 | DestroyPopup(); |
a340b80d | 1115 | |
a340b80d VZ |
1116 | if ( m_text ) |
1117 | m_text->RemoveEventHandler(m_textEvtHandler); | |
1118 | ||
1119 | delete m_textEvtHandler; | |
a340b80d VZ |
1120 | } |
1121 | ||
1122 | ||
1123 | // ---------------------------------------------------------------------------- | |
1124 | // geometry stuff | |
1125 | // ---------------------------------------------------------------------------- | |
1126 | ||
1127 | // Recalculates button and textctrl areas | |
a57d600f | 1128 | void wxComboCtrlBase::CalculateAreas( int btnWidth ) |
a340b80d VZ |
1129 | { |
1130 | wxSize sz = GetClientSize(); | |
1131 | int customBorder = m_widthCustomBorder; | |
a340b80d VZ |
1132 | int btnBorder; // border for button only |
1133 | ||
87419e97 VZ |
1134 | // check if button should really be outside the border: we'll do it it if |
1135 | // its platform default or bitmap+pushbutton background is used, but not if | |
1136 | // there is vertical size adjustment or horizontal spacing. | |
1137 | if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) || | |
1138 | (m_bmpNormal.Ok() && m_blankButtonBg) ) && | |
1139 | m_btnSpacingX == 0 && | |
7dc234d6 | 1140 | m_btnHei <= 0 ) |
a340b80d | 1141 | { |
a340b80d VZ |
1142 | m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE; |
1143 | btnBorder = 0; | |
1144 | } | |
c905c0d6 VZ |
1145 | else if ( (m_iFlags & wxCC_BUTTON_COVERS_BORDER) && |
1146 | m_btnSpacingX == 0 && !m_bmpNormal.Ok() ) | |
1147 | { | |
1148 | m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE); | |
1149 | btnBorder = 0; | |
1150 | } | |
a340b80d VZ |
1151 | else |
1152 | { | |
a340b80d VZ |
1153 | m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE); |
1154 | btnBorder = customBorder; | |
1155 | } | |
1156 | ||
1157 | // Defaul indentation | |
0847e36e JS |
1158 | if ( m_marginLeft < 0 ) |
1159 | m_marginLeft = GetNativeTextIndent(); | |
a340b80d VZ |
1160 | |
1161 | int butWidth = btnWidth; | |
1162 | ||
1163 | if ( butWidth <= 0 ) | |
1164 | butWidth = m_btnWidDefault; | |
1165 | else | |
1166 | m_btnWidDefault = butWidth; | |
1167 | ||
1168 | if ( butWidth <= 0 ) | |
1169 | return; | |
1170 | ||
a9e8bf2d WS |
1171 | int butHeight = sz.y - btnBorder*2; |
1172 | ||
a340b80d | 1173 | // Adjust button width |
7dc234d6 | 1174 | if ( m_btnWid > 0 ) |
a340b80d | 1175 | butWidth = m_btnWid; |
a9e8bf2d WS |
1176 | else |
1177 | { | |
1178 | // Adjust button width to match aspect ratio | |
1179 | // (but only if control is smaller than best size). | |
1180 | int bestHeight = GetBestSize().y; | |
1181 | int height = GetSize().y; | |
a340b80d | 1182 | |
a9e8bf2d WS |
1183 | if ( height < bestHeight ) |
1184 | { | |
1185 | // Make very small buttons square, as it makes | |
1186 | // them accommodate arrow image better and still | |
1187 | // looks decent. | |
1188 | if ( height > 18 ) | |
1189 | butWidth = (height*butWidth)/bestHeight; | |
1190 | else | |
1191 | butWidth = butHeight; | |
1192 | } | |
1193 | } | |
a340b80d VZ |
1194 | |
1195 | // Adjust button height | |
7dc234d6 | 1196 | if ( m_btnHei > 0 ) |
a340b80d VZ |
1197 | butHeight = m_btnHei; |
1198 | ||
1199 | // Use size of normal bitmap if... | |
1200 | // It is larger | |
1201 | // OR | |
1202 | // button width is set to default and blank button bg is not drawn | |
1203 | if ( m_bmpNormal.Ok() ) | |
1204 | { | |
1205 | int bmpReqWidth = m_bmpNormal.GetWidth(); | |
1206 | int bmpReqHeight = m_bmpNormal.GetHeight(); | |
1207 | ||
1208 | // If drawing blank button background, we need to add some margin. | |
1209 | if ( m_blankButtonBg ) | |
1210 | { | |
1211 | bmpReqWidth += BMP_BUTTON_MARGIN*2; | |
1212 | bmpReqHeight += BMP_BUTTON_MARGIN*2; | |
1213 | } | |
1214 | ||
1215 | if ( butWidth < bmpReqWidth || ( m_btnWid == 0 && !m_blankButtonBg ) ) | |
1216 | butWidth = bmpReqWidth; | |
1217 | if ( butHeight < bmpReqHeight || ( m_btnHei == 0 && !m_blankButtonBg ) ) | |
1218 | butHeight = bmpReqHeight; | |
1219 | ||
1220 | // Need to fix height? | |
1221 | if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 ) | |
1222 | { | |
1223 | int newY = butHeight+(customBorder*2); | |
a5bbd1cc | 1224 | SetClientSize(wxDefaultCoord,newY); |
640a91ab PC |
1225 | if ( m_bmpNormal.Ok() || m_btnArea.width != butWidth || m_btnArea.height != butHeight ) |
1226 | m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON; | |
1227 | else | |
1228 | m_iFlags &= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON; | |
c905c0d6 | 1229 | |
a340b80d VZ |
1230 | sz.y = newY; |
1231 | } | |
1232 | } | |
1233 | ||
1234 | int butAreaWid = butWidth + (m_btnSpacingX*2); | |
1235 | ||
1236 | m_btnSize.x = butWidth; | |
1237 | m_btnSize.y = butHeight; | |
1238 | ||
1239 | m_btnArea.x = ( m_btnSide==wxRIGHT ? sz.x - butAreaWid - btnBorder : btnBorder ); | |
2dfa37d6 | 1240 | m_btnArea.y = btnBorder + FOCUS_RING; |
a340b80d | 1241 | m_btnArea.width = butAreaWid; |
2dfa37d6 | 1242 | m_btnArea.height = sz.y - ((btnBorder+FOCUS_RING)*2); |
a340b80d | 1243 | |
2dfa37d6 RD |
1244 | m_tcArea.x = ( m_btnSide==wxRIGHT ? 0 : butAreaWid ) + customBorder + FOCUS_RING; |
1245 | m_tcArea.y = customBorder + FOCUS_RING; | |
1246 | m_tcArea.width = sz.x - butAreaWid - (customBorder*2) - (FOCUS_RING*2); | |
1247 | m_tcArea.height = sz.y - ((customBorder+FOCUS_RING)*2); | |
a340b80d VZ |
1248 | |
1249 | /* | |
1250 | if ( m_text ) | |
1251 | { | |
1252 | ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) + | |
1253 | wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height)); | |
1254 | } | |
1255 | */ | |
1256 | } | |
1257 | ||
a57d600f | 1258 | void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust ) |
a340b80d VZ |
1259 | { |
1260 | if ( !m_text ) | |
1261 | return; | |
1262 | ||
1263 | wxSize sz = GetClientSize(); | |
a340b80d | 1264 | |
f85f5ddf | 1265 | int customBorder = m_widthCustomBorder; |
a340b80d VZ |
1266 | if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER ) |
1267 | { | |
4bcf25e9 JS |
1268 | int x; |
1269 | ||
1270 | if ( !m_widthCustomPaint ) | |
1271 | { | |
1272 | // No special custom paint area - we can use 0 left margin | |
1273 | // with wxTextCtrl. | |
1274 | if ( m_text->SetMargins(0) ) | |
1275 | textCtrlXAdjust = 0; | |
1276 | x = m_tcArea.x + m_marginLeft + textCtrlXAdjust; | |
1277 | } | |
1278 | else | |
1279 | { | |
1280 | // There is special custom paint area - it is better to | |
1281 | // use some margin with the wxTextCtrl. | |
1282 | m_text->SetMargins(m_marginLeft); | |
ce00f59b | 1283 | x = m_tcArea.x + m_widthCustomPaint + |
4bcf25e9 JS |
1284 | m_marginLeft + textCtrlXAdjust; |
1285 | } | |
0847e36e | 1286 | |
4bcf25e9 | 1287 | // Centre textctrl vertically, if needed |
0847e36e | 1288 | #if !TEXTCTRL_TEXT_CENTERED |
a340b80d | 1289 | int tcSizeY = m_text->GetBestSize().y; |
0847e36e JS |
1290 | int diff0 = sz.y - tcSizeY; |
1291 | int y = textCtrlYAdjust + (diff0/2); | |
1292 | #else | |
1293 | wxUnusedVar(textCtrlYAdjust); | |
1294 | int y = 0; | |
1295 | #endif | |
a340b80d VZ |
1296 | |
1297 | if ( y < customBorder ) | |
1298 | y = customBorder; | |
1299 | ||
0847e36e JS |
1300 | m_text->SetSize(x, |
1301 | y, | |
1302 | m_tcArea.width - m_tcArea.x - x, | |
0847e36e | 1303 | -1 ); |
a340b80d VZ |
1304 | |
1305 | // Make sure textctrl doesn't exceed the bottom custom border | |
1306 | wxSize tsz = m_text->GetSize(); | |
0847e36e JS |
1307 | int diff1 = (y + tsz.y) - (sz.y - customBorder); |
1308 | if ( diff1 >= 0 ) | |
a340b80d | 1309 | { |
0847e36e | 1310 | tsz.y = tsz.y - diff1 - 1; |
a340b80d VZ |
1311 | m_text->SetSize(tsz); |
1312 | } | |
1313 | } | |
1314 | else | |
1315 | { | |
0847e36e | 1316 | // If it has border, have textctrl fill the entire text field. |
7e4545b8 | 1317 | m_text->SetSize( m_tcArea.x + m_widthCustomPaint, |
2dfa37d6 RD |
1318 | m_tcArea.y, |
1319 | m_tcArea.width - m_widthCustomPaint, | |
1320 | m_tcArea.height ); | |
a340b80d VZ |
1321 | } |
1322 | } | |
1323 | ||
a57d600f | 1324 | wxSize wxComboCtrlBase::DoGetBestSize() const |
a340b80d VZ |
1325 | { |
1326 | wxSize sizeText(150,0); | |
1327 | ||
1328 | if ( m_text ) | |
1329 | sizeText = m_text->GetBestSize(); | |
1330 | ||
1331 | // TODO: Better method to calculate close-to-native control height. | |
1332 | ||
1333 | int fhei; | |
1334 | if ( m_font.Ok() ) | |
1335 | fhei = (m_font.GetPointSize()*2) + 5; | |
1336 | else if ( wxNORMAL_FONT->Ok() ) | |
1337 | fhei = (wxNORMAL_FONT->GetPointSize()*2) + 5; | |
1338 | else | |
1339 | fhei = sizeText.y + 4; | |
1340 | ||
1341 | // Need to force height to accomodate bitmap? | |
1342 | int btnSizeY = m_btnSize.y; | |
1343 | if ( m_bmpNormal.Ok() && fhei < btnSizeY ) | |
1344 | fhei = btnSizeY; | |
1345 | ||
1346 | // Control height doesn't depend on border | |
1347 | /* | |
1348 | // Add border | |
1349 | int border = m_windowStyle & wxBORDER_MASK; | |
1350 | if ( border == wxSIMPLE_BORDER ) | |
1351 | fhei += 2; | |
1352 | else if ( border == wxNO_BORDER ) | |
1353 | fhei += (m_widthCustomBorder*2); | |
1354 | else | |
1355 | // Sunken etc. | |
1356 | fhei += 4; | |
1357 | */ | |
1358 | ||
1359 | // Final adjustments | |
1360 | #ifdef __WXGTK__ | |
1361 | fhei += 1; | |
1362 | #endif | |
1363 | ||
c66ed668 RD |
1364 | #ifdef __WXMAC__ |
1365 | // these are the numbers from the HIG: | |
1366 | switch ( m_windowVariant ) | |
1367 | { | |
1368 | case wxWINDOW_VARIANT_NORMAL: | |
1369 | default : | |
1370 | fhei = 22; | |
1371 | break; | |
1372 | case wxWINDOW_VARIANT_SMALL: | |
1373 | fhei = 19; | |
1374 | break; | |
1375 | case wxWINDOW_VARIANT_MINI: | |
1376 | fhei = 15; | |
1377 | break; | |
1378 | } | |
1379 | #endif | |
a340b80d | 1380 | |
2dfa37d6 RD |
1381 | fhei += 2 * FOCUS_RING; |
1382 | int width = sizeText.x + FOCUS_RING + COMBO_MARGIN + DEFAULT_DROPBUTTON_WIDTH; | |
1383 | ||
1384 | wxSize ret(width, fhei); | |
a340b80d VZ |
1385 | CacheBestSize(ret); |
1386 | return ret; | |
1387 | } | |
1388 | ||
a57d600f | 1389 | void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event ) |
a340b80d VZ |
1390 | { |
1391 | if ( !IsCreated() ) | |
1392 | return; | |
1393 | ||
a57d600f | 1394 | // defined by actual wxComboCtrls |
a340b80d VZ |
1395 | OnResize(); |
1396 | ||
1397 | event.Skip(); | |
1398 | } | |
1399 | ||
1400 | // ---------------------------------------------------------------------------- | |
1401 | // standard operations | |
1402 | // ---------------------------------------------------------------------------- | |
1403 | ||
a57d600f | 1404 | bool wxComboCtrlBase::Enable(bool enable) |
a340b80d VZ |
1405 | { |
1406 | if ( !wxControl::Enable(enable) ) | |
1407 | return false; | |
1408 | ||
1409 | if ( m_btn ) | |
1410 | m_btn->Enable(enable); | |
1411 | if ( m_text ) | |
1412 | m_text->Enable(enable); | |
004867db | 1413 | |
4df230b8 | 1414 | Refresh(); |
a340b80d VZ |
1415 | |
1416 | return true; | |
1417 | } | |
1418 | ||
a57d600f | 1419 | bool wxComboCtrlBase::Show(bool show) |
a340b80d VZ |
1420 | { |
1421 | if ( !wxControl::Show(show) ) | |
1422 | return false; | |
1423 | ||
1424 | if (m_btn) | |
1425 | m_btn->Show(show); | |
1426 | ||
1427 | if (m_text) | |
1428 | m_text->Show(show); | |
1429 | ||
1430 | return true; | |
1431 | } | |
1432 | ||
a57d600f | 1433 | bool wxComboCtrlBase::SetFont ( const wxFont& font ) |
a340b80d VZ |
1434 | { |
1435 | if ( !wxControl::SetFont(font) ) | |
1436 | return false; | |
1437 | ||
4bcf25e9 JS |
1438 | if ( m_text ) |
1439 | { | |
1440 | // Without hiding the wxTextCtrl there would be some | |
1441 | // visible 'flicker' (at least on Windows XP). | |
1442 | m_text->Hide(); | |
a340b80d | 1443 | m_text->SetFont(font); |
4bcf25e9 JS |
1444 | OnResize(); |
1445 | m_text->Show(); | |
1446 | } | |
a340b80d VZ |
1447 | |
1448 | return true; | |
1449 | } | |
1450 | ||
1451 | #if wxUSE_TOOLTIPS | |
a57d600f | 1452 | void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip) |
a340b80d VZ |
1453 | { |
1454 | wxControl::DoSetToolTip(tooltip); | |
1455 | ||
1456 | // Set tool tip for button and text box | |
1457 | if ( tooltip ) | |
1458 | { | |
1459 | const wxString &tip = tooltip->GetTip(); | |
1460 | if ( m_text ) m_text->SetToolTip(tip); | |
1461 | if ( m_btn ) m_btn->SetToolTip(tip); | |
1462 | } | |
1463 | else | |
1464 | { | |
d3b9f782 VZ |
1465 | if ( m_text ) m_text->SetToolTip( NULL ); |
1466 | if ( m_btn ) m_btn->SetToolTip( NULL ); | |
a340b80d VZ |
1467 | } |
1468 | } | |
1469 | #endif // wxUSE_TOOLTIPS | |
1470 | ||
5f540750 JS |
1471 | bool wxComboCtrlBase::SetForegroundColour(const wxColour& colour) |
1472 | { | |
1473 | if ( wxControl::SetForegroundColour(colour) ) | |
1474 | { | |
1475 | if ( m_text ) | |
1476 | m_text->SetForegroundColour(colour); | |
1477 | return true; | |
1478 | } | |
1479 | return false; | |
1480 | } | |
1481 | ||
1482 | bool wxComboCtrlBase::SetBackgroundColour(const wxColour& colour) | |
1483 | { | |
10ba2677 JS |
1484 | if ( m_text ) |
1485 | m_text->SetBackgroundColour(colour); | |
1486 | m_tcBgCol = colour; | |
bed867e3 | 1487 | m_hasTcBgCol = true; |
10ba2677 | 1488 | return true; |
5f540750 | 1489 | } |
10ba2677 JS |
1490 | |
1491 | wxColour wxComboCtrlBase::GetBackgroundColour() const | |
1492 | { | |
1493 | if ( m_text ) | |
1494 | return m_text->GetBackgroundColour(); | |
1495 | return m_tcBgCol; | |
1496 | } | |
1497 | ||
a340b80d VZ |
1498 | // ---------------------------------------------------------------------------- |
1499 | // painting | |
1500 | // ---------------------------------------------------------------------------- | |
1501 | ||
118f5fbd RR |
1502 | #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__) |
1503 | // prepare combo box background on area in a way typical on platform | |
1504 | void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const | |
a340b80d VZ |
1505 | { |
1506 | wxSize sz = GetClientSize(); | |
1507 | bool isEnabled; | |
c905c0d6 | 1508 | bool doDrawFocusRect; // also selected |
a340b80d VZ |
1509 | |
1510 | // For smaller size control (and for disabled background) use less spacing | |
1511 | int focusSpacingX; | |
1512 | int focusSpacingY; | |
1513 | ||
1514 | if ( !(flags & wxCONTROL_ISSUBMENU) ) | |
1515 | { | |
1516 | // Drawing control | |
1517 | isEnabled = IsEnabled(); | |
640a91ab | 1518 | doDrawFocusRect = ShouldDrawFocus() && !(m_iFlags & wxCC_FULL_BUTTON); |
a340b80d VZ |
1519 | |
1520 | // Windows-style: for smaller size control (and for disabled background) use less spacing | |
1521 | focusSpacingX = isEnabled ? 2 : 1; | |
1522 | focusSpacingY = sz.y > (GetCharHeight()+2) && isEnabled ? 2 : 1; | |
1523 | } | |
1524 | else | |
1525 | { | |
1526 | // Drawing a list item | |
1527 | isEnabled = true; // they are never disabled | |
640a91ab | 1528 | doDrawFocusRect = (flags & wxCONTROL_SELECTED) != 0; |
a340b80d VZ |
1529 | |
1530 | focusSpacingX = 0; | |
1531 | focusSpacingY = 0; | |
1532 | } | |
1533 | ||
1534 | // Set the background sub-rectangle for selection, disabled etc | |
1535 | wxRect selRect(rect); | |
1536 | selRect.y += focusSpacingY; | |
1537 | selRect.height -= (focusSpacingY*2); | |
8e5ec129 WS |
1538 | |
1539 | int wcp = 0; | |
1540 | ||
1541 | if ( !(flags & wxCONTROL_ISSUBMENU) ) | |
1542 | wcp += m_widthCustomPaint; | |
1543 | ||
1544 | selRect.x += wcp + focusSpacingX; | |
1545 | selRect.width -= wcp + (focusSpacingX*2); | |
a340b80d VZ |
1546 | |
1547 | wxColour bgCol; | |
3b9ba64c JS |
1548 | wxColour fgCol; |
1549 | ||
c905c0d6 | 1550 | bool doDrawSelRect = true; |
a340b80d | 1551 | |
3b9ba64c JS |
1552 | // Determine foreground colour |
1553 | if ( isEnabled ) | |
1554 | { | |
1555 | if ( doDrawFocusRect ) | |
1556 | { | |
1557 | fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
1558 | } | |
1559 | else if ( m_hasFgCol ) | |
1560 | { | |
1561 | // Honour the custom foreground colour | |
1562 | fgCol = GetForegroundColour(); | |
1563 | } | |
1564 | else | |
1565 | { | |
1566 | fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
1567 | } | |
1568 | } | |
1569 | else | |
1570 | { | |
1571 | fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); | |
1572 | } | |
1573 | ||
1574 | // Determine background colour | |
a340b80d VZ |
1575 | if ( isEnabled ) |
1576 | { | |
c905c0d6 | 1577 | if ( doDrawFocusRect ) |
a340b80d | 1578 | { |
a340b80d VZ |
1579 | bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); |
1580 | } | |
bed867e3 | 1581 | else if ( m_hasTcBgCol ) |
3b9ba64c JS |
1582 | { |
1583 | // Honour the custom background colour | |
bed867e3 | 1584 | bgCol = m_tcBgCol; |
3b9ba64c | 1585 | } |
a340b80d VZ |
1586 | else |
1587 | { | |
2dfa37d6 | 1588 | #ifndef __WXMAC__ // see note in OnThemeChange |
c905c0d6 | 1589 | doDrawSelRect = false; |
a340b80d | 1590 | bgCol = GetBackgroundColour(); |
2dfa37d6 RD |
1591 | #else |
1592 | bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
1593 | #endif | |
a340b80d VZ |
1594 | } |
1595 | } | |
1596 | else | |
1597 | { | |
2dfa37d6 | 1598 | #ifndef __WXMAC__ // see note in OnThemeChange |
a340b80d | 1599 | bgCol = GetBackgroundColour(); |
2dfa37d6 RD |
1600 | #else |
1601 | bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
1602 | #endif | |
a340b80d VZ |
1603 | } |
1604 | ||
3b9ba64c | 1605 | dc.SetTextForeground( fgCol ); |
a340b80d | 1606 | dc.SetBrush( bgCol ); |
c905c0d6 VZ |
1607 | if ( doDrawSelRect ) |
1608 | { | |
1609 | dc.SetPen( bgCol ); | |
1610 | dc.DrawRectangle( selRect ); | |
1611 | } | |
118f5fbd RR |
1612 | |
1613 | // Don't clip exactly to the selection rectangle so we can draw | |
1614 | // to the non-selected area in front of it. | |
1615 | wxRect clipRect(rect.x,rect.y, | |
1616 | (selRect.x+selRect.width)-rect.x,rect.height); | |
1617 | dc.SetClippingRegion(clipRect); | |
a340b80d | 1618 | } |
118f5fbd RR |
1619 | #else |
1620 | // Save the library size a bit for platforms that re-implement this. | |
1621 | void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const | |
1622 | { | |
1623 | } | |
1624 | #endif | |
a340b80d | 1625 | |
c905c0d6 | 1626 | void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, int flags ) |
a340b80d VZ |
1627 | { |
1628 | int drawState = m_btnState; | |
1629 | ||
c905c0d6 VZ |
1630 | if ( (m_iFlags & wxCC_BUTTON_STAYS_DOWN) && |
1631 | GetPopupWindowState() >= Animating ) | |
a340b80d | 1632 | drawState |= wxCONTROL_PRESSED; |
a340b80d VZ |
1633 | |
1634 | wxRect drawRect(rect.x+m_btnSpacingX, | |
1635 | rect.y+((rect.height-m_btnSize.y)/2), | |
1636 | m_btnSize.x, | |
1637 | m_btnSize.y); | |
1638 | ||
1639 | // Make sure area is not larger than the control | |
1640 | if ( drawRect.y < rect.y ) | |
1641 | drawRect.y = rect.y; | |
1642 | if ( drawRect.height > rect.height ) | |
1643 | drawRect.height = rect.height; | |
1644 | ||
1645 | bool enabled = IsEnabled(); | |
1646 | ||
1647 | if ( !enabled ) | |
1648 | drawState |= wxCONTROL_DISABLED; | |
1649 | ||
1650 | if ( !m_bmpNormal.Ok() ) | |
1651 | { | |
c905c0d6 VZ |
1652 | if ( flags & Button_BitmapOnly ) |
1653 | return; | |
1654 | ||
a340b80d | 1655 | // Need to clear button background even if m_btn is present |
10ba2677 JS |
1656 | if ( (flags & Button_PaintBackground) && |
1657 | (!HasTransparentBackground() || | |
1658 | !(m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE)) ) | |
b61f4f77 WS |
1659 | { |
1660 | wxColour bgCol; | |
1661 | ||
1662 | if ( m_iFlags & wxCC_IFLAG_BUTTON_OUTSIDE ) | |
1663 | bgCol = GetParent()->GetBackgroundColour(); | |
1664 | else | |
1665 | bgCol = GetBackgroundColour(); | |
1666 | ||
1667 | dc.SetBrush(bgCol); | |
1668 | dc.SetPen(bgCol); | |
a340b80d | 1669 | dc.DrawRectangle(rect); |
b61f4f77 | 1670 | } |
a340b80d VZ |
1671 | |
1672 | // Draw standard button | |
1673 | wxRendererNative::Get().DrawComboBoxDropButton(this, | |
1674 | dc, | |
1675 | drawRect, | |
1676 | drawState); | |
1677 | } | |
1678 | else | |
1679 | { | |
1680 | // Draw bitmap | |
1681 | ||
1682 | wxBitmap* pBmp; | |
1683 | ||
1684 | if ( !enabled ) | |
1685 | pBmp = &m_bmpDisabled; | |
1686 | else if ( m_btnState & wxCONTROL_PRESSED ) | |
1687 | pBmp = &m_bmpPressed; | |
1688 | else if ( m_btnState & wxCONTROL_CURRENT ) | |
1689 | pBmp = &m_bmpHover; | |
1690 | else | |
1691 | pBmp = &m_bmpNormal; | |
1692 | ||
1693 | if ( m_blankButtonBg ) | |
1694 | { | |
1695 | // If using blank button background, we need to clear its background | |
1696 | // with button face colour instead of colour for rest of the control. | |
c905c0d6 | 1697 | if ( flags & Button_PaintBackground ) |
a340b80d VZ |
1698 | { |
1699 | wxColour bgCol = GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
1700 | //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
1701 | dc.SetPen(bgCol); | |
1702 | dc.SetBrush(bgCol); | |
1703 | dc.DrawRectangle(rect); | |
1704 | } | |
1705 | ||
c905c0d6 VZ |
1706 | if ( !(flags & Button_BitmapOnly) ) |
1707 | { | |
1708 | wxRendererNative::Get().DrawPushButton(this, | |
1709 | dc, | |
1710 | drawRect, | |
1711 | drawState); | |
1712 | } | |
a340b80d VZ |
1713 | } |
1714 | else | |
1715 | ||
1716 | { | |
1717 | // Need to clear button background even if m_btn is present | |
1718 | // (assume non-button background was cleared just before this call so brushes are good) | |
c905c0d6 | 1719 | if ( flags & Button_PaintBackground ) |
a340b80d VZ |
1720 | dc.DrawRectangle(rect); |
1721 | } | |
1722 | ||
1723 | // Draw bitmap centered in drawRect | |
1724 | dc.DrawBitmap(*pBmp, | |
1725 | drawRect.x + (drawRect.width-pBmp->GetWidth())/2, | |
1726 | drawRect.y + (drawRect.height-pBmp->GetHeight())/2, | |
1727 | true); | |
1728 | } | |
1729 | } | |
1730 | ||
a57d600f | 1731 | void wxComboCtrlBase::RecalcAndRefresh() |
a340b80d VZ |
1732 | { |
1733 | if ( IsCreated() ) | |
1734 | { | |
1735 | wxSizeEvent evt(GetSize(),GetId()); | |
1736 | GetEventHandler()->ProcessEvent(evt); | |
1737 | Refresh(); | |
1738 | } | |
1739 | } | |
1740 | ||
a340b80d VZ |
1741 | // ---------------------------------------------------------------------------- |
1742 | // miscellaneous event handlers | |
1743 | // ---------------------------------------------------------------------------- | |
1744 | ||
a57d600f | 1745 | void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event) |
a340b80d | 1746 | { |
ce968519 RR |
1747 | if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED ) |
1748 | { | |
1749 | if ( m_ignoreEvtText > 0 ) | |
1750 | { | |
1751 | m_ignoreEvtText--; | |
1752 | return; | |
1753 | } | |
1754 | } | |
1755 | ||
98d0cd96 | 1756 | // Change event id, object and string before relaying it forward |
a340b80d | 1757 | event.SetId(GetId()); |
98d0cd96 WS |
1758 | wxString s = event.GetString(); |
1759 | event.SetEventObject(this); | |
1760 | event.SetString(s); | |
a340b80d VZ |
1761 | event.Skip(); |
1762 | } | |
1763 | ||
1764 | // call if cursor is on button area or mouse is captured for the button | |
a57d600f | 1765 | bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event, |
c905c0d6 | 1766 | int flags ) |
a340b80d VZ |
1767 | { |
1768 | int type = event.GetEventType(); | |
1769 | ||
1770 | if ( type == wxEVT_MOTION ) | |
1771 | { | |
c905c0d6 VZ |
1772 | if ( (flags & wxCC_MF_ON_BUTTON) && |
1773 | IsPopupWindowState(Hidden) ) | |
a340b80d VZ |
1774 | { |
1775 | if ( !(m_btnState & wxCONTROL_CURRENT) ) | |
1776 | { | |
1777 | // Mouse hover begins | |
1778 | m_btnState |= wxCONTROL_CURRENT; | |
1779 | if ( HasCapture() ) // Retain pressed state. | |
1780 | m_btnState |= wxCONTROL_PRESSED; | |
1781 | Refresh(); | |
1782 | } | |
1783 | } | |
1784 | else if ( (m_btnState & wxCONTROL_CURRENT) ) | |
1785 | { | |
1786 | // Mouse hover ends | |
1787 | m_btnState &= ~(wxCONTROL_CURRENT|wxCONTROL_PRESSED); | |
1788 | Refresh(); | |
1789 | } | |
1790 | } | |
974a12f8 | 1791 | else if ( type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_DCLICK ) |
a340b80d | 1792 | { |
1efad474 | 1793 | if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) ) |
a340b80d | 1794 | { |
1efad474 RR |
1795 | m_btnState |= wxCONTROL_PRESSED; |
1796 | Refresh(); | |
a340b80d | 1797 | |
1efad474 RR |
1798 | if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) ) |
1799 | OnButtonClick(); | |
1800 | else | |
1801 | // If showing popup now, do not capture mouse or there will be interference | |
1802 | CaptureMouse(); | |
a340b80d | 1803 | } |
a340b80d VZ |
1804 | } |
1805 | else if ( type == wxEVT_LEFT_UP ) | |
1806 | { | |
1807 | ||
1808 | // Only accept event if mouse was left-press was previously accepted | |
1809 | if ( HasCapture() ) | |
1810 | ReleaseMouse(); | |
1811 | ||
1812 | if ( m_btnState & wxCONTROL_PRESSED ) | |
1813 | { | |
1814 | // If mouse was inside, fire the click event. | |
1815 | if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP ) | |
1816 | { | |
1efad474 | 1817 | if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) ) |
a340b80d VZ |
1818 | OnButtonClick(); |
1819 | } | |
1820 | ||
1821 | m_btnState &= ~(wxCONTROL_PRESSED); | |
1822 | Refresh(); | |
1823 | } | |
1824 | } | |
1825 | else if ( type == wxEVT_LEAVE_WINDOW ) | |
1826 | { | |
1827 | if ( m_btnState & (wxCONTROL_CURRENT|wxCONTROL_PRESSED) ) | |
1828 | { | |
1829 | m_btnState &= ~(wxCONTROL_CURRENT); | |
1830 | ||
1831 | // Mouse hover ends | |
974a12f8 | 1832 | if ( IsPopupWindowState(Hidden) ) |
a340b80d VZ |
1833 | { |
1834 | m_btnState &= ~(wxCONTROL_PRESSED); | |
1835 | Refresh(); | |
1836 | } | |
1837 | } | |
1838 | } | |
1839 | else | |
1840 | return false; | |
1841 | ||
c905c0d6 VZ |
1842 | // Never have 'hot' state when popup is being shown |
1843 | // (this is mostly needed because of the animation). | |
1844 | if ( !IsPopupWindowState(Hidden) ) | |
1845 | m_btnState &= ~wxCONTROL_CURRENT; | |
1846 | ||
a340b80d VZ |
1847 | return true; |
1848 | } | |
1849 | ||
a340b80d | 1850 | // returns true if event was consumed or filtered |
a57d600f | 1851 | bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, |
b104d1f0 | 1852 | int WXUNUSED(flags) ) |
a340b80d VZ |
1853 | { |
1854 | wxLongLong t = ::wxGetLocalTimeMillis(); | |
1855 | int evtType = event.GetEventType(); | |
1856 | ||
fd5b4315 | 1857 | #if USES_WXPOPUPWINDOW || USES_GENERICTLW |
06077aaf | 1858 | if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW ) |
c667b518 | 1859 | { |
974a12f8 | 1860 | if ( IsPopupWindowState(Visible) && |
06077aaf VZ |
1861 | ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) ) |
1862 | { | |
a1d5aa93 | 1863 | HidePopup(true); |
06077aaf VZ |
1864 | return true; |
1865 | } | |
c667b518 VZ |
1866 | } |
1867 | #endif | |
1868 | ||
c905c0d6 | 1869 | // Filter out clicks on button immediately after popup dismiss |
a340b80d VZ |
1870 | if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick ) |
1871 | { | |
1872 | event.SetEventType(0); | |
1873 | return true; | |
1874 | } | |
1875 | ||
1876 | return false; | |
1877 | } | |
1878 | ||
a57d600f | 1879 | void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event ) |
a340b80d VZ |
1880 | { |
1881 | int evtType = event.GetEventType(); | |
1882 | ||
1883 | if ( (evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_LEFT_DCLICK) && | |
1884 | (m_windowStyle & wxCB_READONLY) ) | |
1885 | { | |
974a12f8 | 1886 | if ( GetPopupWindowState() >= Animating ) |
a340b80d | 1887 | { |
06077aaf | 1888 | #if USES_WXPOPUPWINDOW |
a340b80d | 1889 | // Click here always hides the popup. |
06077aaf | 1890 | if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW ) |
a1d5aa93 | 1891 | HidePopup(true); |
a340b80d VZ |
1892 | #endif |
1893 | } | |
1894 | else | |
1895 | { | |
1896 | if ( !(m_windowStyle & wxCC_SPECIAL_DCLICK) ) | |
1897 | { | |
1898 | // In read-only mode, clicking the text is the | |
1899 | // same as clicking the button. | |
1900 | OnButtonClick(); | |
1901 | } | |
1902 | else if ( /*evtType == wxEVT_LEFT_UP || */evtType == wxEVT_LEFT_DCLICK ) | |
1903 | { | |
1904 | //if ( m_popupInterface->CycleValue() ) | |
1905 | // Refresh(); | |
1906 | if ( m_popupInterface ) | |
1907 | m_popupInterface->OnComboDoubleClick(); | |
1908 | } | |
1909 | } | |
1910 | } | |
f4084513 | 1911 | else if ( evtType == wxEVT_MOUSEWHEEL ) |
a340b80d | 1912 | { |
f4084513 VS |
1913 | if ( IsPopupShown() ) |
1914 | { | |
1915 | // relay (some) mouse events to the popup | |
174b5c87 | 1916 | m_popup->GetEventHandler()->ProcessEvent(event); |
f4084513 VS |
1917 | } |
1918 | else if ( event.GetWheelAxis() == 0 && | |
1919 | event.GetWheelRotation() != 0 && | |
1920 | event.GetModifiers() == 0 ) | |
1921 | { | |
1922 | // Translate mousewheel actions into key up/down. This is | |
1923 | // the simplest way of getting native behaviour: scrolling the | |
1924 | // wheel moves selection up/down by one item. | |
1925 | wxKeyEvent kevent(wxEVT_KEY_DOWN); | |
1926 | kevent.m_keyCode = event.GetWheelRotation() > 0 | |
1927 | ? WXK_UP | |
1928 | : WXK_DOWN; | |
174b5c87 | 1929 | GetEventHandler()->ProcessEvent(kevent); |
f4084513 VS |
1930 | } |
1931 | else | |
1932 | { | |
1933 | event.Skip(); | |
1934 | } | |
a340b80d VZ |
1935 | } |
1936 | else if ( evtType ) | |
f4084513 | 1937 | { |
a340b80d | 1938 | event.Skip(); |
f4084513 | 1939 | } |
a340b80d VZ |
1940 | } |
1941 | ||
b445b6a7 | 1942 | void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event) |
a340b80d | 1943 | { |
b445b6a7 VZ |
1944 | if ( IsPopupShown() ) |
1945 | { | |
1946 | // pass it to the popped up control | |
174b5c87 | 1947 | GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event); |
b445b6a7 VZ |
1948 | } |
1949 | else // no popup | |
1950 | { | |
bbb86904 JS |
1951 | wxWindow* mainCtrl = GetMainWindowOfCompositeControl(); |
1952 | ||
1953 | if ( mainCtrl->GetParent()->HasFlag(wxTAB_TRAVERSAL) ) | |
1954 | { | |
1955 | if ( mainCtrl->HandleAsNavigationKey(event) ) | |
1956 | return; | |
1957 | } | |
b445b6a7 VZ |
1958 | |
1959 | if ( IsKeyPopupToggle(event) ) | |
1960 | { | |
1961 | OnButtonClick(); | |
1962 | return; | |
1963 | } | |
1964 | ||
1965 | int comboStyle = GetWindowStyle(); | |
1966 | wxComboPopup* popupInterface = GetPopupControl(); | |
1967 | ||
1968 | if ( !popupInterface ) | |
1969 | { | |
1970 | event.Skip(); | |
1971 | return; | |
1972 | } | |
1973 | ||
f029f1d1 VS |
1974 | int keycode = event.GetKeyCode(); |
1975 | ||
b445b6a7 VZ |
1976 | if ( (comboStyle & wxCB_READONLY) || |
1977 | (keycode != WXK_RIGHT && keycode != WXK_LEFT) ) | |
1978 | { | |
1979 | popupInterface->OnComboKeyEvent(event); | |
1980 | } | |
1981 | else | |
1982 | event.Skip(); | |
1983 | } | |
1984 | } | |
1985 | ||
c765e6fb VS |
1986 | void wxComboCtrlBase::OnCharEvent(wxKeyEvent& event) |
1987 | { | |
1988 | if ( IsPopupShown() ) | |
1989 | { | |
1990 | // pass it to the popped up control | |
1991 | GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event); | |
1992 | } | |
1993 | else // no popup | |
1994 | { | |
1995 | wxComboPopup* popupInterface = GetPopupControl(); | |
1996 | if ( popupInterface ) | |
1997 | { | |
1998 | popupInterface->OnComboCharEvent(event); | |
1999 | } | |
2000 | else | |
2001 | { | |
2002 | event.Skip(); | |
2003 | } | |
2004 | } | |
2005 | } | |
2006 | ||
b445b6a7 VZ |
2007 | void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event ) |
2008 | { | |
2009 | if ( event.GetEventType() == wxEVT_SET_FOCUS ) | |
a340b80d | 2010 | { |
9727e8a3 JS |
2011 | wxWindow* tc = GetTextCtrl(); |
2012 | if ( tc && tc != DoFindFocus() ) | |
c905c0d6 | 2013 | { |
9727e8a3 | 2014 | tc->SetFocus(); |
c905c0d6 | 2015 | } |
a340b80d | 2016 | } |
b445b6a7 VZ |
2017 | |
2018 | Refresh(); | |
a340b80d VZ |
2019 | } |
2020 | ||
2dfa37d6 RD |
2021 | void wxComboCtrlBase::OnIdleEvent( wxIdleEvent& WXUNUSED(event) ) |
2022 | { | |
2023 | if ( m_resetFocus ) | |
2024 | { | |
2025 | m_resetFocus = false; | |
2026 | wxWindow* tc = GetTextCtrl(); | |
2027 | if ( tc ) | |
2028 | tc->SetFocus(); | |
2029 | } | |
2030 | } | |
2031 | ||
a57d600f | 2032 | void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) |
a340b80d VZ |
2033 | { |
2034 | OnThemeChange(); | |
0847e36e JS |
2035 | // left margin may also have changed |
2036 | if ( !(m_iFlags & wxCC_IFLAG_LEFT_MARGIN_SET) ) | |
2037 | m_marginLeft = GetNativeTextIndent(); | |
a340b80d VZ |
2038 | RecalcAndRefresh(); |
2039 | } | |
2040 | ||
2041 | // ---------------------------------------------------------------------------- | |
2042 | // popup handling | |
2043 | // ---------------------------------------------------------------------------- | |
2044 | ||
2045 | // Create popup window and the child control | |
a57d600f | 2046 | void wxComboCtrlBase::CreatePopup() |
a340b80d VZ |
2047 | { |
2048 | wxComboPopup* popupInterface = m_popupInterface; | |
2049 | wxWindow* popup; | |
2050 | ||
2051 | if ( !m_winPopup ) | |
06077aaf VZ |
2052 | { |
2053 | #ifdef wxComboPopupWindowBase2 | |
2054 | if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP ) | |
2055 | { | |
fd5b4315 | 2056 | #if !USES_GENERICTLW |
06077aaf VZ |
2057 | m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER ); |
2058 | #else | |
fd5b4315 JS |
2059 | int tlwFlags = wxNO_BORDER; |
2060 | #ifdef wxCC_GENERIC_TLW_IS_FRAME | |
2061 | tlwFlags |= wxFRAME_NO_TASKBAR; | |
2062 | #endif | |
2063 | ||
2064 | #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW | |
2065 | m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, | |
2066 | wxPoint(-21,-21), wxSize(20, 20), | |
2067 | tlwFlags ); | |
2068 | #else | |
06077aaf VZ |
2069 | m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString, |
2070 | wxPoint(-21,-21), wxSize(20, 20), | |
fd5b4315 JS |
2071 | tlwFlags ); |
2072 | #endif | |
06077aaf VZ |
2073 | #endif |
2074 | m_popupWinType = SECONDARY_POPUP_TYPE; | |
2075 | } | |
2076 | else | |
c905c0d6 | 2077 | #endif // wxComboPopupWindowBase2 |
06077aaf VZ |
2078 | { |
2079 | m_winPopup = new wxComboPopupWindow( this, wxNO_BORDER ); | |
2080 | m_popupWinType = PRIMARY_POPUP_TYPE; | |
2081 | } | |
2082 | m_popupWinEvtHandler = new wxComboPopupWindowEvtHandler(this); | |
2083 | m_winPopup->PushEventHandler(m_popupWinEvtHandler); | |
2084 | } | |
a340b80d VZ |
2085 | |
2086 | popupInterface->Create(m_winPopup); | |
2087 | m_popup = popup = popupInterface->GetControl(); | |
2088 | ||
06315578 JS |
2089 | m_popupEvtHandler = new wxComboPopupEvtHandler(this); |
2090 | popup->PushEventHandler( m_popupEvtHandler ); | |
a340b80d VZ |
2091 | |
2092 | // This may be helpful on some platforms | |
2093 | // (eg. it bypasses a wxGTK popupwindow bug where | |
2094 | // window is not initially hidden when it should be) | |
2095 | m_winPopup->Hide(); | |
2096 | ||
2097 | popupInterface->m_iFlags |= wxCP_IFLAG_CREATED; | |
2098 | } | |
2099 | ||
7ca4ac63 WS |
2100 | // Destroy popup window and the child control |
2101 | void wxComboCtrlBase::DestroyPopup() | |
2102 | { | |
a1d5aa93 | 2103 | HidePopup(true); |
c667b518 | 2104 | |
7ca4ac63 | 2105 | if ( m_popup ) |
06315578 | 2106 | m_popup->RemoveEventHandler(m_popupEvtHandler); |
7ca4ac63 | 2107 | |
5276b0a5 | 2108 | wxDELETE(m_popupEvtHandler); |
7ca4ac63 | 2109 | |
5276b0a5 | 2110 | wxDELETE(m_popupInterface); |
7ca4ac63 WS |
2111 | |
2112 | if ( m_winPopup ) | |
06077aaf VZ |
2113 | { |
2114 | m_winPopup->RemoveEventHandler(m_popupWinEvtHandler); | |
5276b0a5 | 2115 | wxDELETE(m_popupWinEvtHandler); |
7ca4ac63 | 2116 | m_winPopup->Destroy(); |
5276b0a5 | 2117 | m_winPopup = NULL; |
06077aaf | 2118 | } |
7ca4ac63 | 2119 | |
d3b9f782 | 2120 | m_popup = NULL; |
7ca4ac63 WS |
2121 | } |
2122 | ||
db53c6ea | 2123 | void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface) |
a340b80d | 2124 | { |
a57d600f | 2125 | wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") ); |
6d0ce565 | 2126 | |
7ca4ac63 | 2127 | DestroyPopup(); |
a340b80d | 2128 | |
6d0ce565 VZ |
2129 | iface->InitBase(this); |
2130 | iface->Init(); | |
2131 | ||
a340b80d VZ |
2132 | m_popupInterface = iface; |
2133 | ||
7ca4ac63 | 2134 | if ( !iface->LazyCreate() ) |
a340b80d VZ |
2135 | { |
2136 | CreatePopup(); | |
2137 | } | |
2138 | else | |
2139 | { | |
d3b9f782 | 2140 | m_popup = NULL; |
a340b80d VZ |
2141 | } |
2142 | ||
6d0ce565 | 2143 | // This must be done after creation |
6636ef8d | 2144 | if ( !m_valueString.empty() ) |
6d0ce565 | 2145 | { |
a340b80d | 2146 | iface->SetStringValue(m_valueString); |
6d0ce565 VZ |
2147 | //Refresh(); |
2148 | } | |
2149 | } | |
a340b80d | 2150 | |
6d0ce565 | 2151 | // Ensures there is atleast the default popup |
a57d600f | 2152 | void wxComboCtrlBase::EnsurePopupControl() |
6d0ce565 VZ |
2153 | { |
2154 | if ( !m_popupInterface ) | |
2155 | SetPopupControl(NULL); | |
a340b80d VZ |
2156 | } |
2157 | ||
a57d600f | 2158 | void wxComboCtrlBase::OnButtonClick() |
a340b80d VZ |
2159 | { |
2160 | // Derived classes can override this method for totally custom | |
2161 | // popup action | |
dc2b49b3 | 2162 | switch ( GetPopupWindowState() ) |
a1d5aa93 | 2163 | { |
dc2b49b3 VS |
2164 | case Hidden: |
2165 | { | |
ffb9247a | 2166 | Popup(); |
dc2b49b3 VS |
2167 | break; |
2168 | } | |
2169 | ||
2170 | case Animating: | |
2171 | case Visible: | |
2172 | { | |
2173 | HidePopup(true); | |
2174 | break; | |
2175 | } | |
a1d5aa93 | 2176 | } |
a340b80d VZ |
2177 | } |
2178 | ||
ffb9247a JS |
2179 | void wxComboCtrlBase::Popup() |
2180 | { | |
2181 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId()); | |
2182 | event.SetEventObject(this); | |
2183 | HandleWindowEvent(event); | |
2184 | ||
2185 | ShowPopup(); | |
2186 | } | |
2187 | ||
a57d600f | 2188 | void wxComboCtrlBase::ShowPopup() |
a340b80d | 2189 | { |
6d0ce565 | 2190 | EnsurePopupControl(); |
974a12f8 RR |
2191 | wxCHECK_RET( !IsPopupWindowState(Visible), wxT("popup window already shown") ); |
2192 | ||
2193 | if ( IsPopupWindowState(Animating) ) | |
2194 | return; | |
a340b80d VZ |
2195 | |
2196 | SetFocus(); | |
2197 | ||
2198 | // Space above and below | |
2199 | int screenHeight; | |
2200 | wxPoint scrPos; | |
2201 | int spaceAbove; | |
2202 | int spaceBelow; | |
2203 | int maxHeightPopup; | |
2204 | wxSize ctrlSz = GetSize(); | |
2205 | ||
2206 | screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ); | |
2207 | scrPos = GetParent()->ClientToScreen(GetPosition()); | |
2208 | ||
2209 | spaceAbove = scrPos.y; | |
2210 | spaceBelow = screenHeight - spaceAbove - ctrlSz.y; | |
2211 | ||
2212 | maxHeightPopup = spaceBelow; | |
2213 | if ( spaceAbove > spaceBelow ) | |
2214 | maxHeightPopup = spaceAbove; | |
2215 | ||
2216 | // Width | |
2217 | int widthPopup = ctrlSz.x + m_extLeft + m_extRight; | |
2218 | ||
2219 | if ( widthPopup < m_widthMinPopup ) | |
2220 | widthPopup = m_widthMinPopup; | |
2221 | ||
2222 | wxWindow* winPopup = m_winPopup; | |
2223 | wxWindow* popup; | |
2224 | ||
2225 | // Need to disable tab traversal of parent | |
2226 | // | |
2227 | // NB: This is to fix a bug in wxMSW. In theory it could also be fixed | |
2228 | // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage | |
2229 | // that if transient popup is open, then tab traversal is to be ignored. | |
2230 | // However, I think this code would still be needed for cases where | |
2231 | // transient popup doesn't work yet (wxWinCE?). | |
bbb86904 JS |
2232 | wxWindow* mainCtrl = GetMainWindowOfCompositeControl(); |
2233 | wxWindow* parent = mainCtrl->GetParent(); | |
a340b80d VZ |
2234 | int parentFlags = parent->GetWindowStyle(); |
2235 | if ( parentFlags & wxTAB_TRAVERSAL ) | |
2236 | { | |
2237 | parent->SetWindowStyle( parentFlags & ~(wxTAB_TRAVERSAL) ); | |
2238 | m_iFlags |= wxCC_IFLAG_PARENT_TAB_TRAVERSAL; | |
2239 | } | |
2240 | ||
2241 | if ( !winPopup ) | |
2242 | { | |
2243 | CreatePopup(); | |
2244 | winPopup = m_winPopup; | |
2245 | popup = m_popup; | |
2246 | } | |
2247 | else | |
2248 | { | |
2249 | popup = m_popup; | |
2250 | } | |
2251 | ||
9727e8a3 | 2252 | winPopup->Enable(); |
a61c9122 | 2253 | |
a340b80d VZ |
2254 | wxASSERT( !m_popup || m_popup == popup ); // Consistency check. |
2255 | ||
2256 | wxSize adjustedSize = m_popupInterface->GetAdjustedSize(widthPopup, | |
2257 | m_heightPopup<=0?DEFAULT_POPUP_HEIGHT:m_heightPopup, | |
2258 | maxHeightPopup); | |
2259 | ||
2260 | popup->SetSize(adjustedSize); | |
2261 | popup->Move(0,0); | |
2262 | m_popupInterface->OnPopup(); | |
2263 | ||
2264 | // | |
2265 | // Reposition and resize popup window | |
2266 | // | |
2267 | ||
2268 | wxSize szp = popup->GetSize(); | |
2269 | ||
2270 | int popupX; | |
2271 | int popupY = scrPos.y + ctrlSz.y; | |
2272 | ||
b7540dc1 | 2273 | // Default anchor is wxLEFT |
a340b80d VZ |
2274 | int anchorSide = m_anchorSide; |
2275 | if ( !anchorSide ) | |
b7540dc1 | 2276 | anchorSide = wxLEFT; |
a340b80d | 2277 | |
b7540dc1 WS |
2278 | int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x; |
2279 | int leftX = scrPos.x - m_extLeft; | |
c4b37573 VZ |
2280 | |
2281 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) | |
2282 | leftX -= ctrlSz.x; | |
2283 | ||
b7540dc1 WS |
2284 | int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X ); |
2285 | ||
2286 | // If there is not enough horizontal space, anchor on the other side. | |
2287 | // If there is no space even then, place the popup at x 0. | |
2288 | if ( anchorSide == wxRIGHT ) | |
2289 | { | |
2290 | if ( rightX < 0 ) | |
2291 | { | |
2292 | if ( (leftX+szp.x) < screenWidth ) | |
2293 | anchorSide = wxLEFT; | |
2294 | else | |
2295 | anchorSide = 0; | |
2296 | } | |
2297 | } | |
2298 | else | |
2299 | { | |
2300 | if ( (leftX+szp.x) >= screenWidth ) | |
2301 | { | |
2302 | if ( rightX >= 0 ) | |
2303 | anchorSide = wxRIGHT; | |
2304 | else | |
2305 | anchorSide = 0; | |
2306 | } | |
2307 | } | |
2308 | ||
2309 | // Select x coordinate according to the anchor side | |
a340b80d | 2310 | if ( anchorSide == wxRIGHT ) |
b7540dc1 WS |
2311 | popupX = rightX; |
2312 | else if ( anchorSide == wxLEFT ) | |
2313 | popupX = leftX; | |
a340b80d | 2314 | else |
b7540dc1 | 2315 | popupX = 0; |
a340b80d | 2316 | |
974a12f8 RR |
2317 | int showFlags = CanDeferShow; |
2318 | ||
a340b80d VZ |
2319 | if ( spaceBelow < szp.y ) |
2320 | { | |
2321 | popupY = scrPos.y - szp.y; | |
974a12f8 | 2322 | showFlags |= ShowAbove; |
a340b80d VZ |
2323 | } |
2324 | ||
974a12f8 RR |
2325 | #if INSTALL_TOPLEV_HANDLER |
2326 | // Put top level window event handler into place | |
2327 | if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW ) | |
2328 | { | |
2329 | if ( !m_toplevEvtHandler ) | |
2330 | m_toplevEvtHandler = new wxComboFrameEventHandler(this); | |
a340b80d | 2331 | |
974a12f8 RR |
2332 | wxWindow* toplev = ::wxGetTopLevelParent( this ); |
2333 | wxASSERT( toplev ); | |
2334 | ((wxComboFrameEventHandler*)m_toplevEvtHandler)->OnPopup(); | |
2335 | toplev->PushEventHandler( m_toplevEvtHandler ); | |
2336 | } | |
2337 | #endif | |
a340b80d VZ |
2338 | |
2339 | // Set string selection (must be this way instead of SetStringSelection) | |
2340 | if ( m_text ) | |
2341 | { | |
2342 | if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) ) | |
2343 | m_text->SelectAll(); | |
2344 | ||
2345 | m_popupInterface->SetStringValue( m_text->GetValue() ); | |
2346 | } | |
2347 | else | |
2348 | { | |
2349 | // This is neede since focus/selection indication may change when popup is shown | |
a340b80d VZ |
2350 | Refresh(); |
2351 | } | |
2352 | ||
2353 | // This must be after SetStringValue | |
974a12f8 | 2354 | m_popupWinState = Animating; |
a340b80d | 2355 | |
974a12f8 | 2356 | wxRect popupWinRect( popupX, popupY, szp.x, szp.y ); |
a340b80d | 2357 | |
974a12f8 | 2358 | m_popup = popup; |
30be036c RR |
2359 | if ( (m_iFlags & wxCC_IFLAG_DISABLE_POPUP_ANIM) || |
2360 | AnimateShow( popupWinRect, showFlags ) ) | |
06077aaf | 2361 | { |
974a12f8 RR |
2362 | DoShowPopup( popupWinRect, showFlags ); |
2363 | } | |
2364 | } | |
a340b80d | 2365 | |
974a12f8 RR |
2366 | bool wxComboCtrlBase::AnimateShow( const wxRect& WXUNUSED(rect), int WXUNUSED(flags) ) |
2367 | { | |
2368 | return true; | |
2369 | } | |
2370 | ||
2371 | void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) ) | |
2372 | { | |
2373 | wxWindow* winPopup = m_winPopup; | |
2374 | ||
2375 | if ( IsPopupWindowState(Animating) ) | |
2376 | { | |
2377 | // Make sure the popup window is shown in the right position. | |
2378 | // Should not matter even if animation already did this. | |
2379 | ||
2380 | // Some platforms (GTK) may like SetSize and Move to be separate | |
2381 | // (though the bug was probably fixed). | |
2382 | winPopup->SetSize( rect ); | |
2383 | ||
c905c0d6 VZ |
2384 | #if USES_WXPOPUPTRANSIENTWINDOW |
2385 | if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW ) | |
2386 | ((wxPopupTransientWindow*)winPopup)->Popup(m_popup); | |
2387 | else | |
2388 | #endif | |
2389 | winPopup->Show(); | |
974a12f8 RR |
2390 | |
2391 | m_popupWinState = Visible; | |
52999871 JS |
2392 | |
2393 | // If popup window was a generic top-level window, or the | |
2394 | // wxPopupWindow implemenation on this platform is classified as | |
2395 | // perfect, then we should be able to safely set focus to the popup | |
2396 | // control. | |
2397 | if ( IsPopupWinTypePerfect(m_popupWinType) ) | |
2398 | m_popup->SetFocus(); | |
06077aaf | 2399 | } |
974a12f8 RR |
2400 | else if ( IsPopupWindowState(Hidden) ) |
2401 | { | |
2402 | // Animation was aborted | |
a340b80d | 2403 | |
974a12f8 RR |
2404 | wxASSERT( !winPopup->IsShown() ); |
2405 | ||
2406 | m_popupWinState = Hidden; | |
2407 | } | |
c905c0d6 VZ |
2408 | |
2409 | Refresh(); | |
a340b80d VZ |
2410 | } |
2411 | ||
a1d5aa93 | 2412 | void wxComboCtrlBase::OnPopupDismiss(bool generateEvent) |
974a12f8 | 2413 | { |
a340b80d | 2414 | // Just in case, avoid double dismiss |
974a12f8 | 2415 | if ( IsPopupWindowState(Hidden) ) |
a340b80d VZ |
2416 | return; |
2417 | ||
9727e8a3 JS |
2418 | // This must be set before focus - otherwise there will be recursive |
2419 | // OnPopupDismisses. | |
974a12f8 | 2420 | m_popupWinState = Hidden; |
a340b80d | 2421 | |
9727e8a3 JS |
2422 | //SetFocus(); |
2423 | m_winPopup->Disable(); | |
2424 | ||
a340b80d VZ |
2425 | // Inform popup control itself |
2426 | m_popupInterface->OnDismiss(); | |
2427 | ||
06315578 JS |
2428 | if ( m_popupEvtHandler ) |
2429 | ((wxComboPopupEvtHandler*)m_popupEvtHandler)->OnPopupDismiss(); | |
a340b80d VZ |
2430 | |
2431 | #if INSTALL_TOPLEV_HANDLER | |
2432 | // Remove top level window event handler | |
2433 | if ( m_toplevEvtHandler ) | |
2434 | { | |
2435 | wxWindow* toplev = ::wxGetTopLevelParent( this ); | |
2436 | if ( toplev ) | |
2437 | toplev->RemoveEventHandler( m_toplevEvtHandler ); | |
2438 | } | |
2439 | #endif | |
2440 | ||
974a12f8 RR |
2441 | m_timeCanAcceptClick = ::wxGetLocalTimeMillis(); |
2442 | ||
2443 | if ( m_popupWinType == POPUPWIN_WXPOPUPTRANSIENTWINDOW ) | |
2444 | m_timeCanAcceptClick += 150; | |
a340b80d VZ |
2445 | |
2446 | // If cursor not on dropdown button, then clear its state | |
2447 | // (technically not required by all ports, but do it for all just in case) | |
22a35096 | 2448 | if ( !m_btnArea.Contains(ScreenToClient(::wxGetMousePosition())) ) |
a340b80d VZ |
2449 | m_btnState = 0; |
2450 | ||
2451 | // Return parent's tab traversal flag. | |
2452 | // See ShowPopup for notes. | |
2453 | if ( m_iFlags & wxCC_IFLAG_PARENT_TAB_TRAVERSAL ) | |
2454 | { | |
2455 | wxWindow* parent = GetParent(); | |
2456 | parent->SetWindowStyle( parent->GetWindowStyle() | wxTAB_TRAVERSAL ); | |
2457 | m_iFlags &= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL); | |
2458 | } | |
2459 | ||
2460 | // refresh control (necessary even if m_text) | |
2461 | Refresh(); | |
2462 | ||
a340b80d | 2463 | SetFocus(); |
a1d5aa93 JS |
2464 | |
2465 | if ( generateEvent ) | |
2466 | { | |
2467 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId()); | |
2468 | event.SetEventObject(this); | |
65702d2f | 2469 | HandleWindowEvent(event); |
a1d5aa93 | 2470 | } |
a340b80d VZ |
2471 | } |
2472 | ||
a1d5aa93 | 2473 | void wxComboCtrlBase::HidePopup(bool generateEvent) |
a340b80d VZ |
2474 | { |
2475 | // Should be able to call this without popup interface | |
974a12f8 | 2476 | if ( IsPopupWindowState(Hidden) ) |
a340b80d VZ |
2477 | return; |
2478 | ||
2479 | // transfer value and show it in textctrl, if any | |
974a12f8 | 2480 | if ( !IsPopupWindowState(Animating) ) |
0306e73e | 2481 | SetValueByUser( m_popupInterface->GetStringValue() ); |
a340b80d | 2482 | |
974a12f8 | 2483 | m_winPopup->Hide(); |
a340b80d | 2484 | |
a1d5aa93 | 2485 | OnPopupDismiss(generateEvent); |
a340b80d VZ |
2486 | } |
2487 | ||
2488 | // ---------------------------------------------------------------------------- | |
2489 | // customization methods | |
2490 | // ---------------------------------------------------------------------------- | |
2491 | ||
a57d600f | 2492 | void wxComboCtrlBase::SetButtonPosition( int width, int height, |
7dc234d6 | 2493 | int side, int spacingX ) |
a340b80d VZ |
2494 | { |
2495 | m_btnWid = width; | |
2496 | m_btnHei = height; | |
2497 | m_btnSide = side; | |
2498 | m_btnSpacingX = spacingX; | |
2499 | ||
735a300a JS |
2500 | if ( width > 0 || height > 0 || spacingX ) |
2501 | m_iFlags |= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON; | |
2502 | ||
a340b80d VZ |
2503 | RecalcAndRefresh(); |
2504 | } | |
2505 | ||
7dc234d6 WS |
2506 | wxSize wxComboCtrlBase::GetButtonSize() |
2507 | { | |
2508 | if ( m_btnSize.x > 0 ) | |
2509 | return m_btnSize; | |
2510 | ||
2511 | wxSize retSize(m_btnWid,m_btnHei); | |
2512 | ||
2513 | // Need to call CalculateAreas now if button size is | |
2514 | // is not explicitly specified. | |
2515 | if ( retSize.x <= 0 || retSize.y <= 0) | |
2516 | { | |
2517 | OnResize(); | |
2518 | ||
2519 | retSize = m_btnSize; | |
2520 | } | |
2521 | ||
2522 | return retSize; | |
2523 | } | |
2524 | ||
a57d600f | 2525 | void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal, |
a340b80d VZ |
2526 | bool blankButtonBg, |
2527 | const wxBitmap& bmpPressed, | |
2528 | const wxBitmap& bmpHover, | |
2529 | const wxBitmap& bmpDisabled ) | |
2530 | { | |
2531 | m_bmpNormal = bmpNormal; | |
2532 | m_blankButtonBg = blankButtonBg; | |
2533 | ||
2534 | if ( bmpPressed.Ok() ) | |
2535 | m_bmpPressed = bmpPressed; | |
2536 | else | |
2537 | m_bmpPressed = bmpNormal; | |
2538 | ||
2539 | if ( bmpHover.Ok() ) | |
2540 | m_bmpHover = bmpHover; | |
2541 | else | |
2542 | m_bmpHover = bmpNormal; | |
2543 | ||
2544 | if ( bmpDisabled.Ok() ) | |
2545 | m_bmpDisabled = bmpDisabled; | |
2546 | else | |
2547 | m_bmpDisabled = bmpNormal; | |
2548 | ||
2549 | RecalcAndRefresh(); | |
2550 | } | |
2551 | ||
a57d600f | 2552 | void wxComboCtrlBase::SetCustomPaintWidth( int width ) |
a340b80d VZ |
2553 | { |
2554 | if ( m_text ) | |
2555 | { | |
2556 | // move textctrl accordingly | |
2557 | wxRect r = m_text->GetRect(); | |
2558 | int inc = width - m_widthCustomPaint; | |
2559 | r.x += inc; | |
2560 | r.width -= inc; | |
2561 | m_text->SetSize( r ); | |
2562 | } | |
2563 | ||
2564 | m_widthCustomPaint = width; | |
2565 | ||
2566 | RecalcAndRefresh(); | |
2567 | } | |
2568 | ||
0847e36e JS |
2569 | bool wxComboCtrlBase::DoSetMargins(const wxPoint& margins) |
2570 | { | |
2571 | // For general sanity's sake, we ignore top margin. Instead | |
2572 | // we will always try to center the text vertically. | |
2573 | bool res = true; | |
2574 | ||
2575 | if ( margins.x != -1 ) | |
2576 | { | |
2577 | m_marginLeft = margins.x; | |
2578 | m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET; | |
2579 | } | |
2580 | else | |
2581 | { | |
2582 | m_marginLeft = GetNativeTextIndent(); | |
2583 | m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET); | |
2584 | } | |
2585 | ||
2586 | if ( margins.y != -1 ) | |
2587 | { | |
2588 | res = false; | |
2589 | } | |
2590 | ||
2591 | RecalcAndRefresh(); | |
2592 | ||
2593 | return res; | |
2594 | } | |
2595 | ||
2596 | wxPoint wxComboCtrlBase::DoGetMargins() const | |
2597 | { | |
2598 | return wxPoint(m_marginLeft, -1); | |
2599 | } | |
2600 | ||
ddadf560 | 2601 | #if WXWIN_COMPATIBILITY_2_8 |
a57d600f | 2602 | void wxComboCtrlBase::SetTextIndent( int indent ) |
a340b80d VZ |
2603 | { |
2604 | if ( indent < 0 ) | |
2605 | { | |
0847e36e JS |
2606 | m_marginLeft = GetNativeTextIndent(); |
2607 | m_iFlags &= ~(wxCC_IFLAG_LEFT_MARGIN_SET); | |
a340b80d VZ |
2608 | } |
2609 | else | |
2610 | { | |
0847e36e JS |
2611 | m_marginLeft = indent; |
2612 | m_iFlags |= wxCC_IFLAG_LEFT_MARGIN_SET; | |
a340b80d VZ |
2613 | } |
2614 | ||
2615 | RecalcAndRefresh(); | |
2616 | } | |
2617 | ||
48284cc7 | 2618 | wxCoord wxComboCtrlBase::GetTextIndent() const |
0847e36e JS |
2619 | { |
2620 | return m_marginLeft; | |
2621 | } | |
2622 | #endif | |
2623 | ||
a57d600f | 2624 | wxCoord wxComboCtrlBase::GetNativeTextIndent() const |
a340b80d VZ |
2625 | { |
2626 | return DEFAULT_TEXT_INDENT; | |
2627 | } | |
2628 | ||
1ac5cfc7 JS |
2629 | void wxComboCtrlBase::SetTextCtrlStyle( int style ) |
2630 | { | |
2631 | m_textCtrlStyle = style; | |
2632 | ||
2633 | if ( m_text ) | |
2634 | m_text->SetWindowStyle(style); | |
2635 | } | |
2636 | ||
a340b80d | 2637 | // ---------------------------------------------------------------------------- |
fda62793 | 2638 | // wxTextEntry interface |
a340b80d VZ |
2639 | // ---------------------------------------------------------------------------- |
2640 | ||
fda62793 | 2641 | wxString wxComboCtrlBase::DoGetValue() const |
a340b80d VZ |
2642 | { |
2643 | if ( m_text ) | |
2644 | return m_text->GetValue(); | |
2645 | return m_valueString; | |
2646 | } | |
2647 | ||
0306e73e JS |
2648 | void wxComboCtrlBase::SetValueWithEvent(const wxString& value, |
2649 | bool withEvent) | |
a340b80d | 2650 | { |
0306e73e JS |
2651 | DoSetValue(value, withEvent ? SetValue_SendEvent : 0); |
2652 | } | |
22b6de6a | 2653 | |
0306e73e JS |
2654 | void wxComboCtrlBase::OnSetValue(const wxString& value) |
2655 | { | |
2656 | // Note: before wxComboCtrl inherited from wxTextEntry, | |
2657 | // this code used to be in SetValueWithEvent(). | |
a340b80d VZ |
2658 | |
2659 | // Since wxComboPopup may want to paint the combo as well, we need | |
2660 | // to set the string value here (as well as sometimes in ShowPopup). | |
4738d674 | 2661 | if ( m_valueString != value ) |
a340b80d | 2662 | { |
238b33ab JS |
2663 | bool found = true; |
2664 | wxString trueValue = value; | |
2665 | ||
2666 | // Conform to wxComboBox behavior: read-only control can only accept | |
2667 | // valid list items and empty string | |
2668 | if ( m_popupInterface && HasFlag(wxCB_READONLY) && value.length() ) | |
2669 | { | |
2670 | found = m_popupInterface->FindItem(value, | |
2671 | &trueValue); | |
2672 | } | |
4738d674 | 2673 | |
238b33ab JS |
2674 | if ( found ) |
2675 | { | |
2676 | m_valueString = trueValue; | |
4738d674 | 2677 | |
238b33ab JS |
2678 | EnsurePopupControl(); |
2679 | ||
2680 | if ( m_popupInterface ) | |
2681 | m_popupInterface->SetStringValue(trueValue); | |
2682 | } | |
a340b80d | 2683 | } |
4738d674 VZ |
2684 | |
2685 | Refresh(); | |
6d0ce565 VZ |
2686 | } |
2687 | ||
0306e73e | 2688 | void wxComboCtrlBase::SetValueByUser(const wxString& value) |
ce968519 | 2689 | { |
0306e73e JS |
2690 | // NB: Order of function calls is important here. Otherwise |
2691 | // the SelectAll() may not work. | |
2692 | ||
2693 | if ( m_text ) | |
2694 | { | |
2695 | m_text->SetValue(value); | |
2696 | ||
2697 | if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) ) | |
2698 | m_text->SelectAll(); | |
2699 | } | |
2700 | ||
2701 | OnSetValue(value); | |
ce968519 RR |
2702 | } |
2703 | ||
6d0ce565 | 2704 | // In this SetValue variant wxComboPopup::SetStringValue is not called |
a57d600f | 2705 | void wxComboCtrlBase::SetText(const wxString& value) |
6d0ce565 VZ |
2706 | { |
2707 | // Unlike in SetValue(), this must be called here or | |
2708 | // the behaviour will no be consistent in readonlys. | |
2709 | EnsurePopupControl(); | |
a340b80d VZ |
2710 | |
2711 | m_valueString = value; | |
2712 | ||
ce968519 RR |
2713 | if ( m_text ) |
2714 | { | |
2715 | m_ignoreEvtText++; | |
2716 | m_text->SetValue( value ); | |
2717 | } | |
2718 | ||
a340b80d VZ |
2719 | Refresh(); |
2720 | } | |
2721 | ||
a57d600f | 2722 | void wxComboCtrlBase::Copy() |
a340b80d VZ |
2723 | { |
2724 | if ( m_text ) | |
2725 | m_text->Copy(); | |
2726 | } | |
2727 | ||
a57d600f | 2728 | void wxComboCtrlBase::Cut() |
a340b80d VZ |
2729 | { |
2730 | if ( m_text ) | |
2731 | m_text->Cut(); | |
2732 | } | |
2733 | ||
a57d600f | 2734 | void wxComboCtrlBase::Paste() |
a340b80d VZ |
2735 | { |
2736 | if ( m_text ) | |
2737 | m_text->Paste(); | |
2738 | } | |
2739 | ||
a57d600f | 2740 | void wxComboCtrlBase::SetInsertionPoint(long pos) |
a340b80d VZ |
2741 | { |
2742 | if ( m_text ) | |
2743 | m_text->SetInsertionPoint(pos); | |
2744 | } | |
2745 | ||
a57d600f | 2746 | long wxComboCtrlBase::GetInsertionPoint() const |
a340b80d VZ |
2747 | { |
2748 | if ( m_text ) | |
2749 | return m_text->GetInsertionPoint(); | |
2750 | ||
2751 | return 0; | |
2752 | } | |
2753 | ||
a57d600f | 2754 | long wxComboCtrlBase::GetLastPosition() const |
a340b80d VZ |
2755 | { |
2756 | if ( m_text ) | |
2757 | return m_text->GetLastPosition(); | |
2758 | ||
2759 | return 0; | |
2760 | } | |
2761 | ||
0306e73e | 2762 | void wxComboCtrlBase::WriteText(const wxString& text) |
a340b80d VZ |
2763 | { |
2764 | if ( m_text ) | |
0306e73e JS |
2765 | { |
2766 | m_text->WriteText(text); | |
2767 | OnSetValue(m_text->GetValue()); | |
2768 | } | |
2769 | else | |
2770 | { | |
2771 | OnSetValue(text); | |
2772 | } | |
a340b80d VZ |
2773 | } |
2774 | ||
0306e73e | 2775 | void wxComboCtrlBase::DoSetValue(const wxString& value, int flags) |
fda62793 JS |
2776 | { |
2777 | if ( m_text ) | |
0306e73e JS |
2778 | { |
2779 | if ( flags & SetValue_SendEvent ) | |
2780 | m_text->SetValue(value); | |
2781 | else | |
2782 | m_text->ChangeValue(value); | |
2783 | } | |
2784 | ||
2785 | OnSetValue(value); | |
2786 | } | |
2787 | ||
2788 | void wxComboCtrlBase::Replace(long from, long to, const wxString& value) | |
2789 | { | |
2790 | if ( m_text ) | |
2791 | { | |
2792 | m_text->Replace(from, to, value); | |
2793 | OnSetValue(m_text->GetValue()); | |
2794 | } | |
fda62793 JS |
2795 | } |
2796 | ||
a57d600f | 2797 | void wxComboCtrlBase::Remove(long from, long to) |
a340b80d VZ |
2798 | { |
2799 | if ( m_text ) | |
0306e73e | 2800 | { |
a340b80d | 2801 | m_text->Remove(from, to); |
0306e73e JS |
2802 | OnSetValue(m_text->GetValue()); |
2803 | } | |
a340b80d VZ |
2804 | } |
2805 | ||
a57d600f | 2806 | void wxComboCtrlBase::SetSelection(long from, long to) |
a340b80d VZ |
2807 | { |
2808 | if ( m_text ) | |
2809 | m_text->SetSelection(from, to); | |
2810 | } | |
2811 | ||
fda62793 JS |
2812 | void wxComboCtrlBase::GetSelection(long *from, long *to) const |
2813 | { | |
2814 | if ( m_text ) | |
2815 | { | |
2816 | m_text->GetSelection(from, to); | |
2817 | } | |
2818 | else | |
2819 | { | |
2820 | *from = 0; | |
2821 | *to = 0; | |
2822 | } | |
2823 | } | |
2824 | ||
2825 | bool wxComboCtrlBase::IsEditable() const | |
2826 | { | |
2827 | if ( m_text ) | |
2828 | return m_text->IsEditable(); | |
2829 | return false; | |
2830 | } | |
2831 | ||
2832 | void wxComboCtrlBase::SetEditable(bool editable) | |
2833 | { | |
2834 | if ( m_text ) | |
2835 | m_text->SetEditable(editable); | |
2836 | } | |
2837 | ||
a57d600f | 2838 | void wxComboCtrlBase::Undo() |
a340b80d VZ |
2839 | { |
2840 | if ( m_text ) | |
2841 | m_text->Undo(); | |
2842 | } | |
2843 | ||
fda62793 JS |
2844 | void wxComboCtrlBase::Redo() |
2845 | { | |
2846 | if ( m_text ) | |
2847 | m_text->Redo(); | |
2848 | } | |
2849 | ||
2850 | bool wxComboCtrlBase::CanUndo() const | |
2851 | { | |
2852 | if ( m_text ) | |
2853 | return m_text->CanUndo(); | |
2854 | ||
2855 | return false; | |
2856 | } | |
2857 | ||
2858 | bool wxComboCtrlBase::CanRedo() const | |
2859 | { | |
2860 | if ( m_text ) | |
2861 | return m_text->CanRedo(); | |
2862 | ||
2863 | return false; | |
2864 | } | |
2865 | ||
107defe3 JS |
2866 | bool wxComboCtrlBase::SetHint(const wxString& hint) |
2867 | { | |
2868 | m_hintText = hint; | |
2869 | bool res = true; | |
2870 | if ( m_text ) | |
2871 | res = m_text->SetHint(hint); | |
2872 | Refresh(); | |
2873 | return res; | |
2874 | } | |
2875 | ||
2876 | wxString wxComboCtrlBase::GetHint() const | |
2877 | { | |
2878 | return m_hintText; | |
2879 | } | |
2880 | ||
a57d600f | 2881 | #endif // wxUSE_COMBOCTRL |