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