]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/checkbox.cpp
compilation fix
[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 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
110} // end of wxCheckBox::SetLabel
111
112wxSize wxCheckBox::DoGetBestSize() const
113{
114 static int nCheckSize = 0;
115
116 if (!nCheckSize)
117 {
118 wxScreenDC vDc;
119
120 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
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 }
129
130 int nWidthCheckbox;
131 int nHeightCheckbox;
132 wxString sStr = wxGetWindowText(GetHWND());
133
134 if (!sStr.IsEmpty())
135 {
136 GetTextExtent( sStr
137 ,&nWidthCheckbox
138 ,&nHeightCheckbox
139 );
140 nWidthCheckbox += nCheckSize + GetCharWidth();
141
142 if (nHeightCheckbox < nCheckSize)
143 nHeightCheckbox = nCheckSize;
144 }
145 else
146 {
147 nWidthCheckbox = nCheckSize;
148 nHeightCheckbox = nCheckSize;
149 }
150
151 return wxSize( nWidthCheckbox
152 ,nHeightCheckbox
153 );
154} // end of wxCheckBox::DoGetBestSize
155
156void wxCheckBox::SetValue(
157 bool bValue
158)
159{
160 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
161} // end of wxCheckBox::SetValue
162
163#ifndef BST_CHECKED
164#define BST_CHECKED 0x0001
165#endif
166
167bool wxCheckBox::GetValue() const
168{
169 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
170} // end of wxCheckBox::GetValue
171
172void wxCheckBox::Command (
173 wxCommandEvent& rEvent
174)
175{
176 SetValue((rEvent.GetInt() != 0));
177 ProcessCommand(rEvent);
178} // end of wxCheckBox:: Command
179
180// ----------------------------------------------------------------------------
181// wxBitmapCheckBox
182// ----------------------------------------------------------------------------
183
184bool wxBitmapCheckBox::Create(
185 wxWindow* pParent
186, wxWindowID vId
187, const wxBitmap* pLabel
188, const wxPoint& rPos
189, const wxSize& rSize
190, long lStyle
191, const wxValidator& rValidator
192, const wxString& rsName
193)
194{
195 SetName(rsName);
196#if wxUSE_VALIDATORS
197 SetValidator(rValidator);
198#endif
199 if (pParent)
200 pParent->AddChild(this);
201
202 SetBackgroundColour(pParent->GetBackgroundColour()) ;
203 SetForegroundColour(pParent->GetForegroundColour()) ;
204 m_windowStyle = lStyle;
205
206 if (vId == -1)
207 m_windowId = NewControlId();
208 else
209 m_windowId = vId;
210
211 int nX = rPos.x;
212 int nY = rPos.y;
213 int nWidth = rSize.x;
214 int nHeight = rSize.y;
215
216 m_nCheckWidth = -1 ;
217 m_nCheckHeight = -1 ;
218// long msStyle = CHECK_FLAGS;
219
220 HWND hButton = 0; // TODO: Create the bitmap checkbox
221
222 m_hWnd = (WXHWND)hButton;
223
224 //
225 // Subclass again for purposes of dialog editing mode
226 //
227 SubclassWin((WXHWND)hButton);
228
229 SetSize( nX
230 ,nY
231 ,nWidth
232 ,nHeight
233 );
234
235 ::WinShowWindow(hButton, TRUE);
236 return TRUE;
237} // end of wxBitmapCheckBox::Create
238
239void wxBitmapCheckBox::SetLabel(
240 const wxBitmap& rBitmap
241)
242{
243 wxFAIL_MSG(wxT("not implemented"));
244} // end of wxBitmapCheckBox::SetLabel
245