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