⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teegallerypanel.pas

📁 TeeChart7Source 控件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{*********************************************}
{   TeeChart Gallery Panel                    }
{   Copyright (c) 1996-2004 by David Berneda  }
{*********************************************}
unit TeeGalleryPanel;
{$I TeeDefs.inc}

interface

Uses {$IFNDEF LINUX}
     Windows,
     Messages,
     {$ENDIF}
     {$IFDEF CLX}
     Qt, QControls, QExtCtrls, QForms, QGraphics,
     {$ELSE}
     Controls, ExtCtrls, Forms, Graphics,
     {$ENDIF}
     {$IFDEF D6}
     Types,
     {$ENDIF}
     {$IFDEF USETHEMES}
     Themes, UxTheme,
     {$ENDIF}
     Classes, Chart, TeeProcs, TeEngine;

Const TeeGalleryNumRows=3;
      TeeGalleryNumCols=4;
      TeeCursorDisabled=crNoDrop;

var   clTeeGallery:TColor=clWhite;
      TeeGalleryCheckMaximize:Boolean=True; { 5.02 }

type
  TGalleryChart=class {$IFDEF CLR}sealed{$ENDIF} (TCustomChart)
  private
    FSmooth         : Boolean;
    ICreatingBitmap : Boolean;

    Procedure AfterDraw(Sender:TObject);
    Function ArrowOrigin:TPoint;

    {$IFNDEF CLX}
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    {$ENDIF}

    procedure DrawSmoothChart;
    procedure DrawSubGalleryArrow;
    procedure SetSmooth(Value:Boolean);
  protected
    {$IFDEF CLX}
    procedure MouseEnter(AControl:TControl); override;
    procedure MouseLeave(AControl:TControl); override;
    {$ENDIF}
  public
    Constructor Create(AOwner:TComponent); override;

    Procedure CheckShowLabels;
    Procedure DrawFrame3D(Erase:Boolean);
    Procedure Focus(Is3D:Boolean);
    Procedure SetMargins;
    Procedure UnFocus(Is3D:Boolean);

    property Smooth:Boolean read FSmooth write SetSmooth default False;
  end;

  TChartList=class {$IFDEF CLR}sealed{$ENDIF} (TList)
  private
    Function GetChart(Index:Integer):TGalleryChart;
  public
    Procedure Clear; override;
    property Items[Index:Integer]:TGalleryChart read GetChart; default;
  end;

  TChartGalleryPanel=class(TCustomPanelNoCaption)
  private
    FColWidth        : Integer;
    FDisplaySub      : Boolean;
    FFocusRotation   : Boolean;
    FNumRows         : Integer;
    FNumCols         : Integer;
    FRowHeight       : Integer;
    FSmooth          : Boolean;
    FView3D          : Boolean;
    FOnChangeChart   : TNotifyEvent;
    FOnSelectedChart : TNotifyEvent;
    FOnSubSelected   : TNotifyEvent;

    tmpSub            : TForm;
    ISubGallery       : Boolean;
    ISelectedChart    : TGalleryChart;
    FOldSmooth        : Boolean;
    
    Procedure ChartEvent(Sender: TObject);
    procedure ChartKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    Procedure SetNumCols(Value:Integer);
    Procedure SetNumRows(Value:Integer);
    procedure SetSmooth(Value:Boolean);
    Procedure SetView3D(Value:Boolean);
    procedure ShowSubGallery;
    procedure SubKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure SubPaintBox(Sender:TObject);
    procedure SubPanelClick(Sender:TObject);
    procedure SubSelected(Sender: TObject);
    Function ValidSeries(Const ASeriesType:TTeeSeriesType; Const APage:String):Boolean;
    {$IFNDEF CLX}
    procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
    {$ENDIF}
  protected
  {$IFDEF CLR}
  public
  {$ENDIF}
    tmpG      : TChartGalleryPanel;
    tmpSeries : TChartSeries;
    tmpType   : TTeeSeriesType; { 5.01 }

  {$IFDEF CLR}
  protected
  {$ENDIF}
    Procedure CalcChartWidthHeight;
    procedure ChartOnDblClick(Sender: TObject);
    Function CreateSubChart(Const ATitle:String):TCustomAxisPanel;
    Procedure CreateSubGallery(AGallery:TChartGalleryPanel; AClass:TChartSeriesClass);
    Procedure GetChartXY(AChart:TGalleryChart; Var x,y:Integer);
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
    procedure Resize; override;
    Procedure ResizeChart(AChart:TGalleryChart; TopOffset:Integer=0);

  {$IFDEF CLR}
  public
  {$ENDIF}
    Procedure AddSubCharts(AGallery:TChartGalleryPanel);
    procedure FindSelectedChart;
    Procedure ShowSelectedChart;
  public
    Charts           : TChartList;
    CheckSeries      : Boolean;
    FunctionsVisible : Boolean;
    SelectedSeries   : TChartSeries;

    Constructor Create(AOwner:TComponent); override;
    Destructor Destroy; override;

    procedure SelectChart(Chart: TGalleryChart); virtual;
    Function CreateChart(Const AType:TTeeSeriesType):TCustomAxisPanel;
    Procedure CreateChartList(ASeriesList:Array of TChartSeriesClass);  // BCB does not allow "const"
    Procedure CreateGalleryPage(Const PageName:String);
    property ColWidth:Integer read FColWidth;

    class Function DefaultMode:Integer;  // 6.02
    class Function DefaultSmooth:Boolean;  // 6.02

    Function GetSeriesClass( Var tmpClass:TChartSeriesClass;
                             Var tmpFunctionClass:TTeeFunctionClass;
                             Var SubIndex:Integer):Boolean;
    Procedure ResizeCharts;

    class Procedure SaveMode(Value:Integer);  // 6.02
    class Procedure SaveSmooth(Value:Boolean);  // 6.02

    procedure UseTheme(Theme: TChartThemeClass); // 7.0

    property RowHeight:Integer read FRowHeight;
    property SelectedChart:TGalleryChart read ISelectedChart write SelectChart;
  published
    property DisplaySub:Boolean read FDisplaySub write FDisplaySub default True;
    property FocusRotation:Boolean read FFocusRotation write FFocusRotation default True;
    property NumRows:Integer read FNumRows write SetNumRows default TeeGalleryNumRows;
    property NumCols:Integer read FNumCols write SetNumCols default TeeGalleryNumCols;
    property Smooth:Boolean read FSmooth write SetSmooth default False;
    property View3D:Boolean read FView3D write SetView3D default True;

    { events }
    property OnSelectedChart:TNotifyEvent read FOnSelectedChart write FOnSelectedChart;
    property OnChangeChart:TNotifyEvent read FOnChangeChart write FOnChangeChart;
    property OnSubSelected:TNotifyEvent read FOnSubSelected write FOnSubSelected;

    { TPanel properties }
    property Align;
    property BevelInner;
    property BevelOuter;
    property BevelWidth;
    property BorderWidth;
    property BorderStyle;
    property Color;
    {$IFNDEF CLX}
    property DragCursor;
    {$ENDIF}
    property DragMode;
    property Enabled;
    property ParentColor;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property Anchors;
    {$IFNDEF CLX}
    property AutoSize;
    {$ENDIF}
    property Constraints;
    {$IFNDEF CLX}
    property DragKind;
    property Locked;
    {$ENDIF}

    { TPanel events }
    property OnClick;
    {$IFDEF D5}
    property OnContextPopup;
    {$ENDIF}
    property OnDblClick;
    {$IFNDEF CLX}
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnStartDrag;
    {$ENDIF}
    property OnEnter;
    property OnExit;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnConstrainedResize;
    {$IFNDEF CLX}
    property OnCanResize;
    property OnDockDrop;
    property OnDockOver;
    property OnEndDock;
    property OnStartDock;
    property OnUnDock;
    {$ENDIF}
  end;

implementation

Uses {$IFDEF CLR}
     Variants,
     {$ENDIF}
     Math, SysUtils,
     TeeConst, TeCanvas, TeePenDlg, Series;

Const clTeeSelected = clSilver; //$0080FFFF;   { <-- color use to select charts }

{ TChartList }
Procedure TChartList.Clear;
var t : Integer;
begin
  for t:=0 to Count-1 do Items[t].Free;
  inherited;
end;

Function TChartList.GetChart(Index:Integer):TGalleryChart;
begin
  result:=TGalleryChart(List{$IFNDEF CLR}^{$ENDIF}[Index]);
end;

{ TGalleryChart }
Constructor TGalleryChart.Create(AOwner:TComponent);
begin
  inherited;

  Legend.Hide;
  LeftAxis.Labels:=False;
  BottomAxis.Labels:=False;
  Title.Font.Color:=clNavy;

  Zoom.Animated:=True;

  With View3DOptions do
  begin
    Orthogonal:=False;
    Zoom       :=90;
    Perspective:=55;

    if TChartGalleryPanel(AOwner).FocusRotation then
    begin
      Rotation   :=335;
      Elevation  :=350;
    end;
  end;

  Chart3DPercent:=100;
  ClipPoints:=False;

  Frame.Hide;
  BevelWidth:=2;
  BevelOuter:=bvNone;

  With LeftWall do
  begin
    Color:=clWhite;
    Size:=4;
    Pen.Color:=clDkGray;
  end;

  With BottomWall do
  begin
    Color:=clWhite;
    Size:=4;
    Pen.Color:=clDkGray;
  end;

  OnAfterDraw:=AfterDraw;
