You've already forked lazarus-ccr
NiceChart: Make sure that TNiceChart.Calculate is always called with a valid canvas. This fixes crash in cocoa.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8867 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -136,6 +136,7 @@ type
|
|||||||
procedure InternalClear;
|
procedure InternalClear;
|
||||||
procedure InternalPaint(ACanvas: TCanvas);
|
procedure InternalPaint(ACanvas: TCanvas);
|
||||||
procedure Calculate(AWidth, AHeight: Integer);
|
procedure Calculate(AWidth, AHeight: Integer);
|
||||||
|
procedure DoCalculate(ACanvas: TCanvas; AWidth, AHeight: Integer);
|
||||||
procedure DoPaint;
|
procedure DoPaint;
|
||||||
procedure SetGridColor(const Value: TColor);
|
procedure SetGridColor(const Value: TColor);
|
||||||
procedure SetShowLegend(const Value: Boolean);
|
procedure SetShowLegend(const Value: Boolean);
|
||||||
@ -908,6 +909,26 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TNiceChart.Calculate(AWidth, AHeight: Integer);
|
procedure TNiceChart.Calculate(AWidth, AHeight: Integer);
|
||||||
|
var
|
||||||
|
bmp: TBitmap;
|
||||||
|
begin
|
||||||
|
if Canvas.HandleAllocated then
|
||||||
|
DoCalculate(Canvas, AWidth, AHeight)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
// Use an auxiliary bitmap in case of early calls when the Canvas has not handle, yet.
|
||||||
|
bmp := TBitmap.Create;
|
||||||
|
try
|
||||||
|
bmp.Width := AWidth;
|
||||||
|
bmp.Height := AHeight;
|
||||||
|
DoCalculate(bmp.Canvas, AWidth, AHeight);
|
||||||
|
finally
|
||||||
|
bmp.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TNiceChart.DoCalculate(ACanvas: TCanvas; AWidth, AHeight: Integer);
|
||||||
var
|
var
|
||||||
x, w, h, y, g: Integer;
|
x, w, h, y, g: Integer;
|
||||||
Titled: Boolean;
|
Titled: Boolean;
|
||||||
@ -924,24 +945,24 @@ begin
|
|||||||
Titled := False;
|
Titled := False;
|
||||||
if FShowTitle and (FTitle <> '') then
|
if FShowTitle and (FTitle <> '') then
|
||||||
begin
|
begin
|
||||||
Canvas.Font.Assign(TitleFont);
|
ACanvas.Font.Assign(TitleFont);
|
||||||
w := Canvas.TextHeight(FTitle);
|
w := ACanvas.TextHeight(FTitle);
|
||||||
RcTitle := Rect(RcChart.Left, RcChart.Top, RcChart.Right, RcChart.Left + w);
|
RcTitle := Rect(RcChart.Left, RcChart.Top, RcChart.Right, RcChart.Left + w);
|
||||||
DrawText(Canvas.Handle, PChar(FTitle), Length(FTitle), RcTitle,
|
DrawText(ACanvas.Handle, PChar(FTitle), Length(FTitle), RcTitle,
|
||||||
DT_CENTER or DT_VCENTER or DT_WORDBREAK or DT_CALCRECT);
|
DT_CENTER or DT_VCENTER or DT_WORDBREAK or DT_CALCRECT);
|
||||||
RcChart.Top := RcTitle.Bottom + FInnerMargin;
|
RcChart.Top := RcTitle.Bottom + FInnerMargin;
|
||||||
Titled := True;
|
Titled := True;
|
||||||
end else
|
end else
|
||||||
SetRectEmpty(RcTitle);
|
SetRectEmpty(RcTitle);
|
||||||
|
|
||||||
Canvas.Font.Assign(FNormalFont);
|
ACanvas.Font.Assign(FNormalFont);
|
||||||
h := Canvas.TextHeight('Ag');
|
h := ACanvas.TextHeight('Ag');
|
||||||
RcChart.Bottom := RcChart.Bottom - (2 * h) - FInnerMargin - FTickLength - FSmallmargin;
|
RcChart.Bottom := RcChart.Bottom - (2 * h) - FInnerMargin - FTickLength - FSmallmargin;
|
||||||
|
|
||||||
BuildYAxis;
|
BuildYAxis;
|
||||||
w := 0;
|
w := 0;
|
||||||
for x := 0 to YAxis.Count-1
|
for x := 0 to YAxis.Count-1 do
|
||||||
do w := Max(w, Canvas.TextWidth(PAxisInfo(YAxis[x])^.Caption));
|
w := Max(w, ACanvas.TextWidth(PAxisInfo(YAxis[x])^.Caption));
|
||||||
RcChart.Left := RcChart.Left + h + FInnerMargin + w + FTickLength + FSmallMargin;
|
RcChart.Left := RcChart.Left + h + FInnerMargin + w + FTickLength + FSmallMargin;
|
||||||
RcTitle.Left := RcChart.Left;
|
RcTitle.Left := RcChart.Left;
|
||||||
RcTitle.Right := RcChart.Right;
|
RcTitle.Right := RcChart.Right;
|
||||||
@ -949,16 +970,16 @@ begin
|
|||||||
|
|
||||||
if FShowLegend and (List.Count > 0) then
|
if FShowLegend and (List.Count > 0) then
|
||||||
begin
|
begin
|
||||||
Canvas.Font.Assign(FNormalFont);
|
ACanvas.Font.Assign(FNormalFont);
|
||||||
w := 0;
|
w := 0;
|
||||||
h := FInnerMargin;
|
h := FInnerMargin;
|
||||||
g := Canvas.TextHeight('Ag');
|
g := ACanvas.TextHeight('Ag');
|
||||||
for x := 0 to List.Count-1 do
|
for x := 0 to List.Count-1 do
|
||||||
begin
|
begin
|
||||||
TNiceSeries(List[x]).Top := h;
|
TNiceSeries(List[x]).Top := h;
|
||||||
Temp.Text := Trim(TNiceSeries(List[x]).FCaption);
|
Temp.Text := Trim(TNiceSeries(List[x]).FCaption);
|
||||||
for y := 0 to Temp.Count-1
|
for y := 0 to Temp.Count-1 do
|
||||||
do w := Max(w, Canvas.TextWidth(Trim(Temp[y])));
|
w := Max(w, ACanvas.TextWidth(Trim(Temp[y])));
|
||||||
h := h + Max(FLegendItemSize, Temp.Count * g);
|
h := h + Max(FLegendItemSize, Temp.Count * g);
|
||||||
if (x <> List.Count-1)
|
if (x <> List.Count-1)
|
||||||
then h := h + FSmallMargin;
|
then h := h + FSmallMargin;
|
||||||
|
Reference in New Issue
Block a user