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