cxgridexportlink.pas

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

PAS
1,695
字号
        if AField is TFMTBCDField then
          Result := TFMTBCDField(AField).Currency
  {$ENDIF}
  end;
end;

function TcxGridCustomExport.IsCurrencyProperties(
  AProperties: TcxCustomEditProperties): Boolean;
begin
  Result := ((AProperties is TcxMaskEditProperties) or
    (AProperties is TcxCalcEditProperties) or
    (AProperties is TcxCurrencyEditProperties)) and UseNativeFormat;
end;

function TcxGridCustomExport.IsEmpty: Boolean;
begin
  Result := (Columns.VisibleCount = 0) or (Rows.VisibleCount = 0);
end;

function TcxGridCustomExport.IsNativeFormatProperties(
  AProperties: TcxCustomEditProperties; AItem: TcxCustomGridTableItem): Boolean;
begin
  Result := (AProperties is TcxDateEditProperties) or (AProperties is TcxSpinEditProperties)
     or (AProperties is TcxTimeEditProperties) or IsCurrencyProperties(AProperties);
  Result := Result and UseNativeFormat;
end;

procedure TcxGridCustomExport.RealBoundsToLogicalBounds(
  const ABounds: TRect; out ALogicalBounds: TRect);
begin
  with ALogicalBounds do
  begin
    Columns.GetPosition(ABounds.Left, ABounds.Right, Left, Right);
    Rows.GetPosition(ABounds.Top, ABounds.Bottom, Top, Bottom);
  end;
end;

procedure TcxGridCustomExport.RealBoundsToLogicalBoundsEx(
  const ABounds, ASearchArea: TRect; out ALogicalBounds: TRect);
begin
  with ALogicalBounds do
  begin
    Columns.GetPositionEx(ABounds.Left, ABounds.Right,
      ASearchArea.Left, ASearchArea.Right, Left, Right);
    Rows.GetPositionEx(ABounds.Top, ABounds.Bottom,
      ASearchArea.Top, ASearchArea.Bottom, Top, Bottom);
  end;
end;

function TcxGridCustomExport.RegisterContentParams(ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AParams: TcxViewParams): Integer;
begin
  Result := Provider.RegisterStyle(GetContentParams(ARecord, AItem, AParams));
end;

function TcxGridCustomExport.RegisterSolidStyle(
  AStyleIndex: Integer; AData: TObject = nil): Integer;
var
  AParams: TcxViewParams;
begin
  AParams.Color := clNone;
  if GridView is TcxCustomGridTableView then
    TcxCustomGridTableView(GridView).Styles.GetViewParams(AStyleIndex, AData, nil, AParams);
  Result := RegisterSolidStyleEx(AParams.Color);
end;

procedure TcxGridCustomExport.RegisterStyles;
var
  AViewParams: TcxViewParams;
begin
  if GridView is TcxCustomGridTableView then
    with TcxCustomGridTableView(GridView).Styles do
    begin
      GetViewParams(vsBackground, nil, Background, AViewParams);
      ViewParamsToExportStyle(AViewParams, FDefaultStyle);
    end;
  Provider.SetDefaultStyle(DefaultStyle);
  DefaultStyleIndex := Provider.RegisterStyle(DefaultStyle);
end;

function TcxGridCustomExport.RegisterSolidStyleEx(AColor: TColor): Integer;
var
  AStyle: TcxCacheCellStyle;
begin
  AStyle := DefaultStyle;
  AStyle.BrushBkColor := ColorToRgb(AColor);
  Result := Provider.RegisterStyle(AStyle);
end;

function TcxGridCustomExport.RegisterViewParams(
  const AViewParams: TcxViewParams; const AAlignment: TAlignment = taLeftJustify): Integer;
var
  AStyle: TcxCacheCellStyle;
begin
  ViewParamsToExportStyle(AViewParams, AStyle, AAlignment);
  Result := Provider.RegisterStyle(AStyle)
end;

function TcxGridCustomExport.SetCellAsGraphic(AColumn, ARow: Integer;
  ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem): Boolean;
var
  AGraphic: TGraphic;
  APicture: TPicture;
begin
  Result := (AItem.GetProperties is TcxImageProperties) and ExportImagesAsGraphic;
  if not Result then Exit;  
  APicture := TPicture.Create;
  try
    LoadPicture(APicture, TcxImageProperties(AItem.GetProperties).GetGraphicClass(
      AItem, ARecord.Index), ARecord.Values[AItem.Index]);
    AGraphic := APicture.Graphic;
    if AGraphic <> nil then
      Provider.SetCellDataGraphic(AColumn, ARow, AGraphic);
  finally
    APicture.Free;
  end
end;

