]> git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobox.cpp
Removed redundant cursor files
[wxWidgets.git] / src / msw / radiobox.cpp
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
57 WX_DEFINE_FLAGS( wxRadioBoxStyle )
58
59 wxBEGIN_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
92 wxEND_FLAGS( wxRadioBoxStyle )
93
94 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
95
96 wxBEGIN_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
99 wxEND_PROPERTIES_TABLE()
100
101 #else
102 IMPLEMENT_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
118 LRESULT 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
128 static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
129
130 // ===========================================================================
131 // implementation
132 // ===========================================================================
133
134 // ---------------------------------------------------------------------------
135 // wxRadioBox creation
136 // ---------------------------------------------------------------------------
137
138 // Radio box item
139 void 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
148 bool 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
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 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!
260 void 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
275 bool 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
318 void wxRadioBox::Command(wxCommandEvent & event)
319 {
320 SetSelection (event.GetInt());
321 SetFocus();
322 ProcessCommand(event);
323 }
324
325 void 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
338 int wxRadioBox::GetCount() const
339 {
340 return m_radioButtons->GetCount();
341 }
342
343 // returns the number of rows
344 int 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
357 int 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
369 void 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 InvalidateBestSize();
379 }
380
381 void wxRadioBox::SetSelection(int N)
382 {
383 wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") );
384
385 // unselect the old button
386 if ( m_selectedButton != wxNOT_FOUND )
387 ::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L);
388
389 // and select the new one
390 ::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L);
391
392 m_selectedButton = N;
393 }
394
395 // Find string for position
396 wxString wxRadioBox::GetString(int item) const
397 {
398 wxCHECK_MSG( IsValid(item), wxEmptyString,
399 wxT("invalid radiobox index") );
400
401 return wxGetWindowText((*m_radioButtons)[item]);
402 }
403
404 void wxRadioBox::SetFocus()
405 {
406 if ( GetCount() > 0 )
407 {
408 ::SetFocus((*m_radioButtons)[m_selectedButton == wxNOT_FOUND
409 ? 0
410 : m_selectedButton]);
411 }
412 }
413
414 // Enable a specific button
415 bool wxRadioBox::Enable(int item, bool enable)
416 {
417 wxCHECK_MSG( IsValid(item), false,
418 wxT("invalid item in wxRadioBox::Enable()") );
419
420 BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable);
421
422 return (ret == 0) == enable;
423 }
424
425 // Show a specific button
426 bool wxRadioBox::Show(int item, bool show)
427 {
428 wxCHECK_MSG( IsValid(item), false,
429 wxT("invalid item in wxRadioBox::Show()") );
430
431 BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE);
432
433 bool changed = (ret != 0) == show;
434 if( changed )
435 InvalidateBestSize();
436 return changed;
437 }
438
439 WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
440
441 // ----------------------------------------------------------------------------
442 // size calculations
443 // ----------------------------------------------------------------------------
444
445 wxSize wxRadioBox::GetMaxButtonSize() const
446 {
447 // calculate the max button size
448 int widthMax = 0,
449 heightMax = 0;
450 const int count = GetCount();
451 for ( int i = 0 ; i < count; i++ )
452 {
453 int width, height;
454 if ( m_radioWidth[i] < 0 )
455 {
456 GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height);
457
458 // adjust the size to take into account the radio box itself
459 // FIXME this is totally bogus!
460 width += RADIO_SIZE;
461 height *= 3;
462 height /= 2;
463 }
464 else
465 {
466 width = m_radioWidth[i];
467 height = m_radioHeight[i];
468 }
469
470 if ( widthMax < width )
471 widthMax = width;
472 if ( heightMax < height )
473 heightMax = height;
474 }
475
476 return wxSize(widthMax, heightMax);
477 }
478
479 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
480 {
481 // the radiobox should be big enough for its buttons
482 int cx1, cy1;
483 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
484
485 int extraHeight = cy1;
486
487 int height = GetNumVer() * sizeBtn.y + cy1/2 + extraHeight;
488 int width = GetNumHor() * (sizeBtn.x + cx1) + cx1;
489
490 // Add extra space under the label, if it exists.
491 if (!wxControl::GetLabel().empty())
492 height += cy1/2;
493
494 // and also wide enough for its label
495 int widthLabel;
496 GetTextExtent(GetTitle(), &widthLabel, NULL);
497 widthLabel += RADIO_SIZE; // FIXME this is bogus too
498 if ( widthLabel > width )
499 width = widthLabel;
500
501 return wxSize(width, height);
502 }
503
504 wxSize wxRadioBox::DoGetBestSize() const
505 {
506 wxSize best = GetTotalButtonSize(GetMaxButtonSize());
507 CacheBestSize(best);
508 return best;
509 }
510
511 // Restored old code.
512 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
513 {
514 int currentX, currentY;
515 GetPosition(&currentX, &currentY);
516 int widthOld, heightOld;
517 GetSize(&widthOld, &heightOld);
518
519 int xx = x;
520 int yy = y;
521
522 if (x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
523 xx = currentX;
524 if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
525 yy = currentY;
526
527 int y_offset = 0;
528 int x_offset = 0;
529
530 int cx1, cy1;
531 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
532
533 // Attempt to have a look coherent with other platforms: We compute the
534 // biggest toggle dim, then we align all items according this value.
535 wxSize maxSize = GetMaxButtonSize();
536 int maxWidth = maxSize.x,
537 maxHeight = maxSize.y;
538
539 wxSize totSize = GetTotalButtonSize(maxSize);
540 int totWidth = totSize.x,
541 totHeight = totSize.y;
542
543 // only change our width/height if asked for
544 if ( width == wxDefaultCoord )
545 {
546 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
547 width = totWidth;
548 else
549 width = widthOld;
550 }
551
552 if ( height == wxDefaultCoord )
553 {
554 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
555 height = totHeight;
556 else
557 height = heightOld;
558 }
559
560 // if our parent had prepared a defer window handle for us, use it (unless
561 // we are a top level window)
562
563 #if USE_DEFERRED_SIZING
564 wxWindowMSW *parent = GetParent();
565 HDWP hdwp = parent && !IsTopLevel() ? (HDWP)parent->m_hDWP : NULL;
566 #else
567 HDWP hdwp = 0;
568 #endif
569
570 wxMoveWindowDeferred(hdwp, this, GetHwnd(), xx, yy, width, height);
571
572 // Now position all the buttons: the current button will be put at
573 // wxPoint(x_offset, y_offset) and the new row/column will start at
574 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
575 // maxHeight) except for the buttons in the last column which should extend
576 // to the right border of radiobox and thus can be wider than this.
577
578 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
579 // left to right order and m_majorDim is the number of columns while
580 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
581 // m_majorDim is the number of rows.
582
583 x_offset += cx1;
584 y_offset += cy1;
585
586 // Add extra space under the label, if it exists.
587 if (!wxControl::GetLabel().empty())
588 y_offset += cy1/2;
589
590 int startX = x_offset;
591 int startY = y_offset;
592
593 const int count = GetCount();
594 for ( int i = 0; i < count; i++ )
595 {
596 // the last button in the row may be wider than the other ones as the
597 // radiobox may be wider than the sum of the button widths (as it
598 // happens, for example, when the radiobox label is very long)
599 bool isLastInTheRow;
600 if ( m_windowStyle & wxRA_SPECIFY_COLS )
601 {
602 // item is the last in its row if it is a multiple of the number of
603 // columns or if it is just the last item
604 int n = i + 1;
605 isLastInTheRow = ((n % m_majorDim) == 0) || (n == count);
606 }
607 else // wxRA_SPECIFY_ROWS
608 {
609 // item is the last in the row if it is in the last columns
610 isLastInTheRow = i >= (count/m_majorDim)*m_majorDim;
611 }
612
613 // is this the start of new row/column?
614 if ( i && (i % m_majorDim == 0) )
615 {
616 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
617 {
618 // start of new column
619 y_offset = startY;
620 x_offset += maxWidth + cx1;
621 }
622 else // start of new row
623 {
624 x_offset = startX;
625 y_offset += maxHeight;
626 if (m_radioWidth[0]>0)
627 y_offset += cy1/2;
628 }
629 }
630
631 int widthBtn;
632 if ( isLastInTheRow )
633 {
634 // make the button go to the end of radio box
635 widthBtn = startX + width - x_offset - 2*cx1;
636 if ( widthBtn < maxWidth )
637 widthBtn = maxWidth;
638 }
639 else
640 {
641 // normal button, always of the same size
642 widthBtn = maxWidth;
643 }
644
645 // make all buttons of the same, maximal size - like this they cover
646 // the radiobox entirely and the radiobox tooltips are always shown
647 // (otherwise they are not when the mouse pointer is in the radiobox
648 // part not belonging to any radiobutton)
649 ::MoveWindow((*m_radioButtons)[i],
650 x_offset, y_offset, widthBtn, maxHeight,
651 TRUE);
652
653 // where do we put the next button?
654 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
655 {
656 // below this one
657 y_offset += maxHeight;
658 if (m_radioWidth[0]>0)
659 y_offset += cy1/2;
660 }
661 else
662 {
663 // to the right of this one
664 x_offset += widthBtn + cx1;
665 }
666 }
667
668 #if USE_DEFERRED_SIZING
669 if (parent)
670 {
671 // hdwp must be updated as it may have been changed
672 parent->m_hDWP = (WXHANDLE)hdwp;
673 }
674 #endif
675 }
676
677 // ----------------------------------------------------------------------------
678 // radio box drawing
679 // ----------------------------------------------------------------------------
680
681 #ifndef __WXWINCE__
682
683 WXHRGN wxRadioBox::MSWGetRegionWithoutChildren()
684 {
685 RECT rc;
686 ::GetWindowRect(GetHwnd(), &rc);
687 HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
688
689 const size_t count = GetCount();
690 for ( size_t i = 0; i < count; ++i )
691 {
692 ::GetWindowRect((*m_radioButtons)[i], &rc);
693 AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc));
694 ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF);
695 }
696
697 return (WXHRGN)hrgn;
698 }
699
700 WXLRESULT
701 wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
702 {
703 if ( nMsg == WM_PRINTCLIENT )
704 {
705 // we have to process WM_PRINTCLIENT ourselves as otherwise the radio
706 // buttons background would never be drawn unless we have a parent with
707 // non default background
708
709 // so check first if we have one
710 if ( !HandlePrintClient((WXHDC)wParam) )
711 {
712 // no, we don't, erase the background ourselves (don't use our own
713 // colour as with static box, see comments there)
714 wxBrush brush(GetParent()->GetBackgroundColour());
715 wxFillRect(GetHwnd(), (HDC)wParam, GetHbrushOf(brush));
716 }
717
718 return 0;
719 }
720 // FIXME: Without this, the radiobox corrupts other controls as it moves
721 // in a dynamic layout. Refreshing causes flicker, but it's better than
722 // leaving droppings. Note that for some reason, wxStaticBox doesn't need
723 // this (perhaps because it has no real children?)
724 else if (nMsg == WM_MOVE)
725 {
726 WXLRESULT res = wxControl::MSWWindowProc(nMsg, wParam, lParam);
727 wxRect rect = GetRect();
728 GetParent()->Refresh(true, & rect);
729 return res;
730 }
731
732 return wxStaticBox::MSWWindowProc(nMsg, wParam, lParam);
733 }
734
735 #endif // __WXWINCE__
736
737 // ---------------------------------------------------------------------------
738 // window proc for radio buttons
739 // ---------------------------------------------------------------------------
740
741 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
742 UINT message,
743 WPARAM wParam,
744 LPARAM lParam)
745 {
746 switch ( message )
747 {
748 case WM_GETDLGCODE:
749 // we must tell IsDialogMessage()/our kbd processing code that we
750 // want to process arrows ourselves because neither of them is
751 // smart enough to handle arrows properly for us
752 {
753 long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd,
754 message, wParam, lParam);
755
756 return lDlgCode | DLGC_WANTARROWS;
757 }
758
759 #if wxUSE_TOOLTIPS
760 case WM_NOTIFY:
761 {
762 NMHDR* hdr = (NMHDR *)lParam;
763 if ( hdr->code == TTN_NEEDTEXT )
764 {
765 wxRadioBox *
766 radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
767
768 wxCHECK_MSG( radiobox, 0,
769 wxT("radio button without radio box?") );
770
771 wxToolTip *tooltip = radiobox->GetToolTip();
772 if ( tooltip )
773 {
774 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
775 ttt->lpszText = (wxChar *)tooltip->GetTip().c_str();
776 }
777
778 // processed
779 return 0;
780 }
781 }
782 break;
783 #endif // wxUSE_TOOLTIPS
784
785 case WM_KEYDOWN:
786 {
787 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
788
789 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
790
791 bool processed = true;
792
793 wxDirection dir;
794 switch ( wParam )
795 {
796 case VK_UP:
797 dir = wxUP;
798 break;
799
800 case VK_LEFT:
801 dir = wxLEFT;
802 break;
803
804 case VK_DOWN:
805 dir = wxDOWN;
806 break;
807
808 case VK_RIGHT:
809 dir = wxRIGHT;
810 break;
811
812 default:
813 processed = false;
814
815 // just to suppress the compiler warning
816 dir = wxALL;
817 }
818
819 if ( processed )
820 {
821 int selOld = radiobox->GetSelection();
822 int selNew = radiobox->GetNextItem
823 (
824 selOld,
825 dir,
826 radiobox->GetWindowStyle()
827 );
828
829 if ( selNew != selOld )
830 {
831 radiobox->SetSelection(selNew);
832 radiobox->SetFocus();
833
834 // emulate the button click
835 radiobox->SendNotificationEvent();
836
837 return 0;
838 }
839 }
840 }
841 break;
842
843 case WM_SETFOCUS:
844 case WM_KILLFOCUS:
845 {
846 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
847
848 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
849
850 // if we don't do this, no focus events are generated for the
851 // radiobox and, besides, we need to notify the parent about
852 // the focus change, otherwise the focus handling logic in
853 // wxControlContainer doesn't work
854 if ( message == WM_SETFOCUS )
855 radiobox->HandleSetFocus((WXHWND)wParam);
856 else
857 radiobox->HandleKillFocus((WXHWND)wParam);
858 }
859 break;
860
861 #ifndef __WXWINCE__
862 case WM_HELP:
863 {
864 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
865
866 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
867
868 bool processed = false;
869
870 wxEvtHandler * const handler = radiobox->GetEventHandler();
871
872 HELPINFO* info = (HELPINFO*) lParam;
873 if ( info->iContextType == HELPINFO_WINDOW )
874 {
875 for ( wxWindow* subjectOfHelp = radiobox;
876 subjectOfHelp;
877 subjectOfHelp = subjectOfHelp->GetParent() )
878 {
879 wxHelpEvent helpEvent(wxEVT_HELP,
880 subjectOfHelp->GetId(),
881 wxPoint(info->MousePos.x,
882 info->MousePos.y));
883 helpEvent.SetEventObject(radiobox);
884 if ( handler->ProcessEvent(helpEvent) )
885 {
886 processed = true;
887 break;
888 }
889 }
890 }
891 else if (info->iContextType == HELPINFO_MENUITEM)
892 {
893 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
894 helpEvent.SetEventObject(radiobox);
895 processed = handler->ProcessEvent(helpEvent);
896 }
897
898 if ( processed )
899 return 0;
900 }
901 break;
902 #endif // !__WXWINCE__
903 }
904
905 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);
906 }
907
908 #endif // wxUSE_RADIOBOX
909