]> git.saurik.com Git - wxWidgets.git/blame - src/os2/radiobut.cpp
Some things needed in the base class of OS/2
[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;
84 m_hWnd = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
85 ,WC_BUTTON
86 ,rsLabel.c_str()
87 ,lsStyle
88 ,0, 0, 0, 0
89 ,GetWinHwnd(pParent)
90 ,HWND_TOP
91 ,(HMENU)m_windowId
92 ,NULL
93 ,NULL
94 );
95 wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create radiobutton"));
cdf1e714 96
3c299c3a 97 if (rsLabel != wxT(""))
cdf1e714 98 {
3c299c3a
DW
99 int nLabelWidth;
100 int nLabelHeight;
101
102 GetTextExtent( rsLabel
103 ,&nLabelWidth
104 ,&nLabelHeight
105 ,NULL
106 ,NULL
107 ,&this->GetFont()
108 );
109 if (nWidth < 0)
110 nWidth = (int)(nLabelWidth + RADIO_SIZE);
111 if (nHeight<0)
112 {
113 nHeight = (int)(nLabelHeight);
114 if (nHeight < RADIO_SIZE)
115 nHeight = RADIO_SIZE;
116 }
117 }
118 else
119 {
120 if (nWidth < 0)
121 nWidth = RADIO_SIZE;
122 if (nHeight < 0)
123 nHeight = RADIO_SIZE;
cdf1e714 124 }
0e320a79 125
3c299c3a
DW
126 //
127 // Subclass again for purposes of dialog editing mode
128 //
129 SubclassWin((WXHWND)m_hWnd);
130 SetFont(pParent->GetFont());
131 SetSize( nX
132 ,nY
133 ,nWidth
134 ,nHeight
135 );
136 return FALSE;
137} // end of wxRadioButton::Create
0e320a79 138
3c299c3a 139//
0e320a79 140// Get single selection, for single choice list items
3c299c3a 141//
0e320a79
DW
142bool wxRadioButton::GetValue() const
143{
3c299c3a
DW
144 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
145} // end of wxRadioButton::GetValue
0e320a79 146
3c299c3a
DW
147bool wxRadioButton::OS2Command(
148 WXUINT wParam
149, WXWORD wId
150)
cdf1e714 151{
3c299c3a
DW
152 if (wParam == BN_CLICKED)
153 {
154 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
155 ,m_windowId
156 );
cdf1e714 157
3c299c3a
DW
158 rEvent.SetEventObject(this);
159 ProcessCommand(rEvent);
160 return TRUE;
161 }
162 else
163 return FALSE;
164} // end of wxRadioButton::OS2Command
cdf1e714 165
3c299c3a
DW
166void wxRadioButton::SetLabel(
167 const wxString& rsLabel
168)
cdf1e714 169{
3c299c3a
DW
170 ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str());
171} // end of wxRadioButton::SetLabel
cdf1e714 172
3c299c3a
DW
173void wxRadioButton::SetValue(
174 bool bValue
175)
cdf1e714 176{
3c299c3a
DW
177 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
178} // end of wxRadioButton::SetValue
0e320a79 179