cxdropdownedit.pas

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

PAS
1,810
字号
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

  { TcxFilterComboBoxHelper }

  TcxFilterComboBoxHelper = class(TcxFilterDropDownEditHelper)
  public
    class function GetFilterEditClass: TcxCustomEditClass; override;
    class procedure InitializeProperties(AProperties,
      AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean); override;
  end;

  { TcxPopupEditPopupWindowViewInfo }

  TcxPopupEditPopupWindowViewInfo = class(TcxCustomEditPopupWindowViewInfo)
  public
    procedure DrawBorder(ACanvas: TcxCanvas; var R: TRect); override;
  end;

  { TcxPopupEditPopupWindow }

  TcxPopupEditPopupWindow = class(TcxCustomEditPopupWindow)
  public
    function GetViewInfoClass: TcxContainerViewInfoClass; override;
  end;

  { TcxCustomPopupEditProperties }

  TcxCustomPopupEditProperties = class(TcxCustomDropDownEditProperties)
  private
    FPopupControl: TControl;
    procedure SetPopupControl(Value: TControl);
  protected
    procedure FreeNotification(Sender: TComponent); override;
    class function GetPopupWindowClass: TcxCustomEditPopupWindowClass; override;
    function IsLookupDataVisual: Boolean; override;
    function PopupWindowCapturesFocus: Boolean; override;
  public
    constructor Create(AOwner: TPersistent); override;
    procedure Assign(Source: TPersistent); override;
    class function GetContainerClass: TcxContainerClass; override;
    // !!!
    property PopupControl: TControl read FPopupControl write SetPopupControl;
    property PopupSizeable default True;
  end;

  { TcxPopupEditProperties }

  TcxPopupEditProperties = class(TcxCustomPopupEditProperties)
  public
    constructor Create(AOwner: TPersistent); override;
  published
    property Alignment;
    property AssignedValues;
    property AutoSelect;
    property BeepOnError;
    property ButtonGlyph;
    property CaseInsensitive;
    property CharCase;
    property ClearKey;
    property EchoMode;
    property HideSelection;
    property IgnoreMaskBlank;
    property ImeMode;
    property ImeName;
    property ImmediateDropDown;
    property ImmediatePopup default True;
    property IncrementalSearch;
    property LookupItems;
    property LookupItemsSorted;
    property MaxLength;
    property MaskKind;
    property EditMask;
    property OEMConvert;
    property PasswordChar;
    property PopupAlignment;
    property PopupAutoSize;
    property PopupClientEdge;
    property PopupControl;
    property PopupHeight;
    property PopupMinHeight;
    property PopupMinWidth;
    property PopupSizeable;
    property PopupSysPanelStyle;
    property PopupWidth;
    property ReadOnly;
    property UseLeftAlignmentOnEditing;
    property ValidateOnEnter;
    property OnChange;
    property OnCloseQuery;
    property OnCloseUp;
    property OnEditValueChanged;
    property OnInitPopup;
    property OnPopup;
    property OnValidate;
  end;

  { TcxCustomPopupEdit }

  TcxPrevPopupControlData = record
    Align: TAlign;
    Bounds: TRect;
    Parent: TWinControl;
    Visible: Boolean;
    BorderStyle: TFormBorderStyle;
  end;

  TcxCustomPopupEdit = class(TcxCustomDropDownEdit)
  private
    FPrevPopupControlData: TcxPrevPopupControlData;
    function GetProperties: TcxCustomPopupEditProperties;
    function GetActiveProperties: TcxCustomPopupEditProperties;
    procedure SetProperties(Value: TcxCustomPopupEditProperties);
  protected
    function CanDropDown: Boolean; override;
    procedure DoInitPopup; override;
    function GetPopupFocusedControl: TWinControl; override;
    function GetPopupWindowClientPreferredSize: TSize; override;
    procedure PopupWindowClosed(Sender: TObject); override;
    procedure PositionPopupWindowChilds(const AClientRect: TRect); override;
    procedure SetupPopupWindow; override;
    procedure HidePopup(Sender: TcxControl; AReason: TcxEditCloseUpReason); virtual;
    procedure RestorePopupControlData; virtual;
    procedure SavePopupControlData; virtual;
  public
    destructor Destroy; override;
    class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
    property ActiveProperties: TcxCustomPopupEditProperties read GetActiveProperties;
    property Properties: TcxCustomPopupEditProperties read GetProperties
      write SetProperties;
  end;

  { TcxPopupEdit }

  TcxPopupEdit = class(TcxCustomPopupEdit)
  private
    function GetActiveProperties: TcxPopupEditProperties;
    function GetProperties: TcxPopupEditProperties;
    procedure SetProperties(Value: TcxPopupEditProperties);
  protected
    function IsCheckAsYouTypeSupports: Boolean; override;
  public
    class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
    property ActiveProperties: TcxPopupEditProperties read GetActiveProperties;
  published
    property Anchors;
    property AutoSize;
    property BeepOnEnter;
    property Constraints;
    property DragMode;
    property Enabled;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property Properties: TcxPopupEditProperties read GetProperties
      write SetProperties;
    property ShowHint;
    property Style;
    property StyleDisabled;
    property StyleFocused;
    property StyleHot;
    property TabOrder;
    property TabStop;
    property Text;
    property Visible;
    property DragCursor;
    property DragKind;
    property ImeMode;
    property ImeName;
    property OnClick;
{$IFDEF DELPHI5}
    property OnContextPopup;
{$ENDIF}
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEditing;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDrag;
    property OnEndDock;
    property OnStartDock;
  end;

