summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Watson <mattdangerw@gmail.com>2013-04-22 15:54:38 -0700
committerP. F. Chimento <philip.chimento@gmail.com>2013-05-16 12:17:09 +0200
commit2ede46e4c3c4cabf9ea46a660247696f1221823a (patch)
treee809d065e82fa700e2ee44ed6b2f65d3b9b37ff2
parent2ca816baa7d8dd68b522fd43fe0539edb63890a1 (diff)
Initial main area widget
Has private getters/setters for two areas. Functioning container. Only shows the content widget. Added all the virtual functions for size requests and allocations. [endlessm/eos-sdk#10]
-rw-r--r--docs/reference/endless/Makefile.am2
-rw-r--r--docs/reference/endless/endless-sections.txt2
-rw-r--r--endless/Makefile.am1
-rw-r--r--endless/endless.h1
-rw-r--r--endless/eosmainarea-private.h63
-rw-r--r--endless/eosmainarea.c241
6 files changed, 307 insertions, 3 deletions
diff --git a/docs/reference/endless/Makefile.am b/docs/reference/endless/Makefile.am
index ec57db9..a90030d 100644
--- a/docs/reference/endless/Makefile.am
+++ b/docs/reference/endless/Makefile.am
@@ -49,7 +49,7 @@ EXTRA_HFILES=
# Header files or dirs to ignore when scanning. Use base file/dir names
# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
-IGNORE_HFILES= eosinit-private.h eostopbar-private.h
+IGNORE_HFILES= eosinit-private.h eostopbar-private.h eosmainarea-private.h
# Images to copy into HTML directory.
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
diff --git a/docs/reference/endless/endless-sections.txt b/docs/reference/endless/endless-sections.txt
index 4024e77..3bdd962 100644
--- a/docs/reference/endless/endless-sections.txt
+++ b/docs/reference/endless/endless-sections.txt
@@ -61,4 +61,4 @@ EosPageManagerClass
eos_page_manager_get_type
<SUBSECTION Private>
EosPageManagerPrivate
-</SECTION> \ No newline at end of file
+</SECTION>
diff --git a/endless/Makefile.am b/endless/Makefile.am
index a313905..fa86fc5 100644
--- a/endless/Makefile.am
+++ b/endless/Makefile.am
@@ -16,6 +16,7 @@ endless_library_sources = \
endless/eoshello.c \
endless/eosinit.c endless/eosinit-private.h \
endless/eospagemanager.c \
+ endless/eosmainarea.c \
endless/eostopbar.c endless/eostopbar-private.h \
endless/eoswindow.c
diff --git a/endless/endless.h b/endless/endless.h
index 9f5706c..48778b0 100644
--- a/endless/endless.h
+++ b/endless/endless.h
@@ -25,4 +25,3 @@ gboolean eos_hello_sample_function (GFile *file,
G_END_DECLS
#endif
-
diff --git a/endless/eosmainarea-private.h b/endless/eosmainarea-private.h
new file mode 100644
index 0000000..3ca90ee
--- /dev/null
+++ b/endless/eosmainarea-private.h
@@ -0,0 +1,63 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#ifndef EOS_MAIN_AREA_H
+#define EOS_MAIN_AREA_H
+
+#include "eostypes.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EOS_TYPE_MAIN_AREA eos_main_area_get_type()
+
+#define EOS_MAIN_AREA(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ EOS_TYPE_MAIN_AREA, EosMainArea))
+
+#define EOS_MAIN_AREA_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ EOS_TYPE_MAIN_AREA, EosMainAreaClass))
+
+#define EOS_IS_MAIN_AREA(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ EOS_TYPE_MAIN_AREA))
+
+#define EOS_IS_MAIN_AREA_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ EOS_TYPE_MAIN_AREA))
+
+#define EOS_MAIN_AREA_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ EOS_TYPE_MAIN_AREA, EosMainAreaClass))
+
+typedef struct _EosMainArea EosMainArea;
+typedef struct _EosMainAreaClass EosMainAreaClass;
+typedef struct _EosMainAreaPrivate EosMainAreaPrivate;
+
+struct _EosMainArea
+{
+ GtkContainer parent;
+
+ EosMainAreaPrivate *priv;
+};
+
+struct _EosMainAreaClass
+{
+ GtkContainerClass parent_class;
+};
+
+GType eos_main_area_get_type (void) G_GNUC_CONST;
+
+GtkWidget *eos_main_area_new (void);
+
+void eos_main_area_set_toolbox (EosMainArea *self,
+ GtkWidget *toolbox);
+GtkWidget *eos_main_area_get_toolbox (EosMainArea *self);
+void eos_main_area_set_content (EosMainArea *self,
+ GtkWidget *content);
+GtkWidget *eos_main_area_get_content (EosMainArea *self);
+
+G_END_DECLS
+
+#endif /* EOS_MAIN_AREA_H */
diff --git a/endless/eosmainarea.c b/endless/eosmainarea.c
new file mode 100644
index 0000000..1d57bb4
--- /dev/null
+++ b/endless/eosmainarea.c
@@ -0,0 +1,241 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#include "config.h"
+#include "eosmainarea-private.h"
+
+#include <gtk/gtk.h>
+
+/*
+ * SECTION:main_area
+ * @short_description: The main area for your application, under the top bar.
+ * @title: EosMainArea
+ *
+ * Stub
+ */
+
+G_DEFINE_TYPE (EosMainArea, eos_main_area, GTK_TYPE_CONTAINER)
+
+#define MAIN_AREA_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), EOS_TYPE_MAIN_AREA, EosMainAreaPrivate))
+
+struct _EosMainAreaPrivate
+{
+ GtkWidget *toolbox;
+ GtkWidget *content;
+};
+
+static void
+eos_main_area_get_preferred_width (GtkWidget *widget,
+ gint *minimal,
+ gint *natural)
+{
+ EosMainArea *self = EOS_MAIN_AREA (widget);
+ GtkWidget *content = self->priv->content;
+
+ if (content && gtk_widget_get_visible (content))
+ gtk_widget_get_preferred_width(content, minimal, natural);
+}
+
+static void
+eos_main_area_get_preferred_height (GtkWidget *widget,
+ gint *minimal,
+ gint *natural)
+{
+ EosMainArea *self = EOS_MAIN_AREA (widget);
+ GtkWidget *content = self->priv->content;
+
+ if (content && gtk_widget_get_visible (content))
+ gtk_widget_get_preferred_height(content, minimal, natural);
+}
+
+static void
+eos_main_area_get_preferred_width_for_height (GtkWidget *widget,
+ gint for_height,
+ gint *minimal,
+ gint *natural)
+{
+ EosMainArea *self = EOS_MAIN_AREA (widget);
+ GtkWidget *content = self->priv->content;
+
+ if (content && gtk_widget_get_visible (content))
+ gtk_widget_get_preferred_width_for_height (content, for_height,
+ minimal, natural);
+}
+
+static void
+eos_main_area_get_preferred_height_for_width (GtkWidget *widget,
+ gint for_width,
+ gint *minimal,
+ gint *natural)
+{
+ EosMainArea *self = EOS_MAIN_AREA (widget);
+ GtkWidget *content = self->priv->content;
+
+ if (content && gtk_widget_get_visible (content))
+ gtk_widget_get_preferred_width_for_height (content, for_width,
+ minimal, natural);
+}
+
+static void
+eos_main_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ EosMainArea *self = EOS_MAIN_AREA (widget);
+ GtkWidget *content = self->priv->content;
+
+ gtk_widget_set_allocation (widget, allocation);
+ if (content && gtk_widget_get_visible (content))
+ gtk_widget_size_allocate (content, allocation);
+}
+
+static void
+eos_main_area_forall(GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ EosMainArea *self = EOS_MAIN_AREA (container);
+ EosMainAreaPrivate *priv = self->priv;
+
+ if (priv->toolbox)
+ (*callback) (priv->toolbox, callback_data);
+
+ if (priv->content)
+ (*callback) (priv->content, callback_data);
+}
+
+static void
+eos_main_area_class_init (EosMainAreaClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (EosMainAreaPrivate));
+
+ widget_class->get_preferred_width = eos_main_area_get_preferred_width;
+ widget_class->get_preferred_height = eos_main_area_get_preferred_height;
+ widget_class->get_preferred_width_for_height = eos_main_area_get_preferred_width_for_height;
+ widget_class->get_preferred_height_for_width = eos_main_area_get_preferred_height_for_width;
+ widget_class->size_allocate = eos_main_size_allocate;
+
+ container_class->forall = eos_main_area_forall;
+}
+
+static void
+eos_main_area_init (EosMainArea *self)
+{
+ gtk_widget_set_has_window(GTK_WIDGET(self), FALSE);
+ self->priv = MAIN_AREA_PRIVATE (self);
+}
+
+/* Internal Public API */
+
+/*
+ * eos_main_area_new:
+ *
+ * Creates a main area. It is invisible by default.
+ *
+ * Returns: a pointer to the main area widget.
+ */
+GtkWidget *
+eos_main_area_new (void)
+{
+ return GTK_WIDGET (g_object_new (EOS_TYPE_MAIN_AREA, NULL));
+}
+
+
+/*
+ * eos_main_area_set_toolbox:
+ * @self: a #EosMainArea
+ * @toolbox: the toolbox widget to be displayed on left of content.
+ *
+ * Adds the toolbox widget to the main area. Passing %NULL will hide the
+ * toolbox area.
+ */
+void
+eos_main_area_set_toolbox (EosMainArea *self,
+ GtkWidget *toolbox)
+{
+ g_return_if_fail (EOS_IS_MAIN_AREA (self));
+ g_return_if_fail (toolbox == NULL || GTK_IS_WIDGET (toolbox));
+ g_return_if_fail (toolbox == NULL || gtk_widget_get_parent (toolbox) == NULL);
+
+ EosMainAreaPrivate *priv = self->priv;
+ GtkWidget *self_widget = GTK_WIDGET (self);
+
+ if (priv->toolbox == toolbox)
+ return;
+
+ if (priv->toolbox)
+ gtk_widget_unparent (priv->toolbox);
+
+ priv->toolbox = toolbox;
+ if (toolbox)
+ gtk_widget_set_parent (toolbox, self_widget);
+
+ if (gtk_widget_get_visible (self_widget))
+ gtk_widget_queue_resize (self_widget);
+}
+
+/*
+ * eos_main_area_get_toolbox:
+ * @self: a #EosMainArea
+ *
+ * Retrieves the toolbox widget for the main area.
+ *
+ * Return value: (transfer none): the toolbox widget,
+ * or %NULL if there is none
+ */
+GtkWidget *
+eos_main_area_get_toolbox (EosMainArea *self)
+{
+ g_return_val_if_fail (EOS_IS_MAIN_AREA (self), NULL);
+ return self->priv->toolbox;
+}
+
+/*
+ * eos_main_area_set_content:
+ * @self: a #EosMainArea
+ * @content: the content widget to be displayed in the center.
+ *
+ * Adds the content widget to the main area.
+ */
+void
+eos_main_area_set_content (EosMainArea *self, GtkWidget *content)
+{
+ g_return_if_fail (EOS_IS_MAIN_AREA (self));
+ g_return_if_fail (content == NULL || GTK_IS_WIDGET (content));
+ g_return_if_fail (content == NULL || gtk_widget_get_parent (content) == NULL);
+
+ EosMainAreaPrivate *priv = self->priv;
+ GtkWidget *self_widget = GTK_WIDGET (self);
+
+ if (priv->content == content)
+ return;
+
+ if (priv->content)
+ gtk_widget_unparent (priv->content);
+
+ priv->content = content;
+ if (content)
+ gtk_widget_set_parent (content, self_widget);
+
+ if (gtk_widget_get_visible (self_widget))
+ gtk_widget_queue_resize (self_widget);
+}
+
+/*
+ * eos_main_area_get_content:
+ * @self: a #EosMainArea
+ *
+ * Retrieves the content widget for the main area.
+ *
+ * Return value: (transfer none): the content widget,
+ * or %NULL if there is none
+ */
+GtkWidget *
+eos_main_area_get_content (EosMainArea *self)
+{
+ g_return_val_if_fail (EOS_IS_MAIN_AREA (self), NULL);
+ return self->priv->content;
+}