home *** CD-ROM | disk | FTP | other *** search
- {**********************************************}
- { TeeChart PageNum Tool }
- { Copyright (c) 2000 by David Berneda }
- {**********************************************}
- {$I teedefs.inc}
- unit TeePageNumTool;
-
- { This unit implements a Chart Tool example:
-
- TPageNumTool
-
- This tool is used to display the current page number.
- The Chart MaxPointsPerPage property should be bigger than zero,
- to divide a chart in pages.
- }
- interface
-
- Uses Windows, Classes, TeCanvas, TeEngine, Chart;
-
- type
- TPageNumShape=class(TTeeCustomShapePosition)
- published
- property Bevel;
- property BevelWidth;
- property Brush;
- property Color;
- property CustomPosition;
- property Font;
- property Frame;
- property Gradient;
- property Left;
- property ShadowColor;
- property ShadowSize;
- property ShapeStyle;
- property Top;
- property Transparency;
- property Transparent;
- property Visible default True;
- end;
-
- TPageNumPosition=(ppLeftTop,ppLeftBottom,ppRightTop,ppRightBottom);
-
- TPageNumTool=class(TTeeCustomTool)
- private
- FFormat : String;
- FPosition : TPageNumPosition;
- FShape : TPageNumShape;
- Procedure DrawPageNum;
- function IsFormatStored: Boolean;
- procedure SetFormat(const Value: String);
- procedure SetPosition(const Value: TPageNumPosition);
- procedure SetShape(const Value: TPageNumShape);
- protected
- Procedure ChartEvent(AEvent:TChartToolEvent); override;
- class Function GetEditorClass:String; override;
- procedure SetParentChart(const Value: TCustomAxisPanel); override;
- public
- Constructor Create(AOwner:TComponent); override;
- Destructor Destroy; override;
- class Function Description:String; override;
- published
- property Active;
- property Format:String read FFormat write SetFormat stored IsFormatStored;
- property Position:TPageNumPosition read FPosition write SetPosition
- default ppLeftTop;
- property Shape:TPageNumShape read FShape write SetShape;
- end;
-
- implementation
-
- Uses TeeConst, SysUtils;
-
- { TPageNumTool }
- Constructor TPageNumTool.Create(AOwner: TComponent);
- begin
- inherited;
- FShape:=TPageNumShape.Create(nil);
- FPosition:=ppLeftTop;
- FFormat:=TeeMsg_PageOfPages;
- end;
-
- Destructor TPageNumTool.Destroy;
- begin
- FShape.Free;
- inherited;
- end;
-
- procedure TPageNumTool.ChartEvent(AEvent: TChartToolEvent);
- begin
- inherited;
- if AEvent=cteAfterDraw then DrawPageNum;
- end;
-
- procedure TPageNumTool.DrawPageNum;
- var x : Integer;
- y : Integer;
- tmpX : Integer;
- tmpY : Integer;
- tmp : String;
- begin
- With ParentChart.Canvas do
- begin
- tmp:=SysUtils.Format( FFormat,
- [TCustomChart(ParentChart).Page,TCustomChart(ParentChart).NumPages]);
- AssignFont(Self.Shape.Font);
-
- if Shape.CustomPosition then
- begin
- x:=Shape.Left+4;
- y:=Shape.Top+2;
- end
- else
- begin
- tmpX:=ParentChart.Width-TextWidth(tmp)-8;
- tmpY:=ParentChart.Height-TextHeight(tmp)-8;
- Case Position of
- ppLeftTop : begin x:=10; y:=10; end;
- ppLeftBottom : begin x:=10; y:=tmpY; end;
- ppRightTop : begin x:=tmpX; y:=10; end;
- else
- begin x:=tmpX; y:=tmpY; end;
- end;
- end;
-
- With Shape.ShapeBounds do
- begin
- Left:=x-4;
- Right:=x+TextWidth(tmp)+2;
- Top:=y-2;
- Bottom:=y+TextHeight(tmp)+2;
- end;
- if Shape.Visible then Shape.Draw;
- BackMode:=cbmTransparent;
- TextOut(x,y, tmp);
- end;
- end;
-
- procedure TPageNumTool.SetFormat(const Value: String);
- begin
- SetStringProperty(FFormat,Value);
- end;
-
- procedure TPageNumTool.SetPosition(const Value: TPageNumPosition);
- begin
- if FPosition<>Value then
- begin
- FPosition:=Value;
- Repaint;
- end;
- end;
-
- class function TPageNumTool.Description: String;
- begin
- result:='Page Number';
- end;
-
- procedure TPageNumTool.SetParentChart(const Value: TCustomAxisPanel);
- begin
- inherited;
- Shape.ParentChart:=Value;
- if Assigned(ParentChart) then Repaint;
- end;
-
- procedure TPageNumTool.SetShape(const Value: TPageNumShape);
- begin
- FShape.Assign(Value);
- end;
-
- class function TPageNumTool.GetEditorClass: String;
- begin
- result:='TPageNumToolEdit';
- end;
-
- function TPageNumTool.IsFormatStored: Boolean;
- begin
- result:=FFormat<>TeeMsg_PageOfPages;
- end;
-
- initialization
- RegisterTeeTools([TPageNumTool])
- finalization
- UnRegisterTeeTools([TPageNumTool]);
- end.
-