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