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