]> git.saurik.com Git - wxWidgets.git/blame - src/os2/checkbox.cpp
disable shared libs for DJGPP (who broke this?)
[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{
5d44b24e 67 SetName(rsName);
5d4b632b 68#if wxUSE_VALIDATORS
5d44b24e 69 SetValidator(rValidator);
5d4b632b 70#endif
5d44b24e
DW
71 if (pParent)
72 pParent->AddChild(this);
37f214d5 73
5d44b24e
DW
74 SetBackgroundColour(pParent->GetBackgroundColour());
75 SetForegroundColour(pParent->GetForegroundColour());
76 m_windowStyle = lStyle;
37f214d5 77
5d44b24e 78 wxString sLabel = rsLabel;
0e320a79 79
5d44b24e
DW
80 if (sLabel == wxT(""))
81 sLabel = wxT(" "); // Apparently needed or checkbox won't show
0e320a79 82
5d44b24e 83 if (vId == -1 )
0e320a79
DW
84 m_windowId = NewControlId();
85 else
5d44b24e
DW
86 m_windowId = vId;
87
88 int nX = rPos.x;
89 int nY = rPos.y;
90 int nWidth = rSize.x;
91 int nHeight = rSize.y;
92 long lSstyle = 0L;
93
94 lSstyle = BS_AUTOCHECKBOX |
95 WS_TABSTOP |
96 WS_VISIBLE;
97 if (lStyle & wxCLIP_SIBLINGS )
98 lSstyle |= WS_CLIPSIBLINGS;
99
5d44b24e
DW
100 m_hWnd = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
101 ,WC_BUTTON
102 ,rsLabel.c_str()
103 ,lSstyle
104 ,0, 0, 0, 0
105 ,GetWinHwnd(pParent)
106 ,HWND_TOP
107 ,(HMENU)m_windowId
108 ,NULL
109 ,NULL
110 );
111
112 //
37f214d5 113 // Subclass again for purposes of dialog editing mode
5d44b24e 114 //
37f214d5
DW
115 SubclassWin(m_hWnd);
116
7993e67c
DW
117 LONG lColor = (LONG)m_backgroundColour.GetPixel();
118
119 ::WinSetPresParam( m_hWnd
120 ,PP_BACKGROUNDCOLOR
121 ,sizeof(LONG)
122 ,(PVOID)&lColor
123 );
124
b3260bce
DW
125 wxFont* pTextFont = new wxFont( 10
126 ,wxMODERN
127 ,wxNORMAL
128 ,wxNORMAL
129 );
130 SetFont(*pTextFont);
5d44b24e
DW
131 SetSize( nX
132 ,nY
133 ,nWidth
134 ,nHeight
135 );
b3260bce 136 delete pTextFont;
5d44b24e
DW
137 return TRUE;
138} // end of wxCheckBox::Create
0e320a79 139
5d44b24e
DW
140void wxCheckBox::SetLabel(
141 const wxString& rsLabel
142)
0e320a79 143{
5d44b24e
DW
144 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
145} // end of wxCheckBox::SetLabel
0e320a79 146
e78c4d50 147wxSize wxCheckBox::DoGetBestSize() const
0e320a79 148{
5d44b24e
DW
149 static int nCheckSize = 0;
150
151 if (!nCheckSize)
152 {
153 wxScreenDC vDc;
154
a756f210 155 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
5d44b24e
DW
156
157 //
158 // The height of a standard button in the dialog units is 8,
159 // translate this to pixels (as one dialog unit is precisely equal to
160 // 8 character heights, it's just the char height)
161 //
162 nCheckSize = vDc.GetCharHeight();
163 }
37f214d5 164
5d44b24e
DW
165 int nWidthCheckbox;
166 int nHeightCheckbox;
167 wxString sStr = wxGetWindowText(GetHWND());
37f214d5 168
5d44b24e 169 if (!sStr.IsEmpty())
37f214d5 170 {
5d44b24e
DW
171 GetTextExtent( sStr
172 ,&nWidthCheckbox
173 ,&nHeightCheckbox
174 );
175 nWidthCheckbox += nCheckSize + GetCharWidth();
37f214d5 176
5d44b24e
DW
177 if (nHeightCheckbox < nCheckSize)
178 nHeightCheckbox = nCheckSize;
37f214d5
DW
179 }
180 else
181 {
5d44b24e
DW
182 nWidthCheckbox = nCheckSize;
183 nHeightCheckbox = nCheckSize;
37f214d5
DW
184 }
185
5d44b24e
DW
186 return wxSize( nWidthCheckbox
187 ,nHeightCheckbox
188 );
189} // end of wxCheckBox::DoGetBestSize
0e320a79 190
5d44b24e
DW
191void wxCheckBox::SetValue(
192 bool bValue
193)
0e320a79 194{
5d44b24e
DW
195 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
196} // end of wxCheckBox::SetValue
0e320a79 197
37f214d5
DW
198#ifndef BST_CHECKED
199#define BST_CHECKED 0x0001
200#endif
201
0e320a79
DW
202bool wxCheckBox::GetValue() const
203{
5d44b24e
DW
204 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
205} // end of wxCheckBox::GetValue
0e320a79 206
5d44b24e
DW
207void wxCheckBox::Command (
208 wxCommandEvent& rEvent
209)
37f214d5 210{
5d44b24e
DW
211 SetValue((rEvent.GetInt() != 0));
212 ProcessCommand(rEvent);
213} // end of wxCheckBox:: Command
0e320a79 214
37f214d5
DW
215// ----------------------------------------------------------------------------
216// wxBitmapCheckBox
217// ----------------------------------------------------------------------------
218
5d44b24e
DW
219bool wxBitmapCheckBox::Create(
220 wxWindow* pParent
221, wxWindowID vId
222, const wxBitmap* pLabel
223, const wxPoint& rPos
224, const wxSize& rSize
225, long lStyle
5d4b632b 226#if wxUSE_VALIDATORS
5d44b24e 227, const wxValidator& rValidator
5d4b632b 228#endif
5d44b24e
DW
229, const wxString& rsName
230)
0e320a79 231{
5d44b24e 232 SetName(rsName);
5d4b632b 233#if wxUSE_VALIDATORS
5d44b24e 234 SetValidator(rValidator);
5d4b632b 235#endif
5d44b24e
DW
236 if (pParent)
237 pParent->AddChild(this);
0e320a79 238
5d44b24e
DW
239 SetBackgroundColour(pParent->GetBackgroundColour()) ;
240 SetForegroundColour(pParent->GetForegroundColour()) ;
241 m_windowStyle = lStyle;
37f214d5 242
5d44b24e 243 if (vId == -1)
0e320a79
DW
244 m_windowId = NewControlId();
245 else
5d44b24e 246 m_windowId = vId;
0e320a79 247
5d44b24e
DW
248 int nX = rPos.x;
249 int nY = rPos.y;
250 int nWidth = rSize.x;
251 int nHeight = rSize.y;
0e320a79 252
5d44b24e
DW
253 m_nCheckWidth = -1 ;
254 m_nCheckHeight = -1 ;
892b89f3 255// long msStyle = CHECK_FLAGS;
0e320a79 256
5d44b24e 257 HWND hButton = 0; // TODO: Create the bitmap checkbox
0e320a79 258
5d44b24e 259 m_hWnd = (WXHWND)hButton;
0e320a79 260
5d44b24e 261 //
37f214d5 262 // Subclass again for purposes of dialog editing mode
5d44b24e
DW
263 //
264 SubclassWin((WXHWND)hButton);
37f214d5 265
5d44b24e
DW
266 SetSize( nX
267 ,nY
268 ,nWidth
269 ,nHeight
270 );
37f214d5 271
5d44b24e 272 ::WinShowWindow(hButton, TRUE);
37f214d5 273 return TRUE;
5d44b24e 274} // end of wxBitmapCheckBox::Create
0e320a79 275
5d44b24e
DW
276void wxBitmapCheckBox::SetLabel(
277 const wxBitmap& rBitmap
278)
0e320a79 279{
37f214d5 280 wxFAIL_MSG(wxT("not implemented"));
5d44b24e 281} // end of wxBitmapCheckBox::SetLabel
0e320a79 282