]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/checkbox.cpp
fixes
[wxWidgets.git] / src / gtk1 / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: checkbox.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "checkbox.h"
13 #endif
14
15 #include "wx/checkbox.h"
16
17 //-----------------------------------------------------------------------------
18 // data
19 //-----------------------------------------------------------------------------
20
21 extern bool g_blockEventsOnDrag;
22
23 //-----------------------------------------------------------------------------
24 // "clicked"
25 //-----------------------------------------------------------------------------
26
27 static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
28 {
29 if (!cb->HasVMT()) return;
30 if (g_blockEventsOnDrag) return;
31
32 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
33 event.SetInt( cb->GetValue() );
34 event.SetEventObject(cb);
35 cb->GetEventHandler()->ProcessEvent(event);
36 }
37
38 //-----------------------------------------------------------------------------
39 // wxCheckBox
40 //-----------------------------------------------------------------------------
41
42 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
43
44 wxCheckBox::wxCheckBox(void)
45 {
46 }
47
48 bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
49 const wxPoint &pos, const wxSize &size,
50 long style, const wxValidator& validator, const wxString &name )
51 {
52 m_needParent = TRUE;
53
54 PreCreation( parent, id, pos, size, style, name );
55
56 SetValidator( validator );
57
58 m_widget = gtk_check_button_new_with_label( m_label );
59
60 wxSize newSize = size;
61 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
62 if (newSize.y == -1) newSize.y = 26;
63 SetSize( newSize.x, newSize.y );
64
65 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
66 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
67
68 PostCreation();
69
70 gtk_widget_realize( GTK_BUTTON( m_widget )->child );
71
72 SetLabel( label );
73
74 SetBackgroundColour( parent->GetBackgroundColour() );
75 SetForegroundColour( parent->GetForegroundColour() );
76
77 Show( TRUE );
78
79 return TRUE;
80 }
81
82 void wxCheckBox::SetValue( bool state )
83 {
84 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
85
86 if (state)
87 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_ACTIVE );
88 else
89 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_NORMAL );
90 }
91
92 bool wxCheckBox::GetValue() const
93 {
94 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
95
96 return GTK_TOGGLE_BUTTON(m_widget)->active;
97 }
98
99 void wxCheckBox::SetLabel( const wxString& label )
100 {
101 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
102
103 wxControl::SetLabel( label );
104
105 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
106 }
107
108 void wxCheckBox::Enable( bool enable )
109 {
110 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
111
112 wxControl::Enable( enable );
113
114 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
115 }
116
117 void wxCheckBox::ApplyWidgetStyle()
118 {
119 SetWidgetStyle();
120 gtk_widget_set_style( m_widget, m_widgetStyle );
121 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
122 }
123
124