gtk/gtkscalebutton.c: use accessor functions to access GtkWidget

This commit is contained in:
Javier Jardón
2010-08-11 23:02:16 +02:00
parent 482637a41e
commit 41fcf40648

View File

@ -896,6 +896,7 @@ gtk_scale_popup (GtkWidget *widget,
GdkEvent *event, GdkEvent *event,
guint32 time) guint32 time)
{ {
GtkAllocation allocation, dock_allocation, scale_allocation;
GtkScaleButton *button; GtkScaleButton *button;
GtkScaleButtonPrivate *priv; GtkScaleButtonPrivate *priv;
GtkAdjustment *adj; GtkAdjustment *adj;
@ -913,13 +914,15 @@ gtk_scale_popup (GtkWidget *widget,
display = gtk_widget_get_display (widget); display = gtk_widget_get_display (widget);
screen = gtk_widget_get_screen (widget); screen = gtk_widget_get_screen (widget);
gtk_widget_get_allocation (widget, &allocation);
/* position roughly */ /* position roughly */
gtk_window_set_screen (GTK_WINDOW (priv->dock), screen); gtk_window_set_screen (GTK_WINDOW (priv->dock), screen);
gdk_window_get_origin (widget->window, &x, &y); gdk_window_get_origin (gtk_widget_get_window (widget),
x += widget->allocation.x; &x, &y);
y += widget->allocation.y; x += allocation.x;
y += allocation.y;
if (priv->orientation == GTK_ORIENTATION_VERTICAL) if (priv->orientation == GTK_ORIENTATION_VERTICAL)
gtk_window_move (GTK_WINDOW (priv->dock), x, y - (SCALE_SIZE / 2)); gtk_window_move (GTK_WINDOW (priv->dock), x, y - (SCALE_SIZE / 2));
@ -928,13 +931,18 @@ gtk_scale_popup (GtkWidget *widget,
gtk_widget_show_all (priv->dock); gtk_widget_show_all (priv->dock);
gdk_window_get_origin (priv->dock->window, &dx, &dy); gdk_window_get_origin (gtk_widget_get_window (priv->dock),
dx += priv->dock->allocation.x; &dx, &dy);
dy += priv->dock->allocation.y; gtk_widget_get_allocation (priv->dock, &dock_allocation);
dx += dock_allocation.x;
dy += dock_allocation.y;
gdk_window_get_origin (priv->scale->window, &sx, &sy);
sx += priv->scale->allocation.x; gdk_window_get_origin (gtk_widget_get_window (priv->scale),
sy += priv->scale->allocation.y; &sx, &sy);
gtk_widget_get_allocation (priv->scale, &scale_allocation);
sx += scale_allocation.x;
sy += scale_allocation.y;
priv->timeout = TRUE; priv->timeout = TRUE;
@ -945,11 +953,10 @@ gtk_scale_popup (GtkWidget *widget,
{ {
startoff = sy - dy; startoff = sy - dy;
x += (widget->allocation.width - priv->dock->allocation.width) / 2; x += (allocation.width - dock_allocation.width) / 2;
y -= startoff; y -= startoff;
y -= GTK_RANGE (priv->scale)->min_slider_size / 2; y -= GTK_RANGE (priv->scale)->min_slider_size / 2;
m = priv->scale->allocation.height - m = scale_allocation.height - GTK_RANGE (priv->scale)->min_slider_size;
GTK_RANGE (priv->scale)->min_slider_size;
y -= m * (1.0 - v); y -= m * (1.0 - v);
} }
else else
@ -957,16 +964,16 @@ gtk_scale_popup (GtkWidget *widget,
startoff = sx - dx; startoff = sx - dx;
x -= startoff; x -= startoff;
y += (widget->allocation.height - priv->dock->allocation.height) / 2; y += (allocation.height - dock_allocation.height) / 2;
x -= GTK_RANGE (priv->scale)->min_slider_size / 2; x -= GTK_RANGE (priv->scale)->min_slider_size / 2;
m = priv->scale->allocation.width - m = scale_allocation.width - GTK_RANGE (priv->scale)->min_slider_size;
GTK_RANGE (priv->scale)->min_slider_size;
x -= m * v; x -= m * v;
} }
/* Make sure the dock stays inside the monitor */ /* Make sure the dock stays inside the monitor */
if (event->type == GDK_BUTTON_PRESS) if (event->type == GDK_BUTTON_PRESS)
{ {
GtkAllocation d_allocation;
int monitor; int monitor;
GdkEventButton *button_event = (GdkEventButton *) event; GdkEventButton *button_event = (GdkEventButton *) event;
GdkRectangle rect; GdkRectangle rect;
@ -986,14 +993,15 @@ gtk_scale_popup (GtkWidget *widget,
/* Move the dock, but set is_moved so we /* Move the dock, but set is_moved so we
* don't forward the first click later on, * don't forward the first click later on,
* as it could make the scale go to the bottom */ * as it could make the scale go to the bottom */
gtk_widget_get_allocation (d, &d_allocation);
if (y < rect.y) if (y < rect.y)
{ {
y = rect.y; y = rect.y;
is_moved = TRUE; is_moved = TRUE;
} }
else if (y + d->allocation.height > rect.height + rect.y) else if (y + d_allocation.height > rect.height + rect.y)
{ {
y = rect.y + rect.height - d->allocation.height; y = rect.y + rect.height - d_allocation.height;
is_moved = TRUE; is_moved = TRUE;
} }
@ -1002,9 +1010,9 @@ gtk_scale_popup (GtkWidget *widget,
x = rect.x; x = rect.x;
is_moved = TRUE; is_moved = TRUE;
} }
else if (x + d->allocation.width > rect.width + rect.x) else if (x + d_allocation.width > rect.width + rect.x)
{ {
x = rect.x + rect.width - d->allocation.width; x = rect.x + rect.width - d_allocation.width;
is_moved = TRUE; is_moved = TRUE;
} }
} }
@ -1030,7 +1038,7 @@ gtk_scale_popup (GtkWidget *widget,
/* grab focus */ /* grab focus */
gtk_device_grab_add (priv->dock, pointer, TRUE); gtk_device_grab_add (priv->dock, pointer, TRUE);
if (gdk_device_grab (pointer, priv->dock->window, if (gdk_device_grab (pointer, gtk_widget_get_window (priv->dock),
GDK_OWNERSHIP_WINDOW, TRUE, GDK_OWNERSHIP_WINDOW, TRUE,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK, NULL, time) != GDK_GRAB_SUCCESS) GDK_POINTER_MOTION_MASK, NULL, time) != GDK_GRAB_SUCCESS)
@ -1040,7 +1048,7 @@ gtk_scale_popup (GtkWidget *widget,
return FALSE; return FALSE;
} }
if (gdk_device_grab (keyboard, priv->dock->window, if (gdk_device_grab (keyboard, gtk_widget_get_window (priv->dock),
GDK_OWNERSHIP_WINDOW, TRUE, GDK_OWNERSHIP_WINDOW, TRUE,
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
NULL, time) != GDK_GRAB_SUCCESS) NULL, time) != GDK_GRAB_SUCCESS)
@ -1062,24 +1070,25 @@ gtk_scale_popup (GtkWidget *widget,
/* forward event to the slider */ /* forward event to the slider */
e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
e->window = priv->scale->window; e->window = gtk_widget_get_window (priv->scale);
/* position: the X position isn't relevant, halfway will work just fine. /* position: the X position isn't relevant, halfway will work just fine.
* The vertical position should be *exactly* in the middle of the slider * The vertical position should be *exactly* in the middle of the slider
* of the scale; if we don't do that correctly, it'll move from its current * of the scale; if we don't do that correctly, it'll move from its current
* position, which means a position change on-click, which is bad. * position, which means a position change on-click, which is bad.
*/ */
gtk_widget_get_allocation (priv->scale, &scale_allocation);
if (priv->orientation == GTK_ORIENTATION_VERTICAL) if (priv->orientation == GTK_ORIENTATION_VERTICAL)
{ {
e->x = priv->scale->allocation.width / 2; e->x = scale_allocation.width / 2;
m = priv->scale->allocation.height - m = scale_allocation.height -
GTK_RANGE (priv->scale)->min_slider_size; GTK_RANGE (priv->scale)->min_slider_size;
e->y = ((1.0 - v) * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; e->y = ((1.0 - v) * m) + GTK_RANGE (priv->scale)->min_slider_size / 2;
} }
else else
{ {
e->y = priv->scale->allocation.height / 2; e->y = scale_allocation.height / 2;
m = priv->scale->allocation.width - m = scale_allocation.width -
GTK_RANGE (priv->scale)->min_slider_size; GTK_RANGE (priv->scale)->min_slider_size;
e->x = (v * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; e->x = (v * m) + GTK_RANGE (priv->scale)->min_slider_size / 2;
} }
@ -1319,7 +1328,7 @@ gtk_scale_button_release_grab (GtkScaleButton *button,
priv->timeout = FALSE; priv->timeout = FALSE;
e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
e->window = GTK_WIDGET (button)->window; e->window = gtk_widget_get_window (GTK_WIDGET (button));
e->type = GDK_BUTTON_RELEASE; e->type = GDK_BUTTON_RELEASE;
gtk_widget_event (GTK_WIDGET (button), (GdkEvent *) e); gtk_widget_event (GTK_WIDGET (button), (GdkEvent *) e);
e->window = event->window; e->window = event->window;