Fixed dropdown height of wxChoice and wxComboBox controls.
[wxWidgets.git] / src / msw / choice.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/choice.cpp
3 // Purpose: wxChoice
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin to derive from wxChoiceBase
6 // Created: 04/01/98
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_CHOICE && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
28
29 #include "wx/choice.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/utils.h"
33 #include "wx/app.h"
34 #include "wx/log.h"
35 #include "wx/brush.h"
36 #include "wx/settings.h"
37 #endif
38
39 #include "wx/msw/private.h"
40
41 // ============================================================================
42 // implementation
43 // ============================================================================
44
45 // ----------------------------------------------------------------------------
46 // creation
47 // ----------------------------------------------------------------------------
48
49 bool wxChoice::Create(wxWindow *parent,
50 wxWindowID id,
51 const wxPoint& pos,
52 const wxSize& size,
53 int n, const wxString choices[],
54 long style,
55 const wxValidator& validator,
56 const wxString& name)
57 {
58 // Experience shows that wxChoice vs. wxComboBox distinction confuses
59 // quite a few people - try to help them
60 wxASSERT_MSG( !(style & wxCB_DROPDOWN) &&
61 !(style & wxCB_READONLY) &&
62 !(style & wxCB_SIMPLE),
63 wxT("this style flag is ignored by wxChoice, you ")
64 wxT("probably want to use a wxComboBox") );
65
66 return CreateAndInit(parent, id, pos, size, n, choices, style,
67 validator, name);
68 }
69
70 bool wxChoice::CreateAndInit(wxWindow *parent,
71 wxWindowID id,
72 const wxPoint& pos,
73 const wxSize& size,
74 int n, const wxString choices[],
75 long style,
76 const wxValidator& validator,
77 const wxString& name)
78 {
79 // initialize wxControl
80 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
81 return false;
82
83 // now create the real HWND
84 if ( !MSWCreateControl(wxT("COMBOBOX"), wxEmptyString, pos, size) )
85 return false;
86
87
88 // initialize the controls contents
89 for ( int i = 0; i < n; i++ )
90 {
91 Append(choices[i]);
92 }
93
94 // and now we may finally size the control properly (if needed)
95 SetInitialSize(size);
96
97 return true;
98 }
99
100 void wxChoice::SetLabel(const wxString& label)
101 {
102 if ( FindString(label) == wxNOT_FOUND )
103 {
104 // unless we explicitly do this here, CB_GETCURSEL will continue to
105 // return the index of the previously selected item which will result
106 // in wrongly replacing the value being set now with the previously
107 // value if the user simply opens and closes (without selecting
108 // anything) the combobox popup
109 SetSelection(-1);
110 }
111
112 wxChoiceBase::SetLabel(label);
113 }
114
115 bool wxChoice::Create(wxWindow *parent,
116 wxWindowID id,
117 const wxPoint& pos,
118 const wxSize& size,
119 const wxArrayString& choices,
120 long style,
121 const wxValidator& validator,
122 const wxString& name)
123 {
124 wxCArrayString chs(choices);
125 return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(),
126 style, validator, name);
127 }
128
129 bool wxChoice::MSWShouldPreProcessMessage(WXMSG *pMsg)
130 {
131 MSG *msg = (MSG *) pMsg;
132
133 // if the dropdown list is visible, don't preprocess certain keys
134 if ( msg->message == WM_KEYDOWN
135 && (msg->wParam == VK_ESCAPE || msg->wParam == VK_RETURN) )
136 {
137 if (::SendMessage(GetHwndOf(this), CB_GETDROPPEDSTATE, 0, 0))
138 {
139 return false;
140 }
141 }
142
143 return wxControl::MSWShouldPreProcessMessage(pMsg);
144 }
145
146 WXDWORD wxChoice::MSWGetStyle(long style, WXDWORD *exstyle) const
147 {
148 // we never have an external border
149 WXDWORD msStyle = wxControl::MSWGetStyle
150 (
151 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
152 );
153
154 // WS_CLIPSIBLINGS is useful with wxChoice and doesn't seem to result in
155 // any problems
156 msStyle |= WS_CLIPSIBLINGS;
157
158 // wxChoice-specific styles
159 msStyle |= CBS_DROPDOWNLIST | WS_HSCROLL | WS_VSCROLL;
160 if ( style & wxCB_SORT )
161 msStyle |= CBS_SORT;
162
163 return msStyle;
164 }
165
166 #ifndef EP_EDITTEXT
167 #define EP_EDITTEXT 1
168 #define ETS_NORMAL 1
169 #endif
170
171 wxVisualAttributes
172 wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
173 {
174 // it is important to return valid values for all attributes from here,
175 // GetXXX() below rely on this
176 wxVisualAttributes attrs;
177
178 // FIXME: Use better dummy window?
179 wxWindow* wnd = wxTheApp->GetTopWindow();
180 if (!wnd)
181 return attrs;
182
183 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
184
185 // there doesn't seem to be any way to get the text colour using themes
186 // API: TMT_TEXTCOLOR doesn't work neither for EDIT nor COMBOBOX
187 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
188
189 // NB: use EDIT, not COMBOBOX (the latter works in XP but not Vista)
190 attrs.colBg = wnd->MSWGetThemeColour(L"EDIT",
191 EP_EDITTEXT,
192 ETS_NORMAL,
193 ThemeColourBackground,
194 wxSYS_COLOUR_WINDOW);
195
196 return attrs;
197 }
198
199 wxChoice::~wxChoice()
200 {
201 Clear();
202 }
203
204 // ----------------------------------------------------------------------------
205 // adding/deleting items to/from the list
206 // ----------------------------------------------------------------------------
207
208 int wxChoice::DoInsertItems(const wxArrayStringsAdapter& items,
209 unsigned int pos,
210 void **clientData, wxClientDataType type)
211 {
212 MSWAllocStorage(items, CB_INITSTORAGE);
213
214 const bool append = pos == GetCount();
215
216 // use CB_ADDSTRING when appending at the end to make sure the control is
217 // resorted if it has wxCB_SORT style
218 const unsigned msg = append ? CB_ADDSTRING : CB_INSERTSTRING;
219
220 if ( append )
221 pos = 0;
222
223 int n = wxNOT_FOUND;
224 const unsigned numItems = items.GetCount();
225 for ( unsigned i = 0; i < numItems; ++i )
226 {
227 n = MSWInsertOrAppendItem(pos, items[i], msg);
228 if ( n == wxNOT_FOUND )
229 return n;
230
231 if ( !append )
232 pos++;
233
234 AssignNewItemClientData(n, clientData, i, type);
235 }
236
237 // we need to refresh our size in order to have enough space for the
238 // newly added items
239 if ( !IsFrozen() )
240 MSWUpdateDropDownHeight();
241
242 InvalidateBestSize();
243
244 return n;
245 }
246
247 void wxChoice::DoDeleteOneItem(unsigned int n)
248 {
249 wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") );
250
251 SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
252
253 if ( !IsFrozen() )
254 MSWUpdateDropDownHeight();
255
256 InvalidateBestSize();
257 }
258
259 void wxChoice::DoClear()
260 {
261 SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0);
262
263 if ( !IsFrozen() )
264 MSWUpdateDropDownHeight();
265
266 InvalidateBestSize();
267 }
268
269 // ----------------------------------------------------------------------------
270 // selection
271 // ----------------------------------------------------------------------------
272
273 int wxChoice::GetSelection() const
274 {
275 // if m_lastAcceptedSelection is set, it means that the dropdown is
276 // currently shown and that we want to use the last "permanent" selection
277 // instead of whatever is under the mouse pointer currently
278 //
279 // otherwise, get the selection from the control
280 return m_lastAcceptedSelection == wxID_NONE ? GetCurrentSelection()
281 : m_lastAcceptedSelection;
282 }
283
284 int wxChoice::GetCurrentSelection() const
285 {
286 return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0);
287 }
288
289 void wxChoice::SetSelection(int n)
290 {
291 SendMessage(GetHwnd(), CB_SETCURSEL, n, 0);
292 }
293
294 // ----------------------------------------------------------------------------
295 // string list functions
296 // ----------------------------------------------------------------------------
297
298 unsigned int wxChoice::GetCount() const
299 {
300 return (unsigned int)SendMessage(GetHwnd(), CB_GETCOUNT, 0, 0);
301 }
302
303 int wxChoice::FindString(const wxString& s, bool bCase) const
304 {
305 #if defined(__WATCOMC__) && defined(__WIN386__)
306 // For some reason, Watcom in WIN386 mode crashes in the CB_FINDSTRINGEXACT message.
307 // wxChoice::Do it the long way instead.
308 unsigned int count = GetCount();
309 for ( unsigned int i = 0; i < count; i++ )
310 {
311 // as CB_FINDSTRINGEXACT is case insensitive, be case insensitive too
312 if (GetString(i).IsSameAs(s, bCase))
313 return i;
314 }
315
316 return wxNOT_FOUND;
317 #else // !Watcom
318 //TODO: Evidently some MSW versions (all?) don't like empty strings
319 //passed to SendMessage, so we have to do it ourselves in that case
320 if ( s.empty() )
321 {
322 unsigned int count = GetCount();
323 for ( unsigned int i = 0; i < count; i++ )
324 {
325 if (GetString(i).empty())
326 return i;
327 }
328
329 return wxNOT_FOUND;
330 }
331 else if (bCase)
332 {
333 // back to base class search for not native search type
334 return wxItemContainerImmutable::FindString( s, bCase );
335 }
336 else
337 {
338 int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT,
339 (WPARAM)-1, (LPARAM)s.wx_str());
340
341 return pos == LB_ERR ? wxNOT_FOUND : pos;
342 }
343 #endif // Watcom/!Watcom
344 }
345
346 void wxChoice::SetString(unsigned int n, const wxString& s)
347 {
348 wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::SetString") );
349
350 // we have to delete and add back the string as there is no way to change a
351 // string in place
352
353 // we need to preserve the client data manually
354 void *oldData = NULL;
355 wxClientData *oldObjData = NULL;
356 if ( HasClientUntypedData() )
357 oldData = GetClientData(n);
358 else if ( HasClientObjectData() )
359 oldObjData = GetClientObject(n);
360
361 ::SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
362 ::SendMessage(GetHwnd(), CB_INSERTSTRING, n, (LPARAM)s.wx_str() );
363
364 // restore the client data
365 if ( oldData )
366 SetClientData(n, oldData);
367 else if ( oldObjData )
368 SetClientObject(n, oldObjData);
369
370 InvalidateBestSize();
371 }
372
373 wxString wxChoice::GetString(unsigned int n) const
374 {
375 int len = (int)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0);
376
377 wxString str;
378 if ( len != CB_ERR && len > 0 )
379 {
380 if ( ::SendMessage
381 (
382 GetHwnd(),
383 CB_GETLBTEXT,
384 n,
385 (LPARAM)(wxChar *)wxStringBuffer(str, len)
386 ) == CB_ERR )
387 {
388 wxLogLastError(wxT("SendMessage(CB_GETLBTEXT)"));
389 }
390 }
391
392 return str;
393 }
394
395 // ----------------------------------------------------------------------------
396 // client data
397 // ----------------------------------------------------------------------------
398
399 void wxChoice::DoSetItemClientData(unsigned int n, void* clientData)
400 {
401 if ( ::SendMessage(GetHwnd(), CB_SETITEMDATA,
402 n, (LPARAM)clientData) == CB_ERR )
403 {
404 wxLogLastError(wxT("CB_SETITEMDATA"));
405 }
406 }
407
408 void* wxChoice::DoGetItemClientData(unsigned int n) const
409 {
410 LPARAM rc = SendMessage(GetHwnd(), CB_GETITEMDATA, n, 0);
411 if ( rc == CB_ERR )
412 {
413 wxLogLastError(wxT("CB_GETITEMDATA"));
414
415 // unfortunately, there is no way to return an error code to the user
416 rc = (LPARAM) NULL;
417 }
418
419 return (void *)rc;
420 }
421
422 // ----------------------------------------------------------------------------
423 // wxMSW-specific geometry management
424 // ----------------------------------------------------------------------------
425
426 namespace
427 {
428
429 // there is a difference between the height passed to CB_SETITEMHEIGHT and the
430 // real height of the combobox; it is probably not constant for all Windows
431 // versions/settings but right now I don't know how to find what it is so it is
432 // temporarily hardcoded to its value under XP systems with normal fonts sizes
433 const int COMBO_HEIGHT_ADJ = 6;
434
435 } // anonymous namespace
436
437 void wxChoice::MSWUpdateVisibleHeight()
438 {
439 if ( m_heightOwn != wxDefaultCoord )
440 {
441 ::SendMessage(GetHwnd(), CB_SETITEMHEIGHT,
442 (WPARAM)-1, m_heightOwn - COMBO_HEIGHT_ADJ);
443 }
444 }
445
446 #if wxUSE_DEFERRED_SIZING
447 void wxChoice::MSWEndDeferWindowPos()
448 {
449 // we can only set the height of the choice itself now as it is reset to
450 // default every time the control is resized
451 MSWUpdateVisibleHeight();
452
453 wxChoiceBase::MSWEndDeferWindowPos();
454 }
455 #endif // wxUSE_DEFERRED_SIZING
456
457 void wxChoice::MSWUpdateDropDownHeight()
458 {
459 // be careful to not change the width here
460 DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, GetSize().y,
461 wxSIZE_USE_EXISTING);
462 }
463
464 void wxChoice::DoMoveWindow(int x, int y, int width, int height)
465 {
466 // here is why this is necessary: if the width is negative, the combobox
467 // window proc makes the window of the size width*height instead of
468 // interpreting height in the usual manner (meaning the height of the drop
469 // down list - usually the height specified in the call to MoveWindow()
470 // will not change the height of combo box per se)
471 //
472 // this behaviour is not documented anywhere, but this is just how it is
473 // here (NT 4.4) and, anyhow, the check shouldn't hurt - however without
474 // the check, constraints/sizers using combos may break the height
475 // constraint will have not at all the same value as expected
476 if ( width < 0 )
477 return;
478
479 wxControl::DoMoveWindow(x, y, width, height);
480 }
481
482 void wxChoice::DoGetSize(int *w, int *h) const
483 {
484 wxControl::DoGetSize(w, h);
485
486 // this is weird: sometimes, the height returned by Windows is clearly the
487 // total height of the control including the drop down list -- but only
488 // sometimes, and sometimes it isn't so work around this here by using our
489 // own stored value if we have it
490 if ( h && m_heightOwn != wxDefaultCoord )
491 *h = m_heightOwn;
492 }
493
494 void wxChoice::DoSetSize(int x, int y,
495 int width, int height,
496 int sizeFlags)
497 {
498 const int heightBest = GetBestSize().y;
499
500 // we need the real height below so get the current one if it's not given
501 if ( height == wxDefaultCoord )
502 {
503 // height not specified, use the same as before
504 DoGetSize(NULL, &height);
505 }
506 else if ( height == heightBest )
507 {
508 // we don't need to manually manage our height, let the system use the
509 // default one
510 m_heightOwn = wxDefaultCoord;
511 }
512 else // non-default height specified
513 {
514 // set our new own height but be careful not to make it too big: the
515 // native control apparently stores it as a single byte and so setting
516 // own height to 256 pixels results in default height being used (255
517 // is still ok)
518 m_heightOwn = height;
519
520 if ( m_heightOwn > UCHAR_MAX )
521 m_heightOwn = UCHAR_MAX;
522 // nor too small: see MSWUpdateVisibleHeight()
523 else if ( m_heightOwn < COMBO_HEIGHT_ADJ )
524 m_heightOwn = COMBO_HEIGHT_ADJ;
525 }
526
527
528 // the height which we must pass to Windows should be the total height of
529 // the control including the drop down list while the height given to us
530 // is, of course, just the height of the permanently visible part of it so
531 // add the drop down height to it
532
533 // don't make the drop down list too tall, arbitrarily limit it to 30
534 // items max and also don't make it too small if it's currently empty
535 size_t nItems = GetCount();
536 if (!HasFlag(wxCB_SIMPLE))
537 {
538 if ( !nItems )
539 nItems = 9;
540 else if ( nItems > 30 )
541 nItems = 30;
542 }
543
544 const int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0);
545 int heightWithItems = 0;
546 if (!HasFlag(wxCB_SIMPLE))
547 // The extra item (" + 1") is required to prevent a vertical
548 // scrollbar from appearing with comctl32.dll versions earlier
549 // than 6.0 (such as found in Win2k).
550 heightWithItems = height + hItem*(nItems + 1);
551 else
552 heightWithItems = SetHeightSimpleComboBox(nItems);
553
554
555 // do resize the native control
556 wxControl::DoSetSize(x, y, width, heightWithItems, sizeFlags);
557
558
559 // make the control itself of the requested height: notice that this
560 // must be done after changing its size or it has no effect (apparently
561 // the height is reset to default during the control layout) and that it's
562 // useless to do it when using the deferred sizing -- in this case it
563 // will be done from MSWEndDeferWindowPos()
564 #if wxUSE_DEFERRED_SIZING
565 if ( m_pendingSize == wxDefaultSize )
566 {
567 // not using deferred sizing, update it immediately
568 MSWUpdateVisibleHeight();
569 }
570 else // in the middle of deferred sizing
571 {
572 // we need to report the size of the visible part of the control back
573 // in GetSize() and not height stored by DoSetSize() in m_pendingSize
574 m_pendingSize = wxSize(width, height);
575 }
576 #else // !wxUSE_DEFERRED_SIZING
577 // always update the visible height immediately
578 MSWUpdateVisibleHeight();
579 #endif // wxUSE_DEFERRED_SIZING
580 }
581
582 wxSize wxChoice::DoGetBestSize() const
583 {
584 // find the widest string
585 int wChoice = 0;
586 int hChoice;
587 const unsigned int nItems = GetCount();
588 for ( unsigned int i = 0; i < nItems; i++ )
589 {
590 int wLine;
591 GetTextExtent(GetString(i), &wLine, NULL);
592 if ( wLine > wChoice )
593 wChoice = wLine;
594 }
595
596 // give it some reasonable default value if there are no strings in the
597 // list
598 if ( wChoice == 0 )
599 wChoice = 100;
600
601 // the combobox should be slightly larger than the widest string
602 wChoice += 5*GetCharWidth();
603 if( HasFlag( wxCB_SIMPLE ) )
604 {
605 hChoice = SetHeightSimpleComboBox( nItems );
606 }
607 else
608 hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight());
609
610 wxSize best(wChoice, hChoice);
611 CacheBestSize(best);
612 return best;
613 }
614
615 int wxChoice::SetHeightSimpleComboBox(int nItems) const
616 {
617 int cx, cy;
618 wxGetCharSize( GetHWND(), &cx, &cy, GetFont() );
619 int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, (WPARAM)-1, 0);
620 return EDIT_HEIGHT_FROM_CHAR_HEIGHT( cy ) * wxMin( wxMax( nItems, 3 ), 6 ) + hItem - 1;
621 }
622
623 // ----------------------------------------------------------------------------
624 // MSW message handlers
625 // ----------------------------------------------------------------------------
626
627 WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
628 {
629 switch ( nMsg )
630 {
631 case WM_LBUTTONUP:
632 {
633 int x = (int)LOWORD(lParam);
634 int y = (int)HIWORD(lParam);
635
636 // Ok, this is truly weird, but if a panel with a wxChoice
637 // loses the focus, then you get a *fake* WM_LBUTTONUP message
638 // with x = 65535 and y = 65535. Filter out this nonsense.
639 //
640 // VZ: I'd like to know how to reproduce this please...
641 if ( x == 65535 && y == 65535 )
642 return 0;
643 }
644 break;
645
646 // we have to handle both: one for the normal case and the other
647 // for readonly
648 case WM_CTLCOLOREDIT:
649 case WM_CTLCOLORLISTBOX:
650 case WM_CTLCOLORSTATIC:
651 {
652 WXHDC hdc;
653 WXHWND hwnd;
654 UnpackCtlColor(wParam, lParam, &hdc, &hwnd);
655
656 WXHBRUSH hbr = MSWControlColor((WXHDC)hdc, hwnd);
657 if ( hbr )
658 return (WXLRESULT)hbr;
659 //else: fall through to default window proc
660 }
661 }
662
663 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
664 }
665
666 bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
667 {
668 /*
669 The native control provides a great variety in the events it sends in
670 the different selection scenarios (undoubtedly for greater amusement of
671 the programmers using it). For the reference, here are the cases when
672 the final selection is accepted (things are quite interesting when it
673 is cancelled too):
674
675 A. Selecting with just the arrows without opening the dropdown:
676 1. CBN_SELENDOK
677 2. CBN_SELCHANGE
678
679 B. Opening dropdown with F4 and selecting with arrows:
680 1. CBN_DROPDOWN
681 2. many CBN_SELCHANGE while changing selection in the list
682 3. CBN_SELENDOK
683 4. CBN_CLOSEUP
684
685 C. Selecting with the mouse:
686 1. CBN_DROPDOWN
687 -- no intermediate CBN_SELCHANGEs --
688 2. CBN_SELENDOK
689 3. CBN_CLOSEUP
690 4. CBN_SELCHANGE
691
692 Admire the different order of messages in all of those cases, it must
693 surely have taken a lot of effort to Microsoft developers to achieve
694 such originality.
695 */
696 switch ( param )
697 {
698 case CBN_DROPDOWN:
699 // we use this value both because we don't want to track selection
700 // using CB_GETCURSEL while the dropdown is opened and because we
701 // need to reset the selection back to it if it's eventually
702 // cancelled by user
703 m_lastAcceptedSelection = GetCurrentSelection();
704 break;
705
706 case CBN_CLOSEUP:
707 // if the selection was accepted by the user, it should have been
708 // reset to wxID_NONE by CBN_SELENDOK, otherwise the selection was
709 // cancelled and we must restore the old one
710 if ( m_lastAcceptedSelection != wxID_NONE )
711 {
712 SetSelection(m_lastAcceptedSelection);
713 m_lastAcceptedSelection = wxID_NONE;
714 }
715 break;
716
717 case CBN_SELENDOK:
718 // reset it to prevent CBN_CLOSEUP from undoing the selection (it's
719 // ok to reset it now as GetCurrentSelection() will now return the
720 // same thing anyhow)
721 m_lastAcceptedSelection = wxID_NONE;
722
723 {
724 const int n = GetSelection();
725
726 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
727 event.SetInt(n);
728 event.SetEventObject(this);
729
730 if ( n > -1 )
731 {
732 event.SetString(GetStringSelection());
733 InitCommandEventWithItems(event, n);
734 }
735
736 ProcessCommand(event);
737 }
738 break;
739
740 // don't handle CBN_SELENDCANCEL: just leave m_lastAcceptedSelection
741 // valid and the selection will be undone in CBN_CLOSEUP above
742
743 // don't handle CBN_SELCHANGE neither, we don't want to generate events
744 // while the dropdown is opened -- but do add it if we ever need this
745
746 default:
747 return false;
748 }
749
750 return true;
751 }
752
753 WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd)
754 {
755 if ( !IsEnabled() )
756 return MSWControlColorDisabled(hDC);
757
758 return wxChoiceBase::MSWControlColor(hDC, hWnd);
759 }
760
761 #endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__)