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