cxdropdownedit.pas

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

PAS
1,810
字号
        ASizeGripSize.cy := ASizeGripSize.cy + 2;
        if ASizeGripSizingRegionSize.cx < ASizeGripSize.cx then
          ASizeGripSizingRegionSize.cx := ASizeGripSize.cx;
        if ASizeGripSizingRegionSize.cy < ASizeGripSize.cy then
          ASizeGripSizingRegionSize.cy := ASizeGripSize.cy;
      end;

      if SizeGripCorner in [ecoTopLeft, ecoBottomLeft] then
        R.Right := R.Left + ASizeGripSizingRegionSize.cx
      else
        R.Left := R.Right - ASizeGripSizingRegionSize.cx;
      if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
        R.Bottom := R.Top + ASizeGripSizingRegionSize.cy
      else
        R.Top := R.Bottom - ASizeGripSizingRegionSize.cy;
      SizeGripSizingRect := R;

      if SizeGripCorner in [ecoTopLeft, ecoBottomLeft] then
        Inc(R.Left, 2)
      else
        Dec(R.Right, 2);
      if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
        Inc(R.Top, 2)
      else
        Dec(R.Bottom, 2);
      SizeGripRect := R;
    end;
  end;

  procedure CalculateCloseButtonRect;
  var
    R: TRect;
    ACloseButtonSize: TSize;
    ATheme: TdxTheme;
  begin
    with AViewInfo do
      if CloseButton then
      begin
        R := SizingRegionBounds;

        if CloseButtonNativeState <> TC_NONE then
        begin
          ATheme := OpenTheme(totWindow);
          GetThemePartSize(ATheme, 0, WP_CLOSEBUTTON, CBS_NORMAL, TS_TRUE,
            ACloseButtonSize);
        end
        else
        begin
          ACloseButtonSize.cy := GetEditPopupWindowSysPanelDefaultHeight(AViewInfo) - 4;
          ACloseButtonSize.cx := ACloseButtonSize.cy;
        end;

        if CloseButtonNativeState = TC_NONE then
          if SizeGripCorner in [ecoTopLeft, ecoBottomLeft] then
            Dec(R.Right, 2)
          else
            Inc(R.Left, 2);

          if SizeGripCorner in [ecoTopLeft, ecoBottomLeft] then
          begin
            R.Left := R.Right - ACloseButtonSize.cx;
            OffsetRect(R, -1, 0);
          end else
          begin
            R.Right := R.Left + ACloseButtonSize.cx;
            OffsetRect(R, 1, 0);
          end;

        if CloseButtonNativeState <> TC_NONE then
          if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
          begin
            Inc(R.Top, (SysPanelHeight - ACloseButtonSize.cy) div 2);
            R.Bottom := R.Top + ACloseButtonSize.cy;
          end else
          begin
            Dec(R.Bottom, (SysPanelHeight - ACloseButtonSize.cy) div 2);
            R.Top := R.Bottom - ACloseButtonSize.cy;
          end
        else
          if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
          begin
            Inc(R.Top, 2);
            R.Bottom := R.Top + ACloseButtonSize.cy;
          end else
          begin
            Dec(R.Bottom, 2);
            R.Top := R.Bottom - ACloseButtonSize.cy;
          end;
        CloseButtonRect := R;
      end
      else
        CloseButtonRect := cxEmptyRect;
  end;

var
  AClientExtent: TRect;
  ASizingFrameWidth: Integer;
begin
  with AViewInfo do
  begin
    AClientExtent := GetEditPopupWindowFrameExtent(AViewInfo);
    ClientRect := Bounds;
    OffsetRect(ClientRect, -Bounds.Left, -Bounds.Top);
    SizingRegionBounds := ClientRect;
    ExtendRect(ClientRect, AClientExtent);

    ASizingFrameWidth := GetEditPopupWindowBorderWidth(AViewInfo, not SysPanelStyle);
    InflateRect(SizingRegionBounds, -ASizingFrameWidth, -ASizingFrameWidth);
    if Shadow then
    begin
      Dec(SizingRegionBounds.Bottom, cxEditShadowWidth);
      Dec(SizingRegionBounds.Right, cxEditShadowWidth);
    end;

    if SysPanelStyle and AreVisualStylesMustBeUsed(NativeStyle, totWindow) then
      CloseButtonNativeState := CloseButtonNativeStateMap[CloseButtonState]
    else
      CloseButtonNativeState := TC_NONE;

    if SysPanelStyle then
    begin
      if Sizeable then
        CalculateSizeGripRect;
      CalculateCloseButtonRect;
    end;
  end;
