removed TTN_NEEDTEXT handlers, we don't use tooltips on demand
[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/settings.h"
33 #include "wx/log.h"
34 // for wxEVT_COMMAND_TEXT_ENTER
35 #include "wx/textctrl.h"
36 #include "wx/app.h"
37 #endif
38
39 #include "wx/brush.h"
40 #include "wx/clipbrd.h"
41 #include "wx/msw/private.h"
42
43 #if wxUSE_TOOLTIPS
44 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
45 #include <commctrl.h>
46 #endif
47 #include "wx/tooltip.h"
48 #endif // wxUSE_TOOLTIPS
49
50 // ----------------------------------------------------------------------------
51 // wxWin macros
52 // ----------------------------------------------------------------------------
53
54 #if wxUSE_EXTENDED_RTTI
55 WX_DEFINE_FLAGS( wxComboBoxStyle )
56
57 wxBEGIN_FLAGS( wxComboBoxStyle )
58 // new style border flags, we put them first to
59 // use them for streaming out
60 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
61 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
62 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
63 wxFLAGS_MEMBER(wxBORDER_RAISED)
64 wxFLAGS_MEMBER(wxBORDER_STATIC)
65 wxFLAGS_MEMBER(wxBORDER_NONE)
66
67 // old style border flags
68 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
69 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
70 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
71 wxFLAGS_MEMBER(wxRAISED_BORDER)
72 wxFLAGS_MEMBER(wxSTATIC_BORDER)
73 wxFLAGS_MEMBER(wxBORDER)
74
75 // standard window styles
76 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
77 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
78 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
79 wxFLAGS_MEMBER(wxWANTS_CHARS)
80 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
81 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
82 wxFLAGS_MEMBER(wxVSCROLL)
83 wxFLAGS_MEMBER(wxHSCROLL)
84
85 wxFLAGS_MEMBER(wxCB_SIMPLE)
86 wxFLAGS_MEMBER(wxCB_SORT)
87 wxFLAGS_MEMBER(wxCB_READONLY)
88 wxFLAGS_MEMBER(wxCB_DROPDOWN)
89
90 wxEND_FLAGS( wxComboBoxStyle )
91
92 IMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxControl,"wx/combobox.h")
93
94 wxBEGIN_PROPERTIES_TABLE(wxComboBox)
95 wxEVENT_PROPERTY( Select , wxEVT_COMMAND_COMBOBOX_SELECTED , wxCommandEvent )
96 wxEVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent )
97
98 // TODO DELEGATES
99 wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
100 wxPROPERTY_COLLECTION( Choices , wxArrayString , wxString , AppendString , GetStrings , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
101 wxPROPERTY( Value ,wxString, SetValue, GetValue, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
102 wxPROPERTY( Selection ,int, SetSelection, GetSelection, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
103 wxPROPERTY_FLAGS( WindowStyle , wxComboBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
104 wxEND_PROPERTIES_TABLE()
105
106 wxBEGIN_HANDLERS_TABLE(wxComboBox)
107 wxEND_HANDLERS_TABLE()
108
109 wxCONSTRUCTOR_5( wxComboBox , wxWindow* , Parent , wxWindowID , Id , wxString , Value , wxPoint , Position , wxSize , Size )
110
111 #else
112
113 IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
114
115 #endif
116
117 BEGIN_EVENT_TABLE(wxComboBox, wxControl)
118 EVT_MENU(wxID_CUT, wxComboBox::OnCut)
119 EVT_MENU(wxID_COPY, wxComboBox::OnCopy)
120 EVT_MENU(wxID_PASTE, wxComboBox::OnPaste)
121 EVT_MENU(wxID_UNDO, wxComboBox::OnUndo)
122 EVT_MENU(wxID_REDO, wxComboBox::OnRedo)
123 EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete)
124 EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll)
125
126 EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut)
127 EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy)
128 EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste)
129 EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo)
130 EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo)
131 EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete)
132 EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll)
133 END_EVENT_TABLE()
134
135 // ----------------------------------------------------------------------------
136 // function prototypes
137 // ----------------------------------------------------------------------------
138
139 LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
140 UINT message,
141 WPARAM wParam,
142 LPARAM lParam);
143
144 // ---------------------------------------------------------------------------
145 // global vars
146 // ---------------------------------------------------------------------------
147
148 // the pointer to standard radio button wnd proc
149 static WNDPROC gs_wndprocEdit = (WNDPROC)NULL;
150
151 // ============================================================================
152 // implementation
153 // ============================================================================
154
155 // ----------------------------------------------------------------------------
156 // wnd proc for subclassed edit control
157 // ----------------------------------------------------------------------------
158
159 LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
160 UINT message,
161 WPARAM wParam,
162 LPARAM lParam)
163 {
164 HWND hwndCombo = ::GetParent(hWnd);
165 wxWindow *win = wxFindWinFromHandle((WXHWND)hwndCombo);
166
167 switch ( message )
168 {
169 // forward some messages to the combobox to generate the appropriate
170 // wxEvents from them
171 case WM_KEYUP:
172 case WM_KEYDOWN:
173 case WM_CHAR:
174 case WM_SYSCHAR:
175 case WM_SYSKEYDOWN:
176 case WM_SYSKEYUP:
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() & wxTE_PROCESS_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
212 return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam);
213 }
214
215 // ----------------------------------------------------------------------------
216 // wxComboBox callbacks
217 // ----------------------------------------------------------------------------
218
219 WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
220 {
221 // TODO: handle WM_CTLCOLOR messages from our EDIT control to be able to
222 // set its colour correctly (to be the same as our own one)
223
224 switch ( nMsg )
225 {
226 case WM_SIZE:
227 // wxStaticBox can generate this message, when modifying the control's style.
228 // This causes the content of the combobox to be selected, for some reason.
229 case WM_STYLECHANGED:
230 {
231 // combobox selection sometimes spontaneously changes when its
232 // size changes, restore it to the old value if necessary
233 long fromOld, toOld;
234 GetSelection(&fromOld, &toOld);
235 WXLRESULT result = wxChoice::MSWWindowProc(nMsg, wParam, lParam);
236
237 long fromNew, toNew;
238 GetSelection(&fromNew, &toNew);
239
240 if ( fromOld != fromNew || toOld != toNew )
241 {
242 SetSelection(fromOld, toOld);
243 }
244
245 return result;
246 }
247 }
248
249 return wxChoice::MSWWindowProc(nMsg, wParam, lParam);
250 }
251
252 bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
253 {
254 switch ( msg )
255 {
256 case WM_CHAR:
257 // for compatibility with wxTextCtrl, generate a special message
258 // when Enter is pressed
259 if ( wParam == VK_RETURN )
260 {
261 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
262 InitCommandEvent(event);
263 event.SetString(GetValue());
264 event.SetInt(GetSelection());
265 if ( ProcessCommand(event) )
266 {
267 // don't let the event through to the native control
268 // because it doesn't need it and may generate an annoying
269 // beep if it gets it
270 return true;
271 }
272 }
273 // fall through
274
275 case WM_SYSCHAR:
276 return HandleChar(wParam, lParam, true /* isASCII */);
277
278 case WM_SYSKEYDOWN:
279 case WM_KEYDOWN:
280 return HandleKeyDown(wParam, lParam);
281
282 case WM_SYSKEYUP:
283 case WM_KEYUP:
284 return HandleKeyUp(wParam, lParam);
285
286 case WM_SETFOCUS:
287 return HandleSetFocus((WXHWND)wParam);
288
289 case WM_KILLFOCUS:
290 return HandleKillFocus((WXHWND)wParam);
291 }
292
293 return false;
294 }
295
296 bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
297 {
298 int sel = -1;
299 wxString value;
300
301 switch ( param )
302 {
303 case CBN_SELENDOK:
304 #ifndef __SMARTPHONE__
305 // we need to reset this to prevent the selection from being undone
306 // by wxChoice, see wxChoice::MSWCommand() and comments there
307 m_lastAcceptedSelection = wxID_NONE;
308 #endif
309
310 // set these variables so that they could be also fixed in
311 // CBN_EDITCHANGE below
312 sel = GetSelection();
313 value = GetStringSelection();
314 {
315 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
316 event.SetEventObject(this);
317 event.SetInt(sel);
318 event.SetString(value);
319 ProcessCommand(event);
320 }
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)
325
326 case CBN_EDITCHANGE:
327 {
328 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
329 event.SetEventObject(this);
330
331 // if sel != -1, value was already initialized above
332 if ( sel == -1 )
333 {
334 value = wxGetWindowText(GetHwnd());
335 }
336
337 event.SetString(value);
338 ProcessCommand(event);
339 }
340 break;
341
342 default:
343 return wxChoice::MSWCommand(param, id);
344 }
345
346 // skip wxChoice version as it would generate its own events for
347 // CBN_SELENDOK
348 return wxControl::MSWCommand(param, id);
349 }
350
351 WXHWND wxComboBox::GetEditHWND() const
352 {
353 // this function should not be called for wxCB_READONLY controls, it is
354 // the callers responsability to check this
355 wxASSERT_MSG( !(GetWindowStyle() & wxCB_READONLY),
356 _T("read-only combobox doesn't have any edit control") );
357
358 POINT pt;
359 pt.x = pt.y = 4;
360 HWND hwndEdit = ::ChildWindowFromPoint(GetHwnd(), pt);
361 if ( !hwndEdit || hwndEdit == GetHwnd() )
362 {
363 wxFAIL_MSG(_T("not read only combobox without edit control?"));
364 }
365
366 return (WXHWND)hwndEdit;
367 }
368
369 // ----------------------------------------------------------------------------
370 // wxComboBox creation
371 // ----------------------------------------------------------------------------
372
373 bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
374 const wxString& value,
375 const wxPoint& pos,
376 const wxSize& size,
377 int n, const wxString choices[],
378 long style,
379 const wxValidator& validator,
380 const wxString& name)
381 {
382 // pretend that wxComboBox is hidden while it is positioned and resized and
383 // show it only right before leaving this method because otherwise there is
384 // some noticeable flicker while the control rearranges itself
385 m_isShown = false;
386
387 if ( !CreateAndInit(parent, id, pos, size, n, choices, style,
388 validator, name) )
389 return false;
390
391 // we shouldn't call SetValue() for an empty string because this would
392 // (correctly) result in an assert with a read only combobox and is useless
393 // for the other ones anyhow
394 if ( !value.empty() )
395 SetValue(value);
396
397 // a (not read only) combobox is, in fact, 2 controls: the combobox itself
398 // and an edit control inside it and if we want to catch events from this
399 // edit control, we must subclass it as well
400 if ( !(style & wxCB_READONLY) )
401 {
402 gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(),
403 wxComboEditWndProc);
404 }
405
406 // and finally, show the control
407 Show(true);
408
409 return true;
410 }
411
412 bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
413 const wxString& value,
414 const wxPoint& pos,
415 const wxSize& size,
416 const wxArrayString& choices,
417 long style,
418 const wxValidator& validator,
419 const wxString& name)
420 {
421 wxCArrayString chs(choices);
422 return Create(parent, id, value, pos, size, chs.GetCount(),
423 chs.GetStrings(), style, validator, name);
424 }
425
426 WXDWORD wxComboBox::MSWGetStyle(long style, WXDWORD *exstyle) const
427 {
428 // we never have an external border
429 WXDWORD msStyle = wxChoice::MSWGetStyle
430 (
431 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
432 );
433
434 // usually WS_TABSTOP is added by wxControl::MSWGetStyle() but as we're
435 // created hidden (see Create() above), it is not done for us but we still
436 // want to have this style
437 msStyle |= WS_TABSTOP;
438
439 // remove the style always added by wxChoice
440 msStyle &= ~CBS_DROPDOWNLIST;
441
442 if ( style & wxCB_READONLY )
443 msStyle |= CBS_DROPDOWNLIST;
444 #ifndef __WXWINCE__
445 else if ( style & wxCB_SIMPLE )
446 msStyle |= CBS_SIMPLE; // A list (shown always) and edit control
447 #endif
448 else
449 msStyle |= CBS_DROPDOWN;
450
451 // there is no reason to not always use CBS_AUTOHSCROLL, so do use it
452 msStyle |= CBS_AUTOHSCROLL;
453
454 // NB: we used to also add CBS_NOINTEGRALHEIGHT here but why?
455
456 return msStyle;
457 }
458
459 // ----------------------------------------------------------------------------
460 // wxComboBox text control-like methods
461 // ----------------------------------------------------------------------------
462
463 wxString wxComboBox::GetValue() const
464 {
465 return wxGetWindowText(m_hWnd);
466 }
467
468 void wxComboBox::SetValue(const wxString& value)
469 {
470 if ( HasFlag(wxCB_READONLY) )
471 SetStringSelection(value);
472 else
473 SetWindowText(GetHwnd(), value.c_str());
474 }
475
476 // Clipboard operations
477 void wxComboBox::Copy()
478 {
479 SendMessage(GetHwnd(), WM_COPY, 0, 0L);
480 }
481
482 void wxComboBox::Cut()
483 {
484 SendMessage(GetHwnd(), WM_CUT, 0, 0L);
485 }
486
487 void wxComboBox::Paste()
488 {
489 SendMessage(GetHwnd(), WM_PASTE, 0, 0L);
490 }
491
492 void wxComboBox::Undo()
493 {
494 if (CanUndo())
495 {
496 HWND hEditWnd = (HWND) GetEditHWND();
497 if ( hEditWnd )
498 ::SendMessage(hEditWnd, EM_UNDO, 0, 0);
499 }
500 }
501
502 void wxComboBox::Redo()
503 {
504 if (CanUndo())
505 {
506 // Same as Undo, since Undo undoes the undo, i.e. a redo.
507 HWND hEditWnd = (HWND) GetEditHWND();
508 if ( hEditWnd )
509 ::SendMessage(hEditWnd, EM_UNDO, 0, 0);
510 }
511 }
512
513 void wxComboBox::SelectAll()
514 {
515 SetSelection(0, GetLastPosition());
516 }
517
518 bool wxComboBox::CanUndo() const
519 {
520 if (!IsEditable())
521 return false;
522
523 HWND hEditWnd = (HWND) GetEditHWND();
524 if ( hEditWnd )
525 return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0;
526 else
527 return false;
528 }
529
530 bool wxComboBox::CanRedo() const
531 {
532 if (!IsEditable())
533 return false;
534
535 HWND hEditWnd = (HWND) GetEditHWND();
536 if ( hEditWnd )
537 return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0;
538 else
539 return false;
540 }
541
542 bool wxComboBox::HasSelection() const
543 {
544 long from, to;
545 GetSelection(&from, &to);
546 return from != to;
547 }
548
549 bool wxComboBox::CanCopy() const
550 {
551 // Can copy if there's a selection
552 return HasSelection();
553 }
554
555 bool wxComboBox::CanCut() const
556 {
557 return IsEditable() && CanCopy();
558 }
559
560 bool wxComboBox::CanPaste() const
561 {
562 if ( !IsEditable() )
563 return false;
564
565 // Standard edit control: check for straight text on clipboard
566 if ( !::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
567 return false;
568
569 bool isTextAvailable = ::IsClipboardFormatAvailable(CF_TEXT) != 0;
570 ::CloseClipboard();
571
572 return isTextAvailable;
573 }
574
575 bool wxComboBox::IsEditable() const
576 {
577 return !HasFlag(wxCB_READONLY);
578 }
579
580 void wxComboBox::SetEditable(bool WXUNUSED(editable))
581 {
582 // Can't implement in MSW?
583 // HWND hWnd = GetHwnd();
584 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
585 }
586
587 void wxComboBox::SetInsertionPoint(long pos)
588 {
589 if ( GetWindowStyle() & wxCB_READONLY )
590 return;
591
592 #ifdef __WIN32__
593 HWND hWnd = GetHwnd();
594 ::SendMessage(hWnd, CB_SETEDITSEL, 0, MAKELPARAM(pos, pos));
595 HWND hEditWnd = (HWND) GetEditHWND();
596 if ( hEditWnd )
597 {
598 // Scroll insertion point into view
599 SendMessage(hEditWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
600 // Why is this necessary? (Copied from wxTextCtrl::SetInsertionPoint)
601 SendMessage(hEditWnd, EM_REPLACESEL, 0, (LPARAM) wxEmptyString);
602 }
603 #endif // __WIN32__
604 }
605
606 void wxComboBox::SetInsertionPointEnd()
607 {
608 // setting insertion point doesn't make sense for read only comboboxes
609 if ( !(GetWindowStyle() & wxCB_READONLY) )
610 {
611 wxTextPos pos = GetLastPosition();
612 SetInsertionPoint(pos);
613 }
614 }
615
616 long wxComboBox::GetInsertionPoint() const
617 {
618 // CB_GETEDITSEL returns the index of the first character of the selection in
619 // its low-order word
620 DWORD pos= (DWORD)::SendMessage(GetHwnd(), CB_GETEDITSEL, 0, 0L);
621 return LOWORD(pos);
622 }
623
624 wxTextPos wxComboBox::GetLastPosition() const
625 {
626 HWND hEditWnd = (HWND) GetEditHWND();
627
628 // Get number of characters in the last (only) line. We'll add this to the character
629 // index for the last line, 1st position.
630 wxTextPos lineLength = (wxTextPos)SendMessage(hEditWnd, EM_LINELENGTH, (WPARAM) 0, (LPARAM)0L);
631
632 return lineLength;
633 }
634
635 void wxComboBox::Replace(long from, long to, const wxString& value)
636 {
637 #if wxUSE_CLIPBOARD
638 Remove(from, to);
639
640 // Now replace with 'value', by pasting.
641 wxSetClipboardData(wxDF_TEXT, (wxObject *)(const wxChar *)value, 0, 0);
642
643 // Paste into edit control
644 SendMessage(GetHwnd(), WM_PASTE, (WPARAM)0, (LPARAM)0L);
645 #else
646 wxUnusedVar(from);
647 wxUnusedVar(to);
648 wxUnusedVar(value);
649 #endif
650 }
651
652 void wxComboBox::Remove(long from, long to)
653 {
654 // Set selection and remove it
655 SetSelection(from, to);
656 SendMessage(GetHwnd(), WM_CUT, (WPARAM)0, (LPARAM)0);
657 }
658
659 void wxComboBox::SetSelection(long from, long to)
660 {
661 // if from and to are both -1, it means (in wxWidgets) that all text should
662 // be selected, translate this into Windows convention
663 if ( (from == -1) && (to == -1) )
664 {
665 from = 0;
666 }
667
668 if ( SendMessage(GetHwnd(), CB_SETEDITSEL,
669 0, (LPARAM)MAKELONG(from, to)) == CB_ERR )
670 {
671 wxLogDebug(_T("CB_SETEDITSEL failed"));
672 }
673 }
674
675 void wxComboBox::GetSelection(long* from, long* to) const
676 {
677 DWORD dwStart, dwEnd;
678 if ( ::SendMessage(GetHwnd(), CB_GETEDITSEL,
679 (WPARAM)&dwStart, (LPARAM)&dwEnd) == CB_ERR )
680 {
681 *from =
682 *to = 0;
683 }
684 else
685 {
686 *from = dwStart;
687 *to = dwEnd;
688 }
689 }
690
691 // ----------------------------------------------------------------------------
692 // standard event handling
693 // ----------------------------------------------------------------------------
694
695 void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
696 {
697 Cut();
698 }
699
700 void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event))
701 {
702 Copy();
703 }
704
705 void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event))
706 {
707 Paste();
708 }
709
710 void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event))
711 {
712 Undo();
713 }
714
715 void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
716 {
717 Redo();
718 }
719
720 void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
721 {
722 long from, to;
723 GetSelection(& from, & to);
724 if (from != -1 && to != -1)
725 Remove(from, to);
726 }
727
728 void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
729 {
730 SetSelection(-1, -1);
731 }
732
733 void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
734 {
735 event.Enable( CanCut() );
736 }
737
738 void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event)
739 {
740 event.Enable( CanCopy() );
741 }
742
743 void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
744 {
745 event.Enable( CanPaste() );
746 }
747
748 void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
749 {
750 event.Enable( CanUndo() );
751 }
752
753 void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
754 {
755 event.Enable( CanRedo() );
756 }
757
758 void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
759 {
760 event.Enable(HasSelection() && IsEditable());
761 }
762
763 void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
764 {
765 event.Enable(GetLastPosition() > 0);
766 }
767
768 #endif // wxUSE_COMBOBOX