⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cxvgridviewinfo.pas

📁 delphi的的三方控件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
begin
  FAutoScaleBands := VerticalGrid.OptionsView.AutoScaleBands;
  inherited CalcLayoutGeneral;
  FBandsIndent := VerticalGrid.OptionsView.BandsInterval;
end;

function TcxBandsViewInfo.CanAddRowToBand(const ARowRect, ABandRect: TRect;
  ABandRowIndex: Integer): Boolean;
begin
  Result := (ARowRect.Bottom <= ABandRect.Bottom) or (ABandRowIndex = 0);
end;

procedure TcxBandsViewInfo.CreateBand(ABandHeight, ABandWidth: Integer);
var
  ABandIndex, ALeft: Integer;
  R: TRect;
begin
  ABandIndex := ViewRects.BandRects.Count;
  if ABandIndex = 0 then
    ALeft := ClientRect.Left
  else
    ALeft := ViewRects.BandRects[ABandIndex - 1].Right;
  R := cxRectBounds(ALeft, ClientRect.Top, ABandWidth,
    Min(ABandHeight, cxRectHeight(ClientRect)));
  ViewRects.BandRects.Add(R);
  if R.Bottom < ClientRect.Bottom then
    ViewRects.EmptyRects.Add(cxRectBounds(R.Left, R.Bottom, ABandIndex,
      cxRectHeight(ClientRect) - cxRectHeight(R)));
end;

function TcxBandsViewInfo.GetBandSizeableRect(const ABandRect: TRect): TRect;
begin
  if VerticalGrid.OptionsView.AutoScaleBands then
    Result := cxNullRect
  else
    Result := inherited GetBandSizeableRect(ABandRect);
end;

function TcxBandsViewInfo.GetMinViewBandWidth: Integer;
begin
  Result := GetViewMinHeaderWidth + VerticalGrid.OptionsView.ValueMinWidth
end;

function TcxBandsViewInfo.GetRowAutoHeight(ARow: TcxCustomRow): Boolean;
begin
  with VerticalGrid.OptionsView do
    Result := CellAutoHeight and not FAutoScaleBands and
      ARow.Options.CanAutoHeight;
end;

function TcxBandsViewInfo.GetViewBandWidth: Integer;
begin
  if not AutoScaleBands then
    Result := ViewHeaderWidth + DividerWidth + ViewValueWidth + 2
  else
    Result := Max(ViewBandWidth, GetMinViewBandWidth);
end;

function TcxBandsViewInfo.GetViewValueWidth: Integer;
begin
  Result := VerticalGrid.OptionsView.ValueWidth
end;

function TcxBandsViewInfo.GetVisibleValueCount: Integer;
begin
  Result := 1;
end;

procedure TcxBandsViewInfo.LayoutStyleChanged;
begin
  if AutoScaleBands then
  begin
    ViewHeaderWidth := Max(VerticalGrid.OptionsView.RowHeaderWidth, GetViewMinHeaderWidth);
    SetDividerPos(ViewHeaderWidth);
    ViewBandWidth := GetMinViewBandWidth;
  end;
  inherited LayoutStyleChanged;
end;

procedure TcxBandsViewInfo.SetDividerPos(APos: Integer);
begin
  FLock := True;
  try
    if AutoScaleBands then
      inherited SetDividerPos(APos)
    else
    begin
      if APos > ClipRect.Right - 4 then APos := ClipRect.Right - 4;
      VerticalGrid.OptionsView.RowHeaderWidth := APos;
    end;
  finally
    FLock := False;
  end;
end;

procedure TcxBandsViewInfo.UpdateBandsWidth;
var
  I, ACurLeft: Integer;
  R, B: TRect;
begin
  ACurLeft := ClientRect.Left;
  with ViewRects do
  begin
    for I := 0 to BandRects.Count - 1 do
    begin
      R := BandRects[I];
      R.Left := ACurLeft;
      R.Right := R.Left + ViewBandWidth;
      Inc(ACurLeft, ViewBandWidth + BandsIndent);
      if AutoScaleBands then
      begin
        if I = BandRects.Count - 1 then
        begin
          Dec(ACurLeft, BandsIndent);
          Inc(R.Right, ClientRect.Right - ACurLeft);
        end;
      end;
      BandRects[I] := R;
    end;
    for I := 0 to EmptyRects.Count - 1 do
    begin
      R := EmptyRects[I];
      B := BandRects[R.Right - R.Left];
      R.Left := B.Left;
      R.Right := B.Right;
      EmptyRects[I] := R;
    end;
  end;
end;

{ TcxMultiRecordViewInfo }

constructor TcxMultiRecordViewInfo.Create(AOwner: TcxEditingControl);
begin
  inherited Create(AOwner);
  FVisibleValueCount := -1;
end;

function TcxMultiRecordViewInfo.GetDefaultGridModeBufferCount: Integer;
var
  W: Integer;
begin
  W := cxRectWidth(ClientRect) - ViewHeaderWidth - DividerWidth - VertLineWidth;
  if W <= 0 then
  begin
    Result := 1;
    Exit;
  end;
  Result := W div (ViewValueWidth + RecordsInterval);
  if Result * (ViewValueWidth + RecordsInterval) < W then Inc(Result);
end;

function TcxMultiRecordViewInfo.GetValueRect(AValueIndex: Integer;
  ARowViewInfo: TcxCustomRowViewInfo): TRect;
var
  ALeft: Integer;
begin
  with ARowViewInfo.RowRect do
  begin
    ALeft := Left + ViewHeaderWidth + DividerWidth +
      AValueIndex * (ViewValueWidth + cxSetValue(RecordsInterval = 0, VertLineWidth,
      RecordsInterval + 2 * VertLineWidth));
    Result := cxRectBounds(ALeft, Top, ViewValueWidth, Bottom - Top);
  end;
end;

procedure TcxMultiRecordViewInfo.UpdateRecord(ARecordIndex: Integer);
var
  I: Integer;
begin
  if ARecordIndex < 0 then Exit;
  for I := 0 to RowsViewInfo.Count - 1 do
    RowsViewInfo[I].UpdateRecord(ARecordIndex);
end;

procedure TcxMultiRecordViewInfo.AddBandRowsLines(const R: TRect);
var
  ASize: TSize;
  ABandRect: TRect;
  I, ALeft, ATop, AHeight: Integer;
  ARowInfo: TcxCustomRowViewInfo;

  procedure AddRecordInterval(ALast: Boolean);
  var
    I: Integer;
    R: TRect;
  begin
    if AHeight > 0 then
      for I := 0 to VisibleValueCount - 2 do
      begin
        if (HorzLineWidth > 0) and not ALast then
          LinesInfo.Add(ALeft, ATop + AHeight, RecordsInterval, HorzLineWidth,
            BandBorderColor);
        R := cxRectBounds(ALeft, ATop, RecordsInterval, AHeight);
        if ALast then Inc(R.Bottom, HorzLineWidth);
        ViewRects.EmptyRects.Add(R);
        if VertLineWidth > 0 then
          LinesInfo.Add(R.Right, R.Top, VertLineWidth, AHeight + HorzLineWidth,
            BandBorderColor);
        Inc(ALeft, ViewValueWidth + RecordsInterval + 2 * VertLineWidth);
      end;
  end;

begin
  if RecordsInterval = 0 then
  begin
    inherited AddBandRowsLines(R);
    Exit;
  end;
  ABandRect := R;
  if RecordsInterval > 0 then
  begin
    ALeft := ABandRect.Left + FCommonWidth;
    ATop := ClientRect.Top;
    AHeight := 0;
    for I := 0 to RowsViewInfo.Count - 1 do
    begin
      ARowInfo := RowsViewInfo[I];
      if not (ARowInfo is TcxCategoryRowViewInfo) then
        Inc(AHeight, cxRectHeight(ARowInfo.RowRect) + HorzLineWidth)
      else
      begin
        AddRecordInterval(False);
        AHeight := 0;
        ATop := ARowInfo.RowRect.Bottom;
        ALeft := ABandRect.Left + 2 * VertLineWidth + DividerWidth +
          ViewHeaderWidth + ViewValueWidth;
      end;
    end;
    AddRecordInterval(True);
  end;
  if (VertLineWidth > 0) then
    with R do
      LinesInfo.Add(Left, Top - HorzLineWidth, VertLineWidth, Bottom - Top,
        BandBorderColor);
  ALeft := R.Left;
  ATop  := R.Top;
  ASize := cxSize(FCommonWidth, R.Bottom - R.Top);
  while ALeft < R.Right do
  begin
    if ALeft + ASize.cx > R.Right then ASize.cx := R.Right - ALeft;
    with cxRectBounds(ALeft, ATop, ASize.cx, ASize.cy) do
    begin
      if HorzLineWidth > 0 then
      begin
        LinesInfo.Add(Left, Top, Right - Left, HorzLineWidth, BandBorderColor);
        LinesInfo.Add(Left, Bottom - HorzLineWidth, Right - Left, HorzLineWidth, BandBorderColor);
      end;
    end;
    Inc(ALeft, RecordsInterval + ASize.cx);
    ASize.cx := 2 * VertLineWidth + ViewValueWidth;
  end;
end;

procedure TcxMultiRecordViewInfo.AddEmptyRects;
var
  ABandRect: TRect;
begin
  ABandRect := ViewRects.BandRects[0];
//  Inc(ABandRect.Bottom, HorzLineWidth * 2); ?
  if ABandRect.Right < ClientRect.Right then
    ViewRects.EmptyRects.Add(cxRect(ABandRect.Right, ABandRect.Top,
      ClientRect.Right, ClientRect.Bottom));
end;

procedure TcxMultiRecordViewInfo.AddRightValueSide(const R: TRect;
  ALast: Boolean);
begin
  inherited AddRightValueSide(R, ALast or (FRecordsInterval > 0));
end;

procedure TcxMultiRecordViewInfo.CalcBandWidth;
var
  AWidth: Integer;     
begin
  ViewHeaderWidth := GetViewHeaderWidth;
  ViewValueWidth := VerticalGrid.OptionsView.ValueWidth;
  AWidth := ViewHeaderWidth + 2 * VertLineWidth + DividerWidth + ViewValueWidth;
  FCommonWidth := AWidth;
  if RecordCount > 1 then
    Inc(AWidth, (RecordCount - Scroller.LeftVisibleRecord - 1) *
      (ViewValueWidth + cxSetValue(RecordsInterval = 0, VertLineWidth,
       RecordsInterval + 2 * VertLineWidth)));
  ViewBandWidth := Min(AWidth, cxRectWidth(ClientRect));
end;

procedure TcxMultiRecordViewInfo.CalcLayoutGeneral;
begin
  FRecordsInterval :=
    TcxvgMultiRecordsOptionsView(VerticalGrid.OptionsView).RecordsInterval;
  inherited CalcLayoutGeneral;
end;

procedure TcxMultiRecordViewInfo.Clear;
begin
  inherited Clear;
  FVisibleValueCount := -1;
  FCommonWidth := 0
end;

function TcxMultiRecordViewInfo.GetBandSizeableRect(
  const ABandRect: TRect): TRect;
var
  ALeft: Integer;
begin
  if TcxVirtualVerticalGrid(VerticalGrid).LayoutStyle <> lsMultiRecordView then
    Result := inherited GetBandSizeableRect(ABandRect)
  else
    with ClientRect do
    begin
      ALeft := ABandRect.Left + ViewHeaderWidth + DividerWidth + ViewValueWidth + VertLineWidth;
      Result := cxRect(ALeft - 1, Top, ALeft + 2, Bottom);
    end;
end;

function TcxMultiRecordViewInfo.GetRowHeight(
  ARowViewInfo: TcxCustomRowViewInfo; ABandWidth: Integer): Integer;
var
  I, ACount: Integer;
begin
  Result := TcxCustomRowAccess(ARowViewInfo.Row).GetRealHeight;
  if GetRowAutoHeight(ARowViewInfo.Row) and (ARowViewInfo.Row.Height < 0) then
  begin
    ACount := VisibleValueCount;
    for I := 0 to ACount - 1 do
      Result := Max(TcxCustomRowViewInfoAccess(ARowViewInfo).GetValueHeight(
        FirstVisibleRecordIndex + I, ViewValueWidth, Self), Result);
  end;
end;

function TcxMultiRecordViewInfo.GetVisibleValueCount: Integer;
begin
  if FVisibleValueCount = -1 then
    FVisibleValueCount := CalcVisibleValueCount;
  Result := FVisibleValueCount;
end;

procedure TcxMultiRecordViewInfo.Reset;
begin
  inherited Reset;
  FVisibleValueCount := -1;
end;

procedure TcxMultiRecordViewInfo.SetDividerPos(APos: Integer);
begin
  if APos > ClipRect.Right - 4 then APos := ClipRect.Right - 4;
  VerticalGrid.OptionsView.RowHeaderWidth := APos;
end;

function TcxMultiRecordViewInfo.CalcVisibleValueCount: Integer;
begin
  Result := 0;
  if cxRectIsEmpty(ClientRect) then Exit;
  Result := Max(1, Min(GetDefaultGridModeBufferCount,
    RecordCount - Scroller.LeftVisibleRecord));
end;

function TcxMultiRecordViewInfo.GetRecordCount: Integer;
begin
  Result := TcxCustomVerticalGridAccess(VerticalGrid).RecordCount;
end;

end.

⌨️ 快捷键说明

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