home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / vlstde / demo1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-12  |  2.8 KB  |  142 lines

  1. // kid13.cpp            BROWSE DIALOG BOX
  2. //    written by Gregory K. Miskin
  3. //    COPYRIGHT (C) 1992.  All Rights Reserved.
  4. //    Gregory K. Miskin, Orem, Utah  USA
  5.  
  6. #define Uses_TEvent
  7. #define Uses_TScrollBar
  8. #define Uses_TListBox
  9. #define Uses_TDialog
  10. #define Uses_TKeys
  11. #define Uses_TProgram
  12. #define Uses_TDeskTop
  13. #define Uses_TButton
  14.  
  15. #include <tv.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include "commands.hpp"
  19. #include "structs.hpp"
  20. #include "demo2.hpp"
  21. #include "demo1.hpp"
  22.  
  23. short screenSize = 18;
  24.  
  25. /*------------------------------------------------------------------------*/
  26. TBrowseNames::TBrowseNames() :
  27.         TDialog(TRect(0, 0, 80, 23), "Browse Names"),
  28.         TWindowInit(&TBrowseNames::initFrame)
  29. {
  30.     TRect r = getClipRect();
  31.     r.grow(-1,-1);
  32.     r.b.y = r.b.y -1;
  33.     r.b.x = r.b.x -1;
  34.  
  35.     vbar = new TScrollBar(TRect (78,1,79,21));
  36.     hbar = new TScrollBar(TRect (1,21,78,22));
  37.  
  38.     vbar->setStep(screenSize, 1);
  39.     hbar->maxVal = 28;
  40.     hbar->setStep(28, 1);
  41.     hbar->setValue(0);
  42.  
  43.     listBox = new VListBox(r, 1, hbar, vbar);
  44.     insert(listBox);
  45.     insert(vbar);
  46.     insert(hbar);
  47.  
  48.     options |= ofCentered;
  49. }
  50.  
  51. /*------------------------------------------------------------------------*/
  52. void TBrowseNames::handleEvent(TEvent &event)
  53. {
  54.      TDialog::handleEvent(event);
  55.  
  56.      switch(event.what)
  57.      {
  58.         case evCommand:
  59.             switch(event.message.command)
  60.             {
  61.                 default:
  62.                     break;
  63.             }
  64.             break;
  65.  
  66.         case evKeyDown:
  67.             switch(event.keyDown.keyCode)
  68.             {
  69.                 case kbRight:
  70.                     if(hbar->value <= hbar->maxVal)
  71.                     {
  72.                         int val = hbar->value + 1;
  73.                         hbar->setValue(val);
  74.                     }
  75.                     break;
  76.  
  77.                 case kbLeft:
  78.                     if(hbar->value > 0)
  79.                     {
  80.                         int val = hbar->value - 1;
  81.                         hbar->setValue(val);
  82.                     }
  83.                     break;
  84.  
  85.                 case kbCtrlRight:
  86.                     if(hbar->value <= hbar->maxVal)
  87.                     {
  88.                         int val = hbar->maxVal;
  89.                         hbar->setValue(val);
  90.                     }
  91.                     break;
  92.  
  93.                 case kbCtrlLeft:
  94.                     if(hbar->value > 0)
  95.                     {
  96.                         int val = 0;
  97.                         hbar->setValue(val);
  98.                     }
  99.                     break;
  100.  
  101.                 case kbAltF3:
  102.                     event.what = evCommand;
  103.                     event.message.command = cmCancel;
  104.                     event.message.infoPtr = 0;
  105.                     putEvent(event);
  106.                     break;
  107.  
  108.                 default:
  109.                     break;
  110.             }
  111.             break;
  112.  
  113.         case evBroadcast:
  114.             if(event.message.command == cmDefault)
  115.                 EditRecord();
  116.             break;
  117.  
  118.         default:
  119.             return;
  120.     }
  121. }
  122.  
  123. /*------------------------------------------------------------------------*/
  124. void TBrowseNames::EditRecord()
  125. {
  126.     long currRecord;
  127.     int recPos = 0;
  128.  
  129.     long item = listBox->focused;
  130.     currRecord = listBox->GetRecord(item);
  131.     status = listBox->cBase->close_all();
  132.  
  133.     edit_record = new TEditRecord(currRecord);
  134.     TProgram::deskTop->execView(edit_record);
  135.     destroy(edit_record);
  136.  
  137.     listBox->OpenFiles();
  138.     listBox->name->top();
  139.     listBox->name->skip(item);
  140.     listBox->draw();
  141. }
  142.