]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/checkbox.cpp
Comment correction.
[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 #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
29IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
31
32extern void wxAssociateWinWithHandle( HWND hWnd
33 ,wxWindowOS2* pWin
34 );
35
36// ============================================================================
37// implementation
38// ============================================================================
39
40// ----------------------------------------------------------------------------
41// wxCheckBox
42// ----------------------------------------------------------------------------
43
44bool wxCheckBox::OS2Command(
45 WXUINT WXUNUSED(uParam)
46, WXWORD WXUNUSED(wId)
47)
48{
49 wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED
50 ,m_windowId
51 );
52 rEvent.SetInt(GetValue());
53 rEvent.SetEventObject(this);
54 ProcessCommand(rEvent);
55 return TRUE;
56} // end of wxCheckBox::OS2Command
57
58bool wxCheckBox::Create(
59 wxWindow* pParent
60, wxWindowID vId
61, const wxString& rsLabel
62, const wxPoint& rPos
63, const wxSize& rSize
64, long lStyle
65, const wxValidator& rValidator
66, const wxString& rsName
67)
68{
69 LONG lColor;
70 bool bOk;
71
72 if (!CreateControl( pParent
73 ,vId
74 ,rPos
75 ,rSize
76 ,lStyle
77 ,rValidator
78 ,rsName
79 ))
80 return FALSE;
81
82
83 long osStyle = BS_AUTOCHECKBOX |
84 WS_TABSTOP |
85 WS_VISIBLE;
86
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;
103} // end of wxCheckBox::Create
104
105void wxCheckBox::SetLabel(
106 const wxString& rsLabel
107)
108{
109 wxString sLabel=::wxPMTextToLabel(rsLabel);
110 ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str());
111} // end of wxCheckBox::SetLabel
112
113wxSize wxCheckBox::DoGetBestSize() const
114{
115 static int nCheckSize = 0;
116
117 if (!nCheckSize)
118 {
119 wxScreenDC vDc;
120
121 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
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 }
130
131 int nWidthCheckbox;
132 int nHeightCheckbox;
133 wxString sStr = wxGetWindowText(GetHWND());
134
135 if (!sStr.IsEmpty())
136 {
137 GetTextExtent( sStr
138 ,&nWidthCheckbox
139 ,&nHeightCheckbox
140 );
141 nWidthCheckbox += nCheckSize + GetCharWidth();
142
143 if (nHeightCheckbox < nCheckSize)
144 nHeightCheckbox = nCheckSize;
145 }
146 else
147 {
148 nWidthCheckbox = nCheckSize;
149 nHeightCheckbox = nCheckSize;
150 }
151
152 return wxSize( nWidthCheckbox
153 ,nHeightCheckbox
154 );
155} // end of wxCheckBox::DoGetBestSize
156
157void wxCheckBox::SetValue(
158 bool bValue
159)
160{
161 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
162} // end of wxCheckBox::SetValue
163
164#ifndef BST_CHECKED
165#define BST_CHECKED 0x0001
166#endif
167
168bool wxCheckBox::GetValue() const
169{
170 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
171} // end of wxCheckBox::GetValue
172
173void wxCheckBox::Command (
174 wxCommandEvent& rEvent
175)
176{
177 SetValue((rEvent.GetInt() != 0));
178 ProcessCommand(rEvent);
179} // end of wxCheckBox:: Command
180
181// ----------------------------------------------------------------------------
182// wxBitmapCheckBox
183// ----------------------------------------------------------------------------
184
185bool wxBitmapCheckBox::Create(
186 wxWindow* pParent
187, wxWindowID vId
188, const wxBitmap* pLabel
189, const wxPoint& rPos
190, const wxSize& rSize
191, long lStyle
192, const wxValidator& rValidator
193, const wxString& rsName
194)
195{
196 SetName(rsName);
197#if wxUSE_VALIDATORS
198 SetValidator(rValidator);
199#endif
200 if (pParent)
201 pParent->AddChild(this);
202
203 SetBackgroundColour(pParent->GetBackgroundColour()) ;
204 SetForegroundColour(pParent->GetForegroundColour()) ;
205 m_windowStyle = lStyle;
206
207 if (vId == -1)
208 m_windowId = NewControlId();
209 else
210 m_windowId = vId;
211
212 int nX = rPos.x;
213 int nY = rPos.y;
214 int nWidth = rSize.x;
215 int nHeight = rSize.y;
216
217 m_nCheckWidth = -1 ;
218 m_nCheckHeight = -1 ;
219// long msStyle = CHECK_FLAGS;
220
221 HWND hButton = 0; // TODO: Create the bitmap checkbox
222
223 m_hWnd = (WXHWND)hButton;
224
225 //
226 // Subclass again for purposes of dialog editing mode
227 //
228 SubclassWin((WXHWND)hButton);
229
230 SetSize( nX
231 ,nY
232 ,nWidth
233 ,nHeight
234 );
235
236 ::WinShowWindow(hButton, TRUE);
237 return TRUE;
238} // end of wxBitmapCheckBox::Create
239
240void wxBitmapCheckBox::SetLabel(
241 const wxBitmap& rBitmap
242)
243{
244 wxFAIL_MSG(wxT("not implemented"));
245} // end of wxBitmapCheckBox::SetLabel
246