1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "button.h"
15 #include "wx/button.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 extern bool g_blockEventsOnDrag
;
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxButton
*button
)
35 if (!button
->HasVMT()) return;
36 if (g_blockEventsOnDrag
) return;
38 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
39 event
.SetEventObject(button
);
40 button
->GetEventHandler()->ProcessEvent(event
);
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 IMPLEMENT_DYNAMIC_CLASS(wxButton
,wxControl
)
49 wxButton::wxButton(void)
53 bool wxButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
54 const wxPoint
&pos
, const wxSize
&size
,
55 long style
, const wxValidator
& validator
, const wxString
&name
)
59 wxSize newSize
= size
;
61 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
63 SetValidator( validator
);
65 m_widget
= gtk_button_new_with_label( m_label
);
68 if (newSize
.x
== -1) newSize
.x
= 15+gdk_string_measure( m_widget
->style
->font
, label
);
69 if (newSize
.y
== -1) newSize
.y
= 26;
70 SetSize( newSize
.x
, newSize
.y
);
72 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
73 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
82 void wxButton::SetDefault(void)
85 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
86 gtk_widget_grab_default( m_widget );
90 void wxButton::SetLabel( const wxString
&label
)
92 wxControl::SetLabel( label
);
93 GtkButton
*bin
= GTK_BUTTON( m_widget
);
94 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
95 gtk_label_set( g_label
, GetLabel() );
98 void wxButton::Enable( bool enable
)
100 wxControl::Enable( enable
);
101 GtkButton
*bin
= GTK_BUTTON( m_widget
);
102 GtkWidget
*label
= bin
->child
;
103 gtk_widget_set_sensitive( label
, enable
);
106 void wxButton::SetFont( const wxFont
&font
)
108 if (((wxFont
*)&font
)->Ok())
111 m_font
= *wxSWISS_FONT
;
113 GtkButton
*bin
= GTK_BUTTON( m_widget
);
114 GtkWidget
*label
= bin
->child
;
116 GtkStyle
*style
= (GtkStyle
*) NULL
;
119 m_hasOwnStyle
= TRUE
;
120 style
= gtk_style_copy( gtk_widget_get_style( label
) );
124 style
= gtk_widget_get_style( label
);
127 gdk_font_unref( style
->font
);
128 style
->font
= gdk_font_ref( m_font
.GetInternalFont( 1.0 ) );
130 gtk_widget_set_style( label
, style
);