Gtk{Tree,List} replacement proposal



Hi,

As some of you know, I've been working for the last few months on a
replacement for the old GtkTree stuff (and in particular, a better
CList,CTree).  I think I finally have the API far enough along that I
can post it to the list for comments.

First, a quick note about the design of the tree:

There are a number of objects associated with this:
 GtkTLView - a view for trees/lists
 GtkTLModel - a generic model for Trees/Lists.
 GtkTreeModel - a simple implementation of the TLModel based on GNodes.
 GtkListModel - a simple implementation of the TLModel for a list
                solution.  It needs a bit of work, and an RBTree
                implementation. 
 GtkTLCell - A generic model for cell renderers
 GtkTlCellTest - a simple implementation for testing purposes (needs to
                 be moved to pango)
 GRBTree - A red-black tree.  It's pretty specific to this
           implementation so it needs renaming at some point.

The tree is split into model/view parts (similar to the tree in swing)
and was inspired somewhat by their design.  Here's an example of some
simple code that creates a tree.

{
        GtkObject *model;
        GtkWidget *view, *window, *scroll;

        model = gtk_tree_model_new ();
        my_init_model (model);
        view = gtk_tlview_new_from_model (model);

        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        scroll = gtk_scrolled_window_new (NULL, NULL);
        gtk_container_add (GTK_CONTAINER (scroll), view);
        gtk_container_add (GTK_CONTAINER (window), scroll);
}

Additionally, if you want to wrap your own model (a database, a
filesystem) you just have to inherit from GtkTLModel and implement your
own accessors.

Some notes on the implementation:
 * The view was designed to hold very-large datasets.  The test program
   has a tree with 50K items in it.
 * Prelighting is currently borked.  I know this and will try to fix it
   soon.
 * There is no DnD API.  This needs to be written.  As I know people
   didn't like the CList interface, and I never really used it, I'd like
   to know what you think.
 * There is no way to alphabetize icons.  I'd like to do this in the
   Java style (with a model wrapping a model) but it hasn't been written
   yet.

The source code is in the 'gtree' module in CVS and needs GTK-1.3
installed to work.  You will need to do a little bit of Makefile hacking,
too, as the it is currently written against my machine.

Thanks,
-Jonathan

Here are the header files:

---------
gtktlview.h
---------
/* gtktlview.h
 * Copyright (C) 2000  Jonathan Blandford
 *
 * 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 __GTK_TLVIEW_H__
#define __GTK_TLVIEW_H__

#include <gtk/gtk.h>
#include "gtktlmodel.h"

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#define GTK_TYPE_TLVIEW			(gtk_tlview_get_type ())
#define GTK_TLVIEW(obj)			(GTK_CHECK_CAST ((obj), GTK_TYPE_TLVIEW, GtkTLView))
#define GTK_TLVIEW_CLASS(klass)		(GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TLVIEW, GtkTLViewClass))
#define GTK_IS_TLVIEW(obj)		(GTK_CHECK_TYPE ((obj), GTK_TYPE_TLVIEW))
#define GTK_IS_TLVIEW_CLASS(klass)	(GTK_CHECK_CLASS_TYPE ((obj), GTK_TYPE_TLVIEW))


typedef enum
{
  GTK_TLVIEW_COLUMN_RESIZEABLE,
  GTK_TLVIEW_COLUMN_AUTOSIZE,
  GTK_TLVIEW_COLUMN_FIXED
} GtkTLViewColumnType;

typedef enum
{
  GTK_TLVIEW_SELECTION_SINGLE,
  GTK_TLVIEW_SELECTION_MULTI
} GtkTLViewSelectionType;

typedef struct _GtkTLView       GtkTLView;
typedef struct _GtkTLViewClass  GtkTLViewClass;
typedef void (*GtkTLViewForeachFunc) (GtkTLNode *node,
				      gpointer  data);
typedef gboolean (*GtkTLViewSelectFunc) (GtkTLNode *node,
					 gpointer data);
struct _GtkTLView
{
  GtkContainer parent;

  gpointer priv;
};

struct _GtkTLViewClass
{
  GtkContainerClass parent_class;

  void (*set_scroll_adjustments) (GtkTLView     *tlview,
				  GtkAdjustment *hadjustment,
				  GtkAdjustment *vadjustment);
};

GtkType        gtk_tlview_get_type                 (void);
GtkWidget     *gtk_tlview_new                      (void);
GtkWidget     *gtk_tlview_new_with_model           (GtkTLModel       *model);

/* Accessors */
GtkTLModel    *gtk_tlview_get_model                (GtkTLView        *tlview);
void           gtk_tlview_set_model                (GtkTLView        *tlview,
						    GtkTLModel       *tlmodel);
