]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/button.cpp
Added window resize patch to wxFrame
[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
acfd422a
RR
25//-----------------------------------------------------------------------------
26// idle system
27//-----------------------------------------------------------------------------
28
29extern void wxapp_install_idle_handler();
30extern bool g_isIdle;
31
66bd6b93
RR
32//-----------------------------------------------------------------------------
33// data
34//-----------------------------------------------------------------------------
35
36extern bool g_blockEventsOnDrag;
37
c801d85f 38//-----------------------------------------------------------------------------
e1e955e1 39// "clicked"
c801d85f
KB
40//-----------------------------------------------------------------------------
41
66bd6b93 42static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
c801d85f 43{
acfd422a
RR
44 if (g_isIdle) wxapp_install_idle_handler();
45
46 if (!button->HasVMT()) return;
47 if (g_blockEventsOnDrag) return;
66bd6b93 48
acfd422a
RR
49 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
50 event.SetEventObject(button);
51 button->GetEventHandler()->ProcessEvent(event);
6de97a3b 52}
c801d85f
KB
53
54//-----------------------------------------------------------------------------
e1e955e1
RR
55// wxButton
56//-----------------------------------------------------------------------------
57
58IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
c801d85f 59
fd0eed64 60wxButton::wxButton()
c801d85f 61{
6de97a3b 62}
c801d85f 63
fd0eed64
RR
64wxButton::~wxButton()
65{
acfd422a 66 if (m_clientData) delete m_clientData;
fd0eed64
RR
67}
68
c801d85f 69bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
32c77a71 70 const wxPoint &pos, const wxSize &size,
6de97a3b 71 long style, const wxValidator& validator, const wxString &name )
c801d85f 72{
b292e2f5
RR
73 m_clientData = (wxClientData*) NULL;
74 m_needParent = TRUE;
75 m_acceptsFocus = TRUE;
32c77a71 76
b292e2f5 77 wxSize newSize = size;
c801d85f 78
b292e2f5 79 PreCreation( parent, id, pos, newSize, style, name );
6de97a3b 80
b292e2f5 81 SetValidator( validator );
32c77a71 82
3bce7509 83 m_widget = gtk_button_new_with_label( m_label.mbc_str() );
b292e2f5 84 SetLabel(label);
32c77a71 85
3bce7509 86 if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label.mbc_str() );
b292e2f5
RR
87 if (newSize.y == -1) newSize.y = 26;
88 SetSize( newSize.x, newSize.y );
32c77a71 89
b292e2f5
RR
90 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
91 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
c801d85f 92
b292e2f5 93 m_parent->AddChild( this );
6ca41e57 94
b292e2f5 95 (m_parent->m_insertCallback)( m_parent, this );
6ca41e57 96
b292e2f5 97 PostCreation();
f96aa4d9 98
b292e2f5
RR
99 SetBackgroundColour( parent->GetBackgroundColour() );
100 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 101 SetFont( parent->GetFont() );
32c77a71 102
b292e2f5 103 Show( TRUE );
32c77a71 104
b292e2f5 105 return TRUE;
6de97a3b 106}
32c77a71 107
c801d85f
KB
108void wxButton::SetDefault(void)
109{
3502e687
RR
110 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
111 gtk_widget_grab_default( m_widget );
112
113 SetSize( m_x, m_y, m_width, m_height );
6de97a3b 114}
c801d85f
KB
115
116void wxButton::SetLabel( const wxString &label )
117{
3bce7509 118 wxCHECK_RET( m_widget != NULL, _T("invalid button") );
f96aa4d9 119
b292e2f5 120 wxControl::SetLabel( label );
f96aa4d9 121
3bce7509 122 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel().mbc_str() );
6de97a3b 123}
c801d85f 124
a9c96bcc
RR
125void wxButton::Enable( bool enable )
126{
3bce7509 127 wxCHECK_RET( m_widget != NULL, _T("invalid button") );
f96aa4d9 128
b292e2f5 129 wxControl::Enable( enable );
f96aa4d9 130
b292e2f5 131 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
a9c96bcc
RR
132}
133
58614078 134void wxButton::ApplyWidgetStyle()
868a2826 135{
b292e2f5
RR
136 SetWidgetStyle();
137 gtk_widget_set_style( m_widget, m_widgetStyle );
138 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
a81258be 139}