]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/button.cpp
linking fixes
[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
1e6feb95
VZ
14#include "wx/defs.h"
15
16#if wxUSE_BUTTON
17
c801d85f
KB
18#include "wx/button.h"
19
20e05ffb
RR
20#include <gdk/gdk.h>
21#include <gtk/gtk.h>
83624f79 22
c801d85f
KB
23//-----------------------------------------------------------------------------
24// classes
25//-----------------------------------------------------------------------------
26
27class wxButton;
28
acfd422a
RR
29//-----------------------------------------------------------------------------
30// idle system
31//-----------------------------------------------------------------------------
32
33extern void wxapp_install_idle_handler();
34extern bool g_isIdle;
35
66bd6b93
RR
36//-----------------------------------------------------------------------------
37// data
38//-----------------------------------------------------------------------------
39
40extern bool g_blockEventsOnDrag;
41
c801d85f 42//-----------------------------------------------------------------------------
e1e955e1 43// "clicked"
c801d85f
KB
44//-----------------------------------------------------------------------------
45
66bd6b93 46static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
c801d85f 47{
32ac755d
RR
48 if (g_isIdle)
49 wxapp_install_idle_handler();
acfd422a 50
a2053b27 51 if (!button->m_hasVMT) return;
acfd422a 52 if (g_blockEventsOnDrag) return;
32ac755d 53
acfd422a
RR
54 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
55 event.SetEventObject(button);
56 button->GetEventHandler()->ProcessEvent(event);
6de97a3b 57}
c801d85f
KB
58
59//-----------------------------------------------------------------------------
e1e955e1
RR
60// wxButton
61//-----------------------------------------------------------------------------
62
63IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
c801d85f 64
fd0eed64 65wxButton::wxButton()
c801d85f 66{
6de97a3b 67}
c801d85f 68
fd0eed64
RR
69wxButton::~wxButton()
70{
fd0eed64
RR
71}
72
c801d85f 73bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
32c77a71 74 const wxPoint &pos, const wxSize &size,
6de97a3b 75 long style, const wxValidator& validator, const wxString &name )
c801d85f 76{
b292e2f5
RR
77 m_needParent = TRUE;
78 m_acceptsFocus = TRUE;
32c77a71 79
4dcaf11a
RR
80 if (!PreCreation( parent, pos, size ) ||
81 !CreateBase( parent, id, pos, size, style, validator, name ))
82 {
223d09f6 83 wxFAIL_MSG( wxT("wxButton creation failed") );
f2593d0d 84 return FALSE;
4dcaf11a 85 }
c801d85f 86
354aa1e3
RR
87/*
88 wxString label2( label );
89 for (size_t i = 0; i < label2.Len(); i++)
90 {
91 if (label2.GetChar(i) == wxT('&'))
92 label2.SetChar(i,wxT('_'));
93 }
94
95 GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
96 gtk_widget_show( accel_label );
97
98 m_widget = gtk_button_new();
99 gtk_container_add( GTK_CONTAINER(m_widget), accel_label );
100
101 gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget );
de1c750f 102
354aa1e3
RR
103 guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() );
104 gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) );
105
106 wxControl::SetLabel( label );
107*/
108
109 m_widget = gtk_button_new_with_label("");
110
111 SetLabel( label );
112
de1c750f
RR
113#if (GTK_MINOR_VERSION > 0)
114 if (style & wxNO_BORDER)
115 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
116#endif
117
b292e2f5
RR
118 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
119 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
c801d85f 120
f03fc89f 121 m_parent->DoAddChild( this );
6ca41e57 122
b292e2f5 123 PostCreation();
f96aa4d9 124
db434467
RR
125 SetFont( parent->GetFont() );
126
127 wxSize best_size( DoGetBestSize() );
128 wxSize new_size( size );
129 if (new_size.x == -1)
130 new_size.x = best_size.x;
131 if (new_size.y == -1)
132 new_size.y = best_size.y;
133 if ((new_size.x != size.x) || (new_size.y != size.y))
134 SetSize( new_size.x, new_size.y );
135
136 SetSize( new_size );
137
b292e2f5
RR
138 SetBackgroundColour( parent->GetBackgroundColour() );
139 SetForegroundColour( parent->GetForegroundColour() );
32c77a71 140
b292e2f5 141 Show( TRUE );
32c77a71 142
b292e2f5 143 return TRUE;
6de97a3b 144}
32c77a71 145
da048e3d 146void wxButton::SetDefault()
c801d85f 147{
3502e687
RR
148 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
149 gtk_widget_grab_default( m_widget );
150
151 SetSize( m_x, m_y, m_width, m_height );
6de97a3b 152}
c801d85f 153
ebea0891
KB
154/* static */
155wxSize wxButton::GetDefaultSize()
8dbf4589
RR
156{
157 return wxSize(80,26);
158}
159
c801d85f
KB
160void wxButton::SetLabel( const wxString &label )
161{
223d09f6 162 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
f96aa4d9 163
b292e2f5 164 wxControl::SetLabel( label );
f96aa4d9 165
3bce7509 166 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel().mbc_str() );
6de97a3b 167}
c801d85f 168
f03fc89f 169bool wxButton::Enable( bool enable )
a9c96bcc 170{
f03fc89f
VZ
171 if ( !wxControl::Enable( enable ) )
172 return FALSE;
f96aa4d9 173
b292e2f5 174 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
f03fc89f
VZ
175
176 return TRUE;
a9c96bcc
RR
177}
178
58614078 179void wxButton::ApplyWidgetStyle()
868a2826 180{
b292e2f5
RR
181 SetWidgetStyle();
182 gtk_widget_set_style( m_widget, m_widgetStyle );
183 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
a81258be 184}
db434467
RR
185
186wxSize wxButton::DoGetBestSize() const
187{
188 wxSize ret( wxControl::DoGetBestSize() );
189 if (ret.x < 80) ret.x = 80;
190 return ret;
191}
192
1e6feb95
VZ
193#endif // wxUSE_BUTTON
194