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