]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
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 | ||
66bd6b93 RR |
23 | //----------------------------------------------------------------------------- |
24 | // data | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
27 | extern bool g_blockEventsOnDrag; | |
28 | ||
c801d85f KB |
29 | //----------------------------------------------------------------------------- |
30 | // wxButton | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl) | |
34 | ||
66bd6b93 | 35 | static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button ) |
c801d85f | 36 | { |
66bd6b93 RR |
37 | if (!button->HasVMT()) return; |
38 | if (g_blockEventsOnDrag) return; | |
39 | ||
c801d85f KB |
40 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); |
41 | event.SetEventObject(button); | |
47908e25 | 42 | button->GetEventHandler()->ProcessEvent(event); |
6de97a3b | 43 | } |
c801d85f KB |
44 | |
45 | //----------------------------------------------------------------------------- | |
46 | ||
47 | wxButton::wxButton(void) | |
48 | { | |
6de97a3b | 49 | } |
c801d85f KB |
50 | |
51 | bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, | |
32c77a71 | 52 | const wxPoint &pos, const wxSize &size, |
6de97a3b | 53 | long style, const wxValidator& validator, const wxString &name ) |
c801d85f KB |
54 | { |
55 | m_needParent = TRUE; | |
32c77a71 | 56 | |
c801d85f KB |
57 | wxSize newSize = size; |
58 | ||
59 | PreCreation( parent, id, pos, newSize, style, name ); | |
6de97a3b RR |
60 | |
61 | SetValidator( validator ); | |
32c77a71 | 62 | |
32c77a71 | 63 | m_widget = gtk_button_new_with_label( m_label ); |
b593568e | 64 | SetLabel(label); |
32c77a71 | 65 | |
c801d85f KB |
66 | if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label ); |
67 | if (newSize.y == -1) newSize.y = 26; | |
68 | SetSize( newSize.x, newSize.y ); | |
32c77a71 VZ |
69 | |
70 | gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", | |
c801d85f KB |
71 | GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); |
72 | ||
73 | PostCreation(); | |
32c77a71 | 74 | |
c801d85f | 75 | Show( TRUE ); |
32c77a71 | 76 | |
c801d85f | 77 | return TRUE; |
6de97a3b | 78 | } |
32c77a71 | 79 | |
c801d85f KB |
80 | void wxButton::SetDefault(void) |
81 | { | |
903f689b RR |
82 | /* |
83 | GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT ); | |
6de97a3b | 84 | gtk_widget_grab_default( m_widget ); |
903f689b | 85 | */ |
6de97a3b | 86 | } |
c801d85f KB |
87 | |
88 | void wxButton::SetLabel( const wxString &label ) | |
89 | { | |
90 | wxControl::SetLabel( label ); | |
b593568e | 91 | GtkButton *bin = GTK_BUTTON( m_widget ); |
b6af8d80 RR |
92 | GtkLabel *g_label = GTK_LABEL( bin->child ); |
93 | gtk_label_set( g_label, GetLabel() ); | |
6de97a3b | 94 | } |
c801d85f | 95 | |
a9c96bcc RR |
96 | void wxButton::Enable( bool enable ) |
97 | { | |
98 | wxControl::Enable( enable ); | |
99 | GtkButton *bin = GTK_BUTTON( m_widget ); | |
100 | GtkWidget *label = bin->child; | |
101 | gtk_widget_set_sensitive( label, enable ); | |
102 | } | |
103 |