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