]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/checkbox.cpp
Added OnEraseBackground to wxNotebook on wxMSW to avoid black background;
[wxWidgets.git] / src / gtk / 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
RR
29 if (!cb->HasVMT()) return;
30 if (g_blockEventsOnDrag) return;
31
c801d85f
KB
32 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
33 event.SetInt( cb->GetValue() );
34 event.SetEventObject(cb);
47908e25 35 cb->GetEventHandler()->ProcessEvent(event);
6de97a3b 36}
c801d85f 37
e1e955e1
RR
38//-----------------------------------------------------------------------------
39// wxCheckBox
c801d85f
KB
40//-----------------------------------------------------------------------------
41
42IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
43
44wxCheckBox::wxCheckBox(void)
45{
6de97a3b 46}
c801d85f
KB
47
48bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
49 const wxPoint &pos, const wxSize &size,
6de97a3b 50 long style, const wxValidator& validator, const wxString &name )
c801d85f
KB
51{
52 m_needParent = TRUE;
53
54 PreCreation( parent, id, pos, size, style, name );
55
6de97a3b
RR
56 SetValidator( validator );
57
1280032d 58 m_widget = gtk_check_button_new_with_label( m_label );
c801d85f
KB
59
60 wxSize newSize = size;
61 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
62 if (newSize.y == -1) newSize.y = 26;
63 SetSize( newSize.x, newSize.y );
64
65 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
66 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
67
68 PostCreation();
69
f96aa4d9
RR
70 gtk_widget_realize( GTK_BUTTON( m_widget )->child );
71
d84eb083
RR
72 SetLabel( label );
73
f96aa4d9
RR
74 SetBackgroundColour( parent->GetBackgroundColour() );
75
c801d85f
KB
76 Show( TRUE );
77
78 return TRUE;
6de97a3b 79}
c801d85f 80
debe6624 81void wxCheckBox::SetValue( bool state )
c801d85f 82{
f96aa4d9
RR
83 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
84
c801d85f
KB
85 if (state)
86 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_ACTIVE );
87 else
88 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_NORMAL );
6de97a3b 89}
c801d85f 90
83058c58 91bool wxCheckBox::GetValue() const
c801d85f 92{
f96aa4d9
RR
93 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
94
95 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b 96}
c801d85f 97
83058c58
RR
98void wxCheckBox::SetLabel( const wxString& label )
99{
f96aa4d9
RR
100 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
101
83058c58 102 wxControl::SetLabel( label );
f96aa4d9
RR
103
104 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
83058c58
RR
105}
106
d3904ceb
RR
107void wxCheckBox::Enable( bool enable )
108{
f96aa4d9
RR
109 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
110
d3904ceb 111 wxControl::Enable( enable );
f96aa4d9
RR
112
113 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
d3904ceb
RR
114}
115
868a2826
RR
116void wxCheckBox::SetFont( const wxFont &font )
117{
f96aa4d9
RR
118 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
119
120 wxControl::SetFont( font );
868a2826 121
f96aa4d9
RR
122 gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
123 gtk_style_ref(
124 gtk_widget_get_style( m_widget ) ) );
125}
126
127void wxCheckBox::SetBackgroundColour( const wxColour &colour )
128{
129 return;
130
131 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
132
133 wxControl::SetBackgroundColour( colour );
868a2826 134
f96aa4d9 135 if (!m_backgroundColour.Ok()) return;
868a2826 136
f96aa4d9
RR
137 gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
138 gtk_style_ref(
139 gtk_widget_get_style( m_widget ) ) );
868a2826 140}
f96aa4d9 141