Use adjustment accessor functions in KatzeScrolled

This commit is contained in:
Christian Dywan 2010-01-30 16:59:37 +01:00
parent c43d887747
commit a1c598851b

View file

@ -18,6 +18,15 @@
#include "katze-scrolled.h" #include "katze-scrolled.h"
#include "katze-utils.h" #include "katze-utils.h"
#if !GTK_CHECK_VERSION (2, 14, 0)
#define gtk_adjustment_get_page_size(adj) adj->page_size
#define gtk_adjustment_get_upper(adj) adj->upper
#define gtk_adjustment_get_lower(adj) adj->lower
#define gtk_adjustment_get_value(adj) adj->value
#define gtk_adjustment_get_page_size(adj) adj->page_size
#define gtk_adjustment_get_page_size(adj) adj->page_size
#endif
#define DEFAULT_INTERVAL 50 #define DEFAULT_INTERVAL 50
#define DEFAULT_DECELERATION 0.7 #define DEFAULT_DECELERATION 0.7
#define DEFAULT_DRAGGING_STOPPED_DELAY 100 #define DEFAULT_DRAGGING_STOPPED_DELAY 100
@ -305,18 +314,24 @@ adjust_scrollbar (KatzeScrolled* scrolled,
{ {
KatzeScrolledPrivate* priv = scrolled->priv; KatzeScrolledPrivate* priv = scrolled->priv;
GtkWidget* widget = GTK_WIDGET (scrolled); GtkWidget* widget = GTK_WIDGET (scrolled);
gdouble page_size, upper, lower, value;
gint x, y; gint x, y;
gint size; gint size;
double position; double position;
GtkWidget* window; GtkWidget* window;
if (adjustment->page_size >= adjustment->upper - adjustment->lower) page_size = gtk_adjustment_get_page_size (adjustment);
upper = gtk_adjustment_get_upper (adjustment);
lower = gtk_adjustment_get_lower (adjustment);
value = gtk_adjustment_get_value (adjustment);
if (page_size >= upper - lower)
{ {
*previous_size = 0; *previous_size = 0;
return FALSE; return FALSE;
} }
size = ((double)adjustment->page_size) / (adjustment->upper - adjustment->lower) * (horizontal size = ((double)page_size) / (upper - lower) * (horizontal
? widget->allocation.height : widget->allocation.width); ? widget->allocation.height : widget->allocation.width);
if (size != *previous_size) if (size != *previous_size)
{ {
@ -341,7 +356,7 @@ adjust_scrollbar (KatzeScrolled* scrolled,
} }
} }
position = (adjustment->value - adjustment->lower) / (adjustment->upper - adjustment->lower); position = (value - lower) / (upper - lower);
window = gtk_widget_get_toplevel (widget); window = gtk_widget_get_toplevel (widget);
if (horizontal) if (horizontal)
{ {
@ -418,35 +433,45 @@ do_timeout_scroll (KatzeScrolled* scrolled)
GtkScrolledWindow* gtk_scrolled = GTK_SCROLLED_WINDOW (scrolled); GtkScrolledWindow* gtk_scrolled = GTK_SCROLLED_WINDOW (scrolled);
GtkAdjustment* hadjustment; GtkAdjustment* hadjustment;
GtkAdjustment* vadjustment; GtkAdjustment* vadjustment;
gdouble hvalue; gdouble hpage_size, hupper, hlower, hvalue, new_hvalue;
gdouble vvalue; gdouble vpage_size, vupper, vlower, vvalue, new_vvalue;
hadjustment = gtk_scrolled_window_get_hadjustment (gtk_scrolled); hadjustment = gtk_scrolled_window_get_hadjustment (gtk_scrolled);
vadjustment = gtk_scrolled_window_get_vadjustment (gtk_scrolled); hpage_size = gtk_adjustment_get_page_size (hadjustment);
hvalue = calculate_timeout_scroll_values (hadjustment->value, hupper = gtk_adjustment_get_upper (hadjustment);
hadjustment->upper - hadjustment->page_size, hlower = gtk_adjustment_get_lower (hadjustment);
hvalue = gtk_adjustment_get_value (hadjustment);
new_hvalue = calculate_timeout_scroll_values (hvalue,
hupper - hpage_size,
&priv->horizontal_speed, &priv->horizontal_speed,
priv->horizontal_deceleration, priv->horizontal_deceleration,
&priv->vertical_deceleration, &priv->vertical_deceleration,
priv->deceleration); priv->deceleration);
vvalue = calculate_timeout_scroll_values (vadjustment->value,
vadjustment->upper - vadjustment->page_size, vadjustment = gtk_scrolled_window_get_vadjustment (gtk_scrolled);
vpage_size = gtk_adjustment_get_page_size (vadjustment);
vupper = gtk_adjustment_get_upper (vadjustment);
vlower = gtk_adjustment_get_lower (vadjustment);
vvalue = gtk_adjustment_get_value (vadjustment);
new_vvalue = calculate_timeout_scroll_values (vvalue,
vupper - vpage_size,
&priv->vertical_speed, &priv->vertical_speed,
priv->vertical_deceleration, priv->vertical_deceleration,
&priv->horizontal_deceleration, &priv->horizontal_deceleration,
priv->deceleration); priv->deceleration);
if (vvalue != vadjustment->value)
if (new_vvalue != vvalue)
{ {
if (hvalue != hadjustment->value) if (new_hvalue != hvalue)
{ {
disable_hadjustment (scrolled); disable_hadjustment (scrolled);
gtk_adjustment_set_value (hadjustment, hvalue); gtk_adjustment_set_value (hadjustment, new_hvalue);
enable_hadjustment (scrolled); enable_hadjustment (scrolled);
} }
gtk_adjustment_set_value (vadjustment, vvalue); gtk_adjustment_set_value (vadjustment, new_vvalue);
} }
else if (hvalue != hadjustment->value) else if (new_hvalue != hvalue)
gtk_adjustment_set_value (hadjustment, hvalue); gtk_adjustment_set_value (hadjustment, new_hvalue);
adjust_scrollbar (scrolled, priv->horizontal_scrollbar_window, adjust_scrollbar (scrolled, priv->horizontal_scrollbar_window,
gtk_scrolled_window_get_hadjustment (gtk_scrolled), gtk_scrolled_window_get_hadjustment (gtk_scrolled),
@ -510,13 +535,14 @@ do_motion_scroll (KatzeScrolled* scrolled,
guint32 timestamp) guint32 timestamp)
{ {
KatzeScrolledPrivate* priv = scrolled->priv; KatzeScrolledPrivate* priv = scrolled->priv;
GtkAdjustment* hadjustment;
GtkAdjustment* vadjustment;
gdouble hvalue;
gdouble vvalue;
if (priv->dragged || gtk_drag_check_threshold (widget, priv->start_x, priv->start_y, x, y)) if (priv->dragged || gtk_drag_check_threshold (widget, priv->start_x, priv->start_y, x, y))
{ {
GtkAdjustment* hadjustment;
GtkAdjustment* vadjustment;
gdouble hpage_size, hupper, hvalue, new_hvalue;
gdouble vpage_size, vupper, vvalue, new_vvalue;
if (timestamp - priv->previous_time > priv->dragging_stopped_delay || !priv->dragged) if (timestamp - priv->previous_time > priv->dragging_stopped_delay || !priv->dragged)
{ {
priv->dragged = TRUE; priv->dragged = TRUE;
@ -554,23 +580,26 @@ do_motion_scroll (KatzeScrolled* scrolled,
} }
hadjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled)); hadjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled));
hvalue = gtk_adjustment_get_value (hadjustment);
new_hvalue = calculate_motion_scroll_values (hvalue,
hupper - hpage_size, x, priv->previous_x);
vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled)); vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled));
hvalue = calculate_motion_scroll_values (hadjustment->value, vvalue = gtk_adjustment_get_value (vadjustment);
hadjustment->upper - hadjustment->page_size, x, priv->previous_x); new_vvalue = calculate_motion_scroll_values (vvalue,
vvalue = calculate_motion_scroll_values (vadjustment->value, vupper - vpage_size, y, priv->previous_y);
vadjustment->upper - vadjustment->page_size, y, priv->previous_y); if (new_vvalue != vvalue)
if (vvalue != vadjustment->value)
{ {
if (hvalue != hadjustment->value) if (new_hvalue != hvalue)
{ {
disable_hadjustment (scrolled); disable_hadjustment (scrolled);
gtk_adjustment_set_value (hadjustment, hvalue); gtk_adjustment_set_value (hadjustment, new_hvalue);
enable_hadjustment (scrolled); enable_hadjustment (scrolled);
} }
gtk_adjustment_set_value (vadjustment, vvalue); gtk_adjustment_set_value (vadjustment, new_vvalue);
} }
else if (hvalue != hadjustment->value) else if (new_hvalue != hvalue)
gtk_adjustment_set_value (hadjustment, hvalue); gtk_adjustment_set_value (hadjustment, new_hvalue);
} }
priv->previous_y = y; priv->previous_y = y;