]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/button.cpp
Some corrections for BC++ compilation; Latex doc corrections
[wxWidgets.git] / src / gtk / 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() );
32c77a71 92
b292e2f5 93 Show( TRUE );
32c77a71 94
b292e2f5 95 return TRUE;
6de97a3b 96}
32c77a71 97
c801d85f
KB
98void wxButton::SetDefault(void)
99{
903f689b
RR
100/*
101 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
6de97a3b 102 gtk_widget_grab_default( m_widget );
903f689b 103*/
6de97a3b 104}
c801d85f
KB
105
106void wxButton::SetLabel( const wxString &label )
107{
b292e2f5 108 wxCHECK_RET( m_widget != NULL, "invalid button" );
f96aa4d9 109
b292e2f5 110 wxControl::SetLabel( label );
f96aa4d9 111
b292e2f5 112 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
6de97a3b 113}
c801d85f 114
a9c96bcc
RR
115void wxButton::Enable( bool enable )
116{
b292e2f5 117 wxCHECK_RET( m_widget != NULL, "invalid button" );
f96aa4d9 118
b292e2f5 119 wxControl::Enable( enable );
f96aa4d9 120
b292e2f5 121 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
a9c96bcc
RR
122}
123
58614078 124void wxButton::ApplyWidgetStyle()
868a2826 125{
b292e2f5
RR
126 SetWidgetStyle();
127 gtk_widget_set_style( m_widget, m_widgetStyle );
128 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
a81258be 129}
f96aa4d9 130
fd0eed64 131