home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / NOTEPAD2.ZIP / MMOUSE.C < prev    next >
C/C++ Source or Header  |  1989-02-08  |  4KB  |  112 lines

  1. /*
  2.  * mmouse.c -- Mouse management
  3.  *
  4.  * Created by Microsoft Corporation, 1989
  5.  */
  6.  
  7. #define INCL_WIN
  8. #include <os2.h>
  9. #include "mtypes.h"
  10. #include "mfuncs.h"
  11.  
  12. /* public function
  13.  *
  14.  * VOID MouseInit(PED ped)
  15.  *
  16.  * Initializes the mouse manager.
  17.  */
  18.  
  19. public VOID MouseInit(PED ped)
  20. {
  21.         ped->fMouseDown = ped->fMouseScroll = FALSE;
  22. }
  23.  
  24. /* public function
  25.  *
  26.  * VOID ProcessMouse (PED ped, USHORT nMessage, SHORT x, SHORT y)
  27.  *
  28.  * Responds to any mouse message (from WM_MOUSEFIRST to WM_MOUSELAST) sent
  29.  * to the MLE window procedure.  x and y are the SIGNED low and high words
  30.  * of mparam1, respectively.
  31.  *
  32.  * This routine also receives WM_TIMER messages from the TID_MOUSESCROLL
  33.  * timer, which is responsible for autoscroll when the mouse is dragged out of
  34.  * the window.
  35.  *
  36.  * Except for buttons 1 and 2 and mouse movement, all mouse messages are
  37.  * ignored.
  38.  */
  39.  
  40. public VOID ProcessMouse (PED ped, USHORT nMessage, SHORT x, SHORT y)
  41. {
  42.     BOOL fOutside;
  43.  
  44.     fOutside = ((x <= 0) ||
  45.                 (y <= 0) ||
  46.                 (x >= (SHORT) ped->rclWnd.xRight-1) ||
  47.                 (y >= (SHORT) ped->rclWnd.yTop-1));
  48.  
  49.     switch (nMessage) {
  50.  
  51.         case WM_BUTTON2DOWN:         // right button sets focus only
  52.             WinSetFocus(HWND_DESKTOP, ped->hwnd);
  53.             break;
  54.  
  55.         case WM_BUTTON1DOWN:
  56.             ped->fMouseDown = TRUE;
  57.             WinSetFocus(HWND_DESKTOP, ped->hwnd);
  58.             WinSetCapture(HWND_DESKTOP, ped->hwnd);
  59.             DispSetCursorXY(ped,x,y,WinGetKeyState(HWND_DESKTOP,VK_SHIFT)<0,
  60.                             FALSE);
  61.             break;
  62.  
  63.         case WM_BUTTON1UP:
  64.             if (ped->fMouseDown) {
  65.                 ped->fMouseDown = FALSE;
  66.                 WinSetCapture (HWND_DESKTOP, NULL);
  67.             }
  68.             if (ped->fMouseScroll) {
  69.                 ped->fMouseScroll = !(WinStopTimer((HAB)NULL,
  70.                                        ped->hwnd, TID_MOUSESCROLL));
  71.             }
  72.             break;
  73.  
  74.         case WM_TIMER:
  75.             if (! ped->fMouseDown)
  76.                  return;
  77.             // otherwise fall through
  78.  
  79.         case WM_MOUSEMOVE:
  80.             if (!ped->fMouseDown) {
  81.                 WinSetPointer(HWND_DESKTOP,
  82.                                WinQuerySysPointer(HWND_DESKTOP,
  83.                                       fOutside ? SPTR_ARROW : SPTR_TEXT,
  84.                                       FALSE));
  85.             }
  86.             if (ped->fMouseDown) {                // dragging cursor
  87.                 DispSetCursorXY(ped, x, y, TRUE, FALSE);
  88.                 if (fOutside != ped->fMouseScroll) {
  89.                     // If we moved into or out of the window, start or stop
  90.                     // the scroll timer.  If we succeed, record the change
  91.                     // in ped;  otherwise, we'll try
  92.                     // again the next time we get this message.
  93.                     if (fOutside) {
  94.                         ped->fMouseScroll = WinStartTimer((HAB)NULL, ped->hwnd,
  95.                             TID_MOUSESCROLL, (USHORT) WinQuerySysValue(
  96.                                          HWND_DESKTOP, SV_SCROLLRATE));
  97.                     } else {
  98.                         ped->fMouseScroll = !(WinStopTimer((HAB)NULL,
  99.                                                  ped->hwnd, TID_MOUSESCROLL));
  100.                     }
  101.                 }
  102.             }
  103.             break;
  104.  
  105.         case WM_BUTTON1DBLCLK:   // select a word
  106.             DispSetCursorXY(ped,x,y,WinGetKeyState(HWND_DESKTOP,VK_SHIFT)<0,
  107.                             TRUE);
  108.             break;
  109.         }
  110. }
  111.  
  112.