]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
Documented help API extension and fixed gsocket compilation.
[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
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
dcf924a3
RR
17#if wxUSE_CHECKBOX
18
83624f79
RR
19#include "gdk/gdk.h"
20#include "gtk/gtk.h"
21
acfd422a
RR
22//-----------------------------------------------------------------------------
23// idle system
24//-----------------------------------------------------------------------------
25
26extern void wxapp_install_idle_handler();
27extern bool g_isIdle;
28
66bd6b93
RR
29//-----------------------------------------------------------------------------
30// data
31//-----------------------------------------------------------------------------
32
33extern bool g_blockEventsOnDrag;
34
c801d85f 35//-----------------------------------------------------------------------------
e1e955e1 36// "clicked"
c801d85f
KB
37//-----------------------------------------------------------------------------
38
66bd6b93 39static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
c801d85f 40{
acfd422a
RR
41 if (g_isIdle) wxapp_install_idle_handler();
42
a2053b27 43 if (!cb->m_hasVMT) return;
ff8bfdbb 44
b292e2f5 45 if (g_blockEventsOnDrag) return;
ff8bfdbb 46
b292e2f5
RR
47 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
48 event.SetInt( cb->GetValue() );
49 event.SetEventObject(cb);
50 cb->GetEventHandler()->ProcessEvent(event);
6de97a3b 51}
c801d85f 52
e1e955e1
RR
53//-----------------------------------------------------------------------------
54// wxCheckBox
c801d85f
KB
55//-----------------------------------------------------------------------------
56
57IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
58
2cc0e28f 59wxCheckBox::wxCheckBox()
c801d85f 60{
6de97a3b 61}
c801d85f 62
2cc0e28f
VZ
63bool wxCheckBox::Create(wxWindow *parent,
64 wxWindowID id,
65 const wxString &label,
66 const wxPoint &pos,
67 const wxSize &size,
68 long style,
69 const wxValidator& validator,
70 const wxString &name )
c801d85f 71{
b292e2f5
RR
72 m_needParent = TRUE;
73 m_acceptsFocus = TRUE;
ff8bfdbb 74
b292e2f5 75 PreCreation( parent, id, pos, size, style, name );
c801d85f 76
ce4169a4 77#if wxUSE_VALIDATORS
b292e2f5 78 SetValidator( validator );
ce4169a4
RR
79#endif
80
2cc0e28f
VZ
81 wxControl::SetLabel( label );
82
83 if ( style & wxALIGN_RIGHT )
84 {
85 // VZ: as I don't know a way to create a right aligned checkbox with
86 // GTK we will create a checkbox without label and a label at the
87 // left of it
88 m_widgetCheckbox = gtk_check_button_new();
6de97a3b 89
3bce7509 90 m_widgetLabel = gtk_label_new(m_label.mbc_str());
2cc0e28f 91 gtk_misc_set_alignment(GTK_MISC(m_widgetLabel), 0.0, 0.5);
ff8bfdbb 92
2cc0e28f
VZ
93 m_widget = gtk_hbox_new(FALSE, 0);
94 gtk_box_pack_start(GTK_BOX(m_widget), m_widgetLabel, FALSE, FALSE, 3);
95 gtk_box_pack_start(GTK_BOX(m_widget), m_widgetCheckbox, FALSE, FALSE, 3);
96
2cc0e28f
VZ
97 gtk_widget_show( m_widgetLabel );
98 gtk_widget_show( m_widgetCheckbox );
99 }
100 else
101 {
3bce7509 102 m_widgetCheckbox = gtk_check_button_new_with_label( m_label.mbc_str() );
2cc0e28f
VZ
103 m_widgetLabel = GTK_BUTTON( m_widgetCheckbox )->child;
104 m_widget = m_widgetCheckbox;
105 }
106
107 wxSize newSize(size);
108 if (newSize.x == -1)
109 {
110 newSize.x = 25 + gdk_string_measure( m_widgetCheckbox->style->font,
3bce7509 111 m_label.mbc_str() );
2cc0e28f
VZ
112 }
113 if (newSize.y == -1)
114 newSize.y = 26;
ff8bfdbb 115
b292e2f5 116 SetSize( newSize.x, newSize.y );
ff8bfdbb 117
2cc0e28f
VZ
118 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
119 "clicked",
120 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback),
121 (gpointer *)this );
ff8bfdbb 122
f03fc89f 123 m_parent->DoAddChild( this );
ff8bfdbb 124
b292e2f5 125 PostCreation();
ff8bfdbb 126
b292e2f5
RR
127 SetBackgroundColour( parent->GetBackgroundColour() );
128 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 129 SetFont( parent->GetFont() );
f96aa4d9 130
b292e2f5 131 Show( TRUE );
ff8bfdbb 132
b292e2f5 133 return TRUE;
6de97a3b 134}
c801d85f 135
debe6624 136void wxCheckBox::SetValue( bool state )
c801d85f 137{
3bce7509 138 wxCHECK_RET( m_widgetCheckbox != NULL, _T("invalid checkbox") );
ff8bfdbb 139
953704c1 140 if (state == GetValue())
8bf45ed1
VZ
141 return;
142
953704c1
RR
143 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widgetCheckbox),
144 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback),
145 (gpointer *)this );
ae0bdb01 146
2cc0e28f 147 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox), state );
953704c1
RR
148
149 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
150 "clicked",
151 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback),
152 (gpointer *)this );
6de97a3b 153}
c801d85f 154
83058c58 155bool wxCheckBox::GetValue() const
c801d85f 156{
3bce7509 157 wxCHECK_MSG( m_widgetCheckbox != NULL, FALSE, _T("invalid checkbox") );
f96aa4d9 158
2cc0e28f 159 return GTK_TOGGLE_BUTTON(m_widgetCheckbox)->active;
6de97a3b 160}
c801d85f 161
83058c58
RR
162void wxCheckBox::SetLabel( const wxString& label )
163{
3bce7509 164 wxCHECK_RET( m_widgetLabel != NULL, _T("invalid checkbox") );
f96aa4d9 165
b292e2f5 166 wxControl::SetLabel( label );
ff8bfdbb 167
3bce7509 168 gtk_label_set( GTK_LABEL(m_widgetLabel), GetLabel().mbc_str() );
83058c58
RR
169}
170
f03fc89f 171bool wxCheckBox::Enable( bool enable )
d3904ceb 172{
f03fc89f
VZ
173 if ( !wxControl::Enable( enable ) )
174 return FALSE;
ff8bfdbb 175
2cc0e28f 176 gtk_widget_set_sensitive( m_widgetLabel, enable );
f03fc89f
VZ
177
178 return TRUE;
d3904ceb
RR
179}
180
58614078 181void wxCheckBox::ApplyWidgetStyle()
868a2826 182{
b292e2f5 183 SetWidgetStyle();
2cc0e28f
VZ
184 gtk_widget_set_style( m_widgetCheckbox, m_widgetStyle );
185 gtk_widget_set_style( m_widgetLabel, m_widgetStyle );
f96aa4d9
RR
186}
187
dcf924a3 188#endif