SetCursor() works now
[wxWidgets.git] / src / msw / radiobox.cpp
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
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "radiobox.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <stdio.h>
25 #include "wx/setup.h"
26 #include "wx/bitmap.h"
27 #include "wx/brush.h"
28 #include "wx/radiobox.h"
29 #endif
30
31 #include "wx/msw/private.h"
32
33 #if !USE_SHARED_LIBRARY
34 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
35 #endif
36
37 bool wxRadioBox::MSWCommand(WXUINT param, WXWORD id)
38 {
39 if (param == BN_CLICKED)
40 {
41 #ifdef __WIN32__
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;
46 #else
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;
51 #endif
52
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;
60 }
61
62 #if WXWIN_COMPATIBILITY
63 wxRadioBox::wxRadioBox(wxWindow *parent, wxFunction func, const char *title,
64 int x, int y, int width, int height,
65 int n, char **choices,
66 int majorDim, long style, const char *name)
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,
71 wxDefaultValidator, name);
72 Callback(func);
73 delete choices2;
74 }
75
76 #endif
77
78 // Radio box item
79 wxRadioBox::wxRadioBox(void)
80 {
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 ;
88 }
89
90 bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
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)
95 {
96 m_selectedButton = -1;
97 m_noItems = n;
98
99 SetName(name);
100 SetValidator(val);
101
102 parent->AddChild(this);
103 m_backgroundColour = parent->GetBackgroundColour() ;
104 m_foregroundColour = parent->GetForegroundColour() ;
105
106 m_windowStyle = (long&)style;
107
108 int x = pos.x;
109 int y = pos.y;
110 int width = size.x;
111 int height = size.y;
112
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 );
150
151 #if wxUSE_CTL3D
152 if (want3D)
153 {
154 Ctl3dSubclassCtl((HWND)m_hWnd);
155 m_useCtl3D = TRUE;
156 }
157 #endif
158
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);
181 #if wxUSE_CTL3D
182 if (want3D)
183 {
184 Ctl3dSubclassCtl((HWND) m_hWnd);
185 m_useCtl3D = TRUE;
186 }
187 #endif
188 if (GetFont().Ok())
189 {
190 SendMessage((HWND)m_radioButtons[i],WM_SETFONT,
191 (WPARAM)GetFont().GetResourceHandle(),0L);
192 }
193 m_subControls.Append((wxObject *)newId);
194 }
195
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);
198
199 SetSelection(0);
200
201 SetSize(x, y, width, height);
202
203 return TRUE;
204 }
205
206 #if 0
207 bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
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)
212 {
213 m_selectedButton = -1;
214 m_noRowsOrCols = 0;
215 m_noItems = n;
216
217 SetName(name);
218 SetValidator(val);
219
220 parent->AddChild(this);
221 m_backgroundColour = parent->GetBackgroundColour() ;
222 m_foregroundColour = parent->GetForegroundColour() ;
223
224 m_windowStyle = (long&)style;
225
226 int x = pos.x;
227 int y = pos.y;
228 int width = size.x;
229 int height = size.y;
230
231 if (id == -1)
232 m_windowId = NewControlId();
233 else
234 m_windowId = id;
235
236
237 m_noRowsOrCols = majorDim;
238 if (majorDim==0)
239 m_majorDim = n ;
240 m_majorDim = majorDim ;
241 HWND the_handle ;
242
243 long msStyle = GROUP_FLAGS;
244
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;
251
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) ;
256
257 the_handle = (HWND) parent->GetHWND();
258
259 #if wxUSE_CTL3D
260 if (want3D)
261 {
262 Ctl3dSubclassCtl((HWND) m_hWnd);
263 m_useCtl3D = TRUE;
264 }
265 #endif
266
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);
292 #if wxUSE_CTL3D
293 if (want3D)
294 {
295 Ctl3dSubclassCtl((HWND) m_hWnd);
296 m_useCtl3D = TRUE;
297 }
298 #endif
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);
303
304 SetSelection(0);
305
306 SetSize(x, y, width, height);
307
308 return TRUE;
309 }
310 #endif
311
312 wxRadioBox::~wxRadioBox(void)
313 {
314 m_isBeingDeleted = TRUE;
315
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 ;
330
331 }
332
333 wxString wxRadioBox::GetLabel(int item) const
334 {
335 GetWindowText((HWND)m_radioButtons[item], wxBuffer, 300);
336 return wxString(wxBuffer);
337 }
338
339 void wxRadioBox::SetLabel(int item, const wxString& label)
340 {
341 m_radioWidth[item] = m_radioHeight[item] = -1 ;
342 SetWindowText((HWND)m_radioButtons[item], (const char *)label);
343 }
344
345 void wxRadioBox::SetLabel(int item, wxBitmap *bitmap)
346 {
347 /*
348 m_radioWidth[item] = bitmap->GetWidth() + FB_MARGIN ;
349 m_radioHeight[item] = bitmap->GetHeight() + FB_MARGIN ;
350 */
351 }
352
353 int wxRadioBox::FindString(const wxString& s) const
354 {
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;
363 }
364
365 void wxRadioBox::SetSelection(int N)
366 {
367 if ((N < 0) || (N >= m_noItems))
368 return;
369
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);
373
374 SendMessage((HWND) m_radioButtons[N], BM_SETCHECK, 1, 0L);
375 m_selectedButton = N;
376 }
377
378 // Get single selection, for single choice list items
379 int wxRadioBox::GetSelection(void) const
380 {
381 return m_selectedButton;
382 }
383
384 // Find string for position
385 wxString wxRadioBox::GetString(int N) const
386 {
387 GetWindowText((HWND) m_radioButtons[N], wxBuffer, 1000);
388 return wxString(wxBuffer);
389 }
390
391 /* NOTE. The contributed code to size the group box according to the
392 * given size simply didn't work (try it in e.g. Dialog Editor)
393 * so sorry, I'm removing it. If you reinstate it, please make sure
394 * it's bullet-proof in Dialog Editor. Meanwhile, it's better to have it
395 * working with a calculated size, than supposedly flexibly but
396 * actually broken. This is rather important when it comes to releasing
397 * stable software. Suggestion: if you modify this, rewrite it completely.
398 * -- JACS 7/2/99
399 */
400
401 #if 0
402 void wxRadioBox::SetSize(int x, int y, int width, int height, int sizeFlags)
403 {
404 int currentX, currentY;
405 GetPosition(&currentX, &currentY);
406 int xx = x;
407 int yy = y;
408
409 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
410 xx = currentX;
411 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
412 yy = currentY;
413
414 AdjustForParentClientOrigin(xx, yy, sizeFlags);
415
416 wxString textRadioButton;
417
418 int y_offset = yy;
419 int x_offset = xx;
420 int current_width, cyf;
421
422 int cx1,cy1;
423 wxGetCharSize(m_hWnd, &cx1, &cy1, & this->GetFont());
424
425 // number of radio boxes in both directions
426 int nbHor, nbVer;
427 if (m_windowStyle & wxRA_SPECIFY_ROWS)
428 {
429 nbVer = m_majorDim ;
430 nbHor = (m_noItems+m_majorDim-1)/m_majorDim ;
431 }
432 else
433 {
434 nbHor = m_majorDim ;
435 nbVer = (m_noItems+m_majorDim-1)/m_majorDim ;
436 }
437
438 // Attempt to have a look coherent with other platforms:
439 // We compute the biggest toggle dim, then we align all
440 // items according this value.
441 int maxWidth = width,
442 maxHeight = height;
443
444 // if we're given the width or height explicitly do not recalculate it, but
445 // use what we have
446
447 bool calcWidth = maxWidth == -1,
448 calcHeight = maxHeight == -1;
449
450 if ( calcWidth || calcHeight )
451 {
452 // init vars to avoid compiler warnings, even if we don't use them
453 int eachWidth = 0,
454 eachHeight = 0;
455
456 for ( int i = 0 ; i < m_noItems; i++ )
457 {
458 if ( m_radioWidth[i] < 0 )
459 {
460 // It's a labelled toggle
461 textRadioButton = wxGetWindowText(m_radioButtons[i]);
462 GetTextExtent(textRadioButton, &current_width, &cyf,
463 NULL, NULL, &GetFont());
464
465 if ( calcWidth )
466 eachWidth = current_width + RADIO_SIZE;
467 if ( calcHeight )
468 eachHeight = (3*cyf)/2;
469 }
470 else
471 {
472 if ( calcWidth )
473 eachWidth = m_radioWidth[i] ;
474 if ( calcHeight )
475 eachHeight = m_radioHeight[i] ;
476 }
477
478 if ( calcWidth && maxWidth < eachWidth )
479 maxWidth = eachWidth;
480 if ( calcHeight && maxHeight < eachHeight )
481 maxHeight = eachHeight;
482 }
483 }
484 else
485 {
486 maxHeight = height/nbVer;
487 maxWidth = width/nbHor;
488 }
489
490 if (m_hWnd)
491 {
492 int totWidth ;
493 int totHeight;
494
495 // this formula works, but I don't know why.
496 // Please, be sure what you do if you modify it!!
497 if (m_radioWidth[0]<0)
498 totHeight = (nbVer * maxHeight) + cy1/2 ;
499 else
500 totHeight = nbVer * (maxHeight+cy1/2) ;
501 totWidth = nbHor * (maxWidth+cx1) ;
502
503 #if !defined(__WIN32__) && (!wxUSE_CTL3D)
504 // Requires a bigger group box in plain Windows
505 MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+(3*cy1)/2,TRUE) ;
506 #else
507 MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+cy1,TRUE) ;
508 #endif
509 x_offset += cx1;
510 y_offset += cy1;
511 }
512
513 #if !defined(__WIN32__) && (!wxUSE_CTL3D)
514 y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label
515 // JACS 2/12/93. CTL3D draws group label quite high.
516 #endif
517 int startX = x_offset ;
518 int startY = y_offset ;
519
520 for ( int i = 0 ; i < m_noItems; i++)
521 {
522 // Bidimensional radio adjustment
523 if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0?
524 {
525 if (m_windowStyle & wxRA_SPECIFY_ROWS)
526 {
527 y_offset = startY;
528 x_offset += maxWidth + cx1 ;
529 }
530 else
531 {
532 x_offset = startX ;
533 y_offset += maxHeight ;
534 if (m_radioWidth[0]>0)
535 y_offset += cy1/2 ;
536 }
537 }
538
539 int eachWidth;
540 int eachHeight;
541
542 if ( m_radioWidth[i] < 0 )
543 {
544 // It's a labeled item
545 textRadioButton = wxGetWindowText(m_radioButtons[i]);
546 GetTextExtent(textRadioButton, &current_width, &cyf,
547 NULL,NULL, & this->GetFont());
548
549 eachWidth = current_width + RADIO_SIZE;
550 eachHeight = (3*cyf)/2;
551 }
552 else
553 {
554 eachWidth = m_radioWidth[i] ;
555 eachHeight = m_radioHeight[i] ;
556 }
557
558 MoveWindow((HWND)m_radioButtons[i], x_offset, y_offset,
559 eachWidth,eachHeight,TRUE);
560 if ( m_windowStyle & wxRA_VERTICAL )
561 if (m_windowStyle & wxRA_SPECIFY_ROWS)
562 {
563 y_offset += maxHeight;
564 if ( m_radioWidth[0] > 0 )
565 y_offset += cy1/2 ;
566 }
567 else
568 {
569 x_offset += maxWidth + cx1;
570 }
571 }
572 }
573 #endif
574
575 // Restored old code.
576 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
577 {
578 int currentX, currentY;
579 GetPosition(&currentX, &currentY);
580 int xx = x;
581 int yy = y;
582
583 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
584 xx = currentX;
585 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
586 yy = currentY;
587
588 char buf[400];
589
590 int y_offset = yy;
591 int x_offset = xx;
592 int current_width, cyf;
593
594 int cx1,cy1 ;
595 wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont());
596 // Attempt to have a look coherent with other platforms:
597 // We compute the biggest toggle dim, then we align all
598 // items according this value.
599 int maxWidth = -1;
600 int maxHeight = -1 ;
601
602 int i;
603 for (i = 0 ; i < m_noItems; i++)
604 {
605 int eachWidth;
606 int eachHeight ;
607 if (m_radioWidth[i]<0)
608 {
609 // It's a labelled toggle
610 GetWindowText((HWND) m_radioButtons[i], buf, 300);
611 GetTextExtent(buf, &current_width, &cyf,NULL,NULL, & GetFont());
612 eachWidth = (int)(current_width + RADIO_SIZE);
613 eachHeight = (int)((3*cyf)/2);
614 }
615 else
616 {
617 eachWidth = m_radioWidth[i] ;
618 eachHeight = m_radioHeight[i] ;
619 }
620 if (maxWidth<eachWidth) maxWidth = eachWidth ;
621 if (maxHeight<eachHeight) maxHeight = eachHeight ;
622 }
623
624 if (m_hWnd)
625 {
626 int totWidth ;
627 int totHeight;
628
629 int nbHor,nbVer;
630
631 if (m_windowStyle & wxRA_SPECIFY_ROWS)
632 {
633 nbVer = m_majorDim ;
634 nbHor = (m_noItems+m_majorDim-1)/m_majorDim ;
635 }
636 else
637 {
638 nbHor = m_majorDim ;
639 nbVer = (m_noItems+m_majorDim-1)/m_majorDim ;
640 }
641
642 // this formula works, but I don't know why.
643 // Please, be sure what you do if you modify it!!
644 if (m_radioWidth[0]<0)
645 totHeight = (nbVer * maxHeight) + cy1/2 ;
646 else
647 totHeight = nbVer * (maxHeight+cy1/2) ;
648 totWidth = nbHor * (maxWidth+cx1) ;
649
650 #if (!CTL3D)
651 // Requires a bigger group box in plain Windows
652 MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+(3*cy1)/2,TRUE) ;
653 #else
654 MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+cy1,TRUE) ;
655 #endif
656 x_offset += cx1;
657 y_offset += cy1;
658 }
659
660 #if (!CTL3D)
661 y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label
662 // JACS 2/12/93. CTL3D draws group label quite high.
663 #endif
664 int startX = x_offset ;
665 int startY = y_offset ;
666
667 for ( i = 0 ; i < m_noItems; i++)
668 {
669 // Bidimensional radio adjustment
670 if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0?
671 {
672 if (m_windowStyle & wxRA_VERTICAL)
673 {
674 y_offset = startY;
675 x_offset += maxWidth + cx1 ;
676 }
677 else
678 {
679 x_offset = startX ;
680 y_offset += maxHeight ;
681 if (m_radioWidth[0]>0)
682 y_offset += cy1/2 ;
683 }
684 }
685 int eachWidth ;
686 int eachHeight ;
687 if (m_radioWidth[i]<0)
688 {
689 // It's a labeled item
690 GetWindowText((HWND) m_radioButtons[i], buf, 300);
691 GetTextExtent(buf, &current_width, &cyf,NULL,NULL, & GetFont());
692
693 // How do we find out radio button bitmap size!!
694 // By adjusting them carefully, manually :-)
695 eachWidth = (int)(current_width + RADIO_SIZE);
696 eachHeight = (int)((3*cyf)/2);
697 }
698 else
699 {
700 eachWidth = m_radioWidth[i] ;
701 eachHeight = m_radioHeight[i] ;
702 }
703
704 MoveWindow((HWND) m_radioButtons[i],x_offset,y_offset,eachWidth,eachHeight,TRUE);
705 if (m_windowStyle & wxRA_SPECIFY_ROWS)
706 {
707 y_offset += maxHeight;
708 if (m_radioWidth[0]>0)
709 y_offset += cy1/2 ;
710 }
711 else
712 x_offset += maxWidth + cx1;
713 }
714 }
715
716
717 void wxRadioBox::GetSize(int *width, int *height) const
718 {
719 RECT rect;
720 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
721
722 if (m_hWnd)
723 wxFindMaxSize(m_hWnd, &rect);
724
725 int i;
726 for (i = 0; i < m_noItems; i++)
727 wxFindMaxSize(m_radioButtons[i], &rect);
728
729 *width = rect.right - rect.left;
730 *height = rect.bottom - rect.top;
731 }
732
733 void wxRadioBox::GetPosition(int *x, int *y) const
734 {
735 wxWindow *parent = GetParent();
736 RECT rect;
737 rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
738
739 int i;
740 for (i = 0; i < m_noItems; i++)
741 wxFindMaxSize(m_radioButtons[i], &rect);
742
743 if (m_hWnd)
744 wxFindMaxSize(m_hWnd, &rect);
745
746 // Since we now have the absolute screen coords,
747 // if there's a parent we must subtract its top left corner
748 POINT point;
749 point.x = rect.left;
750 point.y = rect.top;
751 if (parent)
752 {
753 ::ScreenToClient((HWND) parent->GetHWND(), &point);
754 }
755 // We may be faking the client origin.
756 // So a window that's really at (0, 30) may appear
757 // (to wxWin apps) to be at (0, 0).
758 if (GetParent())
759 {
760 wxPoint pt(GetParent()->GetClientAreaOrigin());
761 point.x -= pt.x;
762 point.y -= pt.y;
763 }
764
765 *x = point.x;
766 *y = point.y;
767 }
768
769 wxString wxRadioBox::GetLabel(void) const
770 {
771 if (m_hWnd)
772 {
773 GetWindowText((HWND) m_hWnd, wxBuffer, 300);
774 return wxString(wxBuffer);
775 }
776 else return wxString("");
777 }
778
779 void wxRadioBox::SetLabel(const wxString& label)
780 {
781 if (m_hWnd)
782 SetWindowText((HWND) m_hWnd, label);
783 }
784
785 void wxRadioBox::SetFocus(void)
786 {
787 if (m_noItems > 0)
788 {
789 if (m_selectedButton == -1)
790 ::SetFocus((HWND) m_radioButtons[0]);
791 else
792 ::SetFocus((HWND) m_radioButtons[m_selectedButton]);
793 }
794
795 }
796
797 bool wxRadioBox::Show(bool show)
798 {
799 m_isShown = show;
800 int cshow;
801 if (show)
802 cshow = SW_SHOW;
803 else
804 cshow = SW_HIDE;
805 if (m_hWnd)
806 ShowWindow((HWND) m_hWnd, cshow);
807 int i;
808 for (i = 0; i < m_noItems; i++)
809 ShowWindow((HWND) m_radioButtons[i], cshow);
810 return TRUE;
811 }
812
813 // Enable a specific button
814 void wxRadioBox::Enable(int item, bool enable)
815 {
816 if (item<0)
817 wxWindow::Enable(enable) ;
818 else if (item < m_noItems)
819 ::EnableWindow((HWND) m_radioButtons[item], enable);
820 }
821
822 // Enable all controls
823 void wxRadioBox::Enable(bool enable)
824 {
825 wxControl::Enable(enable);
826
827 int i;
828 for (i = 0; i < m_noItems; i++)
829 ::EnableWindow((HWND) m_radioButtons[i], enable);
830 }
831
832 // Show a specific button
833 void wxRadioBox::Show(int item, bool show)
834 {
835 if (item<0)
836 wxRadioBox::Show(show) ;
837 else if (item < m_noItems)
838 {
839 int cshow;
840 if (show)
841 cshow = SW_SHOW;
842 else
843 cshow = SW_HIDE;
844 ShowWindow((HWND) m_radioButtons[item], cshow);
845 }
846 }
847
848 WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
849 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
850 {
851 #if wxUSE_CTL3D
852 if ( m_useCtl3D )
853 {
854 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
855 return (WXHBRUSH) hbrush;
856 }
857 #endif
858
859 if (GetParent()->GetTransparentBackground())
860 SetBkMode((HDC) pDC, TRANSPARENT);
861 else
862 SetBkMode((HDC) pDC, OPAQUE);
863
864 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
865 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
866
867 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
868
869 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
870 // has a zero usage count.
871 // backgroundBrush->RealizeResource();
872 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
873 }
874
875 // For single selection items only
876 wxString wxRadioBox::GetStringSelection (void) const
877 {
878 int sel = GetSelection ();
879 if (sel > -1)
880 return this->GetString (sel);
881 else
882 return wxString("");
883 }
884
885 bool wxRadioBox::SetStringSelection (const wxString& s)
886 {
887 int sel = FindString (s);
888 if (sel > -1)
889 {
890 SetSelection (sel);
891 return TRUE;
892 }
893 else
894 return FALSE;
895 }
896
897 bool wxRadioBox::ContainsHWND(WXHWND hWnd) const
898 {
899 int i;
900 for (i = 0; i < Number(); i++)
901 if (GetRadioButtons()[i] == hWnd)
902 return TRUE;
903 return FALSE;
904 }
905
906 void wxRadioBox::Command (wxCommandEvent & event)
907 {
908 SetSelection (event.m_commandInt);
909 ProcessCommand (event);
910 }
911
912 long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
913 {
914 if (nMsg == WM_NCHITTEST)
915 {
916 int xPos = LOWORD(lParam); // horizontal position of cursor
917 int yPos = HIWORD(lParam); // vertical position of cursor
918
919 ScreenToClient(&xPos, &yPos);
920
921 // Make sure you can drag by the top of the groupbox, but let
922 // other (enclosed) controls get mouse events also
923 if (yPos < 10)
924 return (long)HTCLIENT;
925 }
926
927 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
928 }
929