cxgrid.pas

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

PAS
2,183
字号
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure LookAndFeelChanged(Sender: TcxLookAndFeel; AChangedValues: TcxLookAndFeelValues); override;
    procedure Paint; override;
    procedure ReadState(Reader: TReader); override;
    procedure SetChildOrder(Child: TComponent; Order: Integer); override;
    procedure SetName(const NewName: TComponentName); override;
    procedure WndProc(var Message: TMessage); override;

    procedure DoEndDrag(Target: TObject; X, Y: Integer); override;
    procedure DoStartDrag(var DragObject: TDragObject); override;
    procedure DragOver(Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); override;

    procedure CreateHandlers; virtual;
    procedure DestroyHandlers; virtual;

    procedure DoActiveTabChanged(ALevel: TcxGridLevel); virtual;
    procedure DoChange(AGridChange: TcxCustomGridChange);
    procedure DoLayoutChanged(AGridView: TcxCustomGridView); virtual;
    procedure DoProcessChangesStack;
    procedure DoUpdate(AChanges: TList);
    procedure FocusedViewChanged(APrevFocusedView, AFocusedView: TcxCustomGridView); virtual;
    function GetControllerClass: TcxGridControllerClass; virtual;
    function GetDefaultViewClass: TcxCustomGridViewClass; virtual;
    function GetLevelsClass: TcxGridLevelClass; virtual;
    function GetLevelTabsClass: TcxGridLevelTabsClass; virtual;
    function GetPainterClass: TcxGridPainterClass; virtual;
    function GetViewInfoClass: TcxGridViewInfoClass; virtual;
    procedure LevelChanged(ALevel: TcxGridLevel; AChangeKind: TcxGridLevelChangeKind);
    procedure RefreshNavigators;
    procedure StructureNavigatorChanged;
    function UpdateOnRootViewDataChange: Boolean; virtual;
    procedure ViewChanged(AView: TcxCustomGridView; AChangeKind: TcxGridViewChangeNotificationKind);

    procedure UpdateFocusing(AChildFocused: Boolean);
    property LastFocused: Boolean read FLastFocused;

    property FocusedViewNavigator: IcxNavigator read GetFocusedViewNavigator;
    property IsPopupControl: Boolean read FIsPopupControl write FIsPopupControl;
    property NavigatorNotifier: TcxNavigatorControlNotifier read FNavigatorNotifier;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Invalidate(AHardUpdate: Boolean = False); reintroduce;
    procedure RemoveFocus(AGoForward: Boolean);

    procedure BeginUpdate;
    procedure CancelUpdate;
    procedure Changed(AGridChange: TcxCustomGridChange);
    procedure CheckFocusedView;
    procedure EndUpdate;
    procedure LayoutChanged; virtual;
    procedure SizeChanged; virtual;
    property UpdateLocked: Boolean read GetUpdateLocked;

    function CreateView(AViewClass: TcxCustomGridViewClass): TcxCustomGridView;
    function ViewExists(AView: TcxCustomGridView): Boolean;

    procedure RegisterNotification(ANotification: TcxCustomGridNotification);
    procedure UnregisterNotification(ANotification: TcxCustomGridNotification);
    function SendNotifications(AKind: TcxGridNotificationKind; AData: TObject = nil): Boolean;

    procedure RootViewDataChanged(AView: TcxCustomGridView); virtual;

    property ActiveView: TcxCustomGridView read GetActiveView;
    property ActiveLevel: TcxGridLevel read FActiveLevel write SetActiveLevel;
    property BorderStyle default cxcbsDefault;
    property Color;
    property Controller: TcxGridController read FController;
    property DragOpening: Boolean read FDragOpening write FDragOpening default True;
    property DragOpeningWaitTime: Integer read FDragOpeningWaitTime write SetDragOpeningWaitTime
      default cxGridDefaultDragOpeningWaitTime;
    property FocusedView: TcxCustomGridView read FFocusedView write SetFocusedView;
    property Font;
    property Levels: TcxGridLevel read FLevels write SetLevels;
    property LevelTabs: TcxGridLevelTabs read FLevelTabs write SetLevelTabs;
    property LookAndFeel;
    property LookAndFeelPainter;
    property Painter: TcxGridPainter read FPainter;
    property RootLevelOptions: TcxGridLevelOptions read GetRootLevelOptions write SetRootLevelOptions;
    property RootLevelStyles: TcxGridLevelStyles read GetRootLevelStyles write SetRootLevelStyles;
    property StructureNavigator: TcxCustomGridStructureNavigator read GetStructureNavigator;
    property TabStop: Boolean read FTabStop write SetTabStop default True;
    property ViewCount: Integer read GetViewCount;
    property ViewInfo: TcxGridViewInfo read FViewInfo;
    property Views[Index: Integer]: TcxCustomGridView read GetView;
    property OnActiveTabChanged: TcxGridActiveTabChangedEvent read FOnActiveTabChanged write FOnActiveTabChanged;
    property OnFocusedViewChanged: TcxGridFocusedViewChangedEvent read FOnFocusedViewChanged write FOnFocusedViewChanged;
    property OnLayoutChanged: TcxGridLayoutChangedEvent read FOnLayoutChanged write FOnLayoutChanged;
  published    
    property RootLevelStylesEvents: TNotifyEvent read FSubClassEvents write FSubClassEvents;
  end;

  TcxGrid = class(TcxCustomGrid)
  published
    property Align;
    property Anchors;
  {$IFDEF DELPHI6}
    property BevelEdges;
    property BevelInner;
    property BevelOuter;
    property BevelKind;
    property BevelWidth;
    property BorderWidth;
  {$ENDIF}
    property BorderStyle;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    //property ParentColor;
    property ParentFont;
    property PopupMenu;
    property TabOrder;
    property TabStop;
    property Visible;

    //property OnClick;
  {$IFDEF DELPHI5}
    property OnContextPopup;
  {$ENDIF}
    //property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    {property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnMouseWheel;
    property OnMouseWheelDown;
    property OnMouseWheelUp;}
    property OnResize;
    property OnStartDock;
    property OnStartDrag;

    property DragOpening;
    property DragOpeningWaitTime;
    property LevelTabs;
    property LookAndFeel;
    property RootLevelOptions;
    property RootLevelStyles;

    property OnActiveTabChanged;
    property OnFocusedViewChanged;
    property OnLayoutChanged;
    property OnMouseEnter;
    property OnMouseLeave;
  end;

  { TcxGridViewRepository }

  TcxGridViewRepository = class(TComponent)  {5}
  private
    FItems: TList;
    function GetCount: Integer;
    function GetItem(Index: Integer): TcxCustomGridView;
    procedure DestroyItems;
  protected
    procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;

    procedure AddItem(AItem: TcxCustomGridView);
    procedure RemoveItem(AItem: TcxCustomGridView);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function CreateItem(AItemClass: TcxCustomGridViewClass): TcxCustomGridView;
    property Count: Integer read GetCount;
    property Items[Index: Integer]: TcxCustomGridView read GetItem; default;
  end;

