home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / pmics.zip / a2.cc < prev    next >
C/C++ Source or Header  |  1994-12-12  |  3KB  |  125 lines

  1. #include <iframe.hpp>
  2. #include <iapp.hpp>
  3. #include <icombobx.hpp>
  4. #include <imsgbox.hpp>
  5. #include <icolor.hpp>
  6. #include <ikeyhdr.hpp>
  7. #include <iedithdr.hpp>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #define IC_TRACE_DEVELOP
  11. #include <itrace.hpp>
  12.  
  13. class MyEditHandler : public IEditHandler
  14. {
  15. public:                               //Define the public Information
  16.   virtual Boolean         edit(IControlEvent &evt);
  17. };
  18.  
  19. class CommWindow : public IComboBox,
  20.            public IKeyboardHandler
  21. {
  22. public:                               //Define the public Information
  23.   CommWindow(unsigned long windowId, //Constructor for this class
  24.          IWindow *parent);
  25.   virtual Boolean         key(IKeyboardEvent &evt);
  26. private:
  27.   IEntryField  *ef;
  28.   MyEditHandler  *eh;
  29. };
  30.  
  31.  
  32. main()
  33. {
  34.   IFrameWindow *fw = new IFrameWindow(0x1000);
  35.   CommWindow *cbox = new CommWindow(0x1001,fw);
  36.   int i;
  37.  
  38.   fw->setClient(cbox);
  39.   fw->setFocus();
  40.   fw->show();
  41.  
  42.   for (i = 'a'; i <= 'z'; i++) {
  43.     cbox->addAsLast(IString((char)i) + " potatoe");
  44.   }
  45.  
  46.   IApplication::current().run();
  47. }
  48.  
  49. CommWindow::CommWindow(unsigned long windowId, //Constructor for this class
  50.                IWindow *parent) :
  51.              IComboBox (windowId, parent, parent, IRectangle(500,100),
  52.             IComboBox::classDefaultStyle &
  53.             ~(IComboBox::horizontalScroll))
  54. {
  55.   ef = (IEntryField*)IWindow::windowWithId(0x029B,this);
  56.   if (ef) {
  57.     ITRACE_DEVELOP("entry field found, using it");
  58.   }
  59.   else {
  60.     ITRACE_DEVELOP("entry field not found, creating one");
  61.     ef = new IEntryField(0x29b,this);
  62.   }
  63.  
  64.   eh = new MyEditHandler;
  65.  
  66.   handleEventsFor(ef);
  67.   eh->handleEventsFor(ef);
  68.   eh->handleEventsFor(this);
  69.   show();
  70. }
  71.  
  72. Boolean MyEditHandler::edit (IControlEvent &evt)
  73. {
  74.   IFUNCTRACE_DEVELOP();
  75.   return true;
  76. }
  77.  
  78.  
  79. Boolean CommWindow::key (IKeyboardEvent &evt)
  80. {
  81.   char c,s[2];
  82.  
  83.   IFUNCTRACE_DEVELOP();
  84.   ITRACE_DEVELOP("ef contents: " + ef->text());
  85.  
  86.   if (evt.isVirtual()) {
  87.     ITRACE_DEVELOP("vkey: " + IString((unsigned short)(evt.virtualKey())) +
  88.            " *" + IString(evt.repeatCount()));
  89.     switch(evt.virtualKey()) {
  90.     case IKeyboardEvent::backSpace:
  91.       if (ef->text() != "") {
  92.     ITRACE_DEVELOP("BS: deleting last character");
  93.     ef->setText(ef->text().remove(ef->text().length()));
  94.       }
  95.       return true;
  96.     }
  97.     return false;
  98.   }
  99.   
  100.   else if (evt.isCharacter()) {
  101.     ITRACE_DEVELOP("key: " + IString((unsigned short)(evt.character())));
  102.     if (evt.isRepeat() || evt.repeatCount() > 0)
  103.       ITRACE_DEVELOP("repeatCount = "+IString(evt.repeatCount())+
  104.              "isRepeat = "+IString(evt.repeatCount()));
  105.     c = evt.character();
  106.  
  107.     if (c == '\r'){
  108.       ITRACE_DEVELOP("CRLF: clearing entry field");
  109.       ef->setText("");
  110.     }
  111.     else if (c == 'w' && evt.isCtrlDown()) {
  112.       ITRACE_DEVELOP("CTRL-W: trying to remove last word");
  113.       ef->setText( ef->text().removeWords(ef->text().numWords()));
  114.     }
  115.     else {
  116.       ef->setText(IString(ef->text()) + IString(c));
  117.     }
  118.  
  119.     return true;   // inhibit listbox jump to line with first letter
  120.   }
  121.  
  122.   return false;
  123. }
  124.  
  125.