procedure TcxGridCustomExport.SetCellValueAndStyle(
  AColumn, ARow: Integer; const AValue: Variant; const AStyle: TcxCacheCellStyle);
begin
  Provider.SetCellValue(AColumn, ARow, AValue);
  Provider.SetCellStyle(AColumn, ARow, AStyle);
end;

procedure TcxGridCustomExport.SetRealCellStyle(
  const ARealBounds, ASearchArea: TRect; AStyleIndex: Integer);
begin
  SetRealCellStyleAndValue(ARealBounds, ASearchArea, AStyleIndex, Null);
end;

procedure TcxGridCustomExport.SetRealCellStyleAndValue(
  const ARealBounds, ASearchArea: TRect; AStyleIndex: Integer; const AValue: Variant);
var
  R: TRect;
begin
  RealBoundsToLogicalBoundsEx(ARealBounds, ASearchArea, R);
  if not VarIsNull(AValue) then
    Provider.SetCellValue(R.Left, R.Top, AValue);
  Provider.SetCellStyleEx(R.Left, R.Top, R.Bottom - R.Top, R.Right - R.Left, AStyleIndex);
end;

procedure TcxGridCustomExport.SetRealCellStyleAndValueEx(
  const ARealBounds, ASearchArea: TRect; AStyleIndex: Integer;
  ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem);
var
  R: TRect;
begin
  RealBoundsToLogicalBoundsEx(ARealBounds, ASearchArea, R);
  if AItem <> nil then
  begin
    if not Provider.SupportGraphic or not SetCellAsGraphic(R.Left, R.Top, ARecord, AItem) then
      Provider.SetCellValue(R.Left, R.Top, GetViewItemValue(ARecord, AItem));
  end;
  Provider.SetCellStyleEx(R.Left, R.Top, R.Bottom - R.Top, R.Right - R.Left, AStyleIndex);
end;

function TcxGridCustomExport.TextHeight(AFont: TFont): Integer;
begin
  Result := cxTextHeight(AFont) + cxTextOffset * 2;
end;

function TcxGridCustomExport.TextHeightEx(
  const AViewParams: TcxViewParams): Integer;
begin
  Result := TextHeight(AViewParams.Font);
end;

function TcxGridCustomExport.TextWidth(
  AFont: TFont; const AText: string): Integer;
begin
  Result := cxTextWidth(AFont, AText) + cxTextOffset * 2; 
end;

function TcxGridCustomExport.TextWidthEx(
  const AViewParams: TcxViewParams; const AText: string): Integer;
begin
  Result := TextWidth(AViewParams.Font, AText);
end;

procedure TcxGridCustomExport.ViewParamsToExportStyle(
  const AViewParams: TcxViewParams; var AExportStyle: TcxCacheCellStyle;
  const AAlignment: TAlignment = taLeftJustify;
  ABorders: TcxBorders = []; ABorderColor: TColor = clDefault);
var
  I: Integer;
begin
  AExportStyle := DefaultCellStyle;
  with AExportStyle do
  begin
    BrushBkColor := cxColorToRGB(AViewParams.Color);
    FontColor := cxColorToRGB(AViewParams.TextColor);
    StrPCopy(FontName, AViewParams.Font.Name);
    FontStyle := TcxFontStyles(AViewParams.Font.Style);
    FontSize := AViewParams.Font.Size;
    FontCharset := Integer(AViewParams.Font.Charset);
    AlignText := Alignment2ExportAlignment[AAlignment];
    for I := 0 to 3 do
    begin
      Borders[I].IsDefault := (ABorderColor = clDefault) or not (TcxBorder(I) in ABorders);
      Borders[I].Width := BorderWidths[not Borders[I].IsDefault];
      if not Borders[I].IsDefault then
        Borders[I].Color := ColorToRgb(ABorderColor);
    end;
  end;
end;

function TcxGridCustomExport.GetDataController: TcxCustomDataController;
begin
  Result := GridView.DataController;
end;

function TcxGridCustomExport.GetExpandButtonSize: Integer;
begin
  Result := ViewInfo.LookAndFeelPainter.ExpandButtonSize;
end;

function TcxGridCustomExport.GetRecord(
  ARecordIndex: Integer): TcxCustomGridRecord;
begin
  Result := TcxCustomGridRecord(RecordsList[ARecordIndex]);
end;

function TcxGridCustomExport.GetRecordCount: Integer;
begin
  Result := RecordsList.Count;
end;

function TcxGridCustomExport.GetViewInfo: TcxCustomGridViewInfo;
begin
  if FViewInfo = nil then
    FViewInfo := GridView.ViewInfo;
  Result := FViewInfo;
end;

{ TcxExportVisualItem }

function TcxExportVisualItem.GetBoundsRelativeTo(ATop, ALeft: Integer): TRect;
begin
  Result := Bounds;
  OffsetRect(Result, 0, ATop);
  Result.Left := Max(Result.Left, ALeft);
  Result.Right := Max(Result.Right, ALeft);
end;

function TcxExportVisualItem.IsColumn: Boolean;
begin
  Result := Data is TcxGridColumn;
end;

{ TcxExportGroupSummaryItem }

procedure TcxExportGroupSummaryItem.InitWidth;
begin
  Bounds.Right := Min(Bounds.Right, Bounds.Left +
    cxTextWidth(ViewParams.Font, Text) + cxTextOffset * 3);
end;

{ TcxGridTableViewExport }

procedure TcxGridTableViewExport.AddDataRow(
  var ATop, ALeft: Integer; ARow: TcxGridDataRow);
begin
  ALeft := AddIndents(ATop, RecordHeight + GetPreviewHeight(ARow), ARow, ARow.Expandable);
  if (PreviewPlace = ppTop) and HasPreview[ARow] then
    AddRowPreview(ATop, ALeft, ARow);
  CreateRecordFromPattern(ATop, ALeft, ARow);
  Inc(ATop, RecordHeight);
  if (PreviewPlace = ppBottom) and HasPreview[ARow] then
    AddRowPreview(ATop, ALeft, ARow);
end;

procedure TcxGridTableViewExport.AddFooterCells(var ATop, ALeft: Integer;
  ARow: TcxCustomGridRow; ALevel, ADataLevel: Integer; AItems: TcxDataSummaryItems;
  AValues: PVariant; AIsFooter: Boolean);
var
  R: TRect;
  AValue: Variant;
  AColumn: TcxGridColumn;
  AParams: TcxViewParams;
  AItem: TcxDataSummaryItem;
  I, J, ACellCount, ALineIndex, ARowCount: Integer;
  AFooterCell: TcxExportVisualItem;
begin
  if CanShowMultiSummaries(AIsFooter) then
    ARowCount := GetFooterLineCount(AItems)
  else
    ARowCount := RecordRowCount;
  R.Bottom := ATop + ARowCount * (DefaultRowHeight + cxGridFooterCellIndent);
  if ALevel <> 0 then
    ALeft := AddIndents(ATop, R.Bottom - ATop, ARow, False, ALevel - 1);
  R := Rect(ALeft, ATop, RecordWidth, R.Bottom);
  Styles.GetFooterParams(TcxCustomGridRow(ARow), nil, ADataLevel, nil, AParams);
  AddVisualItemEx(R, '', AParams, taLeftJustify, [], clDefault, True);
  ATop := R.Bottom;
  ACellCount := GetFooterCellCount(AItems);
  for I := 0 to PatternCount - 1 do
  begin
    if ACellCount = 0 then Break;
    ALineIndex := 0;
    if Patterns[I].IsColumn then
    begin
      AColumn := TcxGridColumn(Patterns[I].Data);
      for J := 0 to AItems.Count - 1 do
      begin
        AItem := AItems[J];
        if (AItem.ItemLink <> AColumn) or (AItem.Position <> spFooter) then Continue;
        GridView.Styles.GetFooterCellParams(ARow, AColumn, ADataLevel, AItem, AParams);
        if AIsFooter then
          AValue := DataController.Summary.FooterSummaryValues[J]
        else        
          AValue := AValues^[J];
        AFooterCell := AddVisualItemEx(GetFooterItemBounds(I, ALineIndex, R, AIsFooter), AItem.FormatValue(
          AValue, True), AParams, AColumn.FooterAlignmentHorz, cxBordersAll, FooterCellBorderColor);
        if UseNativeFormat and VarIsNumeric(AValue) then
        begin
          AFooterCell.Data2 := AItem;
          AFooterCell.Value := AValue;
          if UseNativeFormat and (AColumn <> nil) and (AItem.Format = '')  then
            AFooterCell.Value := CheckNativeValue(AColumn.GetProperties, AColumn, AValue);
        end;
        Dec(ACellCount);
        Inc(ALineIndex);
        if not CanShowMultiSummaries(AIsFooter) then Break;
      end;
    end;
  end;
end;

procedure TcxGridTableViewExport.AddGroupRow(
  var ATop, ALeft: Integer; ARow: TcxGridGroupRow);
var
  R: TRect;
  S: string;
  AValues: PVariant;
  I, AHeight: Integer;
  AViewParams: TcxViewParams;
  AItems: TcxDataSummaryItems;
  AItem: TcxExportGroupSummaryItem;

⌨️ 快捷键说明

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