[gimp/gtk3-port: 96/232] 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: 96/232] app: implement proper height-for-width in GimpToolPalette
- Date: Sun, 11 Feb 2018 17:01:06 +0000 (UTC)
commit dabef165e8d9836c6ab8149a50c01aeaee3473d8
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 | 83 +++++++++++++++++++++++++++++++---------
1 files changed, 64 insertions(+), 19 deletions(-)
---
diff --git a/app/widgets/gimptoolpalette.c b/app/widgets/gimptoolpalette.c
index cab8ffa..d07844f 100644
--- a/app/widgets/gimptoolpalette.c
+++ b/app/widgets/gimptoolpalette.c
@@ -66,8 +66,19 @@ struct _GimpToolPalettePrivate
static void gimp_tool_palette_dispose (GObject *object);
-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);
static void gimp_tool_palette_hierarchy_changed (GtkWidget *widget,
@@ -103,9 +114,12 @@ gimp_tool_palette_class_init (GimpToolPaletteClass *klass)
object_class->dispose = gimp_tool_palette_dispose;
- widget_class->size_allocate = gimp_tool_palette_size_allocate;
- widget_class->style_set = gimp_tool_palette_style_set;
- widget_class->hierarchy_changed = gimp_tool_palette_hierarchy_changed;
+ 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;
+ widget_class->hierarchy_changed = gimp_tool_palette_hierarchy_changed;
gtk_widget_class_install_style_property (widget_class,
g_param_spec_enum ("tool-icon-size",
@@ -130,6 +144,27 @@ gimp_tool_palette_init (GimpToolPalette *palette)
gtk_tool_palette_set_style (GTK_TOOL_PALETTE (palette), GTK_TOOLBAR_ICONS);
}
+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_dispose (GObject *object)
{
@@ -149,15 +184,30 @@ gimp_tool_palette_dispose (GObject *object)
}
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))
{
@@ -177,21 +227,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;
}
}
@@ -410,7 +455,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]