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