]> git.saurik.com Git - wxWidgets.git/blame - src/msw/checkbox.cpp
Removed /install/gtk/configure from cvs
[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
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "checkbox.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/checkbox.h"
25#endif
26
27#include "wx/msw/private.h"
28
29#if !USE_SHARED_LIBRARY
30IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
31IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
32#endif
33
debe6624 34bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
2bda0e17
KB
35{
36 wxCommandEvent event(wxEVENT_TYPE_CHECKBOX_COMMAND, m_windowId);
37 event.SetInt(GetValue());
38 event.SetEventObject(this);
39 ProcessCommand(event);
40 return TRUE;
41}
42
43// Single check box item
debe6624 44bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
2bda0e17 45 const wxPoint& pos,
debe6624 46 const wxSize& size, long style,
2bda0e17
KB
47 const wxValidator& validator,
48 const wxString& name)
49{
50 SetName(name);
51 SetValidator(validator);
52 if (parent) parent->AddChild(this);
53
54 SetBackgroundColour(parent->GetDefaultBackgroundColour()) ;
55 SetForegroundColour(parent->GetDefaultForegroundColour()) ;
56
57 m_windowStyle = style;
58
59 wxString Label = label;
60 if (Label == "")
61 Label = " "; // Apparently needed or checkbox won't show
62
63 if ( id == -1 )
64 m_windowId = NewControlId();
65 else
66 m_windowId = id;
67
68 int x = pos.x;
69 int y = pos.y;
70 int width = size.x;
71 int height = size.y;
72
73 long msStyle = BS_AUTOCHECKBOX|WS_TABSTOP|WS_CHILD;
74
75 // We perhaps have different concepts of 3D here - a 3D border,
76 // versus a 3D button.
77 // So we only wish to give a border if this is specified
78 // in the style.
79 bool want3D;
80 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
81
82 // Even with extended styles, need to combine with WS_BORDER
83 // for them to look right.
84 if (want3D && ((m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
85 (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER)))
86 msStyle |= WS_BORDER;
87
88 HWND wx_button = CreateWindowEx(exStyle, "BUTTON", (const char *)Label,
89 msStyle,
90 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
91 wxGetInstance(), NULL);
92
93#if CTL3D
94 if (want3D)
95 {
96 Ctl3dSubclassCtl(wx_button);
97 m_useCtl3D = TRUE;
98 }
99#endif
100
101 m_hWnd = (WXHWND) wx_button;
102
103 // Subclass again for purposes of dialog editing mode
104 SubclassWin((WXHWND) wx_button);
105
106 SetFont(* parent->GetFont());
107
108 SetSize(x, y, width, height);
109
110 ShowWindow(wx_button, SW_SHOW);
111 return TRUE;
112}
113
114void wxCheckBox::SetLabel(const wxString& label)
115{
116 SetWindowText((HWND) GetHWND(), (const char *)label);
117}
118
debe6624 119void wxCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17
KB
120{
121 int currentX, currentY;
122 GetPosition(&currentX, &currentY);
123 int x1 = x;
124 int y1 = y;
125 int w1 = width;
126 int h1 = height;
127
128 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
129 x1 = currentX;
130 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
131 y1 = currentY;
132
81d66cf3
JS
133 AdjustForParentClientOrigin(x1, y1, sizeFlags);
134
2bda0e17
KB
135 char buf[300];
136
debe6624 137 int current_width, cyf;
2bda0e17
KB
138 HWND button = (HWND) GetHWND();
139
140 GetWindowText(button, buf, 300);
141 if (buf[0])
142 {
143 GetTextExtent(buf, &current_width, &cyf, NULL, NULL, GetFont());
144 if (w1 < 0)
145 w1 = (int)(current_width + RADIO_SIZE);
146 if (h1 < 0)
147 {
148 h1 = (int)(cyf);
149 if (h1 < RADIO_SIZE)
150 h1 = RADIO_SIZE;
151 }
152 }
153 else
154 {
155 if (w1 < 0)
156 w1 = RADIO_SIZE;
157 if (h1 < 0)
158 h1 = RADIO_SIZE;
159 }
160
161 MoveWindow(button, x1, y1, w1, h1, TRUE);
2bda0e17
KB
162}
163
debe6624 164void wxCheckBox::SetValue(bool val)
2bda0e17
KB
165{
166 SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0);
167}
168
169bool wxCheckBox::GetValue(void) const
170{
171#ifdef __WIN32__
172 return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0) == BST_CHECKED);
173#else
174 return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003);
175#endif
176}
177
debe6624 178WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
2bda0e17
KB
179 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
180{
181#if CTL3D
182 if ( m_useCtl3D )
183 {
184 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
185
186 return (WXHBRUSH) hbrush;
187 }
188#endif
189
190 if (GetParent()->GetTransparentBackground())
191 SetBkMode((HDC) pDC, TRANSPARENT);
192 else
193 SetBkMode((HDC) pDC, OPAQUE);
194
195 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
196 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
197
198 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
199
200 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
201 // has a zero usage count.
202// backgroundBrush->RealizeResource();
203 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
204}
205
206void wxCheckBox::Command (wxCommandEvent & event)
207{
208 SetValue ((event.GetInt() != 0));
209 ProcessCommand (event);
210}
211
debe6624 212bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
2bda0e17 213 const wxPoint& pos,
debe6624 214 const wxSize& size, long style,
2bda0e17
KB
215 const wxValidator& validator,
216 const wxString& name)
217{
218 SetName(name);
219 SetValidator(validator);
220 if (parent) parent->AddChild(this);
221
222 SetBackgroundColour(parent->GetDefaultBackgroundColour()) ;
223 SetForegroundColour(parent->GetDefaultForegroundColour()) ;
224 m_windowStyle = style;
225
226 if ( id == -1 )
227 m_windowId = NewControlId();
228 else
229 m_windowId = id;
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
240 HWND wx_button = CreateWindowEx(MakeExtendedStyle(m_windowStyle), CHECK_CLASS, "toggle",
241 msStyle,
242 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
243 wxGetInstance(), NULL);
244
245#if CTL3D
246 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
247 {
248 Ctl3dSubclassCtl(wx_button);
249 m_useCtl3D = TRUE;
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
258// SetFont(parent->GetFont());
259
260 SetSize(x, y, width, height);
261
262 ShowWindow(wx_button, SW_SHOW);
263 return TRUE;
264}
265
266void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
267{
268}
269
debe6624 270void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17
KB
271{
272 int currentX, currentY;
273 GetPosition(&currentX, &currentY);
274
275 int x1 = x;
276 int y1 = y;
277 int w1 = width;
278 int h1 = height;
279
280 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
281 x1 = currentX;
282 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
283 y1 = currentY;
284
81d66cf3
JS
285 AdjustForParentClientOrigin(x1, y1, sizeFlags);
286
2bda0e17
KB
287 HWND button = (HWND) GetHWND();
288/*
289 if (w1<0)
290 w1 = checkWidth + FB_MARGIN ;
291 if (h1<0)
292 h1 = checkHeight + FB_MARGIN ;
293*/
294 MoveWindow(button, x1, y1, w1, h1, TRUE);
2bda0e17
KB
295}
296
debe6624 297void wxBitmapCheckBox::SetValue(bool val)
2bda0e17
KB
298{
299 SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0);
300}
301
302bool wxBitmapCheckBox::GetValue(void) const
303{
304 return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003);
305}
306
307