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

📄 aqdockingui.pas.~1~

📁 AutomatedDocking Library 控件源代码修改 适合Delphi 2009 和C++ Builder 20009 使用。 修正汉字不能正确显示问题
💻 ~1~
📖 第 1 页 / 共 5 页
字号:

function TaqDockingUIStyle.GetCaptionButtonsPosition: TaqCaptionButtonPostions;
begin
  Result := [bcpBefore, bcpAfter];
end;

procedure TaqDockingUIStyle.CheckMetric(AMetric: TaqDockingUIMetric;
  Value: Integer);
var
  LowValue, HighValue: Integer;
begin
  LowValue := MetricBounds[AMetric].Low;
  HighValue := MetricBounds[AMetric].High;
  if (Value < LowValue) or (Value > HighValue) then
    raise EIntOverflow.CreateFmt(SEInvalidMetricValue, [LowValue, HighValue]);
end;

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

  FShowAccelChar := sacTrue;
  FCaptionFont := TFont.Create;
  FCaptionFont.OnChange := FontChange;
  FTabFont := TFont.Create;
  FTabFont.OnChange := FontChange;
  FActiveCaptionFont := TFont.Create;
  FActiveCaptionFont.OnChange := FontChange;
  FActiveTabFont := TFont.Create;
  FActiveTabFont.OnChange := FontChange;
  FHiddenTabFont := TFont.Create;
  FHiddenTabFont.Color := clBtnShadow;
  FHiddenTabFont.OnChange := FontChange;
  FActiveHiddenTabFont := TFont.Create;
  FActiveHiddenTabFont.OnChange := FontChange;
  FCaptionButtonSize := 14;
  FCaptionButtonWidthRatio := 1.0;
  FSplitterHeight := 4;
  FSplitterWidth := 4;
  FTabIndent := 3;
  FUniformTabWidth := True;
  FLinks := TList.Create;
  FHotTrack := True;
  if AOwner is TaqStyleManager then
    StyleManager := TaqStyleManager(AOwner);
end;

constructor TaqDockingUIStyle.CreateEx(AOwner: TComponent; APredefined: Boolean);
begin
  FPredefined := APredefined;
  Create(AOwner);
end;

procedure TaqDockingUIStyle.DefineProperties(Filer: TFiler);
begin
  inherited;
  Filer.DefineProperty('Predefined', ReadPredefined, WritePredefined, Predefined);
  Filer.DefineProperty('Caption', ReadCaption, WriteCaption, not Predefined);
end;

destructor TaqDockingUIStyle.Destroy;
var
  i: Integer;
begin
  StyleManager := nil;
  for i := 0 to FLinks.Count - 1 do
    TaqStyleChangeLink(FLinks[i]).Sender := nil;
  FreeAndNil(FLinks);
  FreeAndNil(FActiveCaptionFont);
  FreeAndNil(FActiveTabFont);
  FreeAndNil(FCaptionFont);
  FreeAndNil(FTabFont);
  FreeAndNil(FHiddenTabFont);
  FreeAndNil(FActiveHiddenTabFont);
  inherited;
end;

procedure TaqDockingUIStyle.DoDrawCaptionContent(ACanvas: TCanvas;
  ARect: TRect; const AText: string; AState: TaqDockCaptionState;
  AMaxTextWidth: Integer; var AFitText: Boolean; ADrawImage: Boolean;
  AImages: TCustomImageList; AImageIndex: Integer);
var
  R1: TRect;
  PosX: Integer;
  Font: TFont;
  Text: string;
