1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/bmpbuttn.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "bmpbuttn.h"
14 #include "wx/bmpbuttn.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern bool g_blockEventsOnDrag
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
47 wxapp_install_idle_handler();
49 if (!button
->m_hasVMT
) return;
50 if (g_blockEventsOnDrag
) return;
52 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
53 event
.SetEventObject(button
);
54 button
->GetEventHandler()->ProcessEvent(event
);
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
63 if (!button
->m_hasVMT
) return;
64 if (g_blockEventsOnDrag
) return;
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
75 if (!button
->m_hasVMT
) return;
76 if (g_blockEventsOnDrag
) return;
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
87 if (!button
->m_hasVMT
) return;
88 if (g_blockEventsOnDrag
) return;
90 button
->StartSelect();
93 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
97 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
99 if (!button
->m_hasVMT
) return;
100 if (g_blockEventsOnDrag
) return;
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
109 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
111 wxBitmapButton::wxBitmapButton()
115 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
116 const wxPoint
&pos
, const wxSize
&size
,
117 long style
, const wxValidator
& validator
, const wxString
&name
)
120 m_acceptsFocus
= TRUE
;
125 if (!PreCreation( parent
, pos
, size
) ||
126 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
128 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
137 m_widget
= gtk_button_new();
139 #if (GTK_MINOR_VERSION > 0)
140 if (style
& wxNO_BORDER
)
141 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
146 wxSize newSize
= size
;
147 int border
= (style
& wxNO_BORDER
) ? 4 : 10;
148 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetWidth()+border
;
149 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetHeight()+border
;
150 SetSize( newSize
.x
, newSize
.y
);
154 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
155 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
157 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
158 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
159 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
160 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
161 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
162 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
163 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
164 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
166 m_parent
->DoAddChild( this );
170 SetBackgroundColour( parent
->GetBackgroundColour() );
177 void wxBitmapButton::SetDefault()
179 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
180 gtk_widget_grab_default( m_widget
);
182 SetSize( m_x
, m_y
, m_width
, m_height
);
185 void wxBitmapButton::SetLabel( const wxString
&label
)
187 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
189 wxControl::SetLabel( label
);
192 wxString
wxBitmapButton::GetLabel() const
194 wxCHECK_MSG( m_widget
!= NULL
, wxT(""), wxT("invalid button") );
196 return wxControl::GetLabel();
199 void wxBitmapButton::ApplyWidgetStyle()
201 if (GTK_BUTTON(m_widget
)->child
== NULL
) return;
203 wxButton::ApplyWidgetStyle();
206 void wxBitmapButton::SetBitmap()
208 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
212 the_one
= m_disabled
;
213 else if (m_isSelected
)
214 the_one
= m_selected
;
220 if (!the_one
.Ok()) the_one
= m_bitmap
;
221 if (!the_one
.Ok()) return;
223 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
224 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
226 GtkButton
*bin
= GTK_BUTTON(m_widget
);
227 if (bin
->child
== NULL
)
229 GtkWidget
*pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
230 gtk_widget_show(pixmap
);
231 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
234 { // subsequent bitmaps
235 GtkPixmap
*g_pixmap
= GTK_PIXMAP(bin
->child
);
236 gtk_pixmap_set(g_pixmap
, the_one
.GetPixmap(), mask
);
240 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
242 if (!bitmap
.Ok()) return;
248 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
250 if (!bitmap
.Ok()) return;
256 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
258 if (!bitmap
.Ok()) return;
264 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
266 if (!bitmap
.Ok()) return;
272 bool wxBitmapButton::Enable( bool enable
)
274 if ( !wxWindow::Enable(enable
) )
282 void wxBitmapButton::HasFocus()
288 void wxBitmapButton::NotFocus()
294 void wxBitmapButton::StartSelect()
300 void wxBitmapButton::EndSelect()
302 m_isSelected
= FALSE
;
306 #endif // wxUSE_BMPBUTTON