]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/button.cpp
some fixes after global _T() => T() change
[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{
32ac755d
RR
44 if (g_isIdle)
45 wxapp_install_idle_handler();
acfd422a 46
a2053b27 47 if (!button->m_hasVMT) return;
acfd422a 48 if (g_blockEventsOnDrag) return;
32ac755d 49
acfd422a
RR
50 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
51 event.SetEventObject(button);
52 button->GetEventHandler()->ProcessEvent(event);
6de97a3b 53}
c801d85f
KB
54
55//-----------------------------------------------------------------------------
e1e955e1
RR
56// wxButton
57//-----------------------------------------------------------------------------
58
59IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
c801d85f 60
fd0eed64 61wxButton::wxButton()
c801d85f 62{
6de97a3b 63}
c801d85f 64
fd0eed64
RR
65wxButton::~wxButton()
66{
acfd422a 67 if (m_clientData) delete m_clientData;
fd0eed64
RR
68}
69
c801d85f 70bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
32c77a71 71 const wxPoint &pos, const wxSize &size,
6de97a3b 72 long style, const wxValidator& validator, const wxString &name )
c801d85f 73{
b292e2f5
RR
74 m_clientData = (wxClientData*) NULL;
75 m_needParent = TRUE;
76 m_acceptsFocus = TRUE;
32c77a71 77
4dcaf11a
RR
78 if (!PreCreation( parent, pos, size ) ||
79 !CreateBase( parent, id, pos, size, style, validator, name ))
80 {
e90c1d2a 81 wxFAIL_MSG( T("wxButton creation failed") );
4dcaf11a
RR
82 return FALSE;
83 }
c801d85f 84
32c77a71 85
de1c750f
RR
86 m_widget = gtk_button_new_with_label( "" );
87
88#if (GTK_MINOR_VERSION > 0)
89 if (style & wxNO_BORDER)
90 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
91#endif
92
b292e2f5 93 SetLabel(label);
32c77a71 94
3417c2cd
RR
95 int x = 0; int y = 0;
96 wxFont new_font( parent->GetFont() );
97 GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font );
98
4dcaf11a 99 wxSize newSize = size;
92afa2b1
RR
100 if (newSize.x == -1)
101 {
102 newSize.x = 12+x;
103 if (newSize.x < 80) newSize.x = 80;
104 }
105 if (newSize.y == -1)
106 {
107 newSize.y = 11+y;
108 if (newSize.x < 26) newSize.x = 26;
109 }
110
b292e2f5 111 SetSize( newSize.x, newSize.y );
32c77a71 112
b292e2f5
RR
113 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
114 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
c801d85f 115
f03fc89f 116 m_parent->DoAddChild( this );
6ca41e57 117
b292e2f5 118 PostCreation();
f96aa4d9 119
b292e2f5
RR
120 SetBackgroundColour( parent->GetBackgroundColour() );
121 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 122 SetFont( parent->GetFont() );
32c77a71 123
b292e2f5 124 Show( TRUE );
32c77a71 125
b292e2f5 126 return TRUE;
6de97a3b 127}
32c77a71 128
c801d85f
KB
129void wxButton::SetDefault(void)
130{
3502e687
RR
131 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
132 gtk_widget_grab_default( m_widget );
133
134 SetSize( m_x, m_y, m_width, m_height );
6de97a3b 135}
c801d85f 136
ebea0891
KB
137/* static */
138wxSize wxButton::GetDefaultSize()
8dbf4589
RR
139{
140 return wxSize(80,26);
141}
142
c801d85f
KB
143void wxButton::SetLabel( const wxString &label )
144{
e90c1d2a 145 wxCHECK_RET( m_widget != NULL, T("invalid button") );
f96aa4d9 146
b292e2f5 147 wxControl::SetLabel( label );
f96aa4d9 148
3bce7509 149 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel().mbc_str() );
6de97a3b 150}
c801d85f 151
f03fc89f 152bool wxButton::Enable( bool enable )
a9c96bcc 153{
f03fc89f
VZ
154 if ( !wxControl::Enable( enable ) )
155 return FALSE;
f96aa4d9 156
b292e2f5 157 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
f03fc89f
VZ
158
159 return TRUE;
a9c96bcc
RR
160}
161
58614078 162void wxButton::ApplyWidgetStyle()
868a2826 163{
b292e2f5
RR
164 SetWidgetStyle();
165 gtk_widget_set_style( m_widget, m_widgetStyle );
166 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
a81258be 167}