home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / TEEEDIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  7.1 KB  |  232 lines

  1. {*****************************************}
  2. {   TeeChart-Pro 4.0                      }
  3. {   Copyright (c) 1995-98 David Berneda   }
  4. {     TChartEditor                        }
  5. {     TChartPreviewer                     }
  6. {*****************************************}
  7. {$I teedefs.inc}
  8. unit TeeEdit;
  9.  
  10. interface
  11.  
  12. uses
  13.   WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  14.   Dialogs, Chart,
  15.   {$IFDEF D1}
  16.   IEdit16
  17.   {$ELSE}
  18.   IEditCha
  19.   {$ENDIF}
  20.   ;
  21.  
  22. type
  23.   TCustomChartEditor=class(TComponent)
  24.   private
  25.     { Private declarations }
  26.     FChart   : TCustomChart;
  27.     FTitle   : String;
  28.     FOnClose : TNotifyEvent;
  29.     FOnShow  : TNotifyEvent;
  30.     procedure SetChart(const Value: TCustomChart);
  31.   protected
  32.     { Protected declarations }
  33.     procedure Notification( AComponent: TComponent;
  34.                             Operation: TOperation); override;
  35.   public
  36.     { Public declarations }
  37.     Procedure Execute; virtual; abstract;
  38.     property Title:String read FTitle write FTitle;
  39.   published
  40.     { Published declarations }
  41.     property Chart:TCustomChart read FChart write SetChart;
  42.     property OnClose: TNotifyEvent read FOnClose write FOnClose;
  43.     property OnShow: TNotifyEvent read FOnShow write FOnShow;
  44.   end;
  45.  
  46.   TChartEditor = class(TCustomChartEditor)
  47.   private
  48.     { Private declarations }
  49.     FAutoRepaint : Boolean;
  50.     FDefaultTab  : TChartEditorTab;
  51.     FHideTabs    : TChartEditorHiddenTabs;
  52.     FOptions     : TChartEditorOptions;
  53.   public
  54.     { Public declarations }
  55.     Constructor Create(AOwner:TComponent); override;
  56.     Procedure Execute; override;
  57.   published
  58.     { Published declarations }
  59.     property AutoRepaint:Boolean read FAutoRepaint write FAutoRepaint default True;
  60.     property DefaultTab:TChartEditorTab read FDefaultTab write FDefaultTab default cetMain;
  61.     property HideTabs:TChartEditorHiddenTabs read FHideTabs write FHideTabs;
  62.     property Options:TChartEditorOptions read FOptions write FOptions
  63.                                          default eoAll;
  64.     property Title;
  65.   end;
  66.  
  67.   TChartPreviewOption=( cpoChangePrinter,
  68.                         cpoSetupPrinter,
  69.                         cpoResizeChart,
  70.                         cpoMoveChart,
  71.                         cpoChangeDetail,
  72.                         cpoChangePaperOrientation,
  73.                         cpoChangeMargins,
  74.                         cpoProportional,
  75.                         cpoDragChart,
  76.                         cpoPrintPanel,
  77.                         cpoAsBitmap );
  78.  
  79.   TChartPreviewOptions=set of TChartPreviewOption;
  80.  
  81. Const DefaultChartPreviewOptions=[ cpoChangePrinter,
  82.                                    cpoSetupPrinter,
  83.                                    cpoResizeChart,
  84.                                    cpoMoveChart,
  85.                                    cpoChangeDetail,
  86.                                    cpoChangePaperOrientation,
  87.                                    cpoChangeMargins,
  88.                                    cpoProportional ];
  89.  
  90.  
  91. type
  92.   TChartPreviewer = class(TCustomChartEditor)
  93.   private
  94.     FOptions    : TChartPreviewOptions;
  95.     FPaperColor : TColor;
  96.     FWindowState: TWindowState;
  97.     { Private declarations }
  98.   protected
  99.     { Protected declarations }
  100.   public
  101.     { Public declarations }
  102.     Constructor Create(AOwner:TComponent); override;
  103.     Procedure Execute; override;
  104.   published
  105.     { Published declarations }
  106.     property Options:TChartPreviewOptions read FOptions write FOptions
  107.              default DefaultChartPreviewOptions;
  108.     property PaperColor:TColor read FPaperColor write FPaperColor default clWhite;
  109.     property Title;
  110.     property WindowState:TWindowState read FWindowState write FWindowState default wsNormal;
  111.   end;
  112.  
  113. implementation
  114.  
  115. Uses TeeProCo,TeeProcs,EditChar,TeePrevi;
  116.  
  117. procedure TCustomChartEditor.Notification(AComponent: TComponent;
  118.   Operation: TOperation);
  119. begin
  120.   inherited Notification(AComponent, Operation);
  121.   if Operation=opRemove then
  122.      if Assigned(FChart) and (AComponent=FChart) then
  123.         FChart:=nil;
  124. end;
  125.  
  126. procedure TCustomChartEditor.SetChart(const Value: TCustomChart);
  127. begin
  128.   FChart := Value;
  129.   {$IFNDEF D1}
  130.   if Assigned(FChart) then FChart.FreeNotification(Self);
  131.   {$ENDIF}
  132. end;
  133.  
  134. { TChartEditor }
  135. Constructor TChartEditor.Create(AOwner:TComponent);
  136. begin
  137.   inherited Create(AOwner);
  138.   FOptions:=eoAll;
  139.   FDefaultTab:=cetMain;
  140.   FAutoRepaint:=True;
  141. end;
  142.  
  143. procedure TChartEditor.Execute;
  144. Var TheForm : TChartEditForm;
  145.     OldAuto : Boolean;
  146. begin
  147.   if Assigned(FChart) then
  148.   begin
  149.     TheForm:=TChartEditForm.Create(nil);
  150.     With TheForm do
  151.     try
  152.       Caption:=Self.FTitle;
  153.       TheChart:=FChart;
  154.       EditorOptions:=FOptions;
  155.       {$IFDEF TEEHELPEDITOR}
  156.       CheckHelpFile;
  157.       {$ENDIF}
  158.       TheActivePageIndex:=Ord(FDefaultTab);
  159.       TheHiddenTabs:=FHideTabs;
  160.       if Assigned(Self.FOnShow) then Self.FOnShow(TheForm);
  161.       OldAuto:=True; 
  162.       if not Self.FAutoRepaint then
  163.       begin
  164.         OldAuto:=FChart.AutoRepaint;
  165.         FChart.AutoRepaint:=False;
  166.       end;
  167.       ShowModal;
  168.       if not Self.FAutoRepaint then
  169.       begin
  170.         FChart.AutoRepaint:=OldAuto;
  171.         FChart.Repaint;
  172.       end;
  173.     finally
  174.       if Assigned(Self.FOnClose) then Self.FOnClose(TheForm);
  175.       Free;
  176.     end;
  177.     FChart.CancelMouse:=True;
  178.   end;
  179. end;
  180.  
  181. { TChartPreviewer }
  182. Constructor TChartPreviewer.Create(AOwner:TComponent);
  183. begin
  184.   inherited Create(AOwner);
  185.   FOptions:=DefaultChartPreviewOptions;
  186.   FPaperColor:=clWhite;
  187.   FWindowState:=wsNormal;
  188. end;
  189.  
  190. procedure TChartPreviewer.Execute;
  191. var OldPrintTeePanel:Boolean;
  192.     TheForm:TChartPreview;
  193. begin
  194.   if Assigned(FChart) then
  195.   begin
  196.     TheForm:=TChartPreview.Create(nil);
  197.     with TheForm do
  198.     try
  199.       if Self.FTitle<>'' then Caption:=Self.FTitle;
  200.       PreviewPage.Image:=Self.FChart;
  201.       WindowState:=Self.FWindowState;
  202.       if not (cpoChangePrinter in Self.FOptions) then Printers.Enabled:=False;
  203.       if not (cpoSetupPrinter in Self.FOptions) then BSetupPrinter.Enabled:=False;
  204.       PreviewPage.AllowResize:=(cpoResizeChart in Self.FOptions);
  205.       PreviewPage.AllowMove:=(cpoMoveChart in Self.FOptions);
  206.       if not (cpoChangeDetail in Self.FOptions) then ChangeDetailGroup.Enabled:=False;
  207.       if not (cpoChangePaperOrientation in Self.FOptions) then Orientation.Enabled:=False;
  208.       if not (cpoChangeMargins in Self.FOptions) then
  209.       begin
  210.         GBMargins.Enabled:=False;
  211.         BReset.Enabled:=False;
  212.       end;
  213.       PreviewPage.Image.PrintProportional:=(cpoProportional in Self.FOptions);
  214.       PreviewPage.PaperColor:=Self.FPaperColor;
  215.       PreviewPage.DragImage:=(cpoDragChart in Self.FOptions);
  216.       OldPrintTeePanel:=PrintTeePanel;
  217.       PrintTeePanel:=(cpoPrintPanel in Self.FOptions);
  218.       PreviewPage.AsBitmap:=(cpoAsBitmap in Self.FOptions);
  219.       if Assigned(Self.FOnShow) then Self.FOnShow(TheForm);
  220.       ShowModal;
  221.       PrintTeePanel:=OldPrintTeePanel;
  222.     finally
  223.       if Assigned(Self.FOnClose) then Self.FOnClose(TheForm);
  224.       Free;
  225.       Self.FChart.Repaint;
  226.     end;
  227.     Self.FChart.CancelMouse:=True;
  228.   end;
  229. end;
  230.  
  231. end.
  232.