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

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

//#define __STDIO_H
//
#include <iostream.h>

#include <xt++/Intrinsic.h>
#include <xt++/Shell.h>
#include <xt++/Xaw/Label.h>
#include <xt++/Xaw/Command.h>
#include <xt++/Xaw/Form.h>
#include <xt++/Xaw/Dialog.h>
#include <xt++/Xaw/Clock.h>
#include <xt++/Xaw/Panner.h>
#include <xt++/Xaw/Porthole.h>
#include <xt++/Xaw/AsciiText.h>

#include <X11/StringDefs.h>
#include <libc.h>
//#include <stream.h>
#include <iostream.h>

#include "ObjectEditor.h"
#include "Objects.h"
#include "WindowStream.h"

wstream     msg;

void TestCB(Core*, XtPointer, XtPointer)
{
   msg << "testing msg.\n";

   streambuf* buf = msg.rdbuf();

//      char* pp = buf->pbase();

   cerr << "buf= " << buf->out_waiting() << "\n";

   if(!msg)
     cerr << "before use - An error condition in msg\n";
   msg << "Object Created.\n";
   if(!msg)
     cerr << "after use - An error condition in msg\n";
   msg.print();

   msg << flush;
}

void QuitCB(Core* w , XtPointer, XtPointer)
{
   w->GetAppContext()->ExitLoop();
}


main(unsigned int argc, char** argv)
{
   ApplicationContext appContext;

   Display *dpy =  appContext.OpenDisplay(NULL, argv[0], "Eureka",
                        NULL,0,
                        &argc, argv);

   ApplicationShellWidget aw( argv[0], "Eureka", dpy);

   FormWidget    form("form", aw);
   form.Manage();

   FormWidget  controls("controls",form);
   controls.Manage();

   CommandWidget quit("quit", controls);
   quit.AddCallback(XtNcallback, QuitCB, (XtPointer)NULL);
   quit.Manage();

   CommandWidget create("panner", controls);
   create.AddCallback(XtNcallback, TestCB, (XtPointer)NULL);
   create.Manage();

   CommandWidget create_io("create_io", controls);
   create_io.Manage();

   CommandWidget constant("create_constant", controls);
   constant.Manage();

   CommandWidget splitter("create_splitter", controls);
   splitter.Manage();

   CommandWidget multiplier("create_multiplier", controls);
   multiplier.Manage();

   AsciiTextWidget text("msgWindow", form);
   text.Manage();

   msg.attach(&text);

   aw.Realize();

   appContext.MainLoop();

}
