]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/radiobut.cpp
wxFileCtrl::Update was hiding wxWindow::Update
[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#include "wx/dcscreen.h"
25#include "wx/settings.h"
26#endif
27
28#include "wx/os2/private.h"
29
30IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
31
32void wxRadioButton::Init()
33{
34 m_bFocusJustSet = FALSE;
35} // end of wxRadioButton::Init
36
37void wxRadioButton::Command (
38 wxCommandEvent& rEvent
39)
40{
41 SetValue ((rEvent.GetInt() != 0) );
42 ProcessCommand (rEvent);
43} // end of wxRadioButton::Command
44
45bool wxRadioButton::Create(
46 wxWindow* pParent
47, wxWindowID vId
48, const wxString& rsLabel
49, const wxPoint& rPos
50, const wxSize& rSize
51, long lStyle
52#if wxUSE_VALIDATORS
53, const wxValidator& rValidator
54#endif
55, const wxString& rsName
56)
57{
58 if ( !CreateControl( pParent
59 ,vId
60 ,rPos
61 ,rSize
62 ,lStyle
63#if wxUSE_VALIDATORS
64 ,rValidator
65#endif
66 ,rsName))
67 return FALSE;
68
69 long lSstyle = HasFlag(wxRB_GROUP) ? WS_GROUP : 0;
70
71 lSstyle |= BS_AUTORADIOBUTTON;
72
73 if (HasFlag(wxCLIP_SIBLINGS))
74 lSstyle |= WS_CLIPSIBLINGS;
75
76 if (!OS2CreateControl( _T("BUTTON")
77 ,lSstyle
78 ,rPos
79 ,rSize
80 ,rsLabel
81 ,0
82 ))
83 return FALSE;
84
85 if (HasFlag(wxRB_GROUP))
86 SetValue(TRUE);
87
88 SetFont(*wxSMALL_FONT);
89 SetSize( rPos.x
90 ,rPos.y
91 ,rSize.x
92 ,rSize.y
93 );
94 return TRUE;
95} // end of wxRadioButton::Create
96
97wxSize wxRadioButton::DoGetBestSize() const
98{
99 static int snRadioSize = 0;
100
101 if (!snRadioSize)
102 {
103 wxScreenDC vDC;
104
105 vDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
106 snRadioSize = vDC.GetCharHeight();
107 }
108
109 wxString sStr = GetLabel();
110 int nRadioWidth;
111 int nRadioHeight;
112
113 if (!sStr.empty())
114 {
115 GetTextExtent( sStr
116 ,&nRadioWidth
117 ,&nRadioHeight
118 );
119 nRadioWidth += snRadioSize + GetCharWidth();
120 if (nRadioHeight < snRadioSize)
121 nRadioHeight = snRadioSize;
122 }
123 else
124 {
125 nRadioWidth = snRadioSize;
126 nRadioHeight = snRadioSize;
127 }
128 return wxSize( nRadioWidth
129 ,nRadioHeight
130 );
131} // end of wxRadioButton::DoGetBestSize
132
133//
134// Get single selection, for single choice list items
135//
136bool wxRadioButton::GetValue() const
137{
138 return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0));
139} // end of wxRadioButton::GetValue
140
141bool wxRadioButton::OS2Command(
142 WXUINT wParam
143, WXWORD wId
144)
145{
146 if (wParam == BN_CLICKED)
147 {
148 wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
149 ,m_windowId
150 );
151
152 rEvent.SetEventObject(this);
153 ProcessCommand(rEvent);
154 return TRUE;
155 }
156 else
157 return FALSE;
158} // end of wxRadioButton::OS2Command
159
160void wxRadioButton::SetFocus()
161{
162 // when the radio button receives a WM_SETFOCUS message it generates a
163 // BN_CLICKED which is totally unexpected and leads to catastrophic results
164 // if you pop up a dialog from the radio button event handler as, when the
165 // dialog is dismissed, the focus is returned to the radio button which
166 // generates BN_CLICKED which leads to showing another dialog and so on
167 // without end!
168 //
169 // to aviod this, we drop the pseudo BN_CLICKED events generated when the
170 // button gains focus
171 m_bFocusJustSet = TRUE;
172
173 wxControl::SetFocus();
174}
175
176void wxRadioButton::SetLabel(
177 const wxString& rsLabel
178)
179{
180 ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str());
181} // end of wxRadioButton::SetLabel
182
183void wxRadioButton::SetValue(
184 bool bValue
185)
186{
187 ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0);
188} // end of wxRadioButton::SetValue
189