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" 
  20 //----------------------------------------------------------------------------- 
  22 //----------------------------------------------------------------------------- 
  24 extern void wxapp_install_idle_handler(); 
  27 //----------------------------------------------------------------------------- 
  29 //----------------------------------------------------------------------------- 
  31 extern bool   g_blockEventsOnDrag
; 
  33 //----------------------------------------------------------------------------- 
  35 //----------------------------------------------------------------------------- 
  37 static void gtk_checkbox_clicked_callback( GtkWidget 
*WXUNUSED(widget
), wxCheckBox 
*cb 
) 
  39     if (g_isIdle
) wxapp_install_idle_handler(); 
  41     if (!cb
->m_hasVMT
) return; 
  43     if (cb
->m_blockFirstEvent
) 
  45         cb
->m_blockFirstEvent 
= FALSE
; 
  49     if (g_blockEventsOnDrag
) return; 
  51     wxCommandEvent 
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, cb
->GetId()); 
  52     event
.SetInt( cb
->GetValue() ); 
  53     event
.SetEventObject(cb
); 
  54     cb
->GetEventHandler()->ProcessEvent(event
); 
  57 //----------------------------------------------------------------------------- 
  59 //----------------------------------------------------------------------------- 
  61 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
,wxControl
) 
  63 wxCheckBox::wxCheckBox() 
  67 bool wxCheckBox::Create(wxWindow 
*parent
, 
  69                         const wxString 
&label
, 
  73                         const wxValidator
& validator
, 
  74                         const wxString 
&name 
) 
  77     m_acceptsFocus 
= TRUE
; 
  79     PreCreation( parent
, id
, pos
, size
, style
, name 
); 
  81     m_blockFirstEvent 
= FALSE
; 
  83     SetValidator( validator 
); 
  84     wxControl::SetLabel( label 
); 
  86     if ( style 
& wxALIGN_RIGHT 
) 
  88         // VZ: as I don't know a way to create a right aligned checkbox with 
  89         //     GTK we will create a checkbox without label and a label at the 
  91         m_widgetCheckbox 
= gtk_check_button_new(); 
  93         m_widgetLabel 
= gtk_label_new(m_label
.mbc_str()); 
  94         gtk_misc_set_alignment(GTK_MISC(m_widgetLabel
), 0.0, 0.5); 
  96         m_widget 
= gtk_hbox_new(FALSE
, 0); 
  97         gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetLabel
, FALSE
, FALSE
, 3); 
  98         gtk_box_pack_start(GTK_BOX(m_widget
), m_widgetCheckbox
, FALSE
, FALSE
, 3); 
 100         // VZ: why do I have to do this to make them appear? 
 101         gtk_widget_show( m_widgetLabel 
); 
 102         gtk_widget_show( m_widgetCheckbox 
); 
 106         m_widgetCheckbox 
= gtk_check_button_new_with_label( m_label
.mbc_str() ); 
 107         m_widgetLabel 
= GTK_BUTTON( m_widgetCheckbox 
)->child
; 
 108         m_widget 
= m_widgetCheckbox
; 
 111     wxSize 
newSize(size
); 
 114         newSize
.x 
= 25 + gdk_string_measure( m_widgetCheckbox
->style
->font
, 
 120     SetSize( newSize
.x
, newSize
.y 
); 
 122     gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox
), 
 124                         GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
), 
 127     m_parent
->DoAddChild( this ); 
 131     SetBackgroundColour( parent
->GetBackgroundColour() ); 
 132     SetForegroundColour( parent
->GetForegroundColour() ); 
 133     SetFont( parent
->GetFont() ); 
 140 void wxCheckBox::SetValue( bool state 
) 
 142     wxCHECK_RET( m_widgetCheckbox 
!= NULL
, _T("invalid checkbox") ); 
 144     if ( state 
== GetValue() ) 
 147     // for compatibility with wxMSW don't send notification when the check box 
 148     // state is changed programmatically 
 149     m_blockFirstEvent 
= TRUE
; 
 151     gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox
), state 
); 
 154 bool wxCheckBox::GetValue() const 
 156     wxCHECK_MSG( m_widgetCheckbox 
!= NULL
, FALSE
, _T("invalid checkbox") ); 
 158     return GTK_TOGGLE_BUTTON(m_widgetCheckbox
)->active
; 
 161 void wxCheckBox::SetLabel( const wxString
& label 
) 
 163     wxCHECK_RET( m_widgetLabel 
!= NULL
, _T("invalid checkbox") ); 
 165     wxControl::SetLabel( label 
); 
 167     gtk_label_set( GTK_LABEL(m_widgetLabel
), GetLabel().mbc_str() ); 
 170 bool wxCheckBox::Enable( bool enable 
) 
 172     if ( !wxControl::Enable( enable 
) ) 
 175     gtk_widget_set_sensitive( m_widgetLabel
, enable 
); 
 180 void wxCheckBox::ApplyWidgetStyle() 
 183     gtk_widget_set_style( m_widgetCheckbox
, m_widgetStyle 
); 
 184     gtk_widget_set_style( m_widgetLabel
, m_widgetStyle 
);