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