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