suppress annoying beeps when enter is pressed in combobox and there is no default...
[wxWidgets.git] / src / msw / combobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "combobox.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_COMBOBOX
32
33 #ifndef WX_PRECOMP
34 #include "wx/settings.h"
35 #include "wx/log.h"
36 // for wxEVT_COMMAND_TEXT_ENTER
37 #include "wx/textctrl.h"
38 #endif
39
40 #include "wx/app.h"
41 #include "wx/combobox.h"
42 #include "wx/brush.h"
43 #include "wx/clipbrd.h"
44 #include "wx/msw/private.h"
45
46 #if wxUSE_TOOLTIPS
47 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
48 #include <commctrl.h>
49 #endif
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, wxControl,"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, wxControl)
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_SETFOCUS:
178 case WM_KILLFOCUS:
179 {
180 wxComboBox *combo = wxDynamicCast(win, wxComboBox);
181 if ( !combo )
182 {
183 // we can get WM_KILLFOCUS while our parent is already half
184 // destroyed and hence doesn't look like a combobx any
185 // longer, check for it to avoid bogus assert failures
186 if ( !win->IsBeingDeleted() )
187 {
188 wxFAIL_MSG( _T("should have combo as parent") );
189 }
190 }
191 else if ( combo->MSWProcessEditMsg(message, wParam, lParam) )
192 {
193 // handled by parent
194 return 0;
195 }
196 }
197 break;
198
199 case WM_GETDLGCODE:
200 {
201 wxCHECK_MSG( win, 0, _T("should have a parent") );
202
203 if ( win->GetWindowStyle() & wxPROCESS_ENTER )
204 {
205 // need to return a custom dlg code or we'll never get it
206 return DLGC_WANTMESSAGE;
207 }
208 }
209 break;
210
211 // deal with tooltips here
212 #if wxUSE_TOOLTIPS && defined(TTN_NEEDTEXT)
213 case WM_NOTIFY:
214 {
215 wxCHECK_MSG( win, 0, _T("should have a parent") );
216
217 NMHDR* hdr = (NMHDR *)lParam;
218 if ( hdr->code == TTN_NEEDTEXT )
219 {
220 wxToolTip *tooltip = win->GetToolTip();
221 if ( tooltip )
222 {
223 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
224 ttt->lpszText = (wxChar *)tooltip->GetTip().c_str();
225 }
226
227 // processed
228 return 0;
229 }
230 }
231 break;
232 #endif // wxUSE_TOOLTIPS
233 }
234
235 return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam);
236 }
237
238 // ----------------------------------------------------------------------------
239 // wxComboBox callbacks
240 // ----------------------------------------------------------------------------
241
242 WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
243 {
244 // handle WM_CTLCOLOR messages from our EDIT control to be able to set its
245 // colour correctly (to be the same as our own one)
246 switch ( nMsg )
247 {
248 case CB_SETCURSEL:
249 // Selection was set with SetSelection. Update the value too.
250 if ((int)wParam > GetCount())
251 m_value = wxEmptyString;
252 else
253 m_value = GetString(wParam);
254 break;
255 }
256
257 return wxChoice::MSWWindowProc(nMsg, wParam, lParam);
258 }
259
260 bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
261 {
262 switch ( msg )
263 {
264 case WM_CHAR:
265 // for compatibility with wxTextCtrl, generate a special message
266 // when Enter is pressed
267 if ( wParam == VK_RETURN )
268 {
269 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
270 InitCommandEvent(event);
271 event.SetString(GetValue());
272 event.SetInt(GetSelection());
273 if ( ProcessCommand(event) )
274 {
275 // don't let the event through to the native control
276 // because it doesn't need it and may generate an annoying
277 // beep if it gets it
278 return true;
279 }
280 }
281
282 return HandleChar(wParam, lParam, true /* isASCII */);
283
284 case WM_KEYDOWN:
285 return HandleKeyDown(wParam, lParam);
286
287 case WM_KEYUP:
288 return HandleKeyUp(wParam, lParam);
289
290 case WM_SETFOCUS:
291 return HandleSetFocus((WXHWND)wParam);
292
293 case WM_KILLFOCUS:
294 return HandleKillFocus((WXHWND)wParam);
295 }
296
297 return false;
298 }
299
300 bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
301 {
302 wxString value;
303 int sel = -1;
304 switch ( param )
305 {
306 case CBN_SELCHANGE:
307 sel = GetSelection();
308
309 // somehow we get 2 CBN_SELCHANGE events with the same index when
310 // the user selects an item in the combobox -- ignore duplicates
311 if ( sel > -1 && sel != m_selectionOld )
312 {
313 m_selectionOld = sel;
314
315 // GetValue() would still return the old value from here but
316 // according to the docs we should return the new value if the
317 // user calls it in his event handler, so update internal
318 // m_value
319 m_value = GetString(sel);
320
321 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
322 event.SetInt(sel);
323 event.SetEventObject(this);
324 event.SetString(m_value);
325 ProcessCommand(event);
326 }
327 else // no valid selection
328 {
329 m_selectionOld = sel;
330
331 // hence no EVT_TEXT neither
332 break;
333 }
334
335 // fall through: for compability with wxGTK, also send the text
336 // update event when the selection changes (this also seems more
337 // logical as the text does change)
338
339 case CBN_EDITCHANGE:
340 {
341 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
342
343 // if sel != -1, value was initialized above (and we can't use
344 // GetValue() here as it would return the old selection and we
345 // want the new one)
346 if ( sel == -1 )
347 {
348 m_value = wxGetWindowText(GetHwnd());
349 }
350 else // we're synthesizing text updated event from sel change
351 {
352 // We need to retrieve the current selection because the
353 // user may have changed it in the previous handler (for
354 // CBN_SELCHANGE above).
355 sel = GetSelection();
356 if ( sel > -1 )
357 {
358 m_value = GetString(sel);
359 }
360 }
361
362 event.SetString(m_value);
363 event.SetEventObject(this);
364 ProcessCommand(event);
365 }
366 break;
367 }
368
369 // there is no return value for the CBN_ notifications, so always return
370 // false from here to pass the message to DefWindowProc()
371 return false;
372 }
373
374 WXHWND wxComboBox::GetEditHWND() const
375 {
376 // this function should not be called for wxCB_READONLY controls, it is
377 // the callers responsability to check this
378 wxASSERT_MSG( !(GetWindowStyle() & wxCB_READONLY),
379 _T("read-only combobox doesn't have any edit control") );
380
381 POINT pt;
382 pt.x = pt.y = 4;
383 HWND hwndEdit = ::ChildWindowFromPoint(GetHwnd(), pt);
384 if ( !hwndEdit || hwndEdit == GetHwnd() )
385 {
386 wxFAIL_MSG(_T("not read only combobox without edit control?"));
387 }
388
389 return (WXHWND)hwndEdit;
390 }
391
392 // ----------------------------------------------------------------------------
393 // wxComboBox creation
394 // ----------------------------------------------------------------------------
395
396 bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
397 const wxString& value,
398 const wxPoint& pos,
399 const wxSize& size,
400 int n, const wxString choices[],
401 long style,
402 const wxValidator& validator,
403 const wxString& name)
404 {
405 // pretend that wxComboBox is hidden while it is positioned and resized and
406 // show it only right before leaving this method because otherwise there is
407 // some noticeable flicker while the control rearranges itself
408 m_isShown = false;
409
410 if ( !CreateAndInit(parent, id, pos, size, n, choices, style,
411 validator, name) )
412 return false;
413
414 // we shouldn't call SetValue() for an empty string because this would
415 // (correctly) result in an assert with a read only combobox and is useless
416 // for the other ones anyhow
417 if ( !value.empty() )
418 SetValue(value);
419
420 // a (not read only) combobox is, in fact, 2 controls: the combobox itself
421 // and an edit control inside it and if we want to catch events from this
422 // edit control, we must subclass it as well
423 if ( !(style & wxCB_READONLY) )
424 {
425 gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(),
426 wxComboEditWndProc);
427 }
428
429 // and finally, show the control
430 Show(true);
431
432 return true;
433 }
434
435 bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
436 const wxString& value,
437 const wxPoint& pos,
438 const wxSize& size,
439 const wxArrayString& choices,
440 long style,
441 const wxValidator& validator,
442 const wxString& name)
443 {
444 wxCArrayString chs(choices);
445 return Create(parent, id, value, pos, size, chs.GetCount(),
446 chs.GetStrings(), style, validator, name);
447 }
448
449 WXDWORD wxComboBox::MSWGetStyle(long style, WXDWORD *exstyle) const
450 {
451 // we never have an external border
452 WXDWORD msStyle = wxChoice::MSWGetStyle
453 (
454 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
455 );
456
457 // remove the style always added by wxChoice
458 msStyle &= ~CBS_DROPDOWNLIST;
459
460 if ( style & wxCB_READONLY )
461 msStyle |= CBS_DROPDOWNLIST;
462 #ifndef __WXWINCE__
463 else if ( style & wxCB_SIMPLE )
464 msStyle |= CBS_SIMPLE; // A list (shown always) and edit control
465 #endif
466 else
467 msStyle |= CBS_DROPDOWN;
468
469 // there is no reason to not always use CBS_AUTOHSCROLL, so do use it
470 msStyle |= CBS_AUTOHSCROLL;
471
472 // NB: we used to also add CBS_NOINTEGRALHEIGHT here but why?
473
474 return msStyle;
475 }
476
477 // ----------------------------------------------------------------------------
478 // wxComboBox text control-like methods
479 // ----------------------------------------------------------------------------
480
481 void wxComboBox::SetValue(const wxString& value)
482 {
483 if ( HasFlag(wxCB_READONLY) )
484 SetStringSelection(value);
485 else
486 SetWindowText(GetHwnd(), value.c_str());
487
488 m_value = value;
489 m_selectionOld = GetSelection();
490 }
491
492 // Clipboard operations
493 void wxComboBox::Copy()
494 {
495 SendMessage(GetHwnd(), WM_COPY, 0, 0L);
496 }
497
498 void wxComboBox::Cut()
499 {
500 SendMessage(GetHwnd(), WM_CUT, 0, 0L);
501 }
502
503 void wxComboBox::Paste()
504 {
505 SendMessage(GetHwnd(), WM_PASTE, 0, 0L);
506 }
507
508 void wxComboBox::Undo()
509 {
510 if (CanUndo())
511 {
512 HWND hEditWnd = (HWND) GetEditHWND() ;
513 if ( hEditWnd )
514 ::SendMessage(hEditWnd, EM_UNDO, 0, 0);
515 }
516 }
517
518 void wxComboBox::Redo()
519 {
520 if (CanUndo())
521 {
522 // Same as Undo, since Undo undoes the undo, i.e. a redo.
523 HWND hEditWnd = (HWND) GetEditHWND() ;
524 if ( hEditWnd )
525 ::SendMessage(hEditWnd, EM_UNDO, 0, 0);
526 }
527 }
528
529 void wxComboBox::SelectAll()
530 {
531 SetSelection(0, GetLastPosition());
532 }
533
534 bool wxComboBox::CanUndo() const
535 {
536 HWND hEditWnd = (HWND) GetEditHWND() ;
537 if ( hEditWnd )
538 return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0;
539 else
540 return false;
541 }
542
543 bool wxComboBox::CanRedo() const
544 {
545 HWND hEditWnd = (HWND) GetEditHWND() ;
546 if ( hEditWnd )
547 return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0;
548 else
549 return false;
550 }
551
552 bool wxComboBox::HasSelection() const
553 {
554 long from, to;
555 GetSelection(&from, &to);
556 return from != to;
557 }
558
559 bool wxComboBox::CanCopy() const
560 {
561 // Can copy if there's a selection
562 return HasSelection();
563 }
564
565 bool wxComboBox::CanCut() const
566 {
567 return CanCopy() && IsEditable();
568 }
569
570 bool wxComboBox::CanPaste() const
571 {
572 if ( !IsEditable() )
573 return false;
574
575 // Standard edit control: check for straight text on clipboard
576 if ( !::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
577 return false;
578
579 bool isTextAvailable = ::IsClipboardFormatAvailable(CF_TEXT) != 0;
580 ::CloseClipboard();
581
582 return isTextAvailable;
583 }
584
585 bool wxComboBox::IsEditable() const
586 {
587 return !HasFlag(wxCB_READONLY);
588 }
589
590 void wxComboBox::SetEditable(bool WXUNUSED(editable))
591 {
592 // Can't implement in MSW?
593 // HWND hWnd = GetHwnd();
594 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
595 }
596
597 void wxComboBox::SetInsertionPoint(long pos)
598 {
599 if ( GetWindowStyle() & wxCB_READONLY )
600 return;
601
602 #ifdef __WIN32__
603 HWND hWnd = GetHwnd();
604 ::SendMessage(hWnd, CB_SETEDITSEL, 0, MAKELPARAM(pos, pos));
605 HWND hEditWnd = (HWND) GetEditHWND() ;
606 if ( hEditWnd )
607 {
608 // Scroll insertion point into view
609 SendMessage(hEditWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
610 // Why is this necessary? (Copied from wxTextCtrl::SetInsertionPoint)
611 SendMessage(hEditWnd, EM_REPLACESEL, 0, (LPARAM) wxEmptyString);
612 }
613 #endif // __WIN32__
614 }
615
616 void wxComboBox::SetInsertionPointEnd()
617 {
618 // setting insertion point doesn't make sense for read only comboboxes
619 if ( !(GetWindowStyle() & wxCB_READONLY) )
620 {
621 long pos = GetLastPosition();
622 SetInsertionPoint(pos);
623 }
624 }
625
626 long wxComboBox::GetInsertionPoint() const
627 {
628 #ifdef __WIN32__
629 DWORD Pos=(DWORD)SendMessage(GetHwnd(), CB_GETEDITSEL, 0, 0L);
630 return Pos&0xFFFF;
631 #else
632 return 0;
633 #endif
634 }
635
636 long wxComboBox::GetLastPosition() const
637 {
638 HWND hEditWnd = (HWND) GetEditHWND();
639
640 // Get number of characters in the last (only) line. We'll add this to the character
641 // index for the last line, 1st position.
642 int lineLength = (int)SendMessage(hEditWnd, EM_LINELENGTH, (WPARAM) 0, (LPARAM)0L);
643
644 return (long)(lineLength);
645 }
646
647 void wxComboBox::Replace(long from, long to, const wxString& value)
648 {
649 #if wxUSE_CLIPBOARD
650 Remove(from, to);
651
652 // Now replace with 'value', by pasting.
653 wxSetClipboardData(wxDF_TEXT, (wxObject *)(const wxChar *)value, 0, 0);
654
655 // Paste into edit control
656 SendMessage(GetHwnd(), WM_PASTE, (WPARAM)0, (LPARAM)0L);
657 #endif
658 }
659
660 void wxComboBox::Remove(long from, long to)
661 {
662 // Set selection and remove it
663 SetSelection(from, to);
664 SendMessage(GetHwnd(), WM_CUT, (WPARAM)0, (LPARAM)0);
665 }
666
667 void wxComboBox::SetSelection(long from, long to)
668 {
669 HWND hWnd = GetHwnd();
670 long fromChar = from;
671 long toChar = to;
672 // if from and to are both -1, it means
673 // (in wxWidgets) that all text should be selected.
674 // This translates into Windows convention
675 if ((from == -1) && (to == -1))
676 {
677 fromChar = 0;
678 toChar = -1;
679 }
680
681 if ( SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar)) == CB_ERR )
682 {
683 wxLogDebug(_T("CB_SETEDITSEL failed"));
684 }
685 }
686
687 void wxComboBox::GetSelection(long* from, long* to) const
688 {
689 DWORD dwStart, dwEnd;
690 ::SendMessage(GetHwnd(), CB_GETEDITSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
691
692 *from = dwStart;
693 *to = dwEnd;
694 }
695
696 int wxComboBox::GetSelection() const
697 {
698 return wxChoice::GetSelection();
699 }
700
701 // ----------------------------------------------------------------------------
702 // standard event handling
703 // ----------------------------------------------------------------------------
704
705 void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
706 {
707 Cut();
708 }
709
710 void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event))
711 {
712 Copy();
713 }
714
715 void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event))
716 {
717 Paste();
718 }
719
720 void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event))
721 {
722 Undo();
723 }
724
725 void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
726 {
727 Redo();
728 }
729
730 void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
731 {
732 long from, to;
733 GetSelection(& from, & to);
734 if (from != -1 && to != -1)
735 Remove(from, to);
736 }
737
738 void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
739 {
740 SetSelection(-1, -1);
741 }
742
743 void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
744 {
745 event.Enable( CanCut() );
746 }
747
748 void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event)
749 {
750 event.Enable( CanCopy() );
751 }
752
753 void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
754 {
755 event.Enable( CanPaste() );
756 }
757
758 void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
759 {
760 event.Enable( CanUndo() );
761 }
762
763 void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
764 {
765 event.Enable( CanRedo() );
766 }
767
768 void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
769 {
770 event.Enable(HasSelection() && IsEditable()) ;
771 }
772
773 void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
774 {
775 event.Enable(GetLastPosition() > 0);
776 }
777
778 #endif // wxUSE_COMBOBOX
779