You've already forked lazarus-ccr
fpspreadsheet: Fix WorksheetGrid to show selection of merged cell range correctly. Fix cell content of blank cells after adding a hyperlink.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3980 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -1671,7 +1671,7 @@ begin
|
|||||||
if ACell^.ContentType = cctEmpty then
|
if ACell^.ContentType = cctEmpty then
|
||||||
begin
|
begin
|
||||||
ACell^.ContentType := cctUTF8String;
|
ACell^.ContentType := cctUTF8String;
|
||||||
if UriToFileName(hyperlink^.Target, fn) then
|
if (hyperlink^.Target[1] <> '#') and UriToFileName(hyperlink^.Target, fn) then
|
||||||
ACell^.UTF8StringValue := fn
|
ACell^.UTF8StringValue := fn
|
||||||
else
|
else
|
||||||
ACell^.UTF8StringValue := hyperlink^.Target;
|
ACell^.UTF8StringValue := hyperlink^.Target;
|
||||||
|
@@ -1497,18 +1497,19 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCellEdit.EditingDone;
|
procedure TsCellEdit.EditingDone;
|
||||||
var
|
var
|
||||||
r, c: Cardinal;
|
|
||||||
s: String;
|
s: String;
|
||||||
|
cell: PCell;
|
||||||
begin
|
begin
|
||||||
if Worksheet = nil then
|
if Worksheet = nil then
|
||||||
exit;
|
exit;
|
||||||
r := Worksheet.ActiveCellRow;
|
cell := Worksheet.FindCell(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol);
|
||||||
c := Worksheet.ActiveCellCol;
|
if Worksheet.IsMerged(cell) then
|
||||||
|
cell := Worksheet.FindMergeBase(cell);
|
||||||
s := Lines.Text;
|
s := Lines.Text;
|
||||||
if (s <> '') and (s[1] = '=') then
|
if (s <> '') and (s[1] = '=') then
|
||||||
Worksheet.WriteFormula(r, c, Copy(s, 2, Length(s)), true)
|
Worksheet.WriteFormula(cell, Copy(s, 2, Length(s)), true)
|
||||||
else
|
else
|
||||||
Worksheet.WriteCellValueAsString(r, c, s);
|
Worksheet.WriteCellValueAsString(cell, s);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
@@ -1560,14 +1561,21 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCellEdit.ListenerNotification(
|
procedure TsCellEdit.ListenerNotification(
|
||||||
AChangedItems: TsNotificationItems; AData: Pointer = nil);
|
AChangedItems: TsNotificationItems; AData: Pointer = nil);
|
||||||
|
var
|
||||||
|
cell: PCell;
|
||||||
begin
|
begin
|
||||||
if (FWorkbookSource = nil) then
|
if (FWorkbookSource = nil) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
if (lniSelection in AChangedItems) or
|
if (lniSelection in AChangedItems) or
|
||||||
((lniCell in AChangedItems) and (PCell(AData) = SelectedCell))
|
((lniCell in AChangedItems) and (PCell(AData) = SelectedCell))
|
||||||
then
|
then begin
|
||||||
ShowCell(SelectedCell);
|
if Worksheet.IsMerged(SelectedCell) then
|
||||||
|
cell := Worksheet.FindMergeBase(SelectedCell)
|
||||||
|
else
|
||||||
|
cell := SelectedCell;
|
||||||
|
ShowCell(cell);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@@ -68,7 +68,7 @@ type
|
|||||||
FTextOverflowing: Boolean;
|
FTextOverflowing: Boolean;
|
||||||
FEnhEditMode: Boolean;
|
FEnhEditMode: Boolean;
|
||||||
FHyperlinkTimer: TTimer;
|
FHyperlinkTimer: TTimer;
|
||||||
FHyperlinkCell: PCell;
|
FHyperlinkCell: PCell; // Selected cell if it stores a hyperlink
|
||||||
FOnClickHyperlink: TsHyperlinkClickEvent;
|
FOnClickHyperlink: TsHyperlinkClickEvent;
|
||||||
function CalcAutoRowHeight(ARow: Integer): Integer;
|
function CalcAutoRowHeight(ARow: Integer): Integer;
|
||||||
function CalcColWidth(AWidth: Single): Integer;
|
function CalcColWidth(AWidth: Single): Integer;
|
||||||
@@ -1713,7 +1713,8 @@ end;
|
|||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
This procedure is responsible for painting the focus rectangle. We don't want
|
This procedure is responsible for painting the focus rectangle. We don't want
|
||||||
the red dashed rectangle here, but prefer the thick Excel-like black border
|
the red dashed rectangle here, but prefer the thick Excel-like black border
|
||||||
line. This new focus rectangle is drawn by the method DrawSelection.
|
line. This new focus rectangle is drawn by the method DrawSelection because
|
||||||
|
the thick Excel border reaches into adjacent cells.
|
||||||
|
|
||||||
@param ACol Grid column index of the focused cell
|
@param ACol Grid column index of the focused cell
|
||||||
@param ARow Grid row index of the focused cell
|
@param ARow Grid row index of the focused cell
|
||||||
@@ -2000,10 +2001,23 @@ end;
|
|||||||
procedure TsCustomWorksheetGrid.DrawSelection;
|
procedure TsCustomWorksheetGrid.DrawSelection;
|
||||||
var
|
var
|
||||||
P1, P2: TPoint;
|
P1, P2: TPoint;
|
||||||
|
cell: PCell;
|
||||||
|
r1,c1,r2,c2: Cardinal;
|
||||||
|
rng: PsCellRange;
|
||||||
|
begin
|
||||||
|
// Selected cell
|
||||||
|
cell := Worksheet.FindCell(GetWorksheetRow(Selection.Top), GetWorksheetCol(Selection.Left));
|
||||||
|
if Worksheet.IsMerged(cell) then
|
||||||
|
begin
|
||||||
|
Worksheet.FindMergedRange(cell, r1,c1,r2,c2);
|
||||||
|
P1 := CellRect(GetGridCol(c1), GetGridRow(r1)).TopLeft;
|
||||||
|
P2 := CellRect(GetGridCol(c2), GetGridRow(r2)).BottomRight;
|
||||||
|
end else
|
||||||
begin
|
begin
|
||||||
// Cosmetics at the edges of the grid to avoid spurious rests
|
|
||||||
P1 := CellRect(Selection.Left, Selection.Top).TopLeft;
|
P1 := CellRect(Selection.Left, Selection.Top).TopLeft;
|
||||||
P2 := CellRect(Selection.Right, Selection.Bottom).BottomRight;
|
P2 := CellRect(Selection.Right, Selection.Bottom).BottomRight;
|
||||||
|
end;
|
||||||
|
// Cosmetics at the edges of the grid to avoid spurious rests
|
||||||
if Selection.Top > TopRow then dec(P1.Y) else inc(P1.Y);
|
if Selection.Top > TopRow then dec(P1.Y) else inc(P1.Y);
|
||||||
if Selection.Left > LeftCol then dec(P1.X) else inc(P1.X);
|
if Selection.Left > LeftCol then dec(P1.X) else inc(P1.X);
|
||||||
if Selection.Right = ColCount-1 then dec(P2.X);
|
if Selection.Right = ColCount-1 then dec(P2.X);
|
||||||
@@ -2131,7 +2145,9 @@ begin
|
|||||||
oldText := GetCellText(Col, Row);
|
oldText := GetCellText(Col, Row);
|
||||||
if oldText <> FEditText then
|
if oldText <> FEditText then
|
||||||
begin
|
begin
|
||||||
cell := Worksheet.GetCell(Row-FHeaderCount, Col-FHeaderCount);
|
cell := Worksheet.GetCell(GetWorksheetRow(Row), GetWorksheetCol(Col));
|
||||||
|
if Worksheet.IsMerged(cell) then
|
||||||
|
cell := Worksheet.FindMergeBase(cell);
|
||||||
if (FEditText <> '') and (FEditText[1] = '=') then
|
if (FEditText <> '') and (FEditText[1] = '=') then
|
||||||
Worksheet.WriteFormula(cell, Copy(FEditText, 2, Length(FEditText)), true)
|
Worksheet.WriteFormula(cell, Copy(FEditText, 2, Length(FEditText)), true)
|
||||||
else
|
else
|
||||||
@@ -2689,7 +2705,7 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
function TsCustomWorksheetGrid.GetCellText(ACol, ARow: Integer): String;
|
function TsCustomWorksheetGrid.GetCellText(ACol, ARow: Integer): String;
|
||||||
var
|
var
|
||||||
lCell: PCell;
|
cell: PCell;
|
||||||
r, c, i: Integer;
|
r, c, i: Integer;
|
||||||
s: String;
|
s: String;
|
||||||
begin
|
begin
|
||||||
@@ -2717,11 +2733,11 @@ begin
|
|||||||
begin
|
begin
|
||||||
r := ARow - FHeaderCount;
|
r := ARow - FHeaderCount;
|
||||||
c := ACol - FHeaderCount;
|
c := ACol - FHeaderCount;
|
||||||
lCell := Worksheet.FindCell(r, c);
|
cell := Worksheet.FindCell(r, c);
|
||||||
if lCell <> nil then
|
if cell <> nil then
|
||||||
begin
|
begin
|
||||||
Result := TrimToCell(lCell);
|
Result := TrimToCell(cell);
|
||||||
if Worksheet.ReadTextRotation(lCell) = rtStacked then
|
if Worksheet.ReadTextRotation(cell) = rtStacked then
|
||||||
begin
|
begin
|
||||||
s := Result;
|
s := Result;
|
||||||
Result := '';
|
Result := '';
|
||||||
@@ -2751,6 +2767,8 @@ begin
|
|||||||
if FEnhEditMode then // Initiated by "F2"
|
if FEnhEditMode then // Initiated by "F2"
|
||||||
begin
|
begin
|
||||||
cell := Worksheet.FindCell(GetWorksheetRow(ARow), GetWorksheetCol(ACol));
|
cell := Worksheet.FindCell(GetWorksheetRow(ARow), GetWorksheetCol(ACol));
|
||||||
|
if Worksheet.IsMerged(cell) then
|
||||||
|
cell := Worksheet.FindMergeBase(cell);
|
||||||
Result := Worksheet.ReadFormulaAsString(cell, true);
|
Result := Worksheet.ReadFormulaAsString(cell, true);
|
||||||
if Result <> '' then
|
if Result <> '' then
|
||||||
begin
|
begin
|
||||||
@@ -2772,7 +2790,8 @@ begin
|
|||||||
Result := '';
|
Result := '';
|
||||||
end else
|
end else
|
||||||
Result := GetCellText(aCol, aRow);
|
Result := GetCellText(aCol, aRow);
|
||||||
if Assigned(OnGetEditText) then OnGetEditText(Self, aCol, aRow, Result);
|
if Assigned(OnGetEditText) then
|
||||||
|
OnGetEditText(Self, aCol, aRow, Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user