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