3 // *** Color Schemes ***
5 // *** The Old Color Scheme that was causing me auras and ophtalmic migraines -- Uncomment at your own risk! ***
7 FontResource panelFont { $"Courier New", 10 };
8 FontResource codeFont { $"Courier New", 10 };
9 Color selectionColor = Color { 10, 36, 106 };
10 Color selectionText = white;
11 Color viewsBackground = white;
12 Color viewsText = black;
13 Color outputBackground = white;
14 Color outputText = black;
15 Color projectViewBackground = white;
16 Color projectViewText = black;
17 Color codeEditorBG = white;
18 Color codeEditorFG = black;
19 Color marginColor = Color {230, 230, 230};
20 Color selectedMarginColor = Color {200, 200, 200};
21 Color lineNumbersColor = Color {60, 60, 60};
22 SyntaxColorScheme colorScheme
24 keywordColors = [ blue, blue ];
25 commentColor = dimGray;
26 charLiteralColor = crimson;
27 stringLiteralColor = crimson;
28 preprocessorColor = green;
33 // The new nice dark scheme -- so peaceful on my brain
35 FontResource panelFont { $"Courier New", 10 };
36 FontResource codeFont { $"Courier New", 10 };
38 FontResource panelFont { $"Consolas", 12 };
39 FontResource codeFont { $"Consolas", 12 };
41 Color selectionColor = lightYellow;
42 Color selectionText = Color { 30, 40, 50 };
43 Color viewsBackground = Color { 30, 40, 50 };
44 Color viewsText = lightGray;
45 Color outputBackground = black;
46 Color outputText = lime;
47 Color projectViewBackground = Color { 30, 40, 50 };
48 Color projectViewText = lightGray;
49 Color codeEditorBG = black;
50 Color codeEditorFG = ivory;
51 Color marginColor = Color {24, 24, 24};
52 Color selectedMarginColor = Color {64, 64, 64};
53 Color lineNumbersColor = Color {160, 160, 160};
54 SyntaxColorScheme colorScheme
56 keywordColors = [ skyBlue, skyBlue ];
57 commentColor = Color { 125, 125, 125 };
58 charLiteralColor = Color { 245, 50, 245 };
59 stringLiteralColor = Color { 245, 50, 245 };
60 preprocessorColor = { 120, 220, 140 };
61 numberColor = Color { 0, 192, 192 };
64 // *********************
70 // UNTIL IMPLEMENTED IN GRAMMAR
71 #define ACCESS_CLASSDATA(_class, baseClass) \
72 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
75 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
76 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
79 static Array<FileFilter> fileFilters
81 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
82 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
83 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
84 { $"Text files (*.txt)", "txt" },
85 { $"All files", null }
88 static Array<FileType> fileTypes
90 { $"eC Source Code", "ec", whenNoneGiven },
91 { $"Text Files", "txt", never }
94 static char * iconNames[] =
96 "<:ecere>constructs/class.png",
97 "<:ecere>constructs/data.png",
98 "<:ecere>constructs/method.png",
99 "<:ecere>constructs/event.png",
100 "<:ecere>constructs/property.png",
101 "<:ecere>constructs/namespace.png",
102 "<:ecere>constructs/dataType.png",
103 "<:ecere>constructs/enumValue.png",
104 "<:ecere>constructs/dataPrivate.png",
105 "<:ecere>constructs/methodPrivate.png",
106 "<:ecere>constructs/propertyPrivate.png"
109 enum SheetType { methods, properties };
111 extern int __ecereVMethodID_class_OnEdit;
112 extern int __ecereVMethodID_class_OnDisplay;
113 extern int __ecereVMethodID_class_OnGetString;
114 extern int __ecereVMethodID_class_OnFree;
115 extern int __ecereVMethodID_class_OnCompare;
116 extern int __ecereVMethodID_class_OnCopy;
117 extern int __ecereVMethodID_class_OnSaveEdit;
118 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
123 bool ignoreBreakpoints:1;
125 bool oldImplementation:1;
128 class EditFileDialog : FileDialog
132 if(!ide.projectView && ideSettings.ideFileDialogLocation)
133 currentDirectory = ideSettings.ideFileDialogLocation;
134 return FileDialog::OnCreate();
138 EditFileDialog codeEditorFileDialog
140 type = multiOpen, text = $"Open",
141 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
142 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
145 EditFileDialog codeEditorFormFileDialog
147 type = open, text = $"Open Project",
148 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
149 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
152 define OpenBracket = '{';
153 define CloseBracket = '}';
158 actionDeleteMethod = 2,
159 actionDetachMethod = 3,
160 actionAttachMethod = 4,
161 actionReattachMethod = 5
164 //extern StatusField pos, ovr, caps, num;
165 //extern Class thisClass;
171 bool parseError = false;
176 Expression ctxInsideExp;
177 Expression paramsInsideExp;
178 ClassFunction insideFunction;
186 /****************************************************************************
188 ****************************************************************************/
190 static void OutputString(File f, char * string)
193 for(c = 0; string[c]; c++)
195 if(string[c] == '\"')
197 else if(string[c] == '\\')
204 void OutputType(File f, Type type, bool outputName)
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
226 if(!type.isSigned) f.Printf("unsigned ");
230 if(!type.isSigned) f.Printf("unsigned ");
241 if(type._class && !strcmp(type._class.string, "class"))
243 switch(type.classObjectType)
246 f.Printf("any_object");
249 f.Printf("typed_object");
256 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
257 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
267 OutputType(f, type.type, false);
270 OutputType(f, type.type, false);
289 if(type.kind == arrayType)
292 f.Printf("%d", type.arraySize);
298 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
304 f.Seek(pos - *position, current);
306 // Try to delete spaces and \n before...
312 /*else if(ch == '\n')
314 // Look for // comments on the line before
315 EditBox editBox = f.editBox;
316 EditLine line = editBox.line;
323 for(c = 0; text[c]; c++)
332 if(text[c] == '/' && last == '/')
344 f.DeleteBytes(before);
349 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
354 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
356 // Cut & Paste function
362 f.Seek(loc.start.pos - position, current);
364 x1 = editBox.charPos;
365 y1 = editBox.lineNumber;
366 f.Seek(loc.end.pos - loc.start.pos, current);
368 x2 = editBox.charPos;
369 y2 = editBox.lineNumber;
370 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
372 *size = editBox.SelSize();
373 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
374 editBox.GetSel(*text, false);
377 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
378 f.Printf(""); // Make the stream point to where the editbox is
381 void Code_FixProperty(Property prop, Instance object)
383 Designer::FixProperty(prop, object);
386 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
389 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
391 Class dataType = prop.dataTypeClass;
394 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
396 if(dataType && dataType._vTbl && dataType.type == structClass)
398 void * dataForm = new0 byte[dataType.structSize];
399 void * dataTest = new0 byte[dataType.structSize];
401 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
402 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
404 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
406 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
412 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
414 void * dataForm, * dataTest;
416 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
417 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
419 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
421 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
425 else if(dataType && dataType._vTbl)
427 DataValue dataForm, dataTest;
429 GetProperty(prop, selected.instance, &dataForm);
430 GetProperty(prop, test, &dataTest);
432 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
434 SetProperty(prop, test, dataForm);
436 // In case setting on test unset on real instance (e.g. isDefault)
437 if(strcmp(prop.name, "name"))
439 GetProperty(prop, selected.instance, &dataTest);
440 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
441 SetProperty(prop, selected.instance, dataForm);
450 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
452 bool disabled = false;
453 if(selected.oClass == selected)
456 if(selected.classDefinition)
458 for(def = selected.classDefinition.definitions->first; def; def = def.next)
460 if(def.type == defaultPropertiesClassDef)
463 for(prop = def.defProperties->first; prop; prop = prop.next)
465 if(prop.identifiers && prop.identifiers->first)
467 Identifier id = prop.identifiers->first;
468 if(prop.variable && !strcmp(id.string, name))
480 else if(selected.instCode)
483 if(selected.instCode.members)
485 for(members = selected.instCode.members->first; members; members = members.next)
487 if(members.type == dataMembersInit && members.dataMembers)
490 for(prop = members.dataMembers->first; prop; prop = prop.next)
492 if(prop.identifiers && prop.identifiers->first)
494 Identifier id = prop.identifiers->first;
495 if(prop.variable && !strcmp(id.string, name))
510 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
515 method.dataType = ProcessTypeString(method.dataTypeString, false);
516 if(!method.dataType.thisClass && !isForm)
519 method.dataType.thisClass = selectedClass;
521 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
522 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
524 method.dataType.thisClass = null;
528 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
530 bool confirmation = true;
531 Statement body = function.body;
532 // Check if it contains any code
533 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
535 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
536 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
537 Type dataType = method.dataType;
538 Type returnType = dataType.returnType;
539 Expression exp = null;
542 method.dataType = ProcessTypeString(method.dataTypeString, false);
544 confirmation = false;
546 // Check if default function should be calling base class:
547 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
549 if(returnType.kind != voidType)
551 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
555 exp = stmt.expressions->first;
556 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
558 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
559 (exp.type != constantExp || strcmp(exp.constant, "1")))
564 if(exp.type != constantExp || strcmp(exp.constant, "0"))
579 if(returnType.kind != voidType)
581 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
582 exp = stmt.expressions->first;
584 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
585 exp = stmt.expressions->first;
588 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
592 Identifier id = exp.call.exp.identifier;
593 Class base = object.instance._class;
594 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
598 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
599 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
605 for(param = dataType.params.first; param; param = param.next)
607 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
612 arg = arg ?arg.next : null;
619 return !confirmation;
622 class CodeEditor : Window
624 background = marginColor;
625 borderStyle = sizableDeep;
630 isActiveClient = true;
631 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
634 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
635 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
637 SheetType sheetSelected;
642 Context globalContext { };
643 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
656 MethodAction methodAction;
658 ClassFunction function;
660 char methodName[1024];
665 bool membersListShown;
668 EditLine membersLine;
670 Type functionType, instanceType;
674 Point paramsPosition;
675 Expression functionExp;
678 BitmapResource icons[CodeObjectType];
680 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
681 FontResource normalFont { $"Tahoma", 8.25f, window = this };
683 Module privateModule;
684 NameSpace globalData;
687 OpenedFileInfo openedFileInfo;
689 FontResource font { codeFont.faceName, codeFont.size };
690 saveDialog = codeEditorFileDialog;
692 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
695 int maxLineNumberLength;
697 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
699 void ProcessCaretMove(EditBox editBox, int line, int charPos)
702 ObjectInfo classItem;
704 // OnActivateClient is called after OnActivate
707 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
710 if(sheet.codeEditor != this) return;
714 for(classItem = classes.first; classItem; classItem = classItem.next)
716 ClassDefinition classDef = classItem.classDefinition;
717 if(classDef && classDef.loc.Inside(line, charPos))
724 for(object = classItem.instances.first; object; object = object.next)
728 if(object.instCode.loc.Inside(line, charPos))
733 sheet.SelectObject(object);
735 sheet.SelectObject(classItem);
740 //sheet.SelectObject(null);
744 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
748 expectingMove = false;
754 if(line-1 != membersLoc.start.line)
758 char * buffer = membersLine.text;
761 if(charPos - 1 < membersLoc.start.charPos)
763 else if(charPos - 1 > membersLoc.end.charPos)
765 char * buffer = membersLine.text;
766 //if(membersList.currentRow)
770 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
771 if(buffer[c] != ' ' && buffer[c] != '\t')
773 if(c < charPos && buffer[c])
780 membersList.Destroy(0);
781 membersListShown = false;
785 bool back = codeModified;
786 codeModified = false;
788 InvokeParameters(false, false, false);
789 /*if(membersListShown)
790 InvokeAutoComplete(false, 0, true);*/
797 watch(modifiedDocument)
799 ProjectView projectView = ide.projectView;
802 char buffer[MAX_LOCATION];
803 char * fullPath = GetSlashPathBuffer(buffer, fileName);
804 Array<ProjectNode> nodes = ide.workspace.GetAllProjectNodes(fullPath, false);
808 node.modified = modifiedDocument;
809 projectView.Update(null);
817 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
818 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
819 tabKey = true, smartHome = true;
820 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
821 selectionColor = selectionColor, selectionText = selectionText,
822 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
823 font = font, borderStyle = none;
824 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
826 bool OnMouseOver(int x, int y, Modifiers mods)
828 CodeEditor editor = (CodeEditor)master;
829 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
834 void NotifyCaretMove(EditBox editBox, int line, int charPos)
836 // Update Line Numbers
838 int oldLine = lastLine;
839 display.FontExtent(font.font, " ", 1, null, &spaceH);
841 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
845 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
850 if(ide.activeClient == this)
851 ProcessCaretMove(editBox, line, charPos);
853 openedFileInfo.CaretMove(line, charPos);
856 void NotifyOvrToggle(EditBox editBox, bool overwrite)
858 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
861 void NotifyUpdate(EditBox editBox)
868 designer.modifiedDocument = true;
871 modifiedDocument = true;
874 bool NotifyUnsetModified(EditBox editBox)
876 modifiedDocument = false;
880 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
882 if(!loadingFile && after.y != before.y)
884 ProjectView projectView = ide.projectView;
885 if(projectView && fileName)
888 // HOW WE MIGHT WANT TO DO IT:
889 char * text = before.line.text;
890 for(c = before.x-1; c>= 0; c--)
891 if(!isspace(text[c]))
893 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
895 // HOW VISUAL STUDIO DOES IT:
897 char * text = after.line.text;
898 for(c = after.line.count-1; c>= 0; c--)
899 if(!isspace(text[c]))
901 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
904 Update({ 0, 0, editBox.position.x, clientSize.h });
912 for(oClass = classes.first; oClass; oClass = oClass.next)
915 for(object = oClass.instances.first; object; object = object.next)
919 object.instCode.loc.start.AdjustAdd(before, after);
920 object.instCode.loc.end.AdjustAdd(before, after);
925 oClass.classDefinition.loc.start.AdjustAdd(before, after);
926 oClass.classDefinition.loc.end.AdjustAdd(before, after);
932 expectingMove = true;
936 if(before.y != after.y)
940 char * buffer = membersLine.text;
942 bool firstChar = true;
943 bool addedChar = false;
949 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
951 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
953 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
954 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
963 membersLoc.start.charPos++;
968 string[len++] = buffer[c];
972 row = membersList.currentRow;
973 if(row && row.selected)
977 membersLoc.start.charPos--;
985 row = membersList.FindSubString(string);
987 membersList.currentRow = row;
990 row = membersList.FindSubStringi(string);
992 membersList.currentRow = row;
993 membersList.currentRow.selected = false;
996 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
1000 row = membersList.currentRow;
1003 // Accept current string if hiding typing char
1004 if(hide && row && row.selected)
1006 char * string = row.string;
1007 int len = strlen(string);
1008 membersLoc.end.charPos -= after.x - before.x;
1009 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1010 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1011 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1012 editBox.PutS(string);
1013 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1015 after.x += membersLoc.start.charPos + len - before.x;
1016 before.x = membersLoc.start.charPos + len;
1021 membersList.Destroy(0);
1022 membersListShown = false;
1025 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1027 EditLine line = editBox.line;
1028 char * text = line.text;
1029 char ch = text[after.x-1];
1030 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1034 // Can we call invoke auto complete here instead?
1044 // Force caret update already...
1045 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1046 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1048 editBox.GetCaretPosition(&caret);
1052 // Go back in the buffer until no space before
1054 codeModified = true;
1058 EditBoxStream f { editBox = editBox };
1062 if(text[after.x-1] == '>')
1068 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1072 if(!f.Seek(-1, current))
1075 if(!isspace(ch)) break;
1076 f.Seek(-1, current);
1078 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1080 line = editBox.lineNumber + 1;
1081 charPos = editBox.charPos + 1;
1085 exp = FindExpTree(ast, line, charPos);
1089 Type type = exp.expType;
1091 if(type && text[after.x-1] != '.')
1093 if(type.kind == TypePointer || type.kind == TypeArray)
1099 membersList.Clear();
1102 if(membersList.rowCount)
1104 membersList.Sort(null, 1);
1105 membersList.master = this;
1107 caret.y += editBox.GetCaretSize();
1110 membersList.Create();
1113 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1114 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1115 Window parent = membersList.parent;
1117 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1119 y -= editBox.GetCaretSize() + membersList.GetHeight();
1120 membersAbove = true;
1123 membersAbove = false;
1125 membersList.position = { x, y };
1129 membersLoc.start.line = line - 1;
1130 membersLoc.start.charPos = oldCharPos;
1131 membersLoc.end = membersLoc.start;
1132 membersListShown = true;
1137 SetCurrentContext(globalContext);
1139 codeModified = true;
1140 skipModified = true;
1141 if(text[after.x-1] == ':')
1142 InvokeAutoComplete(false, 0, false);
1143 else if(text[after.x-1] == '.')
1144 InvokeAutoComplete(false, 1, false);
1145 else if(text[after.x-1] == '>')
1146 InvokeAutoComplete(false, 2, false);
1147 skipModified = false;
1149 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1151 codeModified = true;
1152 skipModified = true;
1154 if(InvokeAutoComplete(true, 0, false))
1156 if(ch == '(' || ch == OpenBracket)
1157 InvokeParameters(true, true, false);
1159 InvokeParameters(this.functionType ? false : true, false, false);
1162 // InvokeAutoComplete(true, 0, false);
1163 skipModified = false;
1165 else if(ch == ')' || ch == '}' || ch == ';')
1167 codeModified = true;
1168 skipModified = true;
1170 InvokeParameters(false, true, false);
1171 skipModified = false;
1175 bool back = codeModified;
1176 codeModified = false;
1178 InvokeParameters(false, false, true);
1179 if(membersListShown)
1180 InvokeAutoComplete(false, 0, true);
1181 codeModified = back;
1186 bool back = codeModified;
1187 codeModified = false;
1190 InvokeParameters(false, false, true);
1191 /*if(membersListShown)
1192 InvokeAutoComplete(false, 0, true);*/
1194 codeModified = back;
1201 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1203 if(!loadingFile && after.y != before.y)
1205 ProjectView projectView = ide.projectView;
1206 if(projectView && fileName)
1207 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1208 Update({ 0, 0, editBox.position.x, clientSize.h });
1216 for(oClass = classes.first; oClass; oClass = oClass.next)
1220 for(object = oClass.instances.first; object; object = object.next)
1224 loc = &object.instCode.loc;
1226 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1227 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1229 object.instCode = null;
1233 loc->start.AdjustDelete(before, after);
1234 loc->end.AdjustDelete(before, after);
1238 if(oClass.classDefinition)
1240 loc = &oClass.classDefinition.loc;
1241 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1242 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1244 oClass.classDefinition = null;
1248 loc->start.AdjustDelete(before, after);
1249 loc->end.AdjustDelete(before, after);
1254 if(membersListShown)
1257 if(pasteOperation || before.y != after.y)
1261 char * buffer = membersLine.text;
1263 bool firstChar = true;
1267 if(before.x >= membersLoc.start.charPos)
1269 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1271 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1272 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1277 if(!isSpace) firstChar = false;
1280 string[len++] = buffer[c];
1285 // If deleting spaces before...
1286 for(c = before.x; c<membersLoc.start.charPos; c++)
1288 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1296 membersLoc.start.charPos = before.x;
1299 if(membersLoc.end.charPos >= after.x)
1301 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1303 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1304 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1309 if(!isSpace) firstChar = false;
1312 string[len++] = buffer[c];
1320 membersLoc.end.charPos -= after.x - before.x;
1324 row = membersList.FindSubString(string);
1327 row = membersList.FindSubStringi(string);
1329 membersList.currentRow = row;
1330 membersList.currentRow.selected = false;
1333 membersList.currentRow = row;
1335 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1340 membersList.Destroy(0);
1341 membersListShown = false;
1347 InvokeParameters(false, false);
1355 bool NotifyDropped(EditBox editBox, int x, int y)
1357 char * controlClass = toolBox.controlClass;
1358 if(controlClass && controlClass[0])
1362 ObjectInfo classObject;
1364 //editBox.NotifyCaretMove(this, editBox, y, x);
1365 editBox.GoToLineNum(y);
1366 editBox.GoToPosition(editBox.line, y, x);
1368 classObject = selected ? selected.oClass : null;
1370 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1371 selected = classObject.instances.last;
1374 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1377 AddObject(control, &object);
1379 designer.CreateObject(control, object, false, classObject.instance);
1380 // designer.PostCreateObject(control, object, false, classObject.instance);
1381 designer.DroppedObject(control, object, false, classObject.instance);
1383 sheet.AddObject(object, object.name, typeData /* className*/, true);
1386 //codeModified = true;
1393 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1395 if(key == ctrlSpace)
1397 membersList.Destroy(0);
1398 membersListShown = false;
1399 InvokeAutoComplete(false, 0, false);
1402 else if(key == Key { space, ctrl = true, shift = true })
1403 InvokeParameters(false, true, false);
1404 else if(key == escape)
1405 ide.RepositionWindows(true);
1406 else if(key == ctrlF7)
1410 ProjectNode node = ide.projectView.GetNodeForCompilationFromWindow(this, false, null, null);
1414 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1415 $"It can't be compiled.");
1416 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1425 bool OnKeyDown(Key key, unichar ch)
1427 CodeEditor editor = (CodeEditor)master;
1428 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1430 if(editor.membersListShown)
1432 editor.membersList.Destroy(0);
1433 editor.membersListShown = false;
1436 if(editor.paramsShown)
1438 editor.paramsList.Destroy(0);
1439 editor.paramsShown = false;
1440 FreeType(editor.functionType);
1441 FreeType(editor.instanceType);
1443 editor.functionType = null;
1444 editor.instanceType = null;
1445 editor.paramsID = -1;
1449 return EditBox::OnKeyDown(key, ch);
1452 void OnVScroll(ScrollBarAction action, int position, Key key)
1454 if(anchor.left.distance)
1456 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1459 EditBox::OnVScroll(action, position, key);
1461 CodeEditor ce = (CodeEditor)parent;
1462 if(ce.openedFileInfo)
1463 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1467 void OnHScroll(ScrollBarAction action, int position, Key key)
1469 EditBox::OnHScroll(action, position, key);
1471 CodeEditor ce = (CodeEditor)parent;
1472 if(ce.openedFileInfo)
1473 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1480 fullRowSelect = false,
1483 borderStyle = bevel;
1484 // size = { 200, 400 };
1486 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1488 DataRow row = listBox.currentRow;
1491 char * string = row.string;
1493 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1495 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1496 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1497 editBox.PutS(string);
1500 membersListShown = false;
1505 bool OnKeyDown(Key key, unichar ch)
1507 CodeEditor editor = (CodeEditor) master;
1508 if(key == escape || key == leftAlt || key == rightAlt ||
1509 (key.ctrl && key.code != left && key.code != right &&
1510 key.code != leftShift && key.code != rightShift && key.code != space))
1513 if(editor.paramsShown)
1517 editor.paramsList.Destroy(0);
1518 editor.paramsShown = false;
1520 if(editor.membersListShown)
1524 editor.membersList.Destroy(0);
1525 editor.membersListShown = false;
1528 FreeType(editor.functionType);
1529 editor.functionType = null;
1531 FreeType(editor.instanceType);
1532 editor.instanceType = null;
1534 editor.paramsID = -1;
1539 return editor.editBox.OnKeyDown(key, ch);
1543 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1545 CodeEditor editor = (CodeEditor)master;
1546 Window rw = previous ? previous.rootWindow : null;
1547 if(!active && rw != editor.paramsList)
1550 editor.membersListShown = false;
1552 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1555 bool OnKeyHit(Key key, unichar ch)
1557 CodeEditor editor = (CodeEditor) master;
1561 case enter: case tab:
1563 DataRow row = currentRow;
1564 if(row && row.selected)
1566 char * string = row.string;
1568 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1569 editor.editBox.Delete(
1570 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1571 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1572 editor.editBox.PutS(string);
1575 editor.membersListShown = false;
1578 editor.editBox.OnKeyHit(key, ch);
1588 return ListBox::OnKeyHit(key, ch);
1594 // If before . or after
1595 //listBox.Destroy(true);
1596 result = editor.editBox.OnKeyHit(key, ch);
1611 clickThrough = true,
1613 borderStyle = contour,
1615 background = { 255,255,225 },
1617 OnKeyDown = membersList.OnKeyDown;
1619 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1621 CodeEditor editor = (CodeEditor)master;
1622 Window rw = previous ? previous.rootWindow : null;
1623 if(!active && previous != editor.editBox && rw != editor.membersList)
1626 editor.paramsShown = false;
1628 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1631 bool OnKeyHit(Key key, unichar ch)
1633 CodeEditor editor = (CodeEditor)master;
1635 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1638 bool result = true; editor.editBox.OnKeyHit(key, ch);
1639 return (!created) ? false : result;
1646 void OnRedraw(Surface surface)
1648 CodeEditor editor = (CodeEditor) master;
1649 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1651 Type methodType = null;
1655 int functionW, nameW = 0;
1657 int spaceW, spaceH, commaW, commaWB, parW;
1659 int maxW = 0, lineW = 0;
1665 Font font = editor.normalFont.font;
1666 Font boldFont = editor.boldFont.font;
1667 Display display = this.display;
1669 if(!type) { return; };
1671 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1673 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1674 display.FontExtent(font, ", ", 2, &commaW, null);
1675 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1676 display.FontExtent(font, ")", 1, &parW, null);
1679 if(editor.functionType)
1681 PrintType(type.returnType, string, true, true);
1682 display.FontExtent(font, string, strlen(string), &functionW, null);
1684 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1685 totalW = nameW + functionW + 2 * parW;
1689 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1690 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1691 if(instanceName && type.kind != functionType)
1692 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1693 totalW = functionW + nameW;
1694 surface.TextFont(boldFont);
1697 surface.WriteText(x, y, string, strlen(string));
1698 x += functionW + spaceW;
1700 if(editor.functionType)
1703 surface.WriteText(x, y, type.name, strlen(type.name));
1705 surface.WriteText(x, y, "(", 1);
1708 if(methodType && !methodType.staticMethod && methodType.methodClass)
1712 if(id == editor.paramsID)
1713 surface.TextFont(boldFont);
1715 if(methodType.methodClass)
1716 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1720 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1721 width += ((id == editor.paramsID) ? commaWB : commaW);
1726 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1731 x = 2 + nameW + spaceW + functionW + parW;
1735 if(methodType.methodClass)
1736 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1739 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1741 surface.WriteText(x, y, ",", 1);
1742 x += ((id == editor.paramsID) ? commaWB : commaW);
1750 if(id == editor.paramsID)
1751 surface.TextFont(font);
1755 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1757 for(param = type.params.first; param; param = param.next)
1759 char paramString[1024];
1762 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1763 surface.TextFont(boldFont);
1766 PrintType(param, paramString, true, true);
1767 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1769 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1774 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1779 x = 2 + nameW + spaceW + functionW + parW;
1783 surface.WriteText(x, y, paramString, strlen(paramString));
1787 surface.WriteText(x, y, ",", 1);
1788 x += ((id == editor.paramsID) ? commaWB : commaW);
1796 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1797 surface.TextFont(font);
1802 surface.WriteText(x, y, ")", 1);
1804 else if(instanceName && type.kind != functionType)
1806 surface.WriteText(x, y, instanceName, strlen(instanceName));
1810 bool OnResizing(int * w, int * h)
1812 CodeEditor editor = (CodeEditor) master;
1813 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1815 Type methodType = null;
1819 int functionW = 0, nameW = 0;
1821 int spaceW, spaceH, commaW, commaWB, parW;
1823 int maxW = 0, lineW = 0;
1828 Font font = editor.normalFont.font;
1829 Font boldFont = editor.boldFont.font;
1830 Display display = this.display;
1832 if(type.kind == TypeKind::methodType)
1835 ProcessMethodType(type.method);
1836 type = type.method.dataType;
1839 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1840 display.FontExtent(font, ", ", 2, &commaW, null);
1841 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1842 display.FontExtent(font, ")", 1, &parW, null);
1845 if(editor.functionType && type)
1847 PrintType(type.returnType, string, true, true);
1848 display.FontExtent(font, string, strlen(string), &functionW, null);
1850 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1851 totalW = nameW + spaceW + functionW + 2 * parW;
1855 PrintType(type, string, false, true); // /*true);
1856 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1857 if(instanceName && type.kind != functionType)
1858 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1859 totalW = functionW + nameW + spaceW;
1862 if(editor.functionType)
1868 if(methodType.methodClass)
1869 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1870 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1871 width += ((id == editor.paramsID) ? commaWB : commaW);
1876 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1889 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1891 for(param = type.params.first; param; param = param.next)
1893 char paramString[1024];
1897 PrintType(param, paramString, true, true);
1898 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1900 width += ((id == editor.paramsID) ? commaWB : commaW);
1905 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1922 *w = realW + totalW + 4;
1928 Menu fileMenu { menu, $"File", f };
1929 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1930 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1932 Menu debugMenu { menu, $"Debug", d };
1933 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1934 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1935 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1936 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; };
1938 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1939 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1940 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1941 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; };
1943 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1945 ProjectView projectView = ide.projectView;
1946 if(!projectView.buildInProgress)
1948 RTCMenuBits bits = (RTCMenuBits)selection.id;
1949 int line = editBox.lineNumber + 1;
1952 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1953 ProjectConfig config = projectView.project.config;
1954 int bitDepth = ide.workspace.bitDepth;
1955 bool useValgrind = ide.workspace.useValgrind;
1956 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
1962 MenuDivider { debugMenu };
1963 MenuItem debugToggleBreakpoint
1965 debugMenu, $"Toggle Breakpoint", t, f9;
1966 bool NotifySelect(MenuItem selection, Modifiers mods)
1968 ProjectView projectView = ide.projectView;
1969 if(projectView && fileName)
1971 int line = editBox.lineNumber + 1;
1972 ide.debugger.ToggleBreakpoint(fileName, line);
1982 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1986 designer.parent = parent;
1989 toolBox = ((IDEWorkSpace)master).toolBox;
1991 // Debugger bug here: value of toolBox appears as 0
1993 sheet = ((IDEWorkSpace)master).sheet;
1998 bool OnClose(bool parentClosing)
2002 if(ide.workspace && fileName)
2003 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2004 if(inUseDebug && !debugClosing)
2006 debugClosing = true;
2008 if(CloseConfirmation(false))
2011 if(modifiedDocument)
2012 OnFileModified({ modified = true }, null);
2014 debugClosing = false;
2017 if(designer && !designer.closing)
2019 if(designer.visible)
2026 //Window formEditor = designer;
2027 //formEditor.Destroy(0);
2030 ide.AdjustFileMenus();
2035 void OnDestroy(void)
2037 ObjectInfo oClass, next;
2038 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2040 FreeType(this.functionType);
2041 FreeType(this.instanceType);
2046 designer.codeEditor = null;
2047 designer.Destroy(0);
2051 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2053 ObjectInfo object, next;
2055 for(object = oClass.instances.first; object; object = next)
2060 Designer::DestroyObject(object.instance);
2061 delete object.instance;
2063 sheet.DeleteObject(object);
2065 oClass.instances.Delete(object);
2069 Designer::DestroyObject(oClass.instance);
2070 delete oClass.instance;
2072 sheet.DeleteObject(oClass);
2074 classes.Delete(oClass);
2077 if(windowClass && windowClass.data)
2078 UnapplySkin(windowClass);
2082 if(sheet.codeEditor == this)
2084 sheet.codeEditor = null;
2085 toolBox.codeEditor = null;
2091 ProjectView projectView = ide.projectView;
2094 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false, null);
2095 if(node && node.modified)
2097 node.modified = false;
2098 projectView.Update(null);
2104 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2106 // 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
2108 if(directActivation)
2109 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2111 if(active && directActivation)
2115 openedFileInfo.Activate();
2119 Location * loc = null;
2120 UpdateFormCode(); // To ensure update when modifying properties...
2122 // Got to the right spot in code so we don't lose our form selection...
2125 if(selected.instCode)
2126 loc = &selected.instCode.loc;
2127 else if(selected.classDefinition)
2128 loc = &selected.classDefinition.loc;
2130 line = editBox.lineNumber + 1;
2131 charPos = editBox.charPos + 1;
2136 if(selected && !loc->Inside(line, charPos))
2138 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2139 line = editBox.lineNumber + 1;
2140 charPos = editBox.charPos + 1;
2142 else if(selected && selected.classDefinition)
2145 for(object = selected.instances.first; object; object = object.next)
2149 if(object.instCode.loc.Inside(line, charPos))
2155 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2156 line = editBox.lineNumber + 1;
2157 charPos = editBox.charPos + 1;
2162 ProcessCaretMove(editBox, line, charPos);
2167 if(membersListShown)
2169 membersList.Destroy(0);
2170 membersListShown = false;
2174 paramsList.Destroy(0);
2175 paramsShown = false;
2176 FreeType(functionType);
2177 FreeType(instanceType);
2179 functionType = null;
2180 instanceType = null;
2187 bool OnSaveFile(char * fileName)
2194 f = FileOpen(fileName, write);
2197 if(!ide.projectView)
2198 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2202 this.fileName = fileName; // Put this here because the form designer will check for it...
2203 designer.fileName = fileName;
2204 designer.modifiedDocument = false;
2206 editBox.Save(f, false);
2207 modifiedDocument = false;
2215 bool OnFileModified(FileChange fileChange, char * param)
2217 bool reload = false;
2218 if(visible == false && inUseDebug == true)
2219 ide.debugger.WatchesReleaseCodeEditor();
2224 sprintf(message, $"The document %s was modified by another application.\n"
2225 "Would you like to reload it and lose your changes?", fileName);
2226 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2227 contents = message }.Modal() == yes)
2233 File f = FileOpen(fileName, read);
2236 int lineNumber, charPos, len;
2240 updatingCode = true;
2241 lineNumber = editBox.lineNumber;
2242 charPos = editBox.charPos;
2243 scroll = editBox.scroll;
2246 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2247 len = strlen(editBox.line.text);
2248 editBox.GoToLineNum(lineNumber);
2249 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2250 editBox.scroll = scroll;
2251 updatingCode = false;
2252 loadingFile = false;
2254 codeModified = true;
2258 designer.modifiedDocument = false;
2260 modifiedDocument = false;
2268 void OnRedraw(Surface surface)
2271 surface.SetBackground(marginColor);
2272 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2273 if(ideSettings.showLineNumbers)
2275 int currentLineNumber;
2277 char lineFormat[16];
2281 surface.textOpacity = false;
2282 surface.font = font.font;
2283 surface.TextExtent(" ", 1, null, &spaceH);
2284 currentLineNumber = editBox.scroll.y / spaceH + 1;
2285 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2287 surface.SetForeground(lineNumbersColor);
2288 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2290 // Highlight current line
2291 if(editBox.lineNumber == currentLineNumber - 1)
2293 surface.SetBackground(selectedMarginColor);
2294 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2295 surface.SetBackground(marginColor);
2297 sprintf(lineText, lineFormat, currentLineNumber);
2298 if(currentLineNumber <= editBox.numLines)
2299 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2300 currentLineNumber++;
2304 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2306 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2307 int lineCursor, lineTopFrame, breakpointLines[128];
2308 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2309 Debugger debugger = ide.debugger;
2310 BitmapResource bmpRes;
2312 boxH = clientSize.h;
2313 scrollY = editBox.scroll.y;
2314 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2316 bpOnCursor = bpOnTopFrame = false;
2317 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2320 for(i = 0; i < count; i++)
2322 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2324 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2325 if(breakpointLines[i] == lineCursor)
2327 if(breakpointLines[i] == lineTopFrame)
2328 bpOnTopFrame = true;
2331 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2333 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2336 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2337 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2338 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2340 if(editBox.anchor.left.distance)
2342 if(editBox.horzScroll && editBox.horzScroll.visible)
2344 surface.SetBackground(control);
2345 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2350 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2355 lineY = (line - 1) * lineH;
2356 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2358 Bitmap bitmap = resource.bitmap;
2360 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2367 char ext[MAX_EXTENSION];
2368 char * fileName = property::fileName;
2370 if(SearchString(fileName, 0, "Makefile", false, true))
2371 editBox.useTab = true;
2372 designer.fileName = fileName;
2376 GetExtension(fileName, ext);
2378 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2379 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2380 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2381 editBox.syntaxHighlighting = true;
2383 editBox.syntaxHighlighting = false;
2385 if(parsing && !strcmpi(ext, "ec"))
2387 codeModified = true;
2391 maxLineNumberLength = 0;
2396 bool UpdateMarginSize()
2398 if(ideSettings.showLineNumbers)
2400 int numLen = Max(4, nofdigits(editBox.numLines));
2402 maxLineNumberLength = numLen;
2403 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2404 editBox.anchor = Anchor
2406 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2407 right = 0, top = 0, bottom = 0
2412 maxLineNumberLength = 0;
2413 editBox.anchor = Anchor
2415 left = editBox.syntaxHighlighting * 20,
2416 right = 0, top = 0, bottom = 0
2428 bool LoadFile(char * filePath)
2430 File f = FileOpen(filePath, read);
2433 // Added this here...
2434 fileName = filePath;
2436 updatingCode = true;
2438 updatingCode = false;
2439 loadingFile = false;
2448 void AdjustDebugMenus()
2450 bool unavailable = ide.areDebugMenusUnavailable;
2451 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2452 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2453 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2455 debugRunToCursor.disabled = isNotNotRunning;
2456 debugSkipRunToCursor.disabled = isNotNotRunning;
2457 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2458 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2460 debugBpRunToCursor.disabled = isNotNotRunning;
2461 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2462 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2463 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2465 debugToggleBreakpoint.disabled = noBreakpointToggle;
2471 ProjectView projectView = ide.projectView;
2474 designer.fileName = fileName;
2480 sprintf(title, $"Untitled %d", documentID);
2481 // designer.fileName = CopyString(title);
2482 designer.fileName = title;
2487 for(c = 0; c < CodeObjectType::enumSize; c++)
2488 icons[c] = BitmapResource { iconNames[c], window = this };
2490 codeModified = true;
2502 selected.modified = true;
2503 selected.oClass.modified = true;
2505 designer.modifiedDocument = true;
2506 modifiedDocument = true;
2507 formModified = true;
2510 /****************************************************************************
2512 ****************************************************************************/
2520 this.defines.Free(FreeModuleDefine);
2521 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2523 FreeExcludedSymbols(this.excludedSymbols);
2524 FreeContext(this.globalContext);
2526 FreeGlobalData(&this.globalData);
2527 FindCtx_Terminate();
2528 FindParams_Terminate();
2530 if(GetGlobalContext() == globalContext)
2532 SetGlobalData(null);
2533 SetGlobalContext(null);
2534 SetExcludedSymbols(null);
2535 SetTopContext(null);
2536 SetCurrentContext(null);
2539 SetPrivateModule(null);
2542 if(this.privateModule)
2544 FreeTypeData(this.privateModule);
2545 delete this.privateModule;
2546 this.privateModule = null;
2552 static bool reentrant = false;
2557 char * selectedClassName = null, * selectedName = null;
2558 int selectedPos = 0;
2559 Designer backDesigner;
2560 char oldWorkDir[MAX_LOCATION];
2561 char mainModuleName[MAX_FILENAME] = "";
2563 ImportedModule module;
2564 char extension[MAX_EXTENSION];
2565 PathBackup pathBackup { };
2567 Time parseCodeStart = GetTime();
2568 Time startTime, startFindClass;
2570 findClassTotalTime = 0;
2571 checkTypeTotalTime = 0;
2572 externalImportTotalTime = 0;
2573 findClassIgnoreNSTotalTime = 0;
2574 findSymbolTotalTime = 0;
2575 //ResetClassFindTime();
2579 // This temporarily fixes issue with 2 overrides in release mode with VC6 (only happens with both ecere.dll and ide.exe compiled in release mode)
2580 if(reentrant) return;
2587 selectedClassName = CopyString(oClass.name);
2588 if(selected != oClass)
2590 ObjectInfo object = this.selected;
2591 selectedName = CopyString(object.name);
2595 for(check = this.oClass.instances.first; check; check = check.next)
2607 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2609 FindCtx_Terminate();
2610 FindParams_Terminate();
2612 SetGlobalData(&globalData);
2613 SetGlobalContext(globalContext);
2614 SetExcludedSymbols(&excludedSymbols);
2615 SetTopContext(globalContext);
2616 SetCurrentContext(globalContext);
2617 SetDefines(&defines);
2618 SetImports(&imports);
2619 SetCurrentNameSpace(null);
2622 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2623 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2624 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2625 "/I T:\\ecere\\include /E %s", argv[1]);
2629 ChangeWorkingDir("e:\\ec");
2630 sprintf(command, "gcc -x c -E -");
2631 fileInput = DualPipeOpen({ output = true, input = true }, command);
2632 SetFileInput(fileInput);
2637 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2639 fileInput.Write(buffer, 1, count);
2644 fileInput.CloseOutput();
2648 // TOCHECK: COULDN'T WE CALL FreeParser here?
2650 FreeType(this.functionType);
2651 FreeType(this.instanceType);
2652 this.functionType = null;
2653 this.instanceType = null;
2656 sheet.SelectObject(null);
2662 // We don't want the designer to be notified of selection when deleting rows...
2663 backDesigner = designer;
2668 ObjectInfo _class, next;
2670 for(_class = classes.first; _class; _class = next)
2676 for(;object = _class.instances.first;)
2680 Designer::DestroyObject(object.instance);
2681 delete object.instance;
2683 sheet.DeleteObject(object);
2685 _class.instances.Delete(object);
2689 Designer::DestroyObject(_class.instance);
2690 delete _class.instance;
2692 sheet.DeleteObject(_class);
2694 classes.Delete(_class);
2700 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2701 if(windowClass && windowClass.data)
2702 UnapplySkin(windowClass);
2705 designer = backDesigner;
2708 fileInput = editFile = EditBoxStream { editBox = editBox };
2709 SetFileInput(fileInput);
2717 defines.Free(FreeModuleDefine);
2718 imports.Free(FreeModuleImport);
2720 FreeContext(this.globalContext);
2721 FreeExcludedSymbols(this.excludedSymbols);
2724 FreeGlobalData(&this.globalData);
2726 if(this.privateModule)
2728 FreeTypeData(this.privateModule);
2729 delete this.privateModule;
2733 startTime = GetTime();
2734 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2736 printf("classes.count: %d\n", globalContext.classes.count);
2741 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2742 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2745 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2747 SetPrivateModule(privateModule);
2750 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2751 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2752 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2753 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2754 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2757 fileName = this.fileName;
2759 if(ide.workspace && ide.workspace.projects && fileName)
2761 for(p : ide.workspace.projects)
2763 char path[MAX_LOCATION];
2765 MakePathRelative(fileName, p.topNode.path, path);
2766 MakeSlashPath(path);
2768 pn = p.topNode.FindWithPath(path, false);
2777 project = ide.project;
2779 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2781 ChangeWorkingDir(project.topNode.path);
2783 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2785 GetLastDirectory(fileName, mainModuleName);
2786 GetExtension(mainModuleName, extension);
2788 SetBuildingEcereCom(false);
2789 SetBuildingEcereComModule(false);
2791 // TODO: Get symbolsDir from project settings instead...
2794 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2795 ProjectConfig config = project.config;
2796 int bitDepth = ide.workspace.bitDepth;
2797 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2798 SetSymbolsDir(objDir.dir);
2799 ide.SetPath(true, compiler, config, bitDepth);
2803 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2804 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2808 switch(GetRuntimePlatform())
2810 case win32: SetSymbolsDir("obj/debug.win32"); break;
2811 case tux: SetSymbolsDir("obj/debug.linux"); break;
2812 case apple: SetSymbolsDir("obj/debug.apple"); break;
2814 SetIncludeDirs(null);
2815 SetSysIncludeDirs(null);
2819 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2821 // TODO FIX for configless project
2822 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2824 for(item : ide.project.config.options.preprocessorDefinitions)
2826 if(!strcmp(item, "BUILDING_ECERE_COM"))
2828 SetBuildingEcereCom(true);
2835 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2836 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2837 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2838 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2839 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2840 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2841 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2842 strcmpi(mainModuleName, "Mutex.ec")))
2844 SetBuildingEcereComModule(true);
2847 // Predeclare all classes
2849 char symFile[MAX_FILENAME];
2850 char symLocation[MAX_LOCATION];
2851 ImportedModule module, next;
2853 GetLastDirectory(fileName, symFile);
2854 ChangeExtension(symFile, "sym", symFile);
2856 strcpy(symLocation, GetSymbolsDir());
2857 PathCat(symLocation, symFile);
2859 // if(!GetEcereImported() && !GetBuildingEcereCom())
2860 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2863 startTime = GetTime();
2865 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2867 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2872 startTime = GetTime();
2874 // LoadSymbols(symLocation, normalImport, true);
2875 LoadSymbols(symLocation, preDeclImport, false);
2877 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2880 for(module = defines.first; module; module = next)
2883 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2886 defines.Delete(module);
2891 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2893 SetDefaultDeclMode(privateAccess);
2894 SetDeclMode(privateAccess);
2898 SetDefaultDeclMode(defaultAccess);
2899 SetDeclMode(defaultAccess);
2902 StripExtension(mainModuleName);
2903 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2904 defines.AddName(module);
2907 // SetYydebug(true);
2912 startTime = GetTime();
2913 startFindClass = checkTypeTotalTime;
2917 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2919 CheckDataRedefinitions();
2922 SetIncludeDirs(null);
2923 SetSysIncludeDirs(null);
2934 startTime = GetTime();
2936 PrePreProcessClassDefinitions();
2937 ComputeModuleClasses(privateModule);
2938 PreProcessClassDefinitions();
2939 ProcessClassDefinitions();
2941 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2942 startTime = GetTime();
2947 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2948 startTime = GetTime();
2950 ProcessInstantiations();
2952 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2955 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2957 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2958 if(!windowClass || windowClass.internalDecl)
2961 startTime = GetTime();
2963 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2964 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2965 eModule_Load(this.privateModule, "ecere", privateAccess);
2967 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2970 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2972 if(windowClass && windowClass.data)
2973 ApplySkin(windowClass, app.currentSkin.name, null);
2977 startTime = GetTime();
2979 for(external = ast->first; external; external = external.next)
2981 if(external.type == classExternal)
2983 ClassDefinition _class = external._class;
2984 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2986 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2989 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2991 Instance instance = eInstance_New(regClass);
2992 ObjectInfo classObject
2994 name = CopyString(_class._class.name);
2995 instance = instance;
2996 classDefinition = _class;
2997 oClass = classObject;
3000 classes.Add(classObject);
3004 // Moved this at bottom so that the file dialog doesn't show up in eCom
3005 designer.CreateObject(instance, classObject, true, null);
3006 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3008 if(_class.definitions)
3012 for(def = _class.definitions->first; def; def = def.next)
3016 case defaultPropertiesClassDef:
3019 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3021 Identifier id = propDef.identifiers->first;
3024 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3027 Class propertyClass = prop.dataTypeClass;
3029 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3030 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3032 FreeType(propDef.initializer.exp.destType);
3033 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3034 ProcessExpressionType(propDef.initializer.exp);
3036 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3038 Expression computed = CopyExpression(propDef.initializer.exp);
3039 ComputeExpression(computed);
3041 if(computed.isConstant && computed.type == instanceExp && !id.next)
3045 if(computed.instance._class && computed.instance._class.symbol &&
3046 computed.instance._class.symbol.registered &&
3047 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3049 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3051 // This was saved in the control and shouldn't be freed by FreeExpression...
3052 // (Not doing this anymore, incrementing refCount in pass15 instead)
3053 /*if(propertyClass.type == normalClass)
3054 computed.instance.data = null;*/
3058 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3059 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3061 String temp = new char[strlen(computed.string)+1];
3062 ReadString(temp, computed.string);
3063 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3067 propDef.variable = true;
3069 FreeExpression(computed);
3073 Expression computed = CopyExpression(propDef.initializer.exp);
3074 ComputeExpression(computed);
3075 if(computed.isConstant)
3077 //if(computed.type == memberExp) computed = computed.member.exp;
3079 if(computed.type == constantExp)
3081 Operand value = GetOperand(computed);
3082 DataValue valueData;
3083 valueData.i64 = value.i64;
3084 SetProperty(prop, instance, valueData);
3086 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3088 String temp = new char[strlen(computed.string)+1];
3089 ReadString(temp, computed.string);
3090 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3095 propDef.variable = true;
3097 FreeExpression(computed);
3101 propDef.variable = true;
3105 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3106 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3107 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3110 // Maintain a list in FunctionDefinition of who is attached to it
3111 for(def = _class.definitions->first; def; def = def.next)
3113 if(def.type == functionClassDef)
3115 ClassFunction function = def.function;
3116 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3118 function.attached.Add(OldLink { data = method });
3128 case declarationClassDef:
3130 Declaration decl = def.decl;
3133 case instDeclaration:
3135 Instantiation inst = decl.inst;
3136 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3137 if(instClass && eClass_GetDesigner(instClass))
3139 Instance control = eInstance_New(instClass);
3144 oClass = classObject;
3148 classObject.instances.Add(object);
3150 // TOCHECK: Why is this needed now?
3151 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3152 def.object = object;
3154 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3156 designer.CreateObject(control, object, false, classObject.instance);
3157 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3167 // Second pass, process instantiation members
3169 for(def = _class.definitions->first; def; def = def.next)
3173 case declarationClassDef:
3175 Declaration decl = def.decl;
3178 case instDeclaration:
3180 Instantiation inst = decl.inst;
3181 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3182 if(instClass && eClass_GetDesigner(instClass))
3185 object = object ? object.next : classObject.instances.first;
3186 control = object.instance;
3190 MembersInit members;
3191 for(members = inst.members->first; members; members = members.next)
3193 switch(members.type)
3195 case dataMembersInit:
3197 if(members.dataMembers)
3200 DataMember curMember = null;
3201 Class curClass = null;
3202 DataMember subMemberStack[256];
3203 int subMemberStackPos = 0;
3205 for(member = members.dataMembers->first; member; member = member.next)
3208 Identifier ident = member.identifiers ? member.identifiers->first : null;
3211 DataMember _subMemberStack[256];
3212 int _subMemberStackPos = 0;
3213 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3217 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3219 if(thisMember && thisMember.memberAccess == publicAccess)
3221 curMember = thisMember;
3222 curClass = curMember._class;
3223 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3224 subMemberStackPos = _subMemberStackPos;
3230 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3231 if(curMember) found = true;
3233 if(found && curMember.isProperty)
3235 Property prop = (Property) curMember;
3236 Class propertyClass = prop.dataTypeClass;
3238 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3240 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3242 FreeType(member.initializer.exp.destType);
3243 member.initializer.exp.destType = MkClassType(propertyClass.name);
3246 ProcessExpressionType(member.initializer.exp);
3248 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3250 Expression computed;
3252 /*char debugExpString[4096];
3253 debugExpString[0] = '\0';
3254 PrintExpression(member.initializer.exp, debugExpString);*/
3256 computed = CopyExpression(member.initializer.exp);
3259 ComputeExpression(computed);
3261 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3263 if(computed.instance.data)
3265 if(computed.instance._class && computed.instance._class.symbol &&
3266 computed.instance._class.symbol.registered &&
3267 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3269 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3271 // This was saved in the control and shouldn't be freed by FreeExpression...
3272 // (Not doing this anymore, incrementing refCount in pass15 instead)
3273 /*if(propertyClass.type == normalClass)
3274 computed.instance.data = null;*/
3278 else if(computed.type == identifierExp)
3280 member.variable = true;
3282 if(eClass_GetDesigner(propertyClass))
3285 char * name = computed.identifier.string;
3286 if(!strcmp(name, "this"))
3289 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3290 member.variable = false;
3295 for(check = classObject.instances.first; check; check = check.next)
3296 if(check.name && !strcmp(name, check.name))
3299 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3300 member.variable = false;
3306 else if(computed.type == memberExp)
3308 member.variable = true;
3309 if(computed.member.exp.type == identifierExp)
3311 char * name = computed.member.exp.identifier.string;
3312 if(!strcmp(name, "this"))
3314 char * name = computed.member.member.string;
3317 for(check = classObject.instances.first; check; check = check.next)
3318 if(check.name && !strcmp(name, check.name))
3321 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3322 member.variable = false;
3330 for(check = classObject.instances.first; check; check = check.next)
3332 if(check.name && !strcmp(name, check.name))
3334 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3337 DataValue value { };
3338 GetProperty(getProperty, check.instance, &value);
3339 SetProperty(prop, control, value);
3340 member.variable = false;
3348 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3349 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3351 String temp = new char[strlen(computed.string)+1];
3352 ReadString(temp, computed.string);
3353 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3357 member.variable = true;
3359 FreeExpression(computed);
3364 Expression computed = CopyExpression(member.initializer.exp);
3367 ComputeExpression(computed);
3368 if(computed.isConstant)
3370 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3372 if(!strcmp(propertyClass.dataTypeString, "float"))
3373 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3374 else if(!strcmp(propertyClass.dataTypeString, "double"))
3375 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3377 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3379 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3381 String temp = new char[strlen(computed.string)+1];
3382 ReadString(temp, computed.string);
3383 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3388 member.variable = true;
3390 FreeExpression(computed);
3396 member.variable = true;
3398 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3399 member.initializer.exp.type == memberExp) // identifierExp
3401 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3402 if(method && method.type == virtualMethod)
3405 // Maintain a list in FunctionDefinition of who is attached to it
3406 for(def = _class.definitions->first; def; def = def.next)
3408 if(def.type == functionClassDef)
3410 ClassFunction function = def.function;
3411 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3412 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3414 function.attached.Add(OldLink { data = method });
3415 // Reference this particular instance?
3430 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3441 //designer.CreateObject(instance, classObject, true, null);
3442 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3444 designer.PostCreateObject(instance, classObject, true, null);
3446 //instance.state = Hidden;
3447 //instance.Create();
3448 //instance.SetState(Normal, true, 0);
3457 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3461 // Restore Selection
3462 if(selectedClassName)
3465 for(oClass = classes.first; oClass; oClass = oClass.next)
3467 if(!strcmp(oClass.name, selectedClassName))
3469 this.oClass = oClass;
3473 delete selectedClassName;
3482 for(check = this.oClass.instances.first; check; check = check.next)
3484 if(check.name && !strcmp(check.name, selectedName))
3486 this.selected = check;
3492 if(this.oClass.instances.first)
3493 this.selected = this.oClass.instances.first;
3495 this.selected = this.oClass;
3498 else if(selectedPos == -1 || !this.oClass.instances.count)
3499 this.selected = this.oClass;
3505 if(selectedPos > this.oClass.instances.count)
3507 for(check = this.oClass.instances.first; check; check = check.next)
3509 if(selectedPos == pos++)
3511 this.selected = check;
3519 this.oClass = classes.first;
3520 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3522 delete selectedName;
3523 SetSymbolsDir(null);
3525 if(sheet.codeEditor == this)
3526 sheet.SelectObject(selected);
3529 codeModified = false;
3531 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3534 InvokeParameters(false, false, false);
3537 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3543 ChangeWorkingDir(oldWorkDir);
3545 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3546 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3547 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3548 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3549 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3551 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3553 if(inUseDebug && ide.projectView)
3554 ide.debugger.EvaluateWatches();
3559 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3562 Window control = (Window)object.instance;
3563 ObjectInfo classObject = object.oClass;
3565 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3567 if(!strcmp(_class.name, "DesignerBase")) return;
3569 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3571 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3572 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3574 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3575 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3577 Class dataType = prop.dataTypeClass;
3579 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3583 if(dataType.type == structClass)
3585 void * dataForm = new0 byte[dataType.structSize];
3586 void * dataTest = new0 byte[dataType.structSize];
3588 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3589 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3591 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3593 char tempString[1024] = "";
3595 bool needClass = true;
3599 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3601 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3603 eClass_FindNextMember(_class, curClass, curMember, null, null);
3604 if(*curMember != (DataMember)prop)
3605 f.Printf("%s = ", prop.name);
3607 *curMember = (DataMember)prop;
3608 *curClass = curMember->_class;
3611 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3613 f.Printf("%s", string);
3620 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3622 void * dataForm, * dataTest;
3624 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3625 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3627 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3629 char tempString[1024] = "";
3634 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3636 eClass_FindNextMember(_class, curClass, curMember, null, null);
3637 if(*curMember != (DataMember)prop)
3638 f.Printf("%s = ", prop.name);
3639 *curMember = (DataMember)prop;
3640 *curClass = curMember->_class;
3642 if(eClass_GetDesigner(dataType))
3644 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3645 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3646 f.Printf("this", prop.name);
3649 //ObjectInfo classObject;
3650 //for(classObject = classes.first; classObject; classObject = classObject.next)
3654 for(object = classObject.instances.first; object; object = object.next)
3656 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3658 f.Printf("%s", object.name);
3665 bool needClass = true;
3666 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3667 f.Printf("%s", string);
3674 bool needClass = true;
3675 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3677 if(!strcmp(dataType.dataTypeString, "char *"))
3680 OutputString(f, string);
3684 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3686 f.Printf("%s", string);
3689 *lastIsMethod = false;
3694 DataValue dataForm, dataTest;
3696 GetProperty(prop, control, &dataForm);
3697 GetProperty(prop, test, &dataTest);
3699 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3702 char tempString[1024] = "";
3703 SetProperty(prop, test, dataForm);
3705 if(dataType.type != bitClass)
3707 bool needClass = true;
3709 if(dataType.type == enumClass)
3712 Class enumClass = eSystem_FindClass(privateModule, "enum");
3713 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3715 for(value = e.values.first; value; value = value.next)
3717 if((int)value.data == dataForm.i)
3719 string = value.name;
3725 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3727 if(string && string[0])
3732 eClass_FindNextMember(_class, curClass, curMember, null, null);
3733 if(*curMember != (DataMember)prop)
3734 f.Printf("%s = ", prop.name);
3735 *curMember = (DataMember)prop;
3736 *curClass = curMember->_class;
3738 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3739 f.Printf("%sf", string);
3741 f.Printf("%s", string);
3745 else if(dataType.type == bitClass)
3747 bool needClass = true;
3749 if(*prev) f.Printf(", ");
3751 eClass_FindNextMember(_class, curClass, curMember, null, null);
3752 if(*curMember != (DataMember)prop)
3753 f.Printf("%s = ", prop.name);
3754 *curMember = (DataMember)prop;
3755 *curClass = curMember->_class;
3757 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3759 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3761 f.Printf("%s", string);
3763 *lastIsMethod = false;
3773 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3775 Instantiation inst = object.instCode;
3776 Window control = (Window)object.instance;
3778 bool methodPresent = false;
3780 bool lastIsMethod = true;
3781 ObjectInfo classObject = object.oClass;
3787 // Instance removed, delete it
3788 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3790 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3791 position = inst.loc.end.pos + 1;
3795 bool multiLine = false;
3798 // Check if it's an unnamed instance
3801 f.Seek(inst.nameLoc.start.pos - position, current);
3802 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3803 position = inst.nameLoc.end.pos;
3805 f.Printf(object.name);
3810 if(isspace(ch) && ch != '\n')
3812 f.Seek(-1, current);
3820 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3822 f.Seek(pos - position, current);
3827 f.Seek(-1, current);
3836 f.Puts(object.name);
3841 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3842 methodPresent = true;
3850 if(ch == OpenBracket)
3856 // TODO: Simplify this?
3865 f.Seek(-1, current);
3877 if(ch == '\n') { toDelete = count; count = 0; }
3878 else if(isspace(ch)) count++;
3881 f.Seek(-1, current);
3885 toDelete += count - 6;
3895 f.Seek(-toDelete-count, current);
3896 f.DeleteBytes(toDelete);
3897 f.Seek(count, current);
3902 for(c = 0; c<toAdd; c++)
3908 methodPresent = multiLine;
3911 f.Printf(methodPresent ? "\n " : " ");
3917 // Instance not there, create a brand new one
3918 DeleteJunkBefore(f, position, &position);
3919 f.Printf(*firstObject ? "\n\n" : "\n");
3920 *firstObject = false;
3922 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3923 methodPresent = true;
3928 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3930 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3935 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3937 f.Printf(" %s %c ", control._class.name, OpenBracket);
3943 Instance test = eInstance_New(control._class);
3944 DataMember curMember = null;
3945 Class curClass = null;
3948 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3952 // Attach Method here
3953 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3955 if(prev) f.Printf(", ");
3956 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3961 if(inst && !object.deleted)
3963 MembersInit members;
3964 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3966 DeleteJunkBefore(f, position, &position);
3968 // Instance already there, clear out the properties
3969 for(members = inst.members->first; members; members = members.next)
3971 if(members.type == dataMembersInit)
3975 if(members.dataMembers)
3977 bool keptMember = false;
3978 MemberInit lastKept = null;
3980 for(member = members.dataMembers->first; member; member = member.next)
3982 Identifier ident = member.identifiers ? member.identifiers->first : null;
3983 bool deleted = false;
3985 // For now delete if it's not a method
3986 if(!member.variable) // && ident)
3988 if(!ident || !ident.next)
3990 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3993 f.Seek(member.loc.start.pos - position, current);
3994 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3995 position = member.loc.end.pos;
4000 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4001 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4002 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4004 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4005 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4007 f.Seek(member.loc.start.pos - position, current);
4008 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4009 position = member.loc.end.pos;
4021 //f.Seek(member.loc.start.pos - position, current);
4022 //position = member.loc.start.pos;
4023 DeleteJunkBefore(f, member.loc.start.pos, &position);
4024 if(prev) f.Printf(", ");
4025 else if(keptMember) f.Printf(" ");
4030 if(!keptMember || !members.next)
4035 if(keptMember && lastKept != members.dataMembers->last)
4040 f.Seek(-1, current);
4046 f.Seek(-1, current);
4049 else if(!isspace(ch))
4051 f.Seek(-2, current);
4056 f.DeleteBytes(count);
4059 f.Seek(members.loc.end.pos - position, current);
4064 f.Seek(-1, current);
4066 position = members.loc.end.pos + 1;
4070 f.Seek(-1, current);
4071 position = members.loc.end.pos;
4077 lastIsMethod = false;
4082 DeleteJunkBefore(f, position, &position);
4085 if(lastKept != members.dataMembers->last)
4090 f.Seek(-1, current);
4096 f.Seek(-1, current);
4099 else if(!isspace(ch))
4101 f.Seek(-2, current);
4106 f.DeleteBytes(count);
4110 f.Seek(members.loc.end.pos - position, current);
4111 position = members.loc.end.pos;
4115 lastIsMethod = true;
4118 lastIsMethod = false;
4124 f.Seek(members.loc.end.pos - position, current);
4125 position = members.loc.end.pos;
4127 lastIsMethod = true;
4130 else if(members.type == methodMembersInit)
4132 if(this.methodAction == actionDeleteMethod && members.function == function);
4134 methodPresent = true;
4136 // Delete instance method here
4137 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4138 members.function == function)
4140 if(this.moveAttached && !*text)
4141 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4143 DeleteJunkBefore(f, members.loc.start.pos, &position);
4144 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4145 position = members.loc.end.pos + 1;
4150 DeleteJunkBefore(f, position, &position);
4154 DeleteJunkBefore(f, members.loc.start.pos, &position);
4155 lastIsMethod = true;
4159 f.Seek(members.loc.end.pos - position, current);
4160 position = members.loc.end.pos;
4162 DeleteJunkBefore(f, position, &position);
4171 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4173 Method method = this.method;
4174 DeleteJunkBefore(f, position, &position);
4180 if(!method.dataType)
4181 method.dataType = ProcessTypeString(method.dataTypeString, false);
4184 Type dataType = method.dataType;
4185 Type returnType = dataType.returnType;
4188 if(this.moveAttached)
4190 // Move function here:
4191 int newLen = strlen(method.name);
4196 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4198 // First change name of function
4199 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4200 *textSize += newLen - movedFuncIdLen;
4201 memcpy(*text + movedFuncIdPos, method.name, newLen);
4203 // Second, tab right
4206 for(c = 0; (*text)[c]; )
4209 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4212 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4213 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4217 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4227 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4229 // ADDING METHOD HERE
4231 OutputType(f, returnType, false);
4234 if(dataType.thisClass)
4236 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4238 if(dataType.thisClass.shortName)
4239 f.Printf(dataType.thisClass.shortName);
4241 f.Printf(dataType.thisClass.string);
4245 f.Printf(method.name);
4247 for(param = dataType.params.first; param; param = param.next)
4249 OutputType(f, param, true);
4254 f.Printf(" %c\n\n", OpenBracket);
4256 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4258 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4259 f.Printf(" return true;\n");
4260 else if(returnType.kind != voidType)
4261 f.Printf(" return 0;\n");
4266 if(returnType.kind != voidType)
4267 f.Printf("return ");
4268 f.Printf("%s::%s(", control._class.name, method.name);
4269 for(param = dataType.params.first; param; param = param.next)
4271 if(param.prev) f.Printf(", ");
4272 if(param.kind != voidType)
4273 f.Printf(param.name);
4277 f.Printf(" %c\n", CloseBracket);
4283 if(!object.instCode)
4286 f.Printf(" %c;\n", CloseBracket);
4288 f.Printf("%c;\n", CloseBracket);
4290 else if(!object.deleted)
4292 // Turn this into a multiline instance when adding a method
4293 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4295 f.Printf(methodPresent ? "\n " : " ");
4297 f.Seek(inst.loc.end.pos + 1 - position, current);
4298 position = inst.loc.end.pos + 1;
4303 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4306 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4308 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4310 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4312 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4313 if(prop && prop.isProperty && !prop.conversion)
4315 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4316 (!prop.IsSet || prop.IsSet(classObject.instance)))
4318 Class dataType = prop.dataTypeClass;
4319 char tempString[1024] = "";
4321 bool specify = false;
4324 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4325 if(member && member._class == regClass)
4329 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4331 if(dataType && dataType.type == structClass)
4333 void * dataForm = new0 byte[dataType.structSize];
4334 void * dataTest = new0 byte[dataType.structSize];
4336 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4337 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4339 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4341 bool needClass = true;
4343 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4344 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4346 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4348 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4353 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4355 void * dataForm, * dataTest;
4357 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4358 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4360 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4362 char tempString[1024] = "";
4364 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4366 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4368 // Shouldn't go here ...
4369 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4373 bool needClass = true;
4375 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4377 if(!strcmp(dataType.dataTypeString, "char *"))
4379 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4380 OutputString(f, string);
4384 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4386 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4392 DataValue dataForm, dataTest;
4394 GetProperty(prop, classObject.instance, &dataForm);
4395 GetProperty(prop, test, &dataTest);
4397 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4399 SetProperty(prop, test, dataForm);
4400 if(dataType.type == bitClass)
4402 bool needClass = true;
4403 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4405 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4407 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4411 bool needClass = true;
4412 if(dataType.type == enumClass)
4415 Class enumClass = eSystem_FindClass(privateModule, "enum");
4416 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4418 for(value = e.values.first; value; value = value.next)
4420 if((int)value.data == dataForm.i)
4422 string = value.name;
4428 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4429 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4430 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4432 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4441 void UpdateFormCode()
4444 if(!parsing) return;
4451 else if(formModified)
4453 EditBoxStream f { editBox = editBox };
4457 Identifier movedFuncId;
4458 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4459 ObjectInfo classObject;
4465 movedFuncId = GetDeclId(function.declarator);
4466 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4467 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4470 for(classObject = classes.first; classObject; classObject = classObject.next)
4473 ClassDefinition classDef = classObject.classDefinition;
4474 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4477 bool firstObject = true;
4478 ObjectInfo object = classObject.instances.first;
4479 bool lastIsDecl = false;
4481 if(!classObject.modified) continue;
4483 test = eInstance_New(regClass);
4486 // Put it in the same desktop window...
4487 designer.PrepareTestObject(test);
4489 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4490 //f.Printf("%c\n\n", OpenBracket);
4492 // Change the _class name
4493 f.Seek(classDef.nameLoc.start.pos - position, current);
4494 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4495 f.Printf(classObject.name);
4496 position = classDef.nameLoc.end.pos;
4499 // Go to block start, delete all until no white space, put \n
4503 f.Seek(classDef.blockStart.end.pos - position, current);
4504 position = classDef.blockStart.end.pos;
4506 for(; f.Getc(&ch); count++)
4510 f.Seek(-1, current);
4520 f.Seek(-count, current);
4522 f.DeleteBytes(count-back);
4524 position += count-back;
4527 // Output properties
4528 OutputClassProperties(classObject.instance._class, classObject, f, test);
4530 for(def = classDef.definitions->first; def; def = def.next)
4534 case defaultPropertiesClassDef:
4536 bool keptMember = false;
4538 MemberInit lastKept = null;
4541 DeleteJunkBefore(f, def.loc.start.pos, &position);
4544 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4546 Identifier ident = propDef.identifiers->first;
4547 bool deleted = false;
4549 // For now delete if it's a prop
4550 if(!propDef.variable && ident)
4554 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4557 f.Seek(propDef.loc.start.pos - position, current);
4558 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4559 position = propDef.loc.end.pos;
4564 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4565 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4567 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4568 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4570 f.Seek(propDef.loc.start.pos - position, current);
4571 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4572 position = propDef.loc.end.pos;
4590 f.Seek(def.loc.end.pos - position - 1, current);
4595 f.Seek(-1, current);
4598 position = def.loc.end.pos;
4602 if(lastKept != def.defProperties->last)
4607 f.Seek(-1, current);
4613 f.Seek(-1, current);
4616 else if(!isspace(ch))
4618 f.Seek(-2, current);
4623 f.DeleteBytes(count);
4627 f.Seek(def.loc.end.pos - position, current);
4628 position = def.loc.end.pos;
4633 case declarationClassDef:
4635 Declaration decl = def.decl;
4637 if(decl.type == instDeclaration)
4639 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4641 while(def.object && object != def.object)
4643 if(object /*&& ((ObjectInfo)def.object).modified*/)
4644 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4645 object = object.next;
4648 DeleteJunkBefore(f, def.loc.start.pos, &position);
4649 f.Printf(firstObject ? "\n\n " : "\n ");
4650 firstObject = false;
4652 if(def.object && ((ObjectInfo)def.object).modified)
4653 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4655 object = object ? object.next : null;
4659 DeleteJunkBefore(f, def.loc.start.pos, &position);
4660 f.Printf(firstObject ? "\n\n " : "\n ");
4661 firstObject = false;
4667 DeleteJunkBefore(f, def.loc.start.pos, &position);
4668 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4673 case functionClassDef:
4675 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4676 if(!def.function.body) continue;
4680 DeleteJunkBefore(f, def.loc.start.pos, &position);
4683 // Delete _class methods
4684 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4685 def.function == function)
4690 if(moveAttached && !text)
4692 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4695 f.Seek(def.loc.end.pos - position, current);
4696 for(; f.Getc(&ch); count++)
4700 f.Seek(-1, current);
4704 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4706 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4707 position = def.loc.end.pos + count;
4710 // In case of detaching methods in the _class, simply rename the method
4711 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4713 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4714 f.DeleteBytes(movedFuncIdLen);
4716 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4719 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4720 function == def.function)
4722 // In case of attaching methods in the _class, simply rename the method
4723 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4724 position = function.loc.start.pos + movedFuncIdPos;
4725 f.DeleteBytes(movedFuncIdLen);
4726 if(method.dataType.thisClass)
4727 f.Printf("%s::", method.dataType.thisClass.string);
4728 f.Puts(method.name);
4729 position += movedFuncIdLen;
4734 DeleteJunkBefore(f, def.loc.start.pos, &position);
4735 if(def.type == memberAccessClassDef)
4738 firstObject = false;
4748 f.Seek(def.loc.end.pos - position, current);
4749 position = def.loc.end.pos;
4752 // Output attached methods
4753 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4755 DeleteJunkBefore(f, position, &position);
4756 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4759 // ********** INSTANCES ***************
4760 for(; object; object = object.next)
4762 if(!object.instCode)
4764 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4768 DeleteJunkBefore(f, position, &position);
4770 // ****************** METHODS ***********************
4771 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4773 // If detaching an instance method
4774 if(selected != classObject)
4776 int newLen = strlen(methodName);
4779 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4780 // Tab selection left
4783 for(c = 0; text[c]; )
4786 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4787 memmove(text+start, text+start+i, textSize+1-start-i);
4790 for(; text[c] && text[c] != '\n'; c++);
4796 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4797 textSize += newLen - movedFuncIdLen;
4798 memcpy(text + movedFuncIdPos, methodName, newLen);
4805 if(methodAction == actionAddMethod && selected == classObject)
4807 Method method = this.method;
4809 if(!method.dataType)
4810 method.dataType = ProcessTypeString(method.dataTypeString, false);
4812 // ADDING METHOD HERE
4814 Type dataType = method.dataType;
4815 Type returnType = dataType.returnType;
4817 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4821 OutputType(f, returnType, false);
4824 if(dataType.thisClass && !dataType.classObjectType)
4826 if(dataType.thisClass.shortName)
4827 f.Printf(dataType.thisClass.shortName);
4829 f.Printf(dataType.thisClass.string);
4832 f.Printf(method.name);
4834 for(param = dataType.params.first; param; param = param.next)
4836 OutputType(f, param, true);
4841 f.Printf(" %c\n\n", OpenBracket);
4843 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4845 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4846 f.Printf(" return true;\n");
4847 else if(returnType && returnType.kind != voidType)
4848 f.Printf(" return 0;\n");
4853 if(returnType.kind != voidType)
4854 f.Printf("return ");
4856 char * name = ((Specifier)classDef.baseSpecs->first).name;
4857 Symbol _class = FindClass(name);
4858 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4860 for(param = dataType.params.first; param; param = param.next)
4862 if(param.prev) f.Printf(", ");
4863 if(param.kind != voidType)
4864 f.Printf(param.name);
4869 f.Printf(" %c", CloseBracket);
4873 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4885 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4886 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4890 codeModified = false;
4891 formModified = false;
4893 moveAttached = false;
4898 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4901 ClassFunction function = null;
4904 ObjectInfo object = this.selected;
4906 if(object && object == this.oClass)
4908 ClassDefinition classDef = object.oClass.classDefinition;
4910 if(classDef && classDef.definitions)
4912 for(def = classDef.definitions->first; def; def = def.next)
4914 if(def.type == functionClassDef && def.function.declarator)
4916 if(!strcmp(def.function.declarator.symbol.string, methodName))
4918 function = def.function;
4923 else if(def.type == defaultPropertiesClassDef)
4927 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4929 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4930 if(ident && !ident.next)
4932 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4936 propLoc = propDef.loc;
4939 ClassDefinition classDef = object.oClass.classDefinition;
4941 if(classDef.definitions)
4943 for(def = classDef.definitions->first; def; def = def.next)
4945 if(def.type == functionClassDef)
4947 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4949 function = def.function;
4968 Instantiation inst = object.instCode;
4970 // Check here to see if the method already exists, no need to call ModifyCode in that case
4971 if(inst && inst.members)
4973 MembersInit members;
4974 for(members = inst.members->first; members; members = members.next)
4976 switch(members.type)
4978 case dataMembersInit:
4980 if(members.dataMembers)
4983 for(member = members.dataMembers->first; member; member = member.next)
4985 Identifier ident = member.identifiers ? member.identifiers->first : null;
4986 if(ident && !ident.next)
4988 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4992 propLoc = member.loc;
4995 ClassDefinition classDef = object.oClass.classDefinition;
4997 if(classDef.definitions)
4999 for(def = classDef.definitions->first; def; def = def.next)
5001 if(def.type == functionClassDef)
5003 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5005 function = def.function;
5014 // TODO: Fix memory leak
5015 function = ClassFunction
5017 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5029 case methodMembersInit:
5031 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5033 function = members.function;
5045 if(functionPtr) *functionPtr = function;
5049 void GoToMethod(char * methodName /*Method method*/)
5053 ObjectInfo object = selected;
5054 EditBoxStream f { editBox = editBox };
5055 ClassFunction function = null;
5056 bool atChar = false;
5060 Location propLoc = { {0,0,-1} };
5063 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5064 if(function && function.body)
5067 f.Seek(function.body.loc.start.pos+1, current);
5077 f.Seek(-1, current);
5082 else if(!isspace(ch))
5084 f.Seek(-1, current);
5090 else if(propLoc.start.pos > -1)
5092 f.Seek(propLoc.start.pos, current);
5095 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5097 if(function || propLoc.start.pos > -1)
5099 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5100 editBox.CenterOnCursor();
5101 SetState(normal, false, 0);
5104 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5106 FreeClassFunction(function);
5112 void FindCompatibleMethods(Method method, OldList compatible)
5114 ClassDefinition classDef = this.oClass.classDefinition;
5115 if(classDef && classDef.definitions)
5118 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5121 Symbol classSym { };
5122 Symbol selectedClass;
5123 if(this.selected == this.oClass)
5124 selectedClass = classSym;
5126 selectedClass = FindClass(this.selected.instance._class.name);
5128 regClass.name = classDef._class.name;
5129 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5130 for(def = classDef.definitions->first; def; def = def.next)
5132 if(def.type == functionClassDef && def.function.declarator)
5134 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5136 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5139 Type type = def.function.declarator.symbol.type;
5140 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5142 compatible.Add(OldLink { data = def.function });
5148 if(this.oClass && this.oClass.instance)
5150 classSym.registered = regClass;
5151 //classSym.registered = this.oClass.oClass;
5153 for(_class = regClass.base; _class; _class = _class.base)
5156 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5158 // TODO: Understand why these functions popup in attach list
5159 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5161 if(!testMethod.dataType)
5162 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5164 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5165 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5166 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5168 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5169 // ClassFunction function { };
5170 FunctionDefinition function { };
5172 function.declarator = Declarator { };
5173 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5174 excludedSymbols.Add(function.declarator.symbol);
5176 compatible.Add(OldLink { data = function });
5187 void AddMethod(Method method)
5191 char methodName[1024];
5192 strcpy(methodName, method.name);
5193 if(!FindMethod(methodName, null, null))
5195 methodAction = actionAddMethod;
5196 this.method = method;
5200 GoToMethod(methodName);
5204 void DeleteMethod(ClassFunction function)
5208 methodAction = actionDeleteMethod;
5209 this.function = function;
5217 void AttachMethod(Method method, ClassFunction function)
5221 // If it's an instance we'll ask if we want to move it inside...
5222 if(!function.attached.count && function.body)
5224 // Find the function in the _class to check if it's a virtual function
5225 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5226 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5227 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5229 for(def = this.classDefinition.first; def; def = def.next)
5231 if(def.type == functionClassDef)
5233 if(def.function == function)
5238 if(!method || method.type != virtualMethod)
5241 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5242 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5244 moveAttached = true;
5249 methodAction = actionAttachMethod;
5250 this.method = method;
5251 this.function = function;
5258 void ReAttachMethod(Method method, ClassFunction function)
5262 // If it's an instance we'll ask if we want to move it inside...
5263 if(!function.attached.count && function.body)
5265 // Find the function in the _class to check if it's a virtual function
5266 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5267 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5268 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5270 for(def = this.classDefinition.first; def; def = def.next)
5272 if(def.type == functionClassDef)
5274 if(def.function == function)
5279 if(!method || method.type != virtualMethod)
5282 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5283 if(MessageBox { type = yesNo, master = parent, text = title,
5284 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5286 moveAttached = true;
5291 methodAction = actionReattachMethod;
5292 this.method = method;
5293 this.function = function;
5300 void DetachMethod(Method method, ClassFunction function, int type)
5308 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5309 master = sheet, text = $"Name detached method", background = formColor
5313 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5314 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5318 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5319 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5323 dialog, anchor = { left = 5, right = 5, top = 5 }
5325 sprintf(methodName, "%s_%s", selected.name, method.name);
5326 nameBox.contents = methodName;
5328 result = dialog.Modal() == ok;
5329 strcpy(methodName, nameBox.contents);
5334 // If the method is not attached, move it outside
5337 // Add this class to the methodName
5338 char name[1024] = "";
5340 if(this.selected != this.oClass && !method.dataType.thisClass)
5342 strcat(name, this.selected.instance._class.name);
5344 strcat(name, this.methodName);
5345 strcpy(this.methodName, name);
5347 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5349 strcat(name, method.dataType.thisClass.string);
5351 strcat(name, this.methodName);
5352 strcpy(this.methodName, name);
5355 this.moveAttached = true;
5358 this.methodAction = actionDetachMethod;
5359 this.method = method;
5360 this.function = function;
5367 void AddObject(Instance instance, ObjectInfo * object)
5371 //*object = _class.instances.Add(sizeof(ObjectInfo));
5372 *object = ObjectInfo { };
5373 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5374 (*object).oClass = oClass;
5375 (*object).instance = instance;
5380 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5382 // if(strcmp(name, this.oClass.instance.name))
5385 for(check = oClass.instances.first; check; check = check.next)
5386 if(!check.deleted && check.name && !strcmp(name, check.name))
5390 (*object).name = CopyString(name);
5395 toolBox.controlClass = null;
5399 //sheet.AddObject(*object, (*object).name, TypeData, true);
5404 void EnsureUpToDate()
5406 if(sheet && codeModified && parsing)
5410 void SelectObject(ObjectInfo object)
5413 oClass = object ? object.oClass : null;
5415 designer.SelectObject(object, object ? object.instance : null);
5418 void SelectObjectFromDesigner(ObjectInfo object)
5421 sheet.SelectObject(object);
5424 void EnumerateObjects(Sheet sheet)
5428 for(oClass = classes.first; oClass; oClass = oClass.next)
5434 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5435 for(object = oClass.instances.first; object; object = object.next)
5436 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5439 sheet.SelectObject(selected);
5444 designer.AddObject();
5447 void DeleteObject(ObjectInfo object)
5449 delete object.instance;
5450 object.deleted = true;
5451 object.modified = true;
5452 object.oClass.modified = true;
5454 if(selected == object)
5456 bool looped = false;
5457 ObjectInfo select = object;
5461 select = select.prev;
5465 select = object.oClass.instances.last;
5472 sheet.SelectObject(select ? select : oClass);
5475 if(!object.instCode && object.oClass != object)
5478 oClass.instances.Delete(object);
5481 if(sheet.codeEditor == this)
5482 sheet.DeleteObject(object);
5485 void RenameObject(ObjectInfo object, char * name)
5489 // Validate the name:
5490 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5491 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5494 for(c = 0; name[c]; c++)
5495 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5503 object.name = (name && name[0]) ? CopyString(name) : null;
5505 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5509 void DesignerModifiedObject()
5511 sheet.ListProperties(false);
5515 void ListSubMembers(Type member)
5519 for(subMember = member.members.first; subMember; subMember = subMember.next)
5523 DataRow row = membersList.AddString(subMember.name);
5524 row.icon = icons[typeData];
5528 ListSubMembers(subMember);
5533 void ListSubDataMembers(DataMember member, bool isPrivate)
5535 DataMember subMember;
5536 for(subMember = member.members.first; subMember; subMember = subMember.next)
5538 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5542 DataRow row = membersList.AddString(subMember.name);
5543 BitmapResource bitmap = null;
5544 if(!subMember.dataType)
5545 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5547 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5549 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5552 bitmap = { bitmapName };
5553 membersList.AddResource(bitmap);
5556 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5560 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5566 void ListClassMembers(Class whatClass, bool methodsOnly)
5569 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5570 bool isPrivate = false;
5572 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5574 Method method, methodIt;
5576 DataMember memberIt;
5578 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5580 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5581 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5583 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5585 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5587 DataRow row = membersList.FindString(method.name);
5590 row = membersList.AddString(method.name);
5592 if(!method.dataType)
5593 method.dataType = ProcessTypeString(method.dataTypeString, false);
5595 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5603 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5607 if(memberIt.isProperty)
5609 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5611 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5615 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5617 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5620 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5626 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5628 if(member.isProperty)
5630 Property prop = (Property) member;
5631 if(!membersList.FindString(prop.name))
5633 DataRow row = membersList.AddString(prop.name);
5634 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5637 else if(member.name && !membersList.FindString(member.name))
5639 DataRow row = membersList.AddString(member.name);
5641 BitmapResource bitmap = null;
5642 if(!member.dataType)
5643 member.dataType = ProcessTypeString(member.dataTypeString, false);
5645 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5647 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5650 bitmap = { bitmapName };
5651 membersList.AddResource(bitmap);
5654 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5657 ListSubDataMembers(member, member.memberAccess == privateAccess);
5661 if(_class.inheritanceAccess == privateAccess)
5664 if(_class.module != privateModule) break;
5669 void ListClassMembersMatch(Class whatClass, Type methodType)
5672 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5673 bool isPrivate = false;
5675 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5681 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5683 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5685 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5687 if(!method.dataType)
5688 method.dataType = ProcessTypeString(method.dataTypeString, false);
5690 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5692 DataRow row = membersList.FindString(method.name);
5695 row = membersList.AddString(method.name);
5696 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5702 if(_class.inheritanceAccess == privateAccess)
5705 if(_class.module != privateModule) break;
5710 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5713 bool isPrivate = false;
5714 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5720 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5722 if(method.type == virtualMethod)
5724 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5726 DataRow row = membersList.FindString(method.name);
5729 row = membersList.AddString(method.name);
5731 if(!method.dataType)
5732 method.dataType = ProcessTypeString(method.dataTypeString, false);
5734 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5740 for(member = _class.membersAndProperties.first; member; member = member.next)
5742 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5744 if(member.isProperty)
5746 Property prop = (Property)member;
5748 DataRow row = membersList.AddString(prop.name);
5749 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5752 else if(member.name && (!curString || strcmp(curString, member.name)))
5754 DataRow row = membersList.AddString(member.name);
5756 BitmapResource bitmap = null;
5757 if(!member.dataType)
5758 member.dataType = ProcessTypeString(member.dataTypeString, false);
5760 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5762 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5765 bitmap = { bitmapName };
5766 membersList.AddResource(bitmap);
5769 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5772 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5775 if(_class.inheritanceAccess == privateAccess)
5778 if(_class.module != privateModule) break;
5783 void ListMembers(Type type)
5785 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5789 if(type.kind == classType)
5792 ListClassMembers(type._class.registered, false);
5797 for(member = type.members.first; member; member = member.next)
5801 DataRow row = membersList.AddString(member.name);
5802 row.icon = icons[typeData];
5804 else if(member.kind == structType || member.kind == unionType)
5805 ListSubMembers(member);
5811 void ListModule(Module mainModule, int recurse, bool listClasses)
5814 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5815 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5816 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5817 for(module = mainModule.application.allModules.first; module; module = module.next)
5819 if(ModuleVisibility(mainModule, module))
5820 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5824 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5831 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5833 Class _class = link.data;
5834 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5836 DataRow row = membersList.AddString(_class.name);
5837 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5842 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5844 DefinedExpression definedExp = link.data;
5845 DataRow row = membersList.AddString(link /*definedExp*/.name);
5846 row.icon = icons[typeData];
5849 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5851 GlobalFunction function = link.data;
5852 DataRow row = membersList.AddString(link /*function*/.name);
5853 row.icon = icons[typeMethod];
5857 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5859 if(recurse != 2 && listClasses)
5861 if(!membersList.FindString(ns->name))
5863 DataRow row = membersList.AddString(ns->name);
5864 row.icon = icons[typeNameSpace];
5869 ListNameSpace(ns, 2, listClasses);
5873 void ListEnumValues(Class _class)
5875 List<Class> classes { };
5876 for(; _class && _class.type == enumClass; _class = _class.base)
5877 classes.Insert(null, _class);
5878 for(_class : classes)
5880 EnumClassData enumeration = (EnumClassData)_class.data;
5882 for(item = enumeration.values.first; item; item = item.next)
5884 DataRow row = membersList.AddString(item.name);
5885 row.icon = icons[typeEnumValue];
5891 bool ListEnumsModule(Module mainModule, Type dest)
5893 bool result = false;
5895 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5896 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5897 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5898 for(module = mainModule.application.allModules.first; module; module = module.next)
5900 if(ModuleVisibility(mainModule, module))
5901 result |= ListEnums(module.publicNameSpace, dest);
5906 void ListNameSpaceByString(Module mainModule, char * string)
5908 NameSpace * nameSpace;
5910 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5911 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5912 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5913 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5914 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5915 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5916 for(module = mainModule.application.allModules.first; module; module = module.next)
5918 if(ModuleVisibility(mainModule, module))
5920 nameSpace = FindNameSpace(module.publicNameSpace, string);
5921 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5926 bool ListEnums(NameSpace nameSpace, Type dest)
5929 bool result = false;
5931 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5933 Class _class = link.data;
5934 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5935 dest.kind != pointerType && dest.kind != ellipsisType)
5937 OldList conversions { };
5939 type.kind = classType;
5940 type._class = FindClass(_class.name);
5941 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5943 ListEnumValues(_class);
5946 conversions.Free(null);
5950 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5952 result |= ListEnums(nameSpace, dest);
5957 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5961 for(c = 0; (ch = name[c]); c++)
5963 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5965 NameSpace * newSpace;
5966 char * spaceName = new char[c - start + 1];
5967 memcpy(spaceName, name + start, c - start);
5968 spaceName[c-start] = '\0';
5969 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5973 nameSpace = newSpace;
5982 return (NameSpace *)nameSpace;
5985 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5987 bool listedEnums = false;
5988 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5989 bool listClasses = true;
5991 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5993 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5994 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5995 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5997 if(exp.type == identifierExp)
5998 id = realIdentifier;
6000 if(id && id._class && !id._class.name)
6002 listClasses = false;
6005 else if(id && id._class && id._class.name)
6009 Class _class = id.classSym.registered;
6010 if(_class && _class.type == enumClass)
6012 ListEnumValues(_class);
6015 ListClassMembers(id.classSym.registered, true);
6020 else if(id && colons)
6022 ListNameSpaceByString(this.privateModule, id.string);
6027 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6029 listedEnums = ListEnumsModule(this.privateModule, destType);
6032 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6034 ListEnumValues(destType._class.registered);
6037 ListClassPropertiesAndVirtual(insideClass, null);
6041 else if(destType && destType.kind == enumType)
6045 for(value = destType.members.first; value; value = value.next)
6047 DataRow row = membersList.AddString(value.name);
6048 row.icon = icons[typeEnumValue];
6052 ListClassPropertiesAndVirtual(insideClass, null);
6056 else if(insideClass && !enumOnly)
6058 ListClassPropertiesAndVirtual(insideClass, string);
6061 if(listedEnums && string && string[0])
6063 DataRow row = membersList.FindSubString(string);
6065 listedEnums = false;
6068 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6070 ListClassMembersMatch(GetThisClass(), exp.destType);
6072 else if(!insideClass && !enumOnly && !listedEnums)
6075 Symbol symbol = null;
6079 ListClassMembers(GetThisClass(), false);
6082 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6084 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6086 // Don't list enum values?
6087 //if(symbol.type.kind != TypeEnum)
6088 DataRow row = membersList.FindString(symbol.string);
6091 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6093 row = membersList.AddString(symbol.string);
6094 if(symbol.type && symbol.type.kind == functionType)
6095 row.icon = icons[typeMethod];
6096 else if(symbol.type && symbol.type.kind == enumType)
6098 row.icon = icons[typeEnumValue];
6102 BitmapResource bitmap = null;
6103 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6105 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6108 bitmap = { bitmapName };
6109 membersList.AddResource(bitmap);
6112 row.icon = bitmap ? bitmap : icons[typeData];
6119 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6121 DataRow row = membersList.FindString(symbol.string);
6124 row = membersList.AddString(symbol.string);
6125 if(symbol.type.kind == functionType)
6126 row.icon = icons[typeMethod];
6127 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6129 row.icon = icons[typeClass];
6133 row.icon = icons[typeDataType];
6140 ListModule(this.privateModule, 1, listClasses);
6141 // TODO: Implement this with name space
6145 for(data = globalData.first; data; data = data.next)
6147 DataRow row = membersList.FindString(data.name);
6149 data.dataType = ProcessTypeString(data.dataTypeString, false);
6152 row = membersList.AddString(data.name);
6154 if(data.dataType && data.dataType.kind == TypeEnum)
6156 row.icon = icons[typeEnumValue];
6160 BitmapResource bitmap = null;
6161 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6163 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6166 bitmap = { bitmapName };
6167 membersList.AddResource(bitmap);
6170 row.icon = bitmap ? bitmap : icons[typeData];
6178 DataRow row = membersList.AddString("Min");
6179 row.icon = icons[typeMethod];
6181 row = membersList.AddString("Max");
6182 row.icon = icons[typeMethod];
6184 row = membersList.AddString("Abs");
6185 row.icon = icons[typeMethod];
6187 row = membersList.AddString("Sgn");
6188 row.icon = icons[typeMethod];
6194 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6196 EditBoxStream f { editBox = editBox };
6201 updatingCode = true;
6203 if(!method.dataType)
6204 method.dataType = ProcessTypeString(method.dataTypeString, false);
6206 DeleteJunkBefore(f, function.loc.start.pos, &position);
6207 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6209 // ADDING METHOD HERE
6211 Type dataType = method.dataType;
6212 Type returnType = dataType.returnType;
6214 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6220 if(extraIndent) f.Printf(" ");
6222 OutputType(f, returnType, false);
6226 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6228 if(dataType.thisClass.shortName)
6229 f.Printf(dataType.thisClass.shortName);
6231 f.Printf(dataType.thisClass.string);
6234 f.Printf(method.name);
6236 for(param = dataType.params.first; param; param = param.next)
6238 // Decided not to write void...
6239 if(param.kind != voidType)
6241 OutputType(f, param, true);
6247 if(extraIndent) f.Printf(" ");
6248 f.Printf(" %c\n", OpenBracket);
6250 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6256 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6257 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6259 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6261 if(extraIndent) f.Printf(" ");
6262 f.Printf(" return true;\n");
6264 else if(returnType && returnType.kind != voidType)
6266 if(extraIndent) f.Printf(" ");
6267 f.Printf(" return 0;\n");
6272 if(extraIndent) f.Printf(" ");
6274 if(returnType.kind != voidType)
6275 f.Printf("return ");
6276 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6277 for(param = dataType.params.first; param; param = param.next)
6279 if(param.prev) f.Printf(", ");
6280 if(param.kind != voidType)
6281 f.Printf(param.name);
6287 if(extraIndent) f.Printf(" ");
6288 f.Printf(" %c", CloseBracket);
6293 if(extraIndent) { x1 += 3; x2 += 3; }
6294 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6296 this.updatingCode = false;
6300 // Return false if we overrided a function and don't want to run params listing
6301 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6303 bool didOverride = false;
6304 EditLine line = editBox.line;
6305 char * text = line.text;
6306 int lineNum, charPos;
6307 Expression exp = null;
6310 //Identifier id = null;
6311 Expression memberExp = null;
6312 Identifier realIdentifier = null;
6314 if(!parsing) return true;
6315 if(!privateModule) return !didOverride;
6317 insideFunction = null;
6319 charPos = editBox.charPos + 1;
6320 if(!membersListShown)
6325 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6327 EditBoxStream f { editBox = editBox };
6329 updatingCode = true;
6330 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6334 if(!f.Seek(-1, current))
6337 if(!isspace(ch)) break;
6338 f.Seek(-1, current);
6340 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6342 lineNum = editBox.lineNumber + 1;
6343 charPos = editBox.charPos + 1;
6345 updatingCode = false;
6348 if(!membersListShown)
6350 memberExp = FindExpTree(ast, lineNum, charPos);
6351 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6356 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6358 EditBoxStream f { editBox = editBox };
6361 updatingCode = true;
6363 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6366 if(ch == '}' || ch == ',' || ch == ')')
6368 f.Seek(-1, current);
6376 if(!f.Seek(-1, current))
6379 if(!isspace(ch)) break;
6380 f.Seek(-1, current);
6384 f.Seek(-1, current);
6386 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6388 lineNum = editBox.lineNumber + 1;
6389 charPos = editBox.charPos + 1;
6391 updatingCode = false;
6394 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6399 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6400 lineNum = editBox.lineNumber + 1;
6401 charPos = editBox.charPos/* + 1*/;
6405 char tempString[1024];
6406 char * string = null;
6407 CodePosition idStart, idEnd;
6409 if(membersListShown)
6411 char * buffer = membersLine.text;
6413 bool firstChar = true;
6415 string = tempString;
6417 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6419 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6420 if(!isSpace) firstChar = false;
6422 string[len++] = buffer[c];
6426 else //if(realIdentifier)//if(id)
6429 char * buffer = id.string;
6431 bool firstChar = true;
6433 string = tempString;
6434 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6436 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6437 if(!isSpace) firstChar = false;
6439 string[len++] = buffer[c];
6445 EditLine editLine = editBox.line;
6446 bool firstChar = true;
6449 string = tempString;
6450 for(y = lineNum-1; y >= 0; y--)
6452 char * buffer = editLine.text;
6453 int lineCount = editLine.count;
6454 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6456 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6461 idEnd.charPos = x + 2;
6466 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6469 idEnd.charPos = x + 2;
6476 if(!isalnum(buffer[x]) && buffer[x] != '_')
6482 memmove(string+1, string, len++);
6483 string[0] = buffer[x];
6487 //if(done || firstChar)
6488 if(done || !firstChar)
6490 editLine = editLine.prev;
6493 if(!strcmp(string, "case"))
6499 else if(!strcmp(string, "return"))
6505 else if(!strcmp(string, "delete"))
6511 else if(!strcmp(string, "new"))
6517 else if(!strcmp(string, "renew"))
6525 idStart.charPos = x + 1;
6526 idStart.line = y + 1;
6529 if(!membersListShown)
6531 membersList.Clear();
6532 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6534 Type type = memberExp.member.exp.expType;
6535 if(pointer == 2 && type)
6537 if(type.kind == pointerType || type.kind == arrayType)
6546 ListSymbols(exp, enumOnly, string, realIdentifier);
6548 membersList.Sort(null, 1);
6553 // Virtual function override
6554 Identifier id = GetDeclId(insideFunction.declarator);
6555 char * string = id ? id.string : null;
6557 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6560 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6561 insideFunction = null;
6564 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6569 if(!didOverride) //insideFunction)
6571 rowCount = membersList.rowCount;
6574 DataRow row = string ? membersList.FindSubString(string) : null;
6575 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6577 char * newString = row.string;
6578 if(!membersListShown)
6580 membersLoc.start.line = idStart.line-1;
6581 membersLoc.start.charPos = idStart.charPos-1;
6582 //membersLoc.end = membersLoc.start;
6583 membersLoc.end.charPos = idEnd.charPos-1;
6584 membersLoc.end.line = idEnd.line-1;
6585 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6586 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6591 membersList.Destroy(0);
6592 membersListShown = false;
6595 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6597 line, membersLoc.start.line, membersLoc.start.charPos,
6598 line, membersLoc.end.line, membersLoc.end.charPos);
6599 editBox.PutS(newString);
6605 row = membersList.FindSubStringi(string);
6607 membersList.currentRow = row;
6608 membersList.currentRow.selected = false;
6611 membersList.currentRow = row;
6613 if(!membersListShown)
6617 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6618 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6619 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6620 editBox.GetCaretPosition(caret);
6621 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6623 membersList.master = this;
6625 caret.y += editBox.GetCaretSize();
6627 membersList.Create();
6630 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6631 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6632 Window parent = membersList.parent;
6634 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6636 y -= editBox.GetCaretSize() + membersList.size.h;
6637 membersAbove = true;
6640 membersAbove = false;
6642 membersList.position = { x, y };
6646 membersLoc.start.line = lineNum - 1;
6648 if(string && string[0])
6650 membersLoc.start.charPos = idStart.charPos-1;
6651 membersLoc.end = membersLoc.start;
6652 //membersLoc.end.charPos = id.loc.end.charPos-1;
6653 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6657 membersLoc.start.charPos = charPos;
6658 membersLoc.end = membersLoc.start;
6659 membersLoc.end.charPos = charPos;
6661 membersListShown = true;
6663 // Hack to keep caret shown
6664 editBox.GetCaretPosition(caret);
6665 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6668 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6674 SetCurrentContext(globalContext);
6677 return !didOverride;
6680 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6682 EditLine line = editBox.line;
6683 char * text = line.text;
6684 int lineNum, charPos;
6685 Expression exp = null;
6689 if(!parsing) return;
6691 charPos = editBox.charPos + 1;
6694 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6696 EditBoxStream f { editBox = editBox };
6699 updatingCode = true;
6700 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6703 if(ch == '}' || ch == ',' || ch == ')')
6705 f.Seek(-1, current);
6713 if(!f.Seek(-1, current))
6716 if(!isspace(ch)) break;
6717 f.Seek(-1, current);
6721 f.Seek(-1, current);
6723 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6725 lineNum = editBox.lineNumber + 1;
6726 charPos = editBox.charPos + 1;
6728 updatingCode = false;
6731 charPos = Min(charPos, l1.count + 1);
6733 FindParamsTree(ast, lineNum, charPos);
6735 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6736 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6738 ::functionType = null;
6739 ::instanceType = null;
6742 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6743 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6747 Window parent = paramsList.parent;
6749 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6752 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6753 // ( Dummy exp: always ends up with same memory)
6755 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6756 editBox.GetCaretPosition(paramsPosition);
6757 this.paramsPosition.y += editBox.GetCaretSize();
6760 FreeType(this.functionType);
6761 FreeType(this.instanceType);
6763 this.functionType = ::functionType;
6764 this.instanceType = ::instanceType;
6766 if(this.functionType) this.functionType.refCount++;
6767 if(this.instanceType) this.instanceType.refCount++;
6769 this.paramsID = ::paramsID;
6770 functionExp = paramsInsideExp;
6772 paramsList.master = this;
6774 paramsList.Create();
6776 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6777 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6779 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6781 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6785 paramsAbove = false;
6786 if(x + paramsList.size.w > parent.clientSize.w)
6788 x = parent.clientSize.w - paramsList.size.w;
6792 paramsList.position = { x, y };
6794 // Hack to keep caret shown
6797 editBox.GetCaretPosition(caret);
6798 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6801 this.paramsShown = true;
6803 else if((!::functionType && !::instanceType) || reposition)
6805 paramsList.Destroy(0);
6806 paramsShown = false;
6808 FreeType(this.functionType);
6809 FreeType(this.instanceType);
6810 this.functionType = null;
6811 this.instanceType = null;
6815 SetCurrentContext(globalContext);
6823 designer.visible = true;
6824 designer.Activate();
6830 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6832 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6837 static int nofdigits(int v)
6839 if(v == MININT) return 10 + 1;
6840 if(v < 0) return nofdigits(-v) + 1;