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

📄 dxribbongrouplayoutcalculator.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{*******************************************************************}
{                                                                   }
{       Developer Express Visual Component Library                  }
{       ExpressBars components                                      }
{                                                                   }
{       Copyright (c) 1998-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }     
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE    }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE EXPRESSBARS AND ALL ACCOMPANYING VCL }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}

unit dxRibbonGroupLayoutCalculator;

{$I cxVer.inc}

interface

uses
{$IFDEF DELPHI6}
  Types,
{$ENDIF}
  Windows, Classes, dxBar, dxRibbon;

type
  { TdxRibbonGroupLayoutCalculator }

  TSequenceForWholeGroupHeightReducingItem = record
    ItemControlViewInfo: IdxBarItemControlViewInfo;
    OneRowHeightItemControlsBefore: Integer;
    OneRowHeightItemControlsAfter: Integer;
  end;
  TSequenceForWholeGroupHeightReducing = array of TSequenceForWholeGroupHeightReducingItem;
  TSequencesForWholeGroupHeightReducing = array of TSequenceForWholeGroupHeightReducing;

  TdxRibbonGroupLayoutCalculator = class(TInterfacedObject,
    IdxRibbonGroupLayoutCalculator)
  private
    FColumnCount: Integer;
    FGroupRowCount: Integer;
    FGroupRowHeight: Integer;
    FItemControlColumns: array of Integer;
    FItemControlIndexForOneRowHeightReducing: Integer;
    FItemControlSeparators: array of Integer;
    FLastSequenceForWholeGroupHeightReducing: Integer;
    FSequencesForWholeGroupHeightReducing: TSequencesForWholeGroupHeightReducing;
    X: Integer;
    procedure AlignOneRowHeightItemControl(
      AItemControlViewInfo: IdxBarItemControlViewInfo; AColumnWidth: Integer);
    procedure AlignOneRowHeightItemControls(
      AGroupViewInfo: IdxRibbonGroupViewInfo; AFirstIndex, AColumnWidth: Integer);
    procedure CheckDistanceBetweenTwoLastColumns(
      AGroupViewInfo: IdxRibbonGroupViewInfo; ALastItemControlIndex: Integer);
    procedure DistributeOneRowHeightItemControlsOnGroupHeight(
      AGroupViewInfo: IdxRibbonGroupViewInfo; AFirstIndex, ALastIndex: Integer);
    function GetGroupHeight: Integer;
    procedure IncrementColumnCount(AGroupViewInfo: IdxRibbonGroupViewInfo;
      ALastItemControlIndex: Integer);
    procedure OffsetContent(AGroupViewInfo: IdxRibbonGroupViewInfo;
      AFirstItemControlIndex, ALastItemControlIndex, AOffset: Integer);
    procedure PlaceOneRowHeightItemControls(
      AGroupViewInfo: IdxRibbonGroupViewInfo; AFirstIndex, ALastIndex: Integer;
      ADistributeOnGroupHeight: Boolean);
    procedure PlaceSeparator(AGroupViewInfo: IdxRibbonGroupViewInfo;
      AItemControlIndex: Integer);
    procedure PlaceWholeGroupHeightItemControl(
      AGroupViewInfo: IdxRibbonGroupViewInfo; AIndex: Integer);
    function ReduceOneRowHeightItemControlsWithText(
      AGroupViewInfo: IdxRibbonGroupViewInfo;
      AUpToViewLevel: TdxBarItemRealViewLevel): Boolean;
    function ReduceSequenceForWholeGroupHeightReducing(
      ASequenceIndex: Integer): Boolean;
    function ReduceWholeGroupHeightItemControls(
      AGroupViewInfo: IdxRibbonGroupViewInfo): Boolean;
  protected
    property GroupRowCount: Integer read FGroupRowCount;
    property GroupRowHeight: Integer read FGroupRowHeight;
  public
    constructor Create(AGroupRowHeight, AGroupRowCount: Integer);
    // IdxRibbonGroupLayoutCalculator
    procedure CalcInit(AGroupViewInfo: IdxRibbonGroupViewInfo);
    procedure CalcLayout(AGroupViewInfo: IdxRibbonGroupViewInfo);
    function CollapseMultiColumnItemControls(
      AGroupViewInfo: IdxRibbonGroupViewInfo): Boolean;
    function DecreaseMultiColumnItemControlsColumnCount(
      AGroupViewInfo: IdxRibbonGroupViewInfo): Boolean;
    function Reduce(AGroupViewInfo: IdxRibbonGroupViewInfo;
      AUpToViewLevel: TdxBarItemRealViewLevel): Boolean;
    procedure ReduceInit(AGroupViewInfo: IdxRibbonGroupViewInfo);
  end;

