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