1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "checkbox.h"
16 #include "wx/checkbox.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 extern bool g_blockEventsOnDrag
;
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 static void gtk_checkbox_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxCheckBox
*cb
)
30 if (!cb
->HasVMT()) return;
31 if (g_blockEventsOnDrag
) return;
33 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, cb
->GetId());
34 event
.SetInt( cb
->GetValue() );
35 event
.SetEventObject(cb
);
36 cb
->GetEventHandler()->ProcessEvent(event
);
39 //-----------------------------------------------------------------------------
41 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
,wxControl
)
43 wxCheckBox::wxCheckBox(void)
47 wxCheckBox::wxCheckBox( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
48 const wxPoint
&pos
, const wxSize
&size
,
49 long style
, const wxString
&name
)
51 Create( parent
, id
, label
, pos
, size
, style
, name
);
54 bool wxCheckBox::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
55 const wxPoint
&pos
, const wxSize
&size
,
56 long style
, const wxString
&name
)
60 PreCreation( parent
, id
, pos
, size
, style
, name
);
62 m_widget
= gtk_check_button_new_with_label( label
);
64 wxSize newSize
= size
;
65 if (newSize
.x
== -1) newSize
.x
= 25+gdk_string_measure( m_widget
->style
->font
, label
);
66 if (newSize
.y
== -1) newSize
.y
= 26;
67 SetSize( newSize
.x
, newSize
.y
);
69 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
70 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
), (gpointer
*)this );
79 void wxCheckBox::SetValue( bool state
)
82 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), GTK_STATE_ACTIVE
);
84 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), GTK_STATE_NORMAL
);
87 bool wxCheckBox::GetValue(void) const
89 GtkToggleButton
*tb
= GTK_TOGGLE_BUTTON(m_widget
);