cxgroupbox.pas

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

PAS
1,801
字号
      if Edit.LookAndFeel.Kind = lfOffice11 then
        DrawOffice11PanelBackground(ACanvas, ABackgroundRect);
end;

procedure TcxGroupBoxViewInfo.DrawOffice11PanelBackground(ACanvas: TcxCanvas; const R: TRect);
begin
  with Edit.LookAndFeelPainter do
    case Edit.PanelStyle.OfficeBackgroundKind of
      pobkGradient:
        DrawPanelBackground(ACanvas, Edit, R, dxOffice11ToolbarsColor1, dxOffice11ToolbarsColor2);
      pobkOffice11Color:
        DrawPanelBackground(ACanvas, Edit, R, GetMiddleRGB(dxOffice11ToolbarsColor1, dxOffice11ToolbarsColor2, 50));
      pobkStyleColor:
        DrawPanelBackground(ACanvas, Edit, R, BackgroundColor);
    end;
end;

procedure TcxGroupBoxViewInfo.InternalDrawBackground(ACanvas: TcxCanvas);
var
  ABounds: TRect;
begin
  if NativeStyle then
    DrawNativeBackground(ACanvas, CaptionRect)
  else
  begin
    ACanvas.SaveClipRegion;
    try
      if Assigned(Painter) then
      begin
        if Edit.IsPanelStyle then
          ABounds := GetBoundsForPanel
        else
          if BorderStyle = ebsNone then
            ABounds := Bounds
          else
            ABounds := BorderRect;
      {$IFDEF DELPHI7}
        if not Edit.DoCustomDrawContentBackground(ACanvas, ABounds, Painter) then
        begin
      {$ENDIF}
          if Edit.IsPanelStyle then
            Painter.DrawPanelContent(ACanvas, ABounds, BorderStyle <> ebsNone)
          else
          begin
            if BorderStyle = ebsNone then
              Painter.DrawGroupBoxBackground(ACanvas, ABounds, ABounds)
            else
            begin
              cxDrawTransparentControlBackground(Edit, ACanvas, ControlRect);
              Painter.DrawGroupBoxContent(ACanvas, ABounds,
                cxGroupBoxAlignment2GroupBoxCaption(Edit.Alignment));
            end;
          end;
      {$IFDEF DELPHI7}
        end;
      {$ENDIF}
      end
      else
        DrawUsualBackground(ACanvas);
    finally
      ACanvas.RestoreClipRegion;
    end;
  end;
end;

{ TcxGroupBoxViewData }

procedure TcxGroupBoxViewData.Calculate(ACanvas: TcxCanvas;
  const ABounds: TRect; const P: TPoint; Button: TcxMouseButton; Shift: TShiftState;
  AViewInfo: TcxCustomEditViewInfo; AIsMouseEvent: Boolean);
var
  AEditViewInfo: TcxGroupBoxViewInfo;
begin
  AEditViewInfo := TcxGroupBoxViewInfo(AViewInfo);
  AEditViewInfo.IsDesigning := IsDesigning;
  inherited Calculate(ACanvas, ABounds, P, Button, Shift, AViewInfo, AIsMouseEvent);

  if not IsInplace then
  begin
    Edit.CalculateCaptionFont;
    Edit.CalculateVisibleCaption;
    CalcRects(ACanvas, AEditViewInfo);
  end;
end;

function TcxGroupBoxViewData.GetBorderColor: TColor;
begin
  if Style.BorderStyle in [ebsUltraFlat, ebsOffice11] then
  begin
    if Enabled then
      Result := GetEditBorderHighlightColor(Style.BorderStyle = ebsOffice11)
    else
      Result := clBtnShadow;
  end
  else
    Result := Style.BorderColor;
end;

function TcxGroupBoxViewData.GetBorderExtentBySkinPainter: TRect;
begin
  Result := cxEmptyRect;
  if bLeft in Style.Edges then
    Result.Left := 1;
  if bTop in Style.Edges then
    Result.Top := 1;
  if bRight in Style.Edges then
    Result.Right := 1;
  if bBottom in Style.Edges then
    Result.Bottom := 1;
end;

function TcxGroupBoxViewData.GetBorderExtent: TRect;
var
  AHeaderSideBorderOffset: Integer;
