]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/button.cpp
interchanged w and h in wxSplitterWindow::OnSashPositionChange (now
[wxWidgets.git] / src / gtk1 / button.cpp
... / ...
CommitLineData
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//-----------------------------------------------------------------------------
17// classes
18//-----------------------------------------------------------------------------
19
20class wxButton;
21
22//-----------------------------------------------------------------------------
23// data
24//-----------------------------------------------------------------------------
25
26extern bool g_blockEventsOnDrag;
27
28//-----------------------------------------------------------------------------
29// "clicked"
30//-----------------------------------------------------------------------------
31
32static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
33{
34 if (!button->HasVMT()) return;
35 if (g_blockEventsOnDrag) return;
36
37 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
38 event.SetEventObject(button);
39 button->GetEventHandler()->ProcessEvent(event);
40}
41
42//-----------------------------------------------------------------------------
43// wxButton
44//-----------------------------------------------------------------------------
45
46IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
47
48wxButton::wxButton(void)
49{
50}
51
52bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
53 const wxPoint &pos, const wxSize &size,
54 long style, const wxValidator& validator, const wxString &name )
55{
56 m_needParent = TRUE;
57
58 wxSize newSize = size;
59
60 PreCreation( parent, id, pos, newSize, style, name );
61
62 SetValidator( validator );
63
64 m_widget = gtk_button_new_with_label( m_label );
65 SetLabel(label);
66
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 );
70
71 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
72 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
73
74 PostCreation();
75
76 SetBackgroundColour( parent->GetBackgroundColour() );
77
78 Show( TRUE );
79
80 return TRUE;
81}
82
83void wxButton::SetDefault(void)
84{
85/*
86 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
87 gtk_widget_grab_default( m_widget );
88*/
89}
90
91void wxButton::SetLabel( const wxString &label )
92{
93 wxCHECK_RET( m_widget != NULL, "invalid button" );
94
95 wxControl::SetLabel( label );
96
97 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
98}
99
100void wxButton::Enable( bool enable )
101{
102 wxCHECK_RET( m_widget != NULL, "invalid button" );
103
104 wxControl::Enable( enable );
105
106 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
107}
108
109void wxButton::SetFont( const wxFont &font )
110{
111 wxCHECK_RET( m_widget != NULL, "invalid button" );
112
113 wxControl::SetFont( font );
114
115 gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
116 gtk_style_ref(
117 gtk_widget_get_style( m_widget ) ) );
118}
119
120void wxButton::SetBackgroundColour( const wxColour &colour )
121{
122 return;
123
124 wxCHECK_RET( m_widget != NULL, "invalid button" );
125
126 wxControl::SetBackgroundColour( colour );
127
128 if (!m_backgroundColour.Ok()) return;
129
130 gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
131 gtk_style_ref(
132 gtk_widget_get_style( m_widget ) ) );
133}
134
135