]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/checkbox.cpp
fixed bug in GetMimeType under win
[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
ff8bfdbb 7// Licence: wxWindows licence
c801d85f
KB
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;
ff8bfdbb 33
b292e2f5
RR
34 if (cb->m_blockFirstEvent)
35 {
36 cb->m_blockFirstEvent = FALSE;
37 return;
ff8bfdbb
VZ
38 }
39
b292e2f5 40 if (g_blockEventsOnDrag) return;
ff8bfdbb 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,
ff8bfdbb 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;
ff8bfdbb 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 );
ff8bfdbb 70
b292e2f5 71 m_blockFirstEvent = FALSE;
ff8bfdbb 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 );
ff8bfdbb
VZ
77
78 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
b292e2f5 79 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
ff8bfdbb 80
b292e2f5 81 m_parent->AddChild( this );
6ca41e57 82
b292e2f5 83 (m_parent->m_insertCallback)( m_parent, this );
ff8bfdbb 84
b292e2f5 85 PostCreation();
ff8bfdbb 86
b292e2f5 87 gtk_widget_realize( GTK_BUTTON( m_widget )->child );
ff8bfdbb 88
b292e2f5 89 SetLabel( label );
d84eb083 90
b292e2f5
RR
91 SetBackgroundColour( parent->GetBackgroundColour() );
92 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 93 SetFont( parent->GetFont() );
f96aa4d9 94
b292e2f5 95 Show( TRUE );
ff8bfdbb 96
b292e2f5 97 return TRUE;
6de97a3b 98}
c801d85f 99
debe6624 100void wxCheckBox::SetValue( bool state )
c801d85f 101{
b292e2f5 102 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
ff8bfdbb 103
8bf45ed1
VZ
104 if ( state == GetValue() )
105 return;
106
107 // for compatibility with wxMSW don't send notification when the check box
108 // state is changed programmatically
b292e2f5 109 m_blockFirstEvent = TRUE;
ae0bdb01 110
b292e2f5 111 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state );
6de97a3b 112}
c801d85f 113
83058c58 114bool wxCheckBox::GetValue() const
c801d85f 115{
b292e2f5 116 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
f96aa4d9 117
b292e2f5 118 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b 119}
c801d85f 120
83058c58
RR
121void wxCheckBox::SetLabel( const wxString& label )
122{
b292e2f5 123 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
f96aa4d9 124
b292e2f5 125 wxControl::SetLabel( label );
ff8bfdbb 126
b292e2f5 127 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
83058c58
RR
128}
129
d3904ceb
RR
130void wxCheckBox::Enable( bool enable )
131{
b292e2f5 132 wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
f96aa4d9 133
b292e2f5 134 wxControl::Enable( enable );
ff8bfdbb 135
b292e2f5 136 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
d3904ceb
RR
137}
138
58614078 139void wxCheckBox::ApplyWidgetStyle()
868a2826 140{
b292e2f5
RR
141 SetWidgetStyle();
142 gtk_widget_set_style( m_widget, m_widgetStyle );
143 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
f96aa4d9
RR
144}
145
f96aa4d9 146