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