]> git.saurik.com Git - wxWidgets.git/blob - src/os2/radiobox.cpp
Tweaks for demos on MacOSX
[wxWidgets.git] / src / os2 / radiobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/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/wxchar.h"
18 #include "wx/string.h"
19 #include "wx/bitmap.h"
20 #include "wx/brush.h"
21 #include "wx/radiobox.h"
22 #endif
23
24 #include "wx/os2/private.h"
25
26 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
27
28 // ---------------------------------------------------------------------------
29 // private functions
30 // ---------------------------------------------------------------------------
31
32 // wnd proc for radio buttons
33 MRESULT EXPENTRY wxRadioBtnWndProc( HWND hWnd
34 ,UINT uMessage
35 ,MPARAM wParam
36 ,MPARAM lParam
37 );
38 MRESULT EXPENTRY wxRadioBoxWndProc( HWND hWnd
39 ,UINT uMessage
40 ,MPARAM wParam
41 ,MPARAM lParam
42 );
43
44 // ---------------------------------------------------------------------------
45 // global vars
46 // ---------------------------------------------------------------------------
47
48 extern void wxAssociateWinWithHandle( HWND hWnd
49 ,wxWindowOS2* pWin
50 );
51 extern void wxRemoveHandleAssociation( wxWindowOS2 *pWin );
52 // the pointer to standard radio button & box wnd procs
53 static WXFARPROC fnWndProcRadioBtn = NULL;
54 static WXFARPROC fnWndProcRadioBox = NULL;
55
56 // ===========================================================================
57 // implementation
58 // ===========================================================================
59
60 // ---------------------------------------------------------------------------
61 // wxRadioBox
62 // ---------------------------------------------------------------------------
63
64 // Radio box item
65 wxRadioBox::wxRadioBox()
66 {
67 m_nSelectedButton = -1;
68 m_nNoItems = 0;
69 m_ahRadioButtons = NULL;
70 m_pnRadioWidth = NULL;
71 m_pnRadioHeight = NULL;
72 } // end of wxRadioBox::wxRadioBox
73
74 wxRadioBox::~wxRadioBox()
75 {
76 m_isBeingDeleted = true;
77
78 if (m_hWnd)
79 wxRemoveHandleAssociation(this);
80 if (m_ahRadioButtons)
81 {
82 for (int i = 0; i < m_nNoItems; i++)
83 {
84 wxWindow* pWin = wxFindWinFromHandle((WXHWND)m_ahRadioButtons[i]);
85 wxRemoveHandleAssociation(pWin);
86
87 ::WinDestroyWindow((HWND)m_ahRadioButtons[i]);
88 }
89 delete[] m_ahRadioButtons;
90 }
91 if (m_pnRadioWidth)
92 delete[] m_pnRadioWidth;
93 if (m_pnRadioHeight)
94 delete[] m_pnRadioHeight;
95 } // end of wxRadioBox::~wxRadioBox
96
97 void wxRadioBox::Command (
98 wxCommandEvent& rEvent
99 )
100 {
101 SetSelection (rEvent.GetInt());
102 ProcessCommand(rEvent);
103 } // end of wxRadioBox::Command
104
105 bool wxRadioBox::ContainsHWND(
106 WXHWND hWnd
107 ) const
108 {
109 size_t nCount = GetCount();
110 size_t i;
111
112 for (i = 0; i < nCount; i++)
113 {
114 if (GetRadioButtons()[i] == hWnd)
115 return true;
116 }
117 return false;
118 } // end of wxRadioBox::ContainsHWND
119
120 bool wxRadioBox::Create(
121 wxWindow* pParent
122 , wxWindowID vId
123 , const wxString& rsTitle
124 , const wxPoint& rPos
125 , const wxSize& rSize
126 , const wxArrayString& asChoices
127 , int nMajorDim
128 , long lStyle
129 , const wxValidator& rVal
130 , const wxString& rsName
131 )
132 {
133 wxCArrayString chs(asChoices);
134
135 return Create(pParent, vId, rsTitle, rPos, rSize, chs.GetCount(),
136 chs.GetStrings(), nMajorDim, lStyle, rVal, rsName);
137 }
138
139 bool wxRadioBox::Create(
140 wxWindow* pParent
141 , wxWindowID vId
142 , const wxString& rsTitle
143 , const wxPoint& rPos
144 , const wxSize& rSize
145 , int nNum
146 , const wxString asChoices[]
147 , int nMajorDim
148 , long lStyle
149 , const wxValidator& rVal
150 , const wxString& rsName
151 )
152 {
153 wxColour vColour;
154 LONG lColor;
155 HWND hWndParent = GetHwndOf(pParent);
156
157 vColour.Set(wxString(wxT("BLACK")));
158 m_backgroundColour = pParent->GetBackgroundColour();
159 m_nSelectedButton = -1;
160 m_nNoItems = 0;
161
162 //
163 // Common initialization
164 //
165 if (!CreateControl( pParent
166 ,vId
167 ,rPos
168 ,rSize
169 ,lStyle
170 ,rVal
171 ,rsName
172 ))
173 return false;
174 if (!OS2CreateControl( wxT("STATIC")
175 ,SS_GROUPBOX
176 ,rPos
177 ,rSize
178 ,rsTitle
179 ))
180 return false;
181
182 wxAssociateWinWithHandle(m_hWnd, this);
183
184 //
185 // Now we can set m_nNoItems and let SetMajorDim set m_numCols/m_numRows
186 //
187 m_nNoItems = nNum;
188 SetMajorDim(nMajorDim == 0 ? nNum : nMajorDim, lStyle);
189
190 m_ahRadioButtons = new WXHWND[nNum];
191 m_pnRadioWidth = new int[nNum];
192 m_pnRadioHeight = new int[nNum];
193
194 for (int i = 0; i < nNum; i++)
195 {
196 m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1;
197 long lStyleBtn = BS_AUTORADIOBUTTON | WS_VISIBLE;
198 int nNewId = NewControlId();
199
200 if (i == 0)
201 lStyleBtn |= WS_GROUP | WS_TABSTOP;
202
203 wxString sLabel = ::wxPMTextToLabel(asChoices[i]);
204
205 HWND hWndBtn = (WXHWND)::WinCreateWindow ( hWndParent,
206 WC_BUTTON,
207 sLabel.c_str(),
208 lStyleBtn,
209 0, 0, 0, 0,
210 hWndParent,
211 HWND_BOTTOM,
212 (HMENU)nNewId,
213 NULL,
214 NULL
215 );
216 if (!hWndBtn)
217 {
218 return false;
219 }
220 lColor = (LONG)vColour.GetPixel();
221 ::WinSetPresParam( hWndBtn
222 ,PP_FOREGROUNDCOLOR
223 ,sizeof(LONG)
224 ,(PVOID)&lColor
225 );
226
227 lColor = (LONG)m_backgroundColour.GetPixel();
228 ::WinSetPresParam( hWndBtn
229 ,PP_BACKGROUNDCOLOR
230 ,sizeof(LONG)
231 ,(PVOID)&lColor
232 );
233 m_ahRadioButtons[i] = (WXHWND)hWndBtn;
234 SubclassRadioButton((WXHWND)hWndBtn);
235 wxAssociateWinWithHandle(hWndBtn, this);
236 wxOS2SetFont( hWndBtn
237 ,*wxSMALL_FONT
238 );
239 ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this);
240 m_aSubControls.Add(nNewId);
241 }
242
243 //
244 // Create a dummy control to end the group.
245 //
246 (void)::WinCreateWindow ( hWndParent,
247 WC_BUTTON,
248 "",
249 WS_GROUP,
250 0, 0, 0, 0,
251 hWndParent,
252 HWND_TOP,
253 (HMENU)NewControlId(),
254 NULL,
255 NULL
256 );
257 fnWndProcRadioBox = (WXFARPROC)::WinSubclassWindow( GetHwnd()
258 ,(PFNWP)wxRadioBoxWndProc
259 );
260 ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
261 lColor = (LONG)vColour.GetPixel();
262 ::WinSetPresParam( m_hWnd
263 ,PP_FOREGROUNDCOLOR
264 ,sizeof(LONG)
265 ,(PVOID)&lColor
266 );
267
268 lColor = (LONG)m_backgroundColour.GetPixel();
269 ::WinSetPresParam( m_hWnd
270 ,PP_BACKGROUNDCOLOR
271 ,sizeof(LONG)
272 ,(PVOID)&lColor
273 );
274 SetXComp(0);
275 SetYComp(0);
276 SetSelection(0);
277 SetSize( rPos.x
278 ,rPos.y
279 ,rSize.x
280 ,rSize.y
281 );
282 return true;
283 } // end of wxRadioBox::Create
284
285 wxSize wxRadioBox::DoGetBestSize() const
286 {
287 return (GetTotalButtonSize(GetMaxButtonSize()));
288 } // end of wxRadioBox::DoGetBestSize
289
290 void wxRadioBox::DoSetSize(
291 int nX
292 , int nY
293 , int nWidth
294 , int nHeight
295 , int nSizeFlags
296 )
297 {
298 //
299 // Input parameters assume wxWidgets coordinate system
300 //
301 int nCurrentX;
302 int nCurrentY;
303 int nWidthOld;
304 int nHeightOld;
305 int nXx = nX;
306 int nYy = nY;
307 int nXOffset = nXx;
308 int nYOffset = nYy;
309 int nCx1;
310 int nCy1;
311 wxSize vMaxSize = GetMaxButtonSize();
312 int nMaxWidth;
313 int nMaxHeight;
314 wxSize vTotSize;
315 int nTotWidth;
316 int nTotHeight;
317 int nStartX;
318 int nStartY;
319 wxFont vFont = GetFont();
320
321 m_nSizeFlags = nSizeFlags;
322 GetPosition( &nCurrentX
323 ,&nCurrentY
324 );
325 GetSize( &nWidthOld
326 ,&nHeightOld
327 );
328
329 if (nX == wxDefaultCoord && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
330 nXx = nCurrentX;
331 if (nY == wxDefaultCoord && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
332 nYy = nCurrentY;
333 if (nYy < 0)
334 nYy = 0;
335 if (nXx < 0)
336 nXx = 0;
337
338 wxGetCharSize( m_hWnd
339 ,&nCx1
340 ,&nCy1
341 ,&vFont
342 );
343
344 //
345 // Attempt to have a look coherent with other platforms: We compute the
346 // biggest toggle dim, then we align all items according this value.
347 //
348 vMaxSize = GetMaxButtonSize();
349 nMaxWidth = vMaxSize.x;
350 nMaxHeight = vMaxSize.y;
351
352 vTotSize = GetTotalButtonSize(vMaxSize);
353 nTotWidth = vTotSize.x;
354 nTotHeight = vTotSize.y;
355
356 //
357 // Only change our width/height if asked for
358 //
359 if (nWidth == -1)
360 {
361 if (nSizeFlags & wxSIZE_AUTO_WIDTH )
362 nWidth = nTotWidth;
363 else
364 nWidth = nWidthOld;
365 }
366
367 if (nHeight == -1)
368 {
369 if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
370 nHeight = nTotHeight;
371 else
372 nHeight = nHeightOld;
373 }
374
375 //
376 // Now convert to OS/2 coordinate system
377 //
378 wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
379 if (pParent)
380 nYy = GetOS2ParentHeight(pParent) - nYy - nHeight;
381 else
382 {
383 RECTL vRect;
384 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
385 nYy = vRect.yTop - nYy - nHeight;
386 }
387 nYOffset = nYy + nHeight;
388 ::WinSetWindowPos( GetHwnd()
389 ,HWND_TOP
390 ,(LONG)nXx
391 ,(LONG)nYy
392 ,(LONG)nWidth
393 ,(LONG)nHeight
394 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
395 );
396
397 //
398 // Now position all the buttons: the current button will be put at
399 // wxPoint(x_offset, y_offset) and the new row/column will start at
400 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
401 // maxHeight) except for the buttons in the last column which should extend
402 // to the right border of radiobox and thus can be wider than this.
403 //
404 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
405 // left to right order and m_majorDim is the number of columns while
406 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
407 // m_majorDim is the number of rows.
408 //
409 nXOffset += nCx1;
410 nYOffset -= (nMaxHeight + ((3*nCy1)/2));
411
412 nStartX = nXOffset;
413 nStartY = nYOffset;
414
415 for (int i = 0; i < m_nNoItems; i++)
416 {
417 //
418 // The last button in the row may be wider than the other ones as the
419 // radiobox may be wider than the sum of the button widths (as it
420 // happens, for example, when the radiobox label is very long)
421 //
422 bool bIsLastInTheRow;
423
424 if (m_windowStyle & wxRA_SPECIFY_COLS)
425 {
426 //
427 // Item is the last in its row if it is a multiple of the number of
428 // columns or if it is just the last item
429 //
430 int n = i + 1;
431
432 bIsLastInTheRow = ((n % GetMajorDim()) == 0) || (n == m_nNoItems);
433 }
434 else // winRA_SPECIFY_ROWS
435 {
436 //
437 // Item is the last in the row if it is in the last columns
438 //
439 bIsLastInTheRow = i >= (m_nNoItems/GetMajorDim()) * GetMajorDim();
440 }
441
442 //
443 // Is this the start of new row/column?
444 //
445 if (i && (i % GetMajorDim() == 0))
446 {
447 if (m_windowStyle & wxRA_SPECIFY_ROWS)
448 {
449 //
450 // Start of new column
451 //
452 nYOffset = nStartY;
453 nXOffset += nMaxWidth + nCx1;
454 }
455 else // start of new row
456 {
457 nXOffset = nStartX;
458 nYOffset -= nMaxHeight;
459 if (m_pnRadioWidth[0] > 0L)
460 nYOffset -= nCy1/2;
461 }
462 }
463
464 int nWidthBtn;
465
466 if (bIsLastInTheRow)
467 {
468 //
469 // Make the button go to the end of radio box
470 //
471 nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1);
472 if (nWidthBtn < nMaxWidth)
473 nWidthBtn = nMaxWidth;
474 }
475 else
476 {
477 //
478 // Normal button, always of the same size
479 //
480 nWidthBtn = nMaxWidth;
481 }
482
483 //
484 // Make all buttons of the same, maximal size - like this they
485 // cover the radiobox entirely and the radiobox tooltips are always
486 // shown (otherwise they are not when the mouse pointer is in the
487 // radiobox part not belonging to any radiobutton)
488 //
489 ::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
490 ,HWND_BOTTOM
491 ,(LONG)nXOffset
492 ,(LONG)nYOffset
493 ,(LONG)nWidthBtn
494 ,(LONG)nMaxHeight
495 ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
496 );
497 //
498 // Where do we put the next button?
499 //
500 if (m_windowStyle & wxRA_SPECIFY_ROWS)
501 {
502 //
503 // Below this one
504 //
505 nYOffset -= nMaxHeight;
506 if (m_pnRadioWidth[0] > 0)
507 nYOffset -= nCy1/2;
508 }
509 else
510 {
511 //
512 // To the right of this one
513 //
514 nXOffset += nWidthBtn + nCx1;
515 }
516 }
517 } // end of wxRadioBox::DoSetSize
518
519 bool wxRadioBox::Enable(int nItem, bool bEnable)
520 {
521 wxCHECK_MSG( IsValid(nItem), false,
522 wxT("invalid item in wxRadioBox::Enable()") );
523
524 ::WinEnableWindow((HWND) m_ahRadioButtons[nItem], bEnable);
525 return true;
526 } // end of wxRadioBox::Enable
527
528 bool wxRadioBox::Enable(
529 bool bEnable
530 )
531 {
532 if ( !wxControl::Enable(bEnable) )
533 return false;
534 for (int i = 0; i < m_nNoItems; i++)
535 ::WinEnableWindow((HWND)m_ahRadioButtons[i], bEnable);
536 return true;
537 } // end of wxRadioBox::Enable
538
539 int wxRadioBox::GetCount() const
540 {
541 return m_nNoItems;
542 } // end of wxRadioBox::GetCount
543
544 wxString wxRadioBox::GetLabel(int nItem) const
545 {
546 wxCHECK_MSG( IsValid(nItem), wxEmptyString, wxT("invalid radiobox index") );
547
548 return wxGetWindowText(m_ahRadioButtons[nItem]);
549 } // end of wxRadioBox::GetLabel
550
551 wxSize wxRadioBox::GetMaxButtonSize() const
552 {
553 int nWidthMax = 0;
554 int nHeightMax = 0;
555
556 for (int i = 0 ; i < m_nNoItems; i++)
557 {
558 int nWidth;
559 int nHeight;
560
561 if (m_pnRadioWidth[i] < 0L)
562 {
563 GetTextExtent( wxGetWindowText(m_ahRadioButtons[i])
564 ,&nWidth
565 ,&nHeight
566 );
567
568 //
569 // Adjust the size to take into account the radio box itself
570 // FIXME this is totally bogus!
571 //
572 nWidth += RADIO_SIZE;
573 nHeight *= 3;
574 nHeight /= 2;
575 }
576 else
577 {
578 nWidth = m_pnRadioWidth[i];
579 nHeight = m_pnRadioHeight[i];
580 }
581 if (nWidthMax < nWidth )
582 nWidthMax = nWidth;
583 if (nHeightMax < nHeight )
584 nHeightMax = nHeight;
585 }
586 wxSize maxsize( nWidthMax, nHeightMax);
587 return maxsize;
588 } // end of wxRadioBox::GetMaxButtonSize
589
590 // Get single selection, for single choice list items
591 int wxRadioBox::GetSelection() const
592 {
593 return m_nSelectedButton;
594 } // end of wxRadioBox::GetSelection
595
596 void wxRadioBox::GetSize( int* pnWidth, int* pnHeight ) const
597 {
598 RECT vRect;
599
600 vRect.xLeft = -1;
601 vRect.xRight = -1;
602 vRect.yTop = -1;
603 vRect.yBottom = -1;
604
605 if (m_hWnd)
606 wxFindMaxSize( m_hWnd
607 ,&vRect
608 );
609
610 for (int i = 0; i < m_nNoItems; i++)
611 wxFindMaxSize( m_ahRadioButtons[i]
612 ,&vRect
613 );
614
615 if (pnWidth)
616 *pnWidth = vRect.xRight - vRect.xLeft;
617 if (pnHeight)
618 *pnHeight = vRect.yTop - vRect.yBottom;
619 } // end of wxRadioBox::GetSize
620
621 // Find string for position
622 wxString wxRadioBox::GetString( int nNum ) const
623 {
624 wxCHECK_MSG( IsValid(nNum), wxEmptyString, wxT("invalid radiobox index") );
625 return wxGetWindowText(m_ahRadioButtons[nNum]);
626 } // end of wxRadioBox::GetString
627
628 // For single selection items only
629 wxString wxRadioBox::GetStringSelection() const
630 {
631 wxString sResult;
632 int nSel = GetSelection();
633
634 if (nSel > -1)
635 sResult = GetString(nSel);
636 return sResult;
637 } // end of wxRadioBox::GetStringSelection
638
639 wxSize wxRadioBox::GetTotalButtonSize( const wxSize& rSizeBtn ) const
640 {
641 int nCx1;
642 int nCy1;
643 int nHeight;
644 int nWidth;
645 int nWidthLabel = 0;
646
647 nCx1 = GetCharWidth();
648 nCy1 = GetCharHeight();
649 nHeight = GetRowCount() * rSizeBtn.y + (2 * nCy1);
650 nWidth = GetColumnCount() * (rSizeBtn.x + nCx1) + nCx1;
651
652 //
653 // And also wide enough for its label
654 //
655 wxString sStr = wxGetWindowText(GetHwnd());
656 if (!sStr.empty())
657 {
658 GetTextExtent( sStr
659 ,&nWidthLabel
660 ,NULL
661 );
662 nWidthLabel += 2*nCx1;
663 }
664 if (nWidthLabel > nWidth)
665 nWidth = nWidthLabel;
666
667 wxSize total( nWidth, nHeight );
668 return total;
669 } // end of wxRadioBox::GetTotalButtonSize
670
671 WXHBRUSH wxRadioBox::OnCtlColor( WXHDC hwinDC,
672 WXHWND WXUNUSED(hWnd),
673 WXUINT WXUNUSED(uCtlColor),
674 WXUINT WXUNUSED(uMessage),
675 WXWPARAM WXUNUSED(wParam),
676 WXLPARAM WXUNUSED(lParam) )
677 {
678 HPS hPS = (HPS)hwinDC; // pass in a PS handle in OS/2
679
680 if (GetParent()->GetTransparentBackground())
681 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
682 else
683 ::GpiSetBackMix(hPS, BM_OVERPAINT);
684
685 wxColour vColBack = GetBackgroundColour();
686
687 ::GpiSetBackColor(hPS, vColBack.GetPixel());
688 ::GpiSetColor(hPS, vColBack.GetPixel());
689
690 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack, wxSOLID );
691 return ((WXHBRUSH)pBrush->GetResourceHandle());
692 } // end of wxRadioBox::OnCtlColor
693
694 bool wxRadioBox::OS2Command( WXUINT uCmd,
695 WXWORD wId)
696 {
697 int nSelectedButton = -1;
698
699 if (uCmd == BN_CLICKED)
700 {
701 if (wId == GetId())
702 return true;
703
704 for (int i = 0; i < m_nNoItems; i++)
705 {
706 if (wId == wxGetWindowId(m_ahRadioButtons[i]))
707 {
708 nSelectedButton = i;
709 break;
710 }
711 }
712 if (nSelectedButton == -1)
713 {
714 //
715 // Just ignore it
716 //
717 return false;
718 }
719 if (nSelectedButton != m_nSelectedButton)
720 {
721 m_nSelectedButton = nSelectedButton;
722 SendNotificationEvent();
723 }
724 return true;
725 }
726 else
727 return false;
728 } // end of wxRadioBox::OS2Command
729
730 void wxRadioBox::SendNotificationEvent()
731 {
732 wxCommandEvent vEvent( wxEVT_COMMAND_RADIOBOX_SELECTED
733 ,m_windowId
734 );
735
736 vEvent.SetInt( m_nSelectedButton );
737 vEvent.SetString( GetString(m_nSelectedButton) );
738 vEvent.SetEventObject(this);
739 ProcessCommand(vEvent);
740 } // end of wxRadioBox::SendNotificationEvent
741
742 void wxRadioBox::SetFocus()
743 {
744 if (m_nNoItems > 0)
745 {
746 if (m_nSelectedButton == -1)
747 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[0]);
748 else
749 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[m_nSelectedButton]);
750 }
751 } // end of wxRadioBox::SetFocus
752
753 bool wxRadioBox::SetFont(
754 const wxFont& rFont
755 )
756 {
757 if (!wxControl::SetFont(rFont))
758 {
759 //
760 // Nothing to do
761 //
762 return false;
763 }
764 //
765 // Also set the font of our radio buttons
766 //
767 for (int n = 0; n < (int)m_nNoItems; n++)
768 {
769 HWND hWndBtn = (HWND)m_ahRadioButtons[n];
770
771 wxOS2SetFont( hWndBtn
772 ,rFont
773 );
774 ::WinInvalidateRect(hWndBtn, NULL, FALSE);
775 }
776 return true;
777 } // end of wxRadioBox::SetFont
778
779 void wxRadioBox::SetSelection(
780 int nNum
781 )
782 {
783 wxCHECK_RET( IsValid(nNum), wxT("invalid radiobox index") );
784
785 if ( IsValid(m_nSelectedButton) )
786 ::WinSendMsg((HWND)m_ahRadioButtons[m_nSelectedButton], BM_SETCHECK, (MPARAM)0, (MPARAM)0);
787
788 ::WinSendMsg((HWND)m_ahRadioButtons[nNum], BM_SETCHECK, (MPARAM)1, (MPARAM)0);
789 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[nNum]);
790 m_nSelectedButton = nNum;
791 } // end of wxRadioBox::SetSelection
792
793 void wxRadioBox::SetString(
794 int nItem
795 , const wxString& rsLabel
796 )
797 {
798 wxCHECK_RET( IsValid(nItem), wxT("invalid radiobox index") );
799
800 m_pnRadioWidth[nItem] = m_pnRadioHeight[nItem] = -1;
801 ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], (PSZ)rsLabel.c_str());
802 } // end of wxRadioBox::SetString
803
804 bool wxRadioBox::SetStringSelection(const wxString& rsStr)
805 {
806 int nSel = FindString(rsStr);
807
808 if (nSel > -1)
809 {
810 SetSelection(nSel);
811 return true;
812 }
813 else
814 return false;
815 } // end of wxRadioBox::SetStringSelection
816
817 bool wxRadioBox::Show(
818 bool bShow
819 )
820 {
821 if (!wxControl::Show(bShow))
822 return false;
823
824 for (int i = 0; i < m_nNoItems; i++)
825 {
826 ::WinShowWindow((HWND)m_ahRadioButtons[i], (BOOL)bShow);
827 }
828 return true;
829 } // end of wxRadioBox::Show
830
831 // Show a specific button
832 bool wxRadioBox::Show(
833 int nItem
834 , bool bShow
835 )
836 {
837 wxCHECK_MSG( IsValid(nItem), false,
838 wxT("invalid item in wxRadioBox::Show()") );
839
840 ::WinShowWindow((HWND)m_ahRadioButtons[nItem], bShow);
841
842 return true;
843 } // end of wxRadioBox::Show
844
845 void wxRadioBox::SubclassRadioButton(
846 WXHWND hWndBtn
847 )
848 {
849 fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
850 } // end of wxRadioBox::SubclassRadioButton
851
852 MRESULT wxRadioBox::WindowProc(
853 WXUINT uMsg
854 , WXWPARAM wParam
855 , WXLPARAM lParam
856 )
857 {
858 return (wxControl::OS2WindowProc( uMsg
859 ,wParam
860 ,lParam
861 ));
862 } // end of wxRadioBox::WindowProc
863
864 // ---------------------------------------------------------------------------
865 // window proc for radio buttons
866 // ---------------------------------------------------------------------------
867
868 MRESULT wxRadioBtnWndProc(
869 HWND hWnd
870 , UINT uMessage
871 , MPARAM wParam
872 , MPARAM lParam
873 )
874 {
875 switch (uMessage)
876 {
877 case WM_CHAR:
878 {
879 USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
880
881 if (!(uKeyFlags & KC_KEYUP)) // Key Down event
882 {
883 if (uKeyFlags & KC_VIRTUALKEY)
884 {
885 wxRadioBox* pRadiobox = (wxRadioBox *)::WinQueryWindowULong( hWnd
886 ,QWL_USER
887 );
888 USHORT uVk = SHORT2FROMMP((MPARAM)lParam);
889 bool bProcessed = true;
890 wxDirection eDir;
891
892 switch(uVk)
893 {
894 case VK_LEFT:
895 eDir = wxLEFT;
896 break;
897
898 case VK_RIGHT:
899 eDir = wxRIGHT;
900 break;
901
902 case VK_DOWN:
903 eDir = wxDOWN;
904 break;
905
906 case VK_UP:
907 eDir = wxUP;
908 break;
909
910 default:
911 bProcessed = false;
912
913 //
914 // Just to suppress the compiler warning
915 //
916 eDir = wxALL;
917 }
918
919 if (bProcessed)
920 {
921 int nSelOld = pRadiobox->GetSelection();
922 int nSelNew = pRadiobox->GetNextItem( nSelOld
923 ,eDir
924 ,pRadiobox->GetWindowStyleFlag()
925 );
926
927 if (nSelNew != nSelOld)
928 {
929 pRadiobox->SetSelection(nSelNew);
930
931 //
932 // Emulate the button click
933 //
934 pRadiobox->SendNotificationEvent();
935 return 0;
936 }
937 }
938 }
939 }
940 }
941 break;
942 }
943
944 return fnWndProcRadioBtn( hWnd
945 ,(ULONG)uMessage
946 ,(MPARAM)wParam
947 ,(MPARAM)lParam
948 );
949 } // end of wxRadioBtnWndProc
950
951 MRESULT EXPENTRY wxRadioBoxWndProc( HWND hWnd,
952 UINT uMessage,
953 MPARAM wParam,
954 MPARAM lParam )
955 {
956 return (fnWndProcRadioBox( hWnd,
957 (ULONG)uMessage,
958 (MPARAM)wParam,
959 (MPARAM)lParam )
960 );
961 } // end of wxRadioBoxWndProc