var
  cxGridStructureNavigatorClass: TcxCustomGridStructureNavigatorClass;

function GetParentGrid(AControl: TControl): TcxCustomGrid;

implementation

uses
  SysUtils, Math, cxGridCustomTableView;

function GetLevel(ACaller: TComponent; Index: Integer): TComponent;
begin
  Result := TComponent(TList(TcxCustomGrid(ACaller).FTag)[Index]);
end;

function GetView(ACaller: TComponent; Index: Integer): TComponent;
begin
  Result := TcxCustomGrid(ACaller).Views[Index];
end;

{ TcxGridLayoutChange }

procedure TcxGridLayoutChange.Execute;
begin
  if GridView <> nil then
    with GridView do
      if TcxCustomGridViewAccess.GetChangeable(GridView) and
        not IsRectEmpty(Site.BoundsRect) then
      begin
        ViewInfo.MainCalculate(Site.BoundsRect);
        Painter.Invalidate;
      end
      else
  else
    with TcxCustomGrid(Control) do
      if ViewInfo <> nil then
      begin
        ViewInfo.Calculate;
        Painter.Invalidate(True);
      end;
  if Control <> nil then  {7}
    TcxCustomGrid(Control).DoLayoutChanged(GridView);
end;

function TcxGridLayoutChange.IsCompatibleWith(AChange: TcxCustomGridChange): Boolean;
begin
  Result := inherited IsCompatibleWith(AChange) or
    (AChange is TcxGridLayoutChange) and
      ((TcxGridLayoutChange(AChange).GridView = nil) or
       (GridView <> nil) and GridView.HasAsMaster(TcxGridLayoutChange(AChange).GridView)) or
    (AChange is TcxGridSizeChange) and
      ((TcxGridSizeChange(AChange).GridView = nil) or
       (GridView <> nil) and
         ((GridView = TcxGridSizeChange(AChange).GridView) or
          GridView.HasAsMaster(TcxGridSizeChange(AChange).GridView)));
