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