Revision: 8134
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8134&view=rev
Author:   mdehoon
Date:     2010-02-16 14:31:02 +0000 (Tue, 16 Feb 2010)

Log Message:
-----------
Keeping track of the mouse entering and exiting a window, and moving over an
active window.

Modified Paths:
--------------
    trunk/matplotlib/src/_macosx.m

Modified: trunk/matplotlib/src/_macosx.m
===================================================================
--- trunk/matplotlib/src/_macosx.m      2010-02-15 16:38:50 UTC (rev 8133)
+++ trunk/matplotlib/src/_macosx.m      2010-02-16 14:31:02 UTC (rev 8134)
@@ -336,6 +336,8 @@
 @interface View : NSView
 {   PyObject* canvas;
     NSRect rubberband;
+    BOOL inside;
+    NSTrackingRectTag tracking;
 }
 - (void)dealloc;
 - (void)drawRect:(NSRect)rect;
@@ -344,6 +346,8 @@
 - (void)setCanvas: (PyObject*)newCanvas;
 - (BOOL)windowShouldClose:(NSNotification*)notification;
 - (BOOL)isFlipped;
+- (void)mouseEntered:(NSEvent*)event;
+- (void)mouseExited:(NSEvent*)event;
 - (void)mouseDown:(NSEvent*)event;
 - (void)mouseUp:(NSEvent*)event;
 - (void)mouseDragged:(NSEvent*)event;
@@ -4463,6 +4467,8 @@
 {
     self = [super initWithFrame: rect];
     rubberband = NSZeroRect;
+    inside = false;
+    tracking = nil;
     return self;
 }
 
@@ -4470,6 +4476,7 @@
 {
     FigureCanvas* fc = (FigureCanvas*)canvas;
     if (fc) fc->view = NULL;
+    [self removeTrackingRect: tracking];
     [super dealloc];
 }
 
@@ -4551,6 +4558,11 @@
     else
         PyErr_Print();
     PyGILState_Release(gstate);
+    if (tracking) [self removeTrackingRect: tracking];
+    tracking = [self addTrackingRect: [self bounds]
+                               owner: self
+                            userData: nil
+                        assumeInside: NO];
     [self setNeedsDisplay: YES];
 }
 
@@ -4575,6 +4587,45 @@
     return YES;
 }
 
+- (void)mouseEntered:(NSEvent *)event
+{
+    PyGILState_STATE gstate;
+    PyObject* result;
+    NSWindow* window = [self window];
+    if ([window isKeyWindow]==false) return;
+
+    gstate = PyGILState_Ensure();
+    result = PyObject_CallMethod(canvas, "enter_notify_event", "");
+    if(result)
+        Py_DECREF(result);
+    else
+        PyErr_Print();
+    PyGILState_Release(gstate);
+
+    [window setAcceptsMouseMovedEvents: YES];
+    inside = true;
+}
+
+- (void)mouseExited:(NSEvent *)event
+{
+    PyGILState_STATE gstate;
+    PyObject* result;
+    NSWindow* window = [self window];
+    if ([window isKeyWindow]==false) return;
+
+    if (inside==false) return;
+    gstate = PyGILState_Ensure();
+    result = PyObject_CallMethod(canvas, "leave_notify_event", "");
+    if(result)
+        Py_DECREF(result);
+    else
+        PyErr_Print();
+    PyGILState_Release(gstate);
+
+    [[self window] setAcceptsMouseMovedEvents: NO];
+    inside = false;
+}
+
 - (void)mouseDown:(NSEvent *)event
 {
     int x, y;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to