]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
added virtual bool wxWindow::AcceptsFocus()
[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
18//-----------------------------------------------------------------------------
19// wxCheckBox
20//-----------------------------------------------------------------------------
21
22void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), gpointer data )
23{
24 wxCheckBox *cb = (wxCheckBox*)data;
25 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
26 event.SetInt( cb->GetValue() );
27 event.SetEventObject(cb);
28 cb->ProcessEvent(event);
29};
30
31//-----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
34
35wxCheckBox::wxCheckBox(void)
36{
37};
38
39wxCheckBox::wxCheckBox( wxWindow *parent, wxWindowID id, const wxString &label,
40 const wxPoint &pos, const wxSize &size,
debe6624 41 long style, const wxString &name )
c801d85f
KB
42{
43 Create( parent, id, label, pos, size, style, name );
44};
45
46bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
47 const wxPoint &pos, const wxSize &size,
debe6624 48 long style, const wxString &name )
c801d85f
KB
49{
50 m_needParent = TRUE;
51
52 PreCreation( parent, id, pos, size, style, name );
53
54 m_widget = gtk_check_button_new_with_label( label );
55
56 wxSize newSize = size;
57 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
58 if (newSize.y == -1) newSize.y = 26;
59 SetSize( newSize.x, newSize.y );
60
61 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
62 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
63
64 PostCreation();
65
66 Show( TRUE );
67
68 return TRUE;
69};
70
debe6624 71void wxCheckBox::SetValue( bool state )
c801d85f
KB
72{
73 if (state)
74 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_ACTIVE );
75 else
76 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_NORMAL );
77};
78
79bool wxCheckBox::GetValue(void) const
80{
81 GtkToggleButton *tb = GTK_TOGGLE_BUTTON(m_widget);
82 return tb->active;
83};
84