home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / LANCELOT / LSKILL.CPP < prev    next >
C/C++ Source or Header  |  1995-04-07  |  35KB  |  748 lines

  1. /******************************************************************************
  2. * FILE NAME: lskill.cpp                                                       *
  3. *                                                                             *
  4. * DESCRIPTION:                                                                *
  5. *                                                                             *
  6. * Class                                                                       *
  7. *   SkillPage                                                                 *
  8. *   SkillCnrObj                                                               *
  9. *                                                                             *
  10. * COPYRIGHT:                                                                  *
  11. *   Licensed Materials - Property of IBM                                      *
  12. *   (C) Copyright IBM Corporation 1992, 1995                                  *
  13. *   All Rights Reserved                                                       *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  16. *                                                                             *
  17. * CHANGE HISTORY:                                                             *
  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 <iexcbase.hpp>
  24. #include <ireslib.hpp>
  25. #include <ihelp.hpp>
  26. #include "lancelot.h"
  27. #include "lskill.hpp"
  28.  
  29. /******************************************************************************
  30. * Class SkillPage :: SkillPage - Constructor for the skill page               *
  31. *                                                                             *
  32. * Define yourself as an IMultiCellCanvas                                      *
  33. * Create generic page buttons                                                 *
  34. * Create generic page container buttons                                       *
  35. * Define a null skill range combobox                                          *
  36. * Create static text for the skill                                            *
  37. * Create static text for the months experience                                *
  38. * Create entryfield for the skill                                             *
  39. * Create spinbutton for the months experience                                 *
  40. * Define a null container pointer                                             *
  41. * Define a null container object pointer                                      *
  42. * Define a null container column pointer                                      *
  43. * Define a null container column pointer                                      *
  44. * Create an account data object given the key                                 *
  45. * Create a empty account data object                                          *
  46. * Set the key in your private data                                            *
  47. * Set the isQuery in your private data                                        *
  48. * Create the notebook page settings                                           *
  49. ******************************************************************************/
  50. SkillPage::SkillPage(      IWindow* pParent,
  51.                            const IString& aKey )
  52.      :IMultiCellCanvas     ( ID_SKILL_PAGE, pParent, pParent ),
  53.       pageButtons          ( ID_STATUS_PAGE_BUTTONS,
  54.                              this, this, false ),
  55.       pageCnrButtons       ( ID_STATUS_PAGE_CNRBUTTONS,
  56.                              this, this, false ),
  57.       pSkillRange          ( NULL ),
  58.       skillText            ( ID_NO_ITEM, this, this ),
  59.       monthsExpText        ( ID_NO_ITEM, this, this ),
  60.       skill                ( ID_SKI_SKILL_EF, this, this,
  61.                              IRectangle(),
  62.                              IEntryField::classDefaultStyle
  63.                              | IControl::tabStop ),
  64.       monthsExp            ( ID_SKI_YRS_EXP_CBX, this, this,
  65.                              IRectangle(),
  66.                              INumericSpinButton:: classDefaultStyle
  67.                              | IControl::tabStop ),
  68.       pCnr                 ( (IContainerControl*) NULL ),
  69.       pSkillCnrObj         ( (SkillCnrObj*) NULL ),
  70.       pColSkill            ( (IContainerColumn*) NULL ),
  71.       pColExp              ( (IContainerColumn*) NULL ),
  72.       skillData            ( aKey ),
  73.       origSkillData        (),
  74.       Key                  ( aKey ),
  75.       thePageSettings      ( IApplication::current().userResourceLibrary().
  76.                              loadString( STR_SKI_SKILL_TAB ), NULL,
  77.                              INotebook::PageSettings::autoPageSize
  78.                              | INotebook::PageSettings::majorTab ),
  79.        isAquery            ( false ),
  80.        cnrSelHandler       ( this )
  81. {
  82. /*-----------------------------------------------------------------------------
  83. | Save the skill data to another object in case the user wishes to            |
  84. |  undo any changes.                                                          |
  85. | Label the static text objects.                                              |
  86. | Set the limit for the entryfield and combobox.                              |
  87. | Set the combobox range.                                                     |
  88. -----------------------------------------------------------------------------*/
  89.    origSkillData = skillData;
  90.    skillText.setText( STR_SKI_SKILL );
  91.    monthsExpText.setText( STR_SKI_YEARS_EXP );
  92.    skill.setLimit( DISPLAY_LARGE );
  93.    monthsExp.setLimit( DISPLAY_SMALL_RANGE );
  94.    monthsExp.setRange( IRange( 0, 99 ) );
  95.  
  96. /*-----------------------------------------------------------------------------
  97. | Fill the container from the database.                                       |
  98. | Set the objects on yourself (IMultiCellCanvas).                             |
  99. | Start handling the events.                                                  |
  100. -----------------------------------------------------------------------------*/
  101.    fillCnr();
  102.    setCells();
  103.    handleIt();
  104. };
  105.  
  106.  
  107. /******************************************************************************
  108. * Class SkillPage :: SkillPage - Constructor for the skill page               *
  109. *                                                                             *
  110. * Define yourself as an IMultiCellCanvas                                      *
  111. * Create generic page buttons                                                 *
  112. * Create generic page container buttons                                       *
  113. * Define a null skill range combobox                                          *
  114. * Create static text for the skill                                            *
  115. * Create static text for the months experience                                *
  116. * Create entryfield for the skill                                             *
  117. * Create spinbutton for the months experience                                 *
  118. * Define a null container pointer                                             *
  119. * Define a null container object pointer                                      *
  120. * Define a null container column pointer                                      *
  121. * Define a null container column pointer                                      *
  122. * Create an account data object given the key                                 *
  123. * Create a empty account data object                                          *
  124. * Set the key in your private data                                            *
  125. * Set the isQuery in your private data                                        *
  126. * Create the notebook page settings                                           *
  127. ******************************************************************************/
  128. SkillPage::SkillPage(      IWindow* pParent,
  129.                            LQueryData& qd )
  130.      :IMultiCellCanvas     ( ID_SKILL_PAGE, pParent, pParent ),
  131.       pageButtons          ( ID_STATUS_PAGE_BUTTONS,
  132.                              this, this, true),
  133.       pageCnrButtons       ( ID_STATUS_PAGE_CNRBUTTONS,
  134.                              this, this, false ),
  135.       pSkillRange          ( NULL ),
  136.       skillText            ( ID_NO_ITEM, this, this ),
  137.       monthsExpText        ( ID_NO_ITEM, this, this ),
  138.       skill                ( ID_SKI_SKILL_EF, this, this,
  139.                              IRectangle(),
  140.                              IEntryField::classDefaultStyle
  141.                              | IControl::tabStop ),
  142.       monthsExp            ( ID_SKI_YRS_EXP_CBX, this, this,
  143.                              IRectangle(),
  144.                              INumericSpinButton::classDefaultStyle
  145.                              | IControl::tabStop),
  146.       pCnr                 ( (IContainerControl*) NULL ),
  147.       pSkillCnrObj         ( (SkillCnrObj*) NULL ),
  148.       pColSkill            ( (IContainerColumn*) NULL ),
  149.       pColExp              ( (IContainerColumn*) NULL ),
  150.       skillData            ( qd ),
  151.       origSkillData        (),
  152.       Key                  ( qd.queryName() ),
  153.       thePageSettings      ( IApplication::current().userResourceLibrary().
  154.                              loadString( STR_SKI_SKILL_TAB ), NULL,
  155.                              INotebook::PageSettings::autoPageSize
  156.                              | INotebook::PageSettings::majorTab ),
  157.       isAquery             ( true ),
  158.       cnrSelHandler        ( this )
  159. {
  160. /*-----------------------------------------------------------------------------
  161. | Save the skill data to another object in case the user wishes to            |
  162. |  undo any changes.                                                          |
  163. | Label the static text objects.                                              |
  164. | Set the limit for the entryfield and combobox.                              |
  165. | Set the combobox range.                                                     |
  166. -----------------------------------------------------------------------------*/
  167.    origSkillData = skillData;
  168.    skillText.setText( STR_SKI_SKILL  );
  169.    monthsExpText.setText( STR_SKI_YEARS_EXP );
  170.    skill.setLimit( DISPLAY_LIMIT );
  171.    monthsExp.setLimit( DISPLAY_SMALL_RANGE );
  172.    monthsExp.setRange( IRange( 0, 99 ) );
  173.  
  174. /*-----------------------------------------------------------------------------
  175. | Create the skill range combobox.                                            |
  176. | Set the skill range if valid.                                               |
  177. -----------------------------------------------------------------------------*/
  178.    pSkillRange = new QueryRange( ID_SKILL_PAGE_RANGE,
  179.                                  this, this,
  180.                                  ID_SKILL_RANGE);
  181.  
  182.    if ( skillData.theRange().length() )
  183.       pSkillRange->setRange( skillData.theRange() );
  184.  
  185. /*-----------------------------------------------------------------------------
  186. | Fill the container from the database.                                       |
  187. | Set the objects on yourself (IMultiCellCanvas).                             |
  188. | Start handling the events.                                                  |
  189. -----------------------------------------------------------------------------*/
  190.    fillCnr();
  191.    setCells();
  192.    handleIt();
  193. };
  194.  
  195.  
  196. /******************************************************************************
  197. * Class SkillPage :: ~SkillPage - Destructor for the skill page               *
  198. ******************************************************************************/
  199. SkillPage :: ~SkillPage()
  200. {
  201. /*-----------------------------------------------------------------------------
  202. | Stop handling events.                                                       |
  203. -----------------------------------------------------------------------------*/
  204.    ICommandHandler::stopHandlingEventsFor( &pageButtons );
  205.    ICommandHandler::stopHandlingEventsFor( &pageCnrButtons );
  206.    ISelectHandler::stopHandlingEventsFor( &pageButtons );
  207.    cnrSelHandler.stopHandlingEventsFor( pCnr );
  208. };
  209.  
  210.  
  211. /******************************************************************************
  212. * Class SkillPage :: handleIt - Handle events for the skill page              *
  213. ******************************************************************************/
  214. SkillPage&  SkillPage :: handleIt()
  215. {
  216. /*-----------------------------------------------------------------------------
  217. | Start handling events.                                                      |
  218. | Return yourself.                                                            |
  219. -----------------------------------------------------------------------------*/
  220.    ICommandHandler::handleEventsFor( &pageButtons );
  221.    ICommandHandler::handleEventsFor( &pageCnrButtons );
  222.    ISelectHandler::handleEventsFor( &pageButtons );
  223.    return *this;
  224. }
  225.  
  226.  
  227. /******************************************************************************
  228. * Class SkillPage :: fillCnr - Set up the container                           *
  229. ******************************************************************************/
  230. SkillPage&  SkillPage :: fillCnr()
  231. {
  232. /*-----------------------------------------------------------------------------
  233. | If the container already exists,                                            |
  234. |  delete all the objects                                                     |
  235. | Else create a new container.                                                |
  236. -----------------------------------------------------------------------------*/
  237.    if ( pCnr )
  238.       pCnr->deleteAllObjects();
  239.    else
  240.    {
  241.       pCnr = new IContainerControl( ID_SKI_CNR,
  242.                                     this, this,
  243.                                     IRectangle(),
  244.                                     IContainerControl::classDefaultStyle
  245.                                     | IContainerControl::readOnly,
  246.                                     IContainerControl::readOnlyTitle
  247.                                     | IContainerControl::detailsView );
  248.  
  249. /*-----------------------------------------------------------------------------
  250. | Handle selection events for the new container.                              |
  251. -----------------------------------------------------------------------------*/
  252.       cnrSelHandler.handleEventsFor( pCnr );
  253.  
  254. /*-----------------------------------------------------------------------------
  255. | Delete the objects when the container is deleted.                           |
  256. | Tell the container to allow multiple selection.                             |
  257. | Tell the container to automatically refresh upon changes.                   |
  258. -----------------------------------------------------------------------------*/
  259.       pCnr->setDeleteObjectsOnClose();
  260.       pCnr->setDeleteColumnsOnClose();
  261.       pCnr->setMultipleSelection();
  262.  
  263. /*-----------------------------------------------------------------------------
  264. | Create two container columns.                                               |
  265. -----------------------------------------------------------------------------*/
  266.       pColSkill =
  267.          new IContainerColumn( pSkillCnrObj->skillOffset(),
  268.                                IContainerColumn::defaultHeadingStyle(),
  269.                                IContainerColumn::string );
  270.  
  271.       pColExp =
  272.          new IContainerColumn( pSkillCnrObj->expOffset(),
  273.                                IContainerColumn::defaultHeadingStyle(),
  274.                                IContainerColumn::string );
  275.  
  276. /*-----------------------------------------------------------------------------
  277. | Label the container column headings.                                        |
  278. | Show the headings.                                                          |
  279. | Show the headings.                                                          |
  280. -----------------------------------------------------------------------------*/
  281.       pColSkill->setHeadingText(STR_SKI_CURRENT_SKILLS);
  282.       pColExp->setHeadingText(STR_SKI_YEARS_EXP);
  283.       pCnr->showDetailsViewTitles();
  284.  
  285. /*-----------------------------------------------------------------------------
  286. | Add the columns to the container.                                           |
  287. | Add column separators between the columns.                                  |
  288. -----------------------------------------------------------------------------*/
  289.      pCnr->addColumn(pColSkill);
  290.      pCnr->addColumn(pColExp);
  291.      pColSkill->showSeparators( IContainerColumn::verticalSeparator
  292.                                 | IContainerColumn::horizontalSeparator );
  293.      pColExp->showSeparators( IContainerColumn::horizontalSeparator );
  294.    }
  295.  
  296. /*-----------------------------------------------------------------------------
  297. | Start from the beginning of the skill data.                                 |
  298. | While there exists items,                                                   |
  299. |   add objects to the container.                                             |
  300. | Refresh the container.                                                      |
  301. | Return yourself.                                                            |
  302. -----------------------------------------------------------------------------*/
  303.    IString
  304.       skill,
  305.       exp;
  306.    LSkillData::Rule
  307.       rule;
  308.  
  309.    skillData.setFirst();
  310.    while ( skillData.getItem( skill, exp, rule ) )
  311.    {
  312.       addSkill( skill, exp );
  313.       skillData.getNext();
  314.    }
  315.  
  316.    pCnr->refresh();
  317.  
  318.    return *this;
  319. };
  320.  
  321.  
  322. /******************************************************************************
  323. * Class SkillPage :: setCells - Set up your multicell canvas cells            *
  324. ******************************************************************************/
  325. SkillPage&  SkillPage :: setCells()
  326. {
  327. /*-----------------------------------------------------------------------------
  328. | Add the objects to your multicell canvas.                                   |
  329. | Allow the container to expand horizontally.                                 |
  330. | Allow the page buttons to expand horizontally.                              |
  331. | Return yourself.                                                            |
  332. -----------------------------------------------------------------------------*/
  333.    addToCell( &skillText,         2,  2 );
  334.    addToCell( &skill,             2,  3 );
  335.  
  336.    addToCell( &monthsExpText,     2,  4 );
  337.    addToCell( &monthsExp,         2,  5 );
  338.  
  339.    if ( pSkillRange )
  340.       addToCell( pSkillRange,     3,  5,  5,  3 );
  341.  
  342.    addToCell( pCnr,               2,  7,  8,  3 );
  343.    addToCell( &pageCnrButtons,   10,  9 );
  344.    setColumnWidth(                9,  0,  true );
  345.  
  346.    addToCell( &pageButtons,       2, 12,  7,  3 );
  347.    setColumnWidth(                8,  0,  true );
  348.  
  349.    return *this;
  350. };
  351.  
  352.  
  353. /******************************************************************************
  354. * Class SkillPage :: verifyAndSave - Save page information to the database    *
  355. ******************************************************************************/
  356. IBase::Boolean SkillPage::verifyAndSave( IString& theString,
  357.                                          IString& theEntry,
  358.                                          const IString theName )
  359. {
  360. /*-----------------------------------------------------------------------------
  361. | If there is no data or is a query, return.                                  |
  362. -----------------------------------------------------------------------------*/
  363.    if ( ( ! theName.length() )
  364.         && ( ! Key.length() )
  365.         || isAquery )
  366.       return true;
  367.  
  368. /*-----------------------------------------------------------------------------
  369. | If able to retrieve the container information,                              |
  370. |  save the information to the database based on the key or query name.       |
  371. -----------------------------------------------------------------------------*/
  372.    if ( setSkillData() )
  373.    {
  374.       if ( ( theName.length() ) && ( theName.isAlphanumeric() ) )
  375.          skillData.save( theName );
  376.        else
  377.          if ( ( Key.length() ) && ( Key.isAlphanumeric() ) )
  378.             skillData.save( Key );
  379.    }
  380.  
  381.    return true;
  382. };
  383.  
  384. /******************************************************************************
  385. * Class SkillPage :: setSkillData - Retrieve the page information             *
  386. ******************************************************************************/
  387. IBase::Boolean SkillPage::setSkillData()
  388. {
  389.    IContainerControl::ObjectCursor
  390.       iterator( *pCnr );
  391.  
  392.    iterator.setToFirst();
  393.    if ( ! iterator.isValid() )
  394.       return false;
  395.  
  396.    SkillCnrObj
  397.      *cnrEntry;
  398.    IString
  399.       it1,
  400.       it2;
  401.  
  402. /*-----------------------------------------------------------------------------
  403. | Empty the bag.                                                              |
  404. | Iterate through the cursor and add objects to the bag.                      |
  405. -----------------------------------------------------------------------------*/
  406.    skillData.emptyBag();
  407.    while ( iterator.isValid() )
  408.    {
  409.       cnrEntry = (SkillCnrObj *) iterator.current();
  410.       this->skillData.putItem( cnrEntry->getSkill(), cnrEntry->getExp() );
  411.       cnrEntry = (SkillCnrObj *) iterator.next();
  412.    }
  413.  
  414.    return true;
  415. };
  416.  
  417.  
  418. /******************************************************************************
  419. * Class SkillPage :: fillEntryfields - Fill the entryfields for the object    *
  420. ******************************************************************************/
  421. SkillPage& SkillPage::fillEntryfields( SkillCnrObj* pCnrObject )
  422. {
  423. /*-----------------------------------------------------------------------------
  424. | Set the entryfields for the given skill container object.                   |
  425. | Return yourself.                                                            |
  426. -----------------------------------------------------------------------------*/
  427.    skill.setText( pCnrObject->getSkill() );
  428.    monthsExp.setValue( pCnrObject->getExp().asInt() );
  429.  
  430.    return *this;
  431. };
  432.  
  433.  
  434. /******************************************************************************
  435. * Class SkillPage :: command - Catch and process command events.              *
  436. ******************************************************************************/
  437. IBase::Boolean SkillPage::command( ICommandEvent& cmdEvent )
  438. {
  439.    IString
  440.       theMonthsExp = monthsExp.value(),
  441.       theSkill = skill.text();
  442.    LSkillData::Rule
  443.       theRule = LSkillData::na;
  444.    Boolean
  445.       rc = false;
  446.    unsigned int
  447.       count = 0;
  448.  
  449. /*-----------------------------------------------------------------------------
  450. | Create a container object cursor based on the selected objects.             |
  451. | Process the command events.                                                 |
  452. -----------------------------------------------------------------------------*/
  453.    IContainerControl::ObjectCursor
  454.       soc( *pCnr, IContainerObject::selected );
  455.  
  456.    switch ( cmdEvent.commandId() )
  457.    {
  458. /*-----------------------------------------------------------------------------
  459. | User pressed the UNDO button.                                               |
  460. | Reset the skill data to the original skill data.                            |
  461. | Reset the container.                                                        |
  462. | Reset the entryfields.                                                      |
  463. -----------------------------------------------------------------------------*/
  464.       case ID_BUTTON_UNDO:
  465.       {
  466.          skillData = origSkillData;
  467.          fillCnr();
  468.          skill.setText( "" );
  469.          monthsExp.setValue( 0 );
  470.          rc = true;
  471.          break;
  472.       }
  473.  
  474. /*-----------------------------------------------------------------------------
  475. | User pressed the REMOVE button.                                             |
  476. | Iterate through the selected objects,                                       |
  477. |  remove the object from the the database.                                   |
  478. -----------------------------------------------------------------------------*/
  479.       case ID_BUTTON_REMOVE:
  480.       {
  481.          for ( soc.setToFirst();
  482.                soc.isValid();
  483.                soc.setToNext() )
  484.          {
  485.             SkillCnrObj
  486.                *pObj = (SkillCnrObj *) soc.current();
  487.             skillData.putItem( pObj->getSkill(),
  488.                                pObj->getExp(),
  489.                                LSkillData::remove );
  490.            ++count;
  491.          }
  492.  
  493. /*-----------------------------------------------------------------------------
  494. | If no container objects were selected,                                      |
  495. |  notify the user.                                                           |
  496. -----------------------------------------------------------------------------*/
  497.          if ( ! count )
  498.          {
  499.             IMessageBox
  500.                warning( owner() );
  501.             warning.show( STR_MSG_REMOVE,
  502.                           IMessageBox::enterButton
  503.                           | IMessageBox::informationIcon );
  504.          }
  505. /*-----------------------------------------------------------------------------
  506. | Else remove the selected objects from the container.                        |
  507. | Refresh the container.                                                      |
  508. -----------------------------------------------------------------------------*/
  509.          else
  510.          {
  511.             pCnr->removeSelectedObjects();
  512.             skill.setText( "" );
  513.             monthsExp.setValue( 0 );
  514.             pCnr->refresh();
  515.          }
  516.          rc = true;
  517.          break;
  518.       }
  519.  
  520. /*-----------------------------------------------------------------------------
  521. | User pressed the CHANGE button.                                             |
  522. | Ignore all but the first selected container object.                         |
  523. | Update the entryfields with the selected container object information.      |
  524. -----------------------------------------------------------------------------*/
  525.       case ID_BUTTON_CHANGE:
  526.       {
  527.          soc.setToFirst();
  528.          if ( soc.isValid() )
  529.          {
  530.             if ( theSkill.length() )
  531.             {
  532.                changeSkill( theSkill, theMonthsExp, (SkillCnrObj*) soc.current() );
  533.                skill.setText( "" );
  534.                monthsExp.setValue( 0 );
  535.             }
  536.          }
  537.  
  538. /*-----------------------------------------------------------------------------
  539. | If no container objects were selected,                                      |
  540. |  notify the user.                                                           |
  541. -----------------------------------------------------------------------------*/
  542.          else
  543.          {
  544.             IMessageBox
  545.                warning( owner() );
  546.             warning.show( STR_MSG_CHANGE,
  547.                           IMessageBox::enterButton
  548.                           | IMessageBox::informationIcon );
  549.          }
  550.  
  551. /*-----------------------------------------------------------------------------
  552. | Deselect any container objects.                                             |
  553. -----------------------------------------------------------------------------*/
  554.          unMark();
  555.          rc = true;
  556.          break;
  557.       }
  558.  
  559. /*-----------------------------------------------------------------------------
  560. | User pressed the ADD button.                                                |
  561. | Add the entryfield information to the database and container.               |
  562. | Reset the entryfields.                                                      |
  563. -----------------------------------------------------------------------------*/
  564.       case ID_BUTTON_ADD:
  565.       {
  566.          if ( theSkill.length() )
  567.          {
  568.             addSkill( theSkill, theMonthsExp );
  569.             skill.setText( "" );
  570.             monthsExp.setValue( 0 );
  571.          }
  572.  
  573. /*-----------------------------------------------------------------------------
  574. | Deselect any container objects.                                             |
  575. -----------------------------------------------------------------------------*/
  576.          unMark();
  577.          rc = true;
  578.          break;
  579.       }
  580.  
  581.  
  582. /*-----------------------------------------------------------------------------
  583. | User pressed the HELP button.                                               |
  584. | Show the help for the account page.                                         |
  585. -----------------------------------------------------------------------------*/
  586.       case ID_BUTTON_HELP:
  587.       {
  588.          IHelpWindow::helpWindow( this )->
  589.             show( IResourceId( ID_SKILL_PAGE ) );
  590.          rc = true;
  591.          break;
  592.       }
  593.   }
  594.  
  595.   return rc;
  596. };
  597.  
  598.  
  599. /******************************************************************************
  600. * Class SkillPage :: addSkill - Add the skill information to the container    *
  601. ******************************************************************************/
  602. IBase::Boolean SkillPage::addSkill( IString& skill, IString& exp )
  603. {
  604.    Boolean
  605.       rc = true;
  606.  
  607. /*-----------------------------------------------------------------------------
  608. | Create a container text cursor based on the skill.                          |
  609. -----------------------------------------------------------------------------*/
  610.    IContainerControl::TextCursor
  611.       txtCur( *pCnr, IString( skill ), true, false, true );
  612.  
  613. /*-----------------------------------------------------------------------------
  614. | Start at the beginning of the cursor.                                       |
  615. | If the cursor contains a duplicate, set the return code to false.           |
  616. -----------------------------------------------------------------------------*/
  617.    for ( txtCur.setToFirst();
  618.          txtCur.isValid();
  619.          txtCur.setToNext() )
  620.    {
  621.       if ( ( (SkillCnrObj*) txtCur.current() )->getExp() == exp )
  622.       {
  623.          rc = false;
  624.          break;
  625.       }
  626.    }
  627.  
  628. /*-----------------------------------------------------------------------------
  629. | If the object doesn't exist,                                                |
  630. |  Add the object to the database.                                            |
  631. |  Create an skill container object.                                          |
  632. |  Add the object to the container.                                           |
  633. |  Refresh the container.                                                     |
  634. -----------------------------------------------------------------------------*/
  635.    if ( rc )
  636.    {
  637.       if ( isAquery )
  638.       {
  639.          if ( ! skill.length() )
  640.             skill = "*";
  641.          if ( ! exp.length() )
  642.             exp = "*";
  643.       }
  644.  
  645.       skillData.putItem( skill, exp, LSkillData::add );
  646.       pSkillCnrObj = new SkillCnrObj( skill, exp );
  647.       pCnr->addObject( pSkillCnrObj );
  648.       pCnr->refresh();
  649.    }
  650.  
  651.    return rc;
  652. }
  653.  
  654. /******************************************************************************
  655. * Class SkillPage :: changeSkill - Change the skill information for the       *
  656. *  selected container object.                                                 *
  657. ******************************************************************************/
  658. IBase::Boolean SkillPage::changeSkill( IString& skill, IString& exp,
  659.                                        SkillCnrObj* pCnrObj )
  660. {
  661.    Boolean
  662.       rc = true;
  663.  
  664. /*-----------------------------------------------------------------------------
  665. | Create a container text cursor based on the skill.                          |
  666. -----------------------------------------------------------------------------*/
  667.    IContainerControl::TextCursor
  668.       txtCur( *pCnr, IString( skill ), true, false, true );
  669.  
  670. /*-----------------------------------------------------------------------------
  671. | Start at the beginning of the cursor.                                       |
  672. | If the cursor contains a duplicate, set the return code to false.           |
  673. -----------------------------------------------------------------------------*/
  674.    for ( txtCur.setToFirst();
  675.          txtCur.isValid();
  676.          txtCur.setToNext() )
  677.    {
  678.       if ( ( (SkillCnrObj*) txtCur.current() )->getExp() == exp )
  679.       {
  680.          rc = false;
  681.          break;
  682.       }
  683.    }
  684.  
  685.    txtCur.setToFirst();
  686.    if ( !txtCur.isValid() )
  687.       rc = false;
  688.  
  689. /*-----------------------------------------------------------------------------
  690. | If the container object exists -and- the skill exists,                      |
  691. |  Set the container object's data.                                           |
  692. |  Reset the entryfields.                                                     |
  693. |  Deselect the container objects.                                            |
  694. -----------------------------------------------------------------------------*/
  695.    if ( pCnrObj && rc )
  696.    {
  697.       pCnrObj->setSkill( skill );
  698.       pCnrObj->setExp( exp );
  699.    }
  700.  
  701.    return rc;
  702. }
  703.  
  704.  
  705. /******************************************************************************
  706. * Class SkillPage :: unMark - Deselect the selected container objects.        *
  707. ******************************************************************************/
  708. SkillPage&  SkillPage ::  unMark()
  709. {
  710.    IContainerControl::ObjectCursor
  711.       co( *pCnr );
  712.    for ( co.setToFirst();
  713.          co.isValid();
  714.          co.setToNext() )
  715.    {
  716.       try
  717.       {
  718.          pCnr->removeSelected( pCnr->objectAt( co ) );
  719.       }
  720.       catch ( IException& exc )
  721.       {}
  722.    }
  723.  
  724.    return *this;
  725. };
  726.  
  727.  
  728. /******************************************************************************
  729. * Class SkillCnrObj :: SkillCnrObj - Constructor for skill container objects  *
  730. *                                                                             *
  731. * Define yourself as a container object.                                      *
  732. * Set the skill in your private data.                                         *
  733. * Set the experience in your private data.                                    *
  734. ******************************************************************************/
  735. SkillCnrObj::SkillCnrObj( const IString& stSkill,
  736.                           const IString& stExp )
  737.      :IContainerObject(),
  738.       skill( stSkill ),
  739.       exp( stExp )
  740. {};
  741.  
  742.  
  743. /******************************************************************************
  744. * Class SkillCnrObj :: ~SkillCnrObj - Destructor for skill container objects  *
  745. ******************************************************************************/
  746. SkillCnrObj :: ~SkillCnrObj()
  747. {};
  748.