You've already forked lazarus-ccr
fpspreadsheet: Experimental implementation of moving of columns (see http://forum.lazarus.freepascal.org/index.php/topic,35733.0.html)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5750 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -61,6 +61,7 @@ type
|
|||||||
function GetFirst: PsRowCol;
|
function GetFirst: PsRowCol;
|
||||||
function GetLast: PsRowCol;
|
function GetLast: PsRowCol;
|
||||||
procedure InsertRowOrCol(AIndex: Cardinal; IsRow: Boolean);
|
procedure InsertRowOrCol(AIndex: Cardinal; IsRow: Boolean);
|
||||||
|
procedure MoveAlongRow(ARow, AFromCol, AToCol: Cardinal);
|
||||||
procedure Remove(ARow, ACol: Cardinal); overload;
|
procedure Remove(ARow, ACol: Cardinal); overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -607,6 +608,52 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
This method moves the cell in the specified row (ARow) and at column AFromCol
|
||||||
|
along the row before the column with index AToCol.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure TsRowColAVLTree.MoveAlongRow(ARow, AFromCol, AToCol: Cardinal);
|
||||||
|
var
|
||||||
|
c: Cardinal;
|
||||||
|
node: TAVLTreeNode;
|
||||||
|
item: PsRowCol;
|
||||||
|
begin
|
||||||
|
if AFromCol = AToCol then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if AFromCol < AToCol then
|
||||||
|
begin
|
||||||
|
node := FindLowest;
|
||||||
|
while Assigned(node) do
|
||||||
|
begin
|
||||||
|
item := PsRowCol(node.Data);
|
||||||
|
if item^.Row > ARow then exit;
|
||||||
|
if item^.Row = ARow then break;
|
||||||
|
node := FindSuccessor(node);
|
||||||
|
end;
|
||||||
|
c := AFromCol;
|
||||||
|
while c < AToCol do begin
|
||||||
|
Exchange(ARow, c, ARow, c+1);
|
||||||
|
inc(c);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
node:= FindHighest;
|
||||||
|
while Assigned(node) do
|
||||||
|
begin
|
||||||
|
item := PsRowCol(node.Data);
|
||||||
|
if item^.Row < ARow then exit;
|
||||||
|
if item^.Row = ARow then break;
|
||||||
|
node := FindPrecessor(node);
|
||||||
|
end;
|
||||||
|
c := AFromCol;
|
||||||
|
while c > AToCol do begin
|
||||||
|
Exchange(ARow, c, ARow, c-1);
|
||||||
|
dec(c);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Removes the node, but does NOT destroy the associated data reocrd
|
Removes the node, but does NOT destroy the associated data reocrd
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
|
@ -450,6 +450,7 @@ type
|
|||||||
procedure DeleteRow(ARow: Cardinal);
|
procedure DeleteRow(ARow: Cardinal);
|
||||||
procedure InsertCol(ACol: Cardinal);
|
procedure InsertCol(ACol: Cardinal);
|
||||||
procedure InsertRow(ARow: Cardinal);
|
procedure InsertRow(ARow: Cardinal);
|
||||||
|
procedure MoveCol(AFromCol, AToCol: Cardinal);
|
||||||
function ReadDefaultColWidth(AUnits: TsSizeUnits): Single;
|
function ReadDefaultColWidth(AUnits: TsSizeUnits): Single;
|
||||||
function ReadDefaultRowHeight(AUnits: TsSizeUnits): Single;
|
function ReadDefaultRowHeight(AUnits: TsSizeUnits): Single;
|
||||||
function ReadColFont(ACol: PCol): TsFont;
|
function ReadColFont(ACol: PCol): TsFont;
|
||||||
@ -7397,6 +7398,32 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Moves a column from a specified column index to another column index.
|
||||||
|
The operation includes everything associated with the column (cell values,
|
||||||
|
cell properties, formats, formulas, column formats, column widths). Formulas
|
||||||
|
are automatically adjusted for the new position.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure TsWorksheet.MoveCol(AFromCol, AToCol: Cardinal);
|
||||||
|
var
|
||||||
|
r, c: Integer;
|
||||||
|
begin
|
||||||
|
if AFromCol = AToCol then
|
||||||
|
// Nothing to do
|
||||||
|
exit;
|
||||||
|
|
||||||
|
Workbook.DisableNotifications;
|
||||||
|
try
|
||||||
|
for r := 0 to GetLastRowIndex do begin
|
||||||
|
FCells.MoveAlongRow(r, AFromCol, AToCol);
|
||||||
|
FComments.MoveAlongRow(r, AFromCol, AToCol);
|
||||||
|
FHyperlinks.MoveAlongRow(r, AFromCol, AToCol);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Workbook.EnableNotifications;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Reads the value of the default column width and converts it to the specified
|
Reads the value of the default column width and converts it to the specified
|
||||||
units
|
units
|
||||||
|
@ -206,6 +206,7 @@ type
|
|||||||
function CalcWorksheetRowHeight(AValue: Integer): Single;
|
function CalcWorksheetRowHeight(AValue: Integer): Single;
|
||||||
function CellOverflow(ACol, ARow: Integer; AState: TGridDrawState;
|
function CellOverflow(ACol, ARow: Integer; AState: TGridDrawState;
|
||||||
out ACol1, ACol2: Integer; var ARect: TRect): Boolean;
|
out ACol1, ACol2: Integer; var ARect: TRect): Boolean;
|
||||||
|
procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); override;
|
||||||
procedure CreateHandle; override;
|
procedure CreateHandle; override;
|
||||||
procedure CreateNewWorkbook;
|
procedure CreateNewWorkbook;
|
||||||
procedure DblClick; override;
|
procedure DblClick; override;
|
||||||
@ -1595,6 +1596,14 @@ begin
|
|||||||
UpdateRowHeights(AGridRow);
|
UpdateRowHeights(AGridRow);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsCustomWorksheetGrid.ColRowMoved(IsColumn: Boolean;
|
||||||
|
FromIndex,ToIndex: Integer);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
if IsColumn then
|
||||||
|
Worksheet.MoveCol(GetWorksheetCol(FromIndex), GetWorksheetCol(ToIndex));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TsCustomWorksheetGrid.CreateHandle;
|
procedure TsCustomWorksheetGrid.CreateHandle;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
Reference in New Issue
Block a user