]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/checkbox.cpp
Added sashtest GTK makefiles (crashing bug to be solved); added typetest sample
[wxWidgets.git] / src / gtk / checkbox.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: checkbox.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "checkbox.h"
14#endif
15
16#include "wx/checkbox.h"
17
66bd6b93
RR
18//-----------------------------------------------------------------------------
19// data
20//-----------------------------------------------------------------------------
21
22extern bool g_blockEventsOnDrag;
23
c801d85f 24//-----------------------------------------------------------------------------
e1e955e1 25// "clicked"
c801d85f
KB
26//-----------------------------------------------------------------------------
27
66bd6b93 28static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
c801d85f 29{
66bd6b93
RR
30 if (!cb->HasVMT()) return;
31 if (g_blockEventsOnDrag) return;
32
c801d85f
KB
33 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
34 event.SetInt( cb->GetValue() );
35 event.SetEventObject(cb);
47908e25 36 cb->GetEventHandler()->ProcessEvent(event);
6de97a3b 37}
c801d85f 38
e1e955e1
RR
39//-----------------------------------------------------------------------------
40// wxCheckBox
c801d85f
KB
41//-----------------------------------------------------------------------------
42
43IMPLEMENT_DYNAMIC_CLASS(wxCheckBox,wxControl)
44
45wxCheckBox::wxCheckBox(void)
46{
6de97a3b 47}
c801d85f
KB
48
49bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label,
50 const wxPoint &pos, const wxSize &size,
6de97a3b 51 long style, const wxValidator& validator, const wxString &name )
c801d85f
KB
52{
53 m_needParent = TRUE;
54
55 PreCreation( parent, id, pos, size, style, name );
56
6de97a3b
RR
57 SetValidator( validator );
58
1280032d 59 m_widget = gtk_check_button_new_with_label( m_label );
c801d85f
KB
60
61 wxSize newSize = size;
62 if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
63 if (newSize.y == -1) newSize.y = 26;
64 SetSize( newSize.x, newSize.y );
65
66 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
67 GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
68
69 PostCreation();
70
d84eb083
RR
71 SetLabel( label );
72
c801d85f
KB
73 Show( TRUE );
74
75 return TRUE;
6de97a3b 76}
c801d85f 77
debe6624 78void wxCheckBox::SetValue( bool state )
c801d85f
KB
79{
80 if (state)
81 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_ACTIVE );
82 else
83 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), GTK_STATE_NORMAL );
6de97a3b 84}
c801d85f 85
83058c58 86bool wxCheckBox::GetValue() const
c801d85f
KB
87{
88 GtkToggleButton *tb = GTK_TOGGLE_BUTTON(m_widget);
89 return tb->active;
6de97a3b 90}
c801d85f 91
83058c58
RR
92void wxCheckBox::SetLabel( const wxString& label )
93{
94 wxControl::SetLabel( label );
95 GtkButton *bin = GTK_BUTTON( m_widget );
96 GtkLabel *g_label = GTK_LABEL( bin->child );
97 gtk_label_set( g_label, GetLabel() );
98}
99
d3904ceb
RR
100void wxCheckBox::Enable( bool enable )
101{
102 wxControl::Enable( enable );
103 GtkButton *bin = GTK_BUTTON( m_widget );
104 GtkWidget *label = bin->child;
105 gtk_widget_set_sensitive( label, enable );
106}
107
868a2826
RR
108void wxCheckBox::SetFont( const wxFont &font )
109{
3f659fd6
RR
110 if (((wxFont*)&font)->Ok())
111 m_font = font;
112 else
113 m_font = *wxSWISS_FONT;
868a2826
RR
114
115 GtkButton *bin = GTK_BUTTON( m_widget );
116 GtkWidget *label = bin->child;
117
118 GtkStyle *style = (GtkStyle*) NULL;
119 if (!m_hasOwnStyle)
120 {
121 m_hasOwnStyle = TRUE;
122 style = gtk_style_copy( gtk_widget_get_style( label ) );
123 }
124 else
125 {
126 style = gtk_widget_get_style( label );
127 }
128
129 gdk_font_unref( style->font );
130 style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
131
132 gtk_widget_set_style( label, style );
133}