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