[gimp/gtk3-port: 134/215] app: implement proper height-for-width in GimpToolPalette
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 134/215] app: implement proper height-for-width in GimpToolPalette
- Date: Mon, 3 Jan 2011 15:09:39 +0000 (UTC)
commit 6d5dfba5c0f9127f22bfc057b96f179d8422665a
Author: Michael Natterer <mitch gimp org>
Date: Mon Nov 22 11:17:15 2010 +0100
app: implement proper height-for-width in GimpToolPalette
app/widgets/gimptoolpalette.c | 88 ++++++++++++++++++++++++++++++----------
1 files changed, 66 insertions(+), 22 deletions(-)
---
diff --git a/app/widgets/gimptoolpalette.c b/app/widgets/gimptoolpalette.c
index 219f417..c646601 100644
--- a/app/widgets/gimptoolpalette.c
+++ b/app/widgets/gimptoolpalette.c
@@ -81,8 +81,18 @@ static void gimp_tool_palette_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
-static void gimp_tool_palette_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
+static GtkSizeRequestMode
+ gimp_tool_palette_get_request_mode (GtkWidget *widget);
+static void gimp_tool_palette_get_preferred_width (GtkWidget *widget,
+ gint *min_width,
+ gint *pref_width);
+static void gimp_tool_palette_get_preferred_height(GtkWidget *widget,
+ gint *min_width,
+ gint *pref_width);
+static void gimp_tool_palette_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *min_width,
+ gint *pref_width);
static void gimp_tool_palette_style_set (GtkWidget *widget,
GtkStyle *previous_style);
@@ -114,13 +124,16 @@ gimp_tool_palette_class_init (GimpToolPaletteClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->constructed = gimp_tool_palette_constructed;
- object_class->dispose = gimp_tool_palette_dispose;
- object_class->set_property = gimp_tool_palette_set_property;
- object_class->get_property = gimp_tool_palette_get_property;
+ object_class->constructed = gimp_tool_palette_constructed;
+ object_class->dispose = gimp_tool_palette_dispose;
+ object_class->set_property = gimp_tool_palette_set_property;
+ object_class->get_property = gimp_tool_palette_get_property;
- widget_class->size_allocate = gimp_tool_palette_size_allocate;
- widget_class->style_set = gimp_tool_palette_style_set;
+ widget_class->get_request_mode = gimp_tool_palette_get_request_mode;
+ widget_class->get_preferred_width = gimp_tool_palette_get_preferred_width;
+ widget_class->get_preferred_height = gimp_tool_palette_get_preferred_height;
+ widget_class->get_preferred_height_for_width = gimp_tool_palette_height_for_width;
+ widget_class->style_set = gimp_tool_palette_style_set;
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("context",
@@ -343,16 +356,52 @@ gimp_tool_palette_get_property (GObject *object,
}
}
+static GtkSizeRequestMode
+gimp_tool_palette_get_request_mode (GtkWidget *widget)
+{
+ return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+}
+
+static void
+gimp_tool_palette_get_preferred_width (GtkWidget *widget,
+ gint *min_width,
+ gint *pref_width)
+{
+ gint button_width;
+ gint button_height;
+
+ if (gimp_tool_palette_get_button_size (GIMP_TOOL_PALETTE (widget),
+ &button_width, &button_height))
+ {
+ *min_width = *pref_width = button_width;
+ }
+}
+
static void
-gimp_tool_palette_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+gimp_tool_palette_get_preferred_height (GtkWidget *widget,
+ gint *min_height,
+ gint *pref_height)
+{
+ gint button_width;
+ gint button_height;
+
+ if (gimp_tool_palette_get_button_size (GIMP_TOOL_PALETTE (widget),
+ &button_width, &button_height))
+ {
+ *min_height = *pref_height = button_height;
+ }
+}
+
+static void
+gimp_tool_palette_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *min_height,
+ gint *pref_height)
{
GimpToolPalettePrivate *private = GET_PRIVATE (widget);
gint button_width;
gint button_height;
- GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
-
if (gimp_tool_palette_get_button_size (GIMP_TOOL_PALETTE (widget),
&button_width, &button_height))
{
@@ -372,21 +421,16 @@ gimp_tool_palette_size_allocate (GtkWidget *widget,
n_tools++;
}
- tool_columns = MAX (1, (allocation->width / button_width));
+ tool_columns = MAX (1, width / button_width);
tool_rows = n_tools / tool_columns;
if (n_tools % tool_columns)
tool_rows++;
- if (private->tool_rows != tool_rows ||
- private->tool_columns != tool_columns)
- {
- private->tool_rows = tool_rows;
- private->tool_columns = tool_columns;
+ private->tool_rows = tool_rows;
+ private->tool_columns = tool_columns;
- gtk_widget_set_size_request (widget, -1,
- tool_rows * button_height);
- }
+ *min_height = *pref_height = tool_rows * button_height;
}
}
@@ -472,7 +516,7 @@ gimp_tool_palette_get_button_size (GimpToolPalette *palette,
{
GtkRequisition button_requisition;
- gtk_widget_size_request (tool_button, &button_requisition);
+ gtk_widget_get_preferred_size (tool_button, &button_requisition, NULL);
*width = button_requisition.width;
*height = button_requisition.height;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]