cxtextedit.pas

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

PAS
1,593
字号
    procedure Assign(Source: TPersistent); override;
    procedure RestoreDefaults; override;
  published
    property DisplayFormat: Boolean read FDisplayFormat write SetDisplayFormat
      stored IsDisplayFormatStored;
    property EditFormat: Boolean read FEditFormat write SetEditFormat
      stored IsEditFormatStored;
    property MaxLength: Boolean read FMaxLength write SetMaxLength stored False;
    property MaxValue;
    property MinValue;
  end;

  { TcxCustomEditListBox }

  TcxCustomEditListBox = class(TcxCustomInnerListBox)
  private
    FHotTrack: Boolean;
    FOnSelectItem: TNotifyEvent;
    function GetEdit: TcxCustomTextEdit;
  {$IFNDEF DELPHI6}
    function GetItemIndex: Integer;
  {$ENDIF}
    procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;
  protected
    procedure Click; override;
    function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
      MousePos: TPoint): Boolean; override;
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
    function GetItemData(Index: Integer): Longint; override;
    function NeedDrawFocusRect: Boolean; override;
    procedure MeasureItem(Index: Integer; var Height: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure SetItemData(Index: Integer;
      AData: Longint); override;
    function DoDrawItem(AIndex: Integer; const ARect: TRect;
      AState: TOwnerDrawState): Boolean; virtual;
    procedure DoSelectItem;
    function GetDefaultItemHeight: Integer;
    function GetItem(Index: Integer): string; virtual;
    procedure InternalRecreateWindow;
    procedure RecreateWindow; virtual;
    procedure SetItemCount(Value: Integer);
    procedure SetItemIndex(const Value: Integer); {$IFDEF DELPHI6}override;{$ELSE}virtual;{$ENDIF}
    property Edit: TcxCustomTextEdit read GetEdit;
    property HotTrack: Boolean read FHotTrack write FHotTrack;
{$IFNDEF DELPHI6}
    property ItemIndex: Integer read GetItemIndex write SetItemIndex;
{$ENDIF}
    property OnSelectItem: TNotifyEvent read FOnSelectItem write FOnSelectItem;
  public
    constructor Create(AOwner: TComponent); override;
    function GetHeight(ARowCount: Integer; AMaxHeight: Integer): Integer; virtual;
    function GetItemHeight(AIndex: Integer = -1): Integer; virtual;
    function GetItemWidth(AIndex: Integer): Integer; virtual;
    function IsVisible: Boolean;
    procedure SetScrollWidth(Value: Integer);
  end;

  TcxCustomEditListBoxClass = class of TcxCustomEditListBox;

  { IcxTextEditLookupData }

  TcxEditLookupDataGoDirection = (egdBegin, egdEnd, egdNext, egdPrev, egdPageUp, egdPageDown);

  IcxTextEditLookupData = interface
  ['{F49C5F08-7758-4362-A360-1DF02354E708}']
    function CanResizeVisualArea(var NewSize: TSize;
      AMaxHeight: Integer = 0; AMaxWidth: Integer = 0): Boolean;
    procedure CloseUp;
    procedure Deinitialize;
    procedure DropDown;
    procedure DroppedDown(const AFindStr: string);
    function Find(const AText: string): Boolean;
    function GetActiveControl: TControl;
    function GetCurrentKey: TcxEditValue;
    function GetDisplayText(const AKey: TcxEditValue): string; overload;
    function GetOnCurrentKeyChanged: TNotifyEvent;
    function GetOnSelectItem: TNotifyEvent;
    function GetVisualAreaPreferredSize(AMaxHeight: Integer; AWidth: Integer = 0): TSize;
    procedure Go(ADirection: TcxEditLookupDataGoDirection; ACircular: Boolean);
    procedure Initialize(AVisualControlsParent: TWinControl);
    function IsEmpty: Boolean;
    function IsMouseOverList(const P: TPoint): Boolean;
    function Locate(var AText, ATail: string; ANext: Boolean): Boolean;
    procedure PositionVisualArea(const AClientRect: TRect);
    procedure PropertiesChanged;
    procedure SelectItem;
    procedure SetCurrentKey(const AKey: TcxEditValue);
    procedure SetOnCurrentKeyChanged(Value: TNotifyEvent);
    procedure SetOnSelectItem(Value: TNotifyEvent);
    procedure TextChanged;
    property ActiveControl: TControl read GetActiveControl;
    property CurrentKey: TcxEditValue read GetCurrentKey write SetCurrentKey;
    property OnCurrentKeyChanged: TNotifyEvent read GetOnCurrentKeyChanged write SetOnCurrentKeyChanged;
    property OnSelectItem: TNotifyEvent read GetOnSelectItem write SetOnSelectItem;
  end;

  { TcxCustomTextEditLookupData }

  TcxCustomTextEditProperties = class;

  TcxCustomTextEditLookupData = class(TcxInterfacedPersistent, IcxTextEditLookupData)
  private
    FCurrentKey: Integer;
    FItemIndex: Integer;
    FList: TcxCustomEditListBox;
    FOwner: TPersistent;
    FOnCurrentKeyChanged: TNotifyEvent;
    FOnSelectItem: TNotifyEvent;
    function GetEdit: TcxCustomTextEdit;
    function GetItems: TStrings;
    function GetActiveProperties: TcxCustomTextEditProperties;
    function IndexOf(const AText: string): Integer;
    procedure SetItemIndex(Value: Integer);
    procedure SetItems(Value: TStrings);
  protected
    function GetOwner: TPersistent; override;
    procedure DoCurrentKeyChanged;
    procedure DoSelectItem;
    function GetItem(Index: Integer): string; virtual;
    function GetItemCount: Integer; virtual;
    function GetListBoxClass: TcxCustomEditListBoxClass; virtual;
    procedure HandleSelectItem(Sender: TObject); virtual; // TODO test for CLX
    function InternalLocate(var AText, ATail: string; ANext, ASynchronizeWithText: Boolean):
      Boolean; virtual;
    procedure InternalSetItemIndex(Value: Integer);
    procedure ListChanged; virtual;
    procedure SetListItemIndex(Value: Integer);
    property Edit: TcxCustomTextEdit read GetEdit;
    property ItemIndex: Integer read FItemIndex write SetItemIndex stored False;
    property Items: TStrings read GetItems write SetItems;
    property List: TcxCustomEditListBox read FList;
    property ActiveProperties: TcxCustomTextEditProperties read GetActiveProperties;
  public
    constructor Create(AOwner: TPersistent); override;
    function CanResizeVisualArea(var NewSize: TSize;
      AMaxHeight: Integer = 0; AMaxWidth: Integer = 0): Boolean; virtual;
    procedure CloseUp;
    procedure Deinitialize;
    procedure DropDown; virtual;
    procedure DroppedDown(const AFindStr: string); virtual;
    function Find(const AText: string): Boolean; virtual;
    function GetActiveControl: TControl;
    function GetCurrentKey: TcxEditValue;
    function GetDisplayText(const AKey: TcxEditValue): string; overload;
    function GetOnCurrentKeyChanged: TNotifyEvent;
    function GetOnSelectItem: TNotifyEvent;
    function GetVisualAreaPreferredSize(AMaxHeight: Integer; AWidth: Integer = 0): TSize; virtual;
    procedure Go(ADirection: TcxEditLookupDataGoDirection; ACircular: Boolean);
    procedure Initialize(AVisualControlsParent: TWinControl); virtual;
    procedure InternalSetCurrentKey(Value: Integer);
    function IsEmpty: Boolean;
    function IsMouseOverList(const P: TPoint): Boolean;
    function Locate(var AText, ATail: string; ANext: Boolean): Boolean;
    procedure PositionVisualArea(const AClientRect: TRect); virtual;
    procedure PropertiesChanged; virtual;
    procedure SelectItem;
    procedure SetCurrentKey(const AKey: TcxEditValue);
    procedure SetOnCurrentKeyChanged(Value: TNotifyEvent);
    procedure SetOnSelectItem(Value: TNotifyEvent);
    procedure TextChanged; virtual;
    property ActiveControl: TControl read GetActiveControl;
    property CurrentKey: TcxEditValue read GetCurrentKey write SetCurrentKey;
    property OnCurrentKeyChanged: TNotifyEvent read GetOnCurrentKeyChanged write SetOnCurrentKeyChanged;
    property OnSelectItem: TNotifyEvent read GetOnSelectItem write SetOnSelectItem;
  end;

  { TcxCustomTextEditViewData }

  TcxCustomTextEditViewData = class(TcxCustomEditViewData)
  private
    FIsValueEditorWithValueFormatting: Boolean;
    function GetProperties: TcxCustomTextEditProperties;
    function InvertColor(AColor: TColor): TColor;
  protected
    procedure CalculateButtonNativeInfo(AButtonViewInfo: TcxEditButtonViewInfo); override;
    function GetIsEditClass: Boolean; virtual;
    function GetMaxLineCount: Integer; virtual;
    procedure InitCacheData; override;
    function InternalEditValueToDisplayText(AEditValue: TcxEditValue): string; override;
    function InternalGetEditContentSize(ACanvas: TcxCanvas; const AEditValue: TcxEditValue;
      const AEditSizeProperties: TcxEditSizeProperties): TSize; override;
    function IsComboBoxStyle: Boolean; virtual;
    procedure PrepareDrawTextFlags(ACanvas: TcxCanvas;
      AViewInfo: TcxCustomEditViewInfo); virtual;
  public
    procedure Calculate(ACanvas: TcxCanvas; const ABounds: TRect; const P: TPoint;
      Button: TcxMouseButton; Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo;
      AIsMouseEvent: Boolean); override;
    procedure DisplayValueToDrawValue(const ADisplayValue: TcxEditValue;
      AViewInfo: TcxCustomEditViewInfo); virtual;
    procedure EditValueToDrawValue(ACanvas: TcxCanvas; const AEditValue: TcxEditValue;
      AViewInfo: TcxCustomEditViewInfo); override;
    function GetClientExtent(ACanvas: TcxCanvas;
      AViewInfo: TcxCustomEditViewInfo): TRect; override;
    function GetDrawTextFlags: DWORD; virtual;
    function GetDrawTextOffset: TRect; virtual;
    procedure PrepareSelection(AViewInfo: TcxCustomEditViewInfo);
    property Properties: TcxCustomTextEditProperties read GetProperties;
  end;

  { TcxCustomTextEditViewInfo }

  TcxTextOutData = record
    ForceEndEllipsis: Boolean;
    Initialized: Boolean;
    RowCount: Integer;
    SelStart, SelLength: Integer;
    SelBackgroundColor, SelTextColor: TColor;
    TextParams: TcxTextParams;
    TextRect: TRect;
    TextRows: TcxTextRows;
  end;

  TcxCustomTextEditViewInfo = class(TcxCustomEditViewInfo)
  protected
    procedure InternalPaint(ACanvas: TcxCanvas); override;
  public
    ComboBoxStyle: Boolean;
    CustomDrawHandler: TcxTextEditCustomDrawHandler;
    DrawSelectionBar: Boolean;
    DrawTextFlags: DWORD;
    EditingStyle: TcxEditEditingStyle;
    HasPopupWindow: Boolean;
    IsEditClass: Boolean;
    IsOwnerDrawing: Boolean;
    MaxLineCount: Integer;
    SelStart, SelLength: Integer;
    SelTextColor, SelBackgroundColor: TColor;
    Text: string;
    TextOutData: TcxTextOutData;
    TextRect: TRect;
    destructor Destroy; override;
    function NeedShowHint(ACanvas: TcxCanvas; const P: TPoint;
      const AVisibleBounds: TRect; out AText: TCaption;
      out AIsMultiLine: Boolean; out ATextRect: TRect): Boolean; override;
    procedure Offset(DX, DY: Integer); override;
    procedure DrawText(ACanvas: TcxCanvas); virtual;
  {$IFDEF DELPHI10}
    function GetTextBaseLine: Integer; virtual;
  {$ENDIF}
  end;

{ TcxCustomTextEditProperties }

  TcxNewLookupDisplayTextEvent = procedure(Sender: TObject; const AText: TCaption) of object;
  TcxTextEditChars = set of AnsiChar;

  TcxCustomTextEditProperties = class(TcxCustomEditProperties, IcxFormatControllerListener)
  private
    FCharCase: TEditCharCase;
    FDisplayFormat: string;
    FEchoMode: TcxEditEchoMode;
    FEditFormat: string;
    FFixedListSelection: Boolean;
    FFormatChanging: Boolean;
    FHideCursor: Boolean;
    FHideSelection: Boolean;
    FImeMode: TImeMode;
    FImeName: TImeName;
    FImmediateUpdateText: Boolean;
    FIncrementalSearch: Boolean;
    FLookupItems: TStringList;
    FMaxLength: Integer;
    FMRUMode: Boolean;
    FOEMConvert: Boolean;
    FPasswordChar: TCaptionChar;
    FUseDisplayFormatWhenEditing: Boolean;
    FValidChars: TcxTextEditChars;
    FOnNewLookupDisplayText: TcxNewLookupDisplayTextEvent;
    function GetAssignedValues: TcxTextEditPropertiesValues;
    function GetDisplayFormat: string;
    function GetEditFormat: string;
    function GetInnerEditMaxLength: Integer;
    function GetLookupItems: TStrings;
    function GetLookupItemsSorted: Boolean;
    function GetMaxLength: Integer;
    function GetViewStyle: TcxTextEditViewStyle;
    function IsDisplayFormatStored: Boolean;
    function IsEditFormatStored: Boolean;
    function IsMaxLengthStored: Boolean;
    procedure LookupItemsChanged(Sender: TObject);
    procedure ReadIsDisplayFormatAssigned(Reader: TReader); // obsolete
    procedure SetAssignedValues(Value: TcxTextEditPropertiesValues);
    procedure SetDisplayFormat(const Value: string);
    procedure SetEchoMode(Value: TcxEditEchoMode);
    procedure SetEditFormat(const Value: string);
    procedure SetFixedListSelection(Value: Boolean);
    procedure SetHideCursor(Value: Boolean);
    procedure SetHideSelection(Value: Boolean);
    procedure SetImeMode(Value: TImeMode);
    procedure SetImeName(const Value: TImeName);
    procedure SetIncrementalSearch(Value: Boolean);
    procedure SetLookupItems(Value: TStrings);
    procedure SetLookupItemsSorted(Value: Boolean);
    procedure SetMaxLength(Value: Integer);
    procedure SetMRUMode(Value: Boolean);
    procedure SetOEMConvert(Value: Boolean);
    procedure SetPasswordChar(Value: TCaptionChar);
    procedure SetUseDisplayFormatWhenEditing(Value: Boolean);
    procedure SetViewStyle(Value: TcxTextEditViewStyle);
  protected
    procedure AlignmentChangedHandler(Sender: TObject); override;
    procedure BaseSetAlignment(Value: TcxEditAlignment); override;
    function CanValidate: Boolean; override;
    procedure DefineProperties(Filer: TFiler); override; // obsolete
    class function GetAssignedValuesClass: TcxCustomEditPropertiesValuesClass; override;
    function GetDisplayFormatOptions: TcxEditDisplayFormatOptions; override;
    function GetValidateErrorText(AErrorKind: TcxEditErrorKind): string; override;
    class function GetViewDataClass: TcxCustomEditViewDataClass; override;
    function HasDisplayValue: Boolean; override;

    // IcxFormatControllerListener
    procedure FormatChanged; virtual;

    function CanIncrementalSearch: Boolean;
    procedure CheckEditorValueBounds(var DisplayValue: TcxEditValue;
      var ErrorText: TCaption; var Error: Boolean; AEdit: TcxCustomEdit); virtual;
    function DefaultFocusedDisplayValue: TcxEditValue; virtual;

⌨️ 快捷键说明

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