]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/button.cpp
interchanged w and h in wxSplitterWindow::OnSashPositionChange (now
[wxWidgets.git] / src / gtk1 / button.cpp
CommitLineData
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
20class wxButton;
21
66bd6b93
RR
22//-----------------------------------------------------------------------------
23// data
24//-----------------------------------------------------------------------------
25
26extern bool g_blockEventsOnDrag;
27
c801d85f 28//-----------------------------------------------------------------------------
e1e955e1 29// "clicked"
c801d85f
KB
30//-----------------------------------------------------------------------------
31
66bd6b93 32static 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
46IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
c801d85f
KB
47
48wxButton::wxButton(void)
49{
6de97a3b 50}
c801d85f
KB
51
52bool 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();
f96aa4d9
RR
75
76 SetBackgroundColour( parent->GetBackgroundColour() );
32c77a71 77
c801d85f 78 Show( TRUE );
32c77a71 79
c801d85f 80 return TRUE;
6de97a3b 81}
32c77a71 82
c801d85f
KB
83void wxButton::SetDefault(void)
84{
903f689b
RR
85/*
86 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
6de97a3b 87 gtk_widget_grab_default( m_widget );
903f689b 88*/
6de97a3b 89}
c801d85f
KB
90
91void wxButton::SetLabel( const wxString &label )
92{
f96aa4d9
RR
93 wxCHECK_RET( m_widget != NULL, "invalid button" );
94
c801d85f 95 wxControl::SetLabel( label );
f96aa4d9
RR
96
97 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
6de97a3b 98}
c801d85f 99
a9c96bcc
RR
100void wxButton::Enable( bool enable )
101{
f96aa4d9
RR
102 wxCHECK_RET( m_widget != NULL, "invalid button" );
103
a9c96bcc 104 wxControl::Enable( enable );
f96aa4d9
RR
105
106 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
a9c96bcc
RR
107}
108
868a2826
RR
109void wxButton::SetFont( const wxFont &font )
110{
f96aa4d9
RR
111 wxCHECK_RET( m_widget != NULL, "invalid button" );
112
113 wxControl::SetFont( font );
868a2826 114
f96aa4d9
RR
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 );
868a2826 127
f96aa4d9 128 if (!m_backgroundColour.Ok()) return;
868a2826 129
f96aa4d9
RR
130 gtk_widget_set_style( GTK_BUTTON(m_widget)->child,
131 gtk_style_ref(
132 gtk_widget_get_style( m_widget ) ) );
868a2826 133}
f96aa4d9
RR
134
135