Fix a few allocation coordinates & sizes

This commit is contained in:
Timm Bäder 2017-06-28 08:19:35 +02:00 committed by Matthias Clasen
parent 2c2867d45d
commit 3dc6d240b3
11 changed files with 90 additions and 126 deletions

View File

@ -98,22 +98,16 @@ swatch_snapshot (GtkWidget *widget,
{ {
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
cairo_matrix_t matrix; cairo_matrix_t matrix;
GtkAllocation allocation, border_allocation; GtkAllocation border_allocation;
GskRoundedRect content_box; GskRoundedRect content_box;
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_border_allocation (widget, &border_allocation);
/* TODO: This should be the border allocation */
gtk_widget_get_allocation (widget, &border_allocation);
border_allocation.x -= allocation.x;
border_allocation.y -= allocation.y;
gtk_rounded_boxes_init_for_style (NULL, gtk_rounded_boxes_init_for_style (NULL,
NULL, NULL,
&content_box, &content_box,
gtk_style_context_lookup_style (context), gtk_style_context_lookup_style (context),
border_allocation.x, 0, 0,
border_allocation.y,
border_allocation.width, border_allocation.width,
border_allocation.height); border_allocation.height);
gtk_snapshot_push_rounded_clip (snapshot, gtk_snapshot_push_rounded_clip (snapshot,

View File

@ -28,6 +28,7 @@
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtksnapshot.h" #include "gtksnapshot.h"
#include "gtkstylecontext.h" #include "gtkstylecontext.h"
#include "gtkwidgetprivate.h"
typedef struct _GtkDrawingAreaPrivate GtkDrawingAreaPrivate; typedef struct _GtkDrawingAreaPrivate GtkDrawingAreaPrivate;
@ -235,21 +236,22 @@ gtk_drawing_area_snapshot (GtkWidget *widget,
GtkDrawingArea *self = GTK_DRAWING_AREA (widget); GtkDrawingArea *self = GTK_DRAWING_AREA (widget);
GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self); GtkDrawingAreaPrivate *priv = gtk_drawing_area_get_instance_private (self);
cairo_t *cr; cairo_t *cr;
int width, height;
if (!priv->draw_func) if (!priv->draw_func)
return; return;
gtk_widget_get_content_size (widget, &width, &height);
cr = gtk_snapshot_append_cairo (snapshot, cr = gtk_snapshot_append_cairo (snapshot,
&GRAPHENE_RECT_INIT ( &GRAPHENE_RECT_INIT (
0, 0, 0, 0,
gtk_widget_get_allocated_width (widget), width, height
gtk_widget_get_allocated_height (widget)
), ),
"DrawingAreaContents"); "DrawingAreaContents");
priv->draw_func (self, priv->draw_func (self,
cr, cr,
gtk_widget_get_allocated_width (widget), width, height,
gtk_widget_get_allocated_height (widget),
priv->draw_func_target); priv->draw_func_target);
cairo_destroy (cr); cairo_destroy (cr);
} }

View File

@ -86,6 +86,7 @@
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkwindowprivate.h" #include "gtkwindowprivate.h"
#include "gtkwidgetprivate.h"
#include <string.h> #include <string.h>
@ -1515,7 +1516,7 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
if (!completion->priv->filter_model) if (!completion->priv->filter_model)
return; return;
gtk_widget_get_allocation (completion->priv->entry, &allocation); gtk_widget_get_window_allocation (completion->priv->entry, &allocation);
gtk_widget_get_preferred_size (completion->priv->entry, gtk_widget_get_preferred_size (completion->priv->entry,
&entry_req, NULL); &entry_req, NULL);

View File

@ -1660,16 +1660,17 @@ gtk_icon_view_snapshot (GtkWidget *widget,
GtkIconViewDropPosition dest_pos; GtkIconViewDropPosition dest_pos;
GtkIconViewItem *dest_item = NULL; GtkIconViewItem *dest_item = NULL;
GtkStyleContext *context; GtkStyleContext *context;
int width, height;
icon_view = GTK_ICON_VIEW (widget); icon_view = GTK_ICON_VIEW (widget);
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
gtk_widget_get_content_size (widget, &width, &height);
gtk_snapshot_push_clip (snapshot, gtk_snapshot_push_clip (snapshot,
&GRAPHENE_RECT_INIT ( &GRAPHENE_RECT_INIT (
0, 0, 0, 0,
gtk_widget_get_allocated_width (widget), width, height
gtk_widget_get_allocated_height (widget)
), ),
"IconView Clip"); "IconView Clip");
@ -1790,7 +1791,6 @@ static gboolean
gtk_icon_view_motion (GtkWidget *widget, gtk_icon_view_motion (GtkWidget *widget,
GdkEventMotion *event) GdkEventMotion *event)
{ {
GtkAllocation allocation;
GtkIconView *icon_view; GtkIconView *icon_view;
gint abs_y; gint abs_y;
@ -1802,6 +1802,7 @@ gtk_icon_view_motion (GtkWidget *widget,
if (icon_view->priv->doing_rubberband) if (icon_view->priv->doing_rubberband)
{ {
int width, height;
gtk_icon_view_update_rubberband (icon_view); gtk_icon_view_update_rubberband (icon_view);
abs_y = event->y - icon_view->priv->height * abs_y = event->y - icon_view->priv->height *
@ -1809,14 +1810,14 @@ gtk_icon_view_motion (GtkWidget *widget,
(gtk_adjustment_get_upper (icon_view->priv->vadjustment) - (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
gtk_adjustment_get_lower (icon_view->priv->vadjustment))); gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_content_size (widget, &width, &height);
if (abs_y < 0 || abs_y > allocation.height) if (abs_y < 0 || abs_y > height)
{ {
if (abs_y < 0) if (abs_y < 0)
icon_view->priv->scroll_value_diff = abs_y; icon_view->priv->scroll_value_diff = abs_y;
else else
icon_view->priv->scroll_value_diff = abs_y - allocation.height; icon_view->priv->scroll_value_diff = abs_y - height;
icon_view->priv->event_last_x = event->x; icon_view->priv->event_last_x = event->x;
icon_view->priv->event_last_y = event->y; icon_view->priv->event_last_y = event->y;
@ -2582,7 +2583,7 @@ gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
static void static void
gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view) gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
{ {
GtkAllocation allocation; int width, height;
GtkAdjustment *adj = icon_view->priv->hadjustment; GtkAdjustment *adj = icon_view->priv->hadjustment;
gdouble old_page_size; gdouble old_page_size;
gdouble old_upper; gdouble old_upper;
@ -2590,12 +2591,12 @@ gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
gdouble new_value; gdouble new_value;
gdouble new_upper; gdouble new_upper;
gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation); gtk_widget_get_content_size (GTK_WIDGET (icon_view), &width, &height);
old_value = gtk_adjustment_get_value (adj); old_value = gtk_adjustment_get_value (adj);
old_upper = gtk_adjustment_get_upper (adj); old_upper = gtk_adjustment_get_upper (adj);
old_page_size = gtk_adjustment_get_page_size (adj); old_page_size = gtk_adjustment_get_page_size (adj);
new_upper = MAX (allocation.width, icon_view->priv->width); new_upper = MAX (width, icon_view->priv->width);
if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL) if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
{ {
@ -2609,37 +2610,37 @@ gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
* rectangle fixed. This means right edge of thumb should remain fixed. * rectangle fixed. This means right edge of thumb should remain fixed.
* In this case, upper - value - page_size should remain constant. * In this case, upper - value - page_size should remain constant.
*/ */
new_value = (new_upper - allocation.width) - new_value = (new_upper - width) -
(old_upper - old_value - old_page_size); (old_upper - old_value - old_page_size);
new_value = CLAMP (new_value, 0, new_upper - allocation.width); new_value = CLAMP (new_value, 0, new_upper - width);
} }
else else
new_value = CLAMP (old_value, 0, new_upper - allocation.width); new_value = CLAMP (old_value, 0, new_upper - width);
gtk_adjustment_configure (adj, gtk_adjustment_configure (adj,
new_value, new_value,
0.0, 0.0,
new_upper, new_upper,
allocation.width * 0.1, width * 0.1,
allocation.width * 0.9, width * 0.9,
allocation.width); width);
} }
static void static void
gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view) gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
{ {
GtkAllocation allocation; int width, height;
GtkAdjustment *adj = icon_view->priv->vadjustment; GtkAdjustment *adj = icon_view->priv->vadjustment;
gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation); gtk_widget_get_content_size (GTK_WIDGET (icon_view), &width, &height);
gtk_adjustment_configure (adj, gtk_adjustment_configure (adj,
gtk_adjustment_get_value (adj), gtk_adjustment_get_value (adj),
0.0, 0.0,
MAX (allocation.height, icon_view->priv->height), MAX (height, icon_view->priv->height),
allocation.height * 0.1, height * 0.1,
allocation.height * 0.9, height * 0.9,
allocation.height); height);
} }
static void static void
@ -2735,6 +2736,7 @@ gtk_icon_view_layout (GtkIconView *icon_view)
gint col, row; gint col, row;
GtkRequestedSize *sizes; GtkRequestedSize *sizes;
gboolean rtl; gboolean rtl;
int width, height;
if (gtk_icon_view_is_empty (icon_view)) if (gtk_icon_view_is_empty (icon_view))
return; return;
@ -2742,16 +2744,18 @@ gtk_icon_view_layout (GtkIconView *icon_view)
rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL; rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
n_items = gtk_icon_view_get_n_items (icon_view); n_items = gtk_icon_view_get_n_items (icon_view);
gtk_widget_get_content_size (widget, &width, &height);
gtk_icon_view_compute_n_items_for_size (icon_view, gtk_icon_view_compute_n_items_for_size (icon_view,
GTK_ORIENTATION_HORIZONTAL, GTK_ORIENTATION_HORIZONTAL,
gtk_widget_get_allocated_width (widget), width,
NULL, NULL, NULL, NULL,
&n_columns, &item_width); &n_columns, &item_width);
n_rows = (n_items + n_columns - 1) / n_columns; n_rows = (n_items + n_columns - 1) / n_columns;
priv->width = n_columns * (item_width + 2 * priv->item_padding + priv->column_spacing) - priv->column_spacing; priv->width = n_columns * (item_width + 2 * priv->item_padding + priv->column_spacing) - priv->column_spacing;
priv->width += 2 * priv->margin; priv->width += 2 * priv->margin;
priv->width = MAX (priv->width, gtk_widget_get_allocated_width (widget)); priv->width = MAX (priv->width, width);
/* Clear the per row contexts */ /* Clear the per row contexts */
g_ptr_array_set_size (icon_view->priv->row_contexts, 0); g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
@ -2801,9 +2805,9 @@ gtk_icon_view_layout (GtkIconView *icon_view)
priv->height -= priv->row_spacing; priv->height -= priv->row_spacing;
priv->height += priv->margin; priv->height += priv->margin;
priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget)); priv->height = MIN (priv->height, height);
gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height, gtk_distribute_natural_allocation (height - priv->height,
n_rows, n_rows,
sizes); sizes);
@ -2842,7 +2846,7 @@ gtk_icon_view_layout (GtkIconView *icon_view)
priv->height -= priv->row_spacing; priv->height -= priv->row_spacing;
priv->height += priv->margin; priv->height += priv->margin;
priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget)); priv->height = MAX (priv->height, height);
} }
static void static void
@ -2989,23 +2993,7 @@ static void
gtk_icon_view_queue_draw_item (GtkIconView *icon_view, gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
GtkIconViewItem *item) GtkIconViewItem *item)
{ {
GdkRectangle rect; gtk_widget_queue_draw (GTK_WIDGET (icon_view));
GdkRectangle *item_area = &item->cell_area;
GtkAllocation allocation;
rect.x = item_area->x - icon_view->priv->item_padding;
rect.y = item_area->y - icon_view->priv->item_padding;
rect.width = item_area->width + icon_view->priv->item_padding * 2;
rect.height = item_area->height + icon_view->priv->item_padding * 2;
gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
rect.x += allocation.x -
gtk_adjustment_get_value (icon_view->priv->hadjustment);
rect.y += allocation.y -
gtk_adjustment_get_value (icon_view->priv->vadjustment);
gtk_widget_queue_draw_area (GTK_WIDGET (icon_view), rect.x, rect.y, rect.width, rect.height);
} }
void void
@ -3988,7 +3976,7 @@ gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
if (use_align) if (use_align)
{ {
GtkAllocation allocation; int width, height;
gint x, y; gint x, y;
gfloat offset; gfloat offset;
GdkRectangle item_area = GdkRectangle item_area =
@ -4002,14 +3990,14 @@ gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
x =0; x =0;
y =0; y =0;
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_content_size (widget, &width, &height);
offset = y + item_area.y - row_align * (allocation.height - item_area.height); offset = y + item_area.y - row_align * (height - item_area.height);
gtk_adjustment_set_value (icon_view->priv->vadjustment, gtk_adjustment_set_value (icon_view->priv->vadjustment,
gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset); gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
offset = x + item_area.x - col_align * (allocation.width - item_area.width); offset = x + item_area.x - col_align * (width - item_area.width);
gtk_adjustment_set_value (icon_view->priv->hadjustment, gtk_adjustment_set_value (icon_view->priv->hadjustment,
gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset); gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
@ -5931,15 +5919,13 @@ remove_scroll_timeout (GtkIconView *icon_view)
static void static void
gtk_icon_view_autoscroll (GtkIconView *icon_view) gtk_icon_view_autoscroll (GtkIconView *icon_view)
{ {
GtkAllocation allocation;
gint px, py, width, height; gint px, py, width, height;
gint hoffset, voffset; gint hoffset, voffset;
gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
px = icon_view->priv->event_last_x; px = icon_view->priv->event_last_x;
py = icon_view->priv->event_last_y; py = icon_view->priv->event_last_y;
width = allocation.width;
height = allocation.height; gtk_widget_get_content_size (GTK_WIDGET (icon_view), &width, &height);
/* see if we are near the edge. */ /* see if we are near the edge. */
voffset = py - 2 * SCROLL_EDGE_SIZE; voffset = py - 2 * SCROLL_EDGE_SIZE;

View File

@ -1440,7 +1440,7 @@ ensure_row_visible (GtkListBox *box,
if (!priv->adjustment) if (!priv->adjustment)
return; return;
gtk_widget_get_allocation (GTK_WIDGET (row), &allocation); gtk_widget_get_outer_allocation (GTK_WIDGET (row), &allocation);
y = allocation.y; y = allocation.y;
height = allocation.height; height = allocation.height;
@ -1448,7 +1448,7 @@ ensure_row_visible (GtkListBox *box,
header = ROW_PRIV (row)->header; header = ROW_PRIV (row)->header;
if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header)) if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header))
{ {
gtk_widget_get_allocation (header, &allocation); gtk_widget_get_outer_allocation (header, &allocation);
y = allocation.y; y = allocation.y;
height += allocation.height; height += allocation.height;
} }

View File

@ -2559,15 +2559,8 @@ gtk_menu_reorder_child (GtkMenu *menu,
static void static void
gtk_menu_realize (GtkWidget *widget) gtk_menu_realize (GtkWidget *widget)
{ {
GtkMenu *menu = GTK_MENU (widget);
GtkAllocation allocation;
GtkBorder arrow_border;
GTK_WIDGET_CLASS (gtk_menu_parent_class)->realize (widget); GTK_WIDGET_CLASS (gtk_menu_parent_class)->realize (widget);
gtk_widget_get_allocation (widget, &allocation);
get_arrows_border (menu, &arrow_border);
if (GTK_MENU_SHELL (widget)->priv->active_menu_item) if (GTK_MENU_SHELL (widget)->priv->active_menu_item)
gtk_menu_scroll_item_visible (GTK_MENU_SHELL (widget), gtk_menu_scroll_item_visible (GTK_MENU_SHELL (widget),
GTK_MENU_SHELL (widget)->priv->active_menu_item); GTK_MENU_SHELL (widget)->priv->active_menu_item);
@ -3160,7 +3153,7 @@ definitely_within_item (GtkWidget *widget,
GtkAllocation allocation; GtkAllocation allocation;
int w, h; int w, h;
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_outer_allocation (widget, &allocation);
w = allocation.width; w = allocation.width;
h = allocation.height; h = allocation.height;

View File

@ -1412,15 +1412,12 @@ gtk_range_allocate_trough (GtkGizmo *gizmo,
GtkWidget *widget = gtk_widget_get_parent (GTK_WIDGET (gizmo)); GtkWidget *widget = gtk_widget_get_parent (GTK_WIDGET (gizmo));
GtkRange *range = GTK_RANGE (widget); GtkRange *range = GTK_RANGE (widget);
GtkRangePrivate *priv = range->priv; GtkRangePrivate *priv = range->priv;
GtkAllocation slider_alloc, widget_alloc; GtkAllocation slider_alloc;
GtkAllocation trough_alloc;
double value; double value;
/* Slider */ /* Slider */
gtk_range_calc_marks (range); gtk_range_calc_marks (range);
gtk_widget_get_allocation (widget, &widget_alloc);
gtk_widget_get_allocation (GTK_WIDGET (gizmo), &trough_alloc);
gtk_range_compute_slider_position (range, gtk_range_compute_slider_position (range,
gtk_adjustment_get_value (priv->adjustment), gtk_adjustment_get_value (priv->adjustment),
&slider_alloc); &slider_alloc);
@ -2358,19 +2355,19 @@ update_autoscroll_mode (GtkRange *range)
if (range->priv->zoom) if (range->priv->zoom)
{ {
GtkAllocation allocation; int width, height;
gint size, pos; gint size, pos;
gtk_widget_get_allocation (GTK_WIDGET (range), &allocation); gtk_widget_get_content_size (GTK_WIDGET (range), &width, &height);
if (range->priv->orientation == GTK_ORIENTATION_VERTICAL) if (range->priv->orientation == GTK_ORIENTATION_VERTICAL)
{ {
size = allocation.height; size = height;
pos = range->priv->mouse_y; pos = range->priv->mouse_y;
} }
else else
{ {
size = allocation.width; size = width;
pos = range->priv->mouse_x; pos = range->priv->mouse_x;
} }

View File

@ -485,9 +485,9 @@ find_next_pos (GtkWidget *widget,
gint *marks, gint *marks,
GtkPositionType pos) GtkPositionType pos)
{ {
GtkAllocation allocation;
GSList *m; GSList *m;
gint i; gint i;
int width, height;
for (m = list->next, i = 1; m; m = m->next, i++) for (m = list->next, i = 1; m; m = m->next, i++)
{ {
@ -497,11 +497,11 @@ find_next_pos (GtkWidget *widget,
return marks[i]; return marks[i];
} }
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_content_size (widget, &width, &height);
if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL) if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
return allocation.width; return width;
else else
return allocation.height; return height;
} }
static void static void

View File

@ -1083,7 +1083,7 @@ event_close_to_indicator (GtkScrolledWindow *sw,
priv = sw->priv; priv = sw->priv;
gtk_widget_get_allocation (indicator->scrollbar, &indicator_alloc); gtk_widget_get_outer_allocation (indicator->scrollbar, &indicator_alloc);
gdk_event_get_coords (event, &x, &y); gdk_event_get_coords (event, &x, &y);
if (indicator->over) if (indicator->over)
@ -1354,14 +1354,11 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget,
GtkScrolledWindowPrivate *priv = scrolled_window->priv; GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkBin *bin; GtkBin *bin;
GtkAllocation child_allocation; GtkAllocation child_allocation;
GtkAllocation sw_allocation;
GtkWidget *child; GtkWidget *child;
gint sb_width; gint sb_width;
gint sb_height; gint sb_height;
bin = GTK_BIN (scrolled_window); bin = GTK_BIN (scrolled_window);
gtk_widget_get_allocation (GTK_WIDGET (scrolled_window), &sw_allocation);
/* Get possible scrollbar dimensions */ /* Get possible scrollbar dimensions */
gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_HORIZONTAL, -1, gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
@ -3985,9 +3982,6 @@ gtk_scrolled_window_realize (GtkWidget *widget)
{ {
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget); GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv; GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
priv->hindicator.scrollbar = priv->hscrollbar; priv->hindicator.scrollbar = priv->hscrollbar;
priv->vindicator.scrollbar = priv->vscrollbar; priv->vindicator.scrollbar = priv->vscrollbar;

View File

@ -1834,35 +1834,34 @@ gtk_stack_snapshot_under (GtkWidget *widget,
{ {
GtkStack *stack = GTK_STACK (widget); GtkStack *stack = GTK_STACK (widget);
GtkStackPrivate *priv = gtk_stack_get_instance_private (stack); GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
GtkAllocation allocation; int widget_width, widget_height;
gint x, y, width, height, pos_x, pos_y; gint x, y, width, height, pos_x, pos_y;
gtk_widget_get_allocation (widget, &allocation);
gtk_widget_get_content_size (widget, &widget_width, &widget_height);
x = y = 0; x = y = 0;
width = allocation.width;
height = allocation.height;
pos_x = pos_y = 0; pos_x = pos_y = 0;
switch (priv->active_transition_type) switch (priv->active_transition_type)
{ {
case GTK_STACK_TRANSITION_TYPE_UNDER_DOWN: case GTK_STACK_TRANSITION_TYPE_UNDER_DOWN:
y = 0; y = 0;
height = allocation.height * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE)); height = widget_height * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
pos_y = height; pos_y = height;
break; break;
case GTK_STACK_TRANSITION_TYPE_UNDER_UP: case GTK_STACK_TRANSITION_TYPE_UNDER_UP:
y = allocation.height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE)); y = widget_height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
height = allocation.height - y; height = widget_height - y;
pos_y = y - allocation.height; pos_y = y - widget_height;
break; break;
case GTK_STACK_TRANSITION_TYPE_UNDER_LEFT: case GTK_STACK_TRANSITION_TYPE_UNDER_LEFT:
x = allocation.width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE)); x = widget_width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
width = allocation.width - x; width = widget_width - x;
pos_x = x - allocation.width; pos_x = x - widget_width;
break; break;
case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT: case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT:
x = 0; x = 0;
width = allocation.width * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE)); width = widget_width * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
pos_x = width; pos_x = width;
break; break;
default: default:
@ -1900,11 +1899,11 @@ gtk_stack_snapshot_slide (GtkWidget *widget,
if (priv->last_visible_node) if (priv->last_visible_node)
{ {
GtkAllocation allocation;
graphene_matrix_t matrix; graphene_matrix_t matrix;
int x, y; int x, y;
int width, height;
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_content_size (widget, &width, &height);
x = get_bin_window_x (stack); x = get_bin_window_x (stack);
y = get_bin_window_y (stack); y = get_bin_window_y (stack);
@ -1912,16 +1911,16 @@ gtk_stack_snapshot_slide (GtkWidget *widget,
switch (priv->active_transition_type) switch (priv->active_transition_type)
{ {
case GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT: case GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT:
x -= allocation.width; x -= width;
break; break;
case GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT: case GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT:
x += allocation.width; x += width;
break; break;
case GTK_STACK_TRANSITION_TYPE_SLIDE_UP: case GTK_STACK_TRANSITION_TYPE_SLIDE_UP:
y -= allocation.height; y -= height;
break; break;
case GTK_STACK_TRANSITION_TYPE_SLIDE_DOWN: case GTK_STACK_TRANSITION_TYPE_SLIDE_DOWN:
y += allocation.height; y += height;
break; break;
case GTK_STACK_TRANSITION_TYPE_OVER_UP: case GTK_STACK_TRANSITION_TYPE_OVER_UP:
case GTK_STACK_TRANSITION_TYPE_OVER_DOWN: case GTK_STACK_TRANSITION_TYPE_OVER_DOWN:
@ -1937,10 +1936,10 @@ gtk_stack_snapshot_slide (GtkWidget *widget,
} }
if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END && if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END &&
priv->last_visible_widget_height > allocation.height) priv->last_visible_widget_height > height)
y -= priv->last_visible_widget_height - allocation.height; y -= priv->last_visible_widget_height - height;
else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER) else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER)
y -= (priv->last_visible_widget_height - allocation.height) / 2; y -= (priv->last_visible_widget_height - height) / 2;
graphene_matrix_init_translate (&matrix, &GRAPHENE_POINT3D_INIT (x, y, 0)); graphene_matrix_init_translate (&matrix, &GRAPHENE_POINT3D_INIT (x, y, 0));
gtk_snapshot_push_transform (snapshot, &matrix, "StackSlide"); gtk_snapshot_push_transform (snapshot, &matrix, "StackSlide");
@ -1964,6 +1963,8 @@ gtk_stack_snapshot (GtkWidget *widget,
{ {
if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER) if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER)
{ {
int width, height;
if (priv->last_visible_node == NULL && if (priv->last_visible_node == NULL &&
priv->last_visible_child != NULL) priv->last_visible_child != NULL)
{ {
@ -1980,11 +1981,11 @@ gtk_stack_snapshot (GtkWidget *widget,
priv->last_visible_node = gtk_snapshot_finish (&last_visible_snapshot); priv->last_visible_node = gtk_snapshot_finish (&last_visible_snapshot);
} }
gtk_widget_get_content_size (widget, &width, &height);
gtk_snapshot_push_clip (snapshot, gtk_snapshot_push_clip (snapshot,
&GRAPHENE_RECT_INIT( &GRAPHENE_RECT_INIT(
0, 0, 0, 0,
gtk_widget_get_allocated_width (widget), width, height
gtk_widget_get_allocated_height (widget)
), ),
"StackAnimationClip"); "StackAnimationClip");

View File

@ -26,6 +26,7 @@
#include "gtkorientable.h" #include "gtkorientable.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkwidgetprivate.h"
/** /**
* SECTION:gtkstackswitcher * SECTION:gtkstackswitcher
@ -294,26 +295,21 @@ gtk_stack_switcher_drag_motion (GtkWidget *widget,
{ {
GtkStackSwitcher *self = GTK_STACK_SWITCHER (widget); GtkStackSwitcher *self = GTK_STACK_SWITCHER (widget);
GtkStackSwitcherPrivate *priv; GtkStackSwitcherPrivate *priv;
GtkAllocation allocation;
GtkWidget *button; GtkWidget *button;
GHashTableIter iter; GHashTableIter iter;
gpointer value; gpointer value;
gboolean retval = FALSE; gboolean retval = FALSE;
gtk_widget_get_allocation (widget, &allocation);
priv = gtk_stack_switcher_get_instance_private (self); priv = gtk_stack_switcher_get_instance_private (self);
x += allocation.x;
y += allocation.y;
button = NULL; button = NULL;
g_hash_table_iter_init (&iter, priv->buttons); g_hash_table_iter_init (&iter, priv->buttons);
while (g_hash_table_iter_next (&iter, NULL, &value)) while (g_hash_table_iter_next (&iter, NULL, &value))
{ {
gtk_widget_get_allocation (GTK_WIDGET (value), &allocation); GdkRectangle allocation;
if (x >= allocation.x && x <= allocation.x + allocation.width &&
y >= allocation.y && y <= allocation.y + allocation.height) gtk_widget_get_outer_allocation (GTK_WIDGET (value), &allocation);
if (gdk_rectangle_contains_point (&allocation, (int)x, (int)y))
{ {
button = GTK_WIDGET (value); button = GTK_WIDGET (value);
retval = TRUE; retval = TRUE;