]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: radiobox.cpp | |
3 | // Purpose: wxRadioBox | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "radiobox.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include <stdio.h> | |
33 | #include "wx/setup.h" | |
34 | #include "wx/bitmap.h" | |
35 | #include "wx/brush.h" | |
36 | #include "wx/radiobox.h" | |
37 | #endif | |
38 | ||
39 | #include "wx/msw/private.h" | |
40 | ||
41 | #if !USE_SHARED_LIBRARY | |
42 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) | |
43 | #endif | |
44 | ||
45 | // --------------------------------------------------------------------------- | |
46 | // private functions | |
47 | // --------------------------------------------------------------------------- | |
48 | ||
49 | // get the id of the window | |
50 | #ifdef __WIN32__ | |
51 | #define GET_WIN_ID(hwnd) ::GetWindowLong((HWND)hwnd, GWL_ID) | |
52 | #else // Win16 | |
53 | #define GET_WIN_ID(hwnd) ::GetWindowWord((HWND)hwnd, GWW_ID) | |
54 | #endif // Win32/16 | |
55 | ||
56 | // wnd proc for radio buttons | |
57 | #ifdef __WIN32__ | |
58 | LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hWnd, | |
59 | UINT message, | |
60 | WPARAM wParam, | |
61 | LPARAM lParam); | |
62 | #endif | |
63 | ||
64 | // --------------------------------------------------------------------------- | |
65 | // global vars | |
66 | // --------------------------------------------------------------------------- | |
67 | ||
68 | // the pointer to standard radio button wnd proc | |
69 | // static WNDPROC s_wndprocRadioBtn = (WNDPROC)NULL; | |
70 | static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL; | |
71 | ||
72 | // =========================================================================== | |
73 | // implementation | |
74 | // =========================================================================== | |
75 | ||
76 | // --------------------------------------------------------------------------- | |
77 | // wxRadioBox | |
78 | // --------------------------------------------------------------------------- | |
79 | ||
80 | int wxRadioBox::GetNumVer() const | |
81 | { | |
82 | if ( m_windowStyle & wxRA_SPECIFY_ROWS ) | |
83 | { | |
84 | return m_majorDim; | |
85 | } | |
86 | else | |
87 | { | |
88 | return (m_noItems + m_majorDim - 1)/m_majorDim; | |
89 | } | |
90 | } | |
91 | ||
92 | int wxRadioBox::GetNumHor() const | |
93 | { | |
94 | if ( m_windowStyle & wxRA_SPECIFY_ROWS ) | |
95 | { | |
96 | return (m_noItems + m_majorDim - 1)/m_majorDim; | |
97 | } | |
98 | else | |
99 | { | |
100 | return m_majorDim; | |
101 | } | |
102 | } | |
103 | ||
104 | bool wxRadioBox::MSWCommand(WXUINT param, WXWORD id) | |
105 | { | |
106 | if ( param == BN_CLICKED ) | |
107 | { | |
108 | m_selectedButton = -1; | |
109 | ||
110 | for ( int i = 0; i < m_noItems; i++ ) | |
111 | { | |
112 | if ( id == GET_WIN_ID(m_radioButtons[i]) ) | |
113 | { | |
114 | m_selectedButton = i; | |
115 | ||
116 | break; | |
117 | } | |
118 | } | |
119 | ||
120 | wxASSERT_MSG( m_selectedButton != -1, "click from alien button?" ); | |
121 | ||
122 | wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId); | |
123 | event.SetInt( m_selectedButton ); | |
124 | event.SetEventObject( this ); | |
125 | ProcessCommand(event); | |
126 | ||
127 | return TRUE; | |
128 | } | |
129 | else | |
130 | return FALSE; | |
131 | } | |
132 | ||
133 | #if WXWIN_COMPATIBILITY | |
134 | wxRadioBox::wxRadioBox(wxWindow *parent, wxFunction func, const char *title, | |
135 | int x, int y, int width, int height, | |
136 | int n, char **choices, | |
137 | int majorDim, long style, const char *name) | |
138 | { | |
139 | wxString *choices2 = new wxString[n]; | |
140 | for ( int i = 0; i < n; i ++) choices2[i] = choices[i]; | |
141 | Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), n, choices2, majorDim, style, | |
142 | wxDefaultValidator, name); | |
143 | Callback(func); | |
144 | delete choices2; | |
145 | } | |
146 | ||
147 | #endif | |
148 | ||
149 | // Radio box item | |
150 | wxRadioBox::wxRadioBox() | |
151 | { | |
152 | m_selectedButton = -1; | |
153 | m_noItems = 0; | |
154 | m_noRowsOrCols = 0; | |
155 | m_radioButtons = NULL; | |
156 | m_majorDim = 0; | |
157 | m_radioWidth = NULL; | |
158 | m_radioHeight = NULL; | |
159 | } | |
160 | ||
161 | bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, | |
162 | const wxPoint& pos, const wxSize& size, | |
163 | int n, const wxString choices[], | |
164 | int majorDim, long style, | |
165 | const wxValidator& val, const wxString& name) | |
166 | { | |
167 | m_selectedButton = -1; | |
168 | m_noItems = n; | |
169 | ||
170 | SetName(name); | |
171 | SetValidator(val); | |
172 | ||
173 | parent->AddChild(this); | |
174 | m_backgroundColour = parent->GetBackgroundColour(); | |
175 | m_foregroundColour = parent->GetForegroundColour(); | |
176 | ||
177 | m_windowStyle = (long&)style; | |
178 | ||
179 | int x = pos.x; | |
180 | int y = pos.y; | |
181 | int width = size.x; | |
182 | int height = size.y; | |
183 | ||
184 | if (id == -1) | |
185 | m_windowId = NewControlId(); | |
186 | else | |
187 | m_windowId = id; | |
188 | ||
189 | if ( majorDim == 0 ) | |
190 | m_majorDim = n; | |
191 | else | |
192 | m_majorDim = majorDim; | |
193 | m_noRowsOrCols = majorDim; | |
194 | ||
195 | long msStyle = GROUP_FLAGS; | |
196 | ||
197 | bool want3D; | |
198 | WXDWORD exStyle = Determine3DEffects(0, &want3D); | |
199 | // Even with extended styles, need to combine with WS_BORDER | |
200 | // for them to look right. | |
201 | /* | |
202 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) | |
203 | msStyle |= WS_BORDER; | |
204 | */ | |
205 | ||
206 | HWND hwndParent = (HWND)parent->GetHWND(); | |
207 | ||
208 | m_hWnd = (WXHWND)::CreateWindowEx | |
209 | ( | |
210 | (DWORD)exStyle, | |
211 | GROUP_CLASS, | |
212 | title, | |
213 | msStyle, | |
214 | 0, 0, 0, 0, | |
215 | hwndParent, | |
216 | (HMENU)m_windowId, | |
217 | wxGetInstance(), | |
218 | NULL | |
219 | ); | |
220 | ||
221 | #if wxUSE_CTL3D | |
222 | if (want3D) | |
223 | { | |
224 | Ctl3dSubclassCtl((HWND)m_hWnd); | |
225 | m_useCtl3D = TRUE; | |
226 | } | |
227 | #endif // wxUSE_CTL3D | |
228 | ||
229 | SetFont(parent->GetFont()); | |
230 | ||
231 | SubclassWin(m_hWnd); | |
232 | ||
233 | // Some radio boxes test consecutive id. | |
234 | (void)NewControlId(); | |
235 | m_radioButtons = new WXHWND[n]; | |
236 | m_radioWidth = new int[n]; | |
237 | m_radioHeight = new int[n]; | |
238 | int i; | |
239 | for (i = 0; i < n; i++) | |
240 | { | |
241 | m_radioWidth[i] = m_radioHeight[i] = -1; | |
242 | long groupStyle = 0; | |
243 | if ( i == 0 && style == 0 ) | |
244 | groupStyle = WS_GROUP; | |
245 | long newId = NewControlId(); | |
246 | long msStyle = groupStyle | RADIO_FLAGS; | |
247 | ||
248 | HWND hwndBtn = CreateWindowEx(exStyle, RADIO_CLASS, | |
249 | choices[i], msStyle, | |
250 | 0,0,0,0, | |
251 | hwndParent, | |
252 | (HMENU)newId, wxGetInstance(), | |
253 | NULL); | |
254 | ||
255 | m_radioButtons[i] = (WXHWND)hwndBtn; | |
256 | SubclassRadioButton((WXHWND)hwndBtn); | |
257 | ||
258 | wxFont& font = GetFont(); | |
259 | if ( font.Ok() ) | |
260 | { | |
261 | SendMessage(hwndBtn, WM_SETFONT, | |
262 | (WPARAM)font.GetResourceHandle(), 0L); | |
263 | } | |
264 | ||
265 | m_subControls.Append((wxObject *)newId); | |
266 | } | |
267 | ||
268 | // Create a dummy radio control to end the group. | |
269 | (void)CreateWindowEx(0, RADIO_CLASS, "", WS_GROUP | RADIO_FLAGS, | |
270 | 0, 0, 0, 0, hwndParent, | |
271 | (HMENU)NewControlId(), wxGetInstance(), NULL); | |
272 | ||
273 | SetSelection(0); | |
274 | ||
275 | SetSize(x, y, width, height); | |
276 | ||
277 | return TRUE; | |
278 | } | |
279 | ||
280 | wxRadioBox::~wxRadioBox() | |
281 | { | |
282 | m_isBeingDeleted = TRUE; | |
283 | ||
284 | if (m_radioButtons) | |
285 | { | |
286 | int i; | |
287 | for (i = 0; i < m_noItems; i++) | |
288 | DestroyWindow((HWND) m_radioButtons[i]); | |
289 | delete[] m_radioButtons; | |
290 | } | |
291 | if (m_radioWidth) | |
292 | delete[] m_radioWidth; | |
293 | if (m_radioHeight) | |
294 | delete[] m_radioHeight; | |
295 | if (m_hWnd) | |
296 | ::DestroyWindow((HWND) m_hWnd); | |
297 | m_hWnd = 0; | |
298 | ||
299 | } | |
300 | ||
301 | wxString wxRadioBox::GetLabel(int item) const | |
302 | { | |
303 | GetWindowText((HWND)m_radioButtons[item], wxBuffer, 300); | |
304 | return wxString(wxBuffer); | |
305 | } | |
306 | ||
307 | void wxRadioBox::SetLabel(int item, const wxString& label) | |
308 | { | |
309 | m_radioWidth[item] = m_radioHeight[item] = -1; | |
310 | SetWindowText((HWND)m_radioButtons[item], (const char *)label); | |
311 | } | |
312 | ||
313 | void wxRadioBox::SetLabel(int item, wxBitmap *bitmap) | |
314 | { | |
315 | /* | |
316 | m_radioWidth[item] = bitmap->GetWidth() + FB_MARGIN; | |
317 | m_radioHeight[item] = bitmap->GetHeight() + FB_MARGIN; | |
318 | */ | |
319 | } | |
320 | ||
321 | int wxRadioBox::FindString(const wxString& s) const | |
322 | { | |
323 | int i; | |
324 | for (i = 0; i < m_noItems; i++) | |
325 | { | |
326 | GetWindowText((HWND) m_radioButtons[i], wxBuffer, 1000); | |
327 | if (s == wxBuffer) | |
328 | return i; | |
329 | } | |
330 | return -1; | |
331 | } | |
332 | ||
333 | void wxRadioBox::SetSelection(int N) | |
334 | { | |
335 | wxCHECK_RET( (N >= 0) && (N < m_noItems), "invalid radiobox index" ); | |
336 | ||
337 | // Following necessary for Win32s, because Win32s translate BM_SETCHECK | |
338 | if (m_selectedButton >= 0 && m_selectedButton < m_noItems) | |
339 | ::SendMessage((HWND) m_radioButtons[m_selectedButton], BM_SETCHECK, 0, 0L); | |
340 | ||
341 | ::SendMessage((HWND)m_radioButtons[N], BM_SETCHECK, 1, 0L); | |
342 | ::SetFocus((HWND)m_radioButtons[N]); | |
343 | ||
344 | m_selectedButton = N; | |
345 | } | |
346 | ||
347 | // Get single selection, for single choice list items | |
348 | int wxRadioBox::GetSelection() const | |
349 | { | |
350 | return m_selectedButton; | |
351 | } | |
352 | ||
353 | // Find string for position | |
354 | wxString wxRadioBox::GetString(int N) const | |
355 | { | |
356 | return wxGetWindowText(m_radioButtons[N]); | |
357 | } | |
358 | ||
359 | // Restored old code. | |
360 | void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
361 | { | |
362 | int currentX, currentY; | |
363 | GetPosition(¤tX, ¤tY); | |
364 | int xx = x; | |
365 | int yy = y; | |
366 | ||
367 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
368 | xx = currentX; | |
369 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
370 | yy = currentY; | |
371 | ||
372 | char buf[400]; | |
373 | ||
374 | int y_offset = yy; | |
375 | int x_offset = xx; | |
376 | int current_width, cyf; | |
377 | ||
378 | int cx1,cy1; | |
379 | wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont()); | |
380 | // Attempt to have a look coherent with other platforms: | |
381 | // We compute the biggest toggle dim, then we align all | |
382 | // items according this value. | |
383 | int maxWidth = -1; | |
384 | int maxHeight = -1; | |
385 | ||
386 | int i; | |
387 | for (i = 0 ; i < m_noItems; i++) | |
388 | { | |
389 | int eachWidth; | |
390 | int eachHeight; | |
391 | if (m_radioWidth[i]<0) | |
392 | { | |
393 | // It's a labelled toggle | |
394 | GetWindowText((HWND) m_radioButtons[i], buf, 300); | |
395 | GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont()); | |
396 | eachWidth = (int)(current_width + RADIO_SIZE); | |
397 | eachHeight = (int)((3*cyf)/2); | |
398 | } | |
399 | else | |
400 | { | |
401 | eachWidth = m_radioWidth[i]; | |
402 | eachHeight = m_radioHeight[i]; | |
403 | } | |
404 | if (maxWidth<eachWidth) maxWidth = eachWidth; | |
405 | if (maxHeight<eachHeight) maxHeight = eachHeight; | |
406 | } | |
407 | ||
408 | if (m_hWnd) | |
409 | { | |
410 | int totWidth; | |
411 | int totHeight; | |
412 | ||
413 | int nbHor = GetNumHor(), | |
414 | nbVer = GetNumVer(); | |
415 | ||
416 | // this formula works, but I don't know why. | |
417 | // Please, be sure what you do if you modify it!! | |
418 | if (m_radioWidth[0]<0) | |
419 | totHeight = (nbVer * maxHeight) + cy1/2; | |
420 | else | |
421 | totHeight = nbVer * (maxHeight+cy1/2); | |
422 | totWidth = nbHor * (maxWidth+cx1); | |
423 | ||
424 | #if (!CTL3D) | |
425 | // Requires a bigger group box in plain Windows | |
426 | MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+(3*cy1)/2,TRUE); | |
427 | #else | |
428 | MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+cy1,TRUE); | |
429 | #endif | |
430 | x_offset += cx1; | |
431 | y_offset += cy1; | |
432 | } | |
433 | ||
434 | #if (!CTL3D) | |
435 | y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label | |
436 | // JACS 2/12/93. CTL3D draws group label quite high. | |
437 | #endif | |
438 | int startX = x_offset; | |
439 | int startY = y_offset; | |
440 | ||
441 | for ( i = 0 ; i < m_noItems; i++) | |
442 | { | |
443 | // Bidimensional radio adjustment | |
444 | if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0? | |
445 | { | |
446 | if (m_windowStyle & wxRA_VERTICAL) | |
447 | { | |
448 | y_offset = startY; | |
449 | x_offset += maxWidth + cx1; | |
450 | } | |
451 | else | |
452 | { | |
453 | x_offset = startX; | |
454 | y_offset += maxHeight; | |
455 | if (m_radioWidth[0]>0) | |
456 | y_offset += cy1/2; | |
457 | } | |
458 | } | |
459 | int eachWidth; | |
460 | int eachHeight; | |
461 | if (m_radioWidth[i]<0) | |
462 | { | |
463 | // It's a labeled item | |
464 | GetWindowText((HWND) m_radioButtons[i], buf, 300); | |
465 | GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont()); | |
466 | ||
467 | // How do we find out radio button bitmap size!! | |
468 | // By adjusting them carefully, manually :-) | |
469 | eachWidth = (int)(current_width + RADIO_SIZE); | |
470 | eachHeight = (int)((3*cyf)/2); | |
471 | } | |
472 | else | |
473 | { | |
474 | eachWidth = m_radioWidth[i]; | |
475 | eachHeight = m_radioHeight[i]; | |
476 | } | |
477 | ||
478 | MoveWindow((HWND) m_radioButtons[i],x_offset,y_offset,eachWidth,eachHeight,TRUE); | |
479 | if (m_windowStyle & wxRA_SPECIFY_ROWS) | |
480 | { | |
481 | y_offset += maxHeight; | |
482 | if (m_radioWidth[0]>0) | |
483 | y_offset += cy1/2; | |
484 | } | |
485 | else | |
486 | x_offset += maxWidth + cx1; | |
487 | } | |
488 | } | |
489 | ||
490 | ||
491 | void wxRadioBox::GetSize(int *width, int *height) const | |
492 | { | |
493 | RECT rect; | |
494 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
495 | ||
496 | if (m_hWnd) | |
497 | wxFindMaxSize(m_hWnd, &rect); | |
498 | ||
499 | int i; | |
500 | for (i = 0; i < m_noItems; i++) | |
501 | wxFindMaxSize(m_radioButtons[i], &rect); | |
502 | ||
503 | *width = rect.right - rect.left; | |
504 | *height = rect.bottom - rect.top; | |
505 | } | |
506 | ||
507 | void wxRadioBox::GetPosition(int *x, int *y) const | |
508 | { | |
509 | wxWindow *parent = GetParent(); | |
510 | RECT rect; | |
511 | rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; | |
512 | ||
513 | int i; | |
514 | for (i = 0; i < m_noItems; i++) | |
515 | wxFindMaxSize(m_radioButtons[i], &rect); | |
516 | ||
517 | if (m_hWnd) | |
518 | wxFindMaxSize(m_hWnd, &rect); | |
519 | ||
520 | // Since we now have the absolute screen coords, | |
521 | // if there's a parent we must subtract its top left corner | |
522 | POINT point; | |
523 | point.x = rect.left; | |
524 | point.y = rect.top; | |
525 | if (parent) | |
526 | { | |
527 | ::ScreenToClient((HWND) parent->GetHWND(), &point); | |
528 | } | |
529 | // We may be faking the client origin. | |
530 | // So a window that's really at (0, 30) may appear | |
531 | // (to wxWin apps) to be at (0, 0). | |
532 | if (GetParent()) | |
533 | { | |
534 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
535 | point.x -= pt.x; | |
536 | point.y -= pt.y; | |
537 | } | |
538 | ||
539 | *x = point.x; | |
540 | *y = point.y; | |
541 | } | |
542 | ||
543 | wxString wxRadioBox::GetLabel() const | |
544 | { | |
545 | if (m_hWnd) | |
546 | { | |
547 | GetWindowText((HWND) m_hWnd, wxBuffer, 300); | |
548 | return wxString(wxBuffer); | |
549 | } | |
550 | else return wxString(""); | |
551 | } | |
552 | ||
553 | void wxRadioBox::SetLabel(const wxString& label) | |
554 | { | |
555 | if (m_hWnd) | |
556 | SetWindowText((HWND) m_hWnd, label); | |
557 | } | |
558 | ||
559 | void wxRadioBox::SetFocus() | |
560 | { | |
561 | if (m_noItems > 0) | |
562 | { | |
563 | if (m_selectedButton == -1) | |
564 | ::SetFocus((HWND) m_radioButtons[0]); | |
565 | else | |
566 | ::SetFocus((HWND) m_radioButtons[m_selectedButton]); | |
567 | } | |
568 | ||
569 | } | |
570 | ||
571 | bool wxRadioBox::Show(bool show) | |
572 | { | |
573 | m_isShown = show; | |
574 | int cshow; | |
575 | if (show) | |
576 | cshow = SW_SHOW; | |
577 | else | |
578 | cshow = SW_HIDE; | |
579 | if (m_hWnd) | |
580 | ShowWindow((HWND) m_hWnd, cshow); | |
581 | int i; | |
582 | for (i = 0; i < m_noItems; i++) | |
583 | ShowWindow((HWND) m_radioButtons[i], cshow); | |
584 | return TRUE; | |
585 | } | |
586 | ||
587 | // Enable a specific button | |
588 | void wxRadioBox::Enable(int item, bool enable) | |
589 | { | |
590 | if (item<0) | |
591 | wxWindow::Enable(enable); | |
592 | else if (item < m_noItems) | |
593 | ::EnableWindow((HWND) m_radioButtons[item], enable); | |
594 | } | |
595 | ||
596 | // Enable all controls | |
597 | void wxRadioBox::Enable(bool enable) | |
598 | { | |
599 | wxControl::Enable(enable); | |
600 | ||
601 | int i; | |
602 | for (i = 0; i < m_noItems; i++) | |
603 | ::EnableWindow((HWND) m_radioButtons[i], enable); | |
604 | } | |
605 | ||
606 | // Show a specific button | |
607 | void wxRadioBox::Show(int item, bool show) | |
608 | { | |
609 | if (item<0) | |
610 | wxRadioBox::Show(show); | |
611 | else if (item < m_noItems) | |
612 | { | |
613 | int cshow; | |
614 | if (show) | |
615 | cshow = SW_SHOW; | |
616 | else | |
617 | cshow = SW_HIDE; | |
618 | ShowWindow((HWND) m_radioButtons[item], cshow); | |
619 | } | |
620 | } | |
621 | ||
622 | WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, | |
623 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
624 | { | |
625 | #if wxUSE_CTL3D | |
626 | if ( m_useCtl3D ) | |
627 | { | |
628 | HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); | |
629 | return (WXHBRUSH) hbrush; | |
630 | } | |
631 | #endif | |
632 | ||
633 | if (GetParent()->GetTransparentBackground()) | |
634 | SetBkMode((HDC) pDC, TRANSPARENT); | |
635 | else | |
636 | SetBkMode((HDC) pDC, OPAQUE); | |
637 | ||
638 | ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); | |
639 | ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); | |
640 | ||
641 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); | |
642 | ||
643 | // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush | |
644 | // has a zero usage count. | |
645 | // backgroundBrush->RealizeResource(); | |
646 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); | |
647 | } | |
648 | ||
649 | // For single selection items only | |
650 | wxString wxRadioBox::GetStringSelection() const | |
651 | { | |
652 | wxString result; | |
653 | int sel = GetSelection(); | |
654 | if (sel > -1) | |
655 | result = GetString(sel); | |
656 | ||
657 | return result; | |
658 | } | |
659 | ||
660 | bool wxRadioBox::SetStringSelection(const wxString& s) | |
661 | { | |
662 | int sel = FindString (s); | |
663 | if (sel > -1) | |
664 | { | |
665 | SetSelection (sel); | |
666 | return TRUE; | |
667 | } | |
668 | else | |
669 | return FALSE; | |
670 | } | |
671 | ||
672 | bool wxRadioBox::ContainsHWND(WXHWND hWnd) const | |
673 | { | |
674 | int i; | |
675 | for (i = 0; i < Number(); i++) | |
676 | if (GetRadioButtons()[i] == hWnd) | |
677 | return TRUE; | |
678 | return FALSE; | |
679 | } | |
680 | ||
681 | void wxRadioBox::Command (wxCommandEvent & event) | |
682 | { | |
683 | SetSelection (event.m_commandInt); | |
684 | ProcessCommand (event); | |
685 | } | |
686 | ||
687 | long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | |
688 | { | |
689 | if (nMsg == WM_NCHITTEST) | |
690 | { | |
691 | int xPos = LOWORD(lParam); // horizontal position of cursor | |
692 | int yPos = HIWORD(lParam); // vertical position of cursor | |
693 | ||
694 | ScreenToClient(&xPos, &yPos); | |
695 | ||
696 | // Make sure you can drag by the top of the groupbox, but let | |
697 | // other (enclosed) controls get mouse events also | |
698 | if (yPos < 10) | |
699 | return (long)HTCLIENT; | |
700 | } | |
701 | ||
702 | return wxControl::MSWWindowProc(nMsg, wParam, lParam); | |
703 | } | |
704 | ||
705 | void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn) | |
706 | { | |
707 | HWND hwndBtn = (HWND)hWndBtn; | |
708 | ||
709 | if ( !s_wndprocRadioBtn ) | |
710 | s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC); | |
711 | // s_wndprocRadioBtn = (WNDPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC); | |
712 | ||
713 | // No GWL_USERDATA in Win16, so omit this subclassing. | |
714 | #ifdef __WIN32__ | |
715 | ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc); | |
716 | ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this); | |
717 | #endif | |
718 | } | |
719 | ||
720 | // --------------------------------------------------------------------------- | |
721 | // window proc for radio buttons | |
722 | // --------------------------------------------------------------------------- | |
723 | ||
724 | #ifdef __WIN32__ | |
725 | ||
726 | LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd, | |
727 | UINT msg, | |
728 | WPARAM wParam, | |
729 | LPARAM lParam) | |
730 | { | |
731 | bool processed = TRUE; | |
732 | if ( msg != WM_KEYDOWN ) | |
733 | processed = FALSE; | |
734 | ||
735 | if ( processed ) | |
736 | { | |
737 | wxRadioBox *radiobox = (wxRadioBox *)::GetWindowLong(hwnd, GWL_USERDATA); | |
738 | ||
739 | wxCHECK_MSG( radiobox, 0, "radio button without radio box?" ); | |
740 | ||
741 | int sel = radiobox->GetSelection(); | |
742 | ||
743 | switch ( wParam ) | |
744 | { | |
745 | case VK_UP: | |
746 | sel--; | |
747 | break; | |
748 | ||
749 | case VK_LEFT: | |
750 | sel -= radiobox->GetNumVer(); | |
751 | break; | |
752 | ||
753 | case VK_DOWN: | |
754 | sel++; | |
755 | break; | |
756 | ||
757 | case VK_RIGHT: | |
758 | sel += radiobox->GetNumVer(); | |
759 | break; | |
760 | ||
761 | case VK_TAB: | |
762 | { | |
763 | wxNavigationKeyEvent event; | |
764 | event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100)); | |
765 | event.SetWindowChange(FALSE); | |
766 | event.SetEventObject(radiobox); | |
767 | ||
768 | if ( radiobox->GetEventHandler()->ProcessEvent(event) ) | |
769 | return 0; | |
770 | } | |
771 | // fall through | |
772 | ||
773 | default: | |
774 | processed = FALSE; | |
775 | } | |
776 | ||
777 | if ( processed ) | |
778 | { | |
779 | if ( sel >= 0 && sel < radiobox->Number() ) | |
780 | radiobox->SetSelection(sel); | |
781 | } | |
782 | } | |
783 | ||
784 | if ( !processed ) | |
785 | return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, msg, wParam, lParam); | |
786 | else | |
787 | return 0; | |
788 | } | |
789 | #endif | |
790 |