begin
  if Style.LookAndFeel.SkinPainter = nil then
    Result := inherited GetBorderExtent
  else
    Result := GetBorderExtentBySkinPainter; 
  if not IsInplace and (Edit.FAlignment <> alCenterCenter) and not Edit.IsPanelStyle then
  begin
    cxScreenCanvas.Font := Edit.FCaptionFont;
    AHeaderSideBorderOffset := cxScreenCanvas.TextHeight('Qq') div 2 - 1 +
      cxEditMaxBorderWidth;
    case Edit.FAlignment of
      alTopLeft, alTopCenter, alTopRight:
        Result.Top := AHeaderSideBorderOffset;
      alBottomLeft, alBottomCenter, alBottomRight:
        Result.Bottom := AHeaderSideBorderOffset;
      alLeftTop, alLeftCenter, alLeftBottom:
        Result.Left := AHeaderSideBorderOffset - 1;
      alRightTop, alRightCenter, alRightBottom:
        Result.Right := AHeaderSideBorderOffset - 1;
    end;
  end;
end;

function TcxGroupBoxViewData.GetClientExtent(ACanvas: TcxCanvas;
  AViewInfo: TcxCustomEditViewInfo): TRect;
var
  AHeaderSideClientExtent: Integer;
  ABorderWidth: Integer;
begin
  if IsInplace or (Style.LookAndFeel.SkinPainter = nil) then
    Result := inherited GetBorderExtent
  else
  begin
    if Edit.IsPanelStyle then
      Result := Style.LookAndFeel.SkinPainter.PanelBorderSize
    else
      Result := Style.LookAndFeel.SkinPainter.GroupBoxBorderSize(False,
        cxGroupBoxAlignment2GroupBoxCaption(Edit.Alignment));
    ABorderWidth := Edit.LookAndFeelPainter.BorderSize;
    OffsetRect(Result, ABorderWidth, ABorderWidth);
    if HasShadow then
    begin
      Result.Right := Result.Right + cxEditShadowWidth;
      Result.Bottom := Result.Bottom + cxEditShadowWidth;
    end;
    if HasNonClientArea then
      with TcxGroupBoxViewInfo(AViewInfo) do
      begin
        case cxGroupBoxAlignment2GroupBoxCaption(Edit.Alignment) of
          cxgpTop:
            Inc(Result.Bottom, GetCaptionRectIndent.Top);
          cxgpLeft:
            Inc(Result.Right, GetCaptionRectIndent.Left);
        end;
      end;
  end;

  if not IsInplace and not Edit.IsPanelStyle then
    if Edit.FAlignment <> alCenterCenter then
    begin
      cxScreenCanvas.Font := Edit.FCaptionFont;
      AHeaderSideClientExtent := cxScreenCanvas.TextHeight('Qq') +
        Result.Top + cxEditMaxBorderWidth + 1;
      case Edit.FAlignment of
        alTopLeft, alTopCenter, alTopRight:
          Result.Top := AHeaderSideClientExtent;
        alBottomLeft, alBottomCenter, alBottomRight:
          Result.Bottom := AHeaderSideClientExtent;
        alLeftTop, alLeftCenter, alLeftBottom:
          Result.Left := AHeaderSideClientExtent;
        alRightTop, alRightCenter, alRightBottom:
          Result.Right := AHeaderSideClientExtent;
      end;
    end;
end;

function TcxGroupBoxViewData.HasShadow: Boolean;
begin
  Result := Edit.HasShadow and inherited HasShadow;
end;

class function TcxGroupBoxViewData.IsNativeStyle(ALookAndFeel: TcxLookAndFeel): Boolean;
begin
  Result := AreVisualStylesMustBeUsed(
    ALookAndFeel.NativeStyle or (ALookAndFeel.Kind = lfOffice11), totEdit) and
      (ALookAndFeel.SkinPainter = nil);
end;

function TcxGroupBoxViewData.GetContainerState(const ABounds: TRect;
  const P: TPoint; Button: TcxMouseButton; Shift: TShiftState;
  AIsMouseEvent: Boolean): TcxContainerState;
begin
  if Enabled then
    Result := [csNormal]
  else
    Result := [csDisabled];
end;

function TcxGroupBoxViewData.HasNonClientArea: Boolean;
begin
  Result := not IsInplace and Edit.HasNonClientArea;
end;

function TcxGroupBoxViewData.GetShadowWidth: Integer;
begin
  Result := 0;
  if HasShadow then
    Result := cxContainerShadowWidth;
end;

function TcxGroupBoxViewData.GetCaptionRect(ACanvas: TcxCanvas): TRect;
var
  ACaptionSize: TSize;
begin
  if Edit.FVisibleCaption = '' then
  begin
    Result := cxEmptyRect;
    Exit;
  end;
  Edit.AdjustCanvasFontSettings(ACanvas);
  with ACanvas do
  begin
    ACaptionSize := cxTextExtent(Font, Edit.FVisibleCaption, Font.Size);
    Result := Rect(0, 0, ACaptionSize.cx, ACaptionSize.cy);
    OffsetRect(Result, cxCaptionRectLeftBound, 0);
    if not Edit.IsVerticalText then
      AdjustHorizontalCaptionRect(Result)
    else
      AdjustVerticalCaptionRect(Result);
    //B93506
    //InflateRect(Result, 1, 1);
  end;
