]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/spinbutt.cpp
3 // Purpose: wxSpinButton
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/spinbutt.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 extern bool g_blockEventsOnDrag
;
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
35 gtk_value_changed(GtkSpinButton
* spinbutton
, wxSpinButton
* win
)
37 const double value
= gtk_spin_button_get_value(spinbutton
);
38 const int pos
= int(value
);
39 const int oldPos
= win
->m_pos
;
40 if (g_blockEventsOnDrag
|| pos
== oldPos
)
46 wxSpinEvent
event(pos
> oldPos
? wxEVT_SCROLL_LINEUP
: wxEVT_SCROLL_LINEDOWN
, win
->GetId());
47 event
.SetPosition(pos
);
48 event
.SetEventObject(win
);
50 if ((win
->HandleWindowEvent( event
)) &&
53 /* program has vetoed */
54 // this will cause another "value_changed" signal,
55 // but because pos == oldPos nothing will happen
56 gtk_spin_button_set_value(spinbutton
, oldPos
);
62 /* always send a thumbtrack event */
63 wxSpinEvent
event2(wxEVT_SCROLL_THUMBTRACK
, win
->GetId());
64 event2
.SetPosition(pos
);
65 event2
.SetEventObject(win
);
66 win
->HandleWindowEvent(event2
);
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
74 BEGIN_EVENT_TABLE(wxSpinButton
, wxControl
)
75 EVT_SIZE(wxSpinButton::OnSize
)
78 wxSpinButton::wxSpinButton()
83 bool wxSpinButton::Create(wxWindow
*parent
,
90 wxSize new_size
= size
,
91 sizeBest
= DoGetBestSize();
92 new_size
.x
= sizeBest
.x
; // override width always
94 new_size
.y
= sizeBest
.y
;
96 if (!PreCreation( parent
, pos
, new_size
) ||
97 !CreateBase( parent
, id
, pos
, new_size
, style
, wxDefaultValidator
, name
))
99 wxFAIL_MSG( wxT("wxSpinButton creation failed") );
105 m_widget
= gtk_spin_button_new_with_range(0, 100, 1);
106 g_object_ref(m_widget
);
108 gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget
),
109 (int)(m_windowStyle
& wxSP_WRAP
) );
111 g_signal_connect_after(
112 m_widget
, "value_changed", G_CALLBACK(gtk_value_changed
), this);
114 m_parent
->DoAddChild( this );
116 PostCreation(new_size
);
121 int wxSpinButton::GetMin() const
123 wxCHECK_MSG( (m_widget
!= NULL
), 0, wxT("invalid spin button") );
126 gtk_spin_button_get_range((GtkSpinButton
*)m_widget
, &min
, NULL
);
130 int wxSpinButton::GetMax() const
132 wxCHECK_MSG( (m_widget
!= NULL
), 0, wxT("invalid spin button") );
135 gtk_spin_button_get_range((GtkSpinButton
*)m_widget
, NULL
, &max
);
139 int wxSpinButton::GetValue() const
141 wxCHECK_MSG( (m_widget
!= NULL
), 0, wxT("invalid spin button") );
146 void wxSpinButton::SetValue( int value
)
148 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid spin button") );
151 gtk_spin_button_set_value((GtkSpinButton
*)m_widget
, value
);
152 m_pos
= int(gtk_spin_button_get_value((GtkSpinButton
*)m_widget
));
156 void wxSpinButton::SetRange(int minVal
, int maxVal
)
158 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid spin button") );
161 gtk_spin_button_set_range((GtkSpinButton
*)m_widget
, minVal
, maxVal
);
162 m_pos
= int(gtk_spin_button_get_value((GtkSpinButton
*)m_widget
));
166 void wxSpinButton::OnSize( wxSizeEvent
&WXUNUSED(event
) )
168 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid spin button") );
170 m_width
= DoGetBestSize().x
;
171 gtk_widget_set_size_request( m_widget
, m_width
, m_height
);
174 bool wxSpinButton::Enable( bool enable
)
176 if (!base_type::Enable(enable
))
179 // Work around lack of visual update when enabling
181 GTKFixSensitivity(false /* fix even if not under mouse */);
186 void wxSpinButton::GtkDisableEvents() const
188 g_signal_handlers_block_by_func(m_widget
,
189 (gpointer
)gtk_value_changed
, (void*) this);
192 void wxSpinButton::GtkEnableEvents() const
194 g_signal_handlers_unblock_by_func(m_widget
,
195 (gpointer
)gtk_value_changed
, (void*) this);
198 GdkWindow
*wxSpinButton::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
201 // no access to internal GdkWindows
204 return GTK_SPIN_BUTTON(m_widget
)->panel
;
208 wxSize
wxSpinButton::DoGetBestSize() const
210 wxSize
best(15, 26); // FIXME
217 wxSpinButton::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
219 return GetDefaultAttributesFromGTKWidget(gtk_spin_button_new_with_range(0, 100, 1));