GtkAdjustment *gtk_tlview_get_hadjustment          (GtkTLView        *layout);
void           gtk_tlview_set_hadjustment          (GtkTLView        *layout,
						    GtkAdjustment    *adjustment);
GtkAdjustment *gtk_tlview_get_vadjustment          (GtkTLView        *layout);
void           gtk_tlview_set_vadjustment          (GtkTLView        *layout,
						    GtkAdjustment    *adjustment);
gboolean       gtk_tlview_get_headers_visible      (GtkTLView        *tlview);
void           gtk_tlview_set_headers_visible      (GtkTLView        *tlview,
						    gboolean          headers_visible);

/* Selection code */
void           gtk_tlview_selection_set_type       (GtkTLView        *tlview,
						    GtkTLViewSelectionType type);
/* Only meaningful if SELECTION_SINGLE is set */
GtkTLNode     *gtk_tlview_get_selected             (GtkTLView        *tlview);
void           gtk_tlview_selected_foreach         (GtkTLView        *tlview,
						    GtkTLViewForeachFunc func,
						    gpointer          data);
void           gtk_tlview_set_select_function      (GtkTLView        *tlview,
						    GtkTLViewSelectFunc func,
						    gpointer          data);
void           gtk_tlview_select_row               (GtkTLView        *tlview,
						    GtkTLPath        *path);
void           gtk_tlview_unselect_row             (GtkTLView        *tlview,
						    GtkTLPath        *path);
void           gtk_tlview_select_all               (GtkTLView        *tlview);
void           gtk_tlview_unselect_all             (GtkTLView        *tlview);

/* Options for manipulating the columns */
void           gtk_tlview_column_set_visible       (GtkTLView        *tlview,
						    gint              column,
						    gboolean          visible);
gboolean       gtk_tlview_column_get_visible       (GtkTLView        *tlview,
						    gint              column);
void           gtk_tlview_column_set_type          (GtkTLView           *tlview,
						    gint                 column,
						    GtkTLViewColumnType  type);
gint           gtk_tlview_column_get_type          (GtkTLView        *tlview,
						    gint              column);
void           gtk_tlview_columns_set_type         (GtkTLView           *tlview,
						    GtkTLViewColumnType  type);
gint           gtk_tlview_column_get_preferred_size(GtkTLView        *tlview,
						    gint              column);
void           gtk_tlview_columns_autosize         (GtkTLView        *tlview);
gint           gtk_tlview_column_get_size          (GtkTLView        *tlview,
						    gint              column);
void           gtk_tlview_column_set_size          (GtkTLView        *tlview,
						    gint              column,
						    gint              width);
void           gtk_tlview_column_set_min_width     (GtkTLView        *tlview,
						    gint              column,
						    gint              min_width);
gint           gtk_tlview_column_get_min_width     (GtkTLView        *tlview,
						    gint              column);
void           gtk_tlview_column_set_max_width     (GtkTLView        *tlview,
						    gint              column,
						    gint              max_width);
gint           gtk_tlview_column_get_max_width     (GtkTLView        *tlview,
						    gint              column);

/* Options for manipulating the column headers */
void           gtk_tlview_column_set_title_active  (GtkTLView        *tlview,
						    gint              column,
						    gboolean          active);
void           gtk_tlview_columns_set_title_active (GtkTLView        *tlview,
						    gboolean          active);
void           gtk_tlview_column_set_widget        (GtkTLView        *tlview,
						    gint              column,
						    GtkWidget        *widget);
GtkWidget *    gtk_tlview_column_get_widget        (GtkTLView        *tlview,
						    gint              column);
void           gtk_tlview_column_set_justification (GtkTLView        *tlview,
						    gint              column,
						    GtkJustification  justification);
