]> git.saurik.com Git - wxWidgets.git/blame - src/msw/radiobut.cpp
got rid of wxWindow::m_lDlgCode - now wxWANTS_CHARS style should work for all windows...
[wxWidgets.git] / src / msw / radiobut.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: msw/radiobut.cpp
2bda0e17
KB
3// Purpose: wxRadioButton
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c085e333 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
5f199b71
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
c9baf9d7 21#pragma implementation "radiobut.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
c9baf9d7 28#pragma hdrstop
2bda0e17
KB
29#endif
30
1e6feb95
VZ
31#if wxUSE_RADIOBTN
32
2bda0e17 33#ifndef WX_PRECOMP
c9baf9d7
RL
34#include "wx/radiobut.h"
35#include "wx/settings.h"
36#include "wx/brush.h"
37#include "wx/dcscreen.h"
2bda0e17
KB
38#endif
39
40#include "wx/msw/private.h"
41
5f199b71
VZ
42// ============================================================================
43// wxRadioButton implementation
44// ============================================================================
45
46// ----------------------------------------------------------------------------
47// wxRadioButton creation
48// ----------------------------------------------------------------------------
49
2bda0e17 50IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
2bda0e17 51
5f199b71 52void wxRadioButton::Init()
621793f4 53{
5f199b71 54 m_focusJustSet = FALSE;
621793f4
JS
55}
56
5f199b71
VZ
57bool wxRadioButton::Create(wxWindow *parent,
58 wxWindowID id,
59 const wxString& label,
60 const wxPoint& pos,
61 const wxSize& size,
62 long style,
63 const wxValidator& validator,
64 const wxString& name)
2bda0e17 65{
5f199b71
VZ
66 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
67 return FALSE;
2bda0e17 68
5f199b71 69 long msStyle = HasFlag(wxRB_GROUP) ? WS_GROUP : 0;
2bda0e17 70
5f199b71 71 msStyle |= BS_AUTORADIOBUTTON;
2bda0e17 72
5f199b71 73 if ( HasFlag(wxCLIP_SIBLINGS) )
b0766406
JS
74 msStyle |= WS_CLIPSIBLINGS;
75
5f199b71
VZ
76 if ( !MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, 0) )
77 return FALSE;
b0766406 78
5f199b71
VZ
79 // for compatibility with wxGTK, the first radio button in a group is
80 // always checked (this makes sense anyhow as you need to ensure that at
81 // least one button in the group is checked and this is the simlpest way to
82 // do it)
83 if ( HasFlag(wxRB_GROUP) )
84 SetValue(TRUE);
c085e333 85
5f199b71 86 return TRUE;
2bda0e17
KB
87}
88
5f199b71
VZ
89// ----------------------------------------------------------------------------
90// wxRadioButton functions
91// ----------------------------------------------------------------------------
2bda0e17 92
5f199b71 93void wxRadioButton::SetValue(bool value)
2bda0e17 94{
5f199b71
VZ
95 // BST_CHECKED is defined as 1, BST_UNCHECKED as 0, so we can just pass
96 // value as is (we don't sue BST_XXX here as they're not defined for Win16)
97 (void)::SendMessage(GetHwnd(), BM_SETCHECK, (WPARAM)value, 0L);
2bda0e17
KB
98}
99
5f199b71 100bool wxRadioButton::GetValue() const
2bda0e17 101{
5f199b71
VZ
102 // NB: this will also return TRUE for BST_INDETERMINATE value if we ever
103 // have 3-state radio buttons
104 return ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0L) != 0;
2bda0e17
KB
105}
106
5f199b71
VZ
107// ----------------------------------------------------------------------------
108// wxRadioButton event processing
109// ----------------------------------------------------------------------------
110
111void wxRadioButton::Command (wxCommandEvent& event)
2bda0e17 112{
5f199b71
VZ
113 SetValue(event.m_commandInt != 0);
114 ProcessCommand(event);
2bda0e17
KB
115}
116
5f199b71 117void wxRadioButton::SetFocus()
2bda0e17 118{
5f199b71
VZ
119 // when the radio button receives a WM_SETFOCUS message it generates a
120 // BN_CLICKED which is totally unexpected and leads to catastrophic results
121 // if you pop up a dialog from the radio button event handler as, when the
122 // dialog is dismissed, the focus is returned to the radio button which
123 // generates BN_CLICKED which leads to showing another dialog and so on
124 // without end!
125 //
126 // to aviod this, we drop the pseudo BN_CLICKED events generated when the
127 // button gains focus
128 m_focusJustSet = TRUE;
129
130 wxControl::SetFocus();
2bda0e17
KB
131}
132
5f199b71 133bool wxRadioButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
f6bcfd97 134{
5f199b71
VZ
135 if ( param != BN_CLICKED )
136 return FALSE;
137
138 if ( m_focusJustSet )
f6bcfd97 139 {
5f199b71
VZ
140 // see above: we want to ignore this event
141 m_focusJustSet = FALSE;
f6bcfd97 142 }
5f199b71
VZ
143 else // a real clicked event
144 {
145 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, GetId());
146 event.SetEventObject( this );
147 event.SetInt( GetValue() );
f6bcfd97 148
5f199b71
VZ
149 ProcessCommand(event);
150 }
f6bcfd97 151
5f199b71 152 return TRUE;
f6bcfd97 153}
2bda0e17 154
5f199b71
VZ
155// ----------------------------------------------------------------------------
156// wxRadioButton geometry
157// ----------------------------------------------------------------------------
158
159wxSize wxRadioButton::DoGetBestSize() const
2bda0e17 160{
5f199b71 161 static int s_radioSize = 0;
2bda0e17 162
5f199b71
VZ
163 if ( !s_radioSize )
164 {
165 wxScreenDC dc;
166 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
2bda0e17 167
5f199b71
VZ
168 s_radioSize = dc.GetCharHeight();
169 }
2bda0e17 170
5f199b71 171 wxString str = GetLabel();
2bda0e17 172
5f199b71
VZ
173 int wRadio, hRadio;
174 if ( !str.empty() )
175 {
176 GetTextExtent(str, &wRadio, &hRadio);
177 wRadio += s_radioSize + GetCharWidth();
2bda0e17 178
5f199b71
VZ
179 if ( hRadio < s_radioSize )
180 hRadio = s_radioSize;
181 }
182 else
183 {
184 wRadio = s_radioSize;
185 hRadio = s_radioSize;
186 }
2bda0e17 187
5f199b71 188 return wxSize(wRadio, hRadio);
2bda0e17
KB
189}
190
1e6feb95 191#endif // wxUSE_RADIOBTN