]> git.saurik.com Git - wxWidgets.git/blame - src/os2/checkbox.cpp
Fix after removal of PRIOR/NEXT in common headers (duplicates change in GTK2 sources).
[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{
c5f975dd
SN
111 // We should probably compute nCheckSize but it seems to be a constant
112 // independent of its label's font size and not made available by OS/2.
113 int nCheckSize = RADIO_SIZE;
6670f564
WS
114 int nWidthCheckbox;
115 int nHeightCheckbox;
116 wxString sStr = wxGetWindowText(GetHWND());
37f214d5 117
6670f564 118 if (!sStr.empty())
37f214d5 119 {
5d44b24e
DW
120 GetTextExtent( sStr
121 ,&nWidthCheckbox
122 ,&nHeightCheckbox
123 );
c5f975dd 124 nWidthCheckbox += nCheckSize;
37f214d5 125
5d44b24e
DW
126 if (nHeightCheckbox < nCheckSize)
127 nHeightCheckbox = nCheckSize;
37f214d5
DW
128 }
129 else
130 {
5d44b24e
DW
131 nWidthCheckbox = nCheckSize;
132 nHeightCheckbox = nCheckSize;
37f214d5
DW
133 }
134
5d44b24e
DW
135 return wxSize( nWidthCheckbox
136 ,nHeightCheckbox
137 );
138} // end of wxCheckBox::DoGetBestSize
0e320a79 139
5d44b24e
DW
140void wxCheckBox::SetValue(
141 bool bValue
142)
0e320a79 143{
5d44b24e
DW
144 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
145} // end of wxCheckBox::SetValue
0e320a79 146
37f214d5
DW
147#ifndef BST_CHECKED
148#define BST_CHECKED 0x0001
149#endif
150
0e320a79
DW
151bool wxCheckBox::GetValue() const
152{
5d44b24e
DW
153 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
154} // end of wxCheckBox::GetValue
0e320a79 155
5d44b24e
DW
156void wxCheckBox::Command (
157 wxCommandEvent& rEvent
158)
37f214d5 159{
5d44b24e
DW
160 SetValue((rEvent.GetInt() != 0));
161 ProcessCommand(rEvent);
162} // end of wxCheckBox:: Command
0e320a79 163
37f214d5
DW
164// ----------------------------------------------------------------------------
165// wxBitmapCheckBox
166// ----------------------------------------------------------------------------
167
6670f564
WS
168bool wxBitmapCheckBox::Create( wxWindow* pParent,
169 wxWindowID vId,
170 const wxBitmap* WXUNUSED(pLabel),
171 const wxPoint& rPos,
172 const wxSize& rSize,
173 long lStyle,
174 const wxValidator& rValidator,
175 const wxString& rsName)
0e320a79 176{
5d44b24e 177 SetName(rsName);
5d4b632b 178#if wxUSE_VALIDATORS
5d44b24e 179 SetValidator(rValidator);
5d4b632b 180#endif
5d44b24e
DW
181 if (pParent)
182 pParent->AddChild(this);
0e320a79 183
5d44b24e
DW
184 SetBackgroundColour(pParent->GetBackgroundColour()) ;
185 SetForegroundColour(pParent->GetForegroundColour()) ;
186 m_windowStyle = lStyle;
37f214d5 187
5d44b24e 188 if (vId == -1)
0e320a79
DW
189 m_windowId = NewControlId();
190 else
5d44b24e 191 m_windowId = vId;
0e320a79 192
5d44b24e
DW
193 int nX = rPos.x;
194 int nY = rPos.y;
195 int nWidth = rSize.x;
196 int nHeight = rSize.y;
0e320a79 197
5d44b24e
DW
198 m_nCheckWidth = -1 ;
199 m_nCheckHeight = -1 ;
892b89f3 200// long msStyle = CHECK_FLAGS;
0e320a79 201
5d44b24e 202 HWND hButton = 0; // TODO: Create the bitmap checkbox
0e320a79 203
5d44b24e 204 m_hWnd = (WXHWND)hButton;
0e320a79 205
5d44b24e 206 //
37f214d5 207 // Subclass again for purposes of dialog editing mode
5d44b24e
DW
208 //
209 SubclassWin((WXHWND)hButton);
37f214d5 210
5d44b24e
DW
211 SetSize( nX
212 ,nY
213 ,nWidth
214 ,nHeight
215 );
37f214d5 216
5d44b24e 217 ::WinShowWindow(hButton, TRUE);
6670f564 218 return true;
5d44b24e 219} // end of wxBitmapCheckBox::Create
0e320a79 220
6670f564 221void wxBitmapCheckBox::SetLabel( const wxBitmap& WXUNUSED(rBitmap) )
0e320a79 222{
37f214d5 223 wxFAIL_MSG(wxT("not implemented"));
5d44b24e 224} // end of wxBitmapCheckBox::SetLabel