end;

procedure DrawEditPopupCloseButton(ACanvas: TcxCanvas; AViewInfo: TcxCustomEditPopupWindowViewInfo);
const
  ACloseButtonSize = 11;
  AStates: array[Boolean] of Longint = (0, DFCS_PUSHED);
var
  R: TRect;
  APainterClass: TcxCustomLookAndFeelPainterClass;
  ATheme: TdxTheme;
begin
  with AViewInfo do
  begin
    R := AViewInfo.CloseButtonRect;
    if Painter <> nil then
    begin
      Painter.DrawWindowContent(ACanvas, R);
      Painter.DrawEditorButton(ACanvas, R, cxbkCloseBtn, CloseButtonState);
    end
    else
    begin
      APainterClass := GetPainterClass(NativeStyle, CloseButtonStyle);
      if CloseButtonNativeState <> TC_NONE then
      begin
        ATheme := OpenTheme(totWindow);
        CloseButtonNativeState := CloseButtonNativeStateMap[CloseButtonState];
        if IsThemeBackgroundPartiallyTransparent(ATheme, WP_CLOSEBUTTON, CloseButtonNativeState) then
        begin
          ACanvas.Brush.Color := clBtnFace;
          ACanvas.FillRect(R);
        end;
        DrawThemeBackground(ATheme, ACanvas.Handle, WP_CLOSEBUTTON, CloseButtonNativeState, R);
        ACanvas.ExcludeClipRect(R);
      end
      else
        APainterClass.DrawFilterCloseButton(ACanvas, R, CloseButtonState);
    end;
  end;
end;

procedure DrawEditPopupWindowBorder(ACanvas: TcxCanvas; AViewInfo: TcxCustomEditPopupWindowViewInfo;
  var R: TRect);
var
  ABorderWidth: Integer;
begin
  with AViewInfo do
    if DrawCustomBorder(ACanvas, R, ABorderWidth) then
      InflateRect(R, -ABorderWidth, -ABorderWidth)
    else
    begin
      if NativeStyle then
        if IsCompositionEnabled then
          DrawThemeBackground(OpenTheme(totListBox), ACanvas.Handle, LBCP_BORDER_NOSCROLL, LBPSN_HOT, R)
        else
          ACanvas.FrameRect(R, clBtnText)
      else
        if Painter <> nil then
          ACanvas.FrameRect(R, Painter.GetContainerBorderColor(False))
        else
          case BorderStyle of
            epbsSingle:
              ACanvas.FrameRect(R, clBtnText);
            epbsFrame3D, epbsFlat:
              begin
                ACanvas.DrawEdge(R, False, True);
                InflateRect(R, -1, -1);
                ACanvas.DrawEdge(R, False, False);
                if BorderStyle = epbsFrame3D then
                begin
                  InflateRect(R, -1, -1);
                  if ClientEdge then
                    ACanvas.FrameRect(R, clInactiveBorder)
                  else
                    ACanvas.FrameRect(R, clBtnFace);
                  InflateRect(R, -1, -1);
                  if ClientEdge then
                    ACanvas.FrameRect(R, clBtnFace)
                  else
                    ACanvas.DrawEdge(R, True, True);
                end;
              end;
          end;
      InflateRect(R, -1, -1);
    end;
end;

procedure DrawSizeGrip(ACanvas: TcxCanvas; const ARect: TRect;
  ACorner: TcxEditCorner; ANativeStyle: Boolean;
  APainter: TcxCustomLookAndFeelPainterClass; AIsTransparent: Boolean = False);
var
  DX, DY: Integer;
  X, X0, Y, Y0: Integer;
  R: TRect;

  procedure DrawTouch(AColor: TColor);
  begin
    InternalPolyLine(ACanvas, [Point(X, Y0), Point(X0, Y)], AColor, False);
    Inc(X, DX);
    Inc(Y, DY);
  end;

const
  Offset = 2;
  RotateAngleMap: array [TcxEditCorner] of TcxRotationAngle = (ra180, raPlus90, raMinus90, ra0);
var
  AMirrorX, AMirrorY: Boolean;
  ATempRect: TRect;
  AScrollBarSize: TSize;
  I, J, L: Integer;
  APrevBitmap: HBITMAP;
  ATheme: TdxTheme;
  MDC: HDC;
  R1: TRect;
  ABitmap: TcxCustomBitmap;
