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