home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / LANCELOT / LINFOWIN.CPP < prev    next >
C/C++ Source or Header  |  1995-04-07  |  13KB  |  252 lines

  1. /******************************************************************************
  2. * FILE NAME: linfowin.cpp                                                     *
  3. *                                                                             *
  4. * Classes:                                                                    *
  5. *   LInfoWindow                                                               *
  6. *                                                                             *
  7. * COPYRIGHT:                                                                  *
  8. *   Licensed Materials - Property of IBM                                      *
  9. *   (C) Copyright IBM Corporation 1992, 1995                                  *
  10. *   All Rights Reserved                                                       *
  11. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  12. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  13. ******************************************************************************/
  14.  
  15. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  16.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  17. #endif                                  //  is defined.
  18. #include <ireslib.hpp>
  19. #include <irect.hpp>
  20. #include <imsgbox.hpp>
  21. #include <istring.hpp>
  22. #include <isysmenu.hpp>
  23. #include "linfowin.hpp"
  24. #include "lgoodies.hpp"
  25. #include "lancelot.h"
  26.  
  27. /******************************************************************************
  28. * Class LInfoWindow :: LInfoWindow - Constructor for the information window   *
  29. *   given an employee.                                                        *
  30. *                                                                             *
  31. * Define yourself as an IFrameWindow                                          *
  32. * Create title                                                                *
  33. * Create notebook                                                             *
  34. * Create help window                                                          *
  35. * Store pointer to container object                                           *
  36. * Store query flag                                                            *
  37. ******************************************************************************/
  38. LInfoWindow::LInfoWindow   ( unsigned long windowId,
  39.                              IWindow* parent, IWindow* owner,
  40.                              IPoint bottomLeft,
  41.                              LCnrObject* object,
  42.                              LEmployeeData& employee,
  43.                              Boolean isQuery )
  44.      :IFrameWindow         ( windowId, parent, owner ),
  45.       title                ( this ),
  46.       notebook             ( this, this, employee, isQuery ),
  47.       help                 ( ID_HELP_TABLE3, this ),
  48.       pObject              ( object ),
  49.       isAQuery             ( isQuery )
  50. {
  51. /*-----------------------------------------------------------------------------
  52. | If this window was launched from a cnr object,                              |
  53. | - set as open                                                               |
  54. | - increment usage count                                                     |
  55. -----------------------------------------------------------------------------*/
  56.    if ( pObject )
  57.    {
  58.       pObject->setOpen();
  59.       pObject->incrementUsage();
  60.    }
  61.  
  62. /*-----------------------------------------------------------------------------
  63. | Attempt to load the help file                                               |
  64. -----------------------------------------------------------------------------*/
  65.    try
  66.    {
  67.       help.addLibraries( "lanchelp.hlp" );
  68.       help.setTitle( STR_HELP_TITLE );
  69.    }
  70.    catch( ... )
  71.    {}
  72.  
  73. /*-----------------------------------------------------------------------------
  74. | Handle command events for this frame window                                 |
  75. -----------------------------------------------------------------------------*/
  76.    ICommandHandler::handleEventsFor( this );
  77.  
  78. /*-----------------------------------------------------------------------------
  79. | Determine the title for this frame window                                   |
  80. -----------------------------------------------------------------------------*/
  81.    if ( isQuery )
  82.       title.setTitleText( STR_MAIN_TITLE, STR_QUERY_INFO_WINDOW );
  83.    else if ( ! employee.employeeNumber().length() )
  84.        title.setTitleText( STR_MAIN_TITLE, STR_NEW_INFO_WINDOW );
  85.    else
  86.        title.setTitleText( IApplication::current().userResourceLibrary().
  87.                            loadString( STR_MAIN_TITLE ),
  88.                            IString( employee.lastName()  +
  89.                            ", " + employee.firstName() ) );
  90.  
  91. /*-----------------------------------------------------------------------------
  92. | Set the frame's icon                                                        |
  93. | Set the frame's client to be the notebook                                   |
  94. -----------------------------------------------------------------------------*/
  95.    setIcon( ID_ICON_PERSON4 );
  96.    setClient( ¬ebook );
  97.  
  98. /*-----------------------------------------------------------------------------
  99. | Resize the window based on the minimum size of the notebook                 |
  100. -----------------------------------------------------------------------------*/
  101. #ifndef IC_MOTIF
  102.    moveSizeToClient( IRectangle( bottomLeft,
  103.                      notebook.minimumSize() ) );
  104. #else
  105.    moveSizeTo( IRectangle( bottomLeft,
  106.                notebook.minimumSize() ) );
  107. #endif
  108.  
  109. /*-----------------------------------------------------------------------------
  110. | Move the frame window to the best location for the display size             |
  111. | Set the focus to the frame                                                  |
  112. | Show the frame                                                              |
  113. -----------------------------------------------------------------------------*/
  114.    IPoint
  115.       newLocation( LFrameWindow::bestFit( this ) );
  116.    moveTo( newLocation );
  117.    if ( ( ! newLocation.x() ) || ( !newLocation.y() ) )
  118.       maximize();
  119.    setFocus().show();
  120. }
  121.  
  122.  
  123. /******************************************************************************
  124. * Class LInfoWindow :: LInfoWindow - Constructor for the information window   *
  125. *   given a query string.                                                     *
  126. *                                                                             *
  127. * Define yourself as an IFrameWindow                                          *
  128. * Create title                                                                *
  129. * Create notebook                                                             *
  130. * Create help window                                                          *
  131. * Store pointer to container object                                           *
  132. * Store query flag                                                            *
  133. ******************************************************************************/
  134. LInfoWindow::LInfoWindow   ( unsigned long windowId,
  135.                              IWindow* parent, IWindow* owner,
  136.                              IPoint bottomLeft,
  137.                              LMainCnr* cnr,
  138.                              LCnrObject* object,
  139.                              IString queryName )
  140.      :IFrameWindow         ( windowId, parent, owner ),
  141.       title                ( this ),
  142.       notebook             ( this, this, cnr, queryName ),
  143.       help                 ( ID_HELP_TABLE3, this ),
  144.       pObject              ( object ),
  145.       isAQuery             ( true )
  146. {
  147. /*-----------------------------------------------------------------------------
  148. | If this window was launched from a valid cnr object,                        |
  149. | - set as open                                                               |
  150. | - increment usage count                                                     |
  151. -----------------------------------------------------------------------------*/
  152.    if ( pObject )
  153.    {
  154.       pObject->setOpen();
  155.       pObject->incrementUsage();
  156.    }
  157.  
  158. /*-----------------------------------------------------------------------------
  159. | Attempt to load the help file                                               |
  160. -----------------------------------------------------------------------------*/
  161.    try
  162.    {
  163.       help.addLibraries( "lanchelp.hlp" );
  164.       help.setTitle( STR_HELP_TITLE );
  165.    }
  166.    catch( ... )
  167.    {}
  168.  
  169. /*-----------------------------------------------------------------------------
  170. | Handle command events for this frame window                                 |
  171. -----------------------------------------------------------------------------*/
  172.    ICommandHandler::handleEventsFor( this );
  173.  
  174. /*-----------------------------------------------------------------------------
  175. | Set the title of this frame window to indicate a query                      |
  176. -----------------------------------------------------------------------------*/
  177.    title.setTitleText( STR_MAIN_TITLE, STR_QUERY_INFO_WINDOW );
  178.  
  179. /*-----------------------------------------------------------------------------
  180. | Set the frame's icon                                                        |
  181. | Set the frame's client to be the notebook                                   |
  182. -----------------------------------------------------------------------------*/
  183.    setIcon( ID_ICON_PERSON4 );
  184.    setClient( ¬ebook );
  185.  
  186. /*-----------------------------------------------------------------------------
  187. | Resize the window based on the minimum size of the notebook                 |
  188. -----------------------------------------------------------------------------*/
  189. #ifndef IC_MOTIF
  190.    moveSizeToClient( IRectangle( bottomLeft,
  191.                      notebook.minimumSize() ) );
  192. #else
  193.    moveSizeTo( IRectangle( bottomLeft,
  194.                notebook.minimumSize() ) );
  195. #endif
  196.  
  197. /*-----------------------------------------------------------------------------
  198. | Move the frame window to the best location for the display size             |
  199. | Set the focus to the frame                                                  |
  200. | Show the frame                                                              |
  201. -----------------------------------------------------------------------------*/
  202.    IPoint
  203.       newLocation( LFrameWindow::bestFit( this ) );
  204.    moveTo( newLocation );
  205.    if ( ( !newLocation.x() ) || ( ! newLocation.y() ) )
  206.       maximize();
  207.    setFocus().show();
  208. }
  209.  
  210.  
  211. /******************************************************************************
  212. * Class LInfoWindow :: ~LInfoWindow - Destructor for the info window          *
  213. ******************************************************************************/
  214. LInfoWindow::~LInfoWindow()
  215. {
  216. /*-----------------------------------------------------------------------------
  217. | If this window was launched from a valid cnr object,                        |
  218. | - decrement usage count                                                     |
  219. | - if no other information windows are via the cnr object,                   |
  220. |   indicate it is closed                                                     |
  221. -----------------------------------------------------------------------------*/
  222.    if ( pObject )
  223.    {
  224.       pObject->decrementUsage();
  225.       if ( ! pObject->usageCount() )
  226.          pObject->setClosed();
  227.    }
  228. }
  229.  
  230.  
  231. /******************************************************************************
  232. * Class LInfoWindow :: systemCommand()                                        *
  233. *   Handle any system command events for this frame window                    *
  234. ******************************************************************************/
  235. IBase::Boolean LInfoWindow::systemCommand( ICommandEvent& event )
  236. {
  237.    Boolean
  238.       retCode = false;
  239.  
  240. /*-----------------------------------------------------------------------------
  241. | If the user is attempting to close the window,                              |
  242. | - if this is not a query window, then save the personnel data               |
  243. -----------------------------------------------------------------------------*/
  244.    if ( event.commandId() == ISystemMenu::idClose )
  245.    {
  246.       if ( !isAQuery & !notebook.verifyPages( "" ) )
  247.          retCode = true;
  248.    }
  249.  
  250.    return retCode;
  251. }
  252.