// This may look like C code, but it is really -*- C++ -*-

/***********************************************************
Copyright 1991 by the Massachusetts Institute of Technology

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of M.I.T. not be used in advertising or
publicity pertaining to distribution of the software without specific,
written prior permission.  M.I.T. makes no representations about the
suitability of this software for any purpose.  It is provided "as is"
without express or implied warranty.


Author: Roman J. Budzianowski - Project Athena MIT

******************************************************************/

#ifndef _ObjectView_h
#define _ObjectView_h

#include <xt++/Intrinsic.h>
#include <xt++/Xaw/Grip.h>
#include <xt++/Xaw/Command.h>

class ObjectView;
class Connection;

class Anchor : public GripWidget {
 public:
   enum Type { Input, Output };
   enum Location { Left, Right, Top, Bottom, Same };

   void StartConnection();
   void CommitConnection();
   void PositionItself();
   void PositionItself(Position offset, Location loc = Same);
   void UpdatePosition(Position offset, Location loc = Same);

   void Connect(Connection* c) { connected = c; }
   void Disconnect() { connected = NULL; }
   Connection* Connected() { return connected; }

   Anchor(ObjectView* host, Type type, Position offset, Location loc);
 private:
   ObjectView* host;
   Type type;
   Position xoffset;
   Position yoffset;
   Connection*  connected;
};

class iolist {
   friend class ObjectView;

   Anchor *anchor;
   iolist   *next;

   iolist(iolist *next, Anchor *anchor) : next(next), anchor(anchor) {}
};
   

class ObjectView : public LabelWidget {	// XXX got to switch to Command
 private:
   static  Boolean class_inited;
   iolist* inputs;
   iolist* outputs;

   void InitializeClass();
 public:
   ObjectView(Widget workspace, String name);

   void Move(XPoint&);
   void StartMoving();
   void AddInput(Cardinal input_count = 1);
   void AddOutput(Cardinal output_count = 1);
   Connection* GetInputConnections();
   Connection* GetOutputConnections();

};

#endif _ObjectView_h
