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

📄 aqdockinguidefault.pas

📁 AutomatedDocking Library 控件源代码修改 适合Delphi 2009 和C++ Builder 20009 使用。 修正汉字不能正确显示问题
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{*******************************************************************}
{                                                                   }
{       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 aqDockingUIDefault;

{$I aqDockingVer.inc}

interface

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

type
  TaqCustomDefaultUIStyle = class;
  TaqCaptionButtonImages = class;

  TaqCaptionButtonImagesClass = class of TaqCaptionButtonImages;
  TaqCaptionButtonImages = class(TPersistent)
  private
    FOwner: TaqCustomDefaultUIStyle;
    FButtonImages: array [TaqDockButtonKind] of TImageIndex;
    FDrawStyle: TaqImageDrawStyle;
    procedure SetImageIndex(ButtonKind: TaqDockButtonKind; Value: TImageIndex);
    function GetImageIndex(ButtonKind: TaqDockButtonKind): TImageIndex;
    procedure SetIImageIndex(Index: Integer; Value: TImageIndex);
    function GetIImageIndex(Index: Integer): TImageIndex;
    procedure SetDrawStyle(Value: TaqImageDrawStyle);
  protected
    procedure Change; virtual;
    function GetOwner: TPersistent; override;
    procedure AssignTo(Dest: TPersistent); override;

    property Owner: TaqCustomDefaultUIStyle read FOwner;
  public
    procedure Reset;

    property ButtonImages[ButtonKind: TaqDockButtonKind]: TImageIndex read GetImageIndex write SetImageIndex; default;
  published
    constructor Create(AOwner: TaqCustomDefaultUIStyle);

    property DrawStyle: TaqImageDrawStyle read FDrawStyle write SetDrawStyle default idsStretch;
    property HideButton: TImageIndex index dbkHide read GetIImageIndex write SetIImageIndex default -1;
    property UndockButton: TImageIndex index dbkUndock read GetIImageIndex write SetIImageIndex default -1;
    property AutoHideButton: TImageIndex index dbkAutoHide read GetIImageIndex write SetIImageIndex default -1;
    property UndoAutoHideButton: TImageIndex index dbkUndoAutoHide read GetIImageIndex write SetIImageIndex default -1;
    property MaximizeButton: TImageIndex index dbkMaximize read GetIImageIndex write SetIImageIndex default -1;
    property RestoreButton: TImageIndex index dbkRestore read GetIImageIndex write SetIImageIndex default -1;
    property MenuButton: TImageIndex index dbkMenu read GetIImageIndex write SetIImageIndex default -1;
    property HelpButton: TImageIndex index dbkHelp read GetIImageIndex write SetIImageIndex default -1;
    property CustomButton: TImageIndex index dbkCustom read GetIImageIndex write SetIImageIndex default -1;
  end;

  TaqCustomDefaultUIStyle = class(TaqDockingUIStyle)
  private
    FTabColor: TGradient;
    FActiveTabColor: TGradient;
    FActiveCaptionColor: TGradient;
    FCaptionColor: TGradient;
    FTabPaneColor: TGradient;
    FCaptionButtons: TaqCaptionButtonImages;
    FImages: TImageList;
    FImageChangeLink: TChangeLink;
    FSplitterColor: TColor;
    FHideZoneColor: TGradient;
    FHiddenTabColor: TGradient;
    FActiveHiddenTabColor: TGradient;
    procedure SetTabColor(Value: TGradient);
    procedure SetCaptionColor(Value: TGradient);
    procedure GradientChange(Sender: TObject);
    procedure SetTabPaneColor(Value: TGradient);
    procedure SetCaptionButtons(Value: TaqCaptionButtonImages);
    procedure SetImages(Value: TImageList);
    procedure ImagesChanged(Sender: TObject);
    procedure SetActiveCaptionColor(Value: TGradient);
    procedure SetActiveTabColor(Value: TGradient);
    procedure SetSplitterColor(const Value: TColor);
    procedure SetHideZoneColor(const Value: TGradient);
    procedure SetActiveHiddenTabColor(const Value: TGradient);
    procedure SetHiddenTabColor(const Value: TGradient);
  protected
    procedure AssignTo(Dest: TPersistent); override;
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;

    { TaqDockingUIStyle }
    // Low-level drawing routines
    procedure DoDrawCaptionButtonWidget(ACanvas: TCanvas; ARect: TRect;
      AState: TaqDockButtonState; ACaptionState: TaqDockCaptionState;
      AKind: TaqDockButtonKind); override;

    procedure DoDrawTabPaneContent(ACanvas: TCanvas; ARect: TRect;
      AOrientation: TaqOrientation); override;
    procedure DoDrawTabButtonWidget(ACanvas: TCanvas; ARect: TRect;
      AState: TaqTabButtonState; AKind: TaqTabButtonKind); override;

     // High-level drawing routines
    procedure DoDrawTabButton(ACanvas: TCanvas; ARect: TRect;
      AState: TaqTabButtonState; AKind: TaqTabButtonKind); override;
    procedure DoDrawTabPane(ACanvas: TCanvas; ARect: TRect;
      AOrientation: TaqTabOrientation); override;
    procedure DoDrawTabItem(ACanvas: TCanvas; ARect: TRect;
      const AText: string; AState: TaqTabItemState; APosition: TaqTabItemPosition;
      AOrientation: TaqOrientation; AButtonAreaWidthBefore: Integer; AButtonAreaWidthAfter: Integer;
      ADrawImage: Boolean; AImages: TCustomImageList; AImageIndex: Integer); override;
    procedure DoDrawTabTarget(ACanvas: TCanvas; ARect: TRect); override;
    procedure DoDrawCaptionButton(ACanvas: TCanvas; ARect: TRect;
      AState: TaqDockButtonState; ACaptionState: TaqDockCaptionState; AKind: TaqDockButtonKind); override;
    procedure DoDrawCaption(ACanvas: TCanvas; ARect: TRect; const AText: string;
      AState: TaqDockCaptionState; AMaxTextWidth: Integer; var AFitText: Boolean; ADrawImage: Boolean;
      AImages: TCustomImageList; AImageIndex: Integer); override;
    procedure DoDrawSplitter(ACanvas: TCanvas; ARect: TRect;
      AOrientation: TaqSplitterOrientation); override;
    procedure DoDrawControl(ACanvas: TCanvas; ARect: TRect;
      AKind: TaqDockControlDrawKind); override;

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

    function GetCaptionButtonImagesClass: TaqCaptionButtonImagesClass; virtual;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    property ActiveHiddenTabColor: TGradient read FActiveHiddenTabColor write SetActiveHiddenTabColor;
    property ActiveCaptionColor: TGradient read FActiveCaptionColor write SetActiveCaptionColor;
    property ActiveTabColor: TGradient read FActiveTabColor write SetActiveTabColor;
    property CaptionButtons: TaqCaptionButtonImages read FCaptionButtons write SetCaptionButtons;
    property CaptionColor: TGradient read FCaptionColor write SetCaptionColor;
    property HiddenTabColor: TGradient read FHiddenTabColor write SetHiddenTabColor;
    property HideZoneColor: TGradient read FHideZoneColor write SetHideZoneColor;
    property Images: TImageList read FImages write SetImages;
    property TabColor: TGradient read FTabColor write SetTabColor;
    property TabPaneColor: TGradient read FTabPaneColor write SetTabPaneColor;
    property SplitterColor: TColor read FSplitterColor write SetSplitterColor;
  end;

  TaqDefaultUIStyle = class(TaqCustomDefaultUIStyle)
  published
    property ActiveCaptionColor;
    property ActiveCaptionFont;
    property ActiveHiddenTabColor;
    property ActiveHiddenTabFont;
    property ActiveTabColor;
    property ActiveTabFont;
    property CaptionButtons;
    property CaptionButtonSize;
    property CaptionColor;
    property CaptionFont;
    property HiddenTabColor;
    property HiddenTabFont;
    property HideZoneColor;
    property Images;
    property SplitterColor;
    property SplitterHeight;
    property SplitterWidth;
    property TabColor;
    property TabFont;
    property TabIndent;
    property TabPaneColor;

    property OnGetTabWidth;
    property OnDrawTabButton;
    property OnDrawTabPane;
    property OnDrawTabItem;
    property OnDrawTabTarget;
    property OnDrawCaptionButton;
    property OnDrawCaption;
    property OnDrawControl;
    property OnDrawSplitter;
    property OnChange;
  end;

implementation

uses
{$IFDEF VCL}
  StdCtrls, Forms,
{$ELSE}
  QStdCtrls, QForms, Qt,
{$ENDIF}
  Math, SysUtils;

const
  DefMetrics: TaqMetrics = (
    4,   // dumTextSpacingX
    1,   // dumTextSpacingY
    2,   // dumCaptionBorderX
    2,   // dumCaptionBorderY
    3,   // dumTabPadding
    1,   // dumTabTopOffset
    1,   // dumTabItemBorderX
    1,   // dumTabItemBorderY
    1,   // dumTabPaneBorderX
    1,   // dumTabPaneBorderY
    14   // dumTabDefaultButtonSize
    );

{ TaqCaptionButtonImages }

procedure TaqCaptionButtonImages.AssignTo(Dest: TPersistent);
begin
  if Dest is TaqCaptionButtonImages then
    with TaqCaptionButtonImages(Dest) do
      Move(Self.FButtonImages[Low(TaqDockButtonKind)],
        FButtonImages[Low(TaqDockButtonKind)],
        Length(FButtonImages) * SizeOf(TImageIndex))
  else
    inherited;
end;

procedure TaqCaptionButtonImages.Change;
begin
  if FOwner <> nil then
    FOwner.Change;
end;

constructor TaqCaptionButtonImages.Create(AOwner: TaqCustomDefaultUIStyle);
begin
  inherited Create;
  FOwner := AOwner;
  FDrawStyle := idsStretch;
  Reset;
end;

function TaqCaptionButtonImages.GetIImageIndex(Index: Integer): TImageIndex;
begin
  Result := GetImageIndex(TaqDockButtonKind(Index));
end;

function TaqCaptionButtonImages.GetImageIndex(
  ButtonKind: TaqDockButtonKind): TImageIndex;
begin
  Result := FButtonImages[ButtonKind];
end;

function TaqCaptionButtonImages.GetOwner: TPersistent;
begin
  Result := FOwner;
end;

procedure TaqCaptionButtonImages.Reset;
var
  Kind: TaqDockButtonKind;
begin
  for Kind := Low(TaqDockButtonKind) to High(TaqDockButtonKind) do
    FButtonImages[Kind] := -1;
  Change;
end;

procedure TaqCaptionButtonImages.SetDrawStyle(Value: TaqImageDrawStyle);
begin
  if FDrawStyle <> Value then
  begin
    FDrawStyle := Value;
    if FOwner.Images <> nil then
      Change;
  end;
end;

procedure TaqCaptionButtonImages.SetIImageIndex(Index: Integer; Value: TImageIndex);
begin
  SetImageIndex(TaqDockButtonKind(Index), Value);
end;

procedure TaqCaptionButtonImages.SetImageIndex(
  ButtonKind: TaqDockButtonKind; Value: TImageIndex);
begin
  if FButtonImages[ButtonKind] <> Value then
  begin
    FButtonImages[ButtonKind] := Value;
    if FOwner.Images <> nil then
      Change;
  end;
end;

{ TaqGradientUIStyle }

constructor TaqCustomDefaultUIStyle.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FImageChangeLink := TChangeLink.Create;
  FImageChangeLink.OnChange := ImagesChanged;

  FCaptionButtons := GetCaptionButtonImagesClass.Create(Self);

  FTabColor := TGradient.Create;
  FTabColor.StartColor := clBtnHighlight;
  FTabColor.OnChange := GradientChange;
  FActiveTabColor := TGradient.Create;
  FActiveTabColor.OnChange := GradientChange;
  FTabPaneColor := TGradient.Create;
  FTabPaneColor.StartColor := clBtnHighlight;
  FTabPaneColor.OnChange := GradientChange;
  FCaptionColor := TGradient.Create;
  FCaptionColor.OnChange := GradientChange;
  FActiveCaptionColor := TGradient.Create;
  FActiveCaptionColor.OnChange := GradientChange;
  FSplitterColor := clBtnFace;
  FHideZoneColor := TGradient.Create;
  FHideZoneColor.StartColor := clWindow;
  FHideZoneColor.OnChange := GradientChange;
  FActiveHiddenTabColor := TGradient.Create;
  FActiveHiddenTabColor.StartColor := clBtnFace;
  FActiveHiddenTabColor.OnChange := GradientChange;
  FHiddenTabColor := TGradient.Create;
  FHiddenTabColor.StartColor := clBtnFace;
  FHiddenTabColor.OnChange := GradientChange;

  SetMetrics(DefMetrics);
end;

destructor TaqCustomDefaultUIStyle.Destroy;
begin
  Images := nil;
  FreeAndNil(FImageChangeLink);
  FreeAndNil(FCaptionButtons);
  FreeAndNil(FTabPaneColor);
  FreeAndNil(FActiveTabColor);
  FreeAndNil(FTabColor);
  FreeAndNil(FCaptionColor);
  FreeAndNil(FActiveCaptionColor);
  FreeAndNil(FHideZoneColor);
  FreeAndNil(FActiveHiddenTabColor);
  FreeAndNil(FHiddenTabColor);
  inherited;
end;

procedure TaqCustomDefaultUIStyle.DoDrawTabPane(ACanvas: TCanvas; ARect: TRect;
  AOrientation: TaqTabOrientation);
const
  PaddingEdges: array [TaqTabOrientation, Boolean] of TaqEdgeStyle = (
    // Inner, Outer
    (esNone, esRaised),    // dtoTop
    (esRaised, esNone));  // dtoBottom

  PaddingBorders: array [TaqTabOrientation] of TaqEdgeBorders = (
    [ebTop],         // dtoTop
    [ebBottom]       // dtoBottom
    );

  PaneEdges: array [Boolean] of TaqEdgeStyle = (
    // Inner, Outer
    esLowered, esNone);

⌨️ 快捷键说明

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