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