]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/button.cpp
Accelerators now work for wxDialog; wxToolBarSimple fixed when dragging out of
[wxWidgets.git] / src / gtk1 / button.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "button.h"
13#endif
14
15#include "wx/button.h"
16
17//-----------------------------------------------------------------------------
18// classes
19//-----------------------------------------------------------------------------
20
21class wxButton;
22
23//-----------------------------------------------------------------------------
24// data
25//-----------------------------------------------------------------------------
26
27extern bool g_blockEventsOnDrag;
28
29//-----------------------------------------------------------------------------
30// wxButton
31//-----------------------------------------------------------------------------
32
33IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
34
35static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
36{
37 if (!button->HasVMT()) return;
38 if (g_blockEventsOnDrag) return;
39
40 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
41 event.SetEventObject(button);
42 button->GetEventHandler()->ProcessEvent(event);
43}
44
45//-----------------------------------------------------------------------------
46
47wxButton::wxButton(void)
48{
49}
50
51bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
52 const wxPoint &pos, const wxSize &size,
53 long style, const wxValidator& validator, const wxString &name )
54{
55 m_needParent = TRUE;
56
57 wxSize newSize = size;
58
59 PreCreation( parent, id, pos, newSize, style, name );
60
61 SetValidator( validator );
62
63 m_widget = gtk_button_new_with_label( m_label );
64 SetLabel(label);
65
66 if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
67 if (newSize.y == -1) newSize.y = 26;
68 SetSize( newSize.x, newSize.y );
69
70 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
71 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
72
73 PostCreation();
74
75 Show( TRUE );
76
77 return TRUE;
78}
79
80void wxButton::SetDefault(void)
81{
82/*
83 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
84 gtk_widget_grab_default( m_widget );
85*/
86}
87
88void wxButton::SetLabel( const wxString &label )
89{
90 wxControl::SetLabel( label );
91 GtkButton *bin = GTK_BUTTON( m_widget );
92 GtkLabel *g_label = GTK_LABEL( bin->child );
93 gtk_label_set( g_label, GetLabel() );
94}
95
96void wxButton::Enable( bool enable )
97{
98 wxControl::Enable( enable );
99 GtkButton *bin = GTK_BUTTON( m_widget );
100 GtkWidget *label = bin->child;
101 gtk_widget_set_sensitive( label, enable );
102}
103