ide/Property Sheet: Not listing deprecated properties
[sdk] / ide / src / designer / Sheet.ec
1 import "ide"
2
3 import "CodeObject"
4
5 static void UnusedFunction()
6 {
7    int a;
8    Module b;
9    a.OnGetString(0,0,0);
10    a.OnFree();
11    a.OnCopy(null);
12    a.OnCompare(null);
13    a.OnSaveEdit(null,0);
14    a.OnEdit(null,null,0,0,0,0,0);
15    a.OnDisplay(null,0,0,0,0,0,0);
16    b.OnLoad();
17 }
18
19 extern int __ecereVMethodID_class_OnEdit;
20 extern int __ecereVMethodID_class_OnDisplay;
21 extern int __ecereVMethodID_class_OnGetString;
22 extern int __ecereVMethodID_class_OnFree;
23 extern int __ecereVMethodID_class_OnCompare;
24 extern int __ecereVMethodID_class_OnCopy;
25 extern int __ecereVMethodID_class_OnSaveEdit;
26
27 //#define SHOW_METHODS
28
29
30 // *** THESE METHODS SHOULD BE IMPROVED UPON AND USED TO SET PROPERTIES FROM NOW ON ***
31 //     (Other locations where this will be useful: JSON (DataValue version?), CodeEditor, ...)
32 // This takes in a value according to the any_object rules
33
34 void SetPropValue(Property prop, void * object, any_object value)
35 {
36    Class type = prop.dataTypeClass;
37    if(!type)
38       type = prop.dataTypeClass = eSystem_FindClass(prop._class.module, prop.dataTypeString);
39
40    if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
41    {
42       ((void (*)(void *, void *))(void *)prop.Set)(object, value);
43    }
44    // TOFIX: How to swiftly handle classes with base data type?
45    else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
46    {
47       ((void (*)(void *, double))(void *)prop.Set)(object, *(double *)value);
48    }
49    else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
50    {
51       ((void (*)(void *, float))(void *)prop.Set)(object, *(float *)value);
52    }
53    else if(type.typeSize == sizeof(int64))// || !strcmp(type.dataTypeString, "int64") || !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
54    {
55       ((void (*)(void *, int64))(void *)prop.Set)(object, *(int64 *)value);
56    }
57    else if(type.typeSize == sizeof(int))// || !strcmp(type.dataTypeString, "int") || !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
58    {
59       ((void (*)(void *, int))(void *)prop.Set)(object, *(int *)value);
60    }
61    else if(type.typeSize == sizeof(short int)) // || !strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||  !strcmp(type.dataTypeString, "int16"))
62    {
63       ((void (*)(void *, short))(void *)prop.Set)(object, *(short *)value);
64    }
65    else if(type.typeSize == sizeof(byte))// || !strcmp(type.dataTypeString, "char") || !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
66    {
67       ((void (*)(void *, byte))(void *)prop.Set)(object, *(byte *)value);
68    }
69    else
70    {
71       ((void (*)(void *, void *))(void *)prop.Set)(object, value);
72    }
73 }
74
75 any_object GetPropValue(Property prop, Instance object)
76 {
77    if(object)
78    {
79       Class type = prop.dataTypeClass;
80       if(!type)
81       {
82          type = prop.dataTypeClass = eSystem_FindClass(prop._class.module, prop.dataTypeString);
83       }
84
85       if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
86       {
87          return ((void*(*)())(void *)prop.Get)(object);
88       }
89       // TOFIX: How to swiftly handle classes with base data type?
90       else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
91       {
92          double d = ((double(*)(void *))(void *)prop.Get)(object);
93          return d;
94       }
95       else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
96       {
97          float f =((float(*)(void *))(void *)prop.Get)(object);
98          return f;
99       }
100       else if(type.typeSize == sizeof(int64))// || !strcmp(type.dataTypeString, "int64") || !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
101       {
102          return ((int64(*)(void *))(void *)prop.Get)(object);
103       }
104       else if(type.typeSize == sizeof(int))// || !strcmp(type.dataTypeString, "int") || !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
105       {
106          return ((int(*)(void *))(void *)prop.Get)(object);
107       }
108       else if(type.typeSize == sizeof(short int)) // || !strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||  !strcmp(type.dataTypeString, "int16"))
109       {
110          return ((short(*)(void *))(void *)prop.Get)(object);
111       }
112       else if(type.typeSize == sizeof(byte))// || !strcmp(type.dataTypeString, "char") || !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
113       {
114          return ((byte(*)(void *))(void *)prop.Get)(object);
115       }
116       else
117       {
118          return ((int (*)(void *))(void *)prop.Get)(object);
119       }
120    }
121    else
122       return 0;
123 }
124
125 void CopyProperty(Property prop, Instance dest, Instance src)
126 {
127    Class type = prop.dataTypeClass;
128    if(!type)
129       type = prop.dataTypeClass = eSystem_FindClass(prop._class.module, prop.dataTypeString);
130
131    if(type.type == structClass)
132    {
133       void * propData = new0 byte[type.structSize];
134       ((void (*)(void *, void *))(void *)prop.Get)(src, propData);
135       ((void (*)(void *, void *))(void *)prop.Set)(dest, propData);
136       delete propData;
137    }
138    else if(type.type == normalClass || type.type == noHeadClass)
139    {
140       // TOCHECK: Why was there a return here?
141       /*return */((void (*)(void *, void *))(void *)prop.Set)(dest, ((void*(*)(void *))(void *)prop.Get)(src));
142    }
143    // TOFIX: How to swiftly handle classes with base data type?
144    else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
145    {
146       ((void (*)(void *, double))(void *)prop.Set)(dest, ((double(*)(void *))(void *)prop.Get)(src));
147    }
148    else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
149    {
150       ((void (*)(void *, float))(void *)prop.Set)(dest, ((float(*)(void *))(void *)prop.Get)(src));
151    }
152    else if(type.typeSize == sizeof(int64))// || !strcmp(type.dataTypeString, "int64") || !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
153    {
154       ((void (*)(void *, int64))(void *)prop.Set)(dest, ((int64(*)(void *))(void *)prop.Get)(src));
155    }
156    else if(type.typeSize == sizeof(int))// || !strcmp(type.dataTypeString, "int") || !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
157    {
158       ((void (*)(void *, int))(void *)prop.Set)(dest, ((int(*)(void *))(void *)prop.Get)(src));
159    }
160    else if(type.typeSize == sizeof(short int)) // || !strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||  !strcmp(type.dataTypeString, "int16"))
161    {
162       ((void (*)(void *, short))(void *)prop.Set)(dest, ((short(*)(void *))(void *)prop.Get)(src));
163    }
164    else if(type.typeSize == sizeof(byte))// || !strcmp(type.dataTypeString, "char") || !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
165    {
166       ((void (*)(void *, byte))(void *)prop.Set)(dest, ((byte(*)(void *))(void *)prop.Get)(src));
167    }
168    else
169    {
170       ((void (*)(void *, int))(void *)prop.Set)(dest, ((int (*)(void *))(void *)prop.Get)(src));
171    }
172 }
173
174 void GetProperty(Property prop, Instance object, DataValue value)
175 {
176    if(object)
177    {
178       Class type = prop.dataTypeClass;
179       if(!type)
180       {
181          type = prop.dataTypeClass = eSystem_FindClass(prop._class.module, prop.dataTypeString);
182 #ifdef _DEBUG
183          if(prop._class.module.application == __thisModule &&
184             prop.dataTypeClass.module.application == ((Designer)GetActiveDesigner()).codeEditor.privateModule)
185             printf($"Warning");
186 #endif
187       }
188
189       if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
190       {
191          value.p = ((void*(*)(void *))(void *)prop.Get)(object);
192       }
193       // TOFIX: How to swiftly handle classes with base data type?
194       else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
195       {
196          value.d = ((double(*)(void *))(void *)prop.Get)(object);
197       }
198       else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
199       {
200          value.f = ((float(*)(void *))(void *)prop.Get)(object);
201       }
202       else if(type.typeSize == sizeof(int64))// || !strcmp(type.dataTypeString, "int64") || !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
203       {
204          value.i64 = ((int64(*)(void *))(void *)prop.Get)(object);
205       }
206       else if(type.typeSize == sizeof(int))// || !strcmp(type.dataTypeString, "int") || !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
207       {
208          value.i = ((int(*)(void *))(void *)prop.Get)(object);
209       }
210       else if(type.typeSize == sizeof(short int)) // || !strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||  !strcmp(type.dataTypeString, "int16"))
211       {
212          value.s = ((short(*)(void *))(void *)prop.Get)(object);
213       }
214       else if(type.typeSize == sizeof(byte))// || !strcmp(type.dataTypeString, "char") || !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
215       {
216          value.uc = ((byte(*)(void *))(void *)prop.Get)(object);
217       }
218       else
219       {
220          value.i = ((int (*)(void *))(void *)prop.Get)(object);
221       }
222    }
223    else
224       value.i64 = 0;
225 }
226
227 void SetProperty(Property prop, Instance object, DataValue value)
228 {
229    if(object)
230    {
231       Class type = prop.dataTypeClass;
232       if(!type)
233          type = prop.dataTypeClass = eSystem_FindClass(prop._class.module, prop.dataTypeString);
234
235       if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
236       {
237          ((void (*)(void *, void *))(void *)prop.Set)(object, value);
238       }
239       // TOFIX: How to swiftly handle classes with base data type?
240       else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
241       {
242          ((void (*)(void *, double))(void *)prop.Set)(object, value.d);
243       }
244       else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
245       {
246          ((void (*)(void *, float))(void *)prop.Set)(object, value.f);
247       }
248       else if(type.typeSize == sizeof(int64))// || !strcmp(type.dataTypeString, "int64") || !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
249       {
250          ((void (*)(void *, int64))(void *)prop.Set)(object, value.i64);
251       }
252       else if(type.typeSize == sizeof(int))// || !strcmp(type.dataTypeString, "int") || !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
253       {
254          ((void (*)(void *, int))(void *)prop.Set)(object, value.i);
255       }
256       else if(type.typeSize == sizeof(short int)) // || !strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||  !strcmp(type.dataTypeString, "int16"))
257       {
258          ((void (*)(void *, short))(void *)prop.Set)(object, value.s);
259       }
260       else if(type.typeSize == sizeof(byte))// || !strcmp(type.dataTypeString, "char") || !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
261       {
262          ((void (*)(void *, byte))(void *)prop.Set)(object, value.uc);
263       }
264       else
265       {
266          ((void (*)(void *, int))(void *)prop.Set)(object, value.i);
267       }
268    }
269 }
270
271 class Sheet : Window
272 {
273    text = $"Sheet";
274    borderStyle = sizable;
275    hasClose = true;
276    //tabCycle = true;
277    size.w = 300;
278    anchor = { left = 0, top = 0, bottom = 0 };
279    background = formColor;
280
281    Sheet()
282    {
283       dropBox.AddField(dropField);
284       properties.AddField(propertyName);
285       properties.AddField(propertyValue);
286       methods.AddField(methodName);
287    }
288
289    ~Sheet()
290    {
291       categories.Free(null);
292    }
293
294    DropBox dropBox
295    {
296       this,
297       anchor = { left = 0, top = 0, right = 0 };
298
299       bool NotifySelect(DropBox control, DataRow row, Modifiers keyFlags)
300       {
301          ObjectInfo selected = (ObjectInfo)(row ? row.tag : null);
302          ToolBox toolBox = ((IDEWorkSpace)parent).toolBox;
303
304          if(codeEditor && selected)
305             codeEditor.SelectObject(selected);
306
307          // TODO: Get containing class of object
308          toolBox.selectedClass = selected ? selected.oClass : null;
309
310          object = selected ? selected.instance : null;
311
312          methods.Clear();
313          ListProperties(true);
314
315          {
316             DataRow row;
317             row = methods.currentRow;
318             if(row)
319                strcpy(selectedMethod, ((CodeObject)row.GetData(methodName)).name);
320          }
321
322
323          if(selected && selected.instance && codeEditor)
324          {
325             Class _class;
326             int c = 0;
327             int rowHeight = methods.rowHeight;
328
329             propertyValue.userData = (void *)selected.instance;
330
331             // Fill up the methods
332             {
333                CodeObjectType type;
334                {
335                   for(_class = selected.instance._class; _class && _class.type != systemClass; _class = _class.base)
336                   {
337                      int id;
338                      for(id = _class.base ? _class.base.vTblSize : 0; id<_class.vTblSize; id++)
339                      {
340                         Method method;
341                         for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
342                         {
343                            if(method.type == virtualMethod && method.vid == id)
344                            {
345                               if(!method.dataType)
346                                  method.dataType = ProcessTypeString(method.dataTypeString, false);
347
348                               type = method.dataType.thisClass ? typeEvent : typeMethod;
349                               {
350                                  DataRow row = methods.AddRow();
351                                  CodeObject codeObject
352                                  {
353                                     eventsUp = (selected.oClass == selected) ? false : true;
354                                     type = type;
355                                     method = method;
356                                     name = method.name;
357                                     overriden = codeEditor.FindMethod(method.name, &codeObject.function, null);
358                                  };
359                                  if(!codeObject.overriden || codeObject.overriden == 2)
360                                     codeEditor.FindCompatibleMethods(method, codeObject.compatible);
361
362                                  row.SetData(methodName, codeObject);
363
364                                  if(!strcmp(method.name, selectedMethod))
365                                     methods.currentRow = row;
366                               }
367                            }
368                         }
369                      }
370                   }
371                }
372             }
373             methods.Sort(methodName, 1);
374             {
375                DataRow row;
376                for(row = methods.firstRow; row; row = row.next)
377                {
378                   CodeObject codeObject = row.GetData(methodName);
379                   CreateButtons(codeObject, row.index * rowHeight, rowHeight, row);
380                }
381             }
382          }
383          return true;
384       }
385    };
386    DataField dropField { dataType = class(CodeObject) };
387
388    Button propBtn
389    {
390       this, inactive = true, text = $"Properties", bevelOver = true, isRadio = true;
391       size.h = 20;
392       anchor = { left = 0, bottom = 3, right = 0.5 };
393       bitmap = null;
394
395       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
396       {
397          text = $"Properties";
398          button.font = { $"Tahoma", 8.25f, bold = true };
399          methBtn.font = null;
400
401          methods.visible = false;
402          methBtn.Activate();      // Ensure proper cycling (until tab order?)
403          properties.visible = true;
404
405          alphabetical.disabled = false;
406          categorized.disabled = false;
407
408          properties.Activate();
409
410          // ((IDEWorkSpace)master).SheetSelected(Properties);
411          return true;
412       }
413    };
414
415    Button methBtn
416    {
417       this, inactive = true, bevelOver = true;
418       text = $"Methods";
419       isRadio = true;
420       bitmap = null;
421       size.h = 20;
422       anchor = { bottom = 3, left = 0.5, right = 0 };
423
424       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
425       {
426          text = $"Methods";
427          button.font = { $"Tahoma", 8.25f, bold = true };
428          propBtn.font = null;
429
430          properties.visible = false;
431          methBtn.Activate();      // Ensure proper cycling (until tab order?)
432          methods.visible = true;
433
434          alphabetical.disabled = true;
435          categorized.disabled = true;
436
437          methods.Activate();
438                        
439          // ((IDEWorkSpace)master).SheetSelected(Methods);
440          return true;
441       }
442    };
443
444    // Menu
445    menu = Menu { };
446    MenuPlacement editMenu { menu, text = $"Edit" };
447    Menu viewMenu { menu, text = $"View" };
448
449    // Property Sheet
450    ListBox properties
451    {
452       this, anchor = { left = 0, right = 0, top = 50, bottom = 25 };
453       hasVertScroll = true, alwaysEdit = true, collapseControl = true, resizable = true;
454       background = viewsBackground;
455       foreground = viewsText;
456
457       bool NotifySelect(ListBox control, DataRow row, Modifiers keyFlags)
458       {
459          /*
460          if(row)
461          {
462             strcpy(selectedProp, (char *)row.GetData(propertyName));
463             selectedScroll = properties.scroll.y;
464             selectedScroll -= row.index * properties.rowHeight;
465          }
466          else
467             selectedProp[0] = 0;
468          if(row)
469          {
470             prop = ((PropertyInfo)row.GetData(propertyValue)).prop;
471          }
472          else
473             prop = null;
474          */
475          return true;
476       }
477    };
478
479    DataField propertyName { dataType = class(char *), width = 130 };
480    DataField propertyValue { dataType = class(PropertyInfo), width = 0, editable = true };
481
482    // Method Sheet
483    ListBox methods
484    {
485       this, anchor = { left = 0, right = 0, top = 50, bottom = 25 };
486       hasVertScroll = true;
487       background = viewsBackground;
488       foreground = viewsText;
489       // alwaysEdit = true;
490       // resizable = true;
491
492       bool NotifyDoubleClick(ListBox control, int x, int y, Modifiers mods)
493       {
494          CodeObject object = control.GetData(methodName);
495          if(object)
496             codeEditor.AddMethod(object.method);   
497          return false;
498       }
499
500       bool NotifyRightClick(ListBox control, int x, int y, Modifiers mods)
501       {
502          CodeObject object = control.GetData(methodName);
503          Menu menu { };
504          PopupMenu popupMenu;
505          MenuItem item;
506          if(object.overriden == 0)
507          {
508             MenuItem { menu, $"Override", o, enter, bold = true, NotifySelect = OverrideMethodSelected };
509             if(object.compatible.count)
510             {
511                Menu attachMenu { menu, $"Attach", a };
512                OldLink compatible;
513                for(compatible = object.compatible.first; compatible; compatible = compatible.next)
514                {
515                   ClassFunction function = compatible.data;
516                   MenuItem { attachMenu, function.declarator.symbol.string, id = (int64)function, NotifySelect = AttachMethodSelected };
517                }
518             }
519          }
520          else if(object.overriden == 1)
521          {
522             MenuItem { menu, $"Go to", g, enter, bold = true, NotifySelect = GotoMethodSelected };
523             MenuItem { menu, $"Detach", d, d, NotifySelect = DetachMethodSelected };
524             MenuItem { menu, $"Delete", del, del, NotifySelect = DeleteMethodSelected };
525          }
526          else if(object.overriden == 2)
527          {
528             MenuItem { menu, $"Go to", g, enter, bold = true, NotifySelect = GotoMethodSelected };
529             MenuItem { menu, $"Detach", d, d, NotifySelect = DetachMethodSelected };
530             if(object.compatible.count > 1)
531             {
532                Menu attachMenu { menu, $"Reattach", r };
533                OldLink compatible;
534                for(compatible = object.compatible.first; compatible; compatible = compatible.next)
535                {
536                   ClassFunction function = compatible.data;
537                   if(function != object.function)
538                   {
539                      MenuItem { attachMenu, function.declarator.symbol.string, id = (int64)function, NotifySelect = ReattachMethodSelected };
540                   }
541                }
542             }
543          }
544
545          attachMethod = object.method;
546          popupMenu = PopupMenu { menu = menu, master = this, position =
547             {
548                x + control.absPosition.x - app.desktop.absPosition.x,
549                y + control.absPosition.y - app.desktop.absPosition.y
550             } };
551          popupMenu.Create();
552          // popupMenu.Capture();
553          return false;
554       }
555
556       bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
557       {
558          if(row)
559          {
560             CodeObject object = row.GetData(methodName);
561             switch((SmartKey)key)
562             {
563                case enter:
564                   if(!object.overriden)
565                      listBox.NotifyDoubleClick(this, listBox, 0,0, 0);
566                   else
567                      codeEditor.GoToMethod(object.method.name);
568                   break;
569                case del:
570                   if(object.deleteBtn)
571                      object.deleteBtn.NotifyClicked(this, object.deleteBtn, 0,0,0);
572                   else if(object.detachBtn)
573                      object.detachBtn.NotifyClicked(this, object.detachBtn, 0,0,0);
574                   break;
575                case a:
576                   if(object.attachBtn)
577                      object.attachBtn.NotifyPushed(this, object.attachBtn, 0,0,0);
578                   break;
579                case d:
580                   if(object.detachBtn)
581                      object.detachBtn.NotifyClicked(this, object.detachBtn, 0,0,0);
582                   break;
583             }
584          }
585          return true;
586       }
587    };
588
589    DataField methodName { dataType = class(CodeObject) };
590
591 #ifdef SHOW_METHODS
592    methBtn.font = { $"Tahoma", 8.25, bold = true };
593    methBtn.checked = true;
594    properties.visible = false;
595    text = $"Methods";
596 #else
597    propBtn.font = { $"Tahoma", 8.25f, bold = true };
598    propBtn.checked = true;
599    methods.visible = false;
600    text = $"Properties";
601 #endif
602
603    Button alphabetical
604    {
605       this, bevelOver = true, inactive = true, position = { 25, 25 }, size = { 24, 24 };
606       bitmap = { "<:ecere>elements/orderAscending.png" };
607       // isRadio = true;
608
609       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
610       {
611          if(!alphabetical.checked)
612          {
613             alphabetical.checked = true;
614             categorized.checked = false;
615
616             ListProperties(true);
617          }
618          return true;
619       }
620    };
621
622    Button categorized
623    {
624       this, bevelOver = true, checked = true, inactive = true, position = { 0, 25 }, size = { 24, 24 };
625       bitmap = { "<:ecere>elements/orderCategorized.png" };
626       // isRadio = true;
627       
628       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
629       {
630          if(!categorized.checked)
631          {
632             categorized.checked = true;
633             alphabetical.checked = false;
634
635             ListProperties(true);
636          }
637          return true;
638       }
639    };
640
641    property CodeEditor codeEditor
642    {
643       set
644       {
645          if(codeEditor != value)
646          {
647             codeEditor = value;
648             // Refill it up
649             dropBox.Clear();
650             dropField.userData = codeEditor;
651             methodName.userData = codeEditor;
652             
653             if(codeEditor)
654                codeEditor.EnumerateObjects(this);
655           }
656       }
657       get
658       {
659          return codeEditor;
660       }
661    }
662
663    property SheetType sheetSelected
664    {
665       set
666       {
667          if(methBtn.checked != (value == SheetType::methods))
668             ToggleSheet();
669       }
670       get
671       {
672          return methBtn.checked ? methods : properties;
673       }
674    }
675
676    bool OnClose(bool parentClosing)
677    {
678       if(!parentClosing)
679       {
680          visible = false;
681          return false;
682       }
683       return true;
684    }
685
686    bool OnKeyDown(Key key, unichar ch)
687    {
688       if(key == shiftTab)
689          dropBox.Activate();
690       else if(key == tab)
691          ToggleSheet();
692       else if(key == escape)
693       {
694          Window activeClient = ide.activeClient;
695          if(activeClient) 
696             activeClient.Activate();
697          else 
698             ide.RepositionWindows(true);
699       }
700       return true;
701    }
702
703    bool OnKeyHit(Key key, unichar ch)
704    {
705       return properties.OnKeyHit(key, ch);
706    }
707
708    bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
709    {
710       if(active && codeEditor)
711          codeEditor.EnsureUpToDate();
712       return true;
713    }
714
715    void ListProperties(bool clear)
716    {
717       DataRow row = dropBox.currentRow;
718       ObjectInfo selected = row ? (ObjectInfo)row.tag : null;
719       
720       //int scroll = 0;
721       bool categorized = this.categorized.checked;
722       bool currentRow = false;
723       char selectedProp[1024];
724
725       if(clear)
726       {
727          Category cat;
728          DataRow row = properties.currentRow;
729          if(row)
730          {
731             DataRow propRow = row;
732             char * propName;
733             while(propRow && propRow.parent && !propRow.parent.isHeader)
734                propRow = row.parent;
735             
736             propName = propRow.GetData(propertyName);
737             strcpy(this.selectedProp, propName);
738             selectedScroll = properties.scroll.y;
739             selectedScroll -= propRow.index * properties.rowHeight;
740          }
741          currentRow = this.selectedProp[0] ? true : false;
742
743          for(cat = categories.first; cat; cat = cat.next)
744          {
745             cat.collapsed = cat.row.collapsed;
746             cat.row = null;
747          }
748
749          // Preserve selected property (PropertySheetSelect will null it)
750          strcpy(selectedProp, this.selectedProp);
751          properties.Clear();
752          strcpy(this.selectedProp, selectedProp);
753       }
754       if(selected && selected.instance && codeEditor)
755       {
756          Instance test = eInstance_New(selected.instance._class);
757          Class _class = null;
758          incref test;
759
760          // Put it in the same desktop window...
761          if(selected.classDefinition)
762             codeEditor.designer.PrepareTestObject(test);
763
764          // Fill up the properties
765          while(_class != selected.instance._class)
766          {
767             BitMember bitMember = null;
768             Class lastClass = _class;
769             Property propIt;
770
771             for(_class = selected.instance._class; _class.base != lastClass && _class.base.type != systemClass && _class.inheritanceAccess != privateAccess; _class = _class.base);
772
773             for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
774             {
775                if(propIt.isProperty)
776                {
777                   Property prop = eClass_FindProperty(selected.instance._class, propIt.name, GetPrivateModule());
778                   
779                   if(prop && prop.Set && prop.Get && prop.compiled && (!prop.category || strcmpi(prop.category, $"Deprecated")))
780                   {
781                      bool disabled = Code_IsPropertyDisabled(selected, prop.name);
782                      bool bold;
783                      Class dataType = prop.dataTypeClass;
784                      if(!dataType)
785                         dataType = prop.dataTypeClass = eSystem_FindClass(codeEditor.privateModule, prop.dataTypeString);
786
787                      if(!strcmp(_class.name, "DesignerBase"))
788                         disabled = true;
789                      bold = !disabled && Code_IsPropertyModified(test, selected, prop);                           
790
791                      if(dataType)
792                      {
793                         DataRow row;
794                         PropertyInfo info { prop, disabled, bold ? codeEditor.boldFont : codeEditor.normalFont };
795                         char * name = prop.category ? prop.category : $"Misc";
796                         Category category = categories.FindName(name, false);
797
798                         // Hide properties like this for now..
799                         if(name && !strcmp(name, "Private")) 
800                         {
801                            delete info;
802                            continue;
803                         }
804
805                         if(!category)
806                         {
807                            category = Category { name = name };
808                            categories.AddName(category);
809                         }
810                         if(!category.row && categorized)
811                         {
812                            PropertyInfo catInfo { null, false, null, name };
813                            category.row = properties.AddRow();
814                            category.row.SetData(propertyName, name );
815                            category.row.SetData(propertyValue, catInfo);
816                            category.row.isHeader = true;
817                            category.row.collapsed = category.collapsed;
818                         }
819
820                         if(clear)
821                         {
822                            row = categorized ? category.row.FindRow((int64)prop) : properties.FindRow((int64)prop);
823                            if(!row)
824                               row = categorized ? category.row.AddRow() : properties.AddRow();
825                            row.tag = (int64)prop;
826                         }
827                         else
828                            row = categorized ? category.row.FindRow((int64)prop) : properties.FindRow((int64)prop);
829
830                         row.SetData(propertyName, prop.name);
831                         row.SetData(propertyValue, info);
832
833                         if(clear && !strcmp(prop.name, this.selectedProp))
834                            properties.currentRow = row;
835
836                         if(!dataType.noExpansion && (dataType.type == structClass || dataType.type == normalClass || dataType.type == noHeadClass || dataType.type == bitClass))
837                         {
838                            DataMember member;
839                            
840                            if(clear)
841                               row.collapsed = true;
842
843                            for(member = dataType.membersAndProperties.first; member; member = member.next)
844                            {
845                               if(member.isProperty)
846                               {
847                                  Property subProp = (Property)member;
848                                  if(!subProp.conversion && subProp.Get && subProp.Set)
849                                  {
850                                     DataRow subRow;
851                                     PropertyInfo info { prop, disabled, bold ? codeEditor.boldFont : codeEditor.normalFont, null, null, subProp };
852
853                                     if(clear)
854                                     {
855                                        subRow = row.AddRow();
856                                        subRow.tag = (int64)subProp;
857                                     }
858                                     else
859                                        subRow = row.FindRow((int64)subProp);
860                                     
861                                     subRow.SetData(propertyName, subProp.name);
862                                     subRow.SetData(propertyValue, info);
863                                  }
864                               }
865                               else if(member.name)
866                               {
867                                  DataRow subRow;
868                                  PropertyInfo info { prop, disabled, bold ? codeEditor.boldFont : codeEditor.normalFont, null, member, null };
869                                  if(clear)
870                                  {
871                                     subRow = row.AddRow();
872                                     subRow.tag = (int64)member;
873                                  }
874                                  else
875                                     subRow = row.FindRow((int64)member);
876
877                                  subRow.SetData(propertyName, member.name);
878                                  subRow.SetData(propertyValue, info);
879                               }
880                               else
881                               {
882                                  DataMember subMember;
883                                  for(subMember = member.members.first; subMember; subMember = subMember.next)
884                                  {
885                                     DataRow subRow;
886                                     PropertyInfo info { prop, disabled, bold ? codeEditor.boldFont : codeEditor.normalFont, null, subMember, null, member.offset };
887                                     if(clear)
888                                     {
889                                        subRow = row.AddRow();
890                                        subRow.tag = (int64)subMember;
891                                     }
892                                     else
893                                        subRow = row.FindRow((int64)subMember);
894
895                                     subRow.SetData(propertyName, subMember.name);
896                                     subRow.SetData(propertyValue, info);
897                                  }
898                               }
899                            }
900                         }
901                      }
902                   }
903                }
904             }
905          }
906          delete test;
907          // Sort alphabetically for now...
908          if(clear)
909          {
910             // properties.Sort(null, 1);
911             properties.Sort(propertyValue, 1);
912             if(!properties.currentRow)
913             {
914                bool found = false;
915                
916                for(_class = selected.instance._class; _class; _class = _class.base)
917                {
918                   Property prop;
919                   for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
920                   {
921                      if(prop.isProperty && prop.Set && prop.Get && prop.compiled)
922                      {
923                         if(_class.defaultProperty && !strcmp(prop.name, _class.defaultProperty))
924                         {
925                            DataRow row;
926                            char * name = prop.category ? prop.category : $"Misc";
927                            Category category = categories.FindName(name, false);
928                            row = category ? (categorized ? category.row.FindRow((int64)prop) : properties.FindRow((int64)prop)) : null;
929                            properties.currentRow = row;
930                            found = true;
931                            break;                                                                                                                              
932                         }
933                      }
934                   }
935                   if(found) break;
936                }
937                if(!found)
938                   properties.currentRow = properties.firstRow;
939             }
940
941             if(currentRow)
942             {
943                DataRow row = properties.currentRow;
944                properties.scroll.y = selectedScroll + row.index * properties.rowHeight;
945             }
946          }
947       }
948    }
949
950    void AddObject(ObjectInfo object, char * name, CodeObjectType type, bool select)
951    {
952       DataRow after = null;
953       DataRow row;
954       CodeObject codeObject;
955       char * bitmap = null;
956       bool foundClass = false;
957
958       for(row = dropBox.firstRow; row; row = row.next)
959       {
960          CodeObject codeObject = row.GetData(null);
961          if(codeObject.object.oClass == object.oClass)
962             foundClass = true;
963          else if(foundClass)
964             break;
965          after = row;
966       }
967
968       row = (DataRow)dropBox.AddRowAfter(after);
969       
970       row.tag = (int64)object;
971
972       codeObject = 
973       {
974          object = object;
975          name = name;
976          type = type;
977          indent = (type == typeClass) ? 0 : 1;
978       };
979
980       if(type != typeClass)
981          bitmap = (char *)eClass_GetProperty(object.instance._class, "icon");
982       if(bitmap)
983       {
984          codeObject.bitmap = { bitmap };
985          AddResource(codeObject.bitmap);
986       }
987       
988       row.SetData(null, codeObject);
989
990       if(select)
991       {
992          this.object = object ? object.instance : null;
993          propertyValue.userData = object ? (void *)object.instance : null;
994          dropBox.SelectRow(row);
995       }
996    }
997
998    void DeleteObject(ObjectInfo object)
999    {
1000       DataRow row = dropBox.FindRow((int64)object);
1001       if(row)
1002       {
1003          CodeObject codeObject = row.GetData(null);
1004      
1005          if(codeObject.bitmap)
1006             RemoveResource(codeObject.bitmap);
1007          dropBox.DeleteRow(row);
1008       }
1009    }
1010
1011    void SelectObject(ObjectInfo object)
1012    {
1013       if(this)
1014       {
1015          DataRow row = dropBox.FindRow((int64)object);
1016          this.object = object ? object.instance : null;
1017          propertyValue.userData = object ? (void *)object.instance : null;
1018          dropBox.SelectRow(row);
1019       }
1020    }
1021
1022    void RenameObject(ObjectInfo object, char * name)
1023    {
1024       DataRow row = dropBox.FindRow((int64)object);
1025       CodeObject codeObject = row.GetData(null);
1026       // Isn't this useless? Shouldn't it be after?
1027       codeObject.name = name;
1028       // row.SetData(null, codeObject);  // Is this necessary?
1029    }
1030
1031    void DataBox::EditSetData(any_object setValue, bool closingDropDown)
1032    {
1033       ((Sheet)master.master).SetData(setValue, this);
1034    }
1035
1036    void SetData(any_object setValue, DataBox dataBox)
1037    {
1038       //PropertyInfo propertyPtr = row.GetData(null);
1039       PropertyInfo propertyPtr = properties.GetData(null);
1040       Property prop = propertyPtr ? propertyPtr.prop : null;
1041       Instance object = this.object;
1042       if(prop)
1043       {   
1044          Class dataType = prop.dataTypeClass;
1045          if(!dataType)
1046             dataType = prop.dataTypeClass = eSystem_FindClass(codeEditor.privateModule, prop.dataTypeString);
1047          if(propertyPtr.subMember)
1048          {
1049             DataMember member = propertyPtr.subMember;
1050             Class subDataType = member.dataTypeClass;
1051             if(!member.dataTypeClass)
1052                subDataType = member.dataTypeClass = eSystem_FindClass(codeEditor.privateModule, member.dataTypeString);
1053             if(subDataType)
1054             {
1055                void * data = null;
1056                if(!subDataType.dataType)
1057                   subDataType.dataType = ProcessTypeString(subDataType.dataTypeString, false);
1058
1059                if(dataType.type == structClass)
1060                {
1061                   data = new0 byte[dataType.structSize];
1062                   ((void (*)(void *, void *))(void *)prop.Get)(object, data);
1063                   // CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, &setValue, subDataType.size);
1064                   CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, (void *)setValue, subDataType.dataType.size);
1065                   ((void (*)(void *, void *))(void *)prop.Set)(object, data);
1066                }
1067                else if(dataType.type == normalClass || dataType.type == noHeadClass)
1068                {
1069                }
1070                else
1071                {
1072                   if(dataType.type == bitClass)
1073                   {
1074                      BitMember bitMember = (BitMember) member;
1075                      if(subDataType)
1076                      {
1077                         DataValue value = { 0 };
1078                         value.ui = ((uint (*)(void *))(void *)prop.Get)(object);
1079                         value.ui &= ~ (uint)bitMember.mask;
1080                         value.ui |= *(uint32 *)setValue << bitMember.pos;
1081                         ((void (*)(void *, uint))(void *)prop.Set)(object, value.ui);
1082                      }
1083                   }
1084                   else
1085                   {
1086                      // TODO: What does this handle?
1087                      data = dataType.typeSize ? new0 byte[dataType.typeSize] : null;
1088                      ((void (*)(void *, void *))(void *)prop.Get)(object, data);
1089                      // CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, &setValue, subDataType.typeSize);
1090                      CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, (void *)setValue, subDataType.dataType.size);
1091                      // TODO: Support non 32 bit datatypes here
1092                      ((void (*)(void *, void *))(void *)prop.Set)(object, data);
1093                   }
1094                }
1095
1096                if(data) ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType,&data);
1097                delete data;
1098             }
1099          }
1100          else if(propertyPtr.subProperty)
1101          {
1102             Property subProperty = propertyPtr.subProperty;
1103             Class subDataType = subProperty.dataTypeClass;
1104             if(!subDataType)
1105                subDataType = subProperty.dataTypeClass = eSystem_FindClass(codeEditor.privateModule, subProperty.dataTypeString);
1106             if(subDataType)
1107             {
1108                void * data = null;
1109
1110                if(dataType.type == structClass)
1111                {
1112                   data = new0 byte[dataType.structSize];
1113                   ((void (*)(void *, void *))(void *)prop.Get)(object, data);
1114                   ((void (*)(void *, uint))(void *)subProperty.Set)(data, *(uint32 *)setValue);
1115                   ((void (*)(void *, void *))(void *)prop.Set)(object, data);
1116                }
1117                else if(dataType.type == normalClass || dataType.type == noHeadClass)
1118                {
1119                   Instance current = (Instance)((void *(*)(void *))(void *)prop.Get)(object);
1120                   Instance propObject = eInstance_New(dataType);
1121                   CopyInstanceData(dataType, propObject, current);
1122                   ((void (*)(void *, uint))(void *)subProperty.Set)(propObject, (uint32)setValue);
1123                   ((void (*)(void *, void *))(void *)prop.Set)(object, propObject);
1124                }
1125                else
1126                {
1127                   data = dataType.typeSize ? new0 byte[dataType.typeSize] : null;
1128                   ((void (*)(void *, void *))(void *)prop.Get)(object, data);
1129                   ((void (*)(void *, uint))(void *)subProperty.Set)(data, (uint32)setValue);
1130                   // TODO: Support not 32 bit data types here
1131                   ((void (*)(void *, void *))(void *)prop.Set)(object, data);
1132                }
1133
1134                if(data) ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType,&data);
1135                delete data;
1136             }
1137          }
1138          else
1139          {
1140             SetPropValue(prop, object, (uint32)setValue);
1141          }      
1142          Code_FixProperty(propertyPtr.prop, object);
1143
1144          properties.Update(null);
1145          dropBox.Update(null);
1146          codeEditor.designer.Update(null);
1147          codeEditor.Update(null);   // patch for redraw bug if on top
1148
1149          ListProperties(false);
1150
1151          dataBox.editor.font = { propertyPtr.font.faceName, propertyPtr.font.size, propertyPtr.font.bold };
1152          codeEditor.ModifyCode();
1153       }
1154    }
1155
1156    bool SaveEdit(PropertyInfo propertyPtr, Instance object)
1157    {
1158       codeEditor.designer.Update(null);
1159       codeEditor.Update(null);   // patch for redraw bug if on top
1160       properties.Update(null);
1161       dropBox.Update(null);
1162
1163       Code_FixProperty(propertyPtr.prop, object);
1164       ListProperties(false);
1165
1166       codeEditor.ModifyCode();
1167       return true;
1168    }
1169
1170    void ToggleSheet()
1171    {
1172       if(!propBtn.checked)
1173       {
1174          propBtn.checked = true;
1175          propBtn.NotifyClicked(this, propBtn, 0,0,0);
1176       }
1177       else
1178       {
1179          methBtn.checked = true;
1180          methBtn.NotifyClicked(this, methBtn, 0,0,0);
1181       }
1182    }
1183
1184    bool AttachMethodSelected(MenuItem selection, Modifiers mods)
1185    {
1186       ClassFunction function = (ClassFunction)selection.id;
1187       codeEditor.AttachMethod(attachMethod, function);
1188       return true;
1189    }
1190
1191    bool ReattachMethodSelected(MenuItem selection, Modifiers mods)
1192    {
1193       ClassFunction function = (ClassFunction)selection.id;
1194       CodeObject object = methods.GetData(methodName);
1195       codeEditor.ReAttachMethod(attachMethod, function);
1196       return true;
1197    }
1198
1199    bool OverrideMethodSelected(MenuItem selection, Modifiers mods)
1200    {
1201       ClassFunction function = (ClassFunction)selection.id;
1202       CodeObject object = methods.GetData(methodName);
1203       if(object)
1204          codeEditor.AddMethod(object.method);   
1205       return true;
1206    }
1207
1208    bool GotoMethodSelected(MenuItem selection, Modifiers mods)
1209    {
1210       ClassFunction function = (ClassFunction)selection.id;
1211       CodeObject object = methods.GetData(methodName);
1212       if(object)
1213          codeEditor.GoToMethod(object.method.name);
1214       return true;
1215    }
1216
1217    bool DetachMethodSelected(MenuItem selection, Modifiers mods)
1218    {
1219       ClassFunction function = (ClassFunction)selection.id;
1220       CodeObject object = methods.GetData(methodName);
1221       if(object)
1222          codeEditor.DetachMethod(object.method, object.function, object.overriden);
1223       return true;
1224    }
1225
1226    bool DeleteMethodSelected(MenuItem selection, Modifiers mods)
1227    {
1228       ClassFunction function = (ClassFunction)selection.id;
1229       CodeObject object = methods.GetData(methodName);
1230       if(object)
1231          object.deleteBtn.NotifyClicked(this, object.deleteBtn, 0,0,0);
1232       return true;
1233    }
1234
1235    bool AddMethodClicked(Button button, int x, int y, Modifiers mods)
1236    {
1237       DataRow row = (DataRow)button.id;
1238       CodeObject object = row.GetData(methodName);
1239       codeEditor.AddMethod(object.method);   
1240       return true;
1241    }
1242
1243    void CreateButtons(CodeObject codeObject, int y, int h, DataRow row)
1244    {
1245       BitmapResource bitmap;
1246       
1247       if(codeObject.overriden)
1248       {
1249          if(codeObject.overriden == 1)
1250          {
1251             codeObject.deleteBtn = Button
1252             {
1253                methods, master = this,
1254                inactive = true,
1255                bitmap = { ":actions/delete.png", alphaBlend = true },
1256                anchor = { right = 16, top = y },
1257                size = { 16, h },
1258                id = (int64)row;
1259
1260                bool NotifyClicked(Button button, int x, int y, Modifiers mods)
1261                {
1262                   CodeObject codeObject = ((DataRow)button.id).GetData(null);
1263                   bool confirmation = !Code_IsFunctionEmpty(codeObject.function, codeObject.method, codeEditor.selected);
1264
1265                   if(confirmation)
1266                   {
1267                      char title[1024];
1268                      sprintf(title, $"Delete %s", codeObject.name);
1269                      if(MessageBox
1270                         {
1271                            master = parent, type = okCancel, text = title, 
1272                            contents = $"Method still contains code. Are you sure you want to delete it?"
1273                         }.Modal() == ok)
1274                         confirmation = false;
1275                   }
1276
1277                   if(!confirmation && codeObject.function.attached.count)
1278                   {
1279                      char title[1024];
1280                      sprintf(title, $"Delete %s", codeObject.name);
1281                      confirmation = true;
1282                      if(MessageBox
1283                         {
1284                            master = parent, type = okCancel, text = title,
1285                            contents = $"Other methods are still attached to this method. Are you sure you want to delete it?"
1286                         }.Modal() == ok)
1287                         confirmation = false;
1288                   }
1289
1290                   if(!confirmation)
1291                   {
1292                      codeEditor.DeleteMethod(codeObject.function);
1293                   }
1294                   return false;
1295                }
1296             };
1297             incref codeObject.deleteBtn;
1298             codeObject.deleteBtn.Create();
1299          }
1300
1301          if(codeObject.overriden == 2 || !codeObject.function.attached.count)
1302          {
1303             codeObject.detachBtn = Button 
1304             {
1305                methods,
1306                master = methods.master,
1307                inactive = true,
1308                bitmap = { ":actions/detach.png" },
1309                anchor = { right = 0, top = y },
1310                size = { 16, h },
1311                id = (int64)row;
1312
1313                bool NotifyClicked(Button button, int x, int y, Modifiers mods)
1314                {
1315                   DataRow row = (DataRow)button.id;
1316                   CodeObject object = row.GetData(methodName);
1317
1318                   codeEditor.DetachMethod(object.method, object.function, object.overriden);
1319                   return true;
1320                }
1321             };
1322             incref codeObject.detachBtn;
1323             codeObject.detachBtn.Create();
1324          }
1325       }
1326       else
1327       {
1328          if(codeObject.compatible.count)
1329          {
1330             codeObject.attachBtn = Button
1331             {
1332                parent = methods, master = methods.master,
1333                inactive = true,
1334                bitmap = { ":actions/attach.png" },
1335                anchor = { right = 0, top = y },
1336                size = { 16, h },
1337                id = (int64)row;
1338
1339                bool NotifyPushed(Button button, int x, int y, Modifiers mods)
1340                {
1341                   // Create menu
1342                   DataRow row = (DataRow)button.id;
1343                   CodeObject object = row.GetData(methodName);
1344                   OldLink compatible;
1345                   PopupMenu popupMenu;
1346
1347                   Menu menu { };
1348                   
1349                   for(compatible = object.compatible.first; compatible; compatible = compatible.next)
1350                   {
1351                      ClassFunction function = compatible.data;
1352                      MenuItem { menu, function.declarator.symbol.string, id = (int64)function, NotifySelect = AttachMethodSelected };
1353                   }
1354                   attachMethod = object.method;
1355
1356                   popupMenu = PopupMenu
1357                   { 
1358                      master = this, menu = menu, 
1359                      position =
1360                      {
1361                         button.absPosition.x - app.desktop.position.x,
1362                         button.absPosition.y - app.desktop.position.y + button.size.h
1363                      };
1364                   };
1365                   popupMenu.Create();
1366                   button.ReleaseCapture();
1367                   popupMenu.Capture();
1368                   return false;
1369                }
1370             };
1371             incref codeObject.attachBtn;
1372             codeObject.attachBtn.Create();
1373          }
1374       }
1375    }
1376    Instance object;
1377    Method attachMethod;
1378    char selectedMethod[1024];
1379    CodeEditor codeEditor;
1380    OldList categories;
1381    char selectedProp[1024];
1382    int selectedScroll;
1383 }
1384
1385 static int String_OnCompare(char ** string1, char ** string2)
1386 {
1387    int result = 0;
1388    if(*string1 && *string2)
1389       result = strcmpi(*string1, *string2);
1390    else if(!*string1 && *string2)
1391       result = 1;
1392    else if(*string1 && !*string2)
1393       result = -1;
1394    return result;
1395 }
1396
1397 static void CopyInstanceData(Class dataType, Instance propObject, Instance current)
1398 {
1399    Class _class;
1400    for(_class = dataType; _class && _class.type != systemClass; _class = _class.base)
1401    {
1402       DataMember member;
1403       for(member = _class.membersAndProperties.first; member; member = member.next)
1404       {               
1405          Class memberType = member.dataTypeClass;
1406          if(!memberType)
1407             memberType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1408          if(member.isProperty)
1409          {
1410             Property subProp = (Property) member;
1411             if(subProp.Get && subProp.Set)
1412                CopyProperty(subProp, propObject, current);
1413          }
1414          else
1415          {
1416             if(memberType)
1417                // TOCHECK: I have serious doubts this works in many cases.
1418                ((void (*)(void *, void *, void *))(void *)memberType._vTbl[__ecereVMethodID_class_OnCopy])(memberType, (byte *)propObject + member.offset, (byte *)current + member.offset);
1419             else if(member.memberOffset)
1420                memcpy((byte *)propObject + member.offset, (byte *)current + member.offset, member.memberOffset);
1421          }
1422       }
1423    }
1424 }
1425
1426 class PropertyInfo : struct
1427 {
1428 public:
1429    Property prop;
1430    bool disabled;
1431    FontResource font;
1432    char * categoryName;
1433    DataMember subMember;
1434    Property subProperty;
1435    uint extraOffset;
1436
1437    void OnDisplay(Surface surface, int x, int y, int width, Instance object, Alignment alignment, DataDisplayFlags displayFlags)
1438    {
1439       Property prop = this.prop;
1440
1441       surface.TextFont(font.font);
1442       if(disabled)
1443       {  
1444          surface.SetBackground(Color { 170, 170, 170 });
1445          surface.Area(0,0, x+width-1, y+100);
1446       }
1447       else if(prop && prop.dataTypeString)
1448       {
1449          Class dataType = prop.dataTypeClass;
1450          Module module = ((Designer)GetActiveDesigner()).codeEditor.privateModule;
1451          if(!dataType)
1452             dataType = prop.dataTypeClass = eSystem_FindClass(module, prop.dataTypeString);
1453          
1454          if(dataType && prop.Get)
1455          {
1456             void * dataPtr, * data = null, * subData = null;
1457             DataValue valueData, valueSubData;
1458             uint64 bitValue;
1459             
1460             // Get main prop
1461             if(dataType.type == structClass)
1462             {
1463                data = new0 byte[dataType.structSize];
1464                ((void (*)(void *, void *))(void *)prop.Get)(object, data);
1465                dataPtr = data;
1466             }
1467             else
1468             {
1469                GetProperty(prop, object, &valueData);
1470
1471                if(dataType.type == normalClass)
1472                   dataPtr = valueData.p;
1473                else
1474                   dataPtr = &valueData;
1475             }
1476             
1477             // Get sub prop
1478             if(this.subMember)
1479             {
1480                DataMember member = this.subMember;
1481                Class subDataType = member.dataTypeClass;
1482                if(!subDataType)
1483                   subDataType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1484                if(subDataType)
1485                {
1486                   if(dataType.type == bitClass)
1487                   {
1488                      BitMember bitMember = (BitMember)member;
1489                      bitValue = (valueData.i & bitMember.mask) >> bitMember.pos;
1490                      dataPtr = &bitValue;
1491                   }
1492                   else
1493                      dataPtr = (byte *)dataPtr + member.offset + this.extraOffset;
1494                }
1495                dataType = subDataType;
1496             }
1497             else if(this.subProperty)
1498             {
1499                Property subProperty = this.subProperty;
1500                Class subDataType = subProperty.dataTypeClass;
1501                if(!subDataType)
1502                   subDataType = subProperty.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, subProperty.dataTypeString);
1503                if(!subProperty.Get) subDataType = null;
1504                if(subDataType)
1505                {
1506                   if(subDataType.type == structClass)
1507                   {
1508                      subData = new0 byte[subDataType.structSize];
1509                      ((void (*)(void *, void *))(void *)subProperty.Get)(dataPtr, subData);
1510                      dataPtr = subData;
1511                   }
1512                   else
1513                   {
1514                      GetProperty(subProperty, dataPtr, &valueSubData);
1515                      if(subDataType.type == normalClass)
1516                         dataPtr = valueSubData.p;
1517                      else
1518                         dataPtr = &valueSubData;
1519                   }
1520                }
1521                dataType = subDataType;
1522             }
1523
1524             if(dataType)
1525                ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)dataType._vTbl[__ecereVMethodID_class_OnDisplay])(dataType, dataPtr, surface, x, y, width, null, alignment, displayFlags);
1526
1527             delete data;
1528             delete subData;
1529          }
1530       }
1531    }
1532
1533    Window OnEdit(DataBox dataBox, Window obsolete, int x, int y, int w, int h, void * unused)
1534    {
1535       Window editData = null;
1536       Property prop = this.prop;
1537       
1538       dataBox.SetData = Sheet::EditSetData;
1539       if(prop && prop.dataTypeString && !this.disabled)
1540       {
1541          Sheet propertyWindow = (Sheet)dataBox.master.master;
1542          Instance object = propertyWindow.object;
1543          Class dataType = prop.dataTypeClass;
1544          if(!dataType)
1545             dataType = prop.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, prop.dataTypeString);
1546
1547          if(dataType && prop.Get)
1548          {
1549             void * dataPtr, * data = null, * subData = null;
1550             DataValue valueData, valueSubData;
1551             uint64 bitValue;
1552             
1553             // Get main prop
1554             if(dataType.type == structClass)
1555             {
1556                data = new0 byte[dataType.structSize];
1557                ((void (*)(void *, void *))(void *)prop.Get)(object, data);
1558                dataPtr = data;
1559             }
1560             else
1561             {
1562                GetProperty(prop, object, &valueData);
1563                if(dataType.type == normalClass)
1564                   dataPtr = valueData.p;
1565                else
1566                   dataPtr = &valueData;
1567             }
1568             
1569             // Get sub prop
1570             if(this.subMember)
1571             {
1572                DataMember member = this.subMember;
1573                Class subDataType = member.dataTypeClass;
1574                if(!subDataType)
1575                   subDataType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1576                if(subDataType)
1577                {
1578                   if(dataType.type == bitClass)
1579                   {
1580                      BitMember bitMember = (BitMember)member;
1581                      bitValue = (valueData.i & bitMember.mask) >> bitMember.pos;
1582                      dataPtr = &bitValue;
1583                   }
1584                   else
1585                      dataPtr = (byte *)dataPtr + member.offset + this.extraOffset;
1586                }
1587                dataType = subDataType;
1588             }
1589             else if(this.subProperty)
1590             {
1591                Property subProperty = this.subProperty;
1592                Class subDataType = subProperty.dataTypeClass;
1593                if(!subDataType)
1594                   subDataType = subProperty.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, subProperty.dataTypeString);
1595                if(!subProperty.Get) subDataType = null;
1596                if(subDataType)
1597                {
1598                   if(subDataType.type == structClass)
1599                   {
1600                      subData = new0 byte[subDataType.structSize];
1601                      ((void (*)(void *, void *))(void *)subProperty.Get)(dataPtr, subData);
1602                      dataPtr = subData;
1603                   }
1604                   else
1605                   {
1606                      GetProperty(subProperty, dataPtr, &valueSubData);
1607                      if(subDataType.type == normalClass)
1608                         dataPtr = valueSubData.p;
1609                      else
1610                         dataPtr = &valueSubData;
1611                   }
1612                }
1613                dataType = subDataType;
1614             }
1615
1616             if(dataType)
1617                editData = ((Window (*)(void *, void *, DataBox, void *, int, int, int, int, void*))(void *)dataType._vTbl[__ecereVMethodID_class_OnEdit])(dataType, dataPtr, dataBox, obsolete,  x, y, w, h, object /*unused*/);
1618
1619             delete data;
1620             delete subData;
1621
1622             editData.font = { font.faceName, font.size, font.bold };
1623          }
1624       }
1625       return editData;
1626    }
1627
1628    int OnCompare(PropertyInfo data2)
1629    {
1630       char * category1 = prop ? prop.category : categoryName;
1631       char * category2 = data2.prop ? data2.prop.category : data2.categoryName;
1632       int result;
1633
1634       if(!category1) category1 = $"Misc";
1635       if(!category2) category2 = $"Misc";
1636       
1637       if(!prop)
1638       {
1639          // result = String::OnCompare((String)category1, (String)category2);
1640          result = String_OnCompare(&category1, &category2);
1641       }
1642       else
1643       //if(!result)
1644       {
1645          if(subMember && !data2.subMember)
1646          {
1647             result = 1;
1648          }
1649          else if(!subMember && data2.subMember)
1650          {
1651             result = 1;
1652          }
1653          else if(subMember && data2.subMember)
1654          {
1655             if(subMember.id < data2.subMember.id)
1656                result = -1;
1657             else if(subMember.id > data2.subMember.id)
1658                result = 1;
1659             else
1660                result = 0;
1661          }
1662          else if(subProperty && !data2.subProperty)
1663          {
1664             result = 1;
1665          }
1666          else if(!subProperty && data2.subProperty)
1667          {
1668             result = 1;
1669          }
1670          else if(subProperty && data2.subProperty)
1671          {
1672             if(subProperty.id < data2.subProperty.id)
1673                result = -1;
1674             else if(subProperty.id > data2.subProperty.id)
1675                result = 1;
1676             else
1677                result = 0;
1678          }
1679          else if(prop && !data2.prop)
1680             result = 1;
1681          else if(!prop && data2.prop)
1682             result = -1;
1683          else
1684             // result = ((String)prop.name).OnCompare(data2.prop.name);
1685             // result = String::OnCompare((String)prop.name, (String)data2.prop.name);
1686             result = String_OnCompare(&prop.name, &data2.prop.name);
1687       }
1688       return result;
1689    }
1690
1691    bool OnSaveEdit(Window editControl, void * unusedData)
1692    {
1693       Property prop = this.prop;
1694       if(prop)
1695       {
1696          Sheet sheet = (Sheet)editControl.master.master.master;
1697          Instance object = sheet.object;
1698          Class mainDataType = prop.dataTypeClass;
1699          Class dataType;
1700          bool result = false;
1701          void * dataPtr, * data = null, * subData = null;
1702          void * propObject = null;
1703          DataValue valueData = { 0 }, valueSubData = { 0 };
1704          uint bitValue;
1705
1706          if(!mainDataType)
1707             mainDataType = prop.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, prop.dataTypeString);
1708          dataType = mainDataType;
1709          
1710          // Prepare main prop
1711          if(dataType.type == structClass)
1712          {
1713             data = new0 byte[dataType.structSize];
1714             if(this.subMember || this.subProperty)
1715                ((void (*)(void *, void *))(void *)prop.Get)(object, data);
1716             dataPtr = data;
1717             propObject = data;
1718          }
1719          else if(dataType.type == normalClass || dataType.type == noHeadClass)
1720          {
1721             dataPtr = &valueData;
1722             
1723             if(this.subMember || this.subProperty)
1724             {
1725                Class _class;
1726                Instance current = (Instance)((void *(*)(void *))(void *)prop.Get)(object);
1727                propObject = valueData.p = eInstance_New(dataType);
1728                CopyInstanceData(dataType, propObject, current);
1729             }
1730          }
1731          else
1732          {
1733             
1734             if(this.subMember || this.subProperty)
1735                GetProperty(prop, object, &valueData);
1736             
1737             dataPtr = &valueData;
1738             propObject = &valueData;
1739          }
1740          
1741          // Prepare sub prop
1742          if(this.subMember)
1743          {
1744             DataMember member = this.subMember;
1745             Class subDataType = member.dataTypeClass;
1746             if(!subDataType)
1747                subDataType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1748             if(subDataType)
1749             {
1750                if(dataType.type == bitClass)
1751                   dataPtr = &bitValue;
1752                else
1753                   dataPtr = (byte *)dataPtr + member.offset + this.extraOffset;
1754             }
1755             dataType = subDataType;
1756          }
1757          else if(this.subProperty)
1758          {
1759             Property subProperty = this.subProperty;
1760             Class subDataType = subProperty.dataTypeClass;
1761             
1762             if(!subDataType)
1763                subDataType = subProperty.dataTypeClass = 
1764                   eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, subProperty.dataTypeString);
1765             if(!subProperty.Get) subDataType = null;
1766             if(subDataType)
1767             {
1768                if(subDataType.type == structClass)
1769                {
1770                   subData = new0 byte[subDataType.structSize];
1771                   dataPtr = subData;
1772                }
1773                else
1774                   dataPtr = &valueSubData;
1775             }
1776             dataType = subDataType;
1777          }
1778
1779          if(dataType)
1780          {
1781             if(((bool (*)(void *, void *, Window, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnSaveEdit])(dataType, dataPtr, editControl, null))
1782             {
1783                if(mainDataType.type == bitClass && this.subMember)
1784                {
1785                   BitMember bitMember = (BitMember)this.subMember;
1786                   valueData.ui &= ~ (uint)bitMember.mask;
1787                   valueData.ui |= bitValue << bitMember.pos;
1788                }
1789                if(this.subProperty)
1790                {
1791                   if(dataType.type == structClass)
1792                      ((void (*)(void *, void *))(void *)this.subProperty.Set)(propObject, subData);
1793                   else if(dataType.type == unitClass || dataType.type == enumClass || dataType.type == bitClass)
1794                   {
1795                      if(!strcmp(dataType.dataTypeString, "float"))
1796                         ((void(*)(void *,float))(void *)this.subProperty.Set)(propObject, valueSubData.f);
1797                      else if(!strcmp(dataType.dataTypeString, "double"))
1798                         ((void(*)(void *,double))(void *)this.subProperty.Set)(propObject, valueSubData.d);
1799                      else if(!strcmp(dataType.dataTypeString, "byte"))
1800                         ((void(*)(void *,byte))(void *)this.subProperty.Set)(propObject, valueSubData.uc);
1801                      else if(!strcmp(dataType.dataTypeString, "uint16"))
1802                         ((void(*)(void *,uint16))(void *)this.subProperty.Set)(propObject, valueSubData.us);
1803                      else 
1804                         ((void (*)(void *, uint))(void *)this.subProperty.Set)(propObject, valueSubData.ui);
1805                   }
1806                   else
1807                      ((void (*)(void *, uint))(void *)this.subProperty.Set)(propObject, valueSubData.ui);
1808                }
1809                if(mainDataType.type == structClass)
1810                   ((void (*)(void *, void *))(void *)prop.Set)(object, data);
1811                else if(mainDataType.type == unitClass || mainDataType.type == enumClass || mainDataType.type == bitClass)
1812                {
1813                   if(!strcmp(mainDataType.dataTypeString, "float"))
1814                      ((void(*)(void *,float))(void *)prop.Set)(object, valueData.f);
1815                   else if(!strcmp(mainDataType.dataTypeString, "double"))
1816                      ((void(*)(void *,double))(void *)prop.Set)(object, valueData.d);
1817                   else if(!strcmp(mainDataType.dataTypeString, "byte"))
1818                      ((void(*)(void *,byte))(void *)prop.Set)(object, valueData.uc);
1819                   else if(!strcmp(mainDataType.dataTypeString, "uint16"))
1820                      ((void(*)(void *,uint16))(void *)prop.Set)(object, valueData.us);
1821                   else
1822                      ((void (*)(void *, uint))(void *)prop.Set)(object, valueData.ui);
1823                }
1824                else
1825                   ((void (*)(void *, uint))(void *)prop.Set)(object, valueData.ui);
1826
1827                result = true;
1828             }
1829             if(data == dataPtr)     ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, &data);
1830             if(subData == dataPtr)  ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, &subData);
1831          }
1832          delete data;
1833          delete subData;
1834
1835          if(result)
1836             return sheet.SaveEdit(this, object);
1837       }
1838       return false;
1839    }
1840 };
1841
1842 class Category : struct
1843 {
1844    Category prev, next;
1845    char * name;
1846    DataRow row;
1847    bool collapsed;
1848 };