cxpcpainters.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,694 行 · 第 1/5 页

PAS
1,694
字号
  ATab: TcxTab;
begin
  Result := TabsPainterContentWOffsetA[IsTabBorderThick(ATabVisibleIndex),
    ParentInfo.Rotate];
  ATab := ParentInfo.VisibleTabs[ATabVisibleIndex];
  if ATab.PaintingPositionIndex in [3, 6, 11] then
    ExchangeValues(Result.Left, Result.Right);
//  if ParentInfo.Rotate and (ATab.Caption <> '') then
//  begin
//    ACorrection := 12;
//    if ATab.IsMainTab then
//      Inc(ACorrection, 3);
//    ACorrection := (ACorrection - Result.Left - Result.Right) div 2;
//    if GetTabBaseImageSize.cx = 0 then
//      Inc(Result.Left, ACorrection);
//    Inc(Result.Right, ACorrection);
//  end;
end;

procedure TcxPCTabsPainter.GetTabNativePartAndState(ATabVisibleIndex: Integer;
  out PartId, StateId: Integer);
type
  TcxTabPositionWithinRow = (tprLeftMost, tprMiddle, tprRightMost);
const
  ATabNativePartA: array[Boolean, TcxTabPositionWithinRow] of Integer = (
    (TABP_TABITEMLEFTEDGE, TABP_TABITEM, TABP_TABITEMRIGHTEDGE),
    (TABP_TOPTABITEMLEFTEDGE, TABP_TOPTABITEM, TABP_TOPTABITEMRIGHTEDGE)
  );
var
  ALineIndexBoundsA: TcxPCLineIndexBoundsArray;
  ATab: TcxTab;
  ATabPositionWithinRow: TcxTabPositionWithinRow;
begin
  ATab := ParentInfo.VisibleTabs[ATabVisibleIndex];
  InitializeLineBoundsArray(ParentControl, ALineIndexBoundsA);

  if ParentInfo.MultiLine and not ParentInfo.RaggedRight then
  begin
    if ParentInfo.IsTabsContainer then
      ATabPositionWithinRow := tprMiddle
    else
      if (ALineIndexBoundsA[ATab.VisibleRow].Right = ATab.VisibleIndex) then
        ATabPositionWithinRow := tprRightMost
      else
        if ALineIndexBoundsA[ATab.VisibleRow].Left = ATab.VisibleIndex then
          ATabPositionWithinRow := tprLeftMost
        else
          ATabPositionWithinRow := tprMiddle;
  end
  else
    if ParentInfo.IsTabsContainer then
      ATabPositionWithinRow := tprMiddle
    else
      if ALineIndexBoundsA[ATab.VisibleRow].Left = ATab.VisibleIndex then
        ATabPositionWithinRow := tprLeftMost
      else
        if ATab.VisibleIndex = ParentControl.Tabs.VisibleTabsCount - 1 then
          ATabPositionWithinRow := tprRightMost
        else
          ATabPositionWithinRow := tprMiddle;

  // to work like standard PageControl
  if not ParentInfo.MultiLine or ParentInfo.RaggedRight then
    if ATab.IsMainTab and (ATabPositionWithinRow = tprRightMost) then
      ATabPositionWithinRow := tprMiddle;

  PartId := ATabNativePartA[ATab.IsMainTab, ATabPositionWithinRow];
  StateId := GetTabNativeState(ATabVisibleIndex);
end;

function TcxPCTabsPainter.GetTabsContainerOffsets: TRect;
begin
  Result := Rect(TabsContainerOffset, TabsContainerOffset, TabsContainerOffset, 0);
end;

function TcxPCTabsPainter.GetTabsPosition(
  NavigatorButtons: TcxPCNavigatorButtons): TcxPCTabsPosition;