begin
  PosX := ARect.Left + FMetrics[dumTextSpacingX];
  ARect.Right := ARect.Left + Min(ARect.Right - ARect.Left, AMaxTextWidth);

  if ADrawImage and (AImages <> nil) and (AImageIndex >= 0) and
    (AImageIndex < AImages.Count) then
  begin
    if PosX + AImages.Width < ARect.Right then
      AImages.Draw(ACanvas, PosX, ARect.Top + ((ARect.Bottom - ARect.Top - AImages.Height) div 2),
      AImageIndex);
    Inc(PosX, AImages.Width + FMetrics[dumTextSpacingX]);
  end;

  AFitText := PosX < ARect.Right;
  if AFitText then
  begin
    if AState = dcsFocused then
      Font := ActiveCaptionFont
    else
      Font := CaptionFont;
    R1 := ARect; R1.Left := PosX;
    ACanvas.Brush.Style := bsClear;
    ACanvas.Font := Font;
    AFitText := MinimizeText(AText, ACanvas, R1.Right - R1.Left, FShowAccelChar,
      Text);
    OutTextRect(ACanvas, R1, 0, 0, Text, tlCenter, taLeftJustify, False, False,
      FShowAccelChar);
  end;
end;

procedure TaqDockingUIStyle.DoDrawTabItemContent(ACanvas: TCanvas;
  ARect: TRect; const AText: string; AState: TaqTabItemState;
  AOrientation: TaqOrientation; ADrawImage, ADrawText: Boolean;
  AFont, AActiveFont: TFont; AImages: TCustomImageList; AImageIndex: Integer;
  APadding: Boolean);
const
  TextAlignments: array [Boolean] of TAlignment =
    (taLeftJustify, taCenter);
var
  Indent: Integer;
  Text: string;
  P: TPoint;
  TextCenter: Boolean;
begin
  ACanvas.Brush.Style := bsClear;
  if AState in [tisSelected, tisFocused] then
    ACanvas.Font := AActiveFont
  else
    ACanvas.Font := AFont;
  case AState of
    tisHot, tisFocused:
      if FHotTrack then
        ACanvas.Font.Color := clHotLight;
    tisDisabled: ACanvas.Font.Color := clGrayText;
  end;
  FLastTabState := AState;
  FLastTabOrient := AOrientation;

  if APadding and (AState in [tisSelected, tisFocused]) then
    case AOrientation of
      orTop:    Dec(ARect.Bottom, FMetrics[dumTabPadding]);
      orBottom: Inc(ARect.Top, FMetrics[dumTabPadding]);
      orLeft:   Dec(ARect.Right, FMetrics[dumTabPadding]);
      orRight:  Inc(ARect.Left, FMetrics[dumTabPadding]);
    end;

  Indent := FMetrics[dumTextSpacingX];
  ADrawImage := ADrawImage and (AImages <> nil) and (AImageIndex >= 0) and (AImageIndex < AImages.Count);
  ADrawText := ADrawText or not ADrawImage;
  if ADrawImage then
  begin
    if AOrientation in [orTop, orBottom] then
    begin
      P.X := ARect.Left + Indent;
      P.Y := ARect.Top + ((ARect.Bottom - ARect.Top - AImages.Height) div 2);
    end
    else
    begin
      P.X := ARect.Left + ((ARect.Right - ARect.Left - AImages.Width) div 2);
      P.Y := ARect.Top + Indent;
    end;
    AImages.Draw(ACanvas, P.X, P.Y, AImageIndex);
    if AOrientation in [orTop, orBottom] then
      Inc(Indent, AImages.Width + Indent)
    else
      Inc(Indent, AImages.Height + Indent);
  end;

  if ADrawText then
  begin
    if AOrientation in [orTop, orBottom] then
      P.X := ARect.Right - ARect.Left - Indent - FMetrics[dumTextSpacingX] + 2
    else
      P.X := ARect.Bottom - Indent - FMetrics[dumTextSpacingY];

    TextCenter := UniFormTabWidth;
    if not MinimizeText(AText, ACanvas, P.X, FShowAccelChar, Text) then
      TextCenter := False;
    if AOrientation in [orTop, orBottom] then
    begin
      P.X := 0;
      P.Y := FMetrics[dumTabPadding] + FMetrics[dumTextSpacingY] + 1;
      Inc(ARect.Left, Indent);
      if UniformTabWidth and TextCenter then
        Dec(ARect.Left, FMetrics[dumTextSpacingX]);
    end
    else
    begin
      P.X := FMetrics[dumTabPadding] + FMetrics[dumTextSpacingX] + 1;
      P.Y := 0;
      Inc(ARect.Top, Indent);
      if UniformTabWidth and TextCenter then
        Dec(ARect.Top, FMetrics[dumTextSpacingY]);
    end;
    FLastTabTextRect := ARect;
    OutTextRect(ACanvas, ARect, P.X, P.Y,
      Text, tlCenter, TextAlignments[TextCenter{UniformTabWidth}],
      AOrientation in [orLeft, orRight], False, FShowAccelChar);
  end
  else
    FLastTabTextRect := Rect(0, 0, 0, 0);
