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