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