]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/bmpbuttn.cpp
mac support as stubs added
[wxWidgets.git] / src / gtk1 / bmpbuttn.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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//-----------------------------------------------------------------------------
17// classes
18//-----------------------------------------------------------------------------
19
20class wxBitmapButton;
21
22//-----------------------------------------------------------------------------
23// data
24//-----------------------------------------------------------------------------
25
26extern bool g_blockEventsOnDrag;
27
28//-----------------------------------------------------------------------------
29// "clicked"
30//-----------------------------------------------------------------------------
31
32static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
33{
34 if (!button->HasVMT()) return;
35 if (g_blockEventsOnDrag) return;
36
37 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
38 event.SetEventObject(button);
39 button->GetEventHandler()->ProcessEvent(event);
40}
41
42//-----------------------------------------------------------------------------
43// "enter"
44//-----------------------------------------------------------------------------
45
46static void gtk_bmpbutton_enter_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
47{
48 if (!button->HasVMT()) return;
49 if (g_blockEventsOnDrag) return;
50
51 button->HasFocus();
52}
53
54//-----------------------------------------------------------------------------
55// "leave"
56//-----------------------------------------------------------------------------
57
58static void gtk_bmpbutton_leave_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
59{
60 if (!button->HasVMT()) return;
61 if (g_blockEventsOnDrag) return;
62
63 button->NotFocus();
64}
65
66//-----------------------------------------------------------------------------
67// "pressed"
68//-----------------------------------------------------------------------------
69
70static void gtk_bmpbutton_press_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
71{
72 if (!button->HasVMT()) return;
73 if (g_blockEventsOnDrag) return;
74
75 button->StartSelect();
76}
77
78//-----------------------------------------------------------------------------
79// "released"
80//-----------------------------------------------------------------------------
81
82static void gtk_bmpbutton_release_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
83{
84 if (!button->HasVMT()) return;
85 if (g_blockEventsOnDrag) return;
86
87 button->EndSelect();
88}
89
90//-----------------------------------------------------------------------------
91// wxBitmapButton
92//-----------------------------------------------------------------------------
93
94IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxControl)
95
96wxBitmapButton::wxBitmapButton()
97{
98}
99
100bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
101 const wxPoint &pos, const wxSize &size,
102 long style, const wxValidator& validator, const wxString &name )
103{
104 m_needParent = TRUE;
105 m_acceptsFocus = TRUE;
106
107 wxSize newSize = size;
108
109 PreCreation( parent, id, pos, newSize, style, name );
110
111 SetValidator( validator );
112
113 m_bitmap = bitmap;
114 m_disabled = bitmap;
115 m_focus = bitmap;
116 m_selected = bitmap;
117
118 m_label = "";
119
120 m_widget = gtk_button_new();
121
122 if (m_bitmap.Ok())
123 {
124 GdkBitmap *mask = (GdkBitmap *) NULL;
125 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
126 GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
127
128 gtk_widget_show( pixmap );
129 gtk_container_add( GTK_CONTAINER(m_widget), pixmap );
130 }
131
132 if (newSize.x == -1) newSize.x = m_bitmap.GetHeight()+10;
133 if (newSize.y == -1) newSize.y = m_bitmap.GetWidth()+10;
134 SetSize( newSize.x, newSize.y );
135
136 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
137 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this );
138
139 gtk_signal_connect( GTK_OBJECT(m_widget), "enter",
140 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback), (gpointer*)this );
141 gtk_signal_connect( GTK_OBJECT(m_widget), "leave",
142 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback), (gpointer*)this );
143 gtk_signal_connect( GTK_OBJECT(m_widget), "pressed",
144 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback), (gpointer*)this );
145 gtk_signal_connect( GTK_OBJECT(m_widget), "released",
146 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback), (gpointer*)this );
147
148 m_parent->AddChild( this );
149
150 (m_parent->m_insertCallback)( m_parent, this );
151
152 PostCreation();
153
154 SetBackgroundColour( parent->GetBackgroundColour() );
155
156 Show( TRUE );
157
158 return TRUE;
159}
160
161void wxBitmapButton::SetDefault()
162{
163/*
164 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
165 gtk_widget_grab_default( m_widget );
166*/
167}
168
169void wxBitmapButton::SetLabel( const wxString &label )
170{
171 wxCHECK_RET( m_widget != NULL, "invalid button" );
172
173 wxControl::SetLabel( label );
174}
175
176wxString wxBitmapButton::GetLabel() const
177{
178 wxCHECK_MSG( m_widget != NULL, "", "invalid button" );
179
180 return wxControl::GetLabel();
181}
182
183void wxBitmapButton::ApplyWidgetStyle()
184{
185}
186
187void wxBitmapButton::SetBitmap()
188{
189 wxCHECK_RET( m_widget != NULL, "invalid button" );
190
191 wxBitmap the_one;
192
193 if ( ! m_isEnabled )
194 the_one = m_disabled;
195 else
196 {
197 if ( m_isSelected )
198 {
199 the_one = m_selected;
200 }
201 else
202 {
203 if ( m_hasFocus )
204 the_one = m_focus;
205 else
206 the_one = m_bitmap;
207 }
208 }
209
210 if ( ! the_one.Ok() ) the_one = m_bitmap;
211 if ( ! the_one.Ok() ) return;
212
213 GtkButton *bin = GTK_BUTTON( m_widget );
214 GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child );
215
216 GdkBitmap *mask = (GdkBitmap *) NULL;
217 if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
218
219 gtk_pixmap_set( g_pixmap, the_one.GetPixmap(), mask );
220}
221
222void wxBitmapButton::SetBitmapDisabled( const wxBitmap& bitmap )
223{
224 wxCHECK_RET( m_widget != NULL, "invalid button" );
225
226 if ( ! m_disabled.Ok() ) return;
227 m_disabled = bitmap;
228
229 SetBitmap();
230}
231
232void wxBitmapButton::SetBitmapFocus( const wxBitmap& bitmap )
233{
234 wxCHECK_RET( m_widget != NULL, "invalid button" );
235
236 if ( ! m_focus.Ok() ) return;
237 m_focus = bitmap;
238
239 SetBitmap();
240}
241
242void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
243{
244 wxCHECK_RET( m_widget != NULL, "invalid button" );
245
246 if (!m_bitmap.Ok()) return;
247 m_bitmap = bitmap;
248
249 SetBitmap();
250}
251
252void wxBitmapButton::SetBitmapSelected( const wxBitmap& bitmap )
253{
254 wxCHECK_RET( m_widget != NULL, "invalid button" );
255
256 if ( ! m_selected.Ok() ) return;
257 m_selected = bitmap;
258
259 SetBitmap();
260}
261
262void wxBitmapButton::Enable( const bool enable )
263{
264 wxWindow::Enable(enable);
265
266 SetBitmap();
267}
268
269void wxBitmapButton::HasFocus()
270{
271 m_hasFocus = TRUE;
272 SetBitmap();
273}
274
275void wxBitmapButton::NotFocus()
276{
277 m_hasFocus = FALSE;
278 SetBitmap();
279}
280
281void wxBitmapButton::StartSelect()
282{
283 m_isSelected = TRUE;
284 SetBitmap();
285}
286
287void wxBitmapButton::EndSelect()
288{
289 m_isSelected = FALSE;
290 SetBitmap();
291}