diff --git a/docs/reference/libmx/mx-sections.txt b/docs/reference/libmx/mx-sections.txt index ba5d7a80..133306b8 100644 --- a/docs/reference/libmx/mx-sections.txt +++ b/docs/reference/libmx/mx-sections.txt @@ -1514,6 +1514,8 @@ MxNotebookClass mx_notebook_new mx_notebook_set_current_page mx_notebook_get_current_page +mx_notebook_previous_page +mx_notebook_next_page mx_notebook_get_enable_gestures mx_notebook_set_enable_gestures diff --git a/mx/mx-notebook.c b/mx/mx-notebook.c index 0929c587..a1c06bfe 100644 --- a/mx/mx-notebook.c +++ b/mx/mx-notebook.c @@ -467,23 +467,11 @@ mx_notebook_gesture_slide_event_cb (ClutterGesture *gesture, } if (event->direction % 2) - { - /* up, left (1, 3) */ - if (item->prev) - mx_notebook_set_current_page (book, (ClutterActor *)item->prev->data); - else - mx_notebook_set_current_page (book, - (ClutterActor *)g_list_last (item)->data); - } + /* up, left (1, 3) */ + mx_notebook_previous_page (book); else - { - /* down, right (2, 4) */ - if (item->next) - mx_notebook_set_current_page (book, (ClutterActor *)item->next->data); - else - mx_notebook_set_current_page (book, - (ClutterActor *)priv->children->data); - } + /* down, right (2, 4) */ + mx_notebook_next_page (book); return TRUE; } @@ -575,6 +563,66 @@ mx_notebook_get_current_page (MxNotebook *notebook) return notebook->priv->current_page; } +/** + * mx_notebook_previous_page: + * @notebook: A #MxNotebook + * + * Change the current page to previous one. + */ +void +mx_notebook_previous_page (MxNotebook *notebook) +{ + GList *item; + MxNotebookPrivate *priv; + + g_return_if_fail (MX_IS_NOTEBOOK (notebook)); + priv = notebook->priv; + + item = g_list_find (priv->children, priv->current_page); + if (!item) + { + g_warning ("Current page not found in child list"); + return; + } + + if (item->prev) + mx_notebook_set_current_page (notebook, + (ClutterActor *)item->prev->data); + else + mx_notebook_set_current_page (notebook, + (ClutterActor *)g_list_last (item)->data); +} + +/** + * mx_notebook_next_page: + * @notebook: A #MxNotebook + * + * Change the current page to next one. + */ +void +mx_notebook_next_page (MxNotebook *notebook) +{ + GList *item; + MxNotebookPrivate *priv; + + g_return_if_fail (MX_IS_NOTEBOOK (notebook)); + priv = notebook->priv; + + item = g_list_find (priv->children, priv->current_page); + if (!item) + { + g_warning ("Current page not found in child list"); + return; + } + + if (item->next) + mx_notebook_set_current_page (notebook, + (ClutterActor *)item->next->data); + else + mx_notebook_set_current_page (notebook, + (ClutterActor *)priv->children->data); +} + void mx_notebook_set_enable_gestures (MxNotebook *book, gboolean enabled) diff --git a/mx/mx-notebook.h b/mx/mx-notebook.h index fb88e0bc..b0975b47 100644 --- a/mx/mx-notebook.h +++ b/mx/mx-notebook.h @@ -91,6 +91,9 @@ void mx_notebook_set_current_page (MxNotebook *notebook, ClutterActor *page); ClutterActor *mx_notebook_get_current_page (MxNotebook *notebook); +void mx_notebook_previous_page (MxNotebook *notebook); +void mx_notebook_next_page (MxNotebook *notebook); + gboolean mx_notebook_get_enable_gestures (MxNotebook *book); void mx_notebook_set_enable_gestures (MxNotebook *book, gboolean enabled);