GtkJustification gtk_tlview_column_get_justification(GtkTLView        *tlview,
						     gint              column);

/* Actions */
void           gtk_tlview_moveto                   (GtkTLView        *tlview,
						    GtkTLPath        *path,
						    gint              column,
						    gfloat            row_align,
						    gfloat            col_align);
						    
void           gtk_tlview_expand_all               (GtkTLView        *tlview);
void           gtk_tlview_collapse_all             (GtkTLView        *tlview);

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __GTK_TLVIEW_H__ */

---------
gtktlmodel.h
---------
/* gtktlmodel.h
 * Copyright (C) 2000  Jonathan Blandford
 *
 * 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 __GTK_TLMODEL_H__
#define __GTK_TLMODEL_H__

#include <gtk/gtk.h>
#include "gtktlcell.h"

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#define GTK_TYPE_TLMODEL			(gtk_tlmodel_get_type ())
#define GTK_TLMODEL(obj)			(GTK_CHECK_CAST ((obj), GTK_TYPE_TLMODEL, GtkTLModel))
#define GTK_TLMODEL_CLASS(klass)		(GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TLMODEL, GtkTLModelClass))
#define GTK_IS_TLMODEL(obj)			(GTK_CHECK_TYPE ((obj), GTK_TYPE_TLMODEL))
#define GTK_IS_TLMODEL_CLASS(klass)		(GTK_CHECK_CLASS_TYPE ((obj), GTK_TYPE_TLMODEL))
#define GTK_TLMODEL_GET_CLASS(obj)              (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TLMODEL, GtkTLModelClass))

typedef gpointer                GtkTLNode;
typedef struct _GtkTLPath       GtkTLPath;
typedef struct _GtkTLModel      GtkTLModel;
typedef struct _GtkTLModelClass GtkTLModelClass;

struct _GtkTLModel
{
  GtkObject parent;
};

struct _GtkTLModelClass
{
  GtkObjectClass parent_class;

  /* signals */
  void       (* node_changed)    (GtkTLModel *TLModel, GtkTLPath  *path);
  void       (* node_inserted)   (GtkTLModel *TLModel, GtkTLPath  *path);
  void       (* node_deleted)    (GtkTLModel *TLModel, GtkTLPath  *path);

  /* VTable - not signals */
  gint       (* get_columns)       (GtkTLModel *TLModel);
  gchar     *(* get_column_header) (GtkTLModel *TLModel, gint      column);

  GtkTLPath *(* get_root_path)   (GtkTLModel *TLModel);
  GtkTLNode  (* get_node)        (GtkTLModel *TLModel, GtkTLPath  *path);

  GtkTLCell *(* node_get_cell)   (GtkTLModel *TLModel, GtkTLNode   node, gint     column);
  gpointer   (* node_get_data)   (GtkTLModel *TLModel, GtkTLNode   node, gint     column);
  void       (* node_set_udata)  (GtkTLModel *TLModel, GtkTLNode   node, gpointer udata);
  gpointer   (* node_get_udata)  (GtkTLModel *TLModel, GtkTLNode   node);
  GtkTLNode  (* node_copy)       (GtkTLModel *TLModel, GtkTLNode   node);
  gboolean   (* node_next)       (GtkTLModel *TLModel, GtkTLNode  *node);
  GtkTLNode  (* node_children)   (GtkTLModel *TLModel, GtkTLNode   node);
  gboolean   (* node_has_child)  (GtkTLModel *TLModel, GtkTLNode   node);
  gint       (* node_n_children) (GtkTLModel *TLModel, GtkTLNode   node);
  GtkTLNode  (* node_nth_child)  (GtkTLModel *TLModel, GtkTLNode   node, gint     n);
  GtkTLNode  (* node_parent)     (GtkTLModel *TLModel, GtkTLNode   node);
  /* other node functions ...*/
};


/* Basic tlmodel operations */
GtkType      gtk_tlmodel_get_type          (void);

/* GtkTLPath Operations */
GtkTLPath   *gtk_tlpath_new                (void);
void         gtk_tlpath_add_index          (GtkTLPath  *path,
					    gint        index);
void         gtk_tlpath_prepend_index      (GtkTLPath  *path,
					    gint        index);
