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

📄 aqdockingui.pas.~1~

📁 AutomatedDocking Library 控件源代码修改 适合Delphi 2009 和C++ Builder 20009 使用。 修正汉字不能正确显示问题
💻 ~1~
📖 第 1 页 / 共 5 页
字号:
{*******************************************************************}
{                                                                   }
{       AutomatedDocking Library (Cross-Platform Edition)           }
{                                                                   }
{       Copyright (c) 1999-2008 AutomatedQA Corp.                   }
{       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 AUTOMATEDQA CORP. THE REGISTERED DEVELOPER IS        }
{   LICENSED TO DISTRIBUTE THE AUTOMATEDDOCKING LIBRARY AND ALL     }
{   ACCOMPANYING VCL AND CLX 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 WRITTEN CONSENT          }
{   AND PERMISSION FROM AUTOMATEDQA CORP.                           }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}

unit aqDockingUI;

{$I aqDockingVer.inc}

interface

uses
{$IFDEF VCL}
  Graphics, ImgList, Controls,
{$ELSE}
  QGraphics, QImgList, QControls,
{$ENDIF}
  Classes, Types, Contnrs, aqUIHelpers, aqDockingUtils;

type
  TaqTabItemState = (tisNormal, tisHot, tisSelected, tisDisabled, tisFocused);
  TaqTabItemPosition = (tipFirst, tipMiddle, tipLast);
  TaqTabOrientation = (dtoTop, dtoBottom);
  TaqTabButtonKind = (tbkLeft, tbkRight, tbkClose, tbkPopup, tbkPopupEx);
  TaqHideZoneOrientation = (hzoLeft, hzoTop, hzoRight, hzoBottom, hzoDefault);
  TaqDockButtonState = (dbsNormal, dbsHot, dbsPressed, dbsDisabled);
  TaqTabButtonState = TaqDockButtonState;
  TaqDockButtonKind = (dbkHide, dbkUndock, dbkAutoHide, dbkUndoAutoHide, dbkMaximize,
    dbkRestore, dbkMenu, dbkCustom, dbkHelp, dbkNone);
  TaqDockButtonKinds = set of TaqDockButtonKind;
  TaqDockCaptionState = (dcsNormal, dcsHot, dcsSelected, dcsDisabled, dcsFocused);
  TaqDockControlDrawKind = (dckRegularControl, dckTabControl);
  TaqSplitterOrientation = (spoVertical, spoHorizontal);
  TaqCustomCaptionButtonPosition = (bcpBefore, bcpAfter);
  TaqCaptionButtonPostions = set of TaqCustomCaptionButtonPosition;
  TaqCustomCaptionButtonStyle = (cbsButton, cbsIcon);

  TaqDockingUIMetric = (
    // common
    dumTextSpacingX, dumTextSpacingY,
    // caption
    dumCaptionBorderX, dumCaptionBorderY,
    // tab
    dumTabPadding, dumTabTopOffset,
    dumTabItemBorderX, dumTabItemBorderY,
    dumTabPaneBorderX, dumTabPaneBorderY,
    dumTabDefaultButtonSize
    );

  TaqFrameSize = 1..10;
  TaqStyleName = string;

  // Forward declarations.
  TaqDockingUIStyle = class;
  TaqDockingUIStyleClass = class of TaqDockingUIStyle;
  TaqStyleManager = class;
  TaqStyles = class;

  TaqStyleChangeLink = class(TaqChangeLink)
  private
    function GetSender: TaqDockingUIStyle;
    procedure SetSender(const Value: TaqDockingUIStyle);
  public
    destructor Destroy; override;

    property Sender: TaqDockingUIStyle read GetSender write SetSender;
  end;

  TaqStyleNotifyEvent = procedure (Style: TaqDockingUIStyle) of object;

  TaqStylesChangeLink = class(TaqChangeLink)
  private
    FOnChange: TaqStyleNotifyEvent;
    FOnUnRegister: TaqStyleNotifyEvent;
    FOnRegister: TaqStyleNotifyEvent;
  public
    destructor Destroy; override;

    procedure Change(AStyle: TaqDockingUIStyle); reintroduce;
    procedure Register(AStyle: TaqDockingUIStyle);
    procedure UnRegister(AStyle: TaqDockingUIStyle);

    property OnRegister: TaqStyleNotifyEvent read FOnRegister write FOnRegister;
    property OnUnRegister: TaqStyleNotifyEvent read FOnUnRegister write FOnUnRegister;
    property OnChange: TaqStyleNotifyEvent read FOnChange write FOnChange;
  end;

  TaqMetrics = array [TaqDockingUIMetric] of Integer;

  TaqStyleGetCaptionHeightEvent = procedure (Sender: TaqDockingUIStyle;
    State: TaqDockCaptionState; DrawImage: Boolean; Images: TCustomImageList;
    ImageIndex: Integer; var Height: Integer) of object;
  TaqStyleGetTabPaneHeightEvent = procedure (Sender: TaqDockingUIStyle;
    Orientation: TaqTabOrientation; DrawImage: Boolean; Images: TCustomImageList;
    var Height: Integer) of object;
  TaqStyleGetTabHeightEvent = procedure (Sender: TaqDockingUIStyle;
    State: TaqTabItemState; Orientation: TaqTabOrientation;
    DrawImage: Boolean; Images: TCustomImageList; ImageIndex: Integer; var Height: Integer) of object;
  TaqStyleGetTabWidthEvent = procedure (Sender: TaqDockingUIStyle;
    const Text: string; State: TaqTabItemState; Position: TaqTabItemPosition;
    Orientation: TaqTabOrientation; AButtonAreaWidth: Integer; DrawImage: Boolean;
    Images: TCustomImageList; ImageIndex: Integer; var Width: Integer) of object;
  TaqStyleGetTabButtonsBoundsEvent = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect; ButtonSize: TPoint) of object;
  TaqStyleDrawTabButtonEvent = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect; State: TaqTabButtonState;
    Kind: TaqTabButtonKind) of object;
  TaqStyleDrawTabPaneEvent = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect; Orientation: TaqTabOrientation) of object;
  TaqStyleDrawTabItemEvent = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect; const Text: string; State: TaqTabItemState;
    Position: TaqTabItemPosition; Orientation: TaqOrientation;
    AButtonAreaWidth: Integer; DrawImage: Boolean; Images: TCustomImageList; ImageIndex: Integer) of object;
  TaqStyleDrawTabTargetEvent = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect) of object;
  TaqStyleDrawCaptionButtonEvent = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect; State: TaqDockButtonState; CaptionState: TaqDockCaptionState;
    Kind: TaqDockButtonKind) of object;
  TaqStyleDrawCaptionEvent = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect; const Text: string; State: TaqDockCaptionState;
    MaxTextWidth: Integer; var FitText: Boolean; DrawImage: Boolean;
    ImageList: TCustomImageList; ImageIndex: Integer) of object;
  TaqStyleDrawControl = procedure (Sender: TaqDockingUIStyle;
    Canvas: TCanvas; Rect: TRect; Kind: TaqDockControlDrawKind) of object;
  TaqStyleDrawSplitterEvent = procedure (Canvas: TCanvas; Rect: TRect;
    Orientation: TaqSplitterOrientation) of object;

  TaqDockingUIStyle = class(TComponent)
  private
    FStyleManager: TaqStyleManager;
    FPredefined: Boolean;
    FLinks: TList;
    FUpdateCount: Integer;
    FCaptionFont: TFont;
    FTabFont: TFont;
    FCaption: string;
    FActiveCaptionFont: TFont;
    FActiveTabFont: TFont;
    FCaptionButtonSize: Integer;
    FCaptionButtonWidthRatio: Real;
    FSplitterHeight: Integer;
    FSplitterWidth: Integer;
    FTabIndent: Integer;
    FUniformTabWidth: Boolean;
    FShowAccelChar: TaqShowAccelChar;
    FHiddenTabFont: TFont;
    FActiveHiddenTabFont: TFont;
    FOnChange: TNotifyEvent;
    FOnGetTabWidth: TaqStyleGetTabWidthEvent;
    FOnDrawCaptionButton: TaqStyleDrawCaptionButtonEvent;
    FOnDrawCaption: TaqStyleDrawCaptionEvent;
    FOnDrawSplitter: TaqStyleDrawSplitterEvent;
    FOnDrawTabButton: TaqStyleDrawTabButtonEvent;
    FOnDrawTabItem: TaqStyleDrawTabItemEvent;
    FOnDrawTabPane: TaqStyleDrawTabPaneEvent;
    FOnDrawTabTarget: TaqStyleDrawTabTargetEvent;
    FOnDrawControl: TaqStyleDrawControl;
    FOnGetCaptionHeight: TaqStyleGetCaptionHeightEvent;
    FOnGetTabHeight: TaqStyleGetTabHeightEvent;
    FOnGetTabPaneHeight: TaqStyleGetTabPaneHeightEvent;
    FOnGetTabButtonsBounds: TaqStyleGetTabButtonsBoundsEvent;

    function GetIndex: Integer;
    procedure SetCaption(const Value: string);
    procedure ReadCaption(Reader: TReader);
    procedure WriteCaption(Writer: TWriter);
    procedure ReadPredefined(Reader: TReader);
    procedure WritePredefined(Writer: TWriter);
    function GetCaption: string;
    procedure UpdateCaption(const Value: string);
    procedure SetCaptionFont(const Value: TFont);
    procedure SetTabFont(const Value: TFont);
    procedure SetActiveCaptionFont(const Value: TFont);
    procedure SetActiveTabFont(const Value: TFont);
    procedure FontChange(Sender: TObject);
    procedure SetCaptionButtonSize(const Value: Integer);
    procedure SetCaptionButtonWidthRatio(const Value: Real);
    procedure SetSplitterHeight(const Value: Integer);
    procedure SetSplitterWidth(const Value: Integer);
    procedure SetTabIndent(const Value: Integer);
    procedure SetUniformTabWidth(const Value: Boolean);
    procedure SetMetric(AMetric: TaqDockingUIMetric; const Value: Integer);
    procedure SetShowAccelChar(const Value: TaqShowAccelChar);
    procedure SetStyleManager(const Value: TaqStyleManager);
    procedure SetActiveHiddenTabFont(const Value: TFont);
    procedure SetHiddenTabFont(const Value: TFont);
  protected
    FMetrics: TaqMetrics;
    FHotTrack: Boolean;
    FLastTabState: TaqTabItemState;
    FLastTabOrient: TaqOrientation;
    FLastTabTextRect: TRect;

    procedure AssignTo(Dest: TPersistent); override;
    procedure DefineProperties(Filer: TFiler); override;
    procedure ReadState(Reader: TReader); override;

    procedure CheckMetric(AMetric: TaqDockingUIMetric; Value: Integer); virtual;
    function GetMetric(AMetric: TaqDockingUIMetric): Integer; virtual;
    procedure Change; virtual;

    function GetCaptionButtonsPosition: TaqCaptionButtonPostions; virtual;

     // Low-level drawing routines
    procedure DoDrawCaptionContent(ACanvas: TCanvas; ARect: TRect; const AText: string;
      AState: TaqDockCaptionState; AMaxTextWidth: Integer; var AFitText: Boolean; ADrawImage: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer); virtual;
    procedure DoDrawCaptionButtonWidget(ACanvas: TCanvas; ARect: TRect;
      AState: TaqDockButtonState; ACaptionState: TaqDockCaptionState;
      AKind: TaqDockButtonKind); virtual; abstract;

    procedure DoDrawTabItemContent(ACanvas: TCanvas; ARect: TRect;
      const AText: string; AState: TaqTabItemState;
      AOrientation: TaqOrientation; ADrawImage, ADrawText: Boolean;
      AFont, AActiveFont: TFont; AImages: TCustomImageList; AImageIndex: Integer; APadding: Boolean); virtual;
    procedure DoDrawTabPaneContent(ACanvas: TCanvas; ARect: TRect;
      AOrientation: TaqOrientation); virtual; abstract;
    procedure DoDrawTabButtonWidget(ACanvas: TCanvas; ARect: TRect;
      AState: TaqTabButtonState; AKind: TaqTabButtonKind); virtual; abstract;

     // High-level drawing routines
    function DoGetCaptionHeight(AState: TaqDockCaptionState; ADrawImage: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer): Integer; virtual;
    function DoGetTabPaneHeight(AOrientation: TaqTabOrientation; ADrawImage: Boolean;
      AImages: TCustomImageList): Integer; virtual;
    function DoGetTabHeight(AState: TaqTabItemState; AOrientation: TaqTabOrientation;
      ADrawImage: Boolean;  AImages: TCustomImageList; AImageIndex: Integer): Integer; virtual;
    function DoGetTabWidth(const AText: string; AState: TaqTabItemState;
      APosition: TaqTabItemPosition; AOrientation: TaqTabOrientation; AButtonAreaWidth: Integer;
      ADrawImage: Boolean; AImages: TCustomImageList; AImageIndex: Integer): Integer; virtual;
    function DoGetTabButtonsBounds(ACanvas: TCanvas; ARect: TRect; ButtonSize: TPoint): TRect; virtual;
    procedure DoDrawTabButton(ACanvas: TCanvas; ARect: TRect;
      AState: TaqTabButtonState; AKind: TaqTabButtonKind); virtual; abstract;
    procedure DoDrawTabPane(ACanvas: TCanvas; ARect: TRect;
      AOrientation: TaqTabOrientation); virtual; abstract;
    procedure DoDrawTabItem(ACanvas: TCanvas; ARect: TRect;
      const AText: string; AState: TaqTabItemState; APosistion: TaqTabItemPosition;
      AOrientation: TaqOrientation; AButtonAreaWidthBefore: Integer; AButtonAreaWidthAfter: Integer;
      ADrawImage: Boolean; AImages: TCustomImageList; AImageIndex: Integer); virtual; abstract;
    procedure DoDrawTabTarget(ACanvas: TCanvas; ARect: TRect); virtual; abstract;

    procedure DoDrawCaptionButton(ACanvas: TCanvas; ARect: TRect;
      AState: TaqDockButtonState; ACaptionState: TaqDockCaptionState; AKind: TaqDockButtonKind); virtual; abstract;
    procedure DoDrawCaption(ACanvas: TCanvas; ARect: TRect; const AText: string;
      AState: TaqDockCaptionState; AMaxTextWidth: Integer; var AFitCaption: Boolean; ADrawImage: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer); virtual; abstract;

    procedure DoDrawSplitter(ACanvas: TCanvas; ARect: TRect;
      AOrientation: TaqSplitterOrientation); virtual; abstract;
    procedure DoDrawControl(ACanvas: TCanvas; ARect: TRect;
      AKind: TaqDockControlDrawKind); virtual; abstract;

    function DoGetHideZoneHeight(AOrientation: TaqHideZoneOrientation; ADrawImage, ADrawText: Boolean;
      AImages: TCustomImageList): Integer; virtual;
    function DoGetHiddenTabHeight(AState: TaqTabItemState; AOrientation: TaqHideZoneOrientation;
      ADrawImage, ADrawText: Boolean; AImages: TCustomImageList; AImageIndex: Integer): Integer; virtual;
    function DoGetHiddenTabWidth(const AText: string; AState: TaqTabItemState;
      AOrientation: TaqHideZoneOrientation; APosition: TaqTabItemPosition; ADrawImage, ADrawText: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer): Integer; virtual;
    procedure DoDrawHideZone(ACanvas: TCanvas; ASiteRect, ARect: TRect;
      AOrientation: TaqHideZoneOrientation); virtual; abstract;
    procedure DoDrawHiddenTabItem(ACanvas: TCanvas; ARect: TRect;
      const AText: string; AState: TaqTabItemState;
      AOrientation: TaqHideZoneOrientation; APosition: TaqTabItemPosition;
      ADrawImage, ADrawText: Boolean; AImages: TCustomImageList; AImageIndex: Integer); virtual; abstract;

    property UpdateCount: Integer read FUpdateCount;

    property OnGetCaptionHeight: TaqStyleGetCaptionHeightEvent read FOnGetCaptionHeight write FOnGetCaptionHeight;
    property OnGetTabPaneHeight: TaqStyleGetTabPaneHeightEvent read FOnGetTabPaneHeight write FOnGetTabPaneHeight;
    property OnGetTabHeight: TaqStyleGetTabHeightEvent read FOnGetTabHeight write FOnGetTabHeight;
    property OnGetTabWidth: TaqStyleGetTabWidthEvent read FOnGetTabWidth write FOnGetTabWidth;
    property OnDrawTabButton: TaqStyleDrawTabButtonEvent read FOnDrawTabButton write FOnDrawTabButton;
    property OnDrawTabPane: TaqStyleDrawTabPaneEvent read FOnDrawTabPane write FOnDrawTabPane;
    property OnDrawTabItem: TaqStyleDrawTabItemEvent read FOnDrawTabItem write FOnDrawTabItem;
    property OnDrawTabTarget: TaqStyleDrawTabTargetEvent read FOnDrawTabTarget write FOnDrawTabTarget;
    property OnDrawCaptionButton: TaqStyleDrawCaptionButtonEvent read FOnDrawCaptionButton write FOnDrawCaptionButton;
    property OnDrawCaption: TaqStyleDrawCaptionEvent read FOnDrawCaption write FOnDrawCaption;
    property OnDrawControl: TaqStyleDrawControl read FOnDrawControl write FOnDrawControl;
    property OnDrawSplitter: TaqStyleDrawSplitterEvent read FOnDrawSplitter write FOnDrawSplitter;
    property OnChange: TNotifyEvent read FOnChange write FOnChange;
  public
    constructor Create(AOwner: TComponent); override;
    constructor CreateEx(AOwner: TComponent; APredefined: Boolean); virtual;
    destructor Destroy; override;

    procedure BeginUpdate;
    procedure EndUpdate;

    procedure SetMetrics(const AMetrics: TaqMetrics);
    procedure RegisterChanges(ALink: TaqStyleChangeLink);
    procedure UnRegisterChanges(ALink: TaqStyleChangeLink);

    function GetCaptionHeight(AState: TaqDockCaptionState; ADrawImage: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer): Integer;
    function GetTabPaneHeight(AOrientation: TaqTabOrientation; ADrawImage: Boolean;
      AImages: TCustomImageList): Integer;
    function GetTabHeight(AState: TaqTabItemState; AOrientation: TaqTabOrientation;
      ADrawImage: Boolean; AImages: TCustomImageList; AImageIndex: Integer): Integer;
    function GetTabWidth(const AText: string; AState: TaqTabItemState;
      APosition: TaqTabItemPosition; AOrientation: TaqTabOrientation; AButtonAreaWidth: Integer;
      ADrawImage: Boolean; AImages: TCustomImageList; AImageIndex: Integer): Integer;
    function GetTabButtonsBounds(ACanvas: TCanvas; ARect: TRect; ButtonSize: TPoint): TRect;

    procedure DrawTabButton(ACanvas: TCanvas; ARect: TRect;
      AState: TaqTabButtonState; AKind: TaqTabButtonKind);
    procedure DrawTabPane(ACanvas: TCanvas; ARect: TRect;
      AOrientation: TaqTabOrientation);
    procedure DrawTabItem(ACanvas: TCanvas; ARect: TRect;
      const AText: string; AState: TaqTabItemState; APosition: TaqTabItemPosition;
      AOrientation: TaqOrientation; AButtonAreaWidthBefore: Integer; AButtonAreaWidthAfter: Integer;
      ADrawImage: Boolean; AImages: TCustomImageList; AImageIndex: Integer);
    procedure DrawTabTarget(ACanvas: TCanvas; ARect: TRect);

    procedure DrawCaptionButton(ACanvas: TCanvas; ARect: TRect;
      AState: TaqDockButtonState; ACaptionState: TaqDockCaptionState; AKind: TaqDockButtonKind);
    procedure DrawCaption(ACanvas: TCanvas; ARect: TRect; const AText: string;
      AState: TaqDockCaptionState; AMaxTextWidth: Integer; var AFitText: Boolean; ADrawImage: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer);

    procedure DrawSplitter(ACanvas: TCanvas; ARect: TRect; AOrientation: TaqSplitterOrientation);
    procedure DrawControl(ACanvas: TCanvas; ARect: TRect; AKind: TaqDockControlDrawKind);

    function GetHideZoneHeight(AOrientation: TaqHideZoneOrientation; ADrawImage, ADrawText: Boolean;
      AImages: TCustomImageList): Integer;
    function GetHiddenTabHeight(AState: TaqTabItemState; AOrientation: TaqHideZoneOrientation;
      ADrawImage, ADrawText: Boolean; AImages: TCustomImageList; AImageIndex: Integer): Integer;
    function GetHiddenTabWidth(const AText: string; AState: TaqTabItemState;
      AOrientation: TaqHideZoneOrientation; APosition: TaqTabItemPosition; ADrawImage, ADrawText: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer): Integer;
    procedure DrawHideZone(ACanvas: TCanvas; ASiteRect, ARect: TRect;

⌨️ 快捷键说明

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