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