]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
(1) Denis Pershin's patch for wxGTK (memory leaks corrections)
[wxWidgets.git] / src / gtk1 / checkbox.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: checkbox.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "checkbox.h"
14#endif
15
16#include "wx/checkbox.h"
17
66bd6b93
RR
18//-----------------------------------------------------------------------------
19// data
20//-----------------------------------------------------------------------------
21
22extern bool g_blockEventsOnDrag;
23
c801d85f
KB
24//-----------------------------------------------------------------------------
25// wxCheckBox
26//-----------------------------------------------------------------------------
27
66bd6b93 28static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
c801d85f 29{
66bd6b93
RR
30 if (!cb->HasVMT()) return;
31 if (g_blockEventsOnDrag) return;
32
c801d85f
KB
33 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
34 event.SetInt( cb->GetValue() );
35 event.SetEventObject(cb);
47908e25 36 cb->GetEventHandler()->ProcessEvent(event);
c801d85f
KB
37};
38
39//-----------------------------------------------------------------------------
40
41IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
42
43wxCheckBox::wxCheckBox(void)
44{
45};
46
47wxCheckBox::wxCheckBox( wxWindow *parent, wxWindowID id, const wxString &label,
48 const wxPoint &pos, const wxSize &size,
debe6624 49 long style, const wxString &name )
c801d85f
KB
50{
51 Create( parent, id, label, pos, size, style, name );
52};
53
54bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
55 const wxPoint &pos, const wxSize &size,
debe6624 56 long style, const wxString &name )
c801d85f
KB
57{
58 m_needParent = TRUE;
59
60 PreCreation( parent, id, pos, size, style, name );
61
7a4b9130
GL
62 SetLabel( label );
63
c801d85f
KB
64 m_widget = gtk_check_button_new_with_label( label );
65
66 wxSize newSize = size;
67 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
68 if (newSize.y == -1) newSize.y = 26;
69 SetSize( newSize.x, newSize.y );
70
71 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
72 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
73
74 PostCreation();
75
76 Show( TRUE );
77
78 return TRUE;
79};
80
debe6624 81void wxCheckBox::SetValue( bool state )
c801d85f
KB
82{
83 if (state)
84 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_ACTIVE );
85 else
86 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_NORMAL );
87};
88
89bool wxCheckBox::GetValue(void) const
90{
91 GtkToggleButton *tb = GTK_TOGGLE_BUTTON(m_widget);
92 return tb->active;
93};
94