[Xfce4-commits] <midori:master> Add MidoriPanedAction implementation

Christian Dywan noreply at xfce.org
Tue Nov 15 23:56:01 CET 2011


Updating branch refs/heads/master
         to be7c66342424fc546fd365f17d35fcdf987aa142 (commit)
       from ccd0562d7d730fd78834e41c0c559ad2c32edd2c (commit)

commit be7c66342424fc546fd365f17d35fcdf987aa142
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Nov 15 23:55:34 2011 +0100

    Add MidoriPanedAction implementation

 midori/midori-panedaction.c |  199 +++++++++++++++++++++++++++++++++++++++++++
 midori/midori-panedaction.h |   64 ++++++++++++++
 2 files changed, 263 insertions(+), 0 deletions(-)

diff --git a/midori/midori-panedaction.c b/midori/midori-panedaction.c
new file mode 100644
index 0000000..b6f615a
--- /dev/null
+++ b/midori/midori-panedaction.c
@@ -0,0 +1,199 @@
+/*
+ Copyright (C) 2011 Peter Hatina <phatina at redhat.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+#include <string.h>
+#include <katze/katze.h>
+#include "midori-panedaction.h"
+
+struct _MidoriPanedActionChild
+{
+    GtkWidget* widget;
+    gchar* name;
+    gboolean resize;
+    gboolean shrink;
+};
+
+struct _MidoriPanedAction
+{
+    GtkAction parent_instance;
+    GtkWidget* hpaned;
+    GtkWidget* toolitem;
+    struct _MidoriPanedActionChild child1;
+    struct _MidoriPanedActionChild child2;
+};
+
+struct _MidoriPanedActionClass
+{
+    GtkActionClass parent_class;
+};
+
+G_DEFINE_TYPE (MidoriPanedAction, midori_paned_action, GTK_TYPE_ACTION);
+
+static GtkWidget*
+midori_paned_action_create_tool_item (GtkAction *action);
+
+static void
+midori_paned_action_finalize (GObject* object);
+
+static void
+midori_paned_action_init (MidoriPanedAction* paned_action)
+{
+    paned_action->hpaned = NULL;
+    paned_action->toolitem = NULL;
+    memset ((void*) &paned_action->child1, 0, sizeof (struct _MidoriPanedActionChild));
+    memset ((void*) &paned_action->child2, 0, sizeof (struct _MidoriPanedActionChild));
+}
+
+static void
+midori_paned_action_finalize (GObject* object)
+{
+    MidoriPanedAction* paned_action = MIDORI_PANED_ACTION (object);
+
+    g_object_unref (G_OBJECT (paned_action->toolitem));
+    g_object_unref (G_OBJECT (paned_action->hpaned));
+    katze_assign (paned_action->child1.name, NULL);
+    katze_assign (paned_action->child2.name, NULL);
+
+    G_OBJECT_CLASS (midori_paned_action_parent_class)->finalize (object);
+}
+
+static void
+midori_paned_action_class_init (MidoriPanedActionClass* class)
+{
+    GObjectClass* gobject_class;
+    GtkActionClass* action_class;
+
+    gobject_class = G_OBJECT_CLASS (class);
+    gobject_class->finalize = midori_paned_action_finalize;
+
+    action_class = GTK_ACTION_CLASS (class);
+    action_class->create_tool_item = midori_paned_action_create_tool_item;
+}
+
+static GtkWidget*
+midori_paned_action_create_tool_item (GtkAction* action)
+{
+    MidoriPanedAction* paned_action = MIDORI_PANED_ACTION (action);
+    GtkWidget* alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
+    paned_action->hpaned = gtk_hpaned_new ();
+    paned_action->toolitem = GTK_WIDGET (gtk_tool_item_new ());
+    gtk_tool_item_set_expand (GTK_TOOL_ITEM (paned_action->toolitem), TRUE);
+    gtk_container_add (GTK_CONTAINER (paned_action->toolitem), alignment);
+    gtk_container_add (GTK_CONTAINER (alignment), GTK_WIDGET (paned_action->hpaned));
+
+    gtk_paned_pack1 (GTK_PANED (paned_action->hpaned),
+        paned_action->child1.widget,
+        paned_action->child1.resize,
+        paned_action->child1.shrink);
+    gtk_paned_pack2 (GTK_PANED (paned_action->hpaned),
+        paned_action->child2.widget,
+        paned_action->child2.resize,
+        paned_action->child2.shrink);
+
+    gtk_widget_show_all (GTK_WIDGET (paned_action->toolitem));
+    return paned_action->toolitem;
+}
+
+/**
+ * midori_paned_action_set_child1:
+ * @paned_action: a #MidoriPanedAction
+ * @child1: a #GtkWidget to be added into GtkHPaned container
+ * @name: string name for the child2
+ * @resize: should child1 expand when the MidoriPanedAction is resized
+ * @shrink: can child1 be made smaller than its requisition
+ **/
+void
+midori_paned_action_set_child1 (MidoriPanedAction* paned_action,
+                                GtkWidget* child1,
+                                const gchar* name,
+                                gboolean resize,
+                                gboolean shrink)
+{
+    g_return_if_fail (MIDORI_IS_PANED_ACTION (paned_action));
+
+    katze_assign (paned_action->child1.name, g_strdup (name));
+    paned_action->child1.widget = child1;
+    paned_action->child1.resize = resize;
+    paned_action->child1.shrink = shrink;
+}
+
+/**
+ * midori_paned_action_set_child1:
+ * @paned_action: a #MidoriPanedAction
+ * @child2: a #GtkWidget to be added into GtkHPaned container
+ * @name: string name for the child2
+ * @resize: should child2 expand when the MidoriPanedAction is resized
+ * @shrink: can child2 be made smaller than its requisition
+ **/
+void
+midori_paned_action_set_child2 (MidoriPanedAction* paned_action,
+                                GtkWidget* child2,
+                                const gchar* name,
+                                gboolean resize,
+                                gboolean shrink)
+{
+    g_return_if_fail (MIDORI_IS_PANED_ACTION (paned_action));
+
+    katze_assign (paned_action->child2.name, g_strdup (name));
+    paned_action->child2.widget = child2;
+    paned_action->child2.resize = resize;
+    paned_action->child2.shrink = shrink;
+}
+
+/**
+ * midori_paned_action_get_child1:
+ * @paned_action: a #MidoriPanedAction
+ *
+ * returns the first child held in GtkHPaned container
+ **/
+GtkWidget*
+midori_paned_action_get_child1 (MidoriPanedAction* paned_action)
+{
+    g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+
+    return paned_action->child1.widget;
+}
+
+/**
+ * midori_paned_action_get_child1:
+ * @paned_action: a #MidoriPanedAction
+ *
+ * returns the second child held in GtkHPaned container
+ **/
+GtkWidget*
+midori_paned_action_get_child2 (MidoriPanedAction* paned_action)
+{
+    g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+
+    return paned_action->child2.widget;
+}
+
+/**
+ * midori_paned_action_get_child1:
+ * @paned_action: a #MidoriPanedAction
+ * @name: string name for one of the children
+ *
+ * returns a child specified by its name
+ **/
+GtkWidget*
+midori_paned_action_get_child_by_name (MidoriPanedAction* paned_action,
+                                       const gchar* name)
+{
+    g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL);
+    g_return_val_if_fail (name != NULL, NULL);
+
+    if (g_strcmp0 (name, paned_action->child1.name) == 0)
+        return midori_paned_action_get_child1 (paned_action);
+    else if (g_strcmp0 (name, paned_action->child2.name) == 0)
+        return midori_paned_action_get_child2 (paned_action);
+
+    return NULL;
+}
diff --git a/midori/midori-panedaction.h b/midori/midori-panedaction.h
new file mode 100644
index 0000000..384529b
--- /dev/null
+++ b/midori/midori-panedaction.h
@@ -0,0 +1,64 @@
+/*
+ Copyright (C) 2011 Peter Hatina <phatina at redhat.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+#ifndef __MIDORI_PANED_ACTION_H__
+#define __MIDORI_PANED_ACTION_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define MIDORI_TYPE_PANED_ACTION \
+    (midori_paned_action_get_type ())
+#define MIDORI_PANED_ACTION(obj) \
+    (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_PANED_ACTION, MidoriPanedAction))
+#define MIDORI_PANED_ACTION_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_CAST ((klass),  MIDORI_PANED_ACTION, MidoriPanedActionClass))
+#define MIDORI_IS_PANED_ACTION(obj) \
+    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_PANED_ACTION))
+#define MIDORI_IS_PANED_ACTION_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_TYPE ((klass),  MIDORI_TYPE_PANED_ACTION))
+#define MIDORI_PANED_ACTION_GET_CLASS(obj) \
+    (G_TYPE_INSTANCE_GET_CLASS ((obj),  MIDORI_TYPE_PANED_ACTION, MidoriPanedActionClass))
+
+typedef struct _MidoriPanedAction                  MidoriPanedAction;
+typedef struct _MidoriPanedActionClass             MidoriPanedActionClass;
+
+GType
+midori_paned_action_get_type                       (void) G_GNUC_CONST;
+
+void
+midori_paned_action_set_child1                     (MidoriPanedAction* paned_action,
+                                                    GtkWidget* child1,
+                                                    const gchar* name,
+                                                    gboolean resize,
+                                                    gboolean shrink);
+
+void
+midori_paned_action_set_child2                     (MidoriPanedAction* paned_action,
+                                                    GtkWidget* child2,
+                                                    const gchar* name,
+                                                    gboolean resize,
+                                                    gboolean shrink);
+
+GtkWidget*
+midori_paned_action_get_child1                     (MidoriPanedAction* paned_action);
+
+GtkWidget*
+midori_paned_action_get_child2                     (MidoriPanedAction* paned_action);
+
+GtkWidget*
+midori_paned_action_get_child_by_name              (MidoriPanedAction* paned_action,
+                                                    const gchar* name);
+
+G_END_DECLS
+
+#endif // __MIDORI_PANED_ACTION_H__


More information about the Xfce4-commits mailing list