]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/bmpbuttn.cpp
Replace wxTINY_CAPTION_{HORIZ,VERT} with a single wxTINY_CAPTION.
[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
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
b5a5362e 144 m_bitmaps[State_Normal] = 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
b5a5362e 151 if (bitmap.IsOk())
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
151ccd11
RR
175void wxBitmapButton::SetLabel( const wxString &label )
176{
223d09f6 177 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
f96aa4d9 178
43a18898 179 wxControl::SetLabel( label );
6de97a3b 180}
151ccd11 181
f40fdaa3 182void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style)
903f689b 183{
9e691f46
VZ
184 if ( !BUTTON_CHILD(m_widget) )
185 return;
29149a64 186
f40fdaa3 187 wxButton::DoApplyWidgetStyle(style);
43a18898
RR
188}
189
29149a64 190void wxBitmapButton::OnSetBitmap()
43a18898 191{
1e6feb95 192 wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
f96aa4d9 193
9f884528 194 InvalidateBestSize();
902725ee 195
43a18898 196 wxBitmap the_one;
47a8a4d5 197 if (!IsThisEnabled())
b5a5362e
JJ
198 the_one = GetBitmapDisabled();
199 else if (m_isSelected)
200 the_one = GetBitmapPressed();
201 else if (HasFocus())
202 the_one = GetBitmapFocus();
203
204 if (!the_one.IsOk())
205 {
03647350
VZ
206 the_one = GetBitmapLabel();
207 if (!the_one.IsOk())
208 return;
b5a5362e 209 }
f6bcfd97 210
d3b9f782 211 GdkBitmap *mask = NULL;
43a18898 212 if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();
f6bcfd97 213
9e691f46
VZ
214 GtkWidget *child = BUTTON_CHILD(m_widget);
215 if (child == NULL)
29149a64
VZ
216 {
217 // initial bitmap
4fab7128 218 GtkWidget *pixmap;
4fab7128 219 pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask);
67a6726a
RR
220 gtk_widget_show(pixmap);
221 gtk_container_add(GTK_CONTAINER(m_widget), pixmap);
29149a64
VZ
222 }
223 else
67a6726a 224 { // subsequent bitmaps
4fab7128
VS
225 GtkPixmap *pixmap = GTK_PIXMAP(child);
226 gtk_pixmap_set(pixmap, the_one.GetPixmap(), mask);
67a6726a 227 }
903f689b
RR
228}
229
e0aeebed
VS
230wxSize wxBitmapButton::DoGetBestSize() const
231{
232 return wxControl::DoGetBestSize();
233}
234
f03fc89f 235bool wxBitmapButton::Enable( bool enable )
43a18898 236{
f03fc89f 237 if ( !wxWindow::Enable(enable) )
902725ee 238 return false;
43a18898 239
29149a64 240 OnSetBitmap();
f03fc89f 241
902725ee 242 return true;
43a18898
RR
243}
244
d1b8a743 245void wxBitmapButton::GTKSetHasFocus()
43a18898 246{
902725ee 247 m_hasFocus = true;
29149a64 248 OnSetBitmap();
43a18898
RR
249}
250
d1b8a743 251void wxBitmapButton::GTKSetNotFocus()
43a18898 252{
902725ee 253 m_hasFocus = false;
29149a64 254 OnSetBitmap();
43a18898
RR
255}
256
257void wxBitmapButton::StartSelect()
258{
902725ee 259 m_isSelected = true;
29149a64 260 OnSetBitmap();
43a18898
RR
261}
262
263void wxBitmapButton::EndSelect()
264{
902725ee 265 m_isSelected = false;
29149a64 266 OnSetBitmap();
43a18898 267}
f6bcfd97
BP
268
269#endif // wxUSE_BMPBUTTON