//=======================================================================
//@V@:Note: This file generated by vgen V1.00 (12:04:59 PM 23 Sep 1996).
//	vedapp.cpp:	Source for vedApp class
//=======================================================================

#include "vedapp.h"		// Header file

//=========================>>> vedApp::vedApp <<<==========================
  vedApp::vedApp(char* name, int sdi, int h, int w) : vApp(name, sdi, h, w)
  {
    // Constructor

   _vedCmdWin = 0;
#ifdef DEVEL
   _emulation = See;
#else
   _emulation = Generic;
#endif
  }

//=========================>>> vedApp::vedApp <<<==========================
  vedApp::~vedApp()
  {
    // Desstructor
//   if (_vedCmdWin)
//	delete _vedCmdWin;
  }

//=====================>>> vedApp::NewAppWin <<<==========================
  vWindow* vedApp::NewAppWin(vWindow* win, char* name,
    int w, int h, vAppWinInfo* winInfo)
  {
    vAppWinInfo* awinfo = winInfo;
    char *appname = name;

    if (!*name)
      {
	 appname = "V Text Editor";		// Default name
      }
	
    UserDebug1(Build,"vedApp::NewAppWin(%s)\n",appname);

    // Create the first window using provided CmdWindow

    _vedCmdWin = (vedCmdWindow*) win;
    if (!_vedCmdWin)
      {
	_vedCmdWin = new vedCmdWindow(appname, w, h);
      }

    if (!awinfo)
	awinfo = new vAppWinInfo(appname);

    return vApp::NewAppWin(_vedCmdWin, appname, w, h, awinfo);
  }

//============================>>> vedApp::Exit <<<===========================
  void vedApp::Exit(void)
  {
    // This is called to close all windows.

    UserDebug(Build,"vedApp::Exit()\n");

    vApp::Exit();		// Default behavior
  }

//======================>>> vedApp::CloseAppWin <<<===========================
  void vedApp::CloseLastCmdWindow(vWindow* win, int exitcode)
  {
#ifndef V_VersionWindows
    vApp::CloseLastCmdWindow(win,exitcode);
#endif
  }

//======================>>> vedApp::CloseAppWin <<<===========================
  int vedApp::CloseAppWin(vWindow* win)
  {
    // This will be called BEFORE a window has been unregistered or
    // closed.  Default behavior: unregister and close the window.

    vedCmdWindow* cw = (vedCmdWindow*)win;
    if (cw->CheckClose())
        return vApp::CloseAppWin(win);
    return 0;
  }

//=====================>>> vedApp::AppCommand <<<==============================
  void vedApp::AppCommand(vWindow* win, ItemVal id, ItemVal val, CmdType cType)
  {
    // Commands not processed by the window will be passed here

    UserDebug1(Build,"vedApp::AppCmd(ID: %d)\n",id);
    switch (id)
      {

	case M_New:
	  {
	    (void*) theApp->NewAppWin(0, "V Text Editor", 100, 50);
	    return;
	  }

	case M_Open:
	  {
	    vedCmdWindow* cw;
	    cw = (vedCmdWindow*) theApp->NewAppWin(0, "V Text Editor", 100, 50);
	    cw->WindowCommand((ItemVal)M_Open,(ItemVal)0,(CmdType)0);
	    return;
	  }
      }


    vApp::AppCommand(win, id, val, cType);
  }

//=========================>>> vedApp::KeyIn <<<==============================
  void vedApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  {
    // Key strokes not processed by the window will be passed here

    vApp::KeyIn(win, key, shift);
  }

//###########################################################################

  static vedApp ved_App("V Text Editor");	// The instance of the app

//============================>>> AppMain <<<==============================
  int AppMain(int argc, char** argv)
  {
    // Use AppMain to create the main window


    vedCmdWindow* cw;		// Pointer to instance of first window

    cw = (vedCmdWindow*) theApp->NewAppWin(0, "V Text Editor", 500, 250);

    if (argc > 1)
      {
 	theApp->CheckEvents();	// make sure window up
        for (int ix = 1 ; ix < argc ; ++ix)
          {
              if (argv[ix][0] == '-' || argv[ix][0] == '/')	// switch
                {
                  switch (argv[ix][1])
                    {
                      case 'e':
                      case 'E':
                        {
                          switch (argv[ix][2])
                            {
                              case 's':
                              case 'S':
                                {
                                  ((vedApp*)theApp)->SetEmulation(See);
                                  break;
                                }
                              default:
                                  break;
                            }
		 	  break;
                        }

                      default:
                          break;
                    }
                }
              else	// a file name: project or source
                {
                  cw->OpenFile(argv[1]);	// open a file in first window
                }
          }
      }
    else
      {

      }

    cw->WindowCommand(M_SetEmulation,
		(ItemVal)((vedApp*)theApp)->GetEmulation(),(CmdType)0);
    return 0;
  }
