]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/button.cpp
mac support as stubs 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
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 47
fd0eed64 48wxButton::wxButton()
c801d85f 49{
6de97a3b 50}
c801d85f 51
fd0eed64
RR
52wxButton::~wxButton()
53{
54 if (m_clientData) delete m_clientData;
55}
56
c801d85f 57bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
32c77a71 58 const wxPoint &pos, const wxSize &size,
6de97a3b 59 long style, const wxValidator& validator, const wxString &name )
c801d85f 60{
b292e2f5
RR
61 m_clientData = (wxClientData*) NULL;
62 m_needParent = TRUE;
63 m_acceptsFocus = TRUE;
32c77a71 64
b292e2f5 65 wxSize newSize = size;
c801d85f 66
b292e2f5 67 PreCreation( parent, id, pos, newSize, style, name );
6de97a3b 68
b292e2f5 69 SetValidator( validator );
32c77a71 70
b292e2f5
RR
71 m_widget = gtk_button_new_with_label( m_label );
72 SetLabel(label);
32c77a71 73
b292e2f5
RR
74 if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
75 if (newSize.y == -1) newSize.y = 26;
76 SetSize( newSize.x, newSize.y );
32c77a71 77
b292e2f5
RR
78 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
79 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
c801d85f 80
b292e2f5 81 m_parent->AddChild( this );
6ca41e57 82
b292e2f5 83 (m_parent->m_insertCallback)( m_parent, this );
6ca41e57 84
b292e2f5 85 PostCreation();
f96aa4d9 86
b292e2f5
RR
87 SetBackgroundColour( parent->GetBackgroundColour() );
88 SetForegroundColour( parent->GetForegroundColour() );
32c77a71 89
b292e2f5 90 Show( TRUE );
32c77a71 91
b292e2f5 92 return TRUE;
6de97a3b 93}
32c77a71 94
c801d85f
KB
95void wxButton::SetDefault(void)
96{
903f689b
RR
97/*
98 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
6de97a3b 99 gtk_widget_grab_default( m_widget );
903f689b 100*/
6de97a3b 101}
c801d85f
KB
102
103void wxButton::SetLabel( const wxString &label )
104{
b292e2f5 105 wxCHECK_RET( m_widget != NULL, "invalid button" );
f96aa4d9 106
b292e2f5 107 wxControl::SetLabel( label );
f96aa4d9 108
b292e2f5 109 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
6de97a3b 110}
c801d85f 111
a9c96bcc
RR
112void wxButton::Enable( bool enable )
113{
b292e2f5 114 wxCHECK_RET( m_widget != NULL, "invalid button" );
f96aa4d9 115
b292e2f5 116 wxControl::Enable( enable );
f96aa4d9 117
b292e2f5 118 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
a9c96bcc
RR
119}
120
58614078 121void wxButton::ApplyWidgetStyle()
868a2826 122{
b292e2f5
RR
123 SetWidgetStyle();
124 gtk_widget_set_style( m_widget, m_widgetStyle );
125 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
a81258be 126}
f96aa4d9 127
fd0eed64 128