ide: remove background image, make ToolBox and Properties Sheet invisible by default.
[sdk] / ide / src / designer / ToolBox.ec
1 import "ide"
2
3 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp;
4
5 static __attribute__((unused)) void Dummy()
6 {
7    Window a = 0;
8    a.OnLeftButtonUp(0,0,0);
9 }
10
11 class ToolBox : Window
12 {
13    text = $"Toolbox";
14    background = formColor;
15    borderStyle = sizable;
16    hasClose = true;
17    //size = { 200, 500 };
18    size = { 150, 300 };
19    anchor = { right = 0 };
20    //anchor = { right = 0, top = 0, bottom = 0 };
21    hasVertScroll = true;
22    visible = false;
23    menu = Menu { };
24
25    /* isRemote = true;
26    inactive = true;
27    stayOnTop = true; */
28
29    char className[1024];
30    int controlY;
31    Button arrowControl;
32    ObjectInfo selectedClass;
33    CodeEditor codeEditor;
34    char * selectedControl;
35    int numControls;
36
37    Menu viewMenu { menu, $"View" };
38    MenuItem { viewMenu, $"View Toolbox" };
39
40    ~ToolBox()
41    {
42       delete arrowControl;
43    }
44    property char * controlClass
45    {
46       set
47       {
48          arrowControl.checked = true;
49          className[0] = 0;
50          ((Designer)GetActiveDesigner()).objectClass = null;
51       }
52       get
53       {
54          return (char *)className;
55       }
56    }
57    property CodeEditor codeEditor
58    {
59       set { this.codeEditor = value; }
60    }
61    property ObjectInfo selectedClass
62    {
63       set
64       {
65          if(value != selectedClass ||
66             (value && value.instance && (!selectedClass.instance || selectedClass.instance._class != value.instance._class)))
67          {
68             Button control, next;
69
70             selectedControl = null;
71
72             selectedClass = value;
73
74             for(control = (Button)firstChild; control; control = next)
75             {
76                next = (Button)control.next;
77                if(control != arrowControl && !control.nonClient)
78                {
79                   if(control.checked)
80                      selectedControl = (char *)(intptr)control.id;
81                   control.Destroy(0);
82                }
83             }
84             // TOFIX: It seems the virtual space does not get adjusted by only destroying the buttons?
85             scrollArea = { 0, 0 };
86
87             //className = null;      // Had to drag twice on code...
88             arrowControl.checked = true;
89
90             if(value && value.instance)
91             {
92                controlY = 25;
93                numControls = 1;
94                ((Designer)GetActiveDesigner()).FillToolBox();
95             }
96          }
97       }
98    }
99
100    bool OnClose(bool parentClosing)
101    {
102       visible = false;
103       if(!parentClosing)
104          ide.RepositionWindows(false);
105       return parentClosing;
106    }
107
108    bool OnKeyDown(Key key, unichar ch)
109    {
110       if(key == escape)
111       {
112          if(ide.activeClient) ide.activeClient.Activate();
113          //Destroy(0);
114       }
115       return true;
116    }
117
118    void AddControl(Class _class)
119    {
120       Button control = CreateControl(&controlY, (const char *)(intptr)eClass_GetProperty(_class, "icon"), _class.name, _class.name);
121       numControls++;
122       if(selectedControl && !strcmp(selectedControl, _class.name))
123       {
124          control.checked = true;
125          strcpy(className, _class.name);
126          ((Designer)GetActiveDesigner()).objectClass = className;
127       }
128    }
129
130    ToolBox()
131    {
132       int y = 5;
133       arrowControl = CreateControl(&y, ":others/mousePointer.png", $"Pointer", null);
134       arrowControl.checked = true;
135       incref arrowControl;
136    }
137
138    bool OnLeftButtonUp(int x, int y, Modifiers mods)
139    {
140       Designer designer = (Designer)GetActiveDesigner();
141       if(designer && designer.isDragging)
142       {
143          ((Designer)GetActiveDesigner()).isDragging = false;
144          ReleaseCapture();
145          return rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp,
146             x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y, &mods, false, false);
147       }
148       return true;
149    }
150
151    Button CreateControl(int * y, const char * bitmapFile, const char * text, const void * id)
152    {
153       Button control
154       {
155          this;
156          bevelOver = true;
157          isRadio = true;
158          text = text;
159          minClientSize.w = 120;
160          size.h = 20;
161          anchor = Anchor { left = 5, top = *y, right = 5 };
162          alignment = left;
163          bitmap = { bitmapFile };
164          id = (int64)(intptr)id;
165
166          bool NotifyPushed(Button control, int x, int y, Modifiers mods)
167          {
168             control.checked = true;
169             strcpy(className, control.text); //id;
170             if((Designer)GetActiveDesigner())
171             {
172                ((Designer)GetActiveDesigner()).objectClass = control.id ? className : null; //(char *)control.text; //id;
173                ((Designer)GetActiveDesigner()).isDragging = true;
174                control.ReleaseCapture();
175                Capture();
176                cursor = ((GuiApplication)__thisModule.application).GetCursor(arrow);
177             }
178             return true;
179          }
180
181          bool NotifyDoubleClick(Button control, int x, int y, Modifiers mods)
182          {
183             if(control != arrowControl)
184                codeEditor.AddControl();
185             return false;
186          }
187
188          bool NotifyReleased(Button control, int x, int y, Modifiers mods)
189          {
190             // ((Designer)GetActiveDesigner()).isDragging = false;
191             return true;
192          }
193       };
194       control.Create();
195       *y += 20;
196       return control;
197    }
198 }