]> git.saurik.com Git - wxWidgets.git/blame - src/msw/checkbox.cpp
Applied patch [ 583922 ] Make generic/wxListCtrl avail. in WIN32
[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
11b6a93b
VZ
66bool wxCheckBox::Create(wxWindow *parent,
67 wxWindowID id,
68 const wxString& label,
69 const wxPoint& pos,
70 const wxSize& size, long style,
71 const wxValidator& validator,
72 const wxString& name)
2bda0e17 73{
787a85c2 74 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
8912d7eb 75 return FALSE;
4438caf4 76
8912d7eb 77 long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP;
4438caf4
VZ
78 if ( style & wxALIGN_RIGHT )
79 msStyle |= BS_LEFTTEXT;
80
8912d7eb 81 return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0);
2bda0e17
KB
82}
83
84void wxCheckBox::SetLabel(const wxString& label)
85{
f6bcfd97 86 SetWindowText(GetHwnd(), label);
2bda0e17
KB
87}
88
f68586e5 89wxSize wxCheckBox::DoGetBestSize() const
2bda0e17 90{
f6bcfd97 91 static int s_checkSize = 0;
81d66cf3 92
f6bcfd97
BP
93 if ( !s_checkSize )
94 {
95 wxScreenDC dc;
a756f210 96 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
2bda0e17 97
fb1a41cd 98 s_checkSize = dc.GetCharHeight();
f6bcfd97
BP
99 }
100
101 wxString str = wxGetWindowText(GetHWND());
102
103 int wCheckbox, hCheckbox;
4438caf4
VZ
104 if ( !str.IsEmpty() )
105 {
106 GetTextExtent(str, &wCheckbox, &hCheckbox);
f6bcfd97 107 wCheckbox += s_checkSize + GetCharWidth();
27fda0b6 108
f6bcfd97
BP
109 if ( hCheckbox < s_checkSize )
110 hCheckbox = s_checkSize;
4438caf4
VZ
111 }
112 else
2bda0e17 113 {
f6bcfd97
BP
114 wCheckbox = s_checkSize;
115 hCheckbox = s_checkSize;
2bda0e17
KB
116 }
117
4438caf4 118 return wxSize(wCheckbox, hCheckbox);
2bda0e17
KB
119}
120
debe6624 121void wxCheckBox::SetValue(bool val)
2bda0e17 122{
4438caf4 123 SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
2bda0e17
KB
124}
125
2432b92d
JS
126#ifndef BST_CHECKED
127#define BST_CHECKED 0x0001
128#endif
129
bfc6fde4 130bool wxCheckBox::GetValue() const
2bda0e17
KB
131{
132#ifdef __WIN32__
4438caf4 133 return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED);
2bda0e17 134#else
f6bcfd97 135 return ((0x001 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x001);
2bda0e17
KB
136#endif
137}
138
2bda0e17
KB
139void wxCheckBox::Command (wxCommandEvent & event)
140{
141 SetValue ((event.GetInt() != 0));
142 ProcessCommand (event);
143}
144
4438caf4
VZ
145// ----------------------------------------------------------------------------
146// wxBitmapCheckBox
147// ----------------------------------------------------------------------------
148
33ac7e6f 149bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *WXUNUSED(label),
2bda0e17 150 const wxPoint& pos,
debe6624 151 const wxSize& size, long style,
2bda0e17
KB
152 const wxValidator& validator,
153 const wxString& name)
154{
155 SetName(name);
11b6a93b 156#if wxUSE_VALIDATORS
2bda0e17 157 SetValidator(validator);
11b6a93b 158#endif // wxUSE_VALIDATORS
2bda0e17
KB
159 if (parent) parent->AddChild(this);
160
fd71308f
JS
161 SetBackgroundColour(parent->GetBackgroundColour()) ;
162 SetForegroundColour(parent->GetForegroundColour()) ;
2bda0e17
KB
163 m_windowStyle = style;
164
4438caf4
VZ
165 if ( id == -1 )
166 m_windowId = NewControlId();
167 else
168 m_windowId = id;
2bda0e17
KB
169
170 int x = pos.x;
171 int y = pos.y;
172 int width = size.x;
173 int height = size.y;
174
175 checkWidth = -1 ;
176 checkHeight = -1 ;
177 long msStyle = CHECK_FLAGS;
178
223d09f6 179 HWND wx_button = CreateWindowEx(MakeExtendedStyle(m_windowStyle), CHECK_CLASS, wxT("toggle"),
2bda0e17
KB
180 msStyle,
181 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
182 wxGetInstance(), NULL);
183
1f112209 184#if wxUSE_CTL3D
2bda0e17
KB
185 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
186 {
187 Ctl3dSubclassCtl(wx_button);
4438caf4 188 m_useCtl3D = TRUE;
2bda0e17
KB
189 }
190#endif
191
192 m_hWnd = (WXHWND)wx_button;
193
194 // Subclass again for purposes of dialog editing mode
195 SubclassWin((WXHWND)wx_button);
196
2bda0e17
KB
197 SetSize(x, y, width, height);
198
199 ShowWindow(wx_button, SW_SHOW);
4438caf4 200
2bda0e17
KB
201 return TRUE;
202}
203
33ac7e6f 204void wxBitmapCheckBox::SetLabel(const wxBitmap& WXUNUSED(bitmap))
2bda0e17 205{
223d09f6 206 wxFAIL_MSG(wxT("not implemented"));
2bda0e17 207}
1e6feb95
VZ
208
209#endif // wxUSE_CHECKBOX