]>
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 | ||
5d44b24e DW |
37 | bool wxCheckBox::OS2Command( |
38 | WXUINT WXUNUSED(uParam) | |
39 | , WXWORD WXUNUSED(wId) | |
40 | ) | |
37f214d5 | 41 | { |
5d44b24e DW |
42 | wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED |
43 | ,m_windowId | |
44 | ); | |
45 | rEvent.SetInt(GetValue()); | |
46 | rEvent.SetEventObject(this); | |
47 | ProcessCommand(rEvent); | |
37f214d5 | 48 | return TRUE; |
5d44b24e DW |
49 | } // end of wxCheckBox::OS2Command |
50 | ||
51 | bool wxCheckBox::Create( | |
52 | wxWindow* pParent | |
53 | , wxWindowID vId | |
54 | , const wxString& rsLabel | |
55 | , const wxPoint& rPos | |
56 | , const wxSize& rSize | |
57 | , long lStyle | |
5d4b632b | 58 | #if wxUSE_VALIDATORS |
5d44b24e | 59 | , const wxValidator& rValidator |
5d4b632b | 60 | #endif |
5d44b24e DW |
61 | , const wxString& rsName |
62 | ) | |
0e320a79 | 63 | { |
5d44b24e | 64 | SetName(rsName); |
5d4b632b | 65 | #if wxUSE_VALIDATORS |
5d44b24e | 66 | SetValidator(rValidator); |
5d4b632b | 67 | #endif |
5d44b24e DW |
68 | if (pParent) |
69 | pParent->AddChild(this); | |
37f214d5 | 70 | |
5d44b24e DW |
71 | SetBackgroundColour(pParent->GetBackgroundColour()); |
72 | SetForegroundColour(pParent->GetForegroundColour()); | |
73 | m_windowStyle = lStyle; | |
37f214d5 | 74 | |
5d44b24e | 75 | wxString sLabel = rsLabel; |
0e320a79 | 76 | |
5d44b24e DW |
77 | if (sLabel == wxT("")) |
78 | sLabel = wxT(" "); // Apparently needed or checkbox won't show | |
0e320a79 | 79 | |
5d44b24e | 80 | if (vId == -1 ) |
0e320a79 DW |
81 | m_windowId = NewControlId(); |
82 | else | |
5d44b24e DW |
83 | m_windowId = vId; |
84 | ||
85 | int nX = rPos.x; | |
86 | int nY = rPos.y; | |
87 | int nWidth = rSize.x; | |
88 | int nHeight = rSize.y; | |
89 | long lSstyle = 0L; | |
90 | ||
91 | lSstyle = BS_AUTOCHECKBOX | | |
92 | WS_TABSTOP | | |
93 | WS_VISIBLE; | |
94 | if (lStyle & wxCLIP_SIBLINGS ) | |
95 | lSstyle |= WS_CLIPSIBLINGS; | |
96 | ||
97 | // | |
98 | // If the parent is a scrolled window the controls must | |
99 | // have this style or they will overlap the scrollbars | |
100 | // | |
101 | if (pParent) | |
102 | if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) || | |
103 | pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow))) | |
104 | lSstyle |= WS_CLIPSIBLINGS; | |
105 | ||
106 | m_hWnd = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent) | |
107 | ,WC_BUTTON | |
108 | ,rsLabel.c_str() | |
109 | ,lSstyle | |
110 | ,0, 0, 0, 0 | |
111 | ,GetWinHwnd(pParent) | |
112 | ,HWND_TOP | |
113 | ,(HMENU)m_windowId | |
114 | ,NULL | |
115 | ,NULL | |
116 | ); | |
117 | ||
118 | // | |
37f214d5 | 119 | // Subclass again for purposes of dialog editing mode |
5d44b24e | 120 | // |
37f214d5 DW |
121 | SubclassWin(m_hWnd); |
122 | ||
7993e67c DW |
123 | LONG lColor = (LONG)m_backgroundColour.GetPixel(); |
124 | ||
125 | ::WinSetPresParam( m_hWnd | |
126 | ,PP_BACKGROUNDCOLOR | |
127 | ,sizeof(LONG) | |
128 | ,(PVOID)&lColor | |
129 | ); | |
130 | ||
5d44b24e | 131 | SetFont(pParent->GetFont()); |
37f214d5 | 132 | |
5d44b24e DW |
133 | SetSize( nX |
134 | ,nY | |
135 | ,nWidth | |
136 | ,nHeight | |
137 | ); | |
138 | return TRUE; | |
139 | } // end of wxCheckBox::Create | |
0e320a79 | 140 | |
5d44b24e DW |
141 | void wxCheckBox::SetLabel( |
142 | const wxString& rsLabel | |
143 | ) | |
0e320a79 | 144 | { |
5d44b24e DW |
145 | ::WinSetWindowText(GetHwnd(), rsLabel.c_str()); |
146 | } // end of wxCheckBox::SetLabel | |
0e320a79 | 147 | |
e78c4d50 | 148 | wxSize wxCheckBox::DoGetBestSize() const |
0e320a79 | 149 | { |
5d44b24e DW |
150 | static int nCheckSize = 0; |
151 | ||
152 | if (!nCheckSize) | |
153 | { | |
154 | wxScreenDC vDc; | |
155 | ||
156 | vDc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
157 | ||
158 | // | |
159 | // The height of a standard button in the dialog units is 8, | |
160 | // translate this to pixels (as one dialog unit is precisely equal to | |
161 | // 8 character heights, it's just the char height) | |
162 | // | |
163 | nCheckSize = vDc.GetCharHeight(); | |
164 | } | |
37f214d5 | 165 | |
5d44b24e DW |
166 | int nWidthCheckbox; |
167 | int nHeightCheckbox; | |
168 | wxString sStr = wxGetWindowText(GetHWND()); | |
37f214d5 | 169 | |
5d44b24e | 170 | if (!sStr.IsEmpty()) |
37f214d5 | 171 | { |
5d44b24e DW |
172 | GetTextExtent( sStr |
173 | ,&nWidthCheckbox | |
174 | ,&nHeightCheckbox | |
175 | ); | |
176 | nWidthCheckbox += nCheckSize + GetCharWidth(); | |
37f214d5 | 177 | |
5d44b24e DW |
178 | if (nHeightCheckbox < nCheckSize) |
179 | nHeightCheckbox = nCheckSize; | |
37f214d5 DW |
180 | } |
181 | else | |
182 | { | |
5d44b24e DW |
183 | nWidthCheckbox = nCheckSize; |
184 | nHeightCheckbox = nCheckSize; | |
37f214d5 DW |
185 | } |
186 | ||
5d44b24e DW |
187 | return wxSize( nWidthCheckbox |
188 | ,nHeightCheckbox | |
189 | ); | |
190 | } // end of wxCheckBox::DoGetBestSize | |
0e320a79 | 191 | |
5d44b24e DW |
192 | void wxCheckBox::SetValue( |
193 | bool bValue | |
194 | ) | |
0e320a79 | 195 | { |
5d44b24e DW |
196 | ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0); |
197 | } // end of wxCheckBox::SetValue | |
0e320a79 | 198 | |
37f214d5 DW |
199 | #ifndef BST_CHECKED |
200 | #define BST_CHECKED 0x0001 | |
201 | #endif | |
202 | ||
0e320a79 DW |
203 | bool wxCheckBox::GetValue() const |
204 | { | |
5d44b24e DW |
205 | return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L)); |
206 | } // end of wxCheckBox::GetValue | |
0e320a79 | 207 | |
5d44b24e DW |
208 | void wxCheckBox::Command ( |
209 | wxCommandEvent& rEvent | |
210 | ) | |
37f214d5 | 211 | { |
5d44b24e DW |
212 | SetValue((rEvent.GetInt() != 0)); |
213 | ProcessCommand(rEvent); | |
214 | } // end of wxCheckBox:: Command | |
0e320a79 | 215 | |
37f214d5 DW |
216 | // ---------------------------------------------------------------------------- |
217 | // wxBitmapCheckBox | |
218 | // ---------------------------------------------------------------------------- | |
219 | ||
5d44b24e DW |
220 | bool wxBitmapCheckBox::Create( |
221 | wxWindow* pParent | |
222 | , wxWindowID vId | |
223 | , const wxBitmap* pLabel | |
224 | , const wxPoint& rPos | |
225 | , const wxSize& rSize | |
226 | , long lStyle | |
5d4b632b | 227 | #if wxUSE_VALIDATORS |
5d44b24e | 228 | , const wxValidator& rValidator |
5d4b632b | 229 | #endif |
5d44b24e DW |
230 | , const wxString& rsName |
231 | ) | |
0e320a79 | 232 | { |
5d44b24e | 233 | SetName(rsName); |
5d4b632b | 234 | #if wxUSE_VALIDATORS |
5d44b24e | 235 | SetValidator(rValidator); |
5d4b632b | 236 | #endif |
5d44b24e DW |
237 | if (pParent) |
238 | pParent->AddChild(this); | |
0e320a79 | 239 | |
5d44b24e DW |
240 | SetBackgroundColour(pParent->GetBackgroundColour()) ; |
241 | SetForegroundColour(pParent->GetForegroundColour()) ; | |
242 | m_windowStyle = lStyle; | |
37f214d5 | 243 | |
5d44b24e | 244 | if (vId == -1) |
0e320a79 DW |
245 | m_windowId = NewControlId(); |
246 | else | |
5d44b24e | 247 | m_windowId = vId; |
0e320a79 | 248 | |
5d44b24e DW |
249 | int nX = rPos.x; |
250 | int nY = rPos.y; | |
251 | int nWidth = rSize.x; | |
252 | int nHeight = rSize.y; | |
0e320a79 | 253 | |
5d44b24e DW |
254 | m_nCheckWidth = -1 ; |
255 | m_nCheckHeight = -1 ; | |
892b89f3 | 256 | // long msStyle = CHECK_FLAGS; |
0e320a79 | 257 | |
5d44b24e | 258 | HWND hButton = 0; // TODO: Create the bitmap checkbox |
0e320a79 | 259 | |
5d44b24e | 260 | m_hWnd = (WXHWND)hButton; |
0e320a79 | 261 | |
5d44b24e | 262 | // |
37f214d5 | 263 | // Subclass again for purposes of dialog editing mode |
5d44b24e DW |
264 | // |
265 | SubclassWin((WXHWND)hButton); | |
37f214d5 | 266 | |
5d44b24e DW |
267 | SetSize( nX |
268 | ,nY | |
269 | ,nWidth | |
270 | ,nHeight | |
271 | ); | |
37f214d5 | 272 | |
5d44b24e | 273 | ::WinShowWindow(hButton, TRUE); |
37f214d5 | 274 | return TRUE; |
5d44b24e | 275 | } // end of wxBitmapCheckBox::Create |
0e320a79 | 276 | |
5d44b24e DW |
277 | void wxBitmapCheckBox::SetLabel( |
278 | const wxBitmap& rBitmap | |
279 | ) | |
0e320a79 | 280 | { |
37f214d5 | 281 | wxFAIL_MSG(wxT("not implemented")); |
5d44b24e | 282 | } // end of wxBitmapCheckBox::SetLabel |
0e320a79 | 283 |