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