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