[gimp] libgimpwidgets: add properties GimpColorButton:area-width and :area-height



commit 31b4d3801e756cf0c4571aa7a4d73c0674f482b3
Author: Michael Natterer <mitch gimp org>
Date:   Tue Feb 15 20:54:52 2011 +0100

    libgimpwidgets: add properties GimpColorButton:area-width and :area-height

 app/widgets/gimpcolorpanel.c     |   22 ++++++-------
 libgimpwidgets/gimpcolorbutton.c |   67 ++++++++++++++++++++++++++++++-------
 2 files changed, 64 insertions(+), 25 deletions(-)
---
diff --git a/app/widgets/gimpcolorpanel.c b/app/widgets/gimpcolorpanel.c
index b77a80f..2b7bb9c 100644
--- a/app/widgets/gimpcolorpanel.c
+++ b/app/widgets/gimpcolorpanel.c
@@ -196,20 +196,18 @@ gimp_color_panel_new (const gchar       *title,
                       gint               width,
                       gint               height)
 {
-  GimpColorPanel *panel;
-
   g_return_val_if_fail (title != NULL, NULL);
   g_return_val_if_fail (color != NULL, NULL);
-
-  panel = g_object_new (GIMP_TYPE_COLOR_PANEL,
-                        "title", title,
-                        "type",  type,
-                        "color", color,
-                        NULL);
-
-  gtk_widget_set_size_request (GTK_WIDGET (panel), width, height);
-
-  return GTK_WIDGET (panel);
+  g_return_val_if_fail (width > 0, NULL);
+  g_return_val_if_fail (height > 0, NULL);
+
+  return g_object_new (GIMP_TYPE_COLOR_PANEL,
+                       "title",       title,
+                       "type",        type,
+                       "color",       color,
+                       "area-width",  width,
+                       "area-height", height,
+                       NULL);
 }
 
 static void
diff --git a/libgimpwidgets/gimpcolorbutton.c b/libgimpwidgets/gimpcolorbutton.c
index aa873a4..e9c67c7 100644
--- a/libgimpwidgets/gimpcolorbutton.c
+++ b/libgimpwidgets/gimpcolorbutton.c
@@ -82,7 +82,9 @@ enum
   PROP_TITLE,
   PROP_COLOR,
   PROP_TYPE,
-  PROP_UPDATE
+  PROP_UPDATE,
+  PROP_AREA_WIDTH,
+  PROP_AREA_HEIGHT
 };
 
 
@@ -263,6 +265,34 @@ gimp_color_button_class_init (GimpColorButtonClass *klass)
                                                          FALSE,
                                                          G_PARAM_READWRITE |
                                                          G_PARAM_CONSTRUCT));
+
+  /**
+   * GimpColorButton:area-width:
+   *
+   * The minimum width of the button's #GimpColorArea.
+   *
+   * Since: GIMP 2.8
+   */
+  g_object_class_install_property (object_class, PROP_AREA_WIDTH,
+                                   g_param_spec_int ("area-width",
+                                                     NULL, NULL,
+                                                     1, G_MAXINT, 16,
+                                                     G_PARAM_WRITABLE |
+                                                     G_PARAM_CONSTRUCT));
+
+  /**
+   * GimpColorButton:area-height:
+   *
+   * The minimum height of the button's #GimpColorArea.
+   *
+   * Since: GIMP 2.8
+   */
+  g_object_class_install_property (object_class, PROP_AREA_HEIGHT,
+                                   g_param_spec_int ("area-height",
+                                                     NULL, NULL,
+                                                     1, G_MAXINT, 16,
+                                                     G_PARAM_WRITABLE |
+                                                     G_PARAM_CONSTRUCT));
 }
 
 static void
@@ -412,6 +442,7 @@ gimp_color_button_set_property (GObject      *object,
                                 GParamSpec   *pspec)
 {
   GimpColorButton *button = GIMP_COLOR_BUTTON (object);
+  gint             other;
 
   switch (property_id)
     {
@@ -432,6 +463,18 @@ gimp_color_button_set_property (GObject      *object,
       gimp_color_button_set_update (button, g_value_get_boolean (value));
       break;
 
+    case PROP_AREA_WIDTH:
+      gtk_widget_get_size_request (button->color_area, NULL, &other);
+      gtk_widget_set_size_request (button->color_area,
+                                   g_value_get_int (value), other);
+      break;
+
+    case PROP_AREA_HEIGHT:
+      gtk_widget_get_size_request (button->color_area, &other, NULL);
+      gtk_widget_set_size_request (button->color_area,
+                                   other, g_value_get_int (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -568,19 +611,17 @@ gimp_color_button_new (const gchar       *title,
                        const GimpRGB     *color,
                        GimpColorAreaType  type)
 {
-  GimpColorButton *button;
-
   g_return_val_if_fail (color != NULL, NULL);
-
-  button = g_object_new (GIMP_TYPE_COLOR_BUTTON,
-                         "title", title,
-                         "type",  type,
-                         "color", color,
-                         NULL);
-
-  gtk_widget_set_size_request (GTK_WIDGET (button->color_area), width, height);
-
-  return GTK_WIDGET (button);
+  g_return_val_if_fail (width > 0, NULL);
+  g_return_val_if_fail (height > 0, NULL);
+
+  return g_object_new (GIMP_TYPE_COLOR_BUTTON,
+                       "title",       title,
+                       "type",        type,
+                       "color",       color,
+                       "area-width",  width,
+                       "area-height", height,
+                       NULL);
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]