]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/button.cpp
all delete functions now send delete notification event
[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 //-----------------------------------------------------------------------------
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()
49 {
50 }
51
52 wxButton::~wxButton()
53 {
54 if (m_clientData) delete m_clientData;
55 }
56
57 bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
58 const wxPoint &pos, const wxSize &size,
59 long style, const wxValidator& validator, const wxString &name )
60 {
61 m_clientData = (wxClientData*) NULL;
62 m_needParent = TRUE;
63 m_acceptsFocus = TRUE;
64
65 wxSize newSize = size;
66
67 PreCreation( parent, id, pos, newSize, style, name );
68
69 SetValidator( validator );
70
71 m_widget = gtk_button_new_with_label( m_label );
72 SetLabel(label);
73
74 if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
75 if (newSize.y == -1) newSize.y = 26;
76 SetSize( newSize.x, newSize.y );
77
78 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
79 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
80
81 m_parent->AddChild( this );
82
83 (m_parent->m_insertCallback)( m_parent, this );
84
85 PostCreation();
86
87 SetBackgroundColour( parent->GetBackgroundColour() );
88 SetForegroundColour( parent->GetForegroundColour() );
89
90 Show( TRUE );
91
92 return TRUE;
93 }
94
95 void wxButton::SetDefault(void)
96 {
97 /*
98 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
99 gtk_widget_grab_default( m_widget );
100 */
101 }
102
103 void wxButton::SetLabel( const wxString &label )
104 {
105 wxCHECK_RET( m_widget != NULL, "invalid button" );
106
107 wxControl::SetLabel( label );
108
109 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
110 }
111
112 void wxButton::Enable( bool enable )
113 {
114 wxCHECK_RET( m_widget != NULL, "invalid button" );
115
116 wxControl::Enable( enable );
117
118 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
119 }
120
121 void wxButton::ApplyWidgetStyle()
122 {
123 SetWidgetStyle();
124 gtk_widget_set_style( m_widget, m_widgetStyle );
125 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
126 }
127
128