]> git.saurik.com Git - wxWidgets.git/blob - src/os2/radiobox.cpp
Reverted FILLCOLORHINT->FILLCOLOR change. Now when a near black themeColor is returne...
[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 *pnWidth = vRect.xRight - vRect.xLeft;
872 *pnHeight = vRect.yBottom - vRect.yTop;
873 } // end of wxRadioBox::GetSize
874
875 // Find string for position
876 wxString wxRadioBox::GetString(
877 int nNum
878 ) const
879 {
880 return wxGetWindowText(m_ahRadioButtons[nNum]);
881 } // end of wxRadioBox::GetString
882
883 // For single selection items only
884 wxString wxRadioBox::GetStringSelection() const
885 {
886 wxString sResult;
887 int nSel = GetSelection();
888
889 if (nSel > -1)
890 sResult = GetString(nSel);
891 return sResult;
892 } // end of wxRadioBox::GetStringSelection
893
894 wxSize wxRadioBox::GetTotalButtonSize(
895 const wxSize& rSizeBtn
896 ) const
897 {
898 int nCx1;
899 int nCy1;
900 int nExtraHeight;
901 int nHeight;
902 int nWidth;
903 int nWidthLabel;
904
905 wxGetCharSize( m_hWnd
906 ,&nCx1
907 ,&nCy1
908 ,(wxFont*)&GetFont()
909 );
910 nExtraHeight = nCy1;
911
912 nHeight = GetNumVer() * rSizeBtn.y + (2 * nCy1);
913 nWidth = GetNumHor() * (rSizeBtn.x + nCx1) + nCx1;
914
915 //
916 // And also wide enough for its label
917 //
918 GetTextExtent( GetTitle()
919 ,&nWidthLabel
920 ,NULL
921 );
922 nWidthLabel += RADIO_SIZE;
923 if (nWidthLabel > nWidth)
924 nWidth = nWidthLabel;
925
926 return(wxSize( nWidth
927 ,nHeight
928 )
929 );
930 } // end of wxRadioBox::GetTotalButtonSize
931
932 WXHBRUSH wxRadioBox::OnCtlColor(
933 WXHDC hwinDC
934 , WXHWND hWnd
935 , WXUINT uCtlColor
936 , WXUINT uMessage
937 , WXWPARAM wParam
938 , WXLPARAM lParam
939 )
940 {
941 HPS hPS = (HPS)hwinDC; // pass in a PS handle in OS/2
942
943 if (GetParent()->GetTransparentBackground())
944 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
945 else
946 ::GpiSetBackMix(hPS, BM_OVERPAINT);
947
948 wxColour vColBack = GetBackgroundColour();
949
950 ::GpiSetBackColor(hPS, vColBack.GetPixel());
951 ::GpiSetColor(hPS, vColBack.GetPixel());
952
953
954 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
955 ,wxSOLID
956 );
957 return ((WXHBRUSH)pBrush->GetResourceHandle());
958 } // end of wxRadioBox::OnCtlColor
959
960 bool wxRadioBox::OS2Command(
961 WXUINT uCmd
962 , WXWORD wId
963 )
964 {
965 int nSelectedButton = -1;
966
967 if (uCmd == BN_CLICKED)
968 {
969 if (wId == GetId())
970 return TRUE;
971
972
973 for (int i = 0; i < m_nNoItems; i++)
974 {
975 if (wId == wxGetWindowId(m_ahRadioButtons[i]))
976 {
977 nSelectedButton = i;
978 break;
979 }
980 }
981 if (nSelectedButton == -1)
982 {
983 //
984 // Just ignore it
985 //
986 return FALSE;
987 }
988 if (nSelectedButton != m_nSelectedButton)
989 {
990 m_nSelectedButton = nSelectedButton;
991 SendNotificationEvent();
992 }
993 return TRUE;
994 }
995 else
996 return FALSE;
997 } // end of wxRadioBox::OS2Command
998
999 void wxRadioBox::SendNotificationEvent()
1000 {
1001 wxCommandEvent vEvent( wxEVT_COMMAND_RADIOBOX_SELECTED
1002 ,m_windowId
1003 );
1004
1005 vEvent.SetInt( m_nSelectedButton );
1006 vEvent.SetString( GetString(m_nSelectedButton) );
1007 vEvent.SetEventObject(this);
1008 ProcessCommand(vEvent);
1009 } // end of wxRadioBox::SendNotificationEvent
1010
1011 void wxRadioBox::SetFocus()
1012 {
1013 if (m_nNoItems > 0)
1014 {
1015 if (m_nSelectedButton == -1)
1016 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[0]);
1017 else
1018 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[m_nSelectedButton]);
1019 }
1020 } // end of wxRadioBox::SetFocus
1021
1022 bool wxRadioBox::SetFont(
1023 const wxFont& rFont
1024 )
1025 {
1026 if (!wxControl::SetFont(rFont))
1027 {
1028 //
1029 // Nothing to do
1030 //
1031 return FALSE;
1032 }
1033 //
1034 // Also set the font of our radio buttons
1035 //
1036 for (int n = 0; n < (int)m_nNoItems; n++)
1037 {
1038 HWND hWndBtn = (HWND)m_ahRadioButtons[n];
1039
1040 wxOS2SetFont( hWndBtn
1041 ,rFont
1042 );
1043 ::WinInvalidateRect(hWndBtn, NULL, FALSE);
1044 }
1045 return TRUE;
1046 } // end of wxRadioBox::SetFont
1047
1048 void wxRadioBox::SetSelection(
1049 int nNum
1050 )
1051 {
1052 wxCHECK_RET( (nNum >= 0) && (nNum < m_nNoItems), wxT("invalid radiobox index") );
1053
1054 if (m_nSelectedButton >= 0 && m_nSelectedButton < m_nNoItems)
1055 ::WinSendMsg((HWND)m_ahRadioButtons[m_nSelectedButton], BM_SETCHECK, (MPARAM)0, (MPARAM)0);
1056
1057 ::WinSendMsg((HWND)m_ahRadioButtons[nNum], BM_SETCHECK, (MPARAM)1, (MPARAM)0);
1058 ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[nNum]);
1059 m_nSelectedButton = nNum;
1060 } // end of wxRadioBox::SetSelection
1061
1062 void wxRadioBox::SetString(
1063 int nItem
1064 , const wxString& rsLabel
1065 )
1066 {
1067 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems, wxT("invalid radiobox index") );
1068
1069 m_pnRadioWidth[nItem] = m_pnRadioHeight[nItem] = -1;
1070 ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], rsLabel.c_str());
1071 } // end of wxRadioBox::SetString
1072
1073 bool wxRadioBox::SetStringSelection(
1074 const wxString& rsStr
1075 )
1076 {
1077 int nSel = FindString(rsStr);
1078
1079 if (nSel > -1)
1080 {
1081 SetSelection(nSel);
1082 return TRUE;
1083 }
1084 else
1085 return FALSE;
1086 } // end of wxRadioBox::SetStringSelection
1087
1088 bool wxRadioBox::Show(
1089 bool bShow
1090 )
1091 {
1092 if (!wxControl::Show(bShow))
1093 return FALSE;
1094
1095 for (int i = 0; i < m_nNoItems; i++)
1096 {
1097 ::WinShowWindow((HWND)m_ahRadioButtons[i], (BOOL)bShow);
1098 }
1099 return TRUE;
1100 } // end of wxRadioBox::Show
1101
1102 // Show a specific button
1103 void wxRadioBox::Show(
1104 int nItem
1105 , bool bShow
1106 )
1107 {
1108 wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems,
1109 wxT("invalid item in wxRadioBox::Show()") );
1110
1111 ::WinShowWindow((HWND)m_ahRadioButtons[nItem], bShow);
1112 } // end of wxRadioBox::Show
1113
1114 void wxRadioBox::SubclassRadioButton(
1115 WXHWND hWndBtn
1116 )
1117 {
1118 fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
1119 } // end of wxRadioBox::SubclassRadioButton
1120
1121 MRESULT wxRadioBox::WindowProc(
1122 WXUINT uMsg
1123 , WXWPARAM wParam
1124 , WXLPARAM lParam
1125 )
1126 {
1127 return (wxControl::OS2WindowProc( uMsg
1128 ,wParam
1129 ,lParam
1130 ));
1131 } // end of wxRadioBox::WindowProc
1132
1133 // ---------------------------------------------------------------------------
1134 // window proc for radio buttons
1135 // ---------------------------------------------------------------------------
1136
1137 MRESULT wxRadioBtnWndProc(
1138 HWND hWnd
1139 , UINT uMessage
1140 , MPARAM wParam
1141 , MPARAM lParam
1142 )
1143 {
1144 switch (uMessage)
1145 {
1146 case WM_CHAR:
1147 {
1148 USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
1149
1150 if (!(uKeyFlags & KC_KEYUP)) // Key Down event
1151 {
1152 if (uKeyFlags & KC_VIRTUALKEY)
1153 {
1154 wxRadioBox* pRadiobox = (wxRadioBox *)::WinQueryWindowULong( hWnd
1155 ,QWL_USER
1156 );
1157 USHORT uVk = SHORT2FROMMP((MPARAM)lParam);
1158 bool bProcessed = TRUE;
1159 wxDirection eDir;
1160
1161 switch(uVk)
1162 {
1163 case VK_LEFT:
1164 eDir = wxDOWN;
1165 break;
1166
1167 case VK_RIGHT:
1168 eDir = wxDOWN;
1169 break;
1170
1171 case VK_DOWN:
1172 eDir = wxDOWN;
1173 break;
1174
1175 case VK_UP:
1176 eDir = wxUP;
1177 break;
1178
1179 default:
1180 bProcessed = FALSE;
1181
1182 //
1183 // Just to suppress the compiler warning
1184 //
1185 eDir = wxALL;
1186 }
1187
1188 if (bProcessed)
1189 {
1190 int nSelOld = pRadiobox->GetSelection();
1191 int nSelNew = pRadiobox->GetNextItem( nSelOld
1192 ,eDir
1193 ,pRadiobox->GetWindowStyleFlag()
1194 );
1195
1196 if (nSelNew != nSelOld)
1197 {
1198 pRadiobox->SetSelection(nSelNew);
1199
1200 //
1201 // Emulate the button click
1202 //
1203 pRadiobox->SendNotificationEvent();
1204 return 0;
1205 }
1206 }
1207 }
1208 }
1209 }
1210 break;
1211 }
1212
1213 return fnWndProcRadioBtn( hWnd
1214 ,(ULONG)uMessage
1215 ,(MPARAM)wParam
1216 ,(MPARAM)lParam
1217 );
1218 } // end of wxRadioBtnWndProc
1219
1220 MRESULT EXPENTRY wxRadioBoxWndProc(
1221 HWND hWnd
1222 , UINT uMessage
1223 , MPARAM wParam
1224 , MPARAM lParam
1225 )
1226 {
1227 return (fnWndProcRadioBox( hWnd
1228 ,(ULONG)uMessage
1229 ,(MPARAM)wParam
1230 ,(MPARAM)lParam
1231 )
1232 );
1233 } // end of wxRadioBoxWndProc
1234