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