]> git.saurik.com Git - wxWidgets.git/blob - src/os2/radiobox.cpp
implemented menu drawing in the GTK theme
[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* pTextFont = new wxFont( 10
268 ,wxMODERN
269 ,wxNORMAL
270 ,wxNORMAL
271 );
272 wxColour vColour;
273 LONG lColor;
274
275 vColour.Set(wxString("BLACK"));
276 lColor = (LONG)vColour.GetPixel();
277 m_nSelectedButton = -1;
278 m_nNoItems = nNum;
279
280 m_nMajorDim = nMajorDim == 0 ? nNum : nMajorDim;
281 m_nNoRowsOrCols = nMajorDim;
282
283 //
284 // Common initialization
285 //
286 if (!CreateControl( pParent
287 ,vId
288 ,rPos
289 ,rSize
290 ,lStyle
291 #if wxUSE_VALIDATORS
292 ,rVal
293 #endif
294 ,rsName
295 ))
296
297
298
299
300 if (!OS2CreateControl( "STATIC"
301 #if RADIOBTN_PARENT_IS_RADIOBOX
302 ,SS_GROUPBOX | WS_GROUP | WS_CLIPCHILDREN
303 #else
304 ,SS_GROUPBOX | WS_GROUP | WS_CLIPSIBLINGS
305 #endif
306 ,rPos
307 ,rSize
308 ,rsTitle
309 ))
310
311 #if RADIOBTN_PARENT_IS_RADIOBOX
312 HWND hWndParent = GetHwnd();
313 #else
314 HWND hWndParent = GetHwndOf(pParent);
315 #endif
316 HFONT hFont;
317
318 //
319 // Some radio boxes test consecutive id.
320 //
321 (void)NewControlId();
322 m_ahRadioButtons = new WXHWND[nNum];
323 m_pnRadioWidth = new int[nNum];
324 m_pnRadioHeight = new int[nNum];
325
326 if (pTextFont->Ok())
327 {
328 hFont = pTextFont->GetResourceHandle();
329 }
330
331 for (int i = 0; i < nNum; i++)
332 {
333 m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1;
334
335 long lStyleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE;
336 int nNewId = NewControlId();
337
338 if (i == 0 && lStyle == 0)
339 lStyleBtn |= WS_GROUP;
340
341 HWND hWndBtn = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
342 ,WC_BUTTON
343 ,asChoices[i]
344 ,lStyleBtn
345 ,0, 0, 0, 0
346 ,GetWinHwnd(pParent)
347 ,HWND_TOP
348 ,(HMENU)nNewId
349 ,NULL
350 ,NULL
351 );
352 lColor = (LONG)vColour.GetPixel();
353 ::WinSetPresParam( hWndBtn
354 ,PP_FOREGROUNDCOLOR
355 ,sizeof(LONG)
356 ,(PVOID)&lColor
357 );
358 lColor = (LONG)m_backgroundColour.GetPixel();
359
360 ::WinSetPresParam( hWndBtn
361 ,PP_BACKGROUNDCOLOR
362 ,sizeof(LONG)
363 ,(PVOID)&lColor
364 );
365 if (!hWndBtn)
366 {
367 return FALSE;
368 }
369 m_ahRadioButtons[i] = (WXHWND)hWndBtn;
370 SubclassRadioButton((WXHWND)hWndBtn);
371 wxOS2SetFont( hWndBtn
372 ,*pTextFont
373 );
374 ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this);
375 m_aSubControls.Add(nNewId);
376 }
377
378 //
379 // Create a dummy radio control to end the group.
380 //
381 (void)::WinCreateWindow ( GetHwndOf(pParent)
382 ,WC_BUTTON
383 ,""
384 ,WS_GROUP | BS_AUTORADIOBUTTON
385 ,0, 0, 0, 0
386 ,GetWinHwnd(pParent)
387 ,HWND_TOP
388 ,(HMENU)NewControlId()
389 ,NULL
390 ,NULL
391 );
392 SetFont(*pTextFont);
393 lColor = (LONG)vColour.GetPixel();
394 ::WinSetPresParam( m_hWnd
395 ,PP_FOREGROUNDCOLOR
396 ,sizeof(LONG)
397 ,(PVOID)&lColor
398 );
399 lColor = (LONG)m_backgroundColour.GetPixel();
400
401 ::WinSetPresParam( m_hWnd
402 ,PP_BACKGROUNDCOLOR
403 ,sizeof(LONG)
404 ,(PVOID)&lColor
405 );
406 SetSelection(0);
407 SetSize( rPos.x
408 ,rPos.y
409 ,rSize.x
410 ,rSize.y
411 );
412 delete pTextFont;
413 return TRUE;
414 } // end of wxRadioBox::Create
415
416 wxSize wxRadioBox::DoGetBestSize() const
417 {
418 return (GetTotalButtonSize(GetMaxButtonSize()));
419 } // end of WinGuiBase_CRadioBox::DoGetBestSize
420
421 void wxRadioBox::DoSetSize(
422 int nX
423 , int nY
424 , int nWidth
425 , int nHeight
426 , int nSizeFlags
427 )
428 {
429 int nCurrentX;
430 int nCurrentY;
431 int nWidthOld;
432 int nHeightOld;
433 int nXx = nX;
434 int nYy = nY;
435 #if RADIOBTN_PARENT_IS_RADIOBOX
436 int nXOffset = 0;
437 int nYOffset = 0;
438 #else
439 int nXOffset = nXx;
440 int nYOffset = nYy;
441 #endif
442 int nCx1;
443 int nCy1;
444 wxSize vMaxSize = GetMaxButtonSize();
445 int nMaxWidth;
446 int nMaxHeight;
447 wxSize vTotSize;
448 int nTotWidth;
449 int nTotHeight;
450 int nStartX;
451 int nStartY;
452
453 m_nSizeFlags = nSizeFlags;
454 GetPosition( &nCurrentX
455 ,&nCurrentY
456 );
457 GetSize( &nWidthOld
458 ,&nHeightOld
459 );
460
461 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
462 nXx = nCurrentX;
463 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
464 nYy = nCurrentY;
465
466
467 wxGetCharSize( m_hWnd
468 ,&nCx1
469 ,&nCy1
470 ,&GetFont()
471 );
472
473 //
474 // Attempt to have a look coherent with other platforms: We compute the
475 // biggest toggle dim, then we align all items according this value.
476 //
477 vMaxSize = GetMaxButtonSize();
478 nMaxWidth = vMaxSize.x;
479 nMaxHeight = vMaxSize.y;
480
481 vTotSize = GetTotalButtonSize(vMaxSize);
482 nTotWidth = vTotSize.x;
483 nTotHeight = vTotSize.y;
484
485 //
486 // Only change our width/height if asked for
487 //
488 if (nWidth == -1)
489 {
490 if (nSizeFlags & wxSIZE_AUTO_WIDTH )
491 nWidth = nTotWidth;
492 else
493 nWidth = nWidthOld;
494 }
495
496 if (nHeight == -1)
497 {
498 if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
499 nHeight = nTotHeight;
500 else
501 nHeight = nHeightOld;
502 }
503
504 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
505
506 if (pParent)
507 {
508 int nOS2Height = GetOS2ParentHeight(pParent);
509
510 nYy = nOS2Height - (nYy + nHeight);
511 nYOffset = nYy + nHeight;
512 }
513 else
514 {
515 RECTL vRect;
516
517 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
518 nYy = vRect.yTop - (nYy + nHeight);
519 }
520 ::WinSetWindowPos( GetHwnd()
521 ,HWND_TOP
522 ,(LONG)nXx
523 ,(LONG)nYy
524 ,(LONG)nWidth
525 ,(LONG)nHeight
526 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
527 );
528
529 //
530 // Now position all the buttons: the current button will be put at
531 // wxPoint(x_offset, y_offset) and the new row/column will start at
532 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
533 // maxHeight) except for the buttons in the last column which should extend
534 // to the right border of radiobox and thus can be wider than this.
535 //
536 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
537 // left to right order and m_majorDim is the number of columns while
538 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
539 // m_majorDim is the number of rows.
540 //
541 nXOffset += nCx1;
542 nYOffset -= (nMaxHeight + ((3*nCy1)/2));
543
544 nStartX = nXOffset;
545 nStartY = nYOffset;
546
547 for (int i = 0; i < m_nNoItems; i++)
548 {
549 //
550 // The last button in the row may be wider than the other ones as the
551 // radiobox may be wider than the sum of the button widths (as it
552 // happens, for example, when the radiobox label is very long)
553 //
554 bool bIsLastInTheRow;
555
556 if (m_windowStyle & wxRA_SPECIFY_COLS)
557 {
558 //
559 // Item is the last in its row if it is a multiple of the number of
560 // columns or if it is just the last item
561 //
562 int n = i + 1;
563
564 bIsLastInTheRow = ((n % m_nMajorDim) == 0) || (n == m_nNoItems);
565 }
566 else // winRA_SPECIFY_ROWS
567 {
568 //
569 // Item is the last in the row if it is in the last columns
570 //
571 bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim;
572 }
573
574 //
575 // Is this the start of new row/column?
576 //
577 if (i && (i % m_nMajorDim == 0))
578 {
579 if (m_windowStyle & wxRA_SPECIFY_ROWS)
580 {
581
582 //
583 // Start of new column
584 //
585 nYOffset = nStartY;
586 nXOffset += nMaxWidth + nCx1;
587 }
588 else // start of new row
589 {
590 nXOffset = nStartX;
591 nYOffset -= nMaxHeight;
592 if (m_pnRadioWidth[0] > 0L)
593 nYOffset -= nCy1/2;
594 }
595 }
596
597 int nWidthBtn;
598
599 if (bIsLastInTheRow)
600 {
601 //
602 // Make the button go to the end of radio box
603 //
604 nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1);
605 if (nWidthBtn < nMaxWidth)
606 nWidthBtn = nMaxWidth;
607 }
608 else
609 {
610 //
611 // Normal button, always of the same size
612 //
613 nWidthBtn = nMaxWidth;
614 }
615
616 //
617 // Make all buttons of the same, maximal size - like this they
618 // cover the radiobox entirely and the radiobox tooltips are always
619 // shown (otherwise they are not when the mouse pointer is in the
620 // radiobox part not beinting to any radiobutton)
621 //
622 ::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
623 ,HWND_TOP
624 ,(LONG)nXOffset
625 ,(LONG)nYOffset
626 ,(LONG)nWidthBtn
627 ,(LONG)nMaxHeight
628 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
629 );
630 //
631 // Where do we put the next button?
632 //
633 if (m_windowStyle & wxRA_SPECIFY_ROWS)
634 {
635 //
636 // Below this one
637 //
638 nYOffset -= nMaxHeight;
639 if (m_pnRadioWidth[0] > 0)
640 nYOffset -= nCy1/2;
641 }
642 else
643 {
644 //
645 // To the right of this one
646 //
647 nXOffset += nWidthBtn + nCx1;
648 }
649 }
650 } // end of wxRadioBox::DoSetSize
651
652 void wxRadioBox::Enable(
653 int nItem
654 , bool bEnable
655 )
656 {
657 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems,
658 wxT("invalid item in wxRadioBox::Enable()") );
659
660 ::WinEnableWindow((HWND) m_ahRadioButtons[nItem], bEnable);
661 } // end of wxRadioBox::Enable
662
663 bool wxRadioBox::Enable(
664 bool bEnable
665 )
666 {
667 if ( !wxControl::Enable(bEnable) )
668 return FALSE;
669 for (int i = 0; i < m_nNoItems; i++)
670 ::WinEnableWindow((HWND)m_ahRadioButtons[i], bEnable);
671 return TRUE;
672 } // end of wxRadioBox::Enable
673
674 int wxRadioBox::FindString(
675 const wxString& rsStr
676 ) const
677 {
678 for (int i = 0; i < m_nNoItems; i++)
679 {
680 if (rsStr == wxGetWindowText(m_ahRadioButtons[i]) )
681 return i;
682 }
683 return wxNOT_FOUND;
684 } // end of wxRadioBox::FindString
685
686 int wxRadioBox::GetColumnCount() const
687 {
688 return GetNumHor();
689 } // end of wxRadioBox::GetColumnCount
690
691 int wxRadioBox::GetCount() const
692 {
693 return m_nNoItems;
694 } // end of wxRadioBox::GetCount
695
696 wxString wxRadioBox::GetLabel(
697 int nItem
698 ) const
699 {
700 wxCHECK_MSG(nItem >= 0 && nItem < m_nNoItems, wxT(""), wxT("invalid radiobox index") );
701
702 return wxGetWindowText(m_ahRadioButtons[nItem]);
703 } // end of wxRadioBox::GetLabel
704
705 wxSize wxRadioBox::GetMaxButtonSize() const
706 {
707 int nWidthMax = 0;
708 int nHeightMax = 0;
709
710 for (int i = 0 ; i < m_nNoItems; i++)
711 {
712 int nWidth;
713 int nHeight;
714
715 if (m_pnRadioWidth[i] < 0L)
716 {
717 GetTextExtent( wxGetWindowText(m_ahRadioButtons[i])
718 ,&nWidth
719 ,&nHeight
720 );
721
722 //
723 // Adjust the size to take into account the radio box itself
724 // FIXME this is totally bogus!
725 //
726 nWidth += RADIO_SIZE;
727 nHeight *= 3;
728 nHeight /= 2;
729 }
730 else
731 {
732 nWidth = m_pnRadioWidth[i];
733 nHeight = m_pnRadioHeight[i];
734 }
735 if (nWidthMax < nWidth )
736 nWidthMax = nWidth;
737 if (nHeightMax < nHeight )
738 nHeightMax = nHeight;
739 }
740 return(wxSize( nWidthMax
741 ,nHeightMax
742 )
743 );
744 } // end of wxRadioBox::GetMaxButtonSize
745
746 int wxRadioBox::GetNumHor() const
747 {
748 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
749 {
750 return (m_nNoItems + m_nMajorDim - 1)/m_nMajorDim;
751 }
752 else
753 {
754 return m_nMajorDim;
755 }
756 } // end of wxRadioBox::GetNumHor
757
758 int wxRadioBox::GetNumVer() const
759 {
760 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
761 {
762 return m_nMajorDim;
763 }
764 else
765 {
766 return (m_nNoItems + m_nMajorDim - 1)/m_nMajorDim;
767 }
768 } // end of wxRadioBox::GetNumVer
769
770 void wxRadioBox::GetPosition(
771 int* pnX
772 , int* pnY
773 ) const
774 {
775 wxWindowOS2* pParent = GetParent();
776 RECT vRect = { -1, -1, -1, -1 };;
777 POINTL vPoint;
778 int i;
779
780 for (i = 0; i < m_nNoItems; i++)
781 wxFindMaxSize( m_ahRadioButtons[i]
782 ,&vRect
783 );
784 if (m_hWnd)
785 wxFindMaxSize( m_hWnd
786 ,&vRect
787 );
788
789 //
790 // Since we now have the absolute screen coords, if there's a parent we
791 // must subtract its top left corner
792 //
793 vPoint.x = vRect.xLeft;
794 vPoint.y = vRect.yTop;
795 if (pParent)
796 {
797 SWP vSwp;
798
799 ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
800 vPoint.x = vSwp.x;
801 vPoint.y = vSwp.y;
802 }
803
804 //
805 // We may be faking the client origin. So a window that's really at (0, 30)
806 // may appear (to wxWin apps) to be at (0, 0).
807 //
808 if (GetParent())
809 {
810 wxPoint vPt(GetParent()->GetClientAreaOrigin());
811
812 vPoint.x = vPt.x;
813 vPoint.y = vPt.y;
814 }
815 *pnX = vPoint.x;
816 *pnX = vPoint.y;
817 } // end of wxRadioBox::GetPosition
818
819 int wxRadioBox::GetRowCount() const
820 {
821 return GetNumVer();
822 } // end of wxRadioBox::GetRowCount
823
824 // Get single selection, for single choice list items
825 int wxRadioBox::GetSelection() const
826 {
827 return m_nSelectedButton;
828 } // end of wxRadioBox::GetSelection
829
830 void wxRadioBox::GetSize(
831 int* pnWidth
832 , int* pnHeight
833 ) const
834 {
835 RECT vRect;
836 int i;
837
838 vRect.xLeft = -1;
839 vRect.xRight = -1;
840 vRect.yTop = -1;
841 vRect.yBottom = -1;
842
843 if (m_hWnd)
844 wxFindMaxSize( m_hWnd
845 ,&vRect
846 );
847
848 for (i = 0; i < m_nNoItems; i++)
849 wxFindMaxSize( m_ahRadioButtons[i]
850 ,&vRect
851 );
852
853 *pnWidth = vRect.xRight - vRect.xLeft;
854 *pnHeight = vRect.yBottom - vRect.yTop;
855 } // end of wxRadioBox::GetSize
856
857 // Find string for position
858 wxString wxRadioBox::GetString(
859 int nNum
860 ) const
861 {
862 return wxGetWindowText(m_ahRadioButtons[nNum]);
863 } // end of wxRadioBox::GetString
864
865 // For single selection items only
866 wxString wxRadioBox::GetStringSelection() const
867 {
868 wxString sResult;
869 int nSel = GetSelection();
870
871 if (nSel > -1)
872 sResult = GetString(nSel);
873 return sResult;
874 } // end of wxRadioBox::GetStringSelection
875
876 wxSize wxRadioBox::GetTotalButtonSize(
877 const wxSize& rSizeBtn
878 ) const
879 {
880 int nCx1;
881 int nCy1;
882 int nExtraHeight;
883 int nHeight;
884 int nWidth;
885 int nWidthLabel;
886
887 wxGetCharSize( m_hWnd
888 ,&nCx1
889 ,&nCy1
890 ,(wxFont*)&GetFont()
891 );
892 nExtraHeight = nCy1;
893
894 nHeight = GetNumVer() * rSizeBtn.y + (2 * nCy1);
895 nWidth = GetNumHor() * (rSizeBtn.x + nCx1) + nCx1;
896
897 //
898 // And also wide enough for its label
899 //
900 GetTextExtent( GetTitle()
901 ,&nWidthLabel
902 ,NULL
903 );
904 nWidthLabel += RADIO_SIZE;
905 if (nWidthLabel > nWidth)
906 nWidth = nWidthLabel;
907
908 return(wxSize( nWidth
909 ,nHeight
910 )
911 );
912 } // end of wxRadioBox::GetTotalButtonSize
913
914 WXHBRUSH wxRadioBox::OnCtlColor(
915 WXHDC hwinDC
916 , WXHWND hWnd
917 , WXUINT uCtlColor
918 , WXUINT uMessage
919 , WXWPARAM wParam
920 , WXLPARAM lParam
921 )
922 {
923 HPS hPS = (HPS)hwinDC; // pass in a PS handle in OS/2
924
925 if (GetParent()->GetTransparentBackground())
926 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
927 else
928 ::GpiSetBackMix(hPS, BM_OVERPAINT);
929
930 wxColour vColBack = GetBackgroundColour();
931
932 ::GpiSetBackColor(hPS, vColBack.GetPixel());
933 ::GpiSetColor(hPS, vColBack.GetPixel());
934
935
936 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
937 ,wxSOLID
938 );
939 return ((WXHBRUSH)pBrush->GetResourceHandle());
940 } // end of wxRadioBox::OnCtlColor
941
942 bool wxRadioBox::OS2Command(
943 WXUINT uCmd
944 , WXWORD wId
945 )
946 {
947 int nSelectedButton = -1;
948
949 if (uCmd == BN_CLICKED)
950 {
951 if (wId == GetId())
952 return TRUE;
953
954
955 for (int i = 0; i < m_nNoItems; i++)
956 {
957 if (wId == wxGetWindowId(m_ahRadioButtons[i]))
958 {
959 nSelectedButton = i;
960 break;
961 }
962 }
963 if (nSelectedButton == -1)
964 {
965 //
966 // Just ignore it - due to a hack with WM_NCHITTEST handling in our
967 // wnd proc, we can receive dummy click messages when we click near
968 // the radiobox edge (this is ugly but Julian wouldn't let me get
969 // rid of this...)
970 return FALSE;
971 }
972 if (nSelectedButton != m_nSelectedButton)
973 {
974 m_nSelectedButton = nSelectedButton;
975 SendNotificationEvent();
976 }
977 return TRUE;
978 }
979 else
980 return FALSE;
981 } // end of wxRadioBox::OS2Command
982
983 void wxRadioBox::SendNotificationEvent()
984 {
985 wxCommandEvent vEvent( wxEVT_COMMAND_RADIOBOX_SELECTED
986 ,m_windowId
987 );
988
989 vEvent.SetInt( m_nSelectedButton );
990 vEvent.SetString( GetString(m_nSelectedButton) );
991 vEvent.SetEventObject(this);
992 ProcessCommand(vEvent);
993 } // end of wxRadioBox::SendNotificationEvent
994
995 void wxRadioBox::SetFocus()
996 {
997 if (m_nNoItems > 0)
998 {
999 if (m_nSelectedButton == -1)
1000 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[0]);
1001 else
1002 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[m_nSelectedButton]);
1003 }
1004 } // end of wxRadioBox::SetFocus
1005
1006 bool wxRadioBox::SetFont(
1007 const wxFont& rFont
1008 )
1009 {
1010 if (!wxControl::SetFont(rFont))
1011 {
1012 //
1013 // Nothing to do
1014 //
1015 return FALSE;
1016 }
1017 //
1018 // Also set the font of our radio buttons
1019 //
1020 WXHFONT hFont = wxFont(rFont).GetResourceHandle();
1021
1022 for (int n = 0; n < (int)m_nNoItems; n++)
1023 {
1024 HWND hWndBtn = (HWND)m_ahRadioButtons[n];
1025
1026 wxOS2SetFont( hWndBtn
1027 ,rFont
1028 );
1029 ::WinInvalidateRect(hWndBtn, NULL, FALSE);
1030 }
1031 return TRUE;
1032 } // end of wxRadioBox::SetFont
1033
1034 void wxRadioBox::SetSelection(
1035 int nNum
1036 )
1037 {
1038 wxCHECK_RET( (nNum >= 0) && (nNum < m_nNoItems), wxT("invalid radiobox index") );
1039
1040 if (m_nSelectedButton >= 0 && m_nSelectedButton < m_nNoItems)
1041 ::WinSendMsg((HWND)m_ahRadioButtons[m_nSelectedButton], BM_SETCHECK, (MPARAM)0, (MPARAM)0);
1042
1043 ::WinSendMsg((HWND)m_ahRadioButtons[nNum], BM_SETCHECK, (MPARAM)1, (MPARAM)0);
1044 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[nNum]);
1045 m_nSelectedButton = nNum;
1046 } // end of wxRadioBox::SetSelection
1047
1048 void wxRadioBox::SetString(
1049 int nItem
1050 , const wxString& rsLabel
1051 )
1052 {
1053 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems, wxT("invalid radiobox index") );
1054
1055 m_pnRadioWidth[nItem] = m_pnRadioHeight[nItem] = -1;
1056 ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], rsLabel.c_str());
1057 } // end of wxRadioBox::SetString
1058
1059 bool wxRadioBox::SetStringSelection(
1060 const wxString& rsStr
1061 )
1062 {
1063 int nSel = FindString(rsStr);
1064
1065 if (nSel > -1)
1066 {
1067 SetSelection(nSel);
1068 return TRUE;
1069 }
1070 else
1071 return FALSE;
1072 } // end of wxRadioBox::SetStringSelection
1073
1074 bool wxRadioBox::Show(
1075 bool bShow
1076 )
1077 {
1078 int nCmdShow = 0;
1079
1080 if (!wxControl::Show(bShow))
1081 return FALSE;
1082
1083 for (int i = 0; i < m_nNoItems; i++)
1084 {
1085 ::WinShowWindow((HWND)m_ahRadioButtons[i], (BOOL)bShow);
1086 }
1087 return TRUE;
1088 } // end of wxRadioBox::Show
1089
1090 // Show a specific button
1091 void wxRadioBox::Show(
1092 int nItem
1093 , bool bShow
1094 )
1095 {
1096 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems,
1097 wxT("invalid item in wxRadioBox::Show()") );
1098
1099 ::WinShowWindow((HWND)m_ahRadioButtons[nItem], bShow);
1100 } // end of wxRadioBox::Show
1101
1102 void wxRadioBox::SubclassRadioButton(
1103 WXHWND hWndBtn
1104 )
1105 {
1106 HWND hwndBtn = (HWND)hWndBtn;
1107
1108 fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
1109 } // end of wxRadioBox::SubclassRadioButton
1110
1111 MRESULT wxRadioBox::WindowProc(
1112 WXUINT uMsg
1113 , WXWPARAM wParam
1114 , WXLPARAM lParam
1115 )
1116 {
1117 return (wxControl::OS2WindowProc( uMsg
1118 ,wParam
1119 ,lParam
1120 ));
1121 } // end of wxRadioBox::WindowProc
1122
1123 // ---------------------------------------------------------------------------
1124 // window proc for radio buttons
1125 // ---------------------------------------------------------------------------
1126
1127 MRESULT wxRadioBtnWndProc(
1128 HWND hWnd
1129 , UINT uMessage
1130 , MPARAM wParam
1131 , MPARAM lParam
1132 )
1133 {
1134 switch (uMessage)
1135 {
1136 case WM_CHAR:
1137 {
1138 USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
1139
1140 if (!(uKeyFlags & KC_KEYUP)) // Key Down event
1141 {
1142 if (uKeyFlags & KC_VIRTUALKEY)
1143 {
1144 wxRadioBox* pRadiobox = (wxRadioBox *)::WinQueryWindowULong( hWnd
1145 ,QWL_USER
1146 );
1147 USHORT uVk = SHORT2FROMMP((MPARAM)lParam);
1148 bool bProcessed = TRUE;
1149 wxDirection eDir;
1150
1151 switch(uVk)
1152 {
1153 case VK_LEFT:
1154 eDir = wxDOWN;
1155 break;
1156
1157 case VK_RIGHT:
1158 eDir = wxDOWN;
1159 break;
1160
1161 case VK_DOWN:
1162 eDir = wxDOWN;
1163 break;
1164
1165 case VK_UP:
1166 eDir = wxUP;
1167 break;
1168
1169 default:
1170 bProcessed = FALSE;
1171
1172 //
1173 // Just to suppress the compiler warning
1174 //
1175 eDir = wxALL;
1176 }
1177
1178 if (bProcessed)
1179 {
1180 int nSelOld = pRadiobox->GetSelection();
1181 int nSelNew = pRadiobox->GetNextItem( nSelOld
1182 ,eDir
1183 ,pRadiobox->GetWindowStyleFlag()
1184 );
1185
1186 if (nSelNew != nSelOld)
1187 {
1188 pRadiobox->SetSelection(nSelNew);
1189
1190 //
1191 // Emulate the button click
1192 //
1193 pRadiobox->SendNotificationEvent();
1194 return 0;
1195 }
1196 }
1197 }
1198 }
1199 }
1200 break;
1201 }
1202
1203 return fnWndProcRadioBtn( hWnd
1204 ,(ULONG)uMessage
1205 ,(MPARAM)wParam
1206 ,(MPARAM)lParam
1207 );
1208 } // end of wxRadioBtnWndProc
1209