cxgroupbox.pas

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

PAS
1,801
字号
  InternalDrawBackground(ACanvas);
  DrawCaption(ACanvas);

  if not Edit.IsPanelStyle then
    ACanvas.ExcludeClipRect(CaptionRect);

  DrawFrame(ACanvas, GetFrameBounds);

  if Edit.IsDBEditPaintCopyDrawing then
    DrawButtons(ACanvas);
end;

function TcxGroupBoxViewInfo.GetCaptionRectIndent: TRect;
var
  ACaptionPosition: TcxGroupBoxCaptionPosition;
  R1: TRect;
begin
  Result := cxNullRect;
  if Assigned(Edit) and Assigned(Edit.Style.LookAndFeel.SkinPainter) and not Edit.IsPanelStyle then
  begin
    ACaptionPosition := cxGroupBoxAlignment2GroupBoxCaption(Edit.Alignment);
    R1 := Edit.Style.LookAndFeel.SkinPainter.GroupBoxBorderSize(True, ACaptionPosition);
    case ACaptionPosition of
      cxgpTop:
        Result.Top := R1.Top + R1.Bottom;
      cxgpBottom:
        Result.Bottom := R1.Top + R1.Bottom;
      cxgpLeft:
        Result.Left := R1.Right + R1.Left;
      cxgpRight:
        Result.Right := R1.Right + R1.Left;
    end;
  end;
end;

function TcxGroupBoxViewInfo.GetControlRect: TRect;
begin
  Result := cxContainer.GetControlRect(Edit);
end;

function TcxGroupBoxViewInfo.GetEdit: TcxCustomGroupBox;
begin
  Result := TcxCustomGroupBox(FEdit);
end;

function TcxGroupBoxViewInfo.CalcOffsetBoundsForPanel: TRect;
var
  ABorderSize: TRect;
  ACaptionIndentRect: TRect;
  ABorderWidth: Integer;
begin
  ABorderWidth := GetContainerBorderWidth(TcxContainerBorderStyle(BorderStyle));
  ABorderSize := Rect(ABorderWidth, ABorderWidth, ABorderWidth, ABorderWidth);
  ACaptionIndentRect := cxEmptyRect;
  case Edit.Alignment of
    alTopLeft, alLeftTop, alLeftCenter, alLeftBottom, alBottomLeft:
      ACaptionIndentRect.Left := Edit.GetHorizontalCaptionIndent;
    alTopRight, alRightTop, alRightCenter, alRightBottom, alBottomRight:
      ACaptionIndentRect.Right := Edit.GetHorizontalCaptionIndent;
  end;
  case Edit.Alignment of
    alLeftTop, alTopLeft, alTopCenter, alTopRight, alRightTop:
      ACaptionIndentRect.Top := Edit.GetVerticalCaptionIndent;
    alLeftBottom, alBottomLeft, alBottomCenter, alBottomRight, alRightBottom:
      ACaptionIndentRect.Bottom := Edit.GetVerticalCaptionIndent;
  end;
  Result.Left := ABorderSize.Left + ACaptionIndentRect.Left;
  Result.Top := ABorderSize.Top + ACaptionIndentRect.Top;
  Result.Right := ABorderSize.Right + ACaptionIndentRect.Right;
  Result.Bottom := ABorderSize.Bottom + ACaptionIndentRect.Bottom;
end;

procedure TcxGroupBoxViewInfo.CalcBoundsForPanel;
begin
  if Edit.IsPanelStyle then
  begin
    CalcTextBoundsForPanel;
    AdjustTextBoundsForPanel;
    CaptionRect := TextRect;
    AdjustCaptionBoundsForPanel;
  end;
end;

function TcxGroupBoxViewInfo.GetFrameBounds: TRect;
var
  ABorderWidth: Integer;
begin
  ABorderWidth := GetContainerBorderWidth(TcxContainerBorderStyle(BorderStyle));
  if Edit.IsPanelStyle then
    Result := GetBoundsForPanel
  else
  begin
    Result := BorderRect;
    ExtendRectByBorders(Result, ABorderWidth, Edges);
  end;
end;

procedure TcxGroupBoxViewInfo.CalcTextBoundsForPanel;
var
  AFlag: Cardinal;
  ACanvas: TcxCanvas;
begin
  AFlag := CXTO_CALCRECT;
  if Edit.PanelStyle.WordWrap then
    AFlag := AFlag or CXTO_WORDBREAK;
  TextRect := CalcCorrectionBoundsForPanel;
  ACanvas := TcxCanvas.Create(Edit.Canvas.Canvas);
  try
    Edit.AdjustCanvasFontSettings(ACanvas);
    cxTextOut(ACanvas.Handle, PChar(Edit.FVisibleCaption), TextRect, AFlag);
  finally
    FreeAndNil(ACanvas);
  end;
end;

function TcxGroupBoxViewInfo.CalcCorrectionBoundsForPanel: TRect;
var
  AOffsetRect: TRect;
