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