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