home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12518.ZIP / MOU.C < prev    next >
Text File  |  1989-12-11  |  4KB  |  132 lines

  1. /* mou.c RHS 9/30/89
  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(!buttondown && IsMouButtonPressed(MouEvent)) // if mouse button pressed    
  66.             if(event = ButtonPressed(&MouEvent)) // while on screen button    
  67.                 {
  68.                 MsgQSend(qhandle,NULL,0,event);
  69.                 buttondown = TRUE;
  70.                 DosSleep(32L);
  71.                 continue;
  72.                 }
  73.         buttondown = FALSE;
  74.  
  75.         if(MouEvent.row >= dirrow)              // non-PM-like line:
  76.             continue;                           // protecting mouse buttons
  77.  
  78.         for( i = 0, mouse_moved = FALSE; i < numbuttons; i++)
  79.                                                 // if the button is down now
  80.             if(MouButtonPressed(MouEvent,buttons[i].mask))
  81.                 {
  82.                 if(!buttons[i].down)            // if button was previously up
  83.                     {
  84.                     MsgQSend(qhandle,&MouEvent,sizeof(MouEvent),buttons[i].downmsg);
  85.                     buttons[i].down = TRUE;
  86.                     }
  87.                     // if the button was previously down but the mouse moved
  88.                 else if(MouButtonPressed(MouEvent,buttons[i].movedmask))
  89.                     mouse_moved = TRUE;
  90.                 }
  91.             else                                // if button is not down now
  92.                 {
  93.                 if(buttons[i].down)             // if button previously down
  94.                     {
  95.                     MsgQSend(qhandle,&MouEvent,sizeof(MouEvent),buttons[i].upmsg);
  96.                     buttons[i].down = FALSE;
  97.                     }
  98.                 }
  99.     // notify of all mouse movement if button is down (PM gets all movement)
  100.         if(mouse_moved)
  101.             MsgQSend(qhandle,&MouEvent,sizeof(MouEvent),MSG_MOUSEMOVED);
  102.  
  103.         DosSleep(32L);
  104.         }
  105.  
  106.     MouClose(MouHandle);
  107.     }
  108.  
  109. USHORT ButtonPressed(MOUEVENTINFO *ev)
  110.     {
  111.     register USHORT row = ev->row, col = ev->col;
  112.     BUTTON    *b = &buttonlist[0];
  113.  
  114.     for( ; b->text; b++)
  115.         {
  116.         if((row >= b->startrow) && (row <= b->endrow) // if on button
  117.                 && (col >= b->startcol) && (col <= b->endcol))
  118.             
  119.             if(MouB1Pressed(ev->fs))
  120.                 return MOUSECODE(b->left_button_val);
  121.             else if(MouB2Pressed(ev->fs))
  122.                 return MOUSECODE(b->right_button_val);
  123.             else
  124.                 return 0;
  125.         }
  126.     return 0;
  127.     }
  128.  
  129.     /******* end of mouse thread code *************************/
  130.  
  131.  
  132.