]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: button.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
dbf858b5 | 5 | // Id: $Id$ |
01111366 | 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 | ||
6ca41e57 RR |
74 | m_parent->AddChild( this ); |
75 | ||
76 | (m_parent->m_insertCallback)( m_parent, this ); | |
77 | ||
c801d85f | 78 | PostCreation(); |
f96aa4d9 RR |
79 | |
80 | SetBackgroundColour( parent->GetBackgroundColour() ); | |
58614078 | 81 | SetForegroundColour( parent->GetForegroundColour() ); |
32c77a71 | 82 | |
c801d85f | 83 | Show( TRUE ); |
32c77a71 | 84 | |
c801d85f | 85 | return TRUE; |
6de97a3b | 86 | } |
32c77a71 | 87 | |
c801d85f KB |
88 | void wxButton::SetDefault(void) |
89 | { | |
903f689b RR |
90 | /* |
91 | GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT ); | |
6de97a3b | 92 | gtk_widget_grab_default( m_widget ); |
903f689b | 93 | */ |
6de97a3b | 94 | } |
c801d85f KB |
95 | |
96 | void wxButton::SetLabel( const wxString &label ) | |
97 | { | |
f96aa4d9 RR |
98 | wxCHECK_RET( m_widget != NULL, "invalid button" ); |
99 | ||
c801d85f | 100 | wxControl::SetLabel( label ); |
f96aa4d9 RR |
101 | |
102 | gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() ); | |
6de97a3b | 103 | } |
c801d85f | 104 | |
a9c96bcc RR |
105 | void wxButton::Enable( bool enable ) |
106 | { | |
f96aa4d9 RR |
107 | wxCHECK_RET( m_widget != NULL, "invalid button" ); |
108 | ||
a9c96bcc | 109 | wxControl::Enable( enable ); |
f96aa4d9 RR |
110 | |
111 | gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable ); | |
a9c96bcc RR |
112 | } |
113 | ||
58614078 | 114 | void wxButton::ApplyWidgetStyle() |
868a2826 | 115 | { |
58614078 | 116 | SetWidgetStyle(); |
a81258be | 117 | gtk_widget_set_style( m_widget, m_widgetStyle ); |
a81258be RR |
118 | gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle ); |
119 | } | |
f96aa4d9 | 120 |