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 if (!PreCreation( parent
, pos
, size
) ||
76 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
78 wxFAIL_MSG( _T("wxCheckBox creation failed") );
82 wxControl::SetLabel( label
);
84 if ( style
& wxALIGN_RIGHT
)
86 // VZ: as I don't know a way to create a right aligned checkbox with
87 // GTK we will create a checkbox without label and a label at the
89 m_widgetCheckbox
= gtk_check_button_new();
91 m_widgetLabel
= gtk_label_new(m_label
.mbc_str());
92 gtk_misc_set_alignment(GTK_MISC(m_widgetLabel
), 0.0, 0.5);
94 m_widget
= gtk_hbox_new(FALSE
, 0);
95 gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetLabel
, FALSE
, FALSE
, 3);
96 gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetCheckbox
, FALSE
, FALSE
, 3);
98 gtk_widget_show( m_widgetLabel
);
99 gtk_widget_show( m_widgetCheckbox
);
103 m_widgetCheckbox
= gtk_check_button_new_with_label( m_label
.mbc_str() );
104 m_widgetLabel
= GTK_BUTTON( m_widgetCheckbox
)->child
;
105 m_widget
= m_widgetCheckbox
;
108 wxSize
newSize(size
);
111 newSize
.x
= 25 + gdk_string_measure( m_widgetCheckbox
->style
->font
,
117 SetSize( newSize
.x
, newSize
.y
);
119 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox
),
121 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
),
124 m_parent
->DoAddChild( this );
128 SetBackgroundColour( parent
->GetBackgroundColour() );
129 SetForegroundColour( parent
->GetForegroundColour() );
130 SetFont( parent
->GetFont() );
137 void wxCheckBox::SetValue( bool state
)
139 wxCHECK_RET( m_widgetCheckbox
!= NULL
, _T("invalid checkbox") );
141 if (state
== GetValue())
144 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widgetCheckbox
),
145 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
),
148 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox
), state
);
150 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox
),
152 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
),
156 bool wxCheckBox::GetValue() const
158 wxCHECK_MSG( m_widgetCheckbox
!= NULL
, FALSE
, _T("invalid checkbox") );
160 return GTK_TOGGLE_BUTTON(m_widgetCheckbox
)->active
;
163 void wxCheckBox::SetLabel( const wxString
& label
)
165 wxCHECK_RET( m_widgetLabel
!= NULL
, _T("invalid checkbox") );
167 wxControl::SetLabel( label
);
169 gtk_label_set( GTK_LABEL(m_widgetLabel
), GetLabel().mbc_str() );
172 bool wxCheckBox::Enable( bool enable
)
174 if ( !wxControl::Enable( enable
) )
177 gtk_widget_set_sensitive( m_widgetLabel
, enable
);
182 void wxCheckBox::ApplyWidgetStyle()
185 gtk_widget_set_style( m_widgetCheckbox
, m_widgetStyle
);
186 gtk_widget_set_style( m_widgetLabel
, m_widgetStyle
);