]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
The Image sample now does anti-aliasing, oh well.
[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
83624f79
RR
17#include "gdk/gdk.h"
18#include "gtk/gtk.h"
19
66bd6b93
RR
20//-----------------------------------------------------------------------------
21// data
22//-----------------------------------------------------------------------------
23
24extern bool g_blockEventsOnDrag;
25
c801d85f 26//-----------------------------------------------------------------------------
e1e955e1 27// "clicked"
c801d85f
KB
28//-----------------------------------------------------------------------------
29
66bd6b93 30static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
c801d85f 31{
b292e2f5 32 if (!cb->HasVMT()) return;
3069ac4e 33
b292e2f5
RR
34 if (cb->m_blockFirstEvent)
35 {
36 cb->m_blockFirstEvent = FALSE;
37 return;
38 }
3069ac4e 39
b292e2f5 40 if (g_blockEventsOnDrag) return;
66bd6b93 41
b292e2f5
RR
42 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
43 event.SetInt( cb->GetValue() );
44 event.SetEventObject(cb);
45 cb->GetEventHandler()->ProcessEvent(event);
6de97a3b 46}
c801d85f 47
e1e955e1
RR
48//-----------------------------------------------------------------------------
49// wxCheckBox
c801d85f
KB
50//-----------------------------------------------------------------------------
51
52IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
53
54wxCheckBox::wxCheckBox(void)
55{
6de97a3b 56}
c801d85f
KB
57
58bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
59 const wxPoint &pos, const wxSize &size,
6de97a3b 60 long style, const wxValidator& validator, const wxString &name )
c801d85f 61{
b292e2f5
RR
62 m_needParent = TRUE;
63 m_acceptsFocus = TRUE;
c801d85f 64
b292e2f5 65 PreCreation( parent, id, pos, size, style, name );
c801d85f 66
b292e2f5 67 SetValidator( validator );
6de97a3b 68
b292e2f5 69 m_widget = gtk_check_button_new_with_label( m_label );
c801d85f 70
b292e2f5 71 m_blockFirstEvent = FALSE;
3069ac4e 72
b292e2f5
RR
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 );
c801d85f 77
b292e2f5
RR
78 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
79 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
c801d85f 80
b292e2f5 81 m_parent->AddChild( this );
6ca41e57 82
b292e2f5 83 (m_parent->m_insertCallback)( m_parent, this );
6ca41e57 84
b292e2f5 85 PostCreation();
c801d85f 86
b292e2f5 87 gtk_widget_realize( GTK_BUTTON( m_widget )->child );
f96aa4d9 88
b292e2f5 89 SetLabel( label );
d84eb083 90
b292e2f5
RR
91 SetBackgroundColour( parent->GetBackgroundColour() );
92 SetForegroundColour( parent->GetForegroundColour() );
f96aa4d9 93
b292e2f5 94 Show( TRUE );
c801d85f 95
b292e2f5 96 return TRUE;
6de97a3b 97}
c801d85f 98
debe6624 99void wxCheckBox::SetValue( bool state )
c801d85f 100{
b292e2f5 101 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
3069ac4e 102
8bf45ed1
VZ
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
b292e2f5 108 m_blockFirstEvent = TRUE;
ae0bdb01 109
b292e2f5 110 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state );
6de97a3b 111}
c801d85f 112
83058c58 113bool wxCheckBox::GetValue() const
c801d85f 114{
b292e2f5 115 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
f96aa4d9 116
b292e2f5 117 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b 118}
c801d85f 119
83058c58
RR
120void wxCheckBox::SetLabel( const wxString& label )
121{
b292e2f5 122 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
f96aa4d9 123
b292e2f5 124 wxControl::SetLabel( label );
f96aa4d9 125
b292e2f5 126 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
83058c58
RR
127}
128
d3904ceb
RR
129void wxCheckBox::Enable( bool enable )
130{
b292e2f5 131 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
f96aa4d9 132
b292e2f5 133 wxControl::Enable( enable );
f96aa4d9 134
b292e2f5 135 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
d3904ceb
RR
136}
137
58614078 138void wxCheckBox::ApplyWidgetStyle()
868a2826 139{
b292e2f5
RR
140 SetWidgetStyle();
141 gtk_widget_set_style( m_widget, m_widgetStyle );
142 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
f96aa4d9
RR
143}
144
f96aa4d9 145