Initial Commit
[packages] / xemacs-packages / oo-browser / tree-x / tree.h
1 /* ----------------------------------------------------------------------------
2  * File    : tree.h
3  * Purpose : Header file for dynamic tree program
4  * ----------------------------------------------------------------------------
5  */
6
7 #define INTF 1          /* enable interface-specific code */
8
9 #define FOREACH_CHILD(child, tree) \
10    for ((child) = (tree)->child ; (child) ; (child) = (child)->sibling)
11
12 #define PT_IN_RECT(p1, p2, x1, y1, x2, y2)   \
13          ((p1) > (x1) &&                      \
14           (p2) > (y1) &&                       \
15           (p1) < (x2) &&                        \
16           (p2) < (y2))
17
18 #define PT_IN_EXTENT(p1, p2, extent)                 \
19          ((p1) > (extent).pos.x &&                    \
20           (p2) > (extent).pos.y &&                     \
21           (p1) < ((extent).pos.x + (extent).width) &&   \
22           (p2) < ((extent).pos.y + (extent).height))
23
24 #define IS_LEAF(node) \
25    ((node)->child == NULL)
26
27 typedef struct line  Polyline;
28 typedef struct tnode Tree;
29
30 typedef struct point {
31    int x;
32    int y;
33 } Point;
34
35 typedef struct extent {
36    Point pos;                   /* top left corner of rectangle     */
37    int width;
38    int height;
39 } Extent;
40
41 struct line {
42    int dx, dy;
43    Polyline *link;
44 };
45
46 typedef struct polygon {
47    struct {
48       Polyline *head;
49       Polyline *tail;
50    } lower, upper;
51 } Polygon;
52
53 typedef struct label {
54    char *text;                  /* the actual label text */
55    int len;                     /* length of label text  */
56    int xoffset;                 /* the X offset of label inside rectangle */
57    int yoffset;                 /* the Y offset of label inside rectangle */
58 } Label;
59
60 struct tnode {
61    Tree    *parent;
62    Tree    *child;
63    Tree    *sibling;
64    int      width;
65    int      height;
66    int      border;
67    Polygon  contour;
68    Point    offset;             /* offset is relative to 'predecessor'    */
69    Point    pos;                /* position is screen coordinates of node */
70    Point    old_pos;            /* position is screen coordinates of node */
71    int      node_height;        /* height of node in tree */
72    /* all fields below are interface-specific */
73    Label    label;
74    char*    value;
75    Extent   subextent;          /* extent of subtree (excluding this node) */
76    Polygon  old_contour;        /* for caching old contour in elision      */
77    char     elision;            /* TRUE if this node is collapsed          */
78    char     on_path;            /* true if on path to root from node       */
79    char     split;              /* flag for drawing subtree contours       */
80    char     show_contour;       /* flag to show or hide subtree contour    */
81 };
82
83 typedef enum {
84    Erase,
85    Draw
86 } DrawMode;
87
88 typedef enum {
89    Old,
90    New
91 } PosMode;                      /* Position mode */
92
93
94 Polyline* MakeLine(short dx, short dy, Polyline *line);
95 Tree*   MakeNode(void);
96 void    ComputeTreeSize(Tree *tree,
97                         int *width, int *height,
98                         int *x_offset, int *y_offset);
99 void    Unzip       (Tree *tree);
100 void    Zip         (Tree *tree);
101 void    PetrifyTree (Tree *tree, int x, int y);
102 void    DrawTree    (Tree *tree, PosMode pos_mode);
103 void    Delete      (Tree *tree);
104 void    DeleteTree  (Tree *tree, int contour);
105 void    Insert      (Tree *parent, Tree *child, Tree *sibling);
106 void    DrawTreeContour(Tree *tree, PosMode pos_mode,
107                         int color, int detach_p, int select_p, int recursive);
108 void    ComputeSubTreeExtent(Tree *tree);
109 void    LayoutLeaf  (Tree *tree);
110 void    RuboutLeaf  (Tree *tree);
111 void    HiliteNode  (Tree *tree, PosMode pos_mode);
112 void    DeleteNode  (Tree *node);
113 void    DrawNode    (Tree *node, PosMode pos_mode);
114 void    ResetLabels (Tree *tree);
115 void    SetupTree   (Tree *tree);
116 int     SearchTree  (Tree *tree, int x, int y, Tree **node);
117 void    LayoutTree  (Tree *tree);
118
119 /* draw.c */
120 void    BeginFrame (void);
121 void    EndFrame   (void);
122
123 extern Tree     *TheTree;