1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "checkbox.h"
15 #include "wx/checkbox.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 extern bool g_blockEventsOnDrag
;
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 static void gtk_checkbox_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxCheckBox
*cb
)
32 if (!cb
->HasVMT()) return;
34 if (cb
->m_blockFirstEvent
)
36 cb
->m_blockFirstEvent
= FALSE
;
40 if (g_blockEventsOnDrag
) return;
42 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, cb
->GetId());
43 event
.SetInt( cb
->GetValue() );
44 event
.SetEventObject(cb
);
45 cb
->GetEventHandler()->ProcessEvent(event
);
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
,wxControl
)
54 wxCheckBox::wxCheckBox(void)
58 bool wxCheckBox::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
59 const wxPoint
&pos
, const wxSize
&size
,
60 long style
, const wxValidator
& validator
, const wxString
&name
)
63 m_acceptsFocus
= TRUE
;
65 PreCreation( parent
, id
, pos
, size
, style
, name
);
67 SetValidator( validator
);
69 m_widget
= gtk_check_button_new_with_label( m_label
);
71 m_blockFirstEvent
= FALSE
;
73 wxSize newSize
= size
;
74 if (newSize
.x
== -1) newSize
.x
= 25+gdk_string_measure( m_widget
->style
->font
, label
);
75 if (newSize
.y
== -1) newSize
.y
= 26;
76 SetSize( newSize
.x
, newSize
.y
);
78 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
79 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
), (gpointer
*)this );
81 m_parent
->AddChild( this );
83 (m_parent
->m_insertCallback
)( m_parent
, this );
87 gtk_widget_realize( GTK_BUTTON( m_widget
)->child
);
91 SetBackgroundColour( parent
->GetBackgroundColour() );
92 SetForegroundColour( parent
->GetForegroundColour() );
93 SetFont( parent
->GetFont() );
100 void wxCheckBox::SetValue( bool state
)
102 wxCHECK_RET( m_widget
!= NULL
, "invalid checkbox" );
104 if ( state
== GetValue() )
107 // for compatibility with wxMSW don't send notification when the check box
108 // state is changed programmatically
109 m_blockFirstEvent
= TRUE
;
111 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), state
);
114 bool wxCheckBox::GetValue() const
116 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, "invalid checkbox" );
118 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
121 void wxCheckBox::SetLabel( const wxString
& label
)
123 wxCHECK_RET( m_widget
!= NULL
, "invalid checkbox" );
125 wxControl::SetLabel( label
);
127 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child
), GetLabel() );
130 void wxCheckBox::Enable( bool enable
)
132 wxCHECK_RET( m_widget
!= NULL
, "invalid checkbox" );
134 wxControl::Enable( enable
);
136 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
139 void wxCheckBox::ApplyWidgetStyle()
142 gtk_widget_set_style( m_widget
, m_widgetStyle
);
143 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);