[gnome-initial-setup] Add a GisCenterContainer



commit 41313308adaafb98d55429641811eb6ac41b572b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Mar 18 17:36:06 2013 -0400

    Add a GisCenterContainer

 gnome-initial-setup/Makefile.am            |    1 +
 gnome-initial-setup/gis-assistant.c        |   13 +-
 gnome-initial-setup/gis-center-container.c |  198 ++++++++++++++++++++++++++++
 gnome-initial-setup/gis-center-container.h |   63 +++++++++
 4 files changed, 270 insertions(+), 5 deletions(-)
---
diff --git a/gnome-initial-setup/Makefile.am b/gnome-initial-setup/Makefile.am
index e1e2c40..a38ed54 100644
--- a/gnome-initial-setup/Makefile.am
+++ b/gnome-initial-setup/Makefile.am
@@ -14,6 +14,7 @@ libexec_PROGRAMS = gnome-initial-setup gnome-initial-setup-copy-worker
 
 gnome_initial_setup_SOURCES =  \
        gnome-initial-setup.c gnome-initial-setup.h \
+       gis-center-container.c gis-center-container.h \
        gis-assistant.c gis-assistant.h gis-assistant-private.h \
        gis-assistant-gtk.c gis-assistant-gtk.h \
        gis-assistant-gd.c gis-assistant-gd.h \
diff --git a/gnome-initial-setup/gis-assistant.c b/gnome-initial-setup/gis-assistant.c
index a7726ea..c9d89c3 100644
--- a/gnome-initial-setup/gis-assistant.c
+++ b/gnome-initial-setup/gis-assistant.c
@@ -29,6 +29,7 @@
 
 #include "gis-assistant.h"
 #include "gis-assistant-private.h"
+#include "gis-center-container.h"
 
 G_DEFINE_TYPE (GisAssistant, gis_assistant, GTK_TYPE_BOX)
 
@@ -303,6 +304,7 @@ gis_assistant_init (GisAssistant *assistant)
 {
   GisAssistantPrivate *priv = GET_PRIVATE (assistant);
   GtkWidget *navigation;
+  GtkWidget *dummy;
   assistant->priv = priv;
 
   priv->main_layout = gtk_box_new (GTK_ORIENTATION_VERTICAL, 20);
@@ -312,17 +314,12 @@ gis_assistant_init (GisAssistant *assistant)
   gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_NONE);
   gtk_box_pack_start (GTK_BOX (priv->main_layout), priv->frame, TRUE, TRUE, 0);
 
-  priv->action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-
   priv->page_action_widget_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_box_pack_start (GTK_BOX (priv->action_area), priv->page_action_widget_area,
-                      FALSE, FALSE, 0);
 
   navigation = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   gtk_box_set_homogeneous (GTK_BOX (navigation), TRUE);
   gtk_widget_set_halign (navigation, GTK_ALIGN_END);
   gtk_widget_set_hexpand (navigation, TRUE);
