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

📄 cxpcpainters.pas

📁 PageControl 2.0 与1.0兼营版控件 ,TPageControl的扩展。增强了一些功能。
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    DelimiterWidth = 2;
  var
    R: TRect;
    TabsDistance: Integer;
    DelimiterLeftBorder, DelimiterTopBorder: Integer;
    DelimiterRect: TRect;
  begin
    if not IsDelimiterNeeded then Exit;
    R := Tab.FullRect;
    TabsDistance := StandardPainterTabsNormalDistanceA[GetStandardStyle].dw;

    with R do
      if IsVerticalText(ParentControl) then
      begin
        if IsBottomToTopAlignment(ParentControl) then
        begin
          Bottom := Top;
          Top := Bottom - TabsDistance;
        end else
        begin
          Top := Bottom;
          Bottom := Top + TabsDistance;
        end;
        if not InternalSetClipRect(R) then Exit;
        DelimiterTopBorder := Top + (TabsDistance - DelimiterWidth) div 2;
        InternalPolyLine([Point(Left + 1, DelimiterTopBorder), Point(Right - 2, DelimiterTopBorder)], cxPCDarkEdgeColor);
        InternalPolyLine([Point(Left + 1, DelimiterTopBorder + 1), Point(Right - 2, DelimiterTopBorder + 1)], cxPCLightestEdgeColor);
        DelimiterRect := Rect(Left + 1, DelimiterTopBorder, Right - 1, DelimiterTopBorder + 2);
      end else
      begin
        if IsRightToLeftAlignment(ParentControl) then
        begin
          Right := Left;
          Left := Right - TabsDistance;
        end else
        begin
          Left := Right;
          Right := Left + TabsDistance;
        end;
        if not InternalSetClipRect(R) then Exit;
        DelimiterLeftBorder := Left + (TabsDistance - DelimiterWidth) div 2;
        InternalPolyLine([Point(DelimiterLeftBorder, Top + 1), Point(DelimiterLeftBorder, Bottom - 2)], cxPCDarkEdgeColor);
        InternalPolyLine([Point(DelimiterLeftBorder + 1, Top + 1), Point(DelimiterLeftBorder + 1, Bottom - 2)], cxPCLightestEdgeColor);
        DelimiterRect := Rect(DelimiterLeftBorder, Top + 1, DelimiterLeftBorder + 2, Bottom - 1);
      end;
    with ParentInfo.Canvas do
    begin
      SaveClipRgn;
      ExcludeClipRect(DelimiterRect);
      Brush.Style := bsSolid;
      Brush.Color := ParentInfo.Color;
      FillRect(R);
      RestoreClipRgn;
    end;

    InternalResetClipRegion;
    ParentInfo.Canvas.ExcludeClipRect(R);
  end;

begin
  inherited PaintTab(TabVisibleIndex);
  Tab := ParentInfo.VisibleTabs[TabVisibleIndex];
  InternalPaintTabsDelimiter;
end;

procedure TcxPCFlatButtonsPainter.PaintTabFrame(TabVisibleIndex: Integer);
var
  FullRect: TRect;
  Tab: TcxTab;
  TabBodyColor: TColor;
begin
  Tab := ParentInfo.VisibleTabs[TabVisibleIndex];
  TabBodyColor := GetTabBodyColor(TabVisibleIndex);
  FullRect := Tab.FullRect;
  with ParentInfo.Canvas, FullRect do
  begin
    if (not Tab.Tracking) and (Tab.Pressed or Tab.Selected or Tab.IsMainTab) then
    begin
      InternalDrawEdge(FullRect, True);
      InflateRect(FullRect, -StandardPainterTabBorderWidth, -StandardPainterTabBorderWidth);
    end
    else if Tab.HotTrack or Tab.Tracking then
    begin
      InternalPolyLine([Point(Left, Bottom - 2), Point(Left, Top), Point(Right - 2, Top)], cxPCLightestEdgeColor);
      InternalPolyLine([Point(Left, Bottom - 1), Point(Right - 1, Bottom - 1), Point(Right - 1, Top)], cxPCDarkEdgeColor);
      InflateRect(FullRect, -1, -1);
    end;

    Brush.Color := TabBodyColor;
    FillRect(FullRect);

    InflateRect(FullRect, 1, 1);
    InternalDrawFocusRect(TabVisibleIndex, FullRect);
  end;
end;

procedure TcxPCStandardPainter.CalculateButtonsRegion(
  NavigatorButtons: TcxPCNavigatorButtons);
begin
  InternalCalculateButtonsRegion(NavigatorButtons, Size(0, 0), 0);
end;

procedure TcxPCStandardPainter.CalculateButtonsRegionRect(NavigatorButtons: TcxPCNavigatorButtons);
var
  ButtonsWidth: Integer;
