cxpcpainters.pas

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

PAS
1,694
字号
    B := GetBValue(ARGBColor);

    AMinColorComponent := R;
    if G < AMinColorComponent then
      AMinColorComponent := G;
    if B < AMinColorComponent then
      AMinColorComponent := B;
  end;

  function GetBrightness: Integer;
  begin
    Result := R;
    if G > Result then
      Result := G;
    if B > Result then
      Result := B;
  end;

  function GetSaturation(ABrightness: Extended): Extended;
  begin
    if ABrightness = 0 then
      Result := 0
    else
      Result := 100 - AMinColorComponent * 100 / ABrightness;
  end;

  function GetHue(ABrightness: Integer; ASaturation: Extended): Extended;
  begin
    if ASaturation = 0 then
      Result := 0 // ???
    else
    begin
      if R = ABrightness then
        Result := (G - B) * 60 / (ABrightness - AMinColorComponent)
      else if G = ABrightness then
        Result := (B - R) * 60 / (ABrightness - AMinColorComponent) + 120
      else
        Result := (R - G) * 60 / (ABrightness - AMinColorComponent) + 240;
      if Result < 0 then
        Result := Result + 360;
    end;
  end;

var
  ABrightness: Integer;
begin
  PreCalculate;

  ABrightness := GetBrightness;
  Brightness := ABrightness * 100 / 255;
  Saturation := GetSaturation(ABrightness);
  Hue := GetHue(ABrightness, Saturation);
end;

function Light(AColor: TColor; APercentage: Byte): TColor;
var
  AHue, ASaturation, ABrightness: Extended;
begin
  RGBToHSB(ColorToRGB(AColor), AHue, ASaturation, ABrightness);
  ABrightness := ABrightness * (100 + APercentage) / 100;
  if ABrightness > 100 then
    ABrightness := 100;
  Result := HSBToRGB(AHue, ASaturation, ABrightness);
end;

procedure PrepareOneNoteStyleColors;
const
  AColors: array[TOffice11Scheme, 0..5] of TColor = (
    (clBtnShadow, clBtnShadow, clWhite, $6A240A, clBtnFace, clBtnFace),
    ($9C613B, $9A3500, clWhite, $800000, clWhite, $F1A675),
    ($588060, $6B7760, clWhite, $385D3F, clWhite, $8CC2B0),
    ($947C7C, $927476, clWhite, $6F4B4B, clWhite, $CEB9BA)
  );
var
  AColorScheme: TOffice11Scheme;
begin
  AColorScheme := GetOffice11Scheme;
  OneNoteMainTabBorderColor := AColors[AColorScheme, 0];
  OneNoteTabBorderColor := AColors[AColorScheme, 1];
  OneNoteMainTabInnerBorderColor := AColors[AColorScheme, 2];
  OneNoteTabHotBorderColor := AColors[AColorScheme, 3];
  OneNoteTabInnerBorderColor1 := AColors[AColorScheme, 4];
  OneNoteTabInnerBorderColor2 := AColors[AColorScheme, 5];
end;

procedure RotateTabsDistance(var ADistance: TcxPCDistance);
var
  A: Integer;
begin
  A := ADistance.dw;
  ADistance.dw := ADistance.dh;
  ADistance.dh := A;
end;

function Size(cx, cy: Integer): TSize;
begin
  Result.cx := cx;
  Result.cy := cy;
end;

procedure TcxPCTabsPainter.CorrectTabRect(TabVisibleIndex: Integer;
  var TabRectCorrection: TcxPCRectCorrection);
const
  TabRectCorrectionA: array[TcxTabPosition] of TcxPCRectCorrection = (
    (dLeft: -2; dTop: -2; dRight: 2; dBottom: 1),
    (dLeft: -2; dTop: -1; dRight: 2; dBottom: 2),
    (dLeft: -2; dTop: -2; dRight: 1; dBottom: 2),
    (dLeft: -1; dTop: -2; dRight: 2; dBottom: 2)
  );
begin
  inherited CorrectTabRect(TabVisibleIndex, TabRectCorrection);
  if TabVisibleIndex = ParentInfo.MainTabVisibleIndex then
    TabRectCorrection := TabRectCorrectionA[ParentInfo.VisibleTabs[TabVisibleIndex].PaintingPosition];
end;