gint         gtk_tlpath_get_depth          (GtkTLPath  *path);
const gint * gtk_tlpath_get_indices        (GtkTLPath  *path);
void         gtk_tlpath_free               (GtkTLPath  *path);
GtkTLPath   *gtk_tlpath_copy               (GtkTLPath  *path);

/* Header operations */
gint         gtk_tlmodel_get_columns       (GtkTLModel *tlmodel);
gchar       *gtk_tlmodel_get_column_header (GtkTLModel *tlmodel,
					    gint        column);

/* Path manipulations */
GtkTLPath   *gtk_tlmodel_get_root_path     (GtkTLModel *tlmodel);

/* Node operations */
GtkTLNode    gtk_tlmodel_get_node          (GtkTLModel *tlmodel,
					    GtkTLPath  *path);
void         gtk_tlmodel_node_set_udata    (GtkTLModel *TLModel,
					    GtkTLNode   node,
					    gpointer    udata);
gpointer     gtk_tlmodel_node_get_udata    (GtkTLModel *TLModel,
					    GtkTLNode   node);
GtkTLCell   *gtk_tlmodel_node_get_cell     (GtkTLModel *TLModel,
					    GtkTLNode   node,
					    gint        column);
gpointer     gtk_tlmodel_node_get_data     (GtkTLModel *TLModel,
					    GtkTLNode   node,
					    gint        column);
GtkTLNode    gtk_tlmodel_node_copy         (GtkTLModel *tlmodel,
					    GtkTLNode   node);
gboolean     gtk_tlmodel_node_next         (GtkTLModel *tlmodel,
					    GtkTLNode  *node);
GtkTLNode    gtk_tlmodel_node_children     (GtkTLModel *tlmodel,
					    GtkTLNode   node);
gboolean     gtk_tlmodel_node_has_child    (GtkTLModel *tlmodel,
					    GtkTLNode   node);
gint         gtk_tlmodel_node_n_children   (GtkTLModel *tlmodel,
					    GtkTLNode   node);
GtkTLNode    gtk_tlmodel_node_nth_child    (GtkTLModel *tlmodel,
					    GtkTLNode   node,
					    gint        n);
GtkTLNode    gtk_tlmodel_node_parent       (GtkTLModel *tlmodel,
					    GtkTLNode   node);

/* Drawing code and inspectors for nodes added later... */
/* Signals */
void         gtk_tlmodel_node_changed      (GtkTLModel *tlmodel,
					    GtkTLPath  *path);
void         gtk_tlmodel_node_deleted      (GtkTLModel *tlmodel,
					    GtkTLPath  *path);