begin
  ButtonsWidth := CalculateButtonsWidth(NavigatorButtons);
  with ParentInfo, FButtonsRegionRect do
    if TabPosition in [tpTop, tpBottom] then
    begin
      if NavigatorPosition in [npLeftTop, npLeftBottom] then Left := 0
      else Left := Width - ButtonsWidth;
      if TabPosition = tpTop then Top := 0
      else Top := Height - GetButtonHeight;
      Right := Left + ButtonsWidth;
      Bottom := Top + GetButtonHeight;
    end else
    begin
      if NavigatorPosition in [npLeftTop, npRightTop] then Top := 0
      else Top := Height - ButtonsWidth;
      if TabPosition = tpLeft then Left := 0
      else Left := Width - GetButtonHeight;
      Right := Left + GetButtonHeight;
      Bottom := Top + ButtonsWidth;
    end;
end;

function TcxPCStandardPainter.CalculateButtonsWidth(
  NavigatorButtons: TcxPCNavigatorButtons): Integer;
begin
  Result := 0;
  if nbTopLeft in NavigatorButtons then Inc(Result, GetButtonWidth(nbTopLeft));
  if nbBottomRight in NavigatorButtons then Inc(Result, GetButtonWidth(nbBottomRight));
  if nbGoDialog in NavigatorButtons then Inc(Result, GetButtonWidth(nbGoDialog));
end;

function TcxPCStandardPainter.CalculateTabNormalHeight: Integer;
var
  DefaultTabNormalHeight: Integer;
begin
  with ParentInfo do
  begin
    Result := InternalCalculateTabNormalHeight;

    DefaultTabNormalHeight := GetDefaultTabNormalHeight;
    if Result < DefaultTabNormalHeight then
      Result := DefaultTabNormalHeight;

    if (TabHeight >= DefaultTabNormalHeight) and (TabHeight > Result) then
      Result := TabHeight;
  end;
end;

function TcxPCStandardPainter.CalculateTabNormalWidth(
  Tab: TcxTab): Integer;
var
  MinTabNormalWidth: Integer;
begin
  MinTabNormalWidth := GetMinTabNormalWidth;
  with ParentInfo do
//    if TabWidth >= MinTabNormalWidth then
    if TabWidth > 0 then
      Result := TabWidth
    else
    begin
      Result := GetTabBaseImageSize.cx;
      if Result > 0 then
        Inc(Result, 2 * ImageBorder + 6);
      Inc(Result, 12);
      if Tab.VisibleCaption <> '' then
        Inc(Result, Canvas.TextWidth(Tab.VisibleCaption));
      if Result < MinTabNormalWidth then
        Result := MinTabNormalWidth;
    end;
end;

function TcxPCStandardPainter.GetClientRect: TRect;
begin
  Result := GetDisplayRect;
end;

{ TcxPCStandardPainter }

constructor TcxPCStandardPainter.Create(AParent: TcxCustomTabControl);
begin
  inherited Create(AParent);
  FButtonsQueue := nil;
end;

destructor TcxPCStandardPainter.Destroy;
begin
  FButtonsQueue := nil;
  inherited Destroy;
end;

function TcxPCStandardPainter.GetDefaultTabNormalHeight: Integer;
begin
  Result := StandardPainterDefaultTabNormalHeightA[GetStandardStyle];
end;

function TcxPCStandardPainter.GetDefaultTabNormalHTextOffset: Integer;
begin
  Result := StandardPainterDefaultTabNormalHTextOffsetA[GetStandardStyle];
end;

function TcxPCStandardPainter.GetDefaultTabNormalWidth: Integer;
begin
  Result := StandardPainterDefaultTabNormalWidthA[GetStandardStyle];
end;

function TcxPCStandardPainter.GetDefaultTabNormalWTextOffset: Integer;
begin
  Result := StandardPainterDefaultTabNormalWTextOffsetA[GetStandardStyle];
end;

function TcxPCStandardPainter.GetDrawImageOffset(TabVisibleIndex: Integer): TRect;
begin
  Result := StandardPainterDrawImageOffsetA[IsTabBorderThick(TabVisibleIndex),
    GetStandardStyle];
end;

function TcxPCStandardPainter.GetDrawTextOffset(TabVisibleIndex: Integer): TRect;
begin
  Result := StandardPainterDrawTextOffsetA[IsTabBorderThick(TabVisibleIndex),
    GetStandardStyle];
  if IsMainTabBoundWithClient and (ParentInfo.VisibleTabs[TabVisibleIndex].PaintingPositionIndex in [5, 7, 10]) then
    Inc(Result.Bottom);
end;

function TcxPCStandardPainter.GetImageTextDistance: Integer;
begin
  Result := StandardPainterImageTextDistanceA[GetStandardStyle];
end;

