summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Erias Morandeira <femorandeira@igalia.com>2013-05-27 12:30:20 +0200
committerFelipe Erias Morandeira <femorandeira@igalia.com>2013-06-21 14:14:14 +0100
commit68124bb0bb06a865f21e0b28b8944a670d9cd6fd (patch)
treed7582f0909adae2fc620effa06c9a5afb07d6693
parent39c845a71b01e9f8e8d3d74639f8e9e7c391f952 (diff)
EosActionMenu: basic scaffolding to add and remove GtkAction
[endlessm/eos-sdk#79]
-rw-r--r--endless/Makefile.am4
-rw-r--r--endless/eosactionmenu-private.h79
-rw-r--r--endless/eosactionmenu.c147
3 files changed, 229 insertions, 1 deletions
diff --git a/endless/Makefile.am b/endless/Makefile.am
index 3619a97..77f8c95 100644
--- a/endless/Makefile.am
+++ b/endless/Makefile.am
@@ -11,7 +11,8 @@ endless_private_installed_headers = \
endless/eossplashpagemanager.h \
endless/eostypes.h \
endless/eoswindow.h \
- endless/eosactionbutton-private.h
+ endless/eosactionbutton-private.h \
+ endless/eosactionmenu-private.h
endless_library_sources = \
endless/eosapplication.c \
@@ -22,6 +23,7 @@ endless_library_sources = \
endless/eossplashpagemanager.c \
endless/eostopbar.c endless/eostopbar-private.h \
endless/eosactionbutton.c \
+ endless/eosactionmenu.c \
endless/eoswindow.c
# Endless GUI library
diff --git a/endless/eosactionmenu-private.h b/endless/eosactionmenu-private.h
new file mode 100644
index 0000000..181e467
--- /dev/null
+++ b/endless/eosactionmenu-private.h
@@ -0,0 +1,79 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#ifndef EOS_ACTION_MENU_H
+#define EOS_ACTION_MENU_H
+
+#include "eostypes.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EOS_TYPE_ACTION_MENU eos_action_menu_get_type()
+
+#define EOS_ACTION_MENU(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ EOS_TYPE_ACTION_MENU, EosActionMenu))
+
+#define EOS_ACTION_MENU_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ EOS_TYPE_ACTION_MENU, EosActionMenuClass))
+
+#define EOS_IS_ACTION_MENU(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ EOS_TYPE_ACTION_MENU))
+
+#define EOS_IS_ACTION_MENU_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ EOS_TYPE_ACTION_MENU))
+
+#define EOS_ACTION_MENU_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ EOS_TYPE_ACTION_MENU, EosActionMenuClass))
+
+typedef struct _EosActionMenu EosActionMenu;
+typedef struct _EosActionMenuClass EosActionMenuClass;
+typedef struct _EosActionMenuPrivate EosActionMenuPrivate;
+
+struct _EosActionMenu
+{
+ GtkGrid parent;
+
+ EosActionMenuPrivate *priv;
+};
+
+struct _EosActionMenuClass
+{
+ GtkGridClass parent_class;
+};
+
+EOS_SDK_ALL_API_VERSIONS
+GType eos_action_menu_get_type (void) G_GNUC_CONST;
+
+EOS_SDK_ALL_API_VERSIONS
+GtkWidget *eos_action_menu_new ();
+
+EOS_SDK_ALL_API_VERSIONS
+GtkAction *eos_action_menu_add_action (EosActionMenu *menu,
+ const gchar *first_property_name,
+ ...);
+
+EOS_SDK_ALL_API_VERSIONS
+GtkAction *eos_action_menu_get_action (EosActionMenu *menu,
+ const gchar *name);
+
+EOS_SDK_ALL_API_VERSIONS
+GList *eos_action_list_actions (EosActionMenu *menu);
+
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_action_menu_remove_action (EosActionMenu *menu,
+ GtkAction *action);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_action_menu_remove_action_by_name (EosActionMenu *menu,
+ const gchar *name);
+
+G_END_DECLS
+
+#endif /* EOS_ACTION_MENU_H */
diff --git a/endless/eosactionmenu.c b/endless/eosactionmenu.c
new file mode 100644
index 0000000..fa09e02
--- /dev/null
+++ b/endless/eosactionmenu.c
@@ -0,0 +1,147 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#include "config.h"
+#include "eosactionmenu-private.h"
+
+#include "eosactionbutton-private.h"
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <math.h>
+
+#define _EOS_STYLE_CLASS_ACTION_MENU "action-menu"
+
+G_DEFINE_TYPE (EosActionMenu, eos_action_menu, GTK_TYPE_GRID)
+
+#define EOS_ACTION_MENU_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), EOS_TYPE_ACTION_MENU, EosActionMenuPrivate))
+
+struct _EosActionMenuPrivate
+{
+ GtkActionGroup *action_group;
+};
+
+static void
+eos_action_menu_dispose (GObject *object);
+
+static void
+eos_action_menu_finalize (GObject *object);
+
+/* ******* INIT ******* */
+
+static void
+eos_action_menu_class_init (EosActionMenuClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (EosActionMenuPrivate));
+
+ object_class->dispose = eos_action_menu_dispose;
+ object_class->finalize = eos_action_menu_finalize;
+}
+
+static void
+eos_action_menu_init (EosActionMenu *menu)
+{
+ EosActionMenuPrivate *priv;
+
+ menu->priv = EOS_ACTION_MENU_PRIVATE (menu);
+ priv = menu->priv;
+
+ // TODO : name?
+ priv->action_group = gtk_action_group_new ("EosActionMenu");
+}
+
+/* ******* LIFECYCLE ******* */
+
+GtkWidget *
+eos_action_menu_new ()
+{
+ return g_object_new (EOS_TYPE_ACTION_MENU, NULL);
+}
+
+static void
+eos_action_menu_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (eos_action_menu_parent_class)->dispose (object);
+}
+
+static void
+eos_action_menu_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (eos_action_menu_parent_class)->finalize (object);
+}
+
+/* ******* ACTION GROUP MGMT ******* */
+
+GtkAction *
+eos_action_menu_add_action (EosActionMenu *menu,
+ const gchar *first_property_name,
+ ...)
+{
+ EosActionMenuPrivate *priv;
+ GtkAction *action;
+ va_list var_args;
+
+ g_return_val_if_fail (EOS_IS_ACTION_MENU (menu), NULL);
+ menu->priv = EOS_ACTION_MENU_PRIVATE (menu);
+
+ va_start (var_args, first_property_name);
+ action = (GtkAction*) g_object_new_valist (GTK_TYPE_ACTION, first_property_name, var_args);
+ va_end (var_args);
+
+ gtk_action_group_add_action(priv->action_group, action);
+
+ // TODO : create and wire up the action button
+}
+
+GtkAction *
+eos_action_menu_get_action (EosActionMenu *menu,
+ const gchar *name)
+{
+ EosActionMenuPrivate *priv;
+ g_return_val_if_fail (EOS_IS_ACTION_MENU (menu), NULL);
+ menu->priv = EOS_ACTION_MENU_PRIVATE (menu);
+
+ return gtk_action_group_get_action (priv->action_group, name);
+}
+
+GList *
+eos_action_list_actions (EosActionMenu *menu)
+{
+ EosActionMenuPrivate *priv;
+ g_return_val_if_fail (EOS_IS_ACTION_MENU (menu), NULL);
+ priv = menu->priv;
+
+ return gtk_action_group_list_actions (priv->action_group);
+}
+
+void
+eos_action_menu_remove_action (EosActionMenu *menu,
+ GtkAction *action)
+{
+ EosActionMenuPrivate *priv;
+ g_return_if_fail (EOS_IS_ACTION_MENU (menu));
+ priv = menu->priv;
+
+ gtk_action_group_remove_action(priv->action_group, action);
+}
+
+void
+eos_action_menu_remove_action_by_name (EosActionMenu *menu,
+ const gchar *name)
+{
+ GtkAction *action;
+ EosActionMenuPrivate *priv;
+
+ g_return_if_fail (EOS_IS_ACTION_MENU (menu));
+ priv = menu->priv;
+
+ action = gtk_action_group_get_action (priv->action_group, name);
+ if (action)
+ {
+ gtk_action_group_remove_action (priv->action_group, action);
+ }
+}
+
+/* ******* LAYOUT AND VISUALS ******* */
+