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