1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "button.h"
14 #include "wx/button.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern void wxapp_install_idle_handler();
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern bool g_blockEventsOnDrag
;
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxButton
*button
)
45 wxapp_install_idle_handler();
47 if (!button
->m_hasVMT
) return;
48 if (g_blockEventsOnDrag
) return;
50 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
51 event
.SetEventObject(button
);
52 button
->GetEventHandler()->ProcessEvent(event
);
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
59 IMPLEMENT_DYNAMIC_CLASS(wxButton
,wxControl
)
67 if (m_clientData
) delete m_clientData
;
70 bool wxButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
71 const wxPoint
&pos
, const wxSize
&size
,
72 long style
, const wxValidator
& validator
, const wxString
&name
)
74 m_clientData
= (wxClientData
*) NULL
;
76 m_acceptsFocus
= TRUE
;
78 if (!PreCreation( parent
, pos
, size
) ||
79 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
81 wxFAIL_MSG( wxT("wxButton creation failed") );
86 m_widget
= gtk_button_new_with_label( "" );
88 #if (GTK_MINOR_VERSION > 0)
89 if (style
& wxNO_BORDER
)
90 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
96 wxFont
new_font( parent
->GetFont() );
97 GetTextExtent( m_label
, &x
, &y
, (int*)NULL
, (int*)NULL
, &new_font
);
99 wxSize newSize
= size
;
103 if (newSize
.x
< 80) newSize
.x
= 80;
108 if (newSize
.x
< 26) newSize
.x
= 26;
111 SetSize( newSize
.x
, newSize
.y
);
113 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
114 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
116 m_parent
->DoAddChild( this );
120 SetBackgroundColour( parent
->GetBackgroundColour() );
121 SetForegroundColour( parent
->GetForegroundColour() );
122 SetFont( parent
->GetFont() );
129 void wxButton::SetDefault(void)
131 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
132 gtk_widget_grab_default( m_widget
);
134 SetSize( m_x
, m_y
, m_width
, m_height
);
138 wxSize
wxButton::GetDefaultSize()
140 return wxSize(80,26);
143 void wxButton::SetLabel( const wxString
&label
)
145 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
147 wxControl::SetLabel( label
);
149 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child
), GetLabel().mbc_str() );
152 bool wxButton::Enable( bool enable
)
154 if ( !wxControl::Enable( enable
) )
157 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
162 void wxButton::ApplyWidgetStyle()
165 gtk_widget_set_style( m_widget
, m_widgetStyle
);
166 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);