end;

function TaqDockingUIStyle.DoGetCaptionHeight(AState: TaqDockCaptionState;
  ADrawImage: Boolean; AImages: TCustomImageList;
  AImageIndex: Integer): Integer;
var
  ContentHeight: Integer;
begin
  ContentHeight := Max(TextMetrics(CaptionFont, SHeightTestText).Y,
    TextMetrics(ActiveCaptionFont, SHeightTestText).Y);

  if (ADrawImage and (AImages <> nil) and (AImageIndex >= 0) and (AImageIndex < AImages.Count)) then
    ContentHeight := Max(ContentHeight, AImages.Height);

  if ContentHeight < GetCaptionButtonSize.Y then
    ContentHeight := GetCaptionButtonSize.Y;

  Result := ContentHeight + 2 * FMetrics[dumTextSpacingY] +
    2 * FMetrics[dumCaptionBorderY];
end;

function TaqDockingUIStyle.DoGetHiddenTabHeight(AState: TaqTabItemState;
  AOrientation: TaqHideZoneOrientation; ADrawImage, ADrawText: Boolean;
  AImages: TCustomImageList; AImageIndex: Integer): Integer;
begin
  if ADrawText then
    Result := Max(TextMetrics(HiddenTabFont, SHeightTestText).Y,
      TextMetrics(ActiveHiddenTabFont, SHeightTestText).Y)
  else
    Result := 16;
  if ADrawImage and (AImages <> nil) then
    Result := Max(Result, AImages.Height);
  Inc(Result, 2 * FMetrics[dumTextSpacingY] + FMetrics[dumTabItemBorderY]);
end;

function TaqDockingUIStyle.DoGetHiddenTabWidth(const AText: string;
  AState: TaqTabItemState; AOrientation: TaqHideZoneOrientation; APosition: TaqTabItemPosition;
  ADrawImage, ADrawText: Boolean; AImages: TCustomImageList;
  AImageIndex: Integer): Integer;
var
  Fnt: TFont;
  str: string;
begin
  Result := 0;
  ADrawImage := ADrawImage and (AImages <> nil) and (AImageIndex >= 0) and (AImageIndex < AImages.Count);
  ADrawText := ADrawText or not ADrawImage;
  if ADrawText then
  begin
    str := StripHotkey(AText);
    if UniformTabWidth then
      Inc(Result, Max(TextMetrics(ActiveHiddenTabFont, str).X, TextMetrics(HiddenTabFont, str).X))
    else
    begin
      if AState in [tisSelected, tisFocused] then
        Fnt := ActiveHiddenTabFont
      else
        Fnt := HiddenTabFont;
      Inc(Result, TextMetrics(fnt, str).X);
    end;
    if Result > 0 then
      Inc(Result, 3* FMetrics[dumTextSpacingX]);
  end;
  Inc(Result, 2 * FMetrics[dumTabItemBorderX] + FMetrics[dumTextSpacingX]);
  if ADrawImage then
    Inc(Result, AImages.Width + FMetrics[dumTextSpacingX]);
end;

function TaqDockingUIStyle.DoGetHideZoneHeight(
  AOrientation: TaqHideZoneOrientation; ADrawImage, ADrawText: Boolean;
  AImages: TCustomImageList): Integer;
begin
  Result := DoGetHiddenTabHeight(tisFocused, AOrientation, ADrawImage, ADrawText, AImages, 0) +
    FMetrics[dumTabPadding] + FMetrics[dumTabTopOffset] + FMetrics[dumTabPaneBorderY];
end;

function TaqDockingUIStyle.DoGetTabHeight(AState: TaqTabItemState;
  AOrientation: TaqTabOrientation; ADrawImage: Boolean;
  AImages: TCustomImageList; AImageIndex: Integer): Integer;
