cxchartvieweditor.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 725 行 · 第 1/2 页

PAS
725
字号
{********************************************************************}
{                                                                    }
{       Developer Express Visual Component Library                   }
{       ExpressQuantumGrid                                           }
{                                                                    }
{       Copyright (c) 1998-2008 Developer Express Inc.               }
{       ALL RIGHTS RESERVED                                          }
{                                                                    }
{   The entire contents of this file is protected by U.S. and        }
{   International Copyright Laws. Unauthorized reproduction,         }
{   reverse-engineering, and distribution of all or any portion of   }
{   the code contained in this file is strictly prohibited and may   }
{   result in severe civil and criminal penalties and will be        }
{   prosecuted to the maximum extent possible under the law.         }
{                                                                    }
{   RESTRICTIONS                                                     }
{                                                                    }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES            }
{   (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE     }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS    }
{   LICENSED TO DISTRIBUTE THE EXPRESSQUANTUMGRID AND ALL            }
{   ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{                                                                    }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED       }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE         }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE        }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT   }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                       }
{                                                                    }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON        }
{   ADDITIONAL RESTRICTIONS.                                         }
{                                                                    }
{********************************************************************}

unit cxChartViewEditor;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, cxViewEditor, cxGridCustomView, cxGridChartView, ComCtrls, StdCtrls,
  Menus, cxControls, cxPC, cxLookAndFeelPainters, cxButtons;

type
  TcxGridChartItemKind = (ciSeries, ciDataGroup);
  TcxGridChartItemListBoxParams = array[TcxGridChartItemKind] of Integer;

  TcxChartViewEditor = class(TcxViewEditor)
    pmItems: TPopupMenu;
    miItemAdd: TMenuItem;
    miItemDelete: TMenuItem;
    N2: TMenuItem;
    miItemMoveUp: TMenuItem;
    miItemMoveDown: TMenuItem;
    N1: TMenuItem;
    miItemSelectAll: TMenuItem;
    pmItemsAdd: TPopupMenu;
    tcMain: TcxTabControl;
    Panel1: TPanel;
    lbItems: TListBox;
    Panel2: TPanel;
    btnItemAdd: TcxButton;
    btnItemDelete: TcxButton;
    btnItemMoveUp: TcxButton;
    btnItemMoveDown: TcxButton;
    btnItemSelectAll: TcxButton;
    Panel9: TPanel;
    procedure tcMainChanging(Sender: TObject; var AllowChange: Boolean);
    procedure tcMainChange(Sender: TObject);
    procedure lbItemsClick(Sender: TObject);
    procedure btnItemAddClick(Sender: TObject);
    procedure btnItemAddExClick(Sender: TObject);
    procedure miItemAddExClick(Sender: TObject);
    procedure btnItemDeleteClick(Sender: TObject);
    procedure btnItemMoveUpClick(Sender: TObject);
    procedure btnItemMoveDownClick(Sender: TObject);
    procedure btnItemSelectAllClick(Sender: TObject);
    procedure lbItemsStartDrag(Sender: TObject; var DragObject: TDragObject);
    procedure lbItemsDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure lbItemsDragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure lbItemsEndDrag(Sender, Target: TObject; X, Y: Integer);
    procedure lbItemsDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure FormCreate(Sender: TObject);
  private
    FItemPrevDragIndex: Integer;
    FListBoxItemIndex: TcxGridChartItemListBoxParams;
    FListBoxTopIndex: TcxGridChartItemListBoxParams;
    function GetItemClassValue: TcxGridChartItemClass;
    function GetView: TcxGridChartView;
    procedure ReindexItemsProc(AList: TList; ANewIndex: Integer);
  protected
    IsActiveTabChanging: Boolean;

    procedure Loaded; override;

    function GetItem(Index: Integer): TcxGridChartItem; virtual;
    function GetItemClass(AItemKind: TcxGridChartItemKind): TcxGridChartItemClass; virtual;
    function GetItemCount: Integer; virtual;
    function GetItemKind: TcxGridChartItemKind; virtual;
    function GetItemName: string; virtual;
    procedure SetItemKind(Value: TcxGridChartItemKind); virtual;

    function AddItem: TcxGridChartItem;
    procedure UpdateActiveTab; virtual;
    procedure UpdateButtons; virtual;
    procedure UpdateEditor; override;
    procedure UpdateSelection; override;
    procedure UpdateItemList; virtual;

    procedure RestoreListBoxParams;
    procedure SaveListBoxParams;

    property ItemClass: TcxGridChartItemClass read GetItemClassValue;
    property ItemCount: Integer read GetItemCount;
    property ItemKind: TcxGridChartItemKind read GetItemKind write SetItemKind;
    property ItemName: string read GetItemName;
    property Items[Index: Integer]: TcxGridChartItem read GetItem;
  public
    class function GetViewByObject(APersistent: TPersistent): TcxCustomGridView; override;
    property View: TcxGridChartView read GetView;
  end;

  TcxGridChartViewStorage = class(TcxCustomGridViewStorage)
  private
    function GetDiagramArea: TcxGridChartAreaDiagram;
    function GetDiagramBar: TcxGridChartBarDiagram;
    function GetDiagramColumn: TcxGridChartColumnDiagram;
    function GetDiagramLine: TcxGridChartLineDiagram;
    function GetDiagramPie: TcxGridChartPieDiagram;
    function GetLegend: TcxGridChartLegend;
    function GetOptionsBehavior: TcxGridChartOptionsBehavior;
    function GetOptionsCustomize: TcxGridChartOptionsCustomize;
    function GetOptionsView: TcxGridChartOptionsView;
    function GetTitle: TcxGridChartTitle;
    function GetToolBox: TcxGridChartToolBox;
    function GetView: TcxGridChartView;
  protected
    property View: TcxGridChartView read GetView;
  public
    class function GetViewClass: TcxCustomGridViewClass; override;
  published
    property DiagramArea: TcxGridChartAreaDiagram read GetDiagramArea;
    property DiagramBar: TcxGridChartBarDiagram read GetDiagramBar;
    property DiagramColumn: TcxGridChartColumnDiagram read GetDiagramColumn;
    property DiagramLine: TcxGridChartLineDiagram read GetDiagramLine;
    property DiagramPie: TcxGridChartPieDiagram read GetDiagramPie;
    property Legend: TcxGridChartLegend read GetLegend;
    property OptionsBehavior: TcxGridChartOptionsBehavior read GetOptionsBehavior;
    property OptionsCustomize: TcxGridChartOptionsCustomize read GetOptionsCustomize;
    property OptionsView: TcxGridChartOptionsView read GetOptionsView;
    property Title: TcxGridChartTitle read GetTitle;
    property ToolBox: TcxGridChartToolBox read GetToolBox;
  end;

  TcxGridChartViewMenuProvider = class(TcxCustomGridViewMenuProvider)
  private
    function GetGridView: TcxGridChartView;
  protected
    procedure ActivateDiagram(Sender: TcxGridViewMenuItem);
    procedure CreateDataGroup(Sender: TcxGridViewMenuItem);
    procedure CreateSeries(Sender: TcxGridViewMenuItem);
    procedure InitLayoutItems; override;
    procedure InitStructureItems; override;
  public
    property GridView: TcxGridChartView read GetGridView;
  end;

