This repository was archived by the owner on Nov 16, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathTreeView.cpp
More file actions
307 lines (272 loc) · 9.48 KB
/
Copy pathTreeView.cpp
File metadata and controls
307 lines (272 loc) · 9.48 KB
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
#include "StdBhvTree.h"
#include "TreeView.h"
#include "VariableLists/StringVectorList.h"
#include "TagDepthTree.h"
IMPLEMENT_DYNCREATE(TreeView, CView)
/// <summary>
/// Loads the data from file.
/// </summary>
/// <param name="FilePath">The file path.</param>
/// <returns>bool</returns>
inline bool TreeView::LoadDataFromFile(std::string FilePath)
{
Reset();
char LineChar;
bool InsideXMLComment = false;
//If false, then inside tagcontent types instead of tags
bool InsideTag = false;
std::string ScanBuffer = "";
//First name inside tag becomes CurrentTag
std::string CurrentTag = "";
std::string CurrentNodeName = "";
unsigned int CurrentNodeIndex = 0;
//0=NormalTag; 1:SelfContainedTag; 2:TagIsClosing; 3:XMLVersionTag
int TagType = 0;
bool ScanningArgData = false;
std::string ArgElement;
ArgStringList LastArg;
ArgList ArgBuffer;
bool PotentialComment = false;
bool InsideParenthesis = false;
bool InsideClassNodeSection = false;
//0 = Not Scanning TagContent Yet: 1 = Potential SingleLine TagContent: 2 Multi-line target content
short TagContentStage = 0;
//Current state of code loading for certain sections of code
size_t Stage = 0;
//Index of hkobject class node
unsigned int CurrentClassNodeIndex = 0;
//Index of last entered node
unsigned int CurrentNodeIndex = 0;
TagDepthTree TagDepth;
std::string HkClassType = "";
//std::string CurrentNodeName = "";
unsigned ClassNodeIndex = 0;
//class parameter of hkobject
//BhvTreeViewNode* TargetNode = nullptr;
const std::string hkobject = "hkobject";
const std::string Signature = "Signature";
std::ifstream inFile;
inFile.open(FilePath);
if (!inFile)
{
return false;
}
while (inFile >> LineChar)
{
if (PotentialComment)
{
ScanBuffer += LineChar;
if (ScanBuffer == "--")
{
InsideXMLComment = true;
PotentialComment = false;
ScanBuffer = "";
}
else if (ScanBuffer.size() >= 2)//Detecting non-normal format TagName?
{
PotentialComment = false;
ScanBuffer = "!" + ScanBuffer;
}
}
else if (InsideXMLComment)//Ignoring all xml inside xml formatted comment
{
Stage = ScanBuffer.size();
if (Stage == 0)
{
if (LineChar == '-')
{
ScanBuffer = "-";
}
}
else if (Stage == 1)
{
if (LineChar == '-')
{
ScanBuffer = "--";
}
else
{
ScanBuffer = "";
}
}
else
{
if (LineChar == '>')
{
InsideXMLComment = false;
}
ScanBuffer = "";
}
}
else if (ScanningArgData)
{
if (Stage == 0)
{
if (LineChar == '=')
{
Stage = 1;
//CurrentArgName = ScanBuffer;//Don't need to store in separate variable since ScanBuffer not going to be changed until exit scanning argument data
ArgElement = "";
}
else if (LineChar != ' ' && LineChar != '\t' && LineChar != '\n')//Skip Whitespace
{
ScanBuffer += LineChar;
}
}
else if (Stage == 1)
{
if (LineChar == '\"')
{
Stage = 2;
}
}
else if (Stage == 2)
{
if (LineChar == '\"') { Stage = 3; }
}
else if (Stage == 3)
{
if (LineChar == ',')
{
LastArg.Add(ArgElement);
}
else if (LineChar == '\"')
{
ArgBuffer.Add(ScanBuffer, LastArg);
ScanningArgData = false;
}
else
{
ArgElement += LineChar;
}
}
}
else
{
if (InsideTag)
{
if (ScanBuffer == "/" && LineChar == '>')
{
switch (TagType)
{
default://TagIsClosing(TagType==2)
//Decrease TagDepth
TagDepth.RemoveLastTagMatch(CurrentTag);
break;
case 1://SelfContainedTag
NodeBank.Add(CurrentTag, ArgBuffer, CurrentNodeIndex);
break;
case 3://XMLVersionTag(Same as SelfContained Tag except for ? in front and such)
break;
}
CurrentTag = "";//Reset it to clear buffer so next tag has fresh storage
InsideTag = false; TagContentStage = 0;
}
else if (LineChar == '>')
{
//(TagType==0)
CurrentNodeIndex = NodeBank.Add(CurrentTag, ArgBuffer, CurrentNodeIndex);//Index of Last Entered Node is it's parent
if (InsideClassNodeSection && CurrentClassNodeIndex == 0 && CurrentTag == hkobject && ArgBuffer.HasKey(Signature))
{
CurrentClassNodeIndex = CurrentNodeIndex;
CurrentNodeName = ArgBuffer["Name"][0];
NodeLinks.Add(CurrentNodeName, CurrentClassNodeIndex);
}
//Increase TagDepth
CurrentNodeName = CurrentTag;
CurrentTag = "";//Reset it to clear buffer so next tag has fresh storage
InsideTag = false; TagContentStage = 0;
}
else if (CurrentTag.empty())
{
if (!ScanBuffer.empty())
{
if (LineChar == '!')//Detecting potential Commented Out Parts
{
PotentialComment = true;
}
else if (LineChar == ' ' || LineChar == '/t')
{
CurrentTag = ScanBuffer;
}
else
{
ScanBuffer += LineChar;
}
}
else if (LineChar != ' ' && LineChar != ' ' && LineChar != '\n')
{
ScanBuffer += LineChar;
if (LineChar != '\\')
{
ScanningArgData = true; Stage = 0;
}
}
}
else if (TagContentStage > 0)
{
}
else
{
if (LineChar == '<')
{
InsideTag = true;
}
else if (LineChar != ' ' && LineChar != ' ' && LineChar != '\n')
{
ScanBuffer = LineChar;
TagContentStage = 1;
}
}
}
}
}
return true;
}
void TreeView::OnDraw(CDC* pDC)
{
MultiViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CPaintDC dc(this); // Device context for painting
// Double-buffering
CDC* pDCMem = new CDC;
CRect rFrame;
GetClientRect(rFrame);
pDCMem->CreateCompatibleDC(&dc);
// START DRAW -------------------------------------------------
pDCMem->FillSolidRect(rFrame, RGB(255, 255, 255));
UINT nMode = pDCMem->SetBkMode(TRANSPARENT);
CFont* pOldFont = pDCMem->SelectObject(&m_Font);
int iLastNodePos = 0;
iLastNodePos = DrawNodesFromRoot(pDCMem, rFrame.left + m_iIndent, m_iPadding - GetScrollPos(SB_VERT), rFrame);
if (m_bShowLines)
DrawLinesFromRoot(pDCMem);
pDCMem->SelectObject(pOldFont);
pDCMem->SetBkMode(nMode);
pDCMem->Draw3dRect(rFrame, RGB(0, 0, 0), RGB(0, 0, 0)); // Border
// END DRAW -------------------------------------------------
dc.BitBlt(0, 0, rFrame.Width(), rFrame.Height(), pDCMem, 0, 0, SRCCOPY);
delete pDCMem;
// Has the total document height changed?
if (iLastNodePos != m_iDocHeight)
{
BOOL bInvalidate = ((m_iDocHeight < rFrame.Height()) != (iLastNodePos < rFrame.Height()));
m_iDocHeight = iLastNodePos;
ResetScrollBar();
// If the scrollbar has just been hidden/shown, repaint
if (bInvalidate)
Invalidate();
}
}
#ifdef _DEBUG
void TreeView::AssertValid() const
{
CView::AssertValid();
}
void TreeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG