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

  1. {**********************************************}
  2. {   TeeChart Gallery Dialog                    }
  3. {   Copyright (c) 1996-98 by David Berneda     }
  4. {**********************************************}
  5. {$I teedefs.inc}
  6. unit TeeGally;
  7.  
  8. interface
  9.  
  10. uses
  11.   WinProcs,WinTypes, Messages, SysUtils, Classes, Graphics,
  12.   Controls, Forms, Dialogs, ExtCtrls, StdCtrls, TeEngine, Chart, TeeFunci
  13.   {$IFDEF D1}
  14.   ,Tabs
  15.   {$ELSE}
  16.   ,ComCtrls
  17.   {$ENDIF}
  18.   ;
  19.  
  20. Const clTeeGallery1=clRed;
  21.       clTeeGallery2=clBlue;
  22.  
  23. type
  24.   {$IFDEF D1}
  25.   TeeTabControlClass=TTabSet;
  26.   {$ELSE}
  27.   TeeTabControlClass=TTabControl;
  28.   {$ENDIF}
  29.  
  30.   TTeeTabControl=class( TeeTabControlClass )
  31.   public
  32.     Procedure AlignTab;
  33.     Procedure SetTabEvent(Value:TNotifyEvent);
  34.   end;
  35.  
  36.   TTeeGalleryPanel=class(TPanel)
  37.   private
  38.     FView3D:Boolean;
  39.     FOnSelectedChart,
  40.     FOnChangeChart:TNotifyEvent;
  41.     Procedure CheckShowLabels(AChart:TCustomChart);
  42.     Function GetChart(Index:Longint):TCustomChart;
  43.     Procedure SetView3D(Value:Boolean);
  44.     Procedure SetMargins(AChart:TCustomChart);
  45.   protected
  46.     procedure Resize; override;
  47.   public
  48.     SelectedChart  : TCustomChart;
  49.     SelectedSeries : TChartSeries;
  50.     RowHeight      : Longint;
  51.     ColWidth       : Longint;
  52.     NumRows        : Longint;
  53.     NumCols        : Longint;
  54.     ChartList      : TList;
  55.     CheckSeries    : Boolean;
  56.     Constructor Create(AOwner:TComponent); override;
  57.     Destructor Destroy; override;
  58.     Procedure ResizeCharts;
  59.     Procedure CalcChartWidthHeight;
  60.     Procedure SetRowCols(ARows,ACols:Longint);
  61.     Procedure ResizeChart(AChart:TCustomChart);
  62.     Procedure GetChartXY(AChart:TCustomChart; Var x,y:Longint);
  63.     Procedure RemoveCharts;
  64.     Procedure CreateChart(Const tmpType:TTeeSeriesType; Index:Longint);
  65.     procedure ChartOnClick(Sender: TObject);
  66.     procedure ChartOnDblClick(Sender: TObject);
  67.     Procedure ShowSelectedChart;
  68.     procedure FindSelectedChart;
  69.     property View3D:Boolean read FView3D write SetView3D;
  70.     Procedure ProcessKeyDown(Sender:TObject; Var Key:Word; Shift:TShiftState);
  71.     Procedure CreateChartList(Const ASeriesList:Array of TChartSeriesClass);
  72.     property Chart[Index:Longint]:TCustomChart read GetChart;
  73.   published
  74.     property OnSelectedChart:TNotifyEvent read FOnSelectedChart write FOnSelectedChart;
  75.     property OnChangeChart:TNotifyEvent read FOnChangeChart write FOnChangeChart;
  76.   end;
  77.  
  78.   TTeeGallery = class(TForm)
  79.     P1: TPanel;
  80.     BOk: TButton;
  81.     BCancel: TButton;
  82.     CB3D: TCheckBox;
  83.     procedure CB3DClick(Sender: TObject);
  84.     procedure FormShow(Sender: TObject);
  85.     procedure FormResize(Sender: TObject);
  86.     procedure FormCreate(Sender: TObject);
  87.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  88.       Shift: TShiftState);
  89.   private
  90.     { Private declarations }
  91.     TabControl:TTeeTabControl;
  92.   public
  93.     { Public declarations }
  94.     GalleryPanel:TTeeGalleryPanel;
  95.     CreatingForm,
  96.     FunctionsVisible:Boolean;
  97.     OnChangeChart:TNotifyEvent;
  98.     Procedure CreateGallery(APage:Integer);
  99.     Procedure HideButtons;
  100.     Procedure HideFunctions;
  101.     Function CalcNumSeriesPage(Const APage:String):Longint;
  102.     procedure TabControl1Change(Sender: TObject);
  103.     procedure GalleryPanelOnSelected(Sender: TObject);
  104.     Function ValidSeries(Const ASeriesType:TTeeSeriesType; Const APage:String):Boolean;
  105.     Procedure CreateGalleryList(Const ASeriesList:Array of TChartSeriesClass);
  106.   end;
  107.  
  108. { Shows the gallery and asks the user a Series type.
  109.   If user double clicks a chart or presses Ok, a new Series
  110.   is created and returned. The new Series is owned by AOwner
  111.   parameter (usually the Form).
  112. }
  113. Function CreateNewSeriesGallery( AOwner:TComponent;
  114.                                  OldSeries:TChartSeries;
  115.                                  tmpChart:TCustomChart;
  116.                                  AllowSameType,
  117.                                  ShowFunctions:Boolean ):TChartSeries;
  118.  
  119. { Shows the gallery and asks the user a Series type. Then
  120.   changes tmpSeries to the new type. }
  121. procedure ChangeSeriesTypeGallery(AOwner:TComponent; Var tmpSeries:TChartSeries);
  122.  
  123. { Shows the Gallery Dialog and lets the user choose a Series type.
  124.   Returns True if user pressed OK.
  125.   The "tmpClass" parameter returns the choosen type.
  126. }
  127. Function GetChartGalleryClass( AOwner:TComponent;
  128.                                OldSeries:TChartSeries;
  129.                                ShowFunctions:Boolean;
  130.                                Var tmpClass:TChartSeriesClass;
  131.                                Var Show3D:Boolean;
  132.                                Var tmpFunctionClass:TTeeFunctionClass
  133.                               ):Boolean;
  134.  
  135. { Returns the name of a Series in it┤s "gallery" style:
  136.    TLineSeries returns "Line"
  137.    TPieSeries returns "Pie"
  138.    etc.
  139. }
  140. Function GetGallerySeriesName(ASeries:TChartSeries):String;
  141.  
  142. { Shows the gallery and asks the user a Series type. Then
  143.   changes all Series in AChart to the new type. }
  144. procedure ChangeAllSeriesGallery( AOwner:TComponent; AChart:TCustomChart );
  145.  
  146. implementation
  147.  
  148. {$R *.DFM}
  149.  
  150. Uses TeeProcs, TeeConst, Series, TeCanvas;
  151.  
  152. Const clTeeSelected=$0080FFFF;   { <-- color use to select charts }
  153.       TeeDefault_GalleryCols=4;
  154.  
  155. Function FindSeriesClassType(ASeriesClass:TChartSeriesClass; Var AType:TTeeSeriesType):Boolean;
  156. var t:Integer;
  157. begin
  158.   result:=False;
  159.   With TeeSeriesTypes do
  160.   for t:=0 to Count-1 do
  161.   begin
  162.     AType:=SeriesType[t];
  163.     if (AType.SeriesClass=ASeriesClass) and (AType.FunctionClass=nil) then
  164.     begin
  165.       result:=True;
  166.       Exit;
  167.     end;
  168.   end;
  169. end;
  170.  
  171. { TeeGalleryPanel }
  172. Constructor TTeeGalleryPanel.Create(AOwner:TComponent);
  173. begin
  174.   inherited Create(AOwner);
  175.   SelectedChart:=nil;
  176.   SelectedSeries:=nil;
  177.   OnSelectedChart:=nil;
  178.   OnChangeChart:=nil;
  179.   NumCols:=0;
  180.   NumRows:=0;
  181.   ChartList:=TList.Create;
  182.   SetRowCols(3,4);
  183. end;
  184.  
  185. Destructor TTeeGalleryPanel.Destroy;
  186. begin
  187.   RemoveCharts;
  188.   ChartList.Free;
  189.   inherited Destroy;
  190. end;
  191.  
  192. Procedure TTeeGalleryPanel.SetRowCols(ARows,ACols:Longint);
  193. begin
  194.   NumRows:=ARows;
  195.   NumCols:=ACols;
  196.   CalcChartWidthHeight;
  197. end;
  198.  
  199. Procedure TTeeGalleryPanel.GetChartXY(AChart:TCustomChart; Var x,y:Longint);
  200. begin
  201.   y:=AChart.Tag div NumCols;
  202.   x:=AChart.Tag mod NumCols;
  203. end;
  204.  
  205. Procedure TTeeGalleryPanel.RemoveCharts;
  206. var t   : Integer;
  207.     tmp : TCustomChart;
  208. begin
  209.   for t:=0 to ChartList.Count-1 do
  210.   begin
  211.     tmp:=Chart[t];
  212.     tmp.Free;
  213.   end;
  214.   ChartList.Clear;
  215. end;
  216.  
  217. procedure TTeeGalleryPanel.ChartOnDblClick(Sender: TObject);
  218. begin
  219.   SelectedChart:=TCustomChart(Sender);
  220.   if Assigned(FOnSelectedChart) then OnSelectedChart(Self);
  221. end;
  222.  
  223. Procedure TTeeGalleryPanel.CalcChartWidthHeight;
  224. var tmp:Integer;
  225. begin
  226.   if (NumRows>0) and (NumCols>0) then
  227.   begin
  228.     tmp:=BevelWidth+BorderWidth;
  229.     RowHeight:=(Height-tmp) div NumRows;
  230.     ColWidth:=(Width-tmp) div NumCols;
  231.   end;
  232. end;
  233.  
  234. Function GetDefaultGalleryFontSize:Integer;
  235. begin
  236.   result:=StrToInt(TeeMsg_DefaultGalleryFontSize);
  237.   {$IFDEF D3}
  238.   CheckJapaneseFontSize(result);
  239.   {$ENDIF}
  240. end;
  241.  
  242. Procedure TTeeGalleryPanel.CheckShowLabels(AChart:TCustomChart);
  243. var Placement: TWindowPlacement;
  244. begin
  245.   With AChart do
  246.   if AxisVisible then
  247.   begin
  248.     Placement.length := SizeOf(TWindowPlacement);
  249.     GetWindowPlacement((Self.Owner as TForm).Handle, @Placement);
  250.     LeftAxis.Labels:=Placement.showCmd=SW_SHOWMAXIMIZED;
  251.     BottomAxis.Labels:=Placement.showCmd=SW_SHOWMAXIMIZED;
  252. {      View3DOptions.ZoomText:=False; }
  253.   end;
  254. end;
  255.  
  256. Procedure TTeeGalleryPanel.CreateChart(Const tmpType:TTeeSeriesType; Index:Longint);
  257. Var AChart   : TCustomChart;
  258.     tmpClass : TChartSeriesClass;
  259.  
  260.   Procedure CreateSeries;
  261.   Var tmp:Longint;
  262.   begin
  263.     for tmp:=1 to MaxLong(1,tmpType.NumGallerySeries) do
  264.     With CreateNewSeries(Self,AChart,tmpClass,tmpType.FunctionClass) do
  265.     begin
  266.       case tmp of
  267.         1: SeriesColor:=clTeeGallery1;
  268.         2: SeriesColor:=clTeeGallery2;
  269.       end;
  270.     end;
  271.   end;
  272.  
  273. var t : Longint;
  274.     DisabledSeries:Boolean;
  275. begin
  276.   tmpClass:=tmpType.SeriesClass;
  277.   if not Assigned(tmpClass) then tmpClass:=TLineSeries;
  278.   AChart:=TCustomChart.Create(Self);
  279.   ChartList.Add(AChart);
  280.   With AChart do
  281.   begin
  282.     Tag:=Index;
  283.     Name:=TeeMsg_GalleryChartName+IntToStr(Tag);
  284.     ResizeChart(AChart);
  285.     Parent:=Self;
  286.     Legend.Visible:=False;
  287.  
  288.     LeftAxis.Labels:=False;
  289.     BottomAxis.Labels:=False;
  290.  
  291.     Title.Text.Add(tmpType.Description);
  292.     Title.Font.Size:=GetDefaultGalleryFontSize;
  293.     Title.Font.Color:=clNavy;
  294.     AnimatedZoom:=True;
  295.     With View3DOptions do
  296.     begin
  297.       Orthogonal:=False;
  298.       Zoom       :=70;
  299.       Perspective:=60;
  300.       Rotation   :=335;
  301.       Elevation  :=345;
  302.     end;
  303.     Chart3DPercent:=100;
  304.     ClipPoints:=False;
  305.  
  306.     Frame.Visible:=False;
  307.     BevelWidth:=2;
  308.     BevelOuter:=bvNone;
  309.     LeftWall.Size:=4;
  310.     BottomWall.Size:=4;
  311.     LeftWall.Color:=clWhite;
  312.     BottomWall.Color:=clWhite;
  313.     CreateSeries;
  314.     DisabledSeries:=CheckSeries and
  315.                     Assigned(SelectedSeries) and
  316.                     ( not Series[0].IsValidSourceOf(SelectedSeries) );
  317.     if DisabledSeries then
  318.     begin
  319.       Cursor:=crNoDrop;
  320.       OriginalCursor:=Cursor;
  321.       OnClick:=nil;
  322.       OnDblClick:=nil;
  323.       Title.Font.Color:=clGray;
  324.       LeftWall.Pen.Color:=clGray;
  325.       BottomWall.Pen.Color:=clGray;
  326.       LeftAxis.Axis.Width:=1;
  327.       LeftAxis.Axis.Color:=clWhite;
  328.       BottomAxis.Axis.Width:=1;
  329.       BottomAxis.Axis.Color:=clWhite;
  330.     end
  331.     else
  332.     begin
  333.       Cursor:=crTeeHand;
  334.       OriginalCursor:=Cursor;
  335.       OnClick:=ChartOnClick;
  336.       OnDblClick:=ChartOnDblClick;
  337.       OnEnter:=ChartOnClick;
  338.     end;
  339.     Series[0].GalleryChanged3D(Self.FView3D);
  340.     for t:=0 to SeriesCount-1 do
  341.         Series[t].PrepareForGallery(not DisabledSeries);
  342.     SetMargins(AChart);
  343.     CheckShowLabels(AChart);
  344.   end;
  345. end;
  346.  
  347. Function TTeeGalleryPanel.GetChart(Index:Longint):TCustomChart;
  348. begin
  349.   result:=TCustomChart(ChartList[Index]);
  350. end;
  351.  
  352. Procedure TTeeGalleryPanel.ProcessKeyDown(Sender:TObject; Var Key:Word; Shift:TShiftState);
  353.  
  354.     Function FindChartXY(x,y:Longint):TCustomChart;
  355.     var tmpX : Longint;
  356.         tmpY : Longint;
  357.         t    : Longint;
  358.     begin
  359.       for t:=0 to ChartList.Count-1 do
  360.       begin
  361.         result:=Chart[t];
  362.         GetChartXY(result,tmpX,tmpY);
  363.         if (x=tmpx) and (y=tmpy) then exit;
  364.       end;
  365.       result:=nil;
  366.     end;
  367.  
  368. var x,y : Longint;
  369.     tmp : TCustomChart;
  370. begin
  371.   GetChartXY(SelectedChart,x,y);
  372.   Case Key of
  373.     VK_LEFT:   if x>0 then Dec(x);
  374.     VK_RIGHT:  if x<NumCols then Inc(x);
  375.     VK_UP:     if y>0 then Dec(y);
  376.     VK_DOWN:   if y<NumRows then Inc(y);
  377.     VK_RETURN: ChartOnDblClick(SelectedChart);
  378.   end;
  379.   tmp:=FindChartXY(x,y);
  380.   if Assigned(tmp) and (tmp.Cursor=crTeeHand) then ChartOnClick(tmp);
  381. end;
  382.  
  383. Procedure TTeeGalleryPanel.ResizeChart(AChart:TCustomChart);
  384. var tmp       : Longint;
  385.     tmpCol    : Longint;
  386.     tmpRow    : Longint;
  387.     tmpLeft   : Longint;
  388.     tmpTop    : Longint;
  389.     tmpWidth  : Longint;
  390.     tmpHeight : Longint;
  391. begin
  392.   if (NumCols>0) and (NumRows>0) then
  393.   begin
  394.     GetChartXY(AChart,tmpCol,tmpRow);
  395.     tmp:=BevelWidth+BorderWidth;
  396.     tmpLeft:=tmp+(tmpCol*ColWidth);
  397.     tmpTop:=tmp+(tmpRow*RowHeight);
  398.     tmpWidth:=ColWidth;
  399.     tmpHeight:=RowHeight;
  400.     if tmpLeft+tmpWidth>(Width-tmp) then tmpWidth:=(Width-tmp)-tmpLeft;
  401.     if tmpTop+RowHeight>(Height-tmp) then tmpHeight:=(Height-tmp)-tmpTop;
  402.     AChart.SetBounds( tmpLeft,tmpTop,tmpWidth,tmpHeight );
  403.     CheckShowLabels(AChart);
  404.   end;
  405. end;
  406.  
  407. Procedure TTeeGalleryPanel.ShowSelectedChart;
  408. begin
  409.   if not Assigned(SelectedChart) then
  410.   if ChartList.Count>0 then SelectedChart:=Chart[0];
  411.   if Assigned(SelectedChart) then
  412.   With SelectedChart do
  413.   begin
  414. {    Color:=clTeeSelected; }
  415.     With Gradient do
  416.     begin
  417.       Visible:=True;
  418.       Direction:=gdFromTopLeft;
  419.       StartColor:=clTeeSelected;
  420.       EndColor:=clWhite;
  421.     end;
  422.     View3DOptions.Rotation:=345;
  423.     if SeriesCount>0 then Series[0].GalleryChanged3D(Self.FView3D);
  424.     With Title.Font do
  425.     begin
  426.       Style:=[fsBold];
  427.       Color:=clBlack;
  428.       Size:=10;
  429.     end;
  430.     BevelOuter:=bvRaised;
  431.     SetFocus;
  432.     if Assigned(FOnChangeChart) then OnChangeChart(Self);
  433.   end;
  434. end;
  435.  
  436. procedure TTeeGalleryPanel.FindSelectedChart;
  437. var t:Longint;
  438. begin
  439.   SelectedChart:=nil;
  440.   if Assigned(SelectedSeries) then
  441.   begin
  442.     for t:=0 to ChartList.Count-1 do
  443.     With Chart[t][0] do
  444.     if (ClassType=SelectedSeries.ClassType) and (FunctionType=nil) then
  445.     begin
  446.       SelectedChart:=Chart[t];
  447.       break;
  448.     end;
  449.   end;
  450.   ShowSelectedChart;
  451. end;
  452.  
  453. procedure TTeeGalleryPanel.ChartOnClick(Sender: TObject);
  454. var t:Longint;
  455. begin
  456.   SelectedChart:=TCustomChart(Sender);
  457.   ShowSelectedChart;
  458.   for t:=0 to ChartList.Count-1 do
  459.   if ChartList[t]<>Sender then
  460.   with Chart[t] do
  461.   if Gradient.Visible  then
  462.   begin
  463. {    Color:=clBtnFace; }
  464.     Gradient.Visible:=False;
  465.     BevelOuter:=bvNone;
  466.     With Title.Font do
  467.     begin
  468.       Style:=[];
  469.       Color:=clNavy;
  470.       Size:=GetDefaultGalleryFontSize;
  471.     end;
  472.     View3DOptions.Rotation:=335;
  473.     if SeriesCount>0 then
  474.        Series[0].GalleryChanged3D(Self.FView3D);
  475.   end;
  476. end;
  477.  
  478. procedure TTeeGalleryPanel.SetView3D(Value:Boolean);
  479. var t:Integer;
  480. begin
  481.   if Value<>FView3D then
  482.   begin
  483.     FView3D:=Value;
  484.     for t:=0 to ChartList.Count-1 do
  485.     begin
  486.       Chart[t].Series[0].GalleryChanged3D(FView3D);
  487.       SetMargins(Chart[t]);
  488.     end;
  489.   end;
  490. end;
  491.  
  492. Procedure TTeeGalleryPanel.SetMargins(AChart:TCustomChart);
  493. Var tmp:Integer;
  494. begin
  495.   With AChart do
  496.   begin
  497.     if View3D then tmp:=2 else tmp:=6;
  498.     MarginTop    :=tmp;
  499.     MarginBottom :=tmp;
  500.     MarginLeft   :=tmp;
  501.     MarginRight  :=tmp;
  502.   end;
  503. end;
  504.  
  505. Procedure TTeeGalleryPanel.CreateChartList(Const ASeriesList:Array of TChartSeriesClass);
  506. var t     : Integer;
  507.     AType : TTeeSeriesType;
  508. begin
  509.   RemoveCharts;
  510.   for t:=Low(ASeriesList) to High(ASeriesList) do
  511.       if FindSeriesClassType(ASeriesList[t],AType) then CreateChart(AType,t);
  512. end;
  513.  
  514. Procedure TTeeGalleryPanel.ResizeCharts;
  515. var t : Integer;
  516. begin
  517.   CalcChartWidthHeight;
  518.   for t:=0 to ChartList.Count-1 do ResizeChart(Chart[t]);
  519. end;
  520.  
  521. procedure TTeeGalleryPanel.Resize;
  522. begin
  523.   inherited Resize;
  524.   ResizeCharts;
  525. end;
  526.  
  527. { TeeTabControl  }
  528. Procedure TTeeTabControl.AlignTab;
  529. begin
  530.   {$IFDEF D1}
  531.   Align:=alBottom;
  532.   {$ELSE}
  533.   Align:=alClient;
  534.   {$ENDIF}
  535. end;
  536.  
  537. Procedure TTeeTabControl.SetTabEvent(Value:TNotifyEvent);
  538. begin
  539.   {$IFDEF D1}
  540.   OnClick:=Value;
  541.   {$ELSE}
  542.   OnChange:=Value;
  543.   {$ENDIF}
  544. end;
  545.  
  546. { TeeGallery }
  547. Procedure TTeeGallery.HideFunctions;
  548. begin
  549.   TabControl.Tabs.Delete(1);
  550.   FunctionsVisible:=False;
  551. end;
  552.  
  553. Procedure TTeeGallery.HideButtons;
  554. begin
  555.   P1.Visible:=False;
  556. end;
  557.  
  558. Function TTeeGallery.ValidSeries(Const ASeriesType:TTeeSeriesType; Const APage:String):Boolean;
  559. begin
  560.   result:= (ASeriesType.GalleryPage=APage) and
  561.            (FunctionsVisible or (ASeriesType.FunctionClass=nil));
  562. end;
  563.  
  564. Function TTeeGallery.CalcNumSeriesPage(Const APage:String):Longint;
  565. var t:Longint;
  566. begin
  567.   result:=0;
  568.   With TeeSeriesTypes do
  569.   for t:=0 to Count-1 do if ValidSeries(SeriesType[t],APage) then Inc(result);
  570. end;
  571.  
  572. Procedure TTeeGallery.CreateGallery(APage:Integer);
  573. Var tmp    : TTeeSeriesType;
  574.     tmpSt  : String;
  575.     t      : Longint;
  576.     tmpRow : Longint;
  577.     tmpNum : Longint;
  578. begin
  579.   With GalleryPanel do
  580.   begin
  581.     RemoveCharts;
  582.     tmpSt:=TabControl.Tabs[APage];
  583.     { Adjust gallery grid Rows and Columns }
  584.     SetRowCols(3,4);
  585.     tmpNum:=CalcNumSeriesPage(tmpSt);
  586.     if (tmpNum>0) then
  587.       if (NumRows*NumCols) < tmpNum then
  588.       begin
  589.         tmpRow:=tmpNum div 4;
  590.         if tmpRow>0 then
  591.         begin
  592.           if (tmpRow*4) <> tmpNum then Inc(tmpRow);
  593.           SetRowCols(tmpRow,4);
  594.         end;
  595.       end;
  596.  
  597.     View3D:=CB3D.Checked;
  598.     CheckSeries:=not FunctionsVisible;
  599.     With TeeSeriesTypes do
  600.     for t:=0 to Count -1 do
  601.     begin
  602.       tmp:=SeriesType[t];
  603.       if ValidSeries(tmp,tmpSt) then CreateChart(tmp,ChartList.Count);
  604.     end;
  605.   end;
  606. end;
  607.  
  608. procedure TTeeGallery.GalleryPanelOnSelected(Sender: TObject);
  609. begin
  610.   ModalResult:=mrOk;
  611. end;
  612.  
  613. procedure TTeeGallery.CB3DClick(Sender: TObject);
  614. begin
  615.   GalleryPanel.View3D:=CB3D.Checked;
  616. end;
  617.  
  618. procedure TTeeGallery.FormShow(Sender: TObject);
  619. var t : Integer;
  620. begin
  621.   if GalleryPanel.ChartList.Count=0 then
  622.   begin
  623.     With TabControl do
  624.     With TeeSeriesTypes do
  625.     for t:=0 to Count-1 do
  626.     With SeriesType[t] do
  627.       if NumGallerySeries>0 then
  628.          if Tabs.IndexOf(GalleryPage)=-1 then
  629.             if (FunctionsVisible or (FunctionClass=nil)) then
  630.                Tabs.Add(GalleryPage);
  631.     CreateGallery(0);
  632.   end;
  633.   GalleryPanel.FindSelectedChart;
  634. end;
  635.  
  636. procedure TTeeGallery.FormResize(Sender: TObject);
  637. begin
  638.   if Assigned(GalleryPanel) then GalleryPanel.ResizeCharts;
  639. end;
  640.  
  641. procedure TTeeGallery.FormCreate(Sender: TObject);
  642. begin
  643.   CreatingForm:=True;
  644.   TeeEraseBack:=False;
  645.   FunctionsVisible:=True;
  646. {  Width :=389{432};
  647. {  Height:=344{356};
  648.   TabControl:=TTeeTabControl.Create(Self);
  649.   With TabControl do
  650.   begin
  651.     Parent:=Self;
  652.     AlignTab;
  653.     Tabs.Add(TeeMsg_GalleryStandard);
  654.     Tabs.Add(TeeMsg_GalleryFunctions);
  655.     SetTabEvent(TabControl1Change);
  656.     TabIndex:=0;
  657.   end;
  658.   GalleryPanel:=TTeeGalleryPanel.Create(Self);
  659.   With GalleryPanel do
  660.   begin
  661.    {$IFDEF D1}
  662.     Parent:=Self;
  663.    {$ELSE}
  664.     Parent:=TabControl;
  665.    {$ENDIF}
  666.     Align:=alClient;
  667.     BevelOuter:=bvNone;
  668.     OnSelectedChart:=GalleryPanelOnSelected;
  669.   end;
  670.   CreatingForm:=False;
  671. end;
  672.  
  673. procedure TTeeGallery.TabControl1Change(Sender: TObject);
  674. begin
  675.   if not CreatingForm then
  676.   begin
  677.     CreateGallery(TabControl.TabIndex);
  678.     GalleryPanel.FindSelectedChart;
  679.   end;
  680. end;
  681.  
  682. procedure TTeeGallery.FormKeyDown(Sender: TObject; var Key: Word;
  683.   Shift: TShiftState);
  684. begin
  685.   GalleryPanel.ProcessKeyDown(Sender,Key,Shift);
  686. end;
  687.  
  688. Procedure TTeeGallery.CreateGalleryList(Const ASeriesList:Array of TChartSeriesClass);
  689. begin
  690.   With GalleryPanel do
  691.   begin
  692.     RemoveCharts;
  693.     View3D:=CB3D.Checked;
  694.     CheckSeries:=not FunctionsVisible;
  695.     CreateChartList(ASeriesList);
  696.   end;
  697. end;
  698.  
  699. { Helper functions }
  700. Function GetGallerySeriesName(ASeries:TChartSeries):String;
  701. var AType:TTeeSeriesType;
  702. begin
  703.   if FindSeriesClassType(TChartSeriesClass(ASeries.ClassType),AType) then
  704.      result:=AType.Description
  705.   else
  706.      result:=ASeries.ClassName;
  707. end;
  708.  
  709. Function GetChartGalleryClass( AOwner:TComponent;
  710.                                OldSeries:TChartSeries;
  711.                                ShowFunctions:Boolean;
  712.                                Var tmpClass:TChartSeriesClass;
  713.                                Var Show3D:Boolean;
  714.                                Var tmpFunctionClass:TTeeFunctionClass
  715.                               ):Boolean;
  716. var tmpSeries  : TChartSeries;
  717.     tmpGallery : TTeeGallery;
  718. begin
  719.   result:=False;
  720.   tmpGallery:=TTeeGallery.Create(nil);
  721.   With tmpGallery do
  722.   try
  723.     CB3D.Checked:=Show3D;
  724.     GalleryPanel.SelectedSeries:=OldSeries;
  725.     if not ShowFunctions then HideFunctions;
  726.     if ShowModal=mrOk then
  727.     begin
  728.       if Assigned(GalleryPanel.SelectedChart) then
  729.       begin
  730.         tmpSeries:=GalleryPanel.SelectedChart[0];
  731.         tmpClass:=TChartSeriesClass(tmpSeries.ClassType);
  732.         if tmpSeries.FunctionType<>nil then
  733.            tmpFunctionClass:=TTeeFunctionClass(tmpSeries.FunctionType.ClassType)
  734.         else
  735.            tmpFunctionClass:=nil;
  736.         Show3D:=GalleryPanel.SelectedChart.View3D;
  737.         result:=True;
  738.       end;
  739.     end;
  740.   finally
  741.     tmpGallery.Free;
  742.   end;
  743. end;
  744.  
  745. Function CreateNewSeriesGallery( AOwner:TComponent;
  746.                                  OldSeries:TChartSeries;
  747.                                  tmpChart:TCustomChart;
  748.                                  AllowSameType,
  749.                                  ShowFunctions:Boolean ):TChartSeries;
  750. var Show3D   : Boolean;
  751.     tmpClass : TChartSeriesClass;
  752.     tmpFunctionClass:TTeeFunctionClass;
  753. begin
  754.   result:=nil;
  755.   Show3D:=tmpChart.View3D;
  756.   if GetChartGalleryClass(AOwner,OldSeries,AllowSameType,tmpClass,Show3D,tmpFunctionClass) then
  757.   begin
  758.     tmpChart.View3D:=Show3D;
  759.     if (not Assigned(OldSeries)) or
  760.        (AllowSameType or (tmpClass<>OldSeries.ClassType)) then
  761.          result:=CreateNewSeries(AOwner,tmpChart,tmpClass,tmpFunctionClass);
  762.   end;
  763. end;
  764.  
  765. procedure ChangeSeriesTypeGallery(AOwner:TComponent; Var tmpSeries:TChartSeries);
  766. var NewSeries:TChartSeries;
  767. begin
  768.   NewSeries:=CreateNewSeriesGallery(AOwner,tmpSeries,TCustomChart(tmpSeries.ParentChart),False,False);
  769.   if Assigned(NewSeries) then
  770.   begin
  771.     AssignSeries(tmpSeries,NewSeries);
  772.     tmpSeries:=NewSeries;
  773.   end;
  774. end;
  775.  
  776. procedure ChangeAllSeriesGallery( AOwner:TComponent; AChart:TCustomChart );
  777. var NewSeries : TChartSeries;
  778.     tmpSeries : TChartSeries;
  779. begin
  780.   if AChart.SeriesCount>0 then
  781.   begin
  782.     tmpSeries:=AChart[0];
  783.     NewSeries:=CreateNewSeriesGallery(AOwner,tmpSeries,AChart,False,False);
  784.     if Assigned(NewSeries) then
  785.     begin
  786.       AssignSeries(tmpSeries,NewSeries);
  787.       ChangeAllSeriesType(AChart,TChartSeriesClass(NewSeries.ClassType));
  788.     end;
  789.   end;
  790. end;
  791.  
  792. end.
  793.