home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / TeeChartPro / TeeChart5Delphi5Eval.exe / %MAINDIR% / Delphi5 / QuickReport / QrTee.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-10  |  7.1 KB  |  283 lines

  1. {**********************************************}
  2. {  TDBChart for QuickReport                    }
  3. {  Copyright (c) 1996-2000 by David Berneda    }
  4. {  All Rights Reserved                         }
  5. {**********************************************}
  6. {$I teedefs.inc}
  7. unit QrTee;
  8.  
  9. interface
  10.  
  11. uses
  12.   Windows, Messages, SysUtils, Classes, Graphics, Controls,
  13.   Forms, Dialogs, TeeProcs, TeEngine, Chart, QuickRpt, TeCanvas,
  14.   {$IFNDEF NOUSE_BDE}
  15.   DBChart,
  16.   {$ENDIF}
  17.   StdCtrls, Menus, ExtCtrls;
  18.  
  19. type
  20.   TTeeQuickMethod=(qtmBitmap,qtmMetafile);
  21.  
  22.   TQRChart=class;
  23.  
  24.   TQRDBChart=class({$IFNDEF NOUSE_BDE}TCustomDBChart{$ELSE}TCustomChart{$ENDIF})
  25.   protected
  26.   public
  27.     Constructor Create(AOwner : TComponent); override;
  28.     Function GetRectangle:TRect; override;
  29.     procedure Invalidate; override;
  30.     procedure Paint; override;
  31.   published
  32.     {$IFNDEF NOUSE_BDE}
  33.     { TCustomDBChart properties }
  34.     property ShowGlassCursor;
  35.     { TCustomDBChart events }
  36.     property OnProcessRecord;
  37.     {$ENDIF}
  38.  
  39.     { TCustomChart Properties }
  40.     property BackImage;
  41.     property BackImageInside;
  42.     property BackImageMode;
  43.     property BackWall;
  44.     property BottomWall;
  45.     property Foot;
  46.     property Gradient;
  47.     property LeftWall;
  48.     property MarginBottom;
  49.     property MarginLeft;
  50.     property MarginRight;
  51.     property MarginTop;
  52.     property RightWall;
  53.     property SubFoot;
  54.     property SubTitle;
  55.     property Title;
  56.  
  57.     { TCustomChart Events }
  58.     property OnGetLegendPos;
  59.     property OnGetLegendRect;
  60.  
  61.     { TCustomAxisPanel properties }
  62.     property AxisBehind;
  63.     property AxisVisible;
  64.     property BottomAxis;
  65.     property Chart3DPercent;
  66.     property ClipPoints;
  67.     property CustomAxes;
  68.     property DepthAxis;
  69.     property Frame;
  70.     property LeftAxis;
  71.     property Legend;
  72.     property MaxPointsPerPage;
  73.     property Page;
  74.     property RightAxis;
  75.     property ScaleLastPage;
  76.     property SeriesList;
  77.     property TopAxis;
  78.     property View3D;
  79.     property View3DOptions;
  80.     property View3DWalls;
  81.  
  82.     { TCustomAxisPanel events }
  83.     property OnAfterDraw;
  84.     property OnBeforeDrawAxes;
  85.     property OnBeforeDrawChart;
  86.     property OnBeforeDrawSeries;
  87.     property OnGetAxisLabel;
  88.     property OnGetLegendText;
  89.     property OnGetNextAxisLabel;
  90.     property OnPageChange;
  91.  
  92.     { TPanel properties }
  93.     property BevelInner;
  94.     property BevelWidth;
  95.     property BevelOuter default bvNone;
  96.     property BorderWidth;
  97.     property BorderStyle;
  98.     property Color default clWhite;
  99.     property ParentColor;
  100.     property ParentShowHint;
  101.     property PopupMenu;
  102.     property ShowHint;
  103.  
  104.     { TPanel events }
  105.     property OnEnter;
  106.     property OnExit;
  107.     property OnResize;
  108.   end;
  109.  
  110.   TPrintChartEvent = procedure( Sender: TQRChart;
  111.                 Var PaperRect,ChartRect:TRect ) of object;
  112.  
  113.   TQRChart = class(TQRPrintable)
  114.   private
  115.     { Private declarations }
  116.     FOnPrint        : TPrintChartEvent;
  117.     FTeePrintMethod : TTeeQuickMethod;
  118.  
  119.     Function GetChart:TQRDBChart;
  120.     Procedure SetPrintMethod(Value:TTeeQuickMethod);
  121.   protected
  122.     { Protected declarations }
  123.     procedure ReadState(Reader: TReader); override;
  124.   public
  125.     { Public declarations }
  126.     Constructor Create(AOwner : TComponent); override;
  127.     procedure Print(OfsX, OfsY : integer); override;
  128.     procedure Paint; override;
  129.   published
  130.     { Published declarations }
  131.     property Chart : TQRDBChart read GetChart;
  132.     property TeePrintMethod:TTeeQuickMethod read FTeePrintMethod
  133.                                             write SetPrintMethod default qtmMetafile;
  134.     { Published QR events }
  135.     property OnPrint:TPrintChartEvent read FOnPrint write FOnPrint;
  136.  
  137.   end;
  138.  
  139. implementation
  140.  
  141. Uses {$IFNDEF D5}DsgnIntf,{$ENDIF} TeeConst;
  142.  
  143. Const TeeMsg_DefaultQRChart='QRDBChart'; { <-- dont translate }
  144.  
  145. { TQRDBChart }
  146. Constructor TQRDBChart.Create(AOwner : TComponent);
  147. begin
  148.   inherited;
  149.   Color:=clWhite;
  150.   BevelOuter:=bvNone;
  151.   BufferedDisplay:=False;
  152.   SetBounds(-1,-1,1,1);
  153.   Hide;
  154. end;
  155.  
  156. Function TQRDBChart.GetRectangle:TRect;
  157. Var tmpZoomFactor : Double;
  158. begin
  159.   if Assigned(Parent) then
  160.   With TQRChart(Parent) do
  161.   begin
  162.     if Assigned(ParentReport) then tmpZoomFactor:=100.0/ParentReport.Zoom
  163.                               else tmpZoomFactor:=1;
  164.     result:=Rect(0,0, Round(ClientWidth*tmpZoomFactor),
  165.                       Round(ClientHeight*tmpZoomFactor) );
  166.   end;
  167. end;
  168.  
  169. procedure TQRDBChart.Paint;
  170.  
  171.   Procedure DrawGraphic(AGraphic:TGraphic);
  172.   begin
  173.     With TQRChart(Parent) do Canvas.StretchDraw(GetClientRect,AGraphic);
  174.     AGraphic.Free;
  175.   end;
  176.  
  177. begin
  178.   if Assigned(Parent) then
  179.   With TQRChart(Parent) do
  180.   Case FTeePrintMethod of
  181.   qtmMetafile: DrawGraphic(TeeCreateMetafile(True,GetRectangle));
  182.     qtmBitmap: DrawGraphic(TeeCreateBitmap(clWhite,GetRectangle));
  183.   end;
  184. end;
  185.  
  186. procedure TQRDBChart.Invalidate;
  187. begin
  188.   if Assigned(Parent) then Parent.Invalidate;
  189. end;
  190.  
  191. { TQRChart }
  192. Constructor TQRChart.Create(AOwner : TComponent);
  193. begin
  194.   inherited;
  195.   FTeePrintMethod:=qtmMetafile;
  196.   Width :=350;
  197.   Height:=200;
  198.   if (csDesigning in ComponentState) and
  199.      (not (csLoading in Owner.ComponentState)) then
  200.   With TQRDBChart.Create(AOwner) do
  201.   begin
  202.     Parent:=TWinControl(Self);
  203.     Name:=TeeGetUniqueName(AOwner,TeeMsg_DefaultQRChart);
  204.     With Title.Text do
  205.     begin
  206.       Clear;
  207.       Add(Self.ClassName);
  208.     end;
  209.   end;
  210. end;
  211.  
  212. procedure TQRChart.ReadState(Reader: TReader);
  213. Var tmpChart : TQRDBChart;
  214. begin
  215.   tmpChart:=Chart;
  216.   if Assigned(tmpChart) and
  217.      (not (csLoading in tmpChart.ComponentState))
  218.      and (not (csAncestor in tmpChart.ComponentState)) then
  219.           tmpChart.Free;
  220.   inherited;
  221. end;
  222.  
  223. Procedure TQRChart.SetPrintMethod(Value:TTeeQuickMethod);
  224. begin
  225.   if Value<>FTeePrintMethod then
  226.   begin
  227.     FTeePrintMethod:=Value;
  228.     Repaint;
  229.   end;
  230. end;
  231.  
  232. procedure TQRChart.Print(OfsX, OfsY : Integer);
  233. Var QuickRect : TRect;
  234.  
  235.   Procedure PrintGraphic(AGraphic:TGraphic);
  236.   begin
  237.     QRPrinter.Canvas.StretchDraw(QuickRect,AGraphic);
  238.     AGraphic.Free;
  239.   end;
  240.  
  241. Var tmpRect  : TRect;
  242.     tmpChart : TQRDBChart;
  243. begin
  244.   tmpChart:=Chart;
  245.   if Assigned(tmpChart) then
  246.   begin
  247.     {$IFNDEF NOUSE_BDE}
  248.     tmpChart.RefreshData;
  249.     {$ENDIF}
  250.     With ParentReport.QRPrinter do
  251.     begin
  252.       QuickRect:=Rect( Xpos(OfsX+Size.Left),
  253.                        Ypos(OfsY+Size.Top),
  254.                        Xpos(OfsX+Size.Left+Size.Width),
  255.                        Ypos(OfsY+Size.Top+Size.Height));
  256.  
  257.       tmpRect:=tmpChart.GetRectangle;
  258.       if Assigned(FOnPrint) then FOnPrint(Self,QuickRect,tmpRect);
  259.       Case FTeePrintMethod of
  260.       qtmMetafile: PrintGraphic(tmpChart.TeeCreateMetafile(True,tmpRect));
  261.         qtmBitmap: PrintGraphic(tmpChart.TeeCreateBitmap(clWhite,tmpRect));
  262.       end;
  263.     end;
  264.   end;
  265.   inherited;
  266. end;
  267.  
  268. procedure TQRChart.Paint;
  269. begin
  270.   if Assigned(Chart) then Chart.Paint;
  271.   inherited;
  272. end;
  273.  
  274. Function TQRChart.GetChart:TQRDBChart;
  275. begin
  276.   if ControlCount>0 then result:=TQRDBChart(Controls[0])
  277.                     else result:=nil;
  278. end;
  279.  
  280. initialization
  281.   RegisterClass(TQRDBChart);
  282. end.
  283.