]> git.saurik.com Git - wxWidgets.git/blame - src/msw/combobox.cpp
wxMSW: return correct value from wxMessageDialog::GetReturnCode().
[wxWidgets.git] / src / msw / combobox.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
8e25c198 2// Name: src/msw/combobox.cpp
2bda0e17
KB
3// Purpose: wxComboBox class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
6c9a19aa 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
2bda0e17
KB
9/////////////////////////////////////////////////////////////////////////////
10
f6bcfd97
BP
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
2bda0e17
KB
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
fddfd9e1 23 #pragma hdrstop
2bda0e17
KB
24#endif
25
af79c52d
VZ
26#if wxUSE_COMBOBOX
27
670f9935
WS
28#include "wx/combobox.h"
29
2bda0e17 30#ifndef WX_PRECOMP
57bd4c60 31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
fddfd9e1
VZ
32 #include "wx/settings.h"
33 #include "wx/log.h"
ce7fe42e 34 // for wxEVT_TEXT_ENTER
2b5f62a0 35 #include "wx/textctrl.h"
670f9935 36 #include "wx/app.h"
c64755ed 37 #include "wx/brush.h"
2bda0e17
KB
38#endif
39
2bda0e17 40#include "wx/clipbrd.h"
428f8b06 41#include "wx/wupdlock.h"
2bda0e17
KB
42#include "wx/msw/private.h"
43
63f7d502
VZ
44#if wxUSE_UXTHEME
45 #include "wx/msw/uxtheme.h"
46#endif
47
f6bcfd97 48#if wxUSE_TOOLTIPS
f6bcfd97
BP
49 #include "wx/tooltip.h"
50#endif // wxUSE_TOOLTIPS
51
52// ----------------------------------------------------------------------------
53// wxWin macros
54// ----------------------------------------------------------------------------
55
150e31d2
JS
56BEGIN_EVENT_TABLE(wxComboBox, wxControl)
57 EVT_MENU(wxID_CUT, wxComboBox::OnCut)
58 EVT_MENU(wxID_COPY, wxComboBox::OnCopy)
59 EVT_MENU(wxID_PASTE, wxComboBox::OnPaste)
60 EVT_MENU(wxID_UNDO, wxComboBox::OnUndo)
61 EVT_MENU(wxID_REDO, wxComboBox::OnRedo)
62 EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete)
63 EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll)
64
65 EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut)
66 EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy)
67 EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste)
68 EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo)
69 EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo)
70 EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete)
71 EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll)
72END_EVENT_TABLE()
73
f6bcfd97
BP
74// ----------------------------------------------------------------------------
75// function prototypes
76// ----------------------------------------------------------------------------
77
78LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
79 UINT message,
80 WPARAM wParam,
81 LPARAM lParam);
82
83// ---------------------------------------------------------------------------
84// global vars
85// ---------------------------------------------------------------------------
86
87// the pointer to standard radio button wnd proc
975b6bcf 88static WNDPROC gs_wndprocEdit = (WNDPROC)NULL;
f6bcfd97
BP
89
90// ============================================================================
91// implementation
92// ============================================================================
93
75aaa4c5
VZ
94namespace
95{
96
97// Check if the given message should be forwarded from the edit control which
98// is part of the combobox to wxComboBox itself. All messages generating the
99// events that the code using wxComboBox could be interested in must be
100// forwarded.
101bool ShouldForwardFromEditToCombo(UINT message)
102{
103 switch ( message )
104 {
105 case WM_KEYUP:
106 case WM_KEYDOWN:
107 case WM_CHAR:
108 case WM_SYSCHAR:
109 case WM_SYSKEYDOWN:
110 case WM_SYSKEYUP:
111 case WM_SETFOCUS:
112 case WM_KILLFOCUS:
113 case WM_CUT:
114 case WM_COPY:
115 case WM_PASTE:
116 return true;
117 }
118
119 return false;
120}
121
122} // anonymous namespace
123
f6bcfd97
BP
124// ----------------------------------------------------------------------------
125// wnd proc for subclassed edit control
126// ----------------------------------------------------------------------------
127
128LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
129 UINT message,
130 WPARAM wParam,
131 LPARAM lParam)
132{
133 HWND hwndCombo = ::GetParent(hWnd);
134 wxWindow *win = wxFindWinFromHandle((WXHWND)hwndCombo);
135
75aaa4c5 136 if ( ShouldForwardFromEditToCombo(message) )
f6bcfd97 137 {
75aaa4c5
VZ
138 wxComboBox *combo = wxDynamicCast(win, wxComboBox);
139 if ( !combo )
140 {
141 // we can get WM_KILLFOCUS while our parent is already half
142 // destroyed and hence doesn't look like a combobx any
143 // longer, check for it to avoid bogus assert failures
144 if ( !win->IsBeingDeleted() )
f6bcfd97 145 {
75aaa4c5 146 wxFAIL_MSG( wxT("should have combo as parent") );
f6bcfd97 147 }
75aaa4c5
VZ
148 }
149 else if ( combo->MSWProcessEditMsg(message, wParam, lParam) )
150 {
151 // handled by parent
152 return 0;
153 }
154 }
155 else if ( message == WM_GETDLGCODE )
156 {
157 wxCHECK_MSG( win, 0, wxT("should have a parent") );
f6bcfd97 158
75aaa4c5
VZ
159 if ( win->GetWindowStyle() & wxTE_PROCESS_ENTER )
160 {
161 // need to return a custom dlg code or we'll never get it
162 return DLGC_WANTMESSAGE;
163 }
f6bcfd97
BP
164 }
165
166 return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam);
167}
168
f6bcfd97 169// ----------------------------------------------------------------------------
3a7d5f7c 170// wxComboBox callbacks
f6bcfd97
BP
171// ----------------------------------------------------------------------------
172
c140b7e7 173WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
3a7d5f7c 174{
5301d1f7
VZ
175 // TODO: handle WM_CTLCOLOR messages from our EDIT control to be able to
176 // set its colour correctly (to be the same as our own one)
682214d5 177
3a7d5f7c
VZ
178 switch ( nMsg )
179 {
682214d5 180 case WM_SIZE:
3bce55ac
JS
181 // wxStaticBox can generate this message, when modifying the control's style.
182 // This causes the content of the combobox to be selected, for some reason.
183 case WM_STYLECHANGED:
5301d1f7
VZ
184 {
185 // combobox selection sometimes spontaneously changes when its
186 // size changes, restore it to the old value if necessary
e9717bd5
VZ
187 if ( !GetEditHWNDIfAvailable() )
188 break;
189
5301d1f7
VZ
190 long fromOld, toOld;
191 GetSelection(&fromOld, &toOld);
428f8b06
VZ
192
193 // if an editable combobox has a not empty text not from the
194 // list, it tries to autocomplete it from the list when it is
195 // resized, but we don't want this to happen as it doesn't seem
196 // to make any sense, so we forcefully restore the old text
197 wxString textOld;
198 if ( !HasFlag(wxCB_READONLY) && GetCurrentSelection() == -1 )
199 textOld = GetValue();
200
201 // eliminate flickering during following hacks
202 wxWindowUpdateLocker lock(this);
203
5301d1f7 204 WXLRESULT result = wxChoice::MSWWindowProc(nMsg, wParam, lParam);
682214d5 205
428f8b06
VZ
206 if ( !textOld.empty() && GetValue() != textOld )
207 SetLabel(textOld);
208
5301d1f7
VZ
209 long fromNew, toNew;
210 GetSelection(&fromNew, &toNew);
682214d5 211
5301d1f7
VZ
212 if ( fromOld != fromNew || toOld != toNew )
213 {
214 SetSelection(fromOld, toOld);
215 }
682214d5 216
5301d1f7
VZ
217 return result;
218 }
3a7d5f7c
VZ
219 }
220
5301d1f7 221 return wxChoice::MSWWindowProc(nMsg, wParam, lParam);
3a7d5f7c
VZ
222}
223
f6bcfd97
BP
224bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
225{
226 switch ( msg )
227 {
228 case WM_CHAR:
2b5f62a0
VZ
229 // for compatibility with wxTextCtrl, generate a special message
230 // when Enter is pressed
231 if ( wParam == VK_RETURN )
232 {
a2634d81
RR
233 if (SendMessage(GetHwnd(), CB_GETDROPPEDSTATE, 0, 0))
234 return false;
f4322df6 235
ce7fe42e 236 wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId);
593ac33e
VZ
237
238 const int sel = GetSelection();
239 event.SetInt(sel);
2b5f62a0 240 event.SetString(GetValue());
593ac33e
VZ
241 InitCommandEventWithItems(event, sel);
242
ffb1629f
VZ
243 if ( ProcessCommand(event) )
244 {
245 // don't let the event through to the native control
246 // because it doesn't need it and may generate an annoying
247 // beep if it gets it
248 return true;
249 }
2b5f62a0 250 }
75aaa4c5 251 // fall through, WM_CHAR is one of the message we should forward.
2b5f62a0 252
75aaa4c5
VZ
253 default:
254 if ( ShouldForwardFromEditToCombo(msg) )
255 {
256 // For all the messages forward from the edit control the
257 // result is not used.
258 WXLRESULT result;
259 return MSWHandleMessage(&result, msg, wParam, lParam);
260 }
f6bcfd97
BP
261 }
262
02b7b6b0 263 return false;
f6bcfd97
BP
264}
265
6ba93d23 266bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
2bda0e17 267{
fddfd9e1 268 int sel = -1;
7d90194c
VZ
269 wxString value;
270
cd0b1709 271 switch ( param )
8c1c5302 272 {
ae3b1487
VZ
273 case CBN_DROPDOWN:
274 // remember the last selection, just as wxChoice does
275 m_lastAcceptedSelection = GetCurrentSelection();
8933fbc6 276 {
ce7fe42e 277 wxCommandEvent event(wxEVT_COMBOBOX_DROPDOWN, GetId());
8933fbc6
VZ
278 event.SetEventObject(this);
279 ProcessCommand(event);
280 }
281 break;
65676a28 282
8933fbc6 283 case CBN_CLOSEUP:
65676a28
VZ
284 // Do the same thing as in wxChoice but using different event type.
285 if ( m_pendingSelection != wxID_NONE )
286 {
ce7fe42e 287 SendSelectionChangedEvent(wxEVT_COMBOBOX);
65676a28
VZ
288 m_pendingSelection = wxID_NONE;
289 }
8933fbc6 290 {
ce7fe42e 291 wxCommandEvent event(wxEVT_COMBOBOX_CLOSEUP, GetId());
8933fbc6
VZ
292 event.SetEventObject(this);
293 ProcessCommand(event);
294 }
ae3b1487 295 break;
65676a28 296
78a87a5d 297 case CBN_SELENDOK:
8e25c198 298#ifndef __SMARTPHONE__
7d90194c
VZ
299 // we need to reset this to prevent the selection from being undone
300 // by wxChoice, see wxChoice::MSWCommand() and comments there
301 m_lastAcceptedSelection = wxID_NONE;
8e25c198 302#endif
13bcc348 303
7d90194c
VZ
304 // set these variables so that they could be also fixed in
305 // CBN_EDITCHANGE below
306 sel = GetSelection();
f5a45ee2 307 value = GetStringSelection();
d0b6344d
VZ
308
309 // this string is going to become the new combobox value soon but
310 // we need it to be done right now, otherwise the event handler
311 // could get a wrong value when it calls our GetValue()
017dc06b 312 ::SetWindowText(GetHwnd(), value.t_str());
d0b6344d 313
ce7fe42e 314 SendSelectionChangedEvent(wxEVT_COMBOBOX);
fddfd9e1 315
7bc74071 316 // fall through: for compatibility with wxGTK, also send the text
fddfd9e1
VZ
317 // update event when the selection changes (this also seems more
318 // logical as the text does change)
29006414 319
cd0b1709 320 case CBN_EDITCHANGE:
b7bfef38 321 if ( m_allowTextEvents )
cd0b1709 322 {
ce7fe42e 323 wxCommandEvent event(wxEVT_TEXT, GetId());
3adc70bf 324
7d90194c 325 // if sel != -1, value was already initialized above
7ba166dd 326 if ( sel == -1 )
3adc70bf 327 {
7d90194c 328 value = wxGetWindowText(GetHwnd());
3adc70bf
VZ
329 }
330
7d90194c 331 event.SetString(value);
593ac33e
VZ
332 InitCommandEventWithItems(event, sel);
333
0ef2ebba 334 ProcessCommand(event);
cd0b1709
VZ
335 }
336 break;
6ba93d23
VZ
337
338 default:
339 return wxChoice::MSWCommand(param, id);
cd0b1709 340 }
29006414 341
7d90194c 342 // skip wxChoice version as it would generate its own events for
ae3b1487 343 // CBN_SELENDOK and also interfere with our handling of CBN_DROPDOWN
8cc5e8cf 344 return true;
2bda0e17
KB
345}
346
90ac8b50
RR
347bool wxComboBox::MSWShouldPreProcessMessage(WXMSG *pMsg)
348{
349 // prevent command accelerators from stealing editing
350 // hotkeys when we have the focus
351 if (wxIsCtrlDown())
352 {
353 WPARAM vkey = pMsg->wParam;
6b54668b 354
90ac8b50
RR
355 switch (vkey)
356 {
357 case 'C':
358 case 'V':
359 case 'X':
360 case VK_INSERT:
361 case VK_DELETE:
362 case VK_HOME:
363 case VK_END:
364 return false;
365 }
366 }
6b54668b 367
90ac8b50
RR
368 return wxChoice::MSWShouldPreProcessMessage(pMsg);
369}
370
e9717bd5
VZ
371WXHWND wxComboBox::GetEditHWNDIfAvailable() const
372{
1b6010d8
VZ
373 // FIXME-VC6: Only VC6 needs this guard, see WINVER definition in
374 // include/wx/msw/wrapwin.h
375#if defined(WINVER) && WINVER >= 0x0500
df74e2d2
VZ
376 WinStruct<COMBOBOXINFO> info;
377 if ( MSWGetComboBoxInfo(&info) )
e558f953 378 return info.hwndItem;
1b6010d8 379#endif // WINVER >= 0x0500
e558f953
JS
380
381 if (HasFlag(wxCB_SIMPLE))
382 {
383 POINT pt;
384 pt.x = pt.y = 4;
385 return (WXHWND) ::ChildWindowFromPoint(GetHwnd(), pt);
386 }
fe56156f 387
1690c2ce
JS
388 // notice that a slightly safer alternative could be to use FindWindowEx()
389 // but it's not available under WinCE so just take the first child for now
390 // to keep one version of the code for all platforms and fix it later if
391 // problems are discovered
392
74052fe8
VZ
393 // we assume that the only child of the combobox is the edit window
394 return (WXHWND)::GetWindow(GetHwnd(), GW_CHILD);
e9717bd5
VZ
395}
396
f6bcfd97
BP
397WXHWND wxComboBox::GetEditHWND() const
398{
399 // this function should not be called for wxCB_READONLY controls, it is
e9717bd5 400 // the callers responsibility to check this
fa2f57be 401 wxASSERT_MSG( !HasFlag(wxCB_READONLY),
9a83f860 402 wxT("read-only combobox doesn't have any edit control") );
f6bcfd97 403
e9717bd5 404 WXHWND hWndEdit = GetEditHWNDIfAvailable();
9a83f860 405 wxASSERT_MSG( hWndEdit, wxT("combobox without edit control?") );
f6bcfd97 406
e9717bd5 407 return hWndEdit;
f6bcfd97
BP
408}
409
63f7d502
VZ
410wxWindow *wxComboBox::GetEditableWindow()
411{
412 wxASSERT_MSG( !HasFlag(wxCB_READONLY),
9a83f860 413 wxT("read-only combobox doesn't have any edit control") );
63f7d502
VZ
414
415 return this;
416}
417
71e57cd6
VZ
418// ----------------------------------------------------------------------------
419// wxComboBox creation
420// ----------------------------------------------------------------------------
421
debe6624 422bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
c085e333
VZ
423 const wxString& value,
424 const wxPoint& pos,
425 const wxSize& size,
426 int n, const wxString choices[],
427 long style,
428 const wxValidator& validator,
429 const wxString& name)
2bda0e17 430{
bdf5c30d
VZ
431 // pretend that wxComboBox is hidden while it is positioned and resized and
432 // show it only right before leaving this method because otherwise there is
433 // some noticeable flicker while the control rearranges itself
02b7b6b0 434 m_isShown = false;
bdf5c30d 435
71e57cd6
VZ
436 if ( !CreateAndInit(parent, id, pos, size, n, choices, style,
437 validator, name) )
02b7b6b0 438 return false;
f6bcfd97 439
6341d824
VZ
440 // we shouldn't call SetValue() for an empty string because this would
441 // (correctly) result in an assert with a read only combobox and is useless
442 // for the other ones anyhow
443 if ( !value.empty() )
b9b8a2b5 444 SetValue(value);
db34b147 445
f6bcfd97
BP
446 // a (not read only) combobox is, in fact, 2 controls: the combobox itself
447 // and an edit control inside it and if we want to catch events from this
448 // edit control, we must subclass it as well
449 if ( !(style & wxCB_READONLY) )
450 {
94972183 451 gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(), wxComboEditWndProc);
f6bcfd97 452 }
2bda0e17 453
bdf5c30d 454 // and finally, show the control
02b7b6b0 455 Show(true);
bdf5c30d 456
02b7b6b0 457 return true;
2bda0e17
KB
458}
459
584ad2a3
MB
460bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
461 const wxString& value,
462 const wxPoint& pos,
463 const wxSize& size,
464 const wxArrayString& choices,
465 long style,
466 const wxValidator& validator,
467 const wxString& name)
468{
469 wxCArrayString chs(choices);
470 return Create(parent, id, value, pos, size, chs.GetCount(),
471 chs.GetStrings(), style, validator, name);
472}
473
71e57cd6
VZ
474WXDWORD wxComboBox::MSWGetStyle(long style, WXDWORD *exstyle) const
475{
476 // we never have an external border
477 WXDWORD msStyle = wxChoice::MSWGetStyle
478 (
479 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
480 );
481
1dfd425a
VZ
482 // usually WS_TABSTOP is added by wxControl::MSWGetStyle() but as we're
483 // created hidden (see Create() above), it is not done for us but we still
484 // want to have this style
485 msStyle |= WS_TABSTOP;
486
71e57cd6
VZ
487 // remove the style always added by wxChoice
488 msStyle &= ~CBS_DROPDOWNLIST;
489
490 if ( style & wxCB_READONLY )
491 msStyle |= CBS_DROPDOWNLIST;
492#ifndef __WXWINCE__
493 else if ( style & wxCB_SIMPLE )
494 msStyle |= CBS_SIMPLE; // A list (shown always) and edit control
495#endif
496 else
497 msStyle |= CBS_DROPDOWN;
498
499 // there is no reason to not always use CBS_AUTOHSCROLL, so do use it
500 msStyle |= CBS_AUTOHSCROLL;
501
502 // NB: we used to also add CBS_NOINTEGRALHEIGHT here but why?
503
504 return msStyle;
505}
506
507// ----------------------------------------------------------------------------
508// wxComboBox text control-like methods
509// ----------------------------------------------------------------------------
510
e9717bd5
VZ
511wxString wxComboBox::GetValue() const
512{
513 return HasFlag(wxCB_READONLY) ? GetStringSelection()
514 : wxTextEntry::GetValue();
515}
516
2bda0e17
KB
517void wxComboBox::SetValue(const wxString& value)
518{
2b5f62a0
VZ
519 if ( HasFlag(wxCB_READONLY) )
520 SetStringSelection(value);
b38f3ff3 521 else
fa2f57be 522 wxTextEntry::SetValue(value);
150e31d2
JS
523}
524
e6a84162
VZ
525void wxComboBox::Clear()
526{
527 wxChoice::Clear();
528 if ( !HasFlag(wxCB_READONLY) )
529 wxTextEntry::Clear();
530}
531
5ddb3b8c
VZ
532bool wxComboBox::ContainsHWND(WXHWND hWnd) const
533{
534 return hWnd == GetEditHWNDIfAvailable();
535}
536
e9717bd5
VZ
537void wxComboBox::GetSelection(long *from, long *to) const
538{
539 if ( !HasFlag(wxCB_READONLY) )
540 {
541 wxTextEntry::GetSelection(from, to);
542 }
543 else // text selection doesn't make sense for read only comboboxes
544 {
545 if ( from )
546 *from = -1;
547 if ( to )
548 *to = -1;
549 }
550}
551
150e31d2
JS
552bool wxComboBox::IsEditable() const
553{
fa2f57be 554 return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable();
3f5ca6b1
RN
555}
556
150e31d2
JS
557// ----------------------------------------------------------------------------
558// standard event handling
559// ----------------------------------------------------------------------------
560
561void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
562{
563 Cut();
564}
565
566void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event))
567{
568 Copy();
569}
570
571void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event))
572{
573 Paste();
574}
575
576void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event))
577{
578 Undo();
579}
580
581void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
582{
583 Redo();
584}
585
586void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
587{
5a25f858 588 RemoveSelection();
150e31d2
JS
589}
590
591void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
592{
e976429d 593 SelectAll();
150e31d2
JS
594}
595
596void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
597{
598 event.Enable( CanCut() );
599}
600
601void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event)
602{
603 event.Enable( CanCopy() );
604}
605
606void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
607{
608 event.Enable( CanPaste() );
609}
610
611void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
612{
c0e15042 613 event.Enable( IsEditable() && CanUndo() );
150e31d2
JS
614}
615
616void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
617{
c0e15042 618 event.Enable( IsEditable() && CanRedo() );
150e31d2
JS
619}
620
621void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
622{
6b54668b 623 event.Enable(IsEditable() && HasSelection());
150e31d2
JS
624}
625
626void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
627{
e976429d 628 event.Enable(IsEditable() && !wxTextEntry::IsEmpty());
150e31d2
JS
629}
630
d6b9cc87
VZ
631#if wxUSE_TOOLTIPS
632
633void wxComboBox::DoSetToolTip(wxToolTip *tip)
634{
635 wxChoice::DoSetToolTip(tip);
636
637 if ( tip && !HasFlag(wxCB_READONLY) )
f7dd07f6 638 tip->AddOtherWindow(GetEditHWND());
d6b9cc87
VZ
639}
640
641#endif // wxUSE_TOOLTIPS
642
63f7d502
VZ
643#if wxUSE_UXTHEME
644
645bool wxComboBox::SetHint(const wxString& hintOrig)
646{
647 wxString hint(hintOrig);
648 if ( wxUxThemeEngine::GetIfActive() )
649 {
650 // under XP (but not Vista) there is a bug in cue banners
651 // implementation for combobox edit control: the first character is
652 // partially chopped off, so prepend a space to make it fully visible
653 hint.insert(0, " ");
654 }
655
656 return wxTextEntry::SetHint(hint);
657}
658
659#endif // wxUSE_UXTHEME
660
aa24f946
VZ
661wxSize wxComboBox::DoGetSizeFromTextSize(int xlen, int ylen) const
662{
663 wxSize tsize( wxChoice::DoGetSizeFromTextSize(xlen, ylen) );
664
665 if ( !HasFlag(wxCB_READONLY) )
666 {
667 // Add the margins we have previously set
668 wxPoint marg( GetMargins() );
669 marg.x = wxMax(0, marg.x);
670 marg.y = wxMax(0, marg.y);
671 tsize.IncBy( marg );
672 }
673
674 return tsize;
675}
676
71e57cd6 677#endif // wxUSE_COMBOBOX