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

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