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