]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/spinbutt.cpp
31a244d6c3a8b62cd20faa427f75b1e2e67d1472
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
7 // Copyright: (c) Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "spinbutt.h"
15 #include "wx/spinbutt.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern void wxapp_install_idle_handler();
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern bool g_blockEventsOnDrag
;
38 static const float sensitivity
= 0.2;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 static void gtk_spinbutt_callback( GtkWidget
*WXUNUSED(widget
), wxSpinButton
*win
)
46 if (g_isIdle
) wxapp_install_idle_handler();
48 if (!win
->m_hasVMT
) return;
49 if (g_blockEventsOnDrag
) return;
51 float diff
= win
->m_adjust
->value
- win
->m_oldPos
;
52 if (fabs(diff
) < sensitivity
) return;
53 win
->m_oldPos
= win
->m_adjust
->value
;
55 wxEventType command
= wxEVT_NULL
;
57 float line_step
= win
->m_adjust
->step_increment
;
58 float page_step
= win
->m_adjust
->page_increment
;
60 if (fabs(diff
-line_step
) < sensitivity
) command
= wxEVT_SCROLL_LINEDOWN
;
61 else if (fabs(diff
+line_step
) < sensitivity
) command
= wxEVT_SCROLL_LINEUP
;
62 else if (fabs(diff
-page_step
) < sensitivity
) command
= wxEVT_SCROLL_PAGEDOWN
;
63 else if (fabs(diff
+page_step
) < sensitivity
) command
= wxEVT_SCROLL_PAGEUP
;
64 else command
= wxEVT_SCROLL_THUMBTRACK
;
66 int value
= (int)ceil(win
->m_adjust
->value
);
68 wxSpinEvent
event( command
, win
->GetId());
69 event
.SetPosition( value
);
70 event
.SetOrientation( wxVERTICAL
);
71 event
.SetEventObject( win
);
73 win
->GetEventHandler()->ProcessEvent( event
);
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
,wxControl
)
81 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
);
83 BEGIN_EVENT_TABLE(wxSpinButton
, wxControl
)
84 EVT_SIZE(wxSpinButton::OnSize
)
87 bool wxSpinButton::Create(wxWindow
*parent
,
96 wxSize new_size
= size
;
101 if (!PreCreation( parent
, pos
, size
) ||
102 !CreateBase( parent
, id
, pos
, new_size
, style
, wxDefaultValidator
, name
))
104 wxFAIL_MSG( _T("wxXX creation failed") );
110 m_adjust
= (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 100.0, 1.0, 5.0, 0.0);
112 m_widget
= gtk_spin_button_new( m_adjust
, 0, 0 );
114 gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget
), (m_windowStyle
& wxSP_WRAP
) );
116 gtk_signal_connect( GTK_OBJECT (m_adjust
),
118 (GtkSignalFunc
) gtk_spinbutt_callback
,
121 m_parent
->DoAddChild( this );
125 SetBackgroundColour( parent
->GetBackgroundColour() );
132 wxSpinButton::~wxSpinButton()
136 int wxSpinButton::GetMin() const
138 wxCHECK_MSG( (m_widget
!= NULL
), 0, _T("invalid spin button") );
140 return (int)ceil(m_adjust
->lower
);
143 int wxSpinButton::GetMax() const
145 wxCHECK_MSG( (m_widget
!= NULL
), 0, _T("invalid spin button") );
147 return (int)ceil(m_adjust
->upper
);
150 int wxSpinButton::GetValue() const
152 wxCHECK_MSG( (m_widget
!= NULL
), 0, _T("invalid spin button") );
154 return (int)ceil(m_adjust
->value
);
157 void wxSpinButton::SetValue( int value
)
159 wxCHECK_RET( (m_widget
!= NULL
), _T("invalid spin button") );
161 float fpos
= (float)value
;
163 if (fabs(fpos
-m_adjust
->value
) < sensitivity
) return;
165 m_adjust
->value
= fpos
;
167 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "value_changed" );
170 void wxSpinButton::SetRange(int minVal
, int maxVal
)
172 wxCHECK_RET( (m_widget
!= NULL
), _T("invalid spin button") );
174 float fmin
= (float)minVal
;
175 float fmax
= (float)maxVal
;
177 if ((fabs(fmin
-m_adjust
->lower
) < sensitivity
) &&
178 (fabs(fmax
-m_adjust
->upper
) < sensitivity
))
183 m_adjust
->lower
= fmin
;
184 m_adjust
->upper
= fmax
;
186 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
189 void wxSpinButton::OnSize( wxSizeEvent
&WXUNUSED(event
) )
191 wxCHECK_RET( (m_widget
!= NULL
), _T("invalid spin button") );
194 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
197 bool wxSpinButton::IsOwnGtkWindow( GdkWindow
*window
)
199 return GTK_SPIN_BUTTON(m_widget
)->panel
== window
;
202 void wxSpinButton::ApplyWidgetStyle()
205 gtk_widget_set_style( m_widget
, m_widgetStyle
);