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