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