function TcxPCStandardPainter.GetTabContentWOffset(ATabVisibleIndex: Integer): TcxPCWOffset;
begin
  Result := StandardPainterTabContentWOffsetA[IsTabBorderThick(ATabVisibleIndex),
    GetStandardStyle];
end;

function TcxPCStandardPainter.GetDisplayRect: TRect;
var
  IsY: Boolean;
  Border: Integer;
begin
  Result := GetControlRect(ParentControl);
  with ParentInfo, Result do
    if not HideTabs then
    begin
      IsY := TabPosition in [tpTop, tpBottom];

      if TopOrLeftPartRowCount <> RowCount then
      begin
        Border := PointGetter(ExtendedBottomOrRightTabsRect.TopLeft, IsY);
        PointSetter(Result.BottomRight, IsY, Border);
      end;

      if TopOrLeftPartRowCount <> 0 then
      begin
        Border := PointGetter(ExtendedTopOrLeftTabsRect.BottomRight, IsY);
        PointSetter(Result.TopLeft, IsY, Border);
      end;
    end;
end;

function TcxPCStandardPainter.GetGoDialogButtonBounds: TRect;
var
  AButtonIndex: Integer;
begin
  Result := EmptyRect;
  for AButtonIndex := 0 to High(FButtonsQueue) do
    with FButtonsQueue[AButtonIndex] do
      if Button = nbGoDialog then
      begin
        Result := ButtonRect;
        Break;
      end;
end;

function TcxPCStandardPainter.GetGoDialogPosition(GoDialogSize: TSize): TPoint;
const
  GoDialogPositionA: array[TcxTabPosition, TcxPCNavigatorPosition] of TcxPCNavigatorPosition = (
    (npLeftTop, npLeftTop, npRightTop, npRightTop),
    (npLeftBottom, npLeftBottom, npRightBottom, npRightBottom),
    (npLeftTop, npLeftBottom, npLeftTop, npLeftBottom),
    (npRightTop, npRightBottom, npRightTop, npRightBottom)
  );
var
  ButtonIndex: Integer;
  GoDialogPosition: TcxPCNavigatorPosition;
begin
  for ButtonIndex := 0 to High(FButtonsQueue) do
    with ParentInfo, FButtonsQueue[ButtonIndex] do
      if Button = nbGoDialog then
      begin
        GoDialogPosition := GoDialogPositionA[TabPosition, NavigatorPosition];
        if GoDialogPosition in [npLeftTop, npLeftBottom] then
          Result.X := ButtonRect.Left
        else
          Result.X := ButtonRect.Right - GoDialogSize.cx;
        if GoDialogPosition in [npLeftTop, npRightTop] then
          Result.Y := ButtonRect.Bottom
        else
          Result.Y := ButtonRect.Top - GoDialogSize.cy;
        Exit;
      end;
end;

function TcxPCStandardPainter.GetMinTabNormalWidth: Integer;
var
  TabImageRegionWidth: Integer;
begin
  with ParentInfo do
  begin
    Result := GetDefaultTabNormalWidth;
    TabImageRegionWidth := GetTabBaseImageSize.cx;
    if TabImageRegionWidth > 0 then
      Inc(TabImageRegionWidth, 2 * ImageBorder + 6);
    Inc(TabImageRegionWidth, 12);
//      Inc(TabImageRegionWidth, 2 * (ImageBorder +
//        GetTabBorderWidth(nil)));
    if Result < TabImageRegionWidth then
      Result := TabImageRegionWidth;
  end;
end;

function TcxPCStandardPainter.GetMinTabSelectionDistance: TcxPCDistance;
begin
  Result := MinTabSelectionDistance;
end;

function TcxPCStandardPainter.GetTabBorderWidth(Tab: TcxTab): Integer;
begin
  Result := StandardPainterMaxTabBorderWidth;
end;

procedure TcxPCStandardPainter.GetTabClipRect(TabVisibleIndex: Integer;
  var ClipR: TRect; var IntersectClipRectWithCurrentClipRegion: Boolean);
begin
  ClipR := ParentInfo.VisibleTabs[TabVisibleIndex].VisibleRect;
  IntersectClipRectWithCurrentClipRegion := True;
end;

function TcxPCStandardPainter.GetTooNarrowTabContentWOffset(ATabVisibleIndex: Integer): TcxPCWOffset;
begin
  Result := StandardPainterTooNarrowTabContentWOffsetA[
    IsTabBorderThick(ATabVisibleIndex), GetStandardStyle];
end;

function TcxPCStandardPainter.GetTabsNormalDistance: TcxPCDistance;
begin
  Result := StandardPainterTabsNormalDistanceA[GetStandardStyle];
end;

function TcxPCStandardPainter.GetTabsPosition(
  NavigatorButtons: TcxPCNavigatorBut

⌨️ 快捷键说明

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