]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: checkbox.cpp | |
3 | // Purpose: wxCheckBox | |
37f214d5 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
37f214d5 | 6 | // Created: 10/13/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
37f214d5 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
37f214d5 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/checkbox.h" | |
17 | #include "wx/brush.h" | |
0e320a79 DW |
18 | #endif |
19 | ||
37f214d5 DW |
20 | #include "wx/os2/private.h" |
21 | ||
22 | // ---------------------------------------------------------------------------- | |
23 | // macros | |
24 | // ---------------------------------------------------------------------------- | |
0e320a79 | 25 | |
0e320a79 DW |
26 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) |
27 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
0e320a79 | 28 | |
37f214d5 DW |
29 | // ============================================================================ |
30 | // implementation | |
31 | // ============================================================================ | |
32 | ||
33 | // ---------------------------------------------------------------------------- | |
34 | // wxCheckBox | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | bool wxCheckBox::OS2Command(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) | |
38 | { | |
39 | wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); | |
40 | event.SetInt(GetValue()); | |
41 | event.SetEventObject(this); | |
42 | ProcessCommand(event); | |
43 | return TRUE; | |
44 | } | |
45 | ||
0e320a79 DW |
46 | // Single check box item |
47 | bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |
48 | const wxPoint& pos, | |
49 | const wxSize& size, long style, | |
5d4b632b | 50 | #if wxUSE_VALIDATORS |
0e320a79 | 51 | const wxValidator& validator, |
5d4b632b | 52 | #endif |
0e320a79 DW |
53 | const wxString& name) |
54 | { | |
55 | SetName(name); | |
5d4b632b | 56 | #if wxUSE_VALIDATORS |
0e320a79 | 57 | SetValidator(validator); |
5d4b632b | 58 | #endif |
37f214d5 DW |
59 | if (parent) parent->AddChild(this); |
60 | ||
61 | SetBackgroundColour(parent->GetBackgroundColour()) ; | |
62 | SetForegroundColour(parent->GetForegroundColour()) ; | |
63 | ||
0e320a79 DW |
64 | m_windowStyle = style; |
65 | ||
37f214d5 DW |
66 | wxString Label = label; |
67 | if (Label == wxT("")) | |
68 | Label = wxT(" "); // Apparently needed or checkbox won't show | |
0e320a79 DW |
69 | |
70 | if ( id == -1 ) | |
71 | m_windowId = NewControlId(); | |
72 | else | |
73 | m_windowId = id; | |
74 | ||
37f214d5 DW |
75 | int x = pos.x; |
76 | int y = pos.y; | |
77 | int width = size.x; | |
78 | int height = size.y; | |
79 | ||
0e320a79 DW |
80 | // TODO: create checkbox |
81 | ||
37f214d5 DW |
82 | // Subclass again for purposes of dialog editing mode |
83 | SubclassWin(m_hWnd); | |
84 | ||
85 | SetFont(parent->GetFont()); | |
86 | ||
87 | SetSize(x, y, width, height); | |
88 | ||
0e320a79 DW |
89 | return FALSE; |
90 | } | |
91 | ||
92 | void wxCheckBox::SetLabel(const wxString& label) | |
93 | { | |
94 | // TODO | |
95 | } | |
96 | ||
e78c4d50 | 97 | wxSize wxCheckBox::DoGetBestSize() const |
0e320a79 | 98 | { |
37f214d5 DW |
99 | int wCheckbox, hCheckbox; |
100 | ||
101 | wxString str = wxGetWindowText(GetHWND()); | |
102 | ||
103 | if ( !str.IsEmpty() ) | |
104 | { | |
105 | GetTextExtent(str, &wCheckbox, &hCheckbox); | |
106 | wCheckbox += RADIO_SIZE; | |
107 | ||
108 | if ( hCheckbox < RADIO_SIZE ) | |
109 | hCheckbox = RADIO_SIZE; | |
110 | } | |
111 | else | |
112 | { | |
113 | wCheckbox = RADIO_SIZE; | |
114 | hCheckbox = RADIO_SIZE; | |
115 | } | |
116 | ||
117 | return wxSize(wCheckbox, hCheckbox); | |
0e320a79 DW |
118 | } |
119 | ||
120 | void wxCheckBox::SetValue(bool val) | |
121 | { | |
122 | // TODO | |
123 | } | |
124 | ||
37f214d5 DW |
125 | #ifndef BST_CHECKED |
126 | #define BST_CHECKED 0x0001 | |
127 | #endif | |
128 | ||
0e320a79 DW |
129 | bool wxCheckBox::GetValue() const |
130 | { | |
131 | // TODO | |
132 | return FALSE; | |
133 | } | |
134 | ||
37f214d5 DW |
135 | WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
136 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
137 | { | |
138 | // TODO: | |
139 | /* | |
140 | #if wxUSE_CTL3D | |
141 | if ( m_useCtl3D ) | |
142 | { | |
143 | HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); | |
144 | ||
145 | return (WXHBRUSH) hbrush; | |
146 | } | |
147 | #endif | |
148 | ||
149 | if (GetParent()->GetTransparentBackground()) | |
150 | SetBkMode((HDC) pDC, TRANSPARENT); | |
151 | else | |
152 | SetBkMode((HDC) pDC, OPAQUE); | |
153 | ||
154 | ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); | |
155 | ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); | |
156 | ||
157 | */ | |
158 | ||
159 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); | |
160 | ||
161 | ||
162 | // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush | |
163 | // has a zero usage count. | |
164 | // backgroundBrush->RealizeResource(); | |
165 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); | |
166 | } | |
167 | ||
0e320a79 DW |
168 | void wxCheckBox::Command (wxCommandEvent & event) |
169 | { | |
170 | SetValue ((event.GetInt() != 0)); | |
171 | ProcessCommand (event); | |
172 | } | |
173 | ||
37f214d5 DW |
174 | // ---------------------------------------------------------------------------- |
175 | // wxBitmapCheckBox | |
176 | // ---------------------------------------------------------------------------- | |
177 | ||
0e320a79 DW |
178 | bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label, |
179 | const wxPoint& pos, | |
180 | const wxSize& size, long style, | |
5d4b632b | 181 | #if wxUSE_VALIDATORS |
0e320a79 | 182 | const wxValidator& validator, |
5d4b632b | 183 | #endif |
0e320a79 DW |
184 | const wxString& name) |
185 | { | |
186 | SetName(name); | |
5d4b632b | 187 | #if wxUSE_VALIDATORS |
0e320a79 | 188 | SetValidator(validator); |
5d4b632b | 189 | #endif |
0e320a79 DW |
190 | if (parent) parent->AddChild(this); |
191 | ||
37f214d5 DW |
192 | SetBackgroundColour(parent->GetBackgroundColour()) ; |
193 | SetForegroundColour(parent->GetForegroundColour()) ; | |
194 | m_windowStyle = style; | |
195 | ||
0e320a79 DW |
196 | if ( id == -1 ) |
197 | m_windowId = NewControlId(); | |
198 | else | |
199 | m_windowId = id; | |
200 | ||
37f214d5 DW |
201 | int x = pos.x; |
202 | int y = pos.y; | |
203 | int width = size.x; | |
204 | int height = size.y; | |
0e320a79 | 205 | |
37f214d5 DW |
206 | checkWidth = -1 ; |
207 | checkHeight = -1 ; | |
892b89f3 | 208 | // long msStyle = CHECK_FLAGS; |
0e320a79 | 209 | |
37f214d5 | 210 | HWND wx_button = 0; // TODO: Create the bitmap checkbox |
0e320a79 | 211 | |
37f214d5 | 212 | m_hWnd = (WXHWND)wx_button; |
0e320a79 | 213 | |
37f214d5 DW |
214 | // Subclass again for purposes of dialog editing mode |
215 | SubclassWin((WXHWND)wx_button); | |
216 | ||
217 | SetSize(x, y, width, height); | |
218 | ||
219 | // TODO: ShowWindow(wx_button, SW_SHOW); | |
220 | ||
221 | return TRUE; | |
0e320a79 DW |
222 | } |
223 | ||
37f214d5 | 224 | void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap) |
0e320a79 | 225 | { |
37f214d5 | 226 | wxFAIL_MSG(wxT("not implemented")); |
0e320a79 DW |
227 | } |
228 |