cxdropdownedit.pas

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

PAS
1,810
字号
      Y := R.Bottom - 1;
    end;
    X0 := X;
    Y0 := Y;
    for I := 0 to 2 do
    begin
      if AIsTransparent then
      begin
        Inc(X, DX * L);
        Inc(Y, DY * L);
      end
      else
        for J := 1 to L do
          DrawTouch(clBtnFace);
      for J := 1 to L * 2 do
        DrawTouch(clBtnShadow);
      for J := 1 to L do
        DrawTouch(clBtnHighlight);
    end;
  end;
end;

procedure DrawEditPopupWindowFrame(ACanvas: TcxCanvas; AViewInfo: TcxCustomEditPopupWindowViewInfo);
var
  R, R1: TRect;
  A: Integer;
  ABorderColor: TColor;
  AClientEdgeWidth: Integer;
begin
  with AViewInfo do
  begin
    R := Rect(0, 0, Bounds.Right - Bounds.Left, Bounds.Bottom - Bounds.Top);

    if Shadow then
    begin
      Dec(R.Right, cxEditShadowWidth);
      Dec(R.Bottom, cxEditShadowWidth);
      DrawContainerShadow(ACanvas, R);
    end;

    DrawBorder(ACanvas, R);

    if SysPanelStyle and ((BorderStyle = epbsSingle) or (CloseButtonNativeState <> TC_NONE)) then
    begin
      if Painter <> nil then
        ABorderColor := Painter.GetContainerBorderColor(False)
      else
        ABorderColor := clBtnText;
      R1 := ClientRect;
      AClientEdgeWidth := GetEditPopupWindowClientEdgeWidth(AViewInfo);
      if ClientEdge then
        InflateRect(R1, AClientEdgeWidth, AClientEdgeWidth);
      if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
        InternalPolyLine(ACanvas, [Point(R1.Left, R1.Top - 1), Point(R1.Right, R1.Top - 1)], ABorderColor, True)
      else
        InternalPolyLine(ACanvas, [Point(R1.Left, R1.Bottom), Point(R1.Right, R1.Bottom)], ABorderColor, True);
    end;

    if ClientEdge then
    begin
      A := SysPanelHeight;
      if SysPanelStyle and (NativeStyle or (BorderStyle = epbsSingle)) then
        Inc(A);
      R1 := R;
      if SysPanelStyle then
        if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
          Inc(R1.Top, A)
        else
          Dec(R1.Bottom, A);

      ACanvas.DrawEdge(R1, True, True);
      if NativeStyle or (BorderStyle <> epbsFlat) then
      begin
        InflateRect(R1, -1, -1);
        ACanvas.DrawEdge(R1, True, False);
      end;
    end;

    if SysPanelStyle then
    begin
      if Sizeable then
      begin
        DrawSizeGrip(ACanvas, SizeGripRect, SizeGripCorner,
          NativeStyle or (AViewInfo.Painter <> nil), AViewInfo.Painter);
        ACanvas.ExcludeClipRect(SizeGripRect);
      end;

      if not IsRectEmpty(CloseButtonRect) then
      begin
        DrawEditPopupCloseButton(ACanvas, AViewInfo);
        ACanvas.ExcludeClipRect(CloseButtonRect);
      end;
    end;

    if Painter <> nil then
      Painter.DrawWindowContent(ACanvas, ClientRect)
    else
      ACanvas.FillRect(ClientRect, clBtnFace);

    A := SysPanelHeight;
    if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
      R.Bottom := R.Top + A
    else
      R.Top := R.Bottom - A;

    if Painter <> nil then
      Painter.DrawWindowContent(ACanvas, R)
    else
      ACanvas.FillRect(R, clBtnFace);
  end;
end;

procedure DrawPopupEditPopupWindowBorder(ACanvas: TcxCanvas; AViewInfo: TcxCustomEditPopupWindowViewInfo;
  var R: TRect);
begin
  with AViewInfo do
    if not NativeStyle and (BorderStyle = epbsFrame3D) then
    begin
      ACanvas.DrawEdge(R, False, True);
      InflateRect(R, -1, -1);
      ACanvas.DrawEdge(R, False, False);
      InflateRect(R, -1, -1);
      ACanvas.FrameRect(R, clInactiveBorder);
      InflateRect(R, -1, -1);
      ACanvas.FrameRect(R, clBtnFace);
      InflateRect(R, -1, -1);
    end
    else
      DrawEditPopupWindowBorder(ACanvas, AViewInfo, R);
end;

procedure SetEditPopupWindowShadowRegion(APopupWindow: TcxCustomEditPopupWindow);
var
  R: TRect;
  AExcludeRect: TRect;
