]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobut.cpp
no message
[wxWidgets.git] / src / gtk / radiobut.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "radiobut.h"
14#endif
15
16#include "wx/radiobut.h"
17
6de97a3b
RR
18//-----------------------------------------------------------------------------
19// data
20//-----------------------------------------------------------------------------
21
22extern bool g_blockEventsOnDrag;
23
24//-----------------------------------------------------------------------------
25// wxRadioButton
26//-----------------------------------------------------------------------------
27
28IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
29
30static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
31{
32 if (!rb->HasVMT()) return;
33 if (g_blockEventsOnDrag) return;
34
35 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
36 event.SetInt( rb->GetValue() );
37 event.SetEventObject( rb );
38 rb->GetEventHandler()->ProcessEvent( event );
39}
40
41bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& label,
42 const wxPoint& pos, const wxSize& size, long style,
43 const wxValidator& validator, const wxString& name )
44{
45 m_needParent = TRUE;
46
47 wxSize newSize = size;
48
49 PreCreation( parent, id, pos, newSize, style, name );
50
51 SetValidator( validator );
52
c67daf87 53 m_widget = gtk_radio_button_new_with_label( (GSList *) NULL, label );
6de97a3b
RR
54
55 SetLabel(label);
56
57 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label );
58 if (newSize.y == -1) newSize.y = 26;
59 SetSize( newSize.x, newSize.y );
60
61 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
62 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
63
64 PostCreation();
65
66 Show( TRUE );
67
68 return TRUE;
69}
70
71void wxRadioButton::SetLabel( const wxString& label )
72{
73 wxControl::SetLabel( label );
74 GtkButton *bin = GTK_BUTTON( m_widget );
75 GtkLabel *g_label = GTK_LABEL( bin->child );
76 gtk_label_set( g_label, GetLabel() );
77}
78
79void wxRadioButton::SetValue( bool val )
80{
81 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), val );
82}
83
84bool wxRadioButton::GetValue(void) const
85{
86 return GTK_TOGGLE_BUTTON(m_widget)->active;
87}
88
d3904ceb
RR
89void wxRadioButton::Enable( bool enable )
90{
91 wxControl::Enable( enable );
92 GtkButton *bin = GTK_BUTTON( m_widget );
93 GtkWidget *label = bin->child;
94 gtk_widget_set_sensitive( label, enable );
95}
96
868a2826
RR
97void wxRadioButton::SetFont( const wxFont &font )
98{
3f659fd6
RR
99 if (((wxFont*)&font)->Ok())
100 m_font = font;
101 else
102 m_font = *wxSWISS_FONT;
868a2826
RR
103
104 GtkButton *bin = GTK_BUTTON( m_widget );
105 GtkWidget *label = bin->child;
106
107 GtkStyle *style = (GtkStyle*) NULL;
108 if (!m_hasOwnStyle)
109 {
110 m_hasOwnStyle = TRUE;
111 style = gtk_style_copy( gtk_widget_get_style( label ) );
112 }
113 else
114 {
115 style = gtk_widget_get_style( label );
116 }
117
118 gdk_font_unref( style->font );
119 style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
120
121 gtk_widget_set_style( label, style );
122}
6de97a3b 123