-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElementDescMnr.cpp
379 lines (320 loc) · 8.74 KB
/
ElementDescMnr.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
#include "stdafx.h"
#include "ElementDescMnr.h"
#include "utils.h"
#include "apputils.h"
#include "Settings.h"
#include "mainfrm.h"
extern CSettings _Settings;
const int IMG_ID_BODY = 0;
const int IMG_ID_SECTION = 0;
const int IMG_ID_IMAGE = 3;
const int IMG_ID_POEM = 3;
CElementDescMnr _EDMnr;
bool IsDiv(MSHTML::IHTMLElementPtr elem, CString className)
{
if(U::scmp(elem->tagName, L"DIV") == 0 && U::scmp(elem->className, className) == 0)
return true;
return false;
}
bool IsP(MSHTML::IHTMLElementPtr elem, CString className)
{
if(U::scmp(elem->tagName, L"P") == 0 && U::scmp(elem->className, className) == 0)
return true;
return false;
}
// added by SeNS
bool IsStylesheet(MSHTML::IHTMLElementPtr elem)
{
return (U::scmp(elem->className, L"stylesheet") == 0);
}
bool IsStyle(MSHTML::IHTMLElementPtr elem)
{
CString outerHTML = elem->outerHTML;
outerHTML.MakeLower();
return (outerHTML.Find(L"<span class=") == 0);
}
CString GetStylesheetTitle(const MSHTML::IHTMLElementPtr elem)
{
return L"";
}
bool IsSection(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"section");
}
CString GetSectionTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsBody(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"body");
}
CString GetBodyTitle(const MSHTML::IHTMLElementPtr elem)
{
CString caption;
caption = AU::GetAttrCS(elem, L"fbname");
U::NormalizeInplace(caption);
if (caption.IsEmpty())
caption = U::FindTitle(elem);
return caption;
}
bool IsImage(MSHTML::IHTMLElementPtr elem)
{
// return IsDiv(elem, L"image");
return (U::scmp(elem->className, L"image") == 0);
}
CString GetImageTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::GetImageFileName(elem);
}
bool IsAnnotation(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"annotation");
}
CString GetAnnotationTitle(const MSHTML::IHTMLElementPtr elem)
{
return L"";
}
bool IsHistory(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"history");
}
CString GetHistoryTitle(const MSHTML::IHTMLElementPtr elem)
{
return L"";
}
bool IsPoem(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"poem");
}
CString GetPoemTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsStanza(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"stanza");
}
CString GetStanzaTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsTitle(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"title");
}
CString GetTitleTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsEpigraph(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"epigraph");
}
CString GetEpigraphTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsCite(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"cite");
}
CString GetCiteTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsCode(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"code");
}
CString GetCodeTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsSubtitle(MSHTML::IHTMLElementPtr elem)
{
return IsP(elem, L"subtitle");
}
CString GetSubtitleTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
bool IsTable(MSHTML::IHTMLElementPtr elem)
{
return IsDiv(elem, L"table");
}
bool IsTH(MSHTML::IHTMLElementPtr elem)
{
return IsP(elem, L"th");
}
bool IsTD(MSHTML::IHTMLElementPtr elem)
{
return IsP(elem, L"td");
}
bool IsTR(MSHTML::IHTMLElementPtr elem)
{
return IsP(elem, L"tr");
}
CString GetTableTitle(const MSHTML::IHTMLElementPtr elem)
{
return U::FindTitle(elem);
}
CElementDescMnr::CElementDescMnr() : m_initedStEDs(false)
{
}
// Init uses Settings to get information about each item in its list,
// but until Settings are deserialized, that information is reflected
// by CSettings::GetDocTreeItemState via variable which is set to
// CElementDescriptor constructor. On the other hand information about
// serialized fields and default values is collected after initiation, but not before.
// Though we have to assign really deserialized values during creation of CTreeWithToolBar
// explicitly calling information on CSettings::TREEITEMSHOWINFO instance via the same
// CSettings::GetDocTreeItemState. That is non-obvious but works!
bool CElementDescMnr::InitStandartEDs()
{
if(!m_initedStEDs)
{
// SeNS
CElementDescriptor* stylesheet = new CElementDescriptor;
stylesheet->Init(IsStylesheet, GetStylesheetTitle, 0, false, L"Stylesheet");
CElementDescriptor* style = new CElementDescriptor;
style->Init(IsStyle, GetStylesheetTitle, 0, false, L"Style");
CElementDescriptor* section = new CElementDescriptor;
section->Init(IsSection, GetSectionTitle, 0, true, L"Section");
CElementDescriptor* body = new CElementDescriptor;
body->Init(IsBody, GetBodyTitle, 0, true, L"Body");
CElementDescriptor* image = new CElementDescriptor;
image->Init(IsImage, GetImageTitle, 21, true, L"Image");
CElementDescriptor* annotation = new CElementDescriptor;
annotation->Init(IsAnnotation, GetAnnotationTitle, 12, true, L"Annotation");
CElementDescriptor* history = new CElementDescriptor;
history->Init(IsHistory, GetHistoryTitle, 15, true, L"History");
CElementDescriptor* poem = new CElementDescriptor;
poem->Init(IsPoem, GetPoemTitle, 3, true, L"Poem");
CElementDescriptor* stanza = new CElementDescriptor;
stanza->Init(IsStanza, GetStanzaTitle, 3, true, L"Stanza");
CElementDescriptor* title = new CElementDescriptor;
title->Init(IsTitle, GetTitleTitle, 27, false, L"Title");
CElementDescriptor* epigraph = new CElementDescriptor;
epigraph->Init(IsEpigraph, GetEpigraphTitle, 18, false, L"Epigraph");
CElementDescriptor* cite = new CElementDescriptor;
cite->Init(IsCite, GetCiteTitle, 9, false, L"Cite");
// issue #83
/* CElementDescriptor* code = new CElementDescriptor;
code->Init(IsCode, GetCodeTitle, 24, false, L"Code"); */
CElementDescriptor* subtitle = new CElementDescriptor;
subtitle->Init(IsSubtitle, GetSubtitleTitle, 6, true, L"Subtitle");
CElementDescriptor* table = new CElementDescriptor;
table->Init(IsTable, GetTableTitle, 30, true, L"Table");
CElementDescriptor* th = new CElementDescriptor;
th->Init(IsTH, GetTableTitle, 27, true, L"th");
CElementDescriptor* td = new CElementDescriptor;
td->Init(IsTD, GetTableTitle, 27, true, L"td");
CElementDescriptor* tr = new CElementDescriptor;
tr->Init(IsTR, GetTableTitle, 27, true, L"tr");
m_stEDs.Add(stylesheet); // SeNS
m_stEDs.Add(style);
m_stEDs.Add(section);
m_stEDs.Add(body);
m_stEDs.Add(image);
m_stEDs.Add(annotation);
m_stEDs.Add(history);
m_stEDs.Add(poem);
m_stEDs.Add(stanza);
m_stEDs.Add(title);
m_stEDs.Add(epigraph);
m_stEDs.Add(cite);
// m_stEDs.Add(code); // issue #83
m_stEDs.Add(subtitle);
m_stEDs.Add(table);
m_stEDs.Add(th);
m_stEDs.Add(td);
m_stEDs.Add(tr);
m_initedStEDs = true;
}
return true;
}
bool CElementDescMnr::InitScriptEDs()
{
CElementDescriptor* ED;
WIN32_FIND_DATA fd;
int newid = 1;
CString fff = U::GetDocTReeScriptsDir();
HANDLE found = FindFirstFile(U::GetDocTReeScriptsDir() + L"\\*.js", &fd);
if(INVALID_HANDLE_VALUE != found)
{
do
{
ED = new CElementDescriptor;
if(ED->Load(U::GetDocTReeScriptsDir() + L"\\" + fd.cFileName))
{
m_EDs.Add(ED);
}
else
{
delete ED;
}
}
while(FindNextFile(found, &fd));
}
return true;
}
bool CElementDescMnr::GetElementDescriptor(const MSHTML::IHTMLElementPtr elem, CElementDescriptor **desc) const
{
for(int i = 0; i < m_stEDs.GetSize(); i++)
{
if(m_stEDs[i]->IsMe(elem))
{
*desc = m_stEDs[i];
return true;
}
}
for(int i = 0; i < m_EDs.GetSize(); i++)
{
if(m_EDs[i]->IsMe(elem))
{
*desc = m_EDs[i];
return true;
}
}
return false;
}
void CElementDescMnr::AddElementDescriptor(CElementDescriptor *desc)
{
m_EDs.Add(desc);
}
CElementDescriptor* CElementDescMnr::GetStED(int index)
{
return m_stEDs[index];
}
CElementDescriptor* CElementDescMnr::GetED(int index)
{
return m_EDs[index];
}
int CElementDescMnr::GetEDsCount()
{
return m_EDs.GetSize();
}
int CElementDescMnr::GetStEDsCount()
{
return m_stEDs.GetSize();
}
void CElementDescMnr::CleanUpAll()
{
for(int i = 0; i < m_EDs.GetSize(); i++)
{
m_EDs[i]->CleanUp();
}
}
void CElementDescMnr::CleanTree()
{
for(int i = 0; i < m_EDs.GetSize(); i++)
{
m_EDs[i]->CleanUp();
m_EDs[i]->SetViewInTree(false);
}
for(int i = 0; i < m_stEDs.GetSize(); i++)
{
m_stEDs[i]->SetViewInTree(false);
}
}