]> git.saurik.com Git - wxWidgets.git/blame - src/os2/checkbox.cpp
Deallocate wxThreadSpecificInfo when wxThread ends.
[wxWidgets.git] / src / os2 / checkbox.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
ab1ce969 2// Name: src/os2/checkbox.cpp
0e320a79 3// Purpose: wxCheckBox
37f214d5 4// Author: David Webster
0e320a79 5// Modified by:
37f214d5 6// Created: 10/13/99
37f214d5 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
37f214d5
DW
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
ab1ce969
WS
14#include "wx/checkbox.h"
15
37f214d5 16#ifndef WX_PRECOMP
37f214d5 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 29IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
0e320a79 30
f289196b
DW
31extern void wxAssociateWinWithHandle( HWND hWnd
32 ,wxWindowOS2* pWin
33 );
34
37f214d5
DW
35// ============================================================================
36// implementation
37// ============================================================================
38
39// ----------------------------------------------------------------------------
40// wxCheckBox
41// ----------------------------------------------------------------------------
42
6670f564
WS
43bool wxCheckBox::OS2Command( WXUINT WXUNUSED(uParam),
44 WXWORD WXUNUSED(wId) )
37f214d5 45{
ce7fe42e 46 wxCommandEvent rEvent( wxEVT_CHECKBOX, m_windowId );
5d44b24e
DW
47 rEvent.SetInt(GetValue());
48 rEvent.SetEventObject(this);
49 ProcessCommand(rEvent);
6670f564 50 return true;
5d44b24e
DW
51} // end of wxCheckBox::OS2Command
52
ab1ce969
WS
53bool wxCheckBox::Create(wxWindow* pParent,
54 wxWindowID vId,
55 const wxString& rsLabel,
56 const wxPoint& rPos,
57 const wxSize& rSize,
58 long lStyle,
59 const wxValidator& rValidator,
60 const wxString& rsName )
0e320a79 61{
a086de98
DW
62 if (!CreateControl( pParent
63 ,vId
64 ,rPos
65 ,rSize
66 ,lStyle
1d0edc0f 67 ,rValidator
a086de98
DW
68 ,rsName
69 ))
ab1ce969 70 return false;
a086de98 71
f289196b 72
ab1ce969 73 long osStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_VISIBLE;
a086de98 74
ab1ce969 75 bool bOk = OS2CreateControl( wxT("BUTTON")
f289196b
DW
76 ,osStyle
77 ,rPos
78 ,rSize
79 ,rsLabel
80 ,0
81 );
82 m_backgroundColour = pParent->GetBackgroundColour();
ab1ce969
WS
83
84 LONG lColor = (LONG)m_backgroundColour.GetPixel();
f289196b
DW
85 ::WinSetPresParam( m_hWnd
86 ,PP_BACKGROUNDCOLOR
87 ,sizeof(LONG)
88 ,(PVOID)&lColor
89 );
90 wxAssociateWinWithHandle(m_hWnd, this);
91 return bOk;
5d44b24e 92} // end of wxCheckBox::Create
0e320a79 93
ab1ce969 94void wxCheckBox::SetLabel( const wxString& rsLabel )
0e320a79 95{
ab1ce969 96 wxString sLabel=::wxPMTextToLabel(rsLabel);
65f3f920 97 ::WinSetWindowText(GetHwnd(), sLabel.c_str());
5d44b24e 98} // end of wxCheckBox::SetLabel
0e320a79 99
e78c4d50 100wxSize wxCheckBox::DoGetBestSize() const
0e320a79 101{
c5f975dd
SN
102 // We should probably compute nCheckSize but it seems to be a constant
103 // independent of its label's font size and not made available by OS/2.
104 int nCheckSize = RADIO_SIZE;
6670f564
WS
105 int nWidthCheckbox;
106 int nHeightCheckbox;
107 wxString sStr = wxGetWindowText(GetHWND());
37f214d5 108
6670f564 109 if (!sStr.empty())
37f214d5 110 {
5d44b24e
DW
111 GetTextExtent( sStr
112 ,&nWidthCheckbox
113 ,&nHeightCheckbox
114 );
c5f975dd 115 nWidthCheckbox += nCheckSize;
37f214d5 116
5d44b24e
DW
117 if (nHeightCheckbox < nCheckSize)
118 nHeightCheckbox = nCheckSize;
37f214d5
DW
119 }
120 else
121 {
5d44b24e
DW
122 nWidthCheckbox = nCheckSize;
123 nHeightCheckbox = nCheckSize;
37f214d5
DW
124 }
125
ab1ce969 126 return wxSize( nWidthCheckbox, nHeightCheckbox );
5d44b24e 127} // end of wxCheckBox::DoGetBestSize
0e320a79 128
ab1ce969 129void wxCheckBox::SetValue( bool bValue )
0e320a79 130{
5d44b24e
DW
131 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
132} // end of wxCheckBox::SetValue
0e320a79 133
37f214d5
DW
134#ifndef BST_CHECKED
135#define BST_CHECKED 0x0001
136#endif
137
0e320a79
DW
138bool wxCheckBox::GetValue() const
139{
5d44b24e
DW
140 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
141} // end of wxCheckBox::GetValue
0e320a79 142
ab1ce969 143void wxCheckBox::Command ( wxCommandEvent& rEvent )
37f214d5 144{
5d44b24e
DW
145 SetValue((rEvent.GetInt() != 0));
146 ProcessCommand(rEvent);
147} // end of wxCheckBox:: Command
0e320a79 148
37f214d5
DW
149// ----------------------------------------------------------------------------
150// wxBitmapCheckBox
151// ----------------------------------------------------------------------------
152
6670f564
WS
153bool wxBitmapCheckBox::Create( wxWindow* pParent,
154 wxWindowID vId,
155 const wxBitmap* WXUNUSED(pLabel),
156 const wxPoint& rPos,
157 const wxSize& rSize,
158 long lStyle,
159 const wxValidator& rValidator,
160 const wxString& rsName)
0e320a79 161{
5d44b24e 162 SetName(rsName);
5d4b632b 163#if wxUSE_VALIDATORS
5d44b24e 164 SetValidator(rValidator);
5d4b632b 165#endif
5d44b24e
DW
166 if (pParent)
167 pParent->AddChild(this);
0e320a79 168
5d44b24e
DW
169 SetBackgroundColour(pParent->GetBackgroundColour()) ;
170 SetForegroundColour(pParent->GetForegroundColour()) ;
171 m_windowStyle = lStyle;
37f214d5 172
5d44b24e 173 if (vId == -1)
0e320a79
DW
174 m_windowId = NewControlId();
175 else
5d44b24e 176 m_windowId = vId;
0e320a79 177
5d44b24e
DW
178 int nX = rPos.x;
179 int nY = rPos.y;
180 int nWidth = rSize.x;
181 int nHeight = rSize.y;
0e320a79 182
5d44b24e
DW
183 m_nCheckWidth = -1 ;
184 m_nCheckHeight = -1 ;
892b89f3 185// long msStyle = CHECK_FLAGS;
0e320a79 186
5d44b24e 187 HWND hButton = 0; // TODO: Create the bitmap checkbox
0e320a79 188
5d44b24e 189 m_hWnd = (WXHWND)hButton;
0e320a79 190
5d44b24e 191 //
37f214d5 192 // Subclass again for purposes of dialog editing mode
5d44b24e
DW
193 //
194 SubclassWin((WXHWND)hButton);
37f214d5 195
5d44b24e
DW
196 SetSize( nX
197 ,nY
198 ,nWidth
199 ,nHeight
200 );
37f214d5 201
5d44b24e 202 ::WinShowWindow(hButton, TRUE);
6670f564 203 return true;
5d44b24e 204} // end of wxBitmapCheckBox::Create
0e320a79 205
6670f564 206void wxBitmapCheckBox::SetLabel( const wxBitmap& WXUNUSED(rBitmap) )
0e320a79 207{
37f214d5 208 wxFAIL_MSG(wxT("not implemented"));
5d44b24e 209} // end of wxBitmapCheckBox::SetLabel