vcl/inc/osx/salframeview.h |    3 +++
 vcl/osx/salframe.cxx       |   14 --------------
 vcl/osx/salframeview.mm    |   34 ++++++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 14 deletions(-)

New commits:
commit e7f27f96f0789939436cf1cb3dff79579a67cf3d
Author:     Patrick Luby <guibmac...@gmail.com>
AuthorDate: Sun Oct 27 20:15:42 2024 -0400
Commit:     Patrick Luby <guibomac...@gmail.com>
CommitDate: Mon Oct 28 15:06:07 2024 +0100

    Set the native tracking area in -[SalFrameView updateTrackingAreas]
    
    NSTrackingArea has an immutable rectangle so it cannot grow when
    the SalFrameView's window is resized. So, whenever the SalFrameView's
    bounds change, remove the old NSTrackingArea and add a new one with
    the SalFrameView's current bounds.
    
    Change-Id: I70a5be7fbe6dd6b5f4f2ed4878dd12a36ab3622b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175708
    Reviewed-by: Patrick Luby <guibomac...@gmail.com>
    Tested-by: Jenkins

diff --git a/vcl/inc/osx/salframeview.h b/vcl/inc/osx/salframeview.h
index dec2f03a42f3..287ccaedbc06 100644
--- a/vcl/inc/osx/salframeview.h
+++ b/vcl/inc/osx/salframeview.h
@@ -111,6 +111,7 @@ enum class SalEvent;
     BOOL            mbInCommitMarkedText;
     NSAttributedString* mpLastMarkedText;
     BOOL            mbTextInputWantsNonRepeatKeyDown;
+    NSTrackingArea* mpLastTrackingArea;
 }
 +(void)unsetMouseFrame: (AquaSalFrame*)pFrame;
 -(id)initWithSalFrame: (AquaSalFrame*)pFrame;
@@ -146,6 +147,8 @@ enum class SalEvent;
 -(BOOL)handleKeyDownException:(NSEvent*)pEvent;
 -(void)clearLastEvent;
 -(void)clearLastMarkedText;
+-(void)clearLastTrackingArea;
+-(void)updateTrackingAreas;
 /*
     text action methods
 */
diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx
index 940337b770a1..81aae45457a7 100644
--- a/vcl/osx/salframe.cxx
+++ b/vcl/osx/salframe.cxx
@@ -244,20 +244,6 @@ void AquaSalFrame::initWindowAndView()
 
     [mpNSWindow setRestorable:NO];
 
-    // tdf#155092 use tracking areas instead of tracking rectangles
-    // Apparently, the older, tracking rectangles selectors cause
-    // unexpected window resizing upon the first mouse down after the
-    // window has been manually resized so switch to the newer,
-    // tracking areas selectors. Also, the NSTrackingInVisibleRect
-    // option allows us to create one single tracking area that
-    // resizes itself automatically over the lifetime of the view.
-    // Note: for some unknown reason, both NSTrackingMouseMoved and
-    // NSTrackingAssumeInside are necessary options for this fix
-    // to work.
-    NSTrackingArea *pTrackingArea = [[NSTrackingArea alloc] initWithRect: 
[mpNSView bounds] options: ( NSTrackingMouseEnteredAndExited | 
NSTrackingMouseMoved | NSTrackingActiveAlways | NSTrackingAssumeInside | 
NSTrackingInVisibleRect ) owner: mpNSView userInfo: nil];
-    [mpNSView addTrackingArea: pTrackingArea];
-    [pTrackingArea release];
-
     maSysData.mpNSView = mpNSView;
 
     UpdateFrameGeometry();
diff --git a/vcl/osx/salframeview.mm b/vcl/osx/salframeview.mm
index 07193529e0d8..681567f3a5fa 100644
--- a/vcl/osx/salframeview.mm
+++ b/vcl/osx/salframeview.mm
@@ -774,6 +774,7 @@ static void updateWinDataInLiveResize(bool bInLiveResize)
         mbInCommitMarkedText = NO;
         mpLastMarkedText = nil;
         mbTextInputWantsNonRepeatKeyDown = NO;
+        mpLastTrackingArea = nil;
     }
 
     return self;
@@ -783,6 +784,7 @@ static void updateWinDataInLiveResize(bool bInLiveResize)
 {
     [self clearLastEvent];
     [self clearLastMarkedText];
+    [self clearLastTrackingArea];
     [self revokeWrapper];
 
     [super dealloc];
@@ -2129,6 +2131,38 @@ static void updateWinDataInLiveResize(bool bInLiveResize)
     mbTextInputWantsNonRepeatKeyDown = NO;
 }
 
+-(void)clearLastTrackingArea
+{
+    if (mpLastTrackingArea)
+    {
+        [self removeTrackingArea: mpLastTrackingArea];
+        [mpLastTrackingArea release];
+        mpLastTrackingArea = nil;
+    }
+}
+
+-(void)updateTrackingAreas
+{
+    [super updateTrackingAreas];
+
+    // tdf#155092 use tracking areas instead of tracking rectangles
+    // Apparently, the older, tracking rectangles selectors cause
+    // unexpected window resizing upon the first mouse down after the
+    // window has been manually resized so switch to the newer,
+    // tracking areas selectors. Also, the NSTrackingInVisibleRect
+    // option allows us to create one single tracking area that
+    // resizes itself automatically over the lifetime of the view.
+    // Note: for some unknown reason, both NSTrackingMouseMoved and
+    // NSTrackingAssumeInside are necessary options for this fix
+    // to work.
+    // Note: for some unknown reason, [mpLastTrackingArea rect]
+    // returns an empty NSRect (at least on macOS Sequoia) so always
+    // remove the old tracking area and add a new one.
+    [self clearLastTrackingArea];
+    mpLastTrackingArea = [[NSTrackingArea alloc] initWithRect: [self bounds] 
options: ( NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | 
NSTrackingActiveAlways | NSTrackingAssumeInside | NSTrackingInVisibleRect ) 
owner: self userInfo: nil];
+    [self addTrackingArea: mpLastTrackingArea];
+}
+
 - (NSRect)firstRectForCharacterRange:(NSRange)aRange 
actualRange:(NSRangePointer)actualRange
 {
      // FIXME - These should probably be used?

Reply via email to