GtkApplicationWindow: Fix resize grip positioning

Based on a patch by Carlos Garcia Campos, bug 668248
This commit is contained in:
Matthias Clasen 2012-01-20 01:01:08 -05:00
parent 4b7ec2be82
commit 681871dd9e
3 changed files with 49 additions and 26 deletions

View File

@ -24,6 +24,7 @@
#include "gtkapplicationwindow.h"
#include "gtkapplicationprivate.h"
#include "gtkwindowprivate.h"
#include "gtkmodelmenu.h"
#include "gactionmuxer.h"
#include "gtkaccelgroup.h"
@ -635,7 +636,7 @@ gtk_application_window_real_size_allocate (GtkWidget *widget,
gint menubar_height;
GtkWidget *child;
gtk_widget_set_allocation (widget, allocation);
_gtk_window_set_allocation (GTK_WINDOW (widget), allocation);
gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_height, NULL);

View File

@ -5530,34 +5530,55 @@ set_grip_position (GtkWindow *window)
rect.width, rect.height);
}
/* _gtk_window_set_allocation:
* @window: a #GtkWindow
* @allocation: the new allocation
*
* This function is like gtk_widget_set_allocation()
* but does the necessary extra work to update
* the resize grip positioning, etc.
*
* Call this instead of gtk_widget_set_allocation()
* when overriding ::size_allocate in a GtkWindow
* subclass without chaining up.
*/
void
_gtk_window_set_allocation (GtkWindow *window,
GtkAllocation *allocation)
{
GtkWidget *widget = (GtkWidget *)window;
gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
{
/* If it's not a toplevel we're embedded, we need to resize
* the window's window and skip the grip.
*/
if (!gtk_widget_is_toplevel (widget))
{
gdk_window_move_resize (gtk_widget_get_window (widget),
allocation->x, allocation->y,
allocation->width, allocation->height);
}
else
{
update_grip_visibility (window);
set_grip_position (window);
}
}
}
static void
gtk_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
GtkAllocation *allocation)
{
GtkWindow *window = GTK_WINDOW (widget);
GtkAllocation child_allocation;
GtkWidget *child;
guint border_width;
gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
{
/* If it's not a toplevel we're embedded, we need to resize the window's
* window and skip the grip.
*/
if (!gtk_widget_is_toplevel (widget))
{
gdk_window_move_resize (gtk_widget_get_window (widget),
allocation->x, allocation->y,
allocation->width, allocation->height);
}
else
{
update_grip_visibility (window);
set_grip_position (window);
}
}
_gtk_window_set_allocation (window, allocation);
child = gtk_bin_get_child (&(window->bin));
if (child && gtk_widget_get_visible (child))
@ -5565,10 +5586,8 @@ gtk_window_size_allocate (GtkWidget *widget,
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, (gint)allocation->width - child_allocation.x * 2);
child_allocation.height =
MAX (1, (gint)allocation->height - child_allocation.y * 2);
child_allocation.width = MAX (1, allocation->width - border_width * 2);
child_allocation.height = MAX (1, allocation->height - border_width * 2);
gtk_widget_size_allocate (child, &child_allocation);
}
@ -5904,7 +5923,7 @@ gtk_window_get_has_resize_grip (GtkWindow *window)
* Since: 3.0
*/
gboolean
gtk_window_get_resize_grip_area (GtkWindow *window,
gtk_window_get_resize_grip_area (GtkWindow *window,
GdkRectangle *rect)
{
GtkWidget *widget = GTK_WIDGET (window);

View File

@ -68,6 +68,9 @@ void _gtk_window_get_wmclass (GtkWindow *window,
gchar **wmclass_name,
gchar **wmclass_class);
void _gtk_window_set_allocation (GtkWindow *window,
GtkAllocation *allocation);
typedef void (*GtkWindowKeysForeachFunc) (GtkWindow *window,
guint keyval,
GdkModifierType modifiers,