procedure TcxPCTabsPainter.DrawNativeTabBackground(DC: HDC; ATab: TcxTabSheet);
var
  ATheme: TdxTheme;
  R: TRect;
begin
  R := GetDisplayRect;
  InflateRect(R, StandardPainterTabControlFrameBorderWidth,
    StandardPainterTabControlFrameBorderWidth);
  OffsetRect(R, -ATab.Left, -ATab.Top);
  ATheme := OpenTheme(totTab);
  DrawThemeBackground(ATheme, DC, TABP_PANE, 0, R);
end;

function TcxPCTabsPainter.GetButtonContentPosition(
  AButton: TcxPCNavigatorButton): TPoint;
begin
  Result := Get3DButtonContentPosition(AButton);
end;

function TcxPCTabsPainter.GetButtonHeight: Integer;
begin
  if not IsNativePainting then
    Result := inherited GetButtonHeight
  else
    Result := StandardNativePainterButtonHeight;              
end;

function TcxPCTabsPainter.GetButtonsRegionHOffset: Integer;
begin
  Result := 0;
  if ParentInfo.IsTabsContainer then
    Result := TabsContainerOffset;
end;

function TcxPCTabsPainter.GetButtonsRegionWOffset: Integer;
begin
  Result := 0;
  if ParentInfo.IsTabsContainer then
    Result := TabsContainerOffset;
end;

function TcxPCTabsPainter.GetButtonWidth(Button: TcxPCNavigatorButton): Integer;
var
  ASize: TSize;
begin
  if IsNativePainting then
  begin
    Result := StandardNativePainterButtonWidth;
    if Button = nbGoDialog then
    begin
      if GetThemePartSize(OpenTheme(totSpin), ParentInfo.Canvas.Handle, SPNP_DOWN,
        DNS_NORMAL, TS_TRUE, ASize) = S_OK then
          Result := ASize.cx;
    end
    (*else
      if Button = nbClose then
      begin
        if GetThemePartSize(OpenTheme(totWindow), ParentInfo.Canvas.Handle, WP_SMALLCLOSEBUTTON,
          CBS_NORMAL, TS_TRUE, ASize) = S_OK then
            if ParentInfo.TabPosition in [tpTop, tpBottom] then
              Result := ASize.cx
            else
              Result := ASize.cy;
      end;*)
  end
  else
    Result := inherited GetButtonWidth(Button);
end;

function TcxPCTabsPainter.GetClientRectOffset: TRect;

  function GetNativeFrameSizeCorrection: TRect;
  var
    R: TRect;
  begin
    R := GetNativeContentOffset;
    case ParentInfo.TabPosition of
      tpLeft:
        Result := Rect(R.Bottom, R.Left, R.Top, R.Right);
      tpTop:
        Result := R;
      tpRight:
        Result := Rect(R.Top, R.Right, R.Bottom, R.Left);
      tpBottom:
        Result := Rect(R.Right, R.Bottom, R.Left, R.Top);
    end;
    Result.Right := -Result.Right;
    Result.Bottom := -Result.Bottom;
  end;

begin
  Result := inherited GetClientRectOffset;
  if IsNativePainting then
  begin
    OffsetRect(Result, -StandardPainterTabControlFrameBorderWidth,
      -StandardPainterTabControlFrameBorderWidth);
    cxGraphics.ExtendRect(Result, GetNativeFrameSizeCorrection);
  end;
  if ParentInfo.IsTabsContainer and not IsNativePainting then
    Inc(Result.Top, TabsContainerBaseWidth - GetFrameWidth);
end;

function TcxPCTabsPainter.GetDisplayRectOffset: TRect;
begin
  Result := inherited GetDisplayRectOffset;
  if not ParentInfo.HideTabs and (ParentInfo.RowCount > 0) then
    Dec(Result.Top);
end;

function TcxPCTabsPainter.GetDrawImageOffset(TabVisibleIndex: Integer): TRect;
begin
  Result := inherited GetDrawImageOffset(TabVisibleIndex);
  if (ParentInfo.VisibleTabs[TabVisibleIndex].PaintingPositionIndex in [5, 7, 10]) then
    Inc(Result.Bottom);
end;

