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

  1. /******************************************************************************
  2. * FILE NAME: lmainwin.cpp                                                     *
  3. *                                                                             *
  4. * Classes:                                                                    *
  5. *   LMainWindow                                                               *
  6. *   LMainCnr                                                                  *
  7. *   LMainCnrObject                                                            *
  8. *   LMainWindowCommandHandler                                                 *
  9. *   LMainWindowHelpHandler                                                    *
  10. *                                                                             *
  11. * COPYRIGHT:                                                                  *
  12. *   Licensed Materials - Property of IBM                                      *
  13. *   (C) Copyright IBM Corporation 1992, 1995                                  *
  14. *   All Rights Reserved                                                       *
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  17. ******************************************************************************/
  18.  
  19. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  20.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  21. #endif                                  //  is defined.
  22. #include "lmainwin.hpp"
  23. #include "lgoodies.hpp"
  24.  
  25. /******************************************************************************
  26. * Class LMainWindow :: LMainWindow - Constructor for the main window          *
  27. *                                                                             *
  28. * Define yourself as an IFrameWindow                                          *
  29. * Create title                                                                *
  30. * Create menubar                                                              *
  31. * Create information area                                                     *
  32. * Create container                                                            *
  33. * Create toolbar (PM only)                                                    *
  34. * Create help window                                                          *
  35. * Create command handler                                                      *
  36. * Create help handler                                                         *
  37. ******************************************************************************/
  38. LMainWindow::LMainWindow()
  39.      :IFrameWindow         ( ID_MAIN ),
  40.       title                ( this, STR_MAIN_TITLE, STR_MAIN_TITLE2 ),
  41.       menubar              ( ID_MAIN, this ),
  42.       infoarea             ( this ),
  43.       cnr                  ( ID_MAIN_CNR, this, this ),
  44. #ifdef IC_PM
  45.       toolbar              ( ID_MAIN_TOOLBAR, this, &infoarea ),
  46. #endif
  47.       help                 ( ID_HELP_TABLE, this ),
  48.       cmdHdr               ( this, &help, &cnr ),
  49.       helpHdr              (),
  50.       aSelects             ( true )
  51.  
  52. {
  53.  
  54. /*-----------------------------------------------------------------------------
  55. | Attempt to load the help file                                               |
  56. -----------------------------------------------------------------------------*/
  57.    try
  58.    {
  59.       help.addLibraries( "lanchelp.hlp" );
  60.       help.setTitle( STR_HELP_TITLE );
  61.    }
  62.    catch( ... )
  63.    {
  64.       IMessageBox
  65.          msgBox( this );
  66.       msgBox.show( STR_HELP_NOT_FOUND, IMessageBox::warning );
  67.    }
  68.  
  69. /*-----------------------------------------------------------------------------
  70. | Handle command events for this frame window                                 |
  71. | Handle help events for this frame window                                    |
  72.  ----------------------------------------------------------------------------*/
  73.    cmdHdr.handleEventsFor( this );
  74.    helpHdr.handleEventsFor( this );
  75.  
  76. /*-----------------------------------------------------------------------------
  77. | Set the application icon                                                    |
  78. | Set the client to be the container                                          |
  79. | Identify the offset for the infoarea strings                                |
  80. | Set the inactive text for the infoarea                                      |
  81. | Set the application's focus and show it                                     |
  82.  ----------------------------------------------------------------------------*/
  83.    setIcon( ID_MAIN );
  84.    setClient( &cnr );
  85.    infoarea.setStringTableOffset( ID_MAIN_OFFSET_INFOAREA );
  86.    infoarea.setInactiveText( ID_MAIN_OFFSET_INFOAREA+ID_MAIN );
  87.  
  88. /*-----------------------------------------------------------------------------
  89. | Resize the frame window based on the minimum width of the toolbar           |
  90. -----------------------------------------------------------------------------*/
  91.    IRectangle
  92.       clientRect = clientRectFor( rect() );
  93. #ifdef IC_PM
  94.    moveSizeToClient( IRectangle( clientRect.bottomLeft(),
  95.                      IPoint( clientRect.left() + toolbar.minimumSize().width(),
  96.                      clientRect.top() ) ) );
  97. #endif
  98.  
  99. /*-----------------------------------------------------------------------------
  100. | Move the frame window to the best location for the display size             |
  101. | Set the application's focus and show it                                     |
  102.  ----------------------------------------------------------------------------*/
  103.    IPoint
  104.       newLocation( LFrameWindow::bestFit( this ) );
  105.    moveTo( newLocation );
  106.    if ( ( ! newLocation.x() ) || ( ! newLocation.y() )  )
  107.       maximize();
  108.    setFocus().show();
  109. }
  110.  
  111.  
  112. /******************************************************************************
  113. * Class LMainWindow :: ~LMainWindow - Destructor for the main window          *
  114. ******************************************************************************/
  115. LMainWindow::~LMainWindow()
  116. {
  117. /*-----------------------------------------------------------------------------
  118. | Stop handling events.                                                       |
  119. -----------------------------------------------------------------------------*/
  120.    cmdHdr.stopHandlingEventsFor( this );
  121.    helpHdr.stopHandlingEventsFor( this );
  122. }
  123.  
  124.  
  125. /******************************************************************************
  126. * Class LMainWindow :: enableSelects - Enable/disable the selection           *
  127. *   menu items.                                                               *
  128. ******************************************************************************/
  129. LMainWindow& LMainWindow::enableSelects( Boolean which )
  130. {
  131.    menubar.enableItem( ID_MAIN_VIEW_SELECT, which );
  132. #ifdef IC_PM
  133.    toolbar.enableSelects( which );
  134. #endif
  135.    aSelects = which;
  136.    return *this;
  137. }
  138.  
  139.  
  140. /******************************************************************************
  141. * Class LMainCnr :: LMainCnr - Constructor for the main container.            *
  142. *                                                                             *
  143. * Create yourself as an IContainerControl                                     *
  144. * Create the container columns.                                               *
  145. * Define a help window as NULL.                                               *
  146. * Define a poup menu as NULL.                                                 *
  147. * Define the last popup menu object as NULL.                                  *
  148. * Set the object count to 0.                                                  *
  149. ******************************************************************************/
  150. LMainCnr::LMainCnr( unsigned long id, LMainWindow* parent,
  151.                     LMainWindow* owner, IRectangle location )
  152.      :IContainerControl    ( id, parent, owner, location,
  153.                              IContainerControl::extendedSelection ),
  154.       colIcon              ( IContainerColumn::isIcon ),
  155.       colIconText          ( IContainerColumn::isIconViewText ),
  156.       colDesc              ( LMainCnrObject::descOffset() ),
  157.       helpWin              ( NULL ),
  158.       popm                 ( NULL ),
  159.       ptheLastPopupMenuObject ( NULL ),
  160.       objCount             ( 0 )
  161. {
  162. /*-----------------------------------------------------------------------------
  163. | Start handling container events for the container                           |
  164. | Start handling container menu events for the container                      |
  165. -----------------------------------------------------------------------------*/
  166.    ICnrHandler::handleEventsFor( this );
  167.    ICnrMenuHandler::handleEventsFor( this );
  168.  
  169. /*-----------------------------------------------------------------------------
  170. | Populate the container with objects                                         |
  171. -----------------------------------------------------------------------------*/
  172.    populate();
  173.  
  174. /*-----------------------------------------------------------------------------
  175. | Add the cnr columns to the cnr                                              |
  176. -----------------------------------------------------------------------------*/
  177.    addColumn( &colIcon );
  178.    addColumn( &colIconText );
  179.    addColumn( &colDesc );
  180.  
  181. /*-----------------------------------------------------------------------------
  182. | Set the cnr column headings                                                 |
  183. -----------------------------------------------------------------------------*/
  184.    colIconText.setHeadingText( STR_TITLE );
  185.    colDesc.setHeadingText( STR_DESC );
  186.  
  187. /*-----------------------------------------------------------------------------
  188. | Delete cnr objects on closing of the container                              |
  189. -----------------------------------------------------------------------------*/
  190.    setDeleteObjectsOnClose();
  191.  
  192. /*-----------------------------------------------------------------------------
  193. | Regardless of the font size, display the same number of characters          |
  194. |  for the icon text in details view                                          |
  195. -----------------------------------------------------------------------------*/
  196.    IFont
  197.       cnrFont( this );
  198.    setDetailsViewSplit( &colIconText,
  199.                         iconSize().width() +
  200.                         cnrFont.avgCharWidth() * ID_MAIN_CNR_TITLE_WIDTH );
  201.  
  202. /*-----------------------------------------------------------------------------
  203. | Arrange the icons                                                           |
  204. | Show the cnr title and show it                                              |
  205. -----------------------------------------------------------------------------*/
  206.    arrangeIconView();
  207.    showTitle();
  208.    show();
  209. }
  210.  
  211.  
  212. /******************************************************************************
  213. * Class LMainCnr :: ~LMainCnr - Destructor                                    *
  214. ******************************************************************************/
  215. LMainCnr::~LMainCnr()
  216. {
  217. /*-----------------------------------------------------------------------------
  218. | Delete the help window.                                                     |
  219. -----------------------------------------------------------------------------*/
  220.    delete helpWin;
  221. }
  222.  
  223.  
  224. /******************************************************************************
  225. * Class LMainCnr :: populate() - Populate with container objects.             *
  226. ******************************************************************************/
  227. LMainCnr& LMainCnr::populate()
  228. {
  229. /*-----------------------------------------------------------------------------
  230. | Hide the cnr until we're finished deleting and adding all cnr objects       |
  231. -----------------------------------------------------------------------------*/
  232.    hide();
  233.    deleteAllObjects();
  234.    objCount = 0;
  235.  
  236. /*-----------------------------------------------------------------------------
  237. | Add the "Query Personnel" cnr object                                        |
  238. -----------------------------------------------------------------------------*/
  239.    pCnrObject[ ID_MAIN_CNROBJECT + ++objCount ] =
  240.       new LMainCnrObject( ID_ICON_QUERY,
  241.                           IResourceId( STR_QUERY_PERSONNEL_OBJECT ),
  242.                           LMainCnrObject::personnel,
  243.                           IResourceId( STR_QUERY_PERSONNEL_DESC ) );
  244.    addObject( pCnrObject[ ID_MAIN_CNROBJECT + objCount ] );
  245.  
  246. /*-----------------------------------------------------------------------------
  247. | If there is saved query data,                                               |
  248. | - Iterate each saved query and create a cnr object                          |
  249. -----------------------------------------------------------------------------*/
  250.    QueryQry
  251.       qdata;
  252.    for ( qdata.setFirstId();
  253.          qdata.isValid();
  254.          qdata.setNextId() )
  255.    {
  256.       pCnrObject[ ID_MAIN_CNROBJECT + ++objCount ] =
  257.          new LMainCnrObject( ID_ICON_QUERY2, qdata.getQry(),
  258.                              LMainCnrObject::query,
  259.                              IResourceId( STR_CUSTOM_QUERY_DESC ) );
  260.       addObject( pCnrObject[ ID_MAIN_CNROBJECT + objCount ] );
  261.    }
  262.  
  263. /*-----------------------------------------------------------------------------
  264. | Arrange the icons                                                           |
  265. | Reshow it                                                                   |
  266. -----------------------------------------------------------------------------*/
  267.    arrangeIconView();
  268.    show();
  269.  
  270.    return *this;
  271. }
  272.  
  273.  
  274. /******************************************************************************
  275. * Class LMainCnr :: addLastQuery() - Add saved query to container.            *
  276. ******************************************************************************/
  277. LMainCnr& LMainCnr::addLastQuery( IString queryName )
  278. {
  279. /*-----------------------------------------------------------------------------
  280. | Add new query to container                                                  |
  281. -----------------------------------------------------------------------------*/
  282.    pCnrObject[ ID_MAIN_CNROBJECT + ++objCount ] =
  283.       new LMainCnrObject( ID_ICON_QUERY2, queryName,
  284.                           LMainCnrObject::query,
  285.                           IResourceId( STR_CUSTOM_QUERY_DESC ) );
  286.    addObject( pCnrObject[ ID_MAIN_CNROBJECT + objCount ] );
  287.  
  288. /*-----------------------------------------------------------------------------
  289. | Arrange the icons                                                           |
  290. -----------------------------------------------------------------------------*/
  291.    arrangeIconView();
  292.  
  293.    return *this;
  294. }
  295.  
  296.  
  297. /******************************************************************************
  298. * Class LMainCnr :: makePopUpMenu()                                           *
  299. *   Create popup menus based on the type of the cnr object                    *
  300. ******************************************************************************/
  301. IBase::Boolean LMainCnr::makePopUpMenu( IMenuEvent& evt )
  302. {
  303.    Boolean
  304.       retCode = true,
  305.       hasSelectItem = true;
  306.    unsigned long
  307.       whichMenu = 0;
  308. /*-----------------------------------------------------------------------------
  309. | Get the object with the last popup menu                                     |
  310. -----------------------------------------------------------------------------*/
  311.    LMainCnrObject
  312.      *pcnrObject = (LMainCnrObject*)popupMenuObject();
  313.    if ( pcnrObject )
  314.       switch( pcnrObject->type() )
  315.       {
  316.          case LMainCnrObject::personnel :
  317.          {
  318.             whichMenu = ID_MAIN_FUNC_POP;
  319.             hasSelectItem = false;
  320.             break;
  321.          }
  322.  
  323.          case LMainCnrObject::query :
  324.          {
  325.             whichMenu = ID_MAIN_QUERY_POP;
  326.             hasSelectItem = false;
  327.             break;
  328.          }
  329.       }
  330.    else
  331.       whichMenu = ID_MAIN_POP;
  332.  
  333.    if ( whichMenu )
  334.    {
  335. /*-----------------------------------------------------------------------------
  336. | Create a popup menu based on the object's type                              |
  337. | Disable the select menu item if it exists for this menu.                    |
  338. | Automatically delete the popup menu when no longer needed                   |
  339. | Set the last popup menu object to be this cnr object                        |
  340. | Show the popup menu at the mouse position                                   |
  341. -----------------------------------------------------------------------------*/
  342.       popm =
  343.          new IPopUpMenu ( whichMenu, owner() );
  344.       if ( hasSelectItem &&
  345.            !((LMainWindow*)owner())->selectsAllowed() )
  346.          popm->enableItem( ID_MAIN_VIEW_SELECT, false );
  347.       popm->setAutoDeleteObject();
  348.       ptheLastPopupMenuObject = (LMainCnrObject*) popupMenuObject();
  349.       popm->show( evt.mousePosition() );
  350.    }
  351.    return retCode;
  352. }
  353.  
  354.  
  355. /******************************************************************************
  356. * Class LMainCnr :: enter() - Process the enter key on a container object.    *
  357. ******************************************************************************/
  358. IBase::Boolean LMainCnr::enter( ICnrEnterEvent& evt )
  359. {
  360.    Boolean
  361.       retCode = false;
  362.  
  363. /*-----------------------------------------------------------------------------
  364. | If the user pressed enter on a cnr object, send an open message             |
  365. -----------------------------------------------------------------------------*/
  366.    if ( evt.validObject() )
  367.    {
  368.       setLastPopupMenuObject( (LMainCnrObject*) evt.object() );
  369.       postEvent( IWindow::command, ID_MAIN_SELECTED_OPEN );
  370.       retCode = true;
  371.    }
  372.  
  373.    return retCode;
  374. }
  375.  
  376.  
  377. /******************************************************************************
  378. * Class LMainCnr :: help() - Process the help key over a container.           *
  379. ******************************************************************************/
  380. IBase::Boolean LMainCnr::help( ICnrHelpEvent& evt )
  381. {
  382.    delete helpWin;
  383.    helpWin = IHelpWindow::helpWindow( this );
  384.    if ( helpWin )
  385.       helpWin->show( IResourceId( ID_MAIN ) );
  386.    return true;
  387. }
  388.  
  389.  
  390. /******************************************************************************
  391. * Class LMainCnrObject :: LMainCnrObject - Constructor for container object   *
  392. *   given another cnr object                                                  *
  393. ******************************************************************************/
  394. LMainCnrObject::LMainCnrObject( const LMainCnrObject& cnrobj )
  395.      :LCnrObject           ( (const LCnrObject&) cnrobj ),
  396.       theType              ( cnrobj.type() ),
  397.       theDesc              ( cnrobj.description() )
  398. {}
  399.  
  400.  
  401. /******************************************************************************
  402. * Class LMainCnrObject :: LMainCnrObject - Constructor for container object   *
  403. *   given a string title and string description                               *
  404. ******************************************************************************/
  405. LMainCnrObject::LMainCnrObject( unsigned long icon, IString title,
  406.                                 ObjectType type, IString description )
  407.      :LCnrObject( title, icon ),
  408.       theType( type ),
  409.       theDesc( description )
  410. {}
  411.  
  412.  
  413. /******************************************************************************
  414. * Class LMainCnrObject :: LMainCnrObject - Constructor for container object   *
  415. *   given a resource id title and resource id description                     *
  416. ****************************************************************************/
  417. LMainCnrObject::LMainCnrObject( unsigned long icon, IResourceId title,
  418.                                 ObjectType type, IResourceId description )
  419.      :LCnrObject( title, icon ),
  420.       theType( type ),
  421.       theDesc( IApplication::current().userResourceLibrary().
  422.                loadString( description.id() ) )
  423. {}
  424.  
  425.  
  426. /******************************************************************************
  427. * Class LMainCnrObject :: LMainCnrObject - Constructor for container object   *
  428. *   given a string title and resource id description                          *
  429. ******************************************************************************/
  430. LMainCnrObject::LMainCnrObject( unsigned long icon, IString title,
  431.                                 ObjectType type, IResourceId description )
  432.      :LCnrObject( title, icon ),
  433.       theType( type ),
  434.       theDesc( IApplication::current().userResourceLibrary().
  435.                loadString( description.id() ) )
  436. {}
  437.  
  438.  
  439. /******************************************************************************
  440. * Class LMainCnrObject :: ~LMainCnrObject - Destructor                        *
  441. ******************************************************************************/
  442. LMainCnrObject::~LMainCnrObject()
  443. {}
  444.  
  445.  
  446. #ifdef IC_PM
  447. /******************************************************************************
  448. * Class LMainToolBar :: LMainToolBar - Constructor for toolbar                *
  449. *   given a resource id                                                       *
  450. ******************************************************************************/
  451. LMainToolBar::LMainToolBar( unsigned long id, IFrameWindow* owner,
  452.                             ITextControl* infoarea )
  453.      :IToolBar             ( id, owner, IToolBar::aboveClient, false,
  454.                              IToolBar::classDefaultStyle
  455.                              & ~IToolBar::buttonBitmapVisible
  456.                              | IToolBar::buttonBitmapAndTextVisible ),
  457.       openButton           ( ID_MAIN_SELECTED_OPEN, this, this ),
  458.       helpButton           ( ID_MAIN_HELP_INDEX, this, this ),
  459.       deleteButton         ( ID_MAIN_SELECTED_DELETE, this, this ),
  460.       iconButton           ( ID_MAIN_VIEW_OPEN_ICON, this, this ),
  461.       treeButton           ( ID_MAIN_VIEW_OPEN_TREE, this, this ),
  462.       detailsButton        ( ID_MAIN_VIEW_OPEN_DETAILS, this, this ),
  463.       selectAllButton      ( ID_MAIN_VIEW_SELECT_ALL, this, this ),
  464.       deselectAllButton    ( ID_MAIN_VIEW_SELECT_DE, this, this ),
  465.       sortAscButton        ( ID_MAIN_VIEW_SORT_ASC, this, this ),
  466.       sortDescButton       ( ID_MAIN_VIEW_SORT_DESC, this, this ),
  467.       arrangeButton        ( ID_MAIN_VIEW_ARRANGE, this, this ),
  468.       flyText              ( ID_MAIN_FLYTEXT, this ),
  469.       flyHelpHdr           ( &flyText, infoarea, 0, 0 )
  470. {
  471. /*-----------------------------------------------------------------------------
  472. | For these buttons, use the standard bitmaps for these buttons.              |
  473. -----------------------------------------------------------------------------*/
  474.    openButton.setBitmap( IC_ID_OPEN );
  475.    helpButton.setBitmap( IC_ID_HELP );
  476.  
  477. /*-----------------------------------------------------------------------------
  478. | Add the buttons to the toolbar.                                             |
  479. -----------------------------------------------------------------------------*/
  480.    addAsLast( &openButton );
  481.    addAsLast( &deleteButton );
  482.    addAsLast( &iconButton, true );
  483.    addAsLast( &treeButton );
  484.    addAsLast( &detailsButton );
  485.    addAsLast( &selectAllButton, true );
  486.    addAsLast( &deselectAllButton );
  487.    addAsLast( &sortAscButton, true );
  488.    addAsLast( &sortDescButton );
  489.    addAsLast( &arrangeButton );
  490.    addAsLast( &helpButton, true );
  491.  
  492. /*-----------------------------------------------------------------------------
  493. | Identify the flytext string table offset for the fly-over help              |
  494. | Identify the long string table offset for the fly-over help                 |
  495. | Set the missing text to blank                                               |
  496.  ----------------------------------------------------------------------------*/
  497.    flyHelpHdr.setFlyTextStringTableOffset( ID_MAIN_OFFSET_FLYTEXT );
  498.    flyHelpHdr.setLongStringTableOffset( ID_MAIN_OFFSET_INFOAREA );
  499.    flyHelpHdr.setDefaultText( ID_MAIN_OFFSET_INFOAREA+ID_MAIN );
  500.    flyHelpHdr.handleEventsFor( this );
  501. }
  502.  
  503. /******************************************************************************
  504. * Class LMainToolBar :: enableSelects - Enable/disable the selection          *
  505. *   toolbar buttons.                                                          *
  506. ******************************************************************************/
  507. LMainToolBar& LMainToolBar::enableSelects( Boolean which )
  508. {
  509.    selectAllButton.enable( which );
  510.    deselectAllButton.enable( which );
  511.    return *this;
  512. }
  513. #endif
  514.  
  515.  
  516. /******************************************************************************
  517. * Class LMainWindowCommandHandler :: LMainWindowCommandHandler - Constructor  *
  518. *  for handling command events for the frame window                           *
  519. ******************************************************************************/
  520. LMainWindowCommandHandler::LMainWindowCommandHandler
  521.                            ( LMainWindow* owner,
  522.                              IHelpWindow* helpWin,
  523.                              LMainCnr* cnrCtl )
  524.      :pOwner( owner ),
  525.       pHelp( helpWin ),
  526.       pCnr( cnrCtl )
  527. {}
  528.  
  529.  
  530. /******************************************************************************
  531. * Class LMainWindowCommandHandler :: ~LMainWindowCommandHandler - Destructor  *
  532. ******************************************************************************/
  533. LMainWindowCommandHandler::~LMainWindowCommandHandler()
  534. {}
  535.  
  536.  
  537. /******************************************************************************
  538. * Class LMainWindowCommandHandler :: command() - Handle the command events    *
  539. ******************************************************************************/
  540. IBase::Boolean LMainWindowCommandHandler::command( ICommandEvent& evt )
  541. {
  542.    IBase::Boolean
  543.       useObjectCollection = true;
  544.    unsigned long
  545.       cmdId = evt.commandId ();
  546.  
  547. /*-----------------------------------------------------------------------------
  548. | Get the last popup menu object                                              |
  549. | Get a cursor for all the selected items in the cnr                          |
  550.  ----------------------------------------------------------------------------*/
  551.    LMainCnrObject
  552.      *pcurObject = pCnr->lastPopupMenuObject();
  553.    IContainerControl::ObjectCursor
  554.       cnrObjectsSelected( *pCnr, IContainerObject::selected );
  555.  
  556.    cnrObjectsSelected.setToFirst();
  557.    switch( cmdId )
  558.    {
  559.       case ID_MAIN_OBJECT_POP_OPEN:
  560.       {
  561. /*-----------------------------------------------------------------------------
  562. | If the object with the last popup menu is not selected,                     |
  563. |  do not use all selected cnr objects.                                       |
  564. | Else fall through to the ID_MAIN_SELECTED_OPEN.                             |
  565. -----------------------------------------------------------------------------*/
  566.          if ( pcurObject && !pCnr->isSelected( pcurObject ) )
  567.             useObjectCollection = false;
  568.       }
  569.  
  570.       case ID_MAIN_SELECTED_OPEN:
  571.       {
  572.          if ( useObjectCollection )
  573.          {
  574. /*-----------------------------------------------------------------------------
  575. | Open each selected object.                                                  |
  576.  ----------------------------------------------------------------------------*/
  577.             for ( cnrObjectsSelected.setToFirst();
  578.                   cnrObjectsSelected.isValid();
  579.                   cnrObjectsSelected.setToNext() )
  580.             {
  581.                LMainCnrObject
  582.                  *pcurObject = (LMainCnrObject *) cnrObjectsSelected.current();
  583.                if ( pcurObject )
  584.                  openAction( pcurObject );
  585.             }
  586.          }
  587.          else
  588.          {
  589. /*-----------------------------------------------------------------------------
  590. | Open only the current selected object.                                      |
  591. -----------------------------------------------------------------------------*/
  592.             if ( pcurObject )
  593.                openAction( pcurObject );
  594.          }
  595.          break;
  596.       }
  597.  
  598.       case ID_MAIN_OBJECT_POP_DELETE:
  599.       {
  600. /*-----------------------------------------------------------------------------
  601. | If the object with the last popup menu and is not selected,                 |
  602. |  do not use all selected cnr objects.                                       |
  603. | Else fall through to the ID_MAIN_SELECTED_DELETE.                           |
  604. -----------------------------------------------------------------------------*/
  605.          if ( pcurObject && !pCnr->isSelected( pcurObject ) )
  606.             useObjectCollection = false;
  607.       }
  608.  
  609.       case ID_MAIN_SELECTED_DELETE:
  610.       {
  611.          if ( useObjectCollection )
  612.          {
  613. /*-----------------------------------------------------------------------------
  614. | Delete each selected object.                                                |
  615. | - Since the selected cnr object cursor becomes invalidated when             |
  616. |   the object is deleted, we must reset the position each time.              |
  617. -----------------------------------------------------------------------------*/
  618.             do
  619.             {
  620.                LMainCnrObject
  621.                  *pcurObject = (LMainCnrObject *) cnrObjectsSelected.current();
  622.                if ( pcurObject )
  623.                {
  624.                   Boolean
  625.                      wasDeleted = deleteAction( pcurObject );
  626.                   if ( !wasDeleted )
  627.                      pCnr->setSelected( pcurObject, false );
  628.                }
  629.                cnrObjectsSelected.setToFirst();
  630.             }
  631.             while ( cnrObjectsSelected.isValid() );
  632.          }
  633.          else
  634.          {
  635. /*-----------------------------------------------------------------------------
  636. | Delete only the current selected object.                                    |
  637. -----------------------------------------------------------------------------*/
  638.             if ( pcurObject )
  639.                deleteAction( pcurObject );
  640.          }
  641.          break;
  642.       }
  643.  
  644. /*-----------------------------------------------------------------------------
  645. | Show the cnr as details view                                                |
  646. -----------------------------------------------------------------------------*/
  647.       case ID_MAIN_VIEW_OPEN_DETAILS:
  648.       {
  649.          pCnr->showDetailsView();
  650.          pOwner->enableSelects();
  651.          break;
  652.       }
  653.  
  654. /*-----------------------------------------------------------------------------
  655. | Show the cnr as icon tree view                                              |
  656. -----------------------------------------------------------------------------*/
  657.       case ID_MAIN_VIEW_OPEN_TREE:
  658.       {
  659.          pCnr->showTreeIconView();
  660.          pOwner->enableSelects( false );
  661.          break;
  662.       }
  663.  
  664. /*-----------------------------------------------------------------------------
  665. | Show the cnr as icon view                                                   |
  666. -----------------------------------------------------------------------------*/
  667.       case ID_MAIN_VIEW_OPEN_ICON:
  668.       {
  669.          pCnr->showIconView();
  670.          pOwner->enableSelects();
  671.          break;
  672.       }
  673.  
  674. /*-----------------------------------------------------------------------------
  675. | Select all cnr objects by selecting each cnr object                         |
  676. -----------------------------------------------------------------------------*/
  677.       case ID_MAIN_VIEW_SELECT_ALL:
  678.       {
  679.          IContainerControl::ObjectCursor
  680.             objCursor( *pCnr );
  681.          for ( objCursor.setToFirst();
  682.                objCursor.isValid();
  683.                objCursor.setToNext() )
  684.          {
  685.             pCnr->setSelected( objCursor.current() );
  686.          }
  687.          break;
  688.       }
  689.  
  690. /*-----------------------------------------------------------------------------
  691. | Deselect all cnr objects by deselecting each cnr object                     |
  692. -----------------------------------------------------------------------------*/
  693.       case ID_MAIN_VIEW_SELECT_DE:
  694.       {
  695.          IContainerControl::ObjectCursor
  696.             objCursor( *pCnr );
  697.          for ( objCursor.setToFirst();
  698.                objCursor.isValid();
  699.                objCursor.setToNext() )
  700.          {
  701.             pCnr->setSelected( objCursor.current(), false );
  702.          }
  703.          break;
  704.       }
  705.  
  706. /*-----------------------------------------------------------------------------
  707. | Arrange the cnr objects for icon view                                       |
  708. -----------------------------------------------------------------------------*/
  709.       case ID_MAIN_VIEW_ARRANGE:
  710.       {
  711.          pCnr->arrangeIconView();
  712.          break;
  713.       }
  714.  
  715. /*-----------------------------------------------------------------------------
  716. | Sort the cnr objects ascending by their icon text                           |
  717. -----------------------------------------------------------------------------*/
  718.       case ID_MAIN_VIEW_SORT_ASC:
  719.       {
  720.          pCnr->sortByIconText();
  721.          pCnr->arrangeIconView();
  722.          break;
  723.       }
  724.  
  725. /*-----------------------------------------------------------------------------
  726. | Sort the cnr objects descending by their icon text                          |
  727. -----------------------------------------------------------------------------*/
  728.       case ID_MAIN_VIEW_SORT_DESC:
  729.       {
  730.          pCnr->sortByIconText( false );
  731.          pCnr->arrangeIconView();
  732.          break;
  733.       }
  734.  
  735. /*-----------------------------------------------------------------------------
  736. | Show index help                                                             |
  737. -----------------------------------------------------------------------------*/
  738.       case ID_MAIN_HELP_INDEX:
  739.       {
  740.          pHelp->show( IHelpWindow::index );
  741.          break;
  742.       }
  743.  
  744. /*-----------------------------------------------------------------------------
  745. | Show general help                                                           |
  746. -----------------------------------------------------------------------------*/
  747.       case ID_MAIN_HELP_GENERAL:
  748.       {
  749.          pHelp->show( IHelpWindow::general );
  750.          break;
  751.       }
  752.  
  753. /*-----------------------------------------------------------------------------
  754. | Show using help                                                             |
  755. -----------------------------------------------------------------------------*/
  756.       case ID_MAIN_HELP_USING:
  757.       {
  758.          pHelp->show( IHelpWindow::using );
  759.          break;
  760.       }
  761.  
  762. /*-----------------------------------------------------------------------------
  763. | Show product information                                                    |
  764. -----------------------------------------------------------------------------*/
  765.       case ID_MAIN_HELP_PRODUCT:
  766.       {
  767.          IMessageBox
  768.             productBox( pOwner );
  769.          productBox.show( STR_ABOUT_MSG,
  770.                           IMessageBox::informationIcon );
  771.          break;
  772.       }
  773.  
  774. /*-----------------------------------------------------------------------------
  775. | Close this application                                                      |
  776. -----------------------------------------------------------------------------*/
  777.       case ID_MAIN_VIEW_CLOSE:
  778.       {
  779.          pOwner->close();
  780.          break;
  781.       }
  782.  
  783.       default:
  784.       {
  785.          return false;
  786.       }
  787.    }
  788.  
  789.    return true;
  790. }
  791.  
  792.  
  793. /******************************************************************************
  794. * Class LMainWindowCommandHandler :: openAction() - Open the object.          *
  795. ******************************************************************************/
  796. LMainWindowCommandHandler& LMainWindowCommandHandler::openAction( LMainCnrObject* pObject )
  797. {
  798.    IMessageBox
  799.       msg( pOwner );
  800.  
  801.    switch( pObject->type() )
  802.    {
  803. /*-----------------------------------------------------------------------------
  804. | If a personnel query, then open an empty information window                 |
  805. -----------------------------------------------------------------------------*/
  806.       case LMainCnrObject::personnel :
  807.       {
  808.          pObject->setOpen();
  809.          LInfoWindow
  810.            *pqueryWindow = new LInfoWindow( ID_INFO_WINDOW, 0, pOwner,
  811.                                             IPoint(100,100),
  812.                                             pCnr,
  813.                                             pObject,
  814.                                             "" );
  815.          pqueryWindow->setAutoDeleteObject( true );
  816.          break;
  817.       }
  818.  
  819. /*-----------------------------------------------------------------------------
  820. | If a custom personnel query, then open an information window given          |
  821. |  the custom search criteria                                                 |
  822. -----------------------------------------------------------------------------*/
  823.       case LMainCnrObject::query :
  824.       {
  825.          pObject->setOpen();
  826.          LInfoWindow
  827.            *pqueryWindow = new LInfoWindow( ID_INFO_WINDOW, 0, pOwner,
  828.                                             IPoint(100,100),
  829.                                             pCnr,
  830.                                             pObject,
  831.                                             pObject->iconText() );
  832.          pqueryWindow->setAutoDeleteObject( true );
  833.          break;
  834.       }
  835.    }
  836.  
  837.    return *this;
  838. }
  839.  
  840.  
  841. /******************************************************************************
  842. * Class LMainWindowCommandHandler :: deleteAction() - Delete the object.      *
  843. ******************************************************************************/
  844. IBase::Boolean LMainWindowCommandHandler::deleteAction( LMainCnrObject* pObject )
  845. {
  846.    Boolean
  847.       retCode = false;
  848.  
  849.    switch( pObject->type() )
  850.    {
  851. /*-----------------------------------------------------------------------------
  852. | If a personnel query, do not allow it to be deleted                         |
  853. -----------------------------------------------------------------------------*/
  854.       case LMainCnrObject::personnel :
  855.       {
  856.          IString
  857.             objectName = IString( "'" ) +
  858.                          pObject->iconText() + "'";
  859.          IMessageBox
  860.             msg( pOwner );
  861.          msg.show( IApplication::current().userResourceLibrary().
  862.                    loadString( STR_MAIN_DELETE_MSG1 ) +
  863.                    objectName +
  864.                    IApplication::current().userResourceLibrary().
  865.                    loadString( STR_MAIN_DELETE_MSG2 ),
  866.                    IMessageBox::catastrophic );
  867.          retCode = false;
  868.          break;
  869.       }
  870.  
  871. /*-----------------------------------------------------------------------------
  872. | If a customer personnel query,                                              |
  873. | - delete the query from the database                                        |
  874. | - delete the object from the cnr                                            |
  875. -----------------------------------------------------------------------------*/
  876.       case LMainCnrObject::query :
  877.       {
  878.          LQueryData
  879.             queryData;
  880.          IString
  881.             queryName = pObject->iconText();
  882.          queryData.deleteItem( queryName );
  883.          delete pObject;
  884.          retCode = true;
  885.          break;
  886.       }
  887.    }
  888.  
  889.    return retCode;
  890. }
  891.  
  892.  
  893. /******************************************************************************
  894. * Class LMainWindowHelpHandler :: LMainWindowHelpHandler - Constructor for    *
  895. *   handling help events.                                                     *
  896. ******************************************************************************/
  897. LMainWindowHelpHandler::LMainWindowHelpHandler()
  898. {}
  899.  
  900.  
  901. /******************************************************************************
  902. * Class LMainWindowHelpHandler :: ~LMainWindowHelpHandler - Destructor        *
  903. ******************************************************************************/
  904. LMainWindowHelpHandler::~LMainWindowHelpHandler()
  905. {}
  906.  
  907.  
  908. /******************************************************************************
  909. * Class LMainHelpWindowHelpHandler :: keysHelpId()                            *
  910. *   Handle the keys help request event.                                       *
  911. *   This overrides the default provided by library.                           *
  912. ******************************************************************************/
  913. IBase::Boolean LMainWindowHelpHandler::keysHelpId( IEvent& evt )
  914. {
  915.    evt.setResult( ID_MAIN_HELP_KEYS_PANEL);
  916.    return true;
  917. }
  918.