cxgridcustomtableview.pas

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

PAS
1,405
字号
    function GetValue(const ADate: TDateTime): Variant; override;
  end;

  TcxGridDateTimeFilter = (dtfRelativeDays, dtfRelativeDayPeriods, dtfRelativeWeeks,
    dtfRelativeMonths, dtfRelativeYears, dtfPastFuture, dtfMonths, dtfYears);
  TcxGridDateTimeFilters = set of TcxGridDateTimeFilter;
  TcxGridDateTimeGrouping = (dtgDefault, dtgByDateAndTime, dtgRelativeToToday,
    dtgByHour, dtgByDate, dtgByMonth, dtgByYear);

  TcxGridDateRangesClass = class of TcxGridDateRanges;

  TcxGridDateRanges = class
  private
    FDateTimeHandling: TcxCustomGridTableDateTimeHandling;
    FItems: TList;
    FStartOfThisWeek: TDateTime;
    FThisDay: Word;
    FThisMonth: Word;
    FThisMonthNumber: Integer;
    FThisYear: Word;
    FToday: TDateTime;
    function GetCount: Integer;
    function GetItem(Index: Integer): TcxCustomGridDateRange;
  protected
    procedure AddItem(AItem: TcxCustomGridDateRange);
    procedure RemoveItem(AItem: TcxCustomGridDateRange);
    function GetItemIndex(AItem: TcxCustomGridDateRange): Integer;
    procedure SetItemIndex(AItem: TcxCustomGridDateRange; AValue: Integer);

    procedure InitConsts; virtual;
  public
    constructor Create; virtual;
    destructor Destroy; override;
    procedure Add(ARange: TcxCustomGridDateRange); overload;
    procedure Add(ARangeClass: TcxCustomGridDateRangeClass); overload;
    procedure Clear;
    function GetRange(const ADate: TDateTime): TcxCustomGridDateRange; overload;
    function GetRange(ARangeClass: TcxCustomGridDateRangeClass): TcxCustomGridDateRange; overload;
    procedure Init(ADateTimeHandling: TcxCustomGridTableDateTimeHandling); virtual;
    function IsEmpty: Boolean;
    function NeedSortingByTime: Boolean;
    function NeedTime: Boolean;

    property Count: Integer read GetCount;
    property Items[Index: Integer]: TcxCustomGridDateRange read GetItem; default;

    property DateTimeHandling: TcxCustomGridTableDateTimeHandling read FDateTimeHandling;
    property StartOfThisWeek: TDateTime read FStartOfThisWeek;
    property ThisDay: Word read FThisDay;
    property ThisMonth: Word read FThisMonth;
    property ThisMonthNumber: Integer read FThisMonthNumber;
    property ThisYear: Word read FThisYear;
    property Today: TDateTime read FToday;
  end;

  TcxGridFilteringDateRangesClass = class of TcxGridFilteringDateRanges;

  TcxGridFilteringDateRanges = class(TcxGridDateRanges)
  public
    procedure Init(ADateTimeHandling: TcxCustomGridTableDateTimeHandling;
      ADateTimeFilters: TcxGridDateTimeFilters); reintroduce; virtual;
  end;

  TcxGridGroupingDateRangesClass = class of TcxGridGroupingDateRanges;

  TcxGridGroupingDateRanges = class(TcxGridDateRanges)
  public
    procedure Init(ADateTimeHandling: TcxCustomGridTableDateTimeHandling;
      ADateTimeGrouping: TcxGridDateTimeGrouping); reintroduce; virtual;
  end;

  // record

  TcxCustomGridRecordClass = class of TcxCustomGridRecord;

  TcxCustomGridRecord = class
  private
    //FData: Pointer;
    FIndex: Integer;
    FViewData: TcxCustomGridTableViewData;
    FViewInfo: TcxCustomGridRecordViewInfo;
    function GetController: TcxCustomGridTableController;
    function GetDataController: TcxCustomDataController;
    function GetDragHighlighted: Boolean;
    function GetFocused: Boolean;
    function GetGridView: TcxCustomGridTableView;
    function GetIsEditing: Boolean;
    function GetIsNewItemRecord: Boolean;
    function GetIsValid: Boolean;
    function GetLastParentRecordCount: Integer;
    function GetLevel: Integer;
    function GetPartVisible: Boolean;
    function GetRecordIndex: Integer;
    procedure SetExpanded(Value: Boolean);
    procedure SetFocused(Value: Boolean);
  protected
    RecordInfo: TcxRowInfo;
    procedure RefreshRecordInfo; virtual;

    procedure DoCollapse(ARecurse: Boolean); virtual;
    procedure DoExpand(ARecurse: Boolean); virtual;
    //function GetDestroyingOnExpanding: Boolean; virtual;
    function GetExpandable: Boolean; virtual;
    function GetExpanded: Boolean; virtual;
    procedure ToggleExpanded; virtual;

    function GetHasCells: Boolean; virtual;
    function GetIsData: Boolean; virtual;
    function GetIsFirst: Boolean; virtual;
    function GetIsLast: Boolean; virtual;
    function GetIsParent: Boolean; virtual;
    function GetIsParentRecordLast(AIndex: Integer): Boolean;
    function GetParentRecord: TcxCustomGridRecord; virtual;
    function GetSelected: Boolean; virtual;
    function GetVisible: Boolean; virtual;
    procedure SetSelected(Value: Boolean); virtual;

    function GetDisplayText(Index: Integer): string; virtual;
    function GetValueCount: Integer; virtual;
    function GetValue(Index: Integer): Variant; virtual;
    procedure SetDisplayText(Index: Integer; const Value: string); virtual;
    procedure SetValue(Index: Integer; const Value: Variant); virtual;

    procedure KeyDown(var Key: Word; Shift: TShiftState); virtual;

    function GetViewInfoCacheItemClass: TcxCustomGridViewInfoCacheItemClass; virtual; abstract;
    function GetViewInfoClass: TcxCustomGridRecordViewInfoClass; virtual; abstract;

    property IsParent: Boolean read GetIsParent;
    property IsParentRecordLast[AIndex: Integer]: Boolean read GetIsParentRecordLast;
    property IsValid: Boolean read GetIsValid;
    property LastParentRecordCount: Integer read GetLastParentRecordCount;

    property Controller: TcxCustomGridTableController read GetController;
    property DataController: TcxCustomDataController read GetDataController;
    //property DestroyingOnExpanding: Boolean read GetDestroyingOnExpanding;
  public
    constructor Create(AViewData: TcxCustomGridTableViewData; AIndex: Integer;
      const ARecordInfo: TcxRowInfo); virtual;
    destructor Destroy; override;
    function CanFocus: Boolean; virtual;
    function CanFocusCells: Boolean; virtual;
    procedure Collapse(ARecurse: Boolean);
    procedure Expand(ARecurse: Boolean);
    function GetFirstFocusableChild: TcxCustomGridRecord; virtual;
    function GetLastFocusableChild(ARecursive: Boolean): TcxCustomGridRecord; virtual;
    procedure Invalidate(AItem: TcxCustomGridTableItem = nil); virtual;
    procedure MakeVisible;

    //property Data: Pointer read FData write FData;
    property DragHighlighted: Boolean read GetDragHighlighted;
    property DisplayTexts[Index: Integer]: string read GetDisplayText write SetDisplayText;
    property Expandable: Boolean read GetExpandable;
    property Expanded: Boolean read GetExpanded write SetExpanded;
    property Focused: Boolean read GetFocused write SetFocused;
    property GridView: TcxCustomGridTableView read GetGridView;
    property HasCells: Boolean read GetHasCells;
    property Index: Integer read FIndex;
    property IsData: Boolean read GetIsData;
    property IsEditing: Boolean read GetIsEditing;
    property IsFirst: Boolean read GetIsFirst;
    property IsLast: Boolean read GetIsLast;
    property IsNewItemRecord: Boolean read GetIsNewItemRecord;
    property Level: Integer read GetLevel;
    property ParentRecord: TcxCustomGridRecord read GetParentRecord;
    property PartVisible: Boolean read GetPartVisible;
    property RecordIndex: Integer read GetRecordIndex;
    property Selected: Boolean read GetSelected write SetSelected;
    property ValueCount: Integer read GetValueCount;
    property Values[Index: Integer]: Variant read GetValue write SetValue;
    property ViewData: TcxCustomGridTableViewData read FViewData;
    property ViewInfo: TcxCustomGridRecordViewInfo read FViewInfo;
    property Visible: Boolean read GetVisible;
  end;

  // view data

  TcxGridDataOperation = (doSorting, doGrouping, doFiltering);

  TcxCustomGridTableViewData = class(TcxCustomGridViewData)
  private
    FEditingRecord: TcxCustomGridRecord;
    FNewItemRecord: TcxCustomGridRecord;
    FRecords: TList;
    function GetController: TcxCustomGridTableController;
    function GetEditingRecord: TcxCustomGridRecord;
    function GetGridView: TcxCustomGridTableView;
    function GetInternalRecord(Index: Integer): TcxCustomGridRecord;
    function GetRecord(Index: Integer): TcxCustomGridRecord;
    function GetRecordCount: Integer;
    function GetViewInfo: TcxCustomGridTableViewInfo;
    function CreateRecord(AIndex: Integer): TcxCustomGridRecord;
  protected
    function GetFilterValueListClass: TcxGridFilterValueListClass; virtual;
    function GetRecordByKind(AKind, AIndex: Integer): TcxCustomGridRecord; virtual;
    function GetRecordClass(ARecordInfo: TcxRowInfo): TcxCustomGridRecordClass; virtual; abstract;
    function GetRecordKind(ARecord: TcxCustomGridRecord): Integer; virtual;

    procedure AssignEditingRecord;

    procedure CreateNewItemRecord;
    procedure DestroyNewItemRecord;
    function GetNewItemRecordClass: TcxCustomGridRecordClass; virtual;
    procedure RecreateNewItemRecord;

    property Controller: TcxCustomGridTableController read GetController;
    property InternalRecords[Index: Integer]: TcxCustomGridRecord read GetInternalRecord;
    property ViewInfo: TcxCustomGridTableViewInfo read GetViewInfo;
  public
    constructor Create(AGridView: TcxCustomGridView); override;
    destructor Destroy; override;

    procedure Collapse(ARecurse: Boolean); virtual;
    procedure DestroyRecords;
    procedure Expand(ARecurse: Boolean); virtual;
    function GetRecordByIndex(AIndex: Integer): TcxCustomGridRecord;
    function GetRecordByRecordIndex(ARecordIndex: Integer): TcxCustomGridRecord;
    function GetRecordIndexByRecord(ARecord: TcxCustomGridRecord): Integer;
    function IsRecordIndexValid(AIndex: Integer): Boolean;
    procedure Refresh(ARecordCount: Integer); virtual;
    procedure RefreshRecords;

    procedure CheckNewItemRecord;
    function HasNewItemRecord: Boolean; virtual;

    function AddItemToFilter(AParent: TcxFilterCriteriaItemList; AItem: TcxCustomGridTableItem;
      AOperatorKind: TcxFilterOperatorKind; const AValue: Variant; ADisplayText: string = '';
      AReplaceExistent: Boolean = True): TcxFilterCriteriaItem;
    function CreateFilterValueList: TcxGridFilterValueList;
    function GetDisplayText(ARecordIndex, AItemIndex: Integer; out AText: string;
      AUseCustomValue: Boolean = False; ACustomValueOperation: TcxGridDataOperation = doGrouping): Boolean; virtual;

    // custom data handling
    function CustomCompareDataValues(AField: TcxCustomDataField; const AValue1, AValue2: Variant;
      AMode: TcxDataControllerComparisonMode): Integer; virtual;
    function GetCustomDataDisplayText(ARecordIndex, AItemIndex: Integer;
      AOperation: TcxGridDataOperation): string; virtual;
    function GetCustomDataValue(AField: TcxCustomDataField; const AValue: Variant;
      AOperation: TcxGridDataOperation): Variant; overload;
    function GetCustomDataValue(AItem: TcxCustomGridTableItem; const AValue: Variant;
      AOperation: TcxGridDataOperation): Variant; overload; virtual;
    function HasCustomDataHandling(AField: TcxCustomDataField; AOperation: TcxGridDataOperation): Boolean; overload;
    function HasCustomDataHandling(AItem: TcxCustomGridTableItem; AOperation: TcxGridDataOperation): Boolean; overload; virtual;
    function NeedsCustomDataComparison(AField: TcxCustomDataField; AMode: TcxDataControllerComparisonMode): Boolean; virtual;

    property EditingRecord: TcxCustomGridRecord read FEditingRecord;
    property GridView: TcxCustomGridTableView read GetGridView;
    property NewItemRecord: TcxCustomGridRecord read FNewItemRecord;
    property RecordCount: Integer read GetRecordCount;
    property Records[Index: Integer]: TcxCustomGridRecord read GetRecord;
  end;

  { controller }

  // drag&drop objects

  TcxCustomGridTableMovingObject = class(TcxCustomGridMovingObject)
  private
    function GetController: TcxCustomGridTableController;
    function GetCustomizationForm: TcxCustomGridTableCustomizationForm;
  protected
    procedure DragAndDrop(const P: TPoint; var Accepted: Boolean); override;
    property Controller: TcxCustomGridTableController read GetController;
    property CustomizationForm: TcxCustomGridTableCustomizationForm read GetCustomizationForm;
  end;

  TcxGridItemContainerKind = Integer;

  TcxGridItemContainerZone = class
  public
    ItemIndex: Integer;
    constructor Create(AItemIndex: Integer);
    function IsEqual(Value: TcxGridItemContainerZone): Boolean; virtual;
  end;

  TcxCustomGridTableItemMovingObject = class(TcxCustomGridTableMovingObject)
  private
    FDestItemContainerKind: TcxGridItemContainerKind;
    FDestZone: TcxGridItemContainerZone;
    FSourceItemContainerKind: TcxGridItemContainerKind;

⌨️ 快捷键说明

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