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