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

  1. /*******************************************************************************
  2. * FILE NAME: lstatus.cpp                                                       *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *                                                                              *
  6. * Classes                                                                      *
  7. *   StatusCnrObj                                                               *
  8. *   StatusPage                                                                 *
  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 <ireslib.hpp>
  24. #include <ihelp.hpp>
  25. #include "lancelot.h"
  26. #include "lstatus.hpp"
  27. #include "lpagectl.hpp"
  28.  
  29. //-----------------------------------------------------------------------------
  30. // CLASS StatusPage - constructor
  31. //-----------------------------------------------------------------------------
  32. StatusPage :: StatusPage(IWindow* pParent,
  33.                          const IString& aKey)
  34.           : IMultiCellCanvas(ID_STATUS_PAGE, pParent, pParent),
  35.             pageButtons( ID_STATUS_PAGE_BUTTONS,
  36.                          this, this, false ),
  37.             statusText(ID_NO_ITEM, this, this ),
  38.             activeText(ID_NO_ITEM, this, this ),
  39.             startDateText(ID_NO_ITEM, this, this ),
  40.             endDateText(ID_NO_ITEM, this, this ),
  41.             rateText(ID_NO_ITEM, this, this ),
  42.             pActiveCheckBox(NULL),
  43.             pQueryActive(NULL),
  44.             pQueryInactive(NULL),
  45.             startDate(ID_STA_START_DATE_EF, this, this,
  46.                     IRectangle(),
  47.                     IEntryField::classDefaultStyle |
  48.                     IControl::tabStop),
  49.             endDate(ID_STA_END_DATE_EF, this, this,
  50.                     IRectangle(),
  51.                     IEntryField::classDefaultStyle |
  52.                     IControl::tabStop),
  53.             hourlyRate(ID_STA_HOURLY_RATE_EF, this, this,
  54.                     IRectangle(),
  55.                     IEntryField::classDefaultStyle |
  56.                     IControl::tabStop),
  57.             statusData(aKey),
  58.             Key(aKey),
  59.             pStartRange(NULL),
  60.             pEndRange(NULL),
  61.             pPayRange(NULL),
  62.             thePageSettings( IApplication::current().userResourceLibrary().loadString(
  63.                               STR_STA_STATUS_TAB), NULL,
  64.                               INotebook::PageSettings::autoPageSize
  65.                             | INotebook::PageSettings::majorTab ),
  66. #ifdef IC_MOTIF
  67.             dateHandler(this, TEST_DATE),
  68.             rateHandler(this, TEST_CURRENCY),
  69. #endif
  70.             isAquery(false)
  71. {
  72.    statusText.setText(    STR_STA_TITLE  );
  73.    startDateText.setText( STR_STA_START  );
  74.    endDateText.setText(   STR_STA_END    );
  75.    rateText.setText(      STR_STA_HOURLY );
  76.  
  77.    startDate.setLimit( DISPLAY_LIMIT);
  78.    endDate.setLimit(   DISPLAY_LIMIT);
  79.    hourlyRate.setLimit(DISPLAY_LIMIT);
  80.  
  81.    activeText.setText(    STR_STA_ACTIVE );
  82.    pActiveCheckBox = new ICheckBox( ID_CHECK_BOX
  83.                                   , this
  84.                                   , this);
  85.  
  86.    displayData();
  87.    setCells();
  88.    handleIt();
  89. }
  90.  
  91. //-----------------------------------------------------------------------------
  92. // CLASS StatusPage - constructor - a query page
  93. //-----------------------------------------------------------------------------
  94.  
  95. StatusPage :: StatusPage(IWindow* pParent, LQueryData& qd)
  96.           : IMultiCellCanvas(  ID_STATUS_PAGE, pParent, pParent),
  97.             pageButtons( ID_STATUS_PAGE_BUTTONS
  98.                          , this
  99.                          , this
  100.                          , true),
  101.             statusText(ID_NO_ITEM, this, this ),
  102.             activeText(ID_NO_ITEM, this, this ),
  103.             startDateText(ID_NO_ITEM, this, this ),
  104.             endDateText(ID_NO_ITEM, this, this ),
  105.             rateText(ID_NO_ITEM, this, this ),
  106.             pActiveCheckBox(NULL),
  107.             pQueryActive(NULL),
  108.             pQueryInactive(NULL),
  109.             startDate(ID_STA_START_DATE_EF, this, this ),
  110.             endDate(ID_STA_END_DATE_EF, this, this ),
  111.             hourlyRate(ID_STA_HOURLY_RATE_EF, this, this ),
  112.             statusData(qd),
  113.             Key(qd.queryName()),
  114.             pStartRange(NULL),
  115.             pEndRange(NULL),
  116.             pPayRange(NULL),
  117.             thePageSettings( IApplication::current().userResourceLibrary().loadString(
  118.                               STR_STA_STATUS_TAB), NULL,
  119.                               INotebook::PageSettings::autoPageSize
  120.                             | INotebook::PageSettings::majorTab ),
  121. #ifdef IC_MOTIF
  122.             dateHandler(this, TEST_DATE),
  123.             rateHandler(this, TEST_CURRENCY),
  124. #endif
  125.             isAquery(true )
  126. {
  127.  
  128.    statusText.setText(    STR_STA_TITLE  );
  129.    startDateText.setText( STR_STA_START  );
  130.    endDateText.setText(   STR_STA_END    );
  131.    rateText.setText(      STR_STA_HOURLY );
  132.  
  133.    startDate.setLimit( DISPLAY_LIMIT_DATE);
  134.    endDate.setLimit(   DISPLAY_LIMIT_DATE);
  135.    hourlyRate.setLimit(DISPLAY_SMALL);
  136.  
  137.    pQueryActive = new ICheckBox( ID_STATUS_QUERY_ACTIVE, this, this);
  138.    pQueryInactive = new ICheckBox( ID_STATUS_QUERY_INACTIVE, this, this);
  139.  
  140.    pStartRange  = new QueryRange( ID_STATUS_PAGE_START
  141.                                 , this
  142.                                 , this
  143.                                 , ID_STATUS_START);
  144.  
  145.    pEndRange    = new QueryRange( ID_STATUS_PAGE_END
  146.                                 , this
  147.                                 , this
  148.                                 , ID_STATUS_END);
  149.  
  150.    pPayRange = new QueryRange( ID_STATUS_PAGE_PAY
  151.                              , this
  152.                              , this
  153.                              , ID_STATUS_PAY);
  154.  
  155.    pQueryActive->setText(STR_STA_ACTIVE);
  156.    pQueryInactive->setText(STR_STA_INACTIVE);
  157.  
  158.    displayData();
  159.    setCells();
  160.    handleIt();
  161. }
  162.  
  163. //-----------------------------------------------------------------------------
  164. // CLASS StatusPage :: ~StatusPage - destructor
  165. //-----------------------------------------------------------------------------
  166. StatusPage :: ~StatusPage()
  167. {
  168.    ICommandHandler::stopHandlingEventsFor( &pageButtons );
  169.    ISelectHandler::stopHandlingEventsFor( &pageButtons );
  170.    if (pActiveCheckBox)
  171.       checkBoxHandler.stopHandlingEventsFor ( pActiveCheckBox);
  172. #ifdef IC_MOTIF
  173.    if (!isAquery) {
  174.        dateHandler.stopHandlingEventsFor( &startDate );
  175.        dateHandler.stopHandlingEventsFor( &endDate );
  176.        rateHandler.stopHandlingEventsFor( &hourlyRate );
  177.    }
  178. #endif
  179. }
  180.  
  181. //*****************************************************************************
  182. // CLASS StatusPage :: handleIt()
  183. //*****************************************************************************
  184. StatusPage&  StatusPage :: handleIt()
  185. {
  186.    ICommandHandler::handleEventsFor( &pageButtons );
  187.    ISelectHandler::handleEventsFor( &pageButtons );
  188.    if (pActiveCheckBox)
  189.      checkBoxHandler.handleEventsFor ( pActiveCheckBox );
  190. #ifdef IC_MOTIF
  191.    dateHandler.handleEventsFor( &startDate );
  192.    dateHandler.handleEventsFor( &endDate );
  193.    rateHandler.handleEventsFor( &hourlyRate );
  194. #endif
  195.    return *this;
  196. }
  197.  
  198. //-----------------------------------------------------------------------------
  199. // CLASS StatusPage :: setCells() - set up the multi-cell canvas
  200. //-----------------------------------------------------------------------------
  201. StatusPage& StatusPage :: setCells()
  202. {
  203.   addToCell(&statusText,         2,  2);
  204.  
  205.   if (pActiveCheckBox)
  206.   {
  207.     addToCell(&activeText,       2,  4);
  208.     addToCell(pActiveCheckBox,   3,  4);
  209.   }
  210.   else
  211.   {
  212.     addToCell(pQueryActive,      2,  4,  5,  1);
  213.     addToCell(pQueryInactive,    2,  5,  5,  1);
  214.   }
  215.  
  216.   addToCell(&startDateText,      2,  8);
  217.   addToCell(&startDate,          2,  9);
  218.   if ( !pActiveCheckBox )
  219.     addToCell(pStartRange,       3,  9,  5,  3);
  220.  
  221.   addToCell(&endDateText,        2, 11);
  222.   addToCell(&endDate,            2, 12);
  223.   if ( !pActiveCheckBox )
  224.     addToCell(pEndRange,         3, 12,  5,  3);
  225.  
  226.   addToCell(&rateText,           2, 14);
  227.   addToCell(&hourlyRate,         2, 15);
  228.   if ( !pActiveCheckBox )
  229.     addToCell(pPayRange,         3, 15,  5,  2);
  230.  
  231.   addToCell(&pageButtons,        2, 17,  7,  3);
  232.   setColumnWidth( 8, 0, true );
  233.  
  234.   return *this;
  235. }
  236.  
  237. //-----------------------------------------------------------------------------
  238. // CLASS StatusPage :: verifyAndSave() - save to status database (ini)
  239. //-----------------------------------------------------------------------------
  240. IBase :: Boolean StatusPage :: verifyAndSave( IString& theString
  241.                                              ,IString& theEntry
  242.                                              ,const IString& theName )
  243. {
  244.      // verify data
  245.  
  246.      if ((theName.length() == 0) &&
  247.          (Key.length()==0) || isAquery)
  248.         return true;
  249.  
  250.  
  251.     if ((theName.length() > 0 ) && (theName.isAlphanumeric()))
  252.         statusData.save( theName
  253.                         ,hourlyRate.text()
  254.                         ,startDate.text()
  255.                         ,endDate.text()
  256.                         ,(Boolean) checkBoxHandler.getToggle());
  257.     else
  258.       if ((Key.length() > 0 ) && (Key.isAlphanumeric()))
  259.           statusData.save( Key
  260.                          ,hourlyRate.text()
  261.                          ,startDate.text()
  262.                          ,endDate.text()
  263.                          ,(Boolean) checkBoxHandler.getToggle());
  264.  
  265.      return true;
  266. }
  267.  
  268.  
  269. //-----------------------------------------------------------------------------
  270. // CLASS StatusPage :: displayData() - populate page
  271. //-----------------------------------------------------------------------------
  272. StatusPage& StatusPage :: displayData()
  273. {
  274.    startDate.setText(statusData.statusStart() );
  275.    endDate.setText(statusData.statusEnd()    );
  276.    hourlyRate.setText(statusData.statusRate() );
  277.  
  278.    if (pActiveCheckBox) {
  279.       if ((statusData.statusActive() == "yes") ||
  280.           (statusData.statusActive() == "new"))  {
  281.          // the checkbox
  282.          pActiveCheckBox->select();
  283.          checkBoxHandler.setToggle(ACheckBoxHandler::true);
  284.       }
  285.       else {
  286.            pActiveCheckBox->deselect();
  287.            checkBoxHandler.setToggle(ACheckBoxHandler::false);
  288.       }
  289.    }
  290.    else {
  291.       // a query page
  292.       if (statusData.statusActive() == "yes")
  293.          pQueryActive->select();
  294.       else
  295.          pQueryActive->deselect();
  296.  
  297.       if (statusData.statusInactive() == "yes")
  298.          pQueryInactive->select();
  299.       else
  300.          pQueryInactive->deselect();
  301.  
  302.       if (statusData.theRateRange().length() > 0)
  303.          pPayRange->setRange(statusData.theRateRange());
  304.  
  305.       if (statusData.theStartRange().length() > 0)
  306.          pStartRange->setRange(statusData.theStartRange());
  307.  
  308.       if (statusData.theEndRange().length() > 0)
  309.          pEndRange->setRange(statusData.theEndRange());
  310.  
  311.  
  312.    }
  313.  
  314.    // for queryies
  315.    if (statusData.theRateRange().length() != 0)
  316.        pPayRange->setRange(statusData.theRateRange());
  317.  
  318.    if (statusData.theStartRange().length() != 0)
  319.       pStartRange->setRange(statusData.theStartRange());
  320.  
  321.    if (statusData.theEndRange().length() != 0)
  322.       pEndRange->setRange(statusData.theEndRange());
  323.  
  324.    return *this;
  325. }
  326.  
  327.  
  328.  
  329.  
  330. //-----------------------------------------------------------------------------
  331. // CLASS StatusPage :: command() - command handler
  332. //-----------------------------------------------------------------------------
  333. IBase :: Boolean StatusPage :: command(ICommandEvent &cmdEvent)
  334. {
  335.   switch (cmdEvent.commandId()) {       //Get command id
  336.  
  337.     case ID_BUTTON_UNDO:                       //Get the original data back
  338.       displayData();
  339.       return(true);                     //Return command processed
  340.       break;                            //
  341.  
  342.     case ID_BUTTON_HELP:
  343.        // Product Information processing
  344.        IHelpWindow::helpWindow( this )->show(
  345.            IResourceId( ID_STATUS_PAGE ) );
  346.        return true;
  347.  
  348.   } /* end switch */
  349.  
  350.   return(false);                        //Return command not processed
  351. }
  352.  
  353. //-----------------------------------------------------------------------------
  354. // CLASS StatusPage :: pageSettings() - notebook sizing
  355. //-----------------------------------------------------------------------------
  356. INotebook :: PageSettings StatusPage :: pageSettings()
  357. {
  358.    return thePageSettings;
  359. }
  360.  
  361.