#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __GTK_TLMODEL_H__ */
---------
gtktreemodel.h
---------
/* gtktreemodel.h
 * Copyright (C) 2000  Jonathan Blandford
 *
 * 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 __GTK_TREEMODEL_H__
#define __GTK_TREEMODEL_H__

#include <gtk/gtk.h>
#include "gtktlmodel.h"

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#define GTK_TYPE_TREE_MODEL			(gtk_tree_model_get_type ())
#define GTK_TREE_MODEL(obj)			(GTK_CHECK_CAST ((obj), GTK_TYPE_TREE_MODEL, GtkTreeModel))
#define GTK_TREE_MODEL_CLASS(klass)		(GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TREEMODEL, GtkTreeModelClass))
#define GTK_IS_TREE_MODEL(obj)			(GTK_CHECK_TYPE ((obj), GTK_TYPE_TREE_MODEL))
#define GTK_IS_TREE_MODEL_CLASS(klass)		(GTK_CHECK_CLASS_TYPE ((obj), GTK_TYPE_TREE_MODEL))

typedef struct _GtkTreeNode        GtkTreeNode;
typedef struct _GtkTreeModel       GtkTreeModel;
typedef struct _GtkTreeModelClass  GtkTreeModelClass;

struct _GtkTreeModel
{
  GtkTLModel parent;
  GtkTreeNode *root;
  gint columns;
  gchar **column_headers;
};

struct _GtkTreeModelClass
{
  GtkTLModelClass parent_class;
};

GtkType      gtk_tree_model_get_type           (void);
GtkObject   *gtk_tree_model_new                (void);
void         gtk_tree_model_set_columns        (GtkTreeModel   *model,
						gint            columns);
void         gtk_tree_model_set_column_name    (GtkTreeModel   *model,
						gint            column,
						const gchar    *name);
GtkTreeNode *gtk_tree_model_node_new           (void);
void         gtk_tree_model_node_set_cell      (GtkTreeModel   *model,
						GtkTreeNode    *node,
						gint            column,
						GtkTLCell      *renderer,
						gpointer        data);
void         gtk_tree_model_node_destroy       (GtkTreeModel   *model,
						GtkTreeNode    *node);
GtkTreeNode *gtk_tree_model_node_insert        (GtkTreeModel   *model,
						GtkTreeNode    *parent,
						gint            position,
						GtkTreeNode    *node);
GtkTreeNode *gtk_tree_model_node_insert_before (GtkTreeModel   *model,
						GtkTreeNode    *parent,
						GtkTreeNode    *sibling,
						GtkTreeNode    *node);
GtkTreeNode *gtk_tree_model_node_prepend       (GtkTreeModel   *model,
						GtkTreeNode    *parent,
						GtkTreeNode    *node);
GtkTreeNode *gtk_tree_model_node_append        (GtkTreeModel   *model,
						GtkTreeNode    *parent,
						GtkTreeNode    *node);
GtkTreeNode *gtk_tree_model_node_get_root      (GtkTreeModel   *model);
gboolean     gtk_tree_model_node_is_ancestor   (GtkTreeModel   *model,
						GtkTreeNode    *node,
						GtkTreeNode    *descendant);
gint         gtk_tree_model_node_depth         (GtkTreeModel   *model,
						GtkTreeNode    *node);
GtkTreeNode *gtk_tree_model_node_find          (GtkTreeModel   *model,
						GtkTreeNode    *root,
						GTraverseType   order,
						GTraverseFlags  flags,
						gpointer        data);



#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __GTK_TREEMODEL_H__ */
---------
gtklistmodel.h
---------
/* gtklistmodel.h
 * Copyright (C) 2000  Jonathan Blandford
 *
 * 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 __GTK_LIST_MODEL_H__
#define __GTK_LIST_MODEL_H__

#include <gtk/gtk.h>
#include "gtktlmodel.h"

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#define GTK_TYPE_LIST_MODEL			(gtk_list_model_get_type ())
#define GTK_LIST_MODEL(obj)			(GTK_CHECK_CAST ((obj), GTK_TYPE_LIST_MODEL, GtkListModel))
#define GTK_LIST_MODEL_CLASS(klass)		(GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_LISTMODEL, GtkListModelClass))
#define GTK_IS_LIST_MODEL(obj)			(GTK_CHECK_TYPE ((obj), GTK_TYPE_LIST_MODEL))
#define GTK_IS_LIST_MODEL_CLASS(klass)		(GTK_CHECK_CLASS_TYPE ((obj), GTK_TYPE_LIST_MODEL))

typedef struct _GtkListNode        GtkListNode;
typedef struct _GtkListModel       GtkListModel;
typedef struct _GtkListModelClass  GtkListModelClass;

struct _GtkListModel
{
  GtkTLModel parent;
  GtkListNode *root;
  gint columns;
  gchar **column_headers;
};

struct _GtkListModelClass
{
  GtkTLModelClass parent_class;
};

GtkType      gtk_list_model_get_type           (void);
GtkObject   *gtk_list_model_new                (void);
void         gtk_list_model_set_columns        (GtkListModel   *model,
						gint            columns);
void         gtk_list_model_set_column_name    (GtkListModel   *model,
						gint            column,
						const gchar    *name);
GtkListNode *gtk_list_model_node_new           (void);
void         gtk_list_model_node_set_cell      (GtkListModel   *model,
						GtkListNode    *node,
						gint            column,
						GtkTLCell      *renderer,
						gpointer        data);
void         gtk_list_model_node_destroy       (GtkListModel   *model,
						GtkListNode    *node);
GtkListNode *gtk_list_model_node_insert        (GtkListModel   *model,
						gint            position,
						GtkListNode    *node);
GtkListNode *gtk_list_model_node_insert_before (GtkListModel   *model,
						GtkListNode    *sibling,
						GtkListNode    *node);
GtkListNode *gtk_list_model_node_prepend       (GtkListModel   *model,
						GtkListNode    *node);
GtkListNode *gtk_list_model_node_append        (GtkListModel   *model,
						GtkListNode    *node);
GtkListNode *gtk_list_model_node_find          (GtkListModel   *model,
						GtkListNode    *root,
						GTraverseType   order,
						GTraverseFlags  flags,
						gpointer        data);



#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __GTK_LIST_MODEL_H__ */