implementation

uses
  Math, dxThemeConsts, dxThemeManager, dxUxTheme, cxEditConsts, cxEditPaintUtils,
  cxEditUtils, cxScrollBar, cxGeometry, cxDWMApi;

const

  cxEditMouseSizingCursorMap: array[-1 .. 1, -1 .. 1] of TCursor = (
    (crSizeNWSE, crSizeWE, crSizeNESW),
    (crSizeNS, crDefault, crSizeNS),
    (crSizeNESW, crSizeWE, crSizeNWSE)
  );

  cxEditPopupClientEdgeWidthA: array[TcxEditPopupBorderStyle] of Integer = (0, 2, 2, 1);
  cxEditPopupWindowFrameWidthA: array[TcxEditPopupBorderStyle] of Integer = (0, 1, 4, 2);

  CloseButtonNativeStateMap: array [TcxButtonState] of Integer =
    (TC_NONE, CBS_NORMAL, CBS_HOT, CBS_PUSHED, CBS_DISABLED);

type
  TcxCustomEditStyleAccess = class(TcxCustomEditStyle);
  TControlAccess = class(TControl);
  TCustomFormAccess = class(TCustomForm);
  TWinControlAccess = class(TWinControl);

var
  FCapturePointOffset: TSize;
  FHorzFlag, FVertFlag: Integer;
  FSizeFrameBounds: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
  FPaintedSizeFrameBounds: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
  FSizingCapture: Boolean = False;
  FSizingMouseMovement: Boolean = False;

procedure CheckBounds(const AOuterRect: TRect; var AInnerRect: TRect);
begin
  if AInnerRect.Left < AOuterRect.Left then
    AInnerRect.Left := AOuterRect.Left;
  if AInnerRect.Top < AOuterRect.Top then
    AInnerRect.Top := AOuterRect.Top;
  if AInnerRect.Right > AOuterRect.Right then
    AInnerRect.Right := AOuterRect.Right;
  if AInnerRect.Bottom > AOuterRect.Bottom then
    AInnerRect.Bottom := AOuterRect.Bottom;
end;

function GetEditPopupWindowSysPanelDefaultHeight(AViewInfo: TcxCustomEditPopupWindowViewInfo): Integer;
var
  ATheme: TdxTheme;
  ACloseButtonSize: TSize;
  ASizeGripSize: TSize;
begin
  ACloseButtonSize.cy := 0;
  ASizeGripSize.cy := 0;
  with AViewInfo do
    if SysPanelStyle and AreVisualStylesMustBeUsed(NativeStyle, totWindow) then
    begin
      ATheme := OpenTheme(totWindow);
      GetThemePartSize(ATheme, 0, WP_CLOSEBUTTON, CBS_NORMAL, TS_TRUE,
        ACloseButtonSize);
      ATheme := OpenTheme(totScrollBar);
      GetThemePartSize(ATheme, 0, SBP_SIZEBOX, SZB_RIGHTALIGN, TS_TRUE,
        ASizeGripSize);
    end;

  Result := GetSystemMetrics(SM_CYHSCROLL);
  if Result < GetSystemMetrics(SM_CYSIZE) then
    Result := GetSystemMetrics(SM_CYSIZE);
  if Result < ACloseButtonSize.cy then
    Result := ACloseButtonSize.cy;
  if Result < ASizeGripSize.cy then
    Result := ASizeGripSize.cy;
end;

function GetEditPopupWindowClientEdgeWidth(AViewInfo: TcxCustomEditPopupWindowViewInfo): Integer;
begin
  with AViewInfo do
    if ClientEdge then
      if NativeStyle or (Painter <> nil) then
        Result := 2
      else
        Result := cxEditPopupClientEdgeWidthA[BorderStyle]
    else
      Result := 0;
end;

function GetEditPopupWindowBorderWidth(AViewInfo: TcxCustomEditPopupWindowViewInfo; AIncludeClientEdge: Boolean): Integer;
begin
  with AViewInfo do
  begin
    if not DrawCustomBorder(nil, cxEmptyRect, Result) then
      if NativeStyle or (Painter <> nil) then
        Result := 1
      else
        Result := cxEditPopupWindowFrameWidthA[BorderStyle];
    if ClientEdge and AIncludeClientEdge then
      Inc(Result, GetEditPopupWindowClientEdgeWidth(AViewInfo));
  end;
end;

function GetEditPopupWindowFrameExtent(AViewInfo: TcxCustomEditPopupWindowViewInfo): TRect;
var
  AOffset: Integer;
begin
  with AViewInfo do
  begin
    AOffset := GetEditPopupWindowBorderWidth(AViewInfo, True);
    Result := Rect(AOffset, AOffset, AOffset, AOffset);

    if Shadow then
    begin
      Inc(Result.Right, cxEditShadowWidth);
      Inc(Result.Bottom, cxEditShadowWidth);
    end;

    if SysPanelStyle then
    begin
      SysPanelHeight := GetSysPanelHeight;
      AOffset := SysPanelHeight;
      if NativeStyle or (BorderStyle = epbsSingle) or (Painter <> nil) then
        Inc(AOffset);
      if SizeGripCorner in [ecoBottomLeft, ecoBottomRight] then
        Inc(Result.Bottom, AOffset)
      else
        Inc(Result.Top, AOffset);
    end
    else
      SysPanelHeight := 0;

    SizingOffset := GetSystemMetrics(SM_CYHSCROLL);
    if SizingOffset < GetSystemMetrics(SM_CYSIZE) then
      SizingOffset := GetSystemMetrics(SM_CYSIZE);
  end;
end;

procedure CalculateEditPopupWindowViewInfo(AViewInfo: TcxCustomEditPopupWindowViewInfo);

  procedure CalculateSizeGripRect;
  var
    R: TRect;
    ASizeGripSizingRegionSize: TSize;
    ASizeGripSize: TSize;
    ATheme: TdxTheme;
  begin
    with AViewInfo do
    begin
      R := SizingRegionBounds;
      ASizeGripSizingRegionSize.cx := GetEditPopupWindowSysPanelDefaultHeight(AViewInfo) - 2;
      ASizeGripSizingRegionSize.cy := ASizeGripSizingRegionSize.cx;

      if AreVisualStylesMustBeUsed(NativeStyle, totScrollBar) then
      begin
        ATheme := OpenTheme(totScrollBar);
        GetThemePartSize(ATheme, 0, SBP_SIZEBOX, SZB_RIGHTALIGN, TS_TRUE,
          ASizeGripSize);
        ASizeGripSize.cx := ASizeGripSize.cx + 2;

⌨️ 快捷键说明

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