function TcxPCTabsPainter.GetDrawImageWithoutTextWOffset(TabVisibleIndex: Integer): TcxPCWOffset;
begin
  if ParentInfo.Rotate and ParentInfo.VisibleTabs[TabVisibleIndex].IsMainTab then
    Result := TabsPainterDrawImageWithoutTextRotatedMainTabWOffset[ParentInfo.VisibleTabs[TabVisibleIndex].PaintingPositionIndex in [3, 6, 11]]
  else
    Result := inherited GetDrawImageWithoutTextWOffset(TabVisibleIndex);
end;

function TcxPCTabsPainter.GetDrawTextHOffset(TabVisibleIndex: Integer): TRect;
begin
  Result := inherited GetDrawTextHOffset(TabVisibleIndex);
  if (ParentInfo.VisibleTabs[TabVisibleIndex].PaintingPositionIndex in [5, 7, 10]) then
    Inc(Result.Bottom);
  with ParentInfo do
    if VisibleTabs[TabVisibleIndex].IsMainTab and (GetTabRotatedImageSize.cx = 0) then
      Inc(Result.Left, 2);
end;

function TcxPCTabsPainter.GetImageTextDistance(ATabVisibleIndex: Integer): Integer;
//var
//  ACorrection: Integer;
//  ATab: TcxTab;
//  ATabContentWOffset: TcxPCWOffset;
begin
  Result := inherited GetImageTextDistance(ATabVisibleIndex);
//  ATab := ParentInfo.VisibleTabs[ATabVisibleIndex];
//  if ParentInfo.Rotate and (ATab.Caption <> '') then
//  begin
//    ATabContentWOffset := TabsPainterContentWOffsetA[IsTabBorderThick(ATabVisibleIndex),
//      ParentInfo.Rotate];
//    if ATab.PaintingPositionIndex in [3, 6, 11] then
//      ExchangeValues(ATabContentWOffset.Left, ATabContentWOffset.Right);
//    ACorrection := 12;
//    if ATab.IsMainTab then
//      Inc(ACorrection, 3);
//    ACorrection := (ACorrection - ATabContentWOffset.Left - ATabContentWOffset.Right) div 2;
//    Inc(Result, ACorrection);
//  end;
end;

{ TcxPCTabsPainter }

class function TcxPCTabsPainter.GetStandardStyle: TcxPCStandardStyle;
begin
  Result := tsTabs;
end;

class function TcxPCTabsPainter.GetStyleID: TcxPCStyleID;
begin
  Result := cxPCTabsStyle;
end;

class function TcxPCTabsPainter.GetStyleName: TCaption;
begin
  Result := 'Tabs';
end;

class function TcxPCTabsPainter.HasLookAndFeel(ALookAndFeel: TcxLookAndFeel): Boolean;
begin
  Result := ALookAndFeel.GetAvailablePainter([totTab]).LookAndFeelStyle in
    [lfsStandard, lfsNative];
end;

class function TcxPCTabsPainter.IsDefault(ALookAndFeel: TcxLookAndFeel): Boolean;
begin
  Result := ALookAndFeel.NativeStyle;
end;

function TcxPCTabsPainter.GetTabBodyColor(TabVisibleIndex: Integer): TColor;
var
  ATab: TcxTab;
begin
  ATab := ParentInfo.VisibleTabs[TabVisibleIndex];
  if ATab.Highlighted then
    Result := HighlightedTabBodyColor
  else
  begin
    Result := GetTabColor(TabVisibleIndex);
    if Result = clDefault then
      Result := cxPCTabBodyColor;
  end;
end;

function TcxPCTabsPainter.GetTabClipRgn(ATabVisibleIndex: Integer): TcxRegion;
var
  ATab: TcxTab;
  ATabRect: TRect;
begin
  ATab := ParentInfo.VisibleTabs[ATabVisibleIndex];

  ATabRect := ATab.VisibleRect;
  if ATab.IsMainTab then
    ATabRect := GetExtendedRect(ATab.VisibleRect, Rect(0, 0, 0, -1), ATab.PaintingPosition);

  Result := TcxRegion.Create(ATabRect);
end;

function TcxPCTabsPainter.GetTabClipRgnOperation(ATabVisibleIndex: Integer): TcxRegionOperation;
begin
  if not ParentInfo.VisibleTabs[ATabVisibleIndex].IsMainTab then
    Result := roIntersect
  else
    Result := roSet;
end;

function TcxPCTabsPainter.GetTabContentWOffset(ATabVisibleIndex: Integer): TcxPCWOffset;
var
//  ACorrection: Integer;

⌨️ 快捷键说明

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