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