📄 tooledit.pas
字号:
{*******************************************************}
{ }
{ Delphi VCL Extensions (RX) }
{ }
{ Copyright (c) 1995, 1996 AO ROSNO }
{ Copyright (c) 1997, 1998 Master-Bank }
{ }
{*******************************************************}
unit ToolEdit;
interface
{$I RX.INC}
uses Windows, RTLConsts, Variants, Classes,
StdCtrls, Controls, Messages, SysUtils, Forms, Graphics, Menus, Buttons,
Dialogs, RxCtrls, FileCtrl, Mask, DateUtil;
const
scAltDown = scAlt + vk_Down;
DefEditBtnWidth = 21;
type
{$IFDEF WIN32}
TFileExt = type string;
{$ENDIF}
{ TPopupWindow }
TCloseUpEvent = procedure (Sender: TObject; Accept: Boolean) of object;
TPopupAlign = (epaRight, epaLeft);
TPopupWindow = class(TCustomControl)
private
FEditor: TWinControl;
FCloseUp: TCloseUpEvent;
procedure WMMouseActivate(var Message: TMessage); message WM_MOUSEACTIVATE;
protected
procedure CreateParams(var Params: TCreateParams); override;
{$IFDEF WIN32}
function GetValue: Variant; virtual; abstract;
procedure SetValue(const Value: Variant); virtual; abstract;
{$ELSE}
procedure CreateWnd; override;
function GetValue: string; virtual; abstract;
procedure SetValue(const Value: string); virtual; abstract;
{$ENDIF}
procedure InvalidateEditor;
procedure PopupMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure CloseUp(Accept: Boolean); virtual;
public
constructor Create(AOwner: TComponent); override;
function GetPopupText: string; virtual;
procedure Hide;
procedure Show(Origin: TPoint);
property OnCloseUp: TCloseUpEvent read FCloseUp write FCloseUp;
end;
{ TCustomComboEdit }
TEditButton = class(TRxSpeedButton)
private
FNoAction: Boolean;
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
{$IFDEF WIN32}
procedure Paint; override;
{$ENDIF WIN32}
public
constructor Create(AOwner: TComponent); override;
procedure Click; override;
end;
TGlyphKind = (gkCustom, gkDefault, gkDropDown, gkEllipsis);
TCustomComboEdit = class(TCustomMaskEdit)
private
FButton: TEditButton;
FBtnControl: TWinControl;
FOnButtonClick: TNotifyEvent;
FClickKey: TShortCut;
FReadOnly: Boolean;
FDirectInput: Boolean;
FAlwaysEnable: Boolean;
FAlignment: TAlignment;
FPopupVisible: Boolean;
FFocused: Boolean;
FPopupAlign: TPopupAlign;
FGlyphKind: TGlyphKind;
procedure SetEditRect;
procedure RecreateGlyph;
procedure UpdateBtnBounds;
procedure EditButtonClick(Sender: TObject);
function GetMinHeight: Integer;
function GetTextHeight: Integer;
procedure SetShowCaret;
function GetGlyph: TBitmap;
procedure SetGlyph(Value: TBitmap);
function GetPopupVisible: Boolean;
function GetNumGlyphs: TNumGlyphs;
procedure SetNumGlyphs(Value: TNumGlyphs);
function GetButtonWidth: Integer;
procedure SetButtonWidth(Value: Integer);
function GetButtonHint: string;
procedure SetButtonHint(const Value: string);
function GetDirectInput: Boolean;
procedure SetDirectInput(Value: Boolean);
procedure SetReadOnly(Value: Boolean);
procedure SetAlignment(Value: TAlignment);
function IsCustomGlyph: Boolean;
function BtnWidthStored: Boolean;
procedure SetGlyphKind(Value: TGlyphKind);
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMCancelMode(var Message: TCMCancelMode); message CM_CANCELMODE;
procedure CMEnter(var Message: TMessage); message CM_ENTER;
procedure CNCtlColor(var Message: TMessage); message
{$IFDEF WIN32} CN_CTLCOLOREDIT {$ELSE} CN_CTLCOLOR {$ENDIF};
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMSetFocus(var Message: TMessage); message WM_SETFOCUS;
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
procedure WMCut(var Message: TWMCut); message WM_CUT;
{$IFDEF WIN32}
procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
{$ENDIF}
{$IFDEF RX_D4}
procedure CMBiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;
{$ENDIF}
protected
FPopup: TCustomControl;
FDefNumGlyphs: TNumGlyphs;
function GetDefaultBitmap(var DestroyNeeded: Boolean): TBitmap; virtual;
procedure PopupDropDown(DisableEdit: Boolean); virtual;
procedure PopupCloseUp(Sender: TObject; Accept: Boolean);
procedure ShowPopup(Origin: TPoint); virtual;
procedure HidePopup; virtual;
procedure UpdatePopupVisible;
procedure DoChange;
{$IFDEF WIN32}
function AcceptPopup(var Value: Variant): Boolean; virtual;
procedure AcceptValue(const Value: Variant); virtual;
procedure SetPopupValue(const Value: Variant); virtual;
function GetPopupValue: Variant; virtual;
{$ELSE}
function AcceptPopup(var Value: string): Boolean; virtual;
procedure AcceptValue(const Value: string); virtual;
procedure SetPopupValue(const Value: string); virtual;
function GetPopupValue: string; virtual;
{$ENDIF}
procedure Change; override;
procedure PopupChange; virtual;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
function EditCanModify: Boolean; override;
function GetReadOnly: Boolean; virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure ButtonClick; dynamic;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property AlwaysEnable: Boolean read FAlwaysEnable write FAlwaysEnable default False;
property Button: TEditButton read FButton;
property ClickKey: TShortCut read FClickKey write FClickKey
default scAltDown;
property Glyph: TBitmap read GetGlyph write SetGlyph stored IsCustomGlyph;
property GlyphKind: TGlyphKind read FGlyphKind write SetGlyphKind default gkCustom;
property ButtonWidth: Integer read GetButtonWidth write SetButtonWidth
stored BtnWidthStored;
property NumGlyphs: TNumGlyphs read GetNumGlyphs write SetNumGlyphs;
property ButtonHint: string read GetButtonHint write SetButtonHint;
property DirectInput: Boolean read GetDirectInput write SetDirectInput default True;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
property PopupAlign: TPopupAlign read FPopupAlign write FPopupAlign default epaRight;
property PopupVisible: Boolean read GetPopupVisible;
property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DoClick;
procedure SelectAll;
end;
{ TComboEdit }
TComboEdit = class(TCustomComboEdit)
public
property Button;
published
property Alignment;
property AutoSelect;
property BorderStyle;
property ButtonHint;
property CharCase;
property ClickKey;
property Color;
property Ctl3D;
property DirectInput;
property DragCursor;
property DragMode;
property EditMask;
property Enabled;
property Font;
property GlyphKind;
{ Ensure GlyphKind is published before Glyph and ButtonWidth }
property Glyph;
property ButtonWidth;
property HideSelection;
{$IFDEF RX_D4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
{$ENDIF}
{$IFDEF WIN32}
{$IFNDEF VER90}
property ImeMode;
property ImeName;
{$ENDIF}
{$ENDIF}
property MaxLength;
property NumGlyphs;
property OEMConvert;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnButtonClick;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
{$IFDEF WIN32}
property OnStartDrag;
{$ENDIF}
{$IFDEF RX_D5}
property OnContextPopup;
{$ENDIF}
{$IFDEF RX_D4}
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
{ TFileDirEdit }
{ The common parent of TFilenameEdit and TDirectoryEdit }
{ For internal use only; it's not intended to be used separately }
{$IFNDEF WIN32}
const
MaxFileLength = SizeOf(TFileName) - 1;
{$ENDIF}
type
TExecOpenDialogEvent = procedure(Sender: TObject; var Name: string;
var Action: Boolean) of object;
TFileDirEdit = class(TCustomComboEdit)
private
FErrMode: Cardinal;
FAcceptFiles: Boolean;
FOnDropFiles: TNotifyEvent;
FOnBeforeDialog: TExecOpenDialogEvent;
FOnAfterDialog: TExecOpenDialogEvent;
procedure SetDragAccept(Value: Boolean);
procedure SetAcceptFiles(Value: Boolean);
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
protected
FMultipleDirs: Boolean;
procedure CreateHandle; override;
procedure DestroyWindowHandle; override;
function GetDefaultBitmap(var DestroyNeeded: Boolean): TBitmap; override;
{$IFDEF WIN32}
function GetLongName: string; virtual; abstract;
function GetShortName: string; virtual; abstract;
{$ENDIF}
procedure DoAfterDialog(var FileName: string; var Action: Boolean); dynamic;
procedure DoBeforeDialog(var FileName: string; var Action: Boolean); dynamic;
procedure ReceptFileDir(const AFileName: string); virtual; abstract;
procedure ClearFileList; virtual;
procedure DisableSysErrors;
procedure EnableSysErrors;
property GlyphKind default gkDefault;
property MaxLength {$IFNDEF WIN32} default MaxFileLength {$ENDIF};
public
constructor Create(AOwner: TComponent); override;
{$IFDEF WIN32}
property LongName: string read GetLongName;
property ShortName: string read GetShortName;
{$ENDIF}
published
property AcceptFiles: Boolean read FAcceptFiles write SetAcceptFiles default False;
property OnBeforeDialog: TExecOpenDialogEvent read FOnBeforeDialog
write FOnBeforeDialog;
property OnAfterDialog: TExecOpenDialogEvent read FOnAfterDialog
write FOnAfterDialog;
property OnDropFiles: TNotifyEvent read FOnDropFiles write FOnDropFiles;
property OnButtonClick;
end;
{ TFilenameEdit }
TFileDialogKind = (dkOpen, dkSave {$IFDEF RX_D3}, dkOpenPicture,
dkSavePicture {$ENDIF});
TFilenameEdit = class(TFileDirEdit)
private
FDialog: TOpenDialog;
FDialogKind: TFileDialogKind;
procedure CreateEditDialog;
function GetFileName: string;
function GetDefaultExt: TFileExt;
function GetFileEditStyle: TFileEditStyle;
function GetFilter: string;
function GetFilterIndex: Integer;
function GetInitialDir: string;
function GetHistoryList: TStrings;
function GetOptions: TOpenOptions;
function GetDialogTitle: string;
function GetDialogFiles: TStrings;
procedure SetDialogKind(Value: TFileDialogKind);
procedure SetFileName(const Value: string);
procedure SetDefaultExt(Value: TFileExt);
procedure SetFileEditStyle(Value: TFileEditStyle);
procedure SetFilter(const Value: string);
procedure SetFilterIndex(Value: Integer);
procedure SetInitialDir(const Value: string);
procedure SetHistoryList(Value: TStrings);
procedure SetOptions(Value: TOpenOptions);
procedure SetDialogTitle(const Value: string);
function IsCustomTitle: Boolean;
function IsCustomFilter: Boolean;
protected
procedure ButtonClick; override;
procedure ReceptFileDir(const AFileName: string); override;
procedure ClearFileList; override;
{$IFDEF WIN32}
function GetLongName: string; override;
function GetShortName: string; override;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
property Dialog: TOpenDialog read FDialog;
property DialogFiles: TStrings read GetDialogFiles;
published
property DialogKind: TFileDialogKind read FDialogKind write SetDialogKind
default dkOpen;
property DefaultExt: TFileExt read GetDefaultExt write SetDefaultExt;
property FileEditStyle: TFileEditStyle read GetFileEditStyle write SetFileEditStyle
default fsEdit;
property FileName: string read GetFileName write SetFileName stored False;
property Filter: string read GetFilter write SetFilter stored IsCustomFilter;
property FilterIndex: Integer read GetFilterIndex write SetFilterIndex default 1;
property InitialDir: string read GetInitialDir write SetInitialDir;
property HistoryList: TStrings read GetHistoryList write SetHistoryList;
property DialogOptions: TOpenOptions read GetOptions write SetOptions
default [ofHideReadOnly];
property DialogTitle: string read GetDialogTitle write SetDialogTitle
stored IsCustomTitle;
property AutoSelect;
property ButtonHint;
property BorderStyle;
property CharCase;
property ClickKey;
property Color;
property Ctl3D;
property DirectInput;
property DragCursor;
property DragMode;
property EditMask;
property Enabled;
property Font;
property GlyphKind;
{ Ensure GlyphKind is declared before Glyph and ButtonWidth }
property Glyph;
property ButtonWidth;
property HideSelection;
{$IFDEF RX_D4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
{$ENDIF}
{$IFDEF WIN32}
{$IFNDEF VER90}
property ImeMode;
property ImeName;
{$ENDIF}
{$ENDIF}
property NumGlyphs;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
{$IFDEF WIN32}
property OnStartDrag;
{$ENDIF}
{$IFDEF RX_D5}
property OnContextPopup;
{$ENDIF}
{$IFDEF RX_D4}
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
{ TDirectoryEdit }
{$IFDEF WIN32}
TDirDialogKind = (dkVCL, dkWin32);
{$ENDIF}
TDirectoryEdit = class(TFileDirEdit)
private
FOptions: TSelectDirOpts;
FInitialDir: string;
{$IFDEF WIN32}
FDialogText: string;
FDialogKind: TDirDialogKind;
{$ENDIF}
protected
procedure ButtonClick; override;
procedure ReceptFileDir(const AFileName: string); override;
{$IFDEF WIN32}
function GetLongName: string; override;
function GetShortName: string; override;
{$ENDIF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -