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