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