home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / lancelot / linfowin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  12.3 KB  |  253 lines

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