]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/button.cpp
DnD fixes
[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/button.h"
15
16 //-----------------------------------------------------------------------------
17 // classes
18 //-----------------------------------------------------------------------------
19
20 class wxButton;
21
22 //-----------------------------------------------------------------------------
23 // data
24 //-----------------------------------------------------------------------------
25
26 extern bool g_blockEventsOnDrag;
27
28 //-----------------------------------------------------------------------------
29 // "clicked"
30 //-----------------------------------------------------------------------------
31
32 static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
33 {
34 if (!button->HasVMT()) return;
35 if (g_blockEventsOnDrag) return;
36
37 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
38 event.SetEventObject(button);
39 button->GetEventHandler()->ProcessEvent(event);
40 }
41
42 //-----------------------------------------------------------------------------
43 // wxButton
44 //-----------------------------------------------------------------------------
45
46 IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
47
48 wxButton::wxButton(void)
49 {
50 }
51
52 bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
53 const wxPoint &pos, const wxSize &size,
54 long style, const wxValidator& validator, const wxString &name )
55 {
56 m_needParent = TRUE;
57
58 wxSize newSize = size;
59
60 PreCreation( parent, id, pos, newSize, style, name );
61
62 SetValidator( validator );
63
64 m_widget = gtk_button_new_with_label( m_label );
65 SetLabel(label);
66
67 if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
68 if (newSize.y == -1) newSize.y = 26;
69 SetSize( newSize.x, newSize.y );
70
71 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
72 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
73
74 PostCreation();
75
76 SetBackgroundColour( parent->GetBackgroundColour() );
77 SetForegroundColour( parent->GetForegroundColour() );
78
79 Show( TRUE );
80
81 return TRUE;
82 }
83
84 void wxButton::SetDefault(void)
85 {
86 /*
87 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
88 gtk_widget_grab_default( m_widget );
89 */
90 }
91
92 void wxButton::SetLabel( const wxString &label )
93 {
94 wxCHECK_RET( m_widget != NULL, "invalid button" );
95
96 wxControl::SetLabel( label );
97
98 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
99 }
100
101 void wxButton::Enable( bool enable )
102 {
103 wxCHECK_RET( m_widget != NULL, "invalid button" );
104
105 wxControl::Enable( enable );
106
107 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
108 }
109
110 void wxButton::ApplyWidgetStyle()
111 {
112 SetWidgetStyle();
113 gtk_widget_set_style( m_widget, m_widgetStyle );
114 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
115 }
116