aboutsummaryrefslogtreecommitdiffstats
path: root/libowl
diff options
context:
space:
mode:
Diffstat (limited to 'libowl')
-rw-r--r--libowl/Makefile.am15
-rw-r--r--libowl/owlpaned.c349
-rw-r--r--libowl/owlpaned.h60
-rw-r--r--libowl/owltreemodelslice.c280
-rw-r--r--libowl/owltreemodelslice.h71
5 files changed, 775 insertions, 0 deletions
diff --git a/libowl/Makefile.am b/libowl/Makefile.am
new file mode 100644
index 0000000..2386425
--- /dev/null
+++ b/libowl/Makefile.am
@@ -0,0 +1,15 @@
+libowlinclude_HEADERS = \
+ owlpaned.h \
+ owltreemodelslice.h
+
+libowlincludedir = $(includedir)/libowl/
+
+lib_LTLIBRARIES = libowl.la
+
+libowl_la_SOURCES = \
+ $(libowlinclude_HEADERS) \
+ owlpaned.c \
+ owltreemodelslice.c
+
+libowl_la_CPPFLAGS = $(GTK_CFLAGS) -Wall
+libowl_la_LIBADD = $(GTK_LIBS)
diff --git a/libowl/owlpaned.c b/libowl/owlpaned.c
new file mode 100644
index 0000000..3a6d8c8
--- /dev/null
+++ b/libowl/owlpaned.c
@@ -0,0 +1,349 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "owlpaned.h"
+
+static void owl_paned_class_init (OwlPanedClass *klass);
+static void owl_paned_init (OwlPaned *paned);
+static void owl_paned_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void owl_paned_size_allocate_h (GtkWidget *widget,
+ GtkAllocation *allocation);
+static void owl_paned_size_allocate_v (GtkWidget *widget,
+ GtkAllocation *allocation);
+
+G_DEFINE_TYPE(OwlPaned, owl_paned, GTK_TYPE_PANED);
+
+static void
+owl_paned_class_init (OwlPanedClass *class)
+{
+ GtkWidgetClass *widget_class;
+
+ widget_class = (GtkWidgetClass *) class;
+
+ widget_class->size_request = owl_paned_size_request;
+ /* Default to horizontal */
+ widget_class->size_allocate = owl_paned_size_allocate_h;
+}
+
+static void
+owl_paned_init (OwlPaned *owlpaned)
+{
+ GtkPaned *paned;
+
+ g_return_if_fail (OWL_IS_PANED (owlpaned));
+
+ paned = GTK_PANED (owlpaned);
+
+ paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
+ /* The orientation specified the orientation of the separator. */
+ paned->orientation = GTK_ORIENTATION_VERTICAL;
+}
+
+GtkWidget *
+owl_paned_new (void)
+{
+ OwlPaned *paned;
+
+ paned = g_object_new (OWL_TYPE_PANED, NULL);
+
+ return GTK_WIDGET (paned);
+}
+
+static GtkOrientation
+get_orientation (GtkAllocation *allocation)
+{
+ g_assert (allocation);
+
+ if (allocation->width >= allocation->height)
+ return GTK_ORIENTATION_VERTICAL;
+ else
+ return GTK_ORIENTATION_HORIZONTAL;
+}
+
+static void
+owl_paned_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ GtkRequisition child_requisition;
+
+ requisition->width = 0;
+ requisition->height = 0;
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
+ {
+ gtk_widget_size_request (paned->child1, &child_requisition);
+
+ requisition->height = child_requisition.height;
+ requisition->width = child_requisition.width;
+ }
+
+ if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ {
+ gtk_widget_size_request (paned->child2, &child_requisition);
+
+ if (paned->orientation == GTK_ORIENTATION_VERTICAL) {
+ requisition->height = MAX(requisition->height, child_requisition.height);
+ requisition->width += child_requisition.width;
+ } else {
+ requisition->height += child_requisition.height;
+ requisition->width = MAX (requisition->width, child_requisition.width);
+ }
+ }
+
+ requisition->width += GTK_CONTAINER (paned)->border_width * 2;
+ requisition->height += GTK_CONTAINER (paned)->border_width * 2;
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
+ paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ {
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+ if (paned->orientation == GTK_ORIENTATION_VERTICAL) {
+ requisition->width += handle_size;
+ } else {
+ requisition->height += handle_size;
+ }
+ }
+}
+
+static void
+flip_child (GtkWidget *widget, GtkAllocation *child_pos)
+{
+ gint x = widget->allocation.x;
+ gint width = widget->allocation.width;
+
+ child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
+}
+
+static void
+owl_paned_size_allocate_h (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ gint border_width = GTK_CONTAINER (paned)->border_width;
+
+ if (get_orientation (allocation) != GTK_ORIENTATION_VERTICAL) {
+ GtkWidgetClass *widget_class = GTK_WIDGET_GET_CLASS (widget);
+ widget_class->size_allocate = owl_paned_size_allocate_v;
+ owl_paned_size_allocate_v (widget, allocation);
+ return;
+ }
+
+ widget->allocation = *allocation;
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
+ paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ {
+ GtkAllocation child1_allocation;
+ GtkAllocation child2_allocation;
+ GtkRequisition child1_requisition;
+ GtkRequisition child2_requisition;
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
+ gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
+
+ gtk_paned_compute_position (paned,
+ MAX (1, widget->allocation.width
+ - handle_size
+ - 2 * border_width),
+ child1_requisition.width,
+ child2_requisition.width);
+
+ paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
+ paned->handle_pos.y = widget->allocation.y + border_width;
+ paned->handle_pos.width = handle_size;
+ paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
+
+ child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
+ child1_allocation.width = MAX (1, paned->child1_size);
+ child1_allocation.x = widget->allocation.x + border_width;
+ child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
+
+ child2_allocation.x = child1_allocation.x + paned->child1_size + paned->handle_pos.width;
+ child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
+
+ if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
+ {
+ flip_child (widget, &(child2_allocation));
+ flip_child (widget, &(child1_allocation));
+ flip_child (widget, &(paned->handle_pos));
+ }
+
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ if (GTK_WIDGET_MAPPED (widget))
+ gdk_window_show (paned->handle);
+ gdk_window_move_resize (paned->handle,
+ paned->handle_pos.x,
+ paned->handle_pos.y,
+ handle_size,
+ paned->handle_pos.height);
+ }
+
+ /* Now allocate the childen, making sure, when resizing not to
+ * overlap the windows
+ */
+ if (GTK_WIDGET_MAPPED (widget) &&
+ paned->child1->allocation.width < child1_allocation.width)
+ {
+ gtk_widget_size_allocate (paned->child2, &child2_allocation);
+ gtk_widget_size_allocate (paned->child1, &child1_allocation);
+ }
+ else
+ {
+ gtk_widget_size_allocate (paned->child1, &child1_allocation);
+ gtk_widget_size_allocate (paned->child2, &child2_allocation);
+ }
+ }
+ else
+ {
+ GtkAllocation child_allocation;
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gdk_window_hide (paned->handle);
+
+ if (paned->child1)
+ gtk_widget_set_child_visible (paned->child1, TRUE);
+ if (paned->child2)
+ gtk_widget_set_child_visible (paned->child2, TRUE);
+
+ child_allocation.x = widget->allocation.x + border_width;
+ child_allocation.y = widget->allocation.y + border_width;
+ child_allocation.width = MAX (1, allocation->width - 2 * border_width);
+ child_allocation.height = MAX (1, allocation->height - 2 * border_width);
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
+ gtk_widget_size_allocate (paned->child1, &child_allocation);
+ else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ gtk_widget_size_allocate (paned->child2, &child_allocation);
+ }
+}
+
+static void
+owl_paned_size_allocate_v (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ gint border_width = GTK_CONTAINER (paned)->border_width;
+
+ if (get_orientation (allocation) != GTK_ORIENTATION_HORIZONTAL) {
+ GtkWidgetClass *widget_class = GTK_WIDGET_GET_CLASS (widget);
+ widget_class->size_allocate = owl_paned_size_allocate_h;
+ owl_paned_size_allocate_h (widget, allocation);
+ return;
+ }
+
+ widget->allocation = *allocation;
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
+ paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ {
+ GtkRequisition child1_requisition;
+ GtkRequisition child2_requisition;
+ GtkAllocation child1_allocation;
+ GtkAllocation child2_allocation;
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
+ gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
+
+ gtk_paned_compute_position (paned,
+ MAX (1, widget->allocation.height
+ - handle_size
+ - 2 * border_width),
+ child1_requisition.height,
+ child2_requisition.height);
+
+ paned->handle_pos.x = widget->allocation.x + border_width;
+ paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
+ paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
+ paned->handle_pos.height = handle_size;
+
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ if (GTK_WIDGET_MAPPED (widget))
+ gdk_window_show (paned->handle);
+ gdk_window_move_resize (paned->handle,
+ paned->handle_pos.x,
+ paned->handle_pos.y,
+ paned->handle_pos.width,
+ handle_size);
+ }
+
+ child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
+ child1_allocation.height = MAX (1, paned->child1_size);
+ child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
+ child1_allocation.y = widget->allocation.y + border_width;
+
+ child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
+ child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
+
+ /* Now allocate the childen, making sure, when resizing not to
+ * overlap the windows
+ */
+ if (GTK_WIDGET_MAPPED (widget) &&
+ paned->child1->allocation.height < child1_allocation.height)
+ {
+ gtk_widget_size_allocate (paned->child2, &child2_allocation);
+ gtk_widget_size_allocate (paned->child1, &child1_allocation);
+ }
+ else
+ {
+ gtk_widget_size_allocate (paned->child1, &child1_allocation);
+ gtk_widget_size_allocate (paned->child2, &child2_allocation);
+ }
+ }
+ else
+ {
+ GtkAllocation child_allocation;
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gdk_window_hide (paned->handle);
+
+ if (paned->child1)
+ gtk_widget_set_child_visible (paned->child1, TRUE);
+ if (paned->child2)
+ gtk_widget_set_child_visible (paned->child2, TRUE);
+
+ child_allocation.x = widget->allocation.x + border_width;
+ child_allocation.y = widget->allocation.y + border_width;
+ child_allocation.width = MAX (1, allocation->width - 2 * border_width);
+ child_allocation.height = MAX (1, allocation->height - 2 * border_width);
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
+ gtk_widget_size_allocate (paned->child1, &child_allocation);
+ else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ gtk_widget_size_allocate (paned->child2, &child_allocation);
+ }
+}
diff --git a/libowl/owlpaned.h b/libowl/owlpaned.h
new file mode 100644
index 0000000..b7bc7ea
--- /dev/null
+++ b/libowl/owlpaned.h
@@ -0,0 +1,60 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __OWL_PANED_H__
+#define __OWL_PANED_H__
+
+#include <gtk/gtkpaned.h>
+
+G_BEGIN_DECLS
+
+#define OWL_TYPE_PANED (owl_paned_get_type ())
+#define OWL_PANED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OWL_TYPE_PANED, OwlPaned))
+#define OWL_PANED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OWL_TYPE_PANED, OwlPanedClass))
+#define OWL_IS_PANED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OWL_TYPE_PANED))
+#define OWL_IS_PANED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OWL_TYPE_PANED))
+#define OWL_PANED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OWL_TYPE_PANED, OwlPanedClass))
+
+
+typedef struct _OwlPaned OwlPaned;
+typedef struct _OwlPanedClass OwlPanedClass;
+
+struct _OwlPaned
+{
+ GtkPaned paned;
+};
+
+struct _OwlPanedClass
+{
+ GtkPanedClass parent_class;
+};
+
+GType owl_paned_get_type (void) G_GNUC_CONST;
+GtkWidget *owl_paned_new (void);
+
+G_END_DECLS
+
+#endif /* __OWL_PANED_H__ */
diff --git a/libowl/owltreemodelslice.c b/libowl/owltreemodelslice.c
new file mode 100644
index 0000000..356683f
--- /dev/null
+++ b/libowl/owltreemodelslice.c
@@ -0,0 +1,280 @@
+#include <gtk/gtk.h>
+
+#include "owltreemodelslice.h"
+
+struct _OwlTreeModelSlicePrivate {
+ GtkTreeModel *child_model;
+ GtkTreePath *root;
+};
+
+#define OWL_TREE_MODEL_SLICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OWL_TYPE_TREE_MODEL_SLICE, OwlTreeModelSlicePrivate))
+
+static void owl_tree_model_slice_tree_model_init (GtkTreeModelIface *iface);
+
+/*
+ * Implementation prototypes
+ */
+
+static GtkTreeModelFlags owl_tree_model_slice_get_flags (GtkTreeModel *model);
+static gint owl_tree_model_slice_get_n_columns (GtkTreeModel *model);
+static GType owl_tree_model_slice_get_column_type (GtkTreeModel *model, gint index);
+static gboolean owl_tree_model_slice_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path);
+// TODO get_path
+static void owl_tree_model_slice_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value);
+static gboolean owl_tree_model_slice_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter);
+static gboolean owl_tree_model_slice_iter_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent);
+static gboolean owl_tree_model_slice_iter_has_child (GtkTreeModel *model, GtkTreeIter *iter);
+static gint owl_tree_model_slice_iter_n_children (GtkTreeModel *model, GtkTreeIter *iter);
+static gboolean owl_tree_model_slice_iter_nth_child (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent, gint n);
+static gboolean owl_tree_model_slice_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *child);
+// TODO ref node
+// TODO unref node
+
+G_DEFINE_TYPE_EXTENDED (OwlTreeModelSlice,
+ owl_tree_model_slice,
+ G_TYPE_OBJECT,
+ 0,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
+ owl_tree_model_slice_tree_model_init));
+
+static void
+owl_tree_model_slice_init (OwlTreeModelSlice *slice)
+{
+ slice->priv = OWL_TREE_MODEL_SLICE_GET_PRIVATE (slice);
+}
+
+static void
+owl_tree_model_slice_class_init (OwlTreeModelSliceClass *klass)
+{
+ g_type_class_add_private (G_OBJECT_CLASS (klass), sizeof (OwlTreeModelSlicePrivate));
+}
+
+static void
+owl_tree_model_slice_tree_model_init (GtkTreeModelIface *iface)
+{
+ iface->get_flags = owl_tree_model_slice_get_flags;
+ iface->get_n_columns = owl_tree_model_slice_get_n_columns;
+ iface->get_column_type = owl_tree_model_slice_get_column_type;
+ iface->get_iter = owl_tree_model_slice_get_iter;
+ //iface->get_path = owl_tree_model_slice_get_path;
+ iface->get_value = owl_tree_model_slice_get_value;
+ iface->iter_next = owl_tree_model_slice_iter_next;
+ iface->iter_children = owl_tree_model_slice_iter_children;
+ iface->iter_has_child = owl_tree_model_slice_iter_has_child;
+ iface->iter_n_children = owl_tree_model_slice_iter_n_children;
+ iface->iter_nth_child = owl_tree_model_slice_iter_nth_child;
+ iface->iter_parent = owl_tree_model_slice_iter_parent;
+ // iface->ref_node = owl_tree_model_slice_ref_node;
+ // iface->unref_node = owl_tree_model_slice_unref_node;
+}
+
+static GtkTreeModelFlags
+owl_tree_model_slice_get_flags (GtkTreeModel *model)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, 0);
+ g_return_val_if_fail (slice->priv->child_model != NULL, 0);
+
+ return gtk_tree_model_get_flags (slice->priv->child_model) | GTK_TREE_MODEL_LIST_ONLY;
+}
+
+static gint
+owl_tree_model_slice_get_n_columns (GtkTreeModel *model)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, 0);
+ g_return_val_if_fail (slice->priv->child_model != NULL, 0);
+
+ return gtk_tree_model_get_n_columns (slice->priv->child_model);
+}
+
+static GType
+owl_tree_model_slice_get_column_type (GtkTreeModel *model, gint index)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, G_TYPE_INVALID);
+ g_return_val_if_fail (slice->priv->child_model != NULL, G_TYPE_INVALID);
+
+ return gtk_tree_model_get_column_type (slice->priv->child_model, index);
+}
+
+static GtkTreePath*
+convert_to_child (OwlTreeModelSlice *slice, GtkTreePath *path)
+{
+ GtkTreePath *new_path;
+ gint depth;
+ gint *indices;
+
+ g_assert (slice);
+ g_assert (path);
+
+ if (slice->priv->root == NULL)
+ return path;
+
+ new_path = gtk_tree_path_copy (slice->priv->root);
+ depth = gtk_tree_path_get_depth (path);
+ indices = gtk_tree_path_get_indices (path);
+ while (depth--)
+ gtk_tree_path_append_index (new_path, *indices++);
+ return new_path;
+}
+
+static gboolean
+owl_tree_model_slice_get_iter (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GtkTreePath *path)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+ GtkTreePath *new_path;
+
+ g_return_val_if_fail (slice != NULL, FALSE);
+ g_return_val_if_fail (slice->priv->child_model != NULL, FALSE);
+
+ new_path = convert_to_child (slice, path);
+
+ return gtk_tree_model_get_iter (slice->priv->child_model, iter, new_path);
+}
+
+static void
+owl_tree_model_slice_get_value (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gint column,
+ GValue *value)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_if_fail (slice != NULL);
+ g_return_if_fail (slice->priv->child_model != NULL);
+
+ gtk_tree_model_get_value (slice->priv->child_model, iter, column, value);
+}
+
+static gboolean
+owl_tree_model_slice_iter_next (GtkTreeModel *model,
+ GtkTreeIter *iter)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, FALSE);
+ g_return_val_if_fail (slice->priv->child_model != NULL, FALSE);
+
+ return gtk_tree_model_iter_next (slice->priv->child_model, iter);
+}
+
+static gboolean
+owl_tree_model_slice_iter_children (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, FALSE);
+ g_return_val_if_fail (slice->priv->child_model != NULL, FALSE);
+
+ if (parent == NULL)
+ return gtk_tree_model_get_iter_first (model, iter);
+ else
+ return FALSE;
+}
+
+static gboolean
+owl_tree_model_slice_iter_has_child (GtkTreeModel *model,
+ GtkTreeIter *iter)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, FALSE);
+ g_return_val_if_fail (slice->priv->child_model != NULL, FALSE);
+
+ return FALSE;
+}
+
+static gint
+owl_tree_model_slice_iter_n_children (GtkTreeModel *model,
+ GtkTreeIter *iter)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, 0);
+ g_return_val_if_fail (slice->priv->child_model != NULL, 0);
+
+ if (iter) {
+ return 0;
+ } else {
+ GtkTreeIter child_iter;
+ if (!gtk_tree_model_get_iter (slice->priv->child_model, &child_iter, slice->priv->root)) {
+ g_warning ("Cannot get child iterator");
+ return 0;
+ }
+ return gtk_tree_model_iter_n_children (slice->priv->child_model, &child_iter);
+ }
+}
+
+
+static gboolean
+owl_tree_model_slice_iter_nth_child (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent,
+ gint n)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, FALSE);
+ g_return_val_if_fail (slice->priv->child_model != NULL, FALSE);
+
+ if (parent != NULL)
+ return FALSE;
+ else
+ return gtk_tree_model_iter_nth_child (slice->priv->child_model, iter, parent, n);
+}
+
+static gboolean
+owl_tree_model_slice_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *child)
+{
+ OwlTreeModelSlice *slice = OWL_TREE_MODEL_SLICE (model);
+
+ g_return_val_if_fail (slice != NULL, FALSE);
+ g_return_val_if_fail (slice->priv->child_model != NULL, FALSE);
+
+ return FALSE;
+}
+
+GtkTreeModel *
+owl_tree_model_slice_new (GtkTreeModel *child_model,
+ GtkTreePath *root)
+{
+ OwlTreeModelSlice *slice;
+
+ g_return_val_if_fail (child_model != NULL, NULL);
+
+ slice = g_object_new (OWL_TYPE_TREE_MODEL_SLICE, NULL);
+
+ slice->priv->child_model = child_model;
+ slice->priv->root = root;
+
+ return (GtkTreeModel *)slice;
+}
+
+GtkTreeModel *
+gtk_tree_model_slice_get_model (OwlTreeModelSlice *slice)
+{
+ g_return_val_if_fail (OWL_IS_TREE_MODEL_SLICE (slice), NULL);
+
+ return slice->priv->child_model;
+}
+
+
+/* TODO */
+void owl_tree_model_slice_convert_child_iter_to_iter (OwlTreeModelSlice *slice,
+ GtkTreeIter *slice_iter,
+ GtkTreeIter *child_iter);
+void owl_tree_model_slice_convert_iter_to_child_iter (OwlTreeModelSlice *slice,
+ GtkTreeIter *child_iter,
+ GtkTreeIter *slice_iter);
+GtkTreePath *owl_tree_model_slice_convert_child_path_to_path (OwlTreeModelSlice *slice,
+ GtkTreePath *child_path);
+GtkTreePath *owl_tree_model_slice_convert_path_to_child_path (OwlTreeModelSlice *slice,
+ GtkTreePath *slice_path);
diff --git a/libowl/owltreemodelslice.h b/libowl/owltreemodelslice.h
new file mode 100644
index 0000000..5564503
--- /dev/null
+++ b/libowl/owltreemodelslice.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2006 Ross Burton <ross@openedhand.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __OWL_TREE_MODEL_SLICE_H__
+#define __OWL_TREE_MODEL_SLICE_H__
+
+#include <gtk/gtktreemodel.h>
+
+G_BEGIN_DECLS
+
+#define OWL_TYPE_TREE_MODEL_SLICE (owl_tree_model_slice_get_type ())
+#define OWL_TREE_MODEL_SLICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OWL_TYPE_TREE_MODEL_SLICE, OwlTreeModelSlice))
+#define OWL_TREE_MODEL_SLICE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), OWL_TYPE_TREE_MODEL_SLICE, OwlTreeModelSliceClass))
+#define OWL_IS_TREE_MODEL_SLICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OWL_TYPE_TREE_MODEL_SLICE))
+#define OWL_IS_TREE_MODEL_SLICE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), OWL_TYPE_TREE_MODEL_SLICE))
+#define OWL_TREE_MODEL_SLICE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((obj), OWL_TYPE_TREE_MODEL_SLICE, OwlTreeModelSliceClass))
+
+typedef struct _OwlTreeModelSlice OwlTreeModelSlice;
+typedef struct _OwlTreeModelSliceClass OwlTreeModelSliceClass;
+typedef struct _OwlTreeModelSlicePrivate OwlTreeModelSlicePrivate;
+
+struct _OwlTreeModelSlice
+{
+ GObject parent;
+
+ /*< private >*/
+ OwlTreeModelSlicePrivate *priv;
+};
+
+struct _OwlTreeModelSliceClass
+{
+ GObjectClass parent_class;
+};
+
+GType owl_tree_model_slice_get_type (void) G_GNUC_CONST;
+GtkTreeModel *owl_tree_model_slice_new (GtkTreeModel *child_model,
+ GtkTreePath *root);
+
+GtkTreeModel *gtk_tree_model_slice_get_model (OwlTreeModelSlice *slice);
+
+/* TODO */
+void owl_tree_model_slice_convert_child_iter_to_iter (OwlTreeModelSlice *slice,
+ GtkTreeIter *slice_iter,
+ GtkTreeIter *child_iter);
+void owl_tree_model_slice_convert_iter_to_child_iter (OwlTreeModelSlice *slice,
+ GtkTreeIter *child_iter,
+ GtkTreeIter *slice_iter);
+GtkTreePath *owl_tree_model_slice_convert_child_path_to_path (OwlTreeModelSlice *slice,
+ GtkTreePath *child_path);
+GtkTreePath *owl_tree_model_slice_convert_path_to_child_path (OwlTreeModelSlice *slice,
+ GtkTreePath *slice_path);
+
+G_END_DECLS
+
+#endif /* __OWL_TREE_MODEL_SLICE_H__ */