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