]> git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobox.cpp
Added Set/GetQuickBestSize
[wxWidgets.git] / src / msw / radiobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/radiobox.cpp
3 // Purpose: wxRadioBox implementation
4 // Author: Julian Smart
5 // Modified by:
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_RADIOBOX
28
29 #ifndef WX_PRECOMP
30 #include "wx/bitmap.h"
31 #include "wx/brush.h"
32 #include "wx/radiobox.h"
33 #include "wx/settings.h"
34 #include "wx/log.h"
35 #endif
36
37 #include "wx/msw/subwin.h"
38
39 #if wxUSE_TOOLTIPS
40 #include "wx/tooltip.h"
41 #endif // wxUSE_TOOLTIPS
42
43 // TODO: wxCONSTRUCTOR
44 #if 0 // wxUSE_EXTENDED_RTTI
45 WX_DEFINE_FLAGS( wxRadioBoxStyle )
46
47 wxBEGIN_FLAGS( wxRadioBoxStyle )
48 // new style border flags, we put them first to
49 // use them for streaming out
50 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
51 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
52 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
53 wxFLAGS_MEMBER(wxBORDER_RAISED)
54 wxFLAGS_MEMBER(wxBORDER_STATIC)
55 wxFLAGS_MEMBER(wxBORDER_NONE)
56
57 // old style border flags
58 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
59 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
60 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
61 wxFLAGS_MEMBER(wxRAISED_BORDER)
62 wxFLAGS_MEMBER(wxSTATIC_BORDER)
63 wxFLAGS_MEMBER(wxBORDER)
64
65 // standard window styles
66 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
67 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
68 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
69 wxFLAGS_MEMBER(wxWANTS_CHARS)
70 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
71 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
72 wxFLAGS_MEMBER(wxVSCROLL)
73 wxFLAGS_MEMBER(wxHSCROLL)
74
75 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS)
76 wxFLAGS_MEMBER(wxRA_HORIZONTAL)
77 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS)
78 wxFLAGS_MEMBER(wxRA_VERTICAL)
79
80 wxEND_FLAGS( wxRadioBoxStyle )
81
82 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
83
84 wxBEGIN_PROPERTIES_TABLE(wxRadioBox)
85 wxEVENT_PROPERTY( Select , wxEVT_COMMAND_RADIOBOX_SELECTED , wxCommandEvent )
86 wxPROPERTY_FLAGS( WindowStyle , wxRadioBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
87 wxEND_PROPERTIES_TABLE()
88
89 #else
90 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
91 #endif
92
93 /*
94 selection
95 content
96 label
97 dimension
98 item
99 */
100
101 // ---------------------------------------------------------------------------
102 // private functions
103 // ---------------------------------------------------------------------------
104
105 // wnd proc for radio buttons
106 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hWnd,
107 UINT message,
108 WPARAM wParam,
109 LPARAM lParam);
110
111 // ---------------------------------------------------------------------------
112 // global vars
113 // ---------------------------------------------------------------------------
114
115 // the pointer to standard radio button wnd proc
116 static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
117
118 // ===========================================================================
119 // implementation
120 // ===========================================================================
121
122 // ---------------------------------------------------------------------------
123 // wxRadioBox creation
124 // ---------------------------------------------------------------------------
125
126 // Radio box item
127 void wxRadioBox::Init()
128 {
129 m_selectedButton = wxNOT_FOUND;
130 m_radioButtons = NULL;
131 m_radioWidth = NULL;
132 m_radioHeight = NULL;
133 }
134
135 bool wxRadioBox::Create(wxWindow *parent,
136 wxWindowID id,
137 const wxString& title,
138 const wxPoint& pos,
139 const wxSize& size,
140 int n,
141 const wxString choices[],
142 int majorDim,
143 long style,
144 const wxValidator& val,
145 const wxString& name)
146 {
147 // common initialization
148 if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) )
149 return false;
150
151 #if wxUSE_VALIDATORS
152 SetValidator(val);
153 #else
154 wxUnusedVar(val);
155 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
156
157 m_radioButtons = new wxSubwindows(n);
158 m_radioWidth = new int[n];
159 m_radioHeight = new int[n];
160
161 for ( int i = 0; i < n; i++ )
162 {
163 m_radioWidth[i] =
164 m_radioHeight[i] = wxDefaultCoord;
165 long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
166 if ( i == 0 )
167 styleBtn |= WS_GROUP;
168
169 long newId = NewControlId();
170
171 HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
172 choices[i],
173 styleBtn,
174 0, 0, 0, 0, // will be set in SetSize()
175 GetHwndOf(parent),
176 (HMENU)newId,
177 wxGetInstance(),
178 NULL);
179
180 if ( !hwndBtn )
181 {
182 wxLogLastError(wxT("CreateWindow(radio btn)"));
183
184 return false;
185 }
186
187 (*m_radioButtons)[i] = hwndBtn;
188
189 SubclassRadioButton((WXHWND)hwndBtn);
190
191 m_subControls.Add(newId);
192 }
193
194 // Create a dummy radio control to end the group.
195 (void)::CreateWindow(_T("BUTTON"),
196 wxEmptyString,
197 WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
198 0, 0, 0, 0, GetHwndOf(parent),
199 (HMENU)NewControlId(), wxGetInstance(), NULL);
200
201 m_radioButtons->SetFont(GetFont());
202
203 #ifdef __WXWINCE__
204 // Set the z-order correctly
205 SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
206 #endif
207
208 SetMajorDim(majorDim == 0 ? n : majorDim, style);
209 SetSelection(0);
210 SetSize(pos.x, pos.y, size.x, size.y);
211
212 // Now that we have items determine what is the best size and set it.
213 SetBestSize(size);
214
215 return true;
216 }
217
218 bool wxRadioBox::Create(wxWindow *parent,
219 wxWindowID id,
220 const wxString& title,
221 const wxPoint& pos,
222 const wxSize& size,
223 const wxArrayString& choices,
224 int majorDim,
225 long style,
226 const wxValidator& val,
227 const wxString& name)
228 {
229 wxCArrayString chs(choices);
230 return Create(parent, id, title, pos, size, chs.GetCount(),
231 chs.GetStrings(), majorDim, style, val, name);
232 }
233
234 wxRadioBox::~wxRadioBox()
235 {
236 m_isBeingDeleted = true;
237
238 delete m_radioButtons;
239 delete[] m_radioWidth;
240 delete[] m_radioHeight;
241 }
242
243 // NB: if this code is changed, wxGetWindowForHWND() which relies on having the
244 // radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
245 void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
246 {
247 HWND hwndBtn = (HWND)hWndBtn;
248
249 if ( !s_wndprocRadioBtn )
250 s_wndprocRadioBtn = (WXFARPROC)wxGetWindowProc(hwndBtn);
251
252 wxSetWindowProc(hwndBtn, wxRadioBtnWndProc);
253 wxSetWindowUserData(hwndBtn, this);
254 }
255
256 // ----------------------------------------------------------------------------
257 // events generation
258 // ----------------------------------------------------------------------------
259
260 bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id)
261 {
262 if ( cmd == BN_CLICKED )
263 {
264 if (id == GetId())
265 return true;
266
267 int selectedButton = wxNOT_FOUND;
268
269 const unsigned int count = GetCount();
270 for ( unsigned int i = 0; i < count; i++ )
271 {
272 if ( id == wxGetWindowId((*m_radioButtons)[i]) )
273 {
274 selectedButton = i;
275
276 break;
277 }
278 }
279
280 if ( selectedButton == wxNOT_FOUND )
281 {
282 // just ignore it - due to a hack with WM_NCHITTEST handling in our
283 // wnd proc, we can receive dummy click messages when we click near
284 // the radiobox edge (this is ugly but Julian wouldn't let me get
285 // rid of this...)
286 return false;
287 }
288
289 if ( selectedButton != m_selectedButton )
290 {
291 m_selectedButton = selectedButton;
292
293 SendNotificationEvent();
294 }
295 //else: don't generate events when the selection doesn't change
296
297 return true;
298 }
299 else
300 return false;
301 }
302
303 void wxRadioBox::Command(wxCommandEvent & event)
304 {
305 SetSelection (event.GetInt());
306 SetFocus();
307 ProcessCommand(event);
308 }
309
310 void wxRadioBox::SendNotificationEvent()
311 {
312 wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
313 event.SetInt( m_selectedButton );
314 event.SetString(GetString(m_selectedButton));
315 event.SetEventObject( this );
316 ProcessCommand(event);
317 }
318
319 // ----------------------------------------------------------------------------
320 // simple accessors
321 // ----------------------------------------------------------------------------
322
323 unsigned int wxRadioBox::GetCount() const
324 {
325 return m_radioButtons->GetCount();
326 }
327
328 void wxRadioBox::SetString(unsigned int item, const wxString& label)
329 {
330 wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") );
331
332 m_radioWidth[item] =
333 m_radioHeight[item] = wxDefaultCoord;
334
335 ::SetWindowText((*m_radioButtons)[item], label.c_str());
336
337 InvalidateBestSize();
338 }
339
340 void wxRadioBox::SetSelection(int N)
341 {
342 wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") );
343
344 // unselect the old button
345 if ( m_selectedButton != wxNOT_FOUND )
346 ::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L);
347
348 // and select the new one
349 ::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L);
350
351 m_selectedButton = N;
352 }
353
354 // Find string for position
355 wxString wxRadioBox::GetString(unsigned int item) const
356 {
357 wxCHECK_MSG( IsValid(item), wxEmptyString,
358 wxT("invalid radiobox index") );
359
360 return wxGetWindowText((*m_radioButtons)[item]);
361 }
362
363 void wxRadioBox::SetFocus()
364 {
365 if ( GetCount() > 0 )
366 {
367 ::SetFocus((*m_radioButtons)[m_selectedButton == wxNOT_FOUND
368 ? 0
369 : m_selectedButton]);
370 }
371 }
372
373 // Enable a specific button
374 bool wxRadioBox::Enable(unsigned int item, bool enable)
375 {
376 wxCHECK_MSG( IsValid(item), false,
377 wxT("invalid item in wxRadioBox::Enable()") );
378
379 BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable);
380
381 return (ret == 0) != enable;
382 }
383
384 bool wxRadioBox::IsItemEnabled(unsigned int item) const
385 {
386 wxCHECK_MSG( IsValid(item), false,
387 wxT("invalid item in wxRadioBox::IsItemEnabled()") );
388
389 return ::IsWindowEnabled((*m_radioButtons)[item]) != 0;
390 }
391
392 // Show a specific button
393 bool wxRadioBox::Show(unsigned int item, bool show)
394 {
395 wxCHECK_MSG( IsValid(item), false,
396 wxT("invalid item in wxRadioBox::Show()") );
397
398 BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE);
399
400 bool changed = (ret != 0) != show;
401 if ( changed )
402 {
403 InvalidateBestSize();
404 }
405
406 return changed;
407 }
408
409 bool wxRadioBox::IsItemShown(unsigned int item) const
410 {
411 wxCHECK_MSG( IsValid(item), false,
412 wxT("invalid item in wxRadioBox::IsItemShown()") );
413
414 // don't use IsWindowVisible() here because it would return false if the
415 // radiobox itself is hidden while we want to only return false if this
416 // button specifically is hidden
417 return (::GetWindowLong((*m_radioButtons)[item],
418 GWL_STYLE) & WS_VISIBLE) != 0;
419 }
420
421 #if wxUSE_TOOLTIPS
422
423 bool wxRadioBox::HasToolTips() const
424 {
425 return wxStaticBox::HasToolTips() || wxRadioBoxBase::HasItemToolTips();
426 }
427
428 void wxRadioBox::DoSetItemToolTip(unsigned int item, wxToolTip *tooltip)
429 {
430 // we have already checked for the item to be valid in wxRadioBoxBase
431 const HWND hwndRbtn = (*m_radioButtons)[item];
432 if ( tooltip != NULL )
433 tooltip->Add(hwndRbtn);
434 else // unset the tooltip
435 wxToolTip::Remove(hwndRbtn);
436 }
437
438 #endif // wxUSE_TOOLTIPS
439
440 WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
441
442 // ----------------------------------------------------------------------------
443 // size calculations
444 // ----------------------------------------------------------------------------
445
446 wxSize wxRadioBox::GetMaxButtonSize() const
447 {
448 // calculate the max button size
449 int widthMax = 0,
450 heightMax = 0;
451 const unsigned int count = GetCount();
452 for ( unsigned int i = 0 ; i < count; i++ )
453 {
454 int width, height;
455 if ( m_radioWidth[i] < 0 )
456 {
457 GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height);
458
459 // adjust the size to take into account the radio box itself
460 // FIXME this is totally bogus!
461 width += RADIO_SIZE;
462 height *= 3;
463 height /= 2;
464 }
465 else
466 {
467 width = m_radioWidth[i];
468 height = m_radioHeight[i];
469 }
470
471 if ( widthMax < width )
472 widthMax = width;
473 if ( heightMax < height )
474 heightMax = height;
475 }
476
477 return wxSize(widthMax, heightMax);
478 }
479
480 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
481 {
482 // the radiobox should be big enough for its buttons
483 int cx1, cy1;
484 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
485
486 int extraHeight = cy1;
487
488 int height = GetRowCount() * sizeBtn.y + cy1/2 + extraHeight;
489 int width = GetColumnCount() * (sizeBtn.x + cx1) + cx1;
490
491 // Add extra space under the label, if it exists.
492 if (!wxControl::GetLabel().empty())
493 height += cy1/2;
494
495 // and also wide enough for its label
496 int widthLabel;
497 GetTextExtent(wxStripMenuCodes(GetLabel()), &widthLabel, NULL);
498 widthLabel += RADIO_SIZE; // FIXME this is bogus too
499 if ( widthLabel > width )
500 width = widthLabel;
501
502 return wxSize(width, height);
503 }
504
505 wxSize wxRadioBox::DoGetBestSize() const
506 {
507 wxSize best = GetTotalButtonSize(GetMaxButtonSize());
508 CacheBestSize(best);
509 return best;
510 }
511
512 // Restored old code.
513 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
514 {
515 int currentX, currentY;
516 GetPosition(&currentX, &currentY);
517 int widthOld, heightOld;
518 GetSize(&widthOld, &heightOld);
519
520 int xx = x;
521 int yy = y;
522
523 if (x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
524 xx = currentX;
525 if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
526 yy = currentY;
527
528 int y_offset = yy;
529 int x_offset = xx;
530
531 int cx1, cy1;
532 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
533
534 // Attempt to have a look coherent with other platforms: We compute the
535 // biggest toggle dim, then we align all items according this value.
536 wxSize maxSize = GetMaxButtonSize();
537 int maxWidth = maxSize.x,
538 maxHeight = maxSize.y;
539
540 wxSize totSize = GetTotalButtonSize(maxSize);
541 int totWidth = totSize.x,
542 totHeight = totSize.y;
543
544 // only change our width/height if asked for
545 if ( width == wxDefaultCoord )
546 {
547 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
548 width = totWidth;
549 else
550 width = widthOld;
551 }
552
553 if ( height == wxDefaultCoord )
554 {
555 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
556 height = totHeight;
557 else
558 height = heightOld;
559 }
560
561 DoMoveWindow(xx, yy, width, height);
562
563 // Now position all the buttons: the current button will be put at
564 // wxPoint(x_offset, y_offset) and the new row/column will start at
565 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
566 // maxHeight) except for the buttons in the last column which should extend
567 // to the right border of radiobox and thus can be wider than this.
568
569 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
570 // left to right order and GetMajorDim() is the number of columns while
571 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
572 // GetMajorDim() is the number of rows.
573
574 x_offset += cx1;
575 y_offset += cy1;
576
577 // Add extra space under the label, if it exists.
578 if (!wxControl::GetLabel().empty())
579 y_offset += cy1/2;
580
581 int startX = x_offset;
582 int startY = y_offset;
583
584 const unsigned int count = GetCount();
585 for (unsigned int i = 0; i < count; i++)
586 {
587 // the last button in the row may be wider than the other ones as the
588 // radiobox may be wider than the sum of the button widths (as it
589 // happens, for example, when the radiobox label is very long)
590 bool isLastInTheRow;
591 if ( m_windowStyle & wxRA_SPECIFY_COLS )
592 {
593 // item is the last in its row if it is a multiple of the number of
594 // columns or if it is just the last item
595 unsigned int n = i + 1;
596 isLastInTheRow = ((n % GetMajorDim()) == 0) || (n == count);
597 }
598 else // wxRA_SPECIFY_ROWS
599 {
600 // item is the last in the row if it is in the last columns
601 isLastInTheRow = i >= (count/GetMajorDim())*GetMajorDim();
602 }
603
604 // is this the start of new row/column?
605 if ( i && (i % GetMajorDim() == 0) )
606 {
607 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
608 {
609 // start of new column
610 y_offset = startY;
611 x_offset += maxWidth + cx1;
612 }
613 else // start of new row
614 {
615 x_offset = startX;
616 y_offset += maxHeight;
617 if (m_radioWidth[0]>0)
618 y_offset += cy1/2;
619 }
620 }
621
622 int widthBtn;
623 if ( isLastInTheRow )
624 {
625 // make the button go to the end of radio box
626 widthBtn = startX + width - x_offset - 2*cx1;
627 if ( widthBtn < maxWidth )
628 widthBtn = maxWidth;
629 }
630 else
631 {
632 // normal button, always of the same size
633 widthBtn = maxWidth;
634 }
635
636 // make all buttons of the same, maximal size - like this they cover
637 // the radiobox entirely and the radiobox tooltips are always shown
638 // (otherwise they are not when the mouse pointer is in the radiobox
639 // part not belonging to any radiobutton)
640 DoMoveSibling((*m_radioButtons)[i], x_offset, y_offset, widthBtn, maxHeight);
641
642 // where do we put the next button?
643 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
644 {
645 // below this one
646 y_offset += maxHeight;
647 if (m_radioWidth[0]>0)
648 y_offset += cy1/2;
649 }
650 else
651 {
652 // to the right of this one
653 x_offset += widthBtn + cx1;
654 }
655 }
656 }
657
658 // ----------------------------------------------------------------------------
659 // radio box drawing
660 // ----------------------------------------------------------------------------
661
662 #ifndef __WXWINCE__
663
664 WXHRGN wxRadioBox::MSWGetRegionWithoutChildren()
665 {
666 RECT rc;
667 ::GetWindowRect(GetHwnd(), &rc);
668 HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
669
670 const unsigned int count = GetCount();
671 for ( unsigned int i = 0; i < count; ++i )
672 {
673 // don't clip out hidden children
674 if ( !IsItemShown(i) )
675 continue;
676
677 ::GetWindowRect((*m_radioButtons)[i], &rc);
678 AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc));
679 ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF);
680 }
681
682 return (WXHRGN)hrgn;
683 }
684
685 #endif // __WXWINCE__
686
687 // ---------------------------------------------------------------------------
688 // window proc for radio buttons
689 // ---------------------------------------------------------------------------
690
691 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
692 UINT message,
693 WPARAM wParam,
694 LPARAM lParam)
695 {
696 switch ( message )
697 {
698 case WM_GETDLGCODE:
699 // we must tell IsDialogMessage()/our kbd processing code that we
700 // want to process arrows ourselves because neither of them is
701 // smart enough to handle arrows properly for us
702 {
703 long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd,
704 message, wParam, lParam);
705
706 return lDlgCode | DLGC_WANTARROWS;
707 }
708
709 case WM_KEYDOWN:
710 {
711 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
712
713 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
714
715 bool processed = true;
716
717 wxDirection dir;
718 switch ( wParam )
719 {
720 case VK_UP:
721 dir = wxUP;
722 break;
723
724 case VK_LEFT:
725 dir = wxLEFT;
726 break;
727
728 case VK_DOWN:
729 dir = wxDOWN;
730 break;
731
732 case VK_RIGHT:
733 dir = wxRIGHT;
734 break;
735
736 default:
737 processed = false;
738
739 // just to suppress the compiler warning
740 dir = wxALL;
741 }
742
743 if ( processed )
744 {
745 int selOld = radiobox->GetSelection();
746 int selNew = radiobox->GetNextItem
747 (
748 selOld,
749 dir,
750 radiobox->GetWindowStyle()
751 );
752
753 if ( selNew != selOld )
754 {
755 radiobox->SetSelection(selNew);
756 radiobox->SetFocus();
757
758 // emulate the button click
759 radiobox->SendNotificationEvent();
760
761 return 0;
762 }
763 }
764 }
765 break;
766
767 case WM_SETFOCUS:
768 case WM_KILLFOCUS:
769 {
770 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
771
772 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
773
774 // if we don't do this, no focus events are generated for the
775 // radiobox and, besides, we need to notify the parent about
776 // the focus change, otherwise the focus handling logic in
777 // wxControlContainer doesn't work
778 if ( message == WM_SETFOCUS )
779 radiobox->HandleSetFocus((WXHWND)wParam);
780 else
781 radiobox->HandleKillFocus((WXHWND)wParam);
782 }
783 break;
784
785 #ifndef __WXWINCE__
786 case WM_HELP:
787 {
788 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
789
790 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
791
792 bool processed = false;
793
794 wxEvtHandler * const handler = radiobox->GetEventHandler();
795
796 HELPINFO* info = (HELPINFO*) lParam;
797 if ( info->iContextType == HELPINFO_WINDOW )
798 {
799 for ( wxWindow* subjectOfHelp = radiobox;
800 subjectOfHelp;
801 subjectOfHelp = subjectOfHelp->GetParent() )
802 {
803 wxHelpEvent helpEvent(wxEVT_HELP,
804 subjectOfHelp->GetId(),
805 wxPoint(info->MousePos.x,
806 info->MousePos.y));
807 helpEvent.SetEventObject(radiobox);
808 if ( handler->ProcessEvent(helpEvent) )
809 {
810 processed = true;
811 break;
812 }
813 }
814 }
815 else if (info->iContextType == HELPINFO_MENUITEM)
816 {
817 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
818 helpEvent.SetEventObject(radiobox);
819 processed = handler->ProcessEvent(helpEvent);
820 }
821
822 if ( processed )
823 return 0;
824 }
825 break;
826 #endif // !__WXWINCE__
827 }
828
829 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);
830 }
831
832 #endif // wxUSE_RADIOBOX