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