📄 jveditor.pas
字号:
FMax: Integer;
FSmallChange: TScrollBarInc;
FLargeChange: TScrollBarInc;
FPage: Integer;
FHandle: HWND;
FOnScroll: TScrollEvent;
procedure SetParam(Index, Value: Integer);
protected
procedure Scroll(ScrollCode: TScrollCode; var ScrollPos: Integer); dynamic;
public
constructor Create;
procedure SetParams(AMin, AMax, APosition, APage: Integer);
procedure DoScroll(var Msg: TWMScroll);
property Kind: TScrollBarKind read FKind write FKind default sbHorizontal;
property SmallChange: TScrollBarInc read FSmallChange write FSmallChange default 1;
property LargeChange: TScrollBarInc read FLargeChange write FLargeChange default 1;
property Min: Integer index 0 read FMin write SetParam default 0;
property Max: Integer index 1 read FMax write SetParam default 100;
property Position: Integer index 2 read FPosition write SetParam default 0;
property Page: Integer index 3 read FPage write SetParam;
property Handle: HWND read FHandle write FHandle;
property OnScroll: TScrollEvent read FOnScroll write FOnScroll;
end;
TAdjustPersistentBlockMode = (
amInsert, amDelete, amDeleteLine, amLineConcat, amLineBreak
);
TJvCustomEditor = class(TCustomControl)
private
{ internal objects }
FLines: TJvEditorStrings;
scbHorz: TJvControlScrollBar95;
scbVert: TJvControlScrollBar95;
EditorClient: TJvEditorClient;
FGutter: TJvGutter;
FKeyboard: TJvKeyboard;
FUpdateLock: Integer;
FUndoBuffer: TUndoBuffer;
FGroupUndo: Boolean;
FUndoAfterSave: Boolean;
FCompletion: TJvCompletion;
{ internal - Columns and rows attributes }
FCols, FRows: Integer;
FLeftCol, FTopRow: Integer;
// FLeftColMax, FTopRowMax : Integer;
FLastVisibleCol: Integer;
FLastVisibleRow: Integer;
FCaretX: Integer;
FCaretY: Integer;
FVisibleColCount: Integer;
FVisibleRowCount: Integer;
{ internal - other flags and attributes }
FFontCache: TList; // collects all used fonts for faster font creation
FAllRepaint: Boolean;
FCellRect: TCellRect;
IgnoreKeyPress: Boolean;
WaitSecondKey: Boolean;
Key1: Word;
Shift1: TShiftState;
{ internal - selection attributes }
FSelection: TJvSelectionRec;
FUpdateSelBegY: Integer;
FUpdateSelEndY: Integer;
FPersistentBlocksCaretChanged: Boolean;
FclSelectBC: TColor;
FclSelectFC: TColor;
{ mouse support }
TimerScroll: TTimer;
MouseMoveY: Integer;
MouseMoveXX: Integer;
MouseMoveYY: Integer;
FDoubleClick: Boolean;
FMouseDowned: Boolean;
{ internal }
FTabPos: array[0..Max_X] of Boolean;
FTabStops: string;
MyDi: array[0..1024] of Integer;
{ internal - primary for TIReader support }
FEditBuffer: string;
FPEditBuffer: PChar;
FEditBufferSize: Integer;
FCompound: Integer;
{ FMacro - buffer of TEditCommand, each command represents by two chars }
FMacro: TMacro;
FDefMacro: TMacro;
{ visual attributes - properties }
FBorderStyle: TBorderStyle;
FGutterColor: TColor;
FGutterWidth: Integer;
FRightMarginVisible: Boolean;
FRightMargin: Integer;
FRightMarginColor: TColor;
FScrollBars: TScrollStyle;
FDoubleClickLine: Boolean;
FSmartTab: Boolean;
FBackSpaceUnindents: Boolean;
FAutoIndent: Boolean;
FKeepTrailingBlanks: Boolean;
FCursorBeyondEOF: Boolean;
FBlockOverwrite: Boolean;
FPersistentBlocks: Boolean;
FHideCaret: Boolean;
{ non-visual attributes - properties }
FInsertMode: Boolean;
FReadOnly: Boolean;
FModified: Boolean;
FRecording: Boolean;
{ Events }
FOnGetLineAttr: TOnGetLineAttr;
FOnChange: TNotifyEvent;
FOnSelectionChange: TNotifyEvent;
FOnChangeStatus: TOnChangeStatus;
FOnScroll: TNotifyEvent;
FOnResize: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FOnPaintGutter: TOnPaintGutter;
FOnGutterClick: TOnGutterClick;
FOnGutterDblClick: TOnGutterClick;
FOnCompletionIdentifier: TOnCompletion;
FOnCompletionTemplate: TOnCompletion;
FOnCompletionDrawItem: TDrawItemEvent;
FOnCompletionMeasureItem: TMeasureItemEvent;
FOnCompletionApply: TOnCompletionApply;
{ internal message processing }
{$IFNDEF COMPILER4_UP}
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
{$ENDIF COMPILER4_UP}
procedure WMEraseBkgnd(var Msg: TWmEraseBkgnd); message WM_ERASEBKGND;
procedure WMSetFocus(var Msg: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Msg: TWMSetFocus); message WM_KILLFOCUS;
procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMHScroll(var Msg: TWMHScroll); message WM_HSCROLL;
procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
procedure WMMouseWheel(var Msg: TWMMouseWheel); message WM_MOUSEWHEEL;
procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR;
procedure CMFontChanged(var Msg: TMessage); message CM_FONTCHANGED;
procedure WMEditCommand(var Msg: TMessage); message WM_EDITCOMMAND;
procedure WMCopy(var Msg: TMessage); message WM_COPY;
procedure WMCut(var Msg: TMessage); message WM_CUT;
procedure WMPaste(var Msg: TMessage); message WM_PASTE;
procedure UpdateEditorSize;
procedure DoCompletionIdentifier(var Cancel: Boolean);
procedure DoCompletionTemplate(var Cancel: Boolean);
procedure ScrollTimer(Sender: TObject);
procedure ReLine;
function GetDefTabStop(X: Integer; Next: Boolean): Integer;
function GetTabStop(X, Y: Integer; Next: Boolean): Integer;
function GetBackStop(X, Y: Integer): Integer;
procedure TextAllChangedInternal(Unselect: Boolean);
{ property }
procedure SetGutterWidth(AWidth: Integer);
procedure SetGutterColor(AColor: TColor);
function GetLines: TStrings;
procedure SetBorderStyle(Value: TBorderStyle);
procedure SetLines(ALines: TStrings);
function GetSelStart: Integer;
procedure SetSelStart(ASelStart: Integer);
procedure SetSelLength(ASelLength: Integer);
function GetSelLength: Integer;
procedure SetSelBlockFormat(Value: TSelBlockFormat);
procedure SetMode(Index: Integer; Value: Boolean);
procedure SetCaretPosition(Index, Pos: Integer);
procedure SetCols(ACols: Integer);
procedure SetRows(ARows: Integer);
procedure SetScrollBars(Value: TScrollStyle);
procedure SetRightMarginVisible(Value: Boolean);
procedure SetRightMargin(Value: Integer);
procedure SetRightMarginColor(Value: TColor);
procedure UpdateEditorView;
function GetSelBlockFormat: TSelBlockFormat;
function IsNewSelection: Boolean;
procedure AdjustPersistentBlockSelection(X, Y: Integer;
Mode: TAdjustPersistentBlockMode; Args: array of Integer);
procedure AdjustSelLineMode(Restore: Boolean);
protected
LineAttrs: TLineAttrs;
procedure Resize; {$IFDEF COMPILER4_UP} override; {$ELSE} dynamic; {$ENDIF}
procedure CreateWnd; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure Loaded; override;
procedure Paint; override;
procedure ScrollBarScroll(Sender: TObject; ScrollCode: TScrollCode; var
ScrollPos: Integer);
procedure Scroll(Vert: Boolean; ScrollPos: Integer);
procedure PaintLine(Line: Integer; ColBeg, ColEnd: Integer);
function FontCacheFind(LA: TLineAttr): TFont;
procedure FontCacheClear;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure InsertChar(const Key: Char);
function GetClipboardBlockFormat: TSelBlockFormat;
procedure SetClipboardBlockFormat(const Value: TSelBlockFormat);
procedure SetSel(SelX, SelY: Integer);
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseWheel(X, Y: Integer; WheelDelta: Integer; Shift: TShiftState); dynamic;
procedure DblClick; override;
procedure DoPaste; dynamic;
procedure DoCopy; dynamic;
procedure DoCut; dynamic;
procedure DoEnter; override;
procedure DoExit; override;
procedure CursorChanged; {$IFDEF VisualCLX} override; {$ELSE} dynamic; {$ENDIF}
procedure FontChanged; {$IFDEF VisualCLX} override; {$ELSE} dynamic; {$ENDIF}
procedure DrawRightMargin;
procedure PaintSelection;
procedure SetUnSelected;
procedure RemoveSelectedBlock;
procedure PersistentBlocksSetUnSelected;
procedure SetSelUpdateRegion(BegY, EndY: Integer);
procedure Mouse2Cell(X, Y: Integer; var CX, CY: Integer);
procedure Mouse2Caret(X, Y: Integer; var CX, CY: Integer);
procedure CaretCoord(X, Y: Integer; var CX, CY: Integer);
function PosFromMouse(X, Y: Integer): Integer;
procedure SetLockText(const Text: string);
function ExpandTabs(const S: string): string;
function GetAutoIndentStop(Y: Integer): Integer;
// add by patofan
{$IFDEF COMPILER3_UP}
function CheckDoubleByteChar(var x: Integer; y: Integer; ByteType: TMbcsByteType; delta_inc: Integer): Boolean;
{$ENDIF COMPILER3_UP}
// ending add by patofan
procedure NotUndoable;
procedure NotRedoable;
procedure SetCaretInternal(X, Y: Integer);
procedure ValidateEditBuffer;
procedure ChangeBookMark(BookMark: TBookMarkNum; Valid: Boolean);
procedure BeginRecord;
procedure EndRecord(var AMacro: TMacro);
procedure PlayMacro(const AMacro: TMacro);
{ triggers for descendants }
procedure Changed; dynamic;
procedure TextAllChanged; dynamic;
procedure StatusChanged; dynamic;
procedure SelectionChanged; dynamic;
procedure GetLineAttr(var Str: string; Line, ColBeg, ColEnd: Integer); virtual;
procedure GetAttr(Line, ColBeg, ColEnd: Integer); virtual;
procedure ChangeAttr(Line, ColBeg, ColEnd: Integer); virtual;
procedure GutterPaint(Canvas: TCanvas); dynamic;
procedure GutterClick(Line: Integer); dynamic;
procedure GutterDblClick(Line: Integer); dynamic;
procedure BookmarkChanged(BookMark: Integer); dynamic;
procedure CompletionIdentifier(var Cancel: Boolean); dynamic;
procedure CompletionTemplate(var Cancel: Boolean); dynamic;
{ TextModified is called when the editor content has changed. }
procedure TextModified(ACaretX, ACaretY: Integer; Action: TModifiedAction;
const Text: string); dynamic;
property Gutter: TJvGutter read FGutter;
public
BookMarks: TBookMarks;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetLeftTop(ALeftCol, ATopRow: Integer);
procedure ClipboardCopy;
procedure ClipboardPaste;
procedure ClipboardCut;
function CanCopy: Boolean;
function CanPaste: Boolean;
function CanCut: Boolean;
procedure DeleteSelected;
procedure SelectAll;
procedure ClearSelection;
procedure SelectRange(BegX, BegY, EndX, EndY: Integer);
function CalcCellRect(X, Y: Integer): TRect;
procedure SetCaret(X, Y: Integer);
procedure CaretFromPos(Pos: Integer; var X, Y: Integer);
function PosFromCaret(X, Y: Integer): Integer;
procedure PaintCaret(bShow: Boolean);
function GetTextLen: Integer;
function GetSelText: string;
procedure SetSelText(const AValue: string);
function GetWordOnCaret: string;
procedure BeginUpdate;
procedure EndUpdate;
procedure MakeRowVisible(ARow: Integer);
procedure Command(ACommand: TEditCommand); virtual;
procedure PostCommand(ACommand: TEditCommand);
procedure InsertText(const Text: string);
procedure InsertColumnText(X, Y: Integer; const Text: string);
procedure ReplaceWord(const NewString: string);
procedure ReplaceWord2(const NewString: string);
procedure IndentColumns(X: Integer; BegY, EndY: Integer);
procedure UnIndentColumns(X: Integer; BegY, EndY: Integer);
procedure IndentLines(UnIndent: Boolean; BegY, EndY: Integer);
procedure IndentSelLines(UnIndent: Boolean);
procedure BeginCompound;
procedure EndCompound;
function GetText(Position: Longint; Buffer: PChar; Count: Longint): Longint;
property LeftCol: Integer read FLeftCol;
property TopRow: Integer read FTopRow;
property VisibleColCount: Integer read FVisibleColCount;
property VisibleRowCount: Integer read FVisibleRowCount;
property LastVisibleCol: Integer read FLastVisibleCol;
property LastVisibleRow: Integer read FLastVisibleRow;
property Cols: Integer read FCols write SetCols;
property Rows: Integer read FRows write SetRows;
property CaretX: Integer index 0 read FCaretX write SetCaretPosition;
property CaretY: Integer index 1 read FCaretY write SetCaretPosition;
property Modified: Boolean read FModified write FModified;
property SelBlockFormat: TSelBlockFormat read GetSelBlockFormat write SetSelBlockFormat default bfNonInclusive;
property SelStart: Integer read GetSelStart write SetSelStart;
property SelLength: Integer read GetSelLength write SetSelLength;
property SelText: string read GetSelText write SetSelText;
property Keyboard: TJvKeyboard read FKeyboard;
property CellRect: TCellRect read FCellRect;
property UndoBuffer: TUndoBuffer read FUndoBuffer;
property GroupUndo: Boolean read FGroupUndo write FGroupUndo default True;
property UndoAfterSave: Boolean read FUndoAfterSave write FUndoAfterSave;
property Recording: Boolean read FRecording;
public { published in descendants }
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property Lines: TStrings read GetLines write SetLines;
property ScrollBars: TScrollStyle read FScrollBars write SetScrollBars default ssBoth;
property Cursor default crIBeam;
property Color default clWindow;
property GutterWidth: Integer read FGutterWidth write SetGutterWidth;
property GutterColor: TColor read FGutterColor write SetGutterColor default clBtnFace;
property RightMarginVisible: Boolean read FRightMarginVisible write SetRightMarginVisible default True;
property RightMargin: Integer read FRightMargin write SetRightMargin default 80;
property RightMarginColor: TColor read FRightMarginColor write SetRightMarginColor default clBtnFace;
property InsertMode: Boolean index 0 read FInsertMode write SetMode default True;
property ReadOnly: Boolean index 1 read FReadOnly write SetMode default False;
property DoubleClickLine: Boolean read FDoubleClickLine write FDoubleClickLine default False;
property Completion: TJvCompletion read FCompletion write FCompletion;
property TabStops: string read FTabStops write FTabStops;
property SmartTab: Boolean read FSmartTab write FSmartTab default True;
property BackSpaceUnindents: Boolean read FBackSpaceUnindents write FBackSpaceUnindents default True;
property AutoIndent: Boolean read FAutoIndent write FAutoIndent default True;
property KeepTrailingBlanks: Boolean read FKeepTrailingBlanks write FKeepTrailingBlanks default False;
property CursorBeyondEOF: Boolean read FCursorBeyondEOF write FCursorBeyondEOF default False;
property BlockOverwrite: Boolean read FBlockOverwrite write FBlockOverwrite default True;
property PersistentBlocks: Boolean read FPersistentBlocks write FPersistentBlocks default False;
property SelForeColor: TColor read FclSelectFC write FclSelectFC;
property SelBackColor: TColor read FclSelectBC write FclSelectBC;
property HideCaret: Boolean read FHideCaret write FHideCaret default False;
property OnGetLineAttr: TOnGetLineAttr read FOnGetLineAttr write FOnGetLineAttr;
property OnChangeStatus: TOnChangeStatus read FOnChangeStatus write FOnChangeStatus;
property OnScroll: TNotifyEvent read FOnScroll write FOnScroll;
property OnResize: TNotifyEvent read FOnResize write FOnResize;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnSelectionChange: TNotifyEvent read FOnSelectionChange write FOnSelectionChange;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
property OnPaintGutter: TOnPaintGutter read FOnPaintGutter write FOnPaintGutter;
property OnGutterClick: TOnGutterClick read FOnGutterClick write FOnGutterClick;
property OnGutterDblClick: TOnGutterClick read FOnGutterDblClick write FOnGutterDblClick;
property OnCompletionIdentifier: TOnCompletion read FOnCompletionIdentifier write FOnCompletionIdentifier;
property OnCompletionTemplate: TOnCompletion read FOnCompletionTemplate write FOnCompletionTemplate;
property OnCompletionDrawItem: TDrawItemEvent read FOnCompletionDrawItem write FOnCompletionDrawItem;
property OnCompletionMeasureItem: TMeasureItemEvent read FOnCompletionMeasureItem write FOnCompletionMeasureItem;
property OnCompletionApply: TOnCompletionApply read FOnCompletionApply write FOnCompletionApply;
{$IFDEF COMPILER4_UP}
property DockManager;
{$ENDIF COMPILER4_UP}
end;
TJvEditor = class(TJvCustomEditor)
published
property BorderStyle;
property Lines;
property ScrollBars;
property GutterWidth;
property GutterColor;
property RightMarginVisible;
property RightMargin;
property RightMarginColor;
property InsertMode;
property ReadOnly;
property DoubleClickLine;
property HideCaret;
property Completion;
property TabStops;
property SmartTab;
property BackSpaceUnindents;
property AutoIndent;
property KeepTrailingBlanks;
property CursorBeyondEOF;
property SelForeColor;
property SelBackColor;
property SelBlockFormat;
property OnGetLineAttr;
property OnChangeStatus;
property OnScroll;
property OnResize;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnChange;
property OnSelectionChange;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -