home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / examp / protoapp.cpp < prev    next >
C/C++ Source or Header  |  1998-11-09  |  5KB  |  148 lines

  1. //=======================================================================
  2. //  protoapp.xx:     Source file for minimal prototype V application
  3. //  Copyright (C) 1995  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. //  Files required for minimal application:
  23. //      protoapp.h      Header for the min app
  24. //      protoapp.cxx:   Source code for min app
  25. //    mycmdwin.h:    Header code for sample command window
  26. //    mycmdwin.cxx:    Source code for sample command window
  27. //      mydialog.h:     Header for sample modeless dialog
  28. //      mydialog.cxx:   Source for sample modeless dialog
  29. //      mymodal.h:      Header for sample modal dialog
  30. //      mymodal.cxx     Soruce for sample modal dialog
  31. //
  32. //      While these files were generated by hand, they are intended to
  33. //      serve as an example of files that could have been generated by
  34. //      the V interface generator (Vigr)
  35. //                                                             
  36.  
  37. #include "protoapp.h"    // our header
  38.  
  39.     static char newName[] = "[A] Example Subwindow";
  40.  
  41. //=========================>>> myApp::NewAppWin <<<==========================
  42.   vWindow* myApp::NewAppWin(vWindow* win, char* name, int w, int h, vAppWinInfo* winInfo)
  43.   {
  44.     // This version of NewAppWin is provided with the information
  45.     // required to name and size a window.
  46.  
  47.     // Typically, these would get a file name or other information
  48.     // that will setup the AppWinInfo class for information
  49.     // specific to the application. Thus, each open window
  50.     // usually represents a view of a file or data object.
  51.  
  52.     vWindow* thisWin = win;        // local copy to use
  53.     vAppWinInfo* awinfo = winInfo;
  54.  
  55.     char *myname = name;
  56.  
  57.     if (!*name)
  58.       {
  59.     myname = newName;        // make up a name
  60.       }
  61.     
  62.     UserDebug1(Build,"myApp::NewAppWin(%s)\n",myname);
  63.  
  64.     if (!thisWin)            // need to new a window
  65.       {
  66.     thisWin = new myCmdWindow(myname, w, h);
  67.       }
  68.  
  69.     // The real app will no doubt have its own AppWinInfo class.
  70.  
  71.     if (!awinfo)
  72.     awinfo = new vAppWinInfo(myname);
  73.  
  74.     if (!*name)
  75.       {
  76.     newName[1]++;        // Cheap way to generate unique name
  77.       }
  78.     return vApp::NewAppWin(thisWin, myname, w, h, awinfo);
  79.   }
  80.  
  81. //========================>>> myApp::Exit <<<======================
  82.   void myApp::Exit(void)
  83.   {
  84.     // This is called to close all windows. If the app needs to
  85.     // do something special, it can. Otherwise, it can call the
  86.     // general vApp::Exit method, which will generate
  87.     // appropriate calls the the specialized myApp::CloseAppWin
  88.  
  89.     UserDebug(Build,"myApp::Exit()\n");
  90.  
  91.     vApp::Exit();    // easy default behavior
  92.   }
  93.  
  94. //=======================>>> myApp::CloseAppWin <<<===========================
  95.   int myApp::CloseAppWin(vWindow* win)
  96.   {
  97.     // This will be called BEFORE a window has been unregistered or
  98.     // closed.  The app can do whatever it needs to to close down
  99.     // the data associated with this window. Then it can call the
  100.     // general vApp::CloseAppWin to unregister and close this window.
  101.     // Note that the win gives a handle that can be used with
  102.     // vApp::getAppWinInfo to retrieve the AppWinInfo class.
  103.  
  104.     // Code to handle close of window (such as saving/closing a file)
  105.     // would go here...
  106.  
  107.     // Now unregister and close the window.
  108.  
  109.     UserDebug(Build,"myApp::CloseAppWin()\n");
  110.  
  111.     return vApp::CloseAppWin(win);
  112.   }
  113.  
  114. //========================>>> myApp::AppCommand <<<==============================
  115.   void myApp::AppCommand(vWindow* win, ItemVal id, ItemVal val, CmdType cType)
  116.   {
  117.     // Any commands not processed by the window will be passed
  118.     // along to here for default treatment.
  119.  
  120.     UserDebug1(Build,"myApp::AppCmd(ID: %d)\n",id);
  121.     vApp::AppCommand(win, id, val, cType);
  122.   }
  123.  
  124. //=========================>>> myApp::KeyIn <<<==============================
  125.   void myApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  126.   {
  127.     // Any key strokes not processed by the window will be passed
  128.     // along to here for default treatment.
  129.  
  130.     vApp::KeyIn(win, key, shift);
  131.   }
  132.  
  133. //###########################################################################
  134.  
  135.   // EVERY V application needs the equivalent of the following line
  136.  
  137.   static myApp my_App("ProtoApp");    // The instance of the app
  138.  
  139. //============================>>> AppMain <<<==============================
  140.   int AppMain(int argc, char** argv)
  141.   {
  142.     // Use AppMain to create the main window
  143.  
  144.     (void) theApp->NewAppWin(0, "Prototype V Example", 450, 200);
  145.  
  146.     return 0;
  147.   }
  148.