]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ab1ce969 | 2 | // Name: src/msw/checkbox.cpp |
2bda0e17 KB |
3 | // Purpose: wxCheckBox |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
4438caf4 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
4438caf4 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
1e6feb95 VZ |
27 | #if wxUSE_CHECKBOX |
28 | ||
ab1ce969 WS |
29 | #include "wx/checkbox.h" |
30 | ||
2bda0e17 | 31 | #ifndef WX_PRECOMP |
4438caf4 | 32 | #include "wx/brush.h" |
f6bcfd97 BP |
33 | #include "wx/dcscreen.h" |
34 | #include "wx/settings.h" | |
2bda0e17 KB |
35 | #endif |
36 | ||
025f7d77 | 37 | #include "wx/msw/dc.h" // for wxDCTemp |
d4adf63b | 38 | #include "wx/renderer.h" |
533171c2 VZ |
39 | #include "wx/msw/uxtheme.h" |
40 | #include "wx/msw/private/button.h" | |
2bda0e17 | 41 | |
2f259810 VZ |
42 | // ---------------------------------------------------------------------------- |
43 | // constants | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
8941fa88 VZ |
46 | #ifndef BST_UNCHECKED |
47 | #define BST_UNCHECKED 0x0000 | |
48 | #endif | |
49 | ||
2b5f62a0 VZ |
50 | #ifndef BST_CHECKED |
51 | #define BST_CHECKED 0x0001 | |
52 | #endif | |
2bda0e17 | 53 | |
8941fa88 VZ |
54 | #ifndef BST_INDETERMINATE |
55 | #define BST_INDETERMINATE 0x0002 | |
56 | #endif | |
57 | ||
2f259810 VZ |
58 | #ifndef DT_HIDEPREFIX |
59 | #define DT_HIDEPREFIX 0x00100000 | |
60 | #endif | |
61 | ||
62 | #ifndef BP_CHECKBOX | |
63 | #define BP_CHECKBOX 3 | |
64 | #endif | |
65 | ||
66 | // these values are defined in tmschema.h (except the first one) | |
67 | enum | |
68 | { | |
69 | CBS_INVALID, | |
70 | CBS_UNCHECKEDNORMAL, | |
71 | CBS_UNCHECKEDHOT, | |
72 | CBS_UNCHECKEDPRESSED, | |
73 | CBS_UNCHECKEDDISABLED, | |
74 | CBS_CHECKEDNORMAL, | |
75 | CBS_CHECKEDHOT, | |
76 | CBS_CHECKEDPRESSED, | |
77 | CBS_CHECKEDDISABLED, | |
78 | CBS_MIXEDNORMAL, | |
79 | CBS_MIXEDHOT, | |
80 | CBS_MIXEDPRESSED, | |
81 | CBS_MIXEDDISABLED | |
82 | }; | |
83 | ||
84 | // these are our own | |
85 | enum | |
86 | { | |
87 | CBS_HOT_OFFSET = 1, | |
88 | CBS_PRESSED_OFFSET = 2, | |
89 | CBS_DISABLED_OFFSET = 3 | |
90 | }; | |
91 | ||
4438caf4 VZ |
92 | // ============================================================================ |
93 | // implementation | |
94 | // ============================================================================ | |
95 | ||
51741307 | 96 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
97 | WX_DEFINE_FLAGS( wxCheckBoxStyle ) |
98 | ||
3ff066a4 | 99 | wxBEGIN_FLAGS( wxCheckBoxStyle ) |
bc9fb572 JS |
100 | // new style border flags, we put them first to |
101 | // use them for streaming out | |
3ff066a4 SC |
102 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
103 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
104 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
105 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
106 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
107 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
02b7b6b0 | 108 | |
bc9fb572 | 109 | // old style border flags |
3ff066a4 SC |
110 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
111 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
112 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
113 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
114 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
8941fa88 | 115 | wxFLAGS_MEMBER(wxNO_BORDER) |
bc9fb572 JS |
116 | |
117 | // standard window styles | |
3ff066a4 SC |
118 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
119 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
120 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
121 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
8941fa88 | 122 | wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
123 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
124 | wxFLAGS_MEMBER(wxVSCROLL) | |
125 | wxFLAGS_MEMBER(wxHSCROLL) | |
bc9fb572 | 126 | |
3ff066a4 | 127 | wxEND_FLAGS( wxCheckBoxStyle ) |
bc9fb572 | 128 | |
51741307 SC |
129 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckBox, wxControl,"wx/checkbox.h") |
130 | ||
3ff066a4 | 131 | wxBEGIN_PROPERTIES_TABLE(wxCheckBox) |
93212fee | 132 | wxEVENT_PROPERTY( Click , wxEVT_COMMAND_CHECKBOX_CLICKED , wxCommandEvent ) |
51741307 | 133 | |
93212fee VZ |
134 | wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
135 | wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
136 | wxPROPERTY( Value ,bool, SetValue, GetValue, EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 137 | wxPROPERTY_FLAGS( WindowStyle , wxCheckBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 138 | wxEND_PROPERTIES_TABLE() |
2b5f62a0 | 139 | |
3ff066a4 SC |
140 | wxBEGIN_HANDLERS_TABLE(wxCheckBox) |
141 | wxEND_HANDLERS_TABLE() | |
51741307 | 142 | |
02b7b6b0 | 143 | wxCONSTRUCTOR_6( wxCheckBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
144 | #else |
145 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
146 | #endif | |
066f1b7a | 147 | |
066f1b7a | 148 | |
4438caf4 | 149 | // ---------------------------------------------------------------------------- |
2f259810 | 150 | // wxCheckBox creation |
4438caf4 VZ |
151 | // ---------------------------------------------------------------------------- |
152 | ||
2f259810 | 153 | void wxCheckBox::Init() |
2bda0e17 | 154 | { |
2f259810 VZ |
155 | m_state = wxCHK_UNCHECKED; |
156 | m_isPressed = | |
157 | m_isHot = false; | |
2bda0e17 KB |
158 | } |
159 | ||
11b6a93b VZ |
160 | bool wxCheckBox::Create(wxWindow *parent, |
161 | wxWindowID id, | |
162 | const wxString& label, | |
163 | const wxPoint& pos, | |
164 | const wxSize& size, long style, | |
165 | const wxValidator& validator, | |
166 | const wxString& name) | |
2bda0e17 | 167 | { |
2f259810 VZ |
168 | Init(); |
169 | ||
787a85c2 | 170 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) |
02b7b6b0 | 171 | return false; |
4438caf4 | 172 | |
8941fa88 VZ |
173 | long msStyle = WS_TABSTOP; |
174 | ||
175 | if ( style & wxCHK_3STATE ) | |
176 | { | |
2f259810 | 177 | msStyle |= BS_3STATE; |
8941fa88 VZ |
178 | } |
179 | else | |
180 | { | |
181 | wxASSERT_MSG( !Is3rdStateAllowedForUser(), | |
182 | wxT("Using wxCH_ALLOW_3RD_STATE_FOR_USER") | |
183 | wxT(" style flag for a 2-state checkbox is useless") ); | |
2f259810 | 184 | msStyle |= BS_CHECKBOX; |
8941fa88 VZ |
185 | } |
186 | ||
4438caf4 | 187 | if ( style & wxALIGN_RIGHT ) |
8941fa88 | 188 | { |
93212fee | 189 | msStyle |= BS_LEFTTEXT | BS_RIGHT; |
8941fa88 | 190 | } |
4438caf4 | 191 | |
533171c2 VZ |
192 | msStyle |= wxMSWButton::GetMultilineStyle(label); |
193 | ||
8912d7eb | 194 | return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0); |
2bda0e17 KB |
195 | } |
196 | ||
2f259810 VZ |
197 | // ---------------------------------------------------------------------------- |
198 | // wxCheckBox geometry | |
199 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 200 | |
f68586e5 | 201 | wxSize wxCheckBox::DoGetBestSize() const |
2bda0e17 | 202 | { |
f6bcfd97 | 203 | static int s_checkSize = 0; |
81d66cf3 | 204 | |
f6bcfd97 BP |
205 | if ( !s_checkSize ) |
206 | { | |
207 | wxScreenDC dc; | |
a756f210 | 208 | dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
2bda0e17 | 209 | |
fb1a41cd | 210 | s_checkSize = dc.GetCharHeight(); |
f6bcfd97 BP |
211 | } |
212 | ||
213 | wxString str = wxGetWindowText(GetHWND()); | |
214 | ||
215 | int wCheckbox, hCheckbox; | |
ab1ce969 | 216 | if ( !str.empty() ) |
4438caf4 | 217 | { |
533171c2 VZ |
218 | wxClientDC dc(wx_const_cast(wxCheckBox *, this)); |
219 | dc.SetFont(GetFont()); | |
220 | dc.GetMultiLineTextExtent(GetLabelText(str), &wCheckbox, &hCheckbox); | |
f6bcfd97 | 221 | wCheckbox += s_checkSize + GetCharWidth(); |
27fda0b6 | 222 | |
f6bcfd97 BP |
223 | if ( hCheckbox < s_checkSize ) |
224 | hCheckbox = s_checkSize; | |
4438caf4 VZ |
225 | } |
226 | else | |
2bda0e17 | 227 | { |
f6bcfd97 BP |
228 | wCheckbox = s_checkSize; |
229 | hCheckbox = s_checkSize; | |
2bda0e17 | 230 | } |
5a6371b9 JS |
231 | #ifdef __WXWINCE__ |
232 | hCheckbox += 1; | |
233 | #endif | |
2bda0e17 | 234 | |
31582e4e RD |
235 | wxSize best(wCheckbox, hCheckbox); |
236 | CacheBestSize(best); | |
237 | return best; | |
2bda0e17 KB |
238 | } |
239 | ||
2f259810 VZ |
240 | // ---------------------------------------------------------------------------- |
241 | // wxCheckBox operations | |
242 | // ---------------------------------------------------------------------------- | |
243 | ||
533171c2 VZ |
244 | void wxCheckBox::SetLabel(const wxString& label) |
245 | { | |
246 | wxMSWButton::UpdateMultilineStyle(GetHwnd(), label); | |
247 | ||
248 | wxCheckBoxBase::SetLabel(label); | |
249 | } | |
250 | ||
debe6624 | 251 | void wxCheckBox::SetValue(bool val) |
2bda0e17 | 252 | { |
c3732409 | 253 | Set3StateValue(val ? wxCHK_CHECKED : wxCHK_UNCHECKED); |
2bda0e17 KB |
254 | } |
255 | ||
bfc6fde4 | 256 | bool wxCheckBox::GetValue() const |
2bda0e17 | 257 | { |
c3732409 | 258 | return Get3StateValue() != wxCHK_UNCHECKED; |
2bda0e17 KB |
259 | } |
260 | ||
2b5f62a0 | 261 | void wxCheckBox::Command(wxCommandEvent& event) |
2bda0e17 | 262 | { |
8941fa88 VZ |
263 | int state = event.GetInt(); |
264 | wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED) | |
265 | || (state == wxCHK_UNDETERMINED), | |
266 | wxT("event.GetInt() returned an invalid checkbox state") ); | |
267 | ||
268 | Set3StateValue((wxCheckBoxState) state); | |
2b5f62a0 | 269 | ProcessCommand(event); |
2bda0e17 | 270 | } |
1e6feb95 | 271 | |
8941fa88 VZ |
272 | wxCOMPILE_TIME_ASSERT(wxCHK_UNCHECKED == BST_UNCHECKED |
273 | && wxCHK_CHECKED == BST_CHECKED | |
274 | && wxCHK_UNDETERMINED == BST_INDETERMINATE, EnumValuesIncorrect); | |
275 | ||
276 | void wxCheckBox::DoSet3StateValue(wxCheckBoxState state) | |
277 | { | |
2f259810 VZ |
278 | m_state = state; |
279 | if ( !IsOwnerDrawn() ) | |
280 | ::SendMessage(GetHwnd(), BM_SETCHECK, (WPARAM) state, 0); | |
281 | else // owner drawn buttons don't react to this message | |
282 | Refresh(); | |
8941fa88 VZ |
283 | } |
284 | ||
285 | wxCheckBoxState wxCheckBox::DoGet3StateValue() const | |
286 | { | |
2f259810 VZ |
287 | return m_state; |
288 | } | |
289 | ||
290 | bool wxCheckBox::MSWCommand(WXUINT cmd, WXWORD WXUNUSED(id)) | |
291 | { | |
292 | if ( cmd != BN_CLICKED && cmd != BN_DBLCLK ) | |
293 | return false; | |
294 | ||
295 | // first update the value so that user event handler gets the new checkbox | |
296 | // value | |
297 | ||
298 | // ownerdrawn buttons don't manage their state themselves unlike usual | |
299 | // auto checkboxes so do it ourselves in any case | |
300 | wxCheckBoxState state; | |
301 | if ( Is3rdStateAllowedForUser() ) | |
302 | { | |
303 | state = (wxCheckBoxState)((m_state + 1) % 3); | |
304 | } | |
305 | else // 2 state checkbox (at least from users point of view) | |
306 | { | |
307 | // note that wxCHK_UNDETERMINED also becomes unchecked when clicked | |
308 | state = m_state == wxCHK_UNCHECKED ? wxCHK_CHECKED : wxCHK_UNCHECKED; | |
309 | } | |
310 | ||
311 | DoSet3StateValue(state); | |
312 | ||
313 | ||
314 | // generate the event | |
315 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); | |
316 | ||
317 | event.SetInt(state); | |
318 | event.SetEventObject(this); | |
319 | ProcessCommand(event); | |
320 | ||
321 | return true; | |
322 | } | |
323 | ||
324 | // ---------------------------------------------------------------------------- | |
325 | // owner drawn checkboxes stuff | |
326 | // ---------------------------------------------------------------------------- | |
327 | ||
328 | bool wxCheckBox::SetForegroundColour(const wxColour& colour) | |
329 | { | |
330 | if ( !wxCheckBoxBase::SetForegroundColour(colour) ) | |
331 | return false; | |
332 | ||
333 | // the only way to change the checkbox foreground colour under Windows XP | |
334 | // is to owner draw it | |
335 | if ( wxUxThemeEngine::GetIfActive() ) | |
336 | MakeOwnerDrawn(colour.Ok()); | |
337 | ||
338 | return true; | |
339 | } | |
340 | ||
341 | bool wxCheckBox::IsOwnerDrawn() const | |
342 | { | |
343 | return | |
344 | (::GetWindowLong(GetHwnd(), GWL_STYLE) & BS_OWNERDRAW) == BS_OWNERDRAW; | |
345 | } | |
346 | ||
347 | void wxCheckBox::MakeOwnerDrawn(bool ownerDrawn) | |
348 | { | |
349 | long style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
350 | ||
351 | // note that BS_CHECKBOX & BS_OWNERDRAW != 0 so we can't operate on | |
352 | // them as on independent style bits | |
353 | if ( ownerDrawn ) | |
354 | { | |
355 | style &= ~(BS_CHECKBOX | BS_3STATE); | |
356 | style |= BS_OWNERDRAW; | |
357 | ||
358 | Connect(wxEVT_ENTER_WINDOW, | |
359 | wxMouseEventHandler(wxCheckBox::OnMouseEnterOrLeave)); | |
360 | Connect(wxEVT_LEAVE_WINDOW, | |
361 | wxMouseEventHandler(wxCheckBox::OnMouseEnterOrLeave)); | |
362 | Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(wxCheckBox::OnMouseLeft)); | |
363 | Connect(wxEVT_LEFT_UP, wxMouseEventHandler(wxCheckBox::OnMouseLeft)); | |
364 | Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(wxCheckBox::OnFocus)); | |
365 | Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(wxCheckBox::OnFocus)); | |
366 | } | |
367 | else // reset to default colour | |
368 | { | |
369 | style &= ~BS_OWNERDRAW; | |
370 | style |= HasFlag(wxCHK_3STATE) ? BS_3STATE : BS_CHECKBOX; | |
371 | ||
372 | Disconnect(wxEVT_ENTER_WINDOW, | |
373 | wxMouseEventHandler(wxCheckBox::OnMouseEnterOrLeave)); | |
374 | Disconnect(wxEVT_LEAVE_WINDOW, | |
375 | wxMouseEventHandler(wxCheckBox::OnMouseEnterOrLeave)); | |
376 | Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(wxCheckBox::OnMouseLeft)); | |
377 | Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(wxCheckBox::OnMouseLeft)); | |
378 | Disconnect(wxEVT_SET_FOCUS, wxFocusEventHandler(wxCheckBox::OnFocus)); | |
379 | Disconnect(wxEVT_KILL_FOCUS, wxFocusEventHandler(wxCheckBox::OnFocus)); | |
380 | } | |
381 | ||
382 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style); | |
b3433ee7 VZ |
383 | |
384 | if ( !ownerDrawn ) | |
385 | { | |
386 | // ensure that controls state is consistent with internal state | |
387 | DoSet3StateValue(m_state); | |
388 | } | |
2f259810 VZ |
389 | } |
390 | ||
391 | void wxCheckBox::OnMouseEnterOrLeave(wxMouseEvent& event) | |
392 | { | |
393 | m_isHot = event.GetEventType() == wxEVT_ENTER_WINDOW; | |
394 | if ( !m_isHot ) | |
395 | m_isPressed = false; | |
396 | ||
397 | Refresh(); | |
398 | ||
399 | event.Skip(); | |
400 | } | |
401 | ||
402 | void wxCheckBox::OnMouseLeft(wxMouseEvent& event) | |
403 | { | |
404 | // TODO: we should capture the mouse here to be notified about left up | |
405 | // event but this interferes with BN_CLICKED generation so if we | |
406 | // want to do this we'd need to generate them ourselves | |
407 | m_isPressed = event.GetEventType() == wxEVT_LEFT_DOWN; | |
408 | Refresh(); | |
409 | ||
410 | event.Skip(); | |
411 | } | |
412 | ||
413 | void wxCheckBox::OnFocus(wxFocusEvent& event) | |
414 | { | |
415 | Refresh(); | |
416 | ||
417 | event.Skip(); | |
418 | } | |
419 | ||
420 | bool wxCheckBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) | |
421 | { | |
422 | DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)item; | |
423 | ||
424 | if ( !IsOwnerDrawn() || dis->CtlType != ODT_BUTTON ) | |
425 | return wxCheckBoxBase::MSWOnDraw(item); | |
426 | ||
427 | // calculate the rectangles for the check mark itself and the label | |
428 | HDC hdc = dis->hDC; | |
429 | RECT& rect = dis->rcItem; | |
430 | RECT rectCheck, | |
431 | rectLabel; | |
432 | rectCheck.top = | |
433 | rectLabel.top = rect.top; | |
434 | rectCheck.bottom = | |
435 | rectLabel.bottom = rect.bottom; | |
436 | const int checkSize = GetBestSize().y; | |
437 | const int MARGIN = 3; | |
438 | ||
439 | const bool isRightAligned = HasFlag(wxALIGN_RIGHT); | |
440 | if ( isRightAligned ) | |
441 | { | |
442 | rectCheck.right = rect.right; | |
443 | rectCheck.left = rectCheck.right - checkSize; | |
444 | ||
445 | rectLabel.right = rectCheck.left - MARGIN; | |
446 | rectLabel.left = rect.left; | |
447 | } | |
448 | else // normal, left-aligned checkbox | |
449 | { | |
450 | rectCheck.left = rect.left; | |
451 | rectCheck.right = rectCheck.left + checkSize; | |
452 | ||
453 | rectLabel.left = rectCheck.right + MARGIN; | |
454 | rectLabel.right = rect.right; | |
455 | } | |
456 | ||
457 | // show we draw a focus rect? | |
458 | const bool isFocused = m_isPressed || FindFocus() == this; | |
459 | ||
460 | ||
d4adf63b VZ |
461 | // draw the checkbox itself |
462 | wxDCTemp dc(hdc); | |
2f259810 | 463 | |
d4adf63b | 464 | int flags = 0; |
2f259810 | 465 | if ( !IsEnabled() ) |
d4adf63b | 466 | flags |= wxCONTROL_DISABLED; |
2f259810 VZ |
467 | switch ( Get3StateValue() ) |
468 | { | |
469 | case wxCHK_CHECKED: | |
d4adf63b | 470 | flags |= wxCONTROL_CHECKED; |
2f259810 VZ |
471 | break; |
472 | ||
473 | case wxCHK_UNDETERMINED: | |
d4adf63b | 474 | flags |= wxCONTROL_PRESSED; |
2f259810 VZ |
475 | break; |
476 | ||
477 | default: | |
478 | wxFAIL_MSG( _T("unexpected Get3StateValue() return value") ); | |
479 | // fall through | |
480 | ||
481 | case wxCHK_UNCHECKED: | |
482 | // no extra styles needed | |
483 | break; | |
484 | } | |
485 | ||
486 | if ( wxFindWindowAtPoint(wxGetMousePosition()) == this ) | |
d4adf63b | 487 | flags |= wxCONTROL_CURRENT; |
2f259810 | 488 | |
d4adf63b VZ |
489 | wxRendererNative::Get(). |
490 | DrawCheckBox(this, dc, wxRectFromRECT(rectCheck), flags); | |
2f259810 VZ |
491 | |
492 | // draw the text | |
493 | const wxString& label = GetLabel(); | |
494 | ||
495 | // first we need to measure it | |
496 | UINT fmt = DT_NOCLIP; | |
497 | ||
498 | // drawing underlying doesn't look well with focus rect (and the native | |
499 | // control doesn't do it) | |
500 | if ( isFocused ) | |
501 | fmt |= DT_HIDEPREFIX; | |
502 | if ( isRightAligned ) | |
503 | fmt |= DT_RIGHT; | |
504 | // TODO: also use DT_HIDEPREFIX if the system is configured so | |
505 | ||
506 | // we need to get the label real size first if we have to draw a focus rect | |
507 | // around it | |
508 | if ( isFocused ) | |
509 | { | |
e0a050e3 | 510 | if ( !::DrawText(hdc, label.wx_str(), label.length(), &rectLabel, |
2f259810 VZ |
511 | fmt | DT_CALCRECT) ) |
512 | { | |
513 | wxLogLastError(_T("DrawText(DT_CALCRECT)")); | |
514 | } | |
515 | } | |
516 | ||
517 | if ( !IsEnabled() ) | |
518 | { | |
519 | ::SetTextColor(hdc, ::GetSysColor(COLOR_GRAYTEXT)); | |
520 | } | |
521 | ||
e0a050e3 | 522 | if ( !::DrawText(hdc, label.wx_str(), label.length(), &rectLabel, fmt) ) |
2f259810 VZ |
523 | { |
524 | wxLogLastError(_T("DrawText()")); | |
525 | } | |
526 | ||
527 | // finally draw the focus | |
528 | if ( isFocused ) | |
529 | { | |
530 | rectLabel.left--; | |
531 | rectLabel.right++; | |
532 | if ( !::DrawFocusRect(hdc, &rectLabel) ) | |
533 | { | |
534 | wxLogLastError(_T("DrawFocusRect()")); | |
535 | } | |
536 | } | |
537 | ||
538 | return true; | |
8941fa88 VZ |
539 | } |
540 | ||
1e6feb95 | 541 | #endif // wxUSE_CHECKBOX |