- return (int)(m_adjust->upper+0.5);
-};
-
-void wxScrollBar::SetPosition( int viewStart )
-{
- float fpos = (float)viewStart;
- m_oldPos = fpos;
- if (fabs(fpos-m_adjust->value) < 0.2) return;
- m_adjust->value = fpos;
-
- gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
-};
-
-void wxScrollBar::SetScrollbar( int position, int thumbSize, int range, int pageSize,
- bool WXUNUSED(refresh) )
-{
- float fpos = (float)position;
- m_oldPos = fpos;
- float frange = (float)range;
- float fthumb = (float)thumbSize;
- float fpage = (float)pageSize;
-
- if ((fabs(fpos-m_adjust->value) < 0.2) &&
- (fabs(frange-m_adjust->upper) < 0.2) &&
- (fabs(fthumb-m_adjust->page_size) < 0.2) &&
- (fabs(fpage-m_adjust->page_increment) < 0.2))
- return;
-
- m_adjust->lower = 0.0;
- m_adjust->upper = frange;
- m_adjust->value = fpos;
- m_adjust->step_increment = 1.0;
- m_adjust->page_increment = (float)(wxMax(fpage-2,0));
- m_adjust->page_size = fthumb;
-
- gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
-};
-
-// Backward compatibility
-int wxScrollBar::GetValue(void) const
-{
- return GetPosition();
-};
-
-void wxScrollBar::SetValue( int viewStart )
-{
- SetPosition( viewStart );
-};
-
-void wxScrollBar::GetValues( int *viewStart, int *viewLength, int *objectLength, int *pageLength ) const
-{
- int pos = (int)(m_adjust->value+0.5);
- int thumb = (int)(m_adjust->page_size+0.5);
- int page = (int)(m_adjust->page_increment+0.5);
- int range = (int)(m_adjust->upper+0.5);
-
- *viewStart = pos;
- *viewLength = range;
- *objectLength = thumb;
- *pageLength = page;
-};
-
-int wxScrollBar::GetViewLength() const
-{
- return (int)(m_adjust->upper+0.5);
-};
-
-int wxScrollBar::GetObjectLength() const
-{
- return (int)(m_adjust->page_size+0.5);
-};
+ GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
+ return int(adj->upper);
+}
+
+void wxScrollBar::SetThumbPosition( int viewStart )
+{
+ if (GetThumbPosition() != viewStart)
+ {
+ g_signal_handlers_block_by_func(m_widget,
+ (gpointer)gtk_value_changed, this);
+
+ gtk_range_set_value((GtkRange*)m_widget, viewStart);
+ m_scrollPos[0] = gtk_range_get_value((GtkRange*)m_widget);
+
+ g_signal_handlers_unblock_by_func(m_widget,
+ (gpointer)gtk_value_changed, this);
+ }
+}
+
+void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool)
+{
+ if (range == 0)
+ {
+ // GtkRange requires upper > lower
+ range =
+ thumbSize = 1;
+ }
+ GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
+ adj->step_increment = 1;
+ adj->page_increment = pageSize;
+ adj->page_size = thumbSize;
+ adj->value = position;
+ g_signal_handlers_block_by_func(m_widget, (void*)gtk_value_changed, this);
+ gtk_range_set_range((GtkRange*)m_widget, 0, range);
+ m_scrollPos[0] = adj->value;
+ g_signal_handlers_unblock_by_func(m_widget, (void*)gtk_value_changed, this);
+}