ecere/ide: Fixed DataBox::SetData to use any_object data type; Fixed IDE's property...
[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       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 *)prop.Get)(object);
93          return d;
94       }
95       else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
96       {
97          float f =((float(*)())(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 *)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 *)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 *)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 *)prop.Get)(object);
115       }
116       else
117       {
118          return 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       prop.Get(src, propData);
135       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 */prop.Set(dest, ((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 *)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 *)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 *)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 *)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 *)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 *)prop.Get)(src));
167    }
168    else
169    {
170       prop.Set(dest, 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 *)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 *)prop.Get)(object);
197       }
198       else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
199       {
200          value.f = ((float(*)())(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 *)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 *)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 *)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 *)prop.Get)(object);
217       }
218       else
219       {
220          value.i = 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          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 = activeBorder;
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 = ((IDE)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          // ((IDE)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          // ((IDE)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 = (int)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 = (int)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)
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                            continue;
801
802                         if(!category)
803                         {
804                            category = Category { name = name };
805                            categories.AddName(category);
806                         }
807                         if(!category.row && categorized)
808                         {
809                            PropertyInfo catInfo { null, false, null, name };
810                            category.row = properties.AddRow();
811                            category.row.SetData(propertyName, name );
812                            category.row.SetData(propertyValue, catInfo);
813                            category.row.isHeader = true;
814                            category.row.collapsed = category.collapsed;
815                         }
816
817                         if(clear)
818                         {
819                            row = categorized ? category.row.FindRow((int)prop) : properties.FindRow((int)prop);
820                            if(!row)
821                               row = categorized ? category.row.AddRow() : properties.AddRow();
822                            row.tag = (int)prop;
823                         }
824                         else
825                            row = categorized ? category.row.FindRow((int)prop) : properties.FindRow((int)prop);
826
827                         row.SetData(propertyName, prop.name);
828                         row.SetData(propertyValue, info);
829
830                         if(clear && !strcmp(prop.name, this.selectedProp))
831                            properties.currentRow = row;
832
833                         if(!dataType.noExpansion && (dataType.type == structClass || dataType.type == normalClass || dataType.type == noHeadClass || dataType.type == bitClass))
834                         {
835                            DataMember member;
836                            
837                            if(clear)
838                               row.collapsed = true;
839
840                            for(member = dataType.membersAndProperties.first; member; member = member.next)
841                            {
842                               if(member.isProperty)
843                               {
844                                  Property subProp = (Property)member;
845                                  if(!subProp.conversion && subProp.Get && subProp.Set)
846                                  {
847                                     DataRow subRow;
848                                     PropertyInfo info { prop, disabled, bold ? codeEditor.boldFont : codeEditor.normalFont, null, null, subProp };
849
850                                     if(clear)
851                                     {
852                                        subRow = row.AddRow();
853                                        subRow.tag = (int)subProp;
854                                     }
855                                     else
856                                        subRow = row.FindRow((int)subProp);
857                                     
858                                     subRow.SetData(propertyName, subProp.name);
859                                     subRow.SetData(propertyValue, info);
860                                  }
861                               }
862                               else if(member.name)
863                               {
864                                  DataRow subRow;
865                                  PropertyInfo info { prop, disabled, bold ? codeEditor.boldFont : codeEditor.normalFont, null, member, null };
866                                  if(clear)
867                                  {
868                                     subRow = row.AddRow();
869                                     subRow.tag = (int)member;
870                                  }
871                                  else
872                                     subRow = row.FindRow((int)member);
873
874                                  subRow.SetData(propertyName, member.name);
875                                  subRow.SetData(propertyValue, info);
876                               }
877                               else
878                               {
879                                  DataMember subMember;
880                                  for(subMember = member.members.first; subMember; subMember = subMember.next)
881                                  {
882                                     DataRow subRow;
883                                     PropertyInfo info { prop, disabled, bold ? codeEditor.boldFont : codeEditor.normalFont, null, subMember, null, member.offset };
884                                     if(clear)
885                                     {
886                                        subRow = row.AddRow();
887                                        subRow.tag = (int)subMember;
888                                     }
889                                     else
890                                        subRow = row.FindRow((int)subMember);
891
892                                     subRow.SetData(propertyName, subMember.name);
893                                     subRow.SetData(propertyValue, info);
894                                  }
895                               }
896                            }
897                         }
898                      }
899                   }
900                }
901             }
902          }
903          delete test;
904          // Sort alphabetically for now...
905          if(clear)
906          {
907             // properties.Sort(null, 1);
908             properties.Sort(propertyValue, 1);
909             if(!properties.currentRow)
910             {
911                bool found = false;
912                
913                for(_class = selected.instance._class; _class; _class = _class.base)
914                {
915                   Property prop;
916                   for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
917                   {
918                      if(prop.isProperty && prop.Set && prop.Get && prop.compiled)
919                      {
920                         if(_class.defaultProperty && !strcmp(prop.name, _class.defaultProperty))
921                         {
922                            DataRow row;
923                            char * name = prop.category ? prop.category : "Misc";
924                            Category category = categories.FindName(name, false);
925                            row = category ? (categorized ? category.row.FindRow((int)prop) : properties.FindRow((int)prop)) : null;
926                            properties.currentRow = row;
927                            found = true;
928                            break;                                                                                                                              
929                         }
930                      }
931                   }
932                   if(found) break;
933                }
934                if(!found)
935                   properties.currentRow = properties.firstRow;
936             }
937
938             if(currentRow)
939             {
940                DataRow row = properties.currentRow;
941                properties.scroll.y = selectedScroll + row.index * properties.rowHeight;
942             }
943          }
944       }
945    }
946
947    void AddObject(ObjectInfo object, char * name, CodeObjectType type, bool select)
948    {
949       DataRow after = null;
950       DataRow row;
951       CodeObject codeObject;
952       char * bitmap = null;
953       bool foundClass = false;
954
955       for(row = dropBox.firstRow; row; row = row.next)
956       {
957          CodeObject codeObject = row.GetData(null);
958          if(codeObject.object.oClass == object.oClass)
959             foundClass = true;
960          else if(foundClass)
961             break;
962          after = row;
963       }
964
965       row = (DataRow)dropBox.AddRowAfter(after);
966       
967       row.tag = (int)object;
968
969       codeObject = 
970       {
971          object = object;
972          name = name;
973          type = type;
974          indent = (type == typeClass) ? 0 : 1;
975       };
976
977       if(type != typeClass)
978          bitmap = (char *)eClass_GetProperty(object.instance._class, "icon");
979       if(bitmap)
980       {
981          codeObject.bitmap = { bitmap };
982          AddResource(codeObject.bitmap);
983       }
984       
985       row.SetData(null, codeObject);
986
987       if(select)
988       {
989          this.object = object ? object.instance : null;
990          propertyValue.userData = object ? (void *)object.instance : null;
991          dropBox.SelectRow(row);
992       }
993    }
994
995    void DeleteObject(ObjectInfo object)
996    {
997       DataRow row = dropBox.FindRow((int)object);
998       if(row)
999       {
1000          CodeObject codeObject = row.GetData(null);
1001      
1002          if(codeObject.bitmap)
1003             RemoveResource(codeObject.bitmap);
1004          dropBox.DeleteRow(row);
1005       }
1006    }
1007
1008    void SelectObject(ObjectInfo object)
1009    {
1010       if(this)
1011       {
1012          DataRow row = dropBox.FindRow((int)object);
1013          this.object = object ? object.instance : null;
1014          propertyValue.userData = object ? (void *)object.instance : null;
1015          dropBox.SelectRow(row);
1016       }
1017    }
1018
1019    void RenameObject(ObjectInfo object, char * name)
1020    {
1021       DataRow row = dropBox.FindRow((int)object);
1022       CodeObject codeObject = row.GetData(null);
1023       // Isn't this useless? Shouldn't it be after?
1024       codeObject.name = name;
1025       // row.SetData(null, codeObject);  // Is this necessary?
1026    }
1027
1028    void DataBox::EditSetData(any_object setValue, bool closingDropDown)
1029    {
1030       ((Sheet)master.master).SetData(setValue, this);
1031    }
1032
1033    void SetData(any_object setValue, DataBox dataBox)
1034    {
1035       //PropertyInfo propertyPtr = row.GetData(null);
1036       PropertyInfo propertyPtr = properties.GetData(null);
1037       Property prop = propertyPtr ? propertyPtr.prop : null;
1038       Instance object = this.object;
1039       if(prop)
1040       {   
1041          Class dataType = prop.dataTypeClass;
1042          if(!dataType)
1043             dataType = prop.dataTypeClass = eSystem_FindClass(codeEditor.privateModule, prop.dataTypeString);
1044          if(propertyPtr.subMember)
1045          {
1046             DataMember member = propertyPtr.subMember;
1047             Class subDataType = member.dataTypeClass;
1048             if(!member.dataTypeClass)
1049                subDataType = member.dataTypeClass = eSystem_FindClass(codeEditor.privateModule, member.dataTypeString);
1050             if(subDataType)
1051             {
1052                void * data = null;
1053                if(!subDataType.dataType)
1054                   subDataType.dataType = ProcessTypeString(subDataType.dataTypeString, false);
1055
1056                if(dataType.type == structClass)
1057                {
1058                   data = new0 byte[dataType.structSize];
1059                   prop.Get(object, data);
1060                   // CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, &setValue, subDataType.size);
1061                   CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, setValue, subDataType.dataType.size);
1062                   prop.Set(object, data);
1063                }
1064                else if(dataType.type == normalClass || dataType.type == noHeadClass)
1065                {
1066                }
1067                else
1068                {
1069                   if(dataType.type == bitClass)
1070                   {
1071                      BitMember bitMember = (BitMember) member;
1072                      if(subDataType)
1073                      {
1074                         DataValue value = { 0 };
1075                         value.ui = prop.Get(object);
1076                         value.ui &= ~ (uint)bitMember.mask;
1077                         value.ui |= *(uint *)setValue << bitMember.pos;
1078                         prop.Set(object, value.ui);
1079                      }
1080                   }
1081                   else
1082                   {
1083                      data = dataType.typeSize ? new0 byte[dataType.typeSize] : null;
1084                      prop.Get(object, data);
1085                      // CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, &setValue, subDataType.typeSize);
1086                      CopyBytes((byte *)data + member.offset + propertyPtr.extraOffset, setValue, subDataType.dataType.size);
1087                      // TODO: Support non 32 bit datatypes here
1088                      prop.Set(object, data);
1089                   }
1090                }
1091
1092                if(data) dataType._vTbl[__ecereVMethodID_class_OnFree](dataType,&data);
1093                delete data;
1094             }
1095          }
1096          else if(propertyPtr.subProperty)
1097          {
1098             Property subProperty = propertyPtr.subProperty;
1099             Class subDataType = subProperty.dataTypeClass;
1100             if(!subDataType)
1101                subDataType = subProperty.dataTypeClass = eSystem_FindClass(codeEditor.privateModule, subProperty.dataTypeString);
1102             if(subDataType)
1103             {
1104                void * data = null;
1105
1106                if(dataType.type == structClass)
1107                {
1108                   data = new0 byte[dataType.structSize];
1109                   prop.Get(object, data);
1110                   subProperty.Set(data, *(uint *)setValue);
1111                   prop.Set(object, data);
1112                }
1113                else if(dataType.type == normalClass || dataType.type == noHeadClass)
1114                {
1115                   Instance current = (Instance)prop.Get(object);
1116                   Instance propObject = eInstance_New(dataType);
1117                   CopyInstanceData(dataType, propObject, current);
1118                   subProperty.Set(propObject, setValue);
1119                   prop.Set(object, propObject);
1120                }
1121                else
1122                {
1123                   data = dataType.typeSize ? new0 byte[dataType.typeSize] : null;
1124                   prop.Get(object, data);
1125                   subProperty.Set(data, setValue);
1126                   // TODO: Support not 32 bit data types here
1127                   prop.Set(object, data);
1128                }
1129
1130                if(data) dataType._vTbl[__ecereVMethodID_class_OnFree](dataType,&data);
1131                delete data;
1132             }
1133          }
1134          else
1135          {
1136             SetPropValue(prop, object, setValue);
1137          }      
1138          Code_FixProperty(propertyPtr.prop, object);
1139
1140          properties.Update(null);
1141          dropBox.Update(null);
1142          codeEditor.designer.Update(null);
1143          codeEditor.Update(null);   // patch for redraw bug if on top
1144
1145          ListProperties(false);
1146
1147          dataBox.editor.font = { propertyPtr.font.faceName, propertyPtr.font.size, propertyPtr.font.bold };
1148          codeEditor.ModifyCode();
1149       }
1150    }
1151
1152    bool SaveEdit(PropertyInfo propertyPtr, Instance object)
1153    {
1154       codeEditor.designer.Update(null);
1155       codeEditor.Update(null);   // patch for redraw bug if on top
1156       properties.Update(null);
1157       dropBox.Update(null);
1158
1159       Code_FixProperty(propertyPtr.prop, object);
1160       ListProperties(false);
1161
1162       codeEditor.ModifyCode();
1163       return true;
1164    }
1165
1166    void ToggleSheet()
1167    {
1168       if(!propBtn.checked)
1169       {
1170          propBtn.checked = true;
1171          propBtn.NotifyClicked(this, propBtn, 0,0,0);
1172       }
1173       else
1174       {
1175          methBtn.checked = true;
1176          methBtn.NotifyClicked(this, methBtn, 0,0,0);
1177       }
1178    }
1179
1180    bool AttachMethodSelected(MenuItem selection, Modifiers mods)
1181    {
1182       ClassFunction function = (ClassFunction)selection.id;
1183       codeEditor.AttachMethod(attachMethod, function);
1184       return true;
1185    }
1186
1187    bool ReattachMethodSelected(MenuItem selection, Modifiers mods)
1188    {
1189       ClassFunction function = (ClassFunction)selection.id;
1190       CodeObject object = methods.GetData(methodName);
1191       codeEditor.ReAttachMethod(attachMethod, function);
1192       return true;
1193    }
1194
1195    bool OverrideMethodSelected(MenuItem selection, Modifiers mods)
1196    {
1197       ClassFunction function = (ClassFunction)selection.id;
1198       CodeObject object = methods.GetData(methodName);
1199       if(object)
1200          codeEditor.AddMethod(object.method);   
1201       return true;
1202    }
1203
1204    bool GotoMethodSelected(MenuItem selection, Modifiers mods)
1205    {
1206       ClassFunction function = (ClassFunction)selection.id;
1207       CodeObject object = methods.GetData(methodName);
1208       if(object)
1209          codeEditor.GoToMethod(object.method.name);
1210       return true;
1211    }
1212
1213    bool DetachMethodSelected(MenuItem selection, Modifiers mods)
1214    {
1215       ClassFunction function = (ClassFunction)selection.id;
1216       CodeObject object = methods.GetData(methodName);
1217       if(object)
1218          codeEditor.DetachMethod(object.method, object.function, object.overriden);
1219       return true;
1220    }
1221
1222    bool DeleteMethodSelected(MenuItem selection, Modifiers mods)
1223    {
1224       ClassFunction function = (ClassFunction)selection.id;
1225       CodeObject object = methods.GetData(methodName);
1226       if(object)
1227          object.deleteBtn.NotifyClicked(this, object.deleteBtn, 0,0,0);
1228       return true;
1229    }
1230
1231    bool AddMethodClicked(Button button, int x, int y, Modifiers mods)
1232    {
1233       DataRow row = (DataRow)button.id;
1234       CodeObject object = row.GetData(methodName);
1235       codeEditor.AddMethod(object.method);   
1236       return true;
1237    }
1238
1239    void CreateButtons(CodeObject codeObject, int y, int h, DataRow row)
1240    {
1241       BitmapResource bitmap;
1242       
1243       if(codeObject.overriden)
1244       {
1245          if(codeObject.overriden == 1)
1246          {
1247             codeObject.deleteBtn = Button
1248             {
1249                methods, master = this,
1250                inactive = true,
1251                bitmap = { ":actions/delete.png", alphaBlend = true },
1252                anchor = { right = 16, top = y },
1253                size = { 16, h },
1254                id = (int)row;
1255
1256                bool NotifyClicked(Button button, int x, int y, Modifiers mods)
1257                {
1258                   CodeObject codeObject = ((DataRow)button.id).GetData(null);
1259                   bool confirmation = !Code_IsFunctionEmpty(codeObject.function, codeObject.method, codeEditor.selected);
1260
1261                   if(confirmation)
1262                   {
1263                      char title[1024];
1264                      sprintf(title, "Delete %s", codeObject.name);
1265                      if(MessageBox
1266                         {
1267                            master = parent, type = okCancel, text = title, 
1268                            contents = "Method still contains code. Are you sure you want to delete it?"
1269                         }.Modal() == ok)
1270                         confirmation = false;
1271                   }
1272
1273                   if(!confirmation && codeObject.function.attached.count)
1274                   {
1275                      char title[1024];
1276                      sprintf(title, "Delete %s", codeObject.name);
1277                      confirmation = true;
1278                      if(MessageBox
1279                         {
1280                            master = parent, type = okCancel, text = title,
1281                            contents = "Other methods are still attached to this method. Are you sure you want to delete it?"
1282                         }.Modal() == ok)
1283                         confirmation = false;
1284                   }
1285
1286                   if(!confirmation)
1287                   {
1288                      codeEditor.DeleteMethod(codeObject.function);
1289                   }
1290                   return false;
1291                }
1292             };
1293             incref codeObject.deleteBtn;
1294             codeObject.deleteBtn.Create();
1295          }
1296
1297          if(codeObject.overriden == 2 || !codeObject.function.attached.count)
1298          {
1299             codeObject.detachBtn = Button 
1300             {
1301                methods,
1302                master = methods.master,
1303                inactive = true,
1304                bitmap = { ":actions/detach.png" },
1305                anchor = { right = 0, top = y },
1306                size = { 16, h },
1307                id = (int)row;
1308
1309                bool NotifyClicked(Button button, int x, int y, Modifiers mods)
1310                {
1311                   DataRow row = (DataRow)button.id;
1312                   CodeObject object = row.GetData(methodName);
1313
1314                   codeEditor.DetachMethod(object.method, object.function, object.overriden);
1315                   return true;
1316                }
1317             };
1318             incref codeObject.detachBtn;
1319             codeObject.detachBtn.Create();
1320          }
1321       }
1322       else
1323       {
1324          if(codeObject.compatible.count)
1325          {
1326             codeObject.attachBtn = Button
1327             {
1328                parent = methods, master = methods.master,
1329                inactive = true,
1330                bitmap = { ":actions/attach.png" },
1331                anchor = { right = 0, top = y },
1332                size = { 16, h },
1333                id = (int)row;
1334
1335                bool NotifyPushed(Button button, int x, int y, Modifiers mods)
1336                {
1337                   // Create menu
1338                   DataRow row = (DataRow)button.id;
1339                   CodeObject object = row.GetData(methodName);
1340                   OldLink compatible;
1341                   PopupMenu popupMenu;
1342
1343                   Menu menu { };
1344                   
1345                   for(compatible = object.compatible.first; compatible; compatible = compatible.next)
1346                   {
1347                      ClassFunction function = compatible.data;
1348                      MenuItem { menu, function.declarator.symbol.string, id = (int)function, NotifySelect = AttachMethodSelected };
1349                   }
1350                   attachMethod = object.method;
1351
1352                   popupMenu = PopupMenu
1353                   { 
1354                      master = this, menu = menu, 
1355                      position =
1356                      {
1357                         button.absPosition.x - app.desktop.position.x,
1358                         button.absPosition.y - app.desktop.position.y + button.size.h
1359                      };
1360                   };
1361                   popupMenu.Create();
1362                   button.ReleaseCapture();
1363                   popupMenu.Capture();
1364                   return false;
1365                }
1366             };
1367             incref codeObject.attachBtn;
1368             codeObject.attachBtn.Create();
1369          }
1370       }
1371    }
1372    Instance object;
1373    Method attachMethod;
1374    char selectedMethod[1024];
1375    CodeEditor codeEditor;
1376    OldList categories;
1377    char selectedProp[1024];
1378    int selectedScroll;
1379 }
1380
1381 static int String_OnCompare(char ** string1, char ** string2)
1382 {
1383    int result = 0;
1384    if(*string1 && *string2)
1385       result = strcmpi(*string1, *string2);
1386    else if(!*string1 && *string2)
1387       result = 1;
1388    else if(*string1 && !*string2)
1389       result = -1;
1390    return result;
1391 }
1392
1393 static void CopyInstanceData(Class dataType, Instance propObject, Instance current)
1394 {
1395    Class _class;
1396    for(_class = dataType; _class && _class.type != systemClass; _class = _class.base)
1397    {
1398       DataMember member;
1399       for(member = _class.membersAndProperties.first; member; member = member.next)
1400       {               
1401          Class memberType = member.dataTypeClass;
1402          if(!memberType)
1403             memberType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1404          if(member.isProperty)
1405          {
1406             Property subProp = (Property) member;
1407             if(subProp.Get && subProp.Set)
1408                CopyProperty(subProp, propObject, current);
1409          }
1410          else
1411          {
1412             if(memberType)
1413                // TOCHECK: I have serious doubts this works in many cases.
1414                memberType._vTbl[__ecereVMethodID_class_OnCopy](memberType, (byte *)propObject + member.offset, (byte *)current + member.offset);
1415             else if(member.memberOffset)
1416                memcpy((byte *)propObject + member.offset, (byte *)current + member.offset, member.memberOffset);
1417          }
1418       }
1419    }
1420 }
1421
1422 class PropertyInfo : struct
1423 {
1424 public:
1425    Property prop;
1426    bool disabled;
1427    FontResource font;
1428    char * categoryName;
1429    DataMember subMember;
1430    Property subProperty;
1431    uint extraOffset;
1432
1433    void OnDisplay(Surface surface, int x, int y, int width, Instance object, Alignment alignment, DataDisplayFlags displayFlags)
1434    {
1435       Property prop = this.prop;
1436
1437       surface.TextFont(font.font);
1438       if(disabled)
1439       {  
1440          surface.SetBackground(Color { 170, 170, 170 });
1441          surface.Area(0,0, x+width-1, y+100);
1442       }
1443       else if(prop && prop.dataTypeString)
1444       {
1445          Class dataType = prop.dataTypeClass;
1446          Module module = ((Designer)GetActiveDesigner()).codeEditor.privateModule;
1447          if(!dataType)
1448             dataType = prop.dataTypeClass = eSystem_FindClass(module, prop.dataTypeString);
1449          
1450          if(dataType && prop.Get)
1451          {
1452             void * dataPtr, * data = null, * subData = null;
1453             DataValue valueData, valueSubData;
1454             uint64 bitValue;
1455             
1456             // Get main prop
1457             if(dataType.type == structClass)
1458             {
1459                data = new0 byte[dataType.structSize];
1460                prop.Get(object, data);
1461                dataPtr = data;
1462             }
1463             else
1464             {
1465                GetProperty(prop, object, &valueData);
1466
1467                if(dataType.type == normalClass)
1468                   dataPtr = valueData.p;
1469                else
1470                   dataPtr = &valueData;
1471             }
1472             
1473             // Get sub prop
1474             if(this.subMember)
1475             {
1476                DataMember member = this.subMember;
1477                Class subDataType = member.dataTypeClass;
1478                if(!subDataType)
1479                   subDataType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1480                if(subDataType)
1481                {
1482                   if(dataType.type == bitClass)
1483                   {
1484                      BitMember bitMember = (BitMember)member;
1485                      bitValue = (valueData.i & bitMember.mask) >> bitMember.pos;
1486                      dataPtr = &bitValue;
1487                   }
1488                   else
1489                      dataPtr = (byte *)dataPtr + member.offset + this.extraOffset;
1490                }
1491                dataType = subDataType;
1492             }
1493             else if(this.subProperty)
1494             {
1495                Property subProperty = this.subProperty;
1496                Class subDataType = subProperty.dataTypeClass;
1497                if(!subDataType)
1498                   subDataType = subProperty.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, subProperty.dataTypeString);
1499                if(!subProperty.Get) subDataType = null;
1500                if(subDataType)
1501                {
1502                   if(subDataType.type == structClass)
1503                   {
1504                      subData = new0 byte[subDataType.structSize];
1505                      subProperty.Get(dataPtr, subData);
1506                      dataPtr = subData;
1507                   }
1508                   else
1509                   {
1510                      GetProperty(subProperty, dataPtr, &valueSubData);
1511                      if(subDataType.type == normalClass)
1512                         dataPtr = valueSubData.p;
1513                      else
1514                         dataPtr = &valueSubData;
1515                   }
1516                }
1517                dataType = subDataType;
1518             }
1519
1520             if(dataType)
1521                dataType._vTbl[__ecereVMethodID_class_OnDisplay](dataType, dataPtr, surface, x, y, width, null, alignment, displayFlags);
1522
1523             delete data;
1524             delete subData;
1525          }
1526       }
1527    }
1528
1529    Window OnEdit(DataBox dataBox, Window obsolete, int x, int y, int w, int h, void * unused)
1530    {
1531       EditBox editData = null;
1532       Property prop = this.prop;
1533       
1534       dataBox.SetData = Sheet::EditSetData;
1535       if(prop && prop.dataTypeString && !this.disabled)
1536       {
1537          Sheet propertyWindow = (Sheet)dataBox.master.master;
1538          Instance object = propertyWindow.object;
1539          Class dataType = prop.dataTypeClass;
1540          if(!dataType)
1541             dataType = prop.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, prop.dataTypeString);
1542
1543          if(dataType && prop.Get)
1544          {
1545             void * dataPtr, * data = null, * subData = null;
1546             DataValue valueData, valueSubData;
1547             uint64 bitValue;
1548             
1549             // Get main prop
1550             if(dataType.type == structClass)
1551             {
1552                data = new0 byte[dataType.structSize];
1553                prop.Get(object, data);
1554                dataPtr = data;
1555             }
1556             else
1557             {
1558                GetProperty(prop, object, &valueData);
1559                if(dataType.type == normalClass)
1560                   dataPtr = valueData.p;
1561                else
1562                   dataPtr = &valueData;
1563             }
1564             
1565             // Get sub prop
1566             if(this.subMember)
1567             {
1568                DataMember member = this.subMember;
1569                Class subDataType = member.dataTypeClass;
1570                if(!subDataType)
1571                   subDataType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1572                if(subDataType)
1573                {
1574                   if(dataType.type == bitClass)
1575                   {
1576                      BitMember bitMember = (BitMember)member;
1577                      bitValue = (valueData.i & bitMember.mask) >> bitMember.pos;
1578                      dataPtr = &bitValue;
1579                   }
1580                   else
1581                      dataPtr = (byte *)dataPtr + member.offset + this.extraOffset;
1582                }
1583                dataType = subDataType;
1584             }
1585             else if(this.subProperty)
1586             {
1587                Property subProperty = this.subProperty;
1588                Class subDataType = subProperty.dataTypeClass;
1589                if(!subDataType)
1590                   subDataType = subProperty.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, subProperty.dataTypeString);
1591                if(!subProperty.Get) subDataType = null;
1592                if(subDataType)
1593                {
1594                   if(subDataType.type == structClass)
1595                   {
1596                      subData = new0 byte[subDataType.structSize];
1597                      subProperty.Get(dataPtr, subData);
1598                      dataPtr = subData;
1599                   }
1600                   else
1601                   {
1602                      GetProperty(subProperty, dataPtr, &valueSubData);
1603                      if(subDataType.type == normalClass)
1604                         dataPtr = valueSubData.p;
1605                      else
1606                         dataPtr = &valueSubData;
1607                   }
1608                }
1609                dataType = subDataType;
1610             }
1611
1612             if(dataType)
1613                editData = (void *)dataType._vTbl[__ecereVMethodID_class_OnEdit](dataType, dataPtr, dataBox, obsolete,  x, y, w, h, object /*unused*/);
1614
1615             delete data;
1616             delete subData;
1617
1618             editData.font = { font.faceName, font.size, font.bold };
1619          }
1620       }
1621       return editData;
1622    }
1623
1624    int OnCompare(PropertyInfo data2)
1625    {
1626       char * category1 = prop ? prop.category : categoryName;
1627       char * category2 = data2.prop ? data2.prop.category : data2.categoryName;
1628       int result;
1629
1630       if(!category1) category1 = "Misc";
1631       if(!category2) category2 = "Misc";
1632       
1633       if(!prop)
1634       {
1635          // result = String::OnCompare((String)category1, (String)category2);
1636          result = String_OnCompare(&category1, &category2);
1637       }
1638       else
1639       //if(!result)
1640       {
1641          if(subMember && !data2.subMember)
1642          {
1643             result = 1;
1644          }
1645          else if(!subMember && data2.subMember)
1646          {
1647             result = 1;
1648          }
1649          else if(subMember && data2.subMember)
1650          {
1651             if(subMember.id < data2.subMember.id)
1652                result = -1;
1653             else if(subMember.id > data2.subMember.id)
1654                result = 1;
1655             else
1656                result = 0;
1657          }
1658          else if(subProperty && !data2.subProperty)
1659          {
1660             result = 1;
1661          }
1662          else if(!subProperty && data2.subProperty)
1663          {
1664             result = 1;
1665          }
1666          else if(subProperty && data2.subProperty)
1667          {
1668             if(subProperty.id < data2.subProperty.id)
1669                result = -1;
1670             else if(subProperty.id > data2.subProperty.id)
1671                result = 1;
1672             else
1673                result = 0;
1674          }
1675          else if(prop && !data2.prop)
1676             result = 1;
1677          else if(!prop && data2.prop)
1678             result = -1;
1679          else
1680             // result = ((String)prop.name).OnCompare(data2.prop.name);
1681             // result = String::OnCompare((String)prop.name, (String)data2.prop.name);
1682             result = String_OnCompare(&prop.name, &data2.prop.name);
1683       }
1684       return result;
1685    }
1686
1687    bool OnSaveEdit(Window editControl, void * unusedData)
1688    {
1689       Property prop = this.prop;
1690       if(prop)
1691       {
1692          Sheet sheet = (Sheet)editControl.master.master.master;
1693          Instance object = sheet.object;
1694          Class mainDataType = prop.dataTypeClass;
1695          Class dataType;
1696          bool result = false;
1697          void * dataPtr, * data = null, * subData = null;
1698          void * propObject = null;
1699          DataValue valueData = { 0 }, valueSubData = { 0 };
1700          uint bitValue;
1701
1702          if(!mainDataType)
1703             mainDataType = prop.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, prop.dataTypeString);
1704          dataType = mainDataType;
1705          
1706          // Prepare main prop
1707          if(dataType.type == structClass)
1708          {
1709             data = new0 byte[dataType.structSize];
1710             if(this.subMember || this.subProperty)
1711                prop.Get(object, data);
1712             dataPtr = data;
1713             propObject = data;
1714          }
1715          else if(dataType.type == normalClass || dataType.type == noHeadClass)
1716          {
1717             dataPtr = &valueData;
1718             
1719             if(this.subMember || this.subProperty)
1720             {
1721                Class _class;
1722                Instance current = (Instance)prop.Get(object);
1723                propObject = valueData.p = eInstance_New(dataType);
1724                CopyInstanceData(dataType, propObject, current);
1725             }
1726          }
1727          else
1728          {
1729             
1730             if(this.subMember || this.subProperty)
1731                GetProperty(prop, object, &valueData);
1732             
1733             dataPtr = &valueData;
1734             propObject = &valueData;
1735          }
1736          
1737          // Prepare sub prop
1738          if(this.subMember)
1739          {
1740             DataMember member = this.subMember;
1741             Class subDataType = member.dataTypeClass;
1742             if(!subDataType)
1743                subDataType = member.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, member.dataTypeString);
1744             if(subDataType)
1745             {
1746                if(dataType.type == bitClass)
1747                   dataPtr = &bitValue;
1748                else
1749                   dataPtr = (byte *)dataPtr + member.offset + this.extraOffset;
1750             }
1751             dataType = subDataType;
1752          }
1753          else if(this.subProperty)
1754          {
1755             Property subProperty = this.subProperty;
1756             Class subDataType = subProperty.dataTypeClass;
1757             
1758             if(!subDataType)
1759                subDataType = subProperty.dataTypeClass = 
1760                   eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, subProperty.dataTypeString);
1761             if(!subProperty.Get) subDataType = null;
1762             if(subDataType)
1763             {
1764                if(subDataType.type == structClass)
1765                {
1766                   subData = new0 byte[subDataType.structSize];
1767                   dataPtr = subData;
1768                }
1769                else
1770                   dataPtr = &valueSubData;
1771             }
1772             dataType = subDataType;
1773          }
1774
1775          if(dataType)
1776          {
1777             if(dataType._vTbl[__ecereVMethodID_class_OnSaveEdit](dataType, dataPtr, editControl, null))
1778             {
1779                if(mainDataType.type == bitClass && this.subMember)
1780                {
1781                   BitMember bitMember = (BitMember)this.subMember;
1782                   valueData.ui &= ~ (uint)bitMember.mask;
1783                   valueData.ui |= bitValue << bitMember.pos;
1784                }
1785                if(this.subProperty)
1786                {
1787                   if(dataType.type == structClass)
1788                      this.subProperty.Set(propObject, subData);
1789                   else if(dataType.type == unitClass || dataType.type == enumClass || dataType.type == bitClass)
1790                   {
1791                      if(!strcmp(dataType.dataTypeString, "float"))
1792                         ((void(*)(void *,float))(void *)this.subProperty.Set)(propObject, valueSubData.f);
1793                      else if(!strcmp(dataType.dataTypeString, "double"))
1794                         ((void(*)(void *,double))(void *)this.subProperty.Set)(propObject, valueSubData.d);
1795                      else if(!strcmp(dataType.dataTypeString, "byte"))
1796                         ((void(*)(void *,byte))(void *)this.subProperty.Set)(propObject, valueSubData.uc);
1797                      else if(!strcmp(dataType.dataTypeString, "uint16"))
1798                         ((void(*)(void *,uint16))(void *)this.subProperty.Set)(propObject, valueSubData.us);
1799                      else 
1800                         this.subProperty.Set(propObject, valueSubData.ui);
1801                   }
1802                   else
1803                      this.subProperty.Set(propObject, valueSubData.ui);
1804                }
1805                if(mainDataType.type == structClass)
1806                   prop.Set(object, data);
1807                else if(mainDataType.type == unitClass || mainDataType.type == enumClass || mainDataType.type == bitClass)
1808                {
1809                   if(!strcmp(mainDataType.dataTypeString, "float"))
1810                      ((void(*)(void *,float))(void *)prop.Set)(object, valueData.f);
1811                   else if(!strcmp(mainDataType.dataTypeString, "double"))
1812                      ((void(*)(void *,double))(void *)prop.Set)(object, valueData.d);
1813                   else if(!strcmp(mainDataType.dataTypeString, "byte"))
1814                      ((void(*)(void *,byte))(void *)prop.Set)(object, valueData.uc);
1815                   else if(!strcmp(mainDataType.dataTypeString, "uint16"))
1816                      ((void(*)(void *,uint16))(void *)prop.Set)(object, valueData.us);
1817                   else
1818                      prop.Set(object, valueData.ui);
1819                }
1820                else
1821                   prop.Set(object, valueData.ui);
1822
1823                result = true;
1824             }
1825             if(data == dataPtr)     dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, &data);
1826             if(subData == dataPtr)  dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, &subData);
1827          }
1828          delete data;
1829          delete subData;
1830
1831          if(result)
1832             return sheet.SaveEdit(this, object);
1833       }
1834       return false;
1835    }
1836 };
1837
1838 class Category : struct
1839 {
1840    Category prev, next;
1841    char * name;
1842    DataRow row;
1843    bool collapsed;
1844 };