forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeview.cpp
4008 lines (3468 loc) · 127 KB
/
codeview.cpp
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
#include "stdafx.h"
#include "scilexer.h"
#include <initguid.h>
#include <DbgProp.h>
//#include <Windowsx.h>
// The GUID used to identify the coclass of the VB Script engine
// {B54F3741-5B07-11cf-A4B0-00AA004A55E8}
#define szCLSID_VBScript "{B54F3741-5B07-11cf-A4B0-00AA004A55E8}"
DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4, 0xb0, 0x0, 0xaa, 0x0, 0x4a, 0x55, 0xe8);
//DEFINE_GUID(IID_IActiveScriptParse32, 0xbb1a2ae2, 0xa4f9, 0x11cf, 0x8f, 0x20, 0x0, 0x80, 0x5f, 0x2c, 0xd0, 0x64);
//DEFINE_GUID(IID_IActiveScriptParse64,0xc7ef7658,0xe1ee,0x480e,0x97,0xea,0xd5,0x2c,0xb4,0xd7,0x6d,0x17);
//DEFINE_GUID(IID_IActiveScriptDebug, 0x51973C10, 0xCB0C, 0x11d0, 0xB5, 0xC9, 0x00, 0xA0, 0x24, 0x4A, 0x0E, 0x7A);
//#define RECOLOR_LINE WM_USER+100
#define CONTEXTCOOKIE_NORMAL 1000
#define CONTEXTCOOKIE_DEBUG 1001
static constexpr int LAST_ERROR_WIDGET_HEIGHT = 256;
static UINT g_FindMsgString; // Windows message for the FindText dialog
//Scintillia Lexer parses only lower case unless otherwise told
static constexpr char vbsReservedWords[] =
"and as byref byval case call const "
"continue dim do each else elseif end error exit false for function global "
"goto if in loop me new next not nothing on optional or private public "
"redim rem resume select set sub then to true type while with "
"boolean byte currency date double integer long object single string type "
"variant option explicit randomize";
static const string VBvalidChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"s);
static char CaretTextBuff[MAX_FIND_LENGTH];
static char ConstructTextBuff[MAX_FIND_LENGTH];
INT_PTR CALLBACK CVPrefProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
IScriptable::IScriptable()
{
m_wzName[0] = '\0';
}
int CodeViewDispatch::SortAgainstValue(const wstring& pv) const
{
char szName1[MAXSTRING];
WideCharToMultiByteNull(CP_ACP, 0, pv.c_str(), -1, szName1, MAXSTRING, nullptr, nullptr);
CharLowerBuff(szName1, lstrlen(szName1));
char szName2[MAXSTRING];
WideCharToMultiByteNull(CP_ACP, 0, m_wName.c_str(), -1, szName2, MAXSTRING, nullptr, nullptr);
CharLowerBuff(szName2, lstrlen(szName2));
return lstrcmp(szName1, szName2); //WideStrCmp((WCHAR *)pv, m_wzName);
}
void CodeViewer::Init(IScriptableHost *psh)
{
CComObject<DebuggerModule>::CreateInstance(&m_pdm);
m_pdm->AddRef();
m_pdm->Init(this);
m_psh = psh;
m_hwndMain = nullptr;
m_hwndFind = nullptr;
m_hwndStatus = nullptr;
szFindString[0] = '\0';
szReplaceString[0] = '\0';
g_FindMsgString = RegisterWindowMessage(FINDMSGSTRING);
m_pScript = nullptr;
m_visible = false;
m_minimized = false;
const HRESULT res = InitializeScriptEngine();
if (res != S_OK)
{
char bla[128];
sprintf_s(bla, sizeof(bla), "Cannot initialize Script Engine 0x%X", res);
ShowError(bla);
}
m_sdsDirty = eSaveClean;
m_ignoreDirty = false;
m_findreplaceold.lStructSize = 0; // So we know nothing has been searched for yet
m_errorLineNumber = -1;
m_scriptError = false;
}
CodeViewer::~CodeViewer()
{
if (g_pvp && g_pvp->m_pcv == this)
g_pvp->m_pcv = nullptr;
Destroy();
for (size_t i = 0; i < m_vcvd.size(); ++i)
delete m_vcvd[i];
if (m_haccel)
DestroyAcceleratorTable(m_haccel);
m_pdm->Release();
}
//
// UTF-8 conversions/validations:
//
// old ANSI to UTF-8
// allocates new mem block
static char* iso8859_1_to_utf8(const char* str, const size_t length)
{
char* const utf8 = new char[1 + 2*length]; // worst case
char* c = utf8;
for (size_t i = 0; i < length; ++i, ++str)
{
if (*str & 0x80)
{
*c++ = 0xc0 | (char)((unsigned char)*str >> 6);
*c++ = 0x80 | (*str & 0x3f);
}
//else // check for bogus ASCII control characters
//if (*str < 9 || (*str > 10 && *str < 13) || (*str > 13 && *str < 32))
// *c++ = ' ';
else
*c++ = *str;
}
*c++ = '\0';
return utf8;
}
// Copyright (c) 2008-2009 Bjoern Hoehrmann <[email protected]>
// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
#define UTF8_ACCEPT 0
#define UTF8_REJECT 1
static constexpr uint8_t utf8d[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00..1f
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20..3f
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40..5f
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60..7f
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, // 80..9f
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, // a0..bf
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // c0..df
0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, // e0..ef
0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, // f0..ff
0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, // s0..s0
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, // s1..s2
1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, // s3..s4
1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, // s5..s6
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
};
static uint32_t decode(uint32_t* const state, uint32_t* const codep, const uint32_t byte)
{
const uint32_t type = utf8d[byte];
*codep = (*state != UTF8_ACCEPT) ?
(byte & 0x3fu) | (*codep << 6) :
(0xff >> type) & (byte);
*state = utf8d[256 + *state*16 + type];
return *state;
}
static uint32_t validate_utf8(uint32_t *const state, const char * const str, const size_t length)
{
for (size_t i = 0; i < length; i++)
{
const uint32_t type = utf8d[(uint8_t)str[i]];
*state = utf8d[256 + (*state) * 16 + type];
if (*state == UTF8_REJECT)
return UTF8_REJECT;
}
return *state;
}
//
//
//
// strSearchData has to be lower case
template<bool uniqueKey> // otherwise keyName
static int UDKeyIndexHelper(const fi_vector<UserData>& ListIn, const string& strSearchData, int& curPosOut)
{
const int ListSize = (int)ListIn.size();
curPosOut = 1u << 30;
while (!(curPosOut & ListSize) && (curPosOut > 1))
curPosOut >>= 1;
int iJumpDelta = curPosOut >> 1;
--curPosOut; //Zero Base
while (true)
{
const int result = (curPosOut >= ListSize) ? -1 : strSearchData.compare(uniqueKey ? ListIn[curPosOut].m_uniqueKey : lowerCase(ListIn[curPosOut].m_keyName));
if (iJumpDelta == 0 || result == 0) return result;
curPosOut = (result < 0) ? (curPosOut - iJumpDelta) : (curPosOut + iJumpDelta);
iJumpDelta >>= 1;
}
}
//true: Returns current Index of strIn in ListIn based on m_uniqueKey, or -1 if not found
//false: Returns current Index of strIn in ListIn based on m_keyName, or -1 if not found
template <bool uniqueKey> // otherwise keyName
static int UDKeyIndex(const fi_vector<UserData>& ListIn, const string& strIn)
{
if (strIn.empty() || ListIn.empty()) return -1;
int iCurPos;
const int result = UDKeyIndexHelper<uniqueKey>(ListIn, lowerCase(strIn), iCurPos);
///TODO: needs to consider children?
return (result == 0) ? iCurPos : -1;
}
/* FindUD - Now a human Search!
0 =Found set to point at UD in list.
-1 =Not Found
1 =Not Found
-2 =Zero Length string or error
strSearchData has to be lower case */
static int FindUD(const fi_vector<UserData>& ListIn, const string& strSearchData, int& Pos)
{
if (strSearchData.empty() || ListIn.empty()) return -2;
Pos = -1;
const int KeyResult = UDKeyIndexHelper<true>(ListIn, strSearchData, Pos);
//If it's a top level construct it will have no parents and therefore have a unique key.
if (KeyResult == 0) return 0;
//Now see if it's in the Name list
//Jumpdelta should be initialized to the maximum count of an individual key name
//But for the moment the biggest is 64 x's in AMH
Pos += KeyResult; //Start very close to the result of key search
if (Pos < 0) Pos = 0;
//Find the start of other instances of strSearchData by crawling up list
//Usually (but not always) UDKeyIndexHelper<true> returns top of the list so its fast
const size_t SearchWidth = strSearchData.size();
do
{
--Pos;
} while (Pos >= 0 && strSearchData.compare(ListIn[Pos].m_uniqueKey.substr(0, SearchWidth)) == 0);
++Pos;
// now walk down list of Keynames looking for what we want.
int result;
do
{
result = strSearchData.compare(lowerCase(ListIn[Pos].m_keyName));
if (result == 0) break; //Found
++Pos;
if (Pos == (int)ListIn.size()) break;
result = strSearchData.compare(lowerCase(ListIn[Pos].m_keyName).substr(0, SearchWidth));
} while (result == 0); //EO SubList
return result;
}
static bool warn_on_dupes = false;
//Assumes case insensitive sorted list
//Returns index or insertion point (-1 == error)
static size_t FindOrInsertUD(fi_vector<UserData>& ListIn, const UserData& udIn)
{
if (ListIn.empty()) // First in
{
ListIn.push_back(udIn);
return 0;
}
int Pos = 0;
const int KeyFound = udIn.m_uniqueKey.empty() ? -2 : UDKeyIndexHelper<true>(ListIn, udIn.m_uniqueKey, Pos);
if (KeyFound == 0)
{
//Same name, different parents?
const fi_vector<UserData>::const_iterator iterFound = ListIn.begin() + Pos;
const int ParentResult = udIn.m_uniqueParent.compare(iterFound->m_uniqueParent);
if (ParentResult == -1)
ListIn.insert(iterFound, udIn);
else if (ParentResult == 1)
{
ListIn.insert(iterFound+1, udIn);
++Pos;
}
else
{
// detect/warn about duplicate subs/functions (at least rudimentary)
if (g_pvp && g_pvp->m_pcv &&
warn_on_dupes &&
(udIn.eTyping == eSub || udIn.eTyping == eFunction) && // only check subs and functions
(iterFound->m_lineNum != udIn.m_lineNum)) // use this simple check as dupe test: are the keys on different lines?
{
const Sci_Position dwellpos = SendMessage(g_pvp->m_pcv->m_hwndScintilla, SCI_GETSELECTIONSTART, 0, 0);
SendMessage(g_pvp->m_pcv->m_hwndScintilla, SCI_CALLTIPSHOW, dwellpos,
(LPARAM)("Duplicate Definition found: " + iterFound->m_description + " (Line: " + std::to_string(iterFound->m_lineNum) + ")\n " + udIn.m_description + " (Line: " + std::to_string(udIn.m_lineNum) + ')').c_str());
warn_on_dupes = false;
}
// assign again, as e.g. line of func/sub/var could have been changed by other updates
ListIn[Pos] = udIn;
}
return Pos;
}
if (KeyFound == -1) //insert before, somewhere in the middle
{
ListIn.insert(ListIn.begin() + Pos, udIn);
return Pos;
}
else if (KeyFound == 1) //insert above last element - Special case
{
ListIn.insert(ListIn.begin() + (Pos+1), udIn);
return Pos+1;
}
else if ((ListIn.begin() + Pos) == (ListIn.end() - 1))
{ //insert at end
ListIn.push_back(udIn);
return ListIn.size() - 1; //Zero Base
}
return -1;
}
// Needs speeding up.
// can potentially return a static variable, i.e. use the pointer before the next call
static const UserData* GetUDfromUniqueKey(const fi_vector<UserData>& ListIn, const string& UniKey)
{
static UserData retUserData;
retUserData.eTyping = eUnknown;
const size_t ListSize = ListIn.size();
for (size_t i = 0; i < ListSize; ++i)
if (UniKey == ListIn[i].m_uniqueKey)
{
if (ListIn[i].eTyping != eUnknown)
return &ListIn[i];
retUserData = ListIn[i];
}
return &retUserData;
}
//TODO: Needs speeding up.
static size_t GetUDIdxfromUniqueKey(const fi_vector<UserData>& ListIn, const string& UniKey)
{
const size_t ListSize = ListIn.size();
for (size_t i = 0; i < ListSize; ++i)
if (UniKey == ListIn[i].m_uniqueKey)
return i;
return -1;
}
//Finds the closest UD from CurrentLine in ListIn
//On entry CurrentIdx must be set to the UD in the line
static int FindClosestUD(const fi_vector<UserData>& ListIn, const int CurrentLine, const int CurrentIdx)
{
const string strSearchData = lowerCase(ListIn[CurrentIdx].m_keyName);
const size_t SearchWidth = strSearchData.size();
//Find the start of other instances of strIn by crawling up list
int iNewPos = CurrentIdx;
do
{
--iNewPos;
} while (iNewPos >= 0 && strSearchData.compare(ListIn[iNewPos].m_uniqueKey.substr(0, SearchWidth)) == 0);
++iNewPos;
//Now at top of list
//find nearest definition above current line
//int ClosestLineNum = 0;
int ClosestPos = CurrentIdx;
int Delta = INT_MIN;
do
{
const int NewLineNum = ListIn[iNewPos].m_lineNum;
const int NewDelta = NewLineNum - CurrentLine;
if (NewDelta >= Delta && NewLineNum <= CurrentLine && lowerCase(ListIn[iNewPos].m_keyName).compare(strSearchData) == 0)
{
Delta = NewDelta;
//ClosestLineNum = NewLineNum;
ClosestPos = iNewPos;
}
++iNewPos;
} while (iNewPos != (int)ListIn.size() && strSearchData.compare(lowerCase(ListIn[iNewPos].m_keyName).substr(0, SearchWidth)) == 0);
//--iNewPos;
return ClosestPos;
}
// returns true if inserted, false if already in list
static bool FindOrInsertStringIntoAutolist(vector<string>& ListIn, const string &strIn)
{
//First in the list
if (ListIn.empty())
{
ListIn.push_back(strIn);
return true;
}
const unsigned int ListSize = (unsigned int)ListIn.size();
unsigned int iNewPos = 1u << 31;
while (!(iNewPos & ListSize) && (iNewPos > 1))
iNewPos >>= 1;
int iJumpDelta = iNewPos >> 1;
--iNewPos; //Zero Base
const string strSearchData = lowerCase(strIn);
unsigned int iCurPos;
int result;
while (true)
{
iCurPos = iNewPos;
result = (iCurPos >= ListSize) ? - 1 : strSearchData.compare(lowerCase(ListIn[iCurPos]));
if (result == 0) return false; // Already in list
if (iJumpDelta == 0) break;
iNewPos = (result < 0) ? (iCurPos - iJumpDelta) : (iCurPos + iJumpDelta);
iJumpDelta >>= 1;
}
const vector<string>::const_iterator i = ListIn.begin() + iCurPos;
if (result == -1) //insert before, somewhere in the middle
{
ListIn.insert(i, strIn);
return true;
}
if (i == (ListIn.end() - 1)) //insert above last element - Special case
{
ListIn.push_back(strIn);
return true;
}
if (result == 1)
{
ListIn.insert(i+1, strIn);
return true;
}
return false; //Oh pop poop, never should hit here.
}
//
//
//
static void GetRange(const HWND hwndScintilla, const size_t start, const size_t end, char * const text)
{
Sci_TextRange tr;
tr.chrg.cpMin = (Sci_PositionCR)start;
tr.chrg.cpMax = (Sci_PositionCR)end;
tr.lpstrText = text;
SendMessage(hwndScintilla, SCI_GETTEXTRANGE, 0, (LPARAM)&tr);
}
void CodeViewer::GetWordUnderCaret()
{
const LRESULT CurPos = SendMessage(m_hwndScintilla, SCI_GETCURRENTPOS, 0, 0 );
m_wordUnderCaret.chrg.cpMin = (Sci_PositionCR)SendMessage(m_hwndScintilla, SCI_WORDSTARTPOSITION, CurPos, TRUE);
m_wordUnderCaret.chrg.cpMax = (Sci_PositionCR)SendMessage(m_hwndScintilla, SCI_WORDENDPOSITION, CurPos, TRUE);
if ((m_wordUnderCaret.chrg.cpMax - m_wordUnderCaret.chrg.cpMin) > MAX_FIND_LENGTH) return;
SendMessage(m_hwndScintilla, SCI_GETTEXTRANGE, 0, (LPARAM)&m_wordUnderCaret);
}
void CodeViewer::SetClean(const SaveDirtyState sds)
{
if (sds == eSaveClean)
SendMessage(m_hwndScintilla, SCI_SETSAVEPOINT, 0, 0);
m_sdsDirty = sds;
m_psh->SetDirtyScript(sds);
}
void CodeViewer::EndSession()
{
CleanUpScriptEngine();
InitializeScriptEngine();
}
HRESULT CodeViewer::AddTemporaryItem(const BSTR bstr, IDispatch * const pdisp)
{
CodeViewDispatch * const pcvd = new CodeViewDispatch();
pcvd->m_wName = bstr;
pcvd->m_pdisp = pdisp;
pcvd->m_pdisp->QueryInterface(IID_IUnknown, (void **)&pcvd->m_punk);
pcvd->m_punk->Release();
pcvd->m_piscript = nullptr;
pcvd->m_global = false;
if (m_vcvd.GetSortedIndex(pcvd) != -1 || m_vcvdTemp.GetSortedIndex(pcvd) != -1)
{
delete pcvd;
return E_FAIL; //already exists
}
m_vcvdTemp.AddSortedString(pcvd);
constexpr int flags = SCRIPTITEM_ISSOURCE | SCRIPTITEM_ISVISIBLE;
/*const HRESULT hr =*/ m_pScript->AddNamedItem(bstr, flags);
m_pScript->SetScriptState(SCRIPTSTATE_CONNECTED);
return S_OK;
}
HRESULT CodeViewer::AddItem(IScriptable * const piscript, const bool global)
{
CodeViewDispatch * const pcvd = new CodeViewDispatch();
CComBSTR bstr;
piscript->get_Name(&bstr);
pcvd->m_wName = bstr;
pcvd->m_pdisp = piscript->GetDispatch();
pcvd->m_pdisp->QueryInterface(IID_IUnknown, (void **)&pcvd->m_punk);
pcvd->m_punk->Release();
pcvd->m_piscript = piscript;
pcvd->m_global = global;
if (m_vcvd.GetSortedIndex(pcvd) != -1)
{
delete pcvd;
return E_FAIL;
}
m_vcvd.AddSortedString(pcvd);
// Add item to dropdown
char szT[MAXNAMEBUFFER * 2]; // Names can only be 32 characters (plus terminator)
WideCharToMultiByteNull(CP_ACP, 0, pcvd->m_wName.c_str(), -1, szT, sizeof(szT), nullptr, nullptr);
const size_t index = SendMessage(m_hwndItemList, CB_ADDSTRING, 0, (size_t)szT);
SendMessage(m_hwndItemList, CB_SETITEMDATA, index, (size_t)piscript);
//AndyS - WIP insert new item into autocomplete list??
return S_OK;
}
void CodeViewer::RemoveItem(IScriptable * const piscript)
{
CComBSTR bstr;
piscript->get_Name(&bstr);
const int idx = m_vcvd.GetSortedIndex(bstr);
if (idx == -1)
return;
const CodeViewDispatch * const pcvd = m_vcvd[idx];
_ASSERTE(pcvd);
m_vcvd.RemoveElementAt(idx);
// Remove item from dropdown
char szT[MAXNAMEBUFFER*2]; // Names can only be 32 characters (plus terminator)
WideCharToMultiByteNull(CP_ACP, 0, bstr, -1, szT, MAXNAMEBUFFER*2, nullptr, nullptr);
const size_t index = ::SendMessage(m_hwndItemList, CB_FINDSTRINGEXACT, ~0u, (size_t)szT);
::SendMessage(m_hwndItemList, CB_DELETESTRING, index, 0);
delete pcvd;
}
void CodeViewer::SelectItem(IScriptable * const piscript)
{
CComBSTR bstr;
piscript->get_Name(&bstr);
char szT[MAXNAMEBUFFER*2]; // Names can only be 32 characters (plus terminator)
WideCharToMultiByteNull(CP_ACP, 0, bstr, -1, szT, MAXNAMEBUFFER*2, nullptr, nullptr);
const LRESULT index = ::SendMessage(m_hwndItemList, CB_FINDSTRINGEXACT, ~0u, (size_t)szT);
if (index != CB_ERR)
{
::SendMessage(m_hwndItemList, CB_SETCURSEL, index, 0);
ListEventsFromItem();
}
}
HRESULT CodeViewer::ReplaceName(IScriptable * const piscript, const WCHAR * const wzNew)
{
if (m_vcvd.GetSortedIndex(wzNew) != -1)
return E_FAIL;
CComBSTR bstr;
piscript->get_Name(&bstr);
const int idx = m_vcvd.GetSortedIndex(bstr);
if (idx == -1)
return E_FAIL;
CodeViewDispatch * const pcvd = m_vcvd[idx];
_ASSERTE(pcvd);
m_vcvd.RemoveElementAt(idx);
pcvd->m_wName = wzNew;
m_vcvd.AddSortedString(pcvd);
// Remove old name from dropdown and replace it with the new
char szT[MAXNAMEBUFFER*2]; // Names can only be 32 characters (plus terminator)
WideCharToMultiByteNull(CP_ACP, 0, bstr, -1, szT, MAXNAMEBUFFER*2, nullptr, nullptr);
size_t index = ::SendMessage(m_hwndItemList, CB_FINDSTRINGEXACT, ~0u, (size_t)szT);
::SendMessage(m_hwndItemList, CB_DELETESTRING, index, 0);
WideCharToMultiByteNull(CP_ACP, 0, wzNew, -1, szT, MAXNAMEBUFFER*2, nullptr, nullptr);
index = ::SendMessage(m_hwndItemList, CB_ADDSTRING, 0, (size_t)szT);
::SendMessage(m_hwndItemList, CB_SETITEMDATA, index, (size_t)piscript);
::SendMessage(m_hwndItemList, CB_SETCURSEL, index, 0);
ListEventsFromItem(); // Just to get us into a good state
return S_OK;
}
STDMETHODIMP CodeViewer::InitializeScriptEngine()
{
const HRESULT vbScriptResult = CoCreateInstance(CLSID_VBScript, 0, CLSCTX_ALL/*CLSCTX_INPROC_SERVER*/, IID_IActiveScriptParse, (LPVOID*)&m_pScriptParse); //!! CLSCTX_INPROC_SERVER good enough?!
if (vbScriptResult != S_OK) return vbScriptResult;
// This can fail on some systems (I tested with wine 6.9 and this fails)
// In that case, m_pProcessDebugManager will remain as nullptr
CoCreateInstance(
CLSID_ProcessDebugManager,
0,
CLSCTX_ALL,
IID_IProcessDebugManager,
(LPVOID*)&m_pProcessDebugManager
);
// Also check if we have a debugger installed
// If not, we should abandon the process debug manager and fall back to plain basic errors
IDebugApplication* debugApp;
if (SUCCEEDED(GetApplication(&debugApp)))
{
debugApp->Release();
}
else
{
if (m_pProcessDebugManager)
{
m_pProcessDebugManager->Release();
m_pProcessDebugManager = nullptr;
}
}
m_pScriptParse->QueryInterface(IID_IActiveScript,
(LPVOID*)&m_pScript);
m_pScriptParse->QueryInterface(IID_IActiveScriptDebug,
(LPVOID*)&m_pScriptDebug);
m_pScriptParse->InitNew();
m_pScript->SetScriptSite(this);
IObjectSafety* pios;
m_pScriptParse->QueryInterface(IID_IObjectSafety, (LPVOID*)&pios);
if (pios)
{
DWORD supported, enabled;
pios->GetInterfaceSafetyOptions(IID_IActiveScript, &supported, &enabled);
/*const HRESULT hr =*/ pios->SetInterfaceSafetyOptions(IID_IActiveScript, supported, INTERFACE_USES_SECURITY_MANAGER);
pios->Release();
}
return S_OK;
}
STDMETHODIMP CodeViewer::CleanUpScriptEngine()
{
if (m_pScript)
{
//m_pScript->SetScriptState(SCRIPTSTATE_DISCONNECTED);
//m_pScript->SetScriptState(SCRIPTSTATE_CLOSED);
// Cleanly wait for the script to end to allow Exit event, triggered just before closing, to be processed
SCRIPTSTATE state;
m_pScript->GetScriptState(&state);
if (state != SCRIPTSTATE_CLOSED && state != SCRIPTSTATE_UNINITIALIZED)
{
PLOGI << "Sending Close to script interpreter #" << m_pScript;
m_pScript->Close();
U32 startWaitTick = msec();
while ((msec() - startWaitTick < 5000) && (state != SCRIPTSTATE_CLOSED))
{
Sleep(16);
m_pScript->GetScriptState(&state);
}
if (state != SCRIPTSTATE_CLOSED)
{
PLOGE << "Script did not terminated within 5s after request. Forcing close of interpreter #" << m_pScript;
EXCEPINFO eiInterrupt = {};
const LocalString ls(IDS_HANG);
const WCHAR *const wzError = MakeWide(ls.m_szbuffer);
eiInterrupt.bstrDescription = SysAllocString(wzError);
//eiInterrupt.scode = E_NOTIMPL;
eiInterrupt.wCode = 2345;
delete[] wzError;
m_pScript->InterruptScriptThread(SCRIPTTHREADID_BASE /*SCRIPTTHREADID_ALL*/, &eiInterrupt, /*SCRIPTINTERRUPT_DEBUG*/ SCRIPTINTERRUPT_RAISEEXCEPTION);
}
else
{
PLOGI << "Script interpreter state is now closed. Releasing interpreter #" << m_pScript;
}
}
SAFE_RELEASE_NO_RCC(m_pScript);
SAFE_RELEASE_NO_RCC(m_pScriptParse);
SAFE_RELEASE(m_pScriptDebug);
if (m_pProcessDebugManager != nullptr) m_pProcessDebugManager->Release();
}
for (size_t i = 0; i < m_vcvdTemp.size(); ++i)
delete m_vcvdTemp[i];
m_vcvdTemp.clear();
return S_OK;
}
void CodeViewer::SetVisible(const bool visible)
{
if (!visible && !m_minimized)
{
const CRect rc = GetWindowRect();
g_pvp->m_settings.SaveValue(Settings::Editor, "CodeViewPosX"s, (int)rc.left);
g_pvp->m_settings.SaveValue(Settings::Editor, "CodeViewPosY"s, (int)rc.top);
const int w = rc.right - rc.left;
g_pvp->m_settings.SaveValue(Settings::Editor, "CodeViewPosWidth"s, w);
const int h = rc.bottom - rc.top;
g_pvp->m_settings.SaveValue(Settings::Editor, "CodeViewPosHeight"s, h);
}
if (m_hwndFind && !visible)
{
DestroyWindow(m_hwndFind);
m_hwndFind = nullptr;
}
if (IsIconic())
{
// SW_RESTORE usually works in all cases, but if the window
// is maximized, we don't want to restore to a smaller size,
// so we check IsIconic to only restore in the minimized state.
ShowWindow(visible ? SW_RESTORE : SW_HIDE);
m_minimized = false;
}
else
ShowWindow(visible ? SW_SHOW : SW_HIDE);
if (visible)
{
if (!m_visible)
{
const int x = g_pvp->m_settings.LoadValueWithDefault(Settings::Editor, "CodeViewPosX"s, 0);
const int y = g_pvp->m_settings.LoadValueWithDefault(Settings::Editor, "CodeViewPosY"s, 0);
const int w = g_pvp->m_settings.LoadValueWithDefault(Settings::Editor, "CodeViewPosWidth"s, 640);
const int h = g_pvp->m_settings.LoadValueWithDefault(Settings::Editor, "CodeViewPosHeight"s, 490);
POINT p { x, y };
if (MonitorFromPoint(p, MONITOR_DEFAULTTONULL) != NULL) // Do not apply if point is offscreen
SetWindowPos(HWND_TOP, x, y, w, h, SWP_NOMOVE | SWP_NOSIZE);
}
SetForegroundWindow();
}
m_visible = visible;
}
void CodeViewer::SetEnabled(const bool enabled)
{
::SendMessage(m_hwndScintilla, SCI_SETREADONLY, !enabled, 0);
::EnableWindow(m_hwndItemList, enabled);
::EnableWindow(m_hwndEventList, enabled);
}
void CodeViewer::SetCaption(const string& szCaption)
{
string szT;
if (!external_script_name.empty())
szT = "MODIFYING EXTERNAL SCRIPT: " + external_script_name;
else
{
const LocalString ls(IDS_SCRIPT);
szT = szCaption + ' ' + ls.m_szbuffer;
}
SetWindowText(szT.c_str());
}
void CodeViewer::UpdatePrefsfromReg()
{
m_bgColor = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, "BackGroundColor"s, (int)RGB(255,255,255));
m_bgSelColor = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, "BackGroundSelectionColor"s, (int)RGB(192,192,192));
m_displayAutoComplete = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, "DisplayAutoComplete"s, true);
m_displayAutoCompleteLength = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, "DisplayAutoCompleteAfter"s, 1);
m_dwellDisplay = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, "DwellDisplay"s, true);
m_dwellHelp = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, "DwellHelp"s, true);
m_dwellDisplayTime = g_pvp->m_settings.LoadValueWithDefault(Settings::CVEdit, "DwellDisplayTime"s, 700);
for (size_t i = 0; i < m_lPrefsList->size(); ++i)
m_lPrefsList->at(i)->GetPrefsFromReg();
}
void CodeViewer::UpdateRegWithPrefs()
{
g_pvp->m_settings.SaveValue(Settings::CVEdit, "BackGroundColor"s, (int)m_bgColor);
g_pvp->m_settings.SaveValue(Settings::CVEdit, "BackGroundSelectionColor"s, (int)m_bgSelColor);
g_pvp->m_settings.SaveValue(Settings::CVEdit, "DisplayAutoComplete"s, m_displayAutoComplete);
g_pvp->m_settings.SaveValue(Settings::CVEdit, "DisplayAutoCompleteAfter"s, m_displayAutoCompleteLength);
g_pvp->m_settings.SaveValue(Settings::CVEdit, "DwellDisplay"s, m_dwellDisplay);
g_pvp->m_settings.SaveValue(Settings::CVEdit, "DwellHelp"s, m_dwellHelp);
g_pvp->m_settings.SaveValue(Settings::CVEdit, "DwellDisplayTime"s, m_dwellDisplayTime);
for (size_t i = 0; i < m_lPrefsList->size(); i++)
m_lPrefsList->at(i)->SetPrefsToReg();
}
void CodeViewer::InitPreferences()
{
memset(m_prefCols, 0, sizeof(m_prefCols));
m_bgColor = RGB(255,255,255);
m_bgSelColor = RGB(192,192,192);
m_lPrefsList = new vector<CVPreference*>();
m_prefEverythingElse = new CVPreference(RGB(0,0,0), true, "EverythingElse", STYLE_DEFAULT, 0 , IDC_CVP_BUT_COL_EVERYTHINGELSE, IDC_CVP_BUT_FONT_EVERYTHINGELSE);
m_lPrefsList->push_back(m_prefEverythingElse);
prefDefault = new CVPreference(RGB(0,0,0), true, "Default", SCE_B_DEFAULT, 0 , 0, 0);
m_lPrefsList->push_back(prefDefault);
prefVBS = new CVPreference(RGB(0,0,160), true, "ShowVBS", SCE_B_KEYWORD, IDC_CVP_CHECKBOX_VBS, IDC_CVP_BUT_COL_VBS, IDC_CVP_BUT_FONT_VBS);
m_lPrefsList->push_back(prefVBS);
prefComps = new CVPreference(RGB(120,120,0), true, "ShowComponents", SCE_B_KEYWORD3, IDC_CVP_CHKB_COMP, IDC_CVP_BUT_COL_COMPS, IDC_CVP_BUT_FONT_COMPS);
m_lPrefsList->push_back(prefComps);
prefSubs = new CVPreference(RGB(120,0,120), true, "ShowSubs", SCE_B_KEYWORD2, IDC_CVP_CHKB_SUBS, IDC_CVP_BUT_COL_SUBS, IDC_CVP_BUT_FONT_SUBS);
m_lPrefsList->push_back(prefSubs);
prefComments = new CVPreference(RGB(0,120,0), true, "ShowRemarks", SCE_B_COMMENT, IDC_CVP_CHKB_COMMENTS, IDC_CVP_BUT_COL_COMMENTS, IDC_CVP_BUT_FONT_COMMENTS);
m_lPrefsList->push_back(prefComments);
prefLiterals = new CVPreference(RGB(0,120,160), true, "ShowLiterals", SCE_B_STRING, IDC_CVP_CHKB_LITERALS, IDC_CVP_BUT_COL_LITERALS, IDC_CVP_BUT_FONT_LITERALS);
m_lPrefsList->push_back(prefLiterals);
prefVPcore = new CVPreference(RGB(200,50,60), true, "ShowVPcore", SCE_B_KEYWORD4, IDC_CVP_CHKB_VPCORE, IDC_CVP_BUT_COL_VPCORE, IDC_CVP_BUT_FONT_VPCORE);
m_lPrefsList->push_back(prefVPcore);
for (size_t i = 0; i < m_lPrefsList->size(); ++i)
{
CVPreference* const Pref = m_lPrefsList->at(i);
Pref->SetDefaultFont(m_hwndMain);
}
// load prefs from registry
UpdatePrefsfromReg();
}
int CodeViewer::OnCreate(CREATESTRUCT& cs)
{
m_haccel = LoadAccelerators(g_pvp->theInstance, MAKEINTRESOURCE(IDR_CODEVIEWACCEL)); // Accelerator keys
m_hwndMain = GetHwnd();
SetWindowLongPtr(GWLP_USERDATA, (size_t)this);
/////////////////// Item / Event Lists //!! ALL THIS STUFF IS NOT RES/DPI INDEPENDENT! also see WM_SIZE handler
m_hwndItemText = CreateWindowEx(0, "Static", "ObjectsText",
WS_CHILD | WS_VISIBLE | SS_LEFTNOWORDWRAP, 5, 0, 330, 30, m_hwndMain, nullptr, g_pvp->theInstance, 0);
::SetWindowText(m_hwndItemText, "Table component:");
::SendMessage(m_hwndItemText, WM_SETFONT, (size_t)GetStockObject(DEFAULT_GUI_FONT), 0);
m_hwndItemList = CreateWindowEx(0, "ComboBox", "Objects",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
5, 30+2, 330, 400, m_hwndMain, nullptr, g_pvp->theInstance, 0);
::SetWindowLongPtr(m_hwndItemList, GWL_ID, IDC_ITEMLIST);
::SendMessage(m_hwndItemList, WM_SETFONT, (size_t)GetStockObject(DEFAULT_GUI_FONT), 0);
m_hwndEventText = CreateWindowEx(0, "Static", "EventsText",
WS_CHILD | WS_VISIBLE | SS_LEFTNOWORDWRAP, 360 + 5, 0, 330, 30, m_hwndMain, nullptr, g_pvp->theInstance, 0);
::SetWindowText(m_hwndEventText, "Create Sub from component:");
::SendMessage(m_hwndEventText, WM_SETFONT, (size_t)GetStockObject(DEFAULT_GUI_FONT), 0);
m_hwndEventList = CreateWindowEx(0, "ComboBox", "Events",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
360 + 5, 30+2, 330, 400, m_hwndMain, nullptr, g_pvp->theInstance, 0);
::SetWindowLongPtr(m_hwndEventList, GWL_ID, IDC_EVENTLIST);
::SendMessage(m_hwndEventList, WM_SETFONT, (size_t)GetStockObject(DEFAULT_GUI_FONT), 0);
m_hwndFunctionText = CreateWindowEx(0, "Static", "FunctionsText",
WS_CHILD | WS_VISIBLE | SS_LEFTNOWORDWRAP, 730 + 5, 0, 330, 30, m_hwndMain, nullptr, g_pvp->theInstance, 0);
::SetWindowText(m_hwndFunctionText, "Go to Sub/Function:");
::SendMessage(m_hwndFunctionText, WM_SETFONT, (size_t)GetStockObject(DEFAULT_GUI_FONT), 0);
m_hwndFunctionList = CreateWindowEx(0, "ComboBox", "Functions",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL,
730 + 5, 30+2, 330, 400, m_hwndMain, nullptr, g_pvp->theInstance, 0);
::SetWindowLongPtr(m_hwndFunctionList, GWL_ID, IDC_FUNCTIONLIST);
::SendMessage(m_hwndFunctionList, WM_SETFONT, (size_t)GetStockObject(DEFAULT_GUI_FONT), 0);
//////////////////////// Status Window (& Sizing Box)
m_hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE, "", m_hwndMain, 1);
constexpr int foo[4] = { 220, 420, 450, 500 };
::SendMessage(m_hwndStatus, SB_SETPARTS, 4, (size_t)foo);
//////////////////////// Last error widget
m_hwndLastErrorTextArea = CreateWindowEx(0, "Edit", "",
WS_CHILD | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE,
0, 0, 0, 0, m_hwndMain, nullptr, g_pvp->theInstance, 0);
SendMessage(m_hwndLastErrorTextArea, EM_SETREADONLY, TRUE, 0);
::SendMessage(m_hwndLastErrorTextArea, WM_SETFONT, (size_t)GetStockObject(ANSI_FIXED_FONT), 0);
//////////////////////// Scintilla text editor
m_hwndScintilla = CreateWindowEx(0, "Scintilla", "",
WS_CHILD | ES_NOHIDESEL | WS_VISIBLE | ES_SUNKEN | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN,
0, 30+2 +40, 0, 0, m_hwndMain, nullptr, g_pvp->theInstance, 0);
//if still using old dll load VB lexer instead
//use SCI_SETLEXERLANGUAGE as SCI_GETLEXER doesn't return the correct value with SCI_SETLEXER
::SendMessage(m_hwndScintilla, SCI_SETLEXERLANGUAGE, 0, (LPARAM)"vpscript");
const LRESULT lexVersion = SendMessage(m_hwndScintilla, SCI_GETLEXER, 0, 0);
if (lexVersion != SCLEX_VPSCRIPT)
{
::SendMessage(m_hwndScintilla, SCI_SETLEXER, (WPARAM)SCLEX_VBSCRIPT, 0);
}
char szValidChars[256] = {};
::SendMessage(m_hwndScintilla, SCI_GETWORDCHARS, 0, (LPARAM)szValidChars);
m_validChars = szValidChars;
m_stopErrorDisplay = false;
// Create new list of user functions & Collections- filled in ParseForFunction(), first called in LoadFromStream()
m_wordUnderCaret.lpstrText = CaretTextBuff;
m_currentConstruct.lpstrText = ConstructTextBuff;
// parse vb reserved words for auto complete.
int intWordFinish = -1; //skip space
char WordChar = vbsReservedWords[0];
while (WordChar != '\0') //Just make sure with chars, we reached EOL
{
string szWord;
intWordFinish++; //skip space
WordChar = vbsReservedWords[intWordFinish];
while (WordChar != '\0' && WordChar != ' ')
{
szWord += WordChar;
intWordFinish++;
WordChar = vbsReservedWords[intWordFinish];
}
UserData VBWord;
if (!szWord.empty())
{
VBWord.m_uniqueKey = VBWord.m_keyName = szWord;
// Capitalize first letter
const char fl = VBWord.m_keyName[0];
if (fl >= 'a' && fl <= 'z') VBWord.m_keyName[0] = fl - ('a' - 'A');
}
FindOrInsertUD(m_VBwordsDict, VBWord);
}
///// Preferences
InitPreferences();
::SendMessage(m_hwndScintilla, SCI_SETMODEVENTMASK, SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT, 0);
::SendMessage(m_hwndScintilla, SCI_SETKEYWORDS, 0, (LPARAM)vbsReservedWords);
::SendMessage(m_hwndScintilla, SCI_SETTABWIDTH, 4, 0);
// The null visibility policy is like Visual Studio - if a search goes
// off the screen, the newly selected text is placed in the middle of the
// screen
::SendMessage(m_hwndScintilla, SCI_SETVISIBLEPOLICY, 0, 0);
//Set up line numbering
::SendMessage(m_hwndScintilla, SCI_SETMARGINTYPEN, 0, SC_MARGIN_NUMBER);
::SendMessage(m_hwndScintilla, SCI_SETMARGINSENSITIVEN, 1, 1);
::SendMessage(m_hwndScintilla, SCI_SETMARGINWIDTHN, 0, 40);
//Cursor line dimmed
::SendMessage(m_hwndScintilla, SCI_SETCARETLINEVISIBLE, 1, 0);
::SendMessage(m_hwndScintilla, SCI_SETCARETLINEBACK, RGB(240, 240, 255), 0);
//Highlight Errors
::SendMessage(m_hwndScintilla, SCI_INDICSETSTYLE, 0, INDIC_ROUNDBOX);
::SendMessage(m_hwndScintilla, SCI_SETINDICATORCURRENT, 0, 0);
::SendMessage(m_hwndScintilla, SCI_INDICSETFORE, 0, RGB(255, 0, 0));
::SendMessage(m_hwndScintilla, SCI_INDICSETALPHA, 0, 90);
//Set up folding.
::SendMessage(m_hwndScintilla, SCI_SETPROPERTY, (WPARAM)"fold", (LPARAM)"1");
::SendMessage(m_hwndScintilla, SCI_SETPROPERTY, (WPARAM)"fold.compact", (LPARAM)"0");
//Set up folding margin
::SendMessage(m_hwndScintilla, SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL);
::SendMessage(m_hwndScintilla, SCI_SETMARGINMASKN, 1, SC_MASK_FOLDERS);
::SendMessage(m_hwndScintilla, SCI_SETMARGINWIDTHN, 1, 20);
::SendMessage(m_hwndScintilla, SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_MINUS);
::SendMessage(m_hwndScintilla, SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, m_prefEverythingElse->m_rgb);
::SendMessage(m_hwndScintilla, SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, m_bgColor);
//WIP markers
::SendMessage(m_hwndScintilla, SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_PLUS);
::SendMessage(m_hwndScintilla, SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, m_prefEverythingElse->m_rgb);
::SendMessage(m_hwndScintilla, SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, m_bgColor);