]> git.saurik.com Git - wxWidgets.git/blame - src/msw/combobox.cpp
Simplified event based Drag API for wxDataViewCtrl
[wxWidgets.git] / src / msw / combobox.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
8e25c198 2// Name: src/msw/combobox.cpp
2bda0e17
KB
3// Purpose: wxComboBox class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
f6bcfd97
BP
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
fddfd9e1 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
af79c52d
VZ
27#if wxUSE_COMBOBOX
28
670f9935
WS
29#include "wx/combobox.h"
30
2bda0e17 31#ifndef WX_PRECOMP
57bd4c60 32 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
fddfd9e1
VZ
33 #include "wx/settings.h"
34 #include "wx/log.h"
2b5f62a0
VZ
35 // for wxEVT_COMMAND_TEXT_ENTER
36 #include "wx/textctrl.h"
670f9935 37 #include "wx/app.h"
c64755ed 38 #include "wx/brush.h"
2bda0e17
KB
39#endif
40
2bda0e17
KB
41#include "wx/clipbrd.h"
42#include "wx/msw/private.h"
43
f6bcfd97 44#if wxUSE_TOOLTIPS
f6bcfd97
BP
45 #include "wx/tooltip.h"
46#endif // wxUSE_TOOLTIPS
47
48// ----------------------------------------------------------------------------
49// wxWin macros
50// ----------------------------------------------------------------------------
51
6a89f9ee 52#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
53WX_DEFINE_FLAGS( wxComboBoxStyle )
54
3ff066a4 55wxBEGIN_FLAGS( wxComboBoxStyle )
bc9fb572
JS
56 // new style border flags, we put them first to
57 // use them for streaming out
3ff066a4
SC
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)
02b7b6b0 64
bc9fb572 65 // old style border flags
3ff066a4
SC
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)
cb0afb26 71 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
72
73 // standard window styles
3ff066a4
SC
74 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
75 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
76 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
77 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 78 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
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
88wxEND_FLAGS( wxComboBoxStyle )
bc9fb572 89
0ad2a19e 90IMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxChoice,"wx/combobox.h")
6a89f9ee 91
3ff066a4 92wxBEGIN_PROPERTIES_TABLE(wxComboBox)
02b7b6b0 93 wxEVENT_PROPERTY( Select , wxEVT_COMMAND_COMBOBOX_SELECTED , wxCommandEvent )
3ff066a4 94 wxEVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent )
c5ca409b 95
6a89f9ee 96 // TODO DELEGATES
02b7b6b0 97 wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
3ff066a4 98 wxPROPERTY_COLLECTION( Choices , wxArrayString , wxString , AppendString , GetStrings , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
02b7b6b0
WS
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"))
af498247 101 wxPROPERTY_FLAGS( WindowStyle , wxComboBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 102wxEND_PROPERTIES_TABLE()
6a89f9ee 103
3ff066a4
SC
104wxBEGIN_HANDLERS_TABLE(wxComboBox)
105wxEND_HANDLERS_TABLE()
2bda0e17 106
3ff066a4 107wxCONSTRUCTOR_5( wxComboBox , wxWindow* , Parent , wxWindowID , Id , wxString , Value , wxPoint , Position , wxSize , Size )
bb8d428f 108
6a89f9ee 109#else
bb8d428f 110
0ad2a19e 111IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxChoice)
150e31d2 112
bb8d428f
WS
113#endif
114
150e31d2
JS
115BEGIN_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)
131END_EVENT_TABLE()
132
f6bcfd97
BP
133// ----------------------------------------------------------------------------
134// function prototypes
135// ----------------------------------------------------------------------------
136
137LRESULT 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
975b6bcf 147static WNDPROC gs_wndprocEdit = (WNDPROC)NULL;
f6bcfd97
BP
148
149// ============================================================================
150// implementation
151// ============================================================================
152
153// ----------------------------------------------------------------------------
154// wnd proc for subclassed edit control
155// ----------------------------------------------------------------------------
156
157LRESULT 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 {
53c3a78b
VZ
167 // forward some messages to the combobox to generate the appropriate
168 // wxEvents from them
f6bcfd97
BP
169 case WM_KEYUP:
170 case WM_KEYDOWN:
171 case WM_CHAR:
a1254663
VZ
172 case WM_SYSCHAR:
173 case WM_SYSKEYDOWN:
174 case WM_SYSKEYUP:
53c3a78b
VZ
175 case WM_SETFOCUS:
176 case WM_KILLFOCUS:
f6bcfd97
BP
177 {
178 wxComboBox *combo = wxDynamicCast(win, wxComboBox);
64b39766
VZ
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
f6bcfd97 192 return 0;
64b39766 193 }
f6bcfd97
BP
194 }
195 break;
196
f6bcfd97
BP
197 case WM_GETDLGCODE:
198 {
199 wxCHECK_MSG( win, 0, _T("should have a parent") );
200
8e13c1ec 201 if ( win->GetWindowStyle() & wxTE_PROCESS_ENTER )
f6bcfd97
BP
202 {
203 // need to return a custom dlg code or we'll never get it
204 return DLGC_WANTMESSAGE;
205 }
206 }
207 break;
f6bcfd97
BP
208 }
209
210 return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam);
211}
212
f6bcfd97 213// ----------------------------------------------------------------------------
3a7d5f7c 214// wxComboBox callbacks
f6bcfd97
BP
215// ----------------------------------------------------------------------------
216
c140b7e7 217WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
3a7d5f7c 218{
5301d1f7
VZ
219 // TODO: handle WM_CTLCOLOR messages from our EDIT control to be able to
220 // set its colour correctly (to be the same as our own one)
682214d5 221
3a7d5f7c
VZ
222 switch ( nMsg )
223 {
682214d5 224 case WM_SIZE:
3bce55ac
JS
225 // wxStaticBox can generate this message, when modifying the control's style.
226 // This causes the content of the combobox to be selected, for some reason.
227 case WM_STYLECHANGED:
5301d1f7
VZ
228 {
229 // combobox selection sometimes spontaneously changes when its
230 // size changes, restore it to the old value if necessary
e9717bd5
VZ
231 if ( !GetEditHWNDIfAvailable() )
232 break;
233
5301d1f7
VZ
234 long fromOld, toOld;
235 GetSelection(&fromOld, &toOld);
236 WXLRESULT result = wxChoice::MSWWindowProc(nMsg, wParam, lParam);
682214d5 237
5301d1f7
VZ
238 long fromNew, toNew;
239 GetSelection(&fromNew, &toNew);
682214d5 240
5301d1f7
VZ
241 if ( fromOld != fromNew || toOld != toNew )
242 {
243 SetSelection(fromOld, toOld);
244 }
682214d5 245
5301d1f7
VZ
246 return result;
247 }
3a7d5f7c
VZ
248 }
249
5301d1f7 250 return wxChoice::MSWWindowProc(nMsg, wParam, lParam);
3a7d5f7c
VZ
251}
252
f6bcfd97
BP
253bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
254{
255 switch ( msg )
256 {
257 case WM_CHAR:
2b5f62a0
VZ
258 // for compatibility with wxTextCtrl, generate a special message
259 // when Enter is pressed
260 if ( wParam == VK_RETURN )
261 {
a2634d81
RR
262 if (SendMessage(GetHwnd(), CB_GETDROPPEDSTATE, 0, 0))
263 return false;
f4322df6 264
2b5f62a0 265 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
593ac33e
VZ
266
267 const int sel = GetSelection();
268 event.SetInt(sel);
2b5f62a0 269 event.SetString(GetValue());
593ac33e
VZ
270 InitCommandEventWithItems(event, sel);
271
ffb1629f
VZ
272 if ( ProcessCommand(event) )
273 {
274 // don't let the event through to the native control
275 // because it doesn't need it and may generate an annoying
276 // beep if it gets it
277 return true;
278 }
2b5f62a0 279 }
a1254663 280 // fall through
2b5f62a0 281
a1254663 282 case WM_SYSCHAR:
02b7b6b0 283 return HandleChar(wParam, lParam, true /* isASCII */);
889f0b7c 284
a1254663 285 case WM_SYSKEYDOWN:
f6bcfd97
BP
286 case WM_KEYDOWN:
287 return HandleKeyDown(wParam, lParam);
288
a1254663 289 case WM_SYSKEYUP:
f6bcfd97
BP
290 case WM_KEYUP:
291 return HandleKeyUp(wParam, lParam);
53c3a78b
VZ
292
293 case WM_SETFOCUS:
294 return HandleSetFocus((WXHWND)wParam);
295
296 case WM_KILLFOCUS:
297 return HandleKillFocus((WXHWND)wParam);
b65f16da
VS
298
299 case WM_CUT:
300 case WM_COPY:
301 case WM_PASTE:
302 return HandleClipboardEvent(msg);
f6bcfd97
BP
303 }
304
02b7b6b0 305 return false;
f6bcfd97
BP
306}
307
6ba93d23 308bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
2bda0e17 309{
fddfd9e1 310 int sel = -1;
7d90194c
VZ
311 wxString value;
312
cd0b1709 313 switch ( param )
8c1c5302 314 {
ae3b1487
VZ
315 case CBN_DROPDOWN:
316 // remember the last selection, just as wxChoice does
317 m_lastAcceptedSelection = GetCurrentSelection();
318 if ( m_lastAcceptedSelection == -1 )
319 {
320 // but unlike with wxChoice we may have no selection but still
321 // have some text and we should avoid erasing it if the drop
322 // down is cancelled (see #8474)
323 m_lastAcceptedSelection = wxID_NONE;
324 }
325 break;
326
78a87a5d 327 case CBN_SELENDOK:
8e25c198 328#ifndef __SMARTPHONE__
7d90194c
VZ
329 // we need to reset this to prevent the selection from being undone
330 // by wxChoice, see wxChoice::MSWCommand() and comments there
331 m_lastAcceptedSelection = wxID_NONE;
8e25c198 332#endif
13bcc348 333
7d90194c
VZ
334 // set these variables so that they could be also fixed in
335 // CBN_EDITCHANGE below
336 sel = GetSelection();
f5a45ee2 337 value = GetStringSelection();
d0b6344d
VZ
338
339 // this string is going to become the new combobox value soon but
340 // we need it to be done right now, otherwise the event handler
341 // could get a wrong value when it calls our GetValue()
e0a050e3 342 ::SetWindowText(GetHwnd(), value.wx_str());
d0b6344d 343
cd0b1709
VZ
344 {
345 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
7d90194c
VZ
346 event.SetInt(sel);
347 event.SetString(value);
593ac33e
VZ
348 InitCommandEventWithItems(event, sel);
349
cd0b1709
VZ
350 ProcessCommand(event);
351 }
fddfd9e1
VZ
352
353 // fall through: for compability with wxGTK, also send the text
354 // update event when the selection changes (this also seems more
355 // logical as the text does change)
29006414 356
cd0b1709 357 case CBN_EDITCHANGE:
b7bfef38 358 if ( m_allowTextEvents )
cd0b1709 359 {
7ba166dd 360 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
3adc70bf 361
7d90194c 362 // if sel != -1, value was already initialized above
7ba166dd 363 if ( sel == -1 )
3adc70bf 364 {
7d90194c 365 value = wxGetWindowText(GetHwnd());
3adc70bf
VZ
366 }
367
7d90194c 368 event.SetString(value);
593ac33e
VZ
369 InitCommandEventWithItems(event, sel);
370
0ef2ebba 371 ProcessCommand(event);
cd0b1709
VZ
372 }
373 break;
6ba93d23
VZ
374
375 default:
376 return wxChoice::MSWCommand(param, id);
cd0b1709 377 }
29006414 378
7d90194c 379 // skip wxChoice version as it would generate its own events for
ae3b1487 380 // CBN_SELENDOK and also interfere with our handling of CBN_DROPDOWN
8cc5e8cf 381 return true;
2bda0e17
KB
382}
383
90ac8b50
RR
384bool wxComboBox::MSWShouldPreProcessMessage(WXMSG *pMsg)
385{
386 // prevent command accelerators from stealing editing
387 // hotkeys when we have the focus
388 if (wxIsCtrlDown())
389 {
390 WPARAM vkey = pMsg->wParam;
6b54668b 391
90ac8b50
RR
392 switch (vkey)
393 {
394 case 'C':
395 case 'V':
396 case 'X':
397 case VK_INSERT:
398 case VK_DELETE:
399 case VK_HOME:
400 case VK_END:
401 return false;
402 }
403 }
6b54668b 404
90ac8b50
RR
405 return wxChoice::MSWShouldPreProcessMessage(pMsg);
406}
407
e9717bd5
VZ
408WXHWND wxComboBox::GetEditHWNDIfAvailable() const
409{
74052fe8
VZ
410 // notice that a slightly safer alternative could be to use FindWindowEx()
411 // but it's not available under WinCE so just take the first child for now
412 // to keep one version of the code for all platforms and fix it later if
413 // problems are discovered
414
415 // we assume that the only child of the combobox is the edit window
416 return (WXHWND)::GetWindow(GetHwnd(), GW_CHILD);
e9717bd5
VZ
417}
418
f6bcfd97
BP
419WXHWND wxComboBox::GetEditHWND() const
420{
421 // this function should not be called for wxCB_READONLY controls, it is
e9717bd5 422 // the callers responsibility to check this
fa2f57be 423 wxASSERT_MSG( !HasFlag(wxCB_READONLY),
f6bcfd97
BP
424 _T("read-only combobox doesn't have any edit control") );
425
e9717bd5
VZ
426 WXHWND hWndEdit = GetEditHWNDIfAvailable();
427 wxASSERT_MSG( hWndEdit, _T("combobox without edit control?") );
f6bcfd97 428
e9717bd5 429 return hWndEdit;
f6bcfd97
BP
430}
431
71e57cd6
VZ
432// ----------------------------------------------------------------------------
433// wxComboBox creation
434// ----------------------------------------------------------------------------
435
debe6624 436bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
c085e333
VZ
437 const wxString& value,
438 const wxPoint& pos,
439 const wxSize& size,
440 int n, const wxString choices[],
441 long style,
442 const wxValidator& validator,
443 const wxString& name)
2bda0e17 444{
bdf5c30d
VZ
445 // pretend that wxComboBox is hidden while it is positioned and resized and
446 // show it only right before leaving this method because otherwise there is
447 // some noticeable flicker while the control rearranges itself
02b7b6b0 448 m_isShown = false;
bdf5c30d 449
71e57cd6
VZ
450 if ( !CreateAndInit(parent, id, pos, size, n, choices, style,
451 validator, name) )
02b7b6b0 452 return false;
f6bcfd97 453
6341d824
VZ
454 // we shouldn't call SetValue() for an empty string because this would
455 // (correctly) result in an assert with a read only combobox and is useless
456 // for the other ones anyhow
457 if ( !value.empty() )
b9b8a2b5 458 SetValue(value);
db34b147 459
f6bcfd97
BP
460 // a (not read only) combobox is, in fact, 2 controls: the combobox itself
461 // and an edit control inside it and if we want to catch events from this
462 // edit control, we must subclass it as well
463 if ( !(style & wxCB_READONLY) )
464 {
94972183 465 gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(), wxComboEditWndProc);
f6bcfd97 466 }
2bda0e17 467
bdf5c30d 468 // and finally, show the control
02b7b6b0 469 Show(true);
bdf5c30d 470
02b7b6b0 471 return true;
2bda0e17
KB
472}
473
584ad2a3
MB
474bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
475 const wxString& value,
476 const wxPoint& pos,
477 const wxSize& size,
478 const wxArrayString& choices,
479 long style,
480 const wxValidator& validator,
481 const wxString& name)
482{
483 wxCArrayString chs(choices);
484 return Create(parent, id, value, pos, size, chs.GetCount(),
485 chs.GetStrings(), style, validator, name);
486}
487
71e57cd6
VZ
488WXDWORD wxComboBox::MSWGetStyle(long style, WXDWORD *exstyle) const
489{
490 // we never have an external border
491 WXDWORD msStyle = wxChoice::MSWGetStyle
492 (
493 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
494 );
495
1dfd425a
VZ
496 // usually WS_TABSTOP is added by wxControl::MSWGetStyle() but as we're
497 // created hidden (see Create() above), it is not done for us but we still
498 // want to have this style
499 msStyle |= WS_TABSTOP;
500
71e57cd6
VZ
501 // remove the style always added by wxChoice
502 msStyle &= ~CBS_DROPDOWNLIST;
503
504 if ( style & wxCB_READONLY )
505 msStyle |= CBS_DROPDOWNLIST;
506#ifndef __WXWINCE__
507 else if ( style & wxCB_SIMPLE )
508 msStyle |= CBS_SIMPLE; // A list (shown always) and edit control
509#endif
510 else
511 msStyle |= CBS_DROPDOWN;
512
513 // there is no reason to not always use CBS_AUTOHSCROLL, so do use it
514 msStyle |= CBS_AUTOHSCROLL;
515
516 // NB: we used to also add CBS_NOINTEGRALHEIGHT here but why?
517
518 return msStyle;
519}
520
521// ----------------------------------------------------------------------------
522// wxComboBox text control-like methods
523// ----------------------------------------------------------------------------
524
e9717bd5
VZ
525wxString wxComboBox::GetValue() const
526{
527 return HasFlag(wxCB_READONLY) ? GetStringSelection()
528 : wxTextEntry::GetValue();
529}
530
2bda0e17
KB
531void wxComboBox::SetValue(const wxString& value)
532{
2b5f62a0
VZ
533 if ( HasFlag(wxCB_READONLY) )
534 SetStringSelection(value);
b38f3ff3 535 else
fa2f57be 536 wxTextEntry::SetValue(value);
150e31d2
JS
537}
538
e6a84162
VZ
539void wxComboBox::Clear()
540{
541 wxChoice::Clear();
542 if ( !HasFlag(wxCB_READONLY) )
543 wxTextEntry::Clear();
544}
545
e9717bd5
VZ
546void wxComboBox::GetSelection(long *from, long *to) const
547{
548 if ( !HasFlag(wxCB_READONLY) )
549 {
550 wxTextEntry::GetSelection(from, to);
551 }
552 else // text selection doesn't make sense for read only comboboxes
553 {
554 if ( from )
555 *from = -1;
556 if ( to )
557 *to = -1;
558 }
559}
560
150e31d2
JS
561bool wxComboBox::IsEditable() const
562{
fa2f57be 563 return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable();
3f5ca6b1
RN
564}
565
150e31d2
JS
566// ----------------------------------------------------------------------------
567// standard event handling
568// ----------------------------------------------------------------------------
569
570void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
571{
572 Cut();
573}
574
575void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event))
576{
577 Copy();
578}
579
580void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event))
581{
582 Paste();
583}
584
585void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event))
586{
587 Undo();
588}
589
590void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
591{
592 Redo();
593}
594
595void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
596{
5a25f858 597 RemoveSelection();
150e31d2
JS
598}
599
600void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
601{
e976429d 602 SelectAll();
150e31d2
JS
603}
604
605void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
606{
607 event.Enable( CanCut() );
608}
609
610void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event)
611{
612 event.Enable( CanCopy() );
613}
614
615void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
616{
617 event.Enable( CanPaste() );
618}
619
620void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
621{
c0e15042 622 event.Enable( IsEditable() && CanUndo() );
150e31d2
JS
623}
624
625void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
626{
c0e15042 627 event.Enable( IsEditable() && CanRedo() );
150e31d2
JS
628}
629
630void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
631{
6b54668b 632 event.Enable(IsEditable() && HasSelection());
150e31d2
JS
633}
634
635void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
636{
e976429d 637 event.Enable(IsEditable() && !wxTextEntry::IsEmpty());
150e31d2
JS
638}
639
d6b9cc87
VZ
640#if wxUSE_TOOLTIPS
641
642void wxComboBox::DoSetToolTip(wxToolTip *tip)
643{
644 wxChoice::DoSetToolTip(tip);
645
646 if ( tip && !HasFlag(wxCB_READONLY) )
647 tip->Add(GetEditHWND());
648}
649
650#endif // wxUSE_TOOLTIPS
651
71e57cd6 652#endif // wxUSE_COMBOBOX