home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Zone / VRZONE.ISO / mac / PC / PCGLOVE / GLOVE / OBJGLV.ZIP / SRC / MOUSGEST.CPP < prev    next >
C/C++ Source or Header  |  1993-05-12  |  4KB  |  133 lines

  1. //
  2. // MousGest.cpp:
  3. //    Implementation of class GloveMouseGestures.
  4. //    Example use of Object Glove and Court Jesture.
  5. //
  6. // Purpose:
  7. //    Sends messages to other windows to emulate mouse clicks.
  8. //    DOES NOT ALWAYS WORK!  I'm not sure why, I guess
  9. //    I need to send more $$ to Bill Gates or something.
  10. //
  11. // Compatibility:
  12. //    Windows only!
  13. //
  14. // Copyright 1993   Mark Thomas Pflaging
  15. //
  16. // Date:    3/22/93 (Release 3.0)
  17. //
  18. // Copyright 1993, Mark T. Pflaging
  19. #include "mousgest.hpp"
  20.  
  21. TApplication * GloveMouseGestures::app;
  22. POINT * GloveMouseGestures::position;
  23.  
  24. void GloveMouseGestures::Init(InitFile & ini, TApplication * here, char * sectionName)
  25. {
  26.     setName(sectionName);
  27.     app = here;
  28.         suspended = False;
  29.     addId(ini.find(sectionName, "LeftButtonDown", "100 1 X X X X X *2 X X X"), LeftButtonDown);
  30.     addId(ini.find(sectionName, "LeftButtonDoubleClick", "100 1 X X X X X *0 X X X"), LeftButtonDoubleClick);
  31.     addId(ini.find(sectionName, "RightButtonDown", "100 1 X X X X X X *2 X X"), RightButtonDown);
  32.     addId(ini.find(sectionName, "RightButtonDoubleClick", "100 1 X X X X X X *0 X X"), RightButtonDoubleClick);
  33.     addId(ini.find(sectionName, "Suspend", "100 1 X X X X X X X X Start"), Suspend);
  34.     addId(ini.find(sectionName, "Quit", "100 1 X X X X X X X X 9"), Quit);
  35. /***
  36.     for (int i = 0; i <= Twist; i ++) {
  37.         statusBits[i] = False;
  38.     }
  39. ***/
  40. }
  41.  
  42. BOOL GloveMouseGestures::MyPostMessage(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
  43. {
  44.     if ((hwnd == (app->MainWindow)->HWindow) || suspended) return False;
  45.         return (PostMessage(hwnd, umsg, wParam, lParam));
  46. }
  47.  
  48. void GloveMouseGestures::Register(Gesture & arg, Boolean onOrOff)
  49. {
  50.     static HWND lold_where, rold_where;
  51.     NumberedGestSet::Register(arg, onOrOff);
  52.     NumberedGesture & found = (NumberedGesture &)arg;
  53.     HWND where = WindowFromPoint(*position);
  54.     if (onOrOff) {
  55.         // Figure out what part of the window
  56.         // the cursor is now in.
  57.         LRESULT wParam = SendMessage(where, WM_NCHITTEST, 0, MAKELPARAM((WORD)position->x, (WORD)position->y));
  58.         switch (MouseGests(found.getId())) {
  59.         case LeftButtonDown:
  60.             lold_where = where;
  61.             SetActiveWindow(where);
  62.             if ((wParam == HTCLIENT)) {
  63.                 ScreenToClient(where, position);
  64.                 MyPostMessage(where, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(
  65.                     (WORD)(position->x), (WORD)(position->y)
  66.                 ));
  67.             }
  68.                         else {
  69.                 MyPostMessage(where, WM_NCLBUTTONDOWN, wParam, MAKELPARAM((WORD)position->x, (WORD)position->y));
  70.             }
  71.                         break;
  72.         case RightButtonDown:
  73.             rold_where = where;
  74.             SetActiveWindow(where);
  75.             if ((wParam == HTCLIENT)) {
  76.                 ScreenToClient(where, position);
  77.                 MyPostMessage(where, WM_RBUTTONDOWN,MK_RBUTTON, MAKELPARAM(
  78.                     (WORD)(position->x), (WORD)(position->y)
  79.                 ));
  80.             }
  81.                         else {
  82.                 MyPostMessage(where, WM_NCRBUTTONDOWN, wParam, MAKELPARAM((WORD)position->x, (WORD)position->y));
  83.             }
  84.             break;
  85.         case LeftButtonDoubleClick:
  86.             SetActiveWindow(where);
  87.             if ((wParam == HTCLIENT)) {
  88.                 ScreenToClient(where, position);
  89.                 MyPostMessage(where, WM_LBUTTONDBLCLK, MK_LBUTTON, MAKELPARAM(
  90.                     (WORD)(position->x), (WORD)(position->y)
  91.                 ));
  92.             }
  93.                         else {
  94.                 MyPostMessage(where, WM_NCLBUTTONDBLCLK, wParam, MAKELPARAM((WORD)position->x, (WORD)position->y));
  95.             }
  96.                         break;
  97.         case RightButtonDoubleClick:
  98.             SetActiveWindow(where);
  99.             if ((wParam == HTCLIENT)) {
  100.                 ScreenToClient(where, position);
  101.                 MyPostMessage(where, WM_RBUTTONDBLCLK, MK_RBUTTON, MAKELPARAM(
  102.                     (WORD)(position->x), (WORD)(position->y)
  103.                 ));
  104.             }
  105.                         else {
  106.                 MyPostMessage(where, WM_NCRBUTTONDBLCLK, wParam, MAKELPARAM((WORD)position->x, (WORD)position->y));
  107.             }
  108.                         break;
  109.         case Suspend:
  110.             suspended = (suspended ? False : True);
  111.             break;
  112.         case Quit:
  113.             PostMessage((app->MainWindow)->HWindow, WM_CLOSE, 0, 0L);
  114.         }
  115.     }
  116.     if (!onOrOff) {
  117.         switch (MouseGests(found.getId())) {
  118.                 case LeftButtonDown:
  119.             ScreenToClient(where, position);
  120.             MyPostMessage(lold_where, WM_LBUTTONUP,(WPARAM)0, MAKELPARAM(
  121.                 (WORD)(position->x), (WORD)(position->y)
  122.             ));
  123.                 break;
  124.         case RightButtonDown:
  125.             ScreenToClient(where, position);
  126.             MyPostMessage(rold_where, WM_RBUTTONUP,(WPARAM)0, MAKELPARAM(
  127.                 (WORD)(position->x), (WORD)(position->y)
  128.             ));
  129.             break;
  130.         }
  131.     }
  132. }
  133.