]> git.saurik.com Git - wxWidgets.git/blame - src/os2/radiobut.cpp
OS/2 Statusbar fixes in DC
[wxWidgets.git] / src / os2 / radiobut.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose: wxRadioButton
cdf1e714 4// Author: David Webster
0e320a79 5// Modified by:
cdf1e714 6// Created: 10/12/99
0e320a79 7// RCS-ID: $Id$
cdf1e714
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
cdf1e714
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
0e320a79
DW
17#endif
18
cdf1e714
DW
19#ifndef WX_PRECOMP
20#include <stdio.h>
21#include "wx/setup.h"
0e320a79 22#include "wx/radiobut.h"
cdf1e714
DW
23#include "wx/brush.h"
24#endif
25
11e59d47 26#include "wx/os2/private.h"
0e320a79 27
0e320a79 28IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
0e320a79 29
3c299c3a
DW
30void wxRadioButton::Command (
31 wxCommandEvent& rEvent
32)
cdf1e714 33{
3c299c3a
DW
34 SetValue ((rEvent.GetInt() != 0) );
35 ProcessCommand (rEvent);
36} // end of wxRadioButton::Command
37
38bool wxRadioButton::Create(
39 wxWindow* pParent
40, wxWindowID vId
41, const wxString& rsLabel
42, const wxPoint& rPos
43, const wxSize& rSize
44, long lStyle
5d4b632b 45#if wxUSE_VALIDATORS
3c299c3a 46, const wxValidator& rValidator
5d4b632b 47#endif
3c299c3a
DW
48, const wxString& rsName
49)
0e320a79 50{
3c299c3a
DW
51 int nX = rPos.x;
52 int nY = rPos.y;
53 int nWidth = rSize.x;
54 int nHeight = rSize.y;
55 long lsStyle = 0L;
56 long lGroupStyle = 0L;
57
58 SetName(rsName);
5d4b632b 59#if wxUSE_VALIDATORS
3c299c3a 60 SetValidator(rValidator);
5d4b632b 61#endif
0e320a79 62
3c299c3a
DW
63 if (pParent)
64 pParent->AddChild(this);
0e320a79 65
3c299c3a
DW
66 SetBackgroundColour(pParent->GetBackgroundColour());
67 SetForegroundColour(pParent->GetForegroundColour());
cdf1e714 68
3c299c3a 69 if (vId == -1)
cdf1e714 70 m_windowId = (int)NewControlId();
0e320a79 71 else
3c299c3a 72 m_windowId = vId;
cdf1e714 73
0e320a79 74
3c299c3a 75 m_windowStyle = lStyle ;
0e320a79 76
3c299c3a
DW
77 if (m_windowStyle & wxRB_GROUP)
78 lGroupStyle = WS_GROUP;
cdf1e714 79
3c299c3a 80 lsStyle = lGroupStyle | BS_AUTORADIOBUTTON | WS_VISIBLE ;
cdf1e714 81
3c299c3a
DW
82 if (m_windowStyle & wxCLIP_SIBLINGS )
83 lsStyle |= WS_CLIPSIBLINGS;
5d44b24e
DW
84 //
85 // If the parent is a scrolled window the controls must
86 // have this style or they will overlap the scrollbars
87 //
88 if (pParent)
89 if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) ||
90 pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)))
91 lsStyle |= WS_CLIPSIBLINGS;
92
3c299c3a
DW
93 m_hWnd = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
94 ,WC_BUTTON
95 ,rsLabel.c_str()
96 ,lsStyle
97 ,0, 0, 0, 0
98 ,GetWinHwnd(pParent)
99 ,HWND_TOP
100 ,(HMENU)m_windowId
101 ,NULL
102 ,NULL
103 );
104 wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create radiobutton"));
cdf1e714 105
3c299c3a 106 if (rsLabel != wxT(""))
cdf1e714 107 {
3c299c3a
DW
108 int nLabelWidth;
109 int nLabelHeight;
110
111 GetTextExtent( rsLabel
112 ,&nLabelWidth
113 ,&nLabelHeight
114 ,NULL
115 ,NULL
116 ,&this->GetFont()
117 );
118 if (nWidth < 0)
119 nWidth = (int)(nLabelWidth + RADIO_SIZE);
120 if (nHeight<0)
121 {
122 nHeight = (int)(nLabelHeight);
123 if (nHeight < RADIO_SIZE)
124 nHeight = RADIO_SIZE;
125 }
126 }
127 else
128 {
129 if (nWidth < 0)
130 nWidth = RADIO_SIZE;
131 if (nHeight < 0)
132 nHeight = RADIO_SIZE;
cdf1e714 133 }
0e320a79 134
3c299c3a
DW
135 //
136 // Subclass again for purposes of dialog editing mode
137 //
138 SubclassWin((WXHWND)m_hWnd);
139 SetFont(pParent->GetFont());
140 SetSize( nX
141 ,nY
142 ,nWidth
143 ,nHeight
144 );
145 return FALSE;
146} // end of wxRadioButton::Create
0e320a79 147
3c299c3a 148//
0e320a79 149// Get single selection, for single choice list items
3c299c3a 150//
0e320a79
DW
151bool wxRadioButton::GetValue() const
152{
3c299c3a
DW
153 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
154} // end of wxRadioButton::GetValue
0e320a79 155
3c299c3a
DW
156bool wxRadioButton::OS2Command(
157 WXUINT wParam
158, WXWORD wId
159)
cdf1e714 160{
3c299c3a
DW
161 if (wParam == BN_CLICKED)
162 {
163 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
164 ,m_windowId
165 );
cdf1e714 166
3c299c3a
DW
167 rEvent.SetEventObject(this);
168 ProcessCommand(rEvent);
169 return TRUE;
170 }
171 else
172 return FALSE;
173} // end of wxRadioButton::OS2Command
cdf1e714 174
3c299c3a
DW
175void wxRadioButton::SetLabel(
176 const wxString& rsLabel
177)
cdf1e714 178{
3c299c3a
DW
179 ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str());
180} // end of wxRadioButton::SetLabel
cdf1e714 181
3c299c3a
DW
182void wxRadioButton::SetValue(
183 bool bValue
184)
cdf1e714 185{
3c299c3a
DW
186 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
187} // end of wxRadioButton::SetValue
0e320a79 188