aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2021-08-27 16:42:40 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2021-08-27 16:42:40 +1000
commit2413db664abc3389f11be3a6839acc618a70d1d0 (patch)
treeeb4ba16a5ececfaa91134337734b65fd4a94ae29
parent1033917f37d01f2b826a16b4e71ba6a6fd9ef00e (diff)
downloadscintilla-mirror-2413db664abc3389f11be3a6839acc618a70d1d0.tar.gz
Simplify SetScrollingSize and use const where possible.
-rw-r--r--cocoa/ScintillaCocoa.h2
-rw-r--r--cocoa/ScintillaCocoa.mm26
2 files changed, 15 insertions, 13 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index dcc85ba22..0aa38911c 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -159,7 +159,7 @@ public:
void SetVerticalScrollPos() override;
void SetHorizontalScrollPos() override;
bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) override;
- bool SetScrollingSize(void);
+ bool SetScrollingSize();
void Resize();
void UpdateForScroll();
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 91bc55987..ed7150fa0 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -1944,32 +1944,34 @@ bool ScintillaCocoa::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) {
return SetScrollingSize();
}
-bool ScintillaCocoa::SetScrollingSize(void) {
+//--------------------------------------------------------------------------------------------------
+
+/**
+ * Adjust both scrollers to reflect the current scroll ranges and position in the editor.
+ * Called when size changes or when scroll ranges change.
+ */
+
+bool ScintillaCocoa::SetScrollingSize() {
bool changes = false;
SCIContentView *inner = ContentView();
if (!enteredSetScrollingSize) {
enteredSetScrollingSize = true;
NSScrollView *scrollView = ScrollContainer();
- NSClipView *clipView = ScrollContainer().contentView;
- NSRect clipRect = clipView.bounds;
+ const NSRect clipRect = scrollView.contentView.bounds;
CGFloat docHeight = pcs->LinesDisplayed() * vs.lineHeight;
if (!endAtLastLine)
docHeight += (int(scrollView.bounds.size.height / vs.lineHeight)-3) * vs.lineHeight;
// Allow extra space so that last scroll position places whole line at top
- int clipExtra = int(clipRect.size.height) % vs.lineHeight;
+ const int clipExtra = int(clipRect.size.height) % vs.lineHeight;
docHeight += clipExtra;
// Ensure all of clipRect covered by Scintilla drawing
if (docHeight < clipRect.size.height)
docHeight = clipRect.size.height;
- CGFloat docWidth = scrollWidth;
- bool showHorizontalScroll = horizontalScrollBarVisible &&
+ const bool showHorizontalScroll = horizontalScrollBarVisible &&
!Wrapping();
- if (Wrapping())
- docWidth = clipRect.size.width;
- NSRect contentRect = {{0, 0}, {docWidth, docHeight}};
- NSRect contentRectNow = inner.frame;
- changes = (contentRect.size.width != contentRectNow.size.width) ||
- (contentRect.size.height != contentRectNow.size.height);
+ const CGFloat docWidth = Wrapping() ? clipRect.size.width : scrollWidth;
+ const NSRect contentRect = NSMakeRect(0, 0, docWidth, docHeight);
+ changes = !CGSizeEqualToSize(contentRect.size, inner.frame.size);
if (changes) {
inner.frame = contentRect;
}