begin
  AExcludeRect := cxEmptyRect;
  R := GetControlRect(APopupWindow);
  with APopupWindow.ViewInfo do
  begin
    if not NativeStyle then
      if Shadow then
      begin
        Dec(R.Right, cxEditShadowWidth);
        Dec(R.Bottom, cxEditShadowWidth);
        if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
        begin
          AExcludeRect := APopupWindow.OwnerScreenBounds;
          AExcludeRect.TopLeft := APopupWindow.ScreenToClient(AExcludeRect.TopLeft);
          AExcludeRect.BottomRight := APopupWindow.ScreenToClient(AExcludeRect.BottomRight);
          Dec(AExcludeRect.Right, cxEditShadowWidth);
          AExcludeRect.Bottom := APopupWindow.Height;
          AExcludeRect.Top := AExcludeRect.Bottom - cxEditShadowWidth;
        end;
      end;
    SetWindowShadowRegion(APopupWindow.Handle, R,
      NativeStyle, Shadow, AExcludeRect);
  end;
end;

{ TcxCustomEditPopupWindowViewInfo }

procedure TcxCustomEditPopupWindowViewInfo.Calculate;
begin
  CalculateEditPopupWindowViewInfo(Self);
end;

procedure TcxCustomEditPopupWindowViewInfo.DrawBorder(ACanvas: TcxCanvas; var R: TRect);
begin
  DrawEditPopupWindowBorder(ACanvas, Self, R);
end;

function TcxCustomEditPopupWindowViewInfo.GetBorderExtent: TRect;
begin
  Result := GetEditPopupWindowFrameExtent(Self);
end;

function TcxCustomEditPopupWindowViewInfo.GetClientExtent: TRect;
begin
  Result := GetBorderExtent;
end;

function TcxCustomEditPopupWindowViewInfo.GetSysPanelHeight: Integer;
begin
  Result := GetEditPopupWindowSysPanelDefaultHeight(Self);
  if (MinSysPanelHeight > 0) and (Result < MinSysPanelHeight) then
    Result := MinSysPanelHeight;
end;

function TcxCustomEditPopupWindowViewInfo.IsSizingPlace(X, Y: Integer): Boolean;
const
  AHorzFlagMap: array[TcxEditCorner] of Integer = (-1, 1, -1, 1);
  AVertFlagMap: array[TcxEditCorner] of Integer = (-1, -1, 1, 1);
var
  P: TPoint;
  ALeftCorner, ARightCorner, ATopCorner, ABottomCorner: Boolean;
begin
  Result := False;
  if not Sizeable then
    Exit;
  P := Point(X, Y);
  if not PtInRect(Bounds, P) then
    Exit;
  if PtInRect(SizingRegionBounds, P) and not PtInRect(SizeGripSizingRect, P) then
    Exit;
  Result := True;

  if PtInRect(SizeGripSizingRect, P) then
  begin
    FHorzFlag := AHorzFlagMap[SizeGripCorner];
    FVertFlag := AVertFlagMap[SizeGripCorner];
    Exit;
  end;

  ALeftCorner := SizeGripCorner in [ecoTopLeft, ecoBottomLeft];
  ARightCorner := SizeGripCorner in [ecoTopRight, ecoBottomRight];
  ATopCorner := SizeGripCorner in [ecoTopLeft, ecoTopRight];
  ABottomCorner := SizeGripCorner in [ecoBottomLeft, ecoBottomRight];

  FHorzFlag := 0;
  if (X < SizingOffset) and ALeftCorner then
    FHorzFlag := -1;
  if (X >= Bounds.Right - SizingOffset) and ARightCorner then
    FHorzFlag := 1;

  FVertFlag := 0;
  if (Y < SizingOffset) and ATopCorner then
    FVertFlag := -1;
  if (Y >= Bounds.Bottom - SizingOffset) and ABottomCorner then
    FVertFlag := 1;

  if SizeGripCorner in [ecoTopLeft, ecoTopRight] then
  begin
    if FVertFlag = 1 then
    begin
      if (X >= SizingRegionBounds.Left) and (X < SizingRegionBounds.Right) then
        FHorzFlag := 0;
      FVertFlag := 0;
    end;
  end else
  begin
    if FVertFlag = -1 then
    begin
      if (X >= SizingRegionBounds.Left) and (X < SizingRegionBounds.Right) then
        FHorzFlag := 0;
      FVertFlag := 0;
    end;
  end;

  if SysPanelStyle then
    if SizeGripCorner in [ecoTopLeft, ecoBottomLeft] then
    begin
      if FHorzFlag = 1 then
      begin
        if (Y >= SizingRegionBounds.Top) and (Y < SizingRegionBounds.Bottom) then
          FVertFlag := 0;
        FHorzFlag := 0;
      end;
    end else
    begin
      if FHorzFlag = -1 then
      begin
        if (Y >= SizingRegionBounds.Top) and (Y < SizingRegionBounds.Bottom) then
          FVertFlag := 0;
        FHorzFlag := 0;
      end;
    end;
end;

function TcxCustomEditPopupWindowViewInfo.DrawCustomBorder(ACanvas: TcxCanvas; const R: TRect; out ABorderWidth: Integer): Boolean;
begin
  Result := False;
  ABorderWidth := 0;
  if Assigned(FOnCustomDrawBorder) then
    FOnCustomDrawBorder(Self, ACanvas, R, Result, ABorderWidth);
end;

procedure TcxCustomEditPopupWindowViewInfo.InternalPaint(ACanvas: TcxCanvas);
begin
  DrawEditPopupWindowFrame(ACanvas, Self);
end;

{ TcxCustomEditPopupWindow }

constructor TcxCustomEditPopupWindow.Create(AOwnerControl: TWinControl);
begin
  inherited Create(AOwnerControl);
  ViewInfo.CloseButtonState := cxbsNormal;
end;

destructor TcxCustomEditPopupWindow.Destroy;
begin
  FreeAndNil(FSizeFrame);
  inherited Destroy;
end;

function TcxCustomEditPopupWindow.GetViewInfoClass: TcxContainerViewInfoClass;
begin
  Result := TcxCustomEditPopupWindowViewInfo;
end;

procedure TcxCustomEditPopupWindow.Popup(AFocusedControl: TWinControl);
begin
  if not IsOwnerControlVisible then
    Edit.DoFinalizePopup;
  inherited Popup(AFocusedControl);
end;

function TcxCustomEditPopupWindow.AcceptsAnySize: Boolean;
begin
  Result := Edit.ActiveProperties.PopupWindowAcceptsAnySize;
end;

procedure TcxCustomEditPopupWindow.AdjustClientRect(var Rect: TRect);
var
  AClientExtent: TRect;
begin
  AClientExtent := ViewInfo.GetClientExtent;
  ExtendRect(Rect, AClientExtent);
end;

function TcxCustomEditPopupWindow.CalculatePosition: TPoint;
const
  ASizeGripCornerMap: array[Boolean, Boolean] of TcxEditCorner = (
    (ecoTopLeft, ecoBottomLeft),
    (ecoTopRight, ecoBottomRight)
  );
var
  ALeftFlag, ATopFlag: Boolean;
  AOwnerRect: TRect;
  ADesktopWorkArea: TRect;
begin
  OwnerBounds := Edit.GetPopupWindowOwnerControlBounds;
  Result := inherited CalculatePosition;

  AOwnerRect := OwnerScreenBounds;
  ADesktopWorkArea := GetDesktopWorkArea(Point(Result.X, Result.Y));

  ALeftFlag := (AlignHorz = pahRight) and (Result.X + Width = AOwnerRect.Right) and (Result.X > ADesktopWorkArea.Left) or {pahRight + pdVertical}
    (Result.X + Width = AOwnerRect.Left) or                                                    {pahLeft + pdHorizontal}
    (Result.X + Width = ADesktopWorkArea.Right) and (Result.X < AOwnerRect.Right);
  ATopFlag := (AlignVert = pavBottom) and (Result.Y + Height = AOwnerRect.Bottom) and (Result.Y > ADesktopWorkArea.Top) or {pavBottom + pdHorizontal}
    (Result.Y + Height = AOwnerRect.Top) or                                                    {pavTop + pdVertical}
    (Result.Y + Height = ADesktopWorkArea.Bottom) and (Result.Y < AOwnerRect.Bottom);

  ViewInfo.SizeGripCorner := ASizeGripCornerMap[not ALeftFlag, not ATopFlag];

  if Shadow and ATopFlag then
    Inc(Result.Y, cxEditShadowWidth);
end;

procedure TcxCustomEditPopupWindow.CalculateSize;
var
  AClientExtent: TRect;
  AMinSize: TSize;
  APreferredWidth, APreferredHeight: Integer;
  APopupWindowVisualAreaSize: TSize;
begin
  ViewInfo.SizeGripCorner := ecoBottomRight;
  OwnerBounds := Edit.GetPopupWindowOwnerControlBounds;
  AClientExtent := ViewInfo.GetClientExtent;
  AMinSize := M

⌨️ 快捷键说明

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