home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / TeeChartPro / TeeChart5Delphi5Eval.exe / %MAINDIR% / Examples / Features / TeePageNumTool.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-10  |  4.5 KB  |  184 lines

  1. {**********************************************}
  2. {   TeeChart PageNum Tool                      }
  3. {   Copyright (c) 2000 by David Berneda        }
  4. {**********************************************}
  5. {$I teedefs.inc}
  6. unit TeePageNumTool;
  7.  
  8. { This unit implements a Chart Tool example:
  9.  
  10.    TPageNumTool
  11.  
  12.   This tool is used to display the current page number.
  13.   The Chart MaxPointsPerPage property should be bigger than zero,
  14.   to divide a chart in pages.
  15. }
  16. interface
  17.  
  18. Uses Windows, Classes, TeCanvas, TeEngine, Chart;
  19.  
  20. type
  21.   TPageNumShape=class(TTeeCustomShapePosition)
  22.   published
  23.     property Bevel;
  24.     property BevelWidth;
  25.     property Brush;
  26.     property Color;
  27.     property CustomPosition;
  28.     property Font;
  29.     property Frame;
  30.     property Gradient;
  31.     property Left;
  32.     property ShadowColor;
  33.     property ShadowSize;
  34.     property ShapeStyle;
  35.     property Top;
  36.     property Transparency;
  37.     property Transparent;
  38.     property Visible default True;
  39.   end;
  40.  
  41.   TPageNumPosition=(ppLeftTop,ppLeftBottom,ppRightTop,ppRightBottom);
  42.  
  43.   TPageNumTool=class(TTeeCustomTool)
  44.   private
  45.     FFormat   : String;
  46.     FPosition : TPageNumPosition;
  47.     FShape    : TPageNumShape;
  48.     Procedure DrawPageNum;
  49.     function IsFormatStored: Boolean;
  50.     procedure SetFormat(const Value: String);
  51.     procedure SetPosition(const Value: TPageNumPosition);
  52.     procedure SetShape(const Value: TPageNumShape);
  53.   protected
  54.     Procedure ChartEvent(AEvent:TChartToolEvent); override;
  55.     class Function GetEditorClass:String; override;
  56.     procedure SetParentChart(const Value: TCustomAxisPanel); override;
  57.   public
  58.     Constructor Create(AOwner:TComponent); override;
  59.     Destructor Destroy; override;
  60.     class Function Description:String; override;
  61.   published
  62.     property Active;
  63.     property Format:String read FFormat write SetFormat stored IsFormatStored;
  64.     property Position:TPageNumPosition read FPosition write SetPosition
  65.               default ppLeftTop;
  66.     property Shape:TPageNumShape read FShape write SetShape;
  67.   end;
  68.  
  69. implementation
  70.  
  71. Uses TeeConst, SysUtils;
  72.  
  73. { TPageNumTool }
  74. Constructor TPageNumTool.Create(AOwner: TComponent);
  75. begin
  76.   inherited;
  77.   FShape:=TPageNumShape.Create(nil);
  78.   FPosition:=ppLeftTop;
  79.   FFormat:=TeeMsg_PageOfPages;
  80. end;
  81.  
  82. Destructor TPageNumTool.Destroy;
  83. begin
  84.   FShape.Free;
  85.   inherited;
  86. end;
  87.  
  88. procedure TPageNumTool.ChartEvent(AEvent: TChartToolEvent);
  89. begin
  90.   inherited;
  91.   if AEvent=cteAfterDraw then DrawPageNum;
  92. end;
  93.  
  94. procedure TPageNumTool.DrawPageNum;
  95. var x    : Integer;
  96.     y    : Integer;
  97.     tmpX : Integer;
  98.     tmpY : Integer;
  99.     tmp  : String;
  100. begin
  101.   With ParentChart.Canvas do
  102.   begin
  103.     tmp:=SysUtils.Format( FFormat,
  104.             [TCustomChart(ParentChart).Page,TCustomChart(ParentChart).NumPages]);
  105.     AssignFont(Self.Shape.Font);
  106.  
  107.     if Shape.CustomPosition then
  108.     begin
  109.       x:=Shape.Left+4;
  110.       y:=Shape.Top+2;
  111.     end
  112.     else
  113.     begin
  114.       tmpX:=ParentChart.Width-TextWidth(tmp)-8;
  115.       tmpY:=ParentChart.Height-TextHeight(tmp)-8;
  116.       Case Position of
  117.         ppLeftTop     : begin x:=10; y:=10; end;
  118.         ppLeftBottom  : begin x:=10; y:=tmpY; end;
  119.         ppRightTop    : begin x:=tmpX; y:=10; end;
  120.       else
  121.         begin x:=tmpX; y:=tmpY; end;
  122.       end;
  123.     end;
  124.  
  125.     With Shape.ShapeBounds do
  126.     begin
  127.       Left:=x-4;
  128.       Right:=x+TextWidth(tmp)+2;
  129.       Top:=y-2;
  130.       Bottom:=y+TextHeight(tmp)+2;
  131.     end;
  132.     if Shape.Visible then Shape.Draw;
  133.     BackMode:=cbmTransparent;
  134.     TextOut(x,y, tmp);
  135.   end;
  136. end;
  137.  
  138. procedure TPageNumTool.SetFormat(const Value: String);
  139. begin
  140.   SetStringProperty(FFormat,Value);
  141. end;
  142.  
  143. procedure TPageNumTool.SetPosition(const Value: TPageNumPosition);
  144. begin
  145.   if FPosition<>Value then
  146.   begin
  147.     FPosition:=Value;
  148.     Repaint;
  149.   end;
  150. end;
  151.  
  152. class function TPageNumTool.Description: String;
  153. begin
  154.   result:='Page Number';
  155. end;
  156.  
  157. procedure TPageNumTool.SetParentChart(const Value: TCustomAxisPanel);
  158. begin
  159.   inherited;
  160.   Shape.ParentChart:=Value;
  161.   if Assigned(ParentChart) then Repaint;
  162. end;
  163.  
  164. procedure TPageNumTool.SetShape(const Value: TPageNumShape);
  165. begin
  166.   FShape.Assign(Value);
  167. end;
  168.  
  169. class function TPageNumTool.GetEditorClass: String;
  170. begin
  171.   result:='TPageNumToolEdit';
  172. end;
  173.  
  174. function TPageNumTool.IsFormatStored: Boolean;
  175. begin
  176.   result:=FFormat<>TeeMsg_PageOfPages;
  177. end;
  178.  
  179. initialization
  180.   RegisterTeeTools([TPageNumTool])
  181. finalization
  182.   UnRegisterTeeTools([TPageNumTool]);
  183. end.
  184.