]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/button.cpp
HP-UX support added
[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
83624f79
RR
16#include "gdk/gdk.h"
17#include "gtk/gtk.h"
18
c801d85f
KB
19//-----------------------------------------------------------------------------
20// classes
21//-----------------------------------------------------------------------------
22
23class wxButton;
24
66bd6b93
RR
25//-----------------------------------------------------------------------------
26// data
27//-----------------------------------------------------------------------------
28
29extern bool g_blockEventsOnDrag;
30
c801d85f 31//-----------------------------------------------------------------------------
e1e955e1 32// "clicked"
c801d85f
KB
33//-----------------------------------------------------------------------------
34
66bd6b93 35static 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//-----------------------------------------------------------------------------
e1e955e1
RR
46// wxButton
47//-----------------------------------------------------------------------------
48
49IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
c801d85f 50
fd0eed64 51wxButton::wxButton()
c801d85f 52{
6de97a3b 53}
c801d85f 54
fd0eed64
RR
55wxButton::~wxButton()
56{
57 if (m_clientData) delete m_clientData;
58}
59
c801d85f 60bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
32c77a71 61 const wxPoint &pos, const wxSize &size,
6de97a3b 62 long style, const wxValidator& validator, const wxString &name )
c801d85f 63{
b292e2f5
RR
64 m_clientData = (wxClientData*) NULL;
65 m_needParent = TRUE;
66 m_acceptsFocus = TRUE;
32c77a71 67
b292e2f5 68 wxSize newSize = size;
c801d85f 69
b292e2f5 70 PreCreation( parent, id, pos, newSize, style, name );
6de97a3b 71
b292e2f5 72 SetValidator( validator );
32c77a71 73
b292e2f5
RR
74 m_widget = gtk_button_new_with_label( m_label );
75 SetLabel(label);
32c77a71 76
b292e2f5
RR
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 );
32c77a71 80
b292e2f5
RR
81 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
82 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
c801d85f 83
b292e2f5 84 m_parent->AddChild( this );
6ca41e57 85
b292e2f5 86 (m_parent->m_insertCallback)( m_parent, this );
6ca41e57 87
b292e2f5 88 PostCreation();
f96aa4d9 89
b292e2f5
RR
90 SetBackgroundColour( parent->GetBackgroundColour() );
91 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 92 SetFont( parent->GetFont() );
32c77a71 93
b292e2f5 94 Show( TRUE );
32c77a71 95
b292e2f5 96 return TRUE;
6de97a3b 97}
32c77a71 98
c801d85f
KB
99void wxButton::SetDefault(void)
100{
3502e687
RR
101 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
102 gtk_widget_grab_default( m_widget );
103
104 SetSize( m_x, m_y, m_width, m_height );
6de97a3b 105}
c801d85f
KB
106
107void wxButton::SetLabel( const wxString &label )
108{
b292e2f5 109 wxCHECK_RET( m_widget != NULL, "invalid button" );
f96aa4d9 110
b292e2f5 111 wxControl::SetLabel( label );
f96aa4d9 112
b292e2f5 113 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
6de97a3b 114}
c801d85f 115
a9c96bcc
RR
116void wxButton::Enable( bool enable )
117{
b292e2f5 118 wxCHECK_RET( m_widget != NULL, "invalid button" );
f96aa4d9 119
b292e2f5 120 wxControl::Enable( enable );
f96aa4d9 121
b292e2f5 122 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
a9c96bcc
RR
123}
124
58614078 125void wxButton::ApplyWidgetStyle()
868a2826 126{
b292e2f5
RR
127 SetWidgetStyle();
128 gtk_widget_set_style( m_widget, m_widgetStyle );
129 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
a81258be 130}
f96aa4d9 131
fd0eed64 132