]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/checkbox.cpp
Removed some bugs
[wxWidgets.git] / src / gtk1 / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: checkbox.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11
12 #ifdef __GNUG__
13 #pragma implementation "checkbox.h"
14 #endif
15
16 #include "wx/checkbox.h"
17
18 //-----------------------------------------------------------------------------
19 // data
20 //-----------------------------------------------------------------------------
21
22 extern bool g_blockEventsOnDrag;
23
24 //-----------------------------------------------------------------------------
25 // "clicked"
26 //-----------------------------------------------------------------------------
27
28 static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
29 {
30 if (!cb->HasVMT()) return;
31 if (g_blockEventsOnDrag) return;
32
33 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
34 event.SetInt( cb->GetValue() );
35 event.SetEventObject(cb);
36 cb->GetEventHandler()->ProcessEvent(event);
37 }
38
39 //-----------------------------------------------------------------------------
40 // wxCheckBox
41 //-----------------------------------------------------------------------------
42
43 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
44
45 wxCheckBox::wxCheckBox(void)
46 {
47 }
48
49 bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
50 const wxPoint &pos, const wxSize &size,
51 long style, const wxValidator& validator, const wxString &name )
52 {
53 m_needParent = TRUE;
54
55 PreCreation( parent, id, pos, size, style, name );
56
57 SetValidator( validator );
58
59 SetLabel( label );
60
61 m_widget = gtk_check_button_new_with_label( m_label );
62
63 wxSize newSize = size;
64 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
65 if (newSize.y == -1) newSize.y = 26;
66 SetSize( newSize.x, newSize.y );
67
68 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
69 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
70
71 PostCreation();
72
73 Show( TRUE );
74
75 return TRUE;
76 }
77
78 void wxCheckBox::SetValue( bool state )
79 {
80 if (state)
81 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_ACTIVE );
82 else
83 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_NORMAL );
84 }
85
86 bool wxCheckBox::GetValue(void) const
87 {
88 GtkToggleButton *tb = GTK_TOGGLE_BUTTON(m_widget);
89 return tb->active;
90 }
91