📄 jveditorcommon.pas
字号:
procedure Redo;
procedure Clear; override;
procedure Delete;
function CanUndo: Boolean;
end;
TJvUndo = class(TInterfacedObject)
protected
FJvEditor: TJvCustomEditorBase;
FModified: Boolean; // Editor.FModified
FSelection: PJvSelectionRec;
function UndoBuffer: TJvUndoBuffer;
protected
property JvEditor: TJvCustomEditorBase read FJvEditor;
public
constructor Create(AJvEditor: TJvCustomEditorBase);
destructor Destroy; override;
procedure Undo; dynamic; abstract;
procedure Redo; dynamic; {abstract;}
procedure SaveSelection;
procedure RestoreSelection;
end;
TJvCaretUndo = class(TJvUndo)
protected
FCaretX: Integer;
FCaretY: Integer;
property CaretX: Integer read FCaretX write FCaretX;
property CaretY: Integer read FCaretY write FCaretY;
public
constructor Create(AJvEditor: TJvCustomEditorBase; ACaretX, ACaretY: Integer);
procedure Undo; override;
end;
TJvSelectUndo = class(TJvCaretUndo)
public
constructor Create(AJvEditor: TJvCustomEditorBase; ACaretX, ACaretY: Integer);
procedure Undo; override;
end;
TJvUnselectUndo = class(TJvSelectUndo);
TJvBeginCompoundUndo = class(TJvUndo)
public
procedure Undo; override;
end;
TJvEndCompoundUndo = class(TJvBeginCompoundUndo);
TJvControlScrollBar95 = class(TObject)
private
FKind: TScrollBarKind;
FPosition: Integer;
FMin: Integer;
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;
TJvEditorClient = class(TObject)
public
FJvEditor: TJvCustomEditorBase;
Top: Integer;
function Left: Integer;
function Height: Integer;
function Width: Integer;
function ClientWidth: Integer;
function ClientHeight: Integer;
function ClientRect: TRect;
function BoundsRect: TRect;
function GetCanvas: TJvUnicodeCanvas;
property Canvas: TJvUnicodeCanvas read GetCanvas;
end;
TJvGutter = class(TObject)
private
FJvEditor: TJvCustomEditorBase;
public
procedure Paint;
procedure Invalidate;
end;
TJvLineInformation = class(TObject)
private
FLine: Integer;
FSelectStyle: TJvLineSelectStyle;
FData: Pointer;
FEditor: TJvCustomEditorBase;
procedure SetLine(Value: Integer);
procedure SetSelectStyle(const Value: TJvLineSelectStyle);
protected
procedure RepaintLine(LineNum: Integer); virtual;
procedure CheckEmpty; virtual; // releases the object if Data=nil and SelectStyle=lssUnselected
public
constructor Create(AEditor: TJvCustomEditorBase; ALine: Integer);
destructor Destroy; override;
property Line: Integer read FLine write SetLine;
property SelectStyle: TJvLineSelectStyle read FSelectStyle write SetSelectStyle;
property Data: Pointer read FData write FData;
property Editor: TJvCustomEditorBase read FEditor;
end;
TJvLineInformationList = class(TObject)
private
FEditor: TJvCustomEditorBase;
FList: TObjectList;
FDebugColor: TColor;
FDebugTextColor: TColor;
FBreakpointColor: TColor;
FBreakpointTextColor: TColor;
FErrorPointTextColor: TColor;
FErrorPointColor: TColor;
function GetCount: Integer;
function GetData(Index: Integer): Pointer;
function GetItems(Index: Integer): TJvLineInformation;
function GetLineCount: Integer;
function GetLines(Index: Integer): TJvLineInformation;
function GetSelectStyle(Index: Integer): TJvLineSelectStyle;
procedure SetData(Index: Integer; Value: Pointer);
procedure SetSelectStyle(Index: Integer; const Value: TJvLineSelectStyle);
procedure SetBreakpointColor(const Value: TColor);
procedure SetBreakpointTextColor(const Value: TColor);
procedure SetDebugColor(const Value: TColor);
procedure SetDebugTextColor(const Value: TColor);
procedure SetErrorPointColor(const Value: TColor);
procedure SetErrorPointTextColor(const Value: TColor);
protected
function CreateLineInfo(Index: Integer): TJvLineInformation;
// Returns the line information assoziated with the line or creates a new.
// If Index not in [0..Count-1] the function raises EListError
public
constructor Create(AEditor: TJvCustomEditorBase);
destructor Destroy; override;
procedure Clear;
// Clear() removes all extra line information objects
property Count: Integer read GetCount;
property Items[Index: Integer]: TJvLineInformation read GetItems;
property LineCount: Integer read GetLineCount;
// LineCount returns Editor.Lines.Count
property Lines[Index: Integer]: TJvLineInformation read GetLines; default;
// Lines[] returns nil if the line has no extra information
property SelectStyle[Index: Integer]: TJvLineSelectStyle read GetSelectStyle write SetSelectStyle;
// SelectStyle[] returns/sets the select style for the line
property Data[Index: Integer]: Pointer read GetData write SetData;
// Data[] returns/sets the user defined data for the line
property DebugPointColor: TColor read FDebugColor write SetDebugColor;
property DebugPointTextColor: TColor read FDebugTextColor write SetDebugTextColor;
property BreakpointColor: TColor read FBreakpointColor write SetBreakpointColor;
property BreakpointTextColor: TColor read FBreakpointTextColor write SetBreakpointTextColor;
property ErrorPointColor: TColor read FErrorPointColor write SetErrorPointColor;
property ErrorPointTextColor: TColor read FErrorPointTextColor write SetErrorPointTextColor;
property Editor: TJvCustomEditorBase read FEditor;
end;
TJvBracketHighlighting = class(TPersistent)
private
FStart: TRect;
FStop: TRect;
FActive: Boolean;
FFontColor: TColor;
FBorderColor: TColor;
FColor: TColor;
FWordPairs: TStrings;
FCaseSensitiveWordPairs: Boolean;
procedure SetWordPairs(Value: TStrings);
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property Active: Boolean read FActive write FActive default False;
property BorderColor: TColor read FBorderColor write FBorderColor default clSilver;
property Color: TColor read FColor write FColor default clNone;
property FontColor: TColor read FFontColor write FFontColor default clNone;
property CaseSensitiveWordPairs: Boolean read FCaseSensitiveWordPairs write FCaseSensitiveWordPairs default True;
property WordPairs: TStrings read FWordPairs write SetWordPairs;
{ example: "begin=end", "repeat=until", "for=do", "asm=end" }
end;
TJvCustomEditorBase = class(TJvCustomControl, IFixedPopupIntf)
private
{ internal objects }
FScrollBarHorz: TJvControlScrollBar95;
FScrollBarVert: TJvControlScrollBar95;
FEditorClient: TJvEditorClient;
FCompletion: TJvCompletionBase; // must be initialized by a decendent
FGutter: TJvGutter;
FKeyboard: TJvKeyboard;
FUpdateLock: Integer;
FUndoBuffer: TJvUndoBuffer;
FGroupUndo: Boolean;
FUndoAfterSave: Boolean;
FBracketHighlighting: TJvBracketHighlighting;
{ internal - Columns and rows attributes }
FCols: Integer;
FRows: Integer;
FLeftCol: Integer;
FTopRow: Integer;
// FLeftColMax, FTopRowMax : Integer;
FLastVisibleCol: Integer;
FLastVisibleRow: 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 }
FUpdateSelBegY: Integer;
FUpdateSelEndY: Integer;
FPersistentBlocksCaretChanged: Boolean;
FSelBackColor: TColor;
FSelForeColor: TColor;
FLineInformations: TJvLineInformationList;
{ mouse support }
TimerScroll: TTimer;
MouseMoveY: Integer;
MouseMoveXX: Integer;
MouseMoveYY: Integer;
FDoubleClick: Boolean;
FMouseDown: Boolean;
{ internal }
FTabStops: AnsiString; // Tabs string is always an AnsiString
FCompound: Integer;
{ 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;
FBeepOnError: Boolean;
FUseFixedPopup: Boolean;
{ events }
FOnChange: TNotifyEvent;
FOnSelectionChange: TNotifyEvent;
FOnChangeStatus: TNotifyEvent;
FOnScroll: TNotifyEvent;
FOnResize: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FOnPaintGutter: TOnPaintGutter;
FOnGutterClick: TOnGutterClick;
FOnGutterDblClick: TOnGutterClick;
FOnCompletionIdentifier: TOnCompletion;
FOnCompletionTemplate: TOnCompletion;
FOnCompletionDrawItem: TDrawItemEvent;
FOnCompletionMeasureItem: TMeasureItemEvent;
FCurrentLineHighlight: TColor;
{ internal message processing }
procedure WMEditCommand(var Msg: TMessage); message WM_EDITCOMMAND;
procedure WMCompound(var Msg: TMessage); message WM_COMPOUND;
procedure CMResetCaptureControl(var Msg: TMessage); message CM_RESETCAPTURECONTROL;
{$IFDEF VCL}
procedure WMHScroll(var Msg: TWMHScroll); message WM_HSCROLL;
procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR;
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 WMUndo(var Msg: TMessage); message WM_UNDO;
// (p3) added to be compatible with JvFixedEditPopup
procedure WMClear(var Msg: TMessage); message WM_CLEAR;
procedure EMSetReadOnly(var Msg: TMessage); message EM_SETREADONLY;
procedure EMSetSelection(var Msg: TMessage); message EM_SETSEL;
procedure EMGetSelection(var Msg: TMessage); message EM_GETSEL;
procedure EMCanUndo(var Msg: TMessage); message EM_CANUNDO;
procedure WMGetTextLength(var Msg: TMessage); message WM_GETTEXTLENGTH;
{$ENDIF VCL}
protected
FMyDi: TDynIntArray; //array [0..Max_X] of Integer;
FSelection: TJvSelectionRec;
FCaretX: Integer;
FCaretY: Integer;
FTabPos: array [0..Max_X] of Boolean;
{ FMacro - buffer of TEditCommand, each command represents by two chars }
FMacro: TMacro;
FDefMacro: TMacro;
procedure UpdateEditorSize; virtual;
procedure UpdateEditorView; virtual;
procedure ScrollTimer(Sender: TObject);
function ExpandTabsAnsi(const S: AnsiString): AnsiString; // ClipboardPaste
function GetDefTabStop(X: Integer; Next: Boolean): Integer; virtual;
function GetTabStop(X, Y: Integer; Next: Boolean): Integer; virtual; abstract;
function GetBackStop(X, Y: Integer): Integer; virtual; abstract;
function GetAutoIndentStop(Y: Integer): Integer; virtual; abstract;
function GetAnsiTextLine(Y: Integer; out Text: AnsiString): Boolean; virtual; abstract;
function GetAnsiWordOnCaret: AnsiString; virtual; abstract;
{ triggers when Lines changes }
procedure DoLinesChange(Sender: TObject); virtual;
procedure ReLine; virtual; abstract;
procedure TextAllChangedInternal(Unselect: Boolean); virtual;
{ triggers for descendants }
procedure Changed; dynamic;
procedure TextAllChanged; dynamic;
procedure StatusChanged; dynamic;
procedure SelectionChanged; dynamic;
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -