UPD: refactoring common code to uFileViewBaseGrid

This commit is contained in:
rich2014 2025-12-30 21:37:47 +08:00
commit f7628a0bdc
6 changed files with 81 additions and 60 deletions

View file

@ -332,7 +332,7 @@ end;"/>
<PackageName Value="Image32"/>
</Item13>
</RequiredPackages>
<Units Count="297">
<Units Count="298">
<Unit0>
<Filename Value="doublecmd.lpr"/>
<IsPartOfProject Value="True"/>
@ -2149,6 +2149,11 @@ end;"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uDarwinDC"/>
</Unit296>
<Unit297>
<Filename Value="fileviews\ufileviewbasegrid.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uFileViewBaseGrid"/>
</Unit297>
</Units>
</ProjectOptions>
<CompilerOptions>

View file

@ -375,10 +375,7 @@ procedure TBriefDrawGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y:
params.shift:= Shift;
params.x:= X;
params.y:= Y;
MouseToCell( X, Y, params.col, params.row );
if NOT self.IsRowIndexValid(params.row) then
Exit;
MouseToCellWithoutOutbound( X, Y, params.col, params.row );
index:= CellToIndex( params.col, params.row );
if index < 0 then
Exit;

View file

@ -21,7 +21,7 @@ uses
{$IFDEF DARWIN}
uDarwinFileView,
{$ENDIF}
uSmoothScrollingGrid,
uFileViewBaseGrid,
uFileViewWithGrid;
type
@ -32,7 +32,7 @@ type
{ TDrawGridEx }
TDrawGridEx = class(TSmoothScrollingGrid)
TDrawGridEx = class(TFileViewBaseGrid)
private
FMouseDownY: Integer;
FLastMouseMoveTime: QWord;
@ -74,8 +74,6 @@ type
procedure UpdateView;
function MouseOnGrid(X, Y: LongInt): Boolean;
// Returns height of all the header rows.
function GetHeaderHeight: Integer;
@ -92,6 +90,7 @@ type
property GridVertLine: Boolean read GetGridVertLine write SetGridVertLine;
property GridHorzLine: Boolean read GetGridHorzLine write SetGridHorzLine;
function CellToIndex(ACol, ARow: Integer): Integer; override;
property OnDrawCell: TFileViewOnDrawCell read FOnDrawCell write FOnDrawCell;
end;
@ -1132,17 +1131,13 @@ end;
function TColumnsFileView.GetFileIndexFromCursor(X, Y: Integer; out AtFileList: Boolean): PtrInt;
var
bTemp: Boolean;
iRow, iCol: LongInt;
begin
with dgPanel do
begin
bTemp:= AllowOutboundEvents;
AllowOutboundEvents:= False;
MouseToCell(X, Y, iCol, iRow);
AllowOutboundEvents:= bTemp;
Result:= IfThen(iRow < 0, InvalidFileIndex, iRow - FixedRows);
AtFileList := Y >= GetHeaderHeight;
MouseToCellWithoutOutbound(X, Y, iCol, iRow);
Result:= CellToIndex(iCol, iRow);
AtFileList:= (Result >= 0);
end;
end;
@ -2050,6 +2045,7 @@ var
var
handler: TFileSourceUIHandler;
params: TFileSourceUIParams;
index: Integer;
begin
params:= Default( TFileSourceUIParams );
params.sender:= self.ColumnsView;
@ -2063,18 +2059,16 @@ var
params.shift:= Shift;
params.x:= X;
params.y:= Y;
MouseToCell( X, Y, params.col, params.row );
if NOT self.IsRowIndexValid(params.row) then
Exit;
if params.row <= FixedRows then
MouseToCellWithoutOutbound( X, Y, params.col, params.row );
index:= CellToIndex( params.col, params.row );
if index < 0 then
Exit;
ColRowToOffset(True, True, params.col, params.drawingRect.Left, params.drawingRect.Right );
ColRowToOffset(False, True, params.row, params.drawingRect.Top, params.drawingRect.Bottom );
params.decorationRect:= params.drawingRect;
params.displayFile:= ColumnsView.FFiles[params.row - FixedRows];
params.displayFile:= ColumnsView.FFiles[index];
handler.click( params );
end;
@ -2231,18 +2225,6 @@ begin
if ColumnsView.IsMouseSelecting then DoMouseMoveScroll(X, Y);
end;
function TDrawGridEx.MouseOnGrid(X, Y: LongInt): Boolean;
var
bTemp: Boolean;
iRow, iCol: LongInt;
begin
bTemp:= AllowOutboundEvents;
AllowOutboundEvents:= False;
MouseToCell(X, Y, iCol, iRow);
AllowOutboundEvents:= bTemp;
Result:= not ((iCol < 0) and (iRow < 0));
end;
function TDrawGridEx.GetHeaderHeight: Integer;
var
i : Integer;
@ -2430,5 +2412,13 @@ begin
end;
end;
function TDrawGridEx.CellToIndex(ACol, ARow: Integer): Integer;
begin
Result:= -1;
if (ARow < 0) or (ARow >= RowCount) then
Exit;
Result:= ARow - FixedRows;
end;
end.

