]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
2b5f62a0 | 2 | // Name: 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 JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
4438caf4 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
4438caf4 | 21 | #pragma implementation "checkbox.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
4438caf4 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_CHECKBOX |
32 | ||
2bda0e17 | 33 | #ifndef WX_PRECOMP |
4438caf4 VZ |
34 | #include "wx/checkbox.h" |
35 | #include "wx/brush.h" | |
f6bcfd97 BP |
36 | #include "wx/dcscreen.h" |
37 | #include "wx/settings.h" | |
2bda0e17 KB |
38 | #endif |
39 | ||
40 | #include "wx/msw/private.h" | |
41 | ||
2b5f62a0 VZ |
42 | #ifndef BST_CHECKED |
43 | #define BST_CHECKED 0x0001 | |
44 | #endif | |
2bda0e17 | 45 | |
4438caf4 VZ |
46 | // ============================================================================ |
47 | // implementation | |
48 | // ============================================================================ | |
49 | ||
51741307 SC |
50 | #if wxUSE_EXTENDED_RTTI |
51 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckBox, wxControl,"wx/checkbox.h") | |
52 | ||
53 | WX_BEGIN_PROPERTIES_TABLE(wxCheckBox) | |
54 | WX_DELEGATE( OnClick , wxEVT_COMMAND_CHECKBOX_CLICKED , wxCommandEvent ) | |
55 | ||
067e9be6 SC |
56 | WX_PROPERTY( Font , wxFont , SetFont , GetFont , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
57 | WX_PROPERTY( Label,wxString, SetLabel, GetLabel, wxEmptyString , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
58 | WX_PROPERTY( Value ,bool, SetValue, GetValue, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
51741307 | 59 | WX_END_PROPERTIES_TABLE() |
2b5f62a0 | 60 | |
51741307 SC |
61 | WX_BEGIN_HANDLERS_TABLE(wxCheckBox) |
62 | WX_END_HANDLERS_TABLE() | |
63 | ||
64 | WX_CONSTRUCTOR_6( wxCheckBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) | |
65 | #else | |
66 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
67 | #endif | |
066f1b7a | 68 | |
066f1b7a | 69 | |
4438caf4 VZ |
70 | // ---------------------------------------------------------------------------- |
71 | // wxCheckBox | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
debe6624 | 74 | bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) |
2bda0e17 | 75 | { |
4438caf4 VZ |
76 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); |
77 | event.SetInt(GetValue()); | |
78 | event.SetEventObject(this); | |
79 | ProcessCommand(event); | |
80 | return TRUE; | |
2bda0e17 KB |
81 | } |
82 | ||
11b6a93b VZ |
83 | bool wxCheckBox::Create(wxWindow *parent, |
84 | wxWindowID id, | |
85 | const wxString& label, | |
86 | const wxPoint& pos, | |
87 | const wxSize& size, long style, | |
88 | const wxValidator& validator, | |
89 | const wxString& name) | |
2bda0e17 | 90 | { |
787a85c2 | 91 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) |
8912d7eb | 92 | return FALSE; |
4438caf4 | 93 | |
8912d7eb | 94 | long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP; |
4438caf4 VZ |
95 | if ( style & wxALIGN_RIGHT ) |
96 | msStyle |= BS_LEFTTEXT; | |
97 | ||
8912d7eb | 98 | return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0); |
2bda0e17 KB |
99 | } |
100 | ||
101 | void wxCheckBox::SetLabel(const wxString& label) | |
102 | { | |
f6bcfd97 | 103 | SetWindowText(GetHwnd(), label); |
2bda0e17 KB |
104 | } |
105 | ||
f68586e5 | 106 | wxSize wxCheckBox::DoGetBestSize() const |
2bda0e17 | 107 | { |
f6bcfd97 | 108 | static int s_checkSize = 0; |
81d66cf3 | 109 | |
f6bcfd97 BP |
110 | if ( !s_checkSize ) |
111 | { | |
112 | wxScreenDC dc; | |
a756f210 | 113 | dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
2bda0e17 | 114 | |
fb1a41cd | 115 | s_checkSize = dc.GetCharHeight(); |
f6bcfd97 BP |
116 | } |
117 | ||
118 | wxString str = wxGetWindowText(GetHWND()); | |
119 | ||
120 | int wCheckbox, hCheckbox; | |
4438caf4 VZ |
121 | if ( !str.IsEmpty() ) |
122 | { | |
123 | GetTextExtent(str, &wCheckbox, &hCheckbox); | |
f6bcfd97 | 124 | wCheckbox += s_checkSize + GetCharWidth(); |
27fda0b6 | 125 | |
f6bcfd97 BP |
126 | if ( hCheckbox < s_checkSize ) |
127 | hCheckbox = s_checkSize; | |
4438caf4 VZ |
128 | } |
129 | else | |
2bda0e17 | 130 | { |
f6bcfd97 BP |
131 | wCheckbox = s_checkSize; |
132 | hCheckbox = s_checkSize; | |
2bda0e17 KB |
133 | } |
134 | ||
4438caf4 | 135 | return wxSize(wCheckbox, hCheckbox); |
2bda0e17 KB |
136 | } |
137 | ||
debe6624 | 138 | void wxCheckBox::SetValue(bool val) |
2bda0e17 | 139 | { |
4438caf4 | 140 | SendMessage(GetHwnd(), BM_SETCHECK, val, 0); |
2bda0e17 KB |
141 | } |
142 | ||
bfc6fde4 | 143 | bool wxCheckBox::GetValue() const |
2bda0e17 | 144 | { |
2b5f62a0 | 145 | return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) & BST_CHECKED) != 0; |
2bda0e17 KB |
146 | } |
147 | ||
2b5f62a0 | 148 | void wxCheckBox::Command(wxCommandEvent& event) |
2bda0e17 | 149 | { |
2b5f62a0 VZ |
150 | SetValue(event.GetInt() != 0); |
151 | ProcessCommand(event); | |
2bda0e17 | 152 | } |
1e6feb95 VZ |
153 | |
154 | #endif // wxUSE_CHECKBOX |