begin
  Result := Max(TextMetrics(TabFont, SHeightTestText).Y,
    TextMetrics(ActiveTabFont, SHeightTestText).Y);
  if ADrawImage and (AImages <> nil) then
    Result := Max(Result, AImages.Height);
  Inc(Result, 2 * FMetrics[dumTextSpacingY] + FMetrics[dumTabItemBorderY]);
end;

function TaqDockingUIStyle.DoGetTabPaneHeight(
  AOrientation: TaqTabOrientation; ADrawImage: Boolean;
  AImages: TCustomImageList): Integer;
begin
  Result := GetTabHeight(tisFocused, AOrientation, ADrawImage, AImages, 0) +
    FMetrics[dumTabPadding] + FMetrics[dumTabTopOffset] + FMetrics[dumTabPaneBorderY];
end;

function TaqDockingUIStyle.DoGetTabWidth(const AText: string;
  AState: TaqTabItemState; APosition: TaqTabItemPosition;
  AOrientation: TaqTabOrientation; AButtonAreaWidth: Integer; ADrawImage: Boolean;
  AImages: TCustomImageList; AImageIndex: Integer): Integer;
var
  Fnt: TFont;
  str: string;
begin
  str := StripHotkey(AText);
  if UniformTabWidth then
    Result := Max(TextMetrics(ActiveTabFont, str).X, TextMetrics(TabFont, str).X)
  else
  begin
    if AState in [tisSelected, tisFocused] then
      Fnt := ActiveTabFont
    else
      Fnt := TabFont;
    Result := TextMetrics(fnt, str).X;
  end;
  Inc(Result, 2 * (FMetrics[dumTextSpacingX] + FMetrics[dumTabItemBorderX]));
  if AButtonAreaWidth > 0 then
    Inc(Result, AButtonAreaWidth + FMetrics[dumTextSpacingX]);
  if ADrawImage and (AImages <> nil) and (AImageIndex >= 0) and (AImageIndex < AImages.Count) then
    Inc(Result, AImages.Width + FMetrics[dumTextSpacingX]);
end;

function TaqDockingUIStyle.DoGetTabButtonsBounds(ACanvas: TCanvas; ARect: TRect; ButtonSize: TPoint): TRect;
var
  Offset: Integer;
begin
  Offset := Metrics[dumTextSpacingX] + Metrics[dumTabItemBorderX];
  Result.Left := ARect.Left + 3 * Offset div 4;
  Result.Right := ARect.Right - 3 * Offset div 4;

  Offset := (FLastTabTextRect.Bottom - FLastTabTextRect.Top - ButtonSize.Y) div 2;// + 1;
  Result.Bottom := FLastTabTextRect.Bottom - Offset;
  Result.Top := Result.Bottom - ButtonSize.Y;
end;

procedure TaqDockingUIStyle.DrawCaption(ACanvas: TCanvas;
  ARect: TRect; const AText: string; AState: TaqDockCaptionState; AMaxTextWidth: Integer;
  var AFitText: Boolean; ADrawImage: Boolean; AImages: TCustomImageList;
  AImageIndex: Integer);
begin
  if Assigned(FOnDrawCaption) then
    FOnDrawCaption(Self, ACanvas, ARect, AText, AState, AMaxTextWidth, AFitText,
      ADrawImage, AImages, AImageIndex)
  else
    DoDrawCaption(ACanvas, ARect, AText, AState, AMaxTextWidth, AFitText,
      ADrawImage, AImages, AImageIndex);
end;

procedure TaqDockingUIStyle.DrawCaptionButton(ACanvas: TCanvas; ARect: TRect;
  AState: TaqDockButtonState; ACaptionState: TaqDockCaptionState; AKind: TaqDockButtonKind);
begin
  if Assigned(FOnDrawCaptionButton) then
    FOnDrawCaptionButton(Self, ACanvas, ARect, AState, ACaptionState, AKind)
  else
    DoDrawCaptionButton(ACanvas, ARect, AState, ACaptionState, AKind);

⌨️ 快捷键说明

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