]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
Added XRC handler for wxTimePickerCtrl.
[wxWidgets.git] / src / gtk1 / checkbox.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/gtk1/checkbox.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
dbf858b5 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
dcf924a3
RR
13#if wxUSE_CHECKBOX
14
1e6feb95
VZ
15#include "wx/checkbox.h"
16
3cbab641 17#include "wx/gtk1/private.h"
83624f79 18
acfd422a
RR
19//-----------------------------------------------------------------------------
20// idle system
21//-----------------------------------------------------------------------------
22
23extern void wxapp_install_idle_handler();
24extern bool g_isIdle;
25
66bd6b93
RR
26//-----------------------------------------------------------------------------
27// data
28//-----------------------------------------------------------------------------
29
d7fa7eaa
RR
30extern bool g_blockEventsOnDrag;
31extern wxCursor g_globalCursor;
32extern wxWindowGTK *g_delayedFocus;
66bd6b93 33
c801d85f 34//-----------------------------------------------------------------------------
e1e955e1 35// "clicked"
c801d85f
KB
36//-----------------------------------------------------------------------------
37
865bb325 38extern "C" {
89954433
VZ
39static void gtk_checkbox_toggled_callback(GtkWidget *WXUNUSED(widget),
40 wxCheckBox *cb)
c801d85f 41{
acfd422a
RR
42 if (g_isIdle) wxapp_install_idle_handler();
43
a2053b27 44 if (!cb->m_hasVMT) return;
ff8bfdbb 45
b292e2f5 46 if (g_blockEventsOnDrag) return;
3d257b8d 47
9864c56d 48 if (cb->m_blockEvent) return;
ff8bfdbb 49
b292e2f5 50 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
4dcccda6 51 event.SetInt(cb->GetValue());
b292e2f5 52 event.SetEventObject(cb);
937013e0 53 cb->HandleWindowEvent(event);
6de97a3b 54}
865bb325 55}
c801d85f 56
e1e955e1
RR
57//-----------------------------------------------------------------------------
58// wxCheckBox
c801d85f
KB
59//-----------------------------------------------------------------------------
60
2cc0e28f 61wxCheckBox::wxCheckBox()
c801d85f 62{
6de97a3b 63}
c801d85f 64
2cc0e28f
VZ
65bool wxCheckBox::Create(wxWindow *parent,
66 wxWindowID id,
67 const wxString &label,
68 const wxPoint &pos,
69 const wxSize &size,
70 long style,
71 const wxValidator& validator,
72 const wxString &name )
c801d85f 73{
93763ad5
WS
74 m_needParent = true;
75 m_acceptsFocus = true;
76 m_blockEvent = false;
ff8bfdbb 77
f254e242 78 WXValidateStyle(&style);
4dcaf11a
RR
79 if (!PreCreation( parent, pos, size ) ||
80 !CreateBase( parent, id, pos, size, style, validator, name ))
81 {
223d09f6 82 wxFAIL_MSG( wxT("wxCheckBox creation failed") );
93763ad5 83 return false;
4dcaf11a 84 }
ce4169a4 85
2cc0e28f
VZ
86 if ( style & wxALIGN_RIGHT )
87 {
88 // VZ: as I don't know a way to create a right aligned checkbox with
89 // GTK we will create a checkbox without label and a label at the
90 // left of it
91 m_widgetCheckbox = gtk_check_button_new();
6de97a3b 92
eaafd2f8 93 m_widgetLabel = gtk_label_new("");
2cc0e28f 94 gtk_misc_set_alignment(GTK_MISC(m_widgetLabel), 0.0, 0.5);
ff8bfdbb 95
2cc0e28f
VZ
96 m_widget = gtk_hbox_new(FALSE, 0);
97 gtk_box_pack_start(GTK_BOX(m_widget), m_widgetLabel, FALSE, FALSE, 3);
98 gtk_box_pack_start(GTK_BOX(m_widget), m_widgetCheckbox, FALSE, FALSE, 3);
99
2cc0e28f
VZ
100 gtk_widget_show( m_widgetLabel );
101 gtk_widget_show( m_widgetCheckbox );
102 }
103 else
104 {
eaafd2f8 105 m_widgetCheckbox = gtk_check_button_new_with_label("");
9e691f46 106 m_widgetLabel = BUTTON_CHILD( m_widgetCheckbox );
2cc0e28f
VZ
107 m_widget = m_widgetCheckbox;
108 }
eaafd2f8 109 SetLabel( label );
2cc0e28f 110
2cc0e28f 111 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
4dcccda6
VS
112 "toggled",
113 GTK_SIGNAL_FUNC(gtk_checkbox_toggled_callback),
2cc0e28f 114 (gpointer *)this );
ff8bfdbb 115
f03fc89f 116 m_parent->DoAddChild( this );
ff8bfdbb 117
abdeb9e7 118 PostCreation(size);
ff8bfdbb 119
93763ad5 120 return true;
6de97a3b 121}
c801d85f 122
debe6624 123void wxCheckBox::SetValue( bool state )
c801d85f 124{
223d09f6 125 wxCHECK_RET( m_widgetCheckbox != NULL, wxT("invalid checkbox") );
ff8bfdbb 126
953704c1 127 if (state == GetValue())
8bf45ed1
VZ
128 return;
129
93763ad5 130 m_blockEvent = true;
ae0bdb01 131
2cc0e28f 132 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox), state );
1db8dc4a 133
93763ad5 134 m_blockEvent = false;
6de97a3b 135}
c801d85f 136
83058c58 137bool wxCheckBox::GetValue() const
c801d85f 138{
93763ad5 139 wxCHECK_MSG( m_widgetCheckbox != NULL, false, wxT("invalid checkbox") );
f96aa4d9 140
2cc0e28f 141 return GTK_TOGGLE_BUTTON(m_widgetCheckbox)->active;
4dcccda6 142}
4dcccda6 143
83058c58
RR
144void wxCheckBox::SetLabel( const wxString& label )
145{
223d09f6 146 wxCHECK_RET( m_widgetLabel != NULL, wxT("invalid checkbox") );
f96aa4d9 147
b2ff89d6 148 GTKSetLabelForLabel(GTK_LABEL(m_widgetLabel), label);
83058c58
RR
149}
150
f03fc89f 151bool wxCheckBox::Enable( bool enable )
d3904ceb 152{
f03fc89f 153 if ( !wxControl::Enable( enable ) )
93763ad5 154 return false;
ff8bfdbb 155
2cc0e28f 156 gtk_widget_set_sensitive( m_widgetLabel, enable );
f03fc89f 157
93763ad5 158 return true;
d3904ceb
RR
159}
160
f40fdaa3 161void wxCheckBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 162{
f40fdaa3
VS
163 gtk_widget_modify_style(m_widgetCheckbox, style);
164 gtk_widget_modify_style(m_widgetLabel, style);
f96aa4d9
RR
165}
166
2f073eb2
RR
167bool wxCheckBox::IsOwnGtkWindow( GdkWindow *window )
168{
9e691f46 169 return window == TOGGLE_BUTTON_EVENT_WIN(m_widget);
2f073eb2
RR
170}
171
172void wxCheckBox::OnInternalIdle()
173{
174 wxCursor cursor = m_cursor;
a1b806b9 175 if (g_globalCursor.IsOk()) cursor = g_globalCursor;
2f073eb2 176
9e691f46 177 GdkWindow *event_window = TOGGLE_BUTTON_EVENT_WIN(m_widgetCheckbox);
a1b806b9 178 if ( event_window && cursor.IsOk() )
2f073eb2
RR
179 {
180 /* I now set the cursor the anew in every OnInternalIdle call
1db8dc4a
VZ
181 as setting the cursor in a parent window also effects the
182 windows above so that checking for the current cursor is
183 not possible. */
184
9e691f46 185 gdk_window_set_cursor( event_window, cursor.GetCursor() );
2f073eb2
RR
186 }
187
d7fa7eaa
RR
188 if (g_delayedFocus == this)
189 {
190 if (GTK_WIDGET_REALIZED(m_widget))
191 {
192 gtk_widget_grab_focus( m_widget );
193 g_delayedFocus = NULL;
194 }
195 }
3d257b8d 196
e39af974
JS
197 if (wxUpdateUIEvent::CanUpdate(this))
198 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2f073eb2
RR
199}
200
f68586e5
VZ
201wxSize wxCheckBox::DoGetBestSize() const
202{
db434467 203 return wxControl::DoGetBestSize();
f68586e5
VZ
204}
205
9d522606
RD
206// static
207wxVisualAttributes
208wxCheckBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
209{
210 return GetDefaultAttributesFromGTKWidget(gtk_check_button_new);
211}
212
dcf924a3 213#endif