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