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