forked from gphilippot/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScintillaHighlighting.pb
3982 lines (3206 loc) · 162 KB
/
ScintillaHighlighting.pb
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
;--------------------------------------------------------------------------------------------
; Copyright (c) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
;--------------------------------------------------------------------------------------------
CompilerIf #CompileWindows | #CompileLinux | #CompileMac
#SCI_NORM = 0
#SCI_SHIFT = #SCMOD_SHIFT
#SCI_CTRL = #SCMOD_CTRL
#SCI_ALT = #SCMOD_ALT
#SCI_CSHIFT = (#SCI_CTRL | #SCI_SHIFT)
#SCI_ASHIFT = (#SCI_ALT | #SCI_SHIFT)
; remaining from a time when the Scintilla.res was incomplete
Structure SCI_CharacterRange Extends SCCharacterRange
EndStructure
Structure SCI_TextToFind Extends SCTextToFind
EndStructure
; Fix for the #SCI_COUNTCHARACTERS message. Don't use that message directly because of the below newline trouble
;
Procedure CountCharacters(Gadget, startPos, endPos)
Count = ScintillaSendMessage(Gadget, #SCI_COUNTCHARACTERS, startPos, endPos)
; The #SCI_COUNTCHARACTERS message counts CRLF as one char!
; This is especially weird, since its counterpart #SCI_POSITIONRELATIVE counts it as two!
; So scan the range and fix up the count so the two match (and also match our own memory buffers)
For pos = startPos To endPos - 1
If ScintillaSendMessage(Gadget, #SCI_GETCHARAT, pos) = 13 And ScintillaSendMessage(Gadget, #SCI_GETCHARAT, pos + 1) = 10
Count + 1
EndIf
Next pos
ProcedureReturn Count
EndProcedure
Procedure SendEditorFontMessage(Style, FontName$, FontSize)
; Gtk2 'Pango' need an "!" before the font name (else it will use GDK font)
;
CompilerIf #CompileLinuxGtk2
FontName$ = "!"+FontName$
CompilerEndIf
SendEditorMessage(#SCI_STYLESETFONT, Style, ToAscii(FontName$))
SendEditorMessage(#SCI_STYLESETSIZE, Style, FontSize)
EndProcedure
; calculate really used colors (using replacements for disabled colors
;
Procedure CalculateHighlightingColors()
; first set all colors to the user set value
;
For i = 0 To #COLOR_Last
Colors(i)\DisplayValue = Colors(i)\UserValue
Next i
; for these basic colors, there is no choice (checkbox is hidden)
; so nothing to check for them
; #COLOR_GlobalBackground
; #COLOR_NormalText
; #COLOR_Cursor
; #COLOR_Selection
; #COLOR_SelectionText
; #COLOR_PlainBackground
; All other colors have another one they can fallback on, so do the fallback
; for them (in the right order, as sometimes even the fallback has another
; fallback)
;
If Colors(#COLOR_CurrentLine)\Enabled = 0
Colors(#COLOR_CurrentLine)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
EndIf
If Colors(#COLOR_LineNumberBack)\Enabled = 0
Colors(#COLOR_LineNumberBack)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
EndIf
If Colors(#COLOR_LineNumber)\Enabled = 0
Colors(#COLOR_LineNumber)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Marker)\Enabled = 0
Colors(#COLOR_Marker)\DisplayValue = Colors(#COLOR_LineNumber)\DisplayValue
EndIf
; Syntax coloring all falls back on NormalText
;
If Colors(#COLOR_ASMKeyword)\Enabled = 0
Colors(#COLOR_ASMKeyword)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_BasicKeyword)\Enabled = 0
Colors(#COLOR_BasicKeyword)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_CustomKeyword)\Enabled = 0
Colors(#COLOR_CustomKeyword)\DisplayValue = Colors(#COLOR_BasicKeyword)\DisplayValue
EndIf
If Colors(#COLOR_Comment)\Enabled = 0
Colors(#COLOR_Comment)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Constant)\Enabled = 0
Colors(#COLOR_Constant)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Label)\Enabled = 0
Colors(#COLOR_Label)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Number)\Enabled = 0
Colors(#COLOR_Number)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Operator)\Enabled = 0
Colors(#COLOR_Operator)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Pointer)\Enabled = 0
Colors(#COLOR_Pointer)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_PureKeyword)\Enabled = 0
Colors(#COLOR_PureKeyword)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Separator)\Enabled = 0
Colors(#COLOR_Separator)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_String)\Enabled = 0
Colors(#COLOR_String)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Structure)\Enabled = 0
Colors(#COLOR_Structure)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
If Colors(#COLOR_Module)\Enabled = 0
Colors(#COLOR_Module)\DisplayValue = Colors(#COLOR_NormalText)\DisplayValue
EndIf
; Debugger stuff
;
If Colors(#COLOR_DebuggerLineSymbol)\Enabled = 0
Colors(#COLOR_DebuggerLineSymbol)\DisplayValue = Colors(#COLOR_LineNumber)\DisplayValue
EndIf
If Colors(#COLOR_DebuggerErrorSymbol)\Enabled = 0
Colors(#COLOR_DebuggerErrorSymbol)\DisplayValue = Colors(#COLOR_LineNumber)\DisplayValue
EndIf
If Colors(#COLOR_DebuggerWarningSymbol)\Enabled = 0
Colors(#COLOR_DebuggerWarningSymbol)\DisplayValue = Colors(#COLOR_LineNumber)\DisplayValue
EndIf
If Colors(#COLOR_DebuggerBreakpointSymbol)\Enabled = 0
Colors(#COLOR_DebuggerBreakpointSymbol)\DisplayValue = Colors(#COLOR_LineNumber)\DisplayValue
EndIf
If Colors(#COLOR_DebuggerLine)\Enabled = 0
Colors(#COLOR_DebuggerLine)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
EndIf
If Colors(#COLOR_DebuggerError)\Enabled = 0
Colors(#COLOR_DebuggerError)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
EndIf
If Colors(#COLOR_DebuggerWarning)\Enabled = 0
Colors(#COLOR_DebuggerWarning)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
EndIf
If Colors(#COLOR_DebuggerBreakPoint)\Enabled = 0
Colors(#COLOR_DebuggerBreakPoint)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
EndIf
; Other
;
If Colors(#COLOR_GoodBrace)\Enabled = 0
Colors(#COLOR_GoodBrace)\DisplayValue = Colors(#COLOR_Separator)\DisplayValue
EndIf
If Colors(#COLOR_BadBrace)\Enabled = 0
Colors(#COLOR_BadBrace)\DisplayValue = Colors(#COLOR_Separator)\DisplayValue
EndIf
If Colors(#COLOR_DisabledBack)\Enabled = 0
Colors(#COLOR_DisabledBack)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
EndIf
If Colors(#COLOR_Whitespace)\Enabled = 0
Colors(#COLOR_Whitespace)\DisplayValue = Colors(#COLOR_Comment)\DisplayValue
EndIf
If Colors(#COLOR_ProcedureBack)\Enabled = 0
Colors(#COLOR_ProcedureBack)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
MarkProcedureBackground = 0
Else
If Colors(#COLOR_ProcedureBack)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
MarkProcedureBackground = 0
Else
MarkProcedureBackground = 1
EndIf
EndIf
If Colors(#COLOR_SelectionRepeat)\Enabled = 0
Colors(#COLOR_SelectionRepeat)\DisplayValue = Colors(#COLOR_Selection)\DisplayValue
EndIf
EndProcedure
; translate the highlighting colors into the os specific format for a faster highlighting
;
Procedure SetUpHighlightingColors()
; NOTE: When inventing new code styles, update the SetBackgroundColor() procedure to fit!
*NormalTextColor = 1
*BasicKeywordColor = 2
*CommentColor = 3
*ConstantColor = 4
*StringColor = 5
*PureKeywordColor = 6
*ASMKeywordColor = 7
*OperatorColor = 8
*StructureColor = 9
*NumberColor = 10
*PointerColor = 11
*SeparatorColor = 12
*LabelColor = 13
*CustomKeywordColor = 14
*ModuleColor = 15
*BadEscapeColor = 16
; Setup the coloring (do it here, so it affects highlighting changes)
;
If *ActiveSource ; only if a source is loaded
SendEditorFontMessage(#STYLE_DEFAULT, EditorFontName$, EditorFontSize)
If EditorFontStyle & #PB_Font_Bold
SendEditorMessage(#SCI_STYLESETBOLD, #STYLE_DEFAULT, 1)
Else
SendEditorMessage(#SCI_STYLESETBOLD, #STYLE_DEFAULT, 0)
EndIf
If EditorFontStyle & #PB_Font_Italic
SendEditorMessage(#SCI_STYLESETITALIC, #STYLE_DEFAULT, 1)
Else
SendEditorMessage(#SCI_STYLESETITALIC, #STYLE_DEFAULT, 0)
EndIf
If EnableColoring
SendEditorMessage(#SCI_STYLESETBACK, #STYLE_DEFAULT, Colors(#COLOR_GlobalBackground)\DisplayValue)
SendEditorMessage(#SCI_STYLECLEARALL, 0, 0) ; to make the background & font change effective!
SendEditorMessage(#SCI_STYLESETFORE, 1, Colors(#COLOR_NormalText)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 2, Colors(#COLOR_BasicKeyword)\DisplayValue)
If EnableKeywordBolding
SendEditorFontMessage(2, EditorBoldFontName$, EditorFontSize)
SendEditorFontMessage(14, EditorBoldFontName$, EditorFontSize)
SendEditorMessage(#SCI_STYLESETBOLD, 2, 1) ; Bold (no effect on linux, but maybe on windows later)
SendEditorMessage(#SCI_STYLESETBOLD, 14, 1)
If EditorFontStyle & #PB_Font_Italic
SendEditorMessage(#SCI_STYLESETITALIC, 2, 1)
SendEditorMessage(#SCI_STYLESETITALIC, 14, 1)
EndIf
EndIf
SendEditorMessage(#SCI_STYLESETFORE, 3, Colors(#COLOR_Comment)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 4, Colors(#COLOR_Constant)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 5, Colors(#COLOR_String)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 6, Colors(#COLOR_PureKeyword)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 7, Colors(#COLOR_ASMKeyword)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 8, Colors(#COLOR_Operator)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 9, Colors(#COLOR_Structure)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 10, Colors(#COLOR_Number)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 11, Colors(#COLOR_Pointer)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 12, Colors(#COLOR_Separator)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 13, Colors(#COLOR_Label)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 14, Colors(#COLOR_CustomKeyword)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 15, Colors(#COLOR_Module)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, 16, Colors(#COLOR_BadBrace)\DisplayValue)
SendEditorMessage(#SCI_STYLESETBACK, #STYLE_BRACELIGHT, Colors(#COLOR_CurrentLine)\DisplayValue)
SendEditorMessage(#SCI_STYLESETBACK, #STYLE_BRACEBAD , Colors(#COLOR_CurrentLine)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, #STYLE_BRACELIGHT, Colors(#COLOR_GoodBrace)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, #STYLE_BRACEBAD, Colors(#COLOR_BadBrace)\DisplayValue)
SendEditorMessage(#SCI_STYLESETBOLD, #STYLE_BRACELIGHT, 1)
SendEditorMessage(#SCI_STYLESETBOLD, #STYLE_BRACEBAD, 1)
SendEditorMessage(#SCI_SETCARETLINEBACK, Colors(#COLOR_CurrentLine)\DisplayValue, 0)
SendEditorMessage(#SCI_SETCARETFORE, Colors(#COLOR_Cursor)\DisplayValue, 0)
SendEditorMessage(#SCI_STYLESETFORE, #STYLE_INDENTGUIDE, Colors(#COLOR_Whitespace)\DisplayValue)
SendEditorMessage(#SCI_SETWHITESPACEFORE, #True, Colors(#COLOR_Whitespace)\DisplayValue)
CompilerIf #CompileWindows
If Colors(#COLOR_Selection)\DisplayValue = -1 ; special accessibility scheme
SendEditorMessage(#SCI_SETSELBACK, 1, GetSysColor_(#COLOR_HIGHLIGHT))
Else
SendEditorMessage(#SCI_SETSELBACK, 1, Colors(#COLOR_Selection)\DisplayValue)
EndIf
If Colors(#COLOR_SelectionFront)\DisplayValue = -1
SendEditorMessage(#SCI_SETSELFORE, 1, GetSysColor_(#COLOR_HIGHLIGHTTEXT))
Else
SendEditorMessage(#SCI_SETSELFORE, 1, Colors(#COLOR_SelectionFront)\DisplayValue)
EndIf
CompilerElse
SendEditorMessage(#SCI_SETSELBACK, 1, Colors(#COLOR_Selection)\DisplayValue)
SendEditorMessage(#SCI_SETSELFORE, 1, Colors(#COLOR_SelectionFront)\DisplayValue)
CompilerEndIf
SendEditorMessage(#SCI_INDICSETFORE, #INDICATOR_KeywordMatch, Colors(#COLOR_GoodBrace)\DisplayValue)
SendEditorMessage(#SCI_INDICSETFORE, #INDICATOR_KeywordMismatch, Colors(#COLOR_BadBrace)\DisplayValue)
SendEditorMessage(#SCI_INDICSETFORE, #INDICATOR_SelectionRepeat, Colors(#COLOR_SelectionRepeat)\DisplayValue)
; Set the line margin and symbol margin style
;
SendEditorMessage(#SCI_STYLESETBACK, #STYLE_LINENUMBER, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_STYLESETFORE, #STYLE_LINENUMBER, Colors(#COLOR_LineNumber)\DisplayValue)
SendEditorMessage(#SCI_SETFOLDMARGINCOLOUR, 1, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_SETFOLDMARGINHICOLOUR, 1, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_Marker, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_CurrentLineSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_WarningSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_ErrorSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_BreakpointSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Marker, Colors(#COLOR_Marker)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_CurrentLine, Colors(#COLOR_DebuggerLine)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_CurrentLineSymbol, Colors(#COLOR_DebuggerLineSymbol)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Warning, Colors(#COLOR_DebuggerWarning)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_WarningSymbol, Colors(#COLOR_DebuggerWarningSymbol)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Error, Colors(#COLOR_DebuggerError)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_ErrorSymbol, Colors(#COLOR_DebuggerErrorSymbol)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Breakpoint, Colors(#COLOR_DebuggerBreakpoint)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_BreakpointSymbol, Colors(#COLOR_DebuggerBreakpointSymbol)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_ProcedureBack, Colors(#COLOR_ProcedureBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPEN, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEREND, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPENMID, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_FoldVLine, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_FoldVCorner, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_FoldTCorner, Colors(#COLOR_LineNumberBack)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPEN, Colors(#COLOR_LineNumber)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDER, Colors(#COLOR_LineNumber)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEREND, Colors(#COLOR_LineNumber)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPENMID, Colors(#COLOR_LineNumber)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_FoldVLine, Colors(#COLOR_LineNumber)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_FoldVCorner, Colors(#COLOR_LineNumber)\DisplayValue)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_FoldTCorner, Colors(#COLOR_LineNumber)\DisplayValue)
If Colors(#COLOR_ProcedureBack)\Enabled = 0 Or Colors(#COLOR_ProcedureBack)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_ProcedureBack, #SC_MARK_EMPTY)
Else
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_ProcedureBack, #SC_MARK_BACKGROUND)
EndIf
If Colors(#COLOR_CurrentLine)\Enabled = 0 Or Colors(#COLOR_CurrentLine)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
SendEditorMessage(#SCI_SETCARETLINEVISIBLE, 0, 0) ; disable the different color for the current line
Else
SendEditorMessage(#SCI_SETCARETLINEVISIBLE, 1, 0) ; enable the different color for the current line
EndIf
; these are defined to "empty" when not used...
If Colors(#COLOR_DebuggerLine)\Enabled = 0 Or Colors(#COLOR_DebuggerLine)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_CurrentLine, #SC_MARK_EMPTY)
Else
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_CurrentLine, #SC_MARK_BACKGROUND)
EndIf
If Colors(#COLOR_DebuggerWarning)\Enabled = 0 Or Colors(#COLOR_DebuggerWarning)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Error, #SC_MARK_EMPTY)
Else
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Error, #SC_MARK_BACKGROUND)
EndIf
If Colors(#COLOR_DebuggerError)\Enabled = 0 Or Colors(#COLOR_DebuggerError)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Error, #SC_MARK_EMPTY)
Else
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Error, #SC_MARK_BACKGROUND)
EndIf
If Colors(#COLOR_DebuggerBreakpoint)\Enabled = 0 Or Colors(#COLOR_DebuggerBreakpoint)\DisplayValue = Colors(#COLOR_GlobalBackground)\DisplayValue
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Breakpoint, #SC_MARK_EMPTY)
Else
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Breakpoint, #SC_MARK_BACKGROUND)
EndIf
; setup markers and styles for issues
ForEach Issues()
If Issues()\Style <> -1
SendEditorMessage(#SCI_STYLESETFORE, Issues()\Style , Colors(#COLOR_Comment)\DisplayValue)
SendEditorMessage(#SCI_STYLESETBACK, Issues()\Style , Issues()\Color)
EndIf
If Issues()\Marker <> -1
SendEditorMessage(#SCI_MARKERDEFINE, Issues()\Marker, #SC_MARK_BACKGROUND)
SendEditorMessage(#SCI_MARKERSETBACK, Issues()\Marker, Issues()\Color)
EndIf
Next Issues()
Else ; Coloring Disabled
SendEditorMessage(#SCI_STYLERESETDEFAULT, 0, 0)
SendEditorMessage(#SCI_STYLESETBACK, #STYLE_DEFAULT, $FFFFFF)
SendEditorMessage(#SCI_STYLESETFORE, #STYLE_DEFAULT, $000000)
SendEditorMessage(#SCI_STYLESETBACK, #STYLE_LINENUMBER, $FFFFFF)
SendEditorMessage(#SCI_STYLESETFORE, #STYLE_LINENUMBER, $000000)
SendEditorMessage(#SCI_SETWHITESPACEFORE, #True, $000000)
SendEditorMessage(#SCI_SETFOLDMARGINCOLOUR, 1, $FFFFFF)
SendEditorMessage(#SCI_SETFOLDMARGINHICOLOUR, 1, $FFFFFF)
SendEditorMessage(#SCI_INDICSETFORE, #INDICATOR_KeywordMatch, $000000)
SendEditorMessage(#SCI_INDICSETFORE, #INDICATOR_KeywordMismatch, $FFFFFF)
SendEditorMessage(#SCI_INDICSETFORE, #INDICATOR_SelectionRepeat, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_Marker, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_CurrentLineSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_WarningSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_ErrorSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_BreakpointSymbol, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Marker, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_CurrentLine, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_CurrentLineSymbol, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Error, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_ErrorSymbol, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Warning, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_WarningSymbol, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_Breakpoint, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_BreakpointSymbol, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPEN, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEREND, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPENMID, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_FoldVLine, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_FoldVCorner, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETFORE, #MARKER_FoldTCorner, $FFFFFF)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPEN, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDER, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEREND, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPENMID, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_FoldVLine, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_FoldVCorner, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_FoldTCorner, $000000)
SendEditorMessage(#SCI_MARKERSETBACK, #MARKER_ProcedureBack, $FFFFFF)
; these are defined to "empty" when not used...
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_CurrentLine, #SC_MARK_EMPTY)
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Error , #SC_MARK_EMPTY)
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Warning , #SC_MARK_EMPTY)
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_Breakpoint , #SC_MARK_EMPTY)
SendEditorMessage(#SCI_MARKERDEFINE, #MARKER_ProcedureBack, #SC_MARK_EMPTY)
SendEditorMessage(#SCI_SETCARETLINEBACK, $FFFFFF, 0)
SendEditorMessage(#SCI_SETCARETFORE, $000000, 0)
CompilerIf #CompileWindows
SendEditorMessage(#SCI_SETSELBACK, 1, GetSysColor_(#COLOR_HIGHLIGHT))
SendEditorMessage(#SCI_SETSELFORE, 1, GetSysColor_(#COLOR_HIGHLIGHTTEXT))
CompilerElse
SendEditorMessage(#SCI_SETSELBACK, 1, $C0C0C0)
SendEditorMessage(#SCI_SETSELFORE, 1, $000000)
CompilerEndIf
SendEditorMessage(#SCI_SETCARETLINEVISIBLE, 0, 0) ; disable the different color for the current line
; disable issue markers
; no need to do anything for the issue styles, as they will have the default colors
ForEach Issues()
If Issues()\Marker <> -1
SendEditorMessage(#SCI_MARKERDEFINE, Issues()\Marker, #SC_MARK_EMPTY)
EndIf
Next Issues()
EndIf
If EnableLineNumbers
HideLineNumbers(*ActiveSource, 0)
Else
HideLineNumbers(*ActiveSource, 1)
EndIf
; Do not hide the margin as it is used for breakpoint, error etc symbols too
; Instead just clear any old Markers/Folding marks if they were turned off
;
SendEditorMessage(#SCI_SETMARGINWIDTHN, 1, 15)
If EnableFolding = 0
lines = SendEditorMessage(#SCI_GETLINECOUNT)
For i = 0 To lines-1
SendEditorMessage(#SCI_SETFOLDLEVEL, i, #SC_FOLDLEVELBASE)
Next i
SendEditorMessage(#SCI_SHOWLINES, 0, lines-1)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDEROPEN)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDER)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDEREND)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDEROPENMID)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDERSUB)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDERTAIL)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDERMIDTAIL)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_FoldVLine)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_FoldVCorner)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_FoldTCorner)
EndIf
If EnableMarkers = 0
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_Marker)
EndIf
SendEditorMessage(#SCI_SETTABWIDTH, TabLength, 0)
SendEditorMessage(#SCI_SETUSETABS, RealTab, 0)
If ShowWhiteSpace
SendEditorMessage(#SCI_SETVIEWWS, #SCWS_VISIBLEALWAYS)
Else
SendEditorMessage(#SCI_SETVIEWWS, #SCWS_INVISIBLE)
EndIf
If ShowIndentGuides
SendEditorMessage(#SCI_SETINDENTATIONGUIDES, #SC_IV_LOOKBOTH)
Else
SendEditorMessage(#SCI_SETINDENTATIONGUIDES, #SC_IV_NONE)
EndIf
EndIf
EndProcedure
; Need to share the start of the buffer to get the position correctly
;
Global *HighlightBuffer, HighlightOffset, HighlightGadget, NoUserChange
Procedure HighlightCallback(*StringStart.Ascii, Length, *Color, IsBold, TextChanged)
; replace the text only if it was changed by the highlighting engine (case correction)
;
If TextChanged
; Very strange: If the last line es empty and the previous has a keyword (case correction) at the end
; usually, the newline will be replaced with the word. This however makes scintilla act like crazy when
; scrolling to the last line. So we actually only replace the word itself, not any spaces/newline behind it
; this appearently fixes this :|
;
ChangeLength = Length
While ChangeLength > 1 And ValidCharacters(PeekA(*StringStart+ChangeLength-1)) = 0
ChangeLength-1
Wend
;
; note that this change appears in the undo buffer, but this can't be changed, because if you
; disable the undo buffer, you also clear it !
;
ScintillaSendMessage(HighlightGadget, #SCI_SETTARGETSTART, *StringStart-*HighlightBuffer+HighlightOffset, 0)
ScintillaSendMessage(HighlightGadget, #SCI_SETTARGETEND, *StringStart-*HighlightBuffer+HighlightOffset+ChangeLength, 0)
ScintillaSendMessage(HighlightGadget, #SCI_REPLACETARGET, ChangeLength, *StringStart)
EndIf
; Only the good color style is used (faster according to the docs)
;
If EnableColoring
ScintillaSendMessage(HighlightGadget, #SCI_SETSTYLING, Length, *Color)
EndIf
EndProcedure
Procedure HighlightArea(*StartPos, *EndPos)
;
; highlighting is done only on demand (see ScintillaCallback)
;
EndProcedure
Procedure UpdateIsCodeStatus()
If *ActiveSource\IsCode
; re-scan everything
FullSourceScan(*ActiveSource) ; re-scan autocomplete + procedurebrowser
SortParserData(*ActiveSource\Parser, *ActiveSource) ; update sorted data in case its not the active source
UpdateFolding(*ActiveSource, 0, -1) ; redo all folding
Else
; free any parser data
FreeSourceItemArray(@*ActiveSource\Parser)
; reset any folding
highestline = SendEditorMessage(#SCI_GETLINECOUNT) - 1
For i = 0 To highestline
SendEditorMessage(#SCI_ENSUREVISIBLE, i)
Next i
For i = 0 To highestline
SendEditorMessage(#SCI_SETFOLDLEVEL, i, #SC_FOLDLEVELBASE)
Next i
; clear code-related markers
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_CurrentLine)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_CurrentLineSymbol)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_Error)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_ErrorSymbol)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_Warning)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_WarningSymbol)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_Breakpoint)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_BreakpointSymbol)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDEROPEN)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDER)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDEREND)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDEROPENMID)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDERSUB)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDERTAIL)
SendEditorMessage(#SCI_MARKERDELETEALL, #SC_MARKNUM_FOLDERMIDTAIL)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_FoldVLine)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_FoldVCorner)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_FoldTCorner)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_ProcedureStart)
SendEditorMessage(#SCI_MARKERDELETEALL, #MARKER_ProcedureBack)
For i = #MARKER_FirstIssue To #MARKER_LastIssue
SendEditorMessage(#SCI_MARKERDELETEALL, i)
Next i
; clear indicators
SendEditorMessage(#SCI_SETINDICATORCURRENT, #INDICATOR_KeywordMatch)
SendEditorMessage(#SCI_INDICATORCLEARRANGE, 0, SendEditorMessage(#SCI_GETTEXTLENGTH))
SendEditorMessage(#SCI_SETINDICATORCURRENT, #INDICATOR_KeywordMismatch)
SendEditorMessage(#SCI_INDICATORCLEARRANGE, 0, SendEditorMessage(#SCI_GETTEXTLENGTH))
EndIf
SetBackgroundColor()
UpdateHighlighting()
UpdateProcedureList() ; update list for current source
UpdateVariableViewer()
UpdateMenuStates()
SetDebuggerMenuStates()
EndProcedure
Procedure UpdateHighlighting() ; highlight everything after a prefs update
If EnableColoring Or EnableCaseCorrection
If *ActiveSource\IsCode
; Seems to be a scintilla bug: when we update the highlighting (for example set EnableASM mode)
; and the update modifies the text content (for example case-sensitivity) inside
; a folded procedure, we get a mixup and a crash (at a later point)
; I think this is a scintilla issue.
;
; So we unfold all foldpoints, do the update, fold again
;
; store and undo folding info
FoldingInfo$ = CreateFoldingInformation()
count = GetLinesCount(*ActiveSource)
For i = 0 To count-1
If IsFoldPoint(i)
SetFoldState(i, 1)
EndIf
Next i
anchorPos = SendEditorMessage(#SCI_GETANCHOR, 0, 0) ; save & restore the cursor pos
currentPos = SendEditorMessage(#SCI_GETCURRENTPOS, 0, 0)
InBufferLength = SendEditorMessage(#SCI_GETTEXTLENGTH, 0, 0)
*InBuffer = AllocateMemory(InBufferLength+1)
*HighlightBuffer = *InBuffer
HighlightOffset = 0
HighlightGadget = *ActiveSource\EditorGadget
SendEditorMessage(#SCI_GETTEXT, InBufferLength, *InBuffer)
SendEditorMessage(#SCI_SETUNDOCOLLECTION, #False, 0)
If EnableColoring
SendEditorMessage(#SCI_STARTSTYLING, 0, $FFFFFF) ; also overwrites the brace highlights
EndIf
; now call the highlighting engine
;
Modified = GetSourceModified() ; because the case correction changes the modified state!
HighlightingEngine(*InBuffer, InBufferLength, SendEditorMessage(#SCI_GETCURRENTPOS, 0, 0), @HighlightCallback(), 1)
SetSourceModified(Modified)
FreeMemory(*InBuffer)
SendEditorMessage(#SCI_SETUNDOCOLLECTION, #True, 0)
SendEditorMessage(#SCI_SETANCHOR, anchorPos, 0)
SendEditorMessage(#SCI_SETCURRENTPOS, currentPos, 0)
ApplyFoldingInformation(FoldingInfo$)
ElseIf EnableColoring
; non-pb files
InBufferLength = SendEditorMessage(#SCI_GETTEXTLENGTH, 0, 0)
SendEditorMessage(#SCI_STARTSTYLING, 0, $FFFFFF) ; also overwrites the brace highlights
SendEditorMessage(#SCI_SETSTYLING, InBufferLength, *NormalTextColor)
EndIf
EndIf
EndProcedure
; Updates the folding states only, starting at the given line until at least
; lastline. The update will go further as long as the folding level changes,
; but it will stop at lastline when no changes are made.
; (this way it is faster while still doing a correct update)
;
; Also updates procedure background and issue markers in the
; indicated line range
;
Procedure UpdateFolding(*Source.SourceFile, firstline, lastline)
If *Source\IsCode = 0
ProcedureReturn
EndIf
Gadget = *Source\EditorGadget
*Array.ParsedLines = *Source\Parser\SourceItemArray
highestline = ScintillaSendMessage(Gadget, #SCI_GETLINECOUNT) - 1
If *Source\Parser\SourceItemCount < highestline+1
highestline = *Source\Parser\SourceItemCount - 1
EndIf
If firstline < 0 ; could happen when re-highlighting the first line
firstline = 0
EndIf
If lastline < 0 Or lastline > highestline
lastline = highestline
EndIf
If EnableFolding And *Array
If firstline = 0
FoldLevel = #SC_FOLDLEVELBASE
Else
FoldLevel = ScintillaSendMessage(Gadget, #SCI_GETFOLDLEVEL, firstline, 0) & (~#SC_FOLDLEVELHEADERFLAG)
EndIf
; We need to find outwether line is inside a macro for proper handling
; of the foldpoints from here on
; We also need to know if we are inside a procedure for the
; adding the "Procedure Background color" markers
;
If firstline = 0
InsideMacro = 0
InsideProcedure = 0
Else
InsideMacro = 0
InsideProcedure = 0
ProcedureFound = 0 ; once we found that we are inside a procedure, there may be no more checks or it gets overwritten
; Note: In each line, we search left to right (because of the linkedlist),
; but we look at the lines backwards. So to know if there is a Procedure/Macro
; we count the open/close when we find a line with more "open" than "close",
; we are inside it.
;
For i = firstline-1 To 0 Step -1
*Item.SourceItem = *Array\Line[i]\First
While *Item
Select *Item\Type
Case #ITEM_Macro : InsideMacro + 1
Case #ITEM_MacroEnd : InsideMacro - 1
Case #ITEM_Procedure : If ProcedureFound = 0: InsideProcedure + 1: EndIf
Case #ITEM_ProcedureEnd: If ProcedureFound = 0: InsideProcedure - 1: EndIf
EndSelect
*Item = *Item\Next
Wend
If InsideMacro > 0 ; more 'Macro' on the line than 'EndMacro
InsideMacro = 1
InsideProcedure = 0 ; inside a macro we ignore this
Break
ElseIf ProcedureFound = 0 And InsideProcedure > 0 ; more 'Procedure' than 'EndProcedure'
InsideProcedure = 1
ProcedureFound = 1 ; do not abort here as we must check for a macro as well
EndIf
Next i
EndIf
NeedRefresh = 0
For line = firstline To highestline
*Item.SourceItem = *Array\Line[line]\First
CurrentLineLevel = FoldLevel
FoldFlag = 0
MarkProcedure = InsideProcedure
IssueMarker = -1
IssuePriority = 5
While *Item
If InsideMacro = 0
If *Item\Type = #ITEM_FoldStart
FoldFlag = #SC_FOLDLEVELHEADERFLAG
FoldLevel + 1
ElseIf *Item\Type = #ITEM_FoldEnd
FoldLevel - 1
If FoldLevel < #SC_FOLDLEVELBASE
FoldLevel = #SC_FOLDLEVELBASE
EndIf
ElseIf *Item\Type = #ITEM_Procedure
InsideProcedure = 1
MarkProcedure = 1
ElseIf *Item\Type = #ITEM_ProcedureEnd
InsideProcedure = 0
; even when the procedure ends here, still mark the line
EndIf
EndIf
If *Item\Type = #ITEM_Macro
InsideMacro = 1
ElseIf *Item\Type = #ITEM_MacroEnd
InsideMacro = 0
; Special fix when "EndMacro" is a folding keyword. As the #ITEM_FoldEnd
; comes before the EndMacro, it is ignored. So use the EndMacro as the
; trigger in this case then.
;
If IsMacroFolding
FoldLevel - 1
If FoldLevel < #SC_FOLDLEVELBASE
FoldLevel = #SC_FOLDLEVELBASE
EndIf
EndIf
ElseIf *Item\Type = #ITEM_Issue And SelectElement(Issues(), *Item\Issue)
If Issues()\Marker <> -1
If IssueMarker = -1 Or Issues()\Priority < IssuePriority
; if multiple markers, the first or the one with higher priority wins
IssueMarker = Issues()\Marker
IssuePriority = Issues()\Priority
EndIf
EndIf
EndIf
*Item = *Item\Next
Wend
; the fold level changes only affect the following lines, not the current one
ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, line, CurrentLineLevel|FoldFlag)
; to update our own folding markers, which have a lower priority than the default ones,
; which puts them below all other markers
Markers = ScintillaSendMessage(Gadget, #SCI_MARKERGET, line, 0)
; Issue markers
For i = #MARKER_FirstIssue To #MARKER_LastIssue
If i = IssueMarker
If Markers & (1<<i) = 0
ScintillaSendMessage(Gadget, #SCI_MARKERADD, line, i)
NeedRefresh = 1
EndIf
ElseIf Markers & (1<<i)
ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, i)
NeedRefresh = 1
EndIf
Next i
; Procedure background marker
If MarkProcedureBackground And MarkProcedure
If Markers & (1<<#MARKER_ProcedureBack) = 0
ScintillaSendMessage(Gadget, #SCI_MARKERADD, line, #MARKER_ProcedureBack)
NeedRefresh = 1
EndIf
ElseIf Markers & (1<<#MARKER_ProcedureBack)
ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_ProcedureBack)
NeedRefresh = 1
EndIf
; Note: the 'Header' marker has the level of its previous state (ie: 'Procedure a()' line will have level 0)
;
If FoldFlag = 0
If CurrentLineLevel = #SC_FOLDLEVELBASE
; Here we add or remove the marker only when necessary, which save a lot of time on nearly identical file
;
If Markers & (1 << #MARKER_FoldVLine) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVLine) : EndIf
If Markers & (1 << #MARKER_FoldVCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVCorner) : EndIf
If Markers & (1 << #MARKER_FoldTCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldTCorner) : EndIf
ElseIf FoldLevel < CurrentLineLevel
If FoldLevel = #SC_FOLDLEVELBASE
If Markers & (1 << #MARKER_FoldVLine) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVLine) : EndIf
If Markers & (1 << #MARKER_FoldVCorner) = 0 : ScintillaSendMessage(Gadget, #SCI_MARKERADD, line, #MARKER_FoldVCorner) : EndIf
If Markers & (1 << #MARKER_FoldTCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldTCorner) : EndIf
Else
If Markers & (1 << #MARKER_FoldVLine) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVLine) : EndIf
If Markers & (1 << #MARKER_FoldVCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVCorner) : EndIf
If Markers & (1 << #MARKER_FoldTCorner) = 0 : ScintillaSendMessage(Gadget, #SCI_MARKERADD, line, #MARKER_FoldTCorner) : EndIf
EndIf
ElseIf FoldLevel = CurrentLineLevel
If Markers & (1 << #MARKER_FoldVLine) = 0 : ScintillaSendMessage(Gadget, #SCI_MARKERADD, line, #MARKER_FoldVLine) : EndIf
If Markers & (1 << #MARKER_FoldVCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVCorner) : EndIf
If Markers & (1 << #MARKER_FoldTCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldTCorner) : EndIf
Else ; No need to test, it's the last case: LastFoldLevel > FoldLevel
If Markers & (1 << #MARKER_FoldVLine) = 0 : ScintillaSendMessage(Gadget, #SCI_MARKERADD, line, #MARKER_FoldVLine) : EndIf
If Markers & (1 << #MARKER_FoldVCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVCorner) : EndIf
If Markers & (1 << #MARKER_FoldTCorner) : ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldTCorner) : EndIf
EndIf
Else
; Here the mask doesn't work, so don't use it and make sure all the markers are removed
;
If CurrentLineLevel = FoldLevel And CurrentLineLevel > #SC_FOLDLEVELBASE
; Special case: Fold start mark with no content inside of another fold. Add a normal | line
ScintillaSendMessage(Gadget, #SCI_MARKERADD, line, #MARKER_FoldVLine)
Else
ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVLine)
EndIf
ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldVCorner)
ScintillaSendMessage(Gadget, #SCI_MARKERDELETE, line, #MARKER_FoldTCorner)
EndIf
; When removing a fold mark of a folded line, all sublines are no longer viewable.
; To prevent this on folding updates, this command checks the folding structure
; and shows such lines.
;
; only check if the line is currently hidden
If ScintillaSendMessage(Gadget, #SCI_GETLINEVISIBLE, line, 0) = 0
; If there is no parent, we must show the line
; If the parent is visible and unfolded, we must show it as well
;
parentline = ScintillaSendMessage(Gadget, #SCI_GETFOLDPARENT, line, 0)
If parentline = -1 Or (ScintillaSendMessage(Gadget, #SCI_GETLINEVISIBLE, parentline, 0) And ScintillaSendMessage(Gadget, #SCI_GETFOLDEXPANDED, parentline, 0))
ScintillaSendMessage(Gadget, #SCI_SHOWLINES, line, line)
EndIf
EndIf
; If we passed the 'lastline', and the folding level does not change anymore,
; we can stop the update as the following lines should not change anymore as well
; this gains a lot of speed on large sources
;
; Note that we have to check the level of the next line as 'FoldLevel' always affects the following line!
; Note: just checking until we reach the base level is not enough, as there may be further change required
If line > lastline+1 And ScintillaSendMessage(Gadget, #SCI_GETFOLDLEVEL, line+1, 0) & (~#SC_FOLDLEVELHEADERFLAG) = FoldLevel
Break
EndIf
Next line
; there seems to be a refresh bug here sometimes, so force it
If NeedRefresh
RedrawGadget(Gadget)
EndIf
EndIf
EndProcedure
Procedure StreamTextIn(*Buffer, Length)