home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / tutor / tutapp.cpp < prev    next >
C/C++ Source or Header  |  1998-07-03  |  7KB  |  168 lines

  1. //========================================================================
  2. //  tutapp.cpp:     Source file for tutorial V application
  3. //
  4. //      Copyright 1995,1996 Bruce E. Wampler. All rights reserved.
  5. //========================================================================
  6. //
  7. // This file is used to define the main application object. There
  8. // will be exactly one instance of the application object. You will
  9. // usually derive you own app class from the vApp class. This file
  10. // defines a sample myApp class. The usual purpose of myApp is to
  11. // start the initial window, and act as a central controller for
  12. // your application. Rather than reading this file sequentially,
  13. // you should skip to the end and read the comments surrounding the
  14. // AppMain function.
  15.  
  16.  
  17. //  Files required for tutorial minimal application:
  18. //      tutapp.h:       Header for the min app
  19. //      tutapp.cpp:     Source code for min app
  20. //      tcmdwin.h:      Header code for sample command window
  21. //      tcmdwin.cpp:    Source code for sample command window
  22. //      tdialog.h:      Header for sample modeless dialog
  23. //      tdialog.cpp:    Source for sample modeless dialog
  24. //      tmodal.h:       Header for sample modal dialog
  25. //      tmodal.cpp:     Source for sample modal dialog
  26. //
  27.  
  28. // First #include header files we need to use.
  29.  
  30. #include "tutapp.h"     // our header file
  31.  
  32. //=========================>>> tutApp::NewAppWin <<<======================
  33.   vWindow* tutApp::NewAppWin(vWindow* win, char* name, int w, int h,
  34.     vAppWinInfo* winInfo)
  35.   {
  36.     // This version of NewAppWin is provided with the information
  37.     // required to name and size a window. You can derive
  38.     // 
  39.     // Typically, this method would get a file name or other information
  40.     // needed to setup the AppWinInfo class  specifically for the
  41.     // application. Thus, each open window usually represents a view of
  42.     // a file or data object.
  43.  
  44.     vWindow* thisWin = win;             // local copy to use
  45.     vAppWinInfo* awinfo = winInfo;
  46.     char *myname = name;                // local copy
  47.  
  48.     if (!name || !*name)
  49.         myname = "Example";            // make up a name
  50.         
  51.     // The UserDebug macros are useful for tracking what is going on.
  52.     // This shows we're building a window.
  53.  
  54.     UserDebug1(Build,"tutApp::NewAppWin(%s)\n",myname);
  55.  
  56.     // You may instantiate an instance of the window outside of
  57.     // NewAppWin, or allow NewAppWin to create the instance.
  58.  
  59.     if (!thisWin)       // Didn't provide a window, so create one.
  60.         thisWin = new tCmdWindow(myname, w, h);
  61.  
  62.     // The vAppWinInfo class is meant to serve as a database used by the
  63.     // tutApp controller. If you use this feature, you will probably
  64.     // derive your own myAppWinInfo class from vAppWinInfo. The instance
  65.     // of vAppWinInfo created here will be automatically deleted when
  66.     // this window instance is closed through CloseAppWin.
  67.  
  68.     if (!awinfo)        // Did caller provide an appinfo?
  69.         awinfo = new vAppWinInfo(myname);
  70.  
  71.     // After you have created an instance of the window and an instance
  72.     // of the AppWinInfo, you MUST call the base vApp::NewAppWin method.
  73.     // You won't need to explicitly keep track of the pointer to
  74.     // each new window -- unless it has to interact with other windows.
  75.     // If that is the case, then you can use your derived vAppWinInfo
  76.     // to coordinate the interaction.
  77.  
  78.     return vApp::NewAppWin(thisWin,name,w,h,awinfo);
  79.   }
  80.  
  81. //===========================>>> tutApp::Exit <<<=========================
  82.   void tutApp::Exit(void)
  83.   {
  84.     // This can be called to close all windows. If the app needs to do
  85.     // something special, it can. Otherwise, it can call the general
  86.     // vApp::Exit method, which will perform appropriate calls the the
  87.     // specialized tutApp::CloseAppWin.
  88.  
  89.     UserDebug(Build,"tutApp::Exit()\n");
  90.  
  91.     vApp::Exit();       // easy default behavior
  92.   }
  93.  
  94. //======================>>> tutApp::CloseAppWin <<<=======================
  95.   int tutApp::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 the
  99.     // data associated with this window. (It is invoked explicitly by
  100.     // you in response to a Close menu pick, for example, or when the
  101.     // user clicks the close button. It can also be called by vApp::Exit().
  102.     // After this method cleans up, it can then call the superclass
  103.     // vApp::CloseAppWin to unregister and close this window. Note that
  104.     // the win gives a handle that can be used with vApp::getAppWinInfo
  105.     // to retrieve the AppWinInfo class.
  106.  
  107.     UserDebug(Build,"tutApp::CloseAppWin()\n");
  108.  
  109.     // Code to handle close of window (such as saving/closing
  110.     // a file) would go here...
  111.  
  112.     return vApp::CloseAppWin(win);   // Unregister and close the window.
  113.   }
  114.  
  115. //=====================>>> tutApp::AppCommand <<<=========================
  116.   void tutApp::AppCommand(vWindow* win, ItemVal id, ItemVal val,
  117.     CmdType cType)
  118.   {
  119.     // Any commands not processed by the window WindowCommand
  120.     // method will be passed to here for default treatment.
  121.  
  122.     UserDebug1(Build,"tutApp::AppCmd(ID: %d)\n",id);
  123.     vApp::AppCommand(win, id, val, cType);
  124.   }
  125.  
  126. //=======================>>> tutApp::KeyIn <<<============================
  127.   void tutApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  128.   {
  129.     // Any key strokes not processed by the window will be passed
  130.     // along to here for default treatment.
  131.  
  132.     vApp::KeyIn(win, key, shift);
  133.   }
  134.  
  135. //========================================================================
  136. // Remember that any static references to an object are constructed by
  137. // the C++ startup code before main or any other functions are called.
  138. // Thus, the constructor for tutApp (and thus vApp) is invoked before
  139. // anything else happens. This enables V to perform whatever
  140. // initializations are required by the host GUI system - and frees you
  141. // from having to worry about the typical gory details. All this means
  142. // that EVERY V application needs a static instance of the tutApp to
  143. // get things rolling. Note that the global variable theApp is set to
  144. // point to this instance, and is the easiest way to access the vApp
  145. // and tutApp methods (e.g., theApp->Exit()).
  146. //========================================================================
  147.  
  148.   static tutApp tut_App("TutorApp");  // The single instance of the app
  149.  
  150. //===========================>>> AppMain <<<==============================
  151.   int AppMain(int argc, char** argv)
  152.   {
  153.     // The V framework defines the instance of main. After some
  154.     // processing of command line arguments, AppMain is called with
  155.     // cleaned up command line arguments. Note that at this time, no
  156.     // windows have been defined. Normally, AppMain is the place to
  157.     // start up the first window. You can perform any initialization you
  158.     // need to do here.
  159.  
  160.     (void) theApp->NewAppWin(0, "Tutorial V Example", 350, 100, 0);
  161.  
  162.     // At this point, the window is up, and all events are being
  163.     // routed through its methods.
  164.  
  165.     // We MUST return 0 if the status is ok at this point.
  166.     return 0;
  167.   }
  168.