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

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