begin
  if not AIsTransparent then
  begin
    ACanvas.Brush.Color := clBtnFace;
    ACanvas.FillRect(ARect);
  end;
  if APainter <> nil then
  begin
    ABitmap := TcxCustomBitmap.CreateSize(ARect);
    try
      APainter.DrawWindowContent(ABitmap.cxCanvas, ABitmap.ClientRect);
      APainter.DrawSizeGrip(ABitmap.cxCanvas, ABitmap.ClientRect);
      ABitmap.Rotate(RotateAngleMap[ACorner]);
      ACanvas.CopyRect(ARect, ABitmap.Canvas, ABitmap.ClientRect);
    finally
      ABitmap.Free;
    end;
    Exit;
  end;
  if ANativeStyle then
  begin
    ATheme := OpenTheme(totScrollBar);
    GetThemePartSize(ATheme, ACanvas.Handle, SBP_SIZEBOX, SZB_RIGHTALIGN,
      TS_TRUE, AScrollBarSize);
    AScrollBarSize.cx := AScrollBarSize.cx + Offset;
    AScrollBarSize.cy := AScrollBarSize.cy + Offset;
  end else
  begin
    AScrollBarSize.cx := GetSystemMetrics(SM_CXVSCROLL);
    AScrollBarSize.cy := GetSystemMetrics(SM_CYHSCROLL);
  end;
  ATempRect := ARect;
  with ATempRect do
  begin
    if ACorner in [ecoTopRight, ecoBottomRight] then
      Left := Right - AScrollBarSize.cx
    else
      Right := Left + AScrollBarSize.cx;
    if ACorner in [ecoBottomLeft, ecoBottomRight] then
      Top := Bottom - AScrollBarSize.cy
    else
      Bottom := Top + AScrollBarSize.cy;
    AMirrorX := ACorner in [ecoTopLeft, ecoBottomLeft];
    AMirrorY := ACorner in [ecoTopLeft, ecoTopRight];
  end;
  R := ATempRect;
  with R do
  begin
    if AMirrorX then
    begin
      Dec(Right, Offset);
    end
    else
    begin
      Inc(Left, Offset);
    end;
    if AMirrorY then
    begin
      Dec(Bottom, Offset);
    end
    else
    begin
      Inc(Top, Offset);
    end;
  end;

  if ANativeStyle or not AIsTransparent then
  begin
    X := R.Left;
    Y := R.Top;
    OffsetRect(R, -R.Left, -R.Top);
    MDC := CreateCompatibleDC(ACanvas.Handle);
    APrevBitmap := SelectObject(MDC, CreateCompatibleBitmap(ACanvas.Handle, R.Right, R.Bottom));
    if AIsTransparent then
    begin
      with R do
        StretchBlt(MDC, 0, 0, Right, Bottom,
          ACanvas.Handle, X + Byte(AMirrorX) * (Right - 1), Y + Byte(AMirrorY) * (Bottom - 1),
          (2 * Byte(not AMirrorX) - 1) * Right,
          (2 * Byte(not AMirrorY) - 1) * Bottom, SRCCOPY);
    end
    else
      FillRect(MDC, R, COLOR_BTNFACE + 1);
    ATheme := 0;
    if ANativeStyle then
      ATheme := OpenTheme(totScrollBar);
    if ATheme <> 0 then
    begin
      R1 := R;
      DrawThemeBackground(ATheme, MDC, SBP_SIZEBOX, SZB_RIGHTALIGN, R1);
    end
    else
      DrawFrameControl(MDC, R, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
    with R do
    begin
      StretchBlt(ACanvas.Handle, X, Y, Right, Bottom,
        MDC, Byte(AMirrorX) * (Right - 1), Byte(AMirrorY) * (Bottom - 1),
        (2 * Byte(not AMirrorX) - 1) * Right,
        (2 * Byte(not AMirrorY) - 1) * Bottom, SRCCOPY);
    end;
    DeleteObject(SelectObject(MDC, APrevBitmap));
    DeleteDC(MDC);
  end
  else
  begin
    L := (AScrollBarSize.cy - 2) div 12;
    if AMirrorX then
    begin
      DX := 1;
      X := R.Left;
    end else
    begin
      DX := -1;
      X := R.Right - 1;
    end;
    if AMirrorY then
    begin
      DY := 1;
      Y := R.Top;
    end else
    begin
      DY := -1;

⌨️ 快捷键说明

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