]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/bmpbuttn.cpp
Test the commit announcement bot some more by fixing more gtk signal callback handler...
[wxWidgets.git] / src / gtk1 / bmpbuttn.cpp
CommitLineData
151ccd11 1/////////////////////////////////////////////////////////////////////////////
f6bcfd97 2// Name: gtk/bmpbuttn.cpp
151ccd11
RR
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
151ccd11
RR
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
1e6feb95 13#include "wx/defs.h"
151ccd11 14
dcf924a3
RR
15#if wxUSE_BMPBUTTON
16
1e6feb95
VZ
17#include "wx/bmpbuttn.h"
18
3cbab641 19#include "wx/gtk1/private.h"
83624f79 20
151ccd11
RR
21//-----------------------------------------------------------------------------
22// classes
23//-----------------------------------------------------------------------------
24
25class wxBitmapButton;
26
acfd422a
RR
27//-----------------------------------------------------------------------------
28// idle system
29//-----------------------------------------------------------------------------
30
31extern void wxapp_install_idle_handler();
32extern bool g_isIdle;
33
66bd6b93
RR
34//-----------------------------------------------------------------------------
35// data
36//-----------------------------------------------------------------------------
37
38extern bool g_blockEventsOnDrag;
39
151ccd11 40//-----------------------------------------------------------------------------
e1e955e1 41// "clicked"
151ccd11
RR
42//-----------------------------------------------------------------------------
43
865bb325 44extern "C" {
66bd6b93 45static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
151ccd11 46{
f6bcfd97 47 if (g_isIdle)
bf9e3e73 48 wxapp_install_idle_handler();
acfd422a 49
a2053b27 50 if (!button->m_hasVMT) return;
43a18898 51 if (g_blockEventsOnDrag) return;
f6bcfd97 52
43a18898
RR
53 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
54 event.SetEventObject(button);
55 button->GetEventHandler()->ProcessEvent(event);
56}
865bb325 57}
43a18898
RR
58
59//-----------------------------------------------------------------------------
60// "enter"
61//-----------------------------------------------------------------------------
62
865bb325 63extern "C" {
43a18898
RR
64static void gtk_bmpbutton_enter_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
65{
a2053b27 66 if (!button->m_hasVMT) return;
43a18898
RR
67 if (g_blockEventsOnDrag) return;
68
f6bcfd97 69 button->HasFocus();
43a18898 70}
865bb325 71}
43a18898
RR
72
73//-----------------------------------------------------------------------------
74// "leave"
75//-----------------------------------------------------------------------------
76
865bb325 77extern "C" {
43a18898
RR
78static void gtk_bmpbutton_leave_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
79{
a2053b27 80 if (!button->m_hasVMT) return;
43a18898
RR
81 if (g_blockEventsOnDrag) return;
82
f6bcfd97 83 button->NotFocus();
43a18898 84}
865bb325 85}
43a18898
RR
86
87//-----------------------------------------------------------------------------
88// "pressed"
89//-----------------------------------------------------------------------------
90
865bb325 91extern "C" {
43a18898
RR
92static void gtk_bmpbutton_press_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
93{
a2053b27 94 if (!button->m_hasVMT) return;
43a18898
RR
95 if (g_blockEventsOnDrag) return;
96
f6bcfd97 97 button->StartSelect();
43a18898 98}
865bb325 99}
43a18898
RR
100
101//-----------------------------------------------------------------------------
102// "released"
103//-----------------------------------------------------------------------------
104
865bb325 105extern "C" {
43a18898
RR
106static void gtk_bmpbutton_release_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
107{
a2053b27 108 if (!button->m_hasVMT) return;
43a18898
RR
109 if (g_blockEventsOnDrag) return;
110
f6bcfd97 111 button->EndSelect();
6de97a3b 112}
865bb325 113}
151ccd11
RR
114
115//-----------------------------------------------------------------------------
e1e955e1
RR
116// wxBitmapButton
117//-----------------------------------------------------------------------------
118
42b4e99e 119IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxButton)
151ccd11 120
c3dfaa10 121void wxBitmapButton::Init()
151ccd11 122{
c3dfaa10 123 m_hasFocus =
902725ee 124 m_isSelected = false;
6de97a3b 125}
151ccd11 126
c3dfaa10
VZ
127bool wxBitmapButton::Create( wxWindow *parent,
128 wxWindowID id,
129 const wxBitmap& bitmap,
130 const wxPoint& pos,
131 const wxSize& size,
132 long style,
133 const wxValidator& validator,
134 const wxString &name )
151ccd11 135{
902725ee
WS
136 m_needParent = true;
137 m_acceptsFocus = true;
f6bcfd97 138
4dcaf11a
RR
139 if (!PreCreation( parent, pos, size ) ||
140 !CreateBase( parent, id, pos, size, style, validator, name ))
141 {
223d09f6 142 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
902725ee 143 return false;
4dcaf11a 144 }
6de97a3b 145
189f58fa 146 m_bmpNormal = bitmap;
f6bcfd97 147
43a18898 148 m_widget = gtk_button_new();
de1c750f 149
de1c750f
RR
150 if (style & wxNO_BORDER)
151 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
de1c750f 152
1e6feb95 153 if (m_bmpNormal.Ok())
43a18898 154 {
29149a64 155 OnSetBitmap();
43a18898 156 }
f6bcfd97 157
58b907f6 158 gtk_signal_connect_after( GTK_OBJECT(m_widget), "clicked",
43a18898 159 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this );
151ccd11 160
f6bcfd97 161 gtk_signal_connect( GTK_OBJECT(m_widget), "enter",
43a18898 162 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback), (gpointer*)this );
f6bcfd97 163 gtk_signal_connect( GTK_OBJECT(m_widget), "leave",
43a18898 164 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback), (gpointer*)this );
f6bcfd97 165 gtk_signal_connect( GTK_OBJECT(m_widget), "pressed",
43a18898 166 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback), (gpointer*)this );
f6bcfd97 167 gtk_signal_connect( GTK_OBJECT(m_widget), "released",
43a18898 168 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback), (gpointer*)this );
f6bcfd97 169
eb082a08 170 m_parent->DoAddChild( this );
f6bcfd97 171
abdeb9e7 172 PostCreation(size);
f6bcfd97 173
902725ee 174 return true;
6de97a3b 175}
f6bcfd97 176
43a18898 177void wxBitmapButton::SetDefault()
151ccd11 178{
43a18898
RR
179 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
180 gtk_widget_grab_default( m_widget );
f6bcfd97 181
3502e687 182 SetSize( m_x, m_y, m_width, m_height );
6de97a3b 183}
151ccd11
RR
184
185void wxBitmapButton::SetLabel( const wxString &label )
186{
223d09f6 187 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
f96aa4d9 188
43a18898 189 wxControl::SetLabel( label );
6de97a3b 190}
151ccd11 191
f40fdaa3 192void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style)
903f689b 193{
9e691f46
VZ
194 if ( !BUTTON_CHILD(m_widget) )
195 return;
29149a64 196
f40fdaa3 197 wxButton::DoApplyWidgetStyle(style);
43a18898
RR
198}
199
29149a64 200void wxBitmapButton::OnSetBitmap()
43a18898 201{
1e6feb95 202 wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
f96aa4d9 203
9f884528 204 InvalidateBestSize();
902725ee 205
43a18898 206 wxBitmap the_one;
f6bcfd97 207 if (!m_isEnabled)
29149a64 208 the_one = m_bmpDisabled;
67a6726a 209 else if (m_isSelected)
29149a64 210 the_one = m_bmpSelected;
67a6726a 211 else if (m_hasFocus)
29149a64 212 the_one = m_bmpFocus;
f6bcfd97 213 else
902725ee 214 the_one = m_bmpNormal;
43a18898 215
1e6feb95 216 if (!the_one.Ok()) the_one = m_bmpNormal;
de1c750f 217 if (!the_one.Ok()) return;
f6bcfd97 218
43a18898
RR
219 GdkBitmap *mask = (GdkBitmap *) NULL;
220 if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
f6bcfd97 221
9e691f46
VZ
222 GtkWidget *child = BUTTON_CHILD(m_widget);
223 if (child == NULL)
29149a64
VZ
224 {
225 // initial bitmap
4fab7128 226 GtkWidget *pixmap;
4fab7128 227 pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask);
67a6726a
RR
228 gtk_widget_show(pixmap);
229 gtk_container_add(GTK_CONTAINER(m_widget), pixmap);
29149a64
VZ
230 }
231 else
67a6726a 232 { // subsequent bitmaps
4fab7128
VS
233 GtkPixmap *pixmap = GTK_PIXMAP(child);
234 gtk_pixmap_set(pixmap, the_one.GetPixmap(), mask);
67a6726a 235 }
903f689b
RR
236}
237
e0aeebed
VS
238wxSize wxBitmapButton::DoGetBestSize() const
239{
240 return wxControl::DoGetBestSize();
241}
242
f03fc89f 243bool wxBitmapButton::Enable( bool enable )
43a18898 244{
f03fc89f 245 if ( !wxWindow::Enable(enable) )
902725ee 246 return false;
43a18898 247
29149a64 248 OnSetBitmap();
f03fc89f 249
902725ee 250 return true;
43a18898
RR
251}
252
253void wxBitmapButton::HasFocus()
254{
902725ee 255 m_hasFocus = true;
29149a64 256 OnSetBitmap();
43a18898
RR
257}
258
259void wxBitmapButton::NotFocus()
260{
902725ee 261 m_hasFocus = false;
29149a64 262 OnSetBitmap();
43a18898
RR
263}
264
265void wxBitmapButton::StartSelect()
266{
902725ee 267 m_isSelected = true;
29149a64 268 OnSetBitmap();
43a18898
RR
269}
270
271void wxBitmapButton::EndSelect()
272{
902725ee 273 m_isSelected = false;
29149a64 274 OnSetBitmap();
43a18898 275}
f6bcfd97
BP
276
277#endif // wxUSE_BMPBUTTON
dcf924a3 278