]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/bmpbuttn.cpp
removed spurious semicolons
[wxWidgets.git] / src / gtk / bmpbuttn.cpp
CommitLineData
151ccd11 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/gtk/bmpbuttn.cpp
151ccd11
RR
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
151ccd11
RR
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
dcf924a3
RR
13#if wxUSE_BMPBUTTON
14
1e6feb95
VZ
15#include "wx/bmpbuttn.h"
16
9e691f46 17#include "wx/gtk/private.h"
83624f79 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
865bb325 35extern "C" {
66bd6b93 36static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
151ccd11 37{
f6bcfd97 38 if (g_isIdle)
bf9e3e73 39 wxapp_install_idle_handler();
acfd422a 40
a2053b27 41 if (!button->m_hasVMT) return;
43a18898 42 if (g_blockEventsOnDrag) return;
f6bcfd97 43
43a18898
RR
44 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
45 event.SetEventObject(button);
46 button->GetEventHandler()->ProcessEvent(event);
47}
865bb325 48}
43a18898
RR
49
50//-----------------------------------------------------------------------------
51// "enter"
52//-----------------------------------------------------------------------------
53
865bb325 54extern "C" {
43a18898
RR
55static void gtk_bmpbutton_enter_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
56{
a2053b27 57 if (!button->m_hasVMT) return;
43a18898
RR
58 if (g_blockEventsOnDrag) return;
59
f6bcfd97 60 button->HasFocus();
43a18898 61}
865bb325 62}
43a18898
RR
63
64//-----------------------------------------------------------------------------
65// "leave"
66//-----------------------------------------------------------------------------
67
865bb325 68extern "C" {
43a18898
RR
69static void gtk_bmpbutton_leave_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
70{
a2053b27 71 if (!button->m_hasVMT) return;
43a18898
RR
72 if (g_blockEventsOnDrag) return;
73
f6bcfd97 74 button->NotFocus();
43a18898 75}
865bb325 76}
43a18898
RR
77
78//-----------------------------------------------------------------------------
79// "pressed"
80//-----------------------------------------------------------------------------
81
865bb325 82extern "C" {
43a18898
RR
83static void gtk_bmpbutton_press_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
84{
a2053b27 85 if (!button->m_hasVMT) return;
43a18898
RR
86 if (g_blockEventsOnDrag) return;
87
f6bcfd97 88 button->StartSelect();
43a18898 89}
865bb325 90}
43a18898
RR
91
92//-----------------------------------------------------------------------------
93// "released"
94//-----------------------------------------------------------------------------
95
865bb325 96extern "C" {
43a18898
RR
97static void gtk_bmpbutton_release_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
98{
a2053b27 99 if (!button->m_hasVMT) return;
43a18898
RR
100 if (g_blockEventsOnDrag) return;
101
f6bcfd97 102 button->EndSelect();
6de97a3b 103}
865bb325 104}
151ccd11
RR
105
106//-----------------------------------------------------------------------------
e1e955e1
RR
107// wxBitmapButton
108//-----------------------------------------------------------------------------
109
42b4e99e 110IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxButton)
151ccd11 111
c3dfaa10 112void wxBitmapButton::Init()
151ccd11 113{
c3dfaa10 114 m_hasFocus =
902725ee 115 m_isSelected = false;
6de97a3b 116}
151ccd11 117
c3dfaa10
VZ
118bool wxBitmapButton::Create( wxWindow *parent,
119 wxWindowID id,
120 const wxBitmap& bitmap,
121 const wxPoint& pos,
122 const wxSize& size,
123 long style,
124 const wxValidator& validator,
125 const wxString &name )
151ccd11 126{
902725ee 127 m_needParent = true;
f6bcfd97 128
4dcaf11a
RR
129 if (!PreCreation( parent, pos, size ) ||
130 !CreateBase( parent, id, pos, size, style, validator, name ))
131 {
223d09f6 132 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
902725ee 133 return false;
4dcaf11a 134 }
6de97a3b 135
189f58fa 136 m_bmpNormal = bitmap;
f6bcfd97 137
43a18898 138 m_widget = gtk_button_new();
de1c750f 139
de1c750f
RR
140 if (style & wxNO_BORDER)
141 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
de1c750f 142
1e6feb95 143 if (m_bmpNormal.Ok())
43a18898 144 {
29149a64 145 OnSetBitmap();
43a18898 146 }
f6bcfd97 147
9fa72bd2
MR
148 g_signal_connect_after (m_widget, "clicked",
149 G_CALLBACK (gtk_bmpbutton_clicked_callback),
150 this);
151
152 g_signal_connect (m_widget, "enter",
153 G_CALLBACK (gtk_bmpbutton_enter_callback), this);
154 g_signal_connect (m_widget, "leave",
155 G_CALLBACK (gtk_bmpbutton_leave_callback), this);
156 g_signal_connect (m_widget, "pressed",
157 G_CALLBACK (gtk_bmpbutton_press_callback), this);
158 g_signal_connect (m_widget, "released",
159 G_CALLBACK (gtk_bmpbutton_release_callback), this);
f6bcfd97 160
eb082a08 161 m_parent->DoAddChild( this );
f6bcfd97 162
abdeb9e7 163 PostCreation(size);
f6bcfd97 164
902725ee 165 return true;
6de97a3b 166}
f6bcfd97 167
151ccd11
RR
168void wxBitmapButton::SetLabel( const wxString &label )
169{
223d09f6 170 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
f96aa4d9 171
43a18898 172 wxControl::SetLabel( label );
6de97a3b 173}
151ccd11 174
f40fdaa3 175void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style)
903f689b 176{
afa7bd1e 177 if (!GTK_BIN(m_widget)->child)
9e691f46 178 return;
29149a64 179
f40fdaa3 180 wxButton::DoApplyWidgetStyle(style);
43a18898
RR
181}
182
29149a64 183void wxBitmapButton::OnSetBitmap()
43a18898 184{
1e6feb95 185 wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
f96aa4d9 186
9f884528 187 InvalidateBestSize();
902725ee 188
43a18898 189 wxBitmap the_one;
47a8a4d5 190 if (!IsThisEnabled())
29149a64 191 the_one = m_bmpDisabled;
67a6726a 192 else if (m_isSelected)
29149a64 193 the_one = m_bmpSelected;
67a6726a 194 else if (m_hasFocus)
29149a64 195 the_one = m_bmpFocus;
f6bcfd97 196 else
902725ee 197 the_one = m_bmpNormal;
43a18898 198
1e6feb95 199 if (!the_one.Ok()) the_one = m_bmpNormal;
de1c750f 200 if (!the_one.Ok()) return;
f6bcfd97 201
43a18898
RR
202 GdkBitmap *mask = (GdkBitmap *) NULL;
203 if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
f6bcfd97 204
afa7bd1e 205 GtkWidget *child = GTK_BIN(m_widget)->child;
9e691f46 206 if (child == NULL)
29149a64
VZ
207 {
208 // initial bitmap
4fab7128 209 GtkWidget *pixmap;
68567a96 210
4fab7128
VS
211 if (the_one.HasPixbuf())
212 pixmap = gtk_image_new_from_pixbuf(the_one.GetPixbuf());
213 else
214 pixmap = gtk_image_new_from_pixmap(the_one.GetPixmap(), mask);
68567a96 215
67a6726a
RR
216 gtk_widget_show(pixmap);
217 gtk_container_add(GTK_CONTAINER(m_widget), pixmap);
29149a64
VZ
218 }
219 else
67a6726a 220 { // subsequent bitmaps
4fab7128
VS
221 GtkImage *pixmap = GTK_IMAGE(child);
222 if (the_one.HasPixbuf())
223 gtk_image_set_from_pixbuf(pixmap, the_one.GetPixbuf());
224 else
225 gtk_image_set_from_pixmap(pixmap, the_one.GetPixmap(), mask);
67a6726a 226 }
903f689b
RR
227}
228
e0aeebed
VS
229wxSize wxBitmapButton::DoGetBestSize() const
230{
231 return wxControl::DoGetBestSize();
232}
233
f03fc89f 234bool wxBitmapButton::Enable( bool enable )
43a18898 235{
f03fc89f 236 if ( !wxWindow::Enable(enable) )
902725ee 237 return false;
43a18898 238
29149a64 239 OnSetBitmap();
f03fc89f 240
902725ee 241 return true;
43a18898
RR
242}
243
244void wxBitmapButton::HasFocus()
245{
902725ee 246 m_hasFocus = true;
29149a64 247 OnSetBitmap();
43a18898
RR
248}
249
250void wxBitmapButton::NotFocus()
251{
902725ee 252 m_hasFocus = false;
29149a64 253 OnSetBitmap();
43a18898
RR
254}
255
256void wxBitmapButton::StartSelect()
257{
902725ee 258 m_isSelected = true;
29149a64 259 OnSetBitmap();
43a18898
RR
260}
261
262void wxBitmapButton::EndSelect()
263{
902725ee 264 m_isSelected = false;
29149a64 265 OnSetBitmap();
43a18898 266}
f6bcfd97
BP
267
268#endif // wxUSE_BMPBUTTON