Added bitmaps and icons to samples
[wxWidgets.git] / src / gtk1 / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bmpbuttn.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 "bmpbuttn.h"
13 #endif
14
15 #include "wx/bmpbuttn.h"
16
17 //-----------------------------------------------------------------------------
18 // classes
19 //-----------------------------------------------------------------------------
20
21 class wxBitmapButton;
22
23 //-----------------------------------------------------------------------------
24 // wxBitmapButton
25 //-----------------------------------------------------------------------------
26
27 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxControl)
28
29 void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
30 {
31 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
32 event.SetEventObject(button);
33 button->GetEventHandler()->ProcessEvent(event);
34 };
35
36 //-----------------------------------------------------------------------------
37
38 wxBitmapButton::wxBitmapButton(void)
39 {
40 };
41
42 wxBitmapButton::wxBitmapButton( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
43 const wxPoint &pos, const wxSize &size,
44 long style, const wxString &name )
45 {
46 Create( parent, id, bitmap, pos, size, style, name );
47 };
48
49 bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
50 const wxPoint &pos, const wxSize &size,
51 long style, const wxString &name )
52 {
53 m_needParent = TRUE;
54
55 wxSize newSize = size;
56
57 PreCreation( parent, id, pos, newSize, style, name );
58
59 m_bitmap = bitmap;
60 m_label = "";
61
62 m_widget = gtk_button_new();
63
64 if (m_bitmap.Ok())
65 {
66 GdkBitmap *mask = NULL;
67 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
68 GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
69
70 gtk_widget_show( pixmap );
71 gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
72 };
73
74 if (newSize.x == -1) newSize.x = m_bitmap.GetHeight()+10;
75 if (newSize.y == -1) newSize.y = m_bitmap.GetWidth()+10;
76 SetSize( newSize.x, newSize.y );
77
78 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
79 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this );
80
81 PostCreation();
82
83 Show( TRUE );
84
85 return TRUE;
86 };
87
88 void wxBitmapButton::SetDefault(void)
89 {
90 };
91
92 void wxBitmapButton::SetLabel( const wxString &label )
93 {
94 wxControl::SetLabel( label );
95 };
96
97 wxString wxBitmapButton::GetLabel(void) const
98 {
99 return wxControl::GetLabel();
100 };