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