cxgridreg.pas

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

PAS
1,332
字号

function TcxGridTableSummaryItemColumnProperty.InternalGetGridView(APersistent: TPersistent):
  TcxCustomGridView;
begin
  Result := (TcxCustomDataSummaryItem(APersistent).DataController as
    IcxCustomGridDataController).GridView;
end;

{ TcxGridChartItemValueTypeProperty }

type
  TcxGridChartItemValueTypeProperty = class(TcxValueTypeProperty)
  protected
    function IsValueTypeClassValid(AValueTypeClass: TcxValueTypeClass): Boolean; override;
  end;

function TcxGridChartItemValueTypeProperty.IsValueTypeClassValid(AValueTypeClass: TcxValueTypeClass): Boolean;
var
  I: Integer;
begin
  Result := inherited IsValueTypeClassValid(AValueTypeClass);
  if Result then
    for I := 0 to PropCount - 1 do
    begin
      Result := (GetComponent(I) as TcxGridChartItemDataBinding).IsValueTypeClassValid(AValueTypeClass);
      if not Result then Break;
    end;
end;

{ TcxGridChartActiveDiagramProperty }

type
  TcxGridChartActiveDiagramProperty = class(TPropertyEditor)
  private
    function GetGridView: TcxGridChartView;
  public
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;
    property GridView: TcxGridChartView read GetGridView;
  end;

function TcxGridChartActiveDiagramProperty.GetGridView: TcxGridChartView;
begin
  Result := GetComponent(0) as TcxGridChartView;
end;

function TcxGridChartActiveDiagramProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList];
end;

function TcxGridChartActiveDiagramProperty.GetValue: string;
begin
  if GridView.ActiveDiagram = nil then
    Result := 'All diagrams are disabled'
  else
    Result := GridView.ActiveDiagram.DisplayText;
end;

procedure TcxGridChartActiveDiagramProperty.GetValues(Proc: TGetStrProc);
var
  I: Integer;
begin
  for I := 0 to GridView.AvailableDiagramCount - 1 do
    Proc(GridView.AvailableDiagrams[I].DisplayText);
end;

procedure TcxGridChartActiveDiagramProperty.SetValue(const Value: string);
var
  I: Integer;
begin
  for I := 0 to GridView.AvailableDiagramCount - 1 do
    if GridView.AvailableDiagrams[I].DisplayText = Value then
    begin
      GridView.AvailableDiagrams[I].Active := True;
      Modified;
      Break;
    end;
end;

{$IFNDEF NONDB}

{ Ext Lookup }

type
  TcxExtLookupComboBoxPropertiesFieldNameProperty = class(TFieldNameProperty)
  public
    function GetDataSource: TDataSource; override;
  end;

  TcxExtLookupComboBoxPropertiesItemColumnProperty = class(TcxCustomGridTableItemProperty)
  protected
    function InternalGetGridView(APersistent: TPersistent): TcxCustomGridView; override;
  end;

  TcxExtLookupComboBoxPropertiesViewProperty = class(TComponentProperty)
  private
    FProc: TGetStrProc;
    procedure CheckComponent(const Value: string);
  public
    procedure GetValues(Proc: TGetStrProc); override;
  end;

function TcxExtLookupComboBoxPropertiesFieldNameProperty.GetDataSource: TDataSource;
var
  AProperties: TcxExtLookupComboBoxProperties;
begin
  AProperties := GetComponent(0) as TcxExtLookupComboBoxProperties;
  if AProperties.DataController <> nil then
    Result := AProperties.DataController.DataSource
  else
    Result := nil;
end;

function TcxExtLookupComboBoxPropertiesItemColumnProperty.InternalGetGridView(APersistent: TPersistent): TcxCustomGridView;
var
  AProperties: TcxExtLookupComboBoxProperties;
begin
  AProperties := APersistent as TcxExtLookupComboBoxProperties;
  Result := AProperties.View;
end;

procedure TcxExtLookupComboBoxPropertiesViewProperty.GetValues(Proc: TGetStrProc);
begin
  FProc := Proc;
  inherited GetValues(CheckComponent);
end;

procedure TcxExtLookupComboBoxPropertiesViewProperty.CheckComponent(const Value: string);
var
  AView: TcxCustomGridTableView;
begin
  AView := TcxCustomGridTableView(Designer.GetComponent(Value));
  if (AView <> nil) and TcxExtLookupComboBoxProperties.IsViewSupported(AView) then
    FProc(Value);
end;

{$ENDIF}

{$IFDEF DELPHI6}

