]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/checkbox.cpp
Fixed a compliation error, event args should not be const.
[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
14f355c2 11#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
12#pragma implementation "checkbox.h"
13#endif
14
14f355c2
VS
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
1e6feb95 18#include "wx/defs.h"
c801d85f 19
dcf924a3
RR
20#if wxUSE_CHECKBOX
21
1e6feb95
VZ
22#include "wx/checkbox.h"
23
9e691f46 24#include "wx/gtk/private.h"
83624f79 25
acfd422a
RR
26//-----------------------------------------------------------------------------
27// idle system
28//-----------------------------------------------------------------------------
29
30extern void wxapp_install_idle_handler();
31extern bool g_isIdle;
32
66bd6b93
RR
33//-----------------------------------------------------------------------------
34// data
35//-----------------------------------------------------------------------------
36
d7fa7eaa
RR
37extern bool g_blockEventsOnDrag;
38extern wxCursor g_globalCursor;
39extern wxWindowGTK *g_delayedFocus;
66bd6b93 40
c801d85f 41//-----------------------------------------------------------------------------
e1e955e1 42// "clicked"
c801d85f
KB
43//-----------------------------------------------------------------------------
44
66bd6b93 45static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
c801d85f 46{
acfd422a
RR
47 if (g_isIdle) wxapp_install_idle_handler();
48
a2053b27 49 if (!cb->m_hasVMT) return;
ff8bfdbb 50
b292e2f5 51 if (g_blockEventsOnDrag) return;
9864c56d
RR
52
53 if (cb->m_blockEvent) return;
ff8bfdbb 54
b292e2f5
RR
55 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
56 event.SetInt( cb->GetValue() );
57 event.SetEventObject(cb);
58 cb->GetEventHandler()->ProcessEvent(event);
6de97a3b 59}
c801d85f 60
e1e955e1
RR
61//-----------------------------------------------------------------------------
62// wxCheckBox
c801d85f
KB
63//-----------------------------------------------------------------------------
64
65IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
66
2cc0e28f 67wxCheckBox::wxCheckBox()
c801d85f 68{
6de97a3b 69}
c801d85f 70
2cc0e28f
VZ
71bool wxCheckBox::Create(wxWindow *parent,
72 wxWindowID id,
73 const wxString &label,
74 const wxPoint &pos,
75 const wxSize &size,
76 long style,
77 const wxValidator& validator,
78 const wxString &name )
c801d85f 79{
b292e2f5
RR
80 m_needParent = TRUE;
81 m_acceptsFocus = TRUE;
9864c56d 82 m_blockEvent = FALSE;
ff8bfdbb 83
4dcaf11a
RR
84 if (!PreCreation( parent, pos, size ) ||
85 !CreateBase( parent, id, pos, size, style, validator, name ))
86 {
223d09f6 87 wxFAIL_MSG( wxT("wxCheckBox creation failed") );
1db8dc4a 88 return FALSE;
4dcaf11a 89 }
ce4169a4 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
VZ
116 gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
117 "clicked",
118 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback),
119 (gpointer *)this );
ff8bfdbb 120
f03fc89f 121 m_parent->DoAddChild( this );
ff8bfdbb 122
b292e2f5 123 PostCreation();
e8e24dfa 124 InheritAttributes();
db434467
RR
125
126 wxSize size_best( DoGetBestSize() );
127 wxSize new_size( size );
128 if (new_size.x == -1)
129 new_size.x = size_best.x;
130 if (new_size.y == -1)
131 new_size.y = size_best.y;
132 if ((new_size.x != size.x) || (new_size.y != size.y))
133 SetSize( new_size.x, new_size.y );
134
b292e2f5 135 Show( TRUE );
ff8bfdbb 136
b292e2f5 137 return TRUE;
6de97a3b 138}
c801d85f 139
debe6624 140void wxCheckBox::SetValue( bool state )
c801d85f 141{
223d09f6 142 wxCHECK_RET( m_widgetCheckbox != NULL, wxT("invalid checkbox") );
ff8bfdbb 143
953704c1 144 if (state == GetValue())
8bf45ed1
VZ
145 return;
146
9864c56d 147 m_blockEvent = TRUE;
ae0bdb01 148
2cc0e28f 149 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widgetCheckbox), state );
1db8dc4a 150
9864c56d 151 m_blockEvent = FALSE;
6de97a3b 152}
c801d85f 153
83058c58 154bool wxCheckBox::GetValue() const
c801d85f 155{
223d09f6 156 wxCHECK_MSG( m_widgetCheckbox != NULL, FALSE, wxT("invalid checkbox") );
f96aa4d9 157
2cc0e28f 158 return GTK_TOGGLE_BUTTON(m_widgetCheckbox)->active;
6de97a3b 159}
c801d85f 160
83058c58
RR
161void wxCheckBox::SetLabel( const wxString& label )
162{
223d09f6 163 wxCHECK_RET( m_widgetLabel != NULL, wxT("invalid checkbox") );
f96aa4d9 164
b292e2f5 165 wxControl::SetLabel( label );
ff8bfdbb 166
eaafd2f8
VS
167#ifdef __WXGTK20__
168 wxString label2 = PrepareLabelMnemonics( label );
169 gtk_label_set_text_with_mnemonic( GTK_LABEL(m_widgetLabel), wxGTK_CONV( label2 ) );
170#else
fab591c5 171 gtk_label_set( GTK_LABEL(m_widgetLabel), wxGTK_CONV( GetLabel() ) );
eaafd2f8 172#endif
83058c58
RR
173}
174
f03fc89f 175bool wxCheckBox::Enable( bool enable )
d3904ceb 176{
f03fc89f
VZ
177 if ( !wxControl::Enable( enable ) )
178 return FALSE;
ff8bfdbb 179
2cc0e28f 180 gtk_widget_set_sensitive( m_widgetLabel, enable );
f03fc89f
VZ
181
182 return TRUE;
d3904ceb
RR
183}
184
58614078 185void wxCheckBox::ApplyWidgetStyle()
868a2826 186{
b292e2f5 187 SetWidgetStyle();
2cc0e28f
VZ
188 gtk_widget_set_style( m_widgetCheckbox, m_widgetStyle );
189 gtk_widget_set_style( m_widgetLabel, m_widgetStyle );
f96aa4d9
RR
190}
191
2f073eb2
RR
192bool wxCheckBox::IsOwnGtkWindow( GdkWindow *window )
193{
9e691f46 194 return window == TOGGLE_BUTTON_EVENT_WIN(m_widget);
2f073eb2
RR
195}
196
197void wxCheckBox::OnInternalIdle()
198{
199 wxCursor cursor = m_cursor;
200 if (g_globalCursor.Ok()) cursor = g_globalCursor;
201
9e691f46
VZ
202 GdkWindow *event_window = TOGGLE_BUTTON_EVENT_WIN(m_widgetCheckbox);
203 if ( event_window && cursor.Ok() )
2f073eb2
RR
204 {
205 /* I now set the cursor the anew in every OnInternalIdle call
1db8dc4a
VZ
206 as setting the cursor in a parent window also effects the
207 windows above so that checking for the current cursor is
208 not possible. */
209
9e691f46 210 gdk_window_set_cursor( event_window, cursor.GetCursor() );
2f073eb2
RR
211 }
212
d7fa7eaa
RR
213 if (g_delayedFocus == this)
214 {
215 if (GTK_WIDGET_REALIZED(m_widget))
216 {
217 gtk_widget_grab_focus( m_widget );
218 g_delayedFocus = NULL;
219 }
220 }
221
e39af974
JS
222 if (wxUpdateUIEvent::CanUpdate(this))
223 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2f073eb2
RR
224}
225
f68586e5
VZ
226wxSize wxCheckBox::DoGetBestSize() const
227{
db434467 228 return wxControl::DoGetBestSize();
f68586e5
VZ
229}
230
dcf924a3 231#endif