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