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