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