ide, documentor: Fixed more 'long' warnings
[sdk] / documentor / src / Documentor.ec
1 import "ecere"
2 import "ec"
3 import "HTMLView"
4 import "IDESettings"
5 import "SettingsDialog"
6
7 static Context globalContext { };
8 static OldList defines { };
9 static OldList imports { };
10 static NameSpace globalData;
11 static OldList excludedSymbols { offset = (uint)&((Symbol)0).left }; 
12
13 #define UTF8_NUM_BYTES(x)  (__extension__({ byte b = x; (b & 0x80 && b & 0x40) ? ((b & 0x20) ? ((b & 0x10) ? 4 : 3) : 2) : 1; }))
14
15 default:
16 /*extern */int __ecereVMethodID_class_OnGetString;
17 private:
18
19
20 static void Dummy()
21 {
22 int a;
23 a.OnGetString(null, null, null);
24 }
25
26 static bool editing = true;
27
28 enum CodeObjectType { typeClass, typeData, typeMethod, typeEvent, typeProperty, typeNameSpace, typeDataType, typeEnumValue, typeDataPrivate, typeMethodPrivate, typePropertyPrivate };
29
30 static char * iconNames[CodeObjectType] = 
31 {
32    "<:ecere>constructs/class.png",
33    "<:ecere>constructs/data.png",
34    "<:ecere>constructs/method.png",
35    "<:ecere>constructs/event.png",
36    "<:ecere>constructs/property.png",
37    "<:ecere>constructs/namespace.png",
38    "<:ecere>constructs/dataType.png",
39    "<:ecere>constructs/enumValue.png",
40    "<:ecere>constructs/dataPrivate.png",
41    "<:ecere>constructs/methodPrivate.png",
42    "<:ecere>constructs/propertyPrivate.png"
43 };
44
45 IDESettings settings { }; // instantiate the IDESettings class from the IDESettings.ec file. Do this at a global level so that all methods can access settings.
46
47 IDESettingsContainer settingsContainer
48 {
49    driver = "JSON";
50    data = settings;
51    dataOwner = &settings;
52 };
53
54 // WARNING : This function expects a null terminated string since it recursively concatenate...
55 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
56 {
57    if(type)
58    {
59       switch(type.kind)
60       {
61          case classType:
62             if(type._class && type._class.string)
63             {
64                if(fullName)
65                   strcat(string, type._class.string);
66                else
67                {
68                   if(type._class.registered)
69                   {
70                      char hex[20];
71                      sprintf(hex, "%p", type._class.registered);
72                      strcat(string, "<a href=\"api://");
73                      strcat(string, hex);
74                      strcat(string, "\" style=\"text-decoration: none;\">");
75                      strcat(string, type._class.registered.name);
76                      strcat(string, "</a>");
77                   }
78                   else
79                      strcat(string, type._class.string);                     
80                }
81             }
82             break;
83          case pointerType:
84          {
85             /*Type funcType;
86             for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
87             if(funcType && funcType.kind == functionType)
88             {
89                Type param;
90                DocPrintType(funcType.returnType, string, false, fullName);
91                strcat(string, "(*");
92                if(printName || funcType.thisClass)
93                {
94                   strcat(string, " ");
95                   if(funcType.thisClass)
96                   {
97                      strcat(string, funcType.thisClass.string);
98                      strcat(string, "::");
99                   }
100                   if(type.name)
101                      strcat(string, type.name);
102                }
103                strcat(string, ")(");
104                for(param = funcType.params.first; param; param = param.next)
105                {
106                   DocPrintType(param, string, false, fullName);
107                   if(param.next) strcat(string, ", ");
108                }
109                strcat(string, ")");               
110             }
111             else*/
112             {
113                _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
114                if(string[strlen(string)-1] == '(')
115                   strcat(string, "*");
116                else
117                   strcat(string, " *");
118             }
119             break;
120          }
121          case voidType: strcat(string, "void"); break;
122          case intType:  strcat(string, type.isSigned ? "int" : "uint"); break;
123          case int64Type:  strcat(string, type.isSigned ? "int64" : "uint64"); break;
124          case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
125          case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
126          case floatType: strcat(string, "float"); break;
127          case doubleType: strcat(string, "double"); break;
128          case structType:
129             if(type.enumName)
130             {
131                strcat(string, "struct ");
132                strcat(string, type.enumName);
133             }
134             else if(type.typeName)
135             {
136                strcat(string, type.typeName);
137             }
138             else
139             {
140                /*
141                strcat(string, "struct ");
142                strcat(string,"(unnamed)");
143                */
144                Type member;
145                strcat(string, "struct {");
146                for(member = type.members.first; member; member = member.next)
147                {
148                   DocPrintType(member, string, true, fullName);
149                   strcat(string,"; ");
150                }
151                strcat(string,"}");
152             }
153             break;
154          case unionType:
155             if(type.enumName)
156             {
157                strcat(string, "union ");
158                strcat(string, type.enumName);
159             }
160             else if(type.typeName)
161             {
162                strcat(string, type.typeName);
163             }
164             else
165             {
166                strcat(string, "union ");
167                strcat(string,"(unnamed)");
168             }
169             break;
170          case enumType:
171             if(type.enumName)
172             {
173                strcat(string, "enum ");
174                strcat(string, type.enumName);
175             }
176             else if(type.typeName)
177             {
178                strcat(string, type.typeName);
179             }
180             else
181                strcat(string, "enum");
182             break;
183          case functionType:
184          {
185             if(printFunction)
186             {
187                if(type.dllExport)
188                   strcat(string, "dllexport ");
189                DocPrintType(type.returnType, string, false, fullName);
190                strcat(string, " ");
191             }
192             
193             // DANGER: Testing This
194             if(printName)
195             {
196                if(type.name)
197                {
198                   if(fullName)
199                      strcat(string, type.name);
200                   else
201                   {
202                      char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
203                      if(name) name += 2; else name = type.name;
204                      strcat(string, "<b>");
205                      strcat(string, name);
206                      strcat(string, "</b>");
207                   }
208                }
209                else
210                {
211                   printf("");
212                }
213             }
214
215             if(printFunction)
216             {
217                Type param;
218                strcat(string, "(");
219                for(param = type.params.first; param; param = param.next)
220                {
221                   DocPrintType(param, string, true, fullName);
222                   if(param.next) strcat(string, ", ");
223                }
224                strcat(string, ")");
225             }
226             break;
227          }
228          case arrayType:
229          {
230             /*Type funcType;
231             for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
232             if(funcType && funcType.kind == functionType)
233             {
234                Type param;
235                DocPrintType(funcType.returnType, string, false, fullName);
236                strcat(string, "(*");
237                if(printName || funcType.thisClass)
238                {
239                   strcat(string, " ");
240                   if(funcType.thisClass)
241                   {
242                      strcat(string, funcType.thisClass.string);
243                      strcat(string, "::");
244                   }
245                   if(type.name)
246                      strcat(string, type.name);
247                }
248                strcat(string, ")(");
249                for(param = funcType.params.first; param; param = param.next)
250                {
251                   DocPrintType(param, string, false, fullName);
252                   if(param.next) strcat(string, ", ");
253                }
254                strcat(string, ")");               
255             }
256             else*/
257             {
258                char baseType[1024], size[256];
259                Type arrayType = type;
260                baseType[0] = '\0';
261                size[0] = '\0';
262
263                while(arrayType.kind == TypeKind::arrayType)
264                {
265                   strcat(size, "[");
266                   if(arrayType.enumClass)
267                      strcat(size, arrayType.enumClass.string);
268                   else if(arrayType.arraySizeExp)
269                      PrintExpression(arrayType.arraySizeExp, size);
270                   //sprintf(string, "%s[%s]", baseType, size); 
271                   strcat(size, "]");
272
273                   arrayType = arrayType.arrayType;
274                }
275                _PrintType(arrayType, baseType, printName, printFunction, fullName);
276                strcat(string, baseType);
277                strcat(string, size);
278             }
279
280             /*
281                DocPrintType(type.arrayType, baseType, printName, fullName);
282                if(type.enumClass)
283                   strcpy(size, type.enumClass.string);
284                else if(type.arraySizeExp)
285                   PrintExpression(type.arraySizeExp, size);
286                //sprintf(string, "%s[%s]", baseType, size); 
287                strcat(string, baseType);
288                strcat(string, "[");
289                strcat(string, size); 
290                strcat(string, "]");
291                */
292
293             printName = false;
294             break;
295          }
296          case ellipsisType:
297             strcat(string, "...");
298             break;
299          case methodType:
300             _PrintType(type.method.dataType, string, false, printFunction, fullName);
301             break;
302          case subClassType:
303             strcat(string, "subclass(");
304             strcat(string, type._class ? type._class.string : "int");
305             strcat(string, ")");                  
306             break;
307          default:
308             printf("");
309       }
310       if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
311       {
312          strcat(string, " ");
313          strcat(string, type.name);
314       }
315    }
316 }
317
318 void DocPrintType(Type type, char * string, bool printName, bool fullName)
319 {
320    Type funcType;
321    for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
322    if(funcType && funcType.kind == functionType && type != funcType)
323    {
324       char typeString[1024];
325       Type param;
326
327       DocPrintType(funcType.returnType, string, false, fullName);
328       strcat(string, "(");
329       _PrintType(type, string, printName, false, fullName);
330       strcat(string, ")");
331       /*
332       if(type.name)
333          strcat(string, type.name);
334       else
335       {
336          printf("");
337       }
338       */
339       strcat(string, "(");
340       for(param = funcType.params.first; param; param = param.next)
341       {
342          DocPrintType(param, string, true, fullName);
343          if(param.next) strcat(string, ", ");
344       }
345       strcat(string, ")");
346    }
347    else
348       _PrintType(type, string, printName, true, fullName);
349 }
350
351 void AddComponents(Module module, bool isDll)
352 {
353    DataRow row = null;
354    SubModule m;
355
356    if(module.name && (!strcmp(module.name, "ecere") || !strcmp(module.name, "ecereCOM")))
357    {
358       row = mainForm.browser.AddRow();
359       row.SetData(null, APIPageNameSpace { name = "ecereCOM", nameSpace = &module.application.systemNameSpace });
360       row.tag = (int)null;
361       AddNameSpace(row, null, module.application.systemNameSpace, null, "", !isDll);
362    }
363
364    for(m = module.modules.first; m; m = m.next)
365    {
366       if(m.importMode == publicAccess || !isDll)
367          AddComponents(m.module, true);
368    }
369
370    // PUT MODULE DESCRIPTION HERE
371    if(module.name && strcmp(module.name, "ecereCOM"))
372    {
373       row = mainForm.browser.AddRow();
374       row.SetData(null, APIPageNameSpace { name = module.name, module = module, nameSpace = &module.publicNameSpace });
375       row.tag = (int)module;
376       AddNameSpace(row, module, module.publicNameSpace, null /*module.application.systemNameSpace*/, "", !isDll);
377       if(!isDll)
378          AddNameSpace(row, module, module.privateNameSpace, null /*module.application.systemNameSpace*/, "", !isDll);
379    }
380 }
381
382 class APIPage
383 {
384 public:
385    char * name;
386    APIPage page;
387    char * label;
388    bool showPrivate;
389
390    char * OnGetString(char * tempString, void * fieldData, bool * needClass)
391    {
392       return name;
393    }
394
395    virtual void Generate(File f)
396    {
397       page.Generate(f);
398    }
399 };
400
401 enum DocumentationType
402 {
403    nameSpaceDoc,
404    classDoc,
405    functionDoc,
406    methodDoc
407 };
408
409 enum DocumentationItem
410 {
411    description,
412    usage,
413    remarks,
414    example,
415    seeAlso,
416    enumerationValue,
417    definition,
418    conversion,
419    memberDescription,
420    propertyDescription,
421    parameter,
422    returnValue
423 };
424
425 static void FigureFileName(char * fileName, Module module, DocumentationType type, void * object, DocumentationItem item, void * data)
426 {
427    NameSpace * nameSpace, * ns;
428    Class cl = null;
429    Method method = null;
430    GlobalFunction function = null;
431    char nsName[1024], temp[1024];
432    char docFile[1024];
433
434
435    switch(type)
436    {
437       case nameSpaceDoc: nameSpace = object; break;
438       case classDoc:     cl = (Class)object; nameSpace = cl.nameSpace; break;
439       case functionDoc:  function = object; nameSpace = function.nameSpace; break;
440       case methodDoc:    method = object; cl = method._class; nameSpace = cl.nameSpace; break;
441    }
442
443    nsName[0] = 0;
444    ns = nameSpace;
445    while(ns && ns->name)
446    {
447       strcpy(temp, "namespaces/");
448       strcat(temp, ns->name);
449       strcat(temp, "/");
450       strcat(temp, nsName);
451       strcpy(nsName, temp);
452       ns = ns->parent;
453    }
454    sprintf(docFile, "%s.eCdoc", (!module || !module.name || !strcmp(nsName, "namespaces/ecere/namespaces/com")) ? "ecereCOM" : module.name);
455
456    sprintf(fileName, "<%s/%s>", settings.docDir, docFile); // Note that in the ecereIDE.ini file, there can be no quotes around the path, and there needs to be the final backslash. Otherwise this does not work.
457    strcat(fileName, nsName);
458
459    if(cl)
460    {
461       strcat(fileName, "classes/");
462       strcat(fileName, cl.name);
463       strcat(fileName, "/");
464    }
465
466    if(method)
467    {
468       strcat(fileName, "methods/");
469       strcat(fileName, method.name);
470       strcat(fileName, "/");
471    }
472    else if(function)
473    {
474       char * name = RSearchString(function.name, "::", strlen(function.name), true, false);
475       if(name) name += 2; else name = function.name;
476       strcat(fileName, "functions/");
477       strcat(fileName, name);
478       strcat(fileName, "/");
479    }
480
481    switch(item)
482    {
483       case description: strcat(fileName, "description"); break;
484       case usage: strcat(fileName, "usage"); break;
485       case remarks: strcat(fileName, "remarks"); break;
486       case example: strcat(fileName, "example"); break;
487       case seeAlso: strcat(fileName, "seeAlso"); break;
488       case returnValue: strcat(fileName, "returnValue"); break;
489       case enumerationValue: 
490          strcat(fileName, "enumeration values/");
491          strcat(fileName, ((NamedLink)data).name);
492          break;
493       case definition:
494          strcat(fileName, "definitions/");
495          strcat(fileName, ((Definition)data).name);
496          break;
497       case conversion:
498       {
499          char * name = RSearchString(((Property)data).name, "::", strlen(((Property)data).name), true, false);
500          if(name) name += 2; else name = ((Property)data).name;
501          strcat(fileName, "conversions/");
502          strcat(fileName, name);
503          break;
504       }
505       case memberDescription:
506          strcat(fileName, "data members/");
507          strcat(fileName, ((DataMember)data).name);
508          break;
509       case propertyDescription:
510          strcat(fileName, "properties/");
511          strcat(fileName, ((Property)data).name);
512          break;
513       case parameter:
514       {
515          int count;
516          char name[1024];
517          Type prev;
518          strcat(fileName, "parameters/");
519          for(prev = data, count = 0; prev; prev = prev.prev, count++);
520          sprintf(name, "%s.%d", ((Type)data).name, count);
521          strcat(fileName, name);
522          break;
523       }
524    }
525 }
526
527 static char * ReadDoc(Module module, DocumentationType type, void * object, DocumentationItem item, void * data)
528 {
529    char fileName[MAX_LOCATION];
530    String contents = null;
531    File file;
532
533    FigureFileName(fileName, module, type, object, item, data);
534    file = FileOpen(fileName, read);
535    if(file)
536    {
537       uint len;
538       if((len = file.GetSize()))
539       {
540          contents = new char[len+1];
541          file.Read(contents, 1, len);
542          contents[len] = '\0';      
543       }
544       delete file;
545    }
546    if(contents)
547    {
548       int c;
549       for(c = 0; contents[c]; c++)
550          if(!isspace(contents[c])) break;
551       if(!contents[c])
552          delete contents;      
553    }
554    if(editing && !contents)
555       contents = CopyString($"[Add Text]");
556    return contents;
557 }
558
559 class APIPageNameSpace : APIPage
560 {
561    NameSpace * nameSpace;
562    Module module;
563    
564    void Generate(File f)
565    {
566       char string[1024];
567       char nsName[1024], temp[1024];
568       NameSpace * ns;
569       BTNamedLink link;
570       uint tag;
571
572       nsName[0] = 0;
573       ns = nameSpace;
574       while(ns && ns->name)
575       {
576          strcpy(temp, ns->name);
577          if(nsName[0]) strcat(temp, "::");
578          strcat(temp, nsName);
579          strcpy(nsName, temp);
580          ns = ns->parent;
581       }
582       // Generate Class Page
583       f.Printf($"<HTML><HEAD><TITLE>API Reference</TITLE></HEAD>\n<BODY><FONT SIZE=\"3\">\n");
584       if(nsName[0])
585       {
586          f.Printf("<FONT FACE=\"Arial\" SIZE=\"6\">%s</FONT><br><br>\n", nsName );
587          tag = (uint)nameSpace;
588          f.Printf($"Module: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", (module && module.name) ? module : null, (!module || !module.name || !strcmp(nsName, "ecere::com")) ? "ecereCOM" : module.name);
589       }
590       else
591       {
592          tag = (uint)((!module || !module.name || !strcmp(nsName, "ecere::com") ? null : module));
593          f.Printf($"<FONT FACE=\"Arial\" SIZE=\"6\">Module %s</FONT><br>\n", (!module || !module.name || !strcmp(nsName, "ecere::com")) ? "ecereCOM" : module.name);
594       }
595
596       nsName[0] = 0;
597       ns = nameSpace->parent;
598       while(ns && ns->name)
599       {
600          strcpy(temp, ns->name);
601          if(nsName[0]) strcat(temp, "::");
602          strcat(temp, nsName);
603          strcpy(nsName, temp);
604          ns = ns->parent;
605       }
606       if(nsName[0]) 
607          f.Printf($"Parent namespace: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", nameSpace->parent, nsName);
608
609       f.Printf("<br>");
610       {
611          char * desc = ReadDoc(module, nameSpaceDoc, nameSpace, description, null);
612          if(desc)
613          {
614             f.Printf($"<H3>Description</H3><br><br>\n");
615             if(editing)
616             {
617                char fileName[MAX_LOCATION];
618                FigureFileName(fileName, module, nameSpaceDoc, nameSpace, description, null);
619                f.Printf("<a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
620                f.Puts(desc);
621                f.Printf("</a><br><br>");
622             }
623             else
624                f.Printf("%s<br><br>", desc);
625             delete desc;
626          }
627       }
628
629       if(nameSpace->nameSpaces.first)
630       {
631          bool first = true;
632          for(ns = (NameSpace *)nameSpace->nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
633          {
634             char * desc = ReadDoc(module, nameSpaceDoc, ns, description, null);
635             if(first)
636             {
637                f.Printf($"<H3>Sub Namespaces</H3><br><br>\n");
638                f.Printf("<TABLE >\n");
639                first = false;
640             }
641             f.Printf("<TR>");
642             f.Printf("<TD valign=top height=22 nowrap=1><img valign=center src=\"%s\">&nbsp;&nbsp;<a href=\"api://%p\" style=\"text-decoration: none;\">%s</a></TD>", iconNames[typeNameSpace], ns, ns->name);
643             if(desc)
644             {
645                if(editing)
646                {
647                   char fileName[MAX_LOCATION];
648                   FigureFileName(fileName, module, nameSpaceDoc, ns, description, null);
649                   f.Printf("<TD valign=top height=22> <a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
650                   f.Puts(desc);
651                   f.Printf("</a></TD>");
652                }
653                else
654                   f.Printf("<TD valign=top height=22> %s</TD>", desc);
655                delete desc;
656             }
657             f.Printf("</TR><br>\n");
658          }
659          if(!first)
660             f.Printf("</TABLE><br>\n");
661       }
662
663       if(nameSpace->classes.first)
664       {
665          bool first = true;
666          for(link = (BTNamedLink)nameSpace->classes.first; link; link = (BTNamedLink)((BTNode)link).next)
667          {
668             Class cl = link.data;
669             if(!cl.templateClass)
670             {
671                char * desc = ReadDoc(module, classDoc, cl, description, null);
672
673                if(first)
674                {
675                   f.Printf($"<a name=Classes></a><H3>Classes</H3><br><br>\n");
676                   f.Printf("<TABLE >\n");
677                   first = false;
678                }
679
680                f.Printf("<TR>");
681
682                f.Printf("<TD valign=top height=22 nowrap=1><img valign=center src=\"%s\">&nbsp;&nbsp;<a href=\"api://%p\" style=\"text-decoration: none;\">%s</a></TD>", (cl.type == enumClass || cl.type == unitClass || cl.type == systemClass) ? iconNames[typeDataType] : iconNames[typeClass], cl, cl.name);
683                if(desc)
684                {
685                   if(editing)
686                   {
687                      char fileName[MAX_LOCATION];
688                      FigureFileName(fileName, module, classDoc, cl, description, null);
689                      f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
690                      f.Puts(desc);
691                      f.Printf("</a></TD>");
692                   }
693                   else
694                      f.Printf("<TD valign=top height=22>%s</TD>", desc);
695                   delete desc;
696                }            
697                f.Printf("</TR>\n");
698             }
699          }
700          if(!first)
701             f.Printf("</TABLE><br>\n");
702       }
703
704       if(nameSpace->functions.first)
705       {
706          bool first = true;
707          for(link = (BTNamedLink)nameSpace->functions.first; link; link = (BTNamedLink)((BTNode)link).next)
708          {
709             GlobalFunction function = link.data;
710             char * desc = ReadDoc(module, functionDoc, function, description, null);
711             char * name = RSearchString(function.name, "::", strlen(function.name), true, false);
712             if(name) name += 2; else name = function.name;
713             if(first)
714             {
715                f.Printf($"<a name=Functions></a><H3>Functions</H3><br><br>\n");
716                f.Printf("<TABLE >\n");
717                first = false;
718             }
719             f.Printf("<TR>");
720             f.Printf("<TD valign=top height=22 nowrap=1><img valign=center src=\"%s\">&nbsp;&nbsp;<a href=\"api://%p\" style=\"text-decoration: none;\">%s</a></TD>", iconNames[typeMethod], function, name);
721             if(desc)
722             {
723                if(editing)
724                {
725                   char fileName[MAX_LOCATION];
726                   FigureFileName(fileName, module, functionDoc, function, description, null);
727                   f.Printf("<TD valign=top height=22> <a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
728                   f.Puts(desc);
729                   f.Printf("</a></TD>");
730                }
731                else
732                   f.Printf("<TD valign=top height=22> %s</TD>", desc);
733                delete desc;
734             }
735             f.Printf("</TR><br>\n");
736          }
737          if(!first)
738             f.Printf("</TABLE><br>\n");
739       }
740
741       if(nameSpace->defines.first)
742       {
743          bool first = true;
744          for(link = (BTNamedLink)nameSpace->defines.first; link; link = (BTNamedLink)((BTNode)link).next)
745          {
746             DefinedExpression def = link.data;
747             char * desc = ReadDoc(module, nameSpaceDoc, nameSpace, definition, def);
748             if(first)
749             {
750                f.Printf($"<a name=Definitions></a><H3>Definitions</H3><br><br>\n");
751                f.Printf("<TABLE >\n");
752                first = false;
753             }
754             f.Printf("<TR>");
755             f.Printf("<TD valign=top height=22 nowrap=1><a name=%p></a><img valign=center src=\"%s\">&nbsp;&nbsp;%s</TD>", def, iconNames[typeData], def.name);
756             f.Printf("<TD valign=top height=22>%s</TD>", def.value);
757             if(desc)
758             {
759                if(editing)
760                {
761                   char fileName[MAX_LOCATION];
762                   FigureFileName(fileName, module, nameSpaceDoc, nameSpace, definition, def);
763                   f.Printf("<TD valign=top height=22> <a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
764                   f.Puts(desc);
765                   f.Printf("</a></TD>");
766                }
767                else
768                   f.Printf("<TD valign=top height=22> %s</TD>", desc);
769                delete desc;
770             }
771             f.Printf("</TR><br>\n");
772          }
773          if(!first)
774             f.Printf("</TABLE><br>\n");
775       }
776
777       f.Printf("</FONT></BODY></HTML>\n");
778    }   
779 }
780
781 class APIPageClass : APIPage
782 {
783    Class cl;
784
785    void Generate(File f)
786    {
787       char string[1024];
788       Method method;
789       Property prop;
790       DataMember member;
791       char nsName[1024], temp[1024];
792       NameSpace * ns = cl.nameSpace;
793       Module module = cl.module;
794
795       nsName[0] = 0;
796       while(ns && ns->name)
797       {
798          strcpy(temp, ns->name);
799          if(nsName[0]) strcat(temp, "::");
800          strcat(temp, nsName);
801          strcpy(nsName, temp);
802          ns = ns->parent;
803       }
804       // Generate Class Page
805       f.Printf($"<HTML><HEAD><TITLE>API Reference</TITLE></HEAD>\n<BODY><FONT SIZE=\"3\">\n");
806       f.Printf("<FONT FACE=\"Arial\" SIZE=\"6\">%s</FONT><br><br>\n", name);
807
808       f.Printf($"Module: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", (module && module.name) ? module : null, (!module || !module.name || !strcmp(nsName, "ecere::com")) ? "ecereCOM" : module.name);
809       if(nsName[0]) 
810          f.Printf($"Namespace: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", cl.nameSpace, nsName);
811
812       {
813          char * classType = null;
814          switch(cl.type)
815          {
816             case bitClass:
817                classType = $"Bit Collection";
818                break;
819             case enumClass:
820                classType = $"Enumeration";
821                break;
822             case structClass:
823                classType = $"Structure";
824                break;
825             case normalClass:
826                classType = $"Class";
827                break;
828             case noHeadClass:
829                classType = $"Class (No header)";
830                break;
831             case unitClass:
832                classType = $"Unit";
833                break;
834             case systemClass:
835                classType = $"Basic Data Type";
836                break;
837          }
838          f.Printf($"Type: %s<br>\n", classType);
839       }
840       
841       if(cl.type != systemClass && cl.base)
842       {
843          f.Printf($"Base Class: ");
844          if(!strcmp(cl.base.name, "struct") || !strcmp(cl.base.name, "class"))
845          {
846             f.Printf(cl.type == bitClass ? cl.dataTypeString : $"None");
847          }
848          else if(cl.type == enumClass && !strcmp(cl.base.name, "enum"))
849             f.Printf("%s", cl.dataTypeString);
850          else
851             f.Printf("<a href=\"api://%p\" style=\"text-decoration: none;\">%s</a>", cl.base.templateClass ? cl.base.templateClass : cl.base, cl.base.name);
852          f.Printf("<br>\n");
853       }
854
855       {
856          char * desc = ReadDoc(module, classDoc, cl, description, null);
857          if(desc)
858          {
859             f.Printf($"<br><H3>Description</H3><br><br>\n");
860             if(editing)
861             {
862                char fileName[MAX_LOCATION];
863                FigureFileName(fileName, module, classDoc, cl, description, null);
864                f.Printf("<a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
865                f.Puts(desc);
866                f.Printf("</a><br><br>");
867             }
868             else
869                f.Printf("%s<br><br>", desc);
870             delete desc;
871          }
872       }
873
874       if(cl.type == enumClass)
875       {
876          EnumClassData enumeration = (EnumClassData)cl.data;
877          if(enumeration.values.first)
878          {
879             NamedLink item;
880                         
881             f.Printf($"<a name=EnumerationValues></a><H3>Enumeration Values</H3><br><br>\n");
882             f.Printf("<TABLE >\n");
883
884             for(item = enumeration.values.first; item; item = item.next)
885             {
886                char * desc = ReadDoc(module, classDoc, cl, enumerationValue, item);
887                bool needClass = true;
888                Class dataClass;
889                Class base = cl;
890                char tempString[1024];
891                String s;
892                while(base.type == enumClass) base = base.base;
893
894                if(base.type == systemClass ||
895                   (base.type == bitClass && base.membersAndProperties.first && !strcmp(cl.fullName, ((DataMember)base.membersAndProperties.first).dataTypeString)))
896                {
897                   if(!base.dataType)
898                      base.dataType = ProcessTypeString(base.dataTypeString, false);
899
900                   if(base.dataType.kind != classType)
901                   {
902                      char string[256];
903                      Symbol classSym;
904                      string[0] = '\0';
905                      PrintType(base.dataType, string, false, true);
906                      classSym = FindClass(string);
907                      dataClass = classSym ? classSym.registered : null;
908                   }
909                   else
910                      dataClass = base.dataType._class ? base.dataType._class.registered : null;
911                }
912                else
913                   dataClass = base;                  
914                
915                f.Printf("<TR>");
916                f.Printf("<TD valign=top height=22 nowrap=1><a name=%p></a><img valign=center src=\"%s\">&nbsp;&nbsp;%s</TD>", item, iconNames[typeEnumValue], item.name);
917                if(dataClass.type == systemClass)
918                {
919                   needClass = false;
920                   s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)dataClass._vTbl[__ecereVMethodID_class_OnGetString])(dataClass, &item.data, tempString, null, &needClass);
921                }
922                else
923                   s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)eSystem_FindClass(componentsApp, "class")._vTbl[__ecereVMethodID_class_OnGetString])(dataClass, &item.data, tempString, null, &needClass);
924                if(needClass)
925                   f.Printf("<TD valign=top height=22 nowrap=1>%s { %s }</TD>", dataClass.name, s);
926                else
927                   f.Printf("<TD valign=top height=22 nowrap=1>%s</TD>", s);
928                if(desc)
929                {
930                   if(editing)
931                   {
932                      char fileName[MAX_LOCATION];
933                      FigureFileName(fileName, module, classDoc, cl, enumerationValue, item);
934                      f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
935                      f.Puts(desc);
936                      f.Printf("</a></TD>");
937                   }
938                   else
939                      f.Printf("<TD valign=top height=22>%s</TD>", desc);
940                   delete desc;
941                }
942                f.Printf("</TR>");
943             }
944             f.Printf("</TABLE><BR>\n");
945          }
946       }
947
948       if(cl.conversions.first)
949       {
950          f.Printf($"<a name=Conversions></a><H3>Conversions</H3><br><br>\n");
951          f.Printf("<TABLE >\n");
952          for(prop = cl.conversions.first; prop; prop = prop.next)
953          {
954             if((prop.memberAccess == publicAccess || (prop.memberAccess == privateAccess && showPrivate)) && prop.name)
955             {
956                char * desc = ReadDoc(module, classDoc, cl, conversion, prop);
957                DataRow mRow;
958                char * name;
959                Type type = ProcessTypeString(prop.name, false);
960                name = RSearchString(prop.name, "::", strlen(prop.name), true, false);
961                if(name) name += 2; else name = prop.name;
962
963                f.Printf("<TR>");
964                
965                string[0] = 0;
966                DocPrintType(type, string, true, false);
967                
968                f.Printf("<TD valign=top height=22 nowrap=1><a name=%p></a><img valign=center src=\"%s\">&nbsp;&nbsp;%s</TD>", prop, iconNames[typeDataType], string);
969                if(desc)
970                {
971                   if(editing)
972                   {
973                      char fileName[MAX_LOCATION];
974                      FigureFileName(fileName, module, classDoc, cl, conversion, prop);
975                      f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
976                      f.Puts(desc);
977                      f.Printf("</a></TD>");
978                   }
979                   else
980                      f.Printf("<TD valign=top height=22>%s</TD>", desc);
981                   delete desc;
982                }
983                
984                f.Printf("</TR>\n");
985                
986                FreeType(type);
987             }
988          }
989          f.Printf("</TABLE><br>\n");
990       }
991
992       if(cl.membersAndProperties.first)
993       {
994          bool first = true;
995          for(prop = (Property)cl.membersAndProperties.first; prop; prop = prop.next)
996          {
997             if(prop.memberAccess == publicAccess || (prop.memberAccess == privateAccess && showPrivate))
998             {
999                if(first)
1000                {
1001                   f.Printf($"<a name=Members></a><H3>Properties and Members</H3><br><br>\n");
1002                   f.Printf("<TABLE >\n");
1003                   first = false;
1004                }
1005
1006                if(prop.isProperty)
1007                {
1008                   char * desc = ReadDoc(module, classDoc, cl, propertyDescription, prop);
1009                   if(!prop.dataType)
1010                      prop.dataType = ProcessTypeString(prop.dataTypeString, false);
1011
1012                   f.Printf("<TR>");
1013                   string[0] = 0;
1014                   DocPrintType(prop.dataType, string, true, false);
1015
1016                   f.Printf("<TD valign=top height=22 nowrap=1><a name=%p></a><img valign=center src=\"%s\">&nbsp;&nbsp;%s</TD>", prop, iconNames[typeProperty], prop.name);
1017                   f.Printf("<TD valign=top height=22 nowrap=1>%s</TD>", string);
1018                   if(desc)
1019                   {
1020                      if(editing)
1021                      {
1022                         char fileName[MAX_LOCATION];
1023                         FigureFileName(fileName, module, classDoc, cl, propertyDescription, prop);
1024                         f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1025                         f.Puts(desc);
1026                         f.Printf("</a></TD>");
1027                      }
1028                      else
1029                         f.Printf("<TD valign=top height=22>%s</TD>", desc);
1030                      delete desc;
1031                   }
1032                   f.Printf("</TR>\n");
1033                }
1034                else
1035                {
1036                   AddDataMemberToPage(f, (DataMember)prop, 0, showPrivate);
1037                }
1038             }
1039          }
1040          if(!first)
1041             f.Printf("</TABLE><br>\n");
1042       }
1043
1044       if(cl.methods.first)
1045       {
1046          bool first = true;
1047          // Virtual Methods
1048          for(method = (Method)cl.methods.first; method; method = (Method)((BTNode)method).next)
1049          {
1050             if((method.memberAccess == publicAccess || (method.memberAccess == privateAccess && showPrivate)) && method.type == virtualMethod)
1051             {
1052                char * desc = ReadDoc(module, methodDoc, method, description, null);
1053                if(first)
1054                {
1055                   f.Printf($"<a name=VirtualMethods></a><H3>Virtual Methods</H3><br><br>\n");
1056                   f.Printf("<TABLE >\n");
1057                   first = false;
1058                }
1059                if(!method.dataType)
1060                   ProcessMethodType(method);
1061
1062                f.Printf("<TR>");
1063                f.Printf("<TD valign=top height=22 nowrap=1><img valign=center src=\"%s\">&nbsp;&nbsp;<a href=\"api://%p\" style=\"text-decoration: none;\">%s</a></TD>", method.dataType.thisClass ? iconNames[typeEvent] : iconNames[typeMethod], method, method.name);
1064                if(desc)
1065                {
1066                   if(editing)
1067                   {
1068                      char fileName[MAX_LOCATION];
1069                      FigureFileName(fileName, module, methodDoc, method, description, null);
1070                      f.Printf("<TD valign=top height=22> <a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1071                      f.Puts(desc);
1072                      f.Printf("</a></TD>");
1073                   }
1074                   else
1075                      f.Printf("<TD valign=top height=22> %s</TD>", desc);
1076                   delete desc;
1077                }
1078                f.Printf("</TR><br>\n");
1079             }
1080          }
1081          if(!first)
1082             f.Printf("</TABLE><br>\n");
1083
1084          // Non-Virtual Methods
1085          first = true;
1086          for(method = (Method)cl.methods.first; method; method = (Method)((BTNode)method).next)
1087          {
1088             if((method.memberAccess == publicAccess || (method.memberAccess == privateAccess && showPrivate)) && method.type != virtualMethod)
1089             {
1090                char * desc = ReadDoc(module, methodDoc, method, description, null);
1091                if(first)
1092                {
1093                   f.Printf($"<a name=Methods></a><H3>Non-Virtual Methods</H3><br><br>\n");
1094                   f.Printf("<TABLE >\n");
1095                   first = false;
1096                }
1097
1098                if(!method.dataType)
1099                   ProcessMethodType(method);
1100
1101                f.Printf("<TR>");
1102                f.Printf("<TD valign=top height=22 nowrap=1><img valign=center src=\"%s\">&nbsp;&nbsp;<a href=\"api://%p\" style=\"text-decoration: none;\">%s</a></TD>", iconNames[typeMethod], method, method.name);
1103                if(desc)
1104                {
1105                   if(editing)
1106                   {
1107                      char fileName[MAX_LOCATION];
1108                      FigureFileName(fileName, module, methodDoc, method, description, null);
1109                      f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1110                      f.Puts(desc);
1111                      f.Printf("</a></TD>");
1112                   }
1113                   else
1114                      f.Printf("<TD valign=top height=22>%s</TD>", desc);
1115                   delete desc;
1116                }
1117                
1118                f.Printf("</TR><br>\n");
1119             }
1120          }
1121          if(!first)
1122             f.Printf("</TABLE><br>\n");
1123       }
1124       {
1125          char * usageDoc = ReadDoc(module, classDoc, cl, usage, null);
1126          if(usageDoc)
1127          {
1128             f.Printf($"<H3>Usage</H3><br>\n");
1129             if(editing)
1130             {
1131                char fileName[MAX_LOCATION];
1132                FigureFileName(fileName, module, classDoc, cl, usage, null);
1133                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1134                f.Puts(usageDoc);
1135                f.Printf("</a>\n");
1136             }
1137             else
1138                f.Printf("<br>%s\n", usageDoc);
1139             f.Printf("<br><br>\n");
1140             delete usageDoc;
1141          }
1142       }
1143       {
1144          char * exampleDoc = ReadDoc(module, classDoc, cl, example, null);
1145          if(exampleDoc)
1146          {
1147             f.Printf($"<H3>Example</H3><br>\n");
1148             f.Printf($"<FONT face=\"Courier New\">\n");
1149             f.Printf("<br><TABLE >\n");
1150             if(editing)
1151             {
1152                char fileName[MAX_LOCATION];
1153                FigureFileName(fileName, module, classDoc, cl, example, null);
1154                f.Printf("<TR><TD><CODE><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1155                f.Puts(exampleDoc);
1156                f.Printf("</a></CODE></TD></TR>\n"); // bgcolor=#CFC9C0
1157             }
1158             else
1159                f.Printf("<TR><TD><CODE>%s</CODE></TD></TR>\n", exampleDoc);   // bgcolor=#CFC9C0
1160
1161             f.Printf("</TABLE></FONT>\n");
1162             f.Printf("<br>\n");
1163             delete exampleDoc;
1164          }
1165       }
1166       {
1167          char * remarksDoc = ReadDoc(module, classDoc, cl, remarks, null);
1168
1169          if(remarksDoc)
1170          {
1171             f.Printf($"<H3>Remarks</H3><br>\n");
1172             if(editing)
1173             {
1174                char fileName[MAX_LOCATION];
1175                FigureFileName(fileName, module, classDoc, cl, remarks, null);
1176                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1177                f.Puts(remarksDoc);
1178                f.Printf("</a>\n");
1179             }
1180             else
1181                f.Printf("<br>%s\n", remarksDoc);
1182             f.Printf("<br><br>\n");
1183             delete remarksDoc;
1184          }
1185       }
1186       
1187       if(cl.type != systemClass)
1188       {
1189          bool first = true;
1190          OldLink c;
1191          for(c = cl.derivatives.first; c; c = c.next)
1192          {
1193             Class deriv = c.data;
1194             // TO VERIFY: Does this properly check public status?
1195             if(eSystem_FindClass(componentsApp, deriv.fullName))
1196             {
1197                if(first)
1198                {
1199                   f.Printf($"<H3>Derived Classes</H3><br>\n");
1200                   f.Printf("<br>");
1201                   first = false;
1202                }
1203                else
1204                   f.Printf(", ");
1205                f.Printf("<a href=\"api://%p\" style=\"text-decoration: none;\">%s</a>", deriv, deriv.name);
1206              }            
1207          }
1208          if(!first)
1209             f.Printf("<br><br>\n");
1210       }
1211       {
1212          char * seeAlsoDoc = ReadDoc(module, classDoc, cl, seeAlso, null);
1213          if(seeAlsoDoc)
1214          {
1215             f.Printf($"<H3>See Also</H3><br>\n");
1216             if(editing)
1217             {
1218                char fileName[MAX_LOCATION];
1219                FigureFileName(fileName, module, classDoc, cl, seeAlso, null);
1220                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1221                f.Puts(seeAlsoDoc);
1222                f.Printf("</a>\n");
1223             }
1224             else
1225                f.Printf("<br>%s\n", seeAlsoDoc);
1226             f.Printf("<br><br>\n");
1227             delete seeAlsoDoc;
1228          }
1229       }
1230       f.Printf("</FONT></BODY></HTML>\n");
1231    }   
1232 }
1233
1234 class APIPageMethod : APIPage
1235 {
1236    Method method;
1237    void Generate(File f)
1238    {
1239       Class cl = method._class;
1240       char string[1024];
1241       Module module = cl.module;
1242       Type param;
1243       char nsName[1024], temp[1024];
1244       NameSpace * ns = cl.nameSpace;
1245
1246       nsName[0] = 0;
1247       while(ns && ns->name)
1248       {
1249          strcpy(temp, ns->name);
1250          if(nsName[0]) strcat(temp, "::");
1251          strcat(temp, nsName);
1252          strcpy(nsName, temp);
1253          ns = ns->parent;
1254       }
1255
1256       f.Printf($"<HTML><HEAD><TITLE>API Reference</TITLE></HEAD>\n<BODY><FONT SIZE=\"3\">\n");
1257       f.Printf("<FONT FACE=\"Arial\" SIZE=\"6\">%s</FONT><br><br>\n", name);
1258
1259       f.Printf($"Module: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", (module && module.name) ? module : null, (!module || !module.name || !strcmp(nsName, "ecere::com")) ? "ecereCOM" : module.name);
1260       if(nsName[0])
1261          f.Printf($"Namespace: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", cl.nameSpace, nsName);
1262       f.Printf("Class: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", cl, cl.name);
1263       if(method.dataType.staticMethod)
1264       {
1265          f.Printf($"this pointer class: None<br>\n");
1266       }
1267       else if(method.dataType.thisClass && method.dataType.thisClass.registered && (method.dataType.thisClass.registered != method._class || method.type == virtualMethod))
1268       {
1269          f.Printf($"this pointer class: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", method.dataType.thisClass.registered, method.dataType.thisClass.registered.name);
1270       }
1271
1272       // Generate Method Page
1273       string[0] = 0;
1274       if(!method.dataType.name)
1275          method.dataType.name = CopyString(method.name);
1276       DocPrintType(method.dataType, string, true, false);
1277       f.Printf("<br>%s", string);
1278
1279       {
1280          char * desc = ReadDoc(module, methodDoc, method, description, null);
1281          if(desc)
1282          {
1283             f.Printf($"<br><br><H3>Description</H3><br><br>\n");
1284             if(editing)
1285             {
1286                char fileName[MAX_LOCATION];
1287                FigureFileName(fileName, module, methodDoc, method, description, null);
1288                f.Printf("<a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1289                f.Puts(desc);
1290                f.Printf("</a>");
1291             }
1292             else
1293                f.Printf("%s", desc);
1294             delete desc;
1295          }
1296       }
1297
1298       f.Printf("<br><br>\n");
1299       if(method.dataType.params.first && ((Type)method.dataType.params.first).kind != voidType)
1300       {
1301          f.Printf($"<H3>Parameters</H3><br><br>\n");
1302       }
1303       if((method.dataType.returnType && method.dataType.returnType.kind != voidType) ||
1304          (method.dataType.params.first && ((Type)method.dataType.params.first).kind != voidType))
1305       {
1306          f.Printf("<TABLE  valign=center>\n");
1307       }
1308
1309       for(param = method.dataType.params.first; param; param = param.next)
1310       {
1311          // ADD DESCRIPTION HERE
1312          if(param.kind != voidType)
1313          {
1314             char * desc = ReadDoc(module, methodDoc, method, parameter, param);
1315             f.Printf("<TR>");
1316             string[0] = 0;
1317             DocPrintType(param, string, false, false);
1318
1319             f.Printf("<TD valign=top height=22 nowrap=1>%s&nbsp;</TD>\n", param.name ? param.name : "");
1320             f.Printf("<TD valign=top height=22 nowrap=1>%s&nbsp;</TD>\n", string);
1321             if(desc)
1322             {
1323                if(editing)
1324                {
1325                   char fileName[MAX_LOCATION];
1326                   FigureFileName(fileName, module, methodDoc, method, parameter, param);
1327                   f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1328                   f.Puts(desc);
1329                   f.Printf("s</a>&nbsp;</TD>\n");
1330                }
1331                else
1332                   f.Printf("<TD valign=top height=22>%s&nbsp;</TD>\n", desc);
1333                delete desc;
1334             }
1335             
1336             f.Printf("</TR>\n");
1337          }
1338       }
1339       if(method.dataType.returnType && method.dataType.returnType.kind != voidType)
1340       {
1341          char * desc = ReadDoc(module, methodDoc, method, returnValue, null);
1342          if(method.dataType.params.first && ((Type)method.dataType.params.first).kind != voidType)
1343          {
1344             f.Printf("<TR><TD>&nbsp;</TD></TR>");
1345          }
1346          f.Printf("<TR>");
1347          f.Printf($"<TD valign=top height=22 nowrap=1><B>Return Value</B></TD>\n");
1348          string[0] = 0;
1349          DocPrintType(method.dataType.returnType, string, false, false);
1350          f.Printf("<TD valign=top height=22>%s&nbsp;</TD>\n", string);
1351          if(desc)
1352          {
1353             if(editing)
1354             {
1355                char fileName[MAX_LOCATION];
1356                FigureFileName(fileName, module, methodDoc, method, returnValue, null);
1357                f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1358                f.Puts(desc);
1359                f.Printf("</a>&nbsp;</TD>\n");
1360             }
1361             else
1362                f.Printf("<TD valign=top height=22>%s&nbsp;</TD>\n", desc);
1363             delete desc;
1364          }
1365          f.Printf("</TR>\n");
1366          f.Printf("</TABLE>\n");
1367       }
1368       if((method.dataType.returnType && method.dataType.returnType.kind != voidType) ||
1369          (method.dataType.params.first && ((Type)method.dataType.params.first).kind != voidType))
1370       {
1371          f.Printf("</TABLE><br>\n");
1372       }
1373       {
1374          char * usageDoc = ReadDoc(module, methodDoc, method, usage, null);
1375          if(usageDoc)
1376          {
1377             f.Printf($"<H3>Usage</H3><br>\n");
1378             if(editing)
1379             {
1380                char fileName[MAX_LOCATION];
1381                FigureFileName(fileName, module, methodDoc, method, usage, null);
1382                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1383                f.Puts(usageDoc);
1384                f.Printf("</a>\n");
1385             }
1386             else
1387                f.Printf("<br>%s\n", usageDoc);
1388             f.Printf("<br><br>\n");
1389             delete usageDoc;
1390          }
1391       }
1392       {
1393          char * exampleDoc = ReadDoc(module, methodDoc, method, example, null);
1394          if(exampleDoc)
1395          {
1396             f.Printf($"<H3>Example</H3><br>\n");
1397             f.Printf($"<FONT face=\"Courier New\">\n");
1398             f.Printf("<br><TABLE >\n");
1399             if(editing)
1400             {
1401                char fileName[MAX_LOCATION];
1402                FigureFileName(fileName, module, methodDoc, method, example, null);
1403                f.Printf("<TR><TD><CODE><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1404                f.Puts(exampleDoc);
1405                f.Printf("</a></CODE></TD></TR>\n");   // bgcolor=#CFC9C0
1406             }
1407             else
1408                f.Printf("<TR><TD><CODE>%s</CODE></TD></TR>\n", exampleDoc);   // bgcolor=#CFC9C0
1409             f.Printf("</TABLE></FONT>\n");
1410             f.Printf("<br>\n");
1411             delete exampleDoc;
1412          }
1413       }
1414       {
1415          char * remarksDoc = ReadDoc(module, methodDoc, method, remarks, null);
1416          if(remarksDoc)
1417          {
1418             f.Printf($"<H3>Remarks</H3><br>\n");
1419             if(editing)
1420             {
1421                char fileName[MAX_LOCATION];
1422                FigureFileName(fileName, module, methodDoc, method, remarks, null);
1423                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1424                f.Puts(remarksDoc);
1425                f.Printf("</a>\n");
1426             }
1427             else
1428                f.Printf("<br>%s\n", method, remarksDoc);
1429             f.Printf("<br><br>\n");
1430             delete remarksDoc;
1431          }
1432       }
1433       {
1434          char * seeAlsoDoc = ReadDoc(module, methodDoc, method, seeAlso, null);
1435          if(seeAlsoDoc)
1436          {
1437             f.Printf($"<H3>See Also</H3><br>\n");
1438             if(editing)
1439             {
1440                char fileName[MAX_LOCATION];
1441                FigureFileName(fileName, module, methodDoc, method, seeAlso, null);
1442                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1443                f.Puts(seeAlsoDoc);
1444                f.Printf("</a>\n");
1445             }
1446             else
1447                f.Printf("<br>%s\n", method, seeAlsoDoc);
1448             
1449             f.Printf("<br><br>\n");
1450             delete seeAlsoDoc;
1451          }
1452       }
1453       f.Printf("</FONT></BODY></HTML>\n");
1454    }   
1455 }
1456
1457 class APIPageFunction : APIPage
1458 {
1459    GlobalFunction function;
1460    void Generate(File f)
1461    {
1462       char string[1024];
1463       Module module = function.module;
1464       Type param;
1465       char nsName[1024], temp[1024];
1466       NameSpace * ns = function.nameSpace;
1467
1468       nsName[0] = 0;
1469       while(ns && ns->name)
1470       {
1471          strcpy(temp, ns->name);
1472          if(nsName[0]) strcat(temp, "::");
1473          strcat(temp, nsName);
1474          strcpy(nsName, temp);
1475          ns = ns->parent;
1476       }
1477
1478       f.Printf($"<HTML><HEAD><TITLE>API Reference</TITLE></HEAD>\n<BODY><FONT SIZE=\"3\">\n");
1479       f.Printf("<FONT FACE=\"Arial\" SIZE=\"6\">%s</FONT><br><br>\n", name);
1480
1481       f.Printf($"Module: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", (module && module.name) ? module : null, (!module || !module.name || !strcmp(nsName, "ecere::com")) ? "ecereCOM" : module.name);
1482
1483       if(nsName[0])
1484          f.Printf($"Namespace: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", function.nameSpace, nsName);
1485
1486       if(!function.dataType)
1487          function.dataType = ProcessTypeString(function.dataTypeString, false);
1488
1489       if(function.dataType.thisClass && function.dataType.thisClass.registered)
1490       {
1491          f.Printf($"this pointer class: <a href=\"api://%p\" style=\"text-decoration: none;\">%s</a><br>\n", function.dataType.thisClass.registered, function.dataType.thisClass.registered.name);
1492       }
1493
1494       // Generate Method Page
1495       string[0] = 0;
1496       if(!function.dataType.name)
1497          function.dataType.name = CopyString(function.name);
1498       DocPrintType(function.dataType, string, true, false);
1499       f.Printf("<br>%s", string);
1500
1501       {
1502          char * desc = ReadDoc(module, functionDoc, function, description, null);
1503          if(desc)
1504          {
1505             f.Printf($"<br><br><H3>Description</H3><br><br>\n");
1506             if(editing)
1507             {
1508                char fileName[MAX_LOCATION];
1509                FigureFileName(fileName, module, functionDoc, function, description, null);
1510                f.Printf("<a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1511                f.Puts(desc);
1512                f.Printf("</a>");
1513             }
1514             else
1515                f.Printf("%s", desc);
1516             delete desc;
1517          }
1518       }
1519       f.Printf("<br><br>\n");
1520       if(function.dataType.params.first && ((Type)function.dataType.params.first).kind != voidType)
1521       {
1522          f.Printf($"<H3>Parameters</H3><br><br>\n");
1523       }
1524       if((function.dataType.returnType && function.dataType.returnType.kind != voidType) ||
1525          (function.dataType.params.first && ((Type)function.dataType.params.first).kind != voidType))
1526       {
1527          f.Printf("<TABLE  valign=center>\n");
1528       }
1529
1530       for(param = function.dataType.params.first; param; param = param.next)
1531       {
1532          // ADD DESCRIPTION HERE
1533          if(param.kind != voidType)
1534          {
1535             char * desc = ReadDoc(module, functionDoc, function, parameter, param);
1536             f.Printf("<TR>");
1537             string[0] = 0;
1538             DocPrintType(param, string, false, false);
1539
1540             f.Printf("<TD valign=top height=22 nowrap=1>%s&nbsp;</TD>\n", param.name ? param.name : "");
1541             f.Printf("<TD valign=top height=22 nowrap=1>%s&nbsp;</TD>\n", string);
1542             if(param)
1543             {
1544                if(editing)
1545                {
1546                   char fileName[MAX_LOCATION];
1547                   FigureFileName(fileName, module, functionDoc, function, parameter, param);
1548                   f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1549                   f.Puts(desc);
1550                   f.Printf("</a>&nbsp;</TD>\n");
1551                }
1552                else
1553                   f.Printf("<TD valign=top height=22>%s&nbsp;</TD>\n", desc);
1554                delete desc;
1555             }
1556             f.Printf("</TR>\n");
1557          }
1558       }
1559       if(function.dataType.returnType && function.dataType.returnType.kind != voidType)
1560       {
1561          char * desc = ReadDoc(module, functionDoc, function, returnValue, null);
1562          if(function.dataType.params.first && ((Type)function.dataType.params.first).kind != voidType)
1563          {
1564             f.Printf("<TR><TD>&nbsp;</TD></TR>");
1565          }
1566          f.Printf("<TR>");
1567          f.Printf($"<TD valign=top height=22 nowrap=1><B>Return Value</B></TD>\n");
1568          string[0] = 0;
1569          DocPrintType(function.dataType.returnType, string, false, false);
1570          f.Printf("<TD valign=top height=22>%s&nbsp;</TD>\n", string);
1571          if(desc)
1572          {
1573             if(editing)
1574             {
1575                char fileName[MAX_LOCATION];
1576                FigureFileName(fileName, module, functionDoc, function, returnValue, null);
1577                f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1578                f.Puts(desc);
1579                f.Printf("</a>&nbsp;</TD>\n");
1580             }
1581             else
1582                f.Printf("<TD valign=top height=22>%s&nbsp;</TD>\n", function, desc);
1583             delete desc;
1584          }
1585          f.Printf("</TR>\n");
1586          f.Printf("</TABLE>\n");
1587       }
1588       if((function.dataType.returnType && function.dataType.returnType.kind != voidType) ||
1589          (function.dataType.params.first && ((Type)function.dataType.params.first).kind != voidType))
1590       {
1591          f.Printf("</TABLE><br>\n");
1592       }
1593       {
1594          char * usageDoc = ReadDoc(module, functionDoc, function, usage, null);
1595          if(usageDoc)
1596          {
1597             f.Printf($"<H3>Usage</H3><br>\n");
1598             if(editing)
1599             {
1600                char fileName[MAX_LOCATION];
1601                FigureFileName(fileName, module, functionDoc, function, usage, null);
1602                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1603                f.Puts(usageDoc);
1604                f.Printf("</a>\n");
1605             }
1606             else
1607                f.Printf("<br>%s\n", usageDoc);
1608             f.Printf("<br><br>\n");
1609             delete usageDoc;
1610          }
1611       }
1612       {
1613          char * exampleDoc = ReadDoc(module, functionDoc, function, example, null);
1614          if(exampleDoc)
1615          {
1616             f.Printf($"<H3>Example</H3><br>\n");
1617             f.Printf($"<FONT face=\"Courier New\">\n");
1618             f.Printf("<br><TABLE >\n");
1619             if(editing)
1620             {
1621                char fileName[MAX_LOCATION];
1622                FigureFileName(fileName, module, functionDoc, function, example, null);
1623                f.Printf("<TR><TD><CODE><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1624                f.Puts(exampleDoc);
1625                f.Printf("</a></CODE></TD></TR>\n");   // bgcolor=#CFC9C0
1626             }
1627             else
1628                f.Printf("<TR><TD><CODE>%s</CODE></TD></TR>\n", exampleDoc);   // bgcolor=#CFC9C0
1629             f.Printf("</TABLE></FONT>\n");
1630             f.Printf("<br>\n");
1631             delete exampleDoc;
1632          }
1633       }
1634       {
1635          char * remarksDoc = ReadDoc(module, functionDoc, function, remarks, null);
1636          if(remarksDoc)
1637          {
1638             f.Printf($"<H3>Remarks</H3><br>\n");
1639             if(editing)
1640             {
1641                char fileName[MAX_LOCATION];
1642                FigureFileName(fileName, module, functionDoc, function, remarks, null);
1643                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1644                f.Puts(remarksDoc);
1645                f.Printf("</a>\n");
1646             }
1647             else
1648                f.Printf("<br>%s\n", remarksDoc);
1649             f.Printf("<br><br>\n");
1650             delete remarksDoc;
1651          }
1652       }
1653       {
1654          char * seeAlsoDoc = ReadDoc(module, functionDoc, function, seeAlso, null);
1655          if(seeAlsoDoc)
1656          {
1657             f.Printf($"<H3>See Also</H3><br>\n");
1658             if(editing)
1659             {
1660                char fileName[MAX_LOCATION];
1661                FigureFileName(fileName, module, functionDoc, function, seeAlso, null);
1662                f.Printf("<br><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1663                f.Puts(seeAlsoDoc);
1664                f.Printf("</a>\n");
1665             }
1666             else
1667                f.Printf("<br>%s\n", seeAlsoDoc);
1668             f.Printf("<br><br>\n");
1669             delete seeAlsoDoc;
1670          }
1671       }
1672       f.Printf("</FONT></BODY></HTML>\n");
1673    }   
1674 }
1675
1676 static void AddNameSpace(DataRow parentRow, Module module, NameSpace mainNameSpace, NameSpace comNameSpace, char * parentName, bool showPrivate)
1677 {
1678    char nsName[1024];
1679    NameSpace * ns;
1680    NameSpace * nameSpace = mainNameSpace;
1681    DataRow row;
1682    DataRow classesRow = null;
1683    DataRow functionsRow = null, definesRow = null;
1684    APIPage page;
1685
1686    char fileName[MAX_LOCATION];
1687    
1688    strcpy(nsName, parentName ? parentName : "");
1689    if(nameSpace->name)
1690    {
1691       if(nsName[0])
1692          strcat(nsName, "::");
1693       strcat(nsName, nameSpace->name);
1694    }
1695
1696    if(nsName[0])
1697    {
1698       row = parentRow.AddRow();
1699       row.SetData(null, (page = APIPageNameSpace { nameSpace->name, module = module, nameSpace = nameSpace, showPrivate = showPrivate }));
1700       row.tag = (int)nameSpace;
1701       row.icon = mainForm.icons[typeNameSpace];
1702    }
1703    else
1704    {
1705       // "Global NameSpace"
1706       row = parentRow;
1707       page = parentRow.GetData(null);
1708    }
1709
1710    {
1711       bool first = true;
1712
1713       for(ns = (NameSpace *)mainNameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
1714       {
1715          NameSpace * comNS = (comNameSpace != null) ? (NameSpace *)comNameSpace.nameSpaces.FindString(ns->name) : null;
1716          AddNameSpace(row, module, ns, comNS, nsName, showPrivate);
1717       }
1718       if(comNameSpace != null)
1719       {
1720          for(ns = (NameSpace *)comNameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
1721          {
1722             if(!mainNameSpace.nameSpaces.FindString(ns->name))
1723             {
1724                AddNameSpace(row, module, ns, null, nsName, showPrivate);
1725             }
1726          }
1727       }
1728    }
1729    if(mainNameSpace.classes.first || (comNameSpace && comNameSpace.classes.first))
1730    {
1731       for(nameSpace = mainNameSpace ; nameSpace; nameSpace = (nameSpace == mainNameSpace) ? comNameSpace : null)
1732       {
1733          if(nameSpace->classes.first)
1734          {
1735             BTNamedLink link;
1736             Class cl;
1737             for(link = (BTNamedLink)nameSpace->classes.first; link; link = (BTNamedLink)((BTNode)link).next)
1738             {
1739                cl = link.data;
1740                if(!cl.templateClass && (!module || cl.module == module || (!cl.module.name && !strcmp(module.name, "ecere"))))
1741                {
1742                   if(!classesRow) { classesRow = row.AddRow(); classesRow.SetData(null, APIPage { $"Classes", page = page }); classesRow.collapsed = true; classesRow.icon = mainForm.icons[typeClass]; classesRow.tag = 1; }
1743                   AddClass(classesRow, module, cl, nsName, showPrivate);
1744                }
1745             }
1746          }
1747       }
1748    }
1749
1750    if(mainNameSpace.functions.first || (comNameSpace && comNameSpace.functions.first))
1751    {
1752       for(nameSpace = mainNameSpace ; nameSpace; nameSpace = (nameSpace == mainNameSpace) ? comNameSpace : null)
1753       {
1754          if(nameSpace->functions.first)                            
1755          {
1756             BTNamedLink link;
1757             GlobalFunction fn;
1758             for(link = (BTNamedLink)nameSpace->functions.first; link; link = (BTNamedLink)((BTNode)link).next)
1759             {
1760                fn = link.data;
1761                if(!module || fn.module == module || (!fn.module.name && !strcmp(module.name, "ecere")))
1762                {
1763                   char * name = ( name = RSearchString(fn.name, "::", strlen(fn.name), false, false), name ? name + 2 : fn.name);
1764                   DataRow fnRow;
1765                   if(!functionsRow) { functionsRow = row.AddRow(); functionsRow.SetData(null, APIPage { $"Functions", page = page }); functionsRow.collapsed = true; functionsRow.icon = mainForm.icons[typeMethod];  functionsRow.tag = 2; };
1766                   fnRow = functionsRow.AddRow(); fnRow.SetData(null, APIPageFunction { name, function = fn }); fnRow.icon = mainForm.icons[typeMethod]; fnRow.tag = (int)fn;
1767                }
1768             }            
1769          }
1770       }
1771    }
1772    
1773    if(mainNameSpace.defines.first || (comNameSpace && comNameSpace.defines.first))
1774    {
1775       for(nameSpace = mainNameSpace ; nameSpace; nameSpace = (nameSpace == mainNameSpace) ? comNameSpace : null)
1776       {
1777          if(nameSpace->defines.first)
1778          {
1779             BTNamedLink link;
1780             Definition def;
1781             for(link = (BTNamedLink)nameSpace->defines.first; link; link = (BTNamedLink)((BTNode)link).next)
1782             {
1783                def = link.data;
1784                //if(def.module == module)
1785                {
1786                   char * name = ( name = RSearchString(def.name, "::", strlen(def.name), false, false), name ? name + 2 : def.name);
1787                   DataRow defRow;
1788                   if(!definesRow) { definesRow = row.AddRow(); definesRow.SetData(null, APIPage { $"Definitions", page = page }); definesRow.collapsed = true; definesRow.icon = mainForm.icons[typeData]; definesRow.tag = 3; };
1789                   defRow = definesRow.AddRow(); defRow.SetData(null, APIPage { name, page = page }); defRow.icon = mainForm.icons[typeData]; defRow.tag = (int)def;
1790                }
1791             }            
1792          }
1793       }
1794    }
1795 }
1796
1797 static void AddDataMemberToPage(File f, DataMember member, int indent, bool showPrivate)
1798 {
1799    char string[1024];
1800    int c;
1801    if(!member.dataType)
1802       member.dataType = ProcessTypeString(member.dataTypeString, false);
1803
1804    f.Printf("<TR>");
1805    string[0] = 0;
1806    DocPrintType(member.dataType, string, true, false);
1807
1808    f.Printf("<TD valign=top height=22 nowrap=1><a name=%p></a>", member);
1809    for(c = 0; c<indent; c++)
1810       f.Printf("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
1811    f.Printf("<img valign=center src=\"%s\">&nbsp;&nbsp;%s</TD>", iconNames[typeData], member.name ? member.name : ((member.type == structMember) ? "(struct)" : "(union)"));
1812    f.Printf("<TD valign=top height=22 nowrap=1>%s</TD>", (member.type == normalMember) ? string : "");
1813    if(member.type == normalMember)
1814    {
1815       char * desc = ReadDoc(member._class.module, classDoc, member._class, memberDescription, member);
1816       if(desc)
1817       {
1818          if(editing)
1819          {
1820             char fileName[MAX_LOCATION];
1821             FigureFileName(fileName, member._class.module, classDoc, member._class, memberDescription, member);
1822             f.Printf("<TD valign=top height=22><a style=\"text-decoration:none;\" href=\"edit://%s\">", fileName);
1823             f.Puts(desc);
1824             f.Printf("</a></TD>");
1825          }
1826          else
1827             f.Printf("<TD valign=top height=22>%s</TD>", desc);
1828          delete desc;
1829       }
1830    }
1831    else
1832       f.Printf("<TD valign=top height=22></TD>");
1833    
1834    if(member.type != normalMember)
1835    {
1836       DataMember subMember;
1837       for(subMember = member.members.first; subMember; subMember = subMember.next)
1838       {
1839          if((subMember.memberAccess == publicAccess || (subMember.memberAccess == privateAccess && showPrivate)))
1840          {
1841             AddDataMemberToPage(f, subMember, indent + 1, showPrivate);
1842          }
1843       }
1844    }
1845    f.Printf("</TR><br>\n");
1846 }
1847
1848 static void AddDataMember(DataRow parentRow, APIPage page, DataMember member)
1849 {
1850    DataRow row;
1851    if(member.type == normalMember)
1852    {
1853       row = parentRow.AddRow(); row.SetData(null, APIPage { member.name, page = page }); row.icon = mainForm.icons[typeData];
1854       row.tag = (int)member;
1855    }
1856    else
1857    {
1858       DataMember m;
1859       row = parentRow.AddRow(); row.SetData(null, APIPage { (member.type == unionMember) ? "(union)" : "(struct)", page });
1860       row.icon = mainForm.icons[typeData];
1861       row.tag = (int)member;
1862
1863       for(m = member.members.first; m; m = m.next)
1864       {
1865          if(m.memberAccess == publicAccess || (m.memberAccess == privateAccess && page.showPrivate))
1866             AddDataMember(row, page, m);
1867       }
1868    }
1869 }
1870
1871 static void AddClass(DataRow parentRow, Module module, Class cl, char * nsName, bool showPrivate)
1872 {
1873    char fileName[MAX_LOCATION];
1874    char string[1024];
1875    Method method;
1876    Property prop;
1877    DataMember member;
1878    Type param;
1879    DataRow row;
1880    DataRow methodsRow = null, virtualsRow = null, eventsRow = null;
1881    DataRow propertiesRow = null, membersRow = null, conversionsRow = null, enumRow = null;
1882    APIPage page;
1883
1884    row = parentRow.AddRow();
1885    row.SetData(null, (page = APIPageClass { cl.name, cl = cl, showPrivate = showPrivate }));
1886    row.tag = (int)cl;
1887    row.collapsed = true;
1888    row.icon = (cl.type == enumClass || cl.type == unitClass || cl.type == systemClass) ? mainForm.icons[typeDataType] : mainForm.icons[typeClass];
1889
1890    // METHODS
1891    if(cl.methods.first)
1892    {
1893       for(method = (Method)cl.methods.first; method; method = (Method)((BTNode)method).next)
1894       {
1895          if(method.memberAccess == publicAccess || (method.memberAccess == privateAccess && showPrivate))
1896          {
1897             DataRow mRow;
1898             if(!method.dataType)
1899                ProcessMethodType(method);
1900             if(method.type == virtualMethod)
1901             {
1902                if(method.dataType.thisClass)
1903                {
1904                   if(!eventsRow) { eventsRow = row.AddRow(); eventsRow.SetData(null, APIPage { $"Events", page = page }); eventsRow.collapsed = true; eventsRow.icon = mainForm.icons[typeEvent];  eventsRow.tag = 4; }
1905                   mRow = eventsRow.AddRow(); mRow.SetData(null, APIPageMethod { method.name, method = method }); mRow.icon = mainForm.icons[typeEvent];
1906                   mRow.tag = (int)method;
1907                }
1908                else
1909                {
1910                   if(!virtualsRow) { virtualsRow = row.AddRow(); virtualsRow.SetData(null, APIPage { $"Virtual Methods", page = page }); virtualsRow.collapsed = true; virtualsRow.icon = mainForm.icons[typeMethod]; virtualsRow.tag = 4; }
1911                   mRow = virtualsRow.AddRow(); mRow.SetData(null, APIPageMethod { method.name, method = method }); mRow.icon = mainForm.icons[typeMethod];
1912                   mRow.tag = (int)method;
1913                }
1914             }
1915             else
1916             {
1917                if(!methodsRow) { methodsRow = row.AddRow(); methodsRow.SetData(null, APIPage { $"Methods", page = page }); methodsRow.collapsed = true; methodsRow.icon = mainForm.icons[typeMethod]; methodsRow.tag = 5; }
1918                mRow = methodsRow.AddRow(); mRow.SetData(null, APIPageMethod { method.name, method = method }); mRow.icon = mainForm.icons[typeMethod];
1919                mRow.tag = (int)method;
1920             }
1921          }
1922       }
1923    }
1924
1925    if(cl.membersAndProperties.first)
1926    {
1927       for(prop = (Property)cl.membersAndProperties.first; prop; prop = prop.next)
1928       {
1929          if(prop.memberAccess == publicAccess || (prop.memberAccess == privateAccess && showPrivate))
1930          {
1931             if(!prop.dataType)
1932                prop.dataType = ProcessTypeString(prop.dataTypeString, false);
1933             if(prop.isProperty)
1934             {
1935                DataRow mRow;
1936                if(!propertiesRow) { propertiesRow = row.AddRow(); propertiesRow.SetData(null, APIPage { $"Properties", page = page }); propertiesRow.collapsed = true; propertiesRow.icon = mainForm.icons[typeProperty]; propertiesRow.tag = 6; }
1937                mRow = propertiesRow.AddRow(); mRow.SetData(null, APIPage { prop.name, page }); mRow.icon = mainForm.icons[typeProperty];
1938                mRow.tag = (int)prop;
1939             }
1940             else
1941             {
1942                if(!membersRow) { membersRow = row.AddRow(); membersRow.SetData(null, APIPage { $"Data Members", page = page }); membersRow.collapsed = true; membersRow.icon = mainForm.icons[typeData]; membersRow.tag = 6; }
1943                AddDataMember(membersRow, page, (DataMember)prop);
1944             }
1945          }
1946       }
1947    }
1948
1949    if(cl.conversions.first)
1950    {
1951       for(prop = cl.conversions.first; prop; prop = prop.next)
1952       {
1953          DataRow mRow;
1954          char * name;
1955          if(!conversionsRow) { conversionsRow = row.AddRow(); conversionsRow.SetData(null, APIPage { $"Conversions", page = page }); conversionsRow.collapsed = true; conversionsRow.icon = mainForm.icons[typeDataType]; conversionsRow.tag = 7; }
1956          name = RSearchString(prop.name, "::", strlen(prop.name), true, false);
1957          if(name) name += 2; else name = prop.name;
1958          mRow = conversionsRow.AddRow(); mRow.SetData(null, APIPage { name, page = page }); mRow.icon = mainForm.icons[typeDataType];
1959          mRow.tag = (int)prop;
1960       }
1961    }
1962    if(cl.type == enumClass)
1963    {
1964       EnumClassData enumeration = (EnumClassData)cl.data;
1965       NamedLink item;
1966       for(item = enumeration.values.first; item; item = item.next)
1967       {
1968          DataRow mRow;                                                                                                                                                                                      
1969          if(!enumRow) { enumRow = row.AddRow(); enumRow.SetData(null, APIPage { $"Enumeration Values", page = page }); enumRow.collapsed = true; enumRow.icon = mainForm.icons[typeEnumValue]; enumRow.tag = 8; }
1970          mRow = enumRow.AddRow(); mRow.SetData(null, APIPage { item.name, page = page }); mRow.icon = mainForm.icons[typeEnumValue];         
1971          mRow.tag = (int)item;
1972       }
1973    }
1974 }
1975
1976 class MainForm : Window
1977 {
1978    size = { 1000, 600 };
1979    hasClose = true;
1980    borderStyle = sizable;
1981    hasMaximize = true;
1982    hasMinimize = true;
1983    nativeDecorations = true;
1984    icon = { ":documentorIcon.png" };
1985    text = $"API Documentation Browser";
1986
1987    BitmapResource icons[CodeObjectType];
1988
1989    MainForm()
1990    {
1991       CodeObjectType c;
1992       for(c = 0; c < CodeObjectType::enumSize; c++)
1993       {
1994          icons[c] = BitmapResource { iconNames[c], window = this, alphaBlend = true };
1995       }
1996       browser.AddField(DataField { dataType = class(APIPage) });
1997    }
1998
1999    hasMenuBar = true;
2000    menu = Menu { };
2001    Menu fileMenu { menu, $"File", f };
2002    Array<FileFilter> fileFilters
2003    { [
2004       { $"eC Shared Library files (*.dll, *.so, *.dylib)", "dll, so, dylib" },
2005       { $"eC Symbol files (*.sym)", "sym" }
2006    ] };
2007
2008    FileDialog fileDialog
2009    {
2010       filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
2011    };
2012    MenuItem fileOpenItem
2013    {
2014       fileMenu, $"Open...", o, ctrlO;
2015
2016       bool NotifySelect(MenuItem selection, Modifiers mods)
2017       {
2018          if(fileDialog.Modal() == ok)
2019          {
2020             OpenModule(fileDialog.filePath);
2021          }
2022          return true;
2023       }
2024    };
2025    MenuItem fileSettingsItem
2026    {
2027       fileMenu, $"Settings...", s, ctrlS; // set the Settings item to the file menu with shortcut keys:s and ctrl+s
2028
2029       bool NotifySelect(MenuItem selection, Modifiers mods)
2030       {
2031          SettingsDialog { master = this }.Modal(); // Open the settings dialog to allow the user to change the directory for the eCdoc files
2032          return true;
2033       }
2034    };
2035    MenuDivider { fileMenu };
2036    MenuItem fileExit { fileMenu, $"Exit", x, altF4, NotifySelect = MenuFileExit };
2037
2038    void OpenModule(char * filePath)
2039    {
2040       char extension[MAX_EXTENSION];
2041       Module module = null;
2042       static char symbolsDir[MAX_LOCATION];
2043
2044       FreeContext(globalContext);
2045       FreeExcludedSymbols(excludedSymbols);
2046       ::defines.Free(FreeModuleDefine);
2047       imports.Free(FreeModuleImport);
2048       
2049       FreeGlobalData(globalData);
2050       FreeTypeData(componentsApp);
2051       FreeIncludeFiles();
2052       delete componentsApp;
2053
2054       SetGlobalContext(globalContext);
2055       componentsApp = __ecere_COM_Initialize(false, 1, null);
2056       SetPrivateModule(componentsApp);
2057
2058       StripLastDirectory(filePath, symbolsDir);
2059       SetSymbolsDir(symbolsDir);
2060
2061       GetExtension(filePath, extension);
2062
2063       mainForm.browser.Clear();
2064
2065       ImportModule(filePath, normalImport, publicAccess, false);
2066
2067       if(extension[0] && strcmpi(extension, "so") && strcmpi(extension, "dll"))
2068          componentsApp.name = CopyString(filePath);
2069       
2070       for(module = componentsApp.allModules.first; module; module = module.next)
2071       {
2072          if(module.name && (!strcmp(module.name, "ecere") || !strcmp(module.name, "ecereCOM")))
2073             break;
2074       }
2075       if(!module)
2076          eModule_LoadStrict(componentsApp, "ecereCOM", publicAccess /*privateAccess*/);
2077       AddComponents(componentsApp, false);
2078
2079       for(module = componentsApp.allModules.first; module; module = module.next)
2080       {
2081          if(module.name && (!strcmp(module.name, filePath)))
2082             break;
2083       }
2084       if(!module) module = componentsApp;
2085       mainForm.browser.SelectRow(mainForm.browser.FindSubRow((int)module));
2086
2087       SetSymbolsDir(null);
2088    }
2089
2090    ListBox browser
2091    {
2092       this, anchor = { left = 0, top = 0, bottom = 0 }, borderStyle = 0, background = aliceBlue;
2093       treeBranches = true; collapseControl = true; fullRowSelect = false; rootCollapseButton = true;
2094       hotKey = alt0;
2095
2096       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
2097       {
2098          APIPage page = row.GetData(null);
2099          if(view.edit) view.OnLeftButtonDown(0,0,0);
2100          if(page && page.page) page = page.page;
2101          view.edit = false;
2102          view.PositionCaret(true);
2103          if(page != view.page)
2104          {
2105             Window activeChild = this.activeChild;
2106
2107             view.Destroy(0);
2108             if(page)
2109                view.Create();
2110             activeChild.Activate();
2111          }
2112          else if(!view.created)
2113             view.Create();
2114          
2115          {
2116             page = row.GetData(null);
2117             if(page && page.page)
2118             {
2119                switch(row.tag)
2120                {
2121                   case 1: view.GoToAnchor("Classes"); break;
2122                   case 2: view.GoToAnchor("Functions"); break;
2123                   case 3: view.GoToAnchor("Definitions"); break;
2124                   case 4: view.GoToAnchor("VirtualMethods"); break;
2125                   case 5: view.GoToAnchor("Methods"); break;
2126                   case 6: view.GoToAnchor("Members"); break;
2127                   case 7: view.GoToAnchor("Conversions"); break;
2128                   case 8: view.GoToAnchor("EnumerationValues"); break;
2129                   default:
2130                   {
2131                      char hex[20];
2132                      sprintf(hex, "%p", row.tag);
2133                      view.GoToAnchor(hex);
2134                   }
2135                }
2136             }
2137             else
2138             {
2139                view.SetScrollPosition(0, 0);
2140             }
2141          }
2142          return true;
2143       }
2144    };
2145    HelpView view
2146    {
2147       this, anchor = { top = 0, bottom = 0, right = 0 };
2148       hotKey = escape;
2149    };
2150    PaneSplitter slider
2151    {
2152       this, leftPane = browser, rightPane = view, split = 300 /*scaleSplit = 0.3 */
2153    };
2154
2155    bool OnClose(bool parentClosing)
2156    {
2157       if(view.edit)
2158          view.OnLeftButtonDown(0,0,0);
2159       return true;
2160    }
2161
2162    bool OnPostCreate()
2163    {
2164       mainForm.OpenModule((((GuiApplication)__thisModule).argc > 1) ? ((GuiApplication)__thisModule).argv[1] : "ecere");
2165       //mainForm.OpenModule("ec");
2166       //mainForm.OpenModule("c:/games/chess/debug/chess.sym");
2167       //mainForm.OpenModule("c:/ide/Objects.IDE.Win32.Debug/ide.sym");
2168       {
2169          int index = mainForm.browser.currentRow.index;
2170          int rowHeight = mainForm.browser.rowHeight;
2171          int height = mainForm.browser.clientSize.h;
2172
2173          mainForm.browser.scroll = { 0, index * rowHeight - height / 2 };
2174       }
2175       return true;
2176    }
2177 };
2178
2179 class EditDialog : Window
2180 {
2181    borderStyle = sizable;
2182    size = { 600, 400 };
2183    autoCreate = false;
2184
2185    EditBox editBox
2186    {
2187       this, anchor = { left = 16, top = 16, right = 18, bottom = 61 }
2188    };
2189    Button saveChanges
2190    {
2191       this, text = $"Save Changes", anchor = { horz = 184, vert = 160 }
2192    };
2193    Button cancel
2194    {
2195       this, text = $"Cancel", anchor = { horz = 254, vert = 160 }
2196    };
2197 }
2198
2199 #define UTF8_IS_FIRST(x)   (__extension__({ byte b = x; (!(b) || !((b) & 0x80) || (b) & 0x40); }))
2200 #define UTF8_NUM_BYTES(x)  (__extension__({ byte b = x; (b & 0x80 && b & 0x40) ? ((b & 0x20) ? ((b & 0x10) ? 4 : 3) : 2) : 1; }))
2201
2202 class HelpView : HTMLView
2203 {
2204    APIPage page;
2205
2206    hasVertScroll = true;
2207    hasHorzScroll = true;
2208    bool edit;
2209    char editString[MAX_LOCATION];
2210
2211    bool OnCreate()
2212    {
2213       TempFile f { };
2214       page = mainForm.browser.currentRow.GetData(null);
2215       if(page)
2216       {
2217          page.Generate(f);
2218          f.Seek(0, start);
2219          OpenFile(f, null);
2220          GoToAnchor(page.label);
2221          // Go to label...
2222          if(page.page) page = page.page;
2223       }
2224       delete f;
2225       return HTMLView::OnCreate();
2226    }
2227    EditDialog dialog
2228    {
2229
2230    };
2231
2232    void SaveEdit()
2233    {
2234       char archiveFile[MAX_LOCATION];
2235       char fileName[MAX_FILENAME];
2236       char directory[MAX_LOCATION];
2237       char * location;
2238       Archive archive;
2239       SplitArchivePath(editString, archiveFile, &location);
2240       GetLastDirectory(location, fileName);
2241       StripLastDirectory(location, directory);
2242       archive = ArchiveOpen(archiveFile, { true } );
2243       if(archive)
2244       {
2245          TempFile f { };
2246          ArchiveDir dir = archive.OpenDirectory(directory, null, replace);
2247          Block block;
2248          bool empty = true;
2249          for(block = textBlock.parent.subBlocks.first; block; block = block.next)
2250          {
2251             if(block.type == TEXT && block.textLen)
2252             {
2253                empty = false;
2254                break;
2255             }
2256          }
2257          if(!empty)
2258          {
2259             for(block = textBlock.parent.subBlocks.first; block; block = block.next)
2260             {
2261                if(block.type == BR)
2262                   f.Puts("<br>");
2263                else if(block.type == TEXT)
2264                   f.Write(block.text, 1, block.textLen);
2265             }
2266          }
2267          f.Seek(0, start);
2268          dir.AddFromFile(fileName, f, null, replace, 0, null, null);
2269          delete dir;
2270          delete archive;
2271          delete f;
2272          if(empty)
2273          {
2274             Block parent = textBlock.parent;
2275             while((block = parent.subBlocks.first))
2276             {
2277                parent.subBlocks.Remove(block);
2278                delete block;
2279             }
2280             textBlock = Block { type = TEXT, parent = parent, font = parent.font };
2281             textBlock.text = CopyString($"[Add Text]");
2282             textBlock.textLen = strlen(textBlock.text);
2283             parent.subBlocks.Add(textBlock);
2284          }
2285
2286          edit = false;            
2287          if(created)
2288          {
2289             ComputeMinSizes();
2290             ComputeSizes();
2291             PositionCaret(true);
2292             Update(null);
2293          }
2294       }
2295    }
2296
2297    bool OnLeftButtonDown(int x, int y, Modifiers mods)
2298    {
2299       if(edit)
2300       {
2301          // Update overLink
2302          HTMLView::OnMouseMove(x, y, mods);
2303          if(textBlock && overLink == textBlock.parent)
2304          {
2305             selPosition = curPosition = TextPosFromPoint(x, y, &textBlock);
2306             PositionCaret(true);            
2307          }
2308          else
2309          {
2310             SaveEdit();
2311             HTMLView::OnLeftButtonDown(x, y, mods);
2312          }
2313          return true;
2314       }
2315       return HTMLView::OnLeftButtonDown(x, y, mods);
2316    }
2317
2318    bool OnLeftButtonUp(int x, int y, Modifiers mods)
2319    {
2320       if(!edit || !textBlock || clickedLink != textBlock.parent)
2321       {
2322          HTMLView::OnLeftButtonUp(x, y, mods);
2323          if(edit)
2324          {
2325             selPosition = curPosition = TextPosFromPoint(x, y, &textBlock);
2326             PositionCaret(true);
2327          }
2328       }
2329       return true;
2330    }
2331
2332    // Returns true if it needs scrolling
2333    /*
2334    bool FindMouse(int px, int py, int * tx, int * ty, EditLine * tline, bool half)
2335    {
2336       int w;
2337       int c;
2338       int x, y;
2339       EditLine line;
2340       bool needHScroll = false;
2341
2342       if(py < 0)
2343       {
2344          if(this.viewY > 0)
2345          {
2346             y = this.viewY-1;
2347             line = this.viewLine ? (void *)this.viewLine.prev : null;
2348          }
2349          else
2350          {
2351             y = 0;
2352             line = (void *)this.lines.first;
2353          }
2354       }
2355       else
2356       {
2357          py = Min(py, clientSize.h);
2358          py /= this.space.h;
2359          py = Min(py, this.lineCount);
2360          y = this.viewY;
2361          for(c = 0, line = this.viewLine; (line != (void *)this.lines.last && c<py); line = line.next, c++)
2362          {
2363             y++;
2364          }
2365       }
2366
2367       if( (px >= clientSize.w || px < clientSize.w/2) && this.viewX)
2368          needHScroll = true;
2369       px = Max(px,0);
2370       px = Min(px,clientSize.w+this.space.w);
2371
2372       if(tx && line)
2373       {
2374          *tx = AdjustXPosition(line, px + viewX, half, null, MAXINT, 0);
2375       }
2376
2377       if(tline) *tline = line;
2378       if(ty) *ty = y;
2379
2380       // Prevent divide by 0 from non valid this.font
2381       if(!this.space.h)
2382          return (y < this.viewY) || needHScroll;
2383       else
2384          return (y < this.viewY || y >= this.viewY + clientSize.h / this.space.h) || needHScroll;
2385       return false;
2386    }
2387 */
2388 /*
2389    bool OnLeftButtonDown(int mx, int my, Modifiers mods)
2390    {
2391       int x,y;
2392       EditLine line;
2393
2394       if(style.noSelect) return true;
2395
2396       if(!mods.isActivate)
2397       {
2398          Capture();
2399          mouseSelect = true;
2400       }
2401
2402       mouseX = mx - XOFFSET;
2403       mouseY = my;
2404
2405       FindMouse(mouseX, mouseY, &x, &y, &line, true);
2406
2407       if(!style.readOnly)
2408       {
2409          if(wordSelect)
2410             mouseMove = false;
2411          else if(IsMouseOnSelection() && !mods.isActivate)
2412          {
2413             DirtyLine(this.y);
2414             mouseMove = true;
2415             dropX = x;
2416             dropY = y;
2417             dropLine = line;
2418          }
2419       }
2420
2421       if(!mouseMove && !wordSelect && (!mods.isActivate || style.multiLine))
2422       {
2423          if(mods.shift && !mods.isActivate)
2424          {
2425             this.x = x;
2426             this.y = y;
2427             this.line = line;
2428             DirtyAll();
2429          }
2430          else
2431          {
2432             SelDirty();
2433             DirtyLine(this.y);
2434             this.x = x;
2435             this.y = y;
2436             this.line = line;
2437             DirtyLine(this.y);
2438             this.selLine = this.line;
2439             this.selX = this.x;
2440             this.selY = this.y;
2441             //Deselect();
2442          }
2443          ComputeColumn();
2444       }
2445       
2446       UpdateDirty();
2447       UpdateCaretPosition(true);
2448       return true;
2449    }
2450 */
2451 /*
2452    bool OnLeftButtonUp(int x, int y, Modifiers mods)
2453    {
2454       timer.Stop();
2455
2456       mouseSelect = false;
2457       wordSelect = false;
2458       
2459       x -= XOFFSET;
2460       
2461       ReleaseCapture();
2462       if(!style.readOnly)
2463       {
2464          if(mouseMove)
2465          {
2466             EditLine line;
2467             FindMouse(mouseX, mouseY, &x, &y, &line, true);
2468     
2469             dropX = x;
2470             dropY = y;
2471             dropLine = line;
2472
2473             mouseMove = IsMouseOnSelection();
2474
2475             if(!mouseMove)
2476             {
2477                int size = SelSize();
2478                if(size)
2479                {
2480                   char * text = new char[size+1];
2481                   if(text)
2482                   {
2483                      int moveX = 0;
2484                      GetSel(text, false);
2485
2486                      if(Max(selY, this.y) == dropY)
2487                      {
2488                         if(this.x > selX)
2489                         {
2490                            if(this.dropX > this.selX)
2491                               moveX = this.x - this.selX;
2492                         }
2493                         else
2494                         {
2495                            if(this.dropX > this.x)
2496                               moveX = this.selX - this.x;
2497                         }
2498                      }
2499                      DelSel(null);
2500                      this.dropX -= moveX;
2501                      this.selX = this.x = this.dropX;
2502                      this.selY = this.y = this.dropY;
2503                      this.selLine = this.line = this.dropLine;
2504                      AddS(text);
2505                      SetViewToCursor(true);
2506                      delete text;
2507                      Modified();
2508                   }
2509                }
2510             }
2511             else
2512             {
2513                SelDirty();
2514                DirtyLine(this.y);
2515                this.x = x;
2516                this.y = y;
2517                this.line = line;
2518                ComputeColumn();
2519                DirtyLine(this.y);
2520                Deselect();
2521                UpdateDirty();
2522             }
2523          }
2524          else
2525          {
2526             EditLine line;
2527             mouseX = x;
2528             mouseY = y;
2529
2530             FindMouse(mouseX, mouseY, &x, &y, &line, true);
2531
2532             NotifyDropped(master, this, x, y);
2533          }
2534       }
2535       mouseMove = false;
2536       return true;
2537    }
2538
2539    bool OnMouseMove(int mx, int my, Modifiers mods)
2540    {
2541       int x,y;
2542       EditLine line;
2543       bool needScroll;
2544       
2545       if(mods != -1 && mods.isSideEffect) 
2546       { 
2547          SetSelectCursor(); 
2548          return true; 
2549       }
2550       if(style.noSelect) return true;
2551       if(wordSelect) return true;
2552       mouseX = mx - XOFFSET;
2553       mouseY = my;
2554
2555       needScroll = FindMouse(this.mouseX, this.mouseY, &x, &y, &line, true);
2556
2557       if(this.mouseMove || this.mouseSelect)
2558       {
2559          if(!needScroll)
2560             timer.Stop();
2561          else 
2562          {
2563             if(needScroll)
2564                timer.Start();
2565             if(mods != -1 && 
2566                ((style.hScroll) || (style.vScroll)))
2567                return true;
2568          }
2569       }
2570
2571       if(this.mouseMove)
2572       {
2573          DirtyLine(this.dropY);
2574          this.dropX = x;
2575          this.dropY = y;
2576          DirtyLine(this.dropY);
2577          this.dropLine = line;
2578          SetViewToCursor(true);
2579       }
2580       else if(this.mouseSelect)
2581       {
2582          DirtyLine(this.selY);
2583          DirtyLine(this.y);
2584          this.x = x;
2585          this.y = y;
2586          ComputeColumn();
2587          DirtyLine(this.y);
2588          this.line = line;
2589          SetViewToCursor(true);
2590          UpdateDirty();
2591       }
2592       SetSelectCursor();
2593       return true;
2594    }
2595
2596    bool OnLeftDoubleClick(int mx, int my, Modifiers mods)
2597    {
2598       int x,y;
2599       EditLine line;
2600       
2601       mx -= XOFFSET;
2602
2603       if(style.noSelect) return true;
2604       FindMouse(mx, my, &x, &y, &line, false);
2605       if(!NotifyDoubleClick(master, this, line, mods))
2606          return false;
2607       if(x < line.count)
2608       {
2609          int c;
2610          int start = -1;
2611          int numBytes;
2612          for(c = x; c >= 0; c--)
2613          {
2614             unichar ch;
2615             while(c > 0 && !UTF8_IS_FIRST(line.buffer[c])) c--;
2616             ch = UTF8_GET_CHAR(line.buffer + c, numBytes);
2617             if(!IS_ALUNDER(ch))
2618                break;
2619             start = c;
2620          }
2621          if(start != -1)
2622          {
2623             for(c = start; c<line.count; c += numBytes)
2624             {
2625                unichar ch = UTF8_GET_CHAR(line.buffer + c, numBytes);
2626                if(!IS_ALUNDER(ch))
2627                   break;
2628             }
2629             SelDirty();
2630             DirtyLine(this.y);
2631             this.y = y;
2632             DirtyLine(this.y);
2633             this.selX = start;
2634             this.x = c;
2635             ComputeColumn();
2636             this.line = this.selLine = line;
2637             this.wordSelect = (c != start);
2638             UpdateDirty();
2639          }
2640       }
2641       return true;
2642    }
2643 */
2644    bool OnOpen(char * href)
2645    {
2646       if(!strncmp(href, "api://", 6))
2647       {
2648          int tag = (uint)strtoul(href + 6, null, 16);
2649          DataRow row = mainForm.browser.FindSubRow(tag);
2650          if(row)
2651          {
2652             edit = false;
2653             mainForm.browser.SelectRow(row);
2654             while((row = row.parent))
2655                row.collapsed = false;
2656             row = mainForm.browser.currentRow;
2657             mainForm.browser.scroll = { 0, row.index * mainForm.browser.rowHeight - mainForm.browser.clientSize.h / 2 };
2658          }
2659       }
2660       else if(!strncmp(href, "edit://", 7))
2661       {
2662          Block block;
2663          int startX = clickedLink.startX, startY = clickedLink.startY;
2664          for(block = (Block)clickedLink.subBlocks.first; block; block = block.next)
2665          {
2666             if(block.type == TEXT) startX = block.startX, startY = block.startY;
2667             if(block.type == BR && (!block.prev || !block.next || block.next.type != TEXT))
2668             {
2669                Block newBlock { type = TEXT, parent = block.parent, font = block.parent.font };
2670                int tw = 0, th = 0;
2671                display.FontExtent(block.font.font, " ", 1, null, &th);
2672                if(!block.prev)
2673                {
2674                   block.parent.subBlocks.Insert(null, newBlock);
2675                   block = newBlock;
2676                }
2677                else
2678                {
2679                   block.parent.subBlocks.Insert(block, newBlock);
2680                   startY += th;
2681                }               
2682                newBlock.startX = startX;
2683                newBlock.startY = startY;
2684                newBlock.text = new0 char[1];
2685             }
2686          }
2687
2688          textBlock = (Block)clickedLink.subBlocks.first;
2689          if(!strcmp(textBlock.text, $"[Add Text]"))
2690          {
2691             textBlock.text[0] = 0;
2692             textBlock.textLen = 0;               
2693          }
2694
2695          strcpy(editString, href + 7);
2696          selPosition = curPosition = 0;
2697          // dialog.Create();
2698          edit = true;
2699          PositionCaret(true);
2700       }
2701       return true;
2702    }
2703
2704    Block textBlock;
2705    char * text;
2706    int curPosition, selPosition;
2707
2708    bool OnKeyDown(Key key, unichar ch)
2709    {
2710       if(edit)
2711       {
2712          switch(key)
2713          {
2714             case escape:
2715                OnLeftButtonDown(0,0,0);
2716                return false;
2717             case end:
2718                selPosition = curPosition = textBlock.textLen;
2719                PositionCaret(true);
2720                Update(null);
2721                break;
2722             case home:
2723                selPosition = curPosition = 0;
2724                PositionCaret(true);
2725                Update(null);
2726                break;
2727             case ctrlHome:
2728                selPosition = curPosition = 0;
2729                while(textBlock.prev)
2730                   textBlock = textBlock.prev.prev;
2731                PositionCaret(true);
2732                Update(null);
2733                return false;
2734             case ctrlEnd:
2735                while(textBlock.next && textBlock.next.next)
2736                   textBlock = textBlock.next.next;
2737                selPosition = curPosition = textBlock.textLen;
2738                PositionCaret(true);
2739                Update(null);
2740                return false;
2741          }
2742       }
2743       else
2744          return HTMLView::OnKeyDown(key, ch);
2745       return true;
2746    }
2747    bool OnKeyHit(Key key, unichar ch)
2748    {
2749       if(edit)
2750       {
2751          switch(key)
2752          {
2753             case up:
2754             {
2755                if(caretY == textBlock.startY)
2756                {
2757                   if(textBlock.prev)
2758                   {
2759                      textBlock = textBlock.prev.prev;
2760                      selPosition = curPosition = Min(curPosition, textBlock.textLen);
2761                      PositionCaret(false);
2762                      caretY = MAXINT;
2763                   }
2764                   else
2765                      return false;
2766                }
2767
2768                {
2769                   int tw = 0, th = 0;
2770                   int textPos = 0;
2771                   int sx = textBlock.startX, sy = textBlock.startY;
2772                   char * text = textBlock.text;
2773                   int maxW;
2774                   Block block = textBlock;
2775                   while(block && block.type != TD) block = block.parent;
2776                   if(block)
2777                   {
2778                      Block table = block;
2779                      while(table && table.type != TABLE) table = table.parent;
2780                      if(table)
2781                         maxW = block.w - 2* table.cellPadding;
2782                      else
2783                         maxW = clientSize.w - 10 - sx;
2784                   }
2785                   else
2786                      maxW = clientSize.w - 10 - sx;
2787                   display.FontExtent(textBlock.font.font, " ", 1, null, &th);
2788
2789                   do
2790                   {
2791                      int startPos = textPos;
2792                      int width = 0;
2793                      int x = 0;
2794                      bool lineComplete = false;
2795                      for(; textPos<textBlock.textLen && !lineComplete;)
2796                      {
2797                         int w;
2798                         int len;
2799                         char * nextSpace = strchr(text + textPos, ' ');
2800
2801                         if(nextSpace)
2802                            len = (nextSpace - (text + textPos)) + 1;
2803                         else
2804                            len = textBlock.textLen - textPos;
2805                         
2806                         display.FontExtent(textBlock.font.font, text + textPos, len, &w, &th);
2807
2808                         if(x + width + w > maxW && x > 0)
2809                         {
2810                            lineComplete = true;
2811                            break;
2812                         }
2813                         textPos += len;
2814                         width += w;
2815                         if(nextSpace)
2816                         {
2817                            x += width;
2818                            width = 0;
2819                         }
2820                         if(textPos == textBlock.textLen || (sy == caretY - th && caretX <= x + width + sx))
2821                         {
2822                            x += width;
2823                            curPosition = textPos;
2824                            while(curPosition > 0 && x + sx > caretX && textPos > startPos)
2825                            {
2826                               int len;
2827                               while(curPosition > 0 && !UTF8_IS_FIRST(text[--curPosition]));
2828                               len = curPosition - startPos;
2829                               display.FontExtent(textBlock.font.font, text + startPos, len, &x, null);
2830                            }
2831                            selPosition = curPosition;
2832                            PositionCaret(false);
2833                            return false;
2834                         }
2835                      }
2836                      if(sy == caretY - th || textPos == textBlock.textLen)
2837                      {
2838                         if(textPos != textBlock.textLen)
2839                         {
2840                            int c = textPos - 1;
2841                            while(c > 0 && text[c] == ' ') c--;
2842                            selPosition = curPosition = c + 1;
2843                         }
2844                         else
2845                            selPosition = curPosition = textBlock.textLen;
2846                         PositionCaret(false);
2847                         return false;
2848                      }
2849                      sy += th;
2850                      sx = textBlock.startX;
2851                   } while(textPos < textBlock.textLen);
2852                   return false;
2853                }
2854                return false;
2855             }
2856             case down:
2857             {
2858                int tw = 0, th = 0;
2859                int textPos = 0;
2860                int sx = textBlock.startX, sy = textBlock.startY;
2861                char * text = textBlock.text;
2862                int maxW;
2863                Block block = textBlock;
2864                while(block && block.type != TD) block = block.parent;
2865                if(block)
2866                {
2867                   Block table = block;
2868                   while(table && table.type != TABLE) table = table.parent;
2869                   if(table)
2870                      maxW = block.w - 2* table.cellPadding;
2871                   else
2872                      maxW = clientSize.w - 10 - sx;
2873                }
2874                else
2875                   maxW = clientSize.w - 10 - sx;
2876                display.FontExtent(textBlock.font.font, " ", 1, null, &th);
2877
2878                while(!textPos || textPos < textBlock.textLen)
2879                {
2880                   int startPos = textPos;
2881                   int width = 0;
2882                   int x = 0;
2883                   bool lineComplete = false;
2884                   for(; (textPos < textBlock.textLen) && !lineComplete;)
2885                   {
2886                      int w;
2887                      int len;
2888                      char * nextSpace = strchr(text + textPos, ' ');
2889
2890                      if(nextSpace)
2891                         len = (nextSpace - (text + textPos)) + 1;
2892                      else
2893                         len = textBlock.textLen - textPos;
2894                      
2895                      display.FontExtent(textBlock.font.font, text + textPos, len, &w, &th);
2896
2897                      if(x + width + w > maxW && x > 0)
2898                      {
2899                         lineComplete = true;
2900                         break;
2901                      }
2902                      textPos += len;
2903                      width += w;
2904                      if(nextSpace)
2905                      {
2906                         x += width;
2907                         width = 0;
2908                      }
2909                      if(sy > caretY && (textPos == textBlock.textLen || caretX <= x + width + sx))
2910                      {
2911                         curPosition = textPos;
2912                         x += width;
2913                         while(curPosition > 0 && x + sx > caretX && textPos > startPos)
2914                         {
2915                            int len;
2916                            while(curPosition > 0 && !UTF8_IS_FIRST(text[--curPosition]));
2917                            len = curPosition - startPos;
2918                            display.FontExtent(textBlock.font.font, text + startPos, len, &x, null);
2919                         }
2920                         selPosition = curPosition;
2921                         PositionCaret(false);
2922                         return false;
2923                      }
2924                   }
2925                   if(sy > caretY)
2926                   {
2927                      selPosition = curPosition = textBlock.textLen;
2928                      PositionCaret(false);
2929                      return false;
2930                   } 
2931                   else if(textPos == textBlock.textLen && textBlock.next && textBlock.next.next)
2932                   {
2933                      startPos = 0;
2934                      textPos = 0;
2935                      textBlock = textBlock.next.next;
2936                      sy = textBlock.startY;
2937                      sx = textBlock.startX;
2938                      text = textBlock.text;
2939                   }
2940                   else
2941                   {
2942                      sy += th;
2943                      sx = textBlock.startX;
2944                   }
2945                }
2946                
2947                /*if(textBlock.next && textBlock.next.next)
2948                {
2949                   textBlock = textBlock.next.next;
2950                   selPosition = curPosition = Min(curPosition, textBlock.textLen);
2951                   PositionCaret(false);
2952                }*/
2953                break;
2954             }
2955             #define IS_ALUNDER(ch) ((ch) == '_' || isalnum((ch)))
2956             case ctrlRight:
2957             {
2958                // SELECTION CTRL-RIGHT
2959                /*
2960                bool foundAlpha = false;
2961                bool found = false;
2962                Block line, lastLine;
2963                int lastC;
2964
2965                for(line = textBlock; (line && !found); line = line.next ? line.next.next : null)
2966                {
2967                   int start = (line == textBlock) ? curPosition : 0;
2968                   int c;
2969                   for(c = start; c < line.textLen; c++)
2970                   {
2971                      if(IS_ALUNDER(line.text[c]))
2972                      {
2973                         foundAlpha = true;
2974                         lastC = c;
2975                         lastLine = line;
2976                      }
2977                      else if(foundAlpha)
2978                      {
2979                         found = true;
2980                         break;
2981                      }
2982                   }
2983                   if(!found && (c != curPosition || line != textBlock))
2984                   {
2985                      found = true;
2986                      lastLine = line;
2987                      lastC = line.textLen-1;
2988                      break;
2989                   }
2990                }  
2991                if(found)
2992                {
2993                   selPosition = curPosition = lastC+1;
2994                   textBlock = lastLine;
2995                   PositionCaret(true);
2996                }
2997                */
2998                
2999                bool foundAlpha = false;
3000                bool found = false;
3001                Block line;
3002
3003                for(line = textBlock; (line && !found); line = line.next ? line.next.next : null)
3004                {
3005                   int start = (line == textBlock) ? curPosition : 0;
3006                   int c;
3007                   for(c = start; c < line.textLen; c++)
3008                   {
3009                      if(!IS_ALUNDER(line.text[c]))
3010                         foundAlpha = true;
3011                      else if(foundAlpha)
3012                      {
3013                         found = true;
3014                         selPosition = curPosition = c;
3015                         textBlock = line;
3016                         PositionCaret(true);
3017                         break;
3018                      }
3019                   }
3020                   // No next word found, 
3021                   if(!found && (c != curPosition || line != textBlock))
3022                   {
3023                      found = true;
3024                      selPosition = curPosition = line.textLen;
3025                      textBlock = line;
3026                      PositionCaret(true);
3027                   }
3028                   foundAlpha = true;
3029                }
3030                break;
3031             }
3032             case ctrlLeft:
3033             {
3034                bool foundAlpha = false;
3035                bool found = false;
3036                Block line, lastLine;
3037                int lastC;
3038
3039                for(line = textBlock; (line && !found); line = line.prev ? line.prev.prev : null)
3040                {
3041                   int start, c;
3042                   if(curPosition == 0 && line != textBlock)
3043                   {
3044                      foundAlpha = true;
3045                      lastC = line.textLen;
3046                      lastLine = line;
3047                      break;
3048                   }
3049                   if(line == textBlock) start = curPosition-1; else start = line.textLen-1;
3050                   for(c = start; c>=0; c--)
3051                   {
3052                      if(IS_ALUNDER(line.text[c]))
3053                      {
3054                         foundAlpha = true;
3055                         lastC = c;
3056                         lastLine = line;
3057                      }
3058                      else
3059                      {
3060                         if(foundAlpha)
3061                         {
3062                            found = true;
3063                            break;
3064                         }
3065                      }
3066                   }
3067                   // No next word found, 
3068                   if(!found && curPosition > 0)
3069                   {
3070                      foundAlpha = true;
3071                      lastC = 0;
3072                      lastLine = line;
3073                      break;
3074                   }
3075                }
3076                if(foundAlpha)
3077                {
3078                   textBlock = lastLine;
3079                   selPosition = curPosition = lastC;
3080                   PositionCaret(true);
3081                }
3082                break;
3083             }
3084             case right:
3085                if(curPosition < textBlock.textLen)
3086                {
3087                   curPosition += UTF8_NUM_BYTES(textBlock.text[curPosition]);
3088                   PositionCaret(true);
3089                   selPosition = curPosition;
3090                }
3091                else if(textBlock.next && textBlock.next.next)
3092                {
3093                   textBlock = textBlock.next.next;
3094                   selPosition = curPosition = 0;
3095                   PositionCaret(true);
3096                }
3097                break;
3098             case left:
3099                if(curPosition > 0)
3100                {
3101                   while(curPosition > 0 && !UTF8_IS_FIRST(textBlock.text[--curPosition]));
3102                   PositionCaret(true);
3103                   selPosition = curPosition;
3104                }
3105                else if(textBlock.prev)
3106                {
3107                   textBlock = textBlock.prev.prev;
3108                   selPosition = curPosition = textBlock.textLen;
3109                   PositionCaret(true);
3110                }
3111                break;
3112             case backSpace:
3113                if(curPosition)
3114                {
3115                   int c = curPosition;
3116                   int nb = 1;
3117                   while(c > 0 && !UTF8_IS_FIRST(textBlock.text[--c])) nb++;
3118                   memmove(textBlock.text + curPosition - nb, textBlock.text + curPosition, textBlock.textLen - curPosition + 1);
3119                   textBlock.textLen -= nb;
3120                   textBlock.text = renew textBlock.text char[textBlock.textLen + 1];
3121                   curPosition -= nb;
3122                   selPosition = curPosition;
3123                   {
3124                      //Clear(html.block);
3125                      //CreateForms(html.block);
3126                      ComputeMinSizes();
3127                      ComputeSizes();
3128                      //PositionForms();
3129                   }
3130                   PositionCaret(true);
3131                   Update(null);
3132                }
3133                else if(textBlock.prev)
3134                {
3135                   Block prev = textBlock.prev, prevBlock = textBlock.prev.prev;
3136                   prevBlock.text = renew prevBlock.text char[prevBlock.textLen + textBlock.textLen + 1];
3137                   memcpy(prevBlock.text + prevBlock.textLen, textBlock.text, textBlock.textLen + 1);
3138
3139                   selPosition = curPosition = prevBlock.textLen;
3140                   prevBlock.textLen += textBlock.textLen;
3141                   textBlock.parent.subBlocks.Remove(prev);
3142                   delete prev;
3143                   textBlock.parent.subBlocks.Remove(textBlock);                  
3144                   delete textBlock;
3145                   textBlock = prevBlock;
3146                   
3147                   {
3148                      //Clear(html.block);
3149                      //CreateForms(html.block);
3150                      ComputeMinSizes();
3151                      ComputeSizes();
3152                      //PositionForms();
3153                   }
3154                   PositionCaret(true);
3155                   Update(null);
3156                }
3157                break;
3158             case del:
3159                if(textBlock.textLen > curPosition)
3160                {
3161                   int nb = UTF8_NUM_BYTES(textBlock.text[curPosition]);
3162                   memmove(textBlock.text + curPosition, textBlock.text + curPosition + nb, textBlock.textLen - curPosition + 1 - nb + 1);
3163                   textBlock.textLen -= nb;
3164                   textBlock.text = renew textBlock.text char[textBlock.textLen + 1];
3165                   {
3166                      //Clear(html.block);
3167                      //CreateForms(html.block);
3168                      ComputeMinSizes();
3169                      ComputeSizes();
3170                      //PositionForms();
3171                   }
3172                   PositionCaret(true);
3173                   Update(null);
3174                }
3175                else if(textBlock.next && textBlock.next.next)
3176                {
3177                   Block next = textBlock.next, nextBlock = textBlock.next.next;
3178                   textBlock.text = renew textBlock.text char[textBlock.textLen + nextBlock.textLen + 1];
3179                   memcpy(textBlock.text + textBlock.textLen, nextBlock.text, nextBlock.textLen + 1);
3180
3181                   textBlock.textLen += nextBlock.textLen;
3182                   textBlock.parent.subBlocks.Remove(next);
3183                   delete next;
3184                   textBlock.parent.subBlocks.Remove(nextBlock);                  
3185                   delete nextBlock;
3186                   
3187                   {
3188                      //Clear(html.block);
3189                      //CreateForms(html.block);
3190                      ComputeMinSizes();
3191                      ComputeSizes();
3192                      //PositionForms();
3193                   }
3194                   PositionCaret(true);
3195                   Update(null);
3196                }
3197                break;
3198             case enter:
3199             {
3200                Block block { type = BR, parent = textBlock.parent, font = textBlock.font };
3201                Block newBlock { type = TEXT, parent = textBlock.parent, font = textBlock.font };
3202                int startY = textBlock.startY, startX = textBlock.startX;
3203                int tw = 0, th = 0;
3204
3205                display.FontExtent(textBlock.font.font, " ", 1, null, &th);
3206                textBlock.parent.subBlocks.Insert(textBlock, block);
3207                textBlock.parent.subBlocks.Insert(block, newBlock);
3208
3209                startY += th;
3210
3211                newBlock.textLen = textBlock.textLen - curPosition;
3212                newBlock.text = new char[newBlock.textLen+1];
3213                memcpy(newBlock.text, textBlock.text + curPosition, textBlock.textLen - curPosition + 1);
3214                textBlock.textLen = curPosition;
3215                textBlock.text[curPosition] = 0;
3216
3217                newBlock.startY = startY;
3218                newBlock.startX = startX;
3219                selPosition = curPosition = 0;
3220                {
3221                   //Clear(html.block);
3222                   //CreateForms(html.block);
3223                   ComputeMinSizes();
3224                   ComputeSizes();
3225                   //PositionForms();
3226                }
3227                textBlock = newBlock;
3228                PositionCaret(true);
3229                Update(null);
3230                break;
3231             }
3232             case shiftInsert:
3233             case ctrlV:
3234             {
3235                ClipBoard clipBoard { };
3236                if(clipBoard.Load())
3237                {  
3238                   int c;
3239                   char * text = clipBoard.memory;
3240                   char ch;
3241                   int start = 0;
3242                   Block parent = textBlock.parent;
3243                   FontEntry font = textBlock.font;
3244                   for(c = 0; ; c++)
3245                   {
3246                      ch = text[c];
3247                      if(ch == '\n' || ch == '\r' || !ch)
3248                      {
3249                         int len = c - start;
3250                         textBlock.text = renew textBlock.text char[textBlock.textLen + 1 + len];
3251                         memmove(textBlock.text + curPosition + len, textBlock.text + curPosition, textBlock.textLen - curPosition + 1);
3252                         memcpy(textBlock.text + curPosition, text + start, len);
3253                         textBlock.textLen += len;
3254                         curPosition += len;
3255                         selPosition = curPosition;
3256                         if(!ch) break;
3257                         {
3258                            Block block { type = BR, parent = parent, font = font };
3259                            Block newBlock { type = TEXT, parent = parent, font = font };
3260                            int startY = textBlock.startY, startX = textBlock.startX;
3261                            int tw = 0, th = 0;
3262
3263                            display.FontExtent(textBlock.font.font, " ", 1, null, &th);
3264                            textBlock.parent.subBlocks.Insert(textBlock, block);
3265                            textBlock.parent.subBlocks.Insert(block, newBlock);
3266
3267                            startY += th;
3268
3269                            newBlock.textLen = textBlock.textLen - curPosition;
3270                            newBlock.text = new char[newBlock.textLen+1];
3271                            memcpy(newBlock.text, textBlock.text + curPosition, textBlock.textLen - curPosition + 1);
3272                            textBlock.textLen = curPosition;
3273                            textBlock.text[curPosition] = 0;
3274
3275                            newBlock.startY = startY;
3276                            newBlock.startX = startX;
3277                            selPosition = curPosition = 0;
3278                            textBlock = newBlock;
3279                         }
3280                         if(ch == '\r' && text[c+1] == '\n') c++;
3281                         start = c + 1;
3282                      }
3283                   }
3284                   ComputeMinSizes();
3285                   ComputeSizes();
3286                   PositionCaret(true);
3287                   Update(null);
3288                }
3289                delete clipBoard;
3290                break;
3291             }
3292             default:
3293             {
3294                // eC BUG HERE: (Should be fixed)
3295                if(!key.ctrl && !key.alt && ch >= 32 && ch != 128 /*&& ch < 128*/)
3296                {
3297                   char string[5];
3298                   int len = UTF32toUTF8Len(&ch, 1, string, 5);
3299                   int c;
3300
3301                   textBlock.text = renew textBlock.text char[textBlock.textLen + len + 1];
3302                   memmove(textBlock.text + curPosition + len, textBlock.text + curPosition, textBlock.textLen - curPosition + 1);
3303                   
3304                   for(c = 0; c<len; c++)
3305                   {
3306                      textBlock.text[curPosition] = string[c];
3307                      textBlock.textLen++;
3308                      curPosition++;
3309                   }
3310                   selPosition = curPosition;
3311                   
3312                   {
3313                      //Clear(html.block);
3314                      //CreateForms(html.block);
3315                      ComputeMinSizes();
3316                      ComputeSizes();
3317                      //PositionForms();
3318                   }
3319                   PositionCaret(true);
3320                   Update(null);
3321                }
3322             }
3323          }
3324       }
3325       return true;
3326    }
3327
3328    void OnResize(int width, int height)
3329    {
3330       HTMLView::OnResize(width, height);
3331       PositionCaret(true);
3332    }
3333
3334    int caretX, caretY;
3335    void PositionCaret(bool setCaretX)
3336    {
3337       if(edit)
3338       {
3339          int tw = 0, th = 0;
3340          int textPos = 0;
3341          int sx = textBlock.startX, sy = textBlock.startY;
3342          char * text = textBlock.text;
3343          int maxW;
3344          Block block = textBlock;
3345          while(block && block.type != TD) block = block.parent;
3346          if(block)
3347          {
3348             Block table = block;
3349             while(table && table.type != TABLE) table = table.parent;
3350             if(table)
3351                maxW = block.w - 2* table.cellPadding;
3352             else
3353                maxW = clientSize.w - 10 - sx;
3354          }
3355          else
3356             maxW = clientSize.w - 10 - sx;
3357          
3358          display.FontExtent(textBlock.font.font, " ", 1, null, &th);
3359
3360          while(textPos < textBlock.textLen)
3361          {
3362             int startPos = textPos;
3363             int width = 0;
3364             int x = 0;
3365             bool lineComplete = false;
3366
3367             for(; textPos<textBlock.textLen && !lineComplete;)
3368             {
3369                int w;
3370                int len;
3371                char * nextSpace = strchr(text + textPos, ' ');
3372
3373                if(nextSpace)
3374                   len = (nextSpace - (text + textPos)) + 1;
3375                else
3376                   len = textBlock.textLen - textPos;
3377                
3378                display.FontExtent(textBlock.font.font, text + textPos, len, &w, &th);
3379
3380                if(x + width + w > maxW && x > 0)
3381                {
3382                   lineComplete = true;
3383                   break;
3384                }
3385                textPos += len;
3386
3387                width += w;
3388
3389                if(nextSpace)
3390                {
3391                   x += width;
3392                   width = 0;
3393                }
3394             }
3395             if(curPosition < textPos || textPos == textBlock.textLen)
3396             {
3397                int len = curPosition - startPos;
3398                display.FontExtent(textBlock.font.font, text + startPos, len, &tw, null);
3399                sx += tw;
3400                break;            
3401             }
3402             sy += th;
3403             sx = textBlock.startX;
3404          }
3405          if(setCaretX)
3406             caretX = sx;
3407          caretY = sy;
3408          SetCaret(sx, sy, th);
3409          {
3410             Point scrollPos = scroll;
3411             bool doScroll = false;
3412             if(sy - scroll.y + th > clientSize.h)
3413             {
3414                scrollPos.y = sy + th - clientSize.h;
3415                doScroll = true;
3416             }
3417             else if(sy - scroll.y < 0)
3418             {
3419                scrollPos.y = sy;
3420                doScroll = true;            
3421             }
3422             if(sx - scroll.x + 10 > clientSize.w)
3423             {
3424                scrollPos.x = sx + 10 - clientSize.w;
3425                doScroll = true;
3426             }
3427             else if(sx - scroll.x < 10)
3428             {
3429                scrollPos.x = sx - 10;
3430                doScroll = true;            
3431             }
3432             if(doScroll)
3433                scroll = scrollPos;
3434          }
3435       }
3436       else
3437          SetCaret(0,0,0);
3438    }
3439
3440    // Returns a character offset into the TextBlock from a window coordinate
3441    int TextPosFromPoint(int px, int py, Block * block)
3442    {
3443       Block parentBlock = this.textBlock.parent;
3444       Block textBlock;
3445       int result = 0;
3446       *block = this.textBlock;
3447
3448       px += scroll.x;
3449       py += scroll.y;
3450
3451       for(textBlock = parentBlock.subBlocks.first; textBlock; textBlock = textBlock.next)
3452       {
3453          int sx = textBlock.startX, sy = textBlock.startY;
3454          int th = 0;
3455          int textPos = 0;
3456          char * text = textBlock.text;
3457          int maxW;
3458          Block b = textBlock;
3459          int space;
3460
3461          if(textBlock.type != TEXT) continue;
3462
3463          while(b && b.type != TD) b = b.parent;
3464          if(b)
3465          {
3466             Block table = b;
3467             while(table && table.type != TABLE) table = table.parent;
3468             if(table)
3469                maxW = b.w - 2* table.cellPadding;
3470             else
3471                maxW = clientSize.w - 10 - sx;
3472          }
3473          else
3474             maxW = clientSize.w - 10 - sx;
3475          
3476          display.FontExtent(textBlock.font.font, " ", 1, &space, &th);
3477          //space = space/2+2;
3478          space = 2;
3479
3480          while(textPos < textBlock.textLen)
3481          {
3482             int startPos = textPos;
3483             int width = 0;
3484             int x = 0;
3485             bool lineComplete = false;
3486
3487             for(; textPos<textBlock.textLen && !lineComplete;)
3488             {
3489                int w;
3490                int len;
3491                char * nextSpace = strchr(text + textPos, ' ');
3492
3493                if(nextSpace)
3494                   len = (nextSpace - (text + textPos)) + 1;
3495                else
3496                   len = textBlock.textLen - textPos;
3497                
3498                display.FontExtent(textBlock.font.font, text + textPos, len, &w, &th);
3499
3500                sx = x + textBlock.startX;
3501                if(/*py >= sy && */py < sy + th && /*px >= sx-space && */px < sx + w-space)
3502                {
3503                   int c, numBytes;
3504                   char ch;
3505                   *block = textBlock;
3506                   for(c = textPos; (ch = text[c]); c += numBytes)
3507                   {
3508                      numBytes = UTF8_NUM_BYTES(ch);
3509                      display.FontExtent(textBlock.font.font, text + c, numBytes, &w, &th);
3510                      if(/*py >= sy && */py < sy + th && /*px >= sx-w/2-space && */px < sx + w -w/2-space)
3511                         break;
3512                      sx += w;
3513                   }
3514                   return c;
3515                }
3516
3517                if(x + width + w > maxW && x > 0)
3518                {
3519                   lineComplete = true;
3520                   break;
3521                }
3522                textPos += len;
3523
3524                width += w;
3525
3526                if(nextSpace)
3527                {
3528                   x += width;
3529                   width = 0;
3530                }
3531             }
3532             if(/*py >= sy && */py < sy + th)
3533             {
3534                *block = textBlock;
3535                return textBlock.textLen;
3536             }
3537             sy += th;
3538          }
3539          *block = textBlock;
3540          result = textBlock.textLen;
3541       }
3542       return result;
3543    }
3544 }
3545
3546 Application componentsApp;
3547
3548 class Documentor : GuiApplication
3549 {
3550    bool Init()
3551    {
3552       Platform os = GetRuntimePlatform();
3553       componentsApp = __ecere_COM_Initialize(false, 1, null);
3554       SetPrivateModule(componentsApp);
3555       SetGlobalContext(globalContext);
3556       SetExcludedSymbols(&excludedSymbols);
3557       SetDefines(&::defines);
3558       SetImports(&imports);
3559       
3560       SetGlobalData(globalData);
3561
3562       settingsContainer.dataOwner = &settings;
3563       settingsContainer.Load();
3564       if(!settings.docDir || !settings.docDir[0] )
3565       {
3566          if(os == win32) // if Windows OS then
3567          {
3568             char programFilesDir[MAX_LOCATION];
3569             char appData[MAX_LOCATION]; 
3570             char homeDrive[MAX_LOCATION];
3571             char winDir[MAX_LOCATION];
3572             GetEnvironment("APPDATA", appData, sizeof(appData));
3573             GetEnvironment("HOMEDRIVE", homeDrive, sizeof(homeDrive));
3574             GetEnvironment("windir", winDir, sizeof(winDir));
3575             if(GetEnvironment("ProgramFiles", programFilesDir, MAX_LOCATION))
3576             {
3577                PathCat(programFilesDir, "ECERE SDK\\doc");
3578                settings.docDir = programFilesDir;
3579             }
3580             else if(homeDrive && homeDrive[0])
3581             {
3582                PathCat(homeDrive, "ECERE SDK\\doc");
3583                settings.docDir = homeDrive;
3584             }
3585             else if(winDir && winDir[0])
3586             {
3587                PathCat(winDir, "..\\ECERE SDK\\doc");
3588                settings.docDir = winDir;
3589             }
3590             else
3591                settings.docDir = "C:\\ECERE SDK\\doc";
3592          }
3593          else // if Os is Linux, or Mac OSX or something else
3594             settings.docDir = "/usr/share/ecere/doc/";
3595          settingsContainer.Save();
3596       }
3597
3598       //if(argc > 1)
3599       {
3600       #if 0
3601          Module module = eModule_Load(componentsApp, "ecere" /*argv[1]*/, privateAccess);
3602          DataRow row;
3603          AddComponents(module, true);
3604          mainForm.browser.currentRow = row = mainForm.browser.FindSubRow((int)module);
3605          // mainForm.browser.currentRow = row = mainForm.browser.FindSubRow((int)eSystem_FindClass(componentsApp, "Window"));
3606          while((row = row.parent))
3607             row.collapsed = false;
3608       #endif
3609       }
3610       return true;
3611    }
3612
3613    void Terminate()
3614    {
3615       FreeContext(globalContext);
3616       FreeExcludedSymbols(excludedSymbols);
3617       ::defines.Free(FreeModuleDefine);
3618       imports.Free(FreeModuleImport);
3619
3620       FreeGlobalData(globalData);
3621       FreeTypeData(componentsApp);
3622       FreeIncludeFiles();
3623       delete componentsApp;
3624    }
3625 }
3626
3627 MainForm mainForm { };