begin
  AOffsetRect := CalcOffsetBoundsForPanel;
  Result := GetBoundsForPanel;
  with AOffsetRect do
  begin
    Inc(Result.Left, Left);
    Inc(Result.Top, Top);
    Dec(Result.Right, Right);
    Dec(Result.Bottom, Bottom);
  end;
end;

procedure TcxGroupBoxViewInfo.AdjustTextBoundsForPanel;
var
  ATextWidth, ATextHeight: Integer;
  R: TRect;
begin
  with TextRect do
  begin
    ATextWidth := Right - Left;
    ATextHeight := Bottom - Top;
  end;
  R := CalcCorrectionBoundsForPanel;
  OffsetRect(TextRect, R.Left - TextRect.Left, R.Top - TextRect.Top);
  case Edit.Alignment of
    alTopCenter, alBottomCenter, alCenterCenter:
      OffsetRect(TextRect, (R.Right - R.Left - ATextWidth - TextRect.Left) div 2, 0);
    alTopRight, alRightTop, alRightCenter, alRightBottom, alBottomRight:
      OffsetRect(TextRect, R.Right - ATextWidth - TextRect.Left, 0);
  end;
  case Edit.Alignment of
    alLeftCenter, alRightCenter, alCenterCenter:
      OffsetRect(TextRect, 0, (R.Bottom - R.Top - ATextHeight - TextRect.Top) div 2);
    alLeftBottom, alBottomLeft, alBottomCenter, alBottomRight, alRightBottom:
      OffsetRect(TextRect, 0, R.Bottom - ATextHeight - TextRect.Top);
  end;
end;

procedure TcxGroupBoxViewInfo.AdjustCaptionBoundsForPanel;

  procedure ChangeIfLess(var AInValue, AChangeValue: Integer);
  begin
    AInValue := Max(AChangeValue, AInValue);
  end;
  procedure ChangeIfGreat(var AInValue, AChangeValue: Integer);
  begin
    AInValue := Min(AChangeValue, AInValue);
  end;

var
  R: TRect;
begin
  R := CalcCorrectionBoundsForPanel;
  ChangeIfGreat(CaptionRect.Right, R.Right);
  ChangeIfGreat(CaptionRect.Bottom, R.Bottom);
  ChangeIfLess(CaptionRect.Left, R.Left);
  ChangeIfLess(CaptionRect.Top, R.Top);
end;

procedure TcxGroupBoxViewInfo.DrawHorizontalTextCaption(ACanvas: TcxCanvas);
begin
  cxDrawText(ACanvas.Handle, Edit.FVisibleCaption, TextRect, Edit.GetCaptionDrawingFlags);
end;

procedure TcxGroupBoxViewInfo.DrawVerticalTextCaption(ACanvas: TcxCanvas);
var
  AFlags, X, Y: Integer;
begin
  AFlags := ETO_CLIPPED;
  if Edit.FAlignment in [alLeftTop, alLeftCenter, alLeftBottom] then
  begin
    X := TextRect.Left;
    Y := TextRect.Bottom - 1;
  end
  else
  begin
    X := TextRect.Right;
    Y := TextRect.Top + 1;
  end;
  cxExtTextOut(ACanvas.Handle, Edit.FVisibleCaption, Point(X, Y), TextRect, AFlags);
end;

procedure TcxGroupBoxViewInfo.DrawFrame(ACanvas: TcxCanvas; R: TRect);
var
  ABackgroundRect: TRect;
  ANativeState: Integer;
  ATheme: TdxTheme;
begin
  if NativeStyle then
  begin
    if Edit.IsPanelStyle then
    begin
      if BorderStyle <> ebsNone then
        Edit.LookAndFeelPainter.DrawBorder(ACanvas, GetBoundsForPanel);
    end
    else
    begin
      if BorderStyle <> ebsNone then
      begin
        ATheme := OpenTheme(totButton);
        ANativeState := cxNativeState[Enabled];
        ABackgroundRect := GetThemeBackgroundRect(ACanvas);
        DrawThemeBackground(ATheme, ACanvas.Handle, BP_GROUPBOX, ANativeState,
          ABackgroundRect);
      end;
    end;
  end
  else
  begin
    if not Assigned(Painter) then
    begin
      case BorderStyle of
        ebsSingle: ACanvas.FrameRect(R, BorderColor, 1, Edit.ActiveStyle.Edges, True);
        ebsThick: ACanvas.FrameRect(R, BorderColor, 2, Edit.ActiveStyle.Edges, True);
        ebsFlat:
          begin
            ACanvas.FrameRect(R, clBtnShadow, 1, Edit.ActiveStyle.Edges, True);
            InflateRect(R, -1, -1);
            ACanvas.FrameRect(R, clBtnHighlight, 1, Edit.ActiveStyle.Edges, True);
        end;
        ebs3D:
          if Edit.Ctl3D then
          begin
            Dec(R.Right);
            Dec(R.Bottom);
            ACanvas.FrameRect(R, clBtnShadow, 1, Edit.ActiveStyle.Edges, True);
            OffsetRect(R, 1, 1);
            ACanvas.FrameRect(R, clBtnHighlight, 1, Edit.ActiveStyle.Edges, True);
          end
        else
        begin
          ACanvas.FrameRect(R, clWindowFrame, 1, Edit.ActiveStyle.Edges, True);
          InflateRect(R, -1, -1);
          ACanvas.FrameRect(R, BackgroundColor, 1, Edit.ActiveStyle.Edges, True);
        end;
      end;
    end;
  end;
