]> git.saurik.com Git - wxWidgets.git/blob - src/os2/radiobox.cpp
Updated DLL version number
[wxWidgets.git] / src / os2 / radiobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: radiobox.cpp
3 // Purpose: wxRadioBox
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/12/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include <stdio.h>
17 #include "wx/setup.h"
18 #include "wx/wxchar.h"
19 #include "wx/string.h"
20 #include "wx/bitmap.h"
21 #include "wx/brush.h"
22 #include "wx/radiobox.h"
23 #endif
24
25 #include "wx/os2/private.h"
26
27 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
28
29 // ---------------------------------------------------------------------------
30 // private functions
31 // ---------------------------------------------------------------------------
32
33 // wnd proc for radio buttons
34 MRESULT EXPENTRY wxRadioBtnWndProc( HWND hWnd
35 ,UINT uMessage
36 ,MPARAM wParam
37 ,MPARAM lParam
38 );
39
40 // ---------------------------------------------------------------------------
41 // global vars
42 // ---------------------------------------------------------------------------
43
44 // the pointer to standard radio button wnd proc
45 static WXFARPROC fnWndProcRadioBtn = NULL;
46
47 // ===========================================================================
48 // implementation
49 // ===========================================================================
50
51 // ---------------------------------------------------------------------------
52 // wxRadioBox
53 // ---------------------------------------------------------------------------
54
55 // Radio box item
56 wxRadioBox::wxRadioBox()
57 {
58 m_nSelectedButton = -1;
59 m_nNoItems = 0;
60 m_nNoRowsOrCols = 0;
61 m_ahRadioButtons = NULL;
62 m_nMajorDim = 0;
63 m_pnRadioWidth = NULL;
64 m_pnRadioHeight = NULL;
65 } // end of wxRadioBox::wxRadioBox
66
67 wxRadioBox::~wxRadioBox()
68 {
69 m_isBeingDeleted = TRUE;
70
71 if (m_ahRadioButtons)
72 {
73 int i;
74 for (i = 0; i < m_nNoItems; i++)
75 ::WinDestroyWindow((HWND)m_ahRadioButtons[i]);
76 delete[] m_ahRadioButtons;
77 }
78 if (m_pnRadioWidth)
79 delete[] m_pnRadioWidth;
80 if (m_pnRadioHeight)
81 delete[] m_pnRadioHeight;
82 } // end of wxRadioBox::~wxRadioBox
83
84 void wxRadioBox::AdjustButtons(
85 int nX
86 , int nY
87 , int nWidth
88 , int nHeight
89 , int nSizeFlags
90 )
91 {
92 wxSize vMaxSize;
93 int nXOffset = nX;
94 int nYOffset = nY + nHeight;
95 int nCx1;
96 int nCy1;
97 int nStartX;
98 int nStartY;
99 int nMaxWidth;
100 int nMaxHeight;
101 int nTotWidth;
102 int nTotHeight;
103
104 wxGetCharSize( m_hWnd
105 ,&nCx1
106 ,&nCy1
107 ,&GetFont()
108 );
109 vMaxSize = GetMaxButtonSize();
110 nMaxWidth = vMaxSize.x;
111 nMaxHeight = vMaxSize.y;
112
113 nXOffset += nCx1;
114 nYOffset -= (nMaxHeight + ((3*nCy1)/2));
115
116 nStartX = nXOffset;
117 nStartY = nYOffset;
118
119 for (int i = 0; i < m_nNoItems; i++)
120 {
121 //
122 // The last button in the row may be wider than the other ones as the
123 // radiobox may be wider than the sum of the button widths (as it
124 // happens, for example, when the radiobox label is very long)
125 //
126 bool bIsLastInTheRow;
127
128 if (m_windowStyle & wxRA_SPECIFY_COLS)
129 {
130 //
131 // Item is the last in its row if it is a multiple of the number of
132 // columns or if it is just the last item
133 //
134 int n = i + 1;
135
136 bIsLastInTheRow = ((n % m_nMajorDim) == 0) || (n == m_nNoItems);
137 }
138 else // winRA_SPECIFY_ROWS
139 {
140 //
141 // Item is the last in the row if it is in the last columns
142 //
143 bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim;
144 }
145
146 //
147 // Is this the start of new row/column?
148 //
149 if (i && (i % m_nMajorDim == 0))
150 {
151 if (m_windowStyle & wxRA_SPECIFY_ROWS)
152 {
153
154 //
155 // Start of new column
156 //
157 nYOffset = nStartY;
158 nXOffset += nMaxWidth + nCx1;
159 }
160 else // start of new row
161 {
162 nXOffset = nStartX;
163 nYOffset -= nMaxHeight;
164 if (m_pnRadioWidth[0] > 0L)
165 nYOffset -= nCy1/2;
166 }
167 }
168
169 int nWidthBtn;
170
171 if (bIsLastInTheRow)
172 {
173 //
174 // Make the button go to the end of radio box
175 //
176 nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1);
177 if (nWidthBtn < nMaxWidth)
178 nWidthBtn = nMaxWidth;
179 }
180 else
181 {
182 //
183 // Normal button, always of the same size
184 //
185 nWidthBtn = nMaxWidth;
186 }
187
188 //
189 // Make all buttons of the same, maximal size - like this they
190 // cover the radiobox entirely and the radiobox tooltips are always
191 // shown (otherwise they are not when the mouse pointer is in the
192 // radiobox part not beYInt32ing to any radiobutton)
193 //
194 ::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
195 ,HWND_TOP
196 ,(LONG)nXOffset
197 ,(LONG)nYOffset
198 ,(LONG)nWidthBtn
199 ,(LONG)nMaxHeight
200 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
201 );
202 //
203 // Where do we put the next button?
204 //
205 if (m_windowStyle & wxRA_SPECIFY_ROWS)
206 {
207 //
208 // Below this one
209 //
210 nYOffset -= nMaxHeight;
211 if (m_pnRadioWidth[0] > 0)
212 nYOffset -= nCy1/2;
213 }
214 else
215 {
216 //
217 // To the right of this one
218 //
219 nXOffset += nWidthBtn + nCx1;
220 }
221 }
222 } // end of wxRadioBox::AdjustButtons
223
224 void wxRadioBox::Command (
225 wxCommandEvent& rEvent
226 )
227 {
228 SetSelection (rEvent.GetInt());
229 ProcessCommand(rEvent);
230 } // end of wxRadioBox::Command
231
232 bool wxRadioBox::ContainsHWND(
233 WXHWND hWnd
234 ) const
235 {
236 size_t nCount = GetCount();
237 size_t i;
238
239 for (i = 0; i < nCount; i++)
240 {
241 if (GetRadioButtons()[i] == hWnd)
242 return TRUE;
243 }
244 return FALSE;
245 } // end of wxRadioBox::ContainsHWND
246
247 bool wxRadioBox::Create(
248 wxWindow* pParent
249 , wxWindowID vId
250 , const wxString& rsTitle
251 , const wxPoint& rPos
252 , const wxSize& rSize
253 , int nNum
254 , const wxString asChoices[]
255 , int nMajorDim
256 , long lStyle
257 #if wxUSE_VALIDATORS
258 , const wxValidator& rVal
259 #endif
260 , const wxString& rsName
261 )
262 {
263 //
264 // System fonts are too big in OS/2 and they are blue
265 // We want smaller fonts and black by default.
266 //
267 wxFont& rFont = *wxSMALL_FONT;
268 wxColour vColour;
269 LONG lColor;
270
271 vColour.Set(wxString("BLACK"));
272 lColor = (LONG)vColour.GetPixel();
273 m_nSelectedButton = -1;
274 m_nNoItems = nNum;
275
276 m_nMajorDim = nMajorDim == 0 ? nNum : nMajorDim;
277 m_nNoRowsOrCols = nMajorDim;
278
279 //
280 // Common initialization
281 //
282 if (!OS2CreateControl( pParent
283 ,vId
284 ,rPos
285 ,rSize
286 ,lStyle
287 #if wxUSE_VALIDATORS
288 ,rVal
289 #endif
290 ,rsName
291 ))
292
293
294
295
296 if (!OS2CreateControl( "STATIC"
297 ,SS_GROUPBOX | WS_GROUP
298 ,rPos
299 ,rSize
300 ,rsTitle
301 ))
302
303 #if RADIOBTN_PARENT_IS_RADIOBOX
304 HWND hWndParent = GetHwnd();
305 #else
306 HWND hWndParent = GetHwndOf(pParent);
307 #endif
308 HFONT hFont;
309
310 //
311 // Some radio boxes test consecutive id.
312 //
313 (void)NewControlId();
314 m_ahRadioButtons = new WXHWND[nNum];
315 m_pnRadioWidth = new int[nNum];
316 m_pnRadioHeight = new int[nNum];
317
318 if (rFont.Ok())
319 {
320 hFont = rFont.GetResourceHandle();
321 }
322
323 for (int i = 0; i < nNum; i++)
324 {
325 m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1;
326
327 long lStyleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE;
328 int nNewId = NewControlId();
329
330 if (i == 0 && lStyle == 0)
331 lStyleBtn |= WS_GROUP;
332
333 HWND hWndBtn = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
334 ,WC_BUTTON
335 ,asChoices[i]
336 ,lStyleBtn
337 ,0, 0, 0, 0
338 ,GetWinHwnd(pParent)
339 ,HWND_TOP
340 ,(HMENU)nNewId
341 ,NULL
342 ,NULL
343 );
344 ::WinSetPresParam( hWndBtn
345 ,PP_FOREGROUNDCOLOR
346 ,sizeof(LONG)
347 ,(PVOID)&lColor
348 );
349 if (!hWndBtn)
350 {
351 return FALSE;
352 }
353 m_ahRadioButtons[i] = (WXHWND)hWndBtn;
354 SubclassRadioButton((WXHWND)hWndBtn);
355 wxOS2SetFont( hWndBtn
356 ,rFont
357 );
358 ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this);
359 m_aSubControls.Add(nNewId);
360 }
361
362 //
363 // Create a dummy radio control to end the group.
364 //
365 (void)::WinCreateWindow ( GetHwndOf(pParent)
366 ,WC_BUTTON
367 ,""
368 ,WS_GROUP | BS_AUTORADIOBUTTON
369 ,0, 0, 0, 0
370 ,GetWinHwnd(pParent)
371 ,HWND_TOP
372 ,(HMENU)NewControlId()
373 ,NULL
374 ,NULL
375 );
376 SetFont(*wxSMALL_FONT);
377 ::WinSetPresParam( m_hWnd
378 ,PP_FOREGROUNDCOLOR
379 ,sizeof(LONG)
380 ,(PVOID)&lColor
381 );
382 SetSelection(0);
383 SetSize( rPos.x
384 ,rPos.y
385 ,rSize.x
386 ,rSize.y
387 );
388 return TRUE;
389 } // end of wxRadioBox::Create
390
391 wxSize wxRadioBox::DoGetBestSize() const
392 {
393 return (GetTotalButtonSize(GetMaxButtonSize()));
394 } // end of WinGuiBase_CRadioBox::DoGetBestSize
395
396 void wxRadioBox::DoSetSize(
397 int nX
398 , int nY
399 , int nWidth
400 , int nHeight
401 , int nSizeFlags
402 )
403 {
404 int nCurrentX;
405 int nCurrentY;
406 int nWidthOld;
407 int nHeightOld;
408 int nXx = nX;
409 int nYy = nY;
410 #if RADIOBTN_PARENT_IS_RADIOBOX
411 int nXOffset = 0;
412 int nYOffset = 0;
413 #else
414 int nXOffset = nXx;
415 int nYOffset = nYy;
416 #endif
417 int nCx1;
418 int nCy1;
419 wxSize vMaxSize = GetMaxButtonSize();
420 int nMaxWidth;
421 int nMaxHeight;
422 wxSize vTotSize;
423 int nTotWidth;
424 int nTotHeight;
425 int nStartX;
426 int nStartY;
427
428 m_nSizeFlags = nSizeFlags;
429 GetPosition( &nCurrentX
430 ,&nCurrentY
431 );
432 GetSize( &nWidthOld
433 ,&nHeightOld
434 );
435
436 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
437 nXx = nCurrentX;
438 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
439 nYy = nCurrentY;
440
441
442 wxGetCharSize( m_hWnd
443 ,&nCx1
444 ,&nCy1
445 ,&GetFont()
446 );
447
448 //
449 // Attempt to have a look coherent with other platforms: We compute the
450 // biggest toggle dim, then we align all items according this value.
451 //
452 vMaxSize = GetMaxButtonSize();
453 nMaxWidth = vMaxSize.x;
454 nMaxHeight = vMaxSize.y;
455
456 vTotSize = GetTotalButtonSize(vMaxSize);
457 nTotWidth = vTotSize.x;
458 nTotHeight = vTotSize.y;
459
460 //
461 // Only change our width/height if asked for
462 //
463 if (nWidth == -1)
464 {
465 if (nSizeFlags & wxSIZE_AUTO_WIDTH )
466 nWidth = nTotWidth;
467 else
468 nWidth = nWidthOld;
469 }
470
471 if (nHeight == -1)
472 {
473 if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
474 nHeight = nTotHeight;
475 else
476 nHeight = nHeightOld;
477 }
478
479 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
480
481 if (pParent)
482 {
483 int nOS2Height = GetOS2ParentHeight(pParent);
484
485 nYy = nOS2Height - (nYy + nHeight);
486 nYOffset = nYy + nHeight;
487 }
488 else
489 {
490 RECTL vRect;
491
492 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
493 nYy = vRect.yTop - (nYy + nHeight);
494 }
495 ::WinSetWindowPos( GetHwnd()
496 ,HWND_TOP
497 ,(LONG)nXx
498 ,(LONG)nYy
499 ,(LONG)nWidth
500 ,(LONG)nHeight
501 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
502 );
503
504 //
505 // Now position all the buttons: the current button will be put at
506 // wxPoint(x_offset, y_offset) and the new row/column will start at
507 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
508 // maxHeight) except for the buttons in the last column which should extend
509 // to the right border of radiobox and thus can be wider than this.
510 //
511 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
512 // left to right order and m_majorDim is the number of columns while
513 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
514 // m_majorDim is the number of rows.
515 //
516 nXOffset += nCx1;
517 nYOffset -= (nMaxHeight + ((3*nCy1)/2));
518
519 nStartX = nXOffset;
520 nStartY = nYOffset;
521
522 for (int i = 0; i < m_nNoItems; i++)
523 {
524 //
525 // The last button in the row may be wider than the other ones as the
526 // radiobox may be wider than the sum of the button widths (as it
527 // happens, for example, when the radiobox label is very long)
528 //
529 bool bIsLastInTheRow;
530
531 if (m_windowStyle & wxRA_SPECIFY_COLS)
532 {
533 //
534 // Item is the last in its row if it is a multiple of the number of
535 // columns or if it is just the last item
536 //
537 int n = i + 1;
538
539 bIsLastInTheRow = ((n % m_nMajorDim) == 0) || (n == m_nNoItems);
540 }
541 else // winRA_SPECIFY_ROWS
542 {
543 //
544 // Item is the last in the row if it is in the last columns
545 //
546 bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim;
547 }
548
549 //
550 // Is this the start of new row/column?
551 //
552 if (i && (i % m_nMajorDim == 0))
553 {
554 if (m_windowStyle & wxRA_SPECIFY_ROWS)
555 {
556
557 //
558 // Start of new column
559 //
560 nYOffset = nStartY;
561 nXOffset += nMaxWidth + nCx1;
562 }
563 else // start of new row
564 {
565 nXOffset = nStartX;
566 nYOffset -= nMaxHeight;
567 if (m_pnRadioWidth[0] > 0L)
568 nYOffset -= nCy1/2;
569 }
570 }
571
572 int nWidthBtn;
573
574 if (bIsLastInTheRow)
575 {
576 //
577 // Make the button go to the end of radio box
578 //
579 nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1);
580 if (nWidthBtn < nMaxWidth)
581 nWidthBtn = nMaxWidth;
582 }
583 else
584 {
585 //
586 // Normal button, always of the same size
587 //
588 nWidthBtn = nMaxWidth;
589 }
590
591 //
592 // Make all buttons of the same, maximal size - like this they
593 // cover the radiobox entirely and the radiobox tooltips are always
594 // shown (otherwise they are not when the mouse pointer is in the
595 // radiobox part not beinting to any radiobutton)
596 //
597 ::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
598 ,HWND_TOP
599 ,(LONG)nXOffset
600 ,(LONG)nYOffset
601 ,(LONG)nWidthBtn
602 ,(LONG)nMaxHeight
603 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
604 );
605 //
606 // Where do we put the next button?
607 //
608 if (m_windowStyle & wxRA_SPECIFY_ROWS)
609 {
610 //
611 // Below this one
612 //
613 nYOffset -= nMaxHeight;
614 if (m_pnRadioWidth[0] > 0)
615 nYOffset -= nCy1/2;
616 }
617 else
618 {
619 //
620 // To the right of this one
621 //
622 nXOffset += nWidthBtn + nCx1;
623 }
624 }
625 } // end of wxRadioBox::DoSetSize
626
627 void wxRadioBox::Enable(
628 int nItem
629 , bool bEnable
630 )
631 {
632 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems,
633 wxT("invalid item in wxRadioBox::Enable()") );
634
635 ::WinEnableWindow((HWND) m_ahRadioButtons[nItem], bEnable);
636 } // end of wxRadioBox::Enable
637
638 bool wxRadioBox::Enable(
639 bool bEnable
640 )
641 {
642 if ( !wxControl::Enable(bEnable) )
643 return FALSE;
644 for (int i = 0; i < m_nNoItems; i++)
645 ::WinEnableWindow((HWND)m_ahRadioButtons[i], bEnable);
646 return TRUE;
647 } // end of wxRadioBox::Enable
648
649 int wxRadioBox::FindString(
650 const wxString& rsStr
651 ) const
652 {
653 for (int i = 0; i < m_nNoItems; i++)
654 {
655 if (rsStr == wxGetWindowText(m_ahRadioButtons[i]) )
656 return i;
657 }
658 return wxNOT_FOUND;
659 } // end of wxRadioBox::FindString
660
661 int wxRadioBox::GetColumnCount() const
662 {
663 return GetNumHor();
664 } // end of wxRadioBox::GetColumnCount
665
666 int wxRadioBox::GetCount() const
667 {
668 return m_nNoItems;
669 } // end of wxRadioBox::GetCount
670
671 wxString wxRadioBox::GetLabel(
672 int nItem
673 ) const
674 {
675 wxCHECK_MSG(nItem >= 0 && nItem < m_nNoItems, wxT(""), wxT("invalid radiobox index") );
676
677 return wxGetWindowText(m_ahRadioButtons[nItem]);
678 } // end of wxRadioBox::GetLabel
679
680 wxSize wxRadioBox::GetMaxButtonSize() const
681 {
682 int nWidthMax = 0;
683 int nHeightMax = 0;
684
685 for (int i = 0 ; i < m_nNoItems; i++)
686 {
687 int nWidth;
688 int nHeight;
689
690 if (m_pnRadioWidth[i] < 0L)
691 {
692 GetTextExtent( wxGetWindowText(m_ahRadioButtons[i])
693 ,&nWidth
694 ,&nHeight
695 );
696
697 //
698 // Adjust the size to take into account the radio box itself
699 // FIXME this is totally bogus!
700 //
701 nWidth += RADIO_SIZE;
702 nHeight *= 3;
703 nHeight /= 2;
704 }
705 else
706 {
707 nWidth = m_pnRadioWidth[i];
708 nHeight = m_pnRadioHeight[i];
709 }
710 if (nWidthMax < nWidth )
711 nWidthMax = nWidth;
712 if (nHeightMax < nHeight )
713 nHeightMax = nHeight;
714 }
715 return(wxSize( nWidthMax
716 ,nHeightMax
717 )
718 );
719 } // end of wxRadioBox::GetMaxButtonSize
720
721 int wxRadioBox::GetNumHor() const
722 {
723 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
724 {
725 return (m_nNoItems + m_nMajorDim - 1)/m_nMajorDim;
726 }
727 else
728 {
729 return m_nMajorDim;
730 }
731 } // end of wxRadioBox::GetNumHor
732
733 int wxRadioBox::GetNumVer() const
734 {
735 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
736 {
737 return m_nMajorDim;
738 }
739 else
740 {
741 return (m_nNoItems + m_nMajorDim - 1)/m_nMajorDim;
742 }
743 } // end of wxRadioBox::GetNumVer
744
745 void wxRadioBox::GetPosition(
746 int* pnX
747 , int* pnY
748 ) const
749 {
750 wxWindowOS2* pParent = GetParent();
751 RECT vRect = { -1, -1, -1, -1 };;
752 POINTL vPoint;
753 int i;
754
755 for (i = 0; i < m_nNoItems; i++)
756 wxFindMaxSize( m_ahRadioButtons[i]
757 ,&vRect
758 );
759 if (m_hWnd)
760 wxFindMaxSize( m_hWnd
761 ,&vRect
762 );
763
764 //
765 // Since we now have the absolute screen coords, if there's a parent we
766 // must subtract its top left corner
767 //
768 vPoint.x = vRect.xLeft;
769 vPoint.y = vRect.yTop;
770 if (pParent)
771 {
772 SWP vSwp;
773
774 ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
775 vPoint.x = vSwp.x;
776 vPoint.y = vSwp.y;
777 }
778
779 //
780 // We may be faking the client origin. So a window that's really at (0, 30)
781 // may appear (to wxWin apps) to be at (0, 0).
782 //
783 if (GetParent())
784 {
785 wxPoint vPt(GetParent()->GetClientAreaOrigin());
786
787 vPoint.x = vPt.x;
788 vPoint.y = vPt.y;
789 }
790 *pnX = vPoint.x;
791 *pnX = vPoint.y;
792 } // end of wxRadioBox::GetPosition
793
794 int wxRadioBox::GetRowCount() const
795 {
796 return GetNumVer();
797 } // end of wxRadioBox::GetRowCount
798
799 // Get single selection, for single choice list items
800 int wxRadioBox::GetSelection() const
801 {
802 return m_nSelectedButton;
803 } // end of wxRadioBox::GetSelection
804
805 void wxRadioBox::GetSize(
806 int* pnWidth
807 , int* pnHeight
808 ) const
809 {
810 RECT vRect;
811 int i;
812
813 vRect.xLeft = -1;
814 vRect.xRight = -1;
815 vRect.yTop = -1;
816 vRect.yBottom = -1;
817
818 if (m_hWnd)
819 wxFindMaxSize( m_hWnd
820 ,&vRect
821 );
822
823 for (i = 0; i < m_nNoItems; i++)
824 wxFindMaxSize( m_ahRadioButtons[i]
825 ,&vRect
826 );
827
828 *pnWidth = vRect.xRight - vRect.xLeft;
829 *pnHeight = vRect.yBottom - vRect.yTop;
830 } // end of wxRadioBox::GetSize
831
832 // Find string for position
833 wxString wxRadioBox::GetString(
834 int nNum
835 ) const
836 {
837 return wxGetWindowText(m_ahRadioButtons[nNum]);
838 } // end of wxRadioBox::GetString
839
840 // For single selection items only
841 wxString wxRadioBox::GetStringSelection() const
842 {
843 wxString sResult;
844 int nSel = GetSelection();
845
846 if (nSel > -1)
847 sResult = GetString(nSel);
848 return sResult;
849 } // end of wxRadioBox::GetStringSelection
850
851 wxSize wxRadioBox::GetTotalButtonSize(
852 const wxSize& rSizeBtn
853 ) const
854 {
855 int nCx1;
856 int nCy1;
857 int nExtraHeight;
858 int nHeight;
859 int nWidth;
860 int nWidthLabel;
861
862 wxGetCharSize( m_hWnd
863 ,&nCx1
864 ,&nCy1
865 ,(wxFont*)&GetFont()
866 );
867 nExtraHeight = nCy1;
868
869 nHeight = GetNumVer() * rSizeBtn.y + (2 * nCy1);
870 nWidth = GetNumHor() * (rSizeBtn.x + nCx1) + nCx1;
871
872 //
873 // And also wide enough for its label
874 //
875 GetTextExtent( GetTitle()
876 ,&nWidthLabel
877 ,NULL
878 );
879 nWidthLabel += RADIO_SIZE;
880 if (nWidthLabel > nWidth)
881 nWidth = nWidthLabel;
882
883 return(wxSize( nWidth
884 ,nHeight
885 )
886 );
887 } // end of wxRadioBox::GetTotalButtonSize
888
889 WXHBRUSH wxRadioBox::OnCtlColor(
890 WXHDC hwinDC
891 , WXHWND hWnd
892 , WXUINT uCtlColor
893 , WXUINT uMessage
894 , WXWPARAM wParam
895 , WXLPARAM lParam
896 )
897 {
898 HPS hPS = (HPS)hwinDC; // pass in a PS handle in OS/2
899
900 if (GetParent()->GetTransparentBackground())
901 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
902 else
903 ::GpiSetBackMix(hPS, BM_OVERPAINT);
904
905 wxColour vColBack = GetBackgroundColour();
906
907 ::GpiSetBackColor(hPS, vColBack.GetPixel());
908 ::GpiSetColor(hPS, vColBack.GetPixel());
909
910
911 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
912 ,wxSOLID
913 );
914 return ((WXHBRUSH)pBrush->GetResourceHandle());
915 } // end of wxRadioBox::OnCtlColor
916
917 bool wxRadioBox::OS2Command(
918 WXUINT uCmd
919 , WXWORD wId
920 )
921 {
922 int nSelectedButton = -1;
923
924 if (uCmd == BN_CLICKED)
925 {
926 if (wId == GetId())
927 return TRUE;
928
929
930 for (int i = 0; i < m_nNoItems; i++)
931 {
932 if (wId == wxGetWindowId(m_ahRadioButtons[i]))
933 {
934 nSelectedButton = i;
935 break;
936 }
937 }
938 if (nSelectedButton == -1)
939 {
940 //
941 // Just ignore it - due to a hack with WM_NCHITTEST handling in our
942 // wnd proc, we can receive dummy click messages when we click near
943 // the radiobox edge (this is ugly but Julian wouldn't let me get
944 // rid of this...)
945 return FALSE;
946 }
947 if (nSelectedButton != m_nSelectedButton)
948 {
949 m_nSelectedButton = nSelectedButton;
950 SendNotificationEvent();
951 }
952 return TRUE;
953 }
954 else
955 return FALSE;
956 } // end of wxRadioBox::OS2Command
957
958 void wxRadioBox::SendNotificationEvent()
959 {
960 wxCommandEvent vEvent( wxEVT_COMMAND_RADIOBOX_SELECTED
961 ,m_windowId
962 );
963
964 vEvent.SetInt( m_nSelectedButton );
965 vEvent.SetString( GetString(m_nSelectedButton) );
966 vEvent.SetEventObject(this);
967 ProcessCommand(vEvent);
968 } // end of wxRadioBox::SendNotificationEvent
969
970 void wxRadioBox::SetFocus()
971 {
972 if (m_nNoItems > 0)
973 {
974 if (m_nSelectedButton == -1)
975 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[0]);
976 else
977 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[m_nSelectedButton]);
978 }
979 } // end of wxRadioBox::SetFocus
980
981 bool wxRadioBox::SetFont(
982 const wxFont& rFont
983 )
984 {
985 if (!wxControl::SetFont(rFont))
986 {
987 //
988 // Nothing to do
989 //
990 return FALSE;
991 }
992 //
993 // Also set the font of our radio buttons
994 //
995 WXHFONT hFont = wxFont(rFont).GetResourceHandle();
996
997 for (int n = 0; n < (int)m_nNoItems; n++)
998 {
999 HWND hWndBtn = (HWND)m_ahRadioButtons[n];
1000
1001 wxOS2SetFont( hWndBtn
1002 ,rFont
1003 );
1004 ::WinInvalidateRect(hWndBtn, NULL, FALSE);
1005 }
1006 return TRUE;
1007 } // end of wxRadioBox::SetFont
1008
1009 void wxRadioBox::SetSelection(
1010 int nNum
1011 )
1012 {
1013 wxCHECK_RET( (nNum >= 0) && (nNum < m_nNoItems), wxT("invalid radiobox index") );
1014
1015 if (m_nSelectedButton >= 0 && m_nSelectedButton < m_nNoItems)
1016 ::WinSendMsg((HWND)m_ahRadioButtons[m_nSelectedButton], BM_SETCHECK, (MPARAM)0, (MPARAM)0);
1017
1018 ::WinSendMsg((HWND)m_ahRadioButtons[nNum], BM_SETCHECK, (MPARAM)1, (MPARAM)0);
1019 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[nNum]);
1020 m_nSelectedButton = nNum;
1021 } // end of wxRadioBox::SetSelection
1022
1023 void wxRadioBox::SetString(
1024 int nItem
1025 , const wxString& rsLabel
1026 )
1027 {
1028 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems, wxT("invalid radiobox index") );
1029
1030 m_pnRadioWidth[nItem] = m_pnRadioHeight[nItem] = -1;
1031 ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], rsLabel.c_str());
1032 } // end of wxRadioBox::SetString
1033
1034 bool wxRadioBox::SetStringSelection(
1035 const wxString& rsStr
1036 )
1037 {
1038 int nSel = FindString(rsStr);
1039
1040 if (nSel > -1)
1041 {
1042 SetSelection(nSel);
1043 return TRUE;
1044 }
1045 else
1046 return FALSE;
1047 } // end of wxRadioBox::SetStringSelection
1048
1049 bool wxRadioBox::Show(
1050 bool bShow
1051 )
1052 {
1053 int nCmdShow = 0;
1054
1055 if (!wxControl::Show(bShow))
1056 return FALSE;
1057
1058 for (int i = 0; i < m_nNoItems; i++)
1059 {
1060 ::WinShowWindow((HWND)m_ahRadioButtons[i], (BOOL)bShow);
1061 }
1062 return TRUE;
1063 } // end of wxRadioBox::Show
1064
1065 // Show a specific button
1066 void wxRadioBox::Show(
1067 int nItem
1068 , bool bShow
1069 )
1070 {
1071 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems,
1072 wxT("invalid item in wxRadioBox::Show()") );
1073
1074 ::WinShowWindow((HWND)m_ahRadioButtons[nItem], bShow);
1075 } // end of wxRadioBox::Show
1076
1077 void wxRadioBox::SubclassRadioButton(
1078 WXHWND hWndBtn
1079 )
1080 {
1081 HWND hwndBtn = (HWND)hWndBtn;
1082
1083 fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
1084 } // end of wxRadioBox::SubclassRadioButton
1085
1086 MRESULT wxRadioBox::WindowProc(
1087 WXUINT uMsg
1088 , WXWPARAM wParam
1089 , WXLPARAM lParam
1090 )
1091 {
1092 return (wxControl::OS2WindowProc( uMsg
1093 ,wParam
1094 ,lParam
1095 ));
1096 } // end of wxRadioBox::WindowProc
1097
1098 // ---------------------------------------------------------------------------
1099 // window proc for radio buttons
1100 // ---------------------------------------------------------------------------
1101
1102 MRESULT wxRadioBtnWndProc(
1103 HWND hWnd
1104 , UINT uMessage
1105 , MPARAM wParam
1106 , MPARAM lParam
1107 )
1108 {
1109 switch (uMessage)
1110 {
1111 case WM_CHAR:
1112 {
1113 USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
1114
1115 if (!(uKeyFlags & KC_KEYUP)) // Key Down event
1116 {
1117 if (uKeyFlags & KC_VIRTUALKEY)
1118 {
1119 wxRadioBox* pRadiobox = (wxRadioBox *)::WinQueryWindowULong( hWnd
1120 ,QWL_USER
1121 );
1122 USHORT uVk = SHORT2FROMMP((MPARAM)lParam);
1123 bool bProcessed = TRUE;
1124 wxDirection eDir;
1125
1126 switch(uVk)
1127 {
1128 case VK_LEFT:
1129 eDir = wxDOWN;
1130 break;
1131
1132 case VK_RIGHT:
1133 eDir = wxDOWN;
1134 break;
1135
1136 case VK_DOWN:
1137 eDir = wxDOWN;
1138 break;
1139
1140 case VK_UP:
1141 eDir = wxUP;
1142 break;
1143
1144 default:
1145 bProcessed = FALSE;
1146
1147 //
1148 // Just to suppress the compiler warning
1149 //
1150 eDir = wxALL;
1151 }
1152
1153 if (bProcessed)
1154 {
1155 int nSelOld = pRadiobox->GetSelection();
1156 int nSelNew = pRadiobox->GetNextItem( nSelOld
1157 ,eDir
1158 ,pRadiobox->GetWindowStyleFlag()
1159 );
1160
1161 if (nSelNew != nSelOld)
1162 {
1163 pRadiobox->SetSelection(nSelNew);
1164
1165 //
1166 // Emulate the button click
1167 //
1168 pRadiobox->SendNotificationEvent();
1169 return 0;
1170 }
1171 }
1172 }
1173 }
1174 }
1175 break;
1176 }
1177
1178 return fnWndProcRadioBtn( hWnd
1179 ,(ULONG)uMessage
1180 ,(MPARAM)wParam
1181 ,(MPARAM)lParam
1182 );
1183 } // end of wxRadioBtnWndProc
1184