]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/bmpbuttn.cpp
Further fixes to references
[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
f6bcfd97 7// Licence: wxWindows licence
151ccd11
RR
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "bmpbuttn.h"
12#endif
13
1e6feb95 14#include "wx/defs.h"
151ccd11 15
dcf924a3
RR
16#if wxUSE_BMPBUTTON
17
1e6feb95
VZ
18#include "wx/bmpbuttn.h"
19
9e691f46 20#include "wx/gtk/private.h"
83624f79 21
151ccd11
RR
22//-----------------------------------------------------------------------------
23// classes
24//-----------------------------------------------------------------------------
25
26class wxBitmapButton;
27
acfd422a
RR
28//-----------------------------------------------------------------------------
29// idle system
30//-----------------------------------------------------------------------------
31
32extern void wxapp_install_idle_handler();
33extern bool g_isIdle;
34
66bd6b93
RR
35//-----------------------------------------------------------------------------
36// data
37//-----------------------------------------------------------------------------
38
39extern bool g_blockEventsOnDrag;
40
151ccd11 41//-----------------------------------------------------------------------------
e1e955e1 42// "clicked"
151ccd11
RR
43//-----------------------------------------------------------------------------
44
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}
57
58//-----------------------------------------------------------------------------
59// "enter"
60//-----------------------------------------------------------------------------
61
62static void gtk_bmpbutton_enter_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
63{
a2053b27 64 if (!button->m_hasVMT) return;
43a18898
RR
65 if (g_blockEventsOnDrag) return;
66
f6bcfd97 67 button->HasFocus();
43a18898
RR
68}
69
70//-----------------------------------------------------------------------------
71// "leave"
72//-----------------------------------------------------------------------------
73
74static void gtk_bmpbutton_leave_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
75{
a2053b27 76 if (!button->m_hasVMT) return;
43a18898
RR
77 if (g_blockEventsOnDrag) return;
78
f6bcfd97 79 button->NotFocus();
43a18898
RR
80}
81
82//-----------------------------------------------------------------------------
83// "pressed"
84//-----------------------------------------------------------------------------
85
86static void gtk_bmpbutton_press_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
87{
a2053b27 88 if (!button->m_hasVMT) return;
43a18898
RR
89 if (g_blockEventsOnDrag) return;
90
f6bcfd97 91 button->StartSelect();
43a18898
RR
92}
93
94//-----------------------------------------------------------------------------
95// "released"
96//-----------------------------------------------------------------------------
97
98static void gtk_bmpbutton_release_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
99{
a2053b27 100 if (!button->m_hasVMT) return;
43a18898
RR
101 if (g_blockEventsOnDrag) return;
102
f6bcfd97 103 button->EndSelect();
6de97a3b 104}
151ccd11
RR
105
106//-----------------------------------------------------------------------------
e1e955e1
RR
107// wxBitmapButton
108//-----------------------------------------------------------------------------
109
42b4e99e 110IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxButton)
151ccd11 111
43a18898 112wxBitmapButton::wxBitmapButton()
151ccd11 113{
6de97a3b 114}
151ccd11 115
43a18898 116bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
f6bcfd97 117 const wxPoint &pos, const wxSize &size,
43a18898 118 long style, const wxValidator& validator, const wxString &name )
151ccd11 119{
43a18898 120 m_needParent = TRUE;
b292e2f5 121 m_acceptsFocus = TRUE;
f6bcfd97 122
4dcaf11a
RR
123 if (!PreCreation( parent, pos, size ) ||
124 !CreateBase( parent, id, pos, size, style, validator, name ))
125 {
223d09f6 126 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
f6bcfd97 127 return FALSE;
4dcaf11a 128 }
6de97a3b 129
1e6feb95
VZ
130 m_bmpNormal =
131 m_bmpDisabled =
132 m_bmpFocus =
133 m_bmpSelected = bitmap;
f6bcfd97 134
43a18898 135 m_widget = gtk_button_new();
de1c750f 136
f6bcfd97 137#if (GTK_MINOR_VERSION > 0)
de1c750f
RR
138 if (style & wxNO_BORDER)
139 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
140#endif
141
1e6feb95 142 if (m_bmpNormal.Ok())
43a18898 143 {
4dcaf11a 144 wxSize newSize = size;
67a6726a 145 int border = (style & wxNO_BORDER) ? 4 : 10;
29149a64
VZ
146 if (newSize.x == -1)
147 newSize.x = m_bmpNormal.GetWidth()+border;
148 if (newSize.y == -1)
149 newSize.y = m_bmpNormal.GetHeight()+border;
d1af991f 150 SetSize( newSize.x, newSize.y );
29149a64 151 OnSetBitmap();
43a18898 152 }
f6bcfd97
BP
153
154 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
43a18898 155 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this );
151ccd11 156
f6bcfd97 157 gtk_signal_connect( GTK_OBJECT(m_widget), "enter",
43a18898 158 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback), (gpointer*)this );
f6bcfd97 159 gtk_signal_connect( GTK_OBJECT(m_widget), "leave",
43a18898 160 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback), (gpointer*)this );
f6bcfd97 161 gtk_signal_connect( GTK_OBJECT(m_widget), "pressed",
43a18898 162 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback), (gpointer*)this );
f6bcfd97 163 gtk_signal_connect( GTK_OBJECT(m_widget), "released",
43a18898 164 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback), (gpointer*)this );
f6bcfd97 165
eb082a08 166 m_parent->DoAddChild( this );
f6bcfd97 167
43a18898 168 PostCreation();
f6bcfd97 169
43a18898 170 SetBackgroundColour( parent->GetBackgroundColour() );
f96aa4d9 171
43a18898 172 Show( TRUE );
f6bcfd97 173
43a18898 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
43a18898 192wxString wxBitmapButton::GetLabel() const
151ccd11 193{
223d09f6 194 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid button") );
f96aa4d9 195
43a18898 196 return wxControl::GetLabel();
6de97a3b 197}
903f689b 198
43a18898 199void wxBitmapButton::ApplyWidgetStyle()
903f689b 200{
9e691f46
VZ
201 if ( !BUTTON_CHILD(m_widget) )
202 return;
29149a64 203
67a6726a 204 wxButton::ApplyWidgetStyle();
43a18898
RR
205}
206
29149a64 207void wxBitmapButton::OnSetBitmap()
43a18898 208{
1e6feb95 209 wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
f96aa4d9 210
43a18898 211 wxBitmap the_one;
f6bcfd97 212 if (!m_isEnabled)
29149a64 213 the_one = m_bmpDisabled;
67a6726a 214 else if (m_isSelected)
29149a64 215 the_one = m_bmpSelected;
67a6726a 216 else if (m_hasFocus)
29149a64 217 the_one = m_bmpFocus;
f6bcfd97 218 else
1e6feb95
VZ
219 {
220 if (m_isSelected)
221 {
222 the_one = m_bmpSelected;
223 }
224 else
225 {
226 if (m_hasFocus)
227 the_one = m_bmpFocus;
228 else
229 the_one = m_bmpNormal;
230 }
231 }
43a18898 232
1e6feb95 233 if (!the_one.Ok()) the_one = m_bmpNormal;
de1c750f 234 if (!the_one.Ok()) return;
f6bcfd97 235
43a18898
RR
236 GdkBitmap *mask = (GdkBitmap *) NULL;
237 if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
f6bcfd97 238
9e691f46
VZ
239 GtkWidget *child = BUTTON_CHILD(m_widget);
240 if (child == NULL)
29149a64
VZ
241 {
242 // initial bitmap
67a6726a
RR
243 GtkWidget *pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask);
244 gtk_widget_show(pixmap);
245 gtk_container_add(GTK_CONTAINER(m_widget), pixmap);
29149a64
VZ
246 }
247 else
67a6726a 248 { // subsequent bitmaps
9e691f46 249 GtkPixmap *g_pixmap = GTK_PIXMAP(child);
67a6726a
RR
250 gtk_pixmap_set(g_pixmap, the_one.GetPixmap(), mask);
251 }
903f689b
RR
252}
253
f03fc89f 254bool wxBitmapButton::Enable( bool enable )
43a18898 255{
f03fc89f
VZ
256 if ( !wxWindow::Enable(enable) )
257 return FALSE;
43a18898 258
29149a64 259 OnSetBitmap();
f03fc89f
VZ
260
261 return TRUE;
43a18898
RR
262}
263
264void wxBitmapButton::HasFocus()
265{
266 m_hasFocus = TRUE;
29149a64 267 OnSetBitmap();
43a18898
RR
268}
269
270void wxBitmapButton::NotFocus()
271{
272 m_hasFocus = FALSE;
29149a64 273 OnSetBitmap();
43a18898
RR
274}
275
276void wxBitmapButton::StartSelect()
277{
278 m_isSelected = TRUE;
29149a64 279 OnSetBitmap();
43a18898
RR
280}
281
282void wxBitmapButton::EndSelect()
283{
284 m_isSelected = FALSE;
29149a64 285 OnSetBitmap();
43a18898 286}
f6bcfd97
BP
287
288#endif // wxUSE_BMPBUTTON
dcf924a3 289