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

  1. /*******************************************************************************
  2. * FILE NAME: lbadge.cpp                                                        *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *                                                                              *
  6. * Classes                                                                      *
  7. *   BadgeCnrObj                                                                *
  8. *   BadgePage                                                                  *
  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.  
  27. #include "lbadge.hpp"
  28.  
  29. //--------------------------------------------------------------------------
  30. //  CLASS BadgePage - BadgePage - constructor
  31. //--------------------------------------------------------------------------
  32. BadgePage :: BadgePage(IWindow* pParent,
  33.                        const IString& aKey)
  34.           : IMultiCellCanvas(ID_BADGE_PAGE, pParent, pParent),
  35.             badgeData(aKey),
  36.             pageButtons( ID_BADGE_PAGE_BUTTONS,
  37.                          this, this, false),
  38.             pIssueRange(NULL),
  39.             pExpRange(NULL),
  40.             badgeNumberText(ID_NO_ITEM, this, this ),
  41.             issueDateText(ID_NO_ITEM, this, this ),
  42.             expDateText(ID_NO_ITEM, this, this ),
  43.             BadgeNumber(ID_BDG_BADGE_NUMBER_EF, this, this,
  44.                         IRectangle(),
  45.                         IEntryField::classDefaultStyle |
  46.                         IControl::tabStop),
  47.             IssueDate(ID_BDG_ISSUE_DATE_EF, this, this,
  48.                       IRectangle(),
  49.                       IEntryField::classDefaultStyle |
  50.                       IControl::tabStop),
  51.             ExpDate(ID_BDG_EXP_DATE_EF, this, this,
  52.                     IRectangle(),
  53.                     IEntryField::classDefaultStyle |
  54.                     IControl::tabStop),
  55.             Key(aKey),
  56.             thePageSettings( IApplication::current().userResourceLibrary().loadString(
  57.                               STR_BDG_BADGE_TAB), NULL,
  58.                               INotebook::PageSettings::autoPageSize
  59.                             | INotebook::PageSettings::majorTab ),
  60. #ifdef IC_MOTIF
  61.                dateHandler(this, TEST_DATE),
  62. #endif
  63.             isAquery(false)
  64. {
  65.    badgeNumberText.setText( STR_BDG_BADGE_NUMBER);
  66.    issueDateText.setText(   STR_BDG_ISSUE_DATE  );
  67.    expDateText.setText(     STR_BDG_EXP_DATE    );
  68.  
  69.    BadgeNumber.setLimit(DISPLAY_LIMIT);
  70.    IssueDate.setLimit(DISPLAY_LIMIT);
  71.    ExpDate.setLimit(DISPLAY_LIMIT);
  72.  
  73.    displayData();
  74.    setCells();
  75.    handleIt();
  76. }
  77.  
  78. //--------------------------------------------------------------------------
  79. //  CLASS BadgePage - BadgePage - constructor
  80. //--------------------------------------------------------------------------
  81. BadgePage :: BadgePage(IWindow* pParent, LQueryData& qd)
  82.           : IMultiCellCanvas(ID_BADGE_PAGE, pParent, pParent),
  83.             badgeData(qd),
  84.             pageButtons( ID_BADGE_PAGE_BUTTONS,
  85.                          this, this, true),
  86.             pIssueRange(NULL),
  87.             pExpRange(NULL),
  88.             badgeNumberText(ID_NO_ITEM, this, this ),
  89.             issueDateText(ID_NO_ITEM, this, this ),
  90.             expDateText(ID_NO_ITEM, this, this ),
  91.             BadgeNumber(ID_BDG_BADGE_NUMBER_EF, this, this ),
  92.             IssueDate(ID_BDG_ISSUE_DATE_EF, this, this ),
  93.             ExpDate(ID_BDG_EXP_DATE_EF, this, this ),
  94.             Key(qd.queryName()),
  95.             thePageSettings( IApplication::current().userResourceLibrary().loadString(
  96.                               STR_BDG_BADGE_TAB), NULL,
  97.                               INotebook::PageSettings::autoPageSize
  98.                             | INotebook::PageSettings::majorTab ),
  99. #ifdef IC_MOTIF
  100.                dateHandler(this, TEST_DATE),
  101. #endif
  102.             isAquery(true)
  103. {
  104.    badgeNumberText.setText( STR_BDG_BADGE_NUMBER);
  105.    issueDateText.setText(   STR_BDG_ISSUE_DATE  );
  106.    expDateText.setText(     STR_BDG_EXP_DATE    );
  107.  
  108.    BadgeNumber.setLimit(DISPLAY_LIMIT);
  109.    IssueDate.setLimit(DISPLAY_LIMIT);
  110.    ExpDate.setLimit(DISPLAY_LIMIT);
  111.  
  112.    pIssueRange = new QueryRange( ID_BADGE_PAGE_RANGE_EF1
  113.                                    , this
  114.                                    , this
  115.                                    , ID_BADGE_RANGE_1);
  116.  
  117.    pExpRange = new QueryRange( ID_BADGE_PAGE_RANGE_EF2
  118.                                  , this
  119.                                  , this
  120.                                  , ID_BADGE_RANGE_2);
  121.  
  122.    displayData();
  123.    setCells();
  124.    handleIt();
  125. }
  126.  
  127. //--------------------------------------------------------------------------
  128. // CLASS BadgePage- ~BadgePage - destructor
  129. //--------------------------------------------------------------------------
  130. BadgePage :: ~BadgePage()
  131. {
  132.    ICommandHandler::stopHandlingEventsFor( &pageButtons );
  133.    ISelectHandler::stopHandlingEventsFor( &pageButtons );
  134. #ifdef IC_MOTIF
  135.   dateHandler.stopHandlingEventsFor( &IssueDate );
  136.   dateHandler.stopHandlingEventsFor( &ExpDate );
  137. #endif
  138. }
  139.  
  140.  
  141. //--------------------------------------------------------------------------
  142. // CLASS BadgePage- setCells()   set up multi cell
  143. //--------------------------------------------------------------------------
  144. BadgePage&  BadgePage :: setCells()
  145. {
  146.    addToCell(&badgeNumberText, 2,  2);
  147.    addToCell(&BadgeNumber    , 2,  3);
  148.  
  149.    addToCell(&issueDateText  , 2,  5);
  150.    addToCell(&IssueDate      , 2,  6);
  151.  
  152.    if (pIssueRange != NULL)
  153.        addToCell(pIssueRange,  3,  6,  5,  3);
  154.  
  155.    addToCell(&expDateText    , 2,  8);
  156.    addToCell(&ExpDate        , 2,  9);
  157.  
  158.    if (pExpRange != NULL)
  159.       addToCell(pExpRange,     3,  9,  5,  3);
  160.  
  161.    addToCell(&pageButtons,     2, 12,  7,  3);
  162.    setColumnWidth( 8, 0, true );
  163.  
  164.    return *this;
  165. }
  166.  
  167. //*****************************************************************************
  168. // CLASS BadgePage :: handleIt()
  169. //*****************************************************************************
  170. BadgePage&  BadgePage :: handleIt()
  171. {
  172.    ICommandHandler::handleEventsFor( &pageButtons );
  173.    ISelectHandler::handleEventsFor( &pageButtons );
  174. #ifdef IC_MOTIF
  175.    if (!isAquery) {
  176.       dateHandler.handleEventsFor( &IssueDate);
  177.       dateHandler.handleEventsFor( &ExpDate);
  178.    }
  179. #endif
  180.    return *this;
  181. }
  182.  
  183. //--------------------------------------------------------------------------
  184. // CLASS BadgePage- verifyAndSave()  save database info
  185. //--------------------------------------------------------------------------
  186. IBase :: Boolean BadgePage :: verifyAndSave( IString& theString,
  187.                                              IString& theEntry,
  188.                                              const IString& theName )
  189. {
  190.  
  191.   // verify input
  192.  
  193.     if ((theName.length() == 0) && (Key.length() == 0)
  194.        || isAquery)
  195.        return true;
  196.  
  197.     if ((theName.length() > 0 ) && (theName.isAlphanumeric()))
  198.        badgeData.save( theName
  199.                     ,BadgeNumber.text()
  200.                     ,IssueDate.text()
  201.                     ,ExpDate.text() ) ;
  202.     else
  203.       if ((Key.length() > 0 ) && (Key.isAlphanumeric()))
  204.          badgeData.save( Key
  205.                     ,BadgeNumber.text()
  206.                     ,IssueDate.text()
  207.                     ,ExpDate.text() ) ;
  208.  
  209.      return (true);
  210. }
  211.  
  212.  
  213.  
  214. //--------------------------------------------------------------------------
  215. // CLASS BadgePage- displayData()  data to page
  216. //--------------------------------------------------------------------------
  217. BadgePage&  BadgePage :: displayData()
  218. {
  219.  
  220.    BadgeNumber.setText(badgeData.badgeNumber() );
  221.    IssueDate.setText(badgeData.badgeIssue()    );
  222.    ExpDate.setText(badgeData.badgeExpire()    );
  223.  
  224.  
  225.    if (badgeData.theIssueRange().length()  != 0)
  226.       pIssueRange->setRange(badgeData.theIssueRange());
  227.  
  228.    if (badgeData.theExpRange().length()  != 0)
  229.       pExpRange->setRange(badgeData.theIssueRange());
  230.  
  231.    return *this;
  232. }
  233.  
  234.  
  235.  
  236. //--------------------------------------------------------------------------
  237. // CLASS BadgePage- command()
  238. //--------------------------------------------------------------------------
  239. IBase :: Boolean BadgePage :: command(ICommandEvent &cmdEvent)
  240. {
  241.  
  242.   switch (cmdEvent.commandId()) {       //Get command id
  243.  
  244.     case ID_BUTTON_UNDO:                       //Get the original data back
  245.       this->displayData();
  246.       return(true);                     //Return command processed
  247.       break;                            //
  248.  
  249.     case ID_BUTTON_HELP:
  250.        // Product Information processing
  251.        IHelpWindow::helpWindow( this )->show(
  252.            IResourceId( ID_BADGE_PAGE ) );
  253.        return true;
  254.  
  255.   } /* end switch */                    //
  256.  
  257.   return(false);                        //Return command not processed
  258.  
  259. }
  260.  
  261.  
  262. //--------------------------------------------------------------------------
  263. // CLASS BadgePage- pageSettings - notebook sizing
  264. //--------------------------------------------------------------------------
  265. INotebook :: PageSettings BadgePage :: pageSettings()
  266. {
  267.    return thePageSettings;
  268. }
  269.  
  270.