]> git.saurik.com Git - wxWidgets.git/blame - src/msw/checkbox.cpp
1. compilation fixes for TB_REPLACEBITMAP and FONTENUMPROC
[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"
2bda0e17
KB
34#endif
35
36#include "wx/msw/private.h"
37
4438caf4
VZ
38// ----------------------------------------------------------------------------
39// macros
40// ----------------------------------------------------------------------------
41
4438caf4
VZ
42 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
43 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
2bda0e17 44
4438caf4
VZ
45// ============================================================================
46// implementation
47// ============================================================================
48
49// ----------------------------------------------------------------------------
50// wxCheckBox
51// ----------------------------------------------------------------------------
52
debe6624 53bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
2bda0e17 54{
4438caf4
VZ
55 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId);
56 event.SetInt(GetValue());
57 event.SetEventObject(this);
58 ProcessCommand(event);
59 return TRUE;
2bda0e17
KB
60}
61
62// Single check box item
debe6624 63bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
2bda0e17 64 const wxPoint& pos,
debe6624 65 const wxSize& size, long style,
2bda0e17
KB
66 const wxValidator& validator,
67 const wxString& name)
68{
4438caf4
VZ
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;
223d09f6
KB
79 if (Label == wxT(""))
80 Label = wxT(" "); // Apparently needed or checkbox won't show
4438caf4
VZ
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
223d09f6 110 m_hWnd = (WXHWND)CreateWindowEx(exStyle, wxT("BUTTON"), Label,
4438caf4
VZ
111 msStyle,
112 0, 0, 0, 0,
113 (HWND)parent->GetHWND(), (HMENU)m_windowId,
114 wxGetInstance(), NULL);
2bda0e17 115
1f112209 116#if wxUSE_CTL3D
4438caf4
VZ
117 if (want3D)
118 {
119 Ctl3dSubclassCtl(GetHwnd());
120 m_useCtl3D = TRUE;
121 }
2bda0e17
KB
122#endif
123
4438caf4
VZ
124 // Subclass again for purposes of dialog editing mode
125 SubclassWin(m_hWnd);
2bda0e17 126
4438caf4 127 SetFont(parent->GetFont());
2bda0e17 128
4438caf4
VZ
129 SetSize(x, y, width, height);
130
131 return TRUE;
2bda0e17
KB
132}
133
134void wxCheckBox::SetLabel(const wxString& label)
135{
4438caf4 136 SetWindowText(GetHwnd(), label);
2bda0e17
KB
137}
138
f68586e5 139wxSize wxCheckBox::DoGetBestSize() const
2bda0e17 140{
4438caf4 141 int wCheckbox, hCheckbox;
81d66cf3 142
4438caf4 143 wxString str = wxGetWindowText(GetHWND());
2bda0e17 144
4438caf4
VZ
145 if ( !str.IsEmpty() )
146 {
147 GetTextExtent(str, &wCheckbox, &hCheckbox);
148 wCheckbox += RADIO_SIZE;
27fda0b6 149
4438caf4
VZ
150 if ( hCheckbox < RADIO_SIZE )
151 hCheckbox = RADIO_SIZE;
152 }
153 else
2bda0e17 154 {
4438caf4
VZ
155 wCheckbox = RADIO_SIZE;
156 hCheckbox = RADIO_SIZE;
2bda0e17
KB
157 }
158
4438caf4 159 return wxSize(wCheckbox, hCheckbox);
2bda0e17
KB
160}
161
debe6624 162void wxCheckBox::SetValue(bool val)
2bda0e17 163{
4438caf4 164 SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
2bda0e17
KB
165}
166
2432b92d
JS
167#ifndef BST_CHECKED
168#define BST_CHECKED 0x0001
169#endif
170
bfc6fde4 171bool wxCheckBox::GetValue() const
2bda0e17
KB
172{
173#ifdef __WIN32__
4438caf4 174 return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED);
2bda0e17 175#else
4438caf4 176 return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x003);
2bda0e17
KB
177#endif
178}
179
2bda0e17
KB
180void wxCheckBox::Command (wxCommandEvent & event)
181{
182 SetValue ((event.GetInt() != 0));
183 ProcessCommand (event);
184}
185
4438caf4
VZ
186// ----------------------------------------------------------------------------
187// wxBitmapCheckBox
188// ----------------------------------------------------------------------------
189
debe6624 190bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
2bda0e17 191 const wxPoint& pos,
debe6624 192 const wxSize& size, long style,
2bda0e17
KB
193 const wxValidator& validator,
194 const wxString& name)
195{
196 SetName(name);
197 SetValidator(validator);
198 if (parent) parent->AddChild(this);
199
fd71308f
JS
200 SetBackgroundColour(parent->GetBackgroundColour()) ;
201 SetForegroundColour(parent->GetForegroundColour()) ;
2bda0e17
KB
202 m_windowStyle = style;
203
4438caf4
VZ
204 if ( id == -1 )
205 m_windowId = NewControlId();
206 else
207 m_windowId = id;
2bda0e17
KB
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
223d09f6 218 HWND wx_button = CreateWindowEx(MakeExtendedStyle(m_windowStyle), CHECK_CLASS, wxT("toggle"),
2bda0e17
KB
219 msStyle,
220 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
221 wxGetInstance(), NULL);
222
1f112209 223#if wxUSE_CTL3D
2bda0e17
KB
224 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
225 {
226 Ctl3dSubclassCtl(wx_button);
4438caf4 227 m_useCtl3D = TRUE;
2bda0e17
KB
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
2bda0e17
KB
236 SetSize(x, y, width, height);
237
238 ShowWindow(wx_button, SW_SHOW);
4438caf4 239
2bda0e17
KB
240 return TRUE;
241}
242
acbd13a3 243void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
2bda0e17 244{
223d09f6 245 wxFAIL_MSG(wxT("not implemented"));
2bda0e17 246}