Commit 55a98da4 authored by Rob Bradford's avatar Rob Bradford Committed by Matthias Clasen

window: Allow _gtk_window_set_allocation to return a modified allocation

Update the documentation and users of this function to handle
the future case that that we have some internal decorations to the window and
useable allocation is thus smaller.

By having a separate out parameter there is no need to have an in/out function
and allows for greater robustness.

The current implementation simply returns the allocation provided.
parent 026d47d9
......@@ -703,13 +703,17 @@ gtk_application_window_real_size_allocate (GtkWidget *widget,
if (window->priv->menubar != NULL)
{
GtkAllocation menubar_allocation = *allocation;
GtkAllocation menubar_allocation;
GtkAllocation child_allocation;
gint menubar_height;
GtkWidget *child;
_gtk_window_set_allocation (GTK_WINDOW (widget), allocation);
_gtk_window_set_allocation (GTK_WINDOW (widget), allocation, &child_allocation);
menubar_allocation = child_allocation;
gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_height, NULL);
gtk_widget_get_preferred_height_for_width (window->priv->menubar,
menubar_allocation.width,
&menubar_height, NULL);
menubar_allocation.height = menubar_height;
gtk_widget_size_allocate (window->priv->menubar, &menubar_allocation);
......@@ -717,7 +721,6 @@ gtk_application_window_real_size_allocate (GtkWidget *widget,
child = gtk_bin_get_child (GTK_BIN (window));
if (child != NULL && gtk_widget_get_visible (child))
{
GtkAllocation child_allocation = *allocation;
gint border_width;
border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
......
......@@ -5504,7 +5504,9 @@ set_grip_position (GtkWindow *window)
/* _gtk_window_set_allocation:
* @window: a #GtkWindow
* @allocation: the new allocation
* @allocation: the original allocation for the window
* @allocation_out: @allocation taking decorations into
* consideration
*
* This function is like gtk_widget_set_allocation()
* but does the necessary extra work to update
......@@ -5513,13 +5515,22 @@ set_grip_position (GtkWindow *window)
* Call this instead of gtk_widget_set_allocation()
* when overriding ::size_allocate in a GtkWindow
* subclass without chaining up.
*
* The @allocation parameter will be adjusted to
* reflect any internal decorations that the window
* may have. That revised allocation will then be
* returned in the @allocation_out parameter.
*/
void
_gtk_window_set_allocation (GtkWindow *window,
GtkAllocation *allocation)
_gtk_window_set_allocation (GtkWindow *window,
const GtkAllocation *allocation,
GtkAllocation *allocation_out)
{
GtkWidget *widget = (GtkWidget *)window;
g_assert (allocation != NULL);
g_assert (allocation_out != NULL);
gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
......@@ -5539,6 +5550,8 @@ _gtk_window_set_allocation (GtkWindow *window,
set_grip_position (window);
}
}
*allocation_out = *allocation;
}
static void
......@@ -5550,16 +5563,16 @@ gtk_window_size_allocate (GtkWidget *widget,
GtkWidget *child;
guint border_width;
_gtk_window_set_allocation (window, allocation);
_gtk_window_set_allocation (window, allocation, &child_allocation);
child = gtk_bin_get_child (&(window->bin));
if (child && gtk_widget_get_visible (child))
{
border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
child_allocation.x = border_width;
child_allocation.y = border_width;
child_allocation.width = MAX (1, allocation->width - border_width * 2);
child_allocation.height = MAX (1, allocation->height - border_width * 2);
child_allocation.x += border_width;
child_allocation.y += border_width;
child_allocation.width = MAX (1, child_allocation.width - border_width * 2);
child_allocation.height = MAX (1, child_allocation.height - border_width * 2);
gtk_widget_size_allocate (child, &child_allocation);
}
......
......@@ -66,8 +66,9 @@ void _gtk_window_get_wmclass (GtkWindow *window,
gchar **wmclass_name,
gchar **wmclass_class);
void _gtk_window_set_allocation (GtkWindow *window,
GtkAllocation *allocation);
void _gtk_window_set_allocation (GtkWindow *window,
const GtkAllocation *allocation,
GtkAllocation *allocation_out);
typedef void (*GtkWindowKeysForeachFunc) (GtkWindow *window,
guint keyval,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment