]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/radiobut.cpp
Ignore erase failures
[wxWidgets.git] / src / gtk1 / radiobut.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose:
4// Author: Robert Roebling
f96aa4d9
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
c801d85f
KB
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "radiobut.h"
13#endif
14
15#include "wx/radiobut.h"
dcf924a3
RR
16
17#if wxUSE_RADIOBOX
18
83624f79
RR
19#include "gdk/gdk.h"
20#include "gtk/gtk.h"
c801d85f 21
acfd422a
RR
22//-----------------------------------------------------------------------------
23// idle system
24//-----------------------------------------------------------------------------
25
26extern void wxapp_install_idle_handler();
27extern bool g_isIdle;
28
6de97a3b
RR
29//-----------------------------------------------------------------------------
30// data
31//-----------------------------------------------------------------------------
32
33extern bool g_blockEventsOnDrag;
34
35//-----------------------------------------------------------------------------
bb4549de 36// "clicked"
6de97a3b
RR
37//-----------------------------------------------------------------------------
38
bb4549de
RR
39static
40void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
6de97a3b 41{
acfd422a
RR
42 if (g_isIdle) wxapp_install_idle_handler();
43
a2053b27 44 if (!rb->m_hasVMT) return;
bb4549de 45
f5d29b39
RR
46 if (rb->m_blockFirstEvent)
47 {
48 rb->m_blockFirstEvent = FALSE;
49 return;
50 }
bb4549de 51
f5d29b39 52 if (g_blockEventsOnDrag) return;
6de97a3b 53
f5d29b39
RR
54 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
55 event.SetInt( rb->GetValue() );
56 event.SetEventObject( rb );
57 rb->GetEventHandler()->ProcessEvent( event );
6de97a3b
RR
58}
59
bb4549de
RR
60//-----------------------------------------------------------------------------
61// wxRadioButton
62//-----------------------------------------------------------------------------
63
64IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
65
6de97a3b
RR
66bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& label,
67 const wxPoint& pos, const wxSize& size, long style,
68 const wxValidator& validator, const wxString& name )
69{
b292e2f5 70 m_acceptsFocus = TRUE;
f5d29b39 71 m_needParent = TRUE;
6de97a3b 72
f5d29b39 73 wxSize newSize = size;
6de97a3b 74
f5d29b39 75 PreCreation( parent, id, pos, newSize, style, name );
6de97a3b 76
ce4169a4 77#if wxUSE_VALIDATORS
f5d29b39 78 SetValidator( validator );
ce4169a4 79#endif
6de97a3b 80
b019151f 81 m_widget = gtk_radio_button_new_with_label( (GSList *) NULL, label.mbc_str() );
6de97a3b 82
f5d29b39
RR
83 m_theOtherRadioButtton =
84 gtk_radio_button_new_with_label(
85 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget) ),
86 "button2" );
87
88 SetLabel(label);
6de97a3b 89
f5d29b39 90 m_blockFirstEvent = FALSE;
bb4549de 91
b019151f 92 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label.mbc_str() );
f5d29b39
RR
93 if (newSize.y == -1) newSize.y = 26;
94 SetSize( newSize.x, newSize.y );
6de97a3b 95
f5d29b39
RR
96 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
97 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
6de97a3b 98
f03fc89f 99 m_parent->DoAddChild( this );
6ca41e57 100
f5d29b39 101 PostCreation();
6de97a3b 102
f5d29b39
RR
103 SetBackgroundColour( parent->GetBackgroundColour() );
104 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 105 SetFont( parent->GetFont() );
58614078 106
f5d29b39 107 Show( TRUE );
6de97a3b 108
f5d29b39 109 return TRUE;
6de97a3b
RR
110}
111
112void wxRadioButton::SetLabel( const wxString& label )
113{
b019151f 114 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
f96aa4d9 115
f5d29b39
RR
116 wxControl::SetLabel( label );
117 GtkButton *bin = GTK_BUTTON( m_widget );
118 GtkLabel *g_label = GTK_LABEL( bin->child );
b019151f 119 gtk_label_set( g_label, GetLabel().mbc_str() );
6de97a3b
RR
120}
121
122void wxRadioButton::SetValue( bool val )
123{
b019151f 124 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
f96aa4d9 125
0659e7ee
RR
126 if ( val == GetValue() )
127 return;
128
f5d29b39 129 m_blockFirstEvent = TRUE;
ae0bdb01 130
f5d29b39
RR
131 if (val)
132 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), TRUE );
133 else
134 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton), TRUE );
6de97a3b
RR
135}
136
eb082a08 137bool wxRadioButton::GetValue() const
6de97a3b 138{
b019151f 139 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid radiobutton") );
f96aa4d9 140
f5d29b39 141 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b
RR
142}
143
f03fc89f 144bool wxRadioButton::Enable( bool enable )
d3904ceb 145{
f03fc89f
VZ
146 if ( !wxControl::Enable( enable ) )
147 return FALSE;
f96aa4d9 148
f5d29b39 149 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
f03fc89f
VZ
150
151 return TRUE;
d3904ceb
RR
152}
153
58614078 154void wxRadioButton::ApplyWidgetStyle()
868a2826 155{
f5d29b39
RR
156 SetWidgetStyle();
157 gtk_widget_set_style( m_widget, m_widgetStyle );
158 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
f96aa4d9 159}
dcf924a3
RR
160
161#endif