]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/button.cpp
Disabled masked bitmaps under GTK 2.0 until I know
[wxWidgets.git] / src / gtk / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "button.h"
12 #endif
13
14 #include "wx/defs.h"
15
16 #if wxUSE_BUTTON
17
18 #include "wx/button.h"
19
20 #include "wx/gtk/private.h"
21
22 //-----------------------------------------------------------------------------
23 // classes
24 //-----------------------------------------------------------------------------
25
26 class wxButton;
27
28 //-----------------------------------------------------------------------------
29 // idle system
30 //-----------------------------------------------------------------------------
31
32 extern void wxapp_install_idle_handler();
33 extern bool g_isIdle;
34
35 //-----------------------------------------------------------------------------
36 // data
37 //-----------------------------------------------------------------------------
38
39 extern bool g_blockEventsOnDrag;
40
41 //-----------------------------------------------------------------------------
42 // "clicked"
43 //-----------------------------------------------------------------------------
44
45 static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
46 {
47 if (g_isIdle)
48 wxapp_install_idle_handler();
49
50 if (!button->m_hasVMT) return;
51 if (g_blockEventsOnDrag) return;
52
53 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
54 event.SetEventObject(button);
55 button->GetEventHandler()->ProcessEvent(event);
56 }
57
58 //-----------------------------------------------------------------------------
59 // wxButton
60 //-----------------------------------------------------------------------------
61
62 IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
63
64 wxButton::wxButton()
65 {
66 }
67
68 wxButton::~wxButton()
69 {
70 }
71
72 bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
73 const wxPoint &pos, const wxSize &size,
74 long style, const wxValidator& validator, const wxString &name )
75 {
76 m_needParent = TRUE;
77 m_acceptsFocus = TRUE;
78
79 if (!PreCreation( parent, pos, size ) ||
80 !CreateBase( parent, id, pos, size, style, validator, name ))
81 {
82 wxFAIL_MSG( wxT("wxButton creation failed") );
83 return FALSE;
84 }
85
86 /*
87 wxString label2( label );
88 for (size_t i = 0; i < label2.Len(); i++)
89 {
90 if (label2.GetChar(i) == wxT('&'))
91 label2.SetChar(i,wxT('_'));
92 }
93
94 GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
95 gtk_widget_show( accel_label );
96
97 m_widget = gtk_button_new();
98 gtk_container_add( GTK_CONTAINER(m_widget), accel_label );
99
100 gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget );
101
102 guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() );
103 gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) );
104
105 wxControl::SetLabel( label );
106 */
107
108 m_widget = gtk_button_new_with_label("");
109
110 SetLabel( label );
111
112 #if (GTK_MINOR_VERSION > 0)
113 if (style & wxNO_BORDER)
114 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
115 #endif
116
117 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
118 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
119
120 m_parent->DoAddChild( this );
121
122 PostCreation();
123
124 SetFont( parent->GetFont() );
125
126 wxSize best_size( DoGetBestSize() );
127 wxSize new_size( size );
128 if (new_size.x == -1)
129 new_size.x = best_size.x;
130 if (new_size.y == -1)
131 new_size.y = best_size.y;
132 if ((new_size.x != size.x) || (new_size.y != size.y))
133 SetSize( new_size.x, new_size.y );
134
135 SetSize( new_size );
136
137 SetBackgroundColour( parent->GetBackgroundColour() );
138 SetForegroundColour( parent->GetForegroundColour() );
139
140 Show( TRUE );
141
142 return TRUE;
143 }
144
145 void wxButton::SetDefault()
146 {
147 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
148 gtk_widget_grab_default( m_widget );
149
150 SetSize( m_x, m_y, m_width, m_height );
151 }
152
153 /* static */
154 wxSize wxButton::GetDefaultSize()
155 {
156 return wxSize(80,26);
157 }
158
159 void wxButton::SetLabel( const wxString &label )
160 {
161 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
162
163 wxControl::SetLabel( label );
164
165 gtk_label_set( GTK_LABEL( BUTTON_CHILD(m_widget) ), GetLabel().mbc_str() );
166 }
167
168 bool wxButton::Enable( bool enable )
169 {
170 if ( !wxControl::Enable( enable ) )
171 return FALSE;
172
173 gtk_widget_set_sensitive( BUTTON_CHILD(m_widget), enable );
174
175 return TRUE;
176 }
177
178 void wxButton::ApplyWidgetStyle()
179 {
180 SetWidgetStyle();
181 gtk_widget_set_style( m_widget, m_widgetStyle );
182 gtk_widget_set_style( BUTTON_CHILD(m_widget), m_widgetStyle );
183 }
184
185 wxSize wxButton::DoGetBestSize() const
186 {
187 wxSize ret( wxControl::DoGetBestSize() );
188
189 if (!HasFlag(wxBU_EXACTFIT))
190 {
191 if (ret.x < 80) ret.x = 80;
192 }
193
194 return ret;
195 }
196
197 #endif // wxUSE_BUTTON
198