]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/radiobut.cpp
don't assign string literals to a char * variable
[wxWidgets.git] / src / os2 / radiobut.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose: wxRadioButton
4// Author: David Webster
5// Modified by:
6// Created: 10/12/99
7// RCS-ID: $Id$
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include <stdio.h>
21#include "wx/setup.h"
22#include "wx/radiobut.h"
23#include "wx/brush.h"
24#endif
25
26#include "wx/os2/private.h"
27
28IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
29
30void wxRadioButton::Command (
31 wxCommandEvent& rEvent
32)
33{
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
45#if wxUSE_VALIDATORS
46, const wxValidator& rValidator
47#endif
48, const wxString& rsName
49)
50{
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);
59#if wxUSE_VALIDATORS
60 SetValidator(rValidator);
61#endif
62
63 if (pParent)
64 pParent->AddChild(this);
65
66 SetBackgroundColour(pParent->GetBackgroundColour());
67 SetForegroundColour(pParent->GetForegroundColour());
68
69 if (vId == -1)
70 m_windowId = (int)NewControlId();
71 else
72 m_windowId = vId;
73
74
75 m_windowStyle = lStyle ;
76
77 if (m_windowStyle & wxRB_GROUP)
78 lGroupStyle = WS_GROUP;
79
80 lsStyle = lGroupStyle | BS_AUTORADIOBUTTON | WS_VISIBLE ;
81
82 if (m_windowStyle & wxCLIP_SIBLINGS )
83 lsStyle |= WS_CLIPSIBLINGS;
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
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"));
105
106 if (rsLabel != wxT(""))
107 {
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;
133 }
134
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
147
148//
149// Get single selection, for single choice list items
150//
151bool wxRadioButton::GetValue() const
152{
153 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
154} // end of wxRadioButton::GetValue
155
156bool wxRadioButton::OS2Command(
157 WXUINT wParam
158, WXWORD wId
159)
160{
161 if (wParam == BN_CLICKED)
162 {
163 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
164 ,m_windowId
165 );
166
167 rEvent.SetEventObject(this);
168 ProcessCommand(rEvent);
169 return TRUE;
170 }
171 else
172 return FALSE;
173} // end of wxRadioButton::OS2Command
174
175void wxRadioButton::SetLabel(
176 const wxString& rsLabel
177)
178{
179 ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str());
180} // end of wxRadioButton::SetLabel
181
182void wxRadioButton::SetValue(
183 bool bValue
184)
185{
186 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
187} // end of wxRadioButton::SetValue
188