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"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern void wxapp_install_idle_handler();
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 extern bool g_blockEventsOnDrag
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 static void gtk_checkbox_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxCheckBox
*cb
)
41 if (g_isIdle
) wxapp_install_idle_handler();
43 if (!cb
->m_hasVMT
) return;
45 if (g_blockEventsOnDrag
) return;
47 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, cb
->GetId());
48 event
.SetInt( cb
->GetValue() );
49 event
.SetEventObject(cb
);
50 cb
->GetEventHandler()->ProcessEvent(event
);
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
,wxControl
)
59 wxCheckBox::wxCheckBox()
63 bool wxCheckBox::Create(wxWindow
*parent
,
65 const wxString
&label
,
69 const wxValidator
& validator
,
70 const wxString
&name
)
73 m_acceptsFocus
= TRUE
;
75 PreCreation( parent
, id
, pos
, size
, style
, name
);
78 SetValidator( validator
);
81 wxControl::SetLabel( label
);
83 if ( style
& wxALIGN_RIGHT
)
85 // VZ: as I don't know a way to create a right aligned checkbox with
86 // GTK we will create a checkbox without label and a label at the
88 m_widgetCheckbox
= gtk_check_button_new();
90 m_widgetLabel
= gtk_label_new(m_label
.mbc_str());
91 gtk_misc_set_alignment(GTK_MISC(m_widgetLabel
), 0.0, 0.5);
93 m_widget
= gtk_hbox_new(FALSE
, 0);
94 gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetLabel
, FALSE
, FALSE
, 3);
95 gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetCheckbox
, FALSE
, FALSE
, 3);
97 gtk_widget_show( m_widgetLabel
);
98 gtk_widget_show( m_widgetCheckbox
);
102 m_widgetCheckbox
= gtk_check_button_new_with_label( m_label
.mbc_str() );
103 m_widgetLabel
= GTK_BUTTON( m_widgetCheckbox
)->child
;
104 m_widget
= m_widgetCheckbox
;
107 wxSize
newSize(size
);
110 newSize
.x
= 25 + gdk_string_measure( m_widgetCheckbox
->style
->font
,
116 SetSize( newSize
.x
, newSize
.y
);
118 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox
),
120 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
),
123 m_parent
->DoAddChild( this );
127 SetBackgroundColour( parent
->GetBackgroundColour() );
128 SetForegroundColour( parent
->GetForegroundColour() );
129 SetFont( parent
->GetFont() );
136 void wxCheckBox::SetValue( bool state
)
138 wxCHECK_RET( m_widgetCheckbox
!= NULL
, _T("invalid checkbox") );
140 if (state
== GetValue())
143 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widgetCheckbox
),
144 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
),
147 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox
), state
);
149 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox
),
151 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
),
155 bool wxCheckBox::GetValue() const
157 wxCHECK_MSG( m_widgetCheckbox
!= NULL
, FALSE
, _T("invalid checkbox") );
159 return GTK_TOGGLE_BUTTON(m_widgetCheckbox
)->active
;
162 void wxCheckBox::SetLabel( const wxString
& label
)
164 wxCHECK_RET( m_widgetLabel
!= NULL
, _T("invalid checkbox") );
166 wxControl::SetLabel( label
);
168 gtk_label_set( GTK_LABEL(m_widgetLabel
), GetLabel().mbc_str() );
171 bool wxCheckBox::Enable( bool enable
)
173 if ( !wxControl::Enable( enable
) )
176 gtk_widget_set_sensitive( m_widgetLabel
, enable
);
181 void wxCheckBox::ApplyWidgetStyle()
184 gtk_widget_set_style( m_widgetCheckbox
, m_widgetStyle
);
185 gtk_widget_set_style( m_widgetLabel
, m_widgetStyle
);