mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
Prepare for the demise of size_request
The size_request vfunc is going to be dropped in GTK3; replace the usage in MetaAccelLabel and MetaPreview with get_preferred_width/get_preferred_height vfuncs. https://bugzilla.gnome.org/show_bug.cgi?id=633352
This commit is contained in:
parent
1114e5effa
commit
02e709e89e
@ -39,8 +39,12 @@
|
|||||||
|
|
||||||
static void meta_accel_label_destroy (GtkWidget *object);
|
static void meta_accel_label_destroy (GtkWidget *object);
|
||||||
static void meta_accel_label_finalize (GObject *object);
|
static void meta_accel_label_finalize (GObject *object);
|
||||||
static void meta_accel_label_size_request (GtkWidget *widget,
|
static void meta_accel_label_get_preferred_width (GtkWidget *widget,
|
||||||
GtkRequisition *requisition);
|
gint *minimum,
|
||||||
|
gint *natural);
|
||||||
|
static void meta_accel_label_get_preferred_height (GtkWidget *widget,
|
||||||
|
gint *minimum,
|
||||||
|
gint *natural);
|
||||||
static gboolean meta_accel_label_draw (GtkWidget *widget,
|
static gboolean meta_accel_label_draw (GtkWidget *widget,
|
||||||
cairo_t *cr);
|
cairo_t *cr);
|
||||||
|
|
||||||
@ -59,7 +63,8 @@ meta_accel_label_class_init (MetaAccelLabelClass *class)
|
|||||||
|
|
||||||
widget_class->destroy = meta_accel_label_destroy;
|
widget_class->destroy = meta_accel_label_destroy;
|
||||||
|
|
||||||
widget_class->size_request = meta_accel_label_size_request;
|
widget_class->get_preferred_width = meta_accel_label_get_preferred_width;
|
||||||
|
widget_class->get_preferred_height = meta_accel_label_get_preferred_height;
|
||||||
widget_class->draw = meta_accel_label_draw;
|
widget_class->draw = meta_accel_label_draw;
|
||||||
|
|
||||||
class->signal_quote1 = g_strdup ("<:");
|
class->signal_quote1 = g_strdup ("<:");
|
||||||
@ -205,15 +210,15 @@ meta_accel_label_get_accel_width (MetaAccelLabel *accel_label)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_accel_label_size_request (GtkWidget *widget,
|
meta_accel_label_get_preferred_width (GtkWidget *widget,
|
||||||
GtkRequisition *requisition)
|
gint *minimum,
|
||||||
|
gint *natural)
|
||||||
{
|
{
|
||||||
MetaAccelLabel *accel_label = META_ACCEL_LABEL (widget);
|
MetaAccelLabel *accel_label = META_ACCEL_LABEL (widget);
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
gint width;
|
gint width;
|
||||||
|
|
||||||
if (GTK_WIDGET_CLASS (meta_accel_label_parent_class)->size_request)
|
GTK_WIDGET_CLASS (meta_accel_label_parent_class)->get_preferred_width (widget, minimum, natural);
|
||||||
GTK_WIDGET_CLASS (meta_accel_label_parent_class)->size_request (widget, requisition);
|
|
||||||
|
|
||||||
layout = gtk_widget_create_pango_layout (widget, accel_label->accel_string);
|
layout = gtk_widget_create_pango_layout (widget, accel_label->accel_string);
|
||||||
pango_layout_get_pixel_size (layout, &width, NULL);
|
pango_layout_get_pixel_size (layout, &width, NULL);
|
||||||
@ -222,6 +227,14 @@ meta_accel_label_size_request (GtkWidget *widget,
|
|||||||
g_object_unref (G_OBJECT (layout));
|
g_object_unref (G_OBJECT (layout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
meta_accel_label_get_preferred_height (GtkWidget *widget,
|
||||||
|
gint *minimum,
|
||||||
|
gint *natural)
|
||||||
|
{
|
||||||
|
GTK_WIDGET_CLASS (meta_accel_label_parent_class)->get_preferred_height (widget, minimum, natural);
|
||||||
|
}
|
||||||
|
|
||||||
/* Mostly taken from GTK3. */
|
/* Mostly taken from GTK3. */
|
||||||
static gboolean
|
static gboolean
|
||||||
meta_accel_label_draw (GtkWidget *widget,
|
meta_accel_label_draw (GtkWidget *widget,
|
||||||
|
@ -28,8 +28,12 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "preview-widget.h"
|
#include "preview-widget.h"
|
||||||
|
|
||||||
static void meta_preview_size_request (GtkWidget *widget,
|
static void meta_preview_get_preferred_width (GtkWidget *widget,
|
||||||
GtkRequisition *req);
|
gint *minimum,
|
||||||
|
gint *natural);
|
||||||
|
static void meta_preview_get_preferred_height (GtkWidget *widget,
|
||||||
|
gint *minimum,
|
||||||
|
gint *natural);
|
||||||
static void meta_preview_size_allocate (GtkWidget *widget,
|
static void meta_preview_size_allocate (GtkWidget *widget,
|
||||||
GtkAllocation *allocation);
|
GtkAllocation *allocation);
|
||||||
static gboolean meta_preview_draw (GtkWidget *widget,
|
static gboolean meta_preview_draw (GtkWidget *widget,
|
||||||
@ -49,8 +53,11 @@ meta_preview_class_init (MetaPreviewClass *class)
|
|||||||
gobject_class->finalize = meta_preview_finalize;
|
gobject_class->finalize = meta_preview_finalize;
|
||||||
|
|
||||||
widget_class->draw = meta_preview_draw;
|
widget_class->draw = meta_preview_draw;
|
||||||
widget_class->size_request = meta_preview_size_request;
|
widget_class->get_preferred_width = meta_preview_get_preferred_width;
|
||||||
|
widget_class->get_preferred_height = meta_preview_get_preferred_height;
|
||||||
widget_class->size_allocate = meta_preview_size_allocate;
|
widget_class->size_allocate = meta_preview_size_allocate;
|
||||||
|
|
||||||
|
gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (class));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -194,7 +201,6 @@ meta_preview_draw (GtkWidget *widget,
|
|||||||
|
|
||||||
if (preview->theme)
|
if (preview->theme)
|
||||||
{
|
{
|
||||||
int border_width;
|
|
||||||
int client_width;
|
int client_width;
|
||||||
int client_height;
|
int client_height;
|
||||||
MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
|
MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
|
||||||
@ -208,11 +214,8 @@ meta_preview_draw (GtkWidget *widget,
|
|||||||
ensure_info (preview);
|
ensure_info (preview);
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
|
|
||||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
client_width = allocation.width - preview->left_width - preview->right_width;
|
||||||
cairo_translate (cr, border_width, border_width);
|
client_height = allocation.height - preview->top_height - preview->bottom_height;
|
||||||
|
|
||||||
client_width = allocation.width - preview->left_width - preview->right_width - border_width * 2;
|
|
||||||
client_height = allocation.height - preview->top_height - preview->bottom_height - border_width * 2;
|
|
||||||
|
|
||||||
if (client_width < 0)
|
if (client_width < 0)
|
||||||
client_width = 1;
|
client_width = 1;
|
||||||
@ -239,42 +242,69 @@ meta_preview_draw (GtkWidget *widget,
|
|||||||
return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr);
|
return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NO_CHILD_WIDTH 80
|
||||||
|
#define NO_CHILD_HEIGHT 20
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_preview_size_request (GtkWidget *widget,
|
meta_preview_get_preferred_width (GtkWidget *widget,
|
||||||
GtkRequisition *req)
|
gint *minimum,
|
||||||
|
gint *natural)
|
||||||
{
|
{
|
||||||
MetaPreview *preview;
|
MetaPreview *preview;
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
guint border_width;
|
|
||||||
|
|
||||||
preview = META_PREVIEW (widget);
|
preview = META_PREVIEW (widget);
|
||||||
|
|
||||||
ensure_info (preview);
|
ensure_info (preview);
|
||||||
|
|
||||||
req->width = preview->left_width + preview->right_width;
|
*minimum = *natural = preview->left_width + preview->right_width;
|
||||||
req->height = preview->top_height + preview->bottom_height;
|
|
||||||
|
|
||||||
child = gtk_bin_get_child (GTK_BIN (preview));
|
child = gtk_bin_get_child (GTK_BIN (preview));
|
||||||
if (child && gtk_widget_get_visible (child))
|
if (child && gtk_widget_get_visible (child))
|
||||||
{
|
{
|
||||||
GtkRequisition child_requisition;
|
gint child_min, child_nat;
|
||||||
|
|
||||||
gtk_widget_size_request (child, &child_requisition);
|
gtk_widget_get_preferred_width (child, &child_min, &child_nat);
|
||||||
|
|
||||||
req->width += child_requisition.width;
|
*minimum += child_min;
|
||||||
req->height += child_requisition.height;
|
*natural += child_nat;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#define NO_CHILD_WIDTH 80
|
*minimum += NO_CHILD_WIDTH;
|
||||||
#define NO_CHILD_HEIGHT 20
|
*natural += NO_CHILD_WIDTH;
|
||||||
req->width += NO_CHILD_WIDTH;
|
|
||||||
req->height += NO_CHILD_HEIGHT;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
static void
|
||||||
req->width += border_width * 2;
|
meta_preview_get_preferred_height (GtkWidget *widget,
|
||||||
req->height += border_width * 2;
|
gint *minimum,
|
||||||
|
gint *natural)
|
||||||
|
{
|
||||||
|
MetaPreview *preview;
|
||||||
|
GtkWidget *child;
|
||||||
|
|
||||||
|
preview = META_PREVIEW (widget);
|
||||||
|
|
||||||
|
ensure_info (preview);
|
||||||
|
|
||||||
|
*minimum = *natural = preview->top_height + preview->bottom_height;
|
||||||
|
|
||||||
|
child = gtk_bin_get_child (GTK_BIN (preview));
|
||||||
|
if (child && gtk_widget_get_visible (child))
|
||||||
|
{
|
||||||
|
gint child_min, child_nat;
|
||||||
|
|
||||||
|
gtk_widget_get_preferred_height (child, &child_min, &child_nat);
|
||||||
|
|
||||||
|
*minimum += child_min;
|
||||||
|
*natural += child_nat;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*minimum += NO_CHILD_HEIGHT;
|
||||||
|
*natural += NO_CHILD_HEIGHT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -284,7 +314,6 @@ meta_preview_size_allocate (GtkWidget *widget,
|
|||||||
MetaPreview *preview;
|
MetaPreview *preview;
|
||||||
GtkAllocation widget_allocation, child_allocation;
|
GtkAllocation widget_allocation, child_allocation;
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
guint border_width;
|
|
||||||
|
|
||||||
preview = META_PREVIEW (widget);
|
preview = META_PREVIEW (widget);
|
||||||
|
|
||||||
@ -292,17 +321,15 @@ meta_preview_size_allocate (GtkWidget *widget,
|
|||||||
|
|
||||||
gtk_widget_set_allocation (widget, allocation);
|
gtk_widget_set_allocation (widget, allocation);
|
||||||
|
|
||||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
|
||||||
|
|
||||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||||
if (child && gtk_widget_get_visible (child))
|
if (child && gtk_widget_get_visible (child))
|
||||||
{
|
{
|
||||||
gtk_widget_get_allocation (widget, &widget_allocation);
|
gtk_widget_get_allocation (widget, &widget_allocation);
|
||||||
child_allocation.x = widget_allocation.x + border_width + preview->left_width;
|
child_allocation.x = widget_allocation.x + preview->left_width;
|
||||||
child_allocation.y = widget_allocation.y + border_width + preview->top_height;
|
child_allocation.y = widget_allocation.y + preview->top_height;
|
||||||
|
|
||||||
child_allocation.width = MAX (1, widget_allocation.width - border_width * 2 - preview->left_width - preview->right_width);
|
child_allocation.width = MAX (1, widget_allocation.width - preview->left_width - preview->right_width);
|
||||||
child_allocation.height = MAX (1, widget_allocation.height - border_width * 2 - preview->top_height - preview->bottom_height);
|
child_allocation.height = MAX (1, widget_allocation.height - preview->top_height - preview->bottom_height);
|
||||||
|
|
||||||
gtk_widget_size_allocate (child, &child_allocation);
|
gtk_widget_size_allocate (child, &child_allocation);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user