// 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

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

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

#ifndef ObjectView_h
#define ObjectView_h

class ObjectView;
class Connection;
class IO;
class BaseObject;

class Anchor : public GripWidget {
   friend class Connection;
 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, IO* io, Type type, Position offset, Location loc);
 private:
   ObjectView* host;
   IO*         io;
   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 CommandWidget {	
 private:
   static  Boolean class_inited;

   BaseObject* object;
   iolist* inputs;
   iolist* outputs;

   Position input_off;
   Position output_off;

   Cardinal input_count;
   Cardinal output_count;

   void InitializeClass();
 public:
   ObjectView(Widget workspace, String name, BaseObject* object,
	      Cardinal input_count = 1, Cardinal output_count = 1);

   void Move(XPoint&);
   void StartMoving();

   void AddInput(IO*);
   void AddOutput(IO*);
   Connection* GetInputConnections();
   Connection* GetOutputConnections();

   void print_object(ostream&);
   void print_all(ostream&);

   void CreateWidgetObject();
};

#endif _ObjectView_h
