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