---------
gtktlcell.h
---------
/* gtktlcell.h
 * Copyright (C) 2000  Jonathan Blandford
 *
 * 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 __GTK_TLCELL_H__
#define __GTK_TLCELL_H__

#include <gtk/gtk.h>

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

typedef enum
{
  GTK_TLCELL_SELECTED = 1 << 0,
  GTK_TLCELL_PRELIT = 1 << 1,
  GTK_TLCELL_INSENSITIVE = 1 << 2
} GtkTLCellType;

#define GTK_TYPE_TLCELL			(gtk_tlcell_get_type ())
#define GTK_TLCELL(obj)			(GTK_CHECK_CAST ((obj), GTK_TYPE_TLCELL, GtkTLCell))
#define GTK_TLCELL_CLASS(klass)		(GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TLCELL, GtkTLCellClass))
#define GTK_IS_TLCELL(obj)		(GTK_CHECK_TYPE ((obj), GTK_TYPE_TLCELL))
#define GTK_IS_TLCELL_CLASS(klass)	(GTK_CHECK_CLASS_TYPE ((obj), GTK_TYPE_TLCELL))

typedef struct _GtkTLCell GtkTLCell;
typedef struct _GtkTLCellClass GtkTLCellClass;

struct _GtkTLCell
{
  GtkObject parent;
};

struct _GtkTLCellClass
{
  GtkObjectClass parent_class;

  /* vtable - not signals */
  gint (* get_width)  (GtkTLCell *cell, gpointer   data);
  gint (* get_height) (GtkTLCell *cell, gpointer   data);
  void (* render)     (GtkTLCell *cell, GtkWidget *view,  GdkEventExpose *expose, GdkRectangle *area, gint x_offset, gint y_offset, guint flags, gpointer data);
  gint (* event)      (GtkTLCell *cell, GdkEvent  *event, gpointer        data);
  void (* free_data)  (GtkTLCell *cell, gpointer   data);
};

GtkType gtk_tlcell_get_type   (void);
gint    gtk_tlcell_get_width  (GtkTLCell      *cell,
			       gpointer        data);
gint    gtk_tlcell_get_height (GtkTLCell      *cell,
			       gpointer        data);
void    gtk_tlcell_render     (GtkTLCell      *cell,
			       GtkWidget      *view,
			       GdkEventExpose *event,
			       GdkRectangle   *area,
			       gint            x_offset,
			       gint            y_offset,
			       guint           flags,
			       gpointer        data);

void     gtk_tlcell_free_data (GtkTLCell      *cell,
			       gpointer        data);

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __GTK_TLCELL_H__ */
---------
gtktlcelltest.h
---------
/* gtktlcelltest.h
 * Copyright (C) 2000  Jonathan Blandford
 *
 * 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 __GTK_TLCELL_TEST_H__
#define __GTK_TLCELL_TEST_H__

#include <gtk/gtk.h>
#include "gtktlcell.h"

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */


#define GTK_TYPE_TLCELL_TEST		(gtk_tlcell_test_get_type ())
#define GTK_TLCELL_TEST(obj)		(GTK_CHECK_CAST ((obj), GTK_TYPE_TLCELL_TEST, GtkTLCellTest))
#define GTK_TLCELL_TEST_CLASS(klass)	(GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TLCELL_TEST, GtkTLCellTestClass))
#define GTK_IS_TLCELL_TEST(obj)		(GTK_CHECK_TYPE ((obj), GTK_TYPE_TLCELL_TEST))
#define GTK_IS_TLCELL_TEST_CLASS(klass)	(GTK_CHECK_CLASS_TYPE ((obj), GTK_TYPE_TLCELL_TEST))

typedef struct _GtkTLCellTest GtkTLCellTest;
typedef struct _GtkTLCellTestClass GtkTLCellTestClass;