var
  NormalTabsRectCorrection: TRect;

  procedure DoHardCalculation;
  var
    AButtonsWidth: Integer;
    ATabsContainerOffset: TRect;
  begin
    AButtonsWidth := CalculateButtonsRegionWidth(NavigatorButtons);
    ATabsContainerOffset := cxEmptyRect;
    if ParentInfo.IsTabsContainer then
      ATabsContainerOffset := GetTabsContainerOffsets;

    NormalTabsRectCorrection := RotateRect(Rect(0, 2 + ATabsContainerOffset.Top, 0, 0), ParentInfo.TabPosition);
    ExtendRect(Result.ExtendedTabsRect, RotateRect(Rect(0, ATabsContainerOffset.Top, 0, 0), ParentInfo.TabPosition));
    with ParentInfo do
    begin
      if TabPosition in [tpTop, tpBottom] then
      begin
        if MultiLine or (NavigatorButtons = []) then
        begin
          Result.ExtendedTabsRect.Left := ATabsContainerOffset.Left;
          Result.ExtendedTabsRect.Right := Width - ATabsContainerOffset.Left;
          NormalTabsRectCorrection.Left := 2 + ATabsContainerOffset.Left;
          NormalTabsRectCorrection.Right := 2 + ATabsContainerOffset.Left;
        end
        else
        begin
          if NavigatorPosition in [npLeftTop, npLeftBottom] then
          begin
            Result.ExtendedTabsRect.Left := AButtonsWidth;
            Result.ExtendedTabsRect.Right := Width - ATabsContainerOffset.Left;
          end
          else
          begin
            Result.ExtendedTabsRect.Left := ATabsContainerOffset.Left;
            Result.ExtendedTabsRect.Right := Width - AButtonsWidth;
          end;
          NormalTabsRectCorrection.Left := Result.ExtendedTabsRect.Left + 2;
          NormalTabsRectCorrection.Right := Width - Result.ExtendedTabsRect.Right + 2;
        end;
        Result.NormalRowWidth := Width - NormalTabsRectCorrection.Left - NormalTabsRectCorrection.Right;
      end
      else
      begin
        if MultiLine or (NavigatorButtons = []) then
        begin
          Result.ExtendedTabsRect.Top := ATabsContainerOffset.Left;
          Result.ExtendedTabsRect.Bottom := Height - ATabsContainerOffset.Left;
          NormalTabsRectCorrection.Top := 2 + ATabsContainerOffset.Left;
          NormalTabsRectCorrection.Bottom := 2 + ATabsContainerOffset.Left;
        end
        else
        begin
          if NavigatorPosition in [npLeftTop, npRightTop] then
          begin
            Result.ExtendedTabsRect.Top := AButtonsWidth;
            Result.ExtendedTabsRect.Bottom := Height - ATabsContainerOffset.Left;
          end
          else
          begin
            Result.ExtendedTabsRect.Top := ATabsContainerOffset.Left;
            Result.ExtendedTabsRect.Bottom := Height - AButtonsWidth;
          end;
          NormalTabsRectCorrection.Top := Result.ExtendedTabsRect.Top + 2;
          NormalTabsRectCorrection.Bottom := Height - Result.ExtendedTabsRect.Bottom + 2;
        end;
        Result.NormalRowWidth := Height - NormalTabsRectCorrection.Top - NormalTabsRectCorrection.Bottom;
      end;
    end;
  end;

begin
  with Result do
  begin
    ExtendedTabsRect := GetControlRect(ParentControl);
    NormalTabsRect := ExtendedTabsRect;

    DoHardCalculation;

    cxGraphics.ExtendRect(NormalTabsRect, NormalTabsRectCorrection);

    ExtendedTopOrLeftTabsRectBottomOrRightBorderOffset := 0;
    ExtendedBottomOrRightTabsRectTopOrLeftBorderOffset := 0;
    if ParentInfo.TabPosition in [tpTop, tpLeft] then
      ExtendedTopOrLeftTabsRectBottomOrRightBorderOffset := 1
    else
      ExtendedBottomOrRightTabsRectTopOrLeftBorderOffset := -1;
    MinDistanceBetweenTopOrLeftAndBottomOrRightExtendedTabsRects := 0;
  end;

  CalculateButtonsRegion(NavigatorButtons);
end;

function TcxPCTabsPainter.GetTooNarrowTabContentWOffset(
  ATabVisibleIndex: Integer): TcxPCWOffset;
begin
  Result := GetTabContentWOffset(ATabVisibleIndex);
end;

function TcxPCTabsPainter.InternalCalculateTabNormalHeight: Integer;
begin
  if ParentInfo.Rotate then
    Result := inherited InternalCalculateTabNormalHeight - 2
  else
    Result := inherited InternalCalculateTabNormalHeight - 3;
end;

procedure TcxPCTabsPainter.InternalPrepareOutTabImageAndTextData(
  ATabVisibleIndex: Integer; var AImageRect, ATextRect: TRect);
var
  ATab: TcxTab;
begin
  ATab := ParentInfo.VisibleTabs[ATabVisibleIndex];
  if IsNativePainting and ATab.IsMainTab and (ATab.PaintingPositionIndex in [5, 7, 10]) then
  begin
    OffsetRect(AImageRect, 0, 1);
    OffsetRect(ATextRect, 0, 1);
  end;
  inherited InternalPrepareOutTabImageAndTextData(ATabVisibleIndex, AImageRect,
    ATextRect);
end;

procedure TcxPCTabsPainter.InvalidateTabRect(ATabVisibleIndex: Integer);
var
  ATab: TcxTab;
  R: TRect;
begin
  ATab := ParentInfo.VisibleTabs[ATabVisibleIndex];
  R := ATab.VisibleRect;
  R := GetExtendedRect(R, Rect(0, 0, 0, -1), ATab.PaintingPosition);
  ParentControl.InvalidateRect(R, False);
end;

