]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/checkbox.cpp
wxMimeTypesManagerImpl::GetFileTypeFromMimeType() implemented
[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 #include "gdk/gdk.h"
18 #include "gtk/gtk.h"
19
20 //-----------------------------------------------------------------------------
21 // data
22 //-----------------------------------------------------------------------------
23
24 extern bool g_blockEventsOnDrag;
25
26 //-----------------------------------------------------------------------------
27 // "clicked"
28 //-----------------------------------------------------------------------------
29
30 static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
31 {
32 if (!cb->HasVMT()) return;
33
34 if (cb->m_blockFirstEvent)
35 {
36 cb->m_blockFirstEvent = FALSE;
37 return;
38 }
39
40 if (g_blockEventsOnDrag) return;
41
42 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
43 event.SetInt( cb->GetValue() );
44 event.SetEventObject(cb);
45 cb->GetEventHandler()->ProcessEvent(event);
46 }
47
48 //-----------------------------------------------------------------------------
49 // wxCheckBox
50 //-----------------------------------------------------------------------------
51
52 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
53
54 wxCheckBox::wxCheckBox(void)
55 {
56 }
57
58 bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
59 const wxPoint &pos, const wxSize &size,
60 long style, const wxValidator& validator, const wxString &name )
61 {
62 m_needParent = TRUE;
63 m_acceptsFocus = TRUE;
64
65 PreCreation( parent, id, pos, size, style, name );
66
67 SetValidator( validator );
68
69 m_widget = gtk_check_button_new_with_label( m_label );
70
71 m_blockFirstEvent = FALSE;
72
73 wxSize newSize = size;
74 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
75 if (newSize.y == -1) newSize.y = 26;
76 SetSize( newSize.x, newSize.y );
77
78 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
79 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
80
81 m_parent->AddChild( this );
82
83 (m_parent->m_insertCallback)( m_parent, this );
84
85 PostCreation();
86
87 gtk_widget_realize( GTK_BUTTON( m_widget )->child );
88
89 SetLabel( label );
90
91 SetBackgroundColour( parent->GetBackgroundColour() );
92 SetForegroundColour( parent->GetForegroundColour() );
93
94 Show( TRUE );
95
96 return TRUE;
97 }
98
99 void wxCheckBox::SetValue( bool state )
100 {
101 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
102
103 if ( state == GetValue() )
104 return;
105
106 // for compatibility with wxMSW don't send notification when the check box
107 // state is changed programmatically
108 m_blockFirstEvent = TRUE;
109
110 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state );
111 }
112
113 bool wxCheckBox::GetValue() const
114 {
115 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
116
117 return GTK_TOGGLE_BUTTON(m_widget)->active;
118 }
119
120 void wxCheckBox::SetLabel( const wxString& label )
121 {
122 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
123
124 wxControl::SetLabel( label );
125
126 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
127 }
128
129 void wxCheckBox::Enable( bool enable )
130 {
131 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
132
133 wxControl::Enable( enable );
134
135 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
136 }
137
138 void wxCheckBox::ApplyWidgetStyle()
139 {
140 SetWidgetStyle();
141 gtk_widget_set_style( m_widget, m_widgetStyle );
142 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
143 }
144
145