home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / calculat / cppwv13 / imykybrd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  5.4 KB  |  115 lines

  1. /******************************************************************************
  2. * .FILE:        imykybrd.cpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION: Implementation for the class, ICaptureMyKeys                  *
  5. *                                                                             *
  6. * .CLASSES:     ICaptureMyKeys                                                *
  7. *                                                                             *
  8. * .COPYRIGHT:                                                                 *
  9. *    Licensed Material - Program-Property of IBM                              *
  10. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  11. *                                                                             *
  12. * .DISCLAIMER:                                                                *
  13. *   The following [enclosed] code is sample code created by IBM               *
  14. *   Corporation.  This sample code is not part of any standard IBM product    *
  15. *   and is provided to you solely for the purpose of assisting you in the     *
  16. *   development of your applications.  The code is provided 'AS IS',          *
  17. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  18. *   arising out of your use of the sample code, even if they have been        *
  19. *   advised of the possibility of such damages.                               *
  20. *                                                                             *
  21. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  22. *                                                                             *
  23. ******************************************************************************/
  24.  
  25. #include <istring.hpp>
  26. #include <ikeyevt.hpp>   // IKeyboardEvent
  27. #include <ikeyhdr.hpp>   // IKeyboardHandler
  28.  
  29. #ifndef _ITRACE_
  30. #include <itrace.hpp>
  31. #endif
  32.  
  33. #ifndef _IPUSHBUT_
  34. #include <ipushbut.hpp>
  35. #endif
  36.  
  37. #include "ikeypad.hpp"    // IKeypad class header
  38. #include "imykybrd.hpp"   // ICaptureMyKeys class header
  39.  
  40. //***************************************************************************
  41. // Override the characterKeyPress of the IKeyboardHandler class to
  42. // capture the + - * / = keys and pass the rest of the keys on
  43. // to be processed by someone else.
  44. //***************************************************************************
  45.  
  46. ICaptureMyKeys :: ICaptureMyKeys(IPushButton & ipluspb, IPushButton & isubpb,
  47.                                  IPushButton & imultpb, IPushButton & idivpb,
  48.                                  IPushButton & iequalpb,IKeypad & ikeypad) :
  49.                                  PlusPB(ipluspb), MinusPB(isubpb),
  50.                                  MultiplicationPB(imultpb), DivisionPB(idivpb),
  51.                                  EqualPB(iequalpb),Keypad(ikeypad)
  52.  
  53. {}                                    // constructor
  54.  
  55. ICaptureMyKeys :: ~ICaptureMyKeys()   // destructor
  56. {}
  57.  
  58. Boolean  ICaptureMyKeys::characterKeyPress(IKeyboardEvent& keyevt)
  59. {
  60.   // valid keys are: 0-9,+,-,*,/,=
  61.   Boolean bRc = true;         // assume non-numeric key to start with
  62.  
  63.   IFUNCTRACE_DEVELOP();
  64.   ITRACE_DEVELOP("captured key: "+ IString(keyevt.character()));
  65.  
  66.     switch (keyevt.character())
  67.       {
  68.         case '0':
  69.         case '1':
  70.         case '2':
  71.         case '3':
  72.         case '4':
  73.         case '5':
  74.         case '6':
  75.         case '7':
  76.         case '8':
  77.         case '9': /* let cases for 0-9 fall through here */
  78.                   Keypad.setDigit(keyevt.character()); // set the digit in the keypad
  79.                                                        // this kicks off the notifications
  80.                                                        // and the rest of the calculator
  81.                                                        // code takes over the processing
  82.                                                        // of this keyevent
  83.                   keyevt.setResult(true);              // mark key as not processed
  84.                   ITRACE_DEVELOP("captured key: "+ IString(keyevt.character()));
  85.                   break;
  86.         case '+': keyevt.setResult(true);       /* mark key as processed */
  87.                   PlusPB.click();
  88.                   ITRACE_DEVELOP("captured key: "+ IString(keyevt.character()));
  89.                   break;
  90.         case '-': keyevt.setResult(true);     /*mark key as processed */
  91.                   MinusPB.click();
  92.                   ITRACE_DEVELOP("captured key: "+ IString(keyevt.character()));
  93.                   break;
  94.         case '*': keyevt.setResult(true);
  95.                   MultiplicationPB.click();
  96.                   ITRACE_DEVELOP("captured key: "+  IString(keyevt.character()));
  97.                   break;
  98.         case '/': keyevt.setResult(true);
  99.                   DivisionPB.click();
  100.                   break;
  101.         case '=': keyevt.setResult(true);
  102.                   EqualPB.click();
  103.                   ITRACE_DEVELOP("captured key: "+ IString(keyevt.character()));
  104.                   break;
  105.         default:  // DosBeep(100, 100);        // inform the user and eat the key
  106.                   // MessageBeep (0);
  107.                   keyevt.setResult(false);   // pass event on
  108.                   ITRACE_DEVELOP("default=captured key: "+IString(keyevt.character()));
  109.                   break;
  110.       }
  111.  
  112.     return bRc;
  113. }
  114.  
  115.