- 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)
+ {
+ GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
+ const int i = (GtkRange*)m_widget == m_scrollBar[1];
+ const int max = int(adj->upper - adj->page_size);
+ if (viewStart > max)
+ viewStart = max;
+ if (viewStart < 0)
+ viewStart = 0;
+
+ m_scrollPos[i] =
+ adj->value = viewStart;
+ // If a "value_changed" signal emission is not already in progress
+ if (!m_blockValueChanged[i])
+ {
+ gtk_adjustment_value_changed(adj);
+ }
+ }
+}
+
+void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool)
+{
+ if (range == 0)
+ {
+ // GtkRange requires upper > lower
+ range =
+ thumbSize = 1;
+ }
+ if (position > range - thumbSize)
+ position = range - thumbSize;
+ if (position < 0)
+ position = 0;
+ GtkAdjustment* adj = ((GtkRange*)m_widget)->adjustment;
+ adj->step_increment = 1;
+ adj->page_increment = pageSize;
+ adj->page_size = thumbSize;
+ adj->upper = range;
+ SetThumbPosition(position);
+ gtk_adjustment_changed(adj);
+}