struct _GtkTLCellTest
{
  GtkTLCell parent;
};

struct _GtkTLCellTestClass
{
  GtkTLCellClass parent_class;
};

GtkType    gtk_tlcell_test_get_type (void);
GtkTLCell *gtk_tlcell_test_new      (void);

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __GTK_TLCELL_H__ */
---------
gtkrbtree.h
---------
/* gbtree.h
 * Copyright (C) 2000  Red Hat Inc. <jrb@redhat.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 __GRBTREE_H__
#define __GRBTREE_H__

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#include <glib.h>
typedef enum
{
  G_RBNODE_BLACK = 1 << 0,
  G_RBNODE_RED = 1 << 1,
  G_RBNODE_IS_PARENT = 1 << 2,
  G_RBNODE_IS_SELECTED = 1 << 3,
  G_RBNODE_IS_PRELIT = 1 << 4,
  G_RBNODE_IS_VIEW = 1 << 5
} GRBNodeColor;

typedef struct _GRBTree GRBTree;
typedef struct _GRBNode GRBNode;
typedef struct _GRBTreeView GRBTreeView;

typedef void (*GRBTreeTraverseFunc) (GRBTree  *tree,
				     GRBNode  *node,
				     gpointer  data);

struct _GRBTree
{
  GRBNode *root;
  GRBNode *nil;
  GRBTree *parent_tree;
  GRBNode *parent_node;
};

struct _GRBNode
{
  guint flags;
  GRBNode *left;
  GRBNode *right;
  GRBNode *parent;
  gint count;  /* aggregate number of children we have */
  gint offset; /* aggregate of the heights of all our children */
  GRBTree *children;
};

struct _GRBNodeView
{
  GRBNode parent;
  gint offset;
  GRBTree *children;
};
    
#define G_RBNODE_GET_COLOR(node) (node?(((node->flags&G_RBNODE_RED)==G_RBNODE_RED)?G_RBNODE_RED:G_RBNODE_BLACK):G_RBNODE_BLACK)
#define G_RBNODE_SET_COLOR(node,color) if((node->flags&color)!=color)node->flags=node->flags^(G_RBNODE_RED|G_RBNODE_BLACK)
#define G_RBNODE_GET_HEIGHT(node) (node->offset-(node->left->offset+node->right->offset+(node->children?node->children->root->offset:0)))
#define G_RBNODE_SET_FLAG(node, flag) if((node->flags&flag)!=flag)node->flags^=flag
#define G_RBNODE_UNSET_FLAG(node, flag) if((node->flags&flag)==flag)node->flags^=flag
#define G_RBNODE_FLAG_SET(node, flag) (node?(((node->flags&flag)==flag)?TRUE:FALSE):FALSE)

void     g_rbtree_push_allocator (GAllocator           *allocator);
void     g_rbtree_pop_allocator  (void);
GRBTree *g_rbtree_new            (void);
void     g_rbtree_free           (GRBTree              *tree);
void     g_rbtree_remove         (GRBTree              *tree);
void     g_rbtree_destroy        (GRBTree              *tree);
GRBNode *g_rbtree_insert_after   (GRBTree              *tree,
				  GRBNode              *node,
				  gint                  height);
void     g_rbtree_remove_node    (GRBTree              *tree,
				  GRBNode              *node);
GRBNode *g_rbtree_find_count     (GRBTree              *tree,
				  gint                  count);
void     g_rbtree_node_set_height (GRBTree              *tree,
				   GRBNode              *node,
				   gint                  height);
gint     g_rbtree_node_find_offset (GRBTree *tree,
				    GRBNode *node);
gint     g_rbtree_find_offset    (GRBTree              *tree,
				  gint                  offset,
				  GRBTree             **new_tree,
				  GRBNode             **new_node);
void     g_rbtree_traverse       (GRBTree              *tree,
				  GRBNode              *node,
				  GTraverseType         order,
				  GRBTreeTraverseFunc   func,
				  gpointer              data);
GRBNode *g_rbtree_next           (GRBTree              *tree,
				  GRBNode              *node);


/* This func just checks the integrity of the tree */
/* It will go away later. */
void     g_rbtree_test           (GRBTree           *tree);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]