@@ -336,6 +336,8 @@ - (void)close;
336336@interface View : NSView
337337{ PyObject* canvas;
338338 NSRect rubberband;
339+ BOOL inside;
340+ NSTrackingRectTag tracking;
339341}
340342- (void )dealloc ;
341343- (void )drawRect : (NSRect )rect ;
@@ -344,6 +346,8 @@ - (View*)initWithFrame:(NSRect)rect;
344346- (void )setCanvas : (PyObject*)newCanvas ;
345347- (BOOL )windowShouldClose : (NSNotification *)notification ;
346348- (BOOL )isFlipped ;
349+ - (void )mouseEntered : (NSEvent *)event ;
350+ - (void )mouseExited : (NSEvent *)event ;
347351- (void )mouseDown : (NSEvent *)event ;
348352- (void )mouseUp : (NSEvent *)event ;
349353- (void )mouseDragged : (NSEvent *)event ;
@@ -4463,13 +4467,16 @@ - (View*)initWithFrame:(NSRect)rect
44634467{
44644468 self = [super initWithFrame: rect];
44654469 rubberband = NSZeroRect ;
4470+ inside = false ;
4471+ tracking = nil ;
44664472 return self;
44674473}
44684474
44694475- (void )dealloc
44704476{
44714477 FigureCanvas* fc = (FigureCanvas*)canvas;
44724478 if (fc) fc->view = NULL ;
4479+ [self removeTrackingRect: tracking];
44734480 [super dealloc ];
44744481}
44754482
@@ -4551,6 +4558,11 @@ - (void)windowDidResize: (NSNotification*)notification
45514558 else
45524559 PyErr_Print ();
45534560 PyGILState_Release (gstate);
4561+ if (tracking) [self removeTrackingRect: tracking];
4562+ tracking = [self addTrackingRect: [self bounds ]
4563+ owner: self
4564+ userData: nil
4565+ assumeInside: NO ];
45544566 [self setNeedsDisplay: YES ];
45554567}
45564568
@@ -4575,6 +4587,45 @@ - (BOOL)windowShouldClose:(NSNotification*)notification
45754587 return YES ;
45764588}
45774589
4590+ - (void )mouseEntered : (NSEvent *)event
4591+ {
4592+ PyGILState_STATE gstate;
4593+ PyObject* result;
4594+ NSWindow * window = [self window ];
4595+ if ([window isKeyWindow ]==false ) return ;
4596+
4597+ gstate = PyGILState_Ensure ();
4598+ result = PyObject_CallMethod (canvas, " enter_notify_event" , " " );
4599+ if (result)
4600+ Py_DECREF (result);
4601+ else
4602+ PyErr_Print ();
4603+ PyGILState_Release (gstate);
4604+
4605+ [window setAcceptsMouseMovedEvents: YES ];
4606+ inside = true ;
4607+ }
4608+
4609+ - (void )mouseExited : (NSEvent *)event
4610+ {
4611+ PyGILState_STATE gstate;
4612+ PyObject* result;
4613+ NSWindow * window = [self window ];
4614+ if ([window isKeyWindow ]==false ) return ;
4615+
4616+ if (inside==false ) return ;
4617+ gstate = PyGILState_Ensure ();
4618+ result = PyObject_CallMethod (canvas, " leave_notify_event" , " " );
4619+ if (result)
4620+ Py_DECREF (result);
4621+ else
4622+ PyErr_Print ();
4623+ PyGILState_Release (gstate);
4624+
4625+ [[self window ] setAcceptsMouseMovedEvents: NO ];
4626+ inside = false ;
4627+ }
4628+
45784629- (void )mouseDown : (NSEvent *)event
45794630{
45804631 int x, y;
0 commit comments