]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: checkbox.cpp | |
3 | // Purpose: wxCheckBox | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
4438caf4 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
4438caf4 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
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 | ||
31 | #ifndef WX_PRECOMP | |
4438caf4 VZ |
32 | #include "wx/checkbox.h" |
33 | #include "wx/brush.h" | |
2bda0e17 KB |
34 | #endif |
35 | ||
36 | #include "wx/msw/private.h" | |
37 | ||
4438caf4 VZ |
38 | // ---------------------------------------------------------------------------- |
39 | // macros | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
11b6a93b VZ |
42 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) |
43 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
2bda0e17 | 44 | |
4438caf4 VZ |
45 | // ============================================================================ |
46 | // implementation | |
47 | // ============================================================================ | |
48 | ||
49 | // ---------------------------------------------------------------------------- | |
50 | // wxCheckBox | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
debe6624 | 53 | bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) |
2bda0e17 | 54 | { |
4438caf4 VZ |
55 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); |
56 | event.SetInt(GetValue()); | |
57 | event.SetEventObject(this); | |
58 | ProcessCommand(event); | |
59 | return TRUE; | |
2bda0e17 KB |
60 | } |
61 | ||
62 | // Single check box item | |
11b6a93b VZ |
63 | bool wxCheckBox::Create(wxWindow *parent, |
64 | wxWindowID id, | |
65 | const wxString& label, | |
66 | const wxPoint& pos, | |
67 | const wxSize& size, long style, | |
68 | const wxValidator& validator, | |
69 | const wxString& name) | |
2bda0e17 | 70 | { |
4438caf4 | 71 | SetName(name); |
11b6a93b | 72 | #if wxUSE_VALIDATORS |
4438caf4 | 73 | SetValidator(validator); |
11b6a93b | 74 | #endif // wxUSE_VALIDATORS |
4438caf4 VZ |
75 | if (parent) parent->AddChild(this); |
76 | ||
77 | SetBackgroundColour(parent->GetBackgroundColour()) ; | |
78 | SetForegroundColour(parent->GetForegroundColour()) ; | |
79 | ||
80 | m_windowStyle = style; | |
81 | ||
b94ae1ea VZ |
82 | // VZ: disabling this ugliness which completely breaks checkboxes in wxGrid |
83 | // whoever did it, please tell me where and how does the checkbox fail | |
84 | // to appear | |
85 | #if 0 | |
4438caf4 | 86 | wxString Label = label; |
223d09f6 KB |
87 | if (Label == wxT("")) |
88 | Label = wxT(" "); // Apparently needed or checkbox won't show | |
b94ae1ea | 89 | #endif // 0 |
4438caf4 VZ |
90 | |
91 | if ( id == -1 ) | |
92 | m_windowId = NewControlId(); | |
93 | else | |
94 | m_windowId = id; | |
95 | ||
96 | int x = pos.x; | |
97 | int y = pos.y; | |
98 | int width = size.x; | |
99 | int height = size.y; | |
100 | ||
101 | long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD | WS_VISIBLE; | |
102 | if ( style & wxALIGN_RIGHT ) | |
103 | msStyle |= BS_LEFTTEXT; | |
104 | ||
105 | // We perhaps have different concepts of 3D here - a 3D border, | |
106 | // versus a 3D button. | |
107 | // So we only wish to give a border if this is specified | |
108 | // in the style. | |
109 | bool want3D; | |
110 | WXDWORD exStyle = Determine3DEffects(0, &want3D) ; | |
111 | ||
112 | // Even with extended styles, need to combine with WS_BORDER | |
113 | // for them to look right. | |
114 | /* | |
115 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) | |
116 | msStyle |= WS_BORDER; | |
117 | */ | |
118 | ||
b94ae1ea | 119 | m_hWnd = (WXHWND)CreateWindowEx(exStyle, wxT("BUTTON"), label, |
4438caf4 VZ |
120 | msStyle, |
121 | 0, 0, 0, 0, | |
122 | (HWND)parent->GetHWND(), (HMENU)m_windowId, | |
123 | wxGetInstance(), NULL); | |
2bda0e17 | 124 | |
1f112209 | 125 | #if wxUSE_CTL3D |
4438caf4 VZ |
126 | if (want3D) |
127 | { | |
128 | Ctl3dSubclassCtl(GetHwnd()); | |
129 | m_useCtl3D = TRUE; | |
130 | } | |
2bda0e17 KB |
131 | #endif |
132 | ||
4438caf4 VZ |
133 | // Subclass again for purposes of dialog editing mode |
134 | SubclassWin(m_hWnd); | |
2bda0e17 | 135 | |
4438caf4 | 136 | SetFont(parent->GetFont()); |
2bda0e17 | 137 | |
4438caf4 VZ |
138 | SetSize(x, y, width, height); |
139 | ||
140 | return TRUE; | |
2bda0e17 KB |
141 | } |
142 | ||
143 | void wxCheckBox::SetLabel(const wxString& label) | |
144 | { | |
4438caf4 | 145 | SetWindowText(GetHwnd(), label); |
2bda0e17 KB |
146 | } |
147 | ||
f68586e5 | 148 | wxSize wxCheckBox::DoGetBestSize() const |
2bda0e17 | 149 | { |
4438caf4 | 150 | int wCheckbox, hCheckbox; |
81d66cf3 | 151 | |
4438caf4 | 152 | wxString str = wxGetWindowText(GetHWND()); |
2bda0e17 | 153 | |
4438caf4 VZ |
154 | if ( !str.IsEmpty() ) |
155 | { | |
156 | GetTextExtent(str, &wCheckbox, &hCheckbox); | |
157 | wCheckbox += RADIO_SIZE; | |
27fda0b6 | 158 | |
4438caf4 VZ |
159 | if ( hCheckbox < RADIO_SIZE ) |
160 | hCheckbox = RADIO_SIZE; | |
161 | } | |
162 | else | |
2bda0e17 | 163 | { |
4438caf4 VZ |
164 | wCheckbox = RADIO_SIZE; |
165 | hCheckbox = RADIO_SIZE; | |
2bda0e17 KB |
166 | } |
167 | ||
4438caf4 | 168 | return wxSize(wCheckbox, hCheckbox); |
2bda0e17 KB |
169 | } |
170 | ||
debe6624 | 171 | void wxCheckBox::SetValue(bool val) |
2bda0e17 | 172 | { |
4438caf4 | 173 | SendMessage(GetHwnd(), BM_SETCHECK, val, 0); |
2bda0e17 KB |
174 | } |
175 | ||
2432b92d JS |
176 | #ifndef BST_CHECKED |
177 | #define BST_CHECKED 0x0001 | |
178 | #endif | |
179 | ||
bfc6fde4 | 180 | bool wxCheckBox::GetValue() const |
2bda0e17 KB |
181 | { |
182 | #ifdef __WIN32__ | |
4438caf4 | 183 | return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED); |
2bda0e17 | 184 | #else |
4438caf4 | 185 | return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x003); |
2bda0e17 KB |
186 | #endif |
187 | } | |
188 | ||
2bda0e17 KB |
189 | void wxCheckBox::Command (wxCommandEvent & event) |
190 | { | |
191 | SetValue ((event.GetInt() != 0)); | |
192 | ProcessCommand (event); | |
193 | } | |
194 | ||
4438caf4 VZ |
195 | // ---------------------------------------------------------------------------- |
196 | // wxBitmapCheckBox | |
197 | // ---------------------------------------------------------------------------- | |
198 | ||
debe6624 | 199 | bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label, |
2bda0e17 | 200 | const wxPoint& pos, |
debe6624 | 201 | const wxSize& size, long style, |
2bda0e17 KB |
202 | const wxValidator& validator, |
203 | const wxString& name) | |
204 | { | |
205 | SetName(name); | |
11b6a93b | 206 | #if wxUSE_VALIDATORS |
2bda0e17 | 207 | SetValidator(validator); |
11b6a93b | 208 | #endif // wxUSE_VALIDATORS |
2bda0e17 KB |
209 | if (parent) parent->AddChild(this); |
210 | ||
fd71308f JS |
211 | SetBackgroundColour(parent->GetBackgroundColour()) ; |
212 | SetForegroundColour(parent->GetForegroundColour()) ; | |
2bda0e17 KB |
213 | m_windowStyle = style; |
214 | ||
4438caf4 VZ |
215 | if ( id == -1 ) |
216 | m_windowId = NewControlId(); | |
217 | else | |
218 | m_windowId = id; | |
2bda0e17 KB |
219 | |
220 | int x = pos.x; | |
221 | int y = pos.y; | |
222 | int width = size.x; | |
223 | int height = size.y; | |
224 | ||
225 | checkWidth = -1 ; | |
226 | checkHeight = -1 ; | |
227 | long msStyle = CHECK_FLAGS; | |
228 | ||
223d09f6 | 229 | HWND wx_button = CreateWindowEx(MakeExtendedStyle(m_windowStyle), CHECK_CLASS, wxT("toggle"), |
2bda0e17 KB |
230 | msStyle, |
231 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, | |
232 | wxGetInstance(), NULL); | |
233 | ||
1f112209 | 234 | #if wxUSE_CTL3D |
2bda0e17 KB |
235 | if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) |
236 | { | |
237 | Ctl3dSubclassCtl(wx_button); | |
4438caf4 | 238 | m_useCtl3D = TRUE; |
2bda0e17 KB |
239 | } |
240 | #endif | |
241 | ||
242 | m_hWnd = (WXHWND)wx_button; | |
243 | ||
244 | // Subclass again for purposes of dialog editing mode | |
245 | SubclassWin((WXHWND)wx_button); | |
246 | ||
2bda0e17 KB |
247 | SetSize(x, y, width, height); |
248 | ||
249 | ShowWindow(wx_button, SW_SHOW); | |
4438caf4 | 250 | |
2bda0e17 KB |
251 | return TRUE; |
252 | } | |
253 | ||
acbd13a3 | 254 | void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap) |
2bda0e17 | 255 | { |
223d09f6 | 256 | wxFAIL_MSG(wxT("not implemented")); |
2bda0e17 | 257 | } |