home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / tess / tess-1.0 / MouseTracker.m < prev    next >
Encoding:
Text File  |  1992-06-30  |  2.5 KB  |  142 lines

  1. /*
  2.  *    MouseTracker -- Randy Nelson
  3.  *    An abstract class that manages a modal loop for tracking the mouse
  4.  *
  5.  *    You may freely copy, distribute and reuse the code in this example.
  6.  *    NeXT disclaims any warranty of any kind, expressed or implied, as to
  7.  *    its fitness for any particular use.
  8.  */
  9.  
  10. #import "MouseTracker.h"
  11. #import <appkit/Window.h>
  12. #import <appkit/Application.h>
  13. #import <appkit/Control.h>
  14. #import <dpsclient/psops.h>
  15. #import <dpsclient/wraps.h>
  16.  
  17. #define FRAMECLR NX_BLACK
  18. #define BCKGRNDCLR NX_WHITE
  19.  
  20. @implementation MouseTracker
  21.  
  22.  
  23. - initFrame:(const NXRect *)theFrame
  24. {
  25.     [super initFrame:theFrame];
  26.     return self;
  27. }
  28.  
  29. - setTrackingRect:sender
  30. {
  31.     NXRect myFrame = frame;
  32.     [[self superview] convertRect:&myFrame toView:nil];
  33.     [window setTrackingRect:&myFrame
  34.         inside:NO
  35.         owner:self
  36.         tag:23
  37.         left:NO
  38.         right:NO];
  39.     return self;
  40. }
  41.  
  42. - (float)backgroundGray
  43. {
  44.     return backgroundGray;
  45. }
  46.  
  47. - setBackgroundGray:(float)newGray
  48. {
  49.     backgroundGray = newGray;
  50.     [self display];
  51.     return self;
  52. }
  53.  
  54. - setFrameGray:(float)newGray
  55. {
  56.     frameGray = newGray;
  57.     [self display];
  58.     return self;
  59. }
  60.  
  61. - (float)frameGray
  62. {
  63.     return frameGray;
  64. }
  65.  
  66. - newBackgroundGray:sender
  67. {
  68.     backgroundGray = [sender floatValue];
  69.     [self display];
  70.     return self;
  71. }
  72.  
  73. - newFrameGray:sender
  74. {
  75.     frameGray = [sender floatValue];
  76.     [self display];
  77.     return self;
  78. }
  79.  
  80. - mouseDown:(NXEvent *)e
  81.  {
  82.     NXPoint startPoint = e->location, nextPoint;
  83.     int looping = YES;
  84.     int oldMask = [window addToEventMask:NX_MOUSEDRAGGEDMASK];
  85.     
  86.     /* do first mouse down action */
  87.     [self convertPoint:&startPoint fromView:nil];
  88.     [self mouseDownAction:&startPoint];
  89.     
  90.     while (looping){
  91.     e = [NXApp getNextEvent:NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK];
  92.     nextPoint = e->location;
  93.     [self convertPoint:&nextPoint fromView:nil];
  94.     if(e->type == NX_MOUSEDRAGGED){
  95.         [superview autoscroll:e];
  96.  
  97.         /* do continuing mouse dragged action */
  98.         [self mouseDraggedAction:&nextPoint];
  99.     }
  100.     else{
  101.         looping = NO;
  102.  
  103.         /* do mouse up action */
  104.         [self mouseUpAction:&nextPoint];
  105.     }    
  106.     }
  107.     [window setEventMask:oldMask];
  108.     return self;
  109.  }
  110.  
  111. - mouseEntered:(NXEvent *)e
  112. {
  113.     return [super mouseEntered:e];
  114. }
  115.  
  116. - mouseExited:(NXEvent *)e
  117. {
  118.     return [super mouseExited:e];
  119. }
  120.  
  121. - drawSelf:(const NXRect *)r :(int)c
  122. {
  123.     return self;
  124. }
  125.  
  126. - mouseDownAction:(NXPoint *)currentLocation
  127. {    
  128.     return self;
  129. }
  130.  
  131. - mouseDraggedAction:(NXPoint *)currentLocation
  132. {
  133.     return self;
  134. }
  135.  
  136. - mouseUpAction:(NXPoint *)currentLocation
  137. {
  138.     return self;
  139. }
  140.  
  141. @end
  142.