end;

function TcxGroupBoxViewInfo.GetThemeBackgroundRect(
  ACanvas: TcxCanvas): TRect;
begin
  Result := ControlRect;
  if not Edit.IsPanelStyle then
    case Edit.FAlignment of
      alTopLeft, alTopCenter, alTopRight:
        Result.Top := ACanvas.TextHeight('Qq') div 2;
      alBottomLeft, alBottomCenter, alBottomRight:
        Dec(Result.Bottom, ACanvas.TextHeight('Qq') div 2);
      alLeftTop, alLeftCenter, alLeftBottom:
        Result.Left := ACanvas.TextHeight('Qq') div 2;
      alRightTop, alRightCenter, alRightBottom:
        Dec(Result.Right, ACanvas.TextHeight('Qq') div 2);
    end;
end;

function TcxGroupBoxViewInfo.GetBoundsForPanel: TRect;
begin
  Result := Bounds;
  if not NativeStyle and (Painter = nil) then
    if Edit.HasShadow then
    begin
      Dec(Result.Right, cxContainerShadowWidth);
      Dec(Result.Bottom, cxContainerShadowWidth);
    end;
end;

procedure TcxGroupBoxViewInfo.DrawUsualBackground(ACanvas: TcxCanvas);
begin
  if Edit.HasShadow then
    DrawContainerShadow(ACanvas, GetFrameBounds);
  if not Transparent then
  begin
    if Edit.IsTransparent then
      cxDrawTransparentControlBackground(Edit, ACanvas, ControlRect)
    else
      cxEditFillRect(ACanvas, ControlRect, BackgroundColor);
  end;
end;

procedure TcxGroupBoxViewInfo.DrawNativeBackground(ACanvas: TcxCanvas;
  const ACaptionRect: TRect);
begin
  if Edit.IsPanelStyle then
    DrawNativePanelBackground(ACanvas, ACaptionRect)
  else
    DrawNativeGroupBoxBackground(ACanvas);
end;

procedure TcxGroupBoxViewInfo.DrawNativeGroupBoxBackground(
  ACanvas: TcxCanvas);
var
  AClipRgn: TcxRegion;
  ANativeState: Integer;
  ATheme: TdxTheme;
begin
  AClipRgn := ACanvas.GetClipRegion;
  try
    ATheme := OpenTheme(totButton);
    ANativeState := cxNativeState[Enabled];
    if Edit.IsTransparent then
      cxDrawTransparentControlBackground(Edit, ACanvas, Bounds)
    else
      if Edit.IsNativeBackground and
          IsThemeBackgroundPartiallyTransparent(ATheme, BP_GROUPBOX, ANativeState) then
      begin
        cxDrawThemeParentBackground(Edit, ACanvas, Bounds);
        ACanvas.Canvas.Refresh; // SC-B31215
      end
      else
        cxEditFillRect(ACanvas.Handle, Bounds, GetSolidBrush(ACanvas, BackgroundColor));
  finally
    ACanvas.SetClipRegion(AClipRgn, roSet);
  end;
end;

procedure TcxGroupBoxViewInfo.DrawNativePanelBackground(
  ACanvas: TcxCanvas; const ACaptionRect: TRect);
var
  ABackgroundRect: TRect;
begin
  ABackgroundRect := GetBoundsForPanel;
  if BorderStyle <> ebsNone then
    InflateRect(ABackgroundRect, -Edit.LookAndFeelPainter.BorderSize, -Edit.LookAndFeelPainter.BorderSize);

  if Edit.IsTransparent then
  begin
    ACanvas.SaveClipRegion;
    try
      ACanvas.SetClipRegion(TcxRegion.Create(ABackgroundRect), roIntersect);
      Edit.LookAndFeelPainter.DrawPanelBackground(ACanvas, Edit, GetBoundsForPanel);
    finally
      ACanvas.RestoreClipRegion;
    end;
  end
  else
    if Edit.LookAndFeel.NativeStyle then
      if Edit.IsNativeBackground then
        cxDrawThemeParentBackground(Edit, ACanvas, ABackgroundRect)
      else
        Edit.LookAndFeelPainter.DrawPanelBackground(ACanvas, Edit, ABackgroundRect, BackgroundColor)
    else

⌨️ 快捷键说明

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