home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / TVDEMOS.ZIP / MOUSEDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.4 KB  |  144 lines

  1. /*---------------------------------------------------------*/
  2. /*                                                         */
  3. /*   Turbo Vision 1.0                                      */
  4. /*   Copyright (c) 1991 by Borland International           */
  5. /*                                                         */
  6. /*   Mousedlg.cpp : Member functions of following classes: */
  7. /*                     TClickTester                        */
  8. /*                     TMouseDialog                        */
  9. /*---------------------------------------------------------*/
  10.  
  11. #define Uses_TRect
  12. #define Uses_TStaticText
  13. #define Uses_TEvent
  14. #define Uses_TDrawBuffer
  15. #define Uses_TDialog
  16. #define Uses_TLabel
  17. #define Uses_TScrollBar
  18. #define Uses_TCheckBoxes
  19. #define Uses_TButton
  20. #define Uses_TSItem
  21. #define Uses_TEventQueue
  22. #include <tv.h>
  23.  
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <ctype.h>
  27. #include <strstrea.h>
  28. #include <iomanip.h>
  29.  
  30. #include "mousedlg.h"
  31.  
  32.  
  33. #define cpMousePalette "\x07\x08"
  34.  
  35.  
  36. //
  37. // TClickTester functions
  38. //
  39.  
  40. TClickTester::TClickTester(TRect& r, char *aText) :
  41.     TStaticText(r, aText)
  42. {
  43.     clicked = 0;
  44. }
  45.  
  46.  
  47. TPalette& TClickTester::getPalette() const
  48. {
  49.     static TPalette palette( cpMousePalette, sizeof(cpMousePalette)-1 );
  50.     return palette;
  51. }
  52.  
  53.  
  54. void TClickTester::handleEvent(TEvent& event)
  55. {
  56.     TStaticText::handleEvent(event);
  57.  
  58.     if (event.what == evMouseDown)
  59.         {
  60.         if (event.mouse.doubleClick)
  61.             {
  62.             clicked = (clicked) ? 0 : 1;
  63.             drawView();
  64.             }
  65.         clearEvent(event);
  66.         }
  67. }
  68.  
  69.  
  70. void TClickTester::draw()
  71. {
  72.     TDrawBuffer buf;
  73.     char c;
  74.  
  75.     if (clicked)
  76.         c = getColor(2);
  77.     else
  78.         c = getColor(1);
  79.  
  80.     buf.moveChar(0, ' ', c, size.x);
  81.     buf.moveStr(0, text, c);
  82.     writeLine(0, 0, size.x, 1, buf);
  83. }
  84.  
  85.  
  86. //
  87. // TMouseDialog functions
  88. //
  89.  
  90. TMouseDialog::TMouseDialog() :
  91.     TDialog( TRect(0, 0, 34, 12), "Mouse options" ),
  92.     TWindowInit( &TMouseDialog::initFrame )
  93. {
  94.     TRect r(3, 4, 30, 5);
  95.  
  96.     options |= ofCentered;
  97.  
  98.     mouseScrollBar = new TScrollBar(r);
  99.     mouseScrollBar->setParams(1, 1, 20, 20, 1);
  100.     mouseScrollBar->options |= ofSelectable;
  101.     mouseScrollBar->setValue(TEventQueue::doubleDelay);
  102.     insert(mouseScrollBar);
  103.  
  104.     r = TRect(2, 2, 21, 3);
  105.     insert(new TLabel(r, "~M~ouse double click", mouseScrollBar));
  106.  
  107.     r = TRect(3, 3, 30, 4);
  108.     insert(new TClickTester(r, "Fast       Medium      Slow"));
  109.  
  110.     r = TRect(3, 6, 30, 7);
  111.     insert(new TCheckBoxes(r, new TSItem("~R~everse mouse buttons", NULL)));
  112.     oldDelay = TEventQueue::doubleDelay;
  113.  
  114.     r = TRect(9, 9, 19, 11);
  115.     insert(new TButton(r, "O~K~", cmOK, bfDefault));
  116.  
  117.     r = TRect(21, 9, 31, 11);
  118.     insert(new TButton(r, "Cancel", cmCancel, bfNormal));
  119.  
  120.     selectNext( (Boolean) 0);
  121. }
  122.  
  123.  
  124. void TMouseDialog::handleEvent(TEvent& event)
  125. {
  126.     TDialog::handleEvent(event);
  127.     switch(event.what)
  128.         {
  129.         case evCommand:
  130.             if(event.message.command == cmCancel)
  131.                 TEventQueue::doubleDelay = oldDelay;
  132.             break;
  133.  
  134.         case evBroadcast:
  135.             if(event.message.command == cmScrollBarChanged)
  136.                 {
  137.                 TEventQueue::doubleDelay = mouseScrollBar->value;
  138.                 clearEvent(event);
  139.                 }
  140.             break;
  141.         }
  142. }
  143.  
  144.