]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/bmpbuttn.cpp
Tried to find a non-existing bug in the cursor-code
[wxWidgets.git] / src / gtk / 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 // data
25 //-----------------------------------------------------------------------------
26
27 extern bool g_blockEventsOnDrag;
28
29 //-----------------------------------------------------------------------------
30 // "clicked"
31 //-----------------------------------------------------------------------------
32
33 static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
34 {
35 if (!button->HasVMT()) return;
36 if (g_blockEventsOnDrag) return;
37
38 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
39 event.SetEventObject(button);
40 button->GetEventHandler()->ProcessEvent(event);
41 }
42
43 //-----------------------------------------------------------------------------
44 // wxBitmapButton
45 //-----------------------------------------------------------------------------
46
47 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxControl)
48
49 wxBitmapButton::wxBitmapButton(void)
50 {
51 }
52
53 bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
54 const wxPoint &pos, const wxSize &size,
55 long style, const wxValidator& validator, const wxString &name )
56 {
57 m_needParent = TRUE;
58
59 wxSize newSize = size;
60
61 PreCreation( parent, id, pos, newSize, style, name );
62
63 SetValidator( validator );
64
65 m_bitmap = bitmap;
66 m_label = "";
67
68 m_widget = gtk_button_new();
69
70 if (m_bitmap.Ok())
71 {
72 GdkBitmap *mask = (GdkBitmap *) NULL;
73 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
74 GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
75
76 gtk_widget_show( pixmap );
77 gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
78 }
79
80 if (newSize.x == -1) newSize.x = m_bitmap.GetHeight()+10;
81 if (newSize.y == -1) newSize.y = m_bitmap.GetWidth()+10;
82 SetSize( newSize.x, newSize.y );
83
84 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
85 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this );
86
87 PostCreation();
88
89 Show( TRUE );
90
91 return TRUE;
92 }
93
94 void wxBitmapButton::SetDefault(void)
95 {
96 /*
97 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
98 gtk_widget_grab_default( m_widget );
99 */
100 }
101
102 void wxBitmapButton::SetLabel( const wxString &label )
103 {
104 wxControl::SetLabel( label );
105 }
106
107 wxString wxBitmapButton::GetLabel(void) const
108 {
109 return wxControl::GetLabel();
110 }
111
112 void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
113 {
114 m_bitmap = bitmap;
115 if (!m_bitmap.Ok()) return;
116
117 GtkButton *bin = GTK_BUTTON( m_widget );
118 GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child );
119
120 GdkBitmap *mask = (GdkBitmap *) NULL;
121 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
122
123 gtk_pixmap_set( g_pixmap, m_bitmap.GetPixmap(), mask );
124 }
125
126
127
128