widget: Remove gtk_widget_get_content_allocation

Replace it where we still need something similar, e.g. in
gtk_widget_translate_coordinates
This commit is contained in:
Timm Bäder 2017-08-14 12:12:09 +02:00
parent 9c7e089fc2
commit 5f859a1f24
9 changed files with 74 additions and 72 deletions

View File

@ -1392,8 +1392,6 @@ gtk_combo_box_menu_popup (GtkComboBox *combo_box)
{
GtkComboBoxPrivate *priv = combo_box->priv;
gint active_item;
GtkAllocation border_allocation;
GtkAllocation content_allocation;
GtkWidget *active;
update_menu_sensitivity (combo_box, priv->popup_widget);
@ -1413,10 +1411,9 @@ gtk_combo_box_menu_popup (GtkComboBox *combo_box)
if (priv->wrap_width == 0)
{
gint width, min_width, nat_width;
int width, height, min_width, nat_width;
gtk_widget_get_content_allocation (GTK_WIDGET (combo_box), &content_allocation);
width = content_allocation.width;
gtk_widget_get_content_size (GTK_WIDGET (combo_box), &width, &height);
gtk_widget_set_size_request (priv->popup_widget, -1, -1);
gtk_widget_measure (priv->popup_widget, GTK_ORIENTATION_HORIZONTAL, -1,
&min_width, &nat_width, NULL, NULL);
@ -1437,14 +1434,11 @@ gtk_combo_box_menu_popup (GtkComboBox *combo_box)
if (priv->wrap_width > 0 || priv->cell_view == NULL)
{
gtk_widget_get_border_allocation (GTK_WIDGET (combo_box), &border_allocation);
gtk_widget_get_content_allocation (GTK_WIDGET (combo_box), &content_allocation);
g_object_set (priv->popup_widget,
"anchor-hints", (GDK_ANCHOR_FLIP_Y |
GDK_ANCHOR_SLIDE |
GDK_ANCHOR_RESIZE),
"rect-anchor-dx", border_allocation.x - content_allocation.x,
"rect-anchor-dx", 0,
NULL);
gtk_menu_popup_at_widget (GTK_MENU (priv->popup_widget),

View File

@ -2962,7 +2962,7 @@ gtk_entry_get_text_allocation (GtkEntry *entry,
{
GtkEntryPrivate *priv = entry->priv;
gtk_widget_get_content_allocation (GTK_WIDGET (entry), allocation);
gtk_widget_get_own_allocation (GTK_WIDGET (entry), allocation);
allocation->x = priv->text_x;
allocation->width = priv->text_width;
}
@ -6170,7 +6170,6 @@ static void
gtk_entry_move_adjustments (GtkEntry *entry)
{
GtkWidget *widget = GTK_WIDGET (entry);
GtkAllocation allocation;
GtkAdjustment *adjustment;
PangoContext *context;
PangoFontMetrics *metrics;
@ -6181,12 +6180,10 @@ gtk_entry_move_adjustments (GtkEntry *entry)
if (!adjustment)
return;
gtk_widget_get_content_allocation (GTK_WIDGET (entry), &allocation);
/* Cursor/char position, layout offset, border width, and widget allocation */
/* Cursor/char position, layout offset and border width*/
gtk_entry_get_cursor_locations (entry, &x, NULL);
get_layout_position (entry, &layout_x, NULL);
x += allocation.x + layout_x;
x += layout_x;
/* Approximate width of a char, so user can see what is ahead/behind */
context = gtk_widget_get_pango_context (widget);

View File

@ -1570,12 +1570,13 @@ update_drag (GtkPaned *paned,
int ypos)
{
GtkPanedPrivate *priv = paned->priv;
GtkAllocation allocation;
int width, height;
gint pos;
gint handle_size;
gint size;
gtk_widget_get_content_allocation (GTK_WIDGET (paned), &allocation);
gtk_widget_get_content_size (GTK_WIDGET (paned), &width, &height);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
pos = xpos;
else
@ -1591,7 +1592,7 @@ update_drag (GtkPaned *paned,
NULL, &handle_size,
NULL, NULL);
size = allocation.width - pos - handle_size;
size = width - pos - handle_size;
}
else
{

View File

@ -1832,7 +1832,7 @@ coord_to_value (GtkRange *range,
GtkAllocation slider_alloc, trough_alloc;
gtk_widget_get_outer_allocation (priv->slider_widget, &slider_alloc);
gtk_widget_get_content_allocation (priv->trough_widget, &trough_alloc);
gtk_widget_get_outer_allocation (priv->trough_widget, &trough_alloc);
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
{

View File

@ -327,9 +327,10 @@ gtk_scale_allocate_value (GtkScale *scale,
GtkWidget *widget = GTK_WIDGET (scale);
GtkRange *range = GTK_RANGE (widget);
GtkWidget *slider_widget;
GtkAllocation range_alloc, slider_alloc, value_alloc;
GtkAllocation slider_alloc, value_alloc;
int range_width, range_height;
gtk_widget_get_content_allocation (widget, &range_alloc);
gtk_widget_get_content_size (widget, &range_width, &range_height);
slider_widget = gtk_range_get_slider_widget (range);
gtk_widget_get_border_allocation (slider_widget, &slider_alloc);
@ -349,12 +350,12 @@ gtk_scale_allocate_value (GtkScale *scale,
{
case GTK_POS_LEFT:
value_alloc.x = 0;
value_alloc.y = (range_alloc.height - value_alloc.height) / 2;
value_alloc.y = (range_height - value_alloc.height) / 2;
break;
case GTK_POS_RIGHT:
value_alloc.x = range_alloc.width - value_alloc.width;
value_alloc.y = (range_alloc.height - value_alloc.height) / 2;
value_alloc.x = range_width - value_alloc.width;
value_alloc.y = (range_height - value_alloc.height) / 2;
break;
case GTK_POS_TOP:
@ -364,7 +365,7 @@ gtk_scale_allocate_value (GtkScale *scale,
case GTK_POS_BOTTOM:
value_alloc.x = slider_alloc.x + (slider_alloc.width - value_alloc.width) / 2;
value_alloc.y = range_alloc.height - value_alloc.height;
value_alloc.y = range_height - value_alloc.height;
break;
default:
@ -382,18 +383,18 @@ gtk_scale_allocate_value (GtkScale *scale,
break;
case GTK_POS_RIGHT:
value_alloc.x = range_alloc.width - value_alloc.width;
value_alloc.x = range_width - value_alloc.width;
value_alloc.y = (slider_alloc.y + (slider_alloc.height / 2)) - value_alloc.height / 2;
break;
case GTK_POS_TOP:
value_alloc.x = (range_alloc.width - value_alloc.width) / 2;
value_alloc.x = (range_width - value_alloc.width) / 2;
value_alloc.y = 0;
break;
case GTK_POS_BOTTOM:
value_alloc.x = (range_alloc.width - value_alloc.width) / 2;
value_alloc.y = range_alloc.height - value_alloc.height;
value_alloc.x = (range_width - value_alloc.width) / 2;
value_alloc.y = range_height - value_alloc.height;
break;
default:
@ -1537,7 +1538,7 @@ gtk_scale_real_get_layout_offsets (GtkScale *scale,
return;
}
gtk_widget_get_content_allocation (priv->value_widget, &value_alloc);
gtk_widget_get_outer_allocation (priv->value_widget, &value_alloc);
*x = value_alloc.x;
*y = value_alloc.y;

View File

@ -2881,7 +2881,7 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
GtkScrolledWindowPrivate *priv;
gint sb_width;
gint sb_height;
GtkAllocation content_allocation;
int width, height;
g_return_if_fail (widget != NULL);
g_return_if_fail (allocation != NULL);
@ -2895,12 +2895,12 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
gtk_widget_measure (priv->hscrollbar, GTK_ORIENTATION_VERTICAL, -1,
&sb_height, NULL, NULL, NULL);
gtk_widget_get_content_allocation (widget, &content_allocation);
gtk_widget_get_content_size (widget, &width, &height);
allocation->x = content_allocation.x;
allocation->y = content_allocation.y;
allocation->width = content_allocation.width;
allocation->height = content_allocation.height;
allocation->x = 0;
allocation->y = 0;
allocation->width = width;
allocation->height = height;
/* Subtract some things from our available allocation size */
if (priv->vscrollbar_visible && !priv->use_indicators)
@ -2917,7 +2917,7 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
priv->window_placement == GTK_CORNER_BOTTOM_LEFT)))
allocation->x += sb_width;
allocation->width = MAX (1, content_allocation.width - sb_width);
allocation->width = MAX (1, width - sb_width);
}
if (priv->hscrollbar_visible && !priv->use_indicators)
@ -2927,7 +2927,7 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)
allocation->y += (sb_height);
allocation->height = MAX (1, content_allocation.height - sb_height);
allocation->height = MAX (1, height - sb_height);
}
}

View File

@ -1067,7 +1067,7 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
g_source_set_name_by_id (priv->idle_id, "[gtk+] slide_idle_handler");
}
gtk_widget_get_content_allocation (widget, &content_allocation);
gtk_widget_get_own_allocation (widget, &content_allocation);
rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);

View File

@ -954,11 +954,11 @@ gtk_widget_real_pick (GtkWidget *widget,
{
if (x_out && y_out)
{
GtkAllocation content_alloc;
gtk_widget_get_content_allocation (child, &content_alloc);
GtkAllocation own_alloc;
gtk_widget_get_own_allocation (child, &own_alloc);
*x_out = x - content_alloc.x;
*y_out = y - content_alloc.y;
*x_out = own_alloc.x + (x - allocation.x);
*y_out = own_alloc.y + (y - allocation.y);
}
return child;
@ -5645,6 +5645,30 @@ gtk_widget_common_ancestor (GtkWidget *widget_a,
return widget_a;
}
static void
gtk_widget_get_origin_relative_to_parent (GtkWidget *widget,
int *origin_x,
int *origin_y)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GtkBorder margin, border, padding;
GtkCssStyle *style;
style = gtk_css_node_get_style (priv->cssnode);
get_box_margin (style, &margin);
get_box_border (style, &border);
get_box_padding (style, &padding);
/* allocation is relative to the parent's origin */
*origin_x = priv->allocation.x;
*origin_y = priv->allocation.y;
/* ... but points to the upper left, excluding widget margins
* but including all the css properties */
*origin_x += margin.left + border.left + padding.left;
*origin_y += margin.top + border.top + padding.top;
}
/**
* gtk_widget_translate_coordinates:
* @src_widget: a #GtkWidget
@ -5685,12 +5709,12 @@ gtk_widget_translate_coordinates (GtkWidget *src_widget,
parent = src_widget;
while (parent != ancestor)
{
GtkAllocation content_alloc;
int origin_x, origin_y;
gtk_widget_get_content_allocation (parent, &content_alloc);
gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
src_x += content_alloc.x;
src_y += content_alloc.y;
src_x += origin_x;
src_y += origin_y;
parent = _gtk_widget_get_parent (parent);
}
@ -5698,12 +5722,12 @@ gtk_widget_translate_coordinates (GtkWidget *src_widget,
parent = dest_widget;
while (parent != ancestor)
{
GtkAllocation content_alloc;
int origin_x, origin_y;
gtk_widget_get_content_allocation (parent, &content_alloc);
gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
src_x -= content_alloc.x;
src_y -= content_alloc.y;
src_x -= origin_x;
src_y -= origin_y;
parent = _gtk_widget_get_parent (parent);
}
@ -13229,18 +13253,6 @@ void
gtk_widget_get_content_size (GtkWidget *widget,
int *width,
int *height)
{
GtkAllocation alloc;
gtk_widget_get_content_allocation (widget, &alloc);
*width = alloc.width;
*height = alloc.height;
}
void
gtk_widget_get_content_allocation (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GtkBorder margin, border, padding;
@ -13251,14 +13263,13 @@ gtk_widget_get_content_allocation (GtkWidget *widget,
get_box_border (style, &border);
get_box_padding (style, &padding);
*allocation = priv->allocation;
*width = priv->allocation.width;
*height = priv->allocation.height;
allocation->x += margin.left + border.left + padding.left;
allocation->y += margin.top + border.top + padding.top;
allocation->width -= margin.left + border.left + padding.left +
margin.right + border.right + padding.right;
allocation->height -= margin.top + border.top + padding.top +
margin.bottom + border.bottom + padding.bottom;
*width -= margin.left + border.left + padding.left +
margin.right + border.right + padding.right;
*height -= margin.top + border.top + padding.top +
margin.bottom + border.bottom + padding.bottom;
}
void

View File

@ -314,8 +314,6 @@ void gtk_widget_focus_sort (GtkWidget *wi
gboolean gtk_widget_focus_move (GtkWidget *widget,
GtkDirectionType direction,
GPtrArray *focus_order);
void gtk_widget_get_content_allocation (GtkWidget *widget,
GtkAllocation *allocation);
void gtk_widget_get_border_allocation (GtkWidget *widget,
GtkAllocation *allocation);
void gtk_widget_get_outer_allocation (GtkWidget *widget,