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