fpspreadsheet: Add property SelectionPen to WorksheetGrid

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4449 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-01-21 11:39:05 +00:00
parent 7d731629e1
commit bbe063d794
2 changed files with 37 additions and 16 deletions

View File

@ -30,6 +30,8 @@ object MainForm: TMainForm
FrozenCols = 0 FrozenCols = 0
FrozenRows = 0 FrozenRows = 0
ReadFormulas = False ReadFormulas = False
SelectionPen.JoinStyle = pjsMiter
SelectionPen.Width = 3
TextOverflow = True TextOverflow = True
WorkbookSource = WorkbookSource WorkbookSource = WorkbookSource
Align = alClient Align = alClient
@ -49,6 +51,7 @@ object MainForm: TMainForm
TitleFont.Height = -13 TitleFont.Height = -13
TitleFont.Name = 'Arial' TitleFont.Name = 'Arial'
TitleStyle = tsNative TitleStyle = tsNative
UseXORFeatures = True
OnClickHyperlink = WorksheetGridClickHyperlink OnClickHyperlink = WorksheetGridClickHyperlink
end end
end end

View File

@ -39,6 +39,7 @@ type
TsHyperlinkClickEvent = procedure(Sender: TObject; TsHyperlinkClickEvent = procedure(Sender: TObject;
const AHyperlink: TsHyperlink) of object; const AHyperlink: TsHyperlink) of object;
// TsSelectionRectMode = (srmDThickXOR, srmThick, srmDottedXOR,
{@@ TsCustomWorksheetGrid is the ancestor of TsWorksheetGrid and is able to {@@ TsCustomWorksheetGrid is the ancestor of TsWorksheetGrid and is able to
display spreadsheet data along with their formatting. } display spreadsheet data along with their formatting. }
TsCustomWorksheetGrid = class(TCustomDrawGrid, IsSpreadsheetControl) TsCustomWorksheetGrid = class(TCustomDrawGrid, IsSpreadsheetControl)
@ -46,12 +47,7 @@ type
{ Private declarations } { Private declarations }
FWorkbookSource: TsWorkbookSource; FWorkbookSource: TsWorkbookSource;
FInternalWorkbookSource: TsWorkbookSource; FInternalWorkbookSource: TsWorkbookSource;
// FOwnedWorkbook: TsWorkbook;
// FOwnsWorkbook: Boolean;
// FOwnedWorksheet: TsWorksheet;
FHeaderCount: Integer; FHeaderCount: Integer;
// FInitColCount: Integer;
// FInitRowCount: Integer;
FFrozenCols: Integer; FFrozenCols: Integer;
FFrozenRows: Integer; FFrozenRows: Integer;
FEditText: String; FEditText: String;
@ -66,6 +62,7 @@ type
FDrawingCell: PCell; FDrawingCell: PCell;
FTextOverflowing: Boolean; FTextOverflowing: Boolean;
FEnhEditMode: Boolean; FEnhEditMode: Boolean;
FSelPen: TPen;
FHyperlinkTimer: TTimer; FHyperlinkTimer: TTimer;
FHyperlinkCell: PCell; // Selected cell if it stores a hyperlink FHyperlinkCell: PCell; // Selected cell if it stores a hyperlink
FOnClickHyperlink: TsHyperlinkClickEvent; FOnClickHyperlink: TsHyperlinkClickEvent;
@ -153,6 +150,7 @@ type
procedure SetNumberFormats(ALeft, ATop, ARight, ABottom: Integer; AValue: String); procedure SetNumberFormats(ALeft, ATop, ARight, ABottom: Integer; AValue: String);
procedure SetReadFormulas(AValue: Boolean); procedure SetReadFormulas(AValue: Boolean);
procedure SetRowHeights(ARow: Integer; AValue: Integer); procedure SetRowHeights(ARow: Integer; AValue: Integer);
procedure SetSelPen(AValue: TPen);
procedure SetShowGridLines(AValue: Boolean); procedure SetShowGridLines(AValue: Boolean);
procedure SetShowHeaders(AValue: Boolean); procedure SetShowHeaders(AValue: Boolean);
procedure SetTextRotation(ACol, ARow: Integer; AValue: TsTextRotation); procedure SetTextRotation(ACol, ARow: Integer; AValue: TsTextRotation);
@ -222,6 +220,7 @@ type
procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override;
// function SelectCell(AGridCol, AGridRow: Integer): Boolean; override; // function SelectCell(AGridCol, AGridRow: Integer): Boolean; override;
procedure SelectEditor; override; procedure SelectEditor; override;
procedure SelPenChangeHandler(Sender: TObject);
procedure SetEditText(ACol, ARow: Longint; const AValue: string); override; procedure SetEditText(ACol, ARow: Longint; const AValue: string); override;
procedure Setup; procedure Setup;
procedure Sort(AColSorting: Boolean; AIndex, AIndxFrom, AIndxTo:Integer); override; procedure Sort(AColSorting: Boolean; AIndex, AIndxFrom, AIndxTo:Integer); override;
@ -243,6 +242,8 @@ type
{@@ Activates reading of RPN formulas. Should be turned off when {@@ Activates reading of RPN formulas. Should be turned off when
non-implemented formulas crashe reading of the spreadsheet file. } non-implemented formulas crashe reading of the spreadsheet file. }
property ReadFormulas: Boolean read FReadFormulas write SetReadFormulas; property ReadFormulas: Boolean read FReadFormulas write SetReadFormulas;
{@@ Pen used for drawing the selection rectangle }
property SelectionPen: TPen read FSelPen write SetSelPen;
{@@ Shows/hides vertical and horizontal grid lines } {@@ Shows/hides vertical and horizontal grid lines }
property ShowGridLines: Boolean read GetShowGridLines write SetShowGridLines default true; property ShowGridLines: Boolean read GetShowGridLines write SetShowGridLines default true;
{@@ Shows/hides column and row headers in the fixed col/row style of the grid. } {@@ Shows/hides column and row headers in the fixed col/row style of the grid. }
@ -476,6 +477,8 @@ type
{@@ Activates reading of RPN formulas. Should be turned off when {@@ Activates reading of RPN formulas. Should be turned off when
non-implemented formulas crashe reading of the spreadsheet file. } non-implemented formulas crashe reading of the spreadsheet file. }
property ReadFormulas; property ReadFormulas;
{@@ Pen used for drawing the selection rectangle }
property SelectionPen;
{@@ Shows/hides vertical and horizontal grid lines. } {@@ Shows/hides vertical and horizontal grid lines. }
property ShowGridLines; property ShowGridLines;
{@@ Shows/hides column and row headers in the fixed col/row style of the grid. } {@@ Shows/hides column and row headers in the fixed col/row style of the grid. }
@ -943,9 +946,13 @@ begin
FHeaderCount := 1; FHeaderCount := 1;
ColCount := DEFAULT_COL_COUNT + FHeaderCount; ColCount := DEFAULT_COL_COUNT + FHeaderCount;
RowCount := DEFAULT_ROW_COUNT + FHeaderCount; RowCount := DEFAULT_ROW_COUNT + FHeaderCount;
// FInitColCount := DEFAULT_COL_COUNT;
// FInitRowCount := DEFAULT_ROW_COUNT;
FCellFont := TFont.Create; FCellFont := TFont.Create;
FSelPen := TPen.Create;
FSelPen.Style := psSolid;
FSelPen.Width := 3;
FSelPen.Color := clBlack;
FSelPen.JoinStyle := pjsMiter;
FSelPen.OnChange := @SelPenChangeHandler;
FHyperlinkTimer := TTimer.Create(self); FHyperlinkTimer := TTimer.Create(self);
FHyperlinkTimer.Interval := HYPERLINK_TIMER_INTERVAL; FHyperlinkTimer.Interval := HYPERLINK_TIMER_INTERVAL;
FHyperlinkTimer.OnTimer := @HyperlinkTimerElapsed; FHyperlinkTimer.OnTimer := @HyperlinkTimerElapsed;
@ -964,6 +971,7 @@ begin
if FInternalWorkbookSource <> nil then if FInternalWorkbookSource <> nil then
FInternalWorkbookSource.RemoveListener(self); // will be destroyed automatically FInternalWorkbookSource.RemoveListener(self); // will be destroyed automatically
FreeAndNil(FCellFont); FreeAndNil(FCellFont);
FreeAndNil(FSelPen);
inherited Destroy; inherited Destroy;
end; end;
@ -2216,6 +2224,7 @@ var
P1, P2: TPoint; P1, P2: TPoint;
cell: PCell; cell: PCell;
r1,c1,r2,c2: Cardinal; r1,c1,r2,c2: Cardinal;
delta: Integer;
begin begin
if Worksheet = nil then if Worksheet = nil then
exit; exit;
@ -2233,19 +2242,17 @@ begin
P2 := CellRect(Selection.Right, Selection.Bottom).BottomRight; P2 := CellRect(Selection.Right, Selection.Bottom).BottomRight;
end; end;
// Cosmetics at the edges of the grid to avoid spurious rests // Cosmetics at the edges of the grid to avoid spurious rests
if Selection.Top > TopRow then dec(P1.Y) else inc(P1.Y); delta := FSelPen.Width div 2;
if Selection.Left > LeftCol then dec(P1.X) else inc(P1.X); if Selection.Top > TopRow then dec(P1.Y, delta) else inc(P1.Y, delta);
if Selection.Right = ColCount-1 then dec(P2.X); if Selection.Left > LeftCol then dec(P1.X, delta) else inc(P1.X, delta);
if Selection.Bottom = RowCount-1 then dec(P2.Y); if Selection.Right = ColCount-1 then dec(P2.X, delta);
if Selection.Bottom = RowCount-1 then dec(P2.Y, delta);
// Set up the canvas // Set up the canvas
Canvas.Pen.Style := psSolid; Canvas.Pen.Assign(FSelPen);
Canvas.Pen.Width := 3;
Canvas.Pen.JoinStyle := pjsMiter;
if UseXORFeatures then begin if UseXORFeatures then begin
Canvas.Pen.Color := clWhite; Canvas.Pen.Color := clWhite;
Canvas.Pen.Mode := pmXOR; Canvas.Pen.Mode := pmXOR;
end else end;
Canvas.Pen.Color := clBlack;
Canvas.Brush.Style := bsClear; Canvas.Brush.Style := bsClear;
// Paint // Paint
Canvas.Rectangle(P1.X, P1.Y, P2.X, P2.Y); Canvas.Rectangle(P1.X, P1.Y, P2.X, P2.Y);
@ -4106,6 +4113,12 @@ begin
GetWorkbookSource.SelectWorksheet(Workbook.GetWorksheetByIndex(AIndex)); GetWorkbookSource.SelectWorksheet(Workbook.GetWorksheetByIndex(AIndex));
end; end;
{@@ Event handler which fires when an element of the SelectionPen changes. }
procedure TsCustomWOrksheetGrid.SelPenChangeHandler(Sender: TObject);
begin
InvalidateGrid;
end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Standard method inherited from TCustomGrid. Fetches the text that is Standard method inherited from TCustomGrid. Fetches the text that is
currently in the editor. It is not yet transferred to the worksheet because currently in the editor. It is not yet transferred to the worksheet because
@ -5394,6 +5407,11 @@ begin
HeaderSized(false, ARow); HeaderSized(false, ARow);
end; end;
procedure TsCustomWorksheetGrid.SetSelPen(AValue: TPen);
begin
FSelPen.Assign(AValue);
InvalidateGrid;
end;
{ Shows / hides the worksheet's grid lines } { Shows / hides the worksheet's grid lines }
procedure TsCustomWorksheetGrid.SetShowGridLines(AValue: Boolean); procedure TsCustomWorksheetGrid.SetShowGridLines(AValue: Boolean);