home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / vide / videapp.cpp < prev    next >
C/C++ Source or Header  |  1999-03-05  |  6KB  |  237 lines

  1. //=======================================================================
  2. //    videapp.cpp:    Source for videApp class
  3. //=======================================================================
  4.  
  5. #include "videapp.h"        // Header file
  6. #include <v/vos.h>    // <v/vos.h>
  7.  
  8. //=========================>>> videApp::videApp <<<==========================
  9.   videApp::videApp(char* name, int sdi, int h, int w) : vApp(name, sdi, h, w)
  10.   {
  11.     // Constructor
  12.  
  13.      _videCmdWin = 0;
  14.      _videMkFile[0] = 0;
  15. #ifdef DEVEL
  16.      _emulation = See;
  17. #else
  18.      _emulation = Generic;
  19. #endif
  20.   }
  21.  
  22. //=========================>>> videApp::videApp <<<==========================
  23.   videApp::~videApp()
  24.   {
  25.     // Desstructor
  26. //   if (_videCmdWin)
  27. //    delete _videCmdWin;
  28.   }
  29.  
  30. //=====================>>> videApp::NewAppWin <<<==========================
  31.   vWindow* videApp::NewAppWin(vWindow* win, char* name,
  32.     int w, int h, vAppWinInfo* winInfo)
  33.   {
  34.     vAppWinInfo* awinfo = winInfo;
  35.     char *appname = name;
  36.  
  37.     if (!*name)
  38.       {
  39.      appname = "V Text Editor";        // Default name
  40.       }
  41.     
  42.     UserDebug1(Build,"videApp::NewAppWin(%s)\n",appname);
  43.  
  44.     // Create the first window using provided CmdWindow if passed
  45.  
  46.     vWindow* cw = win;    // Pointer to instance of passed window
  47.  
  48.     if (cw != 0 && _videCmdWin == 0)
  49.         _videCmdWin = (videCmdWindow*) cw;        // remember this first window
  50.  
  51.     if (!cw)
  52.       {
  53.     cw = new videCmdWindow(appname, w, h);
  54.       }
  55.  
  56.     if (!awinfo)
  57.     awinfo = new vAppWinInfo(appname);
  58.  
  59.     vWindow* rv = vApp::NewAppWin(cw, appname, w, h, awinfo);
  60.     return rv;
  61.   }
  62.  
  63. //============================>>> videApp::Exit <<<===========================
  64.   void videApp::Exit(void)
  65.   {
  66.     // This is called to close all windows.
  67.  
  68.     UserDebug(Build,"videApp::Exit()\n");
  69.  
  70.     vApp::Exit();        // Default behavior
  71.   }
  72.  
  73. //============================>>> videApp::SetMkFile <<<===========================
  74.   void videApp::SetMkFile(char* mkf)
  75.   {
  76.     // update our global variable CWD and update any open windows
  77.     vOS vos;
  78.     BOOL hadpath = false;
  79.     char temp[maxFileNameSize + 2];
  80.  
  81.     if (strlen(mkf) < maxFileNameSize)
  82.       {
  83.     for (char* cp = mkf ; *cp ; ++cp)
  84.         if (*cp == '/' || *cp == '\\')
  85.           {
  86.         hadpath = true;
  87.         break;
  88.           }
  89.     if (hadpath)
  90.         strcpy(_videMkFile, mkf);
  91.     else
  92.       {
  93.         vos.vGetCWD(temp,maxFileNameSize);
  94.         strcpy(_videMkFile, temp); strcat(_videMkFile,"/");
  95.         strcat(_videMkFile,mkf);
  96.       }
  97.       }
  98.     else
  99.         strcpy(_videMkFile,"Makefile");
  100.  
  101.     if (hadpath)
  102.       {
  103.     strcpy(temp,_videMkFile);
  104.     int ix = strlen(temp);        // strip Makefile part
  105.     while (ix > 0)
  106.       {
  107.         if (temp[ix] == '/' || temp[ix] == '\\')
  108.           {
  109.             temp[ix] = 0;
  110.             break;
  111.           }
  112.         --ix;
  113.       }
  114.  
  115.     vos.vChDir(temp);            // we will work out of that directory
  116.       }
  117.     theApp->SendWindowCommandAll(m_updateMkFile, 0, C_Button);
  118.   }
  119.  
  120. //======================>>> videApp::CloseAppWin <<<===========================
  121.   int videApp::CloseAppWin(vWindow* win)
  122.   {
  123.     // This will be called BEFORE a window has been unregistered or
  124.     // closed.  Default behavior: unregister and close the window.
  125.  
  126.     videCmdWindow* cw = (videCmdWindow*)win;
  127.     if (cw->CheckClose())
  128.         return vApp::CloseAppWin(win);
  129.     else
  130.         return 0;
  131.   }
  132.  
  133. //=====================>>> videApp::AppCommand <<<==============================
  134.   void videApp::AppCommand(vWindow* win, ItemVal id, ItemVal val, CmdType cType)
  135.   {
  136.     // Commands not processed by the window will be passed here
  137.  
  138.     UserDebug1(Build,"videApp::AppCmd(ID: %d)\n",id);
  139.     vApp::AppCommand(win, id, val, cType);
  140.   }
  141.  
  142. //=========================>>> videApp::KeyIn <<<==============================
  143.   void videApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  144.   {
  145.     // Key strokes not processed by the window will be passed here
  146.  
  147.     vApp::KeyIn(win, key, shift);
  148.   }
  149.  
  150. //###########################################################################
  151.  
  152.   static videApp vide_App("The V VIDE (0.2) for GNU g++");    // The instance of the app
  153.  
  154. //============================>>> AppMain <<<==============================
  155.   int AppMain(int argc, char** argv)
  156.   {
  157. #if defined (V_VersionX) || defined (V_VersionOS2)
  158.     (((videApp*)theApp)->DefaultFont).SetFontValues(vfFixed,10);    // use Courier rathern than default
  159. #else
  160.     (((videApp*)theApp)->DefaultFont).SetFontValues(vfFixed,10,vfNormal,vfBold);    // use Courier rathern than default
  161. #endif
  162.     // Use AppMain to create the main window
  163.     videCmdWindow* cw = new videCmdWindow("No Makefile Specified", 80, 12);
  164.     (void) theApp->NewAppWin((vWindow*) cw,
  165.                 "No Makefile Specified", 80, 12, 0);
  166.  
  167.     (((videApp*)theApp)->GetMsgWindow())->SetTitle("No Makefile Specified");
  168.     (((videApp*)theApp)->GetMsgWindow())->AddLine("------------ V IDE ------------");
  169.     (((videApp*)theApp)->GetMsgWindow())->SetRdOnly(1);
  170.  
  171.     if (strstr(argv[0],"vsee") != 0)
  172.     ((videApp*)theApp)->SetEmulation(See);
  173.  
  174.     theApp->CheckEvents();    // make sure window up
  175.     if (argc > 1)
  176.       {
  177.         for (int ix = 1 ; ix < argc ; ++ix)
  178.       {
  179.         if (argv[ix][0] == '-' || argv[ix][0] == '/')    // switch
  180.           {
  181.         switch (argv[ix][1])
  182.           {
  183.             case 'e':
  184.             case 'E':
  185.               {
  186.             switch (argv[ix][2])
  187.               {
  188.                 case 's':
  189.                 case 'S':
  190.                   {
  191.                 ((videApp*)theApp)->SetEmulation(See);
  192.                 break;
  193.                   }
  194.                 default:
  195.                 break;
  196.               }
  197.             break;
  198.               }    // case 'e'
  199.  
  200.             default:
  201.             break;
  202.           }
  203.           }
  204.         else    // a file name: project or source
  205.           {
  206.         // for now, open everything as a file. Evenutally
  207.         // treat .vpjs special
  208.  
  209.         videCmdWindow* cmdw = (videCmdWindow*)
  210.         theApp->NewAppWin(0,"V Text Editor", 80, 24);
  211.         if (!cmdw)
  212.             break;
  213.         if (!cmdw->OpenFile(argv[ix]))
  214.           {
  215.             delete cmdw;
  216.             break;
  217.           }
  218.         else
  219.           {
  220.             cmdw->RaiseWindow();
  221.           }
  222.  
  223.         cmdw->SetSyntaxType(cmdw,argv[ix],0);
  224.         cmdw->vedCanvas->Verify();
  225.         cmdw->ChangeInsMode(1);
  226.           }
  227.       }
  228.       }
  229.     else
  230.       {
  231.  
  232.       }
  233. //    cw->WindowCommand(M_SetEmulation,
  234. //        (ItemVal)((vedApp*)theApp)->GetEmulation(),(CmdType)0);
  235.     return 0;
  236.   }
  237.