end;

{ TcxGridSizeChange }

constructor TcxGridSizeChange.Create(AGridView: TcxCustomGridView;
  AUpdateGridViewOnly: Boolean = False; AKeepMaster: Boolean = False);
begin
  inherited Create(AGridView);
  FUpdateGridViewOnly := AUpdateGridViewOnly;
  FKeepMaster := AKeepMaster;
end;

procedure TcxGridSizeChange.Execute;
begin
  if GridView = nil then
    with TcxCustomGrid(Control) do
      if ActiveView <> nil then
        ActiveView.SizeChanged(False, FKeepMaster)
      else
        LayoutChanged
  else
    with GridView do
      if TcxCustomGridViewAccess.GetChangeable(GridView) then
      begin
        if ViewInfoCache <> nil then
          ViewInfoCache.UnassignValues(FKeepMaster);
        if FUpdateGridViewOnly and FKeepMaster then
          LayoutChanged
        else
          if MasterGridView = nil then
            if {(Control = nil) or }IsPattern then
              {//}LayoutChanged
            else
              TcxCustomGrid(Control).LayoutChanged
          else
            if not IsPattern and not MasterGridView.SizeChanged(False, FKeepMaster) then
              LayoutChanged;
      end;
end;

function TcxGridSizeChange.IsCompatibleWith(AChange: TcxCustomGridChange): Boolean;
begin
  Result := inherited IsCompatibleWith(AChange) or
    (AChange is TcxGridSizeChange) and (TcxGridSizeChange(AChange).GridView = GridView) and
    (TcxGridSizeChange(AChange).KeepMaster = FKeepMaster) and FUpdateGridViewOnly or
    (AChange is TcxGridDataChange) and (TcxGridDataChange(AChange).GridView = GridView);
end;

function TcxGridSizeChange.IsEqual(AChange: TcxCustomGridChange): Boolean;
begin
  Result := inherited IsEqual(AChange) and
    (FKeepMaster = TcxGridSizeChange(AChange).KeepMaster) and
    (FUpdateGridViewOnly = TcxGridSizeChange(AChange).UpdateGridViewOnly);
end;

{ TcxGridViewChange }

constructor TcxGridViewChange.Create(AGridView: TcxCustomGridView;
  const AUpdateBounds: TRect);
begin
  inherited Create(AGridView);
  FUpdateBounds := AUpdateBounds;
end;

constructor TcxGridViewChange.Create(AGridView: TcxCustomGridView;
  const AUpdateRegion: TcxRegion);
begin
  inherited Create(AGridView);
  FUpdateRegion := TcxRegion.Create;
  FUpdateRegion.Combine(AUpdateRegion, roSet, False);
end;

constructor TcxGridViewChange.Create(AGridView: TcxCustomGridView);
begin
  Create(AGridView, Rect(0, 0, 0, 0));
end;

destructor TcxGridViewChange.Destroy;
begin
  FUpdateRegion.Free;
  inherited;
end;

procedure TcxGridViewChange.Execute;
begin
  if not IsRectEmpty(FUpdateBounds) then
    GridView.Painter.Invalidate(FUpdateBounds)
  else
    if FUpdateRegion <> nil then
      GridView.Painter.Invalidate(FUpdateRegion)
    else
      GridView.Painter.Invalidate;
end;

function TcxGridViewChange.IsCompatibleWith(AChange: TcxCustomGridChange): Boolean;
begin
  Result := inherited IsCompatibleWith(AChange) or
    (AChange is TcxGridLayoutChange) and (TcxGridLayoutChange(AChange).GridView = GridView) or
    (AChange is TcxGridSizeChange) and (TcxGridSizeChange(AChange).GridView = GridView);
end;

function TcxGridViewChange.IsEqual(AChange: TcxCustomGridChange): Boolean;
begin
  Result := inherited IsEqual(AChange) and
    ((FUpdateRegion = nil) and (TcxGridViewChange(AChange).UpdateRegion = nil) and
     EqualRect(FUpdateBounds, TcxGridViewChange(AChange).UpdateBounds) or
     (FUpdateRegion <> nil) and (TcxGridViewChange(AChange).UpdateRegion <> nil) and
     FUpdateRegion.IsEqual(TcxGridViewChange(AChange).UpdateRegion));
end;

{ TcxCustomGridStructureNavigator }

constructor TcxCustomGridStructureNavigator.Create(AGrid: TcxCustomGrid);
begin
  inherited Create(nil);
  FGrid := AGrid;
  Parent := FGrid;
end;

procedure TcxCustomGridStructureNavigator.Changed;
begin
  BoundsRect := CalculateBoundsRect;
  BringToFront;
  Invalidate;
end;

procedure TcxCustomGridStructureNavigator.FontChanged;
begin
  inherited;
  Changed;
end;

function TcxCustomGridStructureNavigator.MayFocus: Boolean;
begin
  Result := False;
end;

procedure TcxCustomGridStructureNavigator.BeforeGridLoading;
begin
end;

{ TcxCustomGridHandler }

constructor TcxCustomGridHandler.Create(AControl: TcxCustomGrid);
begin
  inherited Create;
  FControl := AControl;
end;

function TcxCustomGridHandler.GetActiveController: TcxCustomGridController;
begin
  if ActiveGridView <> nil then
    Result := ActiveGridView.Controller
  else
    Result := nil;
end;

function TcxCustomGridHandler.GetActiveGridView: TcxCustomGridView;
begin
  Result := FControl.ActiveView;
end;

function TcxCustomGridHandler.GetLookAndFeelPainter: TcxCustomLookAndFeelPainterClass;
begin
  Result := FControl.LookAndFeelPainter;
end;

function TcxCustomGridHandler.GetViewInfo: TcxGridViewInfo;
begin
  Result := FControl.ViewInfo;
end;

{ TcxGridDesignController }

constructor TcxGridDesignController.Create(AControl: TcxCustomGrid);
begin
  inherited Create;
  FControl := AControl;
end;

function TcxGridDesignController.GetControl: TcxControl;
begin
  Result := FControl;
end;

{ TcxGridDragOpenInfoTab }

constructor TcxGridDragOpenInfoTab.Create(ALevel: TcxGridLevel);
begin
  inherited Create;
  Level := ALevel;
end;

function TcxGridDragOpenInfoTab.Equals(AInfo: TcxCustomGridDragOpenInfo): Boolean;
begin
  Result := inherited Equals(AInfo) and
    (Level = TcxGridDragOpenInfoTab(AInfo).Level);
end;

procedure TcxGridDragOpenInfoTab.Run;
begin
  Level.Active := True;
end;

{ TcxGridController }

destructor TcxGridController.Destroy;
begin

⌨️ 快捷键说明

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