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