]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
wxStringList::Sort() bug corrected
[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{
b292e2f5 29 if (!cb->HasVMT()) return;
3069ac4e 30
b292e2f5
RR
31 if (cb->m_blockFirstEvent)
32 {
33 cb->m_blockFirstEvent = FALSE;
34 return;
35 }
3069ac4e 36
b292e2f5 37 if (g_blockEventsOnDrag) return;
66bd6b93 38
b292e2f5
RR
39 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
40 event.SetInt( cb->GetValue() );
41 event.SetEventObject(cb);
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 58{
b292e2f5
RR
59 m_needParent = TRUE;
60 m_acceptsFocus = TRUE;
c801d85f 61
b292e2f5 62 PreCreation( parent, id, pos, size, style, name );
c801d85f 63
b292e2f5 64 SetValidator( validator );
6de97a3b 65
b292e2f5 66 m_widget = gtk_check_button_new_with_label( m_label );
c801d85f 67
b292e2f5 68 m_blockFirstEvent = FALSE;
3069ac4e 69
b292e2f5
RR
70 wxSize newSize = size;
71 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
72 if (newSize.y == -1) newSize.y = 26;
73 SetSize( newSize.x, newSize.y );
c801d85f 74
b292e2f5
RR
75 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
76 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
c801d85f 77
b292e2f5 78 m_parent->AddChild( this );
6ca41e57 79
b292e2f5 80 (m_parent->m_insertCallback)( m_parent, this );
6ca41e57 81
b292e2f5 82 PostCreation();
c801d85f 83
b292e2f5 84 gtk_widget_realize( GTK_BUTTON( m_widget )->child );
f96aa4d9 85
b292e2f5 86 SetLabel( label );
d84eb083 87
b292e2f5
RR
88 SetBackgroundColour( parent->GetBackgroundColour() );
89 SetForegroundColour( parent->GetForegroundColour() );
f96aa4d9 90
b292e2f5 91 Show( TRUE );
c801d85f 92
b292e2f5 93 return TRUE;
6de97a3b 94}
c801d85f 95
debe6624 96void wxCheckBox::SetValue( bool state )
c801d85f 97{
b292e2f5 98 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
3069ac4e 99
8bf45ed1
VZ
100 if ( state == GetValue() )
101 return;
102
103 // for compatibility with wxMSW don't send notification when the check box
104 // state is changed programmatically
b292e2f5 105 m_blockFirstEvent = TRUE;
ae0bdb01 106
b292e2f5 107 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state );
6de97a3b 108}
c801d85f 109
83058c58 110bool wxCheckBox::GetValue() const
c801d85f 111{
b292e2f5 112 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
f96aa4d9 113
b292e2f5 114 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b 115}
c801d85f 116
83058c58
RR
117void wxCheckBox::SetLabel( const wxString& label )
118{
b292e2f5 119 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
f96aa4d9 120
b292e2f5 121 wxControl::SetLabel( label );
f96aa4d9 122
b292e2f5 123 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
83058c58
RR
124}
125
d3904ceb
RR
126void wxCheckBox::Enable( bool enable )
127{
b292e2f5 128 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
f96aa4d9 129
b292e2f5 130 wxControl::Enable( enable );
f96aa4d9 131
b292e2f5 132 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
d3904ceb
RR
133}
134
58614078 135void wxCheckBox::ApplyWidgetStyle()
868a2826 136{
b292e2f5
RR
137 SetWidgetStyle();
138 gtk_widget_set_style( m_widget, m_widgetStyle );
139 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
f96aa4d9
RR
140}
141
f96aa4d9 142