Source

oo-browser / tree-w32 / tree.h

Full commit
/* ----------------------------------------------------------------------------
 * File    : tree.h
 * Purpose : Header file for dynamic tree program
 * ----------------------------------------------------------------------------
 */

#define INTF 1		/* enable interface-specific code */

#define FOREACH_CHILD(child, tree) \
   for ((child) = (tree)->child ; (child) ; (child) = (child)->sibling)

#define PT_IN_RECT(p1, p2, x1, y1, x2, y2)   \
	 ((p1) > (x1) &&                      \
	  (p2) > (y1) &&                       \
	  (p1) < (x2) &&                        \
	  (p2) < (y2))

#define PT_IN_EXTENT(p1, p2, extent)                 \
	 ((p1) > (extent).pos.x &&                    \
	  (p2) > (extent).pos.y &&                     \
	  (p1) < ((extent).pos.x + (extent).width) &&   \
	  (p2) < ((extent).pos.y + (extent).height))

#define IS_LEAF(node) \
   ((node)->child == NULL)

typedef struct line  TreePolyline;
typedef struct tnode Tree;

typedef struct point {
   int x;
   int y;
} Point;

typedef struct extent {
   Point pos;			/* top left corner of rectangle     */
   int width;
   int height;
} Extent;

struct line {
   int dx, dy;
   TreePolyline *link;
};

typedef struct polygon {
   struct {
      TreePolyline *head;
      TreePolyline *tail;
   } lower, upper;
} TreePolygon;

typedef struct label {
   char *text;			/* the actual label text */
   int len;			/* length of label text  */
   int xoffset;			/* the X offset of label inside rectangle */
   int yoffset;			/* the Y offset of label inside rectangle */
} Label;

struct tnode {
   Tree    *parent;
   Tree    *child;
   Tree    *sibling;
   int      width;
   int      height;
   int      border;
   TreePolygon contour;
   Point    offset;		/* offset is relative to 'predecessor'    */
   Point    pos;	        /* position is screen coordinates of node */
   Point    old_pos;	        /* position is screen coordinates of node */
   int      node_height;	/* height of node in tree */
   /* all fields below are interface-specific */
   Label    label;
   char*    value;
   Extent   subextent;		/* extent of subtree (excluding this node) */
   TreePolygon old_contour;	/* for caching old contour in elision      */
   char     elision;		/* TRUE if this node is collapsed          */
   char     on_path;		/* true if on path to root from node       */
   char     split;              /* flag for drawing subtree contours       */
   char     show_contour;	/* flag to show or hide subtree contour    */
   char	    highlight;		/* TRUE if node shoulf be drawn highlighted*/
   char	    focus;		/* TRUE if node is a selected node         */
};

typedef enum {
   Erase,
   Draw
} DrawMode;

typedef enum {
   Old,
   New
} PosMode;			/* Position mode */

extern TreePolyline* MakeLine();
extern Tree*     MakeNode();
extern void      ComputeTreeSize();
extern void      Unzip();
extern void      Zip();
extern void      Delete (Tree* p);
extern void      DeleteTree (Tree* p, int contour);

extern Tree     *TheTree;
extern int       NumLines;
extern int       NumNodes;