cxedit.pas

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

PAS
1,387
字号
    VisibleCaption: string;
    BackgroundPartiallyTransparent: Boolean;
    ComboBoxStyle: Boolean;
    NativePart: Integer;
    NativeState: Integer;
  end;
  PcxEditButtonViewInfoData = ^TcxEditButtonViewInfoData;

  TcxEditButtonViewInfo = class(TPersistent)
  public
    Bounds: TRect;
    Data: TcxEditButtonViewInfoData;
    Glyph: TBitmap;
    HasBackground: Boolean;
    Index: Integer;
    Stretchable: Boolean;
    VisibleBounds: TRect;
    Width: Integer;
    procedure Assign(Source: TPersistent); override;
    function GetUpdateRegion(AViewInfo: TcxEditButtonViewInfo): TcxRegion; virtual;
    function Repaint(AControl: TWinControl; AViewInfo: TcxEditButtonViewInfo;
      const AEditPosition: TPoint): Boolean; virtual;
  end;

  TcxEditButtonViewInfoClass = class of TcxEditButtonViewInfo;

  { TcxEditButton }

  TcxEditButton = class(TCollectionItem)
  private
    FCaption: TCaption;
    FContentAlignment: TAlignment;
    FDefault: Boolean;
    FEnabled: Boolean;
    FGlyph: TBitmap;
    FHint: string;
    FKind: TcxEditButtonKind;
    FLeftAlignment: Boolean;
    FStretchable: Boolean;
    FTag: TcxTag;
    FTextColor: TColor;
    FVisible: Boolean;
    FVisibleCaption: TCaption;
    FWidth: Integer;
    function GetGlyph: TBitmap;
    procedure GlyphChanged(Sender: TObject);
    function IsTagStored: Boolean;
    procedure SetCaption(const Value: TCaption);
    procedure SetContentAlignment(Value: TAlignment);
    procedure SetDefault(Value: Boolean);
    procedure SetEnabled(Value: Boolean);
    procedure SetGlyph(Value: TBitmap);
    procedure SetKind(Value: TcxEditButtonKind);
    procedure SetLeftAlignment(Value: Boolean);
    procedure SetStretchable(Value: Boolean);
    procedure SetTextColor(Value: TColor);
    procedure SetVisible(Value: Boolean);
    procedure SetWidth(Value: Integer);
  protected
    property TextColor: TColor read FTextColor write SetTextColor default clBtnText; // TODO published
    property VisibleCaption: TCaption read FVisibleCaption;
  public
    constructor Create(Collection: TCollection); override;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
  published
    property Caption: TCaption read FCaption write SetCaption;
    property ContentAlignment: TAlignment read FContentAlignment
      write SetContentAlignment default taCenter;
    property Default: Boolean read FDefault write SetDefault default False;
    property Enabled: Boolean read FEnabled write SetEnabled default True;
    property Glyph: TBitmap read GetGlyph write SetGlyph;
    property Hint: string read FHint write FHint;
    property Kind: TcxEditButtonKind read FKind write SetKind default bkDown;
    property LeftAlignment: Boolean read FLeftAlignment write SetLeftAlignment default False;
    property Stretchable: Boolean read FStretchable write SetStretchable default True;
    property Tag: TcxTag read FTag write FTag stored IsTagStored;
    property Visible: Boolean read FVisible write SetVisible default True;
    property Width: Integer read FWidth write SetWidth default 0;
  end;

  TcxEditButtonClass = class of TcxEditButton;

  { TcxEditButtons }

  TcxEditButtons = class(TCollection)
  private
    FOwner: TPersistent;
    FOnChange: TNotifyEvent;
    function GetItem(Index: Integer): TcxEditButton;
    function GetVisibleCount: Integer;
    procedure SetItem(Index: Integer; Value: TcxEditButton);
  protected
    class function GetButtonClass: TcxEditButtonClass; virtual;
    function GetOwner: TPersistent; override;
    procedure Update(Item: TCollectionItem); override;
    property OnChange: TNotifyEvent read FOnChange write FOnChange;
  public
    constructor Create(AOwner: TPersistent; AButtonClass: TcxEditButtonClass); virtual;
    function Add: TcxEditButton;
    property Items[Index: Integer]: TcxEditButton read GetItem write SetItem; default;
    property VisibleCount: Integer read GetVisibleCount;
  end;

  TcxEditButtonsClass = class of TcxEditButtons;

  { TcxCustomEditViewInfo }

  TcxCustomEditViewInfo = class;
  TcxEditAlignment = class;

  TcxEditDrawBackgroundEvent = procedure(Sender: TcxCustomEditViewInfo;
    ACanvas: TcxCanvas; var AHandled: Boolean) of object;
  TcxEditDrawButtonEvent = procedure(Sender: TcxCustomEditViewInfo;
    ACanvas: TcxCanvas; AButtonVisibleIndex: Integer; var AHandled: Boolean) of object;
  TcxEditDrawButtonBackgroundEvent = procedure(Sender: TcxCustomEditViewInfo;
    ACanvas: TcxCanvas; const ARect: TRect; AButtonVisibleIndex: Integer;
    var AHandled: Boolean) of object;
  TcxEditDrawButtonBorderEvent = procedure(Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
    out ABackgroundRect, AContentRect: TRect; var AHandled: Boolean) of object;
  TcxEditGetButtonStateEvent = procedure(Sender: TcxCustomEditViewInfo;
    AButtonVisibleIndex: Integer; var AState: TcxEditButtonState) of object;
  TcxEditPaintEvent = procedure(Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas) of object;

  TcxDrawBackgroundStyle = (dbsCustom, dbsCustomEdit, dbsNone, dbsSimpleFill, dbsSimpleParent, dbsThemeParent);
  TcxEditViewInfoState = (evsPaintButtons);
  TcxEditViewInfoStates = set of TcxEditViewInfoState;

  TcxCustomEditViewInfo = class(TcxContainerViewInfo)
  private
    FOnDrawBackground: TcxEditDrawBackgroundEvent;
    FOnDrawButton: TcxEditDrawButtonEvent;
    FOnDrawButtonBackground: TcxEditDrawButtonBackgroundEvent;
    FOnDrawButtonBorder: TcxEditDrawButtonBorderEvent;
    FOnGetButtonState: TcxEditGetButtonStateEvent;
    FOnPaint: TcxEditPaintEvent;
    function DoDrawBackground(ACanvas: TcxCanvas): Boolean;
    function DoDrawButton(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer): Boolean;
    function DoDrawButtonBackground(ACanvas: TcxCanvas; const ARect: TRect; AButtonVisibleIndex: Integer): Boolean;
    function DoDrawButtonBorder(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
      out ABackgroundRect, AContentRect: TRect): Boolean;
    function GetDrawBackgroundStyle: TcxDrawBackgroundStyle;
    function IsNativeBackground: Boolean;
    function IsTransparent: Boolean;

    function GetPart(const P: TPoint): Integer;
    function GetPartRect(APart: Integer): TRect;
    function GetHintText(APart: Integer): string;
    function GetHintTextRect(const P: TPoint; APart: Integer): TRect;
  protected
    FEdit: TcxCustomEdit;
    FState: TcxEditViewInfoStates;
    function GetButtonViewInfoClass: TcxEditButtonViewInfoClass; virtual;
    procedure GetColorSettingsByPainter(out ABackground, ATextColor: TColor); virtual;
    function GetContainerBorderStyle: TcxContainerBorderStyle; override;
    procedure InternalPaint(ACanvas: TcxCanvas); override;
    function IsRepaintOnStateChangingNeeded: Boolean; virtual;
    procedure DrawEditButton(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer); virtual;
    procedure SetOnDrawBackground(AValue: TcxEditDrawBackgroundEvent); virtual;

    procedure Draw3DButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
      var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); virtual;
    procedure DrawFlatButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
      var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); virtual;
    procedure DrawHotFlatButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
      var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); virtual;
    procedure DrawNativeButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
      var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); virtual;
    procedure DrawSimpleButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
      var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); virtual;
    procedure DrawUltraFlatButtonBorder(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo;
      AIsOffice11Style: Boolean; var ARect: TRect; var AContentRect: TRect; out APenColor, ABrushColor: TColor); virtual;

    procedure DrawButtonBorderByPainter(AButtonViewInfo: TcxEditButtonViewInfo; var ARect: TRect; out AContentRect: TRect;
      var APenColor, ABrushColor: TColor);
    procedure DrawNativeButtonBackground(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo; const ARect: TRect); virtual;
    procedure DrawUsualButtonBackground(ACanvas: TcxCanvas; AButtonViewInfo: TcxEditButtonViewInfo; const ARect: TRect; ABrushColor: TColor); virtual;
  public
    BorderExtent: TRect;
    BorderStyle: TcxEditBorderStyle;
    ButtonsInfo: array of TcxEditButtonViewInfo;
    Calculated: Boolean;
    Data: Integer;
    EditProperties: TcxCustomEditProperties;
    Enabled: Boolean;
    Focused: Boolean;
    Font: TFont;
    HasBackground: Boolean;
    HasContentOffsets: Boolean;
    HasInnerEdit: Boolean;
    HasTextButtons: Boolean;
    HitTestInfo: Integer;
    HotState: TcxContainerHotState;
    InnerEditRect: TRect;
    IsButtonReallyPressed: Boolean;
    IsContainerInnerControl: Boolean;
    IsDBEditPaintCopyDrawing: Boolean;
    IsDesigning: Boolean;
    IsInplace: Boolean;
    IsSelected: Boolean;
    Left: Integer;
    PaintOptions: TcxEditPaintOptions;
    PopupBorderStyle: TcxEditPopupBorderStyle;
    PressedButton: Integer;
    SelectedButton: Integer;
    ShadowRect: TRect;
    TextColor: TColor;
    Top: Integer;
    Transparent: Boolean;
    WindowHandle: HWND;
    constructor Create; override;
    destructor Destroy; override;
    procedure Assign(Source: TObject); override;
    function GetUpdateRegion(AViewInfo: TcxContainerViewInfo): TcxRegion; override;
    procedure Offset(DX, DY: Integer); override;
    function DrawBackground(ACanvas: TcxCanvas): Boolean; overload;
    function DrawBackground(ACanvas: TcxCanvas; const APos: TPoint): Boolean; overload;
    procedure DrawButton(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer); virtual;
    procedure DrawButtons(ACanvas: TcxCanvas);
    procedure DrawEditBackground(ACanvas: TcxCanvas; ARect, AGlyphRect: TRect; AGlyphTransparent: Boolean);
    procedure DrawNativeStyleEditBackground(ACanvas: TcxCanvas; ADrawBackground: Boolean;
      ABackgroundStyle: TcxEditBackgroundPaintingStyle; ABackgroundBrush: TBrushHandle); virtual;
    function IsBackgroundTransparent: Boolean;

    procedure DrawButtonBackground(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
      const ARect: TRect; ABrushColor: TColor);
    procedure DrawButtonBorder(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
      var ARect: TRect; out AContentRect: TRect; var APenColor, ABrushColor: TColor); virtual;
    procedure DrawButtonContent(ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
      const AContentRect: TRect; APenColor, ABrushColor: TColor; ANeedOffsetContent: Boolean); virtual;

    function IsCustomBackground: Boolean;
    function IsCustomButton(AButtonVisibleIndex: Integer = 0): Boolean;
    function IsCustomButtonBackground(AButtonVisibleIndex: Integer = 0): Boolean;
    function IsCustomButtonBorder(AButtonVisibleIndex: Integer = 0): Boolean;
    function IsCustomDrawButton(AButtonVisibleIndex: Integer = 0): Boolean;

    function IsHotTrack: Boolean; overload; virtual;
    function IsHotTrack(P: TPoint): Boolean; overload; virtual;
    function NeedShowHint(ACanvas: TcxCanvas; const P: TPoint;
      out AText: TCaption; out AIsMultiLine: Boolean;
      out ATextRect: TRect): Boolean; overload; virtual;
    function NeedShowHint(ACanvas: TcxCanvas; const P: TPoint;
      const AVisibleBounds: TRect; out AText: TCaption;
      out AIsMultiLine: Boolean; out ATextRect: TRect): Boolean; overload; virtual;
    procedure Paint(ACanvas: TcxCanvas); override;
    procedure PaintEx(ACanvas: TcxCanvas);
    procedure PrepareCanvasFont(ACanvas: TCanvas); virtual;
    function Repaint(AControl: TWinControl;
      AViewInfo: TcxContainerViewInfo = nil): Boolean; overload; virtual;
    function Repaint(AControl: TWinControl; const AInnerEditRect: TRect;
      AViewInfo: TcxContainerViewInfo = nil): Boolean; overload; virtual;
    procedure SetButtonCount(ACount: Integer);
    property Edit: TcxCustomEdit read FEdit;
    property OnDrawBackground: TcxEditDrawBackgroundEvent read FOnDrawBackground
      write SetOnDrawBackground;
    property OnDrawButton: TcxEditDrawButtonEvent read FOnDrawButton
      write FOnDrawButton;
    property OnDrawButtonBackground: TcxEditDrawButtonBackgroundEvent
      read FOnDrawButtonBackground write FOnDrawButtonBackground;
    property OnDrawButtonBorder: TcxEditDrawButtonBorderEvent
      read FOnDrawButtonBorder write FOnDrawButtonBorder;
    property OnGetButtonState: TcxEditGetButtonStateEvent
      read FOnGetButtonState write FOnGetButtonState;
    property OnPaint: TcxEditPaintEvent read FOnPaint write FOnPaint;
  end;

  { TcxCustomEditViewData }

  TcxInplaceEditPosition = record
    Item: TObject;
    RecordIndex: Integer;
  end;

  TcxInplaceEditParams = record
    MultiRowParent: Boolean;
    Position: TcxInplaceEditPosition;
  end;

⌨️ 快捷键说明

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