]> git.saurik.com Git - wxWidgets.git/blame - src/msw/radiobox.cpp
No longer emit char events for shift/ctrl presses.
[wxWidgets.git] / src / msw / radiobox.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobox.cpp
3// Purpose: wxRadioBox
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c085e333 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
e373f51b
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
da07e033 21 #pragma implementation "radiobox.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
da07e033 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
da07e033
VZ
32 #include <stdio.h>
33 #include "wx/setup.h"
34 #include "wx/bitmap.h"
35 #include "wx/brush.h"
36 #include "wx/radiobox.h"
2bda0e17
KB
37#endif
38
39#include "wx/msw/private.h"
40
41#if !USE_SHARED_LIBRARY
da07e033 42 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
2bda0e17
KB
43#endif
44
e373f51b
VZ
45// ---------------------------------------------------------------------------
46// private functions
47// ---------------------------------------------------------------------------
48
e373f51b 49// wnd proc for radio buttons
2a47d3c1 50#ifdef __WIN32__
e373f51b
VZ
51LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hWnd,
52 UINT message,
53 WPARAM wParam,
54 LPARAM lParam);
2a47d3c1 55#endif
e373f51b
VZ
56
57// ---------------------------------------------------------------------------
58// global vars
59// ---------------------------------------------------------------------------
60
61// the pointer to standard radio button wnd proc
20e85460
JS
62// static WNDPROC s_wndprocRadioBtn = (WNDPROC)NULL;
63static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
e373f51b
VZ
64
65// ===========================================================================
66// implementation
67// ===========================================================================
68
69// ---------------------------------------------------------------------------
70// wxRadioBox
71// ---------------------------------------------------------------------------
72
73int wxRadioBox::GetNumVer() const
74{
75 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
76 {
77 return m_majorDim;
78 }
79 else
80 {
81 return (m_noItems + m_majorDim - 1)/m_majorDim;
82 }
83}
84
85int wxRadioBox::GetNumHor() const
86{
87 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
88 {
89 return (m_noItems + m_majorDim - 1)/m_majorDim;
90 }
91 else
92 {
93 return m_majorDim;
94 }
95}
96
debe6624 97bool wxRadioBox::MSWCommand(WXUINT param, WXWORD id)
2bda0e17 98{
e373f51b 99 if ( param == BN_CLICKED )
da07e033 100 {
9a5ccab4 101 int selectedButton = -1;
e373f51b
VZ
102
103 for ( int i = 0; i < m_noItems; i++ )
104 {
cc2b7472 105 if ( id == wxGetWindowId(m_radioButtons[i]) )
e373f51b 106 {
9a5ccab4 107 selectedButton = i;
e373f51b
VZ
108
109 break;
110 }
111 }
112
9a5ccab4 113 wxASSERT_MSG( selectedButton != -1, "click from alien button?" );
2bda0e17 114
9a5ccab4
VZ
115 if ( selectedButton != m_selectedButton )
116 {
117 m_selectedButton = selectedButton;
118
119 SendNotificationEvent();
120 }
121 //else: don't generate events when the selection doesn't change
e373f51b 122
da07e033
VZ
123 return TRUE;
124 }
e373f51b
VZ
125 else
126 return FALSE;
2bda0e17
KB
127}
128
129#if WXWIN_COMPATIBILITY
130wxRadioBox::wxRadioBox(wxWindow *parent, wxFunction func, const char *title,
da07e033
VZ
131 int x, int y, int width, int height,
132 int n, char **choices,
133 int majorDim, long style, const char *name)
2bda0e17
KB
134{
135 wxString *choices2 = new wxString[n];
136 for ( int i = 0; i < n; i ++) choices2[i] = choices[i];
137 Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), n, choices2, majorDim, style,
da07e033 138 wxDefaultValidator, name);
2bda0e17
KB
139 Callback(func);
140 delete choices2;
141}
142
143#endif
144
145// Radio box item
e373f51b 146wxRadioBox::wxRadioBox()
2bda0e17 147{
da07e033
VZ
148 m_selectedButton = -1;
149 m_noItems = 0;
150 m_noRowsOrCols = 0;
151 m_radioButtons = NULL;
e373f51b
VZ
152 m_majorDim = 0;
153 m_radioWidth = NULL;
154 m_radioHeight = NULL;
2bda0e17
KB
155}
156
debe6624 157bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
da07e033
VZ
158 const wxPoint& pos, const wxSize& size,
159 int n, const wxString choices[],
160 int majorDim, long style,
161 const wxValidator& val, const wxString& name)
2bda0e17 162{
da07e033
VZ
163 m_selectedButton = -1;
164 m_noItems = n;
2bda0e17 165
da07e033
VZ
166 SetName(name);
167 SetValidator(val);
2bda0e17 168
da07e033 169 parent->AddChild(this);
e373f51b
VZ
170 m_backgroundColour = parent->GetBackgroundColour();
171 m_foregroundColour = parent->GetForegroundColour();
2bda0e17 172
da07e033 173 m_windowStyle = (long&)style;
2bda0e17 174
da07e033
VZ
175 int x = pos.x;
176 int y = pos.y;
177 int width = size.x;
178 int height = size.y;
2bda0e17 179
da07e033
VZ
180 if (id == -1)
181 m_windowId = NewControlId();
182 else
183 m_windowId = id;
184
e373f51b
VZ
185 if ( majorDim == 0 )
186 m_majorDim = n;
187 else
188 m_majorDim = majorDim;
da07e033 189 m_noRowsOrCols = majorDim;
da07e033
VZ
190
191 long msStyle = GROUP_FLAGS;
192
193 bool want3D;
e373f51b 194 WXDWORD exStyle = Determine3DEffects(0, &want3D);
da07e033
VZ
195 // Even with extended styles, need to combine with WS_BORDER
196 // for them to look right.
197 /*
198 if ( want3D || wxStyleHasBorder(m_windowStyle) )
199 msStyle |= WS_BORDER;
200 */
201
e373f51b 202 HWND hwndParent = (HWND)parent->GetHWND();
da07e033
VZ
203
204 m_hWnd = (WXHWND)::CreateWindowEx
e373f51b
VZ
205 (
206 (DWORD)exStyle,
207 GROUP_CLASS,
208 title,
209 msStyle,
210 0, 0, 0, 0,
211 hwndParent,
212 (HMENU)m_windowId,
213 wxGetInstance(),
214 NULL
215 );
c085e333 216
1f112209 217#if wxUSE_CTL3D
da07e033
VZ
218 if (want3D)
219 {
220 Ctl3dSubclassCtl((HWND)m_hWnd);
221 m_useCtl3D = TRUE;
222 }
e373f51b 223#endif // wxUSE_CTL3D
2bda0e17 224
da07e033
VZ
225 SetFont(parent->GetFont());
226
e373f51b 227 SubclassWin(m_hWnd);
da07e033
VZ
228
229 // Some radio boxes test consecutive id.
e373f51b 230 (void)NewControlId();
da07e033 231 m_radioButtons = new WXHWND[n];
e373f51b
VZ
232 m_radioWidth = new int[n];
233 m_radioHeight = new int[n];
da07e033
VZ
234 int i;
235 for (i = 0; i < n; i++)
236 {
e373f51b 237 m_radioWidth[i] = m_radioHeight[i] = -1;
da07e033 238 long groupStyle = 0;
e373f51b 239 if ( i == 0 && style == 0 )
da07e033
VZ
240 groupStyle = WS_GROUP;
241 long newId = NewControlId();
242 long msStyle = groupStyle | RADIO_FLAGS;
243
e373f51b
VZ
244 HWND hwndBtn = CreateWindowEx(exStyle, RADIO_CLASS,
245 choices[i], msStyle,
246 0,0,0,0,
247 hwndParent,
248 (HMENU)newId, wxGetInstance(),
249 NULL);
2bda0e17 250
e373f51b
VZ
251 m_radioButtons[i] = (WXHWND)hwndBtn;
252 SubclassRadioButton((WXHWND)hwndBtn);
2bda0e17 253
e373f51b
VZ
254 wxFont& font = GetFont();
255 if ( font.Ok() )
da07e033 256 {
e373f51b
VZ
257 SendMessage(hwndBtn, WM_SETFONT,
258 (WPARAM)font.GetResourceHandle(), 0L);
da07e033 259 }
e373f51b 260
da07e033
VZ
261 m_subControls.Append((wxObject *)newId);
262 }
e373f51b 263
da07e033 264 // Create a dummy radio control to end the group.
e373f51b
VZ
265 (void)CreateWindowEx(0, RADIO_CLASS, "", WS_GROUP | RADIO_FLAGS,
266 0, 0, 0, 0, hwndParent,
267 (HMENU)NewControlId(), wxGetInstance(), NULL);
2bda0e17 268
da07e033 269 SetSelection(0);
2bda0e17 270
da07e033 271 SetSize(x, y, width, height);
2bda0e17 272
da07e033 273 return TRUE;
2bda0e17 274}
2bda0e17 275
e373f51b 276wxRadioBox::~wxRadioBox()
2bda0e17 277{
da07e033 278 m_isBeingDeleted = TRUE;
1eb20d4a 279
da07e033
VZ
280 if (m_radioButtons)
281 {
282 int i;
283 for (i = 0; i < m_noItems; i++)
284 DestroyWindow((HWND) m_radioButtons[i]);
285 delete[] m_radioButtons;
286 }
287 if (m_radioWidth)
e373f51b 288 delete[] m_radioWidth;
da07e033 289 if (m_radioHeight)
e373f51b 290 delete[] m_radioHeight;
da07e033 291 if (m_hWnd)
e373f51b
VZ
292 ::DestroyWindow((HWND) m_hWnd);
293 m_hWnd = 0;
2bda0e17
KB
294
295}
296
debe6624 297wxString wxRadioBox::GetLabel(int item) const
2bda0e17 298{
da07e033
VZ
299 GetWindowText((HWND)m_radioButtons[item], wxBuffer, 300);
300 return wxString(wxBuffer);
2bda0e17
KB
301}
302
debe6624 303void wxRadioBox::SetLabel(int item, const wxString& label)
2bda0e17 304{
e373f51b 305 m_radioWidth[item] = m_radioHeight[item] = -1;
da07e033 306 SetWindowText((HWND)m_radioButtons[item], (const char *)label);
2bda0e17
KB
307}
308
debe6624 309void wxRadioBox::SetLabel(int item, wxBitmap *bitmap)
2bda0e17 310{
da07e033 311 /*
e373f51b
VZ
312 m_radioWidth[item] = bitmap->GetWidth() + FB_MARGIN;
313 m_radioHeight[item] = bitmap->GetHeight() + FB_MARGIN;
da07e033 314 */
2bda0e17
KB
315}
316
317int wxRadioBox::FindString(const wxString& s) const
318{
da07e033
VZ
319 int i;
320 for (i = 0; i < m_noItems; i++)
321 {
322 GetWindowText((HWND) m_radioButtons[i], wxBuffer, 1000);
323 if (s == wxBuffer)
324 return i;
325 }
326 return -1;
2bda0e17
KB
327}
328
debe6624 329void wxRadioBox::SetSelection(int N)
2bda0e17 330{
e373f51b 331 wxCHECK_RET( (N >= 0) && (N < m_noItems), "invalid radiobox index" );
2bda0e17 332
da07e033
VZ
333 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
334 if (m_selectedButton >= 0 && m_selectedButton < m_noItems)
e373f51b
VZ
335 ::SendMessage((HWND) m_radioButtons[m_selectedButton], BM_SETCHECK, 0, 0L);
336
337 ::SendMessage((HWND)m_radioButtons[N], BM_SETCHECK, 1, 0L);
338 ::SetFocus((HWND)m_radioButtons[N]);
2bda0e17 339
da07e033 340 m_selectedButton = N;
2bda0e17
KB
341}
342
343// Get single selection, for single choice list items
e373f51b 344int wxRadioBox::GetSelection() const
2bda0e17 345{
da07e033 346 return m_selectedButton;
2bda0e17
KB
347}
348
349// Find string for position
debe6624 350wxString wxRadioBox::GetString(int N) const
2bda0e17 351{
e373f51b 352 return wxGetWindowText(m_radioButtons[N]);
2bda0e17
KB
353}
354
1f916a19 355// Restored old code.
bfc6fde4 356void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1f916a19
JS
357{
358 int currentX, currentY;
359 GetPosition(&currentX, &currentY);
360 int xx = x;
361 int yy = y;
362
363 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
364 xx = currentX;
365 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
366 yy = currentY;
367
368 char buf[400];
369
370 int y_offset = yy;
371 int x_offset = xx;
372 int current_width, cyf;
373
e373f51b 374 int cx1,cy1;
1f916a19
JS
375 wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont());
376 // Attempt to have a look coherent with other platforms:
377 // We compute the biggest toggle dim, then we align all
378 // items according this value.
379 int maxWidth = -1;
e373f51b 380 int maxHeight = -1;
1f916a19
JS
381
382 int i;
383 for (i = 0 ; i < m_noItems; i++)
384 {
385 int eachWidth;
e373f51b 386 int eachHeight;
1f916a19
JS
387 if (m_radioWidth[i]<0)
388 {
389 // It's a labelled toggle
390 GetWindowText((HWND) m_radioButtons[i], buf, 300);
391 GetTextExtent(buf, &current_width, &cyf,NULL,NULL, & GetFont());
392 eachWidth = (int)(current_width + RADIO_SIZE);
393 eachHeight = (int)((3*cyf)/2);
394 }
395 else
396 {
e373f51b
VZ
397 eachWidth = m_radioWidth[i];
398 eachHeight = m_radioHeight[i];
1f916a19 399 }
e373f51b
VZ
400 if (maxWidth<eachWidth) maxWidth = eachWidth;
401 if (maxHeight<eachHeight) maxHeight = eachHeight;
1f916a19
JS
402 }
403
404 if (m_hWnd)
405 {
e373f51b 406 int totWidth;
1f916a19
JS
407 int totHeight;
408
e373f51b
VZ
409 int nbHor = GetNumHor(),
410 nbVer = GetNumVer();
1f916a19
JS
411
412 // this formula works, but I don't know why.
413 // Please, be sure what you do if you modify it!!
414 if (m_radioWidth[0]<0)
e373f51b 415 totHeight = (nbVer * maxHeight) + cy1/2;
1f916a19 416 else
e373f51b
VZ
417 totHeight = nbVer * (maxHeight+cy1/2);
418 totWidth = nbHor * (maxWidth+cx1);
1f916a19
JS
419
420#if (!CTL3D)
421 // Requires a bigger group box in plain Windows
e373f51b 422 MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+(3*cy1)/2,TRUE);
1f916a19 423#else
e373f51b 424 MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+cy1,TRUE);
1f916a19
JS
425#endif
426 x_offset += cx1;
427 y_offset += cy1;
428 }
429
430#if (!CTL3D)
431 y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label
432 // JACS 2/12/93. CTL3D draws group label quite high.
433#endif
e373f51b
VZ
434 int startX = x_offset;
435 int startY = y_offset;
1f916a19
JS
436
437 for ( i = 0 ; i < m_noItems; i++)
438 {
439 // Bidimensional radio adjustment
440 if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0?
441 {
442 if (m_windowStyle & wxRA_VERTICAL)
443 {
444 y_offset = startY;
e373f51b 445 x_offset += maxWidth + cx1;
1f916a19
JS
446 }
447 else
448 {
e373f51b
VZ
449 x_offset = startX;
450 y_offset += maxHeight;
1f916a19 451 if (m_radioWidth[0]>0)
e373f51b 452 y_offset += cy1/2;
1f916a19
JS
453 }
454 }
e373f51b
VZ
455 int eachWidth;
456 int eachHeight;
1f916a19
JS
457 if (m_radioWidth[i]<0)
458 {
459 // It's a labeled item
460 GetWindowText((HWND) m_radioButtons[i], buf, 300);
461 GetTextExtent(buf, &current_width, &cyf,NULL,NULL, & GetFont());
462
463 // How do we find out radio button bitmap size!!
464 // By adjusting them carefully, manually :-)
465 eachWidth = (int)(current_width + RADIO_SIZE);
466 eachHeight = (int)((3*cyf)/2);
467 }
468 else
469 {
e373f51b
VZ
470 eachWidth = m_radioWidth[i];
471 eachHeight = m_radioHeight[i];
1f916a19
JS
472 }
473
474 MoveWindow((HWND) m_radioButtons[i],x_offset,y_offset,eachWidth,eachHeight,TRUE);
475 if (m_windowStyle & wxRA_SPECIFY_ROWS)
476 {
477 y_offset += maxHeight;
478 if (m_radioWidth[0]>0)
e373f51b 479 y_offset += cy1/2;
1f916a19
JS
480 }
481 else
482 x_offset += maxWidth + cx1;
483 }
484}
485
2bda0e17
KB
486
487void wxRadioBox::GetSize(int *width, int *height) const
488{
da07e033
VZ
489 RECT rect;
490 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
2bda0e17 491
da07e033
VZ
492 if (m_hWnd)
493 wxFindMaxSize(m_hWnd, &rect);
2bda0e17 494
da07e033
VZ
495 int i;
496 for (i = 0; i < m_noItems; i++)
497 wxFindMaxSize(m_radioButtons[i], &rect);
2bda0e17 498
da07e033
VZ
499 *width = rect.right - rect.left;
500 *height = rect.bottom - rect.top;
2bda0e17
KB
501}
502
503void wxRadioBox::GetPosition(int *x, int *y) const
504{
da07e033
VZ
505 wxWindow *parent = GetParent();
506 RECT rect;
507 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
508
509 int i;
510 for (i = 0; i < m_noItems; i++)
511 wxFindMaxSize(m_radioButtons[i], &rect);
512
513 if (m_hWnd)
514 wxFindMaxSize(m_hWnd, &rect);
515
516 // Since we now have the absolute screen coords,
517 // if there's a parent we must subtract its top left corner
518 POINT point;
519 point.x = rect.left;
520 point.y = rect.top;
521 if (parent)
522 {
523 ::ScreenToClient((HWND) parent->GetHWND(), &point);
524 }
525 // We may be faking the client origin.
526 // So a window that's really at (0, 30) may appear
527 // (to wxWin apps) to be at (0, 0).
528 if (GetParent())
529 {
530 wxPoint pt(GetParent()->GetClientAreaOrigin());
531 point.x -= pt.x;
532 point.y -= pt.y;
533 }
534
535 *x = point.x;
536 *y = point.y;
2bda0e17
KB
537}
538
e373f51b 539wxString wxRadioBox::GetLabel() const
2bda0e17 540{
da07e033
VZ
541 if (m_hWnd)
542 {
543 GetWindowText((HWND) m_hWnd, wxBuffer, 300);
544 return wxString(wxBuffer);
545 }
546 else return wxString("");
2bda0e17
KB
547}
548
549void wxRadioBox::SetLabel(const wxString& label)
550{
da07e033
VZ
551 if (m_hWnd)
552 SetWindowText((HWND) m_hWnd, label);
2bda0e17
KB
553}
554
e373f51b 555void wxRadioBox::SetFocus()
2bda0e17 556{
da07e033
VZ
557 if (m_noItems > 0)
558 {
559 if (m_selectedButton == -1)
560 ::SetFocus((HWND) m_radioButtons[0]);
561 else
562 ::SetFocus((HWND) m_radioButtons[m_selectedButton]);
563 }
2bda0e17
KB
564
565}
566
debe6624 567bool wxRadioBox::Show(bool show)
2bda0e17 568{
aed0ed3c 569 m_isShown = show;
da07e033
VZ
570 int cshow;
571 if (show)
572 cshow = SW_SHOW;
573 else
574 cshow = SW_HIDE;
575 if (m_hWnd)
576 ShowWindow((HWND) m_hWnd, cshow);
577 int i;
578 for (i = 0; i < m_noItems; i++)
579 ShowWindow((HWND) m_radioButtons[i], cshow);
580 return TRUE;
2bda0e17
KB
581}
582
583// Enable a specific button
debe6624 584void wxRadioBox::Enable(int item, bool enable)
2bda0e17 585{
da07e033 586 if (item<0)
e373f51b 587 wxWindow::Enable(enable);
da07e033
VZ
588 else if (item < m_noItems)
589 ::EnableWindow((HWND) m_radioButtons[item], enable);
2bda0e17
KB
590}
591
592// Enable all controls
cc2b7472 593bool wxRadioBox::Enable(bool enable)
2bda0e17 594{
cc2b7472
VZ
595 if ( !wxControl::Enable(enable) )
596 return FALSE;
1eb20d4a 597
da07e033
VZ
598 int i;
599 for (i = 0; i < m_noItems; i++)
600 ::EnableWindow((HWND) m_radioButtons[i], enable);
cc2b7472
VZ
601
602 return TRUE;
2bda0e17
KB
603}
604
605// Show a specific button
debe6624 606void wxRadioBox::Show(int item, bool show)
2bda0e17 607{
da07e033 608 if (item<0)
e373f51b 609 wxRadioBox::Show(show);
da07e033
VZ
610 else if (item < m_noItems)
611 {
612 int cshow;
613 if (show)
614 cshow = SW_SHOW;
615 else
616 cshow = SW_HIDE;
617 ShowWindow((HWND) m_radioButtons[item], cshow);
618 }
2bda0e17
KB
619}
620
debe6624 621WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
da07e033 622 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 623{
1f112209 624#if wxUSE_CTL3D
da07e033
VZ
625 if ( m_useCtl3D )
626 {
627 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
628 return (WXHBRUSH) hbrush;
629 }
2bda0e17
KB
630#endif
631
da07e033
VZ
632 if (GetParent()->GetTransparentBackground())
633 SetBkMode((HDC) pDC, TRANSPARENT);
634 else
635 SetBkMode((HDC) pDC, OPAQUE);
2bda0e17 636
da07e033
VZ
637 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
638 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
2bda0e17 639
da07e033 640 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
2bda0e17 641
da07e033
VZ
642 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
643 // has a zero usage count.
644 // backgroundBrush->RealizeResource();
645 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
2bda0e17
KB
646}
647
648// For single selection items only
e373f51b 649wxString wxRadioBox::GetStringSelection() const
2bda0e17 650{
e373f51b
VZ
651 wxString result;
652 int sel = GetSelection();
da07e033 653 if (sel > -1)
e373f51b
VZ
654 result = GetString(sel);
655
656 return result;
2bda0e17
KB
657}
658
e373f51b 659bool wxRadioBox::SetStringSelection(const wxString& s)
2bda0e17 660{
da07e033
VZ
661 int sel = FindString (s);
662 if (sel > -1)
2bda0e17 663 {
da07e033
VZ
664 SetSelection (sel);
665 return TRUE;
2bda0e17 666 }
da07e033
VZ
667 else
668 return FALSE;
2bda0e17
KB
669}
670
2bda0e17
KB
671bool wxRadioBox::ContainsHWND(WXHWND hWnd) const
672{
da07e033 673 int i;
2bda0e17 674 for (i = 0; i < Number(); i++)
da07e033
VZ
675 if (GetRadioButtons()[i] == hWnd)
676 return TRUE;
677 return FALSE;
2bda0e17
KB
678}
679
680void wxRadioBox::Command (wxCommandEvent & event)
681{
da07e033
VZ
682 SetSelection (event.m_commandInt);
683 ProcessCommand (event);
2bda0e17
KB
684}
685
983162bd
JS
686long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
687{
da07e033 688 if (nMsg == WM_NCHITTEST)
983162bd
JS
689 {
690 int xPos = LOWORD(lParam); // horizontal position of cursor
691 int yPos = HIWORD(lParam); // vertical position of cursor
692
693 ScreenToClient(&xPos, &yPos);
694
695 // Make sure you can drag by the top of the groupbox, but let
696 // other (enclosed) controls get mouse events also
697 if (yPos < 10)
698 return (long)HTCLIENT;
699 }
700
da07e033 701 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
983162bd 702}
2bda0e17 703
e373f51b
VZ
704void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
705{
706 HWND hwndBtn = (HWND)hWndBtn;
707
708 if ( !s_wndprocRadioBtn )
20e85460 709 s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC);
e373f51b 710
2a47d3c1
JS
711 // No GWL_USERDATA in Win16, so omit this subclassing.
712#ifdef __WIN32__
e373f51b
VZ
713 ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc);
714 ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this);
2a47d3c1 715#endif
e373f51b
VZ
716}
717
9a5ccab4
VZ
718void wxRadioBox::SendNotificationEvent()
719{
720 wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
721 event.SetInt( m_selectedButton );
722 event.SetEventObject( this );
723 ProcessCommand(event);
724}
725
e373f51b
VZ
726// ---------------------------------------------------------------------------
727// window proc for radio buttons
728// ---------------------------------------------------------------------------
729
2a47d3c1
JS
730#ifdef __WIN32__
731
e373f51b
VZ
732LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
733 UINT msg,
734 WPARAM wParam,
735 LPARAM lParam)
736{
737 bool processed = TRUE;
738 if ( msg != WM_KEYDOWN )
739 processed = FALSE;
740
741 if ( processed )
742 {
743 wxRadioBox *radiobox = (wxRadioBox *)::GetWindowLong(hwnd, GWL_USERDATA);
744
745 wxCHECK_MSG( radiobox, 0, "radio button without radio box?" );
746
747 int sel = radiobox->GetSelection();
748
749 switch ( wParam )
750 {
751 case VK_UP:
752 sel--;
753 break;
754
755 case VK_LEFT:
756 sel -= radiobox->GetNumVer();
757 break;
758
759 case VK_DOWN:
760 sel++;
761 break;
762
763 case VK_RIGHT:
764 sel += radiobox->GetNumVer();
765 break;
766
767 case VK_TAB:
768 {
769 wxNavigationKeyEvent event;
770 event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100));
771 event.SetWindowChange(FALSE);
772 event.SetEventObject(radiobox);
773
774 if ( radiobox->GetEventHandler()->ProcessEvent(event) )
775 return 0;
776 }
777 // fall through
778
779 default:
780 processed = FALSE;
781 }
782
783 if ( processed )
784 {
785 if ( sel >= 0 && sel < radiobox->Number() )
9a5ccab4 786 {
e373f51b 787 radiobox->SetSelection(sel);
9a5ccab4
VZ
788
789 // emulate the button click
790 radiobox->SendNotificationEvent();
791 }
e373f51b
VZ
792 }
793 }
794
795 if ( !processed )
20e85460 796 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, msg, wParam, lParam);
e373f51b
VZ
797 else
798 return 0;
799}
2a47d3c1 800#endif
e373f51b 801