UPD: refactor TFileSourceUIHandler related

This commit is contained in:
rich2014 2024-12-30 00:15:34 +08:00
commit 112ffaa593
3 changed files with 30 additions and 15 deletions

View file

@ -45,9 +45,18 @@ type
procedure confirmOperation( var params: TFileSourceConsultParams ); virtual; abstract;
end;
TFileSourceUIParams = record
sender: TObject;
col: Integer;
row: Integer;
drawingRect: TRect;
iconRect: TRect;
focused: Boolean;
displayFile: TDisplayFile;
end;
TFileSourceUIHandler = class
procedure draw(Sender: TObject; aCol, aRow: Integer;
var aRect: TRect; focused: Boolean; aFile: TDisplayFile); virtual; abstract;
procedure draw( var params: TFileSourceUIParams ); virtual; abstract;
end;
TFileSourceField = record

View file

@ -1539,7 +1539,7 @@ var
AFile: TDisplayFile;
FileSourceDirectAccess: Boolean;
ColumnsSet: TPanelColumnsClass;
onDrawCellFocused: Boolean;
params: TFileSourceUIParams;
//------------------------------------------------------
// begin subprocedures
@ -1965,13 +1965,15 @@ var
handler:= ColumnsView.FileSource.GetUIHandler;
if handler = nil then
Exit;
handler.draw(Self.ColumnsView,aCol,aRow,aRect,onDrawCellFocused,AFile);
params.drawingRect:= aRect;
handler.draw( params );
end;
procedure callOnDrawCell;
begin
if Assigned(OnDrawCell) and not(CsDesigning in ComponentState) then
OnDrawCell(Self.ColumnsView,aCol,aRow,aRect,onDrawCellFocused,AFile);
OnDrawCell(Self.ColumnsView,aCol,aRow,params.drawingRect,params.focused,AFile);
end;
//------------------------------------------------------
@ -1995,6 +1997,12 @@ begin
AFile := ColumnsView.FFiles[ARow - FixedRows]; // substract fixed rows (header)
FileSourceDirectAccess := fspDirectAccess in ColumnsView.FileSource.Properties;
params:= Default( TFileSourceUIParams );
params.sender:= Self.ColumnsView;
params.col:= aCol;
params.row:= aRow;
params.displayFile:= aFile;
if AFile.DisplayStrings.Count = 0 then
ColumnsView.MakeColumnsStrings(AFile, ColumnsSet);
@ -2012,7 +2020,7 @@ begin
DrawOtherCell;
end;
onDrawCellFocused:= (gdSelected in aState) and ColumnsView.Active;
params.focused:= (gdSelected in aState) and ColumnsView.Active;
callFileSourceDrawCell;
callOnDrawCell;

View file

@ -45,8 +45,7 @@ type
{ TiCloudDriverUIHandler }
TiCloudDriverUIHandler = class( TFileSourceUIHandler )
procedure draw(Sender: TObject; aCol, aRow: Integer;
var aRect: TRect; focused: Boolean; aFile: TDisplayFile); override;
procedure draw( var params: TFileSourceUIParams ); override;
end;
var
@ -54,25 +53,24 @@ var
{ TiCloudDriverUIHandler }
procedure TiCloudDriverUIHandler.draw(Sender: TObject; aCol,
aRow: Integer; var aRect: TRect; focused: Boolean; aFile: TDisplayFile);
procedure TiCloudDriverUIHandler.draw( var params: TFileSourceUIParams );
var
image: NSImage;
destRect: NSRect;
graphicsContext: NSGraphicsContext;
begin
if aCol <> 0 then
if params.col <> 0 then
Exit;
if NOT TiCloudDriverFileSource.isSeedFile(aFile.FSFile) then
if NOT TiCloudDriverFileSource.isSeedFile(params.displayFile.FSFile) then
Exit;
image:= NSImage.imageWithSystemSymbolName_accessibilityDescription(
NSSTR('icloud.and.arrow.down'), nil );
destRect.size:= image.size;
destRect.origin.x:= aRect.Right - Round(image.size.width) - 8;
destRect.origin.y:= aRect.Top + (aRect.Height-Round(image.size.height))/2;
destRect.origin.x:= params.drawingRect.Right - Round(image.size.width) - 8;
destRect.origin.y:= params.drawingRect.Top + (params.drawingRect.Height-Round(image.size.height))/2;
NSGraphicsContext.classSaveGraphicsState;
try
@ -91,7 +89,7 @@ begin
NSGraphicsContext.classRestoreGraphicsState;
end;
aRect.Right:= Round(destRect.origin.x) - 4;
params.drawingRect.Right:= Round(destRect.origin.x) - 4;
end;
{ TiCloudDriverFileSource }