summaryrefslogtreecommitdiff
path: root/endless
diff options
context:
space:
mode:
authorFernando Farfan <fernando@endlessm.com>2013-06-10 15:32:59 -0700
committerFernando Farfan <fernando@endlessm.com>2013-06-17 14:17:43 -0700
commit7c96cbbe6ccb9a88b836bc89225fcf2c94fb1cb6 (patch)
treef641c34608df253d67d45c218384f3b43336188d /endless
parent87ceaf572639a1a35e7112747698cb85f9c210fb (diff)
Added support for left topbar and center topbar.
Modified EosPageManager, EosTopbar and EosWindow to have support for the two new topbars. app-window.js includes some tests for these two widgets. [endlessm/eos-sdk#97]
Diffstat (limited to 'endless')
-rw-r--r--endless/eospagemanager.c170
-rw-r--r--endless/eospagemanager.h18
-rw-r--r--endless/eostopbar-private.h7
-rw-r--r--endless/eostopbar.c30
-rw-r--r--endless/eoswindow.c76
5 files changed, 298 insertions, 3 deletions
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c
index c4508a6..2ee9f87 100644
--- a/endless/eospagemanager.c
+++ b/endless/eospagemanager.c
@@ -5,7 +5,7 @@
#include "eospagemanager-private.h"
#include <gtk/gtk.h>
-#include <pstack.h>
+#include "../pstack/pstack.h"
#include <string.h>
@@ -101,6 +101,8 @@ struct _EosPageManagerPageInfo
gboolean fake_page_actions_visible;
GtkWidget *custom_toolbox_widget;
gchar *background_uri;
+ GtkWidget *left_topbar_widget;
+ GtkWidget *center_topbar_widget;
};
struct _EosPageManagerPrivate
@@ -149,6 +151,8 @@ enum
CHILD_PROP_PAGE_ACTIONS,
CHILD_PROP_CUSTOM_TOOLBOX_WIDGET,
CHILD_PROP_BACKGROUND_URI,
+ CHILD_PROP_LEFT_TOPBAR_WIDGET,
+ CHILD_PROP_CENTER_TOPBAR_WIDGET,
NCHILDPROPS
};
@@ -541,6 +545,18 @@ eos_page_manager_get_child_property (GtkContainer *container,
child));
break;
+ case CHILD_PROP_LEFT_TOPBAR_WIDGET:
+ g_value_set_object (value,
+ eos_page_manager_get_page_left_topbar_widget (self,
+ child));
+ break;
+
+ case CHILD_PROP_CENTER_TOPBAR_WIDGET:
+ g_value_set_object (value,
+ eos_page_manager_get_page_center_topbar_widget (self,
+ child));
+ break;
+
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
property_id, pspec);
@@ -577,6 +593,16 @@ eos_page_manager_set_child_property (GtkContainer *container,
g_value_get_object (value));
break;
+ case CHILD_PROP_LEFT_TOPBAR_WIDGET:
+ eos_page_manager_set_page_left_topbar_widget (self, child,
+ g_value_get_object (value));
+ break;
+
+ case CHILD_PROP_CENTER_TOPBAR_WIDGET:
+ eos_page_manager_set_page_center_topbar_widget (self, child,
+ g_value_get_object (value));
+ break;
+
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
property_id, pspec);
@@ -717,6 +743,32 @@ eos_page_manager_class_init (EosPageManagerClass *klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
+ * EosPageManager:left-topbar-widget:
+ *
+ * The left topbar widget belonging to this page, to be displayed on the
+ * left portion of the top bar when the page is displaying. Setting this to
+ * %NULL indicates that there should be no left topbar widget.
+ */
+ eos_page_manager_child_props[CHILD_PROP_LEFT_TOPBAR_WIDGET] =
+ g_param_spec_object ("left-topbar-widget", "Left topbar widget",
+ "Left topbar widget displayed left of the topbar",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * EosPageManager:center-topbar-widget:
+ *
+ * The center topbar widget belonging to this page, to be displayed on the
+ * middle portion of the top bar when the page is displaying. Setting this to
+ * %NULL indicates that there should be no center topbar widget.
+ */
+ eos_page_manager_child_props[CHILD_PROP_CENTER_TOPBAR_WIDGET] =
+ g_param_spec_object ("center-topbar-widget", "Center topbar widget",
+ "Center topbar widget displayed in the middle of the topbar",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
* EosPageManager:background-uri:
*
* The URI for the image file for the background of this page. Setting this to
@@ -1076,6 +1128,122 @@ eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self,
}
/**
+ * eos_page_manager_get_page_left_topbar_widget:
+ * @self: the page manager
+ * @page: the page to be queried
+ *
+ * Retrieves @page's left topbar widget, if it has one.
+ * See #EosPageManager:left-topbar-widget for more information.
+ *
+ * Returns: (transfer none): the left topbar #GtkWidget of @page, or %NULL if there is none.
+ */
+GtkWidget *
+eos_page_manager_get_page_left_topbar_widget (EosPageManager *self,
+ GtkWidget *page)
+{
+ g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), NULL);
+ g_return_val_if_fail (page != NULL && GTK_IS_WIDGET (page), NULL);
+
+ EosPageManagerPageInfo *info = find_page_info_by_widget (self, page);
+ g_return_val_if_fail (info != NULL, NULL);
+
+ return info->left_topbar_widget;
+}
+
+/**
+ * eos_page_manager_set_page_left_topbar_widget:
+ * @self: the page manager
+ * @page: the page
+ * @left_topbar_widget: (allow-none): left topbar widget for @page
+ *
+ * Sets the left topbar widget to be displayed for this @page.
+ * See #EosPageManager:left-topbar-widget for more information.
+ */
+void
+eos_page_manager_set_page_left_topbar_widget (EosPageManager *self,
+ GtkWidget *page,
+ GtkWidget *left_topbar_widget)
+{
+ g_return_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self));
+ g_return_if_fail (page != NULL && GTK_IS_WIDGET (page));
+ g_return_if_fail (left_topbar_widget == NULL ||
+ GTK_IS_WIDGET (left_topbar_widget));
+
+ EosPageManagerPageInfo *info = find_page_info_by_widget (self, page);
+ g_return_if_fail (info != NULL);
+
+ if (info->left_topbar_widget == left_topbar_widget)
+ return;
+
+ if (info->left_topbar_widget)
+ g_object_unref (info->left_topbar_widget);
+
+ g_object_ref (left_topbar_widget);
+ info->left_topbar_widget = left_topbar_widget;
+
+ gtk_container_child_notify (GTK_CONTAINER (self), page,
+ "left-topbar-widget");
+}
+
+/**
+ * eos_page_manager_get_page_center_topbar_widget:
+ * @self: the page manager
+ * @page: the page to be queried
+ *
+ * Retrieves @page's center topbar widget, if it has one.
+ * See #EosPageManager:center-topbar-widget for more information.
+ *
+ * Returns: (transfer none): the center topbar #GtkWidget of @page, or %NULL if there is none.
+ */
+ GtkWidget *
+ eos_page_manager_get_page_center_topbar_widget (EosPageManager *self,
+ GtkWidget *page)
+{
+ g_return_val_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self), NULL);
+ g_return_val_if_fail (page != NULL && GTK_IS_WIDGET (page), NULL);
+
+ EosPageManagerPageInfo *info = find_page_info_by_widget (self, page);
+ g_return_val_if_fail (info != NULL, NULL);
+
+ return info->center_topbar_widget;
+}
+
+/**
+ * eos_page_manager_set_page_center_topbar_widget:
+ * @self: the page manager
+ * @page: the page
+ * @center_topbar_widget: (allow-none): center topbar widget for @page
+ *
+ * Sets the center topbar widget to be displayed for this @page.
+ * See #EosPageManager:center-topbar-widget for more information.
+ */
+void
+eos_page_manager_set_page_center_topbar_widget (EosPageManager *self,
+ GtkWidget *page,
+ GtkWidget *center_topbar_widget)
+{
+ g_return_if_fail (self != NULL && EOS_IS_PAGE_MANAGER (self));
+ g_return_if_fail (page != NULL && GTK_IS_WIDGET (page));
+ g_return_if_fail (center_topbar_widget == NULL ||
+ GTK_IS_WIDGET (center_topbar_widget));
+
+ EosPageManagerPageInfo *info = find_page_info_by_widget (self, page);
+ g_return_if_fail (info != NULL);
+
+ if (info->center_topbar_widget == center_topbar_widget)
+ return;
+
+ if (info->center_topbar_widget)
+ g_object_unref (info->center_topbar_widget);
+
+ g_object_ref (center_topbar_widget);
+ info->center_topbar_widget = center_topbar_widget;
+
+ gtk_container_child_notify (GTK_CONTAINER (self), page,
+ "center-topbar-widget");
+}
+
+/**
* eos_page_manager_get_page_background_uri:
* @self: the page manager
* @page: the page to be queried
diff --git a/endless/eospagemanager.h b/endless/eospagemanager.h
index 7814b24..db6a693 100644
--- a/endless/eospagemanager.h
+++ b/endless/eospagemanager.h
@@ -133,6 +133,24 @@ void eos_page_manager_set_page_custom_toolbox_widget (EosPageManage
GtkWidget *custom_toolbox_widget);
EOS_SDK_ALL_API_VERSIONS
+GtkWidget *eos_page_manager_get_page_left_topbar_widget (EosPageManager *self,
+ GtkWidget *page);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_page_manager_set_page_left_topbar_widget (EosPageManager *self,
+ GtkWidget *page,
+ GtkWidget *left_topbar_widget);
+
+EOS_SDK_ALL_API_VERSIONS
+GtkWidget *eos_page_manager_get_page_center_topbar_widget (EosPageManager *self,
+ GtkWidget *page);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_page_manager_set_page_center_topbar_widget (EosPageManager *self,
+ GtkWidget *page,
+ GtkWidget *center_topbar_widget);
+
+EOS_SDK_ALL_API_VERSIONS
void eos_page_manager_set_transition_duration (EosPageManager *self,
guint duration);
diff --git a/endless/eostopbar-private.h b/endless/eostopbar-private.h
index 800c8de..02ac6c7 100644
--- a/endless/eostopbar-private.h
+++ b/endless/eostopbar-private.h
@@ -51,6 +51,13 @@ GType eos_top_bar_get_type (void) G_GNUC_CONST;
GtkWidget *eos_top_bar_new (void);
+void eos_top_bar_set_left_widget (EosTopBar *self,
+ GtkWidget *left_top_bar_widget);
+
+void
+eos_top_bar_set_center_widget (EosTopBar *self,
+ GtkWidget *center_top_bar_widget);
+
G_END_DECLS
#endif /* EOS_TOP_BAR_H */
diff --git a/endless/eostopbar.c b/endless/eostopbar.c
index ff0f26f..b57ef75 100644
--- a/endless/eostopbar.c
+++ b/endless/eostopbar.c
@@ -19,6 +19,9 @@ struct _EosTopBarPrivate
{
GtkWidget *actions_hbox;
+ GtkWidget *left_top_bar_widget;
+ GtkWidget *center_top_bar_widget;
+
GtkWidget *minimize_button;
GtkWidget *minimize_icon;
GtkWidget *close_button;
@@ -93,6 +96,33 @@ on_close_clicked_cb (GtkButton *button,
g_signal_emit (self, top_bar_signals[CLOSE_CLICKED], 0);
}
+void
+eos_top_bar_set_left_widget (EosTopBar *self,
+ GtkWidget *left_top_bar_widget)
+{
+ self->priv->left_top_bar_widget = left_top_bar_widget;
+ /* TODO
+ if there is a previous widget, remove it first, then add the new one...
+ */
+ gtk_box_pack_start (GTK_BOX (self->priv->actions_hbox),
+ left_top_bar_widget,
+ FALSE, FALSE, 0);
+}
+
+void
+eos_top_bar_set_center_widget (EosTopBar *self,
+ GtkWidget *center_top_bar_widget)
+{
+ gtk_widget_set_halign (GTK_WIDGET (center_top_bar_widget), GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand (GTK_WIDGET (center_top_bar_widget), TRUE);
+
+ self->priv->center_top_bar_widget = center_top_bar_widget;
+
+ gtk_box_pack_start (GTK_BOX (self->priv->actions_hbox),
+ center_top_bar_widget,
+ FALSE, FALSE, 0);
+}
+
static void
eos_top_bar_init (EosTopBar *self)
{
diff --git a/endless/eoswindow.c b/endless/eoswindow.c
index d2c3ea9..37e12e9 100644
--- a/endless/eoswindow.c
+++ b/endless/eoswindow.c
@@ -64,6 +64,8 @@ struct _EosWindowPrivate
GtkWidget *current_page;
gulong child_page_actions_handler;
gulong child_custom_toolbox_handler;
+ gulong child_left_topbar_handler;
+ gulong child_center_topbar_handler;
gulong child_background_handler;
GtkCssProvider *background_provider;
const gchar *current_background_uri;
@@ -130,6 +132,59 @@ update_page_toolbox (EosWindow *self)
}
}
+/**
+ * update_page_left_topbar:
+ * @self: the window
+ *
+ * Ensures that the currently shown state of the left topbar is in line with
+ * the child properties of the currently showing page.
+ */
+static void
+update_page_left_topbar (EosWindow *self)
+{
+ EosPageManager *pm = EOS_PAGE_MANAGER (self->priv->page_manager);
+ EosTopBar *tb = EOS_TOP_BAR (self->priv->top_bar);
+ GtkWidget *page = self->priv->current_page;
+
+ if (page != NULL)
+ {
+ GtkWidget *left_topbar_widget =
+ eos_page_manager_get_page_left_topbar_widget (pm, page);
+ eos_top_bar_set_left_widget (tb, left_topbar_widget);
+ gtk_widget_show (self->priv->top_bar);
+ }
+ else
+ {
+ eos_top_bar_set_left_widget (tb, NULL);
+ }
+}
+
+/**
+ * update_page_center_topbar:
+ * @self: the window
+ *
+ * Ensures that the currently-shown state of the center topbar is in line with
+ * the child properties of the currently-showing page.
+ */
+static void
+update_page_center_topbar (EosWindow *self)
+{
+ EosPageManager *pm = EOS_PAGE_MANAGER (self->priv->page_manager);
+ EosTopBar *tb = EOS_TOP_BAR (self->priv->top_bar);
+ GtkWidget *page = self->priv->current_page;
+
+ if (page != NULL)
+ {
+ GtkWidget *center_topbar_widget =
+ eos_page_manager_get_page_center_topbar_widget (pm, page);
+ eos_top_bar_set_center_widget (tb, center_topbar_widget);
+ }
+ else
+ {
+ eos_top_bar_set_center_widget (tb, NULL);
+ }
+}
+
static void
sync_stack_animation (EosWindow *self)
{
@@ -208,8 +263,8 @@ update_page_background (EosWindow *self)
* update_page:
* @self: the window
*
- * Ensures that the state of the window and the window's main area are in line
- * with the currently showing page and its child properties.
+ * Ensures that the state of the window, the window's main area and top bar are
+ * in line with the currently showing page and its child properties.
*/
static void
update_page (EosWindow *self)
@@ -224,6 +279,10 @@ update_page (EosWindow *self)
self->priv->child_custom_toolbox_handler);
g_signal_handler_disconnect (self->priv->current_page,
self->priv->child_background_handler);
+ g_signal_handler_disconnect (self->priv->current_page,
+ self->priv->child_left_topbar_handler);
+ g_signal_handler_disconnect (self->priv->current_page,
+ self->priv->child_center_topbar_handler);
}
self->priv->current_page = eos_page_manager_get_visible_page (pm);
@@ -231,6 +290,8 @@ update_page (EosWindow *self)
update_page_actions (self);
update_page_toolbox (self);
sync_stack_animation (self);
+ update_page_left_topbar (self);
+ update_page_center_topbar (self);
update_page_background (self);
p_stack_set_transition_type (P_STACK (self->priv->background_stack),
P_STACK_TRANSITION_TYPE_NONE);
@@ -247,6 +308,16 @@ update_page (EosWindow *self)
"child-notify::custom-toolbox-widget",
G_CALLBACK (update_page_toolbox),
self);
+ self->priv->child_left_topbar_handler =
+ g_signal_connect_swapped (self->priv->current_page,
+ "child-notify::left-topbar-widget",
+ G_CALLBACK (update_page_left_topbar),
+ self);
+ self->priv->child_center_topbar_handler =
+ g_signal_connect_swapped (self->priv->current_page,
+ "child-notify::center-topbar-widget",
+ G_CALLBACK (update_page_center_topbar),
+ self);
self->priv->child_background_handler =
g_signal_connect_swapped (self->priv->current_page,
"child-notify::background-uri",
@@ -390,6 +461,7 @@ eos_window_show (GtkWidget *widget)
GTK_WIDGET_CLASS (eos_window_parent_class)->show (widget);
if (self->priv->top_bar != NULL)
gtk_widget_show_all (self->priv->top_bar);
+
}
/* The top bar is an internal child, so include it in our list of internal