-
Notifications
You must be signed in to change notification settings - Fork 1
/
codeview.h
502 lines (394 loc) · 12.7 KB
/
codeview.h
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
#pragma once
#include <Commdlg.h>
#include <activscp.h>
#include <activdbg.h>
#include <atlcom.h>
#include "codeviewedit.h"
#include "scintilla.h"
#include "scilexer.h"
#define MAX_FIND_LENGTH 81
#define MAX_LINE_LENGTH 2048
enum SecurityLevelEnum
{
eSecurityNone = 0,
eSecurityWarnOnUnsafeType = 1,
eSecurityWarnOnType = 2,
eSecurityWarnOnAll = 3,
eSecurityNoControls = 4
};
class IScriptable
{
public:
IScriptable();
STDMETHOD(get_Name)(BSTR *pVal) = 0;
virtual IDispatch *GetDispatch() = 0;
virtual ISelect *GetISelect() = 0;
WCHAR m_wzName[MAXNAMEBUFFER];
};
class CodeViewer;
class DebuggerModule :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<IVPDebug, &IID_IVPDebug, &LIBID_VPinballLib>,
public IScriptable
{
BEGIN_COM_MAP(DebuggerModule)
COM_INTERFACE_ENTRY(IVPDebug)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
STDMETHOD(Print)(VARIANT *pvar);
void Init(CodeViewer * const pcv);
virtual IDispatch *GetDispatch();
virtual ISelect *GetISelect() { return NULL; }
STDMETHOD(get_Name)(BSTR *pVal);
CodeViewer *m_pcv;
};
class IScriptableHost
{
public:
virtual void SelectItem(IScriptable *piscript) = 0;
virtual void SetDirtyScript(SaveDirtyState sds) = 0;
virtual void DoCodeViewCommand(int command) = 0;
};
class CodeViewDispatch
{
public:
CodeViewDispatch();
~CodeViewDispatch();
WCHAR m_wzName[MAXNAMEBUFFER];
IUnknown *m_punk;
IDispatch *m_pdisp;
IScriptable *m_piscript;
bool m_global;
// for VectorSortString
int SortAgainst(const CodeViewDispatch * const pcvd/*void *pvoid*/) const;
int SortAgainstValue(const void * const pv) const;
};
class CodeViewer :
public CComObjectRoot,
//public IDispatchImpl<IDragPoint, &IID_IDragPoint, &LIBID_VPinballLib>,
//public CComCoClass<CodeViewer,&CLSID_DragPoint>,
//public CComObjectRootEx<CComSingleThreadModel>,
public IActiveScriptSite,
public IActiveScriptSiteWindow,
public IInternetHostSecurityManager,
public IServiceProvider,
public UserData,
public CVPrefrence
{
public:
CodeViewer();
virtual ~CodeViewer();
void Init(IScriptableHost *psh);
void Create();
void Destroy();
void SetVisible(const bool visible);
void SetEnabled(const bool enabled);
void SetClean(const SaveDirtyState sds);
// Script Class
STDMETHOD(CleanUpScriptEngine)();
STDMETHOD(InitializeScriptEngine)();
HRESULT AddItem(IScriptable * const piscript, const bool global);
void RemoveItem(IScriptable * const piscript);
HRESULT ReplaceName(IScriptable * const piscript, WCHAR * const wzNew);
void SelectItem(IScriptable * const piscript);
void Compile(const bool message);
void Start();
void EndSession();
HRESULT AddTemporaryItem(const BSTR bstr, IDispatch * const pdisp);
STDMETHOD(GetItemInfo)(LPCOLESTR pstrName, DWORD dwReturnMask,
IUnknown **ppiunkItem, ITypeInfo **ppti);
STDMETHOD(OnScriptError)(IActiveScriptError *pscripterror);
STDMETHOD(GetLCID)(LCID *plcid)
{
*plcid = 9; return S_OK;
}
STDMETHOD(GetDocVersionString)(BSTR *pbstrVersion)
{
*pbstrVersion = SysAllocString(L""); return S_OK;
}
STDMETHOD(OnScriptTerminate)(const VARIANT *pvr, const EXCEPINFO *pei)
{
return S_OK;
}
STDMETHOD(OnStateChange)(SCRIPTSTATE ssScriptState)
{
return S_OK;
}
STDMETHOD(OnEnterScript)();
STDMETHODIMP OnLeaveScript();
STDMETHODIMP GetWindow(HWND *phwnd)
{
*phwnd = GetDesktopWindow(); return S_OK;
}
STDMETHODIMP EnableModeless(BOOL)
{
return S_OK;
}
// Internet Security interface
virtual HRESULT STDMETHODCALLTYPE GetSecurityId(
/* [size_is][out] */ BYTE *pbSecurityId,
/* [out][in] */ DWORD *pcbSecurityId,
/* [in] */ DWORD_PTR dwReserved);
virtual HRESULT STDMETHODCALLTYPE ProcessUrlAction(
/* [in] */ DWORD dwAction,
/* [size_is][out] */ BYTE __RPC_FAR *pPolicy,
/* [in] */ DWORD cbPolicy,
/* [in] */ BYTE __RPC_FAR *pContext,
/* [in] */ DWORD cbContext,
/* [in] */ DWORD dwFlags,
/* [in] */ DWORD dwReserved);
virtual HRESULT STDMETHODCALLTYPE QueryCustomPolicy(
/* [in] */ REFGUID guidKey,
/* [size_is][size_is][out] */ BYTE __RPC_FAR *__RPC_FAR *ppPolicy,
/* [out] */ DWORD __RPC_FAR *pcbPolicy,
/* [in] */ BYTE __RPC_FAR *pContext,
/* [in] */ DWORD cbContext,
/* [in] */ DWORD dwReserved);
bool FControlAlreadyOkayed(CONFIRMSAFETY *pcs);
void AddControlToOkayedList(CONFIRMSAFETY *pcs);
bool FControlMarkedSafe(CONFIRMSAFETY *pcs);
bool FUserManuallyOkaysControl(CONFIRMSAFETY *pcs);
virtual HRESULT STDMETHODCALLTYPE QueryService(
REFGUID guidService,
REFIID riid,
void **ppv);
// Use CComObject to implement AddRef/Release/QI
BEGIN_COM_MAP(CodeViewer)
//COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IActiveScriptSite)
COM_INTERFACE_ENTRY(IActiveScriptSiteWindow)
COM_INTERFACE_ENTRY(IInternetHostSecurityManager)
COM_INTERFACE_ENTRY(IServiceProvider)
END_COM_MAP()
void UncolorError();
void ParseForFunction();
void ShowFindDialog();
void ShowFindReplaceDialog();
void Find(const FINDREPLACE * const pfr);
void Replace(const FINDREPLACE * const pfr);
void SaveToStream(IStream *pistream, HCRYPTHASH const hcrypthash);
void SaveToFile(const char *filename);
void LoadFromStream(IStream *pistream, HCRYPTHASH const hcrypthash, const HCRYPTKEY hcryptkey); // incl. table protection
void LoadFromFile(const char *filename);
void SetCaption(const char * const szCaption);
bool ShowTooltip(SCNotification *Scn);
void ShowAutoComplete(SCNotification *pSCN);
void UpdateRegWithPrefs();
void UpdatePrefsfromReg();
void GetWordUnderCaret();
void ListEventsFromItem();
void FindCodeFromEvent();
void TellHostToSelectItem();
void UpdateScinFromPrefs();
void MarginClick(const int position, const int modifiers);
void EvaluateScriptStatement(const char * const szScript);
void AddToDebugOutput(const char * const szText);
IScriptableHost *m_psh;
IActiveScript* m_pScript;
VectorSortString<CodeViewDispatch*> m_vcvd;
COLORREF m_prefCols[16];
COLORREF m_bgColor;
CVPrefrence *m_prefEverythingElse;
vector<CVPrefrence*> *m_lPrefsList;
int m_displayAutoCompleteLength;
bool m_scriptError; // Whether a script error has occured - used for polling from the game
bool m_visible;
bool m_minimized;
bool m_displayAutoComplete;
bool m_toolTipActive;
bool m_stopErrorDisplay;
bool m_dwellHelp;
bool m_dwellDisplay;
int m_dwellDisplayTime;
vector<UserData> *m_pageConstructsDict;
Sci_TextRange m_wordUnderCaret;
CComObject<DebuggerModule> *m_pdm; // Object to expose to script for global functions
//ULONG m_cref;
HWND m_hwndMain;
HWND m_hwndScintilla;
HWND m_hwndFind;
HWND m_hwndStatus;
HWND m_hwndFunctionList;
HACCEL m_haccel; // Accelerator keys
int m_errorLineNumber;
FINDREPLACE m_findreplaceold; // the last thing found/replaced
SaveDirtyState m_sdsDirty;
bool m_ignoreDirty;
private:
bool ParseOKLineLength(const size_t LineLen);
void ParseDelimtByColon(string &result, string &wholeline);
void ParseFindConstruct(size_t &Pos, const string &UCLine, WordType &Type, int &ConstructSize);
bool ParseStructureName(vector<UserData> *ListIn, UserData ud, const string &UCline, const string &line, const int Lineno);
size_t SureFind(const string &LineIn, const string &ToFind);
void RemoveByVal(string &line);
void RemoveNonVBSChars(string &line);
string ExtractWordOperand(const string &line, const size_t StartPos);
void ColorLine(const int line);
void ColorError(const int line, const int nchar);
void ParseVPCore();
void ReadLineToParseBrain(string wholeline, const int linecount, vector<UserData> *ListIn);
void GetMembers(vector<UserData>* ListIn, const string &StrIn);
void InitPreferences();
void GetParamsFromEvent(const UINT iEvent, char * const szParams);
IActiveScriptParse* m_pScriptParse;
IActiveScriptDebug* m_pScriptDebug;
FINDREPLACE m_findreplacestruct;
char szFindString[MAX_FIND_LENGTH];
char szReplaceString[MAX_FIND_LENGTH];
VectorSortString<CodeViewDispatch*> m_vcvdTemp; // Objects added through script
string m_validChars;
string m_VBvalidChars;
// CodeViewer Preferences
CVPrefrence *prefDefault;
CVPrefrence *prefVBS;
CVPrefrence *prefComps;
CVPrefrence *prefSubs;
CVPrefrence *prefComments;
CVPrefrence *prefLiterals;
CVPrefrence *prefVPcore;
//bool ParentTreeInvalid;
//TODO: int TabStop;
// keyword lists
string m_vbsKeyWords;
vector<string> *m_autoCompList;
// Dictionaries
vector<UserData> *m_VBwordsDict;
vector<UserData> *m_componentsDict;
vector<UserData> *m_VPcoreDict;
vector<UserData> *m_currentMembers;
string m_autoCompString;
string m_autoCompMembersString;
Sci_TextRange m_currentConstruct;
HWND m_hwndItemList;
HWND m_hwndItemText;
HWND m_hwndEventList;
HWND m_hwndEventText;
HWND m_hwndFunctionText;
};
class Collection :
public IDispatchImpl<ICollection, &IID_ICollection, &LIBID_VPinballLib>,
public CComObjectRoot,
public CComCoClass<Collection, &CLSID_Collection>,
public EventProxy<Collection, &DIID_ICollectionEvents>,
public IConnectionPointContainerImpl<Collection>,
public IProvideClassInfo2Impl<&CLSID_Collection, &DIID_ICollectionEvents, &LIBID_VPinballLib>,
public IScriptable,
public ILoadable
{
public:
Collection();
// IScriptable
STDMETHOD(get_Name)(BSTR *pVal);
virtual IDispatch *GetDispatch();
virtual ISelect *GetISelect();
//ILoadable
virtual HRESULT SaveData(IStream *pstm, HCRYPTHASH hcrypthash, const bool backupForPlay);
virtual HRESULT LoadData(IStream *pstm, PinTable *ppt, int version, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey);
virtual bool LoadToken(const int id, BiffReader * const pbr);
STDMETHOD(get_Count)(long __RPC_FAR *plCount);
STDMETHOD(get_Item)(long index, IDispatch __RPC_FAR * __RPC_FAR *ppidisp);
STDMETHOD(get__NewEnum)(IUnknown** ppunk);
BEGIN_COM_MAP(Collection)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ICollection)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(Collection)
CONNECTION_POINT_ENTRY(DIID_ICollectionEvents)
END_CONNECTION_POINT_MAP()
VectorProtected<ISelect> m_visel;
bool m_fireEvents;
bool m_stopSingleEvents;
bool m_groupElements;
};
class OMCollectionEnum :
public CComObjectRootEx<CComSingleThreadModel>,
public IEnumVARIANT
{
public:
BEGIN_COM_MAP(OMCollectionEnum)
COM_INTERFACE_ENTRY(IEnumVARIANT)
END_COM_MAP()
OMCollectionEnum();
~OMCollectionEnum();
STDMETHOD(Init)(Collection *pcol);
STDMETHOD(Next)(ULONG celt, VARIANT __RPC_FAR *rgVar, ULONG __RPC_FAR *pCeltFetched);
STDMETHOD(Skip)(ULONG celt);
STDMETHOD(Reset)();
STDMETHOD(Clone)(IEnumVARIANT __RPC_FAR *__RPC_FAR *ppEnum);
private:
Collection *m_pcol;
int m_index;
};
// general string helpers:
inline bool IsWhitespace(const char ch)
{
return (ch == ' ' || ch == 9/*tab*/);
}
inline string upperCase(string input)
{
for (string::iterator it = input.begin(); it != input.end(); ++it)
*it = toupper(*it);
return input;
}
inline string lowerCase(string input)
{
for (string::iterator it = input.begin(); it != input.end(); ++it)
*it = tolower(*it);
return input;
}
inline void RemovePadding(string &line)
{
const size_t LL = line.length();
size_t Pos = (line.find_first_not_of("\n\r\t ,"));
if (Pos == string::npos)
{
line.clear();
return;
}
if (Pos > 0)
{
if ((SSIZE_T)(LL - Pos) < 1) return;
line = line.substr(Pos, (LL - Pos));
}
Pos = (line.find_last_not_of("\n\r\t ,"));
if (Pos != string::npos)
{
if (Pos < 1) return;
line = line.erase(Pos + 1);
}
}
inline string ParseRemoveVBSLineComments(string &Line)
{
const size_t commentIdx = Line.find("'");
if (commentIdx == string::npos) return "";
string RetVal = Line.substr(commentIdx + 1, string::npos);
RemovePadding(RetVal);
if (commentIdx > 0)
{
Line = Line.substr(0, commentIdx);
return RetVal;
}
Line.clear();
return RetVal;
}
inline void szLower(char * pC)
{
while (*pC)
{
if (*pC >= 'A' && *pC <= 'Z')
*pC += ('a' - 'A');
pC++;
}
}
inline void szUpper(char * pC)
{
while (*pC)
{
if (*pC >= 'a' && *pC <= 'z')
*pC -= ('a' - 'A');
pC++;
}
}