@@ -336,6 +336,8 @@ - (void)close;
336
336
@interface View : NSView
337
337
{ PyObject* canvas;
338
338
NSRect rubberband;
339
+ BOOL inside;
340
+ NSTrackingRectTag tracking;
339
341
}
340
342
- (void )dealloc ;
341
343
- (void )drawRect : (NSRect )rect ;
@@ -344,6 +346,8 @@ - (View*)initWithFrame:(NSRect)rect;
344
346
- (void )setCanvas : (PyObject*)newCanvas ;
345
347
- (BOOL )windowShouldClose : (NSNotification *)notification ;
346
348
- (BOOL )isFlipped ;
349
+ - (void )mouseEntered : (NSEvent *)event ;
350
+ - (void )mouseExited : (NSEvent *)event ;
347
351
- (void )mouseDown : (NSEvent *)event ;
348
352
- (void )mouseUp : (NSEvent *)event ;
349
353
- (void )mouseDragged : (NSEvent *)event ;
@@ -4463,13 +4467,16 @@ - (View*)initWithFrame:(NSRect)rect
4463
4467
{
4464
4468
self = [super initWithFrame: rect];
4465
4469
rubberband = NSZeroRect ;
4470
+ inside = false ;
4471
+ tracking = nil ;
4466
4472
return self;
4467
4473
}
4468
4474
4469
4475
- (void )dealloc
4470
4476
{
4471
4477
FigureCanvas* fc = (FigureCanvas*)canvas;
4472
4478
if (fc) fc->view = NULL ;
4479
+ [self removeTrackingRect: tracking];
4473
4480
[super dealloc ];
4474
4481
}
4475
4482
@@ -4551,6 +4558,11 @@ - (void)windowDidResize: (NSNotification*)notification
4551
4558
else
4552
4559
PyErr_Print ();
4553
4560
PyGILState_Release (gstate);
4561
+ if (tracking) [self removeTrackingRect: tracking];
4562
+ tracking = [self addTrackingRect: [self bounds ]
4563
+ owner: self
4564
+ userData: nil
4565
+ assumeInside: NO ];
4554
4566
[self setNeedsDisplay: YES ];
4555
4567
}
4556
4568
@@ -4575,6 +4587,45 @@ - (BOOL)windowShouldClose:(NSNotification*)notification
4575
4587
return YES ;
4576
4588
}
4577
4589
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
+
4578
4629
- (void )mouseDown : (NSEvent *)event
4579
4630
{
4580
4631
int x, y;
0 commit comments