From c61df8742a4865ac9c67f8ed017248b82fe5574e Mon Sep 17 00:00:00 2001 From: Neil Hodgson Date: Thu, 2 Mar 2023 16:46:14 +1100 Subject: Cache client size when view moved or sized. That allows access to it from secondary threads which otherwise shows warnings. Earlier approach of caching client rectangle failed to handle scrolling. --- cocoa/ScintillaCocoa.h | 3 +++ cocoa/ScintillaCocoa.mm | 17 ++++++++++++++--- src/Editor.cxx | 9 +++++++-- src/Editor.h | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h index 4c1f10a97..f8c3357e0 100644 --- a/cocoa/ScintillaCocoa.h +++ b/cocoa/ScintillaCocoa.h @@ -103,6 +103,8 @@ private: bool isFirstResponder; bool isActive; + Point sizeClient; + bool enteredSetScrollingSize; bool GetPasteboardData(NSPasteboard *board, SelectionText *selectedText); @@ -118,6 +120,7 @@ private: protected: Point GetVisibleOriginInMain() const override; + Point ClientSize() const override; PRectangle GetClientRectangle() const override; PRectangle GetClientDrawingRectangle() override; Point ConvertPoint(NSPoint point); diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 4f4fa1b71..223c9dac0 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -731,6 +731,15 @@ Scintilla::Internal::Point ScintillaCocoa::GetVisibleOriginInMain() const { //-------------------------------------------------------------------------------------------------- +/** + * Return the size of the client area which has been cached. + */ +Scintilla::Internal::Point ScintillaCocoa::ClientSize() const { + return sizeClient; +} + +//-------------------------------------------------------------------------------------------------- + /** * Instead of returning the size of the inner view we have to return the visible part of it * in order to make scrolling working properly. @@ -738,9 +747,7 @@ Scintilla::Internal::Point ScintillaCocoa::GetVisibleOriginInMain() const { */ PRectangle ScintillaCocoa::GetClientRectangle() const { NSScrollView *scrollView = ScrollContainer(); - NSSize size = scrollView.contentView.bounds.size; - Point origin = GetVisibleOriginInMain(); - return PRectangle(origin.x, origin.y, origin.x+size.width, origin.y + size.height); + return NSRectToPRectangle(scrollView.contentView.bounds); } //-------------------------------------------------------------------------------------------------- @@ -2033,6 +2040,10 @@ bool ScintillaCocoa::SetScrollingSize() { void ScintillaCocoa::Resize() { SetScrollingSize(); + + const PRectangle rcClient = GetClientRectangle(); + sizeClient = Point(rcClient.Width(), rcClient.Height()); + ChangeSize(); } diff --git a/src/Editor.cxx b/src/Editor.cxx index 7144a422d..d64a09deb 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -274,6 +274,11 @@ Sci::Line Editor::TopLineOfMain() const noexcept { return topLine; } +Point Editor::ClientSize() const { + const PRectangle rcClient = GetClientRectangle(); + return Point(rcClient.Width(), rcClient.Height()); +} + PRectangle Editor::GetClientRectangle() const { return wMain.GetClientPosition(); } @@ -290,8 +295,8 @@ PRectangle Editor::GetTextRectangle() const { } Sci::Line Editor::LinesOnScreen() const { - const PRectangle rcClient = GetClientRectangle(); - const int htClient = static_cast(rcClient.bottom - rcClient.top); + const Point sizeClient = ClientSize(); + const int htClient = static_cast(sizeClient.y); //Platform::DebugPrintf("lines on screen = %d\n", htClient / lineHeight + 1); return htClient / vs.lineHeight; } diff --git a/src/Editor.h b/src/Editor.h index d757dd4c4..61e0dd5b0 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -308,6 +308,7 @@ protected: // ScintillaBase subclass needs access to much of Editor Point GetVisibleOriginInMain() const override; PointDocument DocumentPointFromView(Point ptView) const; // Convert a point from view space to document Sci::Line TopLineOfMain() const noexcept final; // Return the line at Main's y coordinate 0 + virtual Point ClientSize() const; virtual PRectangle GetClientRectangle() const; virtual PRectangle GetClientDrawingRectangle(); PRectangle GetTextRectangle() const; -- cgit v1.2.3