View file

@ -0,0 +1,50 @@
unit uFileViewBaseGrid;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils,
uSmoothScrollingGrid;
type
{ TFileViewBaseGrid }
TFileViewBaseGrid = class( TSmoothScrollingGrid )
public
function MouseOnGrid(X, Y: LongInt): Boolean;
procedure MouseToCellWithoutOutbound(X, Y: Integer; out ACol, ARow: Longint);
function CellToIndex(ACol, ARow: Integer): Integer; virtual; abstract;
end;
implementation
{ TFileViewBaseGrid }
function TFileViewBaseGrid.MouseOnGrid(X, Y: LongInt): Boolean;
var
bTemp: Boolean;
iRow, iCol: LongInt;
begin
bTemp:= AllowOutboundEvents;
AllowOutboundEvents:= False;
MouseToCell(X, Y, iCol, iRow);
AllowOutboundEvents:= bTemp;
Result:= not (CellToIndex(iCol, iRow) < 0);
end;
procedure TFileViewBaseGrid.MouseToCellWithoutOutbound(X, Y: Integer; out ACol,
ARow: Longint);
var
bTemp: Boolean;
begin
bTemp:= AllowOutboundEvents;
AllowOutboundEvents:= False;
MouseToCell(X, Y, ACol, ARow);
AllowOutboundEvents:= bTemp;
end;
end.

View file

@ -8,7 +8,7 @@ uses
Classes, SysUtils, Controls, Grids, Graphics, StdCtrls, LCLVersion,
uDisplayFile, DCXmlConfig, uFileSorting, uFileProperty,
uFileViewWithMainCtrl, uFile, uFileViewHeader, uFileView, uFileSource,
uSmoothScrollingGrid;
uFileViewBaseGrid;
type
@ -16,7 +16,7 @@ type
{ TFileViewGrid }
TFileViewGrid = class(TSmoothScrollingGrid)
TFileViewGrid = class(TFileViewBaseGrid)
protected
FLastMouseMoveTime: QWord;
FLastMouseScrollTime: QWord;
@ -30,7 +30,6 @@ type
procedure ColWidthsChanged; override;
procedure FinalizeWnd; override;
procedure InitializeWnd; override;
function MouseOnGrid(X, Y: LongInt): Boolean;
procedure DoOnResize; override;
procedure DragCanceled; override;
procedure KeyDown(var Key : Word; Shift : TShiftState); override;
@ -51,7 +50,6 @@ type
{$endif}
public
constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; virtual;
function CellToIndex(ACol, ARow: Integer): Integer; virtual; abstract;
procedure IndexToCell(Index: Integer; out ACol, ARow: Integer); virtual; abstract;
property BorderWidth: Integer read GetBorderWidth;
end;
@ -246,18 +244,6 @@ begin
CalculateColRowCount;
end;
function TFileViewGrid.MouseOnGrid(X, Y: LongInt): Boolean;
var
bTemp: Boolean;
iRow, iCol: LongInt;
begin
bTemp:= AllowOutboundEvents;
AllowOutboundEvents:= False;
MouseToCell(X, Y, iCol, iRow);
AllowOutboundEvents:= bTemp;
Result:= not (CellToIndex(iCol, iRow) < 0);
end;
procedure TFileViewGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
@ -671,17 +657,13 @@ end;
function TFileViewWithGrid.GetFileIndexFromCursor(X, Y: Integer; out AtFileList: Boolean): PtrInt;
var
bTemp: Boolean;
iRow, iCol: LongInt;
begin
with dgPanel do
begin
bTemp:= AllowOutboundEvents;
AllowOutboundEvents:= False;
MouseToCell(X, Y, iCol, iRow);
AllowOutboundEvents:= bTemp;
MouseToCellWithoutOutbound(X, Y, iCol, iRow);
Result:= CellToIndex(iCol, iRow);
AtFileList := True; // Always at file list because header in dgPanel not used
AtFileList:= (Result >= 0);
end;
end;

View file

@ -287,10 +287,7 @@ procedure TThumbDrawGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
params.shift:= Shift;
params.x:= X;
params.y:= Y;
MouseToCell( X, Y, params.col, params.row );
if NOT self.IsRowIndexValid(params.row) then
Exit;
MouseToCellWithoutOutbound( X, Y, params.col, params.row );
index:= CellToIndex( params.col, params.row );
if index < 0 then
Exit;