summaryrefslogtreecommitdiff
path: root/endless
diff options
context:
space:
mode:
authorMatt Watson <mattdangerw@gmail.com>2014-01-13 15:39:25 -0800
committerMatt Watson <mattdangerw@gmail.com>2014-01-22 13:43:04 -0800
commit011fffcedfa2845179355052f69a2f0ceabd5852 (patch)
tree67a302e246e04459bd7b64031ad41579da8607b1 /endless
parent63dae1af95255ec96b17e829e6e15545595347ce (diff)
Added EosCustomContainer C class for gjs containers
forall cannot be overridden in gjs. There's an upstream bug here https://bugzilla.gnome.org/show_bug.cgi?id=701567 but that does not look like it will be fixed soon. So for now added a small c class that take care of GtkContainers add, remove and forall methods. This makes it possible to write generic containers in gjs. See docs for an example [endlessm/eos-sdk#481]
Diffstat (limited to 'endless')
-rw-r--r--endless/Makefile.am2
-rw-r--r--endless/endless.h1
-rw-r--r--endless/eoscustomcontainer.c114
-rw-r--r--endless/eoscustomcontainer.h67
4 files changed, 184 insertions, 0 deletions
diff --git a/endless/Makefile.am b/endless/Makefile.am
index 3a5b95c..74d8b3c 100644
--- a/endless/Makefile.am
+++ b/endless/Makefile.am
@@ -28,6 +28,7 @@ endless_private_installed_headers = \
endless/eosversion.h \
endless/eosactionbutton.h \
endless/eosapplication.h \
+ endless/eoscustomcontainer.h \
endless/eosenums.h \
endless/eosmacros.h \
endless/eospagemanager.h \
@@ -39,6 +40,7 @@ endless_private_installed_headers = \
endless_library_sources = \
endless/eosapplication.c \
+ endless/eoscustomcontainer.c \
endless/eoshello.c \
endless/eosinit.c endless/eosinit-private.h \
endless/eospagemanager.c endless/eospagemanager-private.h \
diff --git a/endless/endless.h b/endless/endless.h
index 9efbe6e..f3f2061 100644
--- a/endless/endless.h
+++ b/endless/endless.h
@@ -18,6 +18,7 @@ G_BEGIN_DECLS
#include "eospagemanager.h"
#include "eossplashpagemanager.h"
#include "eoswindow.h"
+#include "eoscustomcontainer.h"
#undef _EOS_SDK_INSIDE_ENDLESS_H
diff --git a/endless/eoscustomcontainer.c b/endless/eoscustomcontainer.c
new file mode 100644
index 0000000..a68745b
--- /dev/null
+++ b/endless/eoscustomcontainer.c
@@ -0,0 +1,114 @@
+/* Copyright 2014 Endless Mobile, Inc. */
+
+#include "config.h"
+#include "eoscustomcontainer.h"
+
+#include <gtk/gtk.h>
+
+/**
+ * SECTION:custom-container
+ * @short_description: For gjs container implementations
+ * @title: Custom Container
+ *
+ * This container allows for implementing a custom size allocate routine in
+ * gjs. This container implements the bare minimum of virtual functions from
+ * GtkContainer, add, remove and forall. Add and remove simply append to and
+ * remove from an internal list, and forall iterates over that list. Forall
+ * cannot be implemented in gjs, it's not supported by gobject-introspection,
+ * so this is needed for custom gjs containers. This class will not
+ * size_allocate any children or ever queue_resize, so that is up to
+ * subclasses in gjs.
+ *
+ * Here's an example gjs program which allocates a GtkFrame the top right
+ * quarter of it's allocation.
+ * |[
+ * const TestContainer = Lang.Class({
+ * Name: 'TestContainer',
+ * Extends: Endless.CustomContainer,
+ *
+ * _init: function() {
+ * this.parent();
+ *
+ * this._frame = new Gtk.Frame();
+ * this.add(this._frame);
+ * },
+ *
+ * vfunc_size_allocate: function (alloc) {
+ * this.parent(alloc);
+ * alloc.width = alloc.width / 2;
+ * alloc.height = alloc.height / 2;
+ * this._frame.size_allocate(alloc);
+ * }
+ * });
+ * ]|
+ */
+
+typedef struct {
+ GList *children;
+} EosCustomContainerPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (EosCustomContainer, eos_custom_container, GTK_TYPE_CONTAINER)
+
+static void
+eos_custom_container_add (GtkContainer *container,
+ GtkWidget *child)
+{
+ EosCustomContainer *self = EOS_CUSTOM_CONTAINER (container);
+ EosCustomContainerPrivate *priv = eos_custom_container_get_instance_private (self);
+
+ priv->children = g_list_prepend (priv->children, child);
+ gtk_widget_set_parent (child, GTK_WIDGET (container));
+}
+
+static void
+eos_custom_container_remove (GtkContainer *container,
+ GtkWidget *child)
+{
+ EosCustomContainer *self = EOS_CUSTOM_CONTAINER (container);
+ EosCustomContainerPrivate *priv = eos_custom_container_get_instance_private (self);
+
+ priv->children = g_list_remove (priv->children, child);
+ gtk_widget_unparent (child);
+}
+
+static void
+eos_custom_container_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ EosCustomContainer *self = EOS_CUSTOM_CONTAINER (container);
+ EosCustomContainerPrivate *priv = eos_custom_container_get_instance_private (self);
+
+ g_list_foreach (priv->children, (GFunc)callback, callback_data);
+}
+
+static void
+eos_custom_container_class_init (EosCustomContainerClass *klass)
+{
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+
+ container_class->add = eos_custom_container_add;
+ container_class->remove = eos_custom_container_remove;
+ container_class->forall = eos_custom_container_forall;
+}
+
+static void
+eos_custom_container_init (EosCustomContainer *self)
+{
+ GtkWidget *widget = GTK_WIDGET (self);
+ gtk_widget_set_has_window (widget, FALSE);
+}
+
+/**
+ * eos_custom_container_new:
+ *
+ * Creates a new custom container.
+ *
+ * Returns: the custom container.
+ */
+GtkWidget *
+eos_custom_container_new (void)
+{
+ return g_object_new (EOS_TYPE_CUSTOM_CONTAINER, NULL);
+}
diff --git a/endless/eoscustomcontainer.h b/endless/eoscustomcontainer.h
new file mode 100644
index 0000000..743bc59
--- /dev/null
+++ b/endless/eoscustomcontainer.h
@@ -0,0 +1,67 @@
+/* Copyright 2014 Endless Mobile, Inc. */
+
+#ifndef EOS_CUSTOM_CONTAINER_H
+#define EOS_CUSTOM_CONTAINER_H
+
+#if !(defined(_EOS_SDK_INSIDE_ENDLESS_H) || defined(COMPILING_EOS_SDK))
+#error "Please do not include this header file directly."
+#endif
+
+#include "eostypes.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EOS_TYPE_CUSTOM_CONTAINER eos_custom_container_get_type()
+
+#define EOS_CUSTOM_CONTAINER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ EOS_TYPE_CUSTOM_CONTAINER, EosCustomContainer))
+
+#define EOS_CUSTOM_CONTAINER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ EOS_TYPE_CUSTOM_CONTAINER, EosCustomContainerClass))
+
+#define EOS_IS_CUSTOM_CONTAINER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ EOS_TYPE_CUSTOM_CONTAINER))
+
+#define EOS_IS_CUSTOM_CONTAINER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ EOS_TYPE_CUSTOM_CONTAINER))
+
+#define EOS_CUSTOM_CONTAINER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ EOS_TYPE_CUSTOM_CONTAINER, EosCustomContainerClass))
+
+typedef struct _EosCustomContainer EosCustomContainer;
+typedef struct _EosCustomContainerClass EosCustomContainerClass;
+
+/**
+ * EosCustomContainer:
+ *
+ * This structure contains no public members.
+ */
+struct _EosCustomContainer
+{
+ GtkContainer parent;
+};
+
+struct _EosCustomContainerClass
+{
+ GtkContainerClass parent_class;
+
+ /* For further expansion */
+ gpointer _padding[8];
+};
+
+EOS_SDK_ALL_API_VERSIONS
+GType eos_custom_container_get_type (void) G_GNUC_CONST;
+
+EOS_SDK_ALL_API_VERSIONS
+GtkWidget *eos_custom_container_new (void);
+
+G_END_DECLS
+
+#endif /* EOS_CUSTOM_CONTAINER_H */