end;

Procedure TGalleryChart.SetMargins;
Var tmp : Integer;
begin
  if View3D then tmp:=4 else tmp:=5;
  MarginTop    :=tmp;
  MarginBottom :=tmp;
  MarginLeft   :=tmp;
  MarginRight  :=tmp;
end;

Procedure TGalleryChart.DrawFrame3D(Erase:Boolean);
var R : TRect;
begin
  if Cursor<>TeeCursorDisabled then
  begin
    R:=ClientRect;
    if Erase then Frame3D(DelphiCanvas,R,Color,Color{clBtnFace,clBtnFace},1)
             else Frame3D(DelphiCanvas,R,clWhite,clDkGray,1);
  end;
end;

type TSeriesAccess=class(TChartSeries);

Procedure TGalleryChart.Focus(Is3D:Boolean);
begin
  With Gradient do
  begin
    Visible:=True;
    Direction:=gdFromTopLeft;
    StartColor:=clTeeSelected;
    EndColor:=clTeeGallery;
  end;

  if TChartGalleryPanel(Parent).FocusRotation then
  begin
    View3DOptions.Rotation:=345;
    if SeriesCount>0 then
       TSeriesAccess(Series[0]).GalleryChanged3D(Is3D);
  end;

  With Title.Font do
  begin
    Style:=[fsBold];
    Color:=clBlack;
    {$IFDEF CLX}
    Size:=GetDefaultFontSize+2;
    {$ELSE}
    Size:=9;
    {$ENDIF}
  end;
  BevelOuter:=bvRaised;

  if Showing then SetFocus;
end;

Procedure TGalleryChart.UnFocus(Is3D:Boolean);
begin
  if Gradient.Visible then
  begin
    Gradient.Visible:=False;
    BevelOuter:=bvNone;

    With Title.Font do
    begin
      Style:=[];
      Color:=clNavy;
      Size:=GetDefaultFontSize;
    end;

    if TChartGalleryPanel(Parent).FocusRotation then
    begin
      View3DOptions.Rotation:=335;
      if SeriesCount>0 then
         TSeriesAccess(Series[0]).GalleryChanged3D(Is3D);
    end;
  end;
end;

Procedure TGalleryChart.CheckShowLabels;

  Function IsMaximized:Boolean;
  var tmp : TCustomForm;
  {$IFNDEF CLX}
  var Placement : TWindowPlacement;
  {$ENDIF}
  begin
    tmp:=GetParentForm(Self);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -