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" 
  17 //----------------------------------------------------------------------------- 
  19 //----------------------------------------------------------------------------- 
  21 extern bool   g_blockEventsOnDrag
; 
  23 //----------------------------------------------------------------------------- 
  25 //----------------------------------------------------------------------------- 
  27 static void gtk_checkbox_clicked_callback( GtkWidget 
*WXUNUSED(widget
), wxCheckBox 
*cb 
) 
  29     if (!cb
->HasVMT()) return; 
  31     if (cb
->m_blockFirstEvent
) 
  33         cb
->m_blockFirstEvent 
= FALSE
; 
  37     if (g_blockEventsOnDrag
) return; 
  39     wxCommandEvent 
event(wxEVT_COMMAND_CHECKBOX_CLICKED
, cb
->GetId()); 
  40     event
.SetInt( cb
->GetValue() ); 
  41     event
.SetEventObject(cb
); 
  42     cb
->GetEventHandler()->ProcessEvent(event
); 
  45 //----------------------------------------------------------------------------- 
  47 //----------------------------------------------------------------------------- 
  49 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
,wxControl
) 
  51 wxCheckBox::wxCheckBox(void) 
  55 bool wxCheckBox::Create(  wxWindow 
*parent
, wxWindowID id
, const wxString 
&label
, 
  56       const wxPoint 
&pos
, const wxSize 
&size
,  
  57       long style
, const wxValidator
& validator
, const wxString 
&name 
) 
  60     m_acceptsFocus 
= TRUE
; 
  62     PreCreation( parent
, id
, pos
, size
, style
, name 
); 
  64     SetValidator( validator 
); 
  66     m_widget 
= gtk_check_button_new_with_label( m_label 
); 
  68     m_blockFirstEvent 
= FALSE
; 
  70     wxSize newSize 
= size
; 
  71     if (newSize
.x 
== -1) newSize
.x 
= 25+gdk_string_measure( m_widget
->style
->font
, label 
); 
  72     if (newSize
.y 
== -1) newSize
.y 
= 26; 
  73     SetSize( newSize
.x
, newSize
.y 
); 
  75     gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",  
  76       GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback
), (gpointer
*)this ); 
  78     m_parent
->AddChild( this ); 
  80     (m_parent
->m_insertCallback
)( m_parent
, this ); 
  84     gtk_widget_realize( GTK_BUTTON( m_widget 
)->child 
); 
  88     SetBackgroundColour( parent
->GetBackgroundColour() ); 
  89     SetForegroundColour( parent
->GetForegroundColour() ); 
  96 void wxCheckBox::SetValue( bool state 
) 
  98     wxCHECK_RET( m_widget 
!= NULL
, "invalid checkbox" ); 
 100     m_blockFirstEvent 
= TRUE
; 
 102     gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), state 
); 
 105 bool wxCheckBox::GetValue() const 
 107     wxCHECK_MSG( m_widget 
!= NULL
, FALSE
, "invalid checkbox" ); 
 109     return GTK_TOGGLE_BUTTON(m_widget
)->active
; 
 112 void wxCheckBox::SetLabel( const wxString
& label 
) 
 114     wxCHECK_RET( m_widget 
!= NULL
, "invalid checkbox" ); 
 116     wxControl::SetLabel( label 
); 
 118     gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child 
), GetLabel() ); 
 121 void wxCheckBox::Enable( bool enable 
) 
 123     wxCHECK_RET( m_widget 
!= NULL
, "invalid checkbox" ); 
 125     wxControl::Enable( enable 
); 
 127     gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable 
); 
 130 void wxCheckBox::ApplyWidgetStyle() 
 133     gtk_widget_set_style( m_widget
, m_widgetStyle 
); 
 134     gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle 
);