]> git.saurik.com Git - wxWidgets.git/blame - src/msw/checkbox.cpp
added xpmdecod.cpp
[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
1fb45475 159 s_checkSize = (3*dc.GetCharHeight())/2;
f6bcfd97
BP
160 }
161
162 wxString str = wxGetWindowText(GetHWND());
163
164 int wCheckbox, hCheckbox;
4438caf4
VZ
165 if ( !str.IsEmpty() )
166 {
167 GetTextExtent(str, &wCheckbox, &hCheckbox);
f6bcfd97 168 wCheckbox += s_checkSize + GetCharWidth();
27fda0b6 169
f6bcfd97
BP
170 if ( hCheckbox < s_checkSize )
171 hCheckbox = s_checkSize;
4438caf4
VZ
172 }
173 else
2bda0e17 174 {
f6bcfd97
BP
175 wCheckbox = s_checkSize;
176 hCheckbox = s_checkSize;
2bda0e17
KB
177 }
178
4438caf4 179 return wxSize(wCheckbox, hCheckbox);
2bda0e17
KB
180}
181
debe6624 182void wxCheckBox::SetValue(bool val)
2bda0e17 183{
4438caf4 184 SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
2bda0e17
KB
185}
186
2432b92d
JS
187#ifndef BST_CHECKED
188#define BST_CHECKED 0x0001
189#endif
190
bfc6fde4 191bool wxCheckBox::GetValue() const
2bda0e17
KB
192{
193#ifdef __WIN32__
4438caf4 194 return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED);
2bda0e17 195#else
f6bcfd97 196 return ((0x001 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x001);
2bda0e17
KB
197#endif
198}
199
2bda0e17
KB
200void wxCheckBox::Command (wxCommandEvent & event)
201{
202 SetValue ((event.GetInt() != 0));
203 ProcessCommand (event);
204}
205
4438caf4
VZ
206// ----------------------------------------------------------------------------
207// wxBitmapCheckBox
208// ----------------------------------------------------------------------------
209
debe6624 210bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
2bda0e17 211 const wxPoint& pos,
debe6624 212 const wxSize& size, long style,
2bda0e17
KB
213 const wxValidator& validator,
214 const wxString& name)
215{
216 SetName(name);
11b6a93b 217#if wxUSE_VALIDATORS
2bda0e17 218 SetValidator(validator);
11b6a93b 219#endif // wxUSE_VALIDATORS
2bda0e17
KB
220 if (parent) parent->AddChild(this);
221
fd71308f
JS
222 SetBackgroundColour(parent->GetBackgroundColour()) ;
223 SetForegroundColour(parent->GetForegroundColour()) ;
2bda0e17
KB
224 m_windowStyle = style;
225
4438caf4
VZ
226 if ( id == -1 )
227 m_windowId = NewControlId();
228 else
229 m_windowId = id;
2bda0e17
KB
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
223d09f6 240 HWND wx_button = CreateWindowEx(MakeExtendedStyle(m_windowStyle), CHECK_CLASS, wxT("toggle"),
2bda0e17
KB
241 msStyle,
242 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
243 wxGetInstance(), NULL);
244
1f112209 245#if wxUSE_CTL3D
2bda0e17
KB
246 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
247 {
248 Ctl3dSubclassCtl(wx_button);
4438caf4 249 m_useCtl3D = TRUE;
2bda0e17
KB
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
2bda0e17
KB
258 SetSize(x, y, width, height);
259
260 ShowWindow(wx_button, SW_SHOW);
4438caf4 261
2bda0e17
KB
262 return TRUE;
263}
264
acbd13a3 265void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
2bda0e17 266{
223d09f6 267 wxFAIL_MSG(wxT("not implemented"));
2bda0e17 268}