-  gtk_box_pack_end (GTK_BOX (priv->action_area), navigation, TRUE, TRUE, 0);
 
   priv->forward = gtk_button_new ();
   gtk_button_set_image (GTK_BUTTON (priv->forward),
@@ -341,6 +338,12 @@ gis_assistant_init (GisAssistant *assistant)
   g_signal_connect (priv->forward, "clicked", G_CALLBACK (go_forward), assistant);
   g_signal_connect (priv->back, "clicked", G_CALLBACK (go_backward), assistant);
 
+  dummy = gtk_label_new ("");
+
+  priv->action_area = gis_center_container_new (priv->page_action_widget_area,
+                                                dummy,
+                                                navigation);
+
   gis_assistant_locale_changed (assistant);
   gtk_box_pack_start (GTK_BOX (priv->main_layout), priv->action_area, FALSE, TRUE, 0);
 
diff --git a/gnome-initial-setup/gis-center-container.c b/gnome-initial-setup/gis-center-container.c
new file mode 100644
index 0000000..fe9e478
--- /dev/null
+++ b/gnome-initial-setup/gis-center-container.c
@@ -0,0 +1,198 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Red Hat
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ *     Jasper St. Pierre <jstpierre mecheye net>
+ *     Cosimo Cecchi <cosimoc gnome org>
+ */
+
+#include "gis-center-container.h"
+
+struct _GisCenterContainerPrivate
+{
+  GtkWidget *left;
+  GtkWidget *center;
+  GtkWidget *right;
+};
+
+G_DEFINE_TYPE (GisCenterContainer, gis_center_container, GTK_TYPE_CONTAINER);
+
+#define SPACING 6
+
+static void
+gis_center_container_init (GisCenterContainer *center)
+{
+  GisCenterContainerPrivate *priv;
+
+  priv = G_TYPE_INSTANCE_GET_PRIVATE (center, GIS_TYPE_CENTER_CONTAINER, GisCenterContainerPrivate);
+  center->priv = priv;
+
+  gtk_widget_set_has_window (GTK_WIDGET (center), FALSE);
+}
+
+static void
+gis_center_container_get_preferred_width (GtkWidget *widget,
+                                          gint      *minimum_size,
+                                          gint      *natural_size)
+{
+  GisCenterContainer *center = GIS_CENTER_CONTAINER (widget);
+  GisCenterContainerPrivate *priv = center->priv;
+
+  gint sum_min, sum_nat;
+  gint child_min, child_nat;
+
+  gtk_widget_get_preferred_height (priv->left, &child_min, &child_nat);
+  sum_min = child_min;
+  sum_nat = child_nat;
+
+  gtk_widget_get_preferred_height (priv->center, &child_min, &child_nat);
+  sum_min = sum_min + child_min;
+  sum_nat = sum_nat + child_nat + SPACING;
+
+  gtk_widget_get_preferred_height (priv->right, &child_min, &child_nat);
+  sum_min = sum_min + child_min;
+  sum_nat = sum_nat + child_nat + SPACING;
+
+  if (minimum_size)
+    *minimum_size = sum_min;
+  if (natural_size)
+    *natural_size = sum_nat;
+}
+
+static void
+gis_center_container_get_preferred_height (GtkWidget *widget,
+                                           gint      *minimum_size,
+                                           gint      *natural_size)
+{
+  GisCenterContainer *center = GIS_CENTER_CONTAINER (widget);
+  GisCenterContainerPrivate *priv = center->priv;
+  gint max_min, max_nat;
+  gint child_min, child_nat;
+
+  gtk_widget_get_preferred_height (priv->left, &child_min, &child_nat);
+  max_min = child_min;
+  max_nat = child_nat;
+
+  gtk_widget_get_preferred_height (priv->center, &child_min, &child_nat);
+  max_min = MAX (max_min, child_min);
+  max_nat = MAX (max_nat, child_nat);
+
+  gtk_widget_get_preferred_height (priv->right, &child_min, &child_nat);
+  max_min = MAX (max_min, child_min);
+  max_nat = MAX (max_nat, child_nat);
+
+  if (minimum_size)
+    *minimum_size = max_min;
+  if (natural_size)
+    *natural_size = max_nat;
+}
+
+static void
+gis_center_container_size_allocate (GtkWidget     *widget,
+                                    GtkAllocation *allocation)
+{
+  GisCenterContainer *center = GIS_CENTER_CONTAINER (widget);
+  GisCenterContainerPrivate *priv = center->priv;
+  GtkAllocation child_allocation;
+  gint max_side;
+
+  gtk_widget_set_allocation (widget, allocation);
+
+  child_allocation.y = allocation->y;
+  child_allocation.height = allocation->height;
+
+  /* XXX -- fix minimum allocations */
+  {
+    gint left_side, right_side;
+    gtk_widget_get_preferred_width (priv->left, NULL, &left_side);
+    gtk_widget_get_preferred_width (priv->right, NULL, &right_side);
+    max_side = MAX (left_side, right_side);
+  }
+
+  child_allocation.width = max_side;
+
+  child_allocation.x = allocation->x;
+  gtk_widget_size_allocate (priv->left, &child_allocation);
+
+  child_allocation.x = allocation->x + allocation->width - max_side;
+  gtk_widget_size_allocate (priv->right, &child_allocation);
+
+  child_allocation.x = allocation->x + max_side + SPACING;
+  child_allocation.width = allocation->width - max_side * 2 - SPACING * 2;
+  gtk_widget_size_allocate (priv->center, &child_allocation);
+}
+
+static GType
+gis_center_container_child_type (GtkContainer *container)
+{
+  return GTK_TYPE_WIDGET;
+}
+
+static void
+gis_center_container_forall (GtkContainer *container,
+                             gboolean      include_internals,
+                             GtkCallback   callback,
+                             gpointer      callback_data)
+{
+  GisCenterContainer *center = GIS_CENTER_CONTAINER (container);
+  GisCenterContainerPrivate *priv = center->priv;
+
+  callback (priv->left, callback_data);
+  callback (priv->center, callback_data);
+  callback (priv->right, callback_data);
+}
+
+static void
+gis_center_container_class_init (GisCenterContainerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
+
+  widget_class->size_allocate = gis_center_container_size_allocate;
+  widget_class->get_preferred_width = gis_center_container_get_preferred_width;
+  widget_class->get_preferred_height = gis_center_container_get_preferred_height;
+
+  container_class->forall = gis_center_container_forall;
+  container_class->child_type = gis_center_container_child_type;
+  gtk_container_class_handle_border_width (container_class);
+
+  g_type_class_add_private (object_class, sizeof (GisCenterContainerPrivate));
+}
+
+GtkWidget *
+gis_center_container_new (GtkWidget *left,
+                          GtkWidget *center,
+                          GtkWidget *right)
+{
+  GisCenterContainer *container = g_object_new (GIS_TYPE_CENTER_CONTAINER, NULL);
+  GisCenterContainerPrivate *priv = container->priv;
+
+  priv->left = left;
+  gtk_widget_set_parent (left, GTK_WIDGET (container));
+
+  priv->center = center;
+  gtk_widget_set_parent (center, GTK_WIDGET (container));
+
+  priv->right = right;
+  gtk_widget_set_parent (right, GTK_WIDGET (container));
+
+  return GTK_WIDGET (container);
+}
+
diff --git a/gnome-initial-setup/gis-center-container.h b/gnome-initial-setup/gis-center-container.h
new file mode 100644
index 0000000..9bff7e9
--- /dev/null
+++ b/gnome-initial-setup/gis-center-container.h
@@ -0,0 +1,63 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Red Hat
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ *     Jasper St. Pierre <jstpierre mecheye net>
+ *     Cosimo Cecchi <cosimoc gnome org>
+ */
+
+#ifndef __GIS_CENTER_CONTAINER_H__
+#define __GIS_CENTER_CONTAINER_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GIS_TYPE_CENTER_CONTAINER               (gis_center_container_get_type ())
+#define GIS_CENTER_CONTAINER(obj)                           (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIS_TYPE_CENTER_CONTAINER, GisCenterContainer))
+#define GIS_CENTER_CONTAINER_CLASS(klass)                   (G_TYPE_CHECK_CLASS_CAST ((klass),  
GIS_TYPE_CENTER_CONTAINER, GisCenterContainerClass))
+#define GIS_IS_CENTER_CONTAINER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIS_TYPE_CENTER_CONTAINER))
+#define GIS_IS_CENTER_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIS_TYPE_CENTER_CONTAINER))
+#define GIS_CENTER_CONTAINER_GET_CLASS(obj)                 (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GIS_TYPE_CENTER_CONTAINER, GisCenterContainerClass))
+
+typedef struct _GisCenterContainer        GisCenterContainer;
+typedef struct _GisCenterContainerClass   GisCenterContainerClass;
+typedef struct _GisCenterContainerPrivate GisCenterContainerPrivate;
+
+struct _GisCenterContainer
+{
+    GtkContainer parent;
+    
+    GisCenterContainerPrivate *priv;
+};
+
+struct _GisCenterContainerClass
+{
+    GtkContainerClass parent_class;
+};
+
+GType gis_center_container_get_type (void);
+
+GtkWidget * gis_center_container_new (GtkWidget *left,
+                                      GtkWidget *center,
+                                      GtkWidget *right);
+
+G_END_DECLS
+
+#endif /* __GIS_CENTER_CONTAINER_H__ */


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