summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tab-page.c227
1 files changed, 225 insertions, 2 deletions
diff --git a/src/tab-page.c b/src/tab-page.c
index eecfabd..ae6113b 100644
--- a/src/tab-page.c
+++ b/src/tab-page.c
@@ -81,6 +81,62 @@ struct _MqTabPageClass {
G_DEFINE_TYPE(MqTabPage, mq_tab_page, GTK_TYPE_BOX)
static void
+update_tree_sizes(MqTabPage *node, guint step)
+{
+ if (node) {
+ node->tree_size += step;
+ update_tree_sizes(node->parent, step);
+ }
+}
+
+static void
+append_child(MqTabPage *new_node)
+{
+ MqTabPage *parent;
+
+ parent = new_node->source;
+
+ new_node->root = parent->root;
+ new_node->parent = parent;
+ new_node->next = NULL;
+ new_node->prev = parent->last_child; /* May be NULL */
+ new_node->first_child = new_node->last_child = NULL;
+ new_node->tree_size = 0; /* Will be updated */
+ if (parent->last_child) {
+ new_node->position = parent->last_child->position;
+ parent->last_child->next = new_node;
+ } else {
+ new_node->position = parent->position;
+ parent->first_child = new_node;
+ }
+ parent->last_child = new_node;
+ mq_tab_update_positions(new_node, 1);
+ update_tree_sizes(new_node, 1);
+}
+
+static void
+append_sibling(MqTabPage *new_node)
+{
+ MqTabPage *prev_sibling;
+
+ prev_sibling = new_node->source;
+
+ new_node->root = prev_sibling->root;
+ new_node->parent = prev_sibling->parent;
+ new_node->prev = prev_sibling;
+ new_node->next = prev_sibling->next; /* May be NULL */
+ new_node->first_child = new_node->last_child = NULL;
+ new_node->position = prev_sibling->position; /* Will be updated */
+ new_node->tree_size = 0; /* Will be updated */
+ if (prev_sibling->next) {
+ prev_sibling->next->prev = new_node;
+ }
+ prev_sibling->next = new_node;
+ mq_tab_update_positions(new_node, 1);
+ update_tree_sizes(new_node, 1);
+}
+
+static void
title_cb(WebKitWebView *web_view, GParamSpec G_GNUC_UNUSED *param_spec,
MqTabPage *tab_page)
{
@@ -157,11 +213,11 @@ constructed(GObject *object)
break;
case CREATE_SIBLING:
init_non_root(tab_page);
-// append_sibling(tab_page);
+ append_sibling(tab_page);
break;
case CREATE_CHILD:
init_non_root(tab_page);
-// append_child(tab_page);
+ append_child(tab_page);
break;
case CREATE_NONE:
case N_CREATE_TYPES:
@@ -305,3 +361,170 @@ mq_tab_page_new_root(MqWindow *window)
"window", window, /* TODO: Use gtk_widget_get_parent()? */
NULL);
}
+
+void
+mq_tab_page_quit(MqTabPage *tab_page)
+{
+ mq_window_quit(tab_page->window);
+}
+
+MqApplication *
+mq_tab_page_get_application(MqTabPage *tab_page)
+{
+ return tab_page->application;
+}
+
+MqWindow *
+mq_tab_page_get_window(MqTabPage *tab_page)
+{
+ return tab_page->window;
+}
+
+void
+mq_tab_page_update_positions(MqTabPage *node, gint step)
+{
+ if (node) {
+ node->position += step;
+ if (node->tab) {
+ mq_tab_label_set_position(MQ_TAB_LABEL(node->tab),
+ node->position);
+ }
+ if (node->next) {
+ mq_tab_update_positions(node->next, step);
+ } else if (node->parent && node->parent->next) {
+ mq_tab_update_positions(node->parent->next, step);
+ }
+ }
+}
+
+void
+mq_tab_page_update_position(MqTabPage *tab_page, guint position)
+{
+ tab_page->position = position;
+ mq_tab_label_set_position(MQ_TAB_LABEL(tab_page->tab), position);
+}
+
+guint
+mq_tab_page_get_position(MqTabPage *tab_page)
+{
+ return tab_page->position;
+}
+
+guint
+mq_tab_page_get_tree_size(MqTabPage *tab_page)
+{
+ return tab_page->tree_size;
+}
+
+const gchar *
+mq_tab_page_get_title(MqTabPage *tab_page)
+{
+ return tab_page->title;
+}
+
+MqTabPage *
+mq_tab_page_seek(MqTabPage *node, guint position)
+{
+ /* Skip forward to the containing subtree. */
+ while (node && node->position + node->tree_size <= position) {
+ node = node->next;
+ }
+
+ /* Check whether we've gone past the end of the tree. */
+ if (!node) {
+ return NULL;
+ }
+
+ /* Check whether the sibling we've reached is the node we want. */
+ if (node->position == position) {
+ return node;
+ }
+
+ /* Recurse down the subtree. */
+ return mq_tab_seek(node->first_child, position);
+}
+
+static void
+foreach_tab(MqTabPage *node, void (*cb)(MqTabPage *node, va_list ap),
+ va_list ap)
+{
+ va_list aq;
+
+ for (; node; node = node->next) {
+ va_copy(ap, aq);
+ cb(node, aq);
+ va_end(aq);
+
+ va_copy(ap, aq);
+ foreach_tab(node->first_child, cb, aq);
+ va_end(aq);
+ }
+}
+
+void
+mq_tab_page_foreach(MqTabPage *node, void (*cb)(MqTabPage *node, va_list ap),
+ ...)
+{
+ va_list ap;
+
+ va_start(ap, cb);
+ foreach_tab(node->root->first_child, cb, ap);
+ va_end(ap);
+}
+
+MqTabPage *
+mq_tab_page_root(MqTabPage *node)
+{
+ return node ? node->root : NULL;
+}
+
+MqTabPage *
+mq_tab_page_previous(MqTabPage *node)
+{
+ return node ? node->prev : NULL;
+}
+
+MqTabPage *
+mq_tab_page_next(MqTabPage *node)
+{
+ return node ? node->next : NULL;
+}
+
+MqTabPage *
+mq_tab_page_first_child(MqTabPage *node)
+{
+ return node ? node->first_child : NULL;
+}
+
+void
+mq_tab_page_scroll_tab_labels(MqTabPage *node)
+{
+ for (; node; node = node->next) {
+ if (node->tab) {
+ mq_tab_label_scroll(MQ_TAB_LABEL(node->tab));
+ }
+ mq_tab_scroll_tab_labels(node->first_child);
+ }
+}
+
+void
+mq_tab_page_begin_scrolling_tab_labels(MqTabPage *node)
+{
+ for (; node; node = node->next) {
+ if (node->tab) {
+ mq_tab_label_begin_scrolling(MQ_TAB_LABEL(node->tab));
+ }
+ mq_tab_begin_scrolling_tab_labels(node->first_child);
+ }
+}
+
+void
+mq_tab_page_end_scrolling_tab_labels(MqTabPage *node)
+{
+ for (; node; node = node->next) {
+ if (node->tab) {
+ mq_tab_label_end_scrolling(MQ_TAB_LABEL(node->tab));
+ }
+ mq_tab_end_scrolling_tab_labels(node->first_child);
+ }
+}