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