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