sdk: const correctness
[sdk] / ide / src / designer / CodeObject.ec
1 import "ide"
2
3 enum CodeObjectType { typeClass, typeData, typeMethod, typeEvent, typeProperty, typeNameSpace, typeDataType, typeEnumValue, typeDataPrivate, typeMethodPrivate, typePropertyPrivate };
4
5 // patch for GCC 4.4 bug (Can't make it static or the patch won't work)
6 /*static*/ int mystrlen(const char * s)
7 {
8    return strlen(s);
9 }
10 #define strlen mystrlen
11
12 class CodeObject : struct
13 {
14    const char * name;
15    bool bold;
16    CodeObjectType type;
17    int indent;
18    Method method;
19    int overriden;
20    OldList compatible;
21    BitmapResource bitmap;
22    ObjectInfo object;
23
24    ClassFunction function;
25    Button attachBtn, detachBtn, deleteBtn;
26    bool eventsUp;
27
28    void OnDisplay(Surface surface, int x, int y, int width, CodeEditor editor, Alignment alignment, DataDisplayFlags displayFlags)
29    {
30       int indent = displayFlags.dropBox ? 0 : 10;
31       int textOffset;
32       const char * name = object ? (object.name ? object.name : $"(unnamed)") : this.name;
33       int nameLen = strlen(name);
34
35       Bitmap icon = bitmap ? bitmap.bitmap : editor.icons[type].bitmap;
36
37       textOffset = this.indent * indent + (icon ? (/*icon.width + 4*/ 20) : 0);
38       if(overriden || object)
39          surface.TextFont(editor.boldFont.font);
40       else
41          surface.TextFont(editor.normalFont.font);
42
43       surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, nameLen);
44       if(icon)
45          surface.Blit(icon, x + (20 - icon.width) / 2 + this.indent * indent,y + 2,0,0, icon.width, icon.height);
46
47       if(object)
48       {
49          int nameW;
50          char text[1024] = "";
51          int len;
52
53          strcpy(text, object.instance._class.name);
54          len = strlen(text);
55          surface.TextExtent(name, nameLen, &nameW, null);
56
57          surface.TextFont(editor.normalFont.font);
58          surface.WriteTextDots(left, x + textOffset + nameW + 10, y + 2, width - (x + textOffset + nameW + 10), text, len);
59       }
60
61       if(overriden == 2 /*&& codeObject.function*/)
62       {
63          int w, nameW;
64          const char * text = function ? function.declarator.symbol.string : "";
65          int len = strlen(text);
66          int start;
67          if(!text[0])
68             printf("");
69          surface.TextExtent(name, nameLen, &nameW, null);
70          surface.TextExtent(text, len, &w, null);
71
72          start = x + textOffset + nameW + 10;
73
74          surface.WriteTextDots(right, start, y + 2, width - start - 16, text, len);
75       }
76    }
77
78    void OnFree()
79    {
80       OldLink compatible;
81
82       if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
83          FreeClassFunction(function);
84       if(deleteBtn)
85       {
86          deleteBtn.Destroy(0);
87          delete deleteBtn;
88       }
89       if(detachBtn)
90       {
91          detachBtn.Destroy(0);
92          delete detachBtn;
93       }
94       if(attachBtn)
95       {
96          attachBtn.Destroy(0);
97          delete attachBtn;
98       }
99
100       while(compatible = this.compatible.first)
101       {
102          ClassFunction function = compatible.data;
103
104          if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
105             FreeClassFunction(function);
106
107          this.compatible.Delete(compatible);
108       }
109       delete this;
110    }
111
112    const char * OnGetString(char * string, void * fieldData, bool * needClass)
113    {
114       return name ? name : "";
115    }
116
117    int OnCompare(CodeObject b)
118    {
119       int result = 0;
120       if(type == typeEvent && b.type == typeMethod)
121          result = eventsUp ? -1 : 1;
122       else if(type == typeMethod && b.type == typeEvent)
123          result = eventsUp ? 1 : -1;
124       else if(name && b.name)
125          result = strcmpi(name, b.name);
126       else if(!name && b.name)
127          result = 1;
128       else if(name && !b.name)
129          result = -1;
130       return result;
131    }
132 };