home *** CD-ROM | disk | FTP | other *** search
- {**********************************************}
- { TDBChart for QuickReport }
- { Copyright (c) 1996-2000 by David Berneda }
- { All Rights Reserved }
- {**********************************************}
- {$I teedefs.inc}
- unit QrTee;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, TeeProcs, TeEngine, Chart, QuickRpt, TeCanvas,
- {$IFNDEF NOUSE_BDE}
- DBChart,
- {$ENDIF}
- StdCtrls, Menus, ExtCtrls;
-
- type
- TTeeQuickMethod=(qtmBitmap,qtmMetafile);
-
- TQRChart=class;
-
- TQRDBChart=class({$IFNDEF NOUSE_BDE}TCustomDBChart{$ELSE}TCustomChart{$ENDIF})
- protected
- public
- Constructor Create(AOwner : TComponent); override;
- Function GetRectangle:TRect; override;
- procedure Invalidate; override;
- procedure Paint; override;
- published
- {$IFNDEF NOUSE_BDE}
- { TCustomDBChart properties }
- property ShowGlassCursor;
- { TCustomDBChart events }
- property OnProcessRecord;
- {$ENDIF}
-
- { TCustomChart Properties }
- property BackImage;
- property BackImageInside;
- property BackImageMode;
- property BackWall;
- property BottomWall;
- property Foot;
- property Gradient;
- property LeftWall;
- property MarginBottom;
- property MarginLeft;
- property MarginRight;
- property MarginTop;
- property RightWall;
- property SubFoot;
- property SubTitle;
- property Title;
-
- { TCustomChart Events }
- property OnGetLegendPos;
- property OnGetLegendRect;
-
- { TCustomAxisPanel properties }
- property AxisBehind;
- property AxisVisible;
- property BottomAxis;
- property Chart3DPercent;
- property ClipPoints;
- property CustomAxes;
- property DepthAxis;
- property Frame;
- property LeftAxis;
- property Legend;
- property MaxPointsPerPage;
- property Page;
- property RightAxis;
- property ScaleLastPage;
- property SeriesList;
- property TopAxis;
- property View3D;
- property View3DOptions;
- property View3DWalls;
-
- { TCustomAxisPanel events }
- property OnAfterDraw;
- property OnBeforeDrawAxes;
- property OnBeforeDrawChart;
- property OnBeforeDrawSeries;
- property OnGetAxisLabel;
- property OnGetLegendText;
- property OnGetNextAxisLabel;
- property OnPageChange;
-
- { TPanel properties }
- property BevelInner;
- property BevelWidth;
- property BevelOuter default bvNone;
- property BorderWidth;
- property BorderStyle;
- property Color default clWhite;
- property ParentColor;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
-
- { TPanel events }
- property OnEnter;
- property OnExit;
- property OnResize;
- end;
-
- TPrintChartEvent = procedure( Sender: TQRChart;
- Var PaperRect,ChartRect:TRect ) of object;
-
- TQRChart = class(TQRPrintable)
- private
- { Private declarations }
- FOnPrint : TPrintChartEvent;
- FTeePrintMethod : TTeeQuickMethod;
-
- Function GetChart:TQRDBChart;
- Procedure SetPrintMethod(Value:TTeeQuickMethod);
- protected
- { Protected declarations }
- procedure ReadState(Reader: TReader); override;
- public
- { Public declarations }
- Constructor Create(AOwner : TComponent); override;
- procedure Print(OfsX, OfsY : integer); override;
- procedure Paint; override;
- published
- { Published declarations }
- property Chart : TQRDBChart read GetChart;
- property TeePrintMethod:TTeeQuickMethod read FTeePrintMethod
- write SetPrintMethod default qtmMetafile;
- { Published QR events }
- property OnPrint:TPrintChartEvent read FOnPrint write FOnPrint;
-
- end;
-
- implementation
-
- Uses {$IFNDEF D5}DsgnIntf,{$ENDIF} TeeConst;
-
- Const TeeMsg_DefaultQRChart='QRDBChart'; { <-- dont translate }
-
- { TQRDBChart }
- Constructor TQRDBChart.Create(AOwner : TComponent);
- begin
- inherited;
- Color:=clWhite;
- BevelOuter:=bvNone;
- BufferedDisplay:=False;
- SetBounds(-1,-1,1,1);
- Hide;
- end;
-
- Function TQRDBChart.GetRectangle:TRect;
- Var tmpZoomFactor : Double;
- begin
- if Assigned(Parent) then
- With TQRChart(Parent) do
- begin
- if Assigned(ParentReport) then tmpZoomFactor:=100.0/ParentReport.Zoom
- else tmpZoomFactor:=1;
- result:=Rect(0,0, Round(ClientWidth*tmpZoomFactor),
- Round(ClientHeight*tmpZoomFactor) );
- end;
- end;
-
- procedure TQRDBChart.Paint;
-
- Procedure DrawGraphic(AGraphic:TGraphic);
- begin
- With TQRChart(Parent) do Canvas.StretchDraw(GetClientRect,AGraphic);
- AGraphic.Free;
- end;
-
- begin
- if Assigned(Parent) then
- With TQRChart(Parent) do
- Case FTeePrintMethod of
- qtmMetafile: DrawGraphic(TeeCreateMetafile(True,GetRectangle));
- qtmBitmap: DrawGraphic(TeeCreateBitmap(clWhite,GetRectangle));
- end;
- end;
-
- procedure TQRDBChart.Invalidate;
- begin
- if Assigned(Parent) then Parent.Invalidate;
- end;
-
- { TQRChart }
- Constructor TQRChart.Create(AOwner : TComponent);
- begin
- inherited;
- FTeePrintMethod:=qtmMetafile;
- Width :=350;
- Height:=200;
- if (csDesigning in ComponentState) and
- (not (csLoading in Owner.ComponentState)) then
- With TQRDBChart.Create(AOwner) do
- begin
- Parent:=TWinControl(Self);
- Name:=TeeGetUniqueName(AOwner,TeeMsg_DefaultQRChart);
- With Title.Text do
- begin
- Clear;
- Add(Self.ClassName);
- end;
- end;
- end;
-
- procedure TQRChart.ReadState(Reader: TReader);
- Var tmpChart : TQRDBChart;
- begin
- tmpChart:=Chart;
- if Assigned(tmpChart) and
- (not (csLoading in tmpChart.ComponentState))
- and (not (csAncestor in tmpChart.ComponentState)) then
- tmpChart.Free;
- inherited;
- end;
-
- Procedure TQRChart.SetPrintMethod(Value:TTeeQuickMethod);
- begin
- if Value<>FTeePrintMethod then
- begin
- FTeePrintMethod:=Value;
- Repaint;
- end;
- end;
-
- procedure TQRChart.Print(OfsX, OfsY : Integer);
- Var QuickRect : TRect;
-
- Procedure PrintGraphic(AGraphic:TGraphic);
- begin
- QRPrinter.Canvas.StretchDraw(QuickRect,AGraphic);
- AGraphic.Free;
- end;
-
- Var tmpRect : TRect;
- tmpChart : TQRDBChart;
- begin
- tmpChart:=Chart;
- if Assigned(tmpChart) then
- begin
- {$IFNDEF NOUSE_BDE}
- tmpChart.RefreshData;
- {$ENDIF}
- With ParentReport.QRPrinter do
- begin
- QuickRect:=Rect( Xpos(OfsX+Size.Left),
- Ypos(OfsY+Size.Top),
- Xpos(OfsX+Size.Left+Size.Width),
- Ypos(OfsY+Size.Top+Size.Height));
-
- tmpRect:=tmpChart.GetRectangle;
- if Assigned(FOnPrint) then FOnPrint(Self,QuickRect,tmpRect);
- Case FTeePrintMethod of
- qtmMetafile: PrintGraphic(tmpChart.TeeCreateMetafile(True,tmpRect));
- qtmBitmap: PrintGraphic(tmpChart.TeeCreateBitmap(clWhite,tmpRect));
- end;
- end;
- end;
- inherited;
- end;
-
- procedure TQRChart.Paint;
- begin
- if Assigned(Chart) then Chart.Paint;
- inherited;
- end;
-
- Function TQRChart.GetChart:TQRDBChart;
- begin
- if ControlCount>0 then result:=TQRDBChart(Controls[0])
- else result:=nil;
- end;
-
- initialization
- RegisterClass(TQRDBChart);
- end.
-