diff options
author | P. F. Chimento <philip.chimento@gmail.com> | 2013-05-13 15:57:11 +0200 |
---|---|---|
committer | P. F. Chimento <philip.chimento@gmail.com> | 2013-05-16 12:17:10 +0200 |
commit | 44d6f130b7aa8c4eb3fa1642ee46d94377f93061 (patch) | |
tree | 2c85cf52291e66a30961080acafd7673b2a6bbb7 | |
parent | e5644f6bb14c02950f324cd17771374fe06b398b (diff) |
Integrate page manager and main area into EosWindow
-rw-r--r-- | endless/eoswindow.c | 171 | ||||
-rw-r--r-- | endless/eoswindow.h | 12 | ||||
-rw-r--r-- | test/test-window.c | 142 |
3 files changed, 322 insertions, 3 deletions
diff --git a/endless/eoswindow.c b/endless/eoswindow.c index 939d6e1..a42d883 100644 --- a/endless/eoswindow.c +++ b/endless/eoswindow.c @@ -5,6 +5,7 @@ #include "eosapplication.h" #include "eostopbar-private.h" +#include "eosmainarea-private.h" #include <gtk/gtk.h> @@ -41,17 +42,117 @@ struct _EosWindowPrivate EosApplication *application; GtkWidget *top_bar; + GtkWidget *main_area; + + EosPageManager *page_manager; + + /* For keeping track of what to display alongside the current page */ + GtkWidget *current_page; + gulong child_page_actions_handler; + gulong child_custom_toolbox_handler; }; enum { PROP_0, PROP_APPLICATION, + PROP_PAGE_MANAGER, NPROPS }; static GParamSpec *eos_window_props[NPROPS] = { NULL, }; +/* + * update_page_actions: + * @self: the window + * + * Ensures that the currently shown state of the action area is in line with + * the child properties of the currently showing page. + */ +static void +update_page_actions (EosWindow *self) +{ + EosPageManager *pm = EOS_PAGE_MANAGER (self->priv->page_manager); + EosMainArea *ma = EOS_MAIN_AREA (self->priv->main_area); + GtkWidget *page = self->priv->current_page; + + if (page != NULL) + { + gboolean fake_action_area = eos_page_manager_get_page_actions (pm, page); + eos_main_area_set_actions (ma, fake_action_area); + } + else + { + eos_main_area_set_actions (ma, FALSE); + } +} + +/* + * update_page_toolbox: + * @self: the window + * + * Ensures that the currently shown state of the toolbox is in line with + * the child properties of the currently showing page. + */ +static void +update_page_toolbox (EosWindow *self) +{ + EosPageManager *pm = EOS_PAGE_MANAGER (self->priv->page_manager); + EosMainArea *ma = EOS_MAIN_AREA (self->priv->main_area); + GtkWidget *page = self->priv->current_page; + + if (page != NULL) + { + GtkWidget *custom_toolbox_widget = + eos_page_manager_get_page_custom_toolbox_widget (pm, page); + eos_main_area_set_toolbox (ma, custom_toolbox_widget); + } + else + { + eos_main_area_set_toolbox (ma, NULL); + } +} + +/* + * 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. + */ +static void +update_page (EosWindow *self) +{ + EosPageManager *pm = EOS_PAGE_MANAGER (self->priv->page_manager); + + if (self->priv->current_page) + { + g_signal_handler_disconnect (self->priv->current_page, + self->priv->child_page_actions_handler); + g_signal_handler_disconnect (self->priv->current_page, + self->priv->child_custom_toolbox_handler); + } + + self->priv->current_page = eos_page_manager_get_visible_page (pm); + + update_page_actions (self); + update_page_toolbox (self); + + if (self->priv->current_page) + { + self->priv->child_page_actions_handler = + g_signal_connect_swapped (self->priv->current_page, + "child-notify::page-actions", + G_CALLBACK (update_page_actions), + self); + self->priv->child_custom_toolbox_handler = + g_signal_connect_swapped (self->priv->current_page, + "child-notify::custom-toolbox-widget", + G_CALLBACK (update_page_toolbox), + self); + } +} + static void eos_window_get_property (GObject *object, guint property_id, @@ -66,6 +167,10 @@ eos_window_get_property (GObject *object, g_value_set_object (value, self->priv->application); break; + case PROP_PAGE_MANAGER: + g_value_set_object (value, eos_window_get_page_manager (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -90,6 +195,10 @@ eos_window_set_property (GObject *object, "for it to connect to."); break; + case PROP_PAGE_MANAGER: + eos_window_set_page_manager (self, g_value_get_object (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -209,7 +318,6 @@ eos_window_forall (GtkContainer *container, callback_data); } - static void eos_window_class_init (EosWindowClass *klass) { @@ -245,6 +353,17 @@ eos_window_class_init (EosWindowClass *klass) EOS_TYPE_APPLICATION, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + /** + * EosWindow:page-manager: + * + * The #EosPageManager that controls the flow of this window's application. + */ + eos_window_props[PROP_PAGE_MANAGER] = + g_param_spec_object ("page-manager", "Page manager", + "Page manager associated with this window", + EOS_TYPE_PAGE_MANAGER, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, NPROPS, eos_window_props); } @@ -276,6 +395,9 @@ eos_window_init (EosWindow *self) self->priv->top_bar = eos_top_bar_new (); gtk_widget_set_parent (self->priv->top_bar, GTK_WIDGET (self)); + self->priv->main_area = eos_main_area_new (); + gtk_container_add (GTK_CONTAINER (self), self->priv->main_area); + gtk_window_set_decorated (GTK_WINDOW (self), FALSE); gtk_window_maximize (GTK_WINDOW (self)); @@ -283,6 +405,9 @@ eos_window_init (EosWindow *self) G_CALLBACK (on_minimize_clicked_cb), self); g_signal_connect (self->priv->top_bar, "close-clicked", G_CALLBACK (on_close_clicked_cb), self); + + eos_window_set_page_manager (self, + EOS_PAGE_MANAGER (eos_page_manager_new ())); } /* Public API */ @@ -302,3 +427,47 @@ eos_window_new (EosApplication *application) "application", application, NULL)); } + +/** + * eos_window_get_page_manager: + * @self: the window + * + * Stub + * + * Returns: (transfer none) (allow-none): a pointer to the current page manager, + * or %NULL if there is no page manager set. + */ +EosPageManager * +eos_window_get_page_manager (EosWindow *self) +{ + g_return_val_if_fail (self != NULL && EOS_IS_WINDOW (self), NULL); + + return self->priv->page_manager; +} + +/** + * eos_window_set_page_manager: + * @self: the window + * @page_manager: the page manager + * + * Stub + */ +void +eos_window_set_page_manager (EosWindow *self, + EosPageManager *page_manager) +{ + g_return_if_fail (self != NULL && EOS_IS_WINDOW (self)); + g_return_if_fail (page_manager != NULL && EOS_IS_PAGE_MANAGER (page_manager)); + + EosMainArea *main_area = EOS_MAIN_AREA (self->priv->main_area); + + self->priv->page_manager = page_manager; + + eos_main_area_set_content (main_area, + GTK_WIDGET (self->priv->page_manager)); + + update_page (self); + + g_signal_connect_swapped (self->priv->page_manager, "notify::visible-page", + G_CALLBACK (update_page), self); +}
\ No newline at end of file diff --git a/endless/eoswindow.h b/endless/eoswindow.h index 246e666..bbbf2b5 100644 --- a/endless/eoswindow.h +++ b/endless/eoswindow.h @@ -10,6 +10,7 @@ #include "eostypes.h" #include "eosapplication.h" +#include "eospagemanager.h" G_BEGIN_DECLS @@ -61,10 +62,17 @@ struct _EosWindowClass }; EOS_SDK_ALL_API_VERSIONS -GType eos_window_get_type (void) G_GNUC_CONST; +GType eos_window_get_type (void) G_GNUC_CONST; EOS_SDK_ALL_API_VERSIONS -GtkWidget *eos_window_new (EosApplication *application); +GtkWidget *eos_window_new (EosApplication *application); + +EOS_SDK_ALL_API_VERSIONS +EosPageManager *eos_window_get_page_manager (EosWindow *self); + +EOS_SDK_ALL_API_VERSIONS +void eos_window_set_page_manager (EosWindow *self, + EosPageManager *page_manager); G_END_DECLS diff --git a/test/test-window.c b/test/test-window.c index e0618c1..cf854b1 100644 --- a/test/test-window.c +++ b/test/test-window.c @@ -4,6 +4,7 @@ #include <gtk/gtk.h> #include <endless/endless.h> #include "endless/eostopbar-private.h" +#include "endless/eosmainarea-private.h" #include "run-tests.h" @@ -98,6 +99,139 @@ test_has_top_bar (GApplication *app) gtk_widget_destroy (win); } +/* Query all the children of win, including the internal children, to find the +main area */ +static void +find_main_area (GtkWidget *widget, + GtkWidget **main_area_return_location) +{ + if (EOS_IS_MAIN_AREA (widget)) + *main_area_return_location = widget; +} + +static void +test_has_main_area (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + GtkWidget *main_area = NULL; + + gtk_container_forall (GTK_CONTAINER (win), (GtkCallback)find_main_area, + &main_area); + g_assert (main_area != NULL); + g_assert (EOS_IS_MAIN_AREA (main_area)); + + gtk_widget_destroy (win); +} + +static void +test_has_default_page_manager (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + EosPageManager *pm = eos_window_get_page_manager (EOS_WINDOW (win)); + g_assert (pm != NULL); + + g_object_get (win, "page-manager", &pm, NULL); + g_assert (pm != NULL); + + gtk_widget_destroy (win); +} + +static void +test_get_set_page_manager (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + EosPageManager *orig_pm = eos_window_get_page_manager (EOS_WINDOW (win)); + EosPageManager *new_pm = EOS_PAGE_MANAGER (eos_page_manager_new ()); + + g_assert (orig_pm != new_pm); + eos_window_set_page_manager(EOS_WINDOW (win), new_pm); + EosPageManager *test_pm = eos_window_get_page_manager (EOS_WINDOW (win)); + g_assert (new_pm == test_pm); + + gtk_widget_destroy (win); +} + +static void +test_prop_page_manager (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + EosPageManager *orig_pm; + g_object_get(win, "page-manager", &orig_pm, NULL); + EosPageManager *new_pm = EOS_PAGE_MANAGER (eos_page_manager_new ()); + + g_assert (orig_pm != new_pm); + g_object_set(win, "page-manager", new_pm, NULL); + EosPageManager *test_pm; + g_object_get(win, "page-manager", &test_pm, NULL); + g_assert (new_pm == test_pm); + + gtk_widget_destroy (win); +} + +static void +test_main_area_widgets_visibility (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + EosPageManager *pm = eos_window_get_page_manager (EOS_WINDOW (win)); + GtkWidget *main_area = NULL; + + gtk_container_forall (GTK_CONTAINER (win), (GtkCallback)find_main_area, + &main_area); + + GtkWidget *page0 = gtk_label_new ("no-no"); + GtkWidget *page1 = gtk_label_new ("yes-no"); + GtkWidget *page2 = gtk_label_new ("no-yes"); + GtkWidget *page3 = gtk_label_new ("yes-yes"); + + GtkWidget *toolbox1 = gtk_label_new ("toolbox1"); + GtkWidget *toolbox3 = gtk_label_new ("toolbox3"); + + gtk_container_add (GTK_CONTAINER (pm), page0); + gtk_container_add_with_properties (GTK_CONTAINER (pm), page1, + "custom-toolbox-widget", toolbox1, + NULL); + gtk_container_add_with_properties (GTK_CONTAINER (pm), page2, + "page-actions", TRUE, + NULL); + gtk_container_add_with_properties (GTK_CONTAINER (pm), page3, + "custom-toolbox-widget", toolbox3, + "page-actions", TRUE, + NULL); + + GtkWidget *tb; + gboolean actions; + EosMainArea *ma = EOS_MAIN_AREA (main_area); + + eos_page_manager_set_visible_page (pm, page0); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == NULL); + g_assert (actions == FALSE); + + eos_page_manager_set_visible_page (pm, page1); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == toolbox1); + g_assert (actions == FALSE); + + eos_page_manager_set_visible_page (pm, page2); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == NULL); + g_assert (actions == TRUE); + + eos_page_manager_set_visible_page (pm, page3); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == toolbox3); + g_assert (actions == TRUE); + + gtk_widget_destroy (win); +} + void add_window_tests (void) { @@ -106,4 +240,12 @@ add_window_tests (void) test_application_not_null); ADD_APP_WINDOW_TEST ("/window/screen-size", test_screen_size); ADD_APP_WINDOW_TEST ("/window/has-top-bar", test_has_top_bar); + ADD_APP_WINDOW_TEST ("/window/has-main-area", test_has_main_area); + ADD_APP_WINDOW_TEST ("/window/has-default-page-manager", + test_has_default_page_manager); + ADD_APP_WINDOW_TEST ("/window/get-set-page-manager", + test_get_set_page_manager); + ADD_APP_WINDOW_TEST ("/window/prop-page-manager", test_prop_page_manager); + ADD_APP_WINDOW_TEST ("/window/main-area-widgets-visibility", + test_main_area_widgets_visibility); } |