/*  
 *    SCCS ID: %Z%%M% %I% %E% SST
 *
 *    Copyright (c) 1992-1993 Mark Soloway.  All rights reserved.
 *    See SST_LEGAL_NOTICE file for terms of the license. 
 */  
  
#ifndef _TREE_DISPLAYER_H
#define _TREE_DISPLAYER_H

#include <string.h>

#include "ObjectTree.h"
#include "TTGenericArrayTemplate.h"
#include "TTSession.h"
#include "TreeDisplayer_consts.h"
#include "TreeNode.h"

class TreeNodeArray;
class TTMessage;
class UIObject;

class TreeDisplayer : public TTSession {
public:
  TreeDisplayer (const char         *tree_file,
		 CanvasShellDisplay &cs,
		 ObjectTree         &cs_tree,
		 Tt_status          &status)
    : TTSession (status)
    {
      file = (char *)NULL;
      tree = (ObjectTree *)NULL;

      status = useDefaultSessionCallback (TT_TRUE);
      if (status == TT_OK) {
        status = declarePType (TREE_DISPLAYER_PTYPE);
	if (status == TT_OK) {
	  status = joinFile (tree_file);
	  if (status == TT_OK) {
	    canvas_shell = &cs;
	    file = strcpy (new char [strlen (tree_file) + 1], tree_file);
	    tree = &cs_tree;

	    status = displayTree ();
	  }
	}
      }
    }

  ~TreeDisplayer ()
    {
      if (file) delete file;
      if (root) delete root;
      if (selectedNodeID) delete selectedNodeID;

      selectedNodeID = (char *)NULL;
    }

  Tt_status  displayTree ();

  char *getSelectedNodeID () const
    {
      return tree->getSelectedNodeID ();
    }

  char *getFile () const
    {
      return file;
    }

  TreeNode *getRoot () const
    {
      return root;
    }
 
private:
  CanvasShellDisplay *canvas_shell;
  char               *file;
  TreeNode           *root;
  ObjectTree         *tree;

  Tt_status defaultSessionCallback (TTMessage *);
  Tt_status addChildren (TreeNode *, TreeNodeArray *);

  static char *selectedNodeID;
};

#endif
