]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
7 // Copyright: (c) Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "spinbutt.h"
15 #include "wx/spinbutt.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern bool g_blockEventsOnDrag
;
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 static void gtk_spinbutt_callback( GtkWidget
*WXUNUSED(widget
), wxSpinButton
*win
)
34 if (!win
->HasVMT()) return;
35 if (g_blockEventsOnDrag
) return;
37 float diff
= win
->m_adjust
->value
- win
->m_oldPos
;
38 if (fabs(diff
) < 0.2) return;
40 wxEventType command
= wxEVT_NULL
;
42 float line_step
= win
->m_adjust
->step_increment
;
43 float page_step
= win
->m_adjust
->page_increment
;
45 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
46 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
47 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
48 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
49 else command
= wxEVT_SCROLL_THUMBTRACK
;
51 int value
= (int)(win
->m_adjust
->value
+0.5);
53 wxSpinEvent
event( command
, win
->GetId());
54 event
.SetPosition( value
);
55 event
.SetOrientation( wxVERTICAL
);
56 event
.SetEventObject( win
);
58 win
->ProcessEvent( event
);
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
,wxControl
)
67 BEGIN_EVENT_TABLE(wxSpinButton
, wxControl
)
68 EVT_SIZE(wxSpinButton::OnSize
)
71 wxSpinButton::wxSpinButton()
75 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
76 long style
, const wxString
& name
)
80 wxSize new_size
= size
;
82 if (new_size
.y
== -1) new_size
.y
= 30;
84 PreCreation( parent
, id
, pos
, new_size
, style
, name
);
86 // SetValidator( validator );
90 m_adjust
= (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 100.0, 1.0, 5.0, 0.0);
92 m_widget
= gtk_spin_button_new( m_adjust
, 0, 0 );
94 gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget
), (m_windowStyle
& wxSP_WRAP
) );
96 gtk_signal_connect( GTK_OBJECT (m_adjust
),
98 (GtkSignalFunc
) gtk_spinbutt_callback
,
101 m_parent
->AddChild( this );
103 (m_parent
->m_insertCallback
)( m_parent
, this );
107 SetBackgroundColour( parent
->GetBackgroundColour() );
114 wxSpinButton::~wxSpinButton()
118 int wxSpinButton::GetMin() const
120 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
122 return (int)(m_adjust
->lower
+0.5);
125 int wxSpinButton::GetMax() const
127 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
129 return (int)(m_adjust
->upper
+0.5);
132 int wxSpinButton::GetValue() const
134 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
136 return (int)(m_adjust
->value
+0.5);
139 void wxSpinButton::SetValue( int value
)
141 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
143 float fpos
= (float)value
;
145 if (fabs(fpos
-m_adjust
->value
) < 0.2) return;
147 m_adjust
->value
= fpos
;
149 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "value_changed" );
152 void wxSpinButton::SetRange(int minVal
, int maxVal
)
154 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
156 float fmin
= (float)minVal
;
157 float fmax
= (float)maxVal
;
159 if ((fabs(fmin
-m_adjust
->lower
) < 0.2) &&
160 (fabs(fmax
-m_adjust
->upper
) < 0.2))
165 m_adjust
->lower
= fmin
;
166 m_adjust
->upper
= fmax
;
168 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
171 void wxSpinButton::OnSize( wxSizeEvent
&WXUNUSED(event
) )
173 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
176 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
179 bool wxSpinButton::IsOwnGtkWindow( GdkWindow
*window
)
181 return GTK_SPIN_BUTTON(m_widget
)->panel
== window
;
184 void wxSpinButton::ApplyWidgetStyle()
187 gtk_widget_set_style( m_widget
, m_widgetStyle
);
190 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
194 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
196 wxSpinEvent::wxSpinEvent(wxEventType commandType
, int id
):
197 wxScrollEvent(commandType
, id
)