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