implementation

{$R *.dfm}

uses
  Math, cxClasses, cxCustomData, cxDesignWindows;

const
  AddButtonCaption = '&Add';
  AddExButtonCaption = '&Add...';

function GetChartItemName(AItemKind: TcxGridChartItemKind): string;
begin
  case AItemKind of
    ciSeries:
      Result := 'Series';
    ciDataGroup:
      Result := 'DataGroup';
  else
    Result := '';
  end;
end;

function CreateChartItem(AView: TcxGridChartView; AItemKind: TcxGridChartItemKind): TcxGridChartItem;
begin
  AView.BeginUpdate;
  try
    case AItemKind of
      ciSeries:
        Result := AView.CreateSeries;
      ciDataGroup:
        Result := AView.CreateDataGroup;
    else
      Result := nil;
    end;
    Result.Name := GetViewItemUniqueName(AView, Result, GetChartItemName(AItemKind));
  finally
    AView.EndUpdate;
  end;
end;

{ TcxChartViewEditor }

function TcxChartViewEditor.GetItemClassValue: TcxGridChartItemClass;
begin
  Result := GetItemClass(ItemKind);
end;

function TcxChartViewEditor.GetView: TcxGridChartView;
begin
  Result := TcxGridChartView(inherited View);
end;

procedure TcxChartViewEditor.ReindexItemsProc(AList: TList; ANewIndex: Integer);
var
  I: Integer;
