-
-
Notifications
You must be signed in to change notification settings - Fork 325
/
SynMemoEx.pas
7425 lines (6899 loc) · 213 KB
/
SynMemoEx.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// Synopse extended TMemo visual component
// - licensed under a MPL/GPL/LGPL tri-license; version 2.26
unit SynMemoEx;
{
This file is part of Synopse extended TMemo
Synopse SynMemoEx. Copyright (c) Arnaud Bouchez
Synopse Informatique - https://synopse.info
*** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Original Code is Synopse SynMemoEx.
The Initial Developer of the Original Code is Arnaud Bouchez.
Portions created by the Initial Developer are Copyright (c)
the Initial Developer. All Rights Reserved.
Contributor(s):
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****
Based on TMemoEx, by R&A Library 2.03 (c) R&A, 1996-2000.
R&A Library seems now unsupported. Web site is dead, as is their email address.
We decided to put this unit, mostly rewritten, under a MPL/GPL/LGPL tri-license.
* full code rewrite for speed, stability and new features
* regroup in one unit w/out RA Consts
* no expandTabs: too slow
* FAttrs are calculated on the fly: spare RAM on syntax highlight (only text is stored)
* don't use FLines.text on often-call methods (insertText, deleteSelected...)
* fClipProtect: clipBoard Copy/Cut limited to 2K for others programs (copyrights)
* find (text) command
* a lot of bug fixes
Version 1.18
- Unicode compatibility
}
{$I Synopse.inc}
interface
{.$define CLIPBOARDPROTECT} // if defined, ClipProtect truncates clipboard to 2KB
// use only with ONE TMemoEx at once
{$IFNDEF MEMOEX_NOEDITOR}
{$DEFINE MEMOEX_EDITOR} {if not MEMOEX_EDITOR then mode = Viewer}
{$ENDIF}
{$DEFINE MEMOEX_DEFLAYOUT} {set default keyboard layout}
{$IFNDEF MEMOEX_NOUNDO}
{$DEFINE MEMOEX_UNDO} {enable undo}
{$ENDIF}
{$IFNDEF MEMOEX_NOCOMPLETION}
{$DEFINE MEMOEX_COMPLETION} {enable code completion}
{$ENDIF}
{$IFNDEF MEMOEX_EDITOR}
{$UNDEF MEMOEX_DEFLAYOUT}
{$UNDEF MEMOEX_UNDO}
{$UNDEF MEMOEX_COMPLETION}
{$ENDIF MEMOEX_EDITOR}
{ $D-,L-} // avoid jumping in the source for any EComplete exceptions e.g.
{$I Synopse.inc} // define HASINLINE CPU32 CPU64 OWNNORMTOUPPER
uses
Windows,
Messages,
SysUtils,
Classes,
Types,
Graphics,
Controls,
Forms,
ExtCtrls,
StdCtrls,
ClipBrd,
Menus
{$ifdef FPC} // FPC compatibility by alf (alfred) - thanks for the patch!
, LCLType
{$endif FPC}
{$ifdef UNICODE}
, UITypes
{$endif UNICODE};
const
RAEditorCompletionChars: set of AnsiChar =
[#8, '_', '0'..'9', 'A'..'Z', 'a'..'z'];
Separators: set of AnsiChar =
[#0, ' ', '-', #13, #10, '.', ',', '/', '\', ':', '+', '%', '*', '(', ')',
';', '=', '{', '}', '[', ']', '|', '!', '@', '"'];
GutterRightMargin = 2;
WM_EDITCOMMAND = WM_USER + $101;
RA_EX_STYLE_DEFAULT = 0;
RA_CASE_CONVERT_UPPER = 0;
RA_CASE_CONVERT_LOWER = 1;
RA_CASE_CONVERT_INVERT = 2;
type
TRAControlScrollBar95 = class
private
FKind: TScrollBarKind;
FPosition: Integer;
FMin: Integer;
FMax: Integer;
FSmallChange: TScrollBarInc;
FLargeChange: TScrollBarInc;
FPage: integer;
FHandle: hWnd;
FOnScroll: TScrollEvent;
// FVisible : boolean;
procedure SetParam(index, Value: Integer);
// procedure SetVisible(Value : boolean);
// procedure SetLargeChange(Value: TScrollBarInc);
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;
// property Visible : boolean read FVisible write SetVisible;
end;
TCellRect = record
Width: integer;
Height: integer;
end;
PLineAttr = ^TLineAttr;
TLineAttr = packed record
FC, BC: TColor;
case integer of
0:
(Style: TFontStyles;
ex_style: byte;
underlined: boolean);
1:
(LastInteger: integer);
end;
TCustomMemoEx = class;
TWordUnderCursor = record // for TOnWordClick
Text: string;
Style: integer;
CaretX, CaretY, ParaIndex, ParaOffset: integer;
TextStart: integer;
Shift: TShiftState;
end;
TLineAttrs = array of TLineAttr;
TSelAttrs = array of boolean;
TOnGetLineAttr = procedure(Sender: TObject; const Line: string; index: integer; const SelAttrs: TSelAttrs; var Attrs: TLineAttrs) of object;
TOnChangeStatus = TNotifyEvent;
TOnChangeClipboardState = procedure(Sender: TObject; const CanPaste: boolean) of object;
TOnWordClick = procedure(Sender: TObject; const Clicked: TWordUnderCursor) of object;
TOnMouseOver = procedure(Sender: TObject; WordStyle: word; var _Cursor: TCursor) of object;
TOnBreakLine = procedure(Sender: TObject; const Original: string; var _New: string) of object;
TOnConcatLine = procedure(Sender: TObject; const Original: string; var _New: string) of object;
TOnTextInsert = procedure(Sender: TObject; var Text: string) of object;
TOnCaseConversion = function(Sender: TObject; Conversion: byte; const Text: string): string of object;
TOnInsertBlock = function(Sender: TObject; var Text: string): boolean of object;
TOnSaveBlock = procedure(Sender: TObject; const Text: string) of object;
TOnInsertMacro = function(Sender: TObject; MacroID: integer): string of object;
TOnBlockOperation = function(Sender: TObject; MacroID: integer; const Text: string): string of object;
TOnSetCaretPos = procedure(Sender: TObject; CaretX, CaretY: integer) of object;
TOnClipboardPaste = function(Sender: TObject): boolean of object;
{$IFDEF MEMOEX_COMPLETION}
TOnPreprocessCompletion = function(Sender: TObject; const ID, Text: string): string of object;
{$ENDIF}
PAutoChangeWord = ^TAutoChangeWord;
TAutoChangeWord = record
OldWord, NewWord: string;
end;
PParagraph = ^TParagraph;
TParagraph = record
FPreCount, FCount: integer; // length(FString) = FStrings[0..FCount-1]
FStrings: array of string;
FObject: TObject;
end;
TEditorStrings = class(TStrings)
private
FMemoEx: TCustomMemoEx;
FList: array of TParagraph;
FParaLinesCount, FCount: integer;
FOnChanging: TNotifyEvent;
FOnAfterLoad: TNotifyEvent;
FOnBeforeSave: TNotifyEvent;
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 Grow;
procedure InsertItem(Index: integer; const S: string);
protected
procedure Changed; virtual;
procedure Changing; virtual;
function Get(Index: integer): string; override;
function GetParaString(Index: integer): string;
function GetParagraph(Index: integer): PParagraph;
procedure Put(Index: integer; const S: string); override;
procedure PutParaString(Index: integer; const S: string);
procedure PutObject(Index: Integer; AObject: TObject); override;
function GetObject(Index: Integer): TObject; override;
procedure SetUpdateState(Updating: Boolean); override;
function GetTextStr: string; override;
procedure SetTextStr(const Value: string); override;
procedure SetInternal(Index: integer; const Value: string);
procedure SetInternalParaStr(Index: integer; const Value: string);
function GetCount: Integer; override; // make compiler happy
function AddParaStr(ParaIndex: integer; const S: string): integer;
procedure ReLine; // complete line with spaces until caret X pos
property Internal[Index: integer]: string write SetInternal;
property InternalParaStrings[Index: integer]: string write SetInternalParaStr;
public
constructor Create;
destructor Destroy; override;
procedure Clear; override;
procedure BeginUpdate;
procedure EndUpdate;
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;
procedure SetLockText(const Text: string);
function GetTextLength: integer; // fast get length(Text) value
function HasText: boolean; // true if Text<>''
procedure Index2ParaIndex(Index: integer; out Para, ParaIndex: integer);
function GetParagraphByIndex(Index: integer; out ParaIndex, IndexOffs: integer): string;
procedure Caret2Paragraph(X, Y: integer; out ParaIndex, IndexOffs: integer);
procedure Paragraph2Caret(ParaIndex, IndexOffs: integer; out X, Y: integer);
function GetParaOffs(ParaIndex: integer): integer; // in global Text[] string
property ParaLineCount: integer read FParaLinesCount;
property ParaStrings[Index: integer {=ParaY}]: string read GetParaString write PutParaString;
property Paragraphs[Index: integer]: PParagraph read GetParagraph; // = FList[index]
// property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
end;
TModifiedAction = (maInsert, maDelete);
TBookMark = record
X, Y: integer;
Valid: boolean;
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
private
FMemoEx: TCustomMemoEx;
public
procedure Paint;
procedure Invalidate;
end;
TOnPaintGutter = procedure(Sender: TObject; Canvas: TCanvas; const Rect: TRect) of object;
TEditCommand = word;
TMacro = string; { uses as buffer }
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;
{$IFDEF MEMOEX_DEFLAYOUT}
procedure SetDefLayout;
{$ENDIF MEMOEX_DEFLAYOUT}
end;
EComplete = class(EAbort);
EMemoExError = class(Exception);
{$IFDEF MEMOEX_UNDO}
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 IsNewGroup(const AUndo: TUndo): boolean;
public
constructor Create;
procedure Add(AUndo: TUndo);
function LastUndo: TUndo;
procedure Undo;
procedure Redo;
procedure Clear; override;
procedure Delete;
end;
{$ENDIF MEMOEX_UNDO}
{$IFDEF MEMOEX_COMPLETION}
TCompletion = class;
TOnCompletion = procedure(Sender: TObject; var Cancel: boolean) of object;
{$ENDIF MEMOEX_COMPLETION}
TTabStop = (tsTabStop, tsAutoIndent);
{*** TCustomMemoEx }
TCustomMemoEx = class(TCustomControl)
private
{ internal objects }
FLines: TEditorStrings;
scbHorz: TRAControlScrollBar95;
scbVert: TRAControlScrollBar95;
EditorClient: TEditorClient;
FGutter: TGutter;
FKeyboard: TKeyboard;
FBookMarks: TBookMarks;
FUpdateLock: integer;
{$IFDEF MemoEx_UNDO}
FUndoBuffer: TUndoBuffer;
FGroupUndo: boolean;
{$ENDIF MEMOEX_UNDO}
{$IFDEF MEMOEX_COMPLETION}
FCompletion: TCompletion;
{$ENDIF MEMOEX_COMPLETION}
{ internal - Columns and rows attributes }
FCols, FRows: integer;
FLeftCol, FTopRow: integer;
// FLeftColMax, FTopRowMax : integer;
FLastVisibleCol, FLastVisibleRow: integer;
FCaretX, FCaretY: integer;
FVisibleColCount: integer;
FVisibleRowCount: integer;
{ internal - other flags and attributes }
FAllRepaint: boolean;
FCellRect: TCellRect;
{$IFDEF MEMOEX_EDITOR}
IgnoreKeyPress: boolean;
{$ENDIF MEMOEX_EDITOR}
WaitSecondKey: Boolean;
Key1: Word;
Shift1: TShiftState;
{ internal - selection attributes }
FSelected: boolean;
FSelBlock: boolean;
FSelBegX, FSelBegY, FSelEndX, FSelEndY: integer;
FUpdateSelBegX, FUpdateSelEndX, FUpdateSelBegY, FUpdateSelEndY: integer;
FSelStartX, FSelStartY: integer;
FclSelectBC, FclSelectFC: TColor;
{ mouse support }
timerScroll: TTimer;
MouseMoveY, MouseMoveXX, MouseMoveYY: integer;
{ internal }
FTabPos: array of boolean;
FTabStops: string;
{ 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;
FCursorBeyondEOL: Boolean;
{ FInclusive - Inclusive mode }
FInclusive: 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;
FOnSetCaretPos: TOnSetCaretPos;
{$IFDEF MEMOEX_COMPLETION}
FOnCompletionIdentifer: TOnCompletion;
FOnCompletionTemplate: TOnCompletion;
FOnCompletionDrawItem: TDrawItemEvent;
FOnCompletionMeasureItem: TMeasureItemEvent;
FOnPreprocessCompletion: TOnPreprocessCompletion;
{$ENDIF MEMOEX_COMPLETION}
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: boolean;
FWordUnderCursor: TWordUnderCursor;
FClipPasteRtfBackSlashConvert: boolean;
{$ifdef CLIPBOARDPROTECT} // ClipProtect will trunc clipboard to 2KB
FClip: string; // AB
FClipProtect: boolean;
{$endif}
FOnClipboardPaste: TOnClipboardPaste; // AB
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;
{$IFDEF MEMOEX_COMPLETION}
procedure DoCompletionIdentifer(var Cancel: boolean);
procedure DoCompletionTemplate(var Cancel: boolean);
function DoPreprocessCompletion(const ID, OldText: string): string;
{$ENDIF MEMOEX_COMPLETION}
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);
{ properties }
procedure SetGutterWidth(AWidth: integer);
procedure SetGutterColor(AColor: TColor);
procedure SetFont(Value: TFont);
procedure SetBorderStyle(Value: TBorderStyle);
procedure SetLines(ALines: TEditorStrings);
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; out start: integer): string;
procedure GetWordUnderCursor(X, Y: integer; aShift: TShiftState = []);
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);
procedure SetTopRow(const Value: integer);
function GetTextStr: string;
procedure SetTextStr(const Value: string);
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;
{$IFDEF MEMOEX_EDITOR}
procedure KeyPress(var Key: Char); override;
procedure InsertChar(const Key: Char);
{$ENDIF MEMOEX_EDITOR}
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 DoContextPopup(MousePos: TPoint; var Handled: Boolean); override;
// procedure DrawRightMargin;
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;
{$IFDEF MEMOEX_UNDO}
procedure CantUndo;
{$ENDIF MEMOEX_UNDO}
procedure SetCaretInternal(X, Y: integer);
procedure ValidateEditBuffer;
procedure SetXY(X, Y: integer);
{$IFDEF MEMOEX_EDITOR}
procedure ChangeBookMark(const BookMark: TBookMarkNum; const Valid: boolean);
procedure InsertText(const Text: string);
{$ENDIF MEMOEX_EDITOR}
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; var FAttrs: TLineAttrs); virtual;
procedure GutterPaint(Canvas: TCanvas; const Rect: TRect); dynamic;
procedure BookmarkChanged(BookMark: integer); dynamic;
{$IFDEF MEMOEX_COMPLETION}
procedure CompletionIdentifer(var Cancel: boolean); dynamic;
procedure CompletionTemplate(var Cancel: boolean); dynamic;
{$ENDIF MEMOEX_COMPLETION}
property Gutter: TGutter read FGutter;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Invalidate; override;
procedure WndProc(var Message: TMessage); override;
procedure SetLeftTop(ALeftCol, ATopRow: integer);
procedure ClipBoardCopy;
procedure ClipBoardPaste;
procedure ClipBoardCut;
procedure DeleteSelected;
function CalcCellRect(const X, Y: integer): TRect;
procedure SetCaret(const X, Y: integer);
procedure SetCaretAtParaPos(const ParaIndex, IndexOffs: 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);
{$IFDEF MEMOEX_EDITOR}
procedure InsertTextAtCurrentPos(const _Text: string);
function FindNext(const text: string; ignCase: boolean): boolean;
procedure ReplaceWord(const NewString: string);
procedure ReplaceWord2(const NewString: string);
{$ENDIF}
procedure BeginCompound;
procedure EndCompound;
function GetText(Position: longint; Buffer: PChar; Count: longint): longint;
function IsUndoEmpty: boolean;
procedure MouseWheelScroll(Delta: integer);
{$ifdef CLIPBOARDPROTECT} // ClipProtect will trunc clipboard to 2KB
property ClipProtect: boolean read FClipProtect write FClipProtect; // AB
{$endif}
property ClipPasteRtfBackSlashConvert: boolean // AB: rtf
read FClipPasteRtfBackSlashConvert write FClipPasteRtfBackSlashConvert;
property LeftCol: integer read FLeftCol;
property TopRow: integer read FTopRow write SetTopRow;
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 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 BookMarks: TBookMarks read FBookMarks;
property Keyboard: TKeyboard read FKeyboard;
property CellRect: TCellRect read FCellRect;
{$IFDEF MEMOEX_UNDO}
property UndoBuffer: TUndoBuffer read FUndoBuffer;
{$ENDIF MEMOEX_UNDO}
property Recording: boolean read FRecording;
property WordUnderCursor: TWordUnderCursor read FWordUnderCursor;
property SelBegY: integer read FSelBegY;
property SelEndY: integer read FSelEndY;
public
{ published in descendants }
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property Lines: TEditorStrings read FLines write SetLines;
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 Text: string read GetTextStr write SetTextStr;
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;
{$IFDEF MEMOEX_COMPLETION}
property Completion: TCompletion read FCompletion write FCompletion;
{$ENDIF MEMOEX_COMPLETION}
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 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 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 OnSetCaretPos: TOnSetCaretPos read FOnSetCaretPos write FOnSetCaretPos;
property OnClipboardPaste: TOnClipboardPaste read FOnClipboardPaste write FOnClipboardPaste;
{$IFDEF MEMOEX_COMPLETION}
property OnCompletionIdentifer: TOnCompletion read FOnCompletionIdentifer write FOnCompletionIdentifer;
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;
{$ENDIF MEMOEX_COMPLETION}
property DockManager;
end;
TMemoEx = class(TCustomMemoEx)
public
/// a JSON syntax highlighter
class procedure JSONLineAttr(Sender: TObject; const Line: string;
index: Integer; const SelAttrs: TSelAttrs; var Attrs: TLineAttrs);
published
property TabOrder;
property BorderStyle;
property Lines;
property ScrollBars;
property GutterWidth;
property GutterColor;
property RightMarginVisible;
property RightMargin;
property RightMarginColor;
property InsertMode;
property ReadOnly;
property DoubleClickLine;
{$IFDEF MEMOEX_COMPLETION}
property Completion;
{$ENDIF MEMOEX_COMPLETION}
property TabStops;
property SmartTab;
property BackSpaceUnindents;
property AutoIndent;
property KeepTrailingBlanks;
property CursorBeyondEOF;
property CursorBeyondEOL;
property SelForeColor;
property SelBackColor;
property Text;
property StripInvisible;
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 OnSetCaretPos;
{$IFDEF MEMOEX_COMPLETION}
property OnCompletionIdentifer;
property OnCompletionTemplate;
property OnCompletionDrawItem;
property OnCompletionMeasureItem;
property OnPreprocessCompletion;
{$ENDIF MEMOEX_COMPLETION}
{ TCustomControl }
property Align;
property Enabled;
property Color;
{$ifndef FPC}
property Ctl3D;
property OnCanResize;
{$endif FPC}
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 OnConstrainedResize;
property OnDockDrop;
property OnDockOver;
property OnEndDock;
property OnGetSiteInfo;
property OnStartDock;
property OnUnDock;
end;
{$IFDEF MEMOEX_COMPLETION}
TCompletionList = (cmIdentifers, cmTemplates);
TCompletion = class(TPersistent)
private
FMemoEx: TCustomMemoEx;
FPopupList: TListBox;
FAutoChange: TStrings;
FAutoChangeList: TList;
FIdentifers: 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 false;
property Separator: string read FSeparator write FSeparator;
property Identifers: TStrings index 0 read FIdentifers 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;
{$ENDIF MEMOEX_COMPLETION}
const
{ Editor commands }
ecCharFirst = $00;
ecCharLast = $FF;
ecCommandFirst = $100;
ecUser = $8000; { use this for descendants }
{Cursor}
ecLeft = ecCommandFirst + 1;
ecUp = ecLeft + 1;
ecRight = ecLeft + 2;
ecDown = ecLeft + 3;
{Cursor with select}
ecSelLeft = ecCommandFirst + 9;
ecSelUp = ecSelLeft + 1;
ecSelRight = ecSelLeft + 2;
ecSelDown = ecSelLeft + 3;
{Cursor position change according to word}
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;