]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/spinbutt.cpp
83eb28ec50fd93cb6b3011828423fa2f7a8128db
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
7 // Copyright: (c) Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "spinbutt.h"
15 #include "wx/spinbutt.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 extern bool g_blockEventsOnDrag
;
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 static void gtk_spinbutt_callback( GtkWidget
*WXUNUSED(widget
), wxSpinButton
*win
)
30 if (!win
->HasVMT()) return;
31 if (g_blockEventsOnDrag
) return;
33 float diff
= win
->m_adjust
->value
- win
->m_oldPos
;
34 if (fabs(diff
) < 0.2) return;
36 wxEventType command
= wxEVT_NULL
;
38 float line_step
= win
->m_adjust
->step_increment
;
39 float page_step
= win
->m_adjust
->page_increment
;
41 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
42 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
43 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
44 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
45 else command
= wxEVT_SCROLL_THUMBTRACK
;
47 int value
= (int)(win
->m_adjust
->value
+0.5);
49 wxSpinEvent
event( command
, win
->GetId());
50 event
.SetPosition( value
);
51 event
.SetOrientation( wxVERTICAL
);
52 event
.SetEventObject( win
);
54 win
->ProcessEvent( event
);
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
,wxControl
)
63 BEGIN_EVENT_TABLE(wxSpinButton
, wxControl
)
64 EVT_SIZE(wxSpinButton::OnSize
)
67 wxSpinButton::wxSpinButton()
71 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
72 long style
, const wxString
& name
)
76 wxSize new_size
= size
;
78 if (new_size
.y
== -1) new_size
.y
= 30;
80 PreCreation( parent
, id
, pos
, new_size
, style
, name
);
82 // SetValidator( validator );
86 m_adjust
= (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 100.0, 1.0, 5.0, 0.0);
88 m_widget
= gtk_spin_button_new( m_adjust
, 0, 0 );
90 gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget
), (m_windowStyle
& wxSP_WRAP
) );
92 gtk_signal_connect (GTK_OBJECT (m_adjust
), "value_changed",
93 (GtkSignalFunc
) gtk_spinbutt_callback
, (gpointer
) this );
95 m_parent
->AddChild( this );
97 (m_parent
->m_insertCallback
)( m_parent
, this );
101 SetBackgroundColour( parent
->GetBackgroundColour() );
108 wxSpinButton::~wxSpinButton()
112 int wxSpinButton::GetMin() const
114 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
116 return (int)(m_adjust
->lower
+0.5);
119 int wxSpinButton::GetMax() const
121 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
123 return (int)(m_adjust
->upper
+0.5);
126 int wxSpinButton::GetValue() const
128 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
130 return (int)(m_adjust
->value
+0.5);
133 void wxSpinButton::SetValue( int value
)
135 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
137 float fpos
= (float)value
;
139 if (fabs(fpos
-m_adjust
->value
) < 0.2) return;
140 m_adjust
->value
= fpos
;
142 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "value_changed" );
145 void wxSpinButton::SetRange(int minVal
, int maxVal
)
147 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
149 float fmin
= (float)minVal
;
150 float fmax
= (float)maxVal
;
152 if ((fabs(fmin
-m_adjust
->lower
) < 0.2) &&
153 (fabs(fmax
-m_adjust
->upper
) < 0.2))
156 m_adjust
->lower
= fmin
;
157 m_adjust
->upper
= fmax
;
159 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
162 void wxSpinButton::OnSize( wxSizeEvent
&WXUNUSED(event
) )
164 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
167 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
170 bool wxSpinButton::IsOwnGtkWindow( GdkWindow
*window
)
172 return GTK_SPIN_BUTTON(m_widget
)->panel
== window
;
175 void wxSpinButton::ApplyWidgetStyle()
178 gtk_widget_set_style( m_widget
, m_widgetStyle
);
181 //-----------------------------------------------------------------------------
183 //-----------------------------------------------------------------------------
185 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
187 wxSpinEvent::wxSpinEvent(wxEventType commandType
, int id
):
188 wxScrollEvent(commandType
, id
)