]> git.saurik.com Git - wxWidgets.git/blame - src/os2/checkbox.cpp
more non-const string literal warnings correction
[wxWidgets.git] / src / os2 / checkbox.cpp
CommitLineData
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
29IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
0e320a79 31
f289196b
DW
32extern void wxAssociateWinWithHandle( HWND hWnd
33 ,wxWindowOS2* pWin
34 );
35
37f214d5
DW
36// ============================================================================
37// implementation
38// ============================================================================
39
40// ----------------------------------------------------------------------------
41// wxCheckBox
42// ----------------------------------------------------------------------------
43
6670f564
WS
44bool wxCheckBox::OS2Command( WXUINT WXUNUSED(uParam),
45 WXWORD WXUNUSED(wId) )
37f214d5 46{
6670f564 47 wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
5d44b24e
DW
48 rEvent.SetInt(GetValue());
49 rEvent.SetEventObject(this);
50 ProcessCommand(rEvent);
6670f564 51 return true;
5d44b24e
DW
52} // end of wxCheckBox::OS2Command
53
54bool wxCheckBox::Create(
55 wxWindow* pParent
56, wxWindowID vId
57, const wxString& rsLabel
58, const wxPoint& rPos
59, const wxSize& rSize
60, long lStyle
5d44b24e 61, const wxValidator& rValidator
5d44b24e
DW
62, const wxString& rsName
63)
0e320a79 64{
f289196b
DW
65 LONG lColor;
66 bool bOk;
67
a086de98
DW
68 if (!CreateControl( pParent
69 ,vId
70 ,rPos
71 ,rSize
72 ,lStyle
1d0edc0f 73 ,rValidator
a086de98
DW
74 ,rsName
75 ))
76 return FALSE;
77
f289196b 78
a086de98
DW
79 long osStyle = BS_AUTOCHECKBOX |
80 WS_TABSTOP |
81 WS_VISIBLE;
82
f289196b
DW
83 bOk = OS2CreateControl( wxT("BUTTON")
84 ,osStyle
85 ,rPos
86 ,rSize
87 ,rsLabel
88 ,0
89 );
90 m_backgroundColour = pParent->GetBackgroundColour();
91 lColor = (LONG)m_backgroundColour.GetPixel();
92 ::WinSetPresParam( m_hWnd
93 ,PP_BACKGROUNDCOLOR
94 ,sizeof(LONG)
95 ,(PVOID)&lColor
96 );
97 wxAssociateWinWithHandle(m_hWnd, this);
98 return bOk;
5d44b24e 99} // end of wxCheckBox::Create
0e320a79 100
5d44b24e
DW
101void wxCheckBox::SetLabel(
102 const wxString& rsLabel
103)
0e320a79 104{
e94d504d
SN
105 wxString sLabel=::wxPMTextToLabel(rsLabel);
106 ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str());
5d44b24e 107} // end of wxCheckBox::SetLabel
0e320a79 108
e78c4d50 109wxSize wxCheckBox::DoGetBestSize() const
0e320a79 110{
5d44b24e
DW
111 static int nCheckSize = 0;
112
113 if (!nCheckSize)
114 {
115 wxScreenDC vDc;
116
a756f210 117 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
5d44b24e
DW
118
119 //
120 // The height of a standard button in the dialog units is 8,
121 // translate this to pixels (as one dialog unit is precisely equal to
122 // 8 character heights, it's just the char height)
123 //
124 nCheckSize = vDc.GetCharHeight();
125 }
37f214d5 126
6670f564
WS
127 int nWidthCheckbox;
128 int nHeightCheckbox;
129 wxString sStr = wxGetWindowText(GetHWND());
37f214d5 130
6670f564 131 if (!sStr.empty())
37f214d5 132 {
5d44b24e
DW
133 GetTextExtent( sStr
134 ,&nWidthCheckbox
135 ,&nHeightCheckbox
136 );
137 nWidthCheckbox += nCheckSize + GetCharWidth();
37f214d5 138
5d44b24e
DW
139 if (nHeightCheckbox < nCheckSize)
140 nHeightCheckbox = nCheckSize;
37f214d5
DW
141 }
142 else
143 {
5d44b24e
DW
144 nWidthCheckbox = nCheckSize;
145 nHeightCheckbox = nCheckSize;
37f214d5
DW
146 }
147
5d44b24e
DW
148 return wxSize( nWidthCheckbox
149 ,nHeightCheckbox
150 );
151} // end of wxCheckBox::DoGetBestSize
0e320a79 152
5d44b24e
DW
153void wxCheckBox::SetValue(
154 bool bValue
155)
0e320a79 156{
5d44b24e
DW
157 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
158} // end of wxCheckBox::SetValue
0e320a79 159
37f214d5
DW
160#ifndef BST_CHECKED
161#define BST_CHECKED 0x0001
162#endif
163
0e320a79
DW
164bool wxCheckBox::GetValue() const
165{
5d44b24e
DW
166 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
167} // end of wxCheckBox::GetValue
0e320a79 168
5d44b24e
DW
169void wxCheckBox::Command (
170 wxCommandEvent& rEvent
171)
37f214d5 172{
5d44b24e
DW
173 SetValue((rEvent.GetInt() != 0));
174 ProcessCommand(rEvent);
175} // end of wxCheckBox:: Command
0e320a79 176
37f214d5
DW
177// ----------------------------------------------------------------------------
178// wxBitmapCheckBox
179// ----------------------------------------------------------------------------
180
6670f564
WS
181bool wxBitmapCheckBox::Create( wxWindow* pParent,
182 wxWindowID vId,
183 const wxBitmap* WXUNUSED(pLabel),
184 const wxPoint& rPos,
185 const wxSize& rSize,
186 long lStyle,
187 const wxValidator& rValidator,
188 const wxString& rsName)
0e320a79 189{
5d44b24e 190 SetName(rsName);
5d4b632b 191#if wxUSE_VALIDATORS
5d44b24e 192 SetValidator(rValidator);
5d4b632b 193#endif
5d44b24e
DW
194 if (pParent)
195 pParent->AddChild(this);
0e320a79 196
5d44b24e
DW
197 SetBackgroundColour(pParent->GetBackgroundColour()) ;
198 SetForegroundColour(pParent->GetForegroundColour()) ;
199 m_windowStyle = lStyle;
37f214d5 200
5d44b24e 201 if (vId == -1)
0e320a79
DW
202 m_windowId = NewControlId();
203 else
5d44b24e 204 m_windowId = vId;
0e320a79 205
5d44b24e
DW
206 int nX = rPos.x;
207 int nY = rPos.y;
208 int nWidth = rSize.x;
209 int nHeight = rSize.y;
0e320a79 210
5d44b24e
DW
211 m_nCheckWidth = -1 ;
212 m_nCheckHeight = -1 ;
892b89f3 213// long msStyle = CHECK_FLAGS;
0e320a79 214
5d44b24e 215 HWND hButton = 0; // TODO: Create the bitmap checkbox
0e320a79 216
5d44b24e 217 m_hWnd = (WXHWND)hButton;
0e320a79 218
5d44b24e 219 //
37f214d5 220 // Subclass again for purposes of dialog editing mode
5d44b24e
DW
221 //
222 SubclassWin((WXHWND)hButton);
37f214d5 223
5d44b24e
DW
224 SetSize( nX
225 ,nY
226 ,nWidth
227 ,nHeight
228 );
37f214d5 229
5d44b24e 230 ::WinShowWindow(hButton, TRUE);
6670f564 231 return true;
5d44b24e 232} // end of wxBitmapCheckBox::Create
0e320a79 233
6670f564 234void wxBitmapCheckBox::SetLabel( const wxBitmap& WXUNUSED(rBitmap) )
0e320a79 235{
37f214d5 236 wxFAIL_MSG(wxT("not implemented"));
5d44b24e 237} // end of wxBitmapCheckBox::SetLabel