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 //-----------------------------------------------------------------------------
43 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
,wxControl
)
45 wxCheckBox::wxCheckBox(void)
49 bool wxCheckBox::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
50 const wxPoint
&pos
, const wxSize
&size
,
51 long style
, const wxValidator
& validator
, const wxString
&name
)
55 PreCreation( parent
, id
, pos
, size
, style
, name
);
57 SetValidator( validator
);
59 wxControl::SetLabel( label
);
61 m_widget
= gtk_check_button_new_with_label( m_label
);
63 wxSize newSize
= size
;
64 if (newSize
.x
== -1) newSize
.x
= 25+gdk_string_measure( m_widget
->style
->font
, label
);
65 if (newSize
.y
== -1) newSize
.y
= 26;
66 SetSize( newSize
.x
, newSize
.y
);
68 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
69 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
), (gpointer
*)this );
78 void wxCheckBox::SetValue( bool state
)
81 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), GTK_STATE_ACTIVE
);
83 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), GTK_STATE_NORMAL
);
86 bool wxCheckBox::GetValue() const
88 GtkToggleButton
*tb
= GTK_TOGGLE_BUTTON(m_widget
);
92 void wxCheckBox::SetLabel( const wxString
& label
)
94 wxControl::SetLabel( label
);
95 GtkButton
*bin
= GTK_BUTTON( m_widget
);
96 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
97 gtk_label_set( g_label
, GetLabel() );
100 void wxCheckBox::Enable( bool enable
)
102 wxControl::Enable( enable
);
103 GtkButton
*bin
= GTK_BUTTON( m_widget
);
104 GtkWidget
*label
= bin
->child
;
105 gtk_widget_set_sensitive( label
, enable
);
108 void wxCheckBox::SetFont( const wxFont
&font
)
110 if (((wxFont
*)&font
)->Ok())
113 m_font
= *wxSWISS_FONT
;
115 GtkButton
*bin
= GTK_BUTTON( m_widget
);
116 GtkWidget
*label
= bin
->child
;
118 GtkStyle
*style
= (GtkStyle
*) NULL
;
121 m_hasOwnStyle
= TRUE
;
122 style
= gtk_style_copy( gtk_widget_get_style( label
) );
126 style
= gtk_widget_get_style( label
);
129 gdk_font_unref( style
->font
);
130 style
->font
= gdk_font_ref( m_font
.GetInternalFont( 1.0 ) );
132 gtk_widget_set_style( label
, style
);