]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/bmpbuttn.cpp
prevent GTK+ from changing locale when wxUSE_INTL==0, this makes the behaviour consis...
[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);
53 button->GetEventHandler()->ProcessEvent(event);
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
f6bcfd97 67 button->HasFocus();
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
f6bcfd97 81 button->NotFocus();
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
42b4e99e 117IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxButton)
151ccd11 118
c3dfaa10 119void wxBitmapButton::Init()
151ccd11 120{
c3dfaa10 121 m_hasFocus =
902725ee 122 m_isSelected = false;
6de97a3b 123}
151ccd11 124
c3dfaa10
VZ
125bool wxBitmapButton::Create( wxWindow *parent,
126 wxWindowID id,
127 const wxBitmap& bitmap,
128 const wxPoint& pos,
129 const wxSize& size,
130 long style,
131 const wxValidator& validator,
132 const wxString &name )
151ccd11 133{
902725ee
WS
134 m_needParent = true;
135 m_acceptsFocus = true;
f6bcfd97 136
4dcaf11a
RR
137 if (!PreCreation( parent, pos, size ) ||
138 !CreateBase( parent, id, pos, size, style, validator, name ))
139 {
223d09f6 140 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
902725ee 141 return false;
4dcaf11a 142 }
6de97a3b 143
189f58fa 144 m_bmpNormal = bitmap;
f6bcfd97 145
43a18898 146 m_widget = gtk_button_new();
de1c750f 147
de1c750f
RR
148 if (style & wxNO_BORDER)
149 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
de1c750f 150
1e6feb95 151 if (m_bmpNormal.Ok())
43a18898 152 {
29149a64 153 OnSetBitmap();
43a18898 154 }
f6bcfd97 155
58b907f6 156 gtk_signal_connect_after( GTK_OBJECT(m_widget), "clicked",
43a18898 157 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this );
151ccd11 158
f6bcfd97 159 gtk_signal_connect( GTK_OBJECT(m_widget), "enter",
43a18898 160 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback), (gpointer*)this );
f6bcfd97 161 gtk_signal_connect( GTK_OBJECT(m_widget), "leave",
43a18898 162 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback), (gpointer*)this );
f6bcfd97 163 gtk_signal_connect( GTK_OBJECT(m_widget), "pressed",
43a18898 164 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback), (gpointer*)this );
f6bcfd97 165 gtk_signal_connect( GTK_OBJECT(m_widget), "released",
43a18898 166 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback), (gpointer*)this );
f6bcfd97 167
eb082a08 168 m_parent->DoAddChild( this );
f6bcfd97 169
abdeb9e7 170 PostCreation(size);
f6bcfd97 171
902725ee 172 return true;
6de97a3b 173}
f6bcfd97 174
43a18898 175void wxBitmapButton::SetDefault()
151ccd11 176{
43a18898
RR
177 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
178 gtk_widget_grab_default( m_widget );
f6bcfd97 179
3502e687 180 SetSize( m_x, m_y, m_width, m_height );
6de97a3b 181}
151ccd11
RR
182
183void wxBitmapButton::SetLabel( const wxString &label )
184{
223d09f6 185 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
f96aa4d9 186
43a18898 187 wxControl::SetLabel( label );
6de97a3b 188}
151ccd11 189
f40fdaa3 190void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style)
903f689b 191{
9e691f46
VZ
192 if ( !BUTTON_CHILD(m_widget) )
193 return;
29149a64 194
f40fdaa3 195 wxButton::DoApplyWidgetStyle(style);
43a18898
RR
196}
197
29149a64 198void wxBitmapButton::OnSetBitmap()
43a18898 199{
1e6feb95 200 wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
f96aa4d9 201
9f884528 202 InvalidateBestSize();
902725ee 203
43a18898 204 wxBitmap the_one;
f6bcfd97 205 if (!m_isEnabled)
29149a64 206 the_one = m_bmpDisabled;
67a6726a 207 else if (m_isSelected)
29149a64 208 the_one = m_bmpSelected;
67a6726a 209 else if (m_hasFocus)
29149a64 210 the_one = m_bmpFocus;
f6bcfd97 211 else
902725ee 212 the_one = m_bmpNormal;
43a18898 213
1e6feb95 214 if (!the_one.Ok()) the_one = m_bmpNormal;
de1c750f 215 if (!the_one.Ok()) return;
f6bcfd97 216
43a18898
RR
217 GdkBitmap *mask = (GdkBitmap *) NULL;
218 if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
f6bcfd97 219
9e691f46
VZ
220 GtkWidget *child = BUTTON_CHILD(m_widget);
221 if (child == NULL)
29149a64
VZ
222 {
223 // initial bitmap
4fab7128 224 GtkWidget *pixmap;
4fab7128 225 pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask);
67a6726a
RR
226 gtk_widget_show(pixmap);
227 gtk_container_add(GTK_CONTAINER(m_widget), pixmap);
29149a64
VZ
228 }
229 else
67a6726a 230 { // subsequent bitmaps
4fab7128
VS
231 GtkPixmap *pixmap = GTK_PIXMAP(child);
232 gtk_pixmap_set(pixmap, the_one.GetPixmap(), mask);
67a6726a 233 }
903f689b
RR
234}
235
e0aeebed
VS
236wxSize wxBitmapButton::DoGetBestSize() const
237{
238 return wxControl::DoGetBestSize();
239}
240
f03fc89f 241bool wxBitmapButton::Enable( bool enable )
43a18898 242{
f03fc89f 243 if ( !wxWindow::Enable(enable) )
902725ee 244 return false;
43a18898 245
29149a64 246 OnSetBitmap();
f03fc89f 247
902725ee 248 return true;
43a18898
RR
249}
250
251void wxBitmapButton::HasFocus()
252{
902725ee 253 m_hasFocus = true;
29149a64 254 OnSetBitmap();
43a18898
RR
255}
256
257void wxBitmapButton::NotFocus()
258{
902725ee 259 m_hasFocus = false;
29149a64 260 OnSetBitmap();
43a18898
RR
261}
262
263void wxBitmapButton::StartSelect()
264{
902725ee 265 m_isSelected = true;
29149a64 266 OnSetBitmap();
43a18898
RR
267}
268
269void wxBitmapButton::EndSelect()
270{
902725ee 271 m_isSelected = false;
29149a64 272 OnSetBitmap();
43a18898 273}
f6bcfd97
BP
274
275#endif // wxUSE_BMPBUTTON