]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/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"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 extern bool g_blockEventsOnDrag
;
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 static void gtk_spinbutt_callback( GtkWidget
*WXUNUSED(widget
), wxSpinButton
*win
)
31 if (!win
->HasVMT()) return;
32 if (g_blockEventsOnDrag
) return;
34 float diff
= win
->m_adjust
->value
- win
->m_oldPos
;
35 if (fabs(diff
) < 0.2) return;
37 wxEventType command
= wxEVT_NULL
;
39 float line_step
= win
->m_adjust
->step_increment
;
40 float page_step
= win
->m_adjust
->page_increment
;
42 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
43 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
44 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
45 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
46 else command
= wxEVT_SCROLL_THUMBTRACK
;
48 int value
= (int)(win
->m_adjust
->value
+0.5);
50 wxSpinEvent
event( command
, win
->GetId());
51 event
.SetPosition( value
);
52 event
.SetOrientation( wxVERTICAL
);
53 event
.SetEventObject( win
);
55 win
->ProcessEvent( event
);
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
,wxControl
)
64 BEGIN_EVENT_TABLE(wxSpinButton
, wxControl
)
65 EVT_SIZE(wxSpinButton::OnSize
)
68 wxSpinButton::wxSpinButton()
72 bool wxSpinButton::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
73 long style
, const wxString
& name
)
77 wxSize new_size
= size
;
79 if (new_size
.y
== -1) new_size
.y
= 30;
81 PreCreation( parent
, id
, pos
, new_size
, style
, name
);
83 // SetValidator( validator );
87 m_adjust
= (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 100.0, 1.0, 5.0, 0.0);
89 m_widget
= gtk_spin_button_new( m_adjust
, 0, 0 );
91 gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget
), (m_windowStyle
& wxSP_WRAP
) );
93 gtk_signal_connect (GTK_OBJECT (m_adjust
), "value_changed",
94 (GtkSignalFunc
) gtk_spinbutt_callback
, (gpointer
) this );
96 m_parent
->AddChild( this );
98 (m_parent
->m_insertCallback
)( m_parent
, this );
102 SetBackgroundColour( parent
->GetBackgroundColour() );
109 wxSpinButton::~wxSpinButton()
113 int wxSpinButton::GetMin() const
115 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
117 return (int)(m_adjust
->lower
+0.5);
120 int wxSpinButton::GetMax() const
122 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
124 return (int)(m_adjust
->upper
+0.5);
127 int wxSpinButton::GetValue() const
129 wxCHECK_MSG( (m_widget
!= NULL
), 0, "invalid spin button" );
131 return (int)(m_adjust
->value
+0.5);
134 void wxSpinButton::SetValue( int value
)
136 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
138 float fpos
= (float)value
;
140 if (fabs(fpos
-m_adjust
->value
) < 0.2) return;
141 m_adjust
->value
= fpos
;
143 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "value_changed" );
146 void wxSpinButton::SetRange(int minVal
, int maxVal
)
148 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
150 float fmin
= (float)minVal
;
151 float fmax
= (float)maxVal
;
153 if ((fabs(fmin
-m_adjust
->lower
) < 0.2) &&
154 (fabs(fmax
-m_adjust
->upper
) < 0.2))
157 m_adjust
->lower
= fmin
;
158 m_adjust
->upper
= fmax
;
160 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust
), "changed" );
163 void wxSpinButton::OnSize( wxSizeEvent
&WXUNUSED(event
) )
165 wxCHECK_RET( (m_widget
!= NULL
), "invalid spin button" );
168 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
171 bool wxSpinButton::IsOwnGtkWindow( GdkWindow
*window
)
173 return GTK_SPIN_BUTTON(m_widget
)->panel
== window
;
176 void wxSpinButton::ApplyWidgetStyle()
179 gtk_widget_set_style( m_widget
, m_widgetStyle
);
182 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
186 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxScrollEvent
)
188 wxSpinEvent::wxSpinEvent(wxEventType commandType
, int id
):
189 wxScrollEvent(commandType
, id
)