]>
Commit | Line | Data |
---|---|---|
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 | #include "gdk/gdk.h" | |
17 | #include "gtk/gtk.h" | |
18 | ||
19 | //----------------------------------------------------------------------------- | |
20 | // classes | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
23 | class wxButton; | |
24 | ||
25 | //----------------------------------------------------------------------------- | |
26 | // data | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | extern bool g_blockEventsOnDrag; | |
30 | ||
31 | //----------------------------------------------------------------------------- | |
32 | // "clicked" | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
35 | static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button ) | |
36 | { | |
37 | if (!button->HasVMT()) return; | |
38 | if (g_blockEventsOnDrag) return; | |
39 | ||
40 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); | |
41 | event.SetEventObject(button); | |
42 | button->GetEventHandler()->ProcessEvent(event); | |
43 | } | |
44 | ||
45 | //----------------------------------------------------------------------------- | |
46 | // wxButton | |
47 | //----------------------------------------------------------------------------- | |
48 | ||
49 | IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl) | |
50 | ||
51 | wxButton::wxButton() | |
52 | { | |
53 | } | |
54 | ||
55 | wxButton::~wxButton() | |
56 | { | |
57 | if (m_clientData) delete m_clientData; | |
58 | } | |
59 | ||
60 | bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, | |
61 | const wxPoint &pos, const wxSize &size, | |
62 | long style, const wxValidator& validator, const wxString &name ) | |
63 | { | |
64 | m_clientData = (wxClientData*) NULL; | |
65 | m_needParent = TRUE; | |
66 | m_acceptsFocus = TRUE; | |
67 | ||
68 | wxSize newSize = size; | |
69 | ||
70 | PreCreation( parent, id, pos, newSize, style, name ); | |
71 | ||
72 | SetValidator( validator ); | |
73 | ||
74 | m_widget = gtk_button_new_with_label( m_label ); | |
75 | SetLabel(label); | |
76 | ||
77 | if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label ); | |
78 | if (newSize.y == -1) newSize.y = 26; | |
79 | SetSize( newSize.x, newSize.y ); | |
80 | ||
81 | gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", | |
82 | GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); | |
83 | ||
84 | m_parent->AddChild( this ); | |
85 | ||
86 | (m_parent->m_insertCallback)( m_parent, this ); | |
87 | ||
88 | PostCreation(); | |
89 | ||
90 | SetBackgroundColour( parent->GetBackgroundColour() ); | |
91 | SetForegroundColour( parent->GetForegroundColour() ); | |
92 | ||
93 | Show( TRUE ); | |
94 | ||
95 | return TRUE; | |
96 | } | |
97 | ||
98 | void wxButton::SetDefault(void) | |
99 | { | |
100 | /* | |
101 | GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT ); | |
102 | gtk_widget_grab_default( m_widget ); | |
103 | */ | |
104 | } | |
105 | ||
106 | void wxButton::SetLabel( const wxString &label ) | |
107 | { | |
108 | wxCHECK_RET( m_widget != NULL, "invalid button" ); | |
109 | ||
110 | wxControl::SetLabel( label ); | |
111 | ||
112 | gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() ); | |
113 | } | |
114 | ||
115 | void wxButton::Enable( bool enable ) | |
116 | { | |
117 | wxCHECK_RET( m_widget != NULL, "invalid button" ); | |
118 | ||
119 | wxControl::Enable( enable ); | |
120 | ||
121 | gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable ); | |
122 | } | |
123 | ||
124 | void wxButton::ApplyWidgetStyle() | |
125 | { | |
126 | SetWidgetStyle(); | |
127 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
128 | gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle ); | |
129 | } | |
130 | ||
131 |