]> git.saurik.com Git - wxWidgets.git/blame - src/msw/checkbox.cpp
OS/2 updates for statusbar processing
[wxWidgets.git] / src / msw / checkbox.cpp
CommitLineData
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"
f6bcfd97
BP
34 #include "wx/dcscreen.h"
35 #include "wx/settings.h"
2bda0e17
KB
36#endif
37
38#include "wx/msw/private.h"
39
4438caf4
VZ
40// ----------------------------------------------------------------------------
41// macros
42// ----------------------------------------------------------------------------
43
11b6a93b
VZ
44IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
45IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
2bda0e17 46
4438caf4
VZ
47// ============================================================================
48// implementation
49// ============================================================================
50
51// ----------------------------------------------------------------------------
52// wxCheckBox
53// ----------------------------------------------------------------------------
54
debe6624 55bool 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
11b6a93b
VZ
65bool 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)
2bda0e17 72{
4438caf4 73 SetName(name);
11b6a93b 74#if wxUSE_VALIDATORS
4438caf4 75 SetValidator(validator);
11b6a93b 76#endif // wxUSE_VALIDATORS
4438caf4
VZ
77 if (parent) parent->AddChild(this);
78
79 SetBackgroundColour(parent->GetBackgroundColour()) ;
80 SetForegroundColour(parent->GetForegroundColour()) ;
81
82 m_windowStyle = style;
83
b94ae1ea
VZ
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
4438caf4 88 wxString Label = label;
223d09f6
KB
89 if (Label == wxT(""))
90 Label = wxT(" "); // Apparently needed or checkbox won't show
b94ae1ea 91#endif // 0
4438caf4
VZ
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
b94ae1ea 121 m_hWnd = (WXHWND)CreateWindowEx(exStyle, wxT("BUTTON"), label,
4438caf4
VZ
122 msStyle,
123 0, 0, 0, 0,
124 (HWND)parent->GetHWND(), (HMENU)m_windowId,
125 wxGetInstance(), NULL);
2bda0e17 126
1f112209 127#if wxUSE_CTL3D
4438caf4
VZ
128 if (want3D)
129 {
130 Ctl3dSubclassCtl(GetHwnd());
131 m_useCtl3D = TRUE;
132 }
2bda0e17
KB
133#endif
134
4438caf4
VZ
135 // Subclass again for purposes of dialog editing mode
136 SubclassWin(m_hWnd);
2bda0e17 137
4438caf4 138 SetFont(parent->GetFont());
2bda0e17 139
4438caf4
VZ
140 SetSize(x, y, width, height);
141
142 return TRUE;
2bda0e17
KB
143}
144
145void wxCheckBox::SetLabel(const wxString& label)
146{
f6bcfd97 147 SetWindowText(GetHwnd(), label);
2bda0e17
KB
148}
149
f68586e5 150wxSize wxCheckBox::DoGetBestSize() const
2bda0e17 151{
f6bcfd97 152 static int s_checkSize = 0;
81d66cf3 153
f6bcfd97
BP
154 if ( !s_checkSize )
155 {
156 wxScreenDC dc;
157 dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2bda0e17 158
f6bcfd97
BP
159 // the height of a standard button in the dialog units is 8,
160 // translate this to pixels (as one dialog unit is precisely equal to
161 // 8 character heights, it's just the char height)
162 s_checkSize = dc.GetCharHeight();
163 }
164
165 wxString str = wxGetWindowText(GetHWND());
166
167 int wCheckbox, hCheckbox;
4438caf4
VZ
168 if ( !str.IsEmpty() )
169 {
170 GetTextExtent(str, &wCheckbox, &hCheckbox);
f6bcfd97 171 wCheckbox += s_checkSize + GetCharWidth();
27fda0b6 172
f6bcfd97
BP
173 if ( hCheckbox < s_checkSize )
174 hCheckbox = s_checkSize;
4438caf4
VZ
175 }
176 else
2bda0e17 177 {
f6bcfd97
BP
178 wCheckbox = s_checkSize;
179 hCheckbox = s_checkSize;
2bda0e17
KB
180 }
181
4438caf4 182 return wxSize(wCheckbox, hCheckbox);
2bda0e17
KB
183}
184
debe6624 185void wxCheckBox::SetValue(bool val)
2bda0e17 186{
4438caf4 187 SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
2bda0e17
KB
188}
189
2432b92d
JS
190#ifndef BST_CHECKED
191#define BST_CHECKED 0x0001
192#endif
193
bfc6fde4 194bool wxCheckBox::GetValue() const
2bda0e17
KB
195{
196#ifdef __WIN32__
4438caf4 197 return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED);
2bda0e17 198#else
f6bcfd97 199 return ((0x001 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x001);
2bda0e17
KB
200#endif
201}
202
2bda0e17
KB
203void wxCheckBox::Command (wxCommandEvent & event)
204{
205 SetValue ((event.GetInt() != 0));
206 ProcessCommand (event);
207}
208
4438caf4
VZ
209// ----------------------------------------------------------------------------
210// wxBitmapCheckBox
211// ----------------------------------------------------------------------------
212
debe6624 213bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
2bda0e17 214 const wxPoint& pos,
debe6624 215 const wxSize& size, long style,
2bda0e17
KB
216 const wxValidator& validator,
217 const wxString& name)
218{
219 SetName(name);
11b6a93b 220#if wxUSE_VALIDATORS
2bda0e17 221 SetValidator(validator);
11b6a93b 222#endif // wxUSE_VALIDATORS
2bda0e17
KB
223 if (parent) parent->AddChild(this);
224
fd71308f
JS
225 SetBackgroundColour(parent->GetBackgroundColour()) ;
226 SetForegroundColour(parent->GetForegroundColour()) ;
2bda0e17
KB
227 m_windowStyle = style;
228
4438caf4
VZ
229 if ( id == -1 )
230 m_windowId = NewControlId();
231 else
232 m_windowId = id;
2bda0e17
KB
233
234 int x = pos.x;
235 int y = pos.y;
236 int width = size.x;
237 int height = size.y;
238
239 checkWidth = -1 ;
240 checkHeight = -1 ;
241 long msStyle = CHECK_FLAGS;
242
223d09f6 243 HWND wx_button = CreateWindowEx(MakeExtendedStyle(m_windowStyle), CHECK_CLASS, wxT("toggle"),
2bda0e17
KB
244 msStyle,
245 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
246 wxGetInstance(), NULL);
247
1f112209 248#if wxUSE_CTL3D
2bda0e17
KB
249 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
250 {
251 Ctl3dSubclassCtl(wx_button);
4438caf4 252 m_useCtl3D = TRUE;
2bda0e17
KB
253 }
254#endif
255
256 m_hWnd = (WXHWND)wx_button;
257
258 // Subclass again for purposes of dialog editing mode
259 SubclassWin((WXHWND)wx_button);
260
2bda0e17
KB
261 SetSize(x, y, width, height);
262
263 ShowWindow(wx_button, SW_SHOW);
4438caf4 264
2bda0e17
KB
265 return TRUE;
266}
267
acbd13a3 268void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
2bda0e17 269{
223d09f6 270 wxFAIL_MSG(wxT("not implemented"));
2bda0e17 271}