7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
12 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
13 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
16 static Array<FileFilter> fileFilters
18 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
19 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
20 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
21 { $"Text files (*.txt)", "txt" },
22 { $"All files", null }
25 static Array<FileType> fileTypes
27 { $"eC Source Code", "ec", whenNoneGiven },
28 { $"Text Files", "txt", never }
31 static const char * iconNames[] =
33 "<:ecere>constructs/class.png",
34 "<:ecere>constructs/data.png",
35 "<:ecere>constructs/method.png",
36 "<:ecere>constructs/event.png",
37 "<:ecere>constructs/property.png",
38 "<:ecere>constructs/namespace.png",
39 "<:ecere>constructs/dataType.png",
40 "<:ecere>constructs/enumValue.png",
41 "<:ecere>constructs/dataPrivate.png",
42 "<:ecere>constructs/methodPrivate.png",
43 "<:ecere>constructs/propertyPrivate.png"
46 enum SheetType { methods, properties };
48 extern int __ecereVMethodID_class_OnEdit;
49 extern int __ecereVMethodID_class_OnDisplay;
50 extern int __ecereVMethodID_class_OnGetString;
51 extern int __ecereVMethodID_class_OnFree;
52 extern int __ecereVMethodID_class_OnCompare;
53 extern int __ecereVMethodID_class_OnCopy;
54 extern int __ecereVMethodID_class_OnSaveEdit;
55 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
60 bool ignoreBreakpoints:1;
62 bool oldImplementation:1;
65 class EditFileDialog : FileDialog
69 if(!ide.projectView && ideSettings.ideFileDialogLocation)
70 currentDirectory = ideSettings.ideFileDialogLocation;
71 return FileDialog::OnCreate();
75 EditFileDialog codeEditorFileDialog
77 type = multiOpen, text = $"Open",
78 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
79 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
82 EditFileDialog codeEditorFormFileDialog
84 type = open, text = $"Open Project",
85 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
86 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
89 define OpenBracket = '{';
90 define CloseBracket = '}';
95 actionDeleteMethod = 2,
96 actionDetachMethod = 3,
97 actionAttachMethod = 4,
98 actionReattachMethod = 5
101 //extern StatusField pos, ovr, caps, num;
102 //extern Class thisClass;
111 Expression ctxInsideExp;
112 Expression paramsInsideExp;
113 ClassFunction insideFunction;
116 const char * instanceName;
121 /****************************************************************************
123 ****************************************************************************/
125 static void OutputString(File f, const char * string)
128 for(c = 0; string[c]; c++)
130 if(string[c] == '\"')
132 else if(string[c] == '\\')
134 else if(string[c] == '\n')
145 // Consider merging with PrintType ?
146 void OutputType(File f, Type type, bool outputName)
150 if(type.kind != pointerType && type.constant)
158 if(!type.isSigned) f.Printf("unsigned ");
162 if(!type.isSigned) f.Printf("unsigned ");
166 if(!type.isSigned) f.Printf("unsigned ");
170 if(!type.isSigned) f.Printf("unsigned ");
174 if(!type.isSigned) f.Printf("unsigned ");
185 if(type._class && !strcmp(type._class.string, "class"))
187 switch(type.classObjectType)
190 f.Printf("any_object");
193 f.Printf("typed_object");
200 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
201 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
211 OutputType(f, type.type, false);
214 OutputType(f, type.type, false);
235 if(type.kind == arrayType)
238 f.Printf("%d", type.arraySize);
244 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
250 f.Seek(pos - *position, current);
252 // Try to delete spaces and \n before...
258 /*else if(ch == '\n')
260 // Look for // comments on the line before
261 EditBox editBox = f.editBox;
262 EditLine line = editBox.line;
269 for(c = 0; text[c]; c++)
278 if(text[c] == '/' && last == '/')
290 f.DeleteBytes(before);
295 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
300 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
302 // Cut & Paste function
308 f.Seek(loc.start.pos - position, current);
310 x1 = editBox.charPos;
311 y1 = editBox.lineNumber;
312 f.Seek(loc.end.pos - loc.start.pos, current);
314 x2 = editBox.charPos;
315 y2 = editBox.lineNumber;
316 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
318 *size = editBox.SelSize();
319 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
320 editBox.GetSel(*text, false);
323 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
324 f.Printf(""); // Make the stream point to where the editbox is
327 static int64 GetI64EnumValue(Class dataType, DataValue dataForm)
330 switch(dataType.typeSize)
333 if(!strcmp(dataType.dataTypeString, "byte"))
334 i64Value = dataForm.uc;
336 i64Value = dataForm.c;
339 if(!strcmp(dataType.dataTypeString, "uint16"))
340 i64Value = dataForm.us;
342 i64Value = dataForm.s;
345 if(!strcmp(dataType.dataTypeString, "uint"))
346 i64Value = dataForm.ui;
348 i64Value = dataForm.i;
351 if(!strcmp(dataType.dataTypeString, "uint64"))
352 i64Value = *(int64 *)&dataForm.ui64;
354 i64Value = dataForm.i64;
360 void Code_FixProperty(Property prop, Instance object)
362 Designer::FixProperty(prop, object);
365 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
368 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
370 Class dataType = prop.dataTypeClass;
373 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
375 if(dataType && dataType._vTbl && dataType.type == structClass)
377 void * dataForm = new0 byte[dataType.structSize];
378 void * dataTest = new0 byte[dataType.structSize];
380 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
381 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
383 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
385 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
391 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
393 void * dataForm, * dataTest;
394 bool isEditBoxContents = false;
395 bool freeDataForm = false, freeDataTest = false;
397 // Because contents property is broken for mutiline EditBox at the moment
398 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
399 isEditBoxContents = true;
401 if(isEditBoxContents && ((EditBox)selected.instance).multiLine)
403 dataForm = ((EditBox)selected.instance).multiLineContents;
407 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
408 if(isEditBoxContents && ((EditBox)test).multiLine)
410 dataTest = ((EditBox)test).multiLineContents;
414 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
416 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
418 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
422 // Temporary work around until we standardize how properties should manage memory
423 if(!strcmp(prop.name, "strings") && !strcmp(prop._class.name, "DirectoriesBox"))
424 freeDataForm = freeDataTest = true;
425 if(dataType.type == normalClass && dataType.structSize)
427 if(freeDataForm) eInstance_Delete(dataForm);
428 if(freeDataTest) eInstance_Delete(dataTest);
432 if(freeDataForm) delete dataForm;
433 if(freeDataTest) delete dataTest;
436 else if(dataType && dataType._vTbl)
438 DataValue dataForm, dataTest;
440 GetProperty(prop, selected.instance, &dataForm);
441 GetProperty(prop, test, &dataTest);
443 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
445 SetProperty(prop, test, dataForm);
447 // In case setting on test unset on real instance (e.g. isDefault)
448 if(strcmp(prop.name, "name"))
450 GetProperty(prop, selected.instance, &dataTest);
451 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
452 SetProperty(prop, selected.instance, dataForm);
461 bool Code_IsPropertyDisabled(ObjectInfo selected, const char * name)
463 bool disabled = false;
464 if(selected.oClass == selected)
467 if(selected.classDefinition)
469 for(def = selected.classDefinition.definitions->first; def; def = def.next)
471 if(def.type == defaultPropertiesClassDef)
474 for(prop = def.defProperties->first; prop; prop = prop.next)
476 if(prop.identifiers && prop.identifiers->first)
478 Identifier id = prop.identifiers->first;
479 if(prop.variable && !strcmp(id.string, name))
491 else if(selected.instCode)
494 if(selected.instCode.members)
496 for(members = selected.instCode.members->first; members; members = members.next)
498 if(members.type == dataMembersInit && members.dataMembers)
501 for(prop = members.dataMembers->first; prop; prop = prop.next)
503 if(prop.identifiers && prop.identifiers->first)
505 Identifier id = prop.identifiers->first;
506 if(prop.variable && !strcmp(id.string, name))
521 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
526 method.dataType = ProcessTypeString(method.dataTypeString, false);
527 if(!method.dataType.thisClass && !isForm)
530 method.dataType.thisClass = selectedClass;
532 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
533 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false, true);
535 method.dataType.thisClass = null;
539 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
541 bool confirmation = true;
542 Statement body = function.body;
543 // Check if it contains any code
544 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
546 // Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
547 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
548 Type dataType = method.dataType;
549 Type returnType = dataType.returnType;
550 Expression exp = null;
553 method.dataType = ProcessTypeString(method.dataTypeString, false);
555 confirmation = false;
557 // Check if default function should be calling base class:
558 if(object.instance._class._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/) // Temp Check for DefaultFunction
560 if(returnType.kind != voidType)
562 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
566 exp = stmt.expressions->first;
567 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
569 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
570 (exp.type != constantExp || strcmp(exp.constant, "1")))
575 if(exp.type != constantExp || strcmp(exp.constant, "0"))
590 if(returnType.kind != voidType)
592 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
593 exp = stmt.expressions->first;
595 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
596 exp = stmt.expressions->first;
599 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
603 Identifier id = exp.call.exp.identifier;
604 Class base = object.instance._class;
605 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
609 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
610 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
616 for(param = dataType.params.first; param; param = param.next)
618 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
623 arg = arg ?arg.next : null;
630 return !confirmation;
633 class CodeEditor : Window
635 background = colorScheme.marginColor;
636 borderStyle = sizableDeep;
641 isActiveClient = true;
642 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
645 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
646 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
648 SheetType sheetSelected;
653 Context globalContext { };
654 OldList excludedSymbols { offset = (uint)(uintptr)&((Symbol)0).left };
667 MethodAction methodAction;
669 ClassFunction function;
671 char methodName[1024];
676 bool membersListShown;
679 EditLine membersLine;
681 Type functionType, instanceType;
685 Point paramsPosition;
686 Expression functionExp;
689 BitmapResource icons[CodeObjectType];
691 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
692 FontResource normalFont { $"Tahoma", 8.25f, window = this };
694 Module privateModule;
695 NameSpace globalData;
698 OpenedFileInfo openedFileInfo;
700 FontResource font { codeFont.faceName, codeFont.size, codeFont.bold, codeFont.italic };
701 saveDialog = codeEditorFileDialog;
703 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
706 int maxLineNumberLength;
708 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
710 void ProcessCaretMove(EditBox editBox, int line, int charPos)
713 ObjectInfo classItem;
715 // OnActivateClient is called after OnActivate
718 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
721 if(sheet.codeEditor != this) return;
725 for(classItem = classes.first; classItem; classItem = classItem.next)
727 ClassDefinition classDef = classItem.classDefinition;
728 if(classDef && classDef.loc.Inside(line, charPos))
735 for(object = classItem.instances.first; object; object = object.next)
739 if(object.instCode.loc.Inside(line, charPos))
744 sheet.SelectObject(object);
746 sheet.SelectObject(classItem);
751 //sheet.SelectObject(null);
755 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
759 expectingMove = false;
765 if(line-1 != membersLoc.start.line)
771 if(charPos - 1 < membersLoc.start.charPos)
773 else if(charPos - 1 > membersLoc.end.charPos)
775 const char * buffer = membersLine.text;
776 //if(membersList.currentRow)
780 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
781 if(buffer[c] != ' ' && buffer[c] != '\t')
783 if(c < charPos && buffer[c])
790 membersList.Destroy(0);
791 membersListShown = false;
795 bool back = codeModified;
796 codeModified = false;
798 InvokeParameters(false, false, false);
799 /*if(membersListShown)
800 InvokeAutoComplete(false, 0, true);*/
807 watch(modifiedDocument)
809 ProjectView projectView = ide.projectView;
812 char buffer[MAX_LOCATION];
813 char * fullPath = GetSlashPathBuffer(buffer, fileName);
814 Array<ProjectNode> nodes = ide.workspace.GetAllProjectNodes(fullPath, false);
818 node.modified = modifiedDocument;
819 projectView.Update(null);
828 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
829 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
830 tabKey = true, smartHome = true;
831 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
832 selectionColor = colorScheme.selectionColor, selectionText = colorScheme.selectionText,
833 background = colorScheme.codeEditorBG, foreground = colorScheme.codeEditorFG, syntaxColorScheme = colorScheme.syntaxColors,
834 font = font, borderStyle = none;
835 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
837 bool OnMouseOver(int x, int y, Modifiers mods)
839 CodeEditor editor = (CodeEditor)master;
840 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
845 void NotifyCaretMove(EditBox editBox, int line, int charPos)
847 // Update Line Numbers
849 int oldLine = lastLine;
850 display.FontExtent(font.font, " ", 1, null, &spaceH);
852 Box box { 0, (oldLine-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, oldLine*spaceH-1 - editBox.scroll.y };
856 Box box { 0, (line-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, line*spaceH-1 - editBox.scroll.y };
861 if(ide.activeClient == this)
862 ProcessCaretMove(editBox, line, charPos);
864 openedFileInfo.CaretMove(line, charPos);
867 void NotifyOvrToggle(EditBox editBox, bool overwrite)
869 ide.UpdateStateLight(ide.ovr, overwrite);
872 void NotifyUpdate(EditBox editBox)
879 designer.modifiedDocument = true;
882 modifiedDocument = true;
885 bool NotifyUnsetModified(EditBox editBox)
887 modifiedDocument = false;
891 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
893 if(!loadingFile && after.y != before.y)
895 ProjectView projectView = ide.projectView;
896 if(projectView && fileName)
899 // HOW WE MIGHT WANT TO DO IT:
900 const char * text = before.line.text;
901 for(c = Min(before.line.count, before.x-1); c>= 0; c--)
902 if(!isspace(text[c]))
904 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
906 // HOW VISUAL STUDIO DOES IT:
908 char * text = after.line.text;
909 for(c = after.line.count-1; c>= 0; c--)
910 if(!isspace(text[c]))
912 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
915 Update({ 0, 0, editBox.position.x, clientSize.h });
923 for(oClass = classes.first; oClass; oClass = oClass.next)
926 for(object = oClass.instances.first; object; object = object.next)
930 object.instCode.loc.start.AdjustAdd(before, after);
931 object.instCode.loc.end.AdjustAdd(before, after);
936 oClass.classDefinition.loc.start.AdjustAdd(before, after);
937 oClass.classDefinition.loc.end.AdjustAdd(before, after);
943 expectingMove = true;
947 if(before.y != after.y)
951 const char * buffer = membersLine.text;
953 bool firstChar = true;
954 bool addedChar = false;
960 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
962 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
964 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
965 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
974 membersLoc.start.charPos++;
979 string[len++] = buffer[c];
983 row = membersList.currentRow;
984 if(row && row.selected)
988 membersLoc.start.charPos--;
996 row = membersList.FindSubString(string);
998 membersList.currentRow = row;
1001 row = membersList.FindSubStringi(string);
1003 membersList.currentRow = row;
1004 membersList.currentRow.selected = false;
1007 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
1011 row = membersList.currentRow;
1014 // Accept current string if hiding typing char
1015 if(hide && row && row.selected)
1017 const char * string = row.string;
1018 int len = strlen(string);
1019 membersLoc.end.charPos -= after.x - before.x;
1020 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1021 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1022 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1023 editBox.PutS(string);
1024 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1026 after.x += membersLoc.start.charPos + len - before.x;
1027 before.x = membersLoc.start.charPos + len;
1032 membersList.Destroy(0);
1033 membersListShown = false;
1036 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1038 EditLine line = editBox.line;
1039 const char * text = line.text;
1040 char ch = text[after.x-1];
1041 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1045 // Can we call invoke auto complete here instead?
1055 // Force caret update already...
1056 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1057 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1059 editBox.GetCaretPosition(&caret);
1063 // Go back in the buffer until no space before
1065 codeModified = true;
1069 EditBoxStream f { editBox = editBox };
1073 if(text[after.x-1] == '>')
1079 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1083 if(!f.Seek(-1, current))
1086 if(!isspace(ch)) break;
1087 f.Seek(-1, current);
1089 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1091 line = editBox.lineNumber + 1;
1092 charPos = editBox.charPos + 1;
1096 exp = FindExpTree(ast, line, charPos);
1100 Type type = exp.expType;
1102 if(type && text[after.x-1] != '.')
1104 if(type.kind == TypePointer || type.kind == TypeArray)
1110 membersList.Clear();
1113 if(membersList.rowCount)
1115 membersList.Sort(null, 1);
1116 membersList.master = this;
1118 caret.y += editBox.GetCaretSize();
1121 membersList.Create();
1124 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1125 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1126 Window parent = membersList.parent;
1128 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1130 y -= editBox.GetCaretSize() + membersList.GetHeight();
1131 membersAbove = true;
1134 membersAbove = false;
1136 membersList.position = { x, y };
1140 membersLoc.start.line = line - 1;
1141 membersLoc.start.charPos = oldCharPos;
1142 membersLoc.end = membersLoc.start;
1143 membersListShown = true;
1148 SetCurrentContext(globalContext);
1150 codeModified = true;
1151 skipModified = true;
1152 if(text[after.x-1] == ':')
1153 InvokeAutoComplete(false, 0, false);
1154 else if(text[after.x-1] == '.')
1155 InvokeAutoComplete(false, 1, false);
1156 else if(text[after.x-1] == '>')
1157 InvokeAutoComplete(false, 2, false);
1158 skipModified = false;
1160 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1162 codeModified = true;
1163 skipModified = true;
1165 if(InvokeAutoComplete(true, 0, false))
1167 if(ch == '(' || ch == OpenBracket)
1168 InvokeParameters(true, true, false);
1170 InvokeParameters(this.functionType ? false : true, false, false);
1173 // InvokeAutoComplete(true, 0, false);
1174 skipModified = false;
1176 else if(ch == ')' || ch == '}' || ch == ';')
1178 codeModified = true;
1179 skipModified = true;
1181 InvokeParameters(false, true, false);
1182 skipModified = false;
1186 bool back = codeModified;
1187 codeModified = false;
1189 InvokeParameters(false, false, true);
1190 if(membersListShown)
1191 InvokeAutoComplete(false, 0, true);
1192 codeModified = back;
1197 bool back = codeModified;
1198 codeModified = false;
1201 InvokeParameters(false, false, true);
1202 /*if(membersListShown)
1203 InvokeAutoComplete(false, 0, true);*/
1205 codeModified = back;
1212 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1214 if(!loadingFile && after.y != before.y)
1216 ProjectView projectView = ide.projectView;
1217 if(projectView && fileName)
1218 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1219 Update({ 0, 0, editBox.position.x, clientSize.h });
1227 for(oClass = classes.first; oClass; oClass = oClass.next)
1231 for(object = oClass.instances.first; object; object = object.next)
1235 loc = &object.instCode.loc;
1237 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1238 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1240 object.instCode = null;
1244 loc->start.AdjustDelete(before, after);
1245 loc->end.AdjustDelete(before, after);
1249 if(oClass.classDefinition)
1251 loc = &oClass.classDefinition.loc;
1252 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1253 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1255 oClass.classDefinition = null;
1259 loc->start.AdjustDelete(before, after);
1260 loc->end.AdjustDelete(before, after);
1265 if(membersListShown)
1268 if(pasteOperation || before.y != after.y)
1272 const char * buffer = membersLine.text;
1274 bool firstChar = true;
1278 if(before.x >= membersLoc.start.charPos)
1280 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1282 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1283 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1288 if(!isSpace) firstChar = false;
1291 string[len++] = buffer[c];
1296 // If deleting spaces before...
1297 for(c = before.x; c<membersLoc.start.charPos; c++)
1299 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1307 membersLoc.start.charPos = before.x;
1310 if(membersLoc.end.charPos >= after.x)
1312 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1314 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1315 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1320 if(!isSpace) firstChar = false;
1323 string[len++] = buffer[c];
1331 membersLoc.end.charPos -= after.x - before.x;
1335 row = membersList.FindSubString(string);
1338 row = membersList.FindSubStringi(string);
1340 membersList.currentRow = row;
1341 membersList.currentRow.selected = false;
1344 membersList.currentRow = row;
1346 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1351 membersList.Destroy(0);
1352 membersListShown = false;
1358 InvokeParameters(false, false);
1366 bool NotifyDropped(EditBox editBox, int x, int y)
1368 char * controlClass = toolBox.controlClass;
1369 if(controlClass && controlClass[0])
1373 ObjectInfo classObject;
1375 editBox.GoToLineNum(y);
1376 x = Min(x, editBox.line.count);
1377 editBox.GoToPosition(editBox.line, y, x);
1378 // Note: Uncommented this to drag objects after the member instance on which they are dropped
1379 editBox.NotifyCaretMove(this, editBox, y+1, x+1);
1381 classObject = selected ? selected.oClass : null;
1383 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1384 selected = classObject.instances.last;
1387 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1390 AddObject(control, &object);
1392 designer.CreateObject(control, object, false, classObject.instance);
1393 // designer.PostCreateObject(control, object, false, classObject.instance);
1394 designer.DroppedObject(control, object, false, classObject.instance);
1396 sheet.AddObject(object, object.name, typeData /* className*/, true);
1399 //codeModified = true;
1406 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1408 if(key == ctrlSpace)
1410 membersList.Destroy(0);
1411 membersListShown = false;
1412 InvokeAutoComplete(false, 0, false);
1415 else if(key == Key { space, ctrl = true, shift = true })
1416 InvokeParameters(false, true, false);
1417 else if(key == escape)
1418 ide.RepositionWindows(true);
1419 else if(key == ctrlF7)
1423 ProjectNode node = ide.projectView.GetNodeForCompilationFromWindow(this, false, null, null);
1427 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1428 $"It can't be compiled.");
1429 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1438 bool OnKeyDown(Key key, unichar ch)
1440 CodeEditor editor = (CodeEditor)master;
1441 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1443 if(editor.membersListShown)
1445 editor.membersList.Destroy(0);
1446 editor.membersListShown = false;
1449 if(editor.paramsShown)
1451 editor.paramsList.Destroy(0);
1452 editor.paramsShown = false;
1453 FreeType(editor.functionType);
1454 FreeType(editor.instanceType);
1456 editor.functionType = null;
1457 editor.instanceType = null;
1458 editor.paramsID = -1;
1462 return EditBox::OnKeyDown(key, ch);
1465 void OnVScroll(ScrollBarAction action, int position, Key key)
1467 if(anchor.left.distance)
1469 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1472 EditBox::OnVScroll(action, position, key);
1474 CodeEditor ce = (CodeEditor)parent;
1475 if(ce.openedFileInfo)
1476 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1480 void OnHScroll(ScrollBarAction action, int position, Key key)
1482 EditBox::OnHScroll(action, position, key);
1484 CodeEditor ce = (CodeEditor)parent;
1485 if(ce.openedFileInfo)
1486 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1493 fullRowSelect = false,
1496 borderStyle = bevel;
1497 // size = { 200, 400 };
1499 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1501 DataRow row = listBox.currentRow;
1504 const char * string = row.string;
1506 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1508 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1509 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1510 editBox.PutS(string);
1513 membersListShown = false;
1518 bool OnKeyDown(Key key, unichar ch)
1520 CodeEditor editor = (CodeEditor) master;
1521 if(key == escape || key == leftAlt || key == rightAlt ||
1522 (key.ctrl && key.code != left && key.code != right &&
1523 key.code != leftShift && key.code != rightShift && key.code != space))
1526 if(editor.paramsShown)
1530 editor.paramsList.Destroy(0);
1531 editor.paramsShown = false;
1533 if(editor.membersListShown)
1537 editor.membersList.Destroy(0);
1538 editor.membersListShown = false;
1541 FreeType(editor.functionType);
1542 editor.functionType = null;
1544 FreeType(editor.instanceType);
1545 editor.instanceType = null;
1547 editor.paramsID = -1;
1552 return editor.editBox.OnKeyDown(key, ch);
1556 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1558 CodeEditor editor = (CodeEditor)master;
1559 Window rw = previous ? previous.rootWindow : null;
1560 if(!active && rw != editor.paramsList)
1563 editor.membersListShown = false;
1565 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1568 bool OnKeyHit(Key key, unichar ch)
1570 CodeEditor editor = (CodeEditor) master;
1574 case enter: case tab:
1576 DataRow row = currentRow;
1577 if(row && row.selected)
1579 const char * string = row.string;
1581 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1582 editor.editBox.Delete(
1583 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1584 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1585 editor.editBox.PutS(string);
1588 editor.membersListShown = false;
1591 editor.editBox.OnKeyHit(key, ch);
1601 return ListBox::OnKeyHit(key, ch);
1607 // If before . or after
1608 //listBox.Destroy(true);
1609 result = editor.editBox.OnKeyHit(key, ch);
1624 clickThrough = true,
1626 borderStyle = contour,
1628 background = { 255,255,225 },
1630 OnKeyDown = membersList.OnKeyDown;
1632 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1634 CodeEditor editor = (CodeEditor)master;
1635 Window rw = previous ? previous.rootWindow : null;
1636 if(!active && previous != editor.editBox && rw != editor.membersList)
1639 editor.paramsShown = false;
1641 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1644 bool OnKeyHit(Key key, unichar ch)
1646 CodeEditor editor = (CodeEditor)master;
1648 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1651 bool result = true; editor.editBox.OnKeyHit(key, ch);
1652 return (!created) ? false : result;
1659 void OnRedraw(Surface surface)
1661 CodeEditor editor = (CodeEditor) master;
1662 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1664 Type methodType = null;
1668 int functionW, nameW = 0;
1670 int spaceW, spaceH, commaW, commaWB, parW;
1672 int maxW = 0, lineW = 0;
1678 Font font = editor.normalFont.font;
1679 Font boldFont = editor.boldFont.font;
1680 Display display = this.display;
1682 if(!type) { return; };
1684 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1686 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1687 display.FontExtent(font, ", ", 2, &commaW, null);
1688 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1689 display.FontExtent(font, ")", 1, &parW, null);
1692 if(editor.functionType && type.kind == functionType)
1694 PrintType(type.returnType, string, true, true);
1695 display.FontExtent(font, string, strlen(string), &functionW, null);
1697 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1698 totalW = nameW + functionW + 2 * parW;
1702 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1703 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1704 if(instanceName && type.kind != functionType)
1705 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1706 totalW = functionW + nameW;
1707 surface.TextFont(boldFont);
1710 surface.WriteText(x, y, string, strlen(string));
1711 x += functionW + spaceW;
1713 if(editor.functionType)
1716 surface.WriteText(x, y, type.name, strlen(type.name));
1718 surface.WriteText(x, y, "(", 1);
1721 if(methodType && !methodType.staticMethod && methodType.methodClass)
1725 if(id == editor.paramsID)
1726 surface.TextFont(boldFont);
1728 if(methodType.methodClass)
1729 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1733 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1734 width += ((id == editor.paramsID) ? commaWB : commaW);
1739 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1744 x = 2 + nameW + spaceW + functionW + parW;
1748 if(methodType.methodClass)
1749 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1752 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1754 surface.WriteText(x, y, ",", 1);
1755 x += ((id == editor.paramsID) ? commaWB : commaW);
1763 if(id == editor.paramsID)
1764 surface.TextFont(font);
1768 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1770 for(param = type.params.first; param; param = param.next)
1772 char paramString[1024];
1775 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1776 surface.TextFont(boldFont);
1779 PrintType(param, paramString, true, true);
1780 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1782 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1787 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1792 x = 2 + nameW + spaceW + functionW + parW;
1796 surface.WriteText(x, y, paramString, strlen(paramString));
1800 surface.WriteText(x, y, ",", 1);
1801 x += ((id == editor.paramsID) ? commaWB : commaW);
1809 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1810 surface.TextFont(font);
1815 surface.WriteText(x, y, ")", 1);
1817 else if(instanceName && type.kind != functionType)
1819 surface.WriteText(x, y, instanceName, strlen(instanceName));
1823 bool OnResizing(int * w, int * h)
1825 CodeEditor editor = (CodeEditor) master;
1826 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1828 Type methodType = null;
1832 int functionW = 0, nameW = 0;
1834 int spaceW, spaceH, commaW, commaWB, parW;
1836 int maxW = 0, lineW = 0;
1841 Font font = editor.normalFont.font;
1842 Font boldFont = editor.boldFont.font;
1843 Display display = this.display;
1845 if(type.kind == TypeKind::methodType)
1848 ProcessMethodType(type.method);
1849 type = type.method.dataType;
1852 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1853 display.FontExtent(font, ", ", 2, &commaW, null);
1854 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1855 display.FontExtent(font, ")", 1, &parW, null);
1858 if(editor.functionType && type && type.kind == functionType)
1860 PrintType(type.returnType, string, true, true);
1861 display.FontExtent(font, string, strlen(string), &functionW, null);
1863 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1864 totalW = nameW + spaceW + functionW + 2 * parW;
1868 PrintType(type, string, false, true); // /*true);
1869 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1870 if(instanceName && type.kind != functionType)
1871 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1872 totalW = functionW + nameW + spaceW;
1875 if(editor.functionType)
1881 if(methodType.methodClass)
1882 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1883 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1884 width += ((id == editor.paramsID) ? commaWB : commaW);
1889 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1902 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1904 for(param = type.params.first; param; param = param.next)
1906 char paramString[1024];
1910 PrintType(param, paramString, true, true);
1911 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1913 width += ((id == editor.paramsID) ? commaWB : commaW);
1918 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1935 *w = realW + totalW + 4;
1941 Menu fileMenu { menu, $"File", f };
1942 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1943 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1945 Menu editMenu { menu, $"Edit", e };
1946 MenuDivider { editMenu };
1947 MenuItem clearTrailingSpacesItem
1949 editMenu, $"Clear trailing spaces", t, Key { t, ctrl = true, shift = true };
1951 bool NotifySelect(MenuItem selection, Modifiers mods)
1953 // Nuke trailing spaces
1956 editBox.recordUndoEvent = true;
1957 for(line = editBox.firstLine; line; line = line.next, y++)
1959 const String buffer = line.text;
1960 int count = line.count, i = count-1;
1961 while(i >= 0 && isspace(buffer[i])) i--;
1963 editBox.Delete(line, y, i + 1, line, y, count);
1965 editBox.recordUndoEvent = false;
1970 Menu debugMenu { menu, $"Debug", d };
1971 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1972 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1973 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1974 MenuItem debugSkipRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level Skipping Breakpoints", g, Key { f10, shift = true, alt = true }, id = RTCMenuBits { true, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1976 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1977 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1978 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1979 MenuItem debugBpSkipRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level Skipping Breakpoints"/*, g, Key { f10, shift = true, alt = true }*/, id = RTCMenuBits { true, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1981 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1983 ProjectView projectView = ide.projectView;
1984 if(!projectView.buildInProgress)
1986 RTCMenuBits bits = (RTCMenuBits)selection.id;
1987 int line = editBox.lineNumber + 1;
1990 CompilerConfig compiler = ideConfig.compilers.GetCompilerConfig(ide.workspace.activeCompiler);
1991 ProjectConfig config = projectView.project.config;
1992 int bitDepth = ide.workspace.bitDepth;
1993 bool useValgrind = ide.workspace.useValgrind;
1994 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
2000 MenuDivider { debugMenu };
2001 MenuItem debugToggleBreakpoint
2003 debugMenu, $"Toggle Breakpoint", t, f9;
2004 bool NotifySelect(MenuItem selection, Modifiers mods)
2006 ProjectView projectView = ide.projectView;
2007 if(projectView && fileName)
2009 int line = editBox.lineNumber + 1;
2010 ide.debugger.ToggleBreakpoint(fileName, line);
2020 //MenuItem viewDesignerItem, viewProperties, viewMethods;
2024 designer.parent = parent;
2027 toolBox = ((IDEWorkSpace)master).toolBox;
2029 // Debugger bug here: value of toolBox appears as 0
2031 sheet = ((IDEWorkSpace)master).sheet;
2036 bool OnClose(bool parentClosing)
2040 if(ide.workspace && fileName)
2041 ide.workspace.UpdateOpenedFileInfo(fileName, closed, false);
2042 if(inUseDebug && !debugClosing)
2044 debugClosing = true;
2046 if(CloseConfirmation(false))
2049 if(modifiedDocument)
2050 OnFileModified({ modified = true }, null);
2052 debugClosing = false;
2055 if(designer && !designer.closing)
2057 if(designer.visible)
2064 //Window formEditor = designer;
2065 //formEditor.Destroy(0);
2068 ide.AdjustFileMenus();
2073 void OnDestroy(void)
2075 ObjectInfo oClass, next;
2076 // Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2078 FreeType(this.functionType);
2079 FreeType(this.instanceType);
2084 designer.codeEditor = null;
2085 designer.Destroy(0);
2089 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2091 ObjectInfo object, next;
2093 for(object = oClass.instances.first; object; object = next)
2098 Designer::DestroyObject(object.instance);
2099 delete object.instance;
2101 if(object.i18nStrings)
2103 Map<String, bool> i18nStrings = object.i18nStrings;
2106 sheet.DeleteObject(object);
2108 oClass.instances.Delete(object);
2112 Designer::DestroyObject(oClass.instance);
2113 delete oClass.instance;
2115 if(oClass.i18nStrings)
2117 Map<String, bool> i18nStrings = oClass.i18nStrings;
2120 sheet.DeleteObject(oClass);
2122 classes.Delete(oClass);
2127 if(sheet.codeEditor == this)
2129 sheet.codeEditor = null;
2130 toolBox.codeEditor = null;
2136 ProjectView projectView = ide.projectView;
2139 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false, null);
2140 if(node && node.modified)
2142 node.modified = false;
2143 projectView.Update(null);
2149 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2151 // WHY WAS THIS HERE? I think this was here because once you move a window in the ide it's hard to reposition it correctly
2153 if(directActivation)
2154 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2156 if(active && directActivation)
2160 openedFileInfo.Activate();
2164 Location * loc = null;
2165 UpdateFormCode(); // To ensure update when modifying properties...
2167 // Got to the right spot in code so we don't lose our form selection...
2170 if(selected.instCode)
2171 loc = &selected.instCode.loc;
2172 else if(selected.classDefinition)
2173 loc = &selected.classDefinition.loc;
2175 line = editBox.lineNumber + 1;
2176 charPos = editBox.charPos + 1;
2181 if(selected && !loc->Inside(line, charPos))
2183 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2184 line = editBox.lineNumber + 1;
2185 charPos = editBox.charPos + 1;
2187 else if(selected && selected.classDefinition)
2190 for(object = selected.instances.first; object; object = object.next)
2194 if(object.instCode.loc.Inside(line, charPos))
2200 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2201 line = editBox.lineNumber + 1;
2202 charPos = editBox.charPos + 1;
2207 ProcessCaretMove(editBox, line, charPos);
2212 if(membersListShown)
2214 membersList.Destroy(0);
2215 membersListShown = false;
2219 paramsList.Destroy(0);
2220 paramsShown = false;
2221 FreeType(functionType);
2222 FreeType(instanceType);
2224 functionType = null;
2225 instanceType = null;
2232 bool OnSaveFile(const char * fileName)
2239 f = FileOpen(fileName, write);
2242 if(!ide.projectView)
2243 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2247 this.fileName = fileName; // Put this here because the form designer will check for it...
2248 designer.fileName = fileName;
2249 designer.modifiedDocument = false;
2252 editBox.Save(f, false);
2253 modifiedDocument = false;
2261 bool OnFileModified(FileChange fileChange, const char * param)
2263 bool reload = false;
2264 if(visible == false && inUseDebug == true)
2265 ide.debugger.WatchesReleaseCodeEditor();
2270 sprintf(message, $"The document %s was modified by another application.\n"
2271 "Would you like to reload it and lose your changes?", fileName);
2272 if(MessageBox { creationActivation = flash, type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2273 contents = message }.Modal() == yes)
2279 File f = FileOpen(fileName, read);
2282 int lineNumber, charPos, len;
2286 updatingCode = true;
2287 lineNumber = editBox.lineNumber;
2288 charPos = editBox.charPos;
2289 scroll = editBox.scroll;
2292 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2293 len = strlen(editBox.line.text);
2294 editBox.GoToLineNum(lineNumber);
2295 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2296 editBox.scroll = scroll;
2297 updatingCode = false;
2298 loadingFile = false;
2300 codeModified = true;
2304 designer.modifiedDocument = false;
2306 modifiedDocument = false;
2314 void OnRedraw(Surface surface)
2317 surface.SetBackground(colorScheme.marginColor);
2318 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2319 if(ideSettings.showLineNumbers)
2321 int currentLineNumber;
2323 char lineFormat[16];
2327 surface.textOpacity = false;
2328 surface.font = font.font;
2329 surface.TextExtent(" ", 1, null, &spaceH);
2330 currentLineNumber = editBox.scroll.y / spaceH + 1;
2331 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2333 surface.SetForeground(colorScheme.lineNumbersColor);
2334 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2336 // Highlight current line
2337 if(editBox.lineNumber == currentLineNumber - 1)
2339 surface.SetBackground(colorScheme.selectedMarginColor);
2340 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2341 surface.SetBackground(colorScheme.marginColor);
2343 sprintf(lineText, lineFormat, currentLineNumber);
2344 if(currentLineNumber <= editBox.numLines)
2345 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2346 currentLineNumber++;
2350 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2352 bool error, bpOnTopFrame, breakpointEnabled[128];
2353 int lineCursor, lineTopFrame, breakpointLines[128];
2354 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2355 Debugger debugger = ide.debugger;
2356 BitmapResource bmpRes;
2358 boxH = clientSize.h;
2359 scrollY = editBox.scroll.y;
2360 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2362 bpOnTopFrame = false;
2363 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2366 for(i = 0; i < count; i++)
2368 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2370 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2371 if(breakpointLines[i] == lineTopFrame)
2372 bpOnTopFrame = true;
2375 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2377 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2380 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2381 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2382 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2384 if(editBox.anchor.left.distance)
2386 if(editBox.horzScroll && editBox.horzScroll.visible)
2388 surface.SetBackground(control);
2389 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2394 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2399 lineY = (line - 1) * lineH;
2400 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2402 Bitmap bitmap = resource.bitmap;
2404 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2411 char ext[MAX_EXTENSION];
2412 const char * fileName = property::fileName;
2414 if(SearchString(fileName, 0, "Makefile", false, true))
2415 editBox.useTab = true;
2416 designer.fileName = fileName;
2420 GetExtension(fileName, ext);
2422 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2423 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2424 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2425 editBox.syntaxHighlighting = true;
2427 editBox.syntaxHighlighting = false;
2429 if(parsing && !strcmpi(ext, "ec"))
2431 codeModified = true;
2435 maxLineNumberLength = 0;
2440 bool UpdateMarginSize()
2442 if(ideSettings.showLineNumbers)
2444 int numLen = Max(4, nofdigits(editBox.numLines));
2446 maxLineNumberLength = numLen;
2447 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2448 editBox.anchor = Anchor
2450 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2451 right = 0, top = 0, bottom = 0
2456 maxLineNumberLength = 0;
2457 editBox.anchor = Anchor
2459 left = editBox.syntaxHighlighting * 20,
2460 right = 0, top = 0, bottom = 0
2472 bool LoadFile(const char * filePath)
2474 File f = FileOpen(filePath, read);
2477 // Added this here...
2478 fileName = filePath;
2480 updatingCode = true;
2482 updatingCode = false;
2483 loadingFile = false;
2492 void AdjustDebugMenus()
2494 bool unavailable = ide.areDebugMenusUnavailable;
2495 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2496 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2497 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2499 debugRunToCursor.disabled = isNotNotRunning;
2500 debugSkipRunToCursor.disabled = isNotNotRunning;
2501 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2502 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2504 debugBpRunToCursor.disabled = isNotNotRunning;
2505 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2506 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2507 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2509 debugToggleBreakpoint.disabled = noBreakpointToggle;
2516 globalData.classes.CompareKey = (void *)BinaryTree::CompareString;
2517 globalData.defines.CompareKey = (void *)BinaryTree::CompareString;
2518 globalData.functions.CompareKey = (void *)BinaryTree::CompareString;
2519 globalData.nameSpaces.CompareKey = (void *)BinaryTree::CompareString;
2522 designer.fileName = fileName;
2528 sprintf(title, $"Untitled %d", documentID);
2529 // designer.fileName = CopyString(title);
2530 designer.fileName = title;
2535 for(c = 0; c < CodeObjectType::enumSize; c++)
2536 icons[c] = BitmapResource { iconNames[c], window = this };
2538 codeModified = true;
2551 selected.modified = true;
2552 selected.oClass.modified = true;
2554 designer.modifiedDocument = true;
2555 modifiedDocument = true;
2556 formModified = true;
2559 /****************************************************************************
2561 ****************************************************************************/
2565 Class windowClass = eSystem_FindClass(privateModule, "ecere::gui::Window");
2566 if(windowClass && windowClass.data)
2567 UnapplySkin(windowClass);
2570 SetCurrentNameSpace(null);
2576 defines.Free(FreeModuleDefine);
2577 imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2579 FreeExcludedSymbols(excludedSymbols);
2580 FreeContext(globalContext);
2582 FreeGlobalData(&globalData);
2583 FindCtx_Terminate();
2584 FindParams_Terminate();
2586 if(GetGlobalContext() == globalContext)
2588 SetGlobalData(null);
2589 SetGlobalContext(null);
2590 SetExcludedSymbols(null);
2591 SetTopContext(null);
2592 SetCurrentContext(null);
2595 SetPrivateModule(null);
2598 // Note: This code should probably be merged with FreeParser()
2605 defines.Free(FreeModuleDefine);
2606 imports.Free(FreeModuleImport);
2608 FreeContext(this.globalContext);
2609 FreeExcludedSymbols(this.excludedSymbols);
2612 FreeGlobalData(&this.globalData);
2614 if(this.privateModule)
2616 FreeTypeData(this.privateModule);
2617 delete this.privateModule;
2623 static bool reentrant = false;
2628 char * selectedClassName = null, * selectedName = null;
2629 int selectedPos = 0;
2630 Designer backDesigner;
2631 char oldWorkDir[MAX_LOCATION];
2632 char mainModuleName[MAX_FILENAME] = "";
2633 const char * fileName;
2634 ImportedModule module;
2635 char extension[MAX_EXTENSION];
2636 PathBackup pathBackup { };
2638 Time parseCodeStart = GetTime();
2639 Time startTime, startFindClass;
2641 findClassTotalTime = 0;
2642 checkTypeTotalTime = 0;
2643 externalImportTotalTime = 0;
2644 findClassIgnoreNSTotalTime = 0;
2645 findSymbolTotalTime = 0;
2646 //ResetClassFindTime();
2650 // This temporarily fixes issue with 2 overrides in release mode with VC6 (only happens with both ecere.dll and ecere-ide.exe compiled in release mode)
2651 if(reentrant) return;
2658 selectedClassName = CopyString(oClass.name);
2659 if(selected != oClass)
2661 ObjectInfo object = this.selected;
2662 selectedName = CopyString(object.name);
2666 for(check = this.oClass.instances.first; check; check = check.next)
2678 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2681 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2682 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2683 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2684 "/I T:\\ecere\\include /E %s", argv[1]);
2688 ChangeWorkingDir("e:\\ec");
2689 sprintf(command, "gcc -x c -E -");
2690 fileInput = DualPipeOpen({ output = true, input = true }, command);
2691 SetFileInput(fileInput);
2696 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2698 fileInput.Write(buffer, 1, count);
2703 fileInput.CloseOutput();
2707 // TOCHECK: COULDN'T WE CALL FreeParser here?
2709 FreeType(this.functionType);
2710 FreeType(this.instanceType);
2711 this.functionType = null;
2712 this.instanceType = null;
2715 sheet.SelectObject(null);
2721 // We don't want the designer to be notified of selection when deleting rows...
2722 backDesigner = designer;
2727 ObjectInfo _class, next;
2729 for(_class = classes.first; _class; _class = next)
2735 while((object = _class.instances.first))
2739 Designer::DestroyObject(object.instance);
2740 delete object.instance;
2742 if(object.i18nStrings)
2744 Map<String, bool> i18nStrings = object.i18nStrings;
2747 sheet.DeleteObject(object);
2749 _class.instances.Delete(object);
2753 Designer::DestroyObject(_class.instance);
2754 delete _class.instance;
2756 if(_class.i18nStrings)
2758 Map<String, bool> i18nStrings = _class.i18nStrings;
2761 sheet.DeleteObject(_class);
2763 classes.Delete(_class);
2768 designer = backDesigner;
2771 fileInput = editFile = EditBoxStream { editBox = editBox };
2772 SetFileInput(fileInput);
2776 SetGlobalData(&globalData);
2777 SetGlobalContext(globalContext);
2778 SetExcludedSymbols(&excludedSymbols);
2779 SetTopContext(globalContext);
2780 SetCurrentContext(globalContext);
2781 SetDefines(&defines);
2782 SetImports(&imports);
2785 startTime = GetTime();
2786 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2788 printf("classes.count: %d\n", globalContext.classes.count);
2793 CompilerConfig compiler = ideConfig.compilers.GetCompilerConfig(ide.workspace.activeCompiler);
2794 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2797 this.privateModule = __ecere_COM_Initialize((bool)(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4)), 1, null);
2799 SetPrivateModule(privateModule);
2802 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2803 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2804 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2805 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2806 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2809 fileName = this.fileName;
2811 if(ide.workspace && ide.workspace.projects && fileName)
2813 for(p : ide.workspace.projects)
2815 char path[MAX_LOCATION];
2817 MakePathRelative(fileName, p.topNode.path, path);
2818 MakeSlashPath(path);
2820 pn = p.topNode.FindWithPath(path, false);
2829 project = ide.project;
2831 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2833 ChangeWorkingDir(project.topNode.path);
2835 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2837 GetLastDirectory(fileName, mainModuleName);
2838 GetExtension(mainModuleName, extension);
2840 SetBuildingEcereCom(false);
2841 SetBuildingEcereComModule(false);
2843 // TODO: Get symbolsDir from project settings instead...
2846 CompilerConfig compiler = ideConfig.compilers.GetCompilerConfig(ide.workspace.activeCompiler);
2847 ProjectConfig config = project.config;
2848 int bitDepth = ide.workspace.bitDepth;
2849 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2850 SetSymbolsDir(objDir.dir);
2851 SetDefaultNameSpace(project.GetDefaultNameSpace(config));
2852 ide.SetPath(true, compiler, config, bitDepth);
2856 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2857 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2861 switch(__runtimePlatform)
2863 case win32: SetSymbolsDir("obj/debug.win32"); break;
2864 case tux: SetSymbolsDir("obj/debug.linux"); break;
2865 case apple: SetSymbolsDir("obj/debug.apple"); break;
2867 SetIncludeDirs(null);
2868 SetSysIncludeDirs(null);
2869 SetDefaultNameSpace(null);
2873 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2875 // TODO FIX for configless project
2876 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2878 for(item : ide.project.config.options.preprocessorDefinitions)
2880 if(!strcmp(item, "BUILDING_ECERE_COM"))
2882 SetBuildingEcereCom(true);
2889 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2890 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2891 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2892 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2893 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2894 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2895 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2896 strcmpi(mainModuleName, "Mutex.ec")))
2898 SetBuildingEcereComModule(true);
2901 // Predeclare all classes
2903 char symFile[MAX_FILENAME];
2904 char symLocation[MAX_LOCATION];
2905 ImportedModule module, next;
2907 GetLastDirectory(fileName, symFile);
2908 ChangeExtension(symFile, "sym", symFile);
2910 strcpy(symLocation, GetSymbolsDir());
2911 PathCat(symLocation, symFile);
2913 // if(!GetEcereImported() && !GetBuildingEcereCom())
2914 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2917 startTime = GetTime();
2919 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2921 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2926 startTime = GetTime();
2928 // LoadSymbols(symLocation, normalImport, true);
2929 LoadSymbols(symLocation, preDeclImport, false);
2931 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2934 for(module = defines.first; module; module = next)
2937 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2940 defines.Delete(module);
2945 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2947 SetDefaultDeclMode(privateAccess);
2948 SetDeclMode(privateAccess);
2952 SetDefaultDeclMode(defaultAccess);
2953 SetDeclMode(defaultAccess);
2956 StripExtension(mainModuleName);
2957 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2958 defines.AddName(module);
2961 // SetYydebug(true);
2966 startTime = GetTime();
2967 startFindClass = checkTypeTotalTime;
2971 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2973 CheckDataRedefinitions();
2976 SetIncludeDirs(null);
2977 SetSysIncludeDirs(null);
2988 startTime = GetTime();
2990 PrePreProcessClassDefinitions();
2991 ComputeModuleClasses(privateModule);
2992 PreProcessClassDefinitions();
2993 ProcessClassDefinitions();
2995 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2996 startTime = GetTime();
3001 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
3002 startTime = GetTime();
3004 ProcessInstantiations();
3006 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
3009 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
3011 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3012 if(!windowClass || windowClass.internalDecl)
3015 startTime = GetTime();
3017 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
3018 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
3019 eModule_Load(this.privateModule, "ecere", privateAccess);
3021 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
3024 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3026 if(windowClass && windowClass.data)
3027 ApplySkin(windowClass, app.currentSkin.name, null);
3031 startTime = GetTime();
3033 for(external = ast->first; external; external = external.next)
3035 if(external.type == classExternal)
3037 ClassDefinition _class = external._class;
3038 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3040 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3043 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3045 Instance instance = eInstance_New(regClass);
3046 ObjectInfo classObject
3048 name = CopyString(_class._class.name);
3049 instance = instance;
3050 classDefinition = _class;
3051 oClass = classObject;
3053 classes.Add(classObject);
3057 // Moved this at bottom so that the file dialog doesn't show up in eCom
3058 designer.CreateObject(instance, classObject, true, null);
3059 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3061 if(_class.definitions)
3065 for(def = _class.definitions->first; def; def = def.next)
3069 case defaultPropertiesClassDef:
3072 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3074 Identifier id = propDef.identifiers->first;
3077 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3080 Class propertyClass = prop.dataTypeClass;
3082 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3083 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3085 Expression computed;
3086 bool variable = true;
3088 FreeType(propDef.initializer.exp.destType);
3089 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3090 ProcessExpressionType(propDef.initializer.exp);
3092 computed = CopyExpression(propDef.initializer.exp);
3093 ComputeExpression(computed);
3094 if(computed.isConstant)
3096 switch(computed.type)
3099 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3101 String temp = new char[strlen(computed.string)+1];
3102 ReadString(temp, computed.string);
3103 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3106 if(!propDef.initializer.exp.intlString)
3108 Map<String, bool> i18nStrings = classObject.i18nStrings;
3110 classObject.i18nStrings = i18nStrings = { };
3111 i18nStrings[prop.name] = false;
3117 if((propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass) && !id.next)
3121 if(computed.instance._class && computed.instance._class.symbol &&
3122 computed.instance._class.symbol.registered &&
3123 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3125 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3127 // This was saved in the control and shouldn't be freed by FreeExpression...
3128 // (Not doing this anymore, incrementing refCount in pass15 instead)
3129 /*if(propertyClass.type == normalClass)
3130 computed.instance.data = null;*/
3138 Operand value = GetOperand(computed);
3139 DataValue valueData;
3140 valueData.i64 = value.i64;
3141 SetProperty(prop, instance, valueData);
3148 propDef.variable = true;
3149 FreeExpression(computed);
3154 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3155 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3156 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3159 // Maintain a list in FunctionDefinition of who is attached to it
3160 for(def = _class.definitions->first; def; def = def.next)
3162 if(def.type == functionClassDef)
3164 ClassFunction function = def.function;
3165 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3167 function.attached.Add(OldLink { data = method });
3177 case declarationClassDef:
3179 Declaration decl = def.decl;
3182 case instDeclaration:
3184 Instantiation inst = decl.inst;
3185 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3186 if(instClass && eClass_GetDesigner(instClass))
3188 Instance control = eInstance_New(instClass);
3193 oClass = classObject;
3197 classObject.instances.Add(object);
3199 // TOCHECK: Why is this needed now?
3200 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3201 def.object = object;
3203 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3205 designer.CreateObject(control, object, false, classObject.instance);
3206 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3216 // Second pass, process instantiation members
3218 for(def = _class.definitions->first; def; def = def.next)
3222 case declarationClassDef:
3224 Declaration decl = def.decl;
3227 case instDeclaration:
3229 Instantiation inst = decl.inst;
3230 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3231 if(instClass && eClass_GetDesigner(instClass))
3234 object = object ? object.next : classObject.instances.first;
3235 control = object.instance;
3239 MembersInit members;
3240 for(members = inst.members->first; members; members = members.next)
3242 switch(members.type)
3244 case dataMembersInit:
3246 if(members.dataMembers)
3249 DataMember curMember = null;
3250 Class curClass = null;
3251 DataMember subMemberStack[256];
3252 int subMemberStackPos = 0;
3254 for(member = members.dataMembers->first; member; member = member.next)
3257 Identifier ident = member.identifiers ? member.identifiers->first : null;
3260 DataMember _subMemberStack[256];
3261 int _subMemberStackPos = 0;
3262 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3266 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3268 if(thisMember && thisMember.memberAccess == publicAccess)
3270 curMember = thisMember;
3271 curClass = curMember._class;
3272 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3273 subMemberStackPos = _subMemberStackPos;
3279 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3280 if(curMember) found = true;
3282 if(found && curMember.isProperty)
3284 Property prop = (Property) curMember;
3285 Class propertyClass = prop.dataTypeClass;
3286 bool variable = true;
3288 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3290 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3292 FreeType(member.initializer.exp.destType);
3293 member.initializer.exp.destType = MkClassType(propertyClass.name);
3296 Expression computed;
3298 ProcessExpressionType(member.initializer.exp);
3300 computed = CopyExpression(member.initializer.exp);
3303 bool isClass = propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass;
3306 /*char debugExpString[4096];
3307 debugExpString[0] = '\0';
3308 PrintExpression(member.initializer.exp, debugExpString);*/
3310 ComputeExpression(computed);
3312 switch(computed.type)
3315 if(isClass && computed.isConstant && computed.instance.data)
3317 if(computed.instance._class && computed.instance._class.symbol &&
3318 computed.instance._class.symbol.registered &&
3319 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3321 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3323 // This was saved in the control and shouldn't be freed by FreeExpression...
3324 // (Not doing this anymore, incrementing refCount in pass15 instead)
3325 /*if(propertyClass.type == normalClass)
3326 computed.instance.data = null;*/
3332 if(isClass && eClass_GetDesigner(propertyClass))
3335 char * name = computed.identifier.string;
3336 if(!strcmp(name, "this"))
3339 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3345 for(check = classObject.instances.first; check; check = check.next)
3346 if(check.name && !strcmp(name, check.name))
3349 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3359 if(computed.member.exp.type == identifierExp)
3361 char * name = computed.member.exp.identifier.string;
3363 if(!strcmp(name, "this"))
3365 if(computed.member.member)
3367 char * name = computed.member.member.string;
3369 for(check = classObject.instances.first; check; check = check.next)
3370 if(check.name && !strcmp(name, check.name))
3373 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3381 for(check = classObject.instances.first; check; check = check.next)
3383 if(check.name && !strcmp(name, check.name))
3385 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3388 DataValue value { };
3389 GetProperty(getProperty, check.instance, &value);
3390 SetProperty(prop, control, value);
3401 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3403 String temp = new char[strlen(computed.string)+1];
3404 ReadString(temp, computed.string);
3405 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3408 if(!member.initializer.exp.intlString)
3410 Map<String, bool> i18nStrings = object.i18nStrings;
3412 object.i18nStrings = i18nStrings = { };
3413 i18nStrings[prop.name] = false;
3420 if(!isClass && computed.isConstant)
3422 if(!strcmp(propertyClass.dataTypeString, "float"))
3423 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3424 else if(!strcmp(propertyClass.dataTypeString, "double"))
3425 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3427 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3434 FreeExpression(computed);
3438 member.variable = true;
3440 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3441 member.initializer.exp.type == memberExp) // identifierExp
3443 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3444 if(method && method.type == virtualMethod)
3447 // Maintain a list in FunctionDefinition of who is attached to it
3448 for(def = _class.definitions->first; def; def = def.next)
3450 if(def.type == functionClassDef)
3452 ClassFunction function = def.function;
3453 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3454 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3456 function.attached.Add(OldLink { data = method });
3457 // Reference this particular instance?
3472 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3483 //designer.CreateObject(instance, classObject, true, null);
3484 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3486 designer.PostCreateObject(instance, classObject, true, null);
3488 //instance.state = Hidden;
3489 //instance.Create();
3490 //instance.SetState(Normal, true, 0);
3499 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3503 // Restore Selection
3504 if(selectedClassName)
3507 for(oClass = classes.first; oClass; oClass = oClass.next)
3509 if(!strcmp(oClass.name, selectedClassName))
3511 this.oClass = oClass;
3515 delete selectedClassName;
3523 for(check = this.oClass.instances.first; check; check = check.next)
3525 if(check.name && !strcmp(check.name, selectedName))
3527 this.selected = check;
3533 if(this.oClass.instances.first)
3534 this.selected = this.oClass.instances.first;
3536 this.selected = this.oClass;
3539 else if(selectedPos == -1 || !this.oClass.instances.count)
3540 this.selected = this.oClass;
3546 if(selectedPos > this.oClass.instances.count)
3548 for(check = this.oClass.instances.first; check; check = check.next)
3550 if(selectedPos == pos++)
3552 this.selected = check;
3560 this.oClass = classes.first;
3561 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3563 delete selectedName;
3564 SetSymbolsDir(null);
3566 if(sheet.codeEditor == this)
3567 sheet.SelectObject(selected);
3570 codeModified = false;
3572 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3575 InvokeParameters(false, false, false);
3578 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3584 ChangeWorkingDir(oldWorkDir);
3586 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3587 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3588 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3589 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3590 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3592 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3594 if(inUseDebug && ide.projectView)
3595 ide.debugger.EvaluateWatches();
3600 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3603 Window control = (Window)object.instance;
3604 ObjectInfo classObject = object.oClass;
3606 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3608 if(!strcmp(_class.name, "DesignerBase")) return;
3610 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3612 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3613 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3615 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3616 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3618 Class dataType = prop.dataTypeClass;
3620 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3624 if(dataType.type == structClass)
3626 void * dataForm = new0 byte[dataType.structSize];
3627 void * dataTest = new0 byte[dataType.structSize];
3629 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3630 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3632 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3634 char tempString[1024] = "";
3635 const char * string = "";
3636 bool needClass = true;
3640 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3642 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3644 eClass_FindNextMember(_class, curClass, curMember, null, null);
3645 if(*curMember != (DataMember)prop)
3646 f.Printf("%s = ", prop.name);
3648 *curMember = (DataMember)prop;
3649 *curClass = curMember->_class;
3652 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3654 f.Printf("%s", string);
3661 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3663 void * dataForm, * dataTest;
3664 bool isEditBoxContents = false;
3665 bool freeDataForm = false, freeDataTest = false;
3667 // Because contents property is broken for mutiline EditBox at the moment
3668 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
3669 isEditBoxContents = true;
3671 if(isEditBoxContents && ((EditBox)control).multiLine)
3673 dataForm = ((EditBox)control).multiLineContents;
3674 freeDataForm = true;
3677 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3678 if(isEditBoxContents && ((EditBox)test).multiLine)
3680 dataTest = ((EditBox)test).multiLineContents;
3681 freeDataTest = true;
3684 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3686 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3688 char tempString[1024] = "";
3689 const char * string = "";
3693 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3695 eClass_FindNextMember(_class, curClass, curMember, null, null);
3696 if(*curMember != (DataMember)prop)
3697 f.Printf("%s = ", prop.name);
3698 *curMember = (DataMember)prop;
3699 *curClass = curMember->_class;
3701 if(eClass_GetDesigner(dataType))
3703 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3704 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3705 f.Printf("this", prop.name);
3708 //ObjectInfo classObject;
3709 //for(classObject = classes.first; classObject; classObject = classObject.next)
3713 for(object = classObject.instances.first; object; object = object.next)
3715 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3717 f.Printf("%s", object.name);
3724 bool needClass = true;
3725 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3726 f.Printf("%s", string);
3733 bool needClass = true;
3734 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3736 if(!strcmp(dataType.dataTypeString, "char *"))
3738 Map<String, bool> i18nStrings = object.i18nStrings;
3740 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false, null))
3743 f.Printf("%s\"", i18n ? "$" : "");
3744 OutputString(f, string);
3748 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3750 f.Printf("%s", string);
3753 *lastIsMethod = false;
3756 if(freeDataForm) delete dataForm;
3757 if(freeDataTest) delete dataTest;
3761 DataValue dataForm, dataTest;
3763 GetProperty(prop, control, &dataForm);
3764 GetProperty(prop, test, &dataTest);
3766 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3768 char * string = null;
3769 char tempString[1024] = "";
3770 SetProperty(prop, test, dataForm);
3772 if(dataType.type != bitClass)
3774 bool needClass = true;
3776 if(dataType.type == enumClass)
3779 Class enumClass = eSystem_FindClass(privateModule, "enum");
3780 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3781 int64 i64Value = GetI64EnumValue(dataType, dataForm);
3783 for(value = e.values.first; value; value = value.next)
3785 if(value.data == i64Value)
3787 string = value.name;
3793 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3795 if(string && string[0])
3800 eClass_FindNextMember(_class, curClass, curMember, null, null);
3801 if(*curMember != (DataMember)prop)
3802 f.Printf("%s = ", prop.name);
3803 *curMember = (DataMember)prop;
3804 *curClass = curMember->_class;
3806 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3807 f.Printf("%sf", string);
3809 f.Printf("%s", string);
3813 else if(dataType.type == bitClass)
3815 bool needClass = true;
3817 if(*prev) f.Printf(", ");
3819 eClass_FindNextMember(_class, curClass, curMember, null, null);
3820 if(*curMember != (DataMember)prop)
3821 f.Printf("%s = ", prop.name);
3822 *curMember = (DataMember)prop;
3823 *curClass = curMember->_class;
3825 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3827 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3829 f.Printf("%s", string);
3831 *lastIsMethod = false;
3841 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3843 Instantiation inst = object.instCode;
3844 Window control = (Window)object.instance;
3846 bool methodPresent = false;
3847 bool lastIsMethod = true;
3853 // Instance removed, delete it
3854 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3856 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3857 position = inst.loc.end.pos + 1;
3861 bool multiLine = false;
3864 // Check if it's an unnamed instance
3867 f.Seek(inst.nameLoc.start.pos - position, current);
3868 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3869 position = inst.nameLoc.end.pos;
3871 f.Printf(object.name);
3876 if(isspace(ch) && ch != '\n')
3878 f.Seek(-1, current);
3886 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3888 f.Seek(pos - position, current);
3893 f.Seek(-1, current);
3902 f.Puts(object.name);
3907 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3908 methodPresent = true;
3916 if(ch == OpenBracket)
3922 // TODO: Simplify this?
3931 f.Seek(-1, current);
3932 DeleteJunkBefore(f, position, &position);
3944 if(ch == '\n') { toDelete = count; count = 0; }
3945 else if(isspace(ch)) count++;
3948 f.Seek(-1, current);
3952 toDelete += count - 6;
3956 toAdd = 6 - count;*/
3962 f.Seek(-toDelete-count, current);
3963 f.DeleteBytes(toDelete);
3964 f.Seek(count, current);
3967 DeleteJunkBefore(f, position, &position);
3969 // Removed this here as it was adding trailing spaces when adding a method
3974 for(c = 0; c<toAdd; c++)
3981 methodPresent = multiLine;
3983 //if(!prev) -- always false
3984 f.Printf(methodPresent ? "\n " : " ");
3989 // Instance not there, create a brand new one
3990 DeleteJunkBefore(f, position, &position);
3991 f.Printf(*firstObject ? "\n\n" : "\n");
3992 *firstObject = false;
3994 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3995 methodPresent = true;
4000 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
4002 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
4007 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
4009 f.Printf(" %s %c ", control._class.name, OpenBracket);
4015 Instance test = eInstance_New(control._class);
4016 DataMember curMember = null;
4017 Class curClass = null;
4020 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
4024 // Attach Method here
4025 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
4027 if(prev) f.Printf(", ");
4028 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
4033 if(inst && !object.deleted)
4035 MembersInit members;
4036 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
4038 DeleteJunkBefore(f, position, &position);
4040 // Instance already there, clear out the properties
4041 for(members = inst.members ? inst.members->first : null; members; members = members.next)
4043 if(members.type == dataMembersInit)
4047 if(members.dataMembers)
4049 bool keptMember = false;
4050 MemberInit lastKept = null;
4052 for(member = members.dataMembers->first; member; member = member.next)
4054 Identifier ident = member.identifiers ? member.identifiers->first : null;
4055 bool deleted = false;
4057 // For now delete if it's not a method
4058 if(!member.variable) // && ident)
4060 if(!ident || !ident.next)
4062 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4065 f.Seek(member.loc.start.pos - position, current);
4066 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4067 position = member.loc.end.pos;
4072 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4073 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4074 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4076 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4077 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4079 f.Seek(member.loc.start.pos - position, current);
4080 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4081 position = member.loc.end.pos;
4093 //f.Seek(member.loc.start.pos - position, current);
4094 //position = member.loc.start.pos;
4095 DeleteJunkBefore(f, member.loc.start.pos, &position);
4096 if(prev) f.Printf(", ");
4097 else if(keptMember) f.Printf(" ");
4102 if(!keptMember || !members.next)
4106 if(keptMember && lastKept != members.dataMembers->last)
4111 f.Seek(-1, current);
4117 f.Seek(-1, current);
4120 else if(!isspace(ch))
4122 f.Seek(-2, current);
4127 f.DeleteBytes(count);
4130 f.Seek(members.loc.end.pos - position, current);
4135 f.Seek(-1, current);
4137 position = members.loc.end.pos + 1;
4141 f.Seek(-1, current);
4142 position = members.loc.end.pos;
4148 lastIsMethod = false;
4153 DeleteJunkBefore(f, position, &position);
4156 if(lastKept != members.dataMembers->last)
4161 f.Seek(-1, current);
4167 f.Seek(-1, current);
4170 else if(!isspace(ch))
4172 f.Seek(-2, current);
4177 f.DeleteBytes(count);
4181 f.Seek(members.loc.end.pos - position, current);
4182 position = members.loc.end.pos;
4186 lastIsMethod = true;
4189 lastIsMethod = false;
4195 f.Seek(members.loc.end.pos - position, current);
4196 position = members.loc.end.pos;
4198 lastIsMethod = true;
4201 else if(members.type == methodMembersInit)
4203 if(this.methodAction == actionDeleteMethod && members.function == function);
4205 methodPresent = true;
4207 // Delete instance method here
4208 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4209 members.function == function)
4211 if(this.moveAttached && !*text)
4212 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4214 DeleteJunkBefore(f, members.loc.start.pos, &position);
4215 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4216 position = members.loc.end.pos + 1;
4221 DeleteJunkBefore(f, position, &position);
4225 DeleteJunkBefore(f, members.loc.start.pos, &position);
4226 lastIsMethod = true;
4230 f.Seek(members.loc.end.pos - position, current);
4231 position = members.loc.end.pos;
4233 DeleteJunkBefore(f, position, &position);
4242 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4244 Method method = this.method;
4245 DeleteJunkBefore(f, position, &position);
4251 if(!method.dataType)
4252 method.dataType = ProcessTypeString(method.dataTypeString, false);
4255 Type dataType = method.dataType;
4256 Type returnType = dataType.returnType;
4259 if(this.moveAttached)
4261 // Move function here:
4262 int newLen = strlen(method.name);
4267 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4269 // First change name of function
4270 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4271 *textSize += newLen - movedFuncIdLen;
4272 memcpy(*text + movedFuncIdPos, method.name, newLen);
4274 // Second, tab right
4277 for(c = 0; (*text)[c]; )
4280 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4283 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4284 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4288 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4298 // Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4300 // ADDING METHOD HERE
4302 OutputType(f, returnType, false);
4305 if(dataType.thisClass)
4307 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4309 if(dataType.thisClass.shortName)
4310 f.Printf(dataType.thisClass.shortName);
4312 f.Printf(dataType.thisClass.string);
4316 f.Printf(method.name);
4318 for(param = dataType.params.first; param; param = param.next)
4320 OutputType(f, param, true);
4325 f.Printf(" %c\n\n", OpenBracket);
4327 if(control._class._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/) // Temp Check for DefaultFunction
4329 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4330 f.Printf(" return true;\n");
4331 else if(returnType.kind != voidType)
4332 f.Printf(" return 0;\n");
4337 if(returnType.kind != voidType)
4338 f.Printf("return ");
4339 f.Printf("%s::%s(", control._class.name, method.name);
4340 for(param = dataType.params.first; param; param = param.next)
4342 if(param.prev) f.Printf(", ");
4343 if(param.kind != voidType)
4344 f.Printf(param.name);
4348 f.Printf(" %c\n", CloseBracket);
4354 if(!object.instCode)
4355 f.Printf(methodPresent ? " %c;" : "%c;", CloseBracket);
4356 else if(!object.deleted)
4358 // Turn this into a multiline instance when adding a method
4359 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4361 f.Printf(methodPresent ? "\n " : " ");
4363 f.Seek(inst.loc.end.pos + 1 - position, current);
4364 position = inst.loc.end.pos + 1;
4369 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4372 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4374 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4376 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4378 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4379 if(prop && prop.isProperty && !prop.conversion)
4381 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4382 (!prop.IsSet || prop.IsSet(classObject.instance)))
4384 Class dataType = prop.dataTypeClass;
4385 char tempString[1024] = "";
4386 char * string = null;
4387 bool specify = false;
4390 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4391 if(member && member._class == regClass)
4395 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4397 if(dataType && dataType.type == structClass)
4399 void * dataForm = new0 byte[dataType.structSize];
4400 void * dataTest = new0 byte[dataType.structSize];
4402 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4403 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4405 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4407 bool needClass = true;
4409 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4410 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4412 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4414 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4419 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4421 void * dataForm, * dataTest;
4422 bool isEditBoxContents = false;
4423 bool freeDataForm = false, freeDataTest = false;
4425 // Because contents property is broken for mutiline EditBox at the moment
4426 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
4427 isEditBoxContents = true;
4429 if(isEditBoxContents && ((EditBox)classObject.instance).multiLine)
4431 dataForm = ((EditBox)classObject.instance).multiLineContents;
4432 freeDataForm = true;
4435 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4436 if(isEditBoxContents && ((EditBox)test).multiLine)
4438 dataTest = ((EditBox)test).multiLineContents;
4439 freeDataTest = true;
4442 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4444 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4446 char tempString[1024] = "";
4447 char * string = null;
4448 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4450 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4452 // Shouldn't go here ...
4453 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4457 bool needClass = true;
4459 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4461 if(!strcmp(dataType.dataTypeString, "char *"))
4463 Map<String, bool> i18nStrings = classObject.i18nStrings;
4465 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false, null))
4468 f.Printf("\n %s%s = %s\"", specify ? "property::" : "", prop.name, i18n ? "$" : "");
4469 OutputString(f, string);
4473 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4475 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4478 if(freeDataForm) delete dataForm;
4479 if(freeDataTest) delete dataTest;
4483 DataValue dataForm, dataTest;
4485 GetProperty(prop, classObject.instance, &dataForm);
4486 GetProperty(prop, test, &dataTest);
4488 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4490 SetProperty(prop, test, dataForm);
4491 if(dataType.type == bitClass)
4493 bool needClass = true;
4494 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4496 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4498 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4502 bool needClass = true;
4503 if(dataType.type == enumClass)
4506 Class enumClass = eSystem_FindClass(privateModule, "enum");
4507 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4508 int64 i64Value = GetI64EnumValue(dataType, dataForm);
4510 for(value = e.values.first; value; value = value.next)
4512 if(value.data == i64Value)
4514 string = value.name;
4520 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4521 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4522 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4524 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4533 void UpdateFormCode()
4536 if(!parsing) return;
4543 else if(formModified)
4545 EditBoxStream f { editBox = editBox };
4549 Identifier movedFuncId;
4550 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4551 ObjectInfo classObject;
4555 editBox.recordUndoEvent = true;
4559 movedFuncId = GetDeclId(function.declarator);
4560 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4561 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4564 for(classObject = classes.first; classObject; classObject = classObject.next)
4566 ClassDefinition classDef = classObject.classDefinition;
4567 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4570 bool firstObject = true;
4571 ObjectInfo object = classObject.instances.first;
4572 bool lastIsDecl = false;
4574 if(!classObject.modified) continue;
4576 test = eInstance_New(regClass);
4579 // Put it in the same desktop window...
4580 designer.PrepareTestObject(test);
4582 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4583 //f.Printf("%c\n\n", OpenBracket);
4585 // Change the _class name
4586 f.Seek(classDef.nameLoc.start.pos - position, current);
4587 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4588 f.Printf(classObject.name);
4589 position = classDef.nameLoc.end.pos;
4592 // Go to block start, delete all until no white space, put \n
4596 f.Seek(classDef.blockStart.end.pos - position, current);
4597 position = classDef.blockStart.end.pos;
4599 for(; f.Getc(&ch); count++)
4603 f.Seek(-1, current);
4613 f.Seek(-count, current);
4615 f.DeleteBytes(count-back);
4617 position += count-back;
4620 // Output properties
4621 OutputClassProperties(classObject.instance._class, classObject, f, test);
4623 for(def = classDef.definitions->first; def; def = def.next)
4627 case defaultPropertiesClassDef:
4629 bool keptMember = false;
4631 MemberInit lastKept = null;
4634 DeleteJunkBefore(f, def.loc.start.pos, &position);
4636 // This was adding blank spaces between comment and properties -- What was it for?
4639 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4641 Identifier ident = propDef.identifiers->first;
4642 bool deleted = false;
4644 // For now delete if it's a prop
4645 if(!propDef.variable && ident)
4649 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4652 f.Seek(propDef.loc.start.pos - position, current);
4653 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4654 position = propDef.loc.end.pos;
4659 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4660 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4662 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4663 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4665 f.Seek(propDef.loc.start.pos - position, current);
4666 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4667 position = propDef.loc.end.pos;
4684 f.Seek(def.loc.end.pos - position - 1, current);
4689 f.Seek(-1, current);
4692 position = def.loc.end.pos;
4696 if(lastKept != def.defProperties->last)
4701 f.Seek(-1, current);
4707 f.Seek(-1, current);
4710 else if(!isspace(ch))
4712 f.Seek(-2, current);
4717 f.DeleteBytes(count);
4721 f.Seek(def.loc.end.pos - position, current);
4722 position = def.loc.end.pos;
4727 case declarationClassDef:
4729 Declaration decl = def.decl;
4731 if(decl.type == instDeclaration)
4733 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4735 while(def.object && object != def.object)
4737 if(object /*&& ((ObjectInfo)def.object).modified*/)
4738 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4739 object = object.next;
4742 DeleteJunkBefore(f, def.loc.start.pos, &position);
4743 f.Printf(firstObject ? "\n\n " : "\n ");
4744 firstObject = false;
4746 if(def.object && ((ObjectInfo)def.object).modified)
4747 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4749 object = object ? object.next : null;
4753 DeleteJunkBefore(f, def.loc.start.pos, &position);
4754 f.Printf(firstObject ? "\n\n " : "\n ");
4755 firstObject = false;
4761 DeleteJunkBefore(f, def.loc.start.pos, &position);
4762 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4767 case functionClassDef:
4769 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4770 if(!def.function.body) continue;
4774 DeleteJunkBefore(f, def.loc.start.pos, &position);
4777 // Delete _class methods
4778 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4779 def.function == function)
4784 if(moveAttached && !text)
4786 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4789 f.Seek(def.loc.end.pos - position, current);
4790 for(; f.Getc(&ch); count++)
4794 f.Seek(-1, current);
4798 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4800 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4801 position = def.loc.end.pos + count;
4804 // In case of detaching methods in the _class, simply rename the method
4805 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4807 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4808 f.DeleteBytes(movedFuncIdLen);
4810 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4813 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4814 function == def.function)
4816 // In case of attaching methods in the _class, simply rename the method
4817 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4818 position = function.loc.start.pos + movedFuncIdPos;
4819 f.DeleteBytes(movedFuncIdLen);
4820 if(method.dataType.thisClass)
4821 f.Printf("%s::", method.dataType.thisClass.string);
4822 f.Puts(method.name);
4823 position += movedFuncIdLen;
4828 DeleteJunkBefore(f, def.loc.start.pos, &position);
4829 if(def.type == memberAccessClassDef)
4832 firstObject = false;
4842 f.Seek(def.loc.end.pos - position, current);
4843 position = def.loc.end.pos;
4846 // Output attached methods
4847 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4849 DeleteJunkBefore(f, position, &position);
4850 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4853 // ********** INSTANCES ***************
4854 for(; object; object = object.next)
4856 if(!object.instCode)
4858 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4862 DeleteJunkBefore(f, position, &position);
4864 // ****************** METHODS ***********************
4865 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4867 // If detaching an instance method
4868 if(selected != classObject)
4870 int newLen = strlen(methodName);
4873 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4874 // Tab selection left
4877 for(c = 0; text[c]; )
4880 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4881 memmove(text+start, text+start+i, textSize+1-start-i);
4884 for(; text[c] && text[c] != '\n'; c++);
4890 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4891 textSize += newLen - movedFuncIdLen;
4892 memcpy(text + movedFuncIdPos, methodName, newLen);
4899 if(methodAction == actionAddMethod && selected == classObject)
4901 Method method = this.method;
4903 if(!method.dataType)
4904 method.dataType = ProcessTypeString(method.dataTypeString, false);
4906 // ADDING METHOD HERE
4908 Type dataType = method.dataType;
4909 Type returnType = dataType.returnType;
4911 // Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4915 OutputType(f, returnType, false);
4918 if(dataType.thisClass && !dataType.classObjectType)
4920 if(dataType.thisClass.shortName)
4921 f.Printf(dataType.thisClass.shortName);
4923 f.Printf(dataType.thisClass.string);
4926 f.Printf(method.name);
4928 for(param = dataType.params.first; param; param = param.next)
4930 OutputType(f, param, true);
4935 f.Printf(" %c\n\n", OpenBracket);
4937 if(test._class._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/) // Temp Check for DefaultFunction
4939 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4940 f.Printf(" return true;\n");
4941 else if(returnType && returnType.kind != voidType)
4942 f.Printf(" return 0;\n");
4947 if(returnType.kind != voidType)
4948 f.Printf("return ");
4950 char * name = ((Specifier)classDef.baseSpecs->first).name;
4951 Symbol _class = FindClass(name);
4952 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4954 for(param = dataType.params.first; param; param = param.next)
4956 if(param.prev) f.Printf(", ");
4957 if(param.kind != voidType)
4958 f.Printf(param.name);
4963 f.Printf(" %c", CloseBracket);
4967 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4973 editBox.recordUndoEvent = false;
4981 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4982 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4986 codeModified = false;
4987 formModified = false;
4989 moveAttached = false;
4994 int FindMethod(const char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4997 ClassFunction function = null;
5000 ObjectInfo object = this.selected;
5002 if(object && object == this.oClass)
5004 ClassDefinition classDef = object.oClass.classDefinition;
5006 if(classDef && classDef.definitions)
5008 for(def = classDef.definitions->first; def; def = def.next)
5010 if(def.type == functionClassDef && def.function.declarator)
5012 if(!strcmp(def.function.declarator.symbol.string, methodName))
5014 function = def.function;
5019 else if(def.type == defaultPropertiesClassDef)
5023 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
5025 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
5026 if(ident && !ident.next)
5028 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
5032 propLoc = propDef.loc;
5035 ClassDefinition classDef = object.oClass.classDefinition;
5037 if(classDef.definitions)
5039 for(def = classDef.definitions->first; def; def = def.next)
5041 if(def.type == functionClassDef)
5043 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
5045 function = def.function;
5064 Instantiation inst = object.instCode;
5066 // Check here to see if the method already exists, no need to call ModifyCode in that case
5067 if(inst && inst.members)
5069 MembersInit members;
5070 for(members = inst.members->first; members; members = members.next)
5072 switch(members.type)
5074 case dataMembersInit:
5076 if(members.dataMembers)
5079 for(member = members.dataMembers->first; member; member = member.next)
5081 Identifier ident = member.identifiers ? member.identifiers->first : null;
5082 if(ident && !ident.next)
5084 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5088 propLoc = member.loc;
5091 ClassDefinition classDef = object.oClass.classDefinition;
5093 if(classDef.definitions)
5095 for(def = classDef.definitions->first; def; def = def.next)
5097 if(def.type == functionClassDef)
5099 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5101 function = def.function;
5110 // TODO: Fix memory leak
5111 function = ClassFunction
5113 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5125 case methodMembersInit:
5127 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5129 function = members.function;
5141 if(functionPtr) *functionPtr = function;
5145 void GoToMethod(const char * methodName /*Method method*/)
5149 ObjectInfo object = selected;
5150 EditBoxStream f { editBox = editBox };
5151 ClassFunction function = null;
5152 bool atChar = false;
5156 Location propLoc = { {0,0,-1} };
5159 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5160 if(function && function.body)
5163 f.Seek(function.body.loc.start.pos+1, current);
5173 f.Seek(-1, current);
5178 else if(!isspace(ch))
5180 f.Seek(-1, current);
5186 else if(propLoc.start.pos > -1)
5188 f.Seek(propLoc.start.pos, current);
5191 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5193 if(function || propLoc.start.pos > -1)
5195 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5196 editBox.CenterOnCursor();
5197 SetState(normal, false, 0);
5200 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5202 FreeClassFunction(function);
5208 void FindCompatibleMethods(Method method, OldList compatible)
5210 ClassDefinition classDef = this.oClass.classDefinition;
5211 if(classDef && classDef.definitions)
5214 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5217 Symbol classSym { };
5218 Symbol selectedClass;
5219 if(this.selected == this.oClass)
5220 selectedClass = classSym;
5222 selectedClass = FindClass(this.selected.instance._class.name);
5224 regClass.name = classDef._class.name;
5225 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5226 for(def = classDef.definitions->first; def; def = def.next)
5228 if(def.type == functionClassDef && def.function.declarator)
5230 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5232 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5235 Type type = def.function.declarator.symbol.type;
5236 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5238 compatible.Add(OldLink { data = def.function });
5244 if(this.oClass && this.oClass.instance)
5246 classSym.registered = regClass;
5247 //classSym.registered = this.oClass.oClass;
5249 for(_class = regClass.base; _class; _class = _class.base)
5252 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5254 // TODO: Understand why these functions popup in attach list
5255 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5257 if(!testMethod.dataType)
5258 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5260 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5261 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5262 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5264 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5265 // ClassFunction function { };
5266 FunctionDefinition function { };
5268 function.declarator = Declarator { };
5269 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5270 excludedSymbols.Add(function.declarator.symbol);
5272 compatible.Add(OldLink { data = function });
5283 void AddMethod(Method method)
5287 char methodName[1024];
5288 strcpy(methodName, method.name);
5289 if(!FindMethod(methodName, null, null))
5291 methodAction = actionAddMethod;
5292 this.method = method;
5296 GoToMethod(methodName);
5300 void DeleteMethod(ClassFunction function)
5304 methodAction = actionDeleteMethod;
5305 this.function = function;
5313 void AttachMethod(Method method, ClassFunction function)
5317 // If it's an instance we'll ask if we want to move it inside...
5318 if(!function.attached.count && function.body)
5320 // Find the function in the _class to check if it's a virtual function
5321 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5322 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5323 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5325 for(def = this.classDefinition.first; def; def = def.next)
5327 if(def.type == functionClassDef)
5329 if(def.function == function)
5334 if(!method || method.type != virtualMethod)
5337 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5338 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5340 moveAttached = true;
5345 methodAction = actionAttachMethod;
5346 this.method = method;
5347 this.function = function;
5354 void ReAttachMethod(Method method, ClassFunction function)
5358 // If it's an instance we'll ask if we want to move it inside...
5359 if(!function.attached.count && function.body)
5361 // Find the function in the _class to check if it's a virtual function
5362 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5363 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5364 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5366 for(def = this.classDefinition.first; def; def = def.next)
5368 if(def.type == functionClassDef)
5370 if(def.function == function)
5375 if(!method || method.type != virtualMethod)
5378 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5379 if(MessageBox { type = yesNo, master = parent, text = title,
5380 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5382 moveAttached = true;
5387 methodAction = actionReattachMethod;
5388 this.method = method;
5389 this.function = function;
5396 void DetachMethod(Method method, ClassFunction function, int type)
5404 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5405 master = sheet, text = $"Name detached method", background = formColor
5409 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5410 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5414 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5415 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5419 dialog, anchor = { left = 5, right = 5, top = 5 }
5421 sprintf(methodName, "%s_%s", selected.name, method.name);
5422 nameBox.contents = methodName;
5424 result = dialog.Modal() == ok;
5425 strcpy(methodName, nameBox.contents);
5430 // If the method is not attached, move it outside
5433 // Add this class to the methodName
5434 char name[1024] = "";
5436 if(this.selected != this.oClass && !method.dataType.thisClass)
5438 strcat(name, this.selected.instance._class.name);
5440 strcat(name, this.methodName);
5441 strcpy(this.methodName, name);
5443 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5445 strcat(name, method.dataType.thisClass.string);
5447 strcat(name, this.methodName);
5448 strcpy(this.methodName, name);
5451 this.moveAttached = true;
5454 this.methodAction = actionDetachMethod;
5455 this.method = method;
5456 this.function = function;
5463 void AddObject(Instance instance, ObjectInfo * object)
5467 //*object = _class.instances.Add(sizeof(ObjectInfo));
5468 *object = ObjectInfo { };
5469 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5470 (*object).oClass = oClass;
5471 (*object).instance = instance;
5476 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5478 // if(strcmp(name, this.oClass.instance.name))
5481 for(check = oClass.instances.first; check; check = check.next)
5482 if(!check.deleted && check.name && !strcmp(name, check.name))
5486 (*object).name = CopyString(name);
5491 toolBox.controlClass = null;
5495 //sheet.AddObject(*object, (*object).name, TypeData, true);
5500 void EnsureUpToDate()
5502 if(sheet && codeModified && parsing)
5506 void SelectObject(ObjectInfo object)
5509 oClass = object ? object.oClass : null;
5511 designer.SelectObject(object, object ? object.instance : null);
5514 void SelectObjectFromDesigner(ObjectInfo object)
5517 sheet.SelectObject(object);
5520 void EnumerateObjects(Sheet sheet)
5524 for(oClass = classes.first; oClass; oClass = oClass.next)
5530 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5531 for(object = oClass.instances.first; object; object = object.next)
5532 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5535 sheet.SelectObject(selected);
5540 designer.AddObject();
5543 void DeleteObject(ObjectInfo object)
5545 delete object.instance;
5546 object.deleted = true;
5547 object.modified = true;
5548 object.oClass.modified = true;
5550 if(selected == object)
5552 bool looped = false;
5553 ObjectInfo select = object;
5557 select = select.prev;
5561 select = object.oClass.instances.last;
5568 sheet.SelectObject(select ? select : oClass);
5571 if(!object.instCode && object.oClass != object)
5574 oClass.instances.Delete(object);
5577 if(sheet.codeEditor == this)
5578 sheet.DeleteObject(object);
5581 void RenameObject(ObjectInfo object, const char * name)
5585 // Validate the name:
5586 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5587 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5590 for(c = 0; name[c]; c++)
5591 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5599 object.name = (name && name[0]) ? CopyString(name) : null;
5601 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5605 void DesignerModifiedObject()
5607 sheet.ListProperties(false);
5611 void ListSubMembers(Type member)
5615 for(subMember = member.members.first; subMember; subMember = subMember.next)
5619 DataRow row = membersList.AddString(subMember.name);
5620 row.icon = icons[typeData];
5624 ListSubMembers(subMember);
5629 void ListSubDataMembers(DataMember member, bool isPrivate)
5631 DataMember subMember;
5632 for(subMember = member.members.first; subMember; subMember = subMember.next)
5634 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5638 DataRow row = membersList.AddString(subMember.name);
5639 BitmapResource bitmap = null;
5640 if(!subMember.dataType)
5641 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5643 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5645 char * bitmapName = (char *)(intptr)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5648 bitmap = { bitmapName };
5649 membersList.AddResource(bitmap);
5652 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5656 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5662 void ListClassMembers(Class whatClass, bool methodsOnly)
5665 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5666 bool isPrivate = false;
5668 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5670 Method method, methodIt;
5672 DataMember memberIt;
5674 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5676 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5677 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5679 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5681 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5683 DataRow row = membersList.FindString(method.name);
5686 row = membersList.AddString(method.name);
5688 if(!method.dataType)
5689 method.dataType = ProcessTypeString(method.dataTypeString, false);
5691 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5699 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5703 if(memberIt.isProperty)
5705 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5707 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5711 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5713 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5716 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5722 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5724 if(member.isProperty)
5726 Property prop = (Property) member;
5727 if(!membersList.FindString(prop.name))
5729 DataRow row = membersList.AddString(prop.name);
5730 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5733 else if(member.name && !membersList.FindString(member.name))
5735 DataRow row = membersList.AddString(member.name);
5737 BitmapResource bitmap = null;
5738 if(!member.dataType)
5739 member.dataType = ProcessTypeString(member.dataTypeString, false);
5741 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5743 char * bitmapName = (char *)(intptr)eClass_GetProperty(member.dataType._class.registered, "icon");
5746 bitmap = { bitmapName };
5747 membersList.AddResource(bitmap);
5750 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5753 ListSubDataMembers(member, member.memberAccess == privateAccess);
5757 if(_class.inheritanceAccess == privateAccess)
5760 if(_class.module != privateModule) break;
5765 void ListClassMembersMatch(Class whatClass, Type methodType)
5768 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5769 bool isPrivate = false;
5771 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5775 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5777 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5779 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5781 if(!method.dataType)
5782 method.dataType = ProcessTypeString(method.dataTypeString, false);
5784 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false, true))
5786 DataRow row = membersList.FindString(method.name);
5789 row = membersList.AddString(method.name);
5790 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5796 if(_class.inheritanceAccess == privateAccess)
5799 if(_class.module != privateModule) break;
5804 void ListClassPropertiesAndVirtual(Class whatClass, const String curString)
5807 bool isPrivate = false;
5808 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5813 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5815 if(method.type == virtualMethod)
5817 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5819 DataRow row = membersList.FindString(method.name);
5822 row = membersList.AddString(method.name);
5824 if(!method.dataType)
5825 method.dataType = ProcessTypeString(method.dataTypeString, false);
5827 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5833 for(member = _class.membersAndProperties.first; member; member = member.next)
5835 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5837 if(member.isProperty)
5839 Property prop = (Property)member;
5841 DataRow row = membersList.AddString(prop.name);
5842 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5845 else if(member.name && (!curString || strcmp(curString, member.name)))
5847 DataRow row = membersList.AddString(member.name);
5849 BitmapResource bitmap = null;
5850 if(!member.dataType)
5851 member.dataType = ProcessTypeString(member.dataTypeString, false);
5853 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5855 char * bitmapName = (char *)(intptr)eClass_GetProperty(member.dataType._class.registered, "icon");
5858 bitmap = { bitmapName };
5859 membersList.AddResource(bitmap);
5862 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5865 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5868 if(_class.inheritanceAccess == privateAccess)
5871 if(_class.module != privateModule) break;
5876 void ListMembers(Type type)
5878 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5880 if(type.kind == classType)
5883 ListClassMembers(type._class.registered, false);
5888 for(member = type.members.first; member; member = member.next)
5892 DataRow row = membersList.AddString(member.name);
5893 row.icon = icons[typeData];
5895 else if(member.kind == structType || member.kind == unionType)
5896 ListSubMembers(member);
5902 void ListModule(Module mainModule, int recurse, bool listClasses)
5905 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5906 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5907 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5908 for(module = mainModule.application.allModules.first; module; module = module.next)
5910 if(ModuleVisibility(mainModule, module))
5911 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5915 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5922 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5924 Class _class = link.data;
5925 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5927 DataRow row = membersList.AddString(_class.name);
5928 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5933 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5935 //DefinedExpression definedExp = link.data;
5936 DataRow row = membersList.AddString(link /*definedExp*/.name);
5937 row.icon = icons[typeData];
5940 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5942 //GlobalFunction function = link.data;
5943 DataRow row = membersList.AddString(link /*function*/.name);
5944 row.icon = icons[typeMethod];
5948 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5950 if(recurse != 2 && listClasses)
5952 if(!membersList.FindString(ns->name))
5954 DataRow row = membersList.AddString(ns->name);
5955 row.icon = icons[typeNameSpace];
5960 ListNameSpace(ns, 2, listClasses);
5964 void ListEnumValues(Class _class)
5966 List<Class> classes { };
5967 for(; _class && _class.type == enumClass; _class = _class.base)
5968 classes.Insert(null, _class);
5969 for(_class : classes)
5971 EnumClassData enumeration = (EnumClassData)_class.data;
5973 for(item = enumeration.values.first; item; item = item.next)
5975 DataRow row = membersList.AddString(item.name);
5976 row.icon = icons[typeEnumValue];
5982 bool ListEnumsModule(Module mainModule, Type dest)
5984 bool result = false;
5986 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5987 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5988 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5989 for(module = mainModule.application.allModules.first; module; module = module.next)
5991 if(ModuleVisibility(mainModule, module))
5992 result |= ListEnums(module.publicNameSpace, dest);
5997 void ListNameSpaceByString(Module mainModule, const char * string)
5999 NameSpace * nameSpace;
6001 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
6002 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6003 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
6004 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6005 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
6006 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6007 for(module = mainModule.application.allModules.first; module; module = module.next)
6009 if(ModuleVisibility(mainModule, module))
6011 nameSpace = FindNameSpace(module.publicNameSpace, string);
6012 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6017 bool ListEnums(NameSpace nameSpace, Type dest)
6020 bool result = false;
6022 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
6024 Class _class = link.data;
6025 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *") && strcmp(dest._class.string, "bool"))) && !dest.classObjectType)) &&
6026 dest.kind != pointerType && dest.kind != ellipsisType)
6028 OldList conversions { };
6030 type.kind = classType;
6031 type._class = FindClass(_class.name);
6032 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false, true))
6034 ListEnumValues(_class);
6037 conversions.Free(null);
6041 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
6043 result |= ListEnums(nameSpace, dest);
6048 NameSpace * FindNameSpace(NameSpace nameSpace, const char * name)
6052 for(c = 0; (ch = name[c]); c++)
6054 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
6056 NameSpace * newSpace;
6057 char * spaceName = new char[c - start + 1];
6058 memcpy(spaceName, name + start, c - start);
6059 spaceName[c-start] = '\0';
6060 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
6064 nameSpace = newSpace;
6073 return (NameSpace *)nameSpace;
6076 void ListSymbols(Expression exp, bool enumOnly, const char * string, Identifier realIdentifier)
6078 bool listedEnums = false;
6079 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6080 bool listClasses = true;
6082 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6084 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6085 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6086 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6088 if(exp.type == identifierExp)
6089 id = realIdentifier;
6091 if(id && id._class && !id._class.name)
6093 listClasses = false;
6096 else if(id && id._class && id._class.name)
6100 Class _class = id.classSym.registered;
6101 if(_class && _class.type == enumClass)
6103 ListEnumValues(_class);
6106 ListClassMembers(id.classSym.registered, true);
6111 else if(id && colons)
6113 ListNameSpaceByString(this.privateModule, id.string);
6118 if(this.privateModule && destType && (destType.kind == _BoolType || destType.kind == classType || destType.kind == enumType || destType.kind == structType || destType.kind == templateType || destType.kind == thisClassType || destType.kind == unionType ||
6119 (destType.kind == pointerType && destType.type.kind != voidType)))
6120 //if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6122 listedEnums = ListEnumsModule(this.privateModule, destType);
6125 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6127 ListEnumValues(destType._class.registered);
6130 ListClassPropertiesAndVirtual(insideClass, null);
6134 else if(destType && destType.kind == enumType)
6138 for(value = destType.members.first; value; value = value.next)
6140 DataRow row = membersList.AddString(value.name);
6141 row.icon = icons[typeEnumValue];
6145 ListClassPropertiesAndVirtual(insideClass, null);
6149 else if(insideClass && !enumOnly)
6151 ListClassPropertiesAndVirtual(insideClass, string);
6154 if(listedEnums && string && string[0])
6156 DataRow row = membersList.FindSubString(string);
6158 listedEnums = false;
6161 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6163 ListClassMembersMatch(GetThisClass(), exp.destType);
6165 else if(!insideClass && !enumOnly && !listedEnums)
6168 Symbol symbol = null;
6172 ListClassMembers(GetThisClass(), false);
6175 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6177 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6179 // Don't list enum values?
6180 //if(symbol.type.kind != TypeEnum)
6181 DataRow row = membersList.FindString(symbol.string);
6184 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6186 row = membersList.AddString(symbol.string);
6187 if(symbol.type && symbol.type.kind == functionType)
6188 row.icon = icons[typeMethod];
6189 else if(symbol.type && symbol.type.kind == enumType)
6191 row.icon = icons[typeEnumValue];
6195 BitmapResource bitmap = null;
6196 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6198 char * bitmapName = (char *)(intptr)eClass_GetProperty(symbol.type._class.registered, "icon");
6201 bitmap = { bitmapName };
6202 membersList.AddResource(bitmap);
6205 row.icon = bitmap ? bitmap : icons[typeData];
6212 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6214 DataRow row = membersList.FindString(symbol.string);
6217 row = membersList.AddString(symbol.string);
6218 if(symbol.type.kind == functionType)
6219 row.icon = icons[typeMethod];
6220 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6222 row.icon = icons[typeClass];
6226 row.icon = icons[typeDataType];
6233 ListModule(this.privateModule, 1, listClasses);
6234 // TODO: Implement this with name space
6238 for(data = globalData.first; data; data = data.next)
6240 DataRow row = membersList.FindString(data.name);
6242 data.dataType = ProcessTypeString(data.dataTypeString, false);
6245 row = membersList.AddString(data.name);
6247 if(data.dataType && data.dataType.kind == TypeEnum)
6249 row.icon = icons[typeEnumValue];
6253 BitmapResource bitmap = null;
6254 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6256 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6259 bitmap = { bitmapName };
6260 membersList.AddResource(bitmap);
6263 row.icon = bitmap ? bitmap : icons[typeData];
6271 DataRow row = membersList.AddString("Min");
6272 row.icon = icons[typeMethod];
6274 row = membersList.AddString("Max");
6275 row.icon = icons[typeMethod];
6277 row = membersList.AddString("Abs");
6278 row.icon = icons[typeMethod];
6280 row = membersList.AddString("Sgn");
6281 row.icon = icons[typeMethod];
6287 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6289 EditBoxStream f { editBox = editBox };
6294 updatingCode = true;
6296 if(!method.dataType)
6297 method.dataType = ProcessTypeString(method.dataTypeString, false);
6299 DeleteJunkBefore(f, function.loc.start.pos, &position);
6300 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6302 // ADDING METHOD HERE
6304 Type dataType = method.dataType;
6305 Type returnType = dataType.returnType;
6307 // Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6313 if(extraIndent) f.Printf(" ");
6315 OutputType(f, returnType, false);
6319 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6321 if(dataType.thisClass.shortName)
6322 f.Printf(dataType.thisClass.shortName);
6324 f.Printf(dataType.thisClass.string);
6327 f.Printf(method.name);
6329 for(param = dataType.params.first; param; param = param.next)
6331 // Decided not to write void...
6332 if(param.kind != voidType)
6334 OutputType(f, param, true);
6340 if(extraIndent) f.Printf(" ");
6341 f.Printf(" %c\n", OpenBracket);
6343 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6349 (isInstance ? _class : _class.base)._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/ ||
6350 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6352 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6354 if(extraIndent) f.Printf(" ");
6355 f.Printf(" return true;\n");
6357 else if(returnType && returnType.kind != voidType)
6359 if(extraIndent) f.Printf(" ");
6360 f.Printf(" return 0;\n");
6365 if(extraIndent) f.Printf(" ");
6367 if(returnType.kind != voidType)
6368 f.Printf("return ");
6369 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6370 for(param = dataType.params.first; param; param = param.next)
6372 if(param.prev) f.Printf(", ");
6373 if(param.kind != voidType)
6374 f.Printf(param.name);
6380 if(extraIndent) f.Printf(" ");
6381 f.Printf(" %c", CloseBracket);
6386 if(extraIndent) { x1 += 3; x2 += 3; }
6387 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6389 this.updatingCode = false;
6393 // Return false if we overrided a function and don't want to run params listing
6394 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6396 bool didOverride = false;
6397 EditLine line = editBox.line;
6398 int lineNum, charPos;
6399 Expression exp = null;
6402 //Identifier id = null;
6403 Expression memberExp = null;
6404 Identifier realIdentifier = null;
6406 if(!parsing) return true;
6407 if(!privateModule) return !didOverride;
6409 insideFunction = null;
6411 charPos = editBox.charPos + 1;
6412 if(!membersListShown)
6417 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6419 EditBoxStream f { editBox = editBox };
6421 updatingCode = true;
6422 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6426 if(!f.Seek(-1, current))
6429 if(!isspace(ch)) break;
6430 f.Seek(-1, current);
6432 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6434 lineNum = editBox.lineNumber + 1;
6435 charPos = editBox.charPos + 1;
6437 updatingCode = false;
6440 if(!membersListShown)
6442 memberExp = FindExpTree(ast, lineNum, charPos);
6443 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6448 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6450 EditBoxStream f { editBox = editBox };
6453 updatingCode = true;
6455 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6458 if(ch == '}' || ch == ',' || ch == ')')
6460 f.Seek(-1, current);
6468 if(!f.Seek(-1, current))
6471 if(!isspace(ch)) break;
6472 f.Seek(-1, current);
6476 f.Seek(-1, current);
6478 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6480 lineNum = editBox.lineNumber + 1;
6481 charPos = editBox.charPos + 1;
6483 updatingCode = false;
6486 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6491 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6492 lineNum = editBox.lineNumber + 1;
6493 charPos = editBox.charPos/* + 1*/;
6497 char tempString[1024];
6498 char * string = null;
6499 CodePosition idStart { };
6500 CodePosition idEnd { };
6502 if(membersListShown)
6504 const char * buffer = membersLine.text;
6506 bool firstChar = true;
6508 string = tempString;
6510 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6512 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6513 if(!isSpace) firstChar = false;
6515 string[len++] = buffer[c];
6519 else //if(realIdentifier)//if(id)
6522 char * buffer = id.string;
6524 bool firstChar = true;
6526 string = tempString;
6527 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6529 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6530 if(!isSpace) firstChar = false;
6532 string[len++] = buffer[c];
6538 EditLine editLine = editBox.line;
6539 bool firstChar = true;
6542 string = tempString;
6543 for(y = lineNum-1; y >= 0; y--)
6545 const char * buffer = editLine.text;
6546 int lineCount = editLine.count;
6547 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6549 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6554 idEnd.charPos = x + 2;
6559 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6562 idEnd.charPos = x + 2;
6569 if(!isalnum(buffer[x]) && buffer[x] != '_')
6575 memmove(string+1, string, len++);
6576 string[0] = buffer[x];
6580 //if(done || firstChar)
6581 if(done || !firstChar)
6583 editLine = editLine.prev;
6586 if(!strcmp(string, "case"))
6592 else if(!strcmp(string, "return"))
6598 else if(!strcmp(string, "delete"))
6604 else if(!strcmp(string, "new"))
6610 else if(!strcmp(string, "renew"))
6618 idStart.charPos = x + 1;
6619 idStart.line = y + 1;
6622 if(!membersListShown)
6624 membersList.Clear();
6625 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6627 Type type = memberExp.member.exp.expType;
6628 if(pointer == 2 && type)
6630 if(type.kind == pointerType || type.kind == arrayType)
6639 ListSymbols(exp, enumOnly, string, realIdentifier);
6641 membersList.Sort(null, 1);
6646 // Virtual function override
6647 Identifier id = GetDeclId(insideFunction.declarator);
6648 char * string = id ? id.string : null;
6650 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6653 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6654 insideFunction = null;
6657 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6662 if(!didOverride) //insideFunction)
6664 rowCount = membersList.rowCount;
6667 DataRow row = string ? membersList.FindSubString(string) : null;
6668 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6670 const char * newString = row.string;
6671 if(!membersListShown)
6673 membersLoc.start.line = idStart.line-1;
6674 membersLoc.start.charPos = idStart.charPos-1;
6675 //membersLoc.end = membersLoc.start;
6676 membersLoc.end.charPos = idEnd.charPos-1;
6677 membersLoc.end.line = idEnd.line-1;
6678 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6679 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6684 membersList.Destroy(0);
6685 membersListShown = false;
6688 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6690 line, membersLoc.start.line, membersLoc.start.charPos,
6691 line, membersLoc.end.line, membersLoc.end.charPos);
6692 editBox.PutS(newString);
6698 row = membersList.FindSubStringi(string);
6700 membersList.currentRow = row;
6701 membersList.currentRow.selected = false;
6704 membersList.currentRow = row;
6706 if(!membersListShown)
6710 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6711 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6712 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6713 editBox.GetCaretPosition(caret);
6714 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6716 membersList.master = this;
6718 caret.y += editBox.GetCaretSize();
6720 membersList.Create();
6723 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6724 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6725 Window parent = membersList.parent;
6727 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6729 y -= editBox.GetCaretSize() + membersList.size.h;
6730 membersAbove = true;
6733 membersAbove = false;
6735 membersList.position = { x, y };
6739 membersLoc.start.line = lineNum - 1;
6741 if(string && string[0])
6743 membersLoc.start.charPos = idStart.charPos-1;
6744 membersLoc.end = membersLoc.start;
6745 //membersLoc.end.charPos = id.loc.end.charPos-1;
6746 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6750 membersLoc.start.charPos = charPos;
6751 membersLoc.end = membersLoc.start;
6752 membersLoc.end.charPos = charPos;
6754 membersListShown = true;
6756 // Hack to keep caret shown
6757 editBox.GetCaretPosition(caret);
6758 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6761 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6767 SetCurrentContext(globalContext);
6770 return !didOverride;
6773 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6775 int lineNum, charPos;
6779 if(!parsing) return;
6781 charPos = editBox.charPos + 1;
6784 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6786 EditBoxStream f { editBox = editBox };
6789 updatingCode = true;
6790 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6793 if(ch == '}' || ch == ',' || ch == ')')
6795 f.Seek(-1, current);
6803 if(!f.Seek(-1, current))
6806 if(!isspace(ch)) break;
6807 f.Seek(-1, current);
6811 f.Seek(-1, current);
6813 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6815 lineNum = editBox.lineNumber + 1;
6816 charPos = editBox.charPos + 1;
6818 updatingCode = false;
6821 charPos = Min(charPos, l1.count + 1);
6823 FindParamsTree(ast, lineNum, charPos);
6825 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6826 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6828 ::functionType = null;
6829 ::instanceType = null;
6832 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6833 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6837 Window parent = paramsList.parent;
6839 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6842 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6843 // ( Dummy exp: always ends up with same memory)
6845 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6846 editBox.GetCaretPosition(paramsPosition);
6847 this.paramsPosition.y += editBox.GetCaretSize();
6850 FreeType(this.functionType);
6851 FreeType(this.instanceType);
6853 this.functionType = ::functionType;
6854 this.instanceType = ::instanceType;
6856 if(this.functionType) this.functionType.refCount++;
6857 if(this.instanceType) this.instanceType.refCount++;
6859 this.paramsID = ::paramsID;
6860 functionExp = paramsInsideExp;
6862 paramsList.master = this;
6864 paramsList.Create();
6866 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6867 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6869 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6871 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6875 paramsAbove = false;
6876 if(x + paramsList.size.w > parent.clientSize.w)
6878 x = parent.clientSize.w - paramsList.size.w;
6882 paramsList.position = { x, y };
6884 // Hack to keep caret shown
6887 editBox.GetCaretPosition(caret);
6888 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6891 this.paramsShown = true;
6893 else if((!::functionType && !::instanceType) || reposition)
6895 paramsList.Destroy(0);
6896 paramsShown = false;
6898 FreeType(this.functionType);
6899 FreeType(this.instanceType);
6900 this.functionType = null;
6901 this.instanceType = null;
6905 SetCurrentContext(globalContext);
6913 designer.visible = true;
6914 designer.Activate();
6920 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6922 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6927 static int nofdigits(int v)
6929 if(v == MININT) return 10 + 1;
6930 if(v < 0) return nofdigits(-v) + 1;