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 (cb
->m_blockFirstEvent
)
47 cb
->m_blockFirstEvent
= FALSE
;
51 if (g_blockEventsOnDrag
) return;
53 wxCommandEvent
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, cb
->GetId());
54 event
.SetInt( cb
->GetValue() );
55 event
.SetEventObject(cb
);
56 cb
->GetEventHandler()->ProcessEvent(event
);
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
,wxControl
)
65 wxCheckBox::wxCheckBox()
69 bool wxCheckBox::Create(wxWindow
*parent
,
71 const wxString
&label
,
75 const wxValidator
& validator
,
76 const wxString
&name
)
79 m_acceptsFocus
= TRUE
;
81 PreCreation( parent
, id
, pos
, size
, style
, name
);
83 m_blockFirstEvent
= FALSE
;
86 SetValidator( validator
);
89 wxControl::SetLabel( label
);
91 if ( style
& wxALIGN_RIGHT
)
93 // VZ: as I don't know a way to create a right aligned checkbox with
94 // GTK we will create a checkbox without label and a label at the
96 m_widgetCheckbox
= gtk_check_button_new();
98 m_widgetLabel
= gtk_label_new(m_label
.mbc_str());
99 gtk_misc_set_alignment(GTK_MISC(m_widgetLabel
), 0.0, 0.5);
101 m_widget
= gtk_hbox_new(FALSE
, 0);
102 gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetLabel
, FALSE
, FALSE
, 3);
103 gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetCheckbox
, FALSE
, FALSE
, 3);
105 // VZ: why do I have to do this to make them appear?
106 gtk_widget_show( m_widgetLabel
);
107 gtk_widget_show( m_widgetCheckbox
);
111 m_widgetCheckbox
= gtk_check_button_new_with_label( m_label
.mbc_str() );
112 m_widgetLabel
= GTK_BUTTON( m_widgetCheckbox
)->child
;
113 m_widget
= m_widgetCheckbox
;
116 wxSize
newSize(size
);
119 newSize
.x
= 25 + gdk_string_measure( m_widgetCheckbox
->style
->font
,
125 SetSize( newSize
.x
, newSize
.y
);
127 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox
),
129 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
),
132 m_parent
->DoAddChild( this );
136 SetBackgroundColour( parent
->GetBackgroundColour() );
137 SetForegroundColour( parent
->GetForegroundColour() );
138 SetFont( parent
->GetFont() );
145 void wxCheckBox::SetValue( bool state
)
147 wxCHECK_RET( m_widgetCheckbox
!= NULL
, _T("invalid checkbox") );
149 if ( state
== GetValue() )
152 // for compatibility with wxMSW don't send notification when the check box
153 // state is changed programmatically
154 m_blockFirstEvent
= TRUE
;
156 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox
), state
);
159 bool wxCheckBox::GetValue() const
161 wxCHECK_MSG( m_widgetCheckbox
!= NULL
, FALSE
, _T("invalid checkbox") );
163 return GTK_TOGGLE_BUTTON(m_widgetCheckbox
)->active
;
166 void wxCheckBox::SetLabel( const wxString
& label
)
168 wxCHECK_RET( m_widgetLabel
!= NULL
, _T("invalid checkbox") );
170 wxControl::SetLabel( label
);
172 gtk_label_set( GTK_LABEL(m_widgetLabel
), GetLabel().mbc_str() );
175 bool wxCheckBox::Enable( bool enable
)
177 if ( !wxControl::Enable( enable
) )
180 gtk_widget_set_sensitive( m_widgetLabel
, enable
);
185 void wxCheckBox::ApplyWidgetStyle()
188 gtk_widget_set_style( m_widgetCheckbox
, m_widgetStyle
);
189 gtk_widget_set_style( m_widgetLabel
, m_widgetStyle
);