function TcxPCTabsPainter.IsNativePainting: Boolean;
begin
  if csDestroying in ParentControl.ComponentState then
    Result := False
  else
    Result := ParentControl.LookAndFeel.NativeStyle and
      AreVisualStylesAvailable and (OpenTheme(totTab) <> TC_NONE);
end;

function TcxPCTabsPainter.IsOverTab(TabVisibleIndex: Integer; X, Y: Integer): Boolean;
begin
  // TODO
  Result := True;
end;

function TcxPCTabsPainter.NeedShowFrame: Boolean;
begin
  Result := True;
end;

procedure TcxPCTabsPainter.Paint;
begin
{  if IsNativePainting then
  begin
    FMDC := 0;
    FPrevMDCBitmap := 0;
    try
      FMDC := CreateCompatibleDC(ParentInfo.Canvas.Handle);
      FPrevMDCBitmap := SelectObject(FMDC,
        CreateCompatibleBitmap(ParentInfo.Canvas.Handle, ParentControl.Width,
        ParentControl.Height));

      PrepareBackgroundBitmap;
      inherited Paint;
    finally
      if FPrevMDCBitmap <> 0 then
        DeleteObject(SelectObject(FMDC, FPrevMDCBitmap));
      if FMDC <> 0 then
        DeleteDC(FMDC);
    end;
  end
  else}
    inherited Paint;
end;

procedure TcxPCTabsPainter.PaintButton(Button: TcxPCNavigatorButton;
  const ButtonRect: TRect);
const
  AArrowButtonPartIdMap: array [TcxPCArrow] of Integer = (SPNP_UP, SPNP_DOWN,
    SPNP_DOWNHORZ, SPNP_UPHORZ);
  AArrowButtonStateIdMap: array [TcxPCArrow, TcxPCNavigatorButtonState] of Integer = (
    (UPS_NORMAL, UPS_PRESSED, UPS_HOT, UPS_DISABLED),
    (DNS_NORMAL, DNS_PRESSED, DNS_HOT, DNS_DISABLED),
    (DNHZS_NORMAL, DNHZS_PRESSED, DNHZS_HOT, DNHZS_DISABLED),
    (UPHZS_NORMAL, UPHZS_PRESSED, UPHZS_HOT, UPHZS_DISABLED)
  );
  ACloseButtonStateIdMap: array [TcxPCNavigatorButtonState] of Integer =
    (CBS_NORMAL, CBS_PUSHED, CBS_HOT, CBS_DISABLED);
var
  AArrow: TcxPCArrow;
  APartId, AStateId: Integer;
  ATheme: TdxTheme;
begin
  if IsNativePainting then
  begin
    if Button = nbClose then
    begin
      ATheme := OpenTheme(totWindow);
      APartId := WP_SMALLCLOSEBUTTON;
      AStateId := ACloseButtonStateIdMap[ParentInfo.NavigatorButtonsState[Button]];
    end
    else
    begin
      ATheme := OpenTheme(totSpin);
      AArrow := GetButtonArrow(Button);
      APartId := AArrowButtonPartIdMap[AArrow];
      AStateId := AArrowButtonStateIdMap[AArrow, ParentInfo.NavigatorButtonsState[Button]];
    end;
    if ParentControl.ParentBackground and IsThemeBackgroundPartiallyTransparent(ATheme, APartId, AStateId) then
      cxDrawThemeParentBackground(ParentControl, ParentInfo.Canvas, ButtonRect)
    else
    begin
      ParentInfo.Canvas.Brush.Color := ParentInfo.Color;
      ParentInfo.Canvas.FillRect(ButtonRect);
    end;
    DrawThemeBackground(ATheme, ParentInfo.Canvas.Handle, APartId, AStateId,
      ButtonRect);
  end
  else
    inherited PaintButton(Button, ButtonRect);
end;

procedure TcxPCTabsPainter.PaintClientArea;
begin
  if IsNativePainting then
    InternalPaintFrame(ParentInfo.Canvas.Canvas)
  else
    inherited PaintClientArea;
end;

procedure TcxPCTabsPainter.PaintFrame;
var
  AFrameRect: TRect;
begin
  inherited PaintFrame;
  if ParentInfo.IsTabsContainer then
  begin
    AFrameRect := GetFrameRect;
    InflateRect(AFrameRect, -GetFrameWidth, -GetFrameWidth);
    ParentInfo.Canvas.Brush.Color := cxPCTabBodyColor;
    ParentInfo.Canvas.FillRect(AFrameRect);
  end;
end;

procedure TcxPCTabsPainter.PaintTabShape(ATab: TcxTab; ATabVisibleIndex: Integer);

  procedure PaintNativeFrame;
  var
    ABitmap: TBitmap;
    ATab: TcxTab;
    ATabRect: TRect;
  begin
    ATab := ParentInfo.VisibleTabs[ATabVisibleIndex];
    ATabRect := ATab.FullRect;
    if ATab.IsMainTab then
      ATabRect := GetExtendedRec

⌨️ 快捷键说明

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