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