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