📄 memoex.pas
字号:
ETS_SELECTED = 3;
ETS_DISABLED = 4;
ETS_FOCUSED = 5;
ETS_READONLY = 6;
ETS_ASSIST = 7;
type //行号的对齐方式 (左对齐、中间对齐、右对齐) 赵亦平 2004.12.12
TLineNumberAlign = (laLeft, laCenter, laRight); //Windows XP themes support for TMemoEx. HTHEME = THandle;
TIsThemeActive = function: boolean; stdcall;
TOpenThemeData = function (hwnd: HWND; pszClassList: PWideChar): HTHEME; stdcall;
TCloseThemeData = function (Theme: HTHEME) : HRESULT; stdcall;
TIsThemeBackgroundPartiallyTransparent = function(Theme: HTHEME; iPartId, iStateId: integer): boolean; stdcall; TDrawThemeParentBackground = function (hwnd: HWND; hdc: HDC; const Rect: TRect): HRESULT; stdcall; TDrawThemeBackground = function (Theme: HTHEME; hdc: HDC; iPartId: integer; iStateId: integer; const Rect: TRect; pClipRect: PRect): HRESULT; stdcall; TCellRect = record Width: integer; Height: integer; end; TLineAttr = record FC, BC: TColor; Style: TFontStyles; ex_style: byte; end; TCustomMemoEx = class; { Line of attributes. Unlimited array helps to not to think about very long lines. } TLineAttrs = array of TLineAttr; { Line of selected symbols. } TSelAttrs = array of boolean; { User-defined attributes provider. } TOnGetLineAttr = procedure(Sender: TObject; const Line: string; Index: integer; const SelAttrs: TSelAttrs; var Attrs: TLineAttrs) of object; { Event which fires when gutter is being painted. } TOnPaintGutter = procedure (Sender: TObject; Canvas: TCanvas) of object; { Event which fires on status (insert/overwrite mode, record mode, undo buffer, selection) change. } TOnChangeStatus = TNotifyEvent; { Event which fires on clipboard change. CanPaste is true when there is a text in clipboard. } TOnChangeClipboardState = procedure (Sender: TObject; const CanPaste: boolean) of object; { Event which fires when user click on the word. The word is the text with one style. WordText contains text of the word. WordStyle contains style of the word. } TOnWordClick = procedure (Sender: TObject; const WordText: string; WordStyle: word) of object; { Event which fires when user move mouse over the text. WordStyle contains style of the word under mouse cursor. _Cursor contains one of the available cursor images index. } TOnMouseOver = procedure (Sender: TObject; WordStyle: word; var _Cursor: TCursor) of object; { Event which fires when the line is being break. Original contains not breaked yet line. _New contains part of the line which will be wrapped. } TOnBreakLine = procedure (Sender: TObject; const Original: string; var _New: string) of object; { Event which fires when two lines are being pasted together. Original contains line to which _New will be pasted. _New contains line being pated to Original. } TOnConcatLine = procedure (Sender: TObject; const Original: string; var _New: string) of object; { Event which fires when the text is being inserted with InsertTextAtCurrentPos, block insert or pasted from clipboard. } TOnTextInsert = procedure (Sender: TObject; var Text: string) of object; { User-defined case conversion routine. } TOnCaseConversion = function (Sender: TObject; Conversion: byte; const Text: string): string of object; { Block insert. Text contains a text of the block being inserted. } TOnInsertBlock = function (Sender: TObject; var Text: string): boolean of object; { Block save. Text contains a text of the block for saving in file. } TOnSaveBlock = procedure (Sender: TObject; const Text: string) of object; { MacroID is the identifier of the macro shortcut. The result of the event is the text being inserted at current position. } TOnInsertMacro = function (Sender: TObject; MacroID: integer): string of object; { User-defined block operation. MacroID contains identifier of the block operation. Text contains the text of the block to operate. The result of the event is the modified Text. } TOnBlockOperation = function (Sender: TObject; MacroID: integer; const Text: string): string of object; { User-defined operation with auto-completion text. Text contains original text for defined auto-completion. The result of the event is the modified Text. } TOnPreprocessCompletion = function (Sender: TObject; const ID, Text: string): string of object; { Words for auto-change feature. } PAutoChangeWord = ^TAutoChangeWord; TAutoChangeWord = record OldWord, NewWord: string; end; { Paragraph. All lines of the file separated by or symbols are paragraphs. Paragraph contains wrapped lines. } TParagraph = record FChanged: boolean; // paragraph was changed FPreCount, FCount: integer; // number of wrapped lines FStrings: array of string; // wrapped lines FAttrs: TLineAttrs; // paragraph attributes end; { List of the paragraphs. } PParagraphList = ^TParagraphList; TParagraphList = array [0..MaxListSize div 2] of TParagraph; { Editor lines storage. Like TStrings but with word-wrap features. } TMemoExStrings = class(TStrings) private FMemoEx: TCustomMemoEx; FList: PParagraphList; FParaLinesCount, FCount: integer; FCapacity: integer; FOnChange: TNotifyEvent; FOnChanging: TNotifyEvent; { Event which fires after loading the file by LoadFromFile. } FOnAfterLoad: TNotifyEvent; { Event which fires before saving lines to file by SaveToFile. } FOnBeforeSave: TNotifyEvent; procedure FinalizeParagraph(Index: integer); procedure FinalizeParagraphs; procedure Recount(Index: integer); function _GetString(ParaIndex: integer): string; procedure _PutString(ParaIndex: integer; const S: string); procedure ReformatParagraph(ParaIndex: integer); procedure Reformat; procedure CheckLength(const st: string); procedure SetLockText(const Text: string); procedure Grow; procedure InsertItem(Index: integer; const S: string); protected procedure Changed; virtual; procedure Changing; virtual; function Get(Index: integer): string; override; function GetCapacity: integer; override; function GetCount: integer; override; function GetParaLineCount: integer; function GetParaString(Index: integer): string; function GetParagraph(Index: integer): TParagraph; procedure Put(Index: integer; const S: string); override; procedure PutParaString(Index: integer; const S: string); procedure SetCapacity(NewCapacity: integer); override; procedure SetUpdateState(Updating: Boolean); override; procedure SetTextStr(const Value: string); override; procedure SetInternal(Index: integer; const Value: string); procedure SetInternalParaStr(Index: integer; const Value: string); { AddParaStr adds wrapped line to paragraph. } function AddParaStr(ParaIndex: integer; const S: string): integer; function InsertAtPos(Index: integer; const S: string): integer; procedure Index2ParaIndex(Index: integer; var Para, ParaIndex: integer); function GetParagraphByIndex(Index: integer; var ParaIndex, IndexOffs: integer): string; procedure Caret2Paragraph(X, Y: integer; var ParaIndex, IndexOffs: integer); procedure Paragraph2Caret(ParaIndex, IndexOffs: integer; var X, Y: integer); function GetParaOffs(ParaIndex: integer): integer; procedure ReLine; procedure SetParaChanged(ParaIndex: integer); property Internal[Index: integer]: string write SetInternal; property InternalParaStrings[Index: integer]: string write SetInternalParaStr; property Paragraphs[Index: integer]: TParagraph read GetParagraph; public constructor Create; destructor Destroy; override; procedure Clear; override; procedure BeginUpdate; procedure EndUpdate; { Add, Delete and Insert used for work with paragraphs. It was done for compatibility with TStrings. When adding the line (paragraph) it will be automatically wrapped. } function Add(const S: string): integer; override; procedure Delete(Index: integer); override; procedure Insert(Index: integer; const S: string); override; procedure LoadFromFile(const FileName: string); override; procedure SaveToFile(const FileName: string); override; { ParaLineCount contains number of all wrapped lines in list. Count contains number of paragraphs in list. } property ParaLineCount: integer read GetParaLineCount; { ParaStrings return wrapped line. Strings return paragraph line. } property ParaStrings[Index: integer]: string read GetParaString write PutParaString; property OnChange: TNotifyEvent read FOnChange write FOnChange; property OnChanging: TNotifyEvent read FOnChanging write FOnChanging; end; { Bookmark. } TBookmark = record X, Y: integer; // coordinates Valid: boolean; // is bookmark valid end; TBookmarkNum = 0..9; TBookmarks = array[TBookmarkNum] of TBookmark; TEditorClient = class private FMemoEx: TCustomMemoEx; 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: TCanvas; property Canvas: TCanvas read GetCanvas; end; TGutter = class(TObject) private FMemoEx: TCustomMemoEx; FFont: TFont; FDrawBitmap: TBitmap; FLineNumberAlign: TLineNumberAlign; //赵亦平 2004.12.12 procedure SetLineNumberAlign(const Value: TLineNumberAlign); //赵亦平 2004.12.12 procedure DrawGutter(Line: Integer; Canvas : TCanvas); procedure DrawBitmap(Line, offset: Integer; Bitmap : TBitmap; Canvas : TCanvas); public property LineNumberAlign: TLineNumberAlign read FLineNumberAlign write SetLineNumberAlign default laLeft; //赵亦平 2004.12.12 constructor Create; destructor Destroy; override; procedure Paint; procedure Invalidate; end; { TMemoExScrollBar } TMemoExScrollBar = class 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 Message: 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; TEditCommand = word; TMacro = string; TEditKey = class public Key1, Key2: Word; Shift1, Shift2: TShiftState; Command: TEditCommand; constructor Create(const ACommand: TEditCommand; const AKey1: word; const AShift1: TShiftState); constructor Create2(const ACommand: TEditCommand; const AKey1: word; const AShift1: TShiftState; const AKey2: word; const AShift2: TShiftState); end; TKeyboard = class private List: TList; public constructor Create; destructor Destroy; override; procedure Add(const ACommand: TEditCommand; const AKey1: word; const AShift1: TShiftState); procedure Add2(const ACommand: TEditCommand; const AKey1: word; const AShift1: TShiftState; const AKey2: word; const AShift2: TShiftState); procedure Clear; function Command(const AKey: word; const AShift: TShiftState): TEditCommand; function Command2(const AKey1: word; const AShift1: TShiftState; const AKey2: word; const AShift2: TShiftState): TEditCommand; procedure SetDefLayout; end; EMemoExError = class(Exception); TUndoBuffer = class; TUndo = class private FMemoEx: TCustomMemoEx; function UndoBuffer: TUndoBuffer; public constructor Create(const AMemoEx: TCustomMemoEx); procedure Undo; dynamic; abstract; procedure Redo; dynamic; abstract; end; TUndoBuffer = class(TList) private FMemoEx: TCustomMemoEx; FPtr: integer; FCancelUndo, InUndo: boolean; function LastUndo: TUndo; function IsNewGroup(const AUndo: TUndo): boolean; public constructor Create; procedure Add(var AUndo: TUndo); procedure Undo; procedure Redo; procedure Clear; override; procedure Delete; end; TCompletion = class; TOnCompletion = procedure(Sender: TObject; var Cancel: boolean) of object; {$IFDEF VER120} TWMContextMenu = packed record Msg: Cardinal; hWnd: HWND; case Integer of 0: ( XPos: Smallint; YPos: Smallint); 1: ( Pos: TSmallPoint; Result: Longint); end; {$ENDIF} TTabStop = (tsTabStop, tsAutoIndent); EInvalidRightMarginValue = class(Exception); { TCustomMemoEx } TCustomMemoEx = class(TCustomControl) private { internal objects } FLines: TMemoExStrings; scbHorz: TMemoExScrollBar; scbVert: TMemoExScrollBar; EditorClient: TEditorClient; FGutter: TGutter; FKeyboard: TKeyboard; FBookmarks: TBookmarks; FUpdateLock: integer; FUndoBuffer: TUndoBuffer; FGroupUndo: boolean; FCompletion: TCompletion; FCols, FRows: integer; FLeftCol, FTopRow: integer; FLastVisibleCol, FLastVisibleRow: integer; FCaretX, FCaretY: integer; FVisibleColCount: integer; FVisibleRowCount: integer; FAllRepaint: boolean; FCellRect: TCellRect; IgnoreKeyPress: boolean; WaitSecondKey: Boolean; Key1: Word; Shift1: TShiftState; { internal - selection attributes } FSelected: boolean; FSelBlock: boolean; // reserved FSelBegX, FSelBegY, FSelEndX, FSelEndY: integer; FUpdateSelBegX, FUpdateSelEndX, FUpdateSelBegY, FUpdateSelEndY: integer; FSelStartX, FSelStartY: integer; FclSelectBC, FclSelectFC: TColor; { mouse support } timerScroll: TTimer; MouseMoveX, MouseMoveY, MouseMoveXX, MouseMoveYY: integer; { internal } FTabPos: array of boolean; FTabStops: string {$IFDEF VER140} deprecated{$ENDIF}; FCharWidth: array of integer; FTabSize, FIndentSize, FAutoIndentSize: integer; FSmartIndent, FSmartTab: boolean; { 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 } FLineNumberAlign: TLineNumberAlign; //赵亦平 2004.12.12 FBorderStyle: TBorderStyle; FGutterColor: TColor; FGutterWidth: integer; FRightMarginVisible: boolean; FRightMargin, FRealRightMargin: integer; FRightMarginColor: TColor; FScrollBars: TScrollStyle; FDoubleClickLine: boolean; FBackspaceUnindents: Boolean; FAutoIndent: Boolean; FKeepTrailingBlanks: Boolean; FCursorBeyondEOF: Boolean; FCursorBeyondEOL: Boolean; FInclusive: Boolean; // include last symbol into selection or not FSimpleBeginLine: boolean; { non-visual attributes - properties } FInsertMode: boolean; FReadOnly: boolean; FModified: boolean; FRecording: boolean; { Events } FOnGetLineAttr: TOnGetLineAttr; FOnChange: TNotifyEvent; FOnSelectionChange: TNotifyEvent; FOnChangeStatus: TOnChangeStatus; FOnChangeClipboardState: TOnChangeClipboardState; FOnScroll: TNotifyEvent; FOnResize: TNotifyEvent; FOnDblClick: TNotifyEvent; FOnPaintGutter: TOnPaintGutter; FOnWordClick: TOnWordClick; FOnMouseOver: TOnMouseOver; FOnBreakLine: TOnBreakLine; FOnConcatLine: TOnConcatLine; FOnTextInsert: TOnTextInsert; FOnCaseConversion: TOnCaseConversion; FOnInsertBlock: TOnInsertBlock; FOnSaveBlock: TOnSaveBlock; FOnInsertMacro: TOnInsertMacro; FOnBlockOperation: TOnBlockOperation; FOnCompletionIdentifier: TOnCompletion; FOnCompletionTemplate: TOnCompletion; FOnCompletionDrawItem: TDrawItemEvent; FOnCompletionMeasureItem: TMeasureItemEvent; FOnPreprocessCompletion: TOnPreprocessCompletion; FDrawBitmap: TBitmap; FFont: TFont; FWantTabs: boolean; FWordWrap: boolean; FStripInvisible: boolean; FParaX, FParaY: integer; NextClipViewer: THandle; scbVertWidth, scbHorzHeight: integer; Max_X: integer; mouse_down, mouse_dragged, double_clicked, gutter_clicked: boolean; FWordUnderCursor: string; FWordStyleUnderCursor: byte; FUseMaxCharWidth: boolean; FCurrentTheme: HTHEME; FActiveLineColor: TColor; fExtraLineSpacing: integer; FGutterFlat: boolean; mouse_moveRight : boolean; mouse_moveRightx : integer; FMoveRightMargin: boolean; FActiveLineBitmap : TBitmap; FLeftIndent : integer; FShowLineNumber: boolean; FLineNumberStart: Integer; FShowLineSeparator: Boolean; procedure SetUseMaxCharWidth(const Value: boolean); procedure SetFont(Value: TFont); procedure SetMax_X(const Value: integer); procedure UpdateEditorSize(const FullUpdate: boolean = true; const RepaintGutter: boolean = true); procedure RedrawFrom(YFrom: integer); function RepaintParagraph(LineIndex: integer): integer; procedure DoCompletionIdentifier(var Cancel: boolean); procedure DoCompletionTemplate(var Cancel: boolean); function DoPreprocessCompletion(const ID, OldText: string): string; procedure ScrollTimer(Sender: TObject); procedure ReLine; function GetDefTabStop(const X: integer; const Next: Boolean): integer; function GetTabStop(const X, Y: integer; const What: TTabStop; const Next: Boolean): integer; function GetBackStop(const X, Y: integer): integer; procedure TextAllChangedInternal(const Unselect: Boolean); { property } procedure SetGutterWidth(AWidth: integer); procedure SetGutterColor(AColor: TColor); function GetLines: TStrings; procedure SetBorderStyle(Value: TBorderStyle); procedure SetLines(ALines: TStrings); function GetRealOffs(DefOffs, Index: integer): integer; function GetSelStart: integer; procedure SetSelStart(const ASelStart: integer); procedure SetSelLength(const ASelLength: integer); function GetSelLength: integer; procedure SetMode(index: integer; Value: boolean); procedure SetCaretPosition(const 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); function ExtractStringWithStyle(XX, YY: integer; const From: string; Style: word; const LineAttrs: TLineAttrs): string; procedure GetWordUnderCursor(X, Y: integer); function GetAfterLoad: TNotifyEvent; procedure SetAfterLoad(Value: TNotifyEvent); function GetBeforeSave: TNotifyEvent; procedure SetBeforeSave(Value: TNotifyEvent); procedure SetWordWrap(Value: boolean); procedure SetStripInvisible(Value: boolean); procedure SetSelectedText(Value: boolean); procedure FontChanged(Sender: TObject); function GetPlainText: string; procedure SetPlainText(const AValue: string); function GetCaretPos: TPoint; function GetCanUndo: boolean; function GetThemeState: integer; procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED; procedure setActiveLineBitmap(const Value: TBitmap); procedure setLeftIndent(const Value: integer); procedure setLineNumberStart(const Value: Integer); procedure setShowLineNumber(const Value: boolean); function getGutterFont: TFont; procedure SetGutterFont(const Value: TFont); procedure setShowLineSeparator(const Value: Boolean); procedure SetGutterFlat(const Value: boolean); procedure SetActiveLineColor(const Value: TColor); procedure SetExtraLineSpacing(const Value: integer); procedure SetLineNumberAlign(const Value: TLineNumberAlign); //赵亦平 2004.12.12 function GetLineNumberAlign: TLineNumberAlign; //赵亦平 2004.12.12 protected SelAttrs_Size: integer; SelAttrs: TSelAttrs; property FSelectedText: boolean read FSelected write SetSelectedText; procedure Resize; override; 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(const Vert: boolean; const ScrollPos: integer); procedure PaintLine(const Line: integer; ColBeg, ColEnd: integer); procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyPress(var Key: Char); override; procedure InsertChar(const Key: Char); procedure SetSel(const ASelX, ASelY: integer); function GetAttrDelta(StartFrom, EndTo: integer; const LineAttrs: TLineAttrs): 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 DblClick; override; function DoMouseWheel(Shift: TShiftState; WheelDelta: integer; MousePos: TPoint): boolean; override; procedure PaintSelection; procedure SetUnSelected; procedure Mouse2Cell(const X, Y: integer; var CX, CY: integer); procedure Mouse2Caret(const X, Y: integer; var CX, CY: integer); procedure CaretCoord(const X, Y: integer; var CX, CY: integer); function PosFromMouse(const X, Y: integer): integer; procedure SetLockText(const Text: string); function ExpandTabs(const S: string): string; // add by patofan function CheckDoubleByteChar(var x: integer; y: integer; ByteType : TMbcsByteType; delta_inc: integer): boolean; procedure DrawMoveRight; // add by patofan procedure CantUndo {$IFDEF VER140}; deprecated{$ENDIF}; procedure SetCaretInternal(X, Y: integer); procedure ValidateEditBuffer; procedure ChangeBookmark(const Bookmark: TBookmarkNum; const Valid: boolean); procedure InsertText(const Text: string); procedure BeginRecord; procedure EndRecord(var AMacro: TMacro); procedure PlayMacro(const AMacro: TMacro); function YinBounds(AY: integer): boolean; function DoChangeCase(const st: string; Conversion: byte): string; { triggers for descendants } procedure Changed; dynamic; procedure TextAllChanged; dynamic; procedure StatusChanged; dynamic; procedure SelectionChanged; dynamic; procedure ClipboardChanged; dynamic; procedure GetLineAttr(Line, LineIdx, LineOffs, LineLen, ColBeg, ColEnd: integer; const ALine: string); virtual; procedure GetAttr(Line, ColBeg, ColEnd: integer); virtual; procedure ChangeAttr(Line, ColBeg, ColEnd: integer); virtual; procedure GutterPaint(Canvas: TCanvas); dynamic; procedure CompletionIdentifier(var Cancel: boolean); dynamic; procedure CompletionTemplate(var Cancel: boolean); dynamic; procedure BookmarkCnanged(Bookmark: integer); dynamic; function GetBookmark(AIndex: integer): TBookmark; procedure SetBookmark(AIndex: integer; ABookmark: TBookmark); property Gutter: TGutter read FGutter; property Cols: integer read FCols write SetCols; property Rows: integer read FRows write SetRows; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Invalidate; override; procedure Invalidate2; procedure InvalidateGutter; procedure InvalidateLine(Index: integer); procedure WndProc(var Message: TMessage); override; procedure SetLeftTop(ALeftCol, ATopRow: integer); function CalcCellRect(const X, Y: integer): TRect; procedure SetCaret(const X, Y: integer); procedure CaretFromPos(const Pos: integer; var X, Y: integer); function PosFromCaret(const X, Y: integer): integer; procedure PaintCaret(const 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 InsertTextAtCurrentPos(const AText: string); procedure ReplaceWord(const NewString: string); procedure InvalidateBookmarks; procedure BeginCompound; procedure EndCompound; function GetText(Position: longint; Buffer: PChar; Count: longint): longint; procedure ClipBoardCopy {$IFDEF VER140}; deprecated{$ENDIF}; procedure ClipBoardPaste {$IFDEF VER140}; deprecated{$ENDIF}; procedure ClipBoardCut {$IFDEF VER140}; deprecated{$ENDIF}; procedure DeleteSelected {$IFDEF VER140}; deprecated{$ENDIF}; function IsUndoEmpty: boolean {$IFDEF VER140}; deprecated{$ENDIF}; procedure Clear; procedure SetCaretPos(const AValue: TPoint); procedure ClearSelection; procedure ClearUndo; procedure CopyToClipboard; procedure CutToClipboard; procedure PasteFromClipboard; procedure SelectAll; procedure Undo; procedure MouseWheelScroll(Delta: integer); property ShowLineSeparator : Boolean read FShowLineSeparator write setShowLineSeparator; property ShowLineNumber : boolean read FShowLineNumber write setShowLineNumber; property LineNumberStart : Integer read FLineNumberStart write setLineNumberStart; property LeftIndent : integer read fLeftIndent write setLeftIndent; property ExtraLineSpacing : integer read fExtraLineSpacing write SetExtraLineSpacing; property ActiveLineColor : TColor read FActiveLineColor write SetActiveLineColor; property ActiveLineBitmap : TBitmap read FActiveLineBitmap write setActiveLineBitmap; property MoveRightMargin : boolean read FMoveRightMargin write FMoveRightMargin; 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 CaretX: integer index 0 read FCaretX write SetCaretPosition; property CaretY: integer index 1 read FCaretY write SetCaretPosition; property CaretPos: TPoint read GetCaretPos; property Modified: boolean read FModified write FModified; property SelStart: integer read GetSelStart write SetSelStart; property SelLength: integer read GetSelLength write SetSelLength; property SelText: string read GetSelText write SetSelText; property SelectedText: boolean read FSelected; property PlainText: string read GetPlainText write SetPlainText; property Text: string read GetPlainText write SetPlainText; property Bookmarks[Index: integer]: TBookmark read GetBookmark write SetBookmark; property Keyboard: TKeyboard read FKeyboard; property CellRect: TCellRect read FCellRect; property UndoBuffer: TUndoBuffer read FUndoBuffer; property Recording: boolean read FRecording; property WordUnderCursor: string read FWordUnderCursor; property WordStyleUnderCursor: byte read FWordStyleUnderCursor; property CanUndo: boolean read GetCanUndo; public { published in descendants } property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle; property Lines: TStrings read GetLines write SetLines; property LinesEx: TMemoExStrings read FLines write FLines; property ScrollBars: TScrollStyle read FScrollBars write SetScrollBars default ssBoth; property Cursor default crIBeam; property Color default clWindow; property Font: TFont read FFont write SetFont; property GutterWidth: integer read FGutterWidth write SetGutterWidth; property GutterColor: TColor read FGutterColor write SetGutterColor default clBtnFace; property GutterFont: TFont read getGutterFont write SetGutterFont; property GutterFlat : boolean read FGutterFlat write SetGutterFlat; property LineNumberAlign: TLineNumberAlign read GetLineNumberAlign write SetLineNumberAlign default laLeft; //赵亦平 2004.12.12 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: TCompletion read FCompletion write FCompletion; property TabStops: string read FTabStops write FTabStops; property TabSize: integer read FTabSize write FTabSize; property IndentSize: integer read FIndentSize write FIndentSize; property AutoIndentSize: integer read FAutoIndentSize write FAutoIndentSize; property SmartTab: boolean read FSmartTab write FSmartTab default true; property SmartAutoIndent: boolean read FSmartIndent write FSmartIndent 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 CursorBeyondEOL: Boolean read FCursorBeyondEOL write FCursorBeyondEOL default true; property SelForeColor: TColor read FclSelectFC write FclSelectFC; property SelBackColor: TColor read FclSelectBC write FclSelectBC; property StripInvisible: boolean read FStripInvisible write SetStripInvisible default false; property WantTabs: boolean read FWantTabs write FWantTabs default true; property WordWrap: boolean read FWordWrap write SetWordWrap default true; property SimpleBeginLine: boolean read FSimpleBeginLine write FSimpleBeginLine default true; property UseMaxCharWidth: boolean read FUseMaxCharWidth write SetUseMaxCharWidth default true; property OnAfterLoad: TNotifyEvent read GetAfterLoad write SetAfterLoad; property OnBeforeSave: TNotifyEvent read GetBeforeSave write SetBeforeSave; property OnGetLineAttr: TOnGetLineAttr read FOnGetLineAttr write FOnGetLineAttr; property OnChangeStatus: TOnChangeStatus read FOnChangeStatus write FOnChangeStatus; property OnChangeClipboardState: TOnChangeClipboardState read FOnChangeClipboardState write FOnChangeClipboardState; 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 OnMouseOver: TOnMouseOver read FOnMouseOver write FOnMouseOver; property OnWordClick: TOnWordClick read FOnWordClick write FOnWordClick; property OnBreakLine: TOnBreakLine read FOnBreakLine write FOnBreakLine; property OnConcatLine: TOnConcatLine read FOnConcatLine write FOnConcatLine; property OnTextInsert: TOnTextInsert read FOnTextInsert write FOnTextInsert; property OnCaseConversion: TOnCaseConversion read FOnCaseConversion write FOnCaseConversion; property OnInsertBlock: TOnInsertBlock read FOnInsertBlock write FOnInsertBlock; property OnSaveBlock: TOnSaveBlock read FOnSaveBlock write FOnSaveBlock; property OnInsertMacro: TOnInsertMacro read FOnInsertMacro write FOnInsertMacro; property OnBlockOperation: TOnBlockOperation read FOnBlockOperation write FOnBlockOperation; 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 OnPreprocessCompletion: TOnPreprocessCompletion read FOnPreprocessCompletion write FOnPreprocessCompletion; property DockManager; end; TMemoEx = class(TCustomMemoEx) published property ShowLineSeparator; property ShowLineNumber; property LineNumberStart; property LineNumberAlign; property LeftIndent; property GutterFlat; property GutterFont; property ExtraLineSpacing; property ActiveLineColor; property ActiveLineBitmap; property MoveRightMargin; property TabOrder; property BorderStyle; property Lines; property ScrollBars; property GutterWidth; property GutterColor; property RightMarginVisible; property RightMargin; property RightMarginColor; property InsertMode; property ReadOnly; property DoubleClickLine; property Completion; property TabStops; property TabSize; property IndentSize; property AutoIndentSize; property SmartTab; property SmartAutoIndent; property BackspaceUnindents; property AutoIndent; property KeepTrailingBlanks; property CursorBeyondEOF; property CursorBeyondEOL; property SelForeColor; property SelBackColor; property StripInvisible; property SimpleBeginLine; property UseMaxCharWidth; property OnAfterLoad; property OnBeforeSave; property OnEnter; property OnExit; property OnGetLineAttr; property OnChangeStatus; property OnChangeClipboardState; property OnScroll; property OnResize; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnChange; property OnSelectionChange; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnDblClick; property OnMouseWheel; property OnMouseWheelDown; property OnMouseWheelUp; property OnPaintGutter; property OnMouseOver; property OnWordClick; property OnBreakLine; property OnConcatLine; property OnTextInsert; property OnCaseConversion; property OnInsertBlock; property OnSaveBlock; property OnInsertMacro; property OnBlockOperation; property OnCompletionIdentifier; property OnCompletionTemplate; property OnCompletionDrawItem; property OnCompletionMeasureItem; property OnPreprocessCompletion; { TCustomControl } property Align; property Enabled; property Color; property Ctl3D; property Font; property ParentColor; property ParentFont; property ParentShowHint; property PopupMenu; property ShowHint; property TabStop; property Visible; property Anchors; property AutoSize; property BiDiMode; property Constraints; property UseDockManager default true; property DockSite; property DragKind; property ParentBiDiMode; property WantTabs default true; property WordWrap default true; property OnCanResize; property OnConstrainedResize; property OnDockDrop; property OnDockOver; property OnEndDock; property OnGetSiteInfo; property OnStartDock; property OnUnDock; end; TCompletionList = (cmIdentifiers, cmTemplates); TCompletion = class(TPersistent) private FMemoEx: TCustomMemoEx; FPopupList: TListBox; FAutoChange: TStrings; FAutoChangeList: TList; FIdentifiers: TStrings; FTemplates: TStrings; FItems: TStringList; FItemIndex: integer; FMode: TCompletionList; FDefMode: TCompletionList; FItemHeight: integer; FTimer: TTimer; FEnabled: boolean; FVisible: boolean; FDropDownCount: integer; FDropDownWidth: integer; FListBoxStyle: TListBoxStyle; FCaretChar: char; FCRLF: string; FSeparator: string; function DoKeyDown(Key: Word; Shift: TShiftState): boolean; procedure DoKeyPress(Key: Char); procedure OnTimer(Sender: TObject); procedure FindSelItem(var Eq: boolean); procedure ReplaceWord(const ANewString: string); function Cmp1(const S1, S2: string): integer; function Cmp2(const S1, S2: string): boolean; procedure AutoChangeChanged(Sender: TObject); procedure ClearAutoChangeList; procedure UpdateAutoChange; procedure SetStrings(index: integer; AValue: TStrings); function GetItemIndex: integer; procedure SetItemIndex(AValue: integer); function GetInterval: cardinal; procedure SetInterval(AValue: cardinal); procedure MakeItems; function GetItems: TStrings; public constructor Create2(AMemoEx: TCustomMemoEx); destructor Destroy; override; procedure DropDown(const AMode: TCompletionList; const ShowAlways: boolean); procedure DoCompletion(const AMode: TCompletionList); procedure CloseUp(const Apply: boolean); procedure SelectItem; property ItemIndex: integer read GetItemIndex write SetItemIndex; property Visible: boolean read FVisible write FVisible; property Mode: TCompletionList read FMode write FMode; property Items: TStringList read FItems; published property DropDownCount: integer read FDropDownCount write FDropDownCount default 6; property DropDownWidth: integer read FDropDownWidth write FDropDownWidth default 300; property Enabled: boolean read FEnabled write FEnabled default true; property Separator: string read FSeparator write FSeparator; property Identifiers: TStrings index 0 read FIdentifiers write SetStrings; property Templates: TStrings index 1 read FTemplates write SetStrings; property AutoChange: TStrings index 2 read FAutoChange write SetStrings; property ItemHeight: integer read FItemHeight write FItemHeight; property Interval: cardinal read GetInterval write SetInterval; property ListBoxStyle: TListBoxStyle read FListBoxStyle write FListBoxStyle; property CaretChar: char read FCaretChar write FCaretChar; property CRLF: string read FCRLF write FCRLF; end; const { Editor commands } ecCharFirst = $00; ecCharLast = $FF; ecCommandFirst = $100; ecUser = $8000; { use this for descendants } ecLeft = ecCommandFirst + 1; ecUp = ecLeft + 1; ecRight = ecLeft + 2; ecDown = ecLeft + 3; ecSelLeft = ecCommandFirst + 9; ecSelUp = ecSelLeft + 1; ecSelRight = ecSelLeft + 2; ecSelDown = ecSelLeft + 3; ecPrevWord = ecSelDown + 1; ecNextWord = ecPrevWord + 1; ecSelPrevWord = ecPrevWord + 2; ecSelNextWord = ecPrevWord + 3; ecSelWord = ecPrevWord + 4; ecWindowTop = ecSelWord + 1; ecWindowBottom = ecWindowTop + 1; ecPrevPage = ecWindowTop + 2; ecNextPage = ecWindowTop + 3; ecSelPrevPage = ecWindowTop + 4; ecSelNextPage = ecWindowTop + 5; ecBeginLine = ecSelNextPage + 1; ecEndLine = ecBeginLine + 1; ecBeginDoc = ecBeginLine + 2; ecEndDoc = ecBeginLine + 3; ecSelBeginLine = ecBeginLine + 4; ecSelEndLine = ecBeginLine + 5; ecSelBeginDoc = ecBeginLine + 6; ecSelEndDoc = ecBeginLine + 7; ecSelAll = ecBeginLine + 8; ecScrollLineUp = ecSelAll + 1; ecScrollLineDown = ecScrollLineUp + 1; ecInsertPara = ecCommandFirst + 101; ecBackspace = ecInsertPara + 1; ecDelete = ecInsertPara + 2; ecChangeInsertMode = ecInsertPara + 3; ecTab = ecInsertPara + 4; ecBackTab = ecInsertPara + 5; ecIndent = ecInsertPara + 6; ecUnindent = ecInsertPara + 7; ecDeleteSelected = ecInsertPara + 10; ecClipboardCopy = ecInsertPara + 11; ecClipboardCut = ecClipboardCopy + 1; ecClipBoardPaste = ecClipboardCopy + 2; ecDeleteLine = ecClipBoardPaste + 1; ecDeleteWord = ecDeleteLine + 1; ecToUpperCase = ecDeleteLine + 2; ecToLowerCase = ecToUpperCase + 1; ecChangeCase = ecToUpperCase + 2; ecUndo = ecChangeCase + 1; ecRedo = ecUndo + 1; ecBeginCompound = ecUndo + 2; { not implemented } ecEndCompound = ecUndo + 3; { not implemented } ecBeginUpdate = ecUndo + 4; ecEndUpdate = ecUndo + 5; ecSetBookmark0 = ecEndUpdate + 1; ecSetBookmark1 = ecSetBookmark0 + 1; ecSetBookmark2 = ecSetBookmark0 + 2; ecSetBookmark3 = ecSetBookmark0 + 3; ecSetBookmark4 = ecSetBookmark0 + 4; ecSetBookmark5 = ecSetBookmark0 + 5; ecSetBookmark6 = ecSetBookmark0 + 6; ecSetBookmark7 = ecSetBookmark0 + 7; ecSetBookmark8 = ecSetBookmark0 + 8; ecSetBookmark9 = ecSetBookmark0 + 9; ecGotoBookmark0 = ecSetBookmark9 + 1; ecGotoBookmark1 = ecGotoBookmark0 + 1; ecGotoBookmark2 = ecGotoBookmark0 + 2; ecGotoBookmark3 = ecGotoBookmark0 + 3; ecGotoBookmark4 = ecGotoBookmark0 + 4; ecGotoBookmark5 = ecGotoBookmark0 + 5; ecGotoBookmark6 = ecGotoBookmark0 + 6; ecGotoBookmark7 = ecGotoBookmark0 + 7; ecGotoBookmark8 = ecGotoBookmark0 + 8; ecGotoBookmark9 = ecGotoBookmark0 + 9; ecCompletionIdentifiers = ecGotoBookmark9 + 1; ecCompletionTemplates = ecCompletionIdentifiers + 1; ecRecordMacro = ecCompletionTemplates + 1; ecPlayMacro = ecRecordMacro + 1; ecBeginRecord = ecRecordMacro + 2; ecEndRecord = ecRecordMacro + 3; ecSaveBlock = ecEndRecord + 1; ecInsertBlock = ecSaveBlock + 1; ecInsertMacro0 = ecInsertBlock + 1; ecInsertMacro1 = ecInsertMacro0 + 1; ecInsertMacro2 = ecInsertMacro0 + 2; ecInsertMacro3 = ecInsertMacro0 + 3; ecInsertMacro4 = ecInsertMacro0 + 4; ecInsertMacro5 = ecInsertMacro0 + 5; ecInsertMacro6 = ecInsertMacro0 + 6; ecInsertMacro7 = ecInsertMacro0 + 7; ecInsertMacro8 = ecInsertMacro0 + 8; ecInsertMacro9 = ecInsertMacro0 + 9; ecInsertMacroA = ecInsertMacro0 + 10; ecInsertMacroB = ecInsertMacro0 + 11; ecInsertMacroC = ecInsertMacro0 + 12; ecInsertMacroD = ecInsertMacro0 + 13; ecInsertMacroE = ecInsertMacro0 + 14; ecInsertMacroF = ecInsertMacro0 + 15; ecInsertMacroG = ecInsertMacro0 + 16; ecInsertMacroH = ecInsertMacro0 + 17; ecInsertMacroI = ecInsertMacro0 + 18; ecInsertMacroJ = ecInsertMacro0 + 19; ecInsertMacroK = ecInsertMacro0 + 20; ecInsertMacroL = ecInsertMacro0 + 21; ecInsertMacroM = ecInsertMacro0 + 22; ecInsertMacroN = ecInsertMacro0 + 23; ecInsertMacroO = ecInsertMacro0 + 24; ecInsertMacroP = ecInsertMacro0 + 25; ecInsertMacroQ = ecInsertMacro0 + 26; ecInsertMacroR = ecInsertMacro0 + 27; ecInsertMacroS = ecInsertMacro0 + 28; ecInsertMacroT = ecInsertMacro0 + 29; ecInsertMacroU = ecInsertMacro0 + 30; ecInsertMacroV = ecInsertMacro0 + 31; ecInsertMacroW = ecInsertMacro0 + 32; ecInsertMacroX = ecInsertMacro0 + 33; ecInsertMacroY = ecInsertMacro0 + 34; ecInsertMacroZ = ecInsertMacro0 + 35; ecBlockOpA = ecInsertMacroZ + 1; ecBlockOpB = ecBlockOpA + 1; ecBlockOpC = ecBlockOpA + 2; ecBlockOpD = ecBlockOpA + 3; ecBlockOpE = ecBlockOpA + 4; ecBlockOpF = ecBlockOpA + 5; ecBlockOpG = ecBlockOpA + 6; ecBlockOpH = ecBlockOpA + 7; ecBlockOpI = ecBlockOpA + 8; ecBlockOpJ = ecBlockOpA + 9; ecBlockOpK = ecBlockOpA + 10; ecBlockOpL = ecBlockOpA + 11; ecBlockOpM = ecBlockOpA + 12; ecBlockOpN = ecBlockOpA + 13; ecBlockOpO = ecBlockOpA + 14; ecBlockOpP = ecBlockOpA + 15; ecBlockOpQ = ecBlockOpA + 16; ecBlockOpR = ecBlockOpA + 17; ecBlockOpS = ecBlockOpA + 18; ecBlockOpT = ecBlockOpA + 19; ecBlockOpU = ecBlockOpA + 20; ecBlockOpV = ecBlockOpA + 21; ecBlockOpW = ecBlockOpA + 22; ecBlockOpX = ecBlockOpA + 23; ecBlockOpY = ecBlockOpA + 24; ecBlockOpZ = ecBlockOpA + 25; ecBackword = ecBlockOpZ + 1; ecScrollPageUp = ecBackword + 1; ecScrollPageDown = ecScrollPageUp + 1; twoKeyCommand = High(word); const __Brackets = ['(',')','[',']','{','}']; __StdWordDelims = [#0..' ',',','.',';','\',':','''','`']{ + __Brackets}; var ThemesAvailable: boolean; IsThemeActive: TIsThemeActive; OpenThemeData: TOpenThemeData; CloseThemeData: TCloseThemeData; DrawThemeParentBackground: TDrawThemeParentBackground; DrawThemeBackground: TDrawThemeBackground; IsThemeBackgroundPartiallyTransparent: TIsThemeBackgroundPartiallyTransparent; function _CopyToClipboard(Handle: THandle; SelText: string; FontCharset: TFontCharset): boolean; function _PasteFromClipboard(Handle: THandle; FontCharset: TFontCharset; DeleteCRLF: boolean = true): string; function CreateThemeHandle(wnd: HWND): HTHEME; procedure FreeThemeHandle(var theme: HTHEME); procedure Register; implementation uses Consts, Math; const RAEditorCompletionChars = #8+'_0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm芍邮磐秘偾遮咱吕闲嗡钠葸籽倘臆赁ㄩ鲶赍磴
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -