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

📄 dxribbongrouplayoutcalculator.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  end;

var
  AFirstColumnFirstItemControlIndex, AFirstColumnLastItemControlIndex: Integer;
  ASecondColumnFirstItemControlIndex, ASecondColumnLastItemControlIndex: Integer;
  AFirstColumnMaxItemControlRightBound, AFirstColumnMaxButtonGroupRightBound: Integer;
  ASecondColumnMinItemControlLeftBound, ASecondColumnMinButtonGroupLeftBound: Integer;
  AButtonGroupOffset, AOffset, AOffset1, AOffset2: Integer;
begin
  if FColumnCount < 1 then
    Exit;
  ASecondColumnLastItemControlIndex := ALastItemControlIndex;
  ASecondColumnFirstItemControlIndex := GetColumnFirstItemControlIndex(
    ASecondColumnLastItemControlIndex);
  if AGroupViewInfo.GetItemControlViewInfo(ASecondColumnFirstItemControlIndex).HasSeparator then
    Exit;
  AFirstColumnLastItemControlIndex := ASecondColumnFirstItemControlIndex - 1;
  AFirstColumnFirstItemControlIndex := GetColumnFirstItemControlIndex(
    AFirstColumnLastItemControlIndex);
  GetMaxBoundInfoForItemControls(AFirstColumnFirstItemControlIndex, AFirstColumnLastItemControlIndex,
    AFirstColumnMaxItemControlRightBound, AFirstColumnMaxButtonGroupRightBound);
  GetMinBoundInfoForItemControls(ASecondColumnFirstItemControlIndex, ASecondColumnLastItemControlIndex,
    ASecondColumnMinItemControlLeftBound, ASecondColumnMinButtonGroupLeftBound);

  AButtonGroupOffset := AGroupViewInfo.GetOffsetsInfo.ButtonGroupOffset;
  AOffset1 := 0;
  if (AFirstColumnMaxButtonGroupRightBound <> -1) and
    (ASecondColumnMinItemControlLeftBound - AFirstColumnMaxButtonGroupRightBound < AButtonGroupOffset) then
      AOffset1 := AButtonGroupOffset - (ASecondColumnMinItemControlLeftBound - AFirstColumnMaxButtonGroupRightBound);
  AOffset2 := 0;
  if (ASecondColumnMinButtonGroupLeftBound <> MaxInt) and
    (ASecondColumnMinButtonGroupLeftBound - AFirstColumnMaxItemControlRightBound < AButtonGroupOffset) then
      AOffset2 := AButtonGroupOffset - (ASecondColumnMinButtonGroupLeftBound - AFirstColumnMaxItemControlRightBound);
  AOffset := Max(AOffset1, AOffset2);
  if AOffset <> 0 then
  begin
    OffsetContent(AGroupViewInfo, ASecondColumnFirstItemControlIndex, ASecondColumnLastItemControlIndex, AOffset);
    Inc(X, AOffset);
  end;
end;

procedure TdxRibbonGroupLayoutCalculator.DistributeOneRowHeightItemControlsOnGroupHeight(
  AGroupViewInfo: IdxRibbonGroupViewInfo; AFirstIndex, ALastIndex: Integer);
var
  AColumn, AIndex, ARowCount, I: Integer;
  AItemControlViewInfo: IdxBarItemControlViewInfo;
  R: TRect;
begin
  AColumn := FItemControlColumns[AFirstIndex];
  AIndex := AFirstIndex + 1;
  while (AIndex <= ALastIndex) and (FItemControlColumns[AIndex] = AColumn) do
    Inc(AIndex);
  Dec(AIndex);
  ARowCount := AGroupViewInfo.GetItemControlViewInfo(AIndex).GetRow + 1;
  if ARowCount < GroupRowCount then
    for I := AFirstIndex to AIndex do
    begin
      AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(I);
      R := AItemControlViewInfo.GetBounds;
      R.Top := GetGroupHeight - ((GetGroupHeight - GroupRowHeight * ARowCount) div (ARowCount + 1) + GroupRowHeight) * (ARowCount - AGroupViewInfo.GetItemControlViewInfo(I).GetRow);
      R.Bottom := R.Top + GroupRowHeight;
      AItemControlViewInfo.SetBounds(R);
    end;
  for I := AFirstIndex to AIndex do
    AGroupViewInfo.GetItemControlViewInfo(I).SetColumnRowCount(ARowCount);
  Inc(AIndex);
  if AIndex <= ALastIndex then
    DistributeOneRowHeightItemControlsOnGroupHeight(AGroupViewInfo, AIndex, ALastIndex);
end;

function TdxRibbonGroupLayoutCalculator.GetGroupHeight: Integer;
begin
  Result := GroupRowHeight * GroupRowCount;
end;

procedure TdxRibbonGroupLayoutCalculator.IncrementColumnCount(
  AGroupViewInfo: IdxRibbonGroupViewInfo; ALastItemControlIndex: Integer);
begin
  CheckDistanceBetweenTwoLastColumns(AGroupViewInfo, ALastItemControlIndex);
  Inc(FColumnCount);
end;

procedure TdxRibbonGroupLayoutCalculator.OffsetContent(
  AGroupViewInfo: IdxRibbonGroupViewInfo;
  AFirstItemControlIndex, ALastItemControlIndex, AOffset: Integer);
var
  AItemControlViewInfo: IdxBarItemControlViewInfo;
  ASeparatorInfo: TdxBarItemSeparatorInfo;
  I: Integer;
  R: TRect;
begin
  for I := AFirstItemControlIndex to ALastItemControlIndex do
  begin
    AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(I);
    R := AItemControlViewInfo.GetBounds;
    OffsetRect(R, AOffset, 0);
    AItemControlViewInfo.SetBounds(R);
    if FItemControlSeparators[I] <> -1 then
    begin
      ASeparatorInfo := AGroupViewInfo.GetSeparatorInfo(FItemControlSeparators[I]);
      OffsetRect(ASeparatorInfo.Bounds, AOffset, 0);
      AGroupViewInfo.SetSeparatorInfo(FItemControlSeparators[I], ASeparatorInfo);
    end;
  end;
end;

procedure TdxRibbonGroupLayoutCalculator.PlaceOneRowHeightItemControls(
  AGroupViewInfo: IdxRibbonGroupViewInfo; AFirstIndex, ALastIndex: Integer;
  ADistributeOnGroupHeight: Boolean);
var
  AItemControlViewInfo: IdxBarItemControlViewInfo;
  AColumnFirstItemControlIntex, AItemControlWidth, AMaxRowX, ARow, ARowX, I: Integer;
begin
  if AGroupViewInfo.GetItemControlViewInfo(AFirstIndex).HasSeparator then
    PlaceSeparator(AGroupViewInfo, AFirstIndex);
  ARow := 0;
  AMaxRowX := X;
  ARowX := X;
  AColumnFirstItemControlIntex := AFirstIndex;
  for I := AFirstIndex to ALastIndex do
  begin
    AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(I);
    if I > AFirstIndex then
      if (AItemControlViewInfo.GetPosition = ipBeginsNewRow) and
        (AItemControlViewInfo.GetRealPositionInButtonGroup in [bgrpNone, bgrpStart, bgrpSingle]) then
      begin
        Inc(ARow);
        if ARow < GroupRowCount then
          ARowX := X
        else
        begin
          AlignOneRowHeightItemControls(AGroupViewInfo, AColumnFirstItemControlIntex, AMaxRowX - X);
          AColumnFirstItemControlIntex := I;
          ARow := 0;
          X := AMaxRowX;
          IncrementColumnCount(AGroupViewInfo, I - 1);
          ARowX := X;
          AMaxRowX := X;
        end;
      end;
    AItemControlWidth := GetItemControlCurrentWidth(AItemControlViewInfo);
    FItemControlColumns[I] := FColumnCount;
    AItemControlViewInfo.SetRow(ARow);
    if not (AItemControlViewInfo.GetRealPositionInButtonGroup in [bgrpMember, bgrpFinish]) and
      (I > AFirstIndex)  and (FItemControlColumns[I - 1] = FItemControlColumns[I]) and (AGroupViewInfo.GetItemControlViewInfo(I - 1).GetRow = ARow) then
    begin
      if (AItemControlViewInfo.GetRealPositionInButtonGroup in [bgrpStart, bgrpSingle]) or
        (AItemControlViewInfo.GetRealPositionInButtonGroup = bgrpNone) and (AGroupViewInfo.GetItemControlViewInfo(I - 1).GetRealPositionInButtonGroup in [bgrpFinish, bgrpSingle]) then
          Inc(ARowX, AGroupViewInfo.GetOffsetsInfo.ButtonGroupOffset);
    end;
    AItemControlViewInfo.SetBounds(Rect(ARowX, ARow * GroupRowHeight, ARowX + AItemControlWidth, (ARow + 1) * GroupRowHeight));
    Inc(ARowX, AItemControlWidth);
    if ARowX > AMaxRowX then
      AMaxRowX := ARowX;
  end;
  AlignOneRowHeightItemControls(AGroupViewInfo, AColumnFirstItemControlIntex, AMaxRowX - X);
  X := AMaxRowX;
  if ADistributeOnGroupHeight then
    DistributeOneRowHeightItemControlsOnGroupHeight(AGroupViewInfo, AFirstIndex, ALastIndex);
end;

procedure TdxRibbonGroupLayoutCalculator.PlaceSeparator(
  AGroupViewInfo: IdxRibbonGroupViewInfo; AItemControlIndex: Integer);
var
  ASeparatorInfo: TdxBarItemSeparatorInfo;
begin
  ASeparatorInfo.Bounds := Rect(X, dxRibbonItemSeparatorTopOffset,
    X + dxRibbonItemSeparatorAreaWidth,
    GetGroupHeight - dxRibbonItemSeparatorBottomOffset);
  ASeparatorInfo.Kind := skVertical;
  AGroupViewInfo.AddSeparator(ASeparatorInfo);
  Inc(X, dxRibbonItemSeparatorAreaWidth);
  FItemControlSeparators[AItemControlIndex] := AGroupViewInfo.GetSeparatorCount - 1;
end;

procedure TdxRibbonGroupLayoutCalculator.PlaceWholeGroupHeightItemControl(
  AGroupViewInfo: IdxRibbonGroupViewInfo; AIndex: Integer);
var
  AItemControlViewInfo: IdxBarItemControlViewInfo;
  AItemControlWidth: Integer;
begin
  AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AIndex);
  if AItemControlViewInfo.HasSeparator then
    PlaceSeparator(AGroupViewInfo, AIndex);
  AItemControlWidth := GetItemControlCurrentWidth(AItemControlViewInfo);
  AItemControlViewInfo.SetBounds(Rect(X, 0, X + AItemControlWidth, GetGroupHeight));
  FItemControlColumns[AIndex] := FColumnCount;
  AItemControlViewInfo.SetRow(0); // ???
  Inc(X, AItemControlWidth);
end;

function TdxRibbonGroupLayoutCalculator.ReduceOneRowHeightItemControlsWithText(
  AGroupViewInfo: IdxRibbonGroupViewInfo; AUpToViewLevel: TdxBarItemRealViewLevel): Boolean;

  function CanReduce(AItemControlIndex: Integer): Boolean;
  var
    AItemControlViewInfo: IdxBarItemControlViewInfo;
  begin
    AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AItemControlIndex);
    Result := (AItemControlViewInfo.GetViewLevel < AUpToViewLevel) and
      (AUpToViewLevel in AItemControlViewInfo.GetAllowedViewLevels);
  end;

var
  AColumn, AIndex, ARow, I: Integer;
  AColumnWidthAfterReducing, AColumnWidthBeforeReducing, ARowWidthAfterReducing, ARowWidthBeforeReducing: Integer;
  AItemControlsToBeReduced: TInterfaceList;
  AItemControlViewInfo: IdxBarItemControlViewInfo;
begin
  Result := False;
  AIndex := FItemControlIndexForOneRowHeightReducing;
  while (AIndex >= 0) and IsWholeGroupHeightItemControl(AGroupViewInfo, AIndex) do
    Dec(AIndex);
  FItemControlIndexForOneRowHeightReducing := AIndex;
  if AIndex = -1 then
    Exit;
  AColumn := FItemControlColumns[AIndex];
  AColumnWidthBeforeReducing := 0;
  AColumnWidthAfterReducing := 0;
  AItemControlsToBeReduced := TInterfaceList.Create;
  try
    while (AIndex >= 0) and (FItemControlColumns[AIndex] = AColumn) do
    begin
      if IsPartOfHorizontalBox(AGroupViewInfo, AIndex, True) then
      begin
        AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AIndex);
        ARowWidthBeforeReducing := GetItemControlCurrentWidth(AItemControlViewInfo);
        ARow := AItemControlViewInfo.GetRow;
        Dec(AIndex);
        while (AIndex >= 0) and (FItemControlColumns[AIndex] = AColumn) and
          (AGroupViewInfo.GetItemControlViewInfo(AIndex).GetRow = ARow) do
        begin
          AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AIndex);
          Inc(ARowWidthBeforeReducing, GetItemControlCurrentWidth(AItemControlViewInfo));
          Dec(AIndex);
        end;
        ARowWidthAfterReducing := ARowWidthBeforeReducing;
      end
      else
      begin
        AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AIndex);
        ARowWidthBeforeReducing := GetItemControlCurrentWidth(AItemControlViewInfo);
        if CanReduce(AIndex) then
        begin
          ARowWidthAfterReducing := AItemControlViewInfo.GetWidth(AUpToViewLevel);
          AItemControlsToBeReduced.Add(AItemControlViewInfo);
        end
        else
          ARowWidthAfterReducing := ARowWidthBeforeReducing;
        Dec(AIndex);
      end;
      if ARowWidthBeforeReducing > AColumnWidthBeforeReducing then
        AColumnWidthBeforeReducing := ARowWidthBeforeReducing;
      if ARowWidthAfterReducing > AColumnWidthAfterReducing then
        AColumnWidthAfterReducing := ARowWidthAfterReducing;
    end;
    for I := 0 to AItemControlsToBeReduced.Count - 1 do
    begin
      AItemControlViewInfo := IdxBarItemControlViewInfo(AItemControlsToBeReduced[I]);
      if (AItemControlViewInfo.GetWidth(AUpToViewLevel) < AColumnWidthBeforeReducing) and
        (GetItemControlCurrentWidth(AItemControlViewInfo) > AColumnWidthAfterReducing) then
      begin
        AItemControlViewInfo.SetViewLevel(AUpToViewLevel);
        Result := True;
      end;
    end;
    FItemControlIndexForOneRowHeightReducing := AIndex;
    if not Result then
      Result := ReduceOneRowHeightItemControlsWithText(AGroupViewInfo, AUpToViewLevel)
    else
      CalcLayout(AGroupViewInfo);
  finally
    AItemControlsToBeReduced.Free;
  end;
end;

function TdxRibbonGroupLayoutCalculator.ReduceSequenceForWholeGroupHeightReducing(
  ASequenceIndex: Integer): Boolean;

  function GetFreeCellCount(AOneRowHeightItemControlCount: Integer): Integer;
  begin
    Result := (GroupRowCount - AOneRowHeightItemControlCount mod GroupRowCount) mod GroupRowCount;
  end;

  function IsItemGoodForReducing(const AItem: TSequenceForWholeGroupHeightReducingItem): Boolean;
  var
    AFreeCellCountAfterReducing, AFreeCellCountBeforeReducing: Integer;
  begin
    AFreeCellCountBeforeReducing := GetFreeCellCount(AItem.OneRowHeightItemControlsBefore) +
      GetFreeCellCount(AItem.OneRowHeightItemControlsAfter);
    AFreeCellCountAfterReducing := GetFreeCellCount(AItem.OneRowHeightItemControlsBefore + 1 + AItem.OneRowHeightItemControlsAfter);
    Result := AFreeCellCountAfterReducing <= AFreeCellCountBeforeReducing;
  end;

var
  AItemControlViewInfo: IdxBarItemControlViewInfo;
  APrevOneRowHeightItemControlsAfter: Integer;
  ASequence: TSequenceForWholeGroupHeightReducing;
begin
  Result := False;
  ASequence := FSequencesForWholeGroupHeightReducing[ASequenceIndex];
  if Length(ASequence) = 0 then
    Exit;
  if Length(ASequence) = 1 then
  begin
    if IsItemGoodForReducing(ASequence[0]) then
    begin
      AItemControlViewInfo := ASequence[0].ItemControlViewInfo;
      AItemControlViewInfo.SetViewLevel(GetNextViewLevel(AItemControlViewInfo.GetAllowedViewLevels, ivlLargeIconWithText));
      SetLength(FSequencesForWholeGroupHeightReducing[ASequenceIndex], 0);
      Result := True;
    end;
  end
  else
  begin
    AItemControlViewInfo := ASequence[Length(ASequence) - 1].ItemControlViewInfo;
    AItemControlViewInfo.SetViewLevel(GetNextViewLevel(AItemControlViewInfo.GetAllowedViewLevels, ivlLargeIconWithText));
    APrevOneRowHeightItemControlsAfter := ASequence[Length(ASequence) - 2].OneRowHeightItemControlsAfter;
    Inc(ASequence[Length(ASequence) - 2].OneRowHeightItemControlsAfter, ASequence[Length(ASequence) - 1].OneRowHeightItemControlsAfter + 1);
    SetLength(FSequencesForWholeGroupHeightReducing[ASequenceIndex], Length(ASequence) - 1);
    Result := True;
    repeat
      ASequence := FSequencesForWholeGroupHeightReducing[ASequenceIndex];
      if APrevOneRowHeightItemControlsAfter <> 0 then
        Break;
      if not IsItemGoodForReducing(ASequence[Length(ASequence) - 1]) then
        Break;
      AItemControlViewInfo := ASequence[Length(ASequence) - 1].ItemControlViewInfo;
      AItemControlViewInfo.SetViewLevel(GetNextViewLevel(AItemControlViewInfo.GetAllowedViewLevels, ivlLargeIconWithText));
      if Length(ASequence) > 1 then
      begin
        APrevOneRowHeightItemControlsAfter := ASequence[Length(ASequence) - 2].OneRowHeightItemControlsAfter;
        Inc(ASequence[Length(ASequence) - 2].OneRowHeightItemControlsAfter, ASequence[Length(ASequence) - 1].OneRowHeightItemControlsAfter + 1);
      end;
      SetLength(FSequencesForWholeGroupHeightReducing[ASequenceIndex], Length(ASequence) - 1);
    until Length(FSequencesForWholeGroupHeightReducing[ASequenceIndex]) = 0;
  end;
end;

function TdxRibbonGroupLayoutCalculator.ReduceWholeGroupHeightItemControls(
  AGroupViewInfo: IdxRibbonGroupViewInfo): Boolean;
begin
  Result := False;
  while not Result and (FLastSequenceForWholeGroupHeightReducing >= 0) do
  begin
    Result := ReduceSequenceForWholeGroupHeightReducing(FLastSequenceForWholeGroupHeightReducing);
    if not Result then
    begin
      SetLength(FSequencesForWholeGroupHeightReducing, FLastSequenceForWholeGroupHeightReducing);
      Dec(FLastSequenceForWholeGroupHeightReducing);
    end
    else
      CalcLayout(AGroupViewInfo);
  end;
end;

end.

⌨️ 快捷键说明

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