]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
2b5f62a0 | 2 | // Name: msw/checkbox.cpp |
2bda0e17 KB |
3 | // Purpose: wxCheckBox |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
4438caf4 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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 | ||
2b5f62a0 VZ |
42 | #ifndef BST_CHECKED |
43 | #define BST_CHECKED 0x0001 | |
44 | #endif | |
2bda0e17 | 45 | |
4438caf4 VZ |
46 | // ============================================================================ |
47 | // implementation | |
48 | // ============================================================================ | |
49 | ||
51741307 | 50 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
51 | WX_DEFINE_FLAGS( wxCheckBoxStyle ) |
52 | ||
3ff066a4 | 53 | wxBEGIN_FLAGS( wxCheckBoxStyle ) |
bc9fb572 JS |
54 | // new style border flags, we put them first to |
55 | // use them for streaming out | |
3ff066a4 SC |
56 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
57 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
58 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
59 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
60 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
61 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
bc9fb572 JS |
62 | |
63 | // old style border flags | |
3ff066a4 SC |
64 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
65 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
66 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
67 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
68 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
69 | wxFLAGS_MEMBER(wxNO_BORDER) | |
bc9fb572 JS |
70 | |
71 | // standard window styles | |
3ff066a4 SC |
72 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
73 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
74 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
75 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
76 | wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE) | |
77 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
78 | wxFLAGS_MEMBER(wxVSCROLL) | |
79 | wxFLAGS_MEMBER(wxHSCROLL) | |
bc9fb572 | 80 | |
3ff066a4 | 81 | wxEND_FLAGS( wxCheckBoxStyle ) |
bc9fb572 | 82 | |
51741307 SC |
83 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckBox, wxControl,"wx/checkbox.h") |
84 | ||
3ff066a4 SC |
85 | wxBEGIN_PROPERTIES_TABLE(wxCheckBox) |
86 | wxEVENT_PROPERTY( Click , wxEVT_COMMAND_CHECKBOX_CLICKED , wxCommandEvent ) | |
51741307 | 87 | |
3ff066a4 SC |
88 | wxPROPERTY( Font , wxFont , SetFont , GetFont , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
89 | wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
90 | wxPROPERTY( Value ,bool, SetValue, GetValue, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
91 | wxPROPERTY_FLAGS( WindowStyle , wxCheckBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
92 | wxEND_PROPERTIES_TABLE() | |
2b5f62a0 | 93 | |
3ff066a4 SC |
94 | wxBEGIN_HANDLERS_TABLE(wxCheckBox) |
95 | wxEND_HANDLERS_TABLE() | |
51741307 | 96 | |
3ff066a4 | 97 | wxCONSTRUCTOR_6( wxCheckBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
98 | #else |
99 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
100 | #endif | |
066f1b7a | 101 | |
066f1b7a | 102 | |
4438caf4 VZ |
103 | // ---------------------------------------------------------------------------- |
104 | // wxCheckBox | |
105 | // ---------------------------------------------------------------------------- | |
106 | ||
debe6624 | 107 | bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) |
2bda0e17 | 108 | { |
4438caf4 VZ |
109 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); |
110 | event.SetInt(GetValue()); | |
111 | event.SetEventObject(this); | |
112 | ProcessCommand(event); | |
113 | return TRUE; | |
2bda0e17 KB |
114 | } |
115 | ||
11b6a93b VZ |
116 | bool wxCheckBox::Create(wxWindow *parent, |
117 | wxWindowID id, | |
118 | const wxString& label, | |
119 | const wxPoint& pos, | |
120 | const wxSize& size, long style, | |
121 | const wxValidator& validator, | |
122 | const wxString& name) | |
2bda0e17 | 123 | { |
787a85c2 | 124 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) |
8912d7eb | 125 | return FALSE; |
4438caf4 | 126 | |
8912d7eb | 127 | long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP; |
4438caf4 VZ |
128 | if ( style & wxALIGN_RIGHT ) |
129 | msStyle |= BS_LEFTTEXT; | |
130 | ||
8912d7eb | 131 | return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0); |
2bda0e17 KB |
132 | } |
133 | ||
134 | void wxCheckBox::SetLabel(const wxString& label) | |
135 | { | |
f6bcfd97 | 136 | SetWindowText(GetHwnd(), label); |
2bda0e17 KB |
137 | } |
138 | ||
f68586e5 | 139 | wxSize wxCheckBox::DoGetBestSize() const |
2bda0e17 | 140 | { |
f6bcfd97 | 141 | static int s_checkSize = 0; |
81d66cf3 | 142 | |
f6bcfd97 BP |
143 | if ( !s_checkSize ) |
144 | { | |
145 | wxScreenDC dc; | |
a756f210 | 146 | dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
2bda0e17 | 147 | |
fb1a41cd | 148 | s_checkSize = dc.GetCharHeight(); |
f6bcfd97 BP |
149 | } |
150 | ||
151 | wxString str = wxGetWindowText(GetHWND()); | |
152 | ||
153 | int wCheckbox, hCheckbox; | |
4438caf4 VZ |
154 | if ( !str.IsEmpty() ) |
155 | { | |
156 | GetTextExtent(str, &wCheckbox, &hCheckbox); | |
f6bcfd97 | 157 | wCheckbox += s_checkSize + GetCharWidth(); |
27fda0b6 | 158 | |
f6bcfd97 BP |
159 | if ( hCheckbox < s_checkSize ) |
160 | hCheckbox = s_checkSize; | |
4438caf4 VZ |
161 | } |
162 | else | |
2bda0e17 | 163 | { |
f6bcfd97 BP |
164 | wCheckbox = s_checkSize; |
165 | hCheckbox = s_checkSize; | |
2bda0e17 KB |
166 | } |
167 | ||
4438caf4 | 168 | return wxSize(wCheckbox, hCheckbox); |
2bda0e17 KB |
169 | } |
170 | ||
debe6624 | 171 | void wxCheckBox::SetValue(bool val) |
2bda0e17 | 172 | { |
4438caf4 | 173 | SendMessage(GetHwnd(), BM_SETCHECK, val, 0); |
2bda0e17 KB |
174 | } |
175 | ||
bfc6fde4 | 176 | bool wxCheckBox::GetValue() const |
2bda0e17 | 177 | { |
2b5f62a0 | 178 | return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) & BST_CHECKED) != 0; |
2bda0e17 KB |
179 | } |
180 | ||
2b5f62a0 | 181 | void wxCheckBox::Command(wxCommandEvent& event) |
2bda0e17 | 182 | { |
2b5f62a0 VZ |
183 | SetValue(event.GetInt() != 0); |
184 | ProcessCommand(event); | |
2bda0e17 | 185 | } |
1e6feb95 VZ |
186 | |
187 | #endif // wxUSE_CHECKBOX |