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