change_current_page handler

master
Yevgen Muntyan 2007-11-15 22:52:40 -06:00
parent 419f1db1f8
commit 79ba20591b
1 changed files with 102 additions and 35 deletions

View File

@ -223,6 +223,8 @@ static void moo_notebook_set_focus_child(GtkContainer *container,
static void moo_notebook_switch_page (MooNotebook *nb,
guint page_num);
static gboolean moo_notebook_change_current_page (GtkNotebook *notebook,
int offset);
static void notebook_create_arrows (MooNotebook *nb);
static void left_arrow_clicked (GtkWidget *button,
@ -315,6 +317,7 @@ static void moo_notebook_class_init (MooNotebookClass *klass)
GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
moo_notebook_parent_class = g_type_class_peek_parent (klass);
moo_notebook_grand_parent_class = g_type_class_peek_parent (moo_notebook_parent_class);
@ -362,6 +365,9 @@ static void moo_notebook_class_init (MooNotebookClass *klass)
container_class->remove = moo_notebook_remove;
container_class->add = moo_notebook_add;
/* Ctrl-PgUp/PgDown bindings */
notebook_class->change_current_page = moo_notebook_change_current_page;
klass->switch_page = moo_notebook_switch_page;
g_object_class_install_property (gobject_class,
@ -1427,7 +1433,8 @@ void moo_notebook_set_show_tabs (MooNotebook *notebook,
/* Children
*/
static int page_index (MooNotebook *nb,
static int
page_index (MooNotebook *nb,
Page *page)
{
g_return_val_if_fail (page != NULL, -1);
@ -1435,7 +1442,8 @@ static int page_index (MooNotebook *nb,
}
static int page_visible_index (MooNotebook *nb,
static int
page_visible_index (MooNotebook *nb,
Page *page)
{
int i = 0;
@ -1453,7 +1461,8 @@ static int page_visible_index (MooNotebook *nb,
}
static int get_n_visible_pages (MooNotebook *nb)
static int
get_n_visible_pages (MooNotebook *nb)
{
int n = 0;
@ -1465,7 +1474,8 @@ static int get_n_visible_pages (MooNotebook *nb)
}
static Page *get_nth_visible_page (MooNotebook *nb,
static Page *
get_nth_visible_page (MooNotebook *nb,
int n)
{
int i = 0;
@ -1482,7 +1492,8 @@ static Page *get_nth_visible_page (MooNotebook *nb,
/* XXX focus */
gint moo_notebook_insert_page (MooNotebook *nb,
gint
moo_notebook_insert_page (MooNotebook *nb,
GtkWidget *child,
GtkWidget *label,
gint position)
@ -1523,7 +1534,7 @@ gint moo_notebook_insert_page (MooNotebook *nb,
if (GTK_WIDGET_VISIBLE (child) && nb->priv->tabs_visible)
{
/* XXX do soemthing about tabs */
/* XXX do something about tabs */
GTK_WIDGET_SET_FLAGS (nb, GTK_CAN_FOCUS);
gtk_widget_show (label);
}
@ -1541,7 +1552,8 @@ gint moo_notebook_insert_page (MooNotebook *nb,
}
void moo_notebook_reorder_child (MooNotebook *notebook,
void
moo_notebook_reorder_child (MooNotebook *notebook,
GtkWidget *child,
gint position)
{
@ -1568,7 +1580,8 @@ void moo_notebook_reorder_child (MooNotebook *notebook,
}
static Page *find_child (MooNotebook *nb,
static Page *
find_child (MooNotebook *nb,
GtkWidget *child)
{
GSList *l;
@ -1584,7 +1597,8 @@ static Page *find_child (MooNotebook *nb,
}
static Page *find_grand_child (MooNotebook *nb,
static Page *
find_grand_child (MooNotebook *nb,
GtkWidget *child)
{
GSList *l;
@ -1602,7 +1616,8 @@ static Page *find_grand_child (MooNotebook *nb,
}
static Page *find_label (MooNotebook *nb,
static Page *
find_label (MooNotebook *nb,
GtkWidget *label)
{
GSList *l;
@ -1618,7 +1633,8 @@ static Page *find_label (MooNotebook *nb,
}
static Page *get_nth_page (MooNotebook *nb,
static Page *
get_nth_page (MooNotebook *nb,
int n)
{
if (n < 0)
@ -1628,7 +1644,8 @@ static Page *get_nth_page (MooNotebook *nb,
}
static int find_next_visible_page (MooNotebook *nb,
static int
find_next_visible_page (MooNotebook *nb,
int n)
{
int num_pages = moo_notebook_get_n_pages (nb);
@ -1662,7 +1679,8 @@ static int find_next_visible_page (MooNotebook *nb,
}
static void delete_page (MooNotebook *nb,
static void
delete_page (MooNotebook *nb,
Page *page)
{
int n = page_index (nb, page);
@ -1691,7 +1709,8 @@ static void delete_page (MooNotebook *nb,
}
void moo_notebook_remove_page (MooNotebook *notebook,
void
moo_notebook_remove_page (MooNotebook *notebook,
gint page_num)
{
Page *page;
@ -1702,14 +1721,16 @@ void moo_notebook_remove_page (MooNotebook *notebook,
}
gint moo_notebook_get_n_pages (MooNotebook *notebook)
gint
moo_notebook_get_n_pages (MooNotebook *notebook)
{
g_return_val_if_fail (MOO_IS_NOTEBOOK (notebook), 0);
return g_slist_length (notebook->priv->pages);
}
gint moo_notebook_page_num (MooNotebook *notebook,
gint
moo_notebook_page_num (MooNotebook *notebook,
GtkWidget *child)
{
Page *page;
@ -1726,9 +1747,11 @@ gint moo_notebook_page_num (MooNotebook *notebook,
}
gint moo_notebook_get_current_page (MooNotebook *notebook)
gint
moo_notebook_get_current_page (MooNotebook *notebook)
{
g_return_val_if_fail (MOO_IS_NOTEBOOK (notebook), -1);
if (notebook->priv->current_page)
return page_index (notebook, notebook->priv->current_page);
else
@ -1736,7 +1759,8 @@ gint moo_notebook_get_current_page (MooNotebook *notebook)
}
GtkWidget* moo_notebook_get_nth_page (MooNotebook *notebook,
GtkWidget *
moo_notebook_get_nth_page (MooNotebook *notebook,
gint page_num)
{
Page *page;
@ -1752,6 +1776,49 @@ GtkWidget* moo_notebook_get_nth_page (MooNotebook *notebook,
}
static gboolean
moo_notebook_change_current_page (GtkNotebook *notebook,
int offset)
{
MooNotebook *nb = MOO_NOTEBOOK (notebook);
int new_page, n_pages;
g_return_val_if_fail (offset == 1 || offset == -1, FALSE);
if (!nb->priv->current_page)
return FALSE;
new_page = moo_notebook_get_current_page (nb);
n_pages = moo_notebook_get_n_pages (nb);
g_return_val_if_fail (new_page >= 0 && n_pages > 0, FALSE);
if (offset > 0)
{
for (new_page += 1; new_page < n_pages; new_page++)
if (GTK_WIDGET_VISIBLE (moo_notebook_get_nth_page (nb, new_page)))
break;
if (new_page == n_pages)
for (new_page = 0; new_page < n_pages; new_page++)
if (GTK_WIDGET_VISIBLE (moo_notebook_get_nth_page (nb, new_page)))
break;
g_return_val_if_fail (new_page < n_pages, FALSE);
}
else
{
for (new_page -= 1; new_page >= 0; new_page--)
if (GTK_WIDGET_VISIBLE (moo_notebook_get_nth_page (nb, new_page)))
break;
if (new_page < 0)
for (new_page = n_pages - 1; new_page >= 0; new_page--)
if (GTK_WIDGET_VISIBLE (moo_notebook_get_nth_page (nb, new_page)))
break;
g_return_val_if_fail (new_page >= 0, FALSE);
}
moo_notebook_set_current_page (nb, new_page);
return TRUE;
}
static void
moo_notebook_switch_page (MooNotebook *nb,
guint page_num)