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