]> git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobox.cpp
fixed typo in previous commit which, instead of fixing the bug in wxSizerflags::Align...
[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 GetHwnd(),
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, GetHwnd(),
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 int count = GetCount();
273 for ( 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 int wxRadioBox::GetCount() const
327 {
328 return m_radioButtons->GetCount();
329 }
330
331 void wxRadioBox::SetString(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(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(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(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(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(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 int count = GetCount();
436 for ( 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(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 = 0;
513 int x_offset = 0;
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 int count = GetCount();
569 for ( 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 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 ::MoveWindow((*m_radioButtons)[i],
625 x_offset, y_offset, widthBtn, maxHeight,
626 TRUE);
627
628 // where do we put the next button?
629 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
630 {
631 // below this one
632 y_offset += maxHeight;
633 if (m_radioWidth[0]>0)
634 y_offset += cy1/2;
635 }
636 else
637 {
638 // to the right of this one
639 x_offset += widthBtn + cx1;
640 }
641 }
642 }
643
644 // ----------------------------------------------------------------------------
645 // radio box drawing
646 // ----------------------------------------------------------------------------
647
648 #ifndef __WXWINCE__
649
650 WXHRGN wxRadioBox::MSWGetRegionWithoutChildren()
651 {
652 RECT rc;
653 ::GetWindowRect(GetHwnd(), &rc);
654 HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
655
656 const size_t count = GetCount();
657 for ( size_t i = 0; i < count; ++i )
658 {
659 // don't clip out hidden children
660 if ( !IsItemShown(i) )
661 continue;
662
663 ::GetWindowRect((*m_radioButtons)[i], &rc);
664 AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc));
665 ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF);
666 }
667
668 return (WXHRGN)hrgn;
669 }
670
671 WXLRESULT
672 wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
673 {
674 // FIXME: Without this, the radiobox corrupts other controls as it moves
675 // in a dynamic layout. Refreshing causes flicker, but it's better than
676 // leaving droppings. Note that for some reason, wxStaticBox doesn't need
677 // this (perhaps because it has no real children?)
678 if ( nMsg == WM_MOVE )
679 {
680 WXLRESULT res = wxControl::MSWWindowProc(nMsg, wParam, lParam);
681 wxRect rect = GetRect();
682 GetParent()->Refresh(true, & rect);
683 return res;
684 }
685
686 return wxStaticBox::MSWWindowProc(nMsg, wParam, lParam);
687 }
688
689 #endif // __WXWINCE__
690
691 // ---------------------------------------------------------------------------
692 // window proc for radio buttons
693 // ---------------------------------------------------------------------------
694
695 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
696 UINT message,
697 WPARAM wParam,
698 LPARAM lParam)
699 {
700 switch ( message )
701 {
702 case WM_GETDLGCODE:
703 // we must tell IsDialogMessage()/our kbd processing code that we
704 // want to process arrows ourselves because neither of them is
705 // smart enough to handle arrows properly for us
706 {
707 long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd,
708 message, wParam, lParam);
709
710 return lDlgCode | DLGC_WANTARROWS;
711 }
712
713 #if wxUSE_TOOLTIPS
714 case WM_NOTIFY:
715 {
716 NMHDR* hdr = (NMHDR *)lParam;
717 if ( hdr->code == TTN_NEEDTEXT )
718 {
719 wxRadioBox *
720 radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
721
722 wxCHECK_MSG( radiobox, 0,
723 wxT("radio button without radio box?") );
724
725 wxToolTip *tooltip = radiobox->GetToolTip();
726 if ( tooltip )
727 {
728 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
729 ttt->lpszText = (wxChar *)tooltip->GetTip().c_str();
730 }
731
732 // processed
733 return 0;
734 }
735 }
736 break;
737 #endif // wxUSE_TOOLTIPS
738
739 case WM_KEYDOWN:
740 {
741 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
742
743 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
744
745 bool processed = true;
746
747 wxDirection dir;
748 switch ( wParam )
749 {
750 case VK_UP:
751 dir = wxUP;
752 break;
753
754 case VK_LEFT:
755 dir = wxLEFT;
756 break;
757
758 case VK_DOWN:
759 dir = wxDOWN;
760 break;
761
762 case VK_RIGHT:
763 dir = wxRIGHT;
764 break;
765
766 default:
767 processed = false;
768
769 // just to suppress the compiler warning
770 dir = wxALL;
771 }
772
773 if ( processed )
774 {
775 int selOld = radiobox->GetSelection();
776 int selNew = radiobox->GetNextItem
777 (
778 selOld,
779 dir,
780 radiobox->GetWindowStyle()
781 );
782
783 if ( selNew != selOld )
784 {
785 radiobox->SetSelection(selNew);
786 radiobox->SetFocus();
787
788 // emulate the button click
789 radiobox->SendNotificationEvent();
790
791 return 0;
792 }
793 }
794 }
795 break;
796
797 case WM_SETFOCUS:
798 case WM_KILLFOCUS:
799 {
800 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
801
802 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
803
804 // if we don't do this, no focus events are generated for the
805 // radiobox and, besides, we need to notify the parent about
806 // the focus change, otherwise the focus handling logic in
807 // wxControlContainer doesn't work
808 if ( message == WM_SETFOCUS )
809 radiobox->HandleSetFocus((WXHWND)wParam);
810 else
811 radiobox->HandleKillFocus((WXHWND)wParam);
812 }
813 break;
814
815 #ifndef __WXWINCE__
816 case WM_HELP:
817 {
818 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
819
820 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
821
822 bool processed = false;
823
824 wxEvtHandler * const handler = radiobox->GetEventHandler();
825
826 HELPINFO* info = (HELPINFO*) lParam;
827 if ( info->iContextType == HELPINFO_WINDOW )
828 {
829 for ( wxWindow* subjectOfHelp = radiobox;
830 subjectOfHelp;
831 subjectOfHelp = subjectOfHelp->GetParent() )
832 {
833 wxHelpEvent helpEvent(wxEVT_HELP,
834 subjectOfHelp->GetId(),
835 wxPoint(info->MousePos.x,
836 info->MousePos.y));
837 helpEvent.SetEventObject(radiobox);
838 if ( handler->ProcessEvent(helpEvent) )
839 {
840 processed = true;
841 break;
842 }
843 }
844 }
845 else if (info->iContextType == HELPINFO_MENUITEM)
846 {
847 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
848 helpEvent.SetEventObject(radiobox);
849 processed = handler->ProcessEvent(helpEvent);
850 }
851
852 if ( processed )
853 return 0;
854 }
855 break;
856 #endif // !__WXWINCE__
857 }
858
859 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);
860 }
861
862 #endif // wxUSE_RADIOBOX