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

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