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