Cocoa/ListView: improve compatibility with macOS 13+

This commit is contained in:
rich2014 2024-07-21 01:13:02 +08:00
parent 1346a4a34d
commit 7f011e1f63
4 changed files with 30 additions and 24 deletions

View File

@ -67,6 +67,7 @@ type
procedure backend_onInit;
public
procedure dealloc; override;
procedure addSubview(aView: NSView); override;
public
procedure updateItemValue( indexPath:NSIndexPath; cocoaItem:TCocoaCollectionItem );
message 'updateItemValue:cocoaItem:';
@ -118,6 +119,8 @@ type
procedure collectionView_didDeselectItemsAtIndexPaths(
collectionView: NSCollectionView; indexPaths:NSSet );
message 'collectionView:didDeselectItemsAtIndexPaths:';
procedure mouseDown(theEvent: NSEvent); override;
end;
function AllocCocoaCollectionView( style: TViewStyle ): TCocoaCollectionView;
@ -285,9 +288,8 @@ end;
procedure TCocoaListView_CollectionView_LargeIconHandler.onAdjustTextEditorRect(
var aFrame: NSRect);
begin
aFrame.origin.x:= aFrame.origin.x + 1;
aFrame.size.width:= aFrame.size.width - 2;
aFrame.size.height:= aFrame.size.height + 8;
aFrame.origin.x:= aFrame.origin.x + 2;
aFrame.size.width:= aFrame.size.width - 4;
end;
{ TCocoaListView_CollectionView_SmallIconHandler }
@ -362,9 +364,7 @@ end;
procedure TCocoaListView_CollectionView_SmallIconHandler.onAdjustTextEditorRect(
var aFrame: NSRect);
begin
aFrame.origin.y:= aFrame.origin.y - 4;
aFrame.size.width:= aFrame.size.width + 4;
aFrame.size.height:= aFrame.size.height + 8;
end;
{ TCocoaListView_CollectionView_ListHandler }
@ -424,10 +424,9 @@ end;
procedure TCocoaListView_CollectionView_ListHandler.onAdjustTextEditorRect(
var aFrame: NSRect);
begin
aFrame.origin.x:= aFrame.origin.x - 3;
aFrame.origin.y:= aFrame.origin.y - 3;
aFrame.size.width:= aFrame.size.width + 6;
aFrame.size.height:= aFrame.size.height + 6;
aFrame.origin.x:= aFrame.origin.x - 2;
aFrame.origin.y:= aFrame.origin.y - 2;
aFrame.size.width:= aFrame.size.width + 4;
end;
{ TCocoaCollectionItem }
@ -527,6 +526,18 @@ begin
FreeAndNil( self.styleHandler );
end;
procedure TCocoaCollectionView.addSubview(aView: NSView);
var
field: TCocoaTextField;
begin
if aView.isKindOfClass(TCocoaTextField) then begin
field:= TCocoaTextField( aView );
field.setBezeled( False );
field.fixedBorderStyle:= True;
end;
inherited addSubview(aView);
end;
procedure TCocoaCollectionView.updateItemValue(
indexPath:NSIndexPath; cocoaItem: TCocoaCollectionItem );
var
@ -707,4 +718,9 @@ begin
end;
end;
procedure TCocoaCollectionView.mouseDown(theEvent: NSEvent);
begin
inherited mouseDown(theEvent);
end;
end.

View File

@ -63,6 +63,8 @@ type
TCocoaTextField = objcclass(NSTextField, NSTextField_LCLExt)
callback: ICommonCallback;
maxLength: Integer;
fixedBorderStyle: Boolean;
function acceptsFirstResponder: LCLObjCBoolean; override;
function lclGetCallback: ICommonCallback; override;
procedure lclClearCallback; override;

View File

@ -227,8 +227,6 @@ type
function documentView: NSView; message 'documentView';
function scrollView: TCocoaScrollView; message 'scrollView';
function WSHandler: TCocoaWSListViewHandler; message 'WSHandler';
procedure addSubview(aView: NSView); override;
procedure setScrollView(aView: TCocoaScrollView); message 'setScrollView:';
function initializing: Boolean; message 'isinitializing';
end;
@ -2041,17 +2039,6 @@ begin
Result:= _WSHandler;
end;
procedure TCocoaListView.addSubview(aView: NSView);
begin
self.documentView.addSubview(aView);
end;
procedure TCocoaListView.setScrollView(aView: TCocoaScrollView);
begin
_scrollView:= aView;
Inherited addSubview(aView);
end;
function TCocoaListView.initializing: Boolean;
begin
Result:= _initializing;
@ -2087,7 +2074,7 @@ begin
_scrollView.setDocumentView( _backendControl );
_scrollView.setAutoresizingMask( NSViewWidthSizable or NSViewHeightSizable );
_scrollView.callback:= self.callback;
self.setScrollView( _scrollView );
self.addSubView( _scrollView );
ScrollViewSetBorderStyle( _scrollView, callback.getBorderStyle );
backendControlAccess:= TCocoaListViewBackendControlProtocol(_backendControl);

View File

@ -1101,8 +1101,9 @@ begin
cell.setWraps(false);
cell.setScrollable(true);
end;
if NOT TCocoaTextField(field).fixedBorderStyle then
TextFieldSetBorderStyle(field, TCustomEdit(AWinControl).BorderStyle);
TextFieldSetAllignment(field, TCustomEdit(AWinControl).Alignment);
TextFieldSetBorderStyle(field, TCustomEdit(AWinControl).BorderStyle);
UpdateFocusRing(field, TCustomEdit(AWinControl).BorderStyle);
Result:=TLCLHandle(field);