fpspreadsheet: Add WorkbookTabControl to chartlink demo to select the (first) chart of the current sheet.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9474 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
243e25f62b
commit
bb303d45aa
@ -14,30 +14,6 @@ object Form1: TForm1
|
|||||||
Top = 38
|
Top = 38
|
||||||
Width = 5
|
Width = 5
|
||||||
end
|
end
|
||||||
object Chart: TChart
|
|
||||||
Left = 528
|
|
||||||
Height = 489
|
|
||||||
Top = 38
|
|
||||||
Width = 823
|
|
||||||
AxisList = <
|
|
||||||
item
|
|
||||||
Marks.LabelBrush.Style = bsClear
|
|
||||||
Minors = <>
|
|
||||||
Title.LabelFont.Orientation = 900
|
|
||||||
Title.LabelBrush.Style = bsClear
|
|
||||||
end
|
|
||||||
item
|
|
||||||
Alignment = calBottom
|
|
||||||
Marks.LabelBrush.Style = bsClear
|
|
||||||
Minors = <>
|
|
||||||
Title.LabelBrush.Style = bsClear
|
|
||||||
end>
|
|
||||||
Legend.SymbolWidth = 40
|
|
||||||
Title.Text.Strings = (
|
|
||||||
'TAChart'
|
|
||||||
)
|
|
||||||
Align = alClient
|
|
||||||
end
|
|
||||||
object Panel1: TPanel
|
object Panel1: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 38
|
Height = 38
|
||||||
@ -48,7 +24,7 @@ object Form1: TForm1
|
|||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 38
|
ClientHeight = 38
|
||||||
ClientWidth = 1351
|
ClientWidth = 1351
|
||||||
TabOrder = 2
|
TabOrder = 1
|
||||||
object lblFileNames: TLabel
|
object lblFileNames: TLabel
|
||||||
AnchorSideLeft.Control = Panel1
|
AnchorSideLeft.Control = Panel1
|
||||||
AnchorSideTop.Control = Panel1
|
AnchorSideTop.Control = Panel1
|
||||||
@ -119,12 +95,32 @@ object Form1: TForm1
|
|||||||
Caption = 'Panel2'
|
Caption = 'Panel2'
|
||||||
ClientHeight = 489
|
ClientHeight = 489
|
||||||
ClientWidth = 523
|
ClientWidth = 523
|
||||||
TabOrder = 3
|
TabOrder = 2
|
||||||
object sWorksheetGrid: TsWorksheetGrid
|
object Memo: TMemo
|
||||||
|
Left = 1
|
||||||
|
Height = 112
|
||||||
|
Top = 376
|
||||||
|
Width = 521
|
||||||
|
Align = alBottom
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
object sWorkbookTabControl1: TsWorkbookTabControl
|
||||||
Left = 1
|
Left = 1
|
||||||
Height = 375
|
Height = 375
|
||||||
Top = 1
|
Top = 1
|
||||||
Width = 521
|
Width = 521
|
||||||
|
TabIndex = 0
|
||||||
|
Tabs.Strings = (
|
||||||
|
'Sheet1'
|
||||||
|
)
|
||||||
|
Align = alClient
|
||||||
|
TabOrder = 1
|
||||||
|
WorkbookSource = sWorkbookSource
|
||||||
|
object sWorksheetGrid: TsWorksheetGrid
|
||||||
|
Left = 2
|
||||||
|
Height = 350
|
||||||
|
Top = 23
|
||||||
|
Width = 517
|
||||||
FrozenCols = 0
|
FrozenCols = 0
|
||||||
FrozenRows = 0
|
FrozenRows = 0
|
||||||
PageBreakPen.Color = clBlue
|
PageBreakPen.Color = clBlue
|
||||||
@ -138,17 +134,46 @@ object Form1: TForm1
|
|||||||
DefaultColWidth = 64
|
DefaultColWidth = 64
|
||||||
DefaultRowHeight = 22
|
DefaultRowHeight = 22
|
||||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goSmoothScroll]
|
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goSmoothScroll]
|
||||||
TabOrder = 0
|
|
||||||
end
|
|
||||||
object Memo: TMemo
|
|
||||||
Left = 1
|
|
||||||
Height = 112
|
|
||||||
Top = 376
|
|
||||||
Width = 521
|
|
||||||
Align = alBottom
|
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
object Panel3: TPanel
|
||||||
|
Left = 528
|
||||||
|
Height = 489
|
||||||
|
Top = 38
|
||||||
|
Width = 823
|
||||||
|
Align = alClient
|
||||||
|
BevelOuter = bvNone
|
||||||
|
Caption = 'No chart on this worksheet'
|
||||||
|
ClientHeight = 489
|
||||||
|
ClientWidth = 823
|
||||||
|
TabOrder = 3
|
||||||
|
object Chart: TChart
|
||||||
|
Left = 0
|
||||||
|
Height = 489
|
||||||
|
Top = 0
|
||||||
|
Width = 823
|
||||||
|
AxisList = <
|
||||||
|
item
|
||||||
|
Marks.LabelBrush.Style = bsClear
|
||||||
|
Minors = <>
|
||||||
|
Title.LabelFont.Orientation = 900
|
||||||
|
Title.LabelBrush.Style = bsClear
|
||||||
|
end
|
||||||
|
item
|
||||||
|
Alignment = calBottom
|
||||||
|
Marks.LabelBrush.Style = bsClear
|
||||||
|
Minors = <>
|
||||||
|
Title.LabelBrush.Style = bsClear
|
||||||
|
end>
|
||||||
|
Legend.SymbolWidth = 40
|
||||||
|
Title.Text.Strings = (
|
||||||
|
'TAChart'
|
||||||
|
)
|
||||||
|
Align = alClient
|
||||||
|
end
|
||||||
|
end
|
||||||
object sWorkbookSource: TsWorkbookSource
|
object sWorkbookSource: TsWorkbookSource
|
||||||
FileFormat = sfUser
|
FileFormat = sfUser
|
||||||
Options = [boAutoCalc, boReadFormulas]
|
Options = [boAutoCalc, boReadFormulas]
|
||||||
|
@ -26,8 +26,10 @@ type
|
|||||||
OpenDialog: TOpenDialog;
|
OpenDialog: TOpenDialog;
|
||||||
Panel1: TPanel;
|
Panel1: TPanel;
|
||||||
Panel2: TPanel;
|
Panel2: TPanel;
|
||||||
|
Panel3: TPanel;
|
||||||
Splitter1: TSplitter;
|
Splitter1: TSplitter;
|
||||||
sWorkbookSource: TsWorkbookSource;
|
sWorkbookSource: TsWorkbookSource;
|
||||||
|
sWorkbookTabControl1: TsWorkbookTabControl;
|
||||||
sWorksheetGrid: TsWorksheetGrid;
|
sWorksheetGrid: TsWorksheetGrid;
|
||||||
procedure btnBrowseClick(Sender: TObject);
|
procedure btnBrowseClick(Sender: TObject);
|
||||||
procedure btnOpenClick(Sender: TObject);
|
procedure btnOpenClick(Sender: TObject);
|
||||||
@ -52,7 +54,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
TypInfo,
|
TypInfo,
|
||||||
TAChartUtils, TAChartAxis, TAChartAxisUtils, TACustomSeries, TATransformations;
|
TAChartUtils, TAChartAxis, TACustomSeries, TATransformations;
|
||||||
|
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
@ -912,6 +912,8 @@ type
|
|||||||
property Items[AIndex: Integer]: TsChart read GetItem write SetItem; default;
|
property Items[AIndex: Integer]: TsChart read GetItem write SetItem; default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TsChartArray = array of TsChart;
|
||||||
|
|
||||||
|
|
||||||
function ChartColor(AColor: TsColor; ATransparency: Single = 0.0): TsChartColor;
|
function ChartColor(AColor: TsColor; ATransparency: Single = 0.0): TsChartColor;
|
||||||
|
|
||||||
|
@ -647,6 +647,7 @@ type
|
|||||||
function AddChart(AWidth, AHeight: Double; ARow, ACol: Cardinal;
|
function AddChart(AWidth, AHeight: Double; ARow, ACol: Cardinal;
|
||||||
AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
|
AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
|
||||||
function GetChartCount: Integer;
|
function GetChartCount: Integer;
|
||||||
|
function GetCharts: TsChartArray;
|
||||||
procedure RemoveAllCharts;
|
procedure RemoveAllCharts;
|
||||||
procedure RemoveChart(AChart: TsChart);
|
procedure RemoveChart(AChart: TsChart);
|
||||||
{$endif}
|
{$endif}
|
||||||
@ -949,6 +950,7 @@ type
|
|||||||
ARow, ACol: Cardinal; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
|
ARow, ACol: Cardinal; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
|
||||||
function GetChartByIndex(AIndex: Integer): TsChart;
|
function GetChartByIndex(AIndex: Integer): TsChart;
|
||||||
function GetChartCount: Integer;
|
function GetChartCount: Integer;
|
||||||
|
function GetChartIndex(AChart: TsChart): Integer;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
{ Utilities }
|
{ Utilities }
|
||||||
|
@ -29,10 +29,8 @@ function TsWorksheet.GetChartCount: Integer;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
chart: TsChart;
|
chart: TsChart;
|
||||||
idx: Integer;
|
|
||||||
begin
|
begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
idx := GetIndex;
|
|
||||||
for i := 0 to Workbook.GetChartCount-1 do
|
for i := 0 to Workbook.GetChartCount-1 do
|
||||||
begin
|
begin
|
||||||
chart := Workbook.GetChartByIndex(i);
|
chart := Workbook.GetChartByIndex(i);
|
||||||
@ -40,6 +38,30 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Collects all charts which are linked to this worksheet
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
function TsWorksheet.GetCharts: TsChartArray;
|
||||||
|
var
|
||||||
|
i, j, n: Integer;
|
||||||
|
chart: TsChart;
|
||||||
|
begin
|
||||||
|
Result := nil;
|
||||||
|
n := Workbook.GetChartCount;
|
||||||
|
j := 0;
|
||||||
|
SetLength(Result, n);
|
||||||
|
for i := 0 to n-1 do
|
||||||
|
begin
|
||||||
|
chart := Workbook.GetChartByIndex(i);
|
||||||
|
if chart.Worksheet = self then
|
||||||
|
begin
|
||||||
|
Result[j] := chart;
|
||||||
|
inc(j);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
SetLength(Result, j);
|
||||||
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Destroys all charts from the worksheet and removes them from the workbook's
|
Destroys all charts from the worksheet and removes them from the workbook's
|
||||||
internal FCharts list.
|
internal FCharts list.
|
||||||
@ -107,7 +129,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Returns the chart having the given index in the worksheet's chart list
|
Returns the chart having the given index in the workbook's chart list
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
function TsWorkbook.GetChartByIndex(AIndex: Integer): TsChart;
|
function TsWorkbook.GetChartByIndex(AIndex: Integer): TsChart;
|
||||||
begin
|
begin
|
||||||
@ -125,3 +147,14 @@ begin
|
|||||||
Result := FCharts.Count;
|
Result := FCharts.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Returns the index of the given chart in the workbook's chart list
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
function TsWorkbook.GetChartIndex(AChart: TsChart): Integer;
|
||||||
|
begin
|
||||||
|
for Result := 0 to FCharts.Count-1 do
|
||||||
|
if FCharts[Result] = AChart then
|
||||||
|
exit;
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
@ -1969,6 +1969,8 @@ end;
|
|||||||
|
|
||||||
procedure TsWorkbookChartLink.ListenerNotification(AChangedItems: TsNotificationItems;
|
procedure TsWorkbookChartLink.ListenerNotification(AChangedItems: TsNotificationItems;
|
||||||
AData: Pointer = nil);
|
AData: Pointer = nil);
|
||||||
|
var
|
||||||
|
charts: TsChartArray;
|
||||||
begin
|
begin
|
||||||
Unused(AData);
|
Unused(AData);
|
||||||
|
|
||||||
@ -1978,6 +1980,19 @@ begin
|
|||||||
ClearChart;
|
ClearChart;
|
||||||
UpdateChart;
|
UpdateChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Another worksheet is selected --> Select the first chart of the worksheet
|
||||||
|
if (lniWorksheet in AChangedItems) and (WorkbookSource <> nil) then
|
||||||
|
begin
|
||||||
|
charts := WorkbookSource.Worksheet.GetCharts;
|
||||||
|
if Length(charts) > 0 then
|
||||||
|
WorkbookChartIndex := WorkbookSource.Workbook.GetChartIndex(charts[0])
|
||||||
|
else
|
||||||
|
WorkbookChartIndex := -1;
|
||||||
|
ClearChart;
|
||||||
|
UpdateChart;
|
||||||
|
FChart.Visible := WorkbookChartIndex > -1;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsWorkbookChartLink.Notification(AComponent: TComponent; Operation: TOperation);
|
procedure TsWorkbookChartLink.Notification(AComponent: TComponent; Operation: TOperation);
|
||||||
|
Loading…
Reference in New Issue
Block a user