end;

procedure TcxGroupBoxViewData.AdjustHorizontalCaptionRect(var R: TRect);
var
  AShadowWidth: Integer;
begin
  AShadowWidth := GetShadowWidth;

  case Edit.FAlignment of
    alTopCenter, alBottomCenter, alCenterCenter:
      OffsetRect(R, -R.Left + (Edit.Width - AShadowWidth - (R.Right - R.Left)) div 2, 0);
    alTopRight, alRightTop, alRightCenter, alRightBottom, alBottomRight:
      OffsetRect(R, Edit.Width - R.Right - R.Left - AShadowWidth, 0);
  end;
  case Edit.FAlignment of
    alLeftCenter, alRightCenter, alCenterCenter:
      OffsetRect(R, 0, -R.Top + (Edit.Height - AShadowWidth -
        (R.Bottom - R.Top)) div 2);
    alLeftBottom, alBottomLeft, alBottomCenter, alBottomRight, alRightBottom:
      R := Rect(R.Left, Edit.Height - R.Top -
        (R.Bottom - R.Top), R.Right, Edit.Height - R.Top);
  end
end;

procedure TcxGroupBoxViewData.AdjustVerticalCaptionRect(var R: TRect);
var
  AShadowWidth, ATextWidth: Integer;
begin
  AShadowWidth := GetShadowWidth;
  ATextWidth := R.Right - R.Left;

  case Edit.FAlignment of
    alLeftTop:
      begin
        R := Rect(R.Top, R.Left, R.Bottom, 0);
        R.Bottom := R.Top + ATextWidth + 1;
      end;
    alLeftCenter:
      begin
        R := Rect(R.Top, 0, R.Bottom,
        Edit.Height - AShadowWidth - (Edit.Height - AShadowWidth - ATextWidth) div 2);
        R.Top := R.Bottom - ATextWidth - 1;
      end;
    alLeftBottom:
      begin
        R := Rect(R.Top, 0, R.Bottom,
        Edit.Height - AShadowWidth - R.Left);
        R.Top := R.Bottom - ATextWidth - 1;
      end;
    alRightTop:
      R := Rect(Edit.Width - R.Bottom, R.Left,
        Edit.Width - R.Top, R.Left + ATextWidth);
    alRightCenter:
      begin
        R := Rect(Edit.Width - R.Bottom,
          (Edit.Height - ATextWidth) div 2, Edit.Width - R.Top, 0);
        R.Bottom := R.Top + ATextWidth;
      end;
    alRightBottom:
      R := Rect(Edit.Width - R.Bottom,
        Edit.Height - R.Left - ATextWidth, Edit.Width - R.Top,
        Edit.Height - R.Left);
  end;
end;

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

procedure TcxGroupBoxViewData.CalcRects(ACanvas: TcxCanvas;
  AEditViewInfo: TcxGroupBoxViewInfo);

  procedure CalculateBorderRect(var R: TRect; const AIndent: TRect;
    ACaptionPosition: TcxGroupBoxCaptionPosition);
  begin
    if HasNonClientArea then
      case ACaptionPosition of
        cxgpTop:
          Dec(R.Bottom, AIndent.Top);
        cxgpLeft:
          Dec(R.Right, AIndent.Left);
      end;
  end;

  procedure CalculateCaptionRect(var R: TRect; const AIndent: TRect;
    const ATextSize: TSize; ACaptionPosition: TcxGroupBoxCaptionPosition);
  begin
    case ACaptionPosition of
      cxgpBottom:
        R.Top := R.Bottom - ATextSize.cy - AIndent.Bottom;
      cxgpRight:
        R.Left := R.Right - ATextSize.cy - AIndent.Right;
      cxgpCenter:
        R := cxRectCenter(R, ATextSize);
      cxgpLeft:
        begin
          R.Right := R.Left + ATextSize.cy;
          if HasNonClientArea then
            Dec(R.Left, AIndent.Left)
          else
            Inc(R.Right, AIndent.Left);
        end;
      cxgpTop:
        begin
          R.Bottom := R.Top + ATextSize.cy;
          if HasNonClientArea then
            Dec(R.Top, AIndent.Top)
          else
            Inc(R.Bottom, AIndent.Top);
        end;
    end;
  end;

  procedure CalculateTextRect(const ABorderSize: TRect; ATextWidth: Integer);

⌨️ 快捷键说明

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