]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/button.cpp
Dialog unit mods; wxProp tidying
[wxWidgets.git] / src / gtk1 / button.cpp
CommitLineData
c801d85f
KB
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
66bd6b93
RR
23//-----------------------------------------------------------------------------
24// data
25//-----------------------------------------------------------------------------
26
27extern bool g_blockEventsOnDrag;
28
c801d85f 29//-----------------------------------------------------------------------------
e1e955e1 30// "clicked"
c801d85f
KB
31//-----------------------------------------------------------------------------
32
66bd6b93 33static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxButton *button )
c801d85f 34{
66bd6b93
RR
35 if (!button->HasVMT()) return;
36 if (g_blockEventsOnDrag) return;
37
c801d85f
KB
38 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
39 event.SetEventObject(button);
47908e25 40 button->GetEventHandler()->ProcessEvent(event);
6de97a3b 41}
c801d85f
KB
42
43//-----------------------------------------------------------------------------
e1e955e1
RR
44// wxButton
45//-----------------------------------------------------------------------------
46
47IMPLEMENT_DYNAMIC_CLASS(wxButton,wxControl)
c801d85f
KB
48
49wxButton::wxButton(void)
50{
6de97a3b 51}
c801d85f
KB
52
53bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
32c77a71 54 const wxPoint &pos, const wxSize &size,
6de97a3b 55 long style, const wxValidator& validator, const wxString &name )
c801d85f
KB
56{
57 m_needParent = TRUE;
32c77a71 58
c801d85f
KB
59 wxSize newSize = size;
60
61 PreCreation( parent, id, pos, newSize, style, name );
6de97a3b
RR
62
63 SetValidator( validator );
32c77a71 64
32c77a71 65 m_widget = gtk_button_new_with_label( m_label );
b593568e 66 SetLabel(label);
32c77a71 67
c801d85f
KB
68 if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
69 if (newSize.y == -1) newSize.y = 26;
70 SetSize( newSize.x, newSize.y );
32c77a71
VZ
71
72 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
c801d85f
KB
73 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
74
75 PostCreation();
32c77a71 76
c801d85f 77 Show( TRUE );
32c77a71 78
c801d85f 79 return TRUE;
6de97a3b 80}
32c77a71 81
c801d85f
KB
82void wxButton::SetDefault(void)
83{
903f689b
RR
84/*
85 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
6de97a3b 86 gtk_widget_grab_default( m_widget );
903f689b 87*/
6de97a3b 88}
c801d85f
KB
89
90void wxButton::SetLabel( const wxString &label )
91{
92 wxControl::SetLabel( label );
b593568e 93 GtkButton *bin = GTK_BUTTON( m_widget );
b6af8d80
RR
94 GtkLabel *g_label = GTK_LABEL( bin->child );
95 gtk_label_set( g_label, GetLabel() );
6de97a3b 96}
c801d85f 97
a9c96bcc
RR
98void wxButton::Enable( bool enable )
99{
100 wxControl::Enable( enable );
101 GtkButton *bin = GTK_BUTTON( m_widget );
102 GtkWidget *label = bin->child;
103 gtk_widget_set_sensitive( label, enable );
104}
105
868a2826
RR
106void wxButton::SetFont( const wxFont &font )
107{
3f659fd6
RR
108 if (((wxFont*)&font)->Ok())
109 m_font = font;
110 else
111 m_font = *wxSWISS_FONT;
112
868a2826
RR
113 GtkButton *bin = GTK_BUTTON( m_widget );
114 GtkWidget *label = bin->child;
115
116 GtkStyle *style = (GtkStyle*) NULL;
117 if (!m_hasOwnStyle)
118 {
119 m_hasOwnStyle = TRUE;
120 style = gtk_style_copy( gtk_widget_get_style( label ) );
121 }
122 else
123 {
124 style = gtk_widget_get_style( label );
125 }
126
127 gdk_font_unref( style->font );
128 style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
129
130 gtk_widget_set_style( label, style );
131}