summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-03-18 14:26:34 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-03-18 14:26:44 +0100
commitaa955812f988a4c0ffa3a43e9a5ba7a20a0e1f92 (patch)
tree724c1a8437acba6b473d9d0672edf5dba3afca2a
parentace51a4b8d840bee232758185b274afa5c0ae43a (diff)
Fix for issue #411: send FL_ENTER / FL_LEAVE events to Fl_Window objects.
-rw-r--r--src/Fl_cocoa.mm53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 3ec130a21..07404189f 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -535,6 +535,8 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
- (void)rightMouseDown:(NSEvent *)theEvent;
- (void)otherMouseDown:(NSEvent *)theEvent;
- (void)mouseMoved:(NSEvent *)theEvent;
+- (void)mouseEntered:(NSEvent *)theEvent;
+- (void)mouseExited:(NSEvent *)theEvent;
- (void)mouseDragged:(NSEvent *)theEvent;
- (void)rightMouseDragged:(NSEvent *)theEvent;
- (void)otherMouseDragged:(NSEvent *)theEvent;
@@ -554,6 +556,8 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
- (NSInteger)windowLevel;
+#else
+- (void)updateTrackingAreas;
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context;
@@ -576,6 +580,15 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
#endif
[[self standardWindowButton:NSWindowDocumentIconButton] setImage:nil];
[super close];
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+ while (fl_mac_os_version >= 100500) {
+ NSArray *a = [[self contentView] trackingAreas];
+ if ([a count] == 0) break;
+ NSTrackingArea *ta = (NSTrackingArea*)[a objectAtIndex:0];
+ [[self contentView] removeTrackingArea:ta];
+ }
+#endif
+ [self release];
// when a fullscreen window is closed, windowDidResize may be sent after the close message was sent
// and before the FLWindow receives the final dealloc message
w = NULL;
@@ -1051,6 +1064,12 @@ static void cocoaMouseHandler(NSEvent *theEvent)
Fl::handle( sendEvent, window );
}
break;
+ case NSMouseEntered :
+ Fl::handle(FL_ENTER, window);
+ break;
+ case NSMouseExited :
+ Fl::handle(FL_LEAVE, window);
+ break;
default:
break;
}
@@ -2377,8 +2396,41 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
cocoaMouseHandler(theEvent);
}
- (void)mouseMoved:(NSEvent *)theEvent {
+ if (Fl::belowmouse()) cocoaMouseHandler(theEvent);
+}
+- (void)mouseEntered:(NSEvent *)theEvent {
+ cocoaMouseHandler(theEvent);
+}
+- (void)mouseExited:(NSEvent *)theEvent {
cocoaMouseHandler(theEvent);
}
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+- (void)updateTrackingAreas {
+ if (fl_mac_os_version >= 100500) {
+ Fl_Window *win = [(FLWindow*)[self window] getFl_Window];
+ if (!win->parent() && !win->menu_window() && !win->tooltip_window() &&
+ win->user_data() != &Fl_Screen_Driver::transient_scale_display) {
+ while (true) {
+ NSArray *a = [self trackingAreas]; // 10.5
+ if ([a count] == 0) break;
+ NSTrackingArea *ta = (NSTrackingArea*)[a objectAtIndex:0];
+ [self removeTrackingArea:ta]; // 10.5
+ }
+ NSTrackingArea *tracking = [[[NSTrackingArea alloc] // 10.5
+ initWithRect:[self frame]
+ options:NSTrackingActiveAlways |
+ NSTrackingMouseEnteredAndExited |
+ NSTrackingMouseMoved
+ owner:self
+ userInfo:nil] autorelease];
+ if (tracking) {
+ [self addTrackingArea:tracking]; // 10.5
+ }
+ [super updateTrackingAreas];
+ }
+ }
+}
+#endif
- (void)mouseDragged:(NSEvent *)theEvent {
cocoaMouseHandler(theEvent);
}
@@ -3048,6 +3100,7 @@ Fl_X* Fl_Cocoa_Window_Driver::makeWindow()
contentRect:crect
styleMask:winstyle];
[cw setFrameOrigin:crect.origin];
+ [cw setReleasedWhenClosed:NO];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
if (fl_mac_os_version >= 101200) {
if (!w->parent() && (winstyle & NSTitledWindowMask) && (winstyle & NSResizableWindowMask)