fpspreadsheet: Consider hyperlinks when inserting/deleting rows/columns

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3975 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-03-01 22:20:03 +00:00
parent 5a4bb856f5
commit f92da238ee

View File

@ -6409,6 +6409,7 @@ var
firstRow, lastCol, lastRow: Cardinal; firstRow, lastCol, lastRow: Cardinal;
rng: PsCellRange; rng: PsCellRange;
comment: PsComment; comment: PsComment;
hyperlink: PsHyperlink;
begin begin
lastCol := GetLastColIndex; lastCol := GetLastColIndex;
lastRow := GetLastOccupiedRowIndex; lastRow := GetLastOccupiedRowIndex;
@ -6477,6 +6478,22 @@ begin
AVLNode := nextAVLNode; AVLNode := nextAVLNode;
end; end;
// Fix hyperlinks
AVLNode := FHyperlinks.FindLowest;
while Assigned(AVLNode) do begin
nextAVLNode := FHyperlinks.FindSuccessor(AVLNode);
hyperlink := PsHyperlink(AVLNode.Data);
// Update all hyperlink column indexes to the right of the deleted column
if hyperlink^.Col > ACol then
dec(hyperlink^.Col)
else
// Remove the hyperlink if it is in the deleted column
if hyperlink^.Col = ACol then
WriteHyperlink(hyperlink^.Row, ACol, '');
AVLNode := nextAVLNode;
end;
// Delete cells // Delete cells
for r := lastRow downto firstRow do for r := lastRow downto firstRow do
RemoveAndFreeCell(r, ACol); RemoveAndFreeCell(r, ACol);
@ -6520,6 +6537,7 @@ var
cell, nextcell, basecell: PCell; cell, nextcell, basecell: PCell;
rng: PsCellRange; rng: PsCellRange;
comment: PsComment; comment: PsComment;
hyperlink: PsHyperlink;
begin begin
firstCol := GetFirstColIndex; firstCol := GetFirstColIndex;
lastCol := GetLastOccupiedColIndex; lastCol := GetLastOccupiedColIndex;
@ -6586,6 +6604,21 @@ begin
AVLNode := nextAVLNode; AVLNode := nextAVLNode;
end; end;
// Fix hyperlinks
AVLNode := FHyperlinks.FindLowest;
while Assigned(AVLNode) do begin
nextAVLNode := FHyperlinks.FindSuccessor(AVLNode);;
hyperlink := PsHyperlink(AVLNode.Data);
// Update all hyperlink row indexes below the deleted row
if hyperlink^.Row > ARow then
dec(hyperlink^.Row)
else
// Remove the hyperlink if it is in the deleted row
if hyperlink^.Row = ARow then
WriteHyperlink(ARow, hyperlink^.Col, '');
AVLNode := nextAVLNode;
end;
// Delete cells // Delete cells
for c := lastCol downto 0 do for c := lastCol downto 0 do
RemoveAndFreeCell(ARow, c); RemoveAndFreeCell(ARow, c);
@ -6629,6 +6662,7 @@ var
AVLNode: TAVLTreeNode; AVLNode: TAVLTreeNode;
rng: PsCellRange; rng: PsCellRange;
comment: PsComment; comment: PsComment;
hyperlink: PsHyperlink;
begin begin
// Handling of shared formula references is too complicated for me... // Handling of shared formula references is too complicated for me...
// Split them into isolated cell formulas // Split them into isolated cell formulas
@ -6647,6 +6681,14 @@ begin
AVLNode := FComments.FindSuccessor(AVLNode); AVLNode := FComments.FindSuccessor(AVLNode);
end; end;
// Update column index of hyperlinks
AVLNode := FHyperlinks.FindLowest;
while Assigned(AVLNode) do begin
hyperlink := PsHyperlink(AVLNode.Data);
if hyperlink^.Col >= ACol then inc(hyperlink^.Col);
AVLNode := FHyperlinks.FindSuccessor(AVLNode);
end;
// Update column index of cell records // Update column index of cell records
AVLNode := FCells.FindLowest; AVLNode := FCells.FindLowest;
while Assigned(AVLNode) do begin while Assigned(AVLNode) do begin
@ -6756,6 +6798,7 @@ var
AVLNode: TAVLTreeNode; AVLNode: TAVLTreeNode;
rng: PsCellRange; rng: PsCellRange;
comment: PsComment; comment: PsComment;
hyperlink: PsHyperlink;
begin begin
// Handling of shared formula references is too complicated for me... // Handling of shared formula references is too complicated for me...
// Splits them into isolated cell formulas // Splits them into isolated cell formulas
@ -6774,6 +6817,14 @@ begin
AVLNode := FComments.FindSuccessor(AVLNode); AVLNode := FComments.FindSuccessor(AVLNode);
end; end;
// Update row index of cell hyperlinks
AVLNode := FHyperlinks.FindLowest;
while Assigned(AVLNode) do begin
hyperlink := PsHyperlink(AVLNode.Data);
if hyperlink^.Row >= ARow then inc(hyperlink^.Row);
AVLNode := FHyperlinks.FindSuccessor(AVLNode);
end;
// Update row index of cell records // Update row index of cell records
AVLNode := FCells.FindLowest; AVLNode := FCells.FindLowest;
while Assigned(AVLNode) do begin while Assigned(AVLNode) do begin