home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / demos / mousedlg.cpp < prev    next >
C/C++ Source or Header  |  1998-01-19  |  3KB  |  152 lines

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