forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScintEdit.pas
2100 lines (1867 loc) · 65.5 KB
/
ScintEdit.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
unit ScintEdit;
{
Inno Setup
Copyright (C) 1997-2019 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
TScintEdit component: a VCL wrapper for Scintilla
}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ScintInt;
type
TScintEditChangeInfo = record
Inserting: Boolean;
StartPos, Length, LinesDelta: Integer;
end;
TScintEditChangeEvent = procedure(Sender: TObject;
const Info: TScintEditChangeInfo) of object;
TScintEditCharAddedEvent = procedure(Sender: TObject; Ch: AnsiChar) of object;
TScintEditDropFilesEvent = procedure(Sender: TObject; X, Y: Integer;
AFiles: TStrings) of object;
TScintHintInfo = {$IFDEF UNICODE} Controls. {$ENDIF} THintInfo;
TScintEditHintShowEvent = procedure(Sender: TObject;
var Info: TScintHintInfo) of object;
TScintEditMarginClickEvent = procedure(Sender: TObject; MarginNumber: Integer;
Line: Integer) of object;
TScintFindOption = (sfoMatchCase, sfoWholeWord);
TScintFindOptions = set of TScintFindOption;
TScintIndentationGuides = (sigNone, sigReal, sigLookForward, sigLookBoth);
TScintIndicatorNumber = 0..2;
TScintIndicatorNumbers = set of TScintIndicatorNumber;
TScintLineEndings = (sleCRLF, sleCR, sleLF);
TScintLineState = type Integer;
TScintMarkerNumber = 0..31;
TScintMarkerNumbers = set of TScintMarkerNumber;
TScintRange = record
StartPos, EndPos: Integer;
end;
TScintRawCharSet = set of AnsiChar;
TScintRawString = type {$IFDEF UNICODE} RawByteString {$ELSE} AnsiString {$ENDIF};
TScintStyleNumber = 0..31;
TScintVirtualSpaceOption = (svsRectangularSelection, svsUserAccessible);
TScintVirtualSpaceOptions = set of TScintVirtualSpaceOption;
TScintEditStrings = class;
TScintCustomStyler = class;
TScintEdit = class(TWinControl)
private
FAcceptDroppedFiles: Boolean;
FAutoCompleteFontName: String;
FAutoCompleteFontSize: Integer;
FCodePage: Integer;
FDirectPtr: Pointer;
FEffectiveCodePage: Integer;
FEffectiveCodePageDBCS: Boolean;
FFillSelectionToEdge: Boolean;
FForceModified: Boolean;
FIndentationGuides: TScintIndentationGuides;
FLeadBytes: TScintRawCharSet;
FLineNumbers: Boolean;
FLines: TScintEditStrings;
FOnChange: TScintEditChangeEvent;
FOnCharAdded: TScintEditCharAddedEvent;
FOnDropFiles: TScintEditDropFilesEvent;
FOnHintShow: TScintEditHintShowEvent;
FOnMarginClick: TScintEditMarginClickEvent;
FOnModifiedChange: TNotifyEvent;
FOnUpdateUI: TNotifyEvent;
FReportCaretPositionToStyler: Boolean;
FStyler: TScintCustomStyler;
FTabWidth: Integer;
FUseStyleAttributes: Boolean;
FUseTabCharacter: Boolean;
FVirtualSpaceOptions: TScintVirtualSpaceOptions;
FWordWrap: Boolean;
procedure ApplyOptions;
function GetAutoCompleteActive: Boolean;
function GetCaretColumn: Integer;
function GetCaretColumnExpanded: Integer;
function GetCaretLine: Integer;
function GetCaretPosition: Integer;
function GetCaretVirtualSpace: Integer;
function GetInsertMode: Boolean;
function GetLineEndings: TScintLineEndings;
function GetLineEndingString: TScintRawString;
function GetLineHeight: Integer;
function GetLinesInWindow: Integer;
function GetModified: Boolean;
function GetRawSelText: TScintRawString;
function GetRawText: TScintRawString;
function GetRawTextLength: Integer;
function GetReadOnly: Boolean;
function GetSelection: TScintRange;
function GetSelText: String;
function GetTopLine: Integer;
function GetZoom: Integer;
procedure SetAcceptDroppedFiles(const Value: Boolean);
procedure SetAutoCompleteFontName(const Value: String);
procedure SetAutoCompleteFontSize(const Value: Integer);
procedure SetCodePage(const Value: Integer);
procedure SetCaretColumn(const Value: Integer);
procedure SetCaretLine(const Value: Integer);
procedure SetCaretPosition(const Value: Integer);
procedure SetCaretVirtualSpace(const Value: Integer);
procedure SetFillSelectionToEdge(const Value: Boolean);
procedure SetIndentationGuides(const Value: TScintIndentationGuides);
procedure SetLineNumbers(const Value: Boolean);
procedure SetRawSelText(const Value: TScintRawString);
procedure SetRawText(const Value: TScintRawString);
procedure SetReadOnly(const Value: Boolean);
procedure SetSelection(const Value: TScintRange);
procedure SetSelText(const Value: String);
procedure SetStyler(const Value: TScintCustomStyler);
procedure SetTabWidth(const Value: Integer);
procedure SetTopLine(const Value: Integer);
procedure SetUseStyleAttributes(const Value: Boolean);
procedure SetUseTabCharacter(const Value: Boolean);
procedure SetVirtualSpaceOptions(const Value: TScintVirtualSpaceOptions);
procedure SetWordWrap(const Value: Boolean);
procedure SetZoom(const Value: Integer);
procedure StyleNeeded(const EndPos: Integer);
procedure UpdateCodePage;
procedure UpdateLineNumbersWidth;
procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
procedure WMDestroy(var Message: TWMDestroy); message WM_DESTROY;
procedure WMDropFiles(var Message: TWMDropFiles); message WM_DROPFILES;
procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND;
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMMouseWheel(var Message: TMessage); message WM_MOUSEWHEEL;
protected
procedure Change(const AInserting: Boolean; const AStartPos, ALength,
ALinesDelta: Integer); virtual;
procedure CheckPosRange(const StartPos, EndPos: Integer);
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
class procedure Error(const S: String);
class procedure ErrorFmt(const S: String; const Args: array of const);
function GetMainSelection: Integer;
function GetTarget: TScintRange;
procedure InitRawString(var S: TScintRawString; const Len: Integer);
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Notify(const N: TSCNotification); virtual;
procedure SetTarget(const StartPos, EndPos: Integer);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AddMarker(const Line: Integer; const Marker: TScintMarkerNumber);
procedure BeginUndoAction;
function Call(Msg: Cardinal; WParam: Longint; LParam: Longint): Longint;
function CallStr(Msg: Cardinal; WParam: Longint;
const LParamStr: TScintRawString): Longint;
procedure CancelAutoComplete;
function CanRedo: Boolean;
function CanUndo: Boolean;
procedure ChooseCaretX;
procedure ClearAll;
procedure ClearSelection;
procedure ClearUndo;
function ConvertRawStringToString(const S: TScintRawString): String;
function ConvertPCharToRawString(const Text: PChar;
const TextLen: Integer): TScintRawString;
function ConvertStringToRawString(const S: String): TScintRawString;
procedure CopyToClipboard;
procedure CutToClipboard;
procedure DeleteAllMarkersOnLine(const Line: Integer);
procedure DeleteMarker(const Line: Integer; const Marker: TScintMarkerNumber);
procedure EndUndoAction;
function FindRawText(const StartPos, EndPos: Integer; const S: TScintRawString;
const Options: TScintFindOptions; out MatchRange: TScintRange): Boolean;
function FindText(const StartPos, EndPos: Integer; const S: String;
const Options: TScintFindOptions; out MatchRange: TScintRange): Boolean;
procedure ForceModifiedState;
function GetCharAtPosition(const Pos: Integer): AnsiChar;
function GetColumnFromPosition(const Pos: Integer): Integer;
function GetDocLineFromVisibleLine(const VisibleLine: Integer): Integer;
function GetIndicatorsAtPosition(const Pos: Integer): TScintIndicatorNumbers;
function GetLineEndPosition(const Line: Integer): Integer;
function GetLineFromPosition(const Pos: Integer): Integer;
function GetLineIndentation(const Line: Integer): Integer;
function GetLineIndentPosition(const Line: Integer): Integer;
function GetMarkers(const Line: Integer): TScintMarkerNumbers;
function GetPointFromPosition(const Pos: Integer): TPoint;
function GetPositionAfter(const Pos: Integer): Integer;
function GetPositionBefore(const Pos: Integer): Integer;
function GetPositionFromLine(const Line: Integer): Integer;
function GetPositionFromLineColumn(const Line, Column: Integer): Integer;
function GetPositionFromLineExpandedColumn(const Line, ExpandedColumn: Integer): Integer;
function GetPositionFromPoint(const P: TPoint;
const CharPosition, CloseOnly: Boolean): Integer;
function GetPositionOfMatchingBrace(const Pos: Integer): Integer;
function GetRawTextRange(const StartPos, EndPos: Integer): TScintRawString;
function GetStyleAtPosition(const Pos: Integer): TScintStyleNumber;
function GetTextRange(const StartPos, EndPos: Integer): String;
function GetVisibleLineFromDocLine(const DocLine: Integer): Integer;
function GetWordEndPosition(const Pos: Integer; const OnlyWordChars: Boolean): Integer;
function GetWordStartPosition(const Pos: Integer; const OnlyWordChars: Boolean): Integer;
function IsPositionInViewVertically(const Pos: Integer): Boolean;
procedure PasteFromClipboard;
function RawSelTextEquals(const S: TScintRawString; const MatchCase: Boolean): Boolean;
procedure Redo;
function ReplaceRawTextRange(const StartPos, EndPos: Integer;
const S: TScintRawString): TScintRange;
function ReplaceTextRange(const StartPos, EndPos: Integer; const S: String): TScintRange;
procedure RestyleLine(const Line: Integer);
procedure ScrollCaretIntoView;
function SelAvail: Boolean;
procedure SelectAll;
function SelTextEquals(const S: String; const MatchCase: Boolean): Boolean;
procedure SetAutoCompleteFillupChars(const FillupChars: AnsiString);
procedure SetAutoCompleteSelectedItem(const S: TScintRawString);
procedure SetAutoCompleteStopChars(const StopChars: AnsiString);
procedure SetBraceHighlighting(const Pos1, Pos2: Integer);
procedure SetCursorID(const CursorID: Integer);
procedure SetEmptySelection;
procedure SetLineIndentation(const Line, Indentation: Integer);
procedure SetSavePoint;
procedure ShowAutoComplete(const CharsEntered: Integer; const WordList: AnsiString);
procedure Undo;
procedure UpdateStyleAttributes;
function WordAtCursor: String;
procedure ZoomIn;
procedure ZoomOut;
property AutoCompleteActive: Boolean read GetAutoCompleteActive;
property CaretColumn: Integer read GetCaretColumn write SetCaretColumn;
property CaretColumnExpanded: Integer read GetCaretColumnExpanded;
property CaretLine: Integer read GetCaretLine write SetCaretLine;
property CaretPosition: Integer read GetCaretPosition write SetCaretPosition;
property CaretVirtualSpace: Integer read GetCaretVirtualSpace write SetCaretVirtualSpace;
property EffectiveCodePage: Integer read FEffectiveCodePage;
property InsertMode: Boolean read GetInsertMode;
property LineEndings: TScintLineEndings read GetLineEndings;
property LineEndingString: TScintRawString read GetLineEndingString;
property LineHeight: Integer read GetLineHeight;
property Lines: TScintEditStrings read FLines;
property LinesInWindow: Integer read GetLinesInWindow;
property Modified: Boolean read GetModified;
property RawSelText: TScintRawString read GetRawSelText write SetRawSelText;
property RawText: TScintRawString read GetRawText write SetRawText;
property RawTextLength: Integer read GetRawTextLength;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly;
property Selection: TScintRange read GetSelection write SetSelection;
property SelText: String read GetSelText write SetSelText;
property Styler: TScintCustomStyler read FStyler write SetStyler;
property TopLine: Integer read GetTopLine write SetTopLine;
published
property AcceptDroppedFiles: Boolean read FAcceptDroppedFiles write SetAcceptDroppedFiles
default False;
property AutoCompleteFontName: String read FAutoCompleteFontName
write SetAutoCompleteFontName;
property AutoCompleteFontSize: Integer read FAutoCompleteFontSize
write SetAutoCompleteFontSize default 0;
property CodePage: Integer read FCodePage write SetCodePage default 0;
property FillSelectionToEdge: Boolean read FFillSelectionToEdge write SetFillSelectionToEdge
default False;
property Font;
property IndentationGuides: TScintIndentationGuides read FIndentationGuides
write SetIndentationGuides default sigNone;
property LineNumbers: Boolean read FLineNumbers write SetLineNumbers default False;
property ParentFont;
property PopupMenu;
property ReportCaretPositionToStyler: Boolean read FReportCaretPositionToStyler
write FReportCaretPositionToStyler;
property TabStop default True;
property TabWidth: Integer read FTabWidth write SetTabWidth default 8;
property UseStyleAttributes: Boolean read FUseStyleAttributes write SetUseStyleAttributes
default True;
property UseTabCharacter: Boolean read FUseTabCharacter write SetUseTabCharacter
default True;
property VirtualSpaceOptions: TScintVirtualSpaceOptions read FVirtualSpaceOptions
write SetVirtualSpaceOptions default [];
property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
property Zoom: Integer read GetZoom write SetZoom default 0;
property OnChange: TScintEditChangeEvent read FOnChange write FOnChange;
property OnCharAdded: TScintEditCharAddedEvent read FOnCharAdded write FOnCharAdded;
property OnDropFiles: TScintEditDropFilesEvent read FOnDropFiles write FOnDropFiles;
property OnHintShow: TScintEditHintShowEvent read FOnHintShow write FOnHintShow;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMarginClick: TScintEditMarginClickEvent read FOnMarginClick write FOnMarginClick;
property OnModifiedChange: TNotifyEvent read FOnModifiedChange write FOnModifiedChange;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnUpdateUI: TNotifyEvent read FOnUpdateUI write FOnUpdateUI;
end;
TScintEditStrings = class(TStrings)
private
FEdit: TScintEdit;
function GetLineEndingLength(const Index: Integer): Integer;
function GetRawLine(Index: Integer): TScintRawString;
function GetRawLineWithEnding(Index: Integer): TScintRawString;
function GetRawLineLength(Index: Integer): Integer;
function GetRawLineLengthWithEnding(Index: Integer): Integer;
function GetState(Index: Integer): TScintLineState;
procedure PutRawLine(Index: Integer; const S: TScintRawString);
protected
procedure CheckIndexRange(const Index: Integer);
procedure CheckIndexRangePlusOne(const Index: Integer);
{$IFNDEF UNICODE}
class procedure Error(Msg: PResStringRec; Data: Integer);
{$ENDIF}
function Get(Index: Integer): String; override;
function GetCount: Integer; override;
function GetTextStr: String; override;
procedure Put(Index: Integer; const S: String); override;
procedure SetTextStr(const Value: String); override;
public
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: String); override;
procedure InsertRawLine(Index: Integer; const S: TScintRawString);
procedure SetText(Text: PChar); override;
property RawLineLengths[Index: Integer]: Integer read GetRawLineLength;
property RawLineLengthsWithEnding[Index: Integer]: Integer read GetRawLineLengthWithEnding;
property RawLines[Index: Integer]: TScintRawString read GetRawLine write PutRawLine;
property RawLinesWithEnding[Index: Integer]: TScintRawString read GetRawLineWithEnding;
property State[Index: Integer]: TScintLineState read GetState;
end;
TScintStyleAttributes = record
FontName: String;
FontSize: Integer;
FontStyle: TFontStyles;
FontCharset: TFontCharset;
ForeColor: TColor;
BackColor: TColor;
end;
TScintCustomStyler = class(TComponent)
private
FCaretIndex: Integer;
FCurIndex: Integer;
FLineState: TScintLineState;
FStyleStartIndex: Integer;
FStyleStr: AnsiString;
FText: TScintRawString;
FTextLen: Integer;
function GetCurChar: AnsiChar;
function GetEndOfLine: Boolean;
protected
procedure ApplyIndicators(const Indicators: TScintIndicatorNumbers;
StartIndex, EndIndex: Integer);
procedure ApplyStyle(const Style: TScintStyleNumber;
StartIndex, EndIndex: Integer);
procedure CommitStyle(const Style: TScintStyleNumber);
function ConsumeAllRemaining: Boolean;
function ConsumeChar(const C: AnsiChar): Boolean;
function ConsumeCharIn(const Chars: TScintRawCharSet): Boolean;
function ConsumeChars(const Chars: TScintRawCharSet): Boolean;
function ConsumeCharsNot(const Chars: TScintRawCharSet): Boolean;
function ConsumeString(const Chars: TScintRawCharSet): TScintRawString;
function CurCharIn(const Chars: TScintRawCharSet): Boolean;
function CurCharIs(const C: AnsiChar): Boolean;
procedure GetStyleAttributes(const Style: Integer;
var Attributes: TScintStyleAttributes); virtual; abstract;
function LineTextSpans(const S: TScintRawString): Boolean; virtual;
function NextCharIs(const C: AnsiChar): Boolean;
function PreviousCharIn(const Chars: TScintRawCharSet): Boolean;
procedure ResetCurIndexTo(Index: Integer);
procedure ReplaceText(StartIndex, EndIndex: Integer; const C: AnsiChar);
procedure StyleNeeded; virtual; abstract;
property CaretIndex: Integer read FCaretIndex;
property CurChar: AnsiChar read GetCurChar;
property CurIndex: Integer read FCurIndex;
property EndOfLine: Boolean read GetEndOfLine;
property LineState: TScintLineState read FLineState write FLineState;
property StyleStartIndex: Integer read FStyleStartIndex;
property Text: TScintRawString read FText;
property TextLength: Integer read FTextLen;
end;
EScintEditError = class(Exception);
implementation
uses
ShellAPI, RTLConsts, UITypes;
{ TScintEdit }
constructor TScintEdit.Create(AOwner: TComponent);
begin
inherited;
FLines := TScintEditStrings.Create;
FLines.FEdit := Self;
FTabWidth := 8;
FUseStyleAttributes := True;
FUseTabCharacter := True;
SetBounds(0, 0, 257, 193);
ParentColor := False;
TabStop := True;
end;
destructor TScintEdit.Destroy;
begin
SetStyler(nil);
FLines.Free;
FLines := nil;
inherited;
end;
procedure TScintEdit.AddMarker(const Line: Integer;
const Marker: TScintMarkerNumber);
begin
FLines.CheckIndexRange(Line);
Call(SCI_MARKERADD, Line, Marker);
end;
procedure TScintEdit.ApplyOptions;
const
IndentationGuides: array [TScintIndentationGuides] of Integer = (SC_IV_NONE, SC_IV_REAL,
SC_IV_LOOKFORWARD, SC_IV_LOOKBOTH);
var
Flags: Integer;
begin
if not HandleAllocated then
Exit;
Call(SCI_SETSELEOLFILLED, Ord(FFillSelectionToEdge), 0);
Call(SCI_SETTABWIDTH, FTabWidth, 0);
Call(SCI_SETUSETABS, Ord(FUseTabCharacter), 0);
Flags := 0;
if svsRectangularSelection in VirtualSpaceOptions then
Flags := Flags or SCVS_RECTANGULARSELECTION;
if svsUserAccessible in VirtualSpaceOptions then
Flags := Flags or SCVS_USERACCESSIBLE;
Call(SCI_SETVIRTUALSPACEOPTIONS, Flags, 0);
Call(SCI_SETWRAPMODE, Ord(FWordWrap), 0);
Call(SCI_SETINDENTATIONGUIDES, IndentationGuides[FIndentationGuides], 0);
end;
procedure TScintEdit.BeginUndoAction;
begin
Call(SCI_BEGINUNDOACTION, 0, 0);
end;
function TScintEdit.Call(Msg: Cardinal; WParam: Longint; LParam: Longint): Longint;
var
ErrorStatus: LRESULT;
begin
HandleNeeded;
if FDirectPtr = nil then
Error('Call: FDirectPtr is nil');
Result := Scintilla_DirectFunction(FDirectPtr, Msg, WParam, LParam);
ErrorStatus := Scintilla_DirectFunction(FDirectPtr, SCI_GETSTATUS, 0, 0);
if ErrorStatus <> 0 then begin
Scintilla_DirectFunction(FDirectPtr, SCI_SETSTATUS, 0, 0);
ErrorFmt('Error status %d returned after Call(%u, %d, %d) = %d',
[ErrorStatus, Msg, WParam, LParam, Result]);
end;
end;
function TScintEdit.CallStr(Msg: Cardinal; WParam: Longint;
const LParamStr: TScintRawString): Longint;
begin
Result := Call(Msg, WParam, LPARAM(PAnsiChar(LParamStr)));
end;
procedure TScintEdit.CancelAutoComplete;
begin
Call(SCI_AUTOCCANCEL, 0, 0);
end;
function TScintEdit.CanRedo: Boolean;
begin
Result := Call(SCI_CANREDO, 0, 0) <> 0;
end;
function TScintEdit.CanUndo: Boolean;
begin
Result := Call(SCI_CANUNDO, 0, 0) <> 0;
end;
procedure TScintEdit.Change(const AInserting: Boolean;
const AStartPos, ALength, ALinesDelta: Integer);
var
Info: TScintEditChangeInfo;
begin
inherited Changed;
if Assigned(FOnChange) then begin
Info.Inserting := AInserting;
Info.StartPos := AStartPos;
Info.Length := ALength;
Info.LinesDelta := ALinesDelta;
FOnChange(Self, Info);
end;
end;
procedure TScintEdit.CheckPosRange(const StartPos, EndPos: Integer);
begin
if (StartPos < 0) or (StartPos > EndPos) or (EndPos > GetRawTextLength) then
ErrorFmt('CheckPosRange: Invalid range (%d, %d)', [StartPos, EndPos]);
end;
procedure TScintEdit.ChooseCaretX;
begin
Call(SCI_CHOOSECARETX, 0, 0);
end;
procedure TScintEdit.ClearAll;
begin
Call(SCI_CLEARALL, 0, 0);
ChooseCaretX;
end;
procedure TScintEdit.ClearSelection;
begin
Call(SCI_CLEAR, 0, 0);
end;
procedure TScintEdit.ClearUndo;
begin
{ SCI_EMPTYUNDOBUFFER resets the save point but doesn't send a
SCN_SAVEPOINTREACHED notification. Call SetSavePoint manually to get
that. SetSavePoint additionally resets FForceModified. }
SetSavePoint;
Call(SCI_EMPTYUNDOBUFFER, 0, 0);
end;
function TScintEdit.ConvertRawStringToString(const S: TScintRawString): String;
{$IFDEF UNICODE}
var
SrcLen, DestLen: Integer;
DestStr: UnicodeString;
begin
SrcLen := Length(S);
if SrcLen > 0 then begin
DestLen := MultiByteToWideChar(FCodePage, 0, PAnsiChar(S), SrcLen, nil, 0);
if DestLen <= 0 then
Error('MultiByteToWideChar failed');
SetString(DestStr, nil, DestLen);
if MultiByteToWideChar(FCodePage, 0, PAnsiChar(S), SrcLen, @DestStr[1],
Length(DestStr)) <> DestLen then
Error('Unexpected result from MultiByteToWideChar');
end;
Result := DestStr;
end;
{$ELSE}
begin
Result := S;
end;
{$ENDIF}
function TScintEdit.ConvertPCharToRawString(const Text: PChar;
const TextLen: Integer): TScintRawString;
var
{$IFDEF UNICODE}
DestLen: Integer;
{$ENDIF}
DestStr: TScintRawString;
begin
if TextLen > 0 then begin
{$IFDEF UNICODE}
DestLen := WideCharToMultiByte(FCodePage, 0, Text, TextLen, nil, 0, nil, nil);
if DestLen <= 0 then
Error('WideCharToMultiByte failed');
InitRawString(DestStr, DestLen);
if WideCharToMultiByte(FCodePage, 0, Text, TextLen, @DestStr[1], Length(DestStr),
nil, nil) <> DestLen then
Error('Unexpected result from WideCharToMultiByte');
{$ELSE}
SetString(DestStr, Text, TextLen);
{$ENDIF}
end;
Result := DestStr;
end;
function TScintEdit.ConvertStringToRawString(const S: String): TScintRawString;
begin
{$IFDEF UNICODE}
Result := ConvertPCharToRawString(PChar(S), Length(S));
{$ELSE}
Result := S;
{$ENDIF}
end;
procedure TScintEdit.CopyToClipboard;
begin
Call(SCI_COPY, 0, 0);
end;
procedure TScintEdit.CreateParams(var Params: TCreateParams);
begin
inherited;
CreateSubClass(Params, 'Scintilla');
//Params.ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
Params.WindowClass.style := Params.WindowClass.style and
not (CS_HREDRAW or CS_VREDRAW);
end;
procedure TScintEdit.CreateWnd;
begin
inherited;
FDirectPtr := Pointer(SendMessage(Handle, SCI_GETDIRECTPOINTER, 0, 0));
if FDirectPtr = nil then
Error('CreateWnd: FDirectPtr is nil');
UpdateCodePage;
Call(SCI_SETCARETPERIOD, GetCaretBlinkTime, 0);
Call(SCI_SETSCROLLWIDTHTRACKING, 1, 0);
{ The default popup menu conflicts with the VCL's PopupMenu on Delphi 3 }
Call(SCI_USEPOPUP, 0, 0);
{$IFNDEF UNICODE}
{ This hack is needed because non-Unicode VCL replaces the Scintilla's
default Unicode window proc with an ANSI one }
if Win32Platform = VER_PLATFORM_WIN32_NT then
Call(SCI_SETKEYSUNICODE, 1, 0);
{$ENDIF}
ApplyOptions;
UpdateStyleAttributes;
if FAcceptDroppedFiles then
DragAcceptFiles(Handle, True);
end;
procedure TScintEdit.CutToClipboard;
begin
Call(SCI_CUT, 0, 0);
end;
procedure TScintEdit.DeleteAllMarkersOnLine(const Line: Integer);
begin
FLines.CheckIndexRange(Line);
Call(SCI_MARKERDELETE, Line, -1);
end;
procedure TScintEdit.DeleteMarker(const Line: Integer;
const Marker: TScintMarkerNumber);
begin
FLines.CheckIndexRange(Line);
Call(SCI_MARKERDELETE, Line, Marker);
end;
procedure TScintEdit.EndUndoAction;
begin
Call(SCI_ENDUNDOACTION, 0, 0);
end;
class procedure TScintEdit.Error(const S: String);
begin
raise EScintEditError.Create('TScintEdit error: ' + S);
end;
class procedure TScintEdit.ErrorFmt(const S: String; const Args: array of const);
begin
Error(Format(S, Args));
end;
function TScintEdit.FindRawText(const StartPos, EndPos: Integer;
const S: TScintRawString; const Options: TScintFindOptions;
out MatchRange: TScintRange): Boolean;
var
Flags: Integer;
begin
Flags := 0;
if sfoMatchCase in Options then
Flags := Flags or SCFIND_MATCHCASE;
if sfoWholeWord in Options then
Flags := Flags or SCFIND_WHOLEWORD;
SetTarget(StartPos, EndPos);
Call(SCI_SETSEARCHFLAGS, Flags, 0);
Result := Call(SCI_SEARCHINTARGET, Length(S), LPARAM(PAnsiChar(S))) >= 0;
if Result then
MatchRange := GetTarget;
end;
function TScintEdit.FindText(const StartPos, EndPos: Integer; const S: String;
const Options: TScintFindOptions; out MatchRange: TScintRange): Boolean;
begin
Result := FindRawText(StartPos, EndPos, ConvertStringToRawString(S),
Options, MatchRange);
end;
procedure TScintEdit.ForceModifiedState;
begin
if not FForceModified then begin
FForceModified := True;
if Assigned(FOnModifiedChange) then
FOnModifiedChange(Self);
end;
end;
function TScintEdit.GetAutoCompleteActive: Boolean;
begin
Result := Call(SCI_AUTOCACTIVE, 0, 0) <> 0;
end;
function TScintEdit.GetCaretColumn: Integer;
begin
Result := GetColumnFromPosition(GetCaretPosition);
end;
function TScintEdit.GetCaretColumnExpanded: Integer;
begin
Result := Call(SCI_GETCOLUMN, GetCaretPosition, 0);
Inc(Result, GetCaretVirtualSpace);
end;
function TScintEdit.GetCaretLine: Integer;
begin
Result := GetLineFromPosition(GetCaretPosition);
end;
function TScintEdit.GetCaretPosition: Integer;
begin
Result := Call(SCI_GETCURRENTPOS, 0, 0);
end;
function TScintEdit.GetCaretVirtualSpace: Integer;
begin
Result := Call(SCI_GETSELECTIONNCARETVIRTUALSPACE, GetMainSelection, 0);
end;
function TScintEdit.GetCharAtPosition(const Pos: Integer): AnsiChar;
begin
Result := AnsiChar(Call(SCI_GETCHARAT, Pos, 0));
end;
function TScintEdit.GetColumnFromPosition(const Pos: Integer): Integer;
var
Line: Integer;
begin
Line := GetLineFromPosition(Pos);
Result := Pos - GetPositionFromLine(Line);
end;
function TScintEdit.GetDocLineFromVisibleLine(const VisibleLine: Integer): Integer;
begin
Result := Call(SCI_DOCLINEFROMVISIBLE, VisibleLine, 0);
end;
function TScintEdit.GetIndicatorsAtPosition(const Pos: Integer): TScintIndicatorNumbers;
var
Indic: Byte;
begin
Indic := Byte(Call(SCI_GETSTYLEAT, Pos, 0)) shr 5;
Result := TScintIndicatorNumbers(Indic);
end;
function TScintEdit.GetInsertMode: Boolean;
begin
Result := Call(SCI_GETOVERTYPE, 0, 0) = 0;
end;
function TScintEdit.GetLineEndings: TScintLineEndings;
begin
case Call(SCI_GETEOLMODE, 0, 0) of
SC_EOL_CR: Result := sleCR;
SC_EOL_LF: Result := sleLF;
else
Result := sleCRLF;
end;
end;
function TScintEdit.GetLineEndingString: TScintRawString;
const
EndingStrs: array[TScintLineEndings] of TScintRawString =
(#13#10, #13, #10);
begin
Result := EndingStrs[LineEndings];
end;
function TScintEdit.GetLineEndPosition(const Line: Integer): Integer;
begin
FLines.CheckIndexRange(Line);
Result := Call(SCI_GETLINEENDPOSITION, Line, 0);
end;
function TScintEdit.GetLineFromPosition(const Pos: Integer): Integer;
begin
Result := Call(SCI_LINEFROMPOSITION, Pos, 0);
end;
function TScintEdit.GetLineHeight: Integer;
begin
Result := Call(SCI_TEXTHEIGHT, 0, 0);
end;
function TScintEdit.GetLineIndentation(const Line: Integer): Integer;
begin
FLines.CheckIndexRange(Line);
Result := Call(SCI_GETLINEINDENTATION, Line, 0);
end;
function TScintEdit.GetLineIndentPosition(const Line: Integer): Integer;
begin
FLines.CheckIndexRange(Line);
Result := Call(SCI_GETLINEINDENTPOSITION, Line, 0);
end;
function TScintEdit.GetLinesInWindow: Integer;
begin
Result := Call(SCI_LINESONSCREEN, 0, 0);
end;
function TScintEdit.GetMainSelection: Integer;
begin
Result := Call(SCI_GETMAINSELECTION, 0, 0);
end;
function TScintEdit.GetMarkers(const Line: Integer): TScintMarkerNumbers;
begin
FLines.CheckIndexRange(Line);
Integer(Result) := Call(SCI_MARKERGET, Line, 0);
end;
function TScintEdit.GetModified: Boolean;
begin
Result := FForceModified or (Call(SCI_GETMODIFY, 0, 0) <> 0);
end;
function TScintEdit.GetPointFromPosition(const Pos: Integer): TPoint;
begin
Result.X := Call(SCI_POINTXFROMPOSITION, 0, Pos);
Result.Y := Call(SCI_POINTYFROMPOSITION, 0, Pos);
end;
function TScintEdit.GetPositionAfter(const Pos: Integer): Integer;
begin
Result := Call(SCI_POSITIONAFTER, Pos, 0);
end;
function TScintEdit.GetPositionBefore(const Pos: Integer): Integer;
begin
Result := Call(SCI_POSITIONBEFORE, Pos, 0);
end;
function TScintEdit.GetPositionFromLine(const Line: Integer): Integer;
begin
FLines.CheckIndexRangePlusOne(Line);
Result := Call(SCI_POSITIONFROMLINE, Line, 0);
end;
function TScintEdit.GetPositionFromLineColumn(const Line, Column: Integer): Integer;
var
Col, Len: Integer;
begin
Col := Column;
Result := GetPositionFromLine(Line);
Len := GetLineEndPosition(Line) - Result;
if Col > Len then
Col := Len;
if Col > 0 then
Inc(Result, Col);
end;
function TScintEdit.GetPositionFromLineExpandedColumn(const Line,
ExpandedColumn: Integer): Integer;
begin
FLines.CheckIndexRange(Line);
Result := Call(SCI_FINDCOLUMN, Line, ExpandedColumn);
end;
function TScintEdit.GetPositionFromPoint(const P: TPoint;
const CharPosition, CloseOnly: Boolean): Integer;
begin
if CharPosition then begin
if CloseOnly then
Result := Call(SCI_CHARPOSITIONFROMPOINTCLOSE, P.X, P.Y)
else
Result := Call(SCI_CHARPOSITIONFROMPOINT, P.X, P.Y);
end
else begin
if CloseOnly then
Result := Call(SCI_POSITIONFROMPOINTCLOSE, P.X, P.Y)
else
Result := Call(SCI_POSITIONFROMPOINT, P.X, P.Y);
end;
end;
function TScintEdit.GetPositionOfMatchingBrace(const Pos: Integer): Integer;
begin
Result := Call(SCI_BRACEMATCH, Pos, 0);
end;
function TScintEdit.GetRawSelText: TScintRawString;
var
Len: Integer;
S: TScintRawString;
begin
Len := Call(SCI_GETSELTEXT, 0, 0) - 1;
if Len > 0 then begin
InitRawString(S, Len);
Call(SCI_GETSELTEXT, 0, LPARAM(PAnsiChar(@S[1])));
end;
Result := S;
end;
function TScintEdit.GetRawText: TScintRawString;
begin
Result := GetRawTextRange(0, GetRawTextLength);
end;
function TScintEdit.GetRawTextLength: Integer;
begin
Result := Call(SCI_GETLENGTH, 0, 0);
end;
function TScintEdit.GetRawTextRange(const StartPos, EndPos: Integer): TScintRawString;
var
S: TScintRawString;
Range: TSci_TextRange;
begin
CheckPosRange(StartPos, EndPos);
if EndPos > StartPos then begin
InitRawString(S, EndPos - StartPos);
Range.chrg.cpMin := StartPos;
Range.chrg.cpMax := EndPos;
Range.lpstrText := @S[1];
if Call(SCI_GETTEXTRANGE, 0, LPARAM(@Range)) <> EndPos - StartPos then
Error('Unexpected result from SCI_GETTEXTRANGE');
end;
Result := S;
end;
function TScintEdit.GetReadOnly: Boolean;
begin
Result := Call(SCI_GETREADONLY, 0, 0) <> 0;
end;
function TScintEdit.GetSelection: TScintRange;
begin
Result.StartPos := Call(SCI_GETSELECTIONSTART, 0, 0);
Result.EndPos := Call(SCI_GETSELECTIONEND, 0, 0);
end;
function TScintEdit.GetSelText: String;
begin
Result := ConvertRawStringToString(GetRawSelText);
end;
function TScintEdit.GetStyleAtPosition(const Pos: Integer): TScintStyleNumber;
begin
Result := Call(SCI_GETSTYLEAT, Pos, 0) and $1F;
end;
function TScintEdit.GetTarget: TScintRange;
begin
Result.StartPos := Call(SCI_GETTARGETSTART, 0, 0);
Result.EndPos := Call(SCI_GETTARGETEND, 0, 0);
end;
function TScintEdit.GetTextRange(const StartPos, EndPos: Integer): String;
begin
Result := ConvertRawStringToString(GetRawTextRange(StartPos, EndPos));
end;
function TScintEdit.GetTopLine: Integer;
begin
Result := Call(SCI_GETFIRSTVISIBLELINE, 0, 0);
end;
function TScintEdit.GetVisibleLineFromDocLine(const DocLine: Integer): Integer;
begin
FLines.CheckIndexRange(DocLine);
Result := Call(SCI_VISIBLEFROMDOCLINE, DocLine, 0);
end;
function TScintEdit.GetWordEndPosition(const Pos: Integer;
const OnlyWordChars: Boolean): Integer;
begin
Result := Call(SCI_WORDENDPOSITION, Pos, Ord(OnlyWordChars));
end;
function TScintEdit.GetWordStartPosition(const Pos: Integer;
const OnlyWordChars: Boolean): Integer;
begin
Result := Call(SCI_WORDSTARTPOSITION, Pos, Ord(OnlyWordChars));
end;
function TScintEdit.GetZoom: Integer;
begin
Result := Call(SCI_GETZOOM, 0, 0);
end;
procedure TScintEdit.InitRawString(var S: TScintRawString; const Len: Integer);
begin
SetString(S, nil, Len);
{$IFDEF UNICODE}
//experimental, dont need this ATM:
if FCodePage <> 0 then
System.SetCodePage(RawByteString(S), FCodePage, False);
{$ENDIF}
end;
function TScintEdit.IsPositionInViewVertically(const Pos: Integer): Boolean;
var
P: TPoint;
begin