]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/button.cpp
"const" added to wxAceelTable ctor
[wxWidgets.git] / src / gtk1 / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "button.h"
13 #endif
14
15 #include "wx/button.h"
16
17 //-----------------------------------------------------------------------------
18 // classes
19 //-----------------------------------------------------------------------------
20
21 class wxButton;
22
23 //-----------------------------------------------------------------------------
24 // data
25 //-----------------------------------------------------------------------------
26
27 extern bool g_blockEventsOnDrag;
28
29 //-----------------------------------------------------------------------------
30 // "clicked"
31 //-----------------------------------------------------------------------------
32
33 static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
34 {
35 if (!button->HasVMT()) return;
36 if (g_blockEventsOnDrag) return;
37
38 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
39 event.SetEventObject(button);
40 button->GetEventHandler()->ProcessEvent(event);
41 }
42
43 //-----------------------------------------------------------------------------
44 // wxButton
45 //-----------------------------------------------------------------------------
46
47 IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
48
49 wxButton::wxButton(void)
50 {
51 }
52
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 )
56 {
57 m_needParent = TRUE;
58
59 wxSize newSize = size;
60
61 PreCreation( parent, id, pos, newSize, style, name );
62
63 SetValidator( validator );
64
65 m_widget = gtk_button_new_with_label( m_label );
66 SetLabel(label);
67
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 );
71
72 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
73 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
74
75 PostCreation();
76
77 Show( TRUE );
78
79 return TRUE;
80 }
81
82 void wxButton::SetDefault(void)
83 {
84 /*
85 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
86 gtk_widget_grab_default( m_widget );
87 */
88 }
89
90 void wxButton::SetLabel( const wxString &label )
91 {
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() );
96 }
97
98 void wxButton::Enable( bool enable )
99 {
100 wxControl::Enable( enable );
101 GtkButton *bin = GTK_BUTTON( m_widget );
102 GtkWidget *label = bin->child;
103 gtk_widget_set_sensitive( label, enable );
104 }
105
106 void wxButton::SetFont( const wxFont &font )
107 {
108 if (((wxFont*)&font)->Ok())
109 m_font = font;
110 else
111 m_font = *wxSWISS_FONT;
112
113 GtkButton *bin = GTK_BUTTON( m_widget );
114 GtkWidget *label = bin->child;
115
116 GtkStyle *style = (GtkStyle*) NULL;
117 if (!m_hasOwnStyle)
118 {
119 m_hasOwnStyle = TRUE;
120 style = gtk_style_copy( gtk_widget_get_style( label ) );
121 }
122 else
123 {
124 style = gtk_widget_get_style( label );
125 }
126
127 gdk_font_unref( style->font );
128 style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
129
130 gtk_widget_set_style( label, style );
131 }