home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / VIEWPORT / vdapp.cpp < prev    next >
C/C++ Source or Header  |  1998-04-20  |  5KB  |  128 lines

  1. // vdapp.h
  2.  
  3.  
  4. // Copyright (C) 1997  Cliff Johnson                                       //
  5. //                                                                         //
  6. // This program is free software; you can redistribute it and/or           //
  7. // modify it under the terms of the GNU  General Public                    //
  8. // License as published by the Free Software Foundation; either            //
  9. // version 2 of the License, or (at your option) any later version.        //
  10. //                                                                         //
  11. // This software is distributed in the hope that it will be useful,        //
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of          //
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       //
  14. // General Public License for more details.                                //
  15. //                                                                         //
  16. // You should have received a copy of the GNU General Public License       //
  17. // along with this software (see COPYING.LIB); if not, write to the        //
  18. // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
  19.  
  20. #include <vdapp.h>
  21. #include <vdcmdwin.h>
  22.  
  23. //=========================>>> vdApp::NewAppWin <<<======================
  24.   vWindow* vdApp::NewAppWin(vWindow* win, char* name, int w, int h,
  25.     vAppWinInfo* winInfo)
  26.   {
  27.     vWindow* thisWin = win;             // local copy to use
  28.     vAppWinInfo* awinfo = winInfo;
  29.     char *myname = name;                // local copy
  30.  
  31.     if (!name || !*name)
  32.         myname = "Example";            // make up a name
  33.         
  34.     // The UserDebug macros are useful for tracking what is going on.
  35.     // This shows we're building a window.
  36.  
  37.     UserDebug1(Build,"vdApp::NewAppWin(%s)\n",myname);
  38.  
  39.     // You may instantiate an instance of the window outside of
  40.     // NewAppWin, or allow NewAppWin to create the instance.
  41.  
  42.     if (!thisWin) thisWin = new vdCmdWindow(myname, w, h);
  43.  
  44.     // The vAppWinInfo class is meant to serve as a database used by the
  45.     // vdApp controller. If you use this feature, you will probably
  46.     // derive your own myAppWinInfo class from vAppWinInfo. The instance
  47.     // of vAppWinInfo created here will be automatically deleted when
  48.     // this window instance is closed through CloseAppWin.
  49.  
  50.     if (!awinfo)        // Did caller provide an appinfo?
  51.         awinfo = new vAppWinInfo(myname);
  52.  
  53.     // After you have created an instance of the window and an instance
  54.     // of the AppWinInfo, you MUST call the base vApp::NewAppWin method.
  55.     // You won't need to explicitly keep track of the pointer to
  56.     // each new window -- unless it has to interact with other windows.
  57.     // If that is the case, then you can use your derived vAppWinInfo
  58.     // to coordinate the interaction.
  59.  
  60.     return vApp::NewAppWin(thisWin,name,w,h,awinfo);
  61.   }
  62.  
  63. //===========================>>> vdApp::Exit <<<=========================
  64.   void vdApp::Exit(void)
  65.   {
  66.     // This can be called to close all windows. If the app needs to do
  67.     // something special, it can. Otherwise, it can call the general
  68.     // vApp::Exit method, which will perform appropriate calls the the
  69.     // specialized vdApp::CloseAppWin.
  70.  
  71.     UserDebug(Build,"vdApp::Exit()\n");
  72.  
  73.     vApp::Exit();       // easy default behavior
  74.   }
  75.  
  76. //======================>>> vdApp::CloseAppWin <<<=======================
  77.   void vdApp::CloseAppWin(vWindow* win)
  78.   {
  79.     // This will be called BEFORE a window has been unregistered or
  80.     // closed. The app can do whatever it needs to to close down the
  81.     // data associated with this window. (It is invoked explicitly by
  82.     // you in response to a Close menu pick, for example, or when the
  83.     // user clicks the close button. It can also be called by vApp::Exit().
  84.     // After this method cleans up, it can then call the superclass
  85.     // vApp::CloseAppWin to unregister and close this window. Note that
  86.     // the win gives a handle that can be used with vApp::getAppWinInfo
  87.     // to retrieve the AppWinInfo class.
  88.  
  89.     UserDebug(Build,"vdApp::CloseAppWin()\n");
  90.  
  91.     // Code to handle close of window (such as saving/closing
  92.     // a file) would go here...
  93.  
  94.     vApp::CloseAppWin(win);   // Unregister and close the window.
  95.   }
  96.  
  97. //=====================>>> vdApp::AppCommand <<<=========================
  98.   void vdApp::AppCommand(vWindow* win, ItemVal id, ItemVal val,
  99.     CmdType cType)
  100.   {
  101.     // Any commands not processed by the window WindowCommand
  102.     // method will be passed to here for default treatment.
  103.  
  104.     UserDebug1(Build,"vdApp::AppCmd(ID: %d)\n",id);
  105.     vApp::AppCommand(win, id, val, cType);
  106.   }
  107.  
  108. //=======================>>> vdApp::KeyIn <<<============================
  109.   void vdApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  110.   {
  111.     // Any key strokes not processed by the window will be passed
  112.     // along to here for default treatment.
  113.  
  114.     vApp::KeyIn(win, key, shift);
  115.   }
  116.  
  117. //========================================================================
  118.  
  119.   static vdApp vd_App("vdApp");  // The single instance of the app
  120.  
  121. //===========================>>> AppMain <<<==============================
  122.   int AppMain(int argc, char** argv)
  123.   {
  124.     (void) theApp->NewAppWin(0, "FREEdraft 0.3", 850, 480, 0);
  125.  
  126.     return 0; // if everything is groovy.
  127.   }
  128.