begin
  if AList.Count = 0 then Exit;
  for I := AList.Count - 1 downto 0 do
  begin
    if TcxGridChartItem(AList[I]).Index < ANewIndex then
      Dec(ANewIndex);
    TcxGridChartItem(AList[I]).Index := ANewIndex;
  end;
  UpdateDesigner;
end;

procedure TcxChartViewEditor.Loaded;
begin
  inherited;
  tcMain.TabIndex := 0;  // because it is deleted from DFM by SetupBuilder
end;

function TcxChartViewEditor.GetItem(Index: Integer): TcxGridChartItem;
begin
  case ItemKind of
    ciSeries:
      Result := View.Series[Index];
    ciDataGroup:
      Result := View.DataGroups[Index];
  else
    Result := nil;
  end;
end;

function TcxChartViewEditor.GetItemClass(AItemKind: TcxGridChartItemKind): TcxGridChartItemClass;
begin
  case AItemKind of
    ciSeries:
      Result := View.GetSeriesClass;
    ciDataGroup:
      Result := View.GetDataGroupClass;
  else
    Result := nil;
  end;
end;

function TcxChartViewEditor.GetItemCount: Integer;
begin
  case ItemKind of
    ciSeries:
      Result := View.SeriesCount;
    ciDataGroup:
      Result := View.DataGroupCount;
  else
    Result := 0;
  end;
end;

function TcxChartViewEditor.GetItemKind: TcxGridChartItemKind;
begin
  Result := TcxGridChartItemKind(tcMain.TabIndex);
end;

function TcxChartViewEditor.GetItemName: string;
begin
  Result := GetChartItemName(ItemKind);
end;

procedure TcxChartViewEditor.SetItemKind(Value: TcxGridChartItemKind);
begin
  if IsActiveTabChanging then Exit;
  if ItemKind <> Value then
  begin
    SaveListBoxParams;
    tcMain.TabIndex := Ord(Value);
    tcMainChange(nil);
  end;
end;

function TcxChartViewEditor.AddItem: TcxGridChartItem;
begin
  Result := CreateChartItem(View, ItemKind);
  SelectComponent(Result);
  UpdateDesigner;
end;

procedure TcxChartViewEditor.UpdateActiveTab;
var
  AIsItemFoundInSelection: Boolean;
  AItemKind, ASelectedItemKind: TcxGridChartItemKind;
  AList: TList;
  I: Integer;
  AObject: TObject;
begin
  AIsItemFoundInSelection := False;
  ASelectedItemKind := Low(ASelectedItemKind);
  AList := TList.Create;
  try
    GetSelectionList(AList);
    for I := 0 to AList.Count - 1 do
    begin
      AObject := TObject(AList[I]);
      if (AObject is TcxGridChartItem) and (TcxGridChartItem(AObject).GridView = View) then
        for AItemKind := Low(AItemKind) to High(AItemKind) do
          if AObject.ClassType = GetItemClass(AItemKind) then
            if AIsItemFoundInSelection and (ASelectedItemKind <> AItemKind) then
              Exit
            else
            begin
              AIsItemFoundInSelection := True;
              ASelectedItemKind := AItemKind;
              Break;
            end;
    end;
  finally
    AList.Free;
  end;
  if AIsItemFoundInSelection then
    ItemKind := ASelectedItemKind;
end;

procedure TcxChartViewEditor.UpdateButtons;
begin
  btnItemAdd.Enabled := CanAddComponent;
  btnItemDelete.Enabled := CanDeleteComponent(nil) and (lbItems.SelCount > 0);
  btnItemMoveUp.Enabled := lbItems.SelCount > 0;
  btnItemMoveDown.Enabled := lbItems.SelCount > 0;
  btnItemSelectAll.Enabled := lbItems.SelCount < lbItems.Items.Count;

  miItemAdd.Enabled := btnItemAdd.Enabled;
  miItemDelete.Enabled := btnItemDelete.Enabled;
  miItemMoveUp.Enabled := btnItemMoveUp.Enabled;
  miItemMoveDown.Enabled := btnItemMoveDown.Enabled;
  miItemSelectAll.Enabled := btnItemSelectAll.Enabled;

  if Supports(DataController, IcxGridChartViewItemsProvider) then
  begin
    btnItemAdd.Caption := AddExButtonCaption;
    btnItemAdd.OnClick := btnItemAddExClick;
  end
  else
  begin
    btnItemAdd.Caption := AddButtonCaption;

⌨️ 快捷键说明

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