]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/bmpbuttn.cpp
OS/2 updates for statusbar processing
[wxWidgets.git] / src / gtk1 / bmpbuttn.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: gtk/bmpbuttn.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "bmpbuttn.h"
12#endif
13
14#include "wx/bmpbuttn.h"
15
16#if wxUSE_BMPBUTTON
17
18#include <gdk/gdk.h>
19#include <gtk/gtk.h>
20
21//-----------------------------------------------------------------------------
22// classes
23//-----------------------------------------------------------------------------
24
25class wxBitmapButton;
26
27//-----------------------------------------------------------------------------
28// idle system
29//-----------------------------------------------------------------------------
30
31extern void wxapp_install_idle_handler();
32extern bool g_isIdle;
33
34//-----------------------------------------------------------------------------
35// data
36//-----------------------------------------------------------------------------
37
38extern bool g_blockEventsOnDrag;
39
40//-----------------------------------------------------------------------------
41// "clicked"
42//-----------------------------------------------------------------------------
43
44static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
45{
46 if (g_isIdle)
47 wxapp_install_idle_handler();
48
49 if (!button->m_hasVMT) return;
50 if (g_blockEventsOnDrag) return;
51
52 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
53 event.SetEventObject(button);
54 button->GetEventHandler()->ProcessEvent(event);
55}
56
57//-----------------------------------------------------------------------------
58// "enter"
59//-----------------------------------------------------------------------------
60
61static void gtk_bmpbutton_enter_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
62{
63 if (!button->m_hasVMT) return;
64 if (g_blockEventsOnDrag) return;
65
66 button->HasFocus();
67}
68
69//-----------------------------------------------------------------------------
70// "leave"
71//-----------------------------------------------------------------------------
72
73static void gtk_bmpbutton_leave_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
74{
75 if (!button->m_hasVMT) return;
76 if (g_blockEventsOnDrag) return;
77
78 button->NotFocus();
79}
80
81//-----------------------------------------------------------------------------
82// "pressed"
83//-----------------------------------------------------------------------------
84
85static void gtk_bmpbutton_press_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
86{
87 if (!button->m_hasVMT) return;
88 if (g_blockEventsOnDrag) return;
89
90 button->StartSelect();
91}
92
93//-----------------------------------------------------------------------------
94// "released"
95//-----------------------------------------------------------------------------
96
97static void gtk_bmpbutton_release_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
98{
99 if (!button->m_hasVMT) return;
100 if (g_blockEventsOnDrag) return;
101
102 button->EndSelect();
103}
104
105//-----------------------------------------------------------------------------
106// wxBitmapButton
107//-----------------------------------------------------------------------------
108
109IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxButton)
110
111wxBitmapButton::wxBitmapButton()
112{
113}
114
115bool 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 )
118{
119 m_needParent = TRUE;
120 m_acceptsFocus = TRUE;
121
122 m_marginX =
123 m_marginY = 0;
124
125 if (!PreCreation( parent, pos, size ) ||
126 !CreateBase( parent, id, pos, size, style, validator, name ))
127 {
128 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
129 return FALSE;
130 }
131
132 m_bitmap = bitmap;
133 m_disabled = bitmap;
134 m_focus = bitmap;
135 m_selected = bitmap;
136
137 m_widget = gtk_button_new();
138
139#if (GTK_MINOR_VERSION > 0)
140 if (style & wxNO_BORDER)
141 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
142#endif
143
144 if (m_bitmap.Ok())
145 {
146 wxSize newSize = size;
147
148 GdkBitmap *mask = (GdkBitmap *) NULL;
149 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
150 GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
151
152 gtk_widget_show( pixmap );
153 gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
154
155 int border = 10;
156 if (style & wxNO_BORDER) border = 4;
157 if (newSize.x == -1) newSize.x = m_bitmap.GetWidth()+border;
158 if (newSize.y == -1) newSize.y = m_bitmap.GetHeight()+border;
159 SetSize( newSize.x, newSize.y );
160 }
161
162 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
163 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this );
164
165 gtk_signal_connect( GTK_OBJECT(m_widget), "enter",
166 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback), (gpointer*)this );
167 gtk_signal_connect( GTK_OBJECT(m_widget), "leave",
168 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback), (gpointer*)this );
169 gtk_signal_connect( GTK_OBJECT(m_widget), "pressed",
170 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback), (gpointer*)this );
171 gtk_signal_connect( GTK_OBJECT(m_widget), "released",
172 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback), (gpointer*)this );
173
174 m_parent->DoAddChild( this );
175
176 PostCreation();
177
178 SetBackgroundColour( parent->GetBackgroundColour() );
179
180 Show( TRUE );
181
182 return TRUE;
183}
184
185void wxBitmapButton::SetDefault()
186{
187 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
188 gtk_widget_grab_default( m_widget );
189
190 SetSize( m_x, m_y, m_width, m_height );
191}
192
193void wxBitmapButton::SetLabel( const wxString &label )
194{
195 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
196
197 wxControl::SetLabel( label );
198}
199
200wxString wxBitmapButton::GetLabel() const
201{
202 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid button") );
203
204 return wxControl::GetLabel();
205}
206
207void wxBitmapButton::ApplyWidgetStyle()
208{
209}
210
211void wxBitmapButton::SetBitmap()
212{
213 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
214
215 wxBitmap the_one;
216
217 if (!m_isEnabled)
218 the_one = m_disabled;
219 else
220 {
221 if (m_isSelected)
222 {
223 the_one = m_selected;
224 }
225 else
226 {
227 if (m_hasFocus)
228 the_one = m_focus;
229 else
230 the_one = m_bitmap;
231 }
232 }
233
234 if (!the_one.Ok()) the_one = m_bitmap;
235 if (!the_one.Ok()) return;
236
237 GtkButton *bin = GTK_BUTTON( m_widget );
238 GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child );
239
240 GdkBitmap *mask = (GdkBitmap *) NULL;
241 if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
242
243 gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask );
244}
245
246void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
247{
248 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
249
250 if ( ! m_disabled.Ok() ) return;
251 m_disabled = bitmap;
252
253 SetBitmap();
254}
255
256void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
257{
258 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
259
260 if ( ! m_focus.Ok() ) return;
261 m_focus = bitmap;
262
263 SetBitmap();
264}
265
266void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
267{
268 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
269
270 if (!m_bitmap.Ok()) return;
271 m_bitmap = bitmap;
272
273 SetBitmap();
274}
275
276void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
277{
278 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
279
280 if ( ! m_selected.Ok() ) return;
281 m_selected = bitmap;
282
283 SetBitmap();
284}
285
286bool wxBitmapButton::Enable( bool enable )
287{
288 if ( !wxWindow::Enable(enable) )
289 return FALSE;
290
291 SetBitmap();
292
293 return TRUE;
294}
295
296void wxBitmapButton::HasFocus()
297{
298 m_hasFocus = TRUE;
299 SetBitmap();
300}
301
302void wxBitmapButton::NotFocus()
303{
304 m_hasFocus = FALSE;
305 SetBitmap();
306}
307
308void wxBitmapButton::StartSelect()
309{
310 m_isSelected = TRUE;
311 SetBitmap();
312}
313
314void wxBitmapButton::EndSelect()
315{
316 m_isSelected = FALSE;
317 SetBitmap();
318}
319
320#endif // wxUSE_BMPBUTTON
321