]> git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobox.cpp
fixes for new lib dirs for wxMSW
[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/private.h"
42
43 #if wxUSE_TOOLTIPS
44 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
45 #include <commctrl.h>
46 #endif
47 #include "wx/tooltip.h"
48 #endif // wxUSE_TOOLTIPS
49
50 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
51
52 /*
53 selection
54 content
55 label
56 dimension
57 item
58 */
59
60 // there are two possible ways to create the radio buttons: either as children
61 // of the radiobox or as siblings of it - allow playing with both variants for
62 // now, eventually we will choose the best one for our purposes
63 //
64 // two main problems are the keyboard navigation inside the radiobox (arrows
65 // should switch between buttons, not pass focus to the next control) and the
66 // tooltips - a tooltip is associated with the radiobox itself, not the
67 // children...
68 //
69 // the problems with setting this to 1:
70 // a) Alt-<mnemonic of radiobox> isn't handled properly by IsDialogMessage()
71 // because it sets focus to the next control accepting it which is not a
72 // radio button but a radiobox sibling in this case - the only solution to
73 // this would be to handle Alt-<mnemonic> ourselves
74 // b) the problems with setting radiobox colours under Win98/2K were reported
75 // but I couldn't reproduce it so I have no idea about what causes it
76 //
77 // the problems with setting this to 0:
78 // a) the tooltips are not shown for the radiobox - possible solution: make
79 // TTM_WINDOWFROMPOS handling code in msw/tooltip.cpp work (easier said than
80 // done because I don't know why it doesn't work)
81 #define RADIOBTN_PARENT_IS_RADIOBOX 0
82
83 // ---------------------------------------------------------------------------
84 // private functions
85 // ---------------------------------------------------------------------------
86
87 // wnd proc for radio buttons
88 #ifdef __WIN32__
89 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hWnd,
90 UINT message,
91 WPARAM wParam,
92 LPARAM lParam);
93
94 // ---------------------------------------------------------------------------
95 // global vars
96 // ---------------------------------------------------------------------------
97
98 // the pointer to standard radio button wnd proc
99 static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
100
101 #endif // __WIN32__
102
103 // ===========================================================================
104 // implementation
105 // ===========================================================================
106
107 // ---------------------------------------------------------------------------
108 // wxRadioBox
109 // ---------------------------------------------------------------------------
110
111 int wxRadioBox::GetCount() const
112 {
113 return m_noItems;
114 }
115
116 int wxRadioBox::GetColumnCount() const
117 {
118 return GetNumHor();
119 }
120
121 int wxRadioBox::GetRowCount() const
122 {
123 return GetNumVer();
124 }
125
126 // returns the number of rows
127 int wxRadioBox::GetNumVer() const
128 {
129 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
130 {
131 return m_majorDim;
132 }
133 else
134 {
135 return (m_noItems + m_majorDim - 1)/m_majorDim;
136 }
137 }
138
139 // returns the number of columns
140 int wxRadioBox::GetNumHor() const
141 {
142 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
143 {
144 return (m_noItems + m_majorDim - 1)/m_majorDim;
145 }
146 else
147 {
148 return m_majorDim;
149 }
150 }
151
152 bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id)
153 {
154 if ( cmd == BN_CLICKED )
155 {
156 if (id == GetId())
157 return TRUE;
158
159 int selectedButton = -1;
160
161 for ( int i = 0; i < m_noItems; i++ )
162 {
163 if ( id == wxGetWindowId(m_radioButtons[i]) )
164 {
165 selectedButton = i;
166
167 break;
168 }
169 }
170
171 if ( selectedButton == -1 )
172 {
173 // just ignore it - due to a hack with WM_NCHITTEST handling in our
174 // wnd proc, we can receive dummy click messages when we click near
175 // the radiobox edge (this is ugly but Julian wouldn't let me get
176 // rid of this...)
177 return FALSE;
178 }
179
180 if ( selectedButton != m_selectedButton )
181 {
182 m_selectedButton = selectedButton;
183
184 SendNotificationEvent();
185 }
186 //else: don't generate events when the selection doesn't change
187
188 return TRUE;
189 }
190 else
191 return FALSE;
192 }
193
194 // Radio box item
195 wxRadioBox::wxRadioBox()
196 {
197 m_selectedButton = -1;
198 m_noItems = 0;
199 m_noRowsOrCols = 0;
200 m_radioButtons = NULL;
201 m_majorDim = 0;
202 m_radioWidth = NULL;
203 m_radioHeight = NULL;
204 }
205
206 bool wxRadioBox::Create(wxWindow *parent,
207 wxWindowID id,
208 const wxString& title,
209 const wxPoint& pos,
210 const wxSize& size,
211 int n,
212 const wxString choices[],
213 int majorDim,
214 long style,
215 const wxValidator& val,
216 const wxString& name)
217 {
218 // initialize members
219 m_selectedButton = -1;
220 m_noItems = 0;
221
222 m_majorDim = majorDim == 0 ? n : majorDim;
223 m_noRowsOrCols = majorDim;
224
225 // common initialization
226 if ( !CreateControl(parent, id, pos, size, style, val, name) )
227 return FALSE;
228
229 // create the static box
230 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX | WS_GROUP,
231 pos, size, title, 0) )
232 return FALSE;
233
234 // and now create the buttons
235 m_noItems = n;
236 #if RADIOBTN_PARENT_IS_RADIOBOX
237 HWND hwndParent = GetHwnd();
238 #else
239 HWND hwndParent = GetHwndOf(parent);
240 #endif
241
242 // Some radio boxes test consecutive id.
243 (void)NewControlId();
244 m_radioButtons = new WXHWND[n];
245 m_radioWidth = new int[n];
246 m_radioHeight = new int[n];
247
248 WXHFONT hfont = 0;
249 wxFont& font = GetFont();
250 if ( font.Ok() )
251 {
252 hfont = font.GetResourceHandle();
253 }
254
255 for ( int i = 0; i < n; i++ )
256 {
257 m_radioWidth[i] =
258 m_radioHeight[i] = -1;
259 long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
260 if ( i == 0 && style == 0 )
261 styleBtn |= WS_GROUP;
262
263 long newId = NewControlId();
264
265 HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
266 choices[i],
267 styleBtn,
268 0, 0, 0, 0, // will be set in SetSize()
269 hwndParent,
270 (HMENU)newId,
271 wxGetInstance(),
272 NULL);
273
274 if ( !hwndBtn )
275 {
276 wxLogLastError(wxT("CreateWindow(radio btn)"));
277
278 return FALSE;
279 }
280
281 m_radioButtons[i] = (WXHWND)hwndBtn;
282
283 SubclassRadioButton((WXHWND)hwndBtn);
284
285 if ( hfont )
286 {
287 ::SendMessage(hwndBtn, WM_SETFONT, (WPARAM)hfont, 0L);
288 }
289
290 m_subControls.Add(newId);
291 }
292
293 // Create a dummy radio control to end the group.
294 (void)::CreateWindow(_T("BUTTON"),
295 wxEmptyString,
296 WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
297 0, 0, 0, 0, hwndParent,
298 (HMENU)NewControlId(), wxGetInstance(), NULL);
299
300 SetSelection(0);
301
302 SetSize(pos.x, pos.y, size.x, size.y);
303
304 return TRUE;
305 }
306
307 wxRadioBox::~wxRadioBox()
308 {
309 m_isBeingDeleted = TRUE;
310
311 if (m_radioButtons)
312 {
313 int i;
314 for (i = 0; i < m_noItems; i++)
315 ::DestroyWindow((HWND)m_radioButtons[i]);
316 delete[] m_radioButtons;
317 }
318
319 if (m_radioWidth)
320 delete[] m_radioWidth;
321 if (m_radioHeight)
322 delete[] m_radioHeight;
323
324 }
325
326 void wxRadioBox::SetString(int item, const wxString& label)
327 {
328 wxCHECK_RET( item >= 0 && item < m_noItems, wxT("invalid radiobox index") );
329
330 m_radioWidth[item] = m_radioHeight[item] = -1;
331 SetWindowText((HWND)m_radioButtons[item], label.c_str());
332 }
333
334 void wxRadioBox::SetSelection(int N)
335 {
336 wxCHECK_RET( (N >= 0) && (N < m_noItems), wxT("invalid radiobox index") );
337
338 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
339 if (m_selectedButton >= 0 && m_selectedButton < m_noItems)
340 ::SendMessage((HWND) m_radioButtons[m_selectedButton], BM_SETCHECK, 0, 0L);
341
342 ::SendMessage((HWND)m_radioButtons[N], BM_SETCHECK, 1, 0L);
343
344 m_selectedButton = N;
345 }
346
347 // Get single selection, for single choice list items
348 int wxRadioBox::GetSelection() const
349 {
350 return m_selectedButton;
351 }
352
353 // Find string for position
354 wxString wxRadioBox::GetString(int item) const
355 {
356 wxCHECK_MSG( item >= 0 && item < m_noItems, wxEmptyString,
357 wxT("invalid radiobox index") );
358
359 return wxGetWindowText(m_radioButtons[item]);
360 }
361
362 // ----------------------------------------------------------------------------
363 // size calculations
364 // ----------------------------------------------------------------------------
365
366 wxSize wxRadioBox::GetMaxButtonSize() const
367 {
368 // calculate the max button size
369 int widthMax = 0,
370 heightMax = 0;
371 for ( int i = 0 ; i < m_noItems; i++ )
372 {
373 int width, height;
374 if ( m_radioWidth[i] < 0 )
375 {
376 GetTextExtent(wxGetWindowText(m_radioButtons[i]), &width, &height);
377
378 // adjust the size to take into account the radio box itself
379 // FIXME this is totally bogus!
380 width += RADIO_SIZE;
381 height *= 3;
382 height /= 2;
383 }
384 else
385 {
386 width = m_radioWidth[i];
387 height = m_radioHeight[i];
388 }
389
390 if ( widthMax < width )
391 widthMax = width;
392 if ( heightMax < height )
393 heightMax = height;
394 }
395
396 return wxSize(widthMax, heightMax);
397 }
398
399 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
400 {
401 // the radiobox should be big enough for its buttons
402 int cx1, cy1;
403 wxGetCharSize(m_hWnd, &cx1, &cy1, &GetFont());
404
405 int extraHeight = cy1;
406
407 /* We'll assume the adjustments below are OK for Win 3.1 too
408 #if defined(CTL3D) && !CTL3D
409 // Requires a bigger group box in plain Windows
410 extraHeight *= 3;
411 extraHeight /= 2;
412 #endif
413 */
414
415 int height = GetNumVer() * sizeBtn.y + cy1/2 + extraHeight;
416 int width = GetNumHor() * (sizeBtn.x + cx1) + cx1;
417
418 // Add extra space under the label, if it exists.
419 if (!wxControl::GetLabel().IsEmpty())
420 height += cy1/2;
421
422 // and also wide enough for its label
423 int widthLabel;
424 GetTextExtent(GetTitle(), &widthLabel, NULL);
425 widthLabel += RADIO_SIZE; // FIXME this is bogus too
426 if ( widthLabel > width )
427 width = widthLabel;
428
429 return wxSize(width, height);
430 }
431
432 wxSize wxRadioBox::DoGetBestSize() const
433 {
434 return GetTotalButtonSize(GetMaxButtonSize());
435 }
436
437 // Restored old code.
438 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
439 {
440 int currentX, currentY;
441 GetPosition(&currentX, &currentY);
442 int widthOld, heightOld;
443 GetSize(&widthOld, &heightOld);
444
445 int xx = x;
446 int yy = y;
447
448 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
449 xx = currentX;
450 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
451 yy = currentY;
452
453 #if RADIOBTN_PARENT_IS_RADIOBOX
454 int y_offset = 0;
455 int x_offset = 0;
456 #else
457 int y_offset = yy;
458 int x_offset = xx;
459 #endif
460
461 int cx1, cy1;
462 wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont());
463
464 // Attempt to have a look coherent with other platforms: We compute the
465 // biggest toggle dim, then we align all items according this value.
466 wxSize maxSize = GetMaxButtonSize();
467 int maxWidth = maxSize.x,
468 maxHeight = maxSize.y;
469
470 wxSize totSize = GetTotalButtonSize(maxSize);
471 int totWidth = totSize.x,
472 totHeight = totSize.y;
473
474 // only change our width/height if asked for
475 if ( width == -1 )
476 {
477 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
478 width = totWidth;
479 else
480 width = widthOld;
481 }
482
483 if ( height == -1 )
484 {
485 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
486 height = totHeight;
487 else
488 height = heightOld;
489 }
490
491 ::MoveWindow(GetHwnd(), xx, yy, width, height, TRUE);
492
493 // Now position all the buttons: the current button will be put at
494 // wxPoint(x_offset, y_offset) and the new row/column will start at
495 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
496 // maxHeight) except for the buttons in the last column which should extend
497 // to the right border of radiobox and thus can be wider than this.
498
499 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
500 // left to right order and m_majorDim is the number of columns while
501 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
502 // m_majorDim is the number of rows.
503
504 x_offset += cx1;
505 y_offset += cy1;
506
507 // Add extra space under the label, if it exists.
508 if (!wxControl::GetLabel().IsEmpty())
509 y_offset += cy1/2;
510
511 int startX = x_offset;
512 int startY = y_offset;
513
514 for ( int i = 0; i < m_noItems; i++ )
515 {
516 // the last button in the row may be wider than the other ones as the
517 // radiobox may be wider than the sum of the button widths (as it
518 // happens, for example, when the radiobox label is very long)
519 bool isLastInTheRow;
520 if ( m_windowStyle & wxRA_SPECIFY_COLS )
521 {
522 // item is the last in its row if it is a multiple of the number of
523 // columns or if it is just the last item
524 int n = i + 1;
525 isLastInTheRow = ((n % m_majorDim) == 0) || (n == m_noItems);
526 }
527 else // wxRA_SPECIFY_ROWS
528 {
529 // item is the last in the row if it is in the last columns
530 isLastInTheRow = i >= (m_noItems/m_majorDim)*m_majorDim;
531 }
532
533 // is this the start of new row/column?
534 if ( i && (i % m_majorDim == 0) )
535 {
536 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
537 {
538 // start of new column
539 y_offset = startY;
540 x_offset += maxWidth + cx1;
541 }
542 else // start of new row
543 {
544 x_offset = startX;
545 y_offset += maxHeight;
546 if (m_radioWidth[0]>0)
547 y_offset += cy1/2;
548 }
549 }
550
551 int widthBtn;
552 if ( isLastInTheRow )
553 {
554 // make the button go to the end of radio box
555 widthBtn = startX + width - x_offset - 2*cx1;
556 if ( widthBtn < maxWidth )
557 widthBtn = maxWidth;
558 }
559 else
560 {
561 // normal button, always of the same size
562 widthBtn = maxWidth;
563 }
564
565 // VZ: make all buttons of the same, maximal size - like this they
566 // cover the radiobox entirely and the radiobox tooltips are always
567 // shown (otherwise they are not when the mouse pointer is in the
568 // radiobox part not belonging to any radiobutton)
569 ::MoveWindow((HWND)m_radioButtons[i],
570 x_offset, y_offset, widthBtn, maxHeight,
571 TRUE);
572
573 // where do we put the next button?
574 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
575 {
576 // below this one
577 y_offset += maxHeight;
578 if (m_radioWidth[0]>0)
579 y_offset += cy1/2;
580 }
581 else
582 {
583 // to the right of this one
584 x_offset += widthBtn + cx1;
585 }
586 }
587 }
588
589 void wxRadioBox::GetSize(int *width, int *height) const
590 {
591 RECT rect;
592 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
593
594 if (m_hWnd)
595 wxFindMaxSize(m_hWnd, &rect);
596
597 int i;
598 for (i = 0; i < m_noItems; i++)
599 wxFindMaxSize(m_radioButtons[i], &rect);
600
601 *width = rect.right - rect.left;
602 *height = rect.bottom - rect.top;
603 }
604
605 void wxRadioBox::GetPosition(int *x, int *y) const
606 {
607 wxWindow *parent = GetParent();
608 RECT rect = { -1, -1, -1, -1 };
609
610 int i;
611 for (i = 0; i < m_noItems; i++)
612 wxFindMaxSize(m_radioButtons[i], &rect);
613
614 if (m_hWnd)
615 wxFindMaxSize(m_hWnd, &rect);
616
617 // Since we now have the absolute screen coords, if there's a parent we
618 // must subtract its top left corner
619 POINT point;
620 point.x = rect.left;
621 point.y = rect.top;
622 if (parent)
623 {
624 ::ScreenToClient((HWND) parent->GetHWND(), &point);
625 }
626
627 // We may be faking the client origin. So a window that's really at (0, 30)
628 // may appear (to wxWin apps) to be at (0, 0).
629 if (GetParent())
630 {
631 wxPoint pt(GetParent()->GetClientAreaOrigin());
632 point.x -= pt.x;
633 point.y -= pt.y;
634 }
635
636 *x = point.x;
637 *y = point.y;
638 }
639
640 void wxRadioBox::SetFocus()
641 {
642 if (m_noItems > 0)
643 {
644 ::SetFocus((HWND)m_radioButtons[m_selectedButton == -1
645 ? 0
646 : m_selectedButton]);
647 }
648
649 }
650
651 bool wxRadioBox::Show(bool show)
652 {
653 if ( !wxControl::Show(show) )
654 return FALSE;
655
656 int nCmdShow = show ? SW_SHOW : SW_HIDE;
657 for ( int i = 0; i < m_noItems; i++ )
658 {
659 ::ShowWindow((HWND)m_radioButtons[i], nCmdShow);
660 }
661
662 return TRUE;
663 }
664
665 // Enable a specific button
666 void wxRadioBox::Enable(int item, bool enable)
667 {
668 wxCHECK_RET( item >= 0 && item < m_noItems,
669 wxT("invalid item in wxRadioBox::Enable()") );
670
671 ::EnableWindow((HWND) m_radioButtons[item], enable);
672 }
673
674 // Enable all controls
675 bool wxRadioBox::Enable(bool enable)
676 {
677 if ( !wxControl::Enable(enable) )
678 return FALSE;
679
680 for (int i = 0; i < m_noItems; i++)
681 ::EnableWindow((HWND) m_radioButtons[i], enable);
682
683 return TRUE;
684 }
685
686 // Show a specific button
687 void wxRadioBox::Show(int item, bool show)
688 {
689 wxCHECK_RET( item >= 0 && item < m_noItems,
690 wxT("invalid item in wxRadioBox::Show()") );
691
692 ::ShowWindow((HWND)m_radioButtons[item], show ? SW_SHOW : SW_HIDE);
693 }
694
695 bool wxRadioBox::ContainsHWND(WXHWND hWnd) const
696 {
697 size_t count = GetCount();
698 for ( size_t i = 0; i < count; i++ )
699 {
700 if ( GetRadioButtons()[i] == hWnd )
701 return TRUE;
702 }
703
704 return FALSE;
705 }
706
707 void wxRadioBox::Command(wxCommandEvent & event)
708 {
709 SetSelection (event.m_commandInt);
710 SetFocus();
711 ProcessCommand (event);
712 }
713
714 // NB: if this code is changed, wxGetWindowForHWND() which relies on having the
715 // radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
716 void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
717 {
718 HWND hwndBtn = (HWND)hWndBtn;
719
720 if ( !s_wndprocRadioBtn )
721 s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC);
722
723 ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc);
724 ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this);
725 }
726
727 void wxRadioBox::SendNotificationEvent()
728 {
729 wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
730 event.SetInt( m_selectedButton );
731 event.SetString( GetString(m_selectedButton) );
732 event.SetEventObject( this );
733 ProcessCommand(event);
734 }
735
736 bool wxRadioBox::SetFont(const wxFont& font)
737 {
738 if ( !wxControl::SetFont(font) )
739 {
740 // nothing to do
741 return FALSE;
742 }
743
744 // also set the font of our radio buttons
745 WXHFONT hfont = wxFont(font).GetResourceHandle();
746 for ( int n = 0; n < m_noItems; n++ )
747 {
748 HWND hwndBtn = (HWND)m_radioButtons[n];
749 ::SendMessage(hwndBtn, WM_SETFONT, (WPARAM)hfont, 0L);
750
751 // otherwise the buttons are not redrawn correctly
752 ::InvalidateRect(hwndBtn, NULL, FALSE /* don't erase bg */);
753 }
754
755 return TRUE;
756 }
757
758 // ----------------------------------------------------------------------------
759 // our window proc
760 // ----------------------------------------------------------------------------
761
762 long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
763 {
764 switch ( nMsg )
765 {
766 #ifdef __WIN32__
767 case WM_CTLCOLORSTATIC:
768 // set the colour of the radio buttons to be the same as ours
769 {
770 HDC hdc = (HDC)wParam;
771
772 const wxColour& colBack = GetBackgroundColour();
773 ::SetBkColor(hdc, wxColourToRGB(colBack));
774 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
775
776 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
777
778 return (WXHBRUSH)brush->GetResourceHandle();
779 }
780 #endif // Win32
781
782 // VZ: this code breaks radiobox redrawing under Windows XP, don't use
783 // it. If you need to get messages from the static controls,
784 // create them as a child of another (non static) window
785 #if 0
786 // This is required for the radiobox to be sensitive to mouse input,
787 // e.g. for Dialog Editor.
788 case WM_NCHITTEST:
789 {
790 int xPos = LOWORD(lParam); // horizontal position of cursor
791 int yPos = HIWORD(lParam); // vertical position of cursor
792
793 ScreenToClient(&xPos, &yPos);
794
795 // Make sure you can drag by the top of the groupbox, but let
796 // other (enclosed) controls get mouse events also
797 if (yPos < 10)
798 return (long)HTCLIENT;
799 }
800 break;
801 #endif // 0
802 }
803
804 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
805 }
806
807 WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
808 #if wxUSE_CTL3D
809 WXUINT message,
810 WXWPARAM wParam,
811 WXLPARAM lParam
812 #else
813 WXUINT WXUNUSED(message),
814 WXWPARAM WXUNUSED(wParam),
815 WXLPARAM WXUNUSED(lParam)
816 #endif
817 )
818 {
819 #if wxUSE_CTL3D
820 if ( m_useCtl3D )
821 {
822 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
823 return (WXHBRUSH) hbrush;
824 }
825 #endif // wxUSE_CTL3D
826
827 HDC hdc = (HDC)pDC;
828 wxColour colBack = GetBackgroundColour();
829
830 if (!IsEnabled())
831 colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
832
833 ::SetBkColor(hdc, wxColourToRGB(colBack));
834 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
835
836 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
837
838 return (WXHBRUSH)brush->GetResourceHandle();
839 }
840
841
842 // ---------------------------------------------------------------------------
843 // window proc for radio buttons
844 // ---------------------------------------------------------------------------
845
846 #ifdef __WIN32__
847
848 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
849 UINT message,
850 WPARAM wParam,
851 LPARAM lParam)
852 {
853 switch ( message )
854 {
855 case WM_GETDLGCODE:
856 // we must tell IsDialogMessage()/our kbd processing code that we
857 // want to process arrows ourselves because neither of them is
858 // smart enough to handle arrows properly for us
859 {
860 long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd,
861 message, wParam, lParam);
862
863 return lDlgCode | DLGC_WANTARROWS;
864 }
865
866 #if wxUSE_TOOLTIPS
867 case WM_NOTIFY:
868 {
869 NMHDR* hdr = (NMHDR *)lParam;
870 if ( hdr->code == TTN_NEEDTEXT )
871 {
872 wxRadioBox *radiobox = (wxRadioBox *)
873 ::GetWindowLong(hwnd, GWL_USERDATA);
874
875 wxCHECK_MSG( radiobox, 0,
876 wxT("radio button without radio box?") );
877
878 wxToolTip *tooltip = radiobox->GetToolTip();
879 if ( tooltip )
880 {
881 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
882 ttt->lpszText = (wxChar *)tooltip->GetTip().c_str();
883 }
884
885 // processed
886 return 0;
887 }
888 }
889 break;
890 #endif // wxUSE_TOOLTIPS
891
892 case WM_KEYDOWN:
893 {
894 wxRadioBox *radiobox = (wxRadioBox *)
895 ::GetWindowLong(hwnd, GWL_USERDATA);
896
897 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
898
899 bool processed = TRUE;
900
901 wxDirection dir;
902 switch ( wParam )
903 {
904 case VK_UP:
905 dir = wxUP;
906 break;
907
908 case VK_LEFT:
909 dir = wxLEFT;
910 break;
911
912 case VK_DOWN:
913 dir = wxDOWN;
914 break;
915
916 case VK_RIGHT:
917 dir = wxRIGHT;
918 break;
919
920 default:
921 processed = FALSE;
922
923 // just to suppress the compiler warning
924 dir = wxALL;
925 }
926
927 if ( processed )
928 {
929 int selOld = radiobox->GetSelection();
930 int selNew = radiobox->GetNextItem
931 (
932 selOld,
933 dir,
934 radiobox->GetWindowStyle()
935 );
936
937 if ( selNew != selOld )
938 {
939 radiobox->SetSelection(selNew);
940 radiobox->SetFocus();
941
942 // emulate the button click
943 radiobox->SendNotificationEvent();
944
945 return 0;
946 }
947 }
948 }
949 break;
950
951 #ifdef __WIN32__
952 case WM_HELP:
953 {
954 wxRadioBox *radiobox = (wxRadioBox *)
955 ::GetWindowLong(hwnd, GWL_USERDATA);
956
957 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
958
959 bool processed = TRUE;
960
961 // HELPINFO doesn't seem to be supported on WinCE.
962 #ifndef __WXWINCE__
963 HELPINFO* info = (HELPINFO*) lParam;
964 // Don't yet process menu help events, just windows
965 if (info->iContextType == HELPINFO_WINDOW)
966 #endif
967 {
968 wxWindow* subjectOfHelp = radiobox;
969 bool eventProcessed = FALSE;
970 while (subjectOfHelp && !eventProcessed)
971 {
972 wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(),
973 #ifdef __WXWINCE__
974 wxPoint(0, 0)
975 #else
976 wxPoint(info->MousePos.x, info->MousePos.y)
977 #endif
978 ) ; // info->iCtrlId);
979 helpEvent.SetEventObject(radiobox);
980 eventProcessed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
981
982 // Go up the window hierarchy until the event is handled (or not)
983 subjectOfHelp = subjectOfHelp->GetParent();
984 }
985 processed = eventProcessed;
986 }
987 #ifndef __WXWINCE__
988 else if (info->iContextType == HELPINFO_MENUITEM)
989 {
990 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
991 helpEvent.SetEventObject(radiobox);
992 processed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
993 }
994 else
995 processed = FALSE;
996 #endif
997 if (processed)
998 return 0;
999
1000 break;
1001 }
1002 #endif // __WIN32__
1003 }
1004
1005 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);
1006 }
1007
1008 #endif // __WIN32__
1009
1010 #endif // wxUSE_RADIOBOX