[gnome-builder/wip/chergert/perspective] egg: add box with max-width-request



commit 1c8c362fa021476b154498a591ae31ace97edc70
Author: Christian Hergert <chergert redhat com>
Date:   Sun Nov 29 01:25:50 2015 -0800

    egg: add box with max-width-request
    
    Until gtk gets this on GtkWidget, we could use this to help with some
    sizing stuff.

 contrib/egg/Makefile.am |    2 +
 contrib/egg/egg-box.c   |  130 +++++++++++++++++++++++++++++++++++++++++++++++
 contrib/egg/egg-box.h   |   42 +++++++++++++++
 3 files changed, 174 insertions(+), 0 deletions(-)
---
diff --git a/contrib/egg/Makefile.am b/contrib/egg/Makefile.am
index 63761d4..e6dc1fb 100644
--- a/contrib/egg/Makefile.am
+++ b/contrib/egg/Makefile.am
@@ -11,6 +11,8 @@ libegg_private_la_SOURCES = \
        egg-animation.h \
        egg-binding-group.c \
        egg-binding-group.h \
+       egg-box.c \
+       egg-box.h \
        egg-centering-bin.c \
        egg-centering-bin.h \
        egg-counter.c \
diff --git a/contrib/egg/egg-box.c b/contrib/egg/egg-box.c
new file mode 100644
index 0000000..edc4fd7
--- /dev/null
+++ b/contrib/egg/egg-box.c
@@ -0,0 +1,130 @@
+/* egg-box.c
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "egg-box.h"
+
+typedef struct
+{
+  gint max_width_request;
+} EggBoxPrivate;
+
+enum {
+  PROP_0,
+  PROP_MAX_WIDTH_REQUEST,
+  LAST_PROP
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (EggBox, egg_box, GTK_TYPE_BOX)
+
+static GParamSpec *properties [LAST_PROP];
+
+static void
+egg_box_get_preferred_width (GtkWidget *widget,
+                             gint      *min_width,
+                             gint      *nat_width)
+{
+  EggBox *self = (EggBox *)widget;
+  EggBoxPrivate *priv = egg_box_get_instance_private (self);
+
+  g_assert (EGG_IS_BOX (self));
+
+  GTK_WIDGET_CLASS (egg_box_parent_class)->get_preferred_width (widget, min_width, nat_width);
+
+  if (priv->max_width_request > 0)
+    {
+      if (*min_width > priv->max_width_request)
+        *min_width = priv->max_width_request;
+
+      if (*nat_width > priv->max_width_request)
+        *nat_width = priv->max_width_request;
+    }
+}
+
+static void
+egg_box_get_property (GObject    *object,
+                      guint       prop_id,
+                      GValue     *value,
+                      GParamSpec *pspec)
+{
+  EggBox *self = EGG_BOX (object);
+  EggBoxPrivate *priv = egg_box_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_MAX_WIDTH_REQUEST:
+      g_value_set_int (value, priv->max_width_request);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+egg_box_set_property (GObject      *object,
+                      guint         prop_id,
+                      const GValue *value,
+                      GParamSpec   *pspec)
+{
+  EggBox *self = EGG_BOX (object);
+  EggBoxPrivate *priv = egg_box_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_MAX_WIDTH_REQUEST:
+      priv->max_width_request = g_value_get_int (value);
+      gtk_widget_queue_resize (GTK_WIDGET (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+egg_box_class_init (EggBoxClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->get_property = egg_box_get_property;
+  object_class->set_property = egg_box_set_property;
+
+  widget_class->get_preferred_width = egg_box_get_preferred_width;
+
+  properties [PROP_MAX_WIDTH_REQUEST] =
+    g_param_spec_int ("max-width-request",
+                      "Max Width Request",
+                      "Max Width Request",
+                      -1,
+                      G_MAXINT,
+                      -1,
+                      (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, LAST_PROP, properties);
+}
+
+static void
+egg_box_init (EggBox *self)
+{
+  EggBoxPrivate *priv = egg_box_get_instance_private (self);
+
+  priv->max_width_request = -1;
+}
diff --git a/contrib/egg/egg-box.h b/contrib/egg/egg-box.h
new file mode 100644
index 0000000..a8718cf
--- /dev/null
+++ b/contrib/egg/egg-box.h
@@ -0,0 +1,42 @@
+/* egg-box.h
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EGG_BOX_H
+#define EGG_BOX_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EGG_TYPE_BOX (egg_box_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (EggBox, egg_box, EGG, BOX, GtkBox)
+
+struct _EggBoxClass
+{
+  GtkBoxClass parent_class;
+};
+
+GtkWidget *egg_box_new                   (void);
+gint       egg_box_get_max_width_request (EggBox *self);
+void       egg_box_set_max_width_request (EggBox *self,
+                                          gint    max_width_request);
+
+G_END_DECLS
+
+#endif /* EGG_BOX_H */


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