Cocoa: fix #40081 #40853 by completely reimplementing TManualScrollView with Legacy/Overlay Style Scroller, Merge branch 'cocoa/scroll'

TCocoaManualScrollView is based on NSView without native Scroller.
it doesn't require the document to have the full size it claims, so it is usually suitable for components of unlimited size.
it corresponds to components such as TreeView, Grid, SynEdit.
Legacy and Overlay style Scroller were implemented, they have visual effects highly similar to native Scrollers.

on the contrary, TCocoaScrollView is based on NSScrollView with native Scroller.
it requires the document to have the full size it claims, so it is usually suitable for components of limited size.
it corresponds to components such as ListBox, ListView, ScrollBox, Form.
This commit is contained in:
rich2014 2024-07-01 20:13:14 +08:00
commit 05e119e924
4 changed files with 1124 additions and 169 deletions

View File

@ -8,7 +8,78 @@ interface
uses
CocoaAll, Cocoa_Extra, CocoaConst;
type
NSColorFunction = Function(): NSColor;
function getCocoaScrollerDefaultKnobColor: NSColor;
var
// the style of the TCocoaScrollBar managed by TCocoaManualScrollView,
// the default value is System Preferred.
// note: TCocoaScrollBar not managed by TCocoaManualScrollView is always
// Legacy Style.
CocoaScrollerPreferredStyle : NSScrollerStyle = -1;
// Scroller Knob Fade in/out time interval, in Seconds
CocoaScrollerKnobFadeTimeInterval : Double = 0.02;
// Scroller Knob Radius, in Dots
CocoaScrollerKnobRadius : Double = 4;
// Legacy Style Scroller Knob Color
CocoaScrollerOverlayStyleKnobColor : NSColorFunction = @getCocoaScrollerDefaultKnobColor;
// Legacy Style Scroller Knob Alpha in Normal
CocoaScrollerLegacyStyleAlpha : Double = 0.25;
// Legacy Style Scroller Knob Alpha when mouse enters
CocoaScrollerLegacyStyleAlphaBlack : Double = 0.50;
// Legacy Style Scroller Knob Alpha Step when fading in/out
CocoaScrollerLegacyStyleFadeStep : Double = 0.05;
// Legacy Style Scroller Knob Position, in Dots
CocoaScrollerLegacyStyleKnobPos : Double = 3;
// Legacy Style Scroller Knob Shrunk Size, in Dots
CocoaScrollerLegacyStyleKnobShrunkSize : Double = 5;
// Overly Style Scroller Knob Color
CocoaScrollerLegacyStyleKnobColor : NSColorFunction = @getCocoaScrollerDefaultKnobColor;
// Overly Style Scroller Auto Hide Delay Time, in Seconds
CocoaScrollerOverlayStyleAutoHideDelayTime : Double = 0.9;
// Overlay Style Scroller Alpha in Normal
CocoaScrollerOverlayStyleAlpha : Double = 0.5;
// Overlay Style Scroller Alpha Step when fading out
CocoaScrollerOverlayStyleFadeStep : Double = -0.1;
// Overlay Style Scroller Alpha when fade out ends
CocoaScrollerOverlayStyleFadeTo : Double = 0;
// Overlay Style Scroller expands time interval, in Seconds
CocoaScrollerOverlayStyleExpandTimeInterval : Double = 0.03;
// Overlay Style Scroller expands when the mouse enters, in Dots
CocoaScrollerOverlayStyleExpandSize : Double = 4;
// Overlay Style Scroller Knob Position, in Dots
CocoaScrollerOverlayStyleKnobPos : Double = 5;
// Overlay Style Scroller Knob Shrunk Size, in Dots
CocoaScrollerOverlayStyleKnobShrunkSize : Double = 6;
// in extreme cases, the normally calculated Knob size of Overlay Scroller
// may be too small, keep the min size.
// min height for the Knob of VerticalScroller
// min width for the Knob of HorizontalScroller
CocoaScrollerOverlayStyleKnobMinSize : Double = 25;
// for compatiblity with LCL 1.8 release. The macOS base is 72ppi
CocoaBasePPI : Integer = 96;
@ -38,6 +109,11 @@ var
implementation
function getCocoaScrollerDefaultKnobColor: NSColor;
begin
Result:= NSColor.controlTextColor;
end;
initialization
CocoaDefaultCheckMenuImageName:= NSSTR('NSMenuCheckmark');
CocoaDefaultRadioMenuImageName:= NSSTR('NSDatePickerCalendarHome');

File diff suppressed because it is too large Load Diff

View File

@ -1678,11 +1678,10 @@ begin
begin
mn := TCocoaManualScrollView(obj);
case SBStyle of
SB_Vert: Result := mn.hasVerticalScroller and not mn.verticalScroller.isHidden;
SB_Horz: Result := mn.hasHorizontalScroller and not mn.horizontalScroller.isHidden;
SB_Vert: Result := mn.hasVerticalScroller;
SB_Horz: Result := mn.hasHorizontalScroller;
else
Result := mn.hasHorizontalScroller and not mn.horizontalScroller.isHidden
and mn.hasVerticalScroller and not mn.verticalScroller.isHidden;
Result := mn.hasHorizontalScroller and mn.hasVerticalScroller;
end;
end
else

View File

@ -2270,7 +2270,12 @@ begin
prm.Height:=ScrollBase;
end;
scr:=NSView(TCocoaScrollBar.alloc).lclInitWithCreateParams(prm);
// for the Scroller created separately through TCocoaWSScrollBar.CreateHandle(),
// due to the lack of the control over the Layout by TCocoaManualScrollView,
// only the Legacy Style can be used for compatibility.
// it's the same logical relationship as NSScrollView and NSScroller.
scr:= createLegacyScroller;
scr.lclInitWithCreateParams(prm);
scr.callback:=TLCLCommonCallback.Create(scr, AWinControl);
// OnChange (scrolling) event handling