]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: button.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
01111366 RR |
5 | // Id: $id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
c801d85f KB |
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 | ||
66bd6b93 RR |
22 | //----------------------------------------------------------------------------- |
23 | // data | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
26 | extern bool g_blockEventsOnDrag; | |
27 | ||
c801d85f | 28 | //----------------------------------------------------------------------------- |
e1e955e1 | 29 | // "clicked" |
c801d85f KB |
30 | //----------------------------------------------------------------------------- |
31 | ||
66bd6b93 | 32 | static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button ) |
c801d85f | 33 | { |
66bd6b93 RR |
34 | if (!button->HasVMT()) return; |
35 | if (g_blockEventsOnDrag) return; | |
36 | ||
c801d85f KB |
37 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); |
38 | event.SetEventObject(button); | |
47908e25 | 39 | button->GetEventHandler()->ProcessEvent(event); |
6de97a3b | 40 | } |
c801d85f KB |
41 | |
42 | //----------------------------------------------------------------------------- | |
e1e955e1 RR |
43 | // wxButton |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl) | |
c801d85f KB |
47 | |
48 | wxButton::wxButton(void) | |
49 | { | |
6de97a3b | 50 | } |
c801d85f KB |
51 | |
52 | bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, | |
32c77a71 | 53 | const wxPoint &pos, const wxSize &size, |
6de97a3b | 54 | long style, const wxValidator& validator, const wxString &name ) |
c801d85f KB |
55 | { |
56 | m_needParent = TRUE; | |
32c77a71 | 57 | |
c801d85f KB |
58 | wxSize newSize = size; |
59 | ||
60 | PreCreation( parent, id, pos, newSize, style, name ); | |
6de97a3b RR |
61 | |
62 | SetValidator( validator ); | |
32c77a71 | 63 | |
32c77a71 | 64 | m_widget = gtk_button_new_with_label( m_label ); |
b593568e | 65 | SetLabel(label); |
32c77a71 | 66 | |
c801d85f KB |
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 ); | |
32c77a71 VZ |
70 | |
71 | gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", | |
c801d85f KB |
72 | GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); |
73 | ||
74 | PostCreation(); | |
32c77a71 | 75 | |
c801d85f | 76 | Show( TRUE ); |
32c77a71 | 77 | |
c801d85f | 78 | return TRUE; |
6de97a3b | 79 | } |
32c77a71 | 80 | |
c801d85f KB |
81 | void wxButton::SetDefault(void) |
82 | { | |
903f689b RR |
83 | /* |
84 | GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT ); | |
6de97a3b | 85 | gtk_widget_grab_default( m_widget ); |
903f689b | 86 | */ |
6de97a3b | 87 | } |
c801d85f KB |
88 | |
89 | void wxButton::SetLabel( const wxString &label ) | |
90 | { | |
91 | wxControl::SetLabel( label ); | |
b593568e | 92 | GtkButton *bin = GTK_BUTTON( m_widget ); |
b6af8d80 RR |
93 | GtkLabel *g_label = GTK_LABEL( bin->child ); |
94 | gtk_label_set( g_label, GetLabel() ); | |
6de97a3b | 95 | } |
c801d85f | 96 | |
a9c96bcc RR |
97 | void wxButton::Enable( bool enable ) |
98 | { | |
99 | wxControl::Enable( enable ); | |
100 | GtkButton *bin = GTK_BUTTON( m_widget ); | |
101 | GtkWidget *label = bin->child; | |
102 | gtk_widget_set_sensitive( label, enable ); | |
103 | } | |
104 | ||
868a2826 RR |
105 | void wxButton::SetFont( const wxFont &font ) |
106 | { | |
3f659fd6 RR |
107 | if (((wxFont*)&font)->Ok()) |
108 | m_font = font; | |
109 | else | |
110 | m_font = *wxSWISS_FONT; | |
111 | ||
868a2826 RR |
112 | GtkButton *bin = GTK_BUTTON( m_widget ); |
113 | GtkWidget *label = bin->child; | |
114 | ||
115 | GtkStyle *style = (GtkStyle*) NULL; | |
116 | if (!m_hasOwnStyle) | |
117 | { | |
118 | m_hasOwnStyle = TRUE; | |
119 | style = gtk_style_copy( gtk_widget_get_style( label ) ); | |
120 | } | |
121 | else | |
122 | { | |
123 | style = gtk_widget_get_style( label ); | |
124 | } | |
125 | ||
126 | gdk_font_unref( style->font ); | |
127 | style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); | |
128 | ||
129 | gtk_widget_set_style( label, style ); | |
130 | } |