home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / test / testapp.cpp < prev    next >
C/C++ Source or Header  |  1999-01-07  |  7KB  |  212 lines

  1. //=======================================================================
  2. //  testapp.xx:     Source file for test prototype V application
  3. //  Copyright (C) 1995,1996, 1997, 1998  Bruce E. Wampler
  4. //
  5. //  This program is part of the V C++ GUI Framework example programs.
  6. //
  7. //  This program is free software; you can redistribute it and/or modify
  8. //  it under the terms of the GNU General Public License as published by
  9. //  the Free Software Foundation; either version 2 of the License, or
  10. //  (at your option) any later version.
  11. //
  12. //  This program is distributed in the hope that it will be useful,
  13. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. //  GNU General Public License for more details.
  16. //
  17. //  You should have received a copy of the GNU General Public License
  18. //  (see COPYING) along with this program; if not, write to the Free
  19. //  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. //=======================================================================
  21.  
  22. //
  23. //
  24. //  Files required for minimal application:
  25. //      testapp.h       Header for the test app
  26. //      testoapp.cxx:   Source code for min app
  27. //      vtcmdwin.h:     Header code for sample command window
  28. //      vtcmdwin.cxx:   Source code for sample command window
  29. //      vtdialog.h:     Header for sample modeless dialog
  30. //      vtdialog.cxx:   Source for sample modeless dialog
  31. //      mymodal.h:      Header for sample modal dialog
  32. //      mymodal.cxx     Soruce for sample modal dialog
  33. //
  34. //      While these files were generated by hand, they are intended to
  35. //      serve as an example of files that could have been generated by
  36. //      the V interface generator (Vigr)
  37. //                                                             
  38.  
  39. #include <v/vnotice.h>  // so we can use notice
  40.  
  41. #include "testapp.h"    // our header
  42.  
  43.     static char newName[] = "[A] Example Subwindow";
  44.     static vWindow* firstWindow = 0;
  45.  
  46. //=========================>>> testApp::testapp <<<=========================
  47.   testApp::testApp(char* name, int simSDI) : vApp(name,simSDI)
  48.   {
  49.     _defWin = 0;
  50.     _defAppWinInfo = 0;
  51.   }
  52.  
  53. //=========================>>> testApp::~testapp <<<=========================
  54.   testApp::~testApp()
  55.   {
  56.  
  57.   }
  58.  
  59. //=========================>>> myApp::NewAppWin <<<==========================
  60.   vWindow* testApp::NewAppWin(vWindow* win, VCONST char* name, int w, int h,
  61.                 vAppWinInfo* winInfo)
  62.   {
  63.     // This version of NewAppWin is provided with the information
  64.     // required to name and size a window.
  65.  
  66.     // Typically, these would get a file name or other information
  67.     // that will setup the AppWinInfo class for information
  68.     // specific to the application. Thus, each open window
  69.     // usually represents a view of a file or data object.
  70.  
  71.     vWindow* thisWin = win;             // local copy to use
  72.     vAppWinInfo* awinfo = winInfo;
  73.  
  74.     char *myname = (char*)name;
  75.  
  76.     if (!*name)
  77.       {
  78.         myname = newName;               // make up a name
  79.       }
  80.         
  81.     UserDebug1(Build,"testApp::NewAppWin(%s)\n",myname);
  82.  
  83.     if (!thisWin)                       // need to new a window
  84.       {
  85.         thisWin = new testCmdWindow(myname, w, h);
  86.         _defWin = firstWindow = thisWin;
  87.       }
  88.  
  89.     // The real app will no doubt have its own AppWinInfo class.
  90.  
  91.     if (!awinfo)
  92.       {
  93.         awinfo = new vAppWinInfo(myname);
  94.     if (!_defAppWinInfo)
  95.         _defAppWinInfo = awinfo;
  96.       }
  97.  
  98.     if (!*name)
  99.       {
  100.         newName[1]++;           // Cheap way to generate unique name
  101.       }
  102.  
  103.     return vApp::NewAppWin(thisWin, myname, w, h, awinfo);
  104.   }
  105.  
  106. //===========================>>> testApp::Exit <<<=============================
  107.   void testApp::Exit(void)
  108.   {
  109.     // This is called to close all windows. If the app needs to
  110.     // do something special, it can. Otherwise, it can call the
  111.     // general vApp::Exit method, which will generate
  112.     // appropriate calls the the specialized testApp::CloseAppWin
  113.  
  114.     UserDebug(Build,"testApp::Exit()\n");
  115.  
  116.  
  117.     vApp::Exit();       // easy default behavior
  118.   }
  119.  
  120. //=======================>>> testApp::CloseAppWin <<<===========================
  121.   int testApp::CloseAppWin(vWindow* win)
  122.   {
  123.     // This will be called BEFORE a window has been unregistered or
  124.     // closed.  The app can do whatever it needs to to close down
  125.     // the data associated with this window. Then it can call the
  126.     // general vApp::CloseAppWin to unregister and close this window.
  127.     // Note that the win gives a handle that can be used with
  128.     // vApp::getAppWinInfo to retrieve the AppWinInfo class.
  129.  
  130.     // Code to handle close of window (such as saving/closing a file)
  131.     // would go here...
  132.  
  133.     // Now unregister and close the window.
  134.  
  135.     UserDebug(Build,"testApp::CloseAppWin()\n");
  136.  
  137.     return vApp::CloseAppWin(win);
  138.   }
  139.  
  140. //==================>>> testApp::CloseLastCmdWindow <<<=======================
  141.   void testApp::CloseLastCmdWindow(vWindow* win, int exitcode)
  142.   {
  143.     // Override - just return, which will leave just the
  144.     // empty MDI frame on windows.  
  145. #ifndef V_VersionWindows
  146.     vApp::CloseLastCmdWindow(win, exitcode);
  147. #endif
  148.   }
  149.  
  150. //========================>>> testApp::AppCommand <<<===========================
  151.   void testApp::AppCommand(vWindow* win, ItemVal id, ItemVal val, CmdType cType)
  152.   {
  153.     // Any commands not processed by the window will be passed
  154.     // along to here for default treatment.
  155.  
  156.     UserDebug1(Build,"testApp::AppCmd(ID: %d)\n",id);
  157.     if (id == 901)
  158.       {
  159.         vNoticeDialog note(this);
  160.         note.Notice("This is generated from testApp, not a dialog.");
  161.         return;
  162.       }
  163.     else if (id == 902)
  164.       {
  165.         if (firstWindow)
  166.             firstWindow->RaiseWindow();
  167.         return;
  168.       }
  169.     else if (id == 903)         // Shift first window
  170.       {
  171.         if (firstWindow)
  172.           {
  173.             int l,t,r,b;
  174.             firstWindow->GetPosition(l,t,r,b);
  175.             firstWindow->SetPosition(l+30,t+30);
  176.           }
  177.         return;
  178.       }
  179.     else if (id == M_New || id == M_Open)
  180.       {
  181.       (void) theApp->NewAppWin(0, "Prototype V Example", 600, 250, 0);
  182.       return;
  183.       }
  184.     vApp::AppCommand(win, id, val, cType);
  185.   }
  186.  
  187. //=========================>>> testApp::KeyIn <<<==============================
  188.   void testApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  189.   {
  190.     // Any key strokes not processed by the window will be passed
  191.     // along to here for default treatment.
  192.  
  193.     vApp::KeyIn(win, key, shift);
  194.   }
  195.  
  196. //###########################################################################
  197.  
  198.   // EVERY V application needs the equivalent of the following line
  199.  
  200.   static testApp* tApp = new testApp("V test (Σσ)",0); // The instance of the app
  201.  
  202. //============================>>> AppMain <<<==============================
  203.   int AppMain(int argc, char** argv)
  204.   {
  205.     // Use AppMain to create the main window
  206.  
  207.  
  208.     (void) theApp->NewAppWin(0, "Prototype V Example (Σσ)", 600, 250, 0);
  209.  
  210.     return 0;
  211.   }
  212.