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