/*
* $XConsortium: Tree.c,v 1.45 94/04/17 20:13:20 kaleb Exp $
*
Copyright (c) 1990, 1994 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
* Copyright 1989 Prentice Hall
*
* Permission to use, copy, modify, and distribute this software for any
* purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation.
*
* Prentice Hall and the authors disclaim all warranties with regard
* to this software, including all implied warranties of merchantability and
* fitness. In no event shall Prentice Hall or the authors be liable
* for any special, indirect or cosequential damages or any damages whatsoever
* resulting from loss of use, data or profits, whether in an action of
* contract, negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*
* Authors: Jim Fulton, MIT X Consortium,
* based on a version by Douglas Young, Prentice Hall
*
* This widget is based on the Tree widget described on pages 397-419 of
* Douglas Young's book "The X Window System, Programming and Applications
* additional blank space to make the structure of the graph easier to see
* as well as to support vertical trees.
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
/* widget class method */
static void ClassInitialize();
static void Initialize();
static void ConstraintInitialize();
static void ConstraintDestroy();
static Boolean ConstraintSetValues();
static void Destroy();
static XtGeometryResult GeometryManager();
static void ChangeManaged();
static void Redisplay();
static XtGeometryResult QueryGeometry();
/* utility routines */
static void insert_node();
static void delete_node();
static void layout_tree();
/*
* resources of the tree itself
*/
(XtPointer) WestGravity },
};
/*
* resources that are attached to all children of the tree
*/
};
{
/* core_class fields */
"Tree", /* class_name */
sizeof(TreeRec), /* widget_size */
ClassInitialize, /* class_init */
NULL, /* class_part_init */
FALSE, /* class_inited */
Initialize, /* initialize */
NULL, /* initialize_hook */
XtInheritRealize, /* realize */
NULL, /* actions */
0, /* num_actions */
resources, /* resources */
NULLQUARK, /* xrm_class */
TRUE, /* compress_motion */
TRUE, /* compress_exposure */
TRUE, /* compress_enterleave*/
TRUE, /* visible_interest */
Destroy, /* destroy */
NULL, /* resize */
Redisplay, /* expose */
SetValues, /* set_values */
NULL, /* set_values_hook */
XtInheritSetValuesAlmost, /* set_values_almost */
NULL, /* get_values_hook */
NULL, /* accept_focus */
XtVersion, /* version */
NULL, /* callback_private */
NULL, /* tm_table */
QueryGeometry, /* query_geometry */
NULL, /* display_accelerator*/
NULL, /* extension */
},
{
/* composite_class fields */
GeometryManager, /* geometry_manager */
ChangeManaged, /* change_managed */
XtInheritInsertChild, /* insert_child */
XtInheritDeleteChild, /* delete_child */
NULL, /* extension */
},
{
/* constraint_class fields */
treeConstraintResources, /* subresources */
sizeof(TreeConstraintsRec), /* constraint_size */
ConstraintInitialize, /* initialize */
ConstraintDestroy, /* destroy */
ConstraintSetValues, /* set_values */
NULL, /* extension */
},
{
/* Tree class fields */
0, /* ignore */
}
};
/*****************************************************************************
* *
* tree utility routines *
* *
*****************************************************************************/
int *sizep;
int n;
{
int i;
Dimension *l;
if (!*listp) {
(unsigned int) sizeof(Dimension));
return;
}
if (n > *sizep) {
(unsigned int) (n*sizeof(Dimension)));
if (!*listp) {
*sizep = 0;
return;
}
*sizep = n;
}
return;
}
TreeWidget w;
{
if (w->tree.line_width != 0) {
valuemask |= GCLineWidth;
}
}
{
int nindex;
/*
* If there isn't more room in the children array,
* allocate additional space.
*/
(unsigned int)
sizeof(Widget)));
}
/*
* Add the sub_node in the next available slot and
* increment the counter.
*/
}
{
int pos, i;
/*
* Make sure the parent exists.
*/
if (!parent) return;
/*
* Find the sub_node on its parent's list.
*/
/*
* Decrement the number of children
*/
/*
* Fill in the gap left by the sub_node.
* Zero the last slot for good luck.
*/
}
{
break;
default:
break;
}
}
/*****************************************************************************
* *
* tree class methods *
* *
*****************************************************************************/
static void ClassInitialize ()
{
}
/*ARGSUSED*/
{
/*
* Make sure the widget's width and height are
* greater than zero.
*/
/*
* Set the padding according to the orientation
*/
if (IsHorizontal (request)) {
} else {
}
}
/*
* Create a graphics context for the connecting lines.
*/
/*
* Create the hidden root widget.
*/
/*
* Allocate the array used to hold the widest values per depth
*/
/*
* make sure that our gravity is one of the acceptable values
*/
}
/* ARGSUSED */
{
/*
* Initialize the widget to have no sub-nodes.
*/
/*
* If this widget has a super-node, add it to that
* widget' sub-nodes list. Otherwise make it a sub-node of
* the tree_root widget.
*/
}
/* ARGSUSED */
{
/*
* If the foreground color has changed, redo the GC's
* and indicate a redraw.
*/
}
/*
* If the minimum spacing has changed, recalculate the
* tree layout. layout_tree() does a redraw, so we don't
* need SetValues to do another one.
*/
}
}
}
}
return redraw;
}
/* ARGSUSED */
{
/*
* If the parent field has changed, remove the widget
* from the old widget's children list and add it to the
* new one.
*/
/*
* If the Tree widget has been realized,
* compute new layout.
*/
}
return False;
}
static void ConstraintDestroy (w)
Widget w;
{
int i;
/*
* Remove the widget from its parent's sub-nodes list and
* make all this widget's sub-nodes sub-nodes of the parent.
*/
else
}
}
/* ARGSUSED */
Widget w;
{
/*
* No position changes allowed!.
*/
return (XtGeometryNo);
/*
* Allow all resize requests.
*/
return (XtGeometryYes);
}
{
}
{
}
/* ARGSUSED */
{
/*
* If the Tree widget is visible, visit each managed child.
*/
int i, j;
/*
* Don't draw lines from the fake tree_root.
*/
case WestGravity:
/* fall through */
case EastGravity:
break;
case NorthGravity:
/* fall through */
case SouthGravity:
break;
}
case WestGravity:
/*
* right center to left center
*/
(int) k->core.x,
break;
case NorthGravity:
/*
* bottom center to top center
*/
(int) k->core.y);
break;
case EastGravity:
/*
* left center to right center
*/
(k->core.x +
break;
case SouthGravity:
/*
* top center to bottom center
*/
(k->core.y +
break;
}
}
}
}
}
}
Widget w;
{
return XtGeometryYes;
return XtGeometryNo;
else
return XtGeometryAlmost;
}
/*****************************************************************************
* *
* tree layout algorithm *
* *
* Each node in the tree is "shrink-wrapped" with a minimal bounding *
* rectangle, laid next to its siblings (with a small about of padding in *
* between) and then wrapped with their parent. Parents are centered about *
* their children (or vice versa if the parent is larger than the children). *
* *
*****************************************************************************/
Widget w;
int depth;
{
int i;
/*
* Set the max-size per level.
*/
}
/*
* initialize
*/
/*
* Figure the size of the opposite dimension (vertical if tree is
* horizontal, else vice versa). The other dimension will be set
* in the second pass once we know the maximum dimensions.
*/
newwidth = 0;
newheight = 0;
if (horiz) {
} else {
}
}
/*
* Now fit parent onto side (or top) of bounding box and correct for
* extra padding. Be careful of unsigned arithmetic.
*/
if (horiz) {
} else {
}
}
Widget w;
int level;
{
int i;
if (w) {
if (level > 0) {
/*
* mirror if necessary
*/
case EastGravity:
break;
case SouthGravity:
break;
}
/*
* Move the widget into position.
*/
}
/*
* Set the positions of all children.
*/
}
}
Widget w;
int depth;
Position x, y;
{
int i;
/*
* If no children, then just lay out where requested.
*/
if (horiz) {
}
} else {
}
}
/*
* Have children, so walk down tree laying out children, then laying
* out parents.
*/
if (horiz) {
newy = y;
} else {
newx = x;
}
if (horiz) {
} else {
}
}
/*
* now layout parent between first and last children
*/
if (relayout) {
/* Adjustments are disallowed if they result in a position above
* or to the left of the originally requested position, because
* this could collide with the position of the previous sibling.
*/
if (horiz) {
} else {
}
}
}
{
if (insetvalues) {
} else {
&replyHeight);
/*
* Accept any compromise.
*/
if (result == XtGeometryAlmost)
}
return;
}
{
int i;
/*
* Do a depth-first search computing the width and height of the bounding
* box for the tree at that position (and below). Then, walk again using
* this information to layout the children at each level.
*/
return;
*dp = 0;
/*
* Second pass to do final layout. Each child's bounding box is stacked
* on top of (if horizontal, else next to) on top of its siblings. The
* parent is centered between the first and last children.
*/
/*
* Move each widget into place.
*/
/*
* And redisplay.
*/
}
}
/*****************************************************************************
* *
* Public Routines *
* *
*****************************************************************************/
void
#else
#endif
{
}