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