]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
Put braces around all calls to wxLogFunctions() inside an if statement.
[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
61IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
62
2cc0e28f 63wxCheckBox::wxCheckBox()
c801d85f 64{
6de97a3b 65}
c801d85f 66
2cc0e28f
VZ
67bool wxCheckBox::Create(wxWindow *parent,
68 wxWindowID id,
69 const wxString &label,
70 const wxPoint &pos,
71 const wxSize &size,
72 long style,
73 const wxValidator& validator,
74 const wxString &name )
c801d85f 75{
93763ad5
WS
76 m_needParent = true;
77 m_acceptsFocus = true;
78 m_blockEvent = false;
ff8bfdbb 79
4dcaf11a
RR
80 if (!PreCreation( parent, pos, size ) ||
81 !CreateBase( parent, id, pos, size, style, validator, name ))
82 {
223d09f6 83 wxFAIL_MSG( wxT("wxCheckBox creation failed") );
93763ad5 84 return false;
4dcaf11a 85 }
ce4169a4 86
4dcccda6
VS
87 wxASSERT_MSG( (style & wxCHK_ALLOW_3RD_STATE_FOR_USER) == 0 ||
88 (style & wxCHK_3STATE) != 0,
89 wxT("Using wxCHK_ALLOW_3RD_STATE_FOR_USER")
90 wxT(" style flag for a 2-state checkbox is useless") );
91
2cc0e28f
VZ
92 if ( style & wxALIGN_RIGHT )
93 {
94 // VZ: as I don't know a way to create a right aligned checkbox with
95 // GTK we will create a checkbox without label and a label at the
96 // left of it
97 m_widgetCheckbox = gtk_check_button_new();
6de97a3b 98
eaafd2f8 99 m_widgetLabel = gtk_label_new("");
2cc0e28f 100 gtk_misc_set_alignment(GTK_MISC(m_widgetLabel), 0.0, 0.5);
ff8bfdbb 101
2cc0e28f
VZ
102 m_widget = gtk_hbox_new(FALSE, 0);
103 gtk_box_pack_start(GTK_BOX(m_widget), m_widgetLabel, FALSE, FALSE, 3);
104 gtk_box_pack_start(GTK_BOX(m_widget), m_widgetCheckbox, FALSE, FALSE, 3);
105
2cc0e28f
VZ
106 gtk_widget_show( m_widgetLabel );
107 gtk_widget_show( m_widgetCheckbox );
108 }
109 else
110 {
eaafd2f8 111 m_widgetCheckbox = gtk_check_button_new_with_label("");
9e691f46 112 m_widgetLabel = BUTTON_CHILD( m_widgetCheckbox );
2cc0e28f
VZ
113 m_widget = m_widgetCheckbox;
114 }
eaafd2f8 115 SetLabel( label );
2cc0e28f 116
2cc0e28f 117 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
4dcccda6
VS
118 "toggled",
119 GTK_SIGNAL_FUNC(gtk_checkbox_toggled_callback),
2cc0e28f 120 (gpointer *)this );
ff8bfdbb 121
f03fc89f 122 m_parent->DoAddChild( this );
ff8bfdbb 123
abdeb9e7 124 PostCreation(size);
ff8bfdbb 125
93763ad5 126 return true;
6de97a3b 127}
c801d85f 128
debe6624 129void wxCheckBox::SetValue( bool state )
c801d85f 130{
223d09f6 131 wxCHECK_RET( m_widgetCheckbox != NULL, wxT("invalid checkbox") );
ff8bfdbb 132
953704c1 133 if (state == GetValue())
8bf45ed1
VZ
134 return;
135
93763ad5 136 m_blockEvent = true;
ae0bdb01 137
2cc0e28f 138 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox), state );
1db8dc4a 139
93763ad5 140 m_blockEvent = false;
6de97a3b 141}
c801d85f 142
83058c58 143bool wxCheckBox::GetValue() const
c801d85f 144{
93763ad5 145 wxCHECK_MSG( m_widgetCheckbox != NULL, false, wxT("invalid checkbox") );
f96aa4d9 146
2cc0e28f 147 return GTK_TOGGLE_BUTTON(m_widgetCheckbox)->active;
4dcccda6 148}
4dcccda6 149
83058c58
RR
150void wxCheckBox::SetLabel( const wxString& label )
151{
223d09f6 152 wxCHECK_RET( m_widgetLabel != NULL, wxT("invalid checkbox") );
f96aa4d9 153
b2ff89d6 154 GTKSetLabelForLabel(GTK_LABEL(m_widgetLabel), label);
83058c58
RR
155}
156
f03fc89f 157bool wxCheckBox::Enable( bool enable )
d3904ceb 158{
f03fc89f 159 if ( !wxControl::Enable( enable ) )
93763ad5 160 return false;
ff8bfdbb 161
2cc0e28f 162 gtk_widget_set_sensitive( m_widgetLabel, enable );
f03fc89f 163
93763ad5 164 return true;
d3904ceb
RR
165}
166
f40fdaa3 167void wxCheckBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 168{
f40fdaa3
VS
169 gtk_widget_modify_style(m_widgetCheckbox, style);
170 gtk_widget_modify_style(m_widgetLabel, style);
f96aa4d9
RR
171}
172
2f073eb2
RR
173bool wxCheckBox::IsOwnGtkWindow( GdkWindow *window )
174{
9e691f46 175 return window == TOGGLE_BUTTON_EVENT_WIN(m_widget);
2f073eb2
RR
176}
177
178void wxCheckBox::OnInternalIdle()
179{
180 wxCursor cursor = m_cursor;
181 if (g_globalCursor.Ok()) cursor = g_globalCursor;
182
9e691f46
VZ
183 GdkWindow *event_window = TOGGLE_BUTTON_EVENT_WIN(m_widgetCheckbox);
184 if ( event_window && cursor.Ok() )
2f073eb2
RR
185 {
186 /* I now set the cursor the anew in every OnInternalIdle call
1db8dc4a
VZ
187 as setting the cursor in a parent window also effects the
188 windows above so that checking for the current cursor is
189 not possible. */
190
9e691f46 191 gdk_window_set_cursor( event_window, cursor.GetCursor() );
2f073eb2
RR
192 }
193
d7fa7eaa
RR
194 if (g_delayedFocus == this)
195 {
196 if (GTK_WIDGET_REALIZED(m_widget))
197 {
198 gtk_widget_grab_focus( m_widget );
199 g_delayedFocus = NULL;
200 }
201 }
3d257b8d 202
e39af974
JS
203 if (wxUpdateUIEvent::CanUpdate(this))
204 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2f073eb2
RR
205}
206
f68586e5
VZ
207wxSize wxCheckBox::DoGetBestSize() const
208{
db434467 209 return wxControl::DoGetBestSize();
f68586e5
VZ
210}
211
9d522606
RD
212// static
213wxVisualAttributes
214wxCheckBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
215{
216 return GetDefaultAttributesFromGTKWidget(gtk_check_button_new);
217}
218
dcf924a3 219#endif