type
  TcxGridSelectionEditor = class(TSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

  TcxGridLevelSelectionEditor = class(TSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

  TcxCustomTableViewSelectionEditor = class(TSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

  TcxCustomDBTableViewSelectionEditor = class(TcxCustomTableViewSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

  TcxCustomGridTableItemSelectionEditor = class(TSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

procedure TcxGridSelectionEditor.RequiresUnits(Proc: TGetStrProc);
begin
  Proc(UnitNamePrefix + 'cxStyles');
end;

procedure TcxGridLevelSelectionEditor.RequiresUnits(Proc: TGetStrProc);
begin
  Proc(UnitNamePrefix + 'cxStyles');
end;

procedure TcxCustomTableViewSelectionEditor.RequiresUnits(Proc: TGetStrProc);
begin
  Proc(UnitNamePrefix + 'cxStyles');
  Proc('cxCustomData');
  Proc(UnitNamePrefix + 'cxGraphics');
  Proc('cxFilter');
  Proc('cxData');
  Proc('cxDataStorage');
  Proc(UnitNamePrefix + 'cxEdit');
end;

procedure TcxCustomDBTableViewSelectionEditor.RequiresUnits(Proc: TGetStrProc);
begin
  inherited RequiresUnits(Proc);
  Proc('DB');
  Proc('cxDBData');
end;

procedure TcxCustomGridTableItemSelectionEditor.RequiresUnits(Proc: TGetStrProc);
var
  I: Integer;
  AComponent: TComponent;
  AItem: TcxCustomGridTableItem;
begin
  for I := 0 to Designer.Root.ComponentCount - 1 do
  begin
    AComponent := Designer.Root.Components[I];
    if AComponent is TcxCustomGridTableItem then
    begin
      AItem := TcxCustomGridTableItem(AComponent);
      if AItem.Properties <> nil then
        Proc(GetTypeData(PTypeInfo(AItem.Properties.ClassType.ClassInfo)).UnitName);
    end;
  end;
end;

{ TcxGridChartViewSelectionEditor }

type
  TcxGridChartViewSelectionEditor = class(TSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

procedure TcxGridChartViewSelectionEditor.RequiresUnits(Proc: TGetStrProc);
begin
  inherited;
  Proc('cxStyles');
  Proc('cxCustomData');
  Proc('cxGraphics');
end;

{$IFNDEF NONDB}

{ TcxGridDBChartViewSelectionEditor }

type
  TcxGridDBChartViewSelectionEditor = class(TcxGridChartViewSelectionEditor)
  public
    procedure RequiresUnits(Proc: TGetStrProc); override;
  end;

procedure TcxGridDBChartViewSelectionEditor.RequiresUnits(Proc: TGetStrProc);
begin
  inherited;
  Proc('DB');
  Proc('cxDBData');
end;

{$ENDIF}

{$ENDIF}

type

{ TcxImageComboBoxItemsProperty }
  
  TcxImageComboBoxItemsProperty = class(TPropertyEditor)
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
  end;

procedure TcxImageComboBoxItemsProperty.Edit;
var
  S: string;
  AProperties: TcxImageComboBoxProperties;
begin
  S := 'Properties' + '.' + GetName;
  AProperties := TcxImageComboBoxProperties(GetComponent(0));
  if (AProperties.Owner <> nil) and (AProperties.Owner is TComponent) then
    S := TComponent(AProperties.Owner).Name + '.' + S;
  with TfmImageComboBoxItemsEditor.Create(
    AProperties.Items, AProperties.Images, AProperties.LargeImages) do
  try
    Caption := S;
    if ShowModal = mrOk then
      Self.Designer.Modified;
  finally
    Free;
  end;
end;

function TcxImageComboBoxItemsProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paReadOnly];
end;

function TcxImageComboBoxItemsProperty.GetValue: string;
begin
  FmtStr(Result, '(%s)', [GetPropType^.Name]);
end;

procedure Register;
begin
{$IFDEF DELPHI9}
  ForceDemandLoadState(dlDisable);
{$ENDIF}  

  RegisterComponentEditor(TcxGrid, TGridEditor);
  RegisterComponentEditor(TcxGridViewRepository, TGridViewRepositoryEditor);

  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxCustomGrid, 'RootLevelStylesEvents',
    TcxGridRootLevelStylesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxCustomGridTableItem, 'PropertiesEvents',
    TcxGridTableItemPropertiesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxCustomGridTableItem, 'StylesEvents',
    TcxGridTableItemStylesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxCustomGridView, 'DataControllerEvents',
    TcxGridDataControllerEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxCustomGridView, 'StylesEvents',
    TcxGridViewStylesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxCustomGridTableView, 'NavigatorButtonsEvents',
    TcxGridViewNavigatorButtonsEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridLevel, 'StylesEvents',
    TcxGridLevelStylesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridBand, 'StylesEvents',
    TcxGridBandStylesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartSeries, 'StylesEvents',
    TcxGridChartSeriesStylesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartHistogram, 'ValuesEvents',
    TcxGridChartHistogramValuesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartView, 'CategoriesEvents',
    TcxGridChartCategoriesEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartView, 'DiagramAreaEvents',
    TcxGridChartAreaDiagramEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartView, 'DiagramBarEvents',
    TcxGridChartBarDiagramEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartView, 'DiagramColumnEvents',
    TcxGridChartColumnDiagramEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartView, 'DiagramLineEvents',
    TcxGridChartLineDiagramEventsProperty);
  RegisterPropertyEditor(TypeInfo(TNotifyEvent), TcxGridChartView, 'DiagramPieEvents',
    TcxGridChartPieDiagramEventsProperty);

  RegisterPropertyEditor(TypeInfo(TcxCustomGridView), TcxGridLevel, 'GridView',
    TcxGridLevelGridViewProperty);
  RegisterPropertyEditor(TypeInfo(TImageIndex), TcxGridLevel, 'ImageIndex',
    TcxGridLevelImageIndexProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxCustomGridTableItem, 'PropertiesClassName', nil);
  RegisterPropertyEditor(TypeInfo(TcxCustomEditProperties), TcxCustomGridTableItem,
    'Properties', TcxCustomGridTableItemPropertiesProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxGridItemDataBinding, 'ValueType',
    TcxValueTypeProperty);
  RegisterPropertyEditor(TypeInfo(TComponent), TcxCustomGridView, 'PopupMenu',
    TcxControlPopupMenuProperty);
  RegisterPropertyEditor(TypeInfo(Boolean), TcxCustomGridTableOptionsSelection, 'HideFocusRect', nil);
  RegisterPropertyEditor(TypeInfo(TAlignment), TcxGridBand, 'Alignment', nil);
  RegisterPropertyEditor(TypeInfo(Integer), TcxGridBandedColumnPosition, 'BandIndex',
    TcxGridBandedColumnBandIndexProperty);
  RegisterPropertyEditor(TypeInfo(Integer), TcxGridBandPosition, 'BandIndex',
    TcxGridBandBandIndexProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxGridChartItemDataBinding, 'ValueType',
    TcxGridChartItemValueTypeProperty);
  RegisterPropertyEditor(TypeInfo(TcxGridChartDiagram), TcxGridChartView, 'ActiveDiagram',
    TcxGridChartActiveDiagramProperty);

  RegisterPropertyEditor(TypeInfo(TcxCustomGridTableItem), TcxCustomGridTableOptionsBehavior,
    'IncSearchItem', TcxGridIncSearchItemProperty);
  RegisterPropertyEditor(TypeInfo(TcxCustomGridTableItem), TcxGridPreview,
    'Column', TcxGridPreviewColumnProperty);
  RegisterPropertyEditor(TypeInfo(TcxCustomGridTableItem), TcxGridTableSummaryItem,
    'Column', TcxGridTableSummaryItemColumnProperty);
{$IFNDEF NONDB}
  RegisterPropertyEditor(TypeInfo(TcxCustomGridTableItem), TcxGridDBTableSummaryItem,
    'Column', TcxGridTableSummaryItemColumnProperty);
{$ENDIF}
  RegisterPropertyEditor(TypeInfo(TcxCustomGridTableItem), TcxGridTableSummaryGroupItemLink,
    'Column', TcxGridTableSummaryItemColumnProperty);

{$IFNDEF NONDB}
  RegisterPropertyEditor(TypeInfo(string), TcxDBDataController, 'DetailKeyFieldNames', TFieldNameProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxDBDataController, 'KeyFieldNames', TFieldNameProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxDBDataController, 'MasterKeyFieldNames', TMasterKeyFieldNamesProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxDBDataSummaryItem, 'FieldName', TcxDBDataSummaryItemFieldNameProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxGridItemDBDataBinding, 'FieldName', TcxGridItemDBDataBindingFieldNameProperty);
  RegisterPropertyEditor(TypeInfo(string), TcxGridDBChartItemDataBinding, 'FieldName', TcxGridDBChartItemDataBindingFieldNameProperty);
{$ENDIF}

  RegisterNoIcon([TcxGridLevel,
    TcxGridTableView, {$IFNDEF NONDB}TcxGridDBTableView,{$ENDIF}
    TcxGridBandedTableView, {$IFNDEF NONDB}TcxGridDBBandedTableView,{$ENDIF}
    TcxGridChartView, {$IFNDEF NONDB}TcxGridDBChartView,{$ENDIF}
    TcxGridCardView{$IFNDEF NONDB}, TcxGridDBCardView{$ENDIF}]);
  RegisterNoIcon([
    TcxGridColumn, {$IFNDEF NONDB}TcxGridDBColumn,{$ENDIF}
    TcxGridBandedColumn, {$IFNDEF NONDB}TcxGridDBBandedColumn,{$ENDIF}
    TcxGridCardViewRow, {$IFNDEF NONDB}TcxGridDBCardViewRow,{$ENDIF}
    TcxGridChartDataGroup, {$IFNDEF NONDB}TcxGridDBChartDataGroup,{$ENDIF}
    TcxGridChartSeries{$IFNDEF NONDB}, TcxGridDBChartSeries{$ENDIF}]);
  RegisterNoIcon([TcxGridTableViewStyleSheet, TcxGridBandedTableViewStyleSheet, TcxGridCardViewStyleSheet]);
  RegisterComponents('Dev Express', [TcxGrid, TcxGridViewRepository]);
{$IFNDEF NONDB}
  // Ext Lookup
  RegisterComponents('Express Editors 6', [TcxExtLookupComboBox]);
  RegisterComponents('Express DBEditors 6', [TcxDBExtLookupComboBox]);
  RegisterEditRepositoryItem(TcxEditRepositoryExtLookupComboBoxItem, cxSEditRepositoryExtLookupComboBoxItem);
  RegisterPropertyEditor(TypeInfo(string), TcxExtLookupComboBoxProperties, 'KeyFieldNames', TcxExtLookupComboBoxPropertiesFieldNameProperty);
  RegisterPropertyEditor(TypeInfo(TcxCustomGridTableItem), TcxExtLookupComboBoxProperties, 'ListFieldItem', TcxExtLookupComboBoxPropertiesItemColumnProperty);
  RegisterPropertyEditor(TypeInfo(TcxCustomGridTableView), TcxExtLookupComboBoxProperties, 'View', TcxExtLookupComboBoxPropertiesViewProperty);
  RegisterPropertyEditor(TypeInfo(TShortCut), TcxExtLookupComboBoxProperties, 'ClearKey', TShortCutProperty);
{$ENDIF}

{$IFDEF DELPHI6}
  RegisterSelectionEditor(TcxCustomGrid, TcxGridSelectionEditor);
  RegisterSelectionEditor(TcxGridLevel, TcxGridLevelSelectionEditor);
  RegisterSelectionEditor(TcxCustomGridTableView, TcxCustomTableViewSelectionEditor);
  RegisterSelectionEditor(TcxGridChartView, TcxGridChartViewSelectionEditor);
{$IFNDEF NONDB}
  RegisterSelectionEditor(TcxGridDBTableView, TcxCustomDBTableViewSelectionEditor);
  RegisterSelectionEditor(TcxGridDBBandedTableView, TcxCustomDBTableViewSelectionEditor);
  RegisterSelectionEditor(TcxGridDBCardView, TcxCustomDBTableViewSelectionEditor);
  RegisterSelectionEditor(TcxGridDBChartView, TcxGridDBChartViewSelectionEditor);
{$ENDIF}
  RegisterSelectionEditor(TcxCustomGridTableItem, TcxCustomGridTableItemSelectionEditor);
{$ENDIF}

  RegisterPropertyEditor(TypeInfo(TcxImageComboBoxItems),
    TcxImageComboBoxProperties, 'Items', TcxImageComboBoxItemsProperty);

end;

initialization
{$IFDEF DELPHI6}
  StartClassGroup(TControl);
  GroupDescendentsWith(TcxGrid, TControl);
  GroupDescendentsWith(TcxGridViewRepository, TControl);
  GroupDescendentsWith(TcxGridLevel, TControl);
  GroupDescendentsWith(TcxCustomGridView, TControl);
  GroupDescendentsWith(TcxCustomGridTableItem, TControl);
  GroupDescendentsWith(TcxGridItemDataBinding, TControl);
  GroupDescendentsWith(TcxGridChartItem, TControl);
{$ENDIF}
  RegisterStyleSheetClass(TcxGridTableViewStyleSheet);
  RegisterStyleSheetClass(TcxGridBandedTableViewStyleSheet);
  RegisterStyleSheetClass(TcxGridCardViewStyleSheet);

finalization
  UnregisterStyleSheetClass(TcxGridCardViewStyleSheet);
  UnregisterStyleSheetClass(TcxGridBandedTableViewStyleSheet);
  UnregisterStyleSheetClass(TcxGridTableViewStyleSheet);

end.

⌨️ 快捷键说明

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