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