procedure CalcItemControlsRealPositionInButtonGroup(AItemControlViewInfos: TList);

implementation

uses
  SysUtils, cxClasses, cxGeometry, cxGraphics, Math;

const
  dxRibbonGroupMinContentWidth = 30;

  dxRibbonItemSeparatorTopOffset = 5;
  dxRibbonItemSeparatorBottomOffset = 6;
  dxRibbonItemSeparatorAreaWidth = 8;

procedure FindFirstElementOfSequenceForWholeGroupHeightReducing(
  AGroupViewInfo: IdxRibbonGroupViewInfo; var AFirstIndex: Integer;
  out AOneRowHeightItemControlCount: Integer); forward;
procedure FindSequenceForWholeGroupHeightReducing(
  AGroupViewInfo: IdxRibbonGroupViewInfo; var AFirstIndex: Integer;
  out ASequence: TSequenceForWholeGroupHeightReducing); forward;
function GetItemControlCurrentWidth(
  AItemControlViewInfo: IdxBarItemControlViewInfo): Integer; forward;
function IsNewColumnItemControl(
  AItemControlViewInfo: IdxBarItemControlViewInfo): Boolean; overload; forward;
function IsNewColumnItemControl(AGroupViewInfo: IdxRibbonGroupViewInfo;
  AItemControlIndex: Integer): Boolean; overload; forward;
function IsPartOfHorizontalBox(AGroupViewInfo: IdxRibbonGroupViewInfo;
  AItemControlIndex: Integer; ACanBeginHorizontalBox: Boolean): Boolean; forward;
function IsWholeGroupHeightItemControl(
  AItemControlViewInfo: IdxBarItemControlViewInfo): Boolean; overload; forward;
function IsWholeGroupHeightItemControl(AGroupViewInfo: IdxRibbonGroupViewInfo;
  AItemControlIndex: Integer): Boolean; overload; forward;
function IsWholeGroupHeightOnlyItemControl(
  AItemControlViewInfo: IdxBarItemControlViewInfo): Boolean; overload; forward;
function IsWholeGroupHeightOnlyItemControl(AGroupViewInfo: IdxRibbonGroupViewInfo;
  AItemControlIndex: Integer): Boolean; overload; forward;
function SkipHorizontalBox(AGroupViewInfo: IdxRibbonGroupViewInfo;
  var AFirstIndex: Integer; out AIsWholeGroupHeightBox: Boolean): Boolean; forward;

procedure CalcItemControlsRealPositionInButtonGroup(AItemControlViewInfos: TList);

  function GetItemControlViewInfo(AItemControlIndex: Integer): IdxBarItemControlViewInfo;
  begin
    Result := IdxBarItemControlViewInfo(AItemControlViewInfos[AItemControlIndex]);
  end;

  function GetItemControlPositionInButtonGroup(
    AItemControlViewInfo: IdxBarItemControlViewInfo): TdxBarButtonGroupPosition;
  begin
    Result := AItemControlViewInfo.GetPositionInButtonGroup;
    if IsWholeGroupHeightOnlyItemControl(AItemControlViewInfo) then
      Result := bgpNone;
  end;

  function NextItemControlIsMemberOfButtonGroup(AItemControlIndex: Integer): Boolean;
  var
    AItemControlViewInfo: IdxBarItemControlViewInfo;
  begin
    Result := AItemControlIndex + 1 < AItemControlViewInfos.Count;
    if Result then
    begin
      AItemControlViewInfo := GetItemControlViewInfo(AItemControlIndex + 1);
      Result := (GetItemControlPositionInButtonGroup(AItemControlViewInfo) = bgpMember) and
        not AItemControlViewInfo.HasSeparator;
    end;
  end;

  function GetItemControlRealPositionInButtonGroup(
    AItemControlIndex: Integer): TdxBarButtonGroupRealPosition;
  var
    AItemControlViewInfo: IdxBarItemControlViewInfo;
  begin
    case GetItemControlPositionInButtonGroup(GetItemControlViewInfo(AItemControlIndex)) of
      bgpStart:
        if NextItemControlIsMemberOfButtonGroup(AItemControlIndex) then
          Result := bgrpStart
        else
          Result := bgrpSingle;
      bgpMember:
        begin
          Result := bgrpNone;
          if not (GetItemControlViewInfo(AItemControlIndex).HasSeparator) and
            (AItemControlIndex > 0) then
          begin
            AItemControlViewInfo := GetItemControlViewInfo(AItemControlIndex - 1);
            if AItemControlViewInfo.GetRealPositionInButtonGroup in [bgrpStart, bgrpMember] then
            begin
              if NextItemControlIsMemberOfButtonGroup(AItemControlIndex) then
                Result := bgrpMember
              else
                Result := bgrpFinish;
            end;
          end;
        end;
    else
      Result := bgrpNone;
    end;
  end;

var
  I: Integer;
begin
  for I := 0 to AItemControlViewInfos.Count - 1 do
    GetItemControlViewInfo(I).SetRealPositionInButtonGroup(
      GetItemControlRealPositionInButtonGroup(I));
end;

procedure FindFirstElementOfSequenceForWholeGroupHeightReducing(
  AGroupViewInfo: IdxRibbonGroupViewInfo; var AFirstIndex: Integer;
  out AOneRowHeightItemControlCount: Integer);
var
  AIsWholeGroupHeightHorizontalBox: Boolean;
begin
  AOneRowHeightItemControlCount := 0;
  repeat
    if IsWholeGroupHeightOnlyItemControl(AGroupViewInfo, AFirstIndex) then
    begin
      Inc(AFirstIndex);
      Continue;
    end;
    if not SkipHorizontalBox(AGroupViewInfo, AFirstIndex, AIsWholeGroupHeightHorizontalBox) then
    begin
      if not IsWholeGroupHeightItemControl(AGroupViewInfo, AFirstIndex) then
      begin
        Inc(AOneRowHeightItemControlCount);
        Inc(AFirstIndex);
      end;
      Break;
    end;
    if not AIsWholeGroupHeightHorizontalBox then
    begin
      Inc(AOneRowHeightItemControlCount);
      Break;
    end;
  until AFirstIndex >= AGroupViewInfo.GetItemControlCount;
end;

procedure FindSequenceForWholeGroupHeightReducing(
  AGroupViewInfo: IdxRibbonGroupViewInfo; var AFirstIndex: Integer;
  out ASequence: TSequenceForWholeGroupHeightReducing);

var
  AIsHorizontalBox, AIsWholeGroupHeightHorizontalBox: Boolean;
  AOneRowHeightItemControlCount: Integer;
begin
  SetLength(ASequence, 0);
  if AFirstIndex >= AGroupViewInfo.GetItemControlCount then
    Exit;
  FindFirstElementOfSequenceForWholeGroupHeightReducing(AGroupViewInfo,
    AFirstIndex, AOneRowHeightItemControlCount);
  if AFirstIndex >= AGroupViewInfo.GetItemControlCount then
    Exit;
  if IsWholeGroupHeightItemControl(AGroupViewInfo, AFirstIndex) then
  begin
    SetLength(ASequence, Length(ASequence) + 1);
    with ASequence[Length(ASequence) - 1] do
    begin
      ItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AFirstIndex);
      OneRowHeightItemControlsBefore := AOneRowHeightItemControlCount;
      OneRowHeightItemControlsAfter := 0;
    end;
    AOneRowHeightItemControlCount := 0;
    Inc(AFirstIndex);
  end;
  while AFirstIndex < AGroupViewInfo.GetItemControlCount do
  begin
    if IsWholeGroupHeightOnlyItemControl(AGroupViewInfo, AFirstIndex) or
      IsNewColumnItemControl(AGroupViewInfo, AFirstIndex) then
        Break;
    AIsHorizontalBox := SkipHorizontalBox(AGroupViewInfo, AFirstIndex,
      AIsWholeGroupHeightHorizontalBox);
    if AIsHorizontalBox and AIsWholeGroupHeightHorizontalBox then
      Break;
    if AIsHorizontalBox or not IsWholeGroupHeightItemControl(AGroupViewInfo, AFirstIndex) then
    begin
      if not AIsHorizontalBox then
        Inc(AFirstIndex);
      Inc(AOneRowHeightItemControlCount);
      Continue;
    end
    else
    begin
      if Length(ASequence) > 0 then
        ASequence[Length(ASequence) - 1].OneRowHeightItemControlsAfter := AOneRowHeightItemControlCount;
      SetLength(ASequence, Length(ASequence) + 1);
      with ASequence[Length(ASequence) - 1] do
      begin
        ItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AFirstIndex);
        OneRowHeightItemControlsBefore := AOneRowHeightItemControlCount;
        OneRowHeightItemControlsAfter := 0;
      end;
      AOneRowHeightItemControlCount := 0;
      Inc(AFirstIndex);
    end;
  end;
  if (Length(ASequence) > 0) and (AOneRowHeightItemControlCount > 0) then
    ASequence[Length(ASequence) - 1].OneRowHeightItemControlsAfter := AOneRowHeightItemControlCount;
  if (Length(ASequence) = 0) and (AFirstIndex < AGroupViewInfo.GetItemControlCount) then
    FindSequenceForWholeGroupHeightReducing(AGroupViewInfo, AFirstIndex, ASequence);
end;

function GetItemControlCurrentWidth(
  AItemControlViewInfo: IdxBarItemControlViewInfo): Integer;
begin
  Result := AItemControlViewInfo.GetWidth(AItemControlViewInfo.GetViewLevel);
end;

function IsNewColumnItemControl(
  AItemControlViewInfo: IdxBarItemControlViewInfo): Boolean; overload;
begin
  Result := AItemControlViewInfo.HasSeparator or
    (AItemControlViewInfo.GetPosition = ipBeginsNewColumn) and
    (AItemControlViewInfo.GetRealPositionInButtonGroup in [bgrpNone, bgrpStart, bgrpSingle]);
end;

function IsNewColumnItemControl(AGroupViewInfo: IdxRibbonGroupViewInfo;
  AItemControlIndex: Integer): Boolean; overload;
begin
  Result := IsNewColumnItemControl(
    AGroupViewInfo.GetItemControlViewInfo(AItemControlIndex));
end;

function IsPartOfHorizontalBox(AGroupViewInfo: IdxRibbonGroupViewInfo;
  AItemControlIndex: Integer; ACanBeginHorizontalBox: Boolean): Boolean;
var
  AItemControlViewInfo: IdxBarItemControlViewInfo;
  ARealPositionInButtonGroup: TdxBarButtonGroupRealPosition;
begin
  ARealPositionInButtonGroup := AGroupViewInfo.GetItemControlViewInfo(AItemControlIndex).GetRealPositionInButtonGroup;
  if (ARealPositionInButtonGroup in [bgrpMember, bgrpFinish]) or
    ACanBeginHorizontalBox and (ARealPositionInButtonGroup = bgrpStart) then
  begin
    Result := True;
    Exit;
  end;
  Result := False;
  if ACanBeginHorizontalBox and (AItemControlIndex + 1 < AGroupViewInfo.GetItemControlCount) then
  begin
    AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AItemControlIndex + 1);
    Result := not IsNewColumnItemControl(AItemControlViewInfo) and
      (AItemControlViewInfo.GetPosition = ipContinuesRow);
  end;
  if not Result then
  begin
    AItemControlViewInfo := AGroupViewInfo.GetItemControlViewInfo(AItemControlIndex);
    Result := (AItemControlViewInfo.GetPosition = ipContinuesRow) and

⌨️ 快捷键说明

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