Applied patch [ 832096 ] Final separation for GUI and console for Open Watcom
[wxWidgets.git] / src / os2 / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: checkbox.cpp
3 // Purpose: wxCheckBox
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
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"
18 #include "wx/scrolwin.h"
19 #include "wx/dcscreen.h"
20 #include "wx/settings.h"
21 #endif
22
23 #include "wx/os2/private.h"
24
25 // ----------------------------------------------------------------------------
26 // macros
27 // ----------------------------------------------------------------------------
28
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
31
32 extern void wxAssociateWinWithHandle( HWND hWnd
33 ,wxWindowOS2* pWin
34 );
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 // ----------------------------------------------------------------------------
41 // wxCheckBox
42 // ----------------------------------------------------------------------------
43
44 wxCheckBoxBase::wxCheckBoxBase()
45 {
46 }
47
48 bool wxCheckBox::OS2Command(
49 WXUINT WXUNUSED(uParam)
50 , WXWORD WXUNUSED(wId)
51 )
52 {
53 wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED
54 ,m_windowId
55 );
56 rEvent.SetInt(GetValue());
57 rEvent.SetEventObject(this);
58 ProcessCommand(rEvent);
59 return TRUE;
60 } // end of wxCheckBox::OS2Command
61
62 bool wxCheckBox::Create(
63 wxWindow* pParent
64 , wxWindowID vId
65 , const wxString& rsLabel
66 , const wxPoint& rPos
67 , const wxSize& rSize
68 , long lStyle
69 , const wxValidator& rValidator
70 , const wxString& rsName
71 )
72 {
73 LONG lColor;
74 bool bOk;
75
76 if (!CreateControl( pParent
77 ,vId
78 ,rPos
79 ,rSize
80 ,lStyle
81 ,rValidator
82 ,rsName
83 ))
84 return FALSE;
85
86
87 long osStyle = BS_AUTOCHECKBOX |
88 WS_TABSTOP |
89 WS_VISIBLE;
90
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;
107 } // end of wxCheckBox::Create
108
109 void wxCheckBox::SetLabel(
110 const wxString& rsLabel
111 )
112 {
113 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
114 } // end of wxCheckBox::SetLabel
115
116 wxSize wxCheckBox::DoGetBestSize() const
117 {
118 static int nCheckSize = 0;
119
120 if (!nCheckSize)
121 {
122 wxScreenDC vDc;
123
124 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
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 }
133
134 int nWidthCheckbox;
135 int nHeightCheckbox;
136 wxString sStr = wxGetWindowText(GetHWND());
137
138 if (!sStr.IsEmpty())
139 {
140 GetTextExtent( sStr
141 ,&nWidthCheckbox
142 ,&nHeightCheckbox
143 );
144 nWidthCheckbox += nCheckSize + GetCharWidth();
145
146 if (nHeightCheckbox < nCheckSize)
147 nHeightCheckbox = nCheckSize;
148 }
149 else
150 {
151 nWidthCheckbox = nCheckSize;
152 nHeightCheckbox = nCheckSize;
153 }
154
155 return wxSize( nWidthCheckbox
156 ,nHeightCheckbox
157 );
158 } // end of wxCheckBox::DoGetBestSize
159
160 void wxCheckBox::SetValue(
161 bool bValue
162 )
163 {
164 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
165 } // end of wxCheckBox::SetValue
166
167 #ifndef BST_CHECKED
168 #define BST_CHECKED 0x0001
169 #endif
170
171 bool wxCheckBox::GetValue() const
172 {
173 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
174 } // end of wxCheckBox::GetValue
175
176 void wxCheckBox::Command (
177 wxCommandEvent& rEvent
178 )
179 {
180 SetValue((rEvent.GetInt() != 0));
181 ProcessCommand(rEvent);
182 } // end of wxCheckBox:: Command
183
184 // ----------------------------------------------------------------------------
185 // wxBitmapCheckBox
186 // ----------------------------------------------------------------------------
187
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
195 , const wxValidator& rValidator
196 , const wxString& rsName
197 )
198 {
199 SetName(rsName);
200 #if wxUSE_VALIDATORS
201 SetValidator(rValidator);
202 #endif
203 if (pParent)
204 pParent->AddChild(this);
205
206 SetBackgroundColour(pParent->GetBackgroundColour()) ;
207 SetForegroundColour(pParent->GetForegroundColour()) ;
208 m_windowStyle = lStyle;
209
210 if (vId == -1)
211 m_windowId = NewControlId();
212 else
213 m_windowId = vId;
214
215 int nX = rPos.x;
216 int nY = rPos.y;
217 int nWidth = rSize.x;
218 int nHeight = rSize.y;
219
220 m_nCheckWidth = -1 ;
221 m_nCheckHeight = -1 ;
222 // long msStyle = CHECK_FLAGS;
223
224 HWND hButton = 0; // TODO: Create the bitmap checkbox
225
226 m_hWnd = (WXHWND)hButton;
227
228 //
229 // Subclass again for purposes of dialog editing mode
230 //
231 SubclassWin((WXHWND)hButton);
232
233 SetSize( nX
234 ,nY
235 ,nWidth
236 ,nHeight
237 );
238
239 ::WinShowWindow(hButton, TRUE);
240 return TRUE;
241 } // end of wxBitmapCheckBox::Create
242
243 void wxBitmapCheckBox::SetLabel(
244 const wxBitmap& rBitmap
245 )
246 {
247 wxFAIL_MSG(wxT("not implemented"));
248 } // end of wxBitmapCheckBox::SetLabel
249