home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / LANCELOT / LPERSWIN.CPP < prev    next >
C/C++ Source or Header  |  1995-05-01  |  50KB  |  1,091 lines

  1. /****************************************************************************
  2. * LANCELOT SAMPLE PROGRAM - lperswin.cpp                                    *
  3. *                                                                           *
  4. * Classes : LPersonnelWindow                                                *
  5. *           LPersonnelWindowCommandHandler                                  *
  6. *           LPersonnelCnr                                                   *
  7. *           LPersonnelCnrObject                                             *
  8. *           LPersonnelWindowHelpHandler                                     *
  9. *                                                                           *
  10. * DISCLAIMER OF WARRANTIES:                                                 *
  11. *   The following [enclosed] code is sample code created by IBM             *
  12. *   Corporation.  This sample code is not part of any standard IBM product  *
  13. *   and is provided to you solely for the purpose of assisting you in the   *
  14. *   development of your applications.  The code is provided "AS IS",        *
  15. *   without warranty of any kind.  IBM shall not be liable for any damages  *
  16. *   arising out of your use of the sample code, even if they have been      *
  17. *   advised of the possibility of such damages.                             *
  18. ****************************************************************************/
  19.  
  20. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  21.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  22. #endif                                  //  is defined.
  23. #include "lperswin.hpp"
  24. #include "linfowin.hpp"
  25. #include "lgoodies.hpp"
  26.  
  27. /******************************************************************************
  28. * Class LPersonnelWindow :: LPersonnelWindow - Constructor for the personnel  *
  29. *   window.                                                                   *
  30. *                                                                             *
  31. * Define yourself as an IFrameWindow                                          *
  32. * Create title                                                                *
  33. * Create menubar                                                              *
  34. * Create information area                                                     *
  35. * Create container                                                            *
  36. * Create toolbar (PM only)                                                    *
  37. * Create help window                                                          *
  38. * Create command handler                                                      *
  39. * Create help handler                                                         *
  40. * Store department query string                                               *
  41. ******************************************************************************/
  42. LPersonnelWindow::LPersonnelWindow( IWindow* owner,
  43.                                     QueryIntersection& bagOfIds,
  44.                                     const IString deptQuery )
  45.      :IFrameWindow         ( ID_PERSONNEL, 0, owner ),
  46.       title                ( this, STR_MAIN_TITLE, STR_PERSONNEL_TITLE ),
  47.       menubar              ( ID_PERSONNEL, this ),
  48.       infoarea             ( this ),
  49.       cnr                  ( ID_PERSONNEL_CNR, this, this ),
  50. #ifdef IC_PM
  51.       toolbar              ( ID_PERSONNEL_TOOLBAR, this, &infoarea ),
  52. #endif
  53.       help                 ( ID_HELP_TABLE2, this ),
  54.       cmdHdr               ( this, &help, &cnr ),
  55.       helpHdr              (),
  56.       aDeptQuery           ( deptQuery ),
  57.       aSelects             ( true )
  58. {
  59. /*-----------------------------------------------------------------------------
  60. | Attempt to load the help file                                               |
  61. -----------------------------------------------------------------------------*/
  62.    try
  63.    {
  64.       help.addLibraries( "lanchelp.hlp" );
  65.       help.setTitle( STR_HELP_TITLE );
  66.    }
  67.    catch( ... )
  68.    {}
  69.  
  70. #ifdef IC_PM
  71. /*-----------------------------------------------------------------------------
  72. | Handle Drag/Drop                                                            |
  73. -----------------------------------------------------------------------------*/
  74.    cnr.setItemProvider( &this->provider );
  75.    IDMHandler::enableDragDropFor( &cnr );
  76. #endif
  77.  
  78. /*-----------------------------------------------------------------------------
  79. | Handle command events for this frame window                                 |
  80. | Handle help events for this frame window                                    |
  81.  ----------------------------------------------------------------------------*/
  82.    cmdHdr.handleEventsFor( this );
  83.    helpHdr.handleEventsFor( this );
  84.  
  85. /*-----------------------------------------------------------------------------
  86. | Set the application icon                                                    |
  87. | Set the client to be the container                                          |
  88. | Identify the offset for the infoarea strings                                |
  89. | Set the inactive text for the infoarea                                      |
  90. | Populate the cnr with cnr objects                                           |
  91. | Set the application's focus and show it                                     |
  92.  ----------------------------------------------------------------------------*/
  93.    setIcon( ID_PERSONNEL );
  94.    setClient( &cnr );
  95.    infoarea.setStringTableOffset( ID_PERSONNEL_OFFSET_INFOAREA );
  96.    infoarea.setInactiveText( ID_PERSONNEL_OFFSET_INFOAREA+ID_PERSONNEL );
  97.    populate( bagOfIds );
  98.  
  99. /*-----------------------------------------------------------------------------
  100. | Resize the frame window based on the minimum width of the toolbar           |
  101. -----------------------------------------------------------------------------*/
  102.    IRectangle
  103.       clientRect = clientRectFor( rect() );
  104. #ifdef IC_PM
  105.    moveSizeToClient( IRectangle( clientRect.bottomLeft(),
  106.                      IPoint( clientRect.left() + toolbar.minimumSize().width(),
  107.                      clientRect.top() ) ) );
  108. #endif
  109.  
  110. /*-----------------------------------------------------------------------------
  111. | Move the frame window to the best location for the display size             |
  112. | Set the application's focus and show it                                     |
  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 LPersonnelWindow :: ~LPersonnelWindow - Destructor for the            *
  125. *   personnel window.                                                         *
  126. ******************************************************************************/
  127. LPersonnelWindow::~LPersonnelWindow()
  128. {
  129. /*-----------------------------------------------------------------------------
  130. | Stop handling events.                                                       |
  131. -----------------------------------------------------------------------------*/
  132.    cmdHdr.stopHandlingEventsFor( this );
  133.    helpHdr.stopHandlingEventsFor( this );
  134. }
  135.  
  136.  
  137. /******************************************************************************
  138. * Class LPersonnelWindow :: enableSelects - Enable/disable the selection      *
  139. *   menu items.                                                               *
  140. ******************************************************************************/
  141. LPersonnelWindow& LPersonnelWindow::enableSelects( Boolean which )
  142. {
  143.    menubar.enableItem( ID_PERSONNEL_VIEW_SELECT, which );
  144. #ifdef IC_PM
  145.    toolbar.enableSelects( which );
  146. #endif
  147.    aSelects = which;
  148.  
  149.    return *this;
  150. }
  151.  
  152.  
  153. /******************************************************************************
  154. * Class LPersonnelWindow :: populate() - Populate the container with people   *
  155. ******************************************************************************/
  156. LPersonnelWindow& LPersonnelWindow::populate( QueryIntersection& empIds )
  157. {
  158. /*-----------------------------------------------------------------------------
  159. | Hide the cnr until we're finished deleting and adding all cnr objects       |
  160. -----------------------------------------------------------------------------*/
  161.    cnr.hide();
  162. /*-----------------------------------------------------------------------------
  163. | If there are employees that match the search criteria,                      |
  164. | - Iterate each employee and create a cnr object                             |
  165. -----------------------------------------------------------------------------*/
  166.    for ( empIds.setFirstId();
  167.          empIds.isValid();
  168.          empIds.setNextId() )
  169.    {
  170.       LEmployeeData
  171.          emp( empIds.getId() );
  172.       unsigned long
  173.          empType = ID_ICON_PERSON1;
  174.       switch ( emp.employeeType() )
  175.       {
  176.          case LEmployeeData::Regular:
  177.          {
  178.             empType = ID_ICON_PERSON1;
  179.             break;
  180.          }
  181.          case LEmployeeData::Manager:
  182.          {
  183.             empType = ID_ICON_PERSON2;
  184.             break;
  185.          }
  186.          case LEmployeeData::Supplemental:
  187.          {
  188.             empType = ID_ICON_PERSON3;
  189.             break;
  190.          }
  191.          case LEmployeeData::Unemployed:
  192.          {
  193.             empType = ID_ICON_PERSON4;
  194.             break;
  195.          }
  196.          default:
  197.          {
  198.             empType = ID_ICON_PERSON_UNKNOWN;
  199.             break;
  200.          }
  201.       }
  202.       LPersonnelCnrObject
  203.         *pCnrObject = new LPersonnelCnrObject( empType, emp );
  204.  
  205.       cnr.addObject( pCnrObject );
  206.    }
  207.  
  208. /*-----------------------------------------------------------------------------
  209. | Arrange the icons                                                           |
  210. | Reshow it                                                                   |
  211. -----------------------------------------------------------------------------*/
  212.    cnr.arrangeIconView();
  213.    cnr.show();
  214.  
  215.    return *this;
  216. }
  217.  
  218.  
  219. /******************************************************************************
  220. * Class LPersonnelCnr :: LPersonnelCnr - Constructor for the personnel        *
  221. *   container.                                                                *
  222. *                                                                             *
  223. * Define yourself as an IContainerControl                                     *
  224. * Create the various container columns                                        *
  225. * Define a help window as NULL                                                *
  226. * Define a popup menu as NULL                                                 *
  227. * Define the last popup menu container object as NULL                         *
  228. ******************************************************************************/
  229. LPersonnelCnr::LPersonnelCnr( unsigned long id, LPersonnelWindow* parent,
  230.                               LPersonnelWindow* owner, IRectangle location )
  231.      :IContainerControl    ( id, parent, owner, location,
  232.                              IContainerControl::extendedSelection ),
  233.       colIcon              ( IContainerColumn::isIcon ),
  234.       colIconText          ( IContainerColumn ::isIconViewText ),
  235.       colLastName          ( offsetof( LPersonnelCnrObject, theEmployee.theLastName ) ),
  236.       colFirstName         ( offsetof( LPersonnelCnrObject, theEmployee.theFirstName ) ),
  237.       colMiddleInitial     ( offsetof( LPersonnelCnrObject, theEmployee.theMiddleInitial ) ),
  238.       colEmployeeNumber    ( offsetof( LPersonnelCnrObject, theEmployee.theEmployeeNum ) ),
  239.       colInternalPhone     ( offsetof( LPersonnelCnrObject, theEmployee.theInternalPhone ) ),
  240.       colExternalPhone     ( offsetof( LPersonnelCnrObject, theEmployee.theExternalPhone ) ),
  241.       colInternalAddress   ( offsetof( LPersonnelCnrObject, theEmployee.theInternalAddr ) ),
  242.       colExternalAddress   ( offsetof( LPersonnelCnrObject, theEmployee.theExternalAddr ) ),
  243.       colRoom              ( offsetof( LPersonnelCnrObject, theEmployee.theRoom ) ),
  244.       colBuilding          ( offsetof( LPersonnelCnrObject, theEmployee.theBuilding ) ),
  245.       colDepartment        ( offsetof( LPersonnelCnrObject, theEmployee.theDeptName ) ),
  246.       colManagerNumber     ( offsetof( LPersonnelCnrObject, theEmployee.theManagerNum ) ),
  247.       colManagerName       ( offsetof( LPersonnelCnrObject, theEmployee.theManagerName ) ),
  248.       helpWin              ( NULL ),
  249.       popm                 ( NULL ),
  250.       ptheLastPopupMenuObject ( NULL )
  251. {
  252. /*-----------------------------------------------------------------------------
  253. | Start handling container events for the container                           |
  254. | Start handling container menu events for the container                      |
  255. -----------------------------------------------------------------------------*/
  256.    ICnrHandler::handleEventsFor( this );
  257.    ICnrMenuHandler::handleEventsFor( this );
  258.  
  259. /*-----------------------------------------------------------------------------
  260. | Add the cnr columns to the cnr                                              |
  261. -----------------------------------------------------------------------------*/
  262.    addColumn( &colIcon );
  263.    addColumn( &colIconText );
  264.    addColumn( &colLastName );
  265.    addColumn( &colFirstName );
  266.    addColumn( &colMiddleInitial );
  267.    addColumn( &colEmployeeNumber );
  268.    addColumn( &colInternalPhone );
  269.    addColumn( &colExternalPhone );
  270.    addColumn( &colInternalAddress );
  271.    addColumn( &colExternalAddress );
  272.    addColumn( &colRoom );
  273.    addColumn( &colBuilding );
  274.    addColumn( &colDepartment );
  275.    addColumn( &colManagerNumber );
  276.    addColumn( &colManagerName );
  277.  
  278. /*-----------------------------------------------------------------------------
  279. | Set the cnr column headings                                                 |
  280. -----------------------------------------------------------------------------*/
  281.    colIconText.setHeadingText( STR_PERSON );
  282.    colLastName.setHeadingText( STR_LASTNAME );
  283.    colFirstName.setHeadingText( STR_FIRSTNAME );
  284.    colMiddleInitial.setHeadingText( STR_MI );
  285.    colEmployeeNumber.setHeadingText( STR_EMPLOYEENUM );
  286.    colInternalPhone.setHeadingText( STR_INTPHONE );
  287.    colExternalPhone.setHeadingText( STR_EXTPHONE );
  288.    colInternalAddress.setHeadingText( STR_INTADDR );
  289.    colExternalAddress.setHeadingText( STR_EXTADDR );
  290.    colRoom.setHeadingText( STR_ROOM );
  291.    colBuilding.setHeadingText( STR_BUILDING );
  292.    colDepartment.setHeadingText( STR_DEPT );
  293.    colManagerNumber.setHeadingText( STR_MGRNUM );
  294.    colManagerName.setHeadingText( STR_MGR );
  295.  
  296. /*-----------------------------------------------------------------------------
  297. | Define column separators for details view                                   |
  298. -----------------------------------------------------------------------------*/
  299.    colLastName.showSeparators();
  300.    colFirstName.showSeparators();
  301.    colMiddleInitial.showSeparators();
  302.    colEmployeeNumber.showSeparators();
  303.    colInternalPhone.showSeparators();
  304.    colExternalPhone.showSeparators();
  305.    colInternalAddress.showSeparators();
  306.    colExternalAddress.showSeparators();
  307.    colRoom.showSeparators();
  308.    colBuilding.showSeparators();
  309.    colDepartment.showSeparators();
  310.    colManagerNumber.showSeparators();
  311.    colManagerName.showSeparators();
  312.  
  313. /*-----------------------------------------------------------------------------
  314. | Delete cnr objects on closing of the container                              |
  315. -----------------------------------------------------------------------------*/
  316.    setDeleteObjectsOnClose();
  317.  
  318. /*-----------------------------------------------------------------------------
  319. | Regardless of the font size, display the same number of characters          |
  320. | for the icon text in details view                                           |
  321. -----------------------------------------------------------------------------*/
  322.    IFont
  323.       cnrFont( this );
  324.    setDetailsViewSplit( &colIconText,
  325.                         iconSize().width() +
  326.                         cnrFont.avgCharWidth() * ID_PERSONNEL_CNR_TITLE_WIDTH );
  327.  
  328. /*-----------------------------------------------------------------------------
  329. | Arrange the icons                                                           |
  330. | Show the cnr title                                                          |
  331. -----------------------------------------------------------------------------*/
  332.    arrangeIconView();
  333.    showTitle();
  334. }
  335.  
  336.  
  337. /******************************************************************************
  338. * Class LPersonnelCnr :: ~LPersonnelCnr - Destructor                          *
  339. ******************************************************************************/
  340. LPersonnelCnr::~LPersonnelCnr()
  341. {
  342. /*-----------------------------------------------------------------------------
  343. | Delete the help window.                                                     |
  344. -----------------------------------------------------------------------------*/
  345.    delete helpWin;
  346. }
  347.  
  348.  
  349. /******************************************************************************
  350. * Class LPersonnelCnr :: makePopUpMenu()                                      *
  351. *   Create popup menus based on whether is over cnr or cnr object.            *
  352. ******************************************************************************/
  353. IBase::Boolean LPersonnelCnr::makePopUpMenu( IMenuEvent& evt )
  354. {
  355. /*-----------------------------------------------------------------------------
  356. | Get the object with the last popup menu                                     |
  357. -----------------------------------------------------------------------------*/
  358.    ptheLastPopupMenuObject = (LPersonnelCnrObject*) popupMenuObject();
  359.  
  360. /*-----------------------------------------------------------------------------
  361. | Create a popup menu based on the object's type                              |
  362. | Disable the select menu item if it exists for this menu.                    |
  363. | Automatically delete the popup menu when no longer needed                   |
  364. | Show the popup menu at the mouse position                                   |
  365. -----------------------------------------------------------------------------*/
  366.    Boolean
  367.       hasSelectItem = true;
  368.  
  369.    if ( lastPopupMenuObject() )
  370.    {
  371.       popm =
  372.          new IPopUpMenu ( ID_PERSONNEL_OBJECT_POP, owner() );
  373.       hasSelectItem = false;
  374.    }
  375.    else
  376.       popm =
  377.          new IPopUpMenu ( ID_PERSONNEL_POP, owner() );
  378.  
  379.    if ( hasSelectItem &&
  380.       !((LPersonnelWindow*)owner())->selectsAllowed() )
  381.       popm->enableItem( ID_PERSONNEL_VIEW_SELECT, false );
  382.    popm->setAutoDeleteObject();
  383.    popm->show( evt.mousePosition() );
  384.  
  385.    return true;
  386. }
  387.  
  388.  
  389. /******************************************************************************
  390. * Class LPersonnelCnr :: enter() - Process the enter key on a container object*
  391. ******************************************************************************/
  392. IBase::Boolean LPersonnelCnr::enter( ICnrEnterEvent& evt )
  393. {
  394. /*---------------------------------------------------------------------------
  395. | If the user pressed enter on a cnr object, send an open message           |
  396. ---------------------------------------------------------------------------*/
  397.    if ( evt.validObject() )
  398.    {
  399.       ptheLastPopupMenuObject = (LPersonnelCnrObject*) evt.object();
  400.       postEvent( IWindow::command, ID_PERSONNEL_SELECTED_OPEN );
  401.    }
  402.  
  403.    return true;
  404. }
  405.  
  406.  
  407. /******************************************************************************
  408. * Class LPersonnelCnr :: help() - Process the help key over a container.      *
  409. ******************************************************************************/
  410. IBase::Boolean LPersonnelCnr::help( ICnrHelpEvent& evt )
  411. {
  412.    delete helpWin;
  413.    helpWin = IHelpWindow::helpWindow( this );
  414.    if ( helpWin )
  415.       helpWin->show( IResourceId( ID_PERSONNEL_C ) );
  416.  
  417.    return true;
  418. }
  419.  
  420. /******************************************************************************
  421. * Class LPersonnelCnrObject :: LPersonnelCnrObject - Constructor for          *
  422. *   container object given an existing object.                                *
  423. ******************************************************************************/
  424. LPersonnelCnrObject::LPersonnelCnrObject( const LPersonnelCnrObject& cnrobj )
  425.      :LCnrObject           ( (const LCnrObject&) cnrobj ),
  426.       theEmployee          ( cnrobj.employeeRecord() )
  427. {}
  428.  
  429.  
  430. /****************************************************************************
  431. * Class LPersonnelCnrObject :: LPersonnelCnrObject - Constructor for        *
  432. *   container object given an employee.                                     *
  433. ****************************************************************************/
  434. LPersonnelCnrObject::LPersonnelCnrObject( unsigned long icon,
  435.                                           const LEmployeeData& employee )
  436.      :LCnrObject           ( IString( employee.lastName() ) + ", " +
  437.                              employee.firstName(), icon ),
  438.       theEmployee          ( employee )
  439. {}
  440.  
  441.  
  442. /******************************************************************************
  443. * Class LPersonnelCnrObject :: ~LPersonnelCnrObject - Destructor              *
  444. ******************************************************************************/
  445. LPersonnelCnrObject::~LPersonnelCnrObject()
  446. {}
  447.  
  448.  
  449. #ifdef IC_PM
  450. /******************************************************************************
  451. * Class LPersonnelToolBar :: LPersonnelToolBar - Constructor for toolbar      *
  452. *   given a resource id                                                       *
  453. *                                                                             *
  454. * Define yourself as an IToolBar                                              *
  455. * Create the various IToolBarButtons                                          *
  456. * Create flyover help                                                         *
  457. * Create flyover help handler                                                 *
  458. ******************************************************************************/
  459. LPersonnelToolBar::LPersonnelToolBar( unsigned long id, IFrameWindow* owner,
  460.                                       ITextControl* infoarea )
  461.      :IToolBar             ( id, owner, IToolBar::aboveClient, false,
  462.                              IToolBar::classDefaultStyle
  463.                              & ~IToolBar::buttonBitmapVisible
  464.                              | IToolBar::buttonBitmapAndTextVisible ),
  465.       openButton           ( ID_PERSONNEL_SELECTED_OPEN, this, this ),
  466.       createButton         ( ID_PERSONNEL_SELECTED_CREATE, this, this ),
  467.       transferButton       ( ID_PERSONNEL_SELECTED_TRANSFER, this, this ),
  468.       helpButton           ( ID_PERSONNEL_HELP_INDEX, this, this ),
  469.       deleteButton         ( ID_PERSONNEL_SELECTED_DELETE, this, this ),
  470.       iconButton           ( ID_PERSONNEL_VIEW_OPEN_ICON, this, this ),
  471.       treeButton           ( ID_PERSONNEL_VIEW_OPEN_TREE, this, this ),
  472.       detailsButton        ( ID_PERSONNEL_VIEW_OPEN_DETAILS, this, this ),
  473.       selectAllButton      ( ID_PERSONNEL_VIEW_SELECT_ALL, this, this ),
  474.       deselectAllButton    ( ID_PERSONNEL_VIEW_SELECT_DE, this, this ),
  475.       sortAscButton        ( ID_PERSONNEL_VIEW_SORT_ASC, this, this ),
  476.       sortDescButton       ( ID_PERSONNEL_VIEW_SORT_DESC, this, this ),
  477.       arrangeButton        ( ID_PERSONNEL_VIEW_ARRANGE, this, this ),
  478.       flyText              ( ID_PERSONNEL_FLYTEXT, this ),
  479.       flyHelpHdr           ( &flyText, infoarea, 0, 0 )
  480. {
  481. /*-----------------------------------------------------------------------------
  482. | For these buttons, use the standard bitmaps for these buttons.              |
  483. -----------------------------------------------------------------------------*/
  484.    openButton.setBitmap( IC_ID_OPEN );
  485.    helpButton.setBitmap( IC_ID_HELP );
  486.  
  487.  
  488. /*-----------------------------------------------------------------------------
  489. | Add the buttons to the toolbar.                                             |
  490. -----------------------------------------------------------------------------*/
  491.    addAsLast( &openButton );
  492.    addAsLast( &createButton );
  493.    addAsLast( &transferButton );
  494.    addAsLast( &deleteButton );
  495.    addAsLast( &iconButton, true );
  496.    addAsLast( &treeButton );
  497.    addAsLast( &detailsButton );
  498.    addAsLast( &selectAllButton, true );
  499.    addAsLast( &deselectAllButton );
  500.    addAsLast( &sortAscButton, true );
  501.    addAsLast( &sortDescButton );
  502.    addAsLast( &arrangeButton );
  503.    addAsLast( &helpButton, true );
  504.  
  505. /*-----------------------------------------------------------------------------
  506. | Identify the flytext string table offset for the fly-over help              |
  507. | Identify the long string table offset for the fly-over help                 |
  508. | Set the missing text to blank                                               |
  509.  ----------------------------------------------------------------------------*/
  510.    flyHelpHdr.setFlyTextStringTableOffset( ID_PERSONNEL_OFFSET_FLYTEXT );
  511.    flyHelpHdr.setLongStringTableOffset( ID_PERSONNEL_OFFSET_INFOAREA );
  512.    flyHelpHdr.setDefaultText( ID_PERSONNEL_OFFSET_INFOAREA+ID_PERSONNEL );
  513.    flyHelpHdr.handleEventsFor( this );
  514. }
  515.  
  516.  
  517. /******************************************************************************
  518. * Class LPersonnelToolBar :: enableSelects - Enable/disable the selection     *
  519. *   toolbar buttons.                                                          *
  520. ******************************************************************************/
  521. LPersonnelToolBar& LPersonnelToolBar::enableSelects( Boolean which )
  522. {
  523.    selectAllButton.enable( which );
  524.    deselectAllButton.enable( which );
  525.    return *this;
  526. }
  527. #endif
  528.  
  529.  
  530. /******************************************************************************
  531. * Class LPersonnelWindowCommandHandler :: LPersonnelWindowCommandHandler -    *
  532. *  Constructor for handling command events for the frame window               *
  533. ******************************************************************************/
  534. LPersonnelWindowCommandHandler::LPersonnelWindowCommandHandler
  535.                            ( LPersonnelWindow* owner,
  536.                              IHelpWindow* helpWin,
  537.                              LPersonnelCnr* cnrCtl )
  538.      :pOwner( owner ),
  539.       pHelp( helpWin ),
  540.       pCnr( cnrCtl )
  541. {}
  542.  
  543.  
  544. /******************************************************************************
  545. * Class LPersonnelWindowCommandHandler :: ~LPersonnelWindowCommandHandler -   *
  546. *   Destructor                                                                *
  547. ******************************************************************************/
  548. LPersonnelWindowCommandHandler::~LPersonnelWindowCommandHandler()
  549. {}
  550.  
  551.  
  552. /******************************************************************************
  553. * Class LPersonnelWindowCommandHandler :: command() - Handle the command event*
  554. ******************************************************************************/
  555. IBase::Boolean LPersonnelWindowCommandHandler::command( ICommandEvent& evt )
  556. {
  557.    IBase::Boolean
  558.       useObjectCollection = true;
  559.    unsigned long
  560.       cmdId = evt.commandId ();
  561.  
  562. /*-----------------------------------------------------------------------------
  563. | Get the last popup menu object                                              |
  564. | Get a cursor for all the selected items in the cnr                          |
  565.  ----------------------------------------------------------------------------*/
  566.    LPersonnelCnrObject
  567.      *pcurObject = pCnr->lastPopupMenuObject();
  568.    IContainerControl::ObjectCursor
  569.       cnrObjectsSelected( *pCnr, IContainerObject::selected );
  570.  
  571.    cnrObjectsSelected.setToFirst();
  572.    switch( cmdId )
  573.    {
  574. /*-----------------------------------------------------------------------------
  575. | If the object with the last popup menu is not selected,                     |
  576. |  do not use all selected cnr objects.                                       |
  577. | Else fall through to the ID_PERSONNEL_SELECTED_OPEN.                        |
  578. -----------------------------------------------------------------------------*/
  579.       case ID_PERSONNEL_OBJECT_POP_OPEN:
  580.       {
  581.          if ( pcurObject && !pCnr->isSelected( pcurObject ) )
  582.             useObjectCollection = false;
  583.       }
  584.  
  585.       case ID_PERSONNEL_SELECTED_OPEN:
  586.       {
  587.          if ( useObjectCollection )
  588.          {
  589. /*-----------------------------------------------------------------------------
  590. | Open each selected object.                                                  |
  591.  ----------------------------------------------------------------------------*/
  592.             for ( cnrObjectsSelected.setToFirst();
  593.                   cnrObjectsSelected.isValid();
  594.                   cnrObjectsSelected.setToNext() )
  595.             {
  596.                LPersonnelCnrObject
  597.                   *pcurObject = (LPersonnelCnrObject *) cnrObjectsSelected.current();
  598.                if ( pcurObject )
  599.                   openAction( pcurObject );
  600.             }
  601.          }
  602.          else
  603.          {
  604. /*-----------------------------------------------------------------------------
  605. | Open only the current selected object.                                      |
  606. -----------------------------------------------------------------------------*/
  607.             if ( pcurObject )
  608.                openAction( pcurObject );
  609.          }
  610.          break;
  611.       }
  612.  
  613. /*-----------------------------------------------------------------------------
  614. | If the object with the last popup menu and is not selected,                 |
  615. |  do not use all selected cnr objects.                                       |
  616. | Else fall through to the ID_PERSONNEL_SELECTED_DELETE.                      |
  617. -----------------------------------------------------------------------------*/
  618.       case ID_PERSONNEL_OBJECT_POP_CREATE:
  619.       {
  620.          if ( pcurObject && !pCnr->isSelected( pcurObject ) )
  621.             useObjectCollection = false;
  622.       }
  623.  
  624.       case ID_PERSONNEL_SELECTED_CREATE:
  625.       {
  626.          if ( useObjectCollection )
  627.          {
  628. /*-----------------------------------------------------------------------------
  629. | Create each selected object.                                                |
  630.  ----------------------------------------------------------------------------*/
  631.             for ( cnrObjectsSelected.setToFirst();
  632.                   cnrObjectsSelected.isValid();
  633.                  cnrObjectsSelected.setToNext() )
  634.             {
  635.                LPersonnelCnrObject
  636.                  *pcurObject = (LPersonnelCnrObject *) cnrObjectsSelected.current();
  637.                if ( pcurObject )
  638.                   createAction( pcurObject );
  639.             }
  640.          }
  641.          else
  642.          {
  643. /*-----------------------------------------------------------------------------
  644. | Create only the current selected object.                                    |
  645. -----------------------------------------------------------------------------*/
  646.             if ( pcurObject )
  647.                createAction( pcurObject );
  648.          }
  649.          break;
  650.       }
  651.  
  652. /*-----------------------------------------------------------------------------
  653. | If the object with the last popup menu and is not selected,                 |
  654. |  do not use all selected cnr objects.                                       |
  655. | Else fall through to the ID_PERSONNEL_SELECTED_TRANSFER.                    |
  656. -----------------------------------------------------------------------------*/
  657.       case ID_PERSONNEL_OBJECT_POP_TRANSFER:
  658.       {
  659.          if ( pcurObject && !pCnr->isSelected( pcurObject ) )
  660.             useObjectCollection = false;
  661.       }
  662.  
  663.       case ID_PERSONNEL_SELECTED_TRANSFER:
  664.       {
  665.          if ( useObjectCollection )
  666.          {
  667. /*-----------------------------------------------------------------------------
  668. | Transfer each selected object.                                              |
  669.  ----------------------------------------------------------------------------*/
  670.             for ( cnrObjectsSelected.setToFirst();
  671.                   cnrObjectsSelected.isValid();
  672.                   cnrObjectsSelected.setToNext() )
  673.             {
  674.                LPersonnelCnrObject
  675.                   *pcurObject = (LPersonnelCnrObject *) cnrObjectsSelected.current();
  676.                if ( pcurObject )
  677.                   transferAction( pcurObject );
  678.             }
  679.          }
  680.          else
  681.          {
  682. /*-----------------------------------------------------------------------------
  683. | Transfer only the current selected object.                                  |
  684. -----------------------------------------------------------------------------*/
  685.             if ( pcurObject )
  686.                transferAction( pcurObject );
  687.          }
  688.          break;
  689.       }
  690.  
  691. /*-----------------------------------------------------------------------------
  692. | If the object with the last popup menu and is not selected,                 |
  693. |  do not use all selected cnr objects.                                       |
  694. | Else fall through to the ID_PERSONNEL_SELECTED_DELETE.                      |
  695. -----------------------------------------------------------------------------*/
  696.       case ID_PERSONNEL_OBJECT_POP_DELETE:
  697.       {
  698.          if ( pcurObject && !pCnr->isSelected( pcurObject ) )
  699.             useObjectCollection = false;
  700.       }
  701.  
  702.       case ID_PERSONNEL_SELECTED_DELETE:
  703.       {
  704.          if ( useObjectCollection )
  705.          {
  706. /*-----------------------------------------------------------------------------
  707. | Delete each selected object.                                                |
  708. -----------------------------------------------------------------------------*/
  709.             do
  710.             {
  711.                LPersonnelCnrObject
  712.                   *pcurObject = (LPersonnelCnrObject *)cnrObjectsSelected.current();
  713.                if ( pcurObject )
  714.                {
  715.                   Boolean
  716.                      wasDeleted = deleteAction( pcurObject );
  717.                   if ( !wasDeleted )
  718.                      pCnr->setSelected( pcurObject, false );
  719.                }
  720.                cnrObjectsSelected.setToFirst();
  721.             }
  722.             while ( cnrObjectsSelected.isValid() );
  723.  
  724.          }
  725.          else
  726.          {
  727. /*-----------------------------------------------------------------------------
  728. | Delete only the current selected object.                                    |
  729. -----------------------------------------------------------------------------*/
  730.             if ( pcurObject )
  731.                deleteAction( pcurObject );
  732.          }
  733.          break;
  734.       }
  735.  
  736. /*-----------------------------------------------------------------------------
  737. | Show the cnr as details view                                                |
  738. -----------------------------------------------------------------------------*/
  739.       case ID_PERSONNEL_VIEW_OPEN_DETAILS:
  740.       {
  741.          pCnr->showDetailsView();
  742.          pOwner->enableSelects();
  743.          break;
  744.       }
  745.  
  746. /*-----------------------------------------------------------------------------
  747. | Show the cnr as tree view                                                   |
  748. -----------------------------------------------------------------------------*/
  749.       case ID_PERSONNEL_VIEW_OPEN_TREE:
  750.       {
  751.          pCnr->showTreeIconView();
  752.          pOwner->enableSelects( false );
  753.          break;
  754.       }
  755.  
  756. /*-----------------------------------------------------------------------------
  757. | Show the cnr as icon view                                                   |
  758. -----------------------------------------------------------------------------*/
  759.       case ID_PERSONNEL_VIEW_OPEN_ICON:
  760.       {
  761.          pCnr->showIconView();
  762.          pOwner->enableSelects();
  763.          break;
  764.       }
  765.  
  766. /*-----------------------------------------------------------------------------
  767. | Select all cnr objects by selecting each cnr object                         |
  768. -----------------------------------------------------------------------------*/
  769.       case ID_PERSONNEL_VIEW_SELECT_ALL:
  770.       {
  771.          IContainerControl::ObjectCursor
  772.             objCursor( *pCnr );
  773.          for ( objCursor.setToFirst();
  774.                objCursor.isValid();
  775.                objCursor.setToNext() )
  776.          {
  777.             pCnr->setSelected( objCursor.current() );
  778.          }
  779.          break;
  780.       }
  781.  
  782. /*-----------------------------------------------------------------------------
  783. | Select all cnr objects by deselecting each cnr object                       |
  784. -----------------------------------------------------------------------------*/
  785.       case ID_PERSONNEL_VIEW_SELECT_DE:
  786.       {
  787.          IContainerControl::ObjectCursor
  788.             objCursor( *pCnr );
  789.          for ( objCursor.setToFirst();
  790.                objCursor.isValid();
  791.                objCursor.setToNext() )
  792.          {
  793.             pCnr->setSelected( objCursor.current(), false );
  794.          }
  795.          break;
  796.       }
  797.  
  798. /*-----------------------------------------------------------------------------
  799. | Arrange the cnr objects for icon view                                       |
  800. -----------------------------------------------------------------------------*/
  801.       case ID_PERSONNEL_VIEW_ARRANGE:
  802.       {
  803.          pCnr->arrangeIconView();
  804.          break;
  805.       }
  806.  
  807. /*-----------------------------------------------------------------------------
  808. | Sort the cnr objects ascending by their icon text                           |
  809. -----------------------------------------------------------------------------*/
  810.       case ID_PERSONNEL_VIEW_SORT_ASC:
  811.       {
  812.          pCnr->sortByIconText();
  813.          pCnr->arrangeIconView();
  814.          break;
  815.       }
  816.  
  817. /*-----------------------------------------------------------------------------
  818. | Sort the cnr objects descending by their icon text                          |
  819. -----------------------------------------------------------------------------*/
  820.       case ID_PERSONNEL_VIEW_SORT_DESC:
  821.       {
  822.          pCnr->sortByIconText( false );
  823.          pCnr->arrangeIconView();
  824.          break;
  825.       }
  826.  
  827. /*-----------------------------------------------------------------------------
  828. | Show help index                                                             |
  829. -----------------------------------------------------------------------------*/
  830.       case ID_PERSONNEL_HELP_INDEX:
  831.       {
  832.          pHelp->show( IHelpWindow::index );
  833.          break;
  834.       }
  835.  
  836. /*-----------------------------------------------------------------------------
  837. | Show general help                                                           |
  838. -----------------------------------------------------------------------------*/
  839.       case ID_PERSONNEL_HELP_GENERAL:
  840.       {
  841.          pHelp->show( IHelpWindow::general );
  842.          break;
  843.       }
  844.  
  845. /*-----------------------------------------------------------------------------
  846. | Show using help                                                             |
  847. -----------------------------------------------------------------------------*/
  848.       case ID_PERSONNEL_HELP_USING:
  849.       {
  850.          pHelp->show( IHelpWindow::using );
  851.          break;
  852.       }
  853.  
  854. /*-----------------------------------------------------------------------------
  855. | Show product information                                                    |
  856. -----------------------------------------------------------------------------*/
  857.       case ID_PERSONNEL_HELP_PRODUCT:
  858.       {
  859.          IMessageBox
  860.             productBox( pOwner );
  861.          productBox.show( STR_ABOUT_MSG,
  862.                           IMessageBox::informationIcon );
  863.         break;
  864.       }
  865.  
  866. /*-----------------------------------------------------------------------------
  867. | Close the frame window                                                      |
  868. -----------------------------------------------------------------------------*/
  869.       case ID_PERSONNEL_VIEW_CLOSE:
  870.       {
  871.          pOwner->close();
  872.          break;
  873.       }
  874.  
  875.       default:
  876.       {
  877.          return false;
  878.       }
  879.     }
  880.  
  881.     return true;
  882. }
  883.  
  884.  
  885. /******************************************************************************
  886. * Class LPersonnelWindowCommandHandler :: openAction() - Open the person.     *
  887. ******************************************************************************/
  888. LPersonnelWindowCommandHandler& LPersonnelWindowCommandHandler::openAction
  889.                            ( LPersonnelCnrObject* pObject )
  890. {
  891. /*-----------------------------------------------------------------------------
  892. | Get the employee's record                                                   |
  893. | Set the object as open                                                      |
  894. | Show an information window for the employee                                 |
  895. -----------------------------------------------------------------------------*/
  896.    LEmployeeData
  897.       tempData( pObject->employeeRecord() );
  898.    pObject->setOpen();
  899.    LInfoWindow
  900.      *pEmployeeWindow = new LInfoWindow( ID_INFO_WINDOW, 0, pOwner,
  901.                                          IPoint( 100, 100 ),
  902.                                          pObject,
  903.                                          tempData,
  904.                                          false );
  905.    pEmployeeWindow->setAutoDeleteObject( true );
  906.  
  907.    return *this;
  908. }
  909.  
  910.  
  911. /******************************************************************************
  912. * Class LPersonnelWindowCommandHandler :: createAction() - Create a person.   *
  913. ******************************************************************************/
  914. LPersonnelWindowCommandHandler& LPersonnelWindowCommandHandler::createAction
  915.                            ( LPersonnelCnrObject* pObject )
  916. {
  917. /*-----------------------------------------------------------------------------
  918. | Start an information window for the new employee                            |
  919. -----------------------------------------------------------------------------*/
  920.    LEmployeeData
  921.       tempData( "" );
  922.    LInfoWindow
  923.      *pEmployeeWindow = new LInfoWindow( ID_INFO_WINDOW, 0, pOwner,
  924.                                          IPoint( 100, 100 ),
  925.                                          pObject,
  926.                                          tempData,
  927.                                          false );
  928.    pEmployeeWindow->setAutoDeleteObject( true );
  929.  
  930.    return *this;
  931. }
  932.  
  933.  
  934. /******************************************************************************
  935. * Class LPersonnelWindowCommandHandler :: transferAction() - Transfer a       *
  936. *   person.                                                                   *
  937. ******************************************************************************/
  938. LPersonnelWindowCommandHandler& LPersonnelWindowCommandHandler::transferAction
  939.                            ( LPersonnelCnrObject* pObject )
  940. {
  941. /*-----------------------------------------------------------------------------
  942. | Get the employee's record                                                   |
  943. -----------------------------------------------------------------------------*/
  944.    LEmployeeData
  945.       empData = pObject->employeeRecord();
  946.    IString
  947.       person = IString("'") + empData.firstName() + " " +
  948.                empData.lastName() + "'";
  949.    IString
  950.       curDept = IString("'") + empData.department() + "'";
  951.  
  952. /*-----------------------------------------------------------------------------
  953. | Ask the user for the new department name                                    |
  954. -----------------------------------------------------------------------------*/
  955.    LAskUser
  956.       askUser( ID_ASKUSER, IWindow::desktopWindow(), pOwner,
  957.                IApplication::current().userResourceLibrary().
  958.                loadString( STR_TRANSFER_MSG1 ) + person,
  959.                IApplication::current().userResourceLibrary().
  960.                loadString( STR_TRANSFER_MSG2 ) +
  961.                curDept + ".",
  962.                IApplication::current().userResourceLibrary().
  963.                loadString( STR_TRANSFER_MSG3 ) );
  964.  
  965.  
  966. /*-----------------------------------------------------------------------------
  967. | If the user pressed OK                                                      |
  968. | - Get the text the user specified in the dialog                             |
  969. | - Change the employee's department to the user specified text               |
  970. | - Put the change to the database                                            |
  971. -----------------------------------------------------------------------------*/
  972.    if ( askUser.pressedOk() )
  973.    {
  974.       IString
  975.          newDept = askUser.text();
  976.       if ( newDept.length() )
  977.       {
  978.          empData.setDepartment( newDept );
  979.          empData.save( empData.employeeNumber() );
  980.          curDept = IString("'") + newDept + "'";
  981.  
  982.          IMessageBox
  983.             msg( pOwner );
  984.           msg.show( person + IApplication::current().userResourceLibrary().
  985.                     loadString( STR_TRANSFER_MSG4 ) +
  986.                     curDept + ".",
  987.                     IMessageBox::informationIcon );
  988.       }
  989.    }
  990.  
  991.    return *this;
  992. }
  993.  
  994.  
  995. /******************************************************************************
  996. * Class LPersonnelWindowCommandHandler :: deleteAction() - Fire a person!     *
  997. ******************************************************************************/
  998. IBase::Boolean LPersonnelWindowCommandHandler::deleteAction
  999.                            ( LPersonnelCnrObject* pObject )
  1000. {
  1001.    Boolean
  1002.       retCode = false;
  1003.  
  1004. /*-----------------------------------------------------------------------------
  1005. | Ask if the user really wants to delete or just set to inactive.             |
  1006. -----------------------------------------------------------------------------*/
  1007.    IMessageBox
  1008.       msgBox( pOwner );
  1009.    IMessageBox::Response
  1010.       response = msgBox.show( IResourceId( STR_PERSONNEL_DELETE_MSG ),
  1011.                               IMessageBox::warningIcon |
  1012.                               IMessageBox::yesNoCancelButton,
  1013.                               ID_PERSONNEL_DELETE_HELP );
  1014.  
  1015. /*-----------------------------------------------------------------------------
  1016. | Get the employee's record                                                   |
  1017. -----------------------------------------------------------------------------*/
  1018.    LEmployeeData
  1019.       empData = pObject->employeeRecord();
  1020.    IString
  1021.       person = empData.firstName() + " " +
  1022.                empData.lastName();
  1023.  
  1024. /*-----------------------------------------------------------------------------
  1025. | Delete the employee                                                         |
  1026. | - Delete the employee from the database                                     |
  1027. | - Delete the cnr object                                                     |
  1028. -----------------------------------------------------------------------------*/
  1029.    if ( response == IMessageBox::no )
  1030.    {
  1031.       LDeleteEmployee
  1032.          deleteEmp;
  1033.       deleteEmp.deleteFromDataBase( empData.employeeNumber() );
  1034.       delete pObject;
  1035.       msgBox.show( STR_PERSONNEL_DELETED_MSG,
  1036.                    IMessageBox::okButton |
  1037.                    IMessageBox::informationIcon );
  1038.       retCode = true;
  1039.    }
  1040.  
  1041. /*-----------------------------------------------------------------------------
  1042. | Set the employee to inactive                                                |
  1043. | - Get the employee's status data                                            |
  1044. | - Put the status data back with active set to false                         |
  1045. -----------------------------------------------------------------------------*/
  1046.    else if ( response == IMessageBox::yes )
  1047.    {
  1048.       LStatusData
  1049.          statData( empData.employeeNumber() );
  1050.       statData.save( empData.employeeNumber(),
  1051.                      statData.statusRate(),
  1052.                      statData.statusStart(),
  1053.                      statData.statusEnd(),
  1054.                      false );
  1055.       msgBox.show( STR_PERSONNEL_INACTIVE_MSG,
  1056.                    IMessageBox::okButton
  1057.                    | IMessageBox::informationIcon );
  1058.       retCode = false;
  1059.    }
  1060.  
  1061.    return retCode;
  1062. }
  1063.  
  1064.  
  1065. /******************************************************************************
  1066. * Class LPersonnelWindowHelpHandler :: LPersonnelWindowHelpHandler -          *
  1067. *   Constructor for handling help events.                                     *
  1068. ******************************************************************************/
  1069. LPersonnelWindowHelpHandler::LPersonnelWindowHelpHandler()
  1070. {}
  1071.  
  1072.  
  1073. /******************************************************************************
  1074. * Class LPersonnelWindowHelpHandler :: ~LPersonnelWindowHelpHandler -         *
  1075. *   Destructor                                                                *
  1076. ******************************************************************************/
  1077. LPersonnelWindowHelpHandler::~LPersonnelWindowHelpHandler()
  1078. {}
  1079.  
  1080.  
  1081. /******************************************************************************
  1082. * Class LPersonnelHelpWindowHelpHandler :: keysHelpId()                       *
  1083. *   Handle the keys help request event.                                       *
  1084. *   This overrides the default provided by library.                           *
  1085. ******************************************************************************/
  1086. IBase::Boolean LPersonnelWindowHelpHandler::keysHelpId( IEvent& evt )
  1087. {
  1088.    evt.setResult( ID_PERSONNEL_HELP_KEYS_PANEL);
  1089.    return true;
  1090. }
  1091.