home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / s12628.zip / MOU.C < prev    next >
Text File  |  1990-07-01  |  4KB  |  138 lines

  1. /* mou.c
  2.  *
  3.  * mouse thread code for PMAccess
  4.  *
  5.  */
  6.  
  7. #define INCL_DOS
  8. #define INCL_SUB
  9. #include<os2.h>
  10. #include"mou.h"
  11. #include"moudefs.h"
  12. #include"msgq.h"
  13. #include"button.h"
  14. #include"msgs.h"
  15. #include"errexit.h"
  16.  
  17. extern long MouSem;
  18. extern PCHAR mainmsgqueue;
  19. extern BUTTON buttonlist[];
  20. extern USHORT dirrow;
  21.  
  22. typedef struct _moubuttons
  23.     {
  24.     USHORT    mask;
  25.     USHORT    movedmask;
  26.     USHORT    down;
  27.     USHORT    upmsg;
  28.     USHORT    downmsg;
  29.     } MOUBUTTONS;
  30.  
  31. MOUBUTTONS buttons[3] =
  32.         {
  33. { MOU_B1, MOUSE_MOTION_WITH_BN1_DOWN, FALSE, MSG_B1UP, MSG_B1DOWN },
  34. { MOU_B2, MOUSE_MOTION_WITH_BN2_DOWN, FALSE, MSG_B2UP, MSG_B2DOWN },
  35. { MOU_B3, MOUSE_MOTION_WITH_BN3_DOWN, FALSE, MSG_B3UP, MSG_B3DOWN }
  36.         };
  37.  
  38. USHORT ButtonPressed(MOUEVENTINFO *ev);
  39.  
  40. void MouThread(void)
  41.     {
  42.     MOUEVENTINFO MouEvent;
  43.     USHORT       WaitOption = MOU_WAIT;      // set to block on input
  44.     HQUEUE       qhandle;
  45.     USHORT       buttondown = FALSE, numbuttons,i;
  46.     USHORT       retval, mouse_moved,event;
  47.     HMOU         MouHandle;
  48.  
  49.     MsgQOpen(&qhandle,mainmsgqueue);
  50.  
  51.     if((retval = MouOpen((PSZ)NULL,(PHMOU)&MouHandle)))
  52.         error_exit(retval,"MouOpen");
  53.  
  54.     MouDrawPtr(MouHandle);                   // display mouse pointer
  55.     MouFlushQue(MouHandle);                  // flush mouse queue
  56.     MouGetNumButtons(&numbuttons,MouHandle); // get button count
  57.     DosSemClear(&MouSem);                    // notify main thread
  58.  
  59.     while(TRUE)
  60.         {                                       // read the queue
  61.         MouReadEventQue(&MouEvent,&WaitOption,MouHandle);
  62.         MouEventDropLowBit(MouEvent);      // turn off the low bit
  63.  
  64.             // notify if screen button pressed
  65.                                            // if mouse button pressed
  66.         if(!buttondown && IsMouButtonPressed(MouEvent))
  67.                                           // while on screen button
  68.             if(event = ButtonPressed(&MouEvent))
  69.                 {
  70.                 MsgQSend(qhandle,NULL,0,event);
  71.                 buttondown = TRUE;
  72.                 DosSleep(32L);
  73.                 continue;
  74.                 }
  75.         buttondown = FALSE;
  76.  
  77.         if(MouEvent.row >= dirrow)     // non-PM-like line:
  78.             continue;                  // protecting mouse buttons
  79.  
  80.         for( i = 0, mouse_moved = FALSE; i < numbuttons; i++)
  81.                                        // if the button is down now
  82.             if(MouButtonPressed(MouEvent,buttons[i].mask))
  83.                 {
  84.                 if(!buttons[i].down)   // if button was previously up
  85.                     {
  86.                     MsgQSend(qhandle,&MouEvent,sizeof(MouEvent),
  87.                              buttons[i].downmsg);
  88.                     buttons[i].down = TRUE;
  89.                     }
  90.                     // if button was previously down but mouse moved
  91.                 else if(MouButtonPressed(
  92.                         MouEvent,buttons[i].movedmask))
  93.                     mouse_moved = TRUE;
  94.                 }
  95.             else                       // if button is not down now
  96.                 {
  97.                 if(buttons[i].down)    // if button previously down
  98.                     {
  99.                     MsgQSend(qhandle,&MouEvent,sizeof(MouEvent),
  100.                              buttons[i].upmsg);
  101.                     buttons[i].down = FALSE;
  102.                     }
  103.                 }
  104.     // notify of all mouse movement if button is down
  105.     // (PM gets all movement)
  106.         if(mouse_moved)
  107.             MsgQSend(qhandle,&MouEvent,sizeof(MouEvent),
  108.                 MSG_MOUSEMOVED);
  109.  
  110.         DosSleep(32L);
  111.         }
  112.  
  113.     MouClose(MouHandle);
  114.     }
  115.  
  116. USHORT ButtonPressed(MOUEVENTINFO *ev)
  117.     {
  118.     register USHORT row = ev->row, col = ev->col;
  119.     BUTTON    *b = &buttonlist[0];
  120.  
  121.     for( ; b->text; b++)
  122.         {
  123.         if((row >= b->startrow) && (row <= b->endrow) // if on button
  124.                 && (col >= b->startcol) && (col <= b->endcol))
  125.  
  126.             if(MouB1Pressed(ev->fs))
  127.                 return MOUSECODE(b->left_button_val);
  128.             else if(MouB2Pressed(ev->fs))
  129.                 return MOUSECODE(b->right_button_val);
  130.             else
  131.                 return 0;
  132.         }
  133.     return 0;
  134.     }
  135.  
  136.     /******* end of mouse thread code *************************/
  137. 
  138.