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