summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/editor.c
blob: 25b8f35e1b12b544272a922e473a6da7367e7a9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819

#include "egui_log.h"
#include "ffi_glue.h"
#include "ffi_abstraction.h"
#include "gui_widget.h"
#include "props_helper.h"
#include "objtree.h"
#include "propview.h"
#include "itemview.h"
#include "gui_parser.h"
#include "egui_logic_private.h"

#define EDJE_EDIT_IS_UNSTABLE_AND_I_KNOW_ABOUT_IT 1
#include <Elementary.h>
#include <Edje_Edit.h>

#include "elm_widget.h"

#define MAIN_WDG_INFO "main_wdg_info_key"

/* Function to call in the end of undo/redo in order to update view.
 * Update is made according to head memento. */
static void
_editor_undo_redo_post(const Gui_Memento *memento);

static Gui_Context *_active_ctx = NULL;
static const Egui_Layout_Widgets *g;

void
_active_context_set(Gui_Context *ctx)
{
   _active_ctx = ctx;
}

Gui_Context *
_active_context_get()
{
   return _active_ctx;
}

typedef enum {
     BORDER_OUT =    0,
     BORDER_LEFT =   1 << 0,
     BORDER_RIGHT =  1 << 1,
     BORDER_TOP =    1 << 2,
     BORDER_BOTTOM = 1 << 3,
     /* Need separate names for borders and markers. They are used as keys in hash. */
     BORDER_MARKER_LEFT = BORDER_LEFT,
     BORDER_MARKER_RIGHT = BORDER_RIGHT,
     BORDER_MARKER_TOP = BORDER_TOP,
     BORDER_MARKER_BOTTOM = BORDER_BOTTOM,

     BORDER_MARKER_TOP_LEFT = BORDER_MARKER_TOP | BORDER_MARKER_LEFT,
     BORDER_MARKER_TOP_RIGHT = BORDER_MARKER_TOP | BORDER_MARKER_RIGHT,

     BORDER_MARKER_BOTTOM_LEFT = BORDER_MARKER_BOTTOM | BORDER_MARKER_LEFT,
     BORDER_MARKER_BOTTOM_RIGHT = BORDER_MARKER_BOTTOM | BORDER_MARKER_RIGHT

} Border_Type;

typedef struct _Main_Wdg_Info
{
   Eo *frame;
} Main_Wdg_Info;

static Main_Wdg_Info*
main_wdg_info_new()
{
   return calloc(1, sizeof(Main_Wdg_Info));
}

static void
main_wdg_info_frame_set(Main_Wdg_Info *wi, Eo *fr)
{
   wi->frame = fr;
}

static Eo*
main_wdg_info_frame_get(const Main_Wdg_Info *wi)
{
   return wi->frame;
}

Eina_Bool
widget_name_change(Gui_Widget *wdg, const char *str)
{
   const Gui_Context *ctx = wdg_context_get(wdg);
   if (!gui_context_dep_data_update(ctx, wdg_dep_id_get(wdg), str))
     {
        ERR("Name \"%s\" already exists!", str);
        return EINA_FALSE;
     }

   const Gui_Widget *sel  = gui_context_data_get(ctx, SELECTED_WDG);
   objtree_item_selected_set(sel);

   return EINA_TRUE;
}

/* x_fix/y_fix - correction of initial position of smart_parent. whis is not resized before elm_run. */
static void
_canvas_free_coords_get(const Gui_Context *ctx, Evas_Coord x_fix, Evas_Coord y_fix, Evas_Coord *x, Evas_Coord *y)
{
   Evas_Coord x0 = 340 + x_fix, y0 = 120 + y_fix, w0 = 1060, h0 = 900, retx, rety, ymax = 120;
   Eina_List *main_widgets = gui_context_main_widgets_get(ctx);
   Eina_List *itr;
   Dep_Id *wdg_id;
   retx = x0;
   rety = y0;

   EINA_LIST_FOREACH(main_widgets, itr, wdg_id)
     {
        Evas_Coord fx, fy, fw, fh;
        Gui_Widget *wdg = wdg_get(wdg_id);
        if (!wdg) continue;
        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
        if (wi)
          {
             eo_do(main_wdg_info_frame_get(wi), evas_obj_size_get(&fw, &fh));
             eo_do(main_wdg_info_frame_get(wi), evas_obj_position_get(&fx, &fy));
             if ((fx + fw) < (x0 + w0 - 100))
               {
                  retx = fx + fw;
                  if ((fy + fh) > ymax)
                    ymax = fy + fh;
               }
             else
               {
                  retx = x0;
                  rety = ymax;
                  if (rety > (y0 + h0)) rety = y0;
               }
          }
     }
   if (x) *x = retx;
   if (y) *y = rety;
}

int
which_border(Evas_Coord x, Evas_Coord y, Evas_Coord ow, Evas_Coord oh)
{
   /* Width of border to catch callback. */
   Evas_Coord bw = 10;
   int lr = 0, tb = 0;
   if (x < bw) lr = BORDER_LEFT;
   else if (x > ow - bw) lr = BORDER_RIGHT;
   if (y < bw) tb = BORDER_TOP;
   else if (y > oh - bw) tb = BORDER_BOTTOM;
   return lr | tb;
}

static Eina_Bool
_marker_mouse_down(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);
static Eina_Bool
_marker_mouse_up(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);
static Eina_Bool
_marker_mouse_in(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);
static Eina_Bool
_marker_mouse_out(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);
#define STR(par) #par

#define LINE(id, x, y, l, w, visibility) \
   ({\
       Eo *line = NULL;\
       eo_do(g->main_win->main_win, line = eo_key_data_get(STR(id)));\
       if (!line)\
          {\
             line = eo_add(EVAS_RECTANGLE_CLASS, g->main_win->main_win);\
             eo_do(g->main_win->main_win, eo_key_data_set(STR(id), line, NULL));\
             eo_do(line, evas_obj_color_set(0, 255, 0, 255));\
             eo_do(evas_object_smart_parent_get(g->main_win->main_box), evas_obj_smart_member_add(line)); \
          }\
       eo_do(line, evas_obj_visibility_set(visibility));\
       eo_do(line, evas_obj_position_set(x, y));\
       eo_do(line, evas_obj_size_set(l, w));\
       eo_do(line, evas_obj_raise());\
   })

#define MARKER(id, x, y, visibility) \
   ({ \
    Eo *_m = NULL;\
    eo_do(g->main_win->main_win, _m = eo_key_data_get(STR(id)));\
    if (!_m)\
        {\
           _m = eo_add(EVAS_RECTANGLE_CLASS, g->main_win->main_win);\
           eo_do(g->main_win->main_win, eo_key_data_set(STR(id), _m, NULL));\
           eo_do(_m, evas_obj_color_set(0, 255, 0, 255));\
           eo_do(_m, evas_obj_size_set(7, 7));\
           eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, _marker_mouse_down, (void *) (intptr_t) id)); \
           eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, _marker_mouse_up, (void *) (intptr_t) id)); \
           eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_IN, _marker_mouse_in, (void *) (intptr_t) id)); \
           eo_do(_m, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_OUT, _marker_mouse_out, (void *) (intptr_t) id)); \
           eo_do(evas_object_smart_parent_get(g->main_win->main_box), evas_obj_smart_member_add(_m)); \
        }\
      eo_do(_m, evas_obj_position_set(x, y)); \
      eo_do(_m, evas_obj_raise());\
      eo_do(_m, evas_obj_visibility_set(visibility));\
    })

/* Draws border around obj, Evas is taken from base_obj;
 * markers and lines are saved in base_obj*/
static void
_wdg_border_draw(const Gui_Widget *wdg, Eina_Bool visibility)
{
   const Gui_Session *session = gui_context_editor_session_get(_active_context_get());
   Eo *obj = NULL;
   Eo *win_wdg_eo = NULL;
   if (wdg)
     {
        if (IS_MAIN(wdg))
          {
             Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
             if (wi) obj = main_wdg_info_frame_get(wi);
          }
        else
          {
             const Gui_Widget *win_wdg = wdg_main_wdg_get(wdg);
             Main_Wdg_Info *wi = wdg_data_get(win_wdg, MAIN_WDG_INFO);
             if (wi) win_wdg_eo = main_wdg_info_frame_get(wi);
             obj = session_eo_get(session, wdg);
             win_wdg_eo = elm_object_content_get(win_wdg_eo);
          }
     }

   Evas_Coord ox = 0, oy = 0, ow = 0, oh = 0, minw = 0, minh = 0;
   Evas_Coord lw = 0 , lh = 0, hs = 5;

   static Eo *prev_obj = NULL;
   static Evas_Coord prev_ox = 0, prev_oy = 0, prev_ow = 0, prev_oh = 0;
   static Eina_Bool prev_visibility = EINA_FALSE;

   /* This is made, to have opportunity to pass NULL and hide border.*/
   if (obj)
     {
        Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
        if (win_wdg_eo) eo_do(win_wdg_eo,
              evas_obj_position_get(&bx, &by),
              evas_obj_size_get(&bw, &bh));

        eo_do(obj, evas_obj_position_get(&ox, &oy));
        eo_do(obj, evas_obj_size_hint_min_get(&minw, &minh));
        eo_do(obj, evas_obj_size_get(&ow, &oh));
        if (ow < minw) ow = minw;
        if (oh < minh) oh = minh;

        ox += bx;
        oy += by;

        lw = ow + 2;
        lh = oh + 2;
        /* Redraw border only if coords or object were changed. */
        if ((obj != prev_obj) || (ox != prev_ox) || (oy != prev_oy) ||
            (ow != prev_ow) || (oh != prev_oh) || (prev_visibility != visibility))
          {
             prev_obj = obj;
             prev_ox = ox;
             prev_oy = oy;
             prev_ow = ow;
             prev_oh = oh;
             prev_visibility = visibility;
          }
        else
          {
             return;
          }
     }

   LINE(BORDER_TOP, ox - 1, oy - 1, lw, 1, visibility);
   LINE(BORDER_BOTTOM, ox - 1, oy + oh + 1, lw, 1, visibility);
   LINE(BORDER_RIGHT, ox + ow + 1, oy - 1, 1, lh, visibility);
   LINE(BORDER_LEFT, ox - 1, oy - 1, 1, lh, visibility);

   MARKER(BORDER_MARKER_TOP_LEFT, ox - 1 - hs - 1, oy - 1 - hs - 1, visibility);
   MARKER(BORDER_MARKER_TOP, ox + ow / 2 - hs / 2, oy - 1 - hs - 1, visibility);
   MARKER(BORDER_MARKER_TOP_RIGHT, ox + ow + 1, oy - 1 - hs - 1, visibility);
   MARKER(BORDER_MARKER_RIGHT, ox + ow + 1, oy + oh / 2 - hs / 2, visibility);
   MARKER(BORDER_MARKER_BOTTOM_RIGHT, ox + ow + 1, oy + oh + 1, visibility);
   MARKER(BORDER_MARKER_BOTTOM, ox + ow / 2 - hs / 2, oy + oh + 1, visibility);
   MARKER(BORDER_MARKER_BOTTOM_LEFT, ox - 1 - hs - 1, oy + oh + 1, visibility);
   MARKER(BORDER_MARKER_LEFT, ox - 1 - hs - 1 , oy + oh / 2 - hs / 2, visibility);
}
#undef LINE
#undef MARKER
#undef STR

static void
_on_mouse_move_widget_drag(void *data, Evas *e EINA_UNUSED, Evas_Object *obj,
void *event_info)
{
   Gui_Context *ctx = data;
   static int cx, cy;
   Evas_Coord ox, oy;
   Evas_Event_Mouse_Move *ev = event_info;

   /*FIXME: remove static stuff after tripple callback wil be fixed*/
   if ((cx == ev->cur.canvas.x) && (cy == ev->cur.canvas.y))
     return;

   eo_do(obj, evas_obj_position_get(&ox, &oy));
   ox = ox + (ev->cur.canvas.x - ev->prev.canvas.x);
   oy = oy + (ev->cur.canvas.y - ev->prev.canvas.y);

   eo_do(obj, evas_obj_position_set(ox, oy));
     {
        Gui_Widget *wdg = wdg_find_by_eo(gui_context_editor_session_get(ctx), ctx, obj);
        Gui_Widget_Property *prop;
        Gui_Value *val;

        if (wdg)
          {
             prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET);
             if (prop)
               {
                  val = prop_value_nth_get(prop, 0);
                  gui_value_int_set(val, ox);
                  val = prop_value_nth_get(prop, 1);
                  gui_value_int_set(val, oy);
                  propview_item_update(prop);
               }
          }
     }
   cx = ev->cur.canvas.x;
   cy = ev->cur.canvas.y;
}

static void
_frame_mouse_move(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *fr, void *event_info)
{
   Evas_Coord ox, oy;
   Evas_Event_Mouse_Move *ev = event_info;
   Gui_Widget *wdg;
   Gui_Widget_Property *prop;

   eo_do(fr, evas_obj_position_get(&ox, &oy));

   ox = ox + (ev->cur.canvas.x - ev->prev.canvas.x);
   oy = oy + (ev->cur.canvas.y - ev->prev.canvas.y);

   eo_do(fr, wdg = eo_key_data_get("winwdg"));

   /* FIXME: Move frame here, because we don't know if win must have position property*/
   eo_do(fr, evas_obj_position_set(ox, oy));
   prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET);
   if (prop)
     {
        Gui_Value *val;
        val = prop_value_nth_get(prop, 0);
        gui_value_int_set(val, ox);
        val = prop_value_nth_get(prop, 1);
        gui_value_int_set(val, oy);
        propview_item_update(prop);
     }
}

const Gui_Widget*
_editor_wdg_selected_get()
{
   Gui_Context *ctx = _active_context_get();
   if (!ctx) return NULL;
   return gui_context_data_get(ctx, SELECTED_WDG);
}

static void
_editor_wdg_selected_set(const Gui_Widget *wdg)
{
   const Gui_Widget *old_wdg = _editor_wdg_selected_get();
   if ((old_wdg) && (old_wdg == wdg)) return;

   /* Hide previous border*/
   if (old_wdg)
     {
        _wdg_border_draw(old_wdg, EINA_FALSE);
     }
   else
     {
        /* During context call _win_resize() will be called.
         * It will draw border around win, but widget was not selected yet.
         * So need to hide border. */
        _wdg_border_draw(NULL, EINA_FALSE);
     }

   /* Show new border*/
   if (wdg)
     {
        Gui_Context *ctx = (Gui_Context *) wdg_context_get(wdg);
        gui_context_data_set(ctx, SELECTED_WDG, (Gui_Widget *) wdg);

        Eo *obj = session_eo_get(gui_context_editor_session_get(ctx), wdg);
        /* Stack up */
        //   eo_do(obj, evas_obj_raise());
        /* Set focus */
        eo_do(obj, evas_obj_focus_set(EINA_TRUE));
     }
   else
     {
        gui_context_data_set(_active_context_get(), SELECTED_WDG, NULL);
     }
}

/* Second parameter is used to indicate if the wdg has to be deleted */
static void
_iter_widget_delete(Gui_Widget *wdg)
{
   Eina_List *children = NULL, *l, *l2;
   Dep_Id *wid;
   Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(_active_context_get());

   children = wdg_children_list_get(wdg);
   EINA_LIST_FOREACH_SAFE(children, l, l2, wid)
     {
        Gui_Widget *w = wdg_get(wid);
        if (w) _iter_widget_delete(w);
     }

   /* If widget is Win, look for its frame and unset content, but don't delete frame. */
   Eo *win_inlined_image = NULL, *optional_win = NULL;
   /* Each time we iterate over widgets in order to delete them, we set window's frame invisible.
    * DUring creation it will be visible again. Frame deleted only when project is closed. */
   if (IS_MAIN(wdg))
     {
        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
        if (wi)
          {
             if (!IS_WIN(wdg))
               {
                  Eo *o = session_eo_get(session, wdg);
                  optional_win = eo_do(o, eo_key_data_get("__editor_win"));
               }
             Eo *fr = main_wdg_info_frame_get(wi);
             if (fr)
               {
                  win_inlined_image = elm_object_content_unset(fr);
                  eo_do(fr, evas_obj_visibility_set(EINA_FALSE));
               }
          }
     }
   manager_widget_delete(session, wdg, MODE_EDITOR, NULL);

   /* Delete window's inline image */
   if (win_inlined_image)
     {
        eo_del(optional_win);
        eo_del(win_inlined_image);
     }
}

static void
_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
//   Gui_Context *ctx = data;
   ERR("key down");
}

/* Callback, which adds MOUSE_MOVE callback,
 * to implement drag-and-drop in editor mode*/
static void
_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Gui_Context *ctx = data;
   const Gui_Session *session = gui_context_editor_session_get(ctx);
   Gui_Widget *wdg = wdg_find_by_eo(session, ctx, obj);
   EINA_SAFETY_ON_NULL_RETURN(wdg);

   Eo *wdg_eo = session_eo_get(session, wdg);
   evas_object_focus_set(wdg_eo, EINA_TRUE);
   _editor_wdg_selected_set(wdg);
   objtree_item_selected_set(wdg);

   evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _on_mouse_move_widget_drag, ctx);
}

/* Callback, which deletes MOUSE_MOVE callback,
 * to implement drag-and-drop*/
static Eina_Bool
_mouse_up(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   /* Delete all callbacks,
    * because sometimes _mouse_down is called several times. */
   while(evas_object_event_callback_del
          (obj, EVAS_CALLBACK_MOUSE_MOVE, _on_mouse_move_widget_drag));
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_marker_mouse_move(void *data, Eo *marker EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
   Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(_active_context_get());
   Eo *weo;
   Evas_Coord ox, oy, ow, oh, minw, minh, dx, dy;
   Evas_Event_Mouse_Move *ev = event_info;
   /*FIXME: type */
   Border_Type border = (int) (intptr_t) data;

   Eo *cur_logo = NULL;
   const Gui_Widget *wdg = _editor_wdg_selected_get();

   dx = ev->cur.canvas.x - ev->prev.canvas.x;
   dy = ev->cur.canvas.y - ev->prev.canvas.y;

   /* in base object cursor description is save.
    * base object is win's Eo for widget,
    * and canvas(main window) for frame. */
   const Eo *base_obj;
   if (IS_MAIN(wdg))
     {
        base_obj = canvas_get();
        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
        weo = main_wdg_info_frame_get(wi);

        /* When resizing frame, we need to get min width and height form window.
         * And don't forget deltas*/
        Eo *ww = session_eo_get(session, wdg);
        eo_do(ww, evas_obj_size_hint_min_get(&minw, &minh));
        intptr_t dw, dh;
        eo_do(weo, dw = (intptr_t) eo_key_data_get("dw"));
        eo_do(weo, dh = (intptr_t) eo_key_data_get("dh"));
        minw += dw;
        minh += dh;
     }
   else
     {
        const Gui_Widget *win_wdg = wdg_main_wdg_get(wdg);
        base_obj = session_eo_get(session, win_wdg);
        /* Eo object of widget. */
        weo = session_eo_get(session, wdg);
        eo_do(weo, evas_obj_size_hint_min_get(&minw, &minh));
     }

   eo_do(base_obj, cur_logo = eo_key_data_get("cursor"));
   if (cur_logo)
     eo_do(cur_logo, evas_obj_position_set(ev->cur.canvas.x + 7, ev->cur.canvas.y + 5));

   eo_do(weo, evas_obj_position_get(&ox, &oy));
   eo_do(weo, evas_obj_size_get(&ow, &oh));

   if (border & BORDER_MARKER_LEFT)
     {
        if ((ev->prev.canvas.x < ox) && ((ow - dx) > 0) && ((ow - dx) >= minw))
          {
             ow = ow - dx;
             ox = ox + dx;
          }
     }
   else if (border & BORDER_MARKER_RIGHT)
     {
        if ((ev->prev.canvas.x > (ox + ow)) && ((ow + dx) >= minw))
          {
             ow = ow + dx;
          }
     }

   if (border & BORDER_MARKER_TOP)
     {
        if ((ev->prev.canvas.y < oy) && ((oh - dy) > 0) && ((oh - dy) >= minh))
          {
             oh = oh - dy;
             oy = oy + dy;
          }
     }
   else if (border & BORDER_MARKER_BOTTOM)
     {
        if ((ev->prev.canvas.y >= (oy + oh)) && ((oh + dy) >= minh))
          {
             oh = oh + dy;
          }
     }

   eo_do(weo, evas_obj_position_set(ox, oy));
   eo_do(weo, evas_obj_size_set(ow, oh));

   if (IS_MAIN(wdg))
     {
        Gui_Widget_Property *prop;
        Gui_Value *val;

        prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET);
        if (prop)
          {
             Evas_Coord dw, dh;
             eo_do(weo, dw = (Evas_Coord) (intptr_t) eo_key_data_get("dw"));
             eo_do(weo, dh = (Evas_Coord) (intptr_t) eo_key_data_get("dh"));
             /* ow and oh are frame's sizes, we need to subtract delta,
              * to get window's size.*/
             ow = ow - dw;
             oh = oh - dh;

             val = prop_value_nth_get(prop, 0);
             gui_value_int_set(val, ow);
             val = prop_value_nth_get(prop, 1);
             gui_value_int_set(val, oh);
             propview_item_update(prop);
             /* win has size prop, so move it through manager*/
             manager_widget_property_add(session, wdg, prop, MODE_EDITOR, NULL);
          }
     }
   else
     {
        /* This probably should be in _wdg_resize(),
         * but it interferes when updating size and position from Propview. */
        Gui_Widget_Property *prop;
        Gui_Value *val;
        prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, SIZE_SET);
        if (prop)
          {
             val = prop_value_nth_get(prop, 0);
             gui_value_int_set(val, ow);
             val = prop_value_nth_get(prop, 1);
             gui_value_int_set(val, oh);
             propview_item_update(prop);
          }

        prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, POSITION_SET);
        if (prop)
          {
             val = prop_value_nth_get(prop, 0);
             gui_value_int_set(val, ox);
             val = prop_value_nth_get(prop, 1);
             gui_value_int_set(val, oy);
             propview_item_update(prop);
          }
     }

   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_marker_mouse_down(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_MOVE, _marker_mouse_move, data));
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_marker_mouse_up(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   eo_do(obj, eo_event_callback_del(EVAS_OBJECT_EVENT_MOUSE_MOVE, _marker_mouse_move, data));
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_marker_mouse_in(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Coord sz = 17, trans_size = 25;
   Evas_Event_Mouse_Down *ev = event_info;
   const Gui_Session *session = gui_context_editor_session_get(_active_context_get());

   const Gui_Widget *wdg = _editor_wdg_selected_get();

   const Eo *base_obj;
   if (IS_MAIN(wdg))
     {
        base_obj = canvas_get();
     }
   else
     {
        const Gui_Widget *win_wdg = wdg_main_wdg_get(wdg);
        base_obj = session_eo_get(session, win_wdg);
     }

   /* This is "arrow" icon which flows around cursor. */
   Eo *cur_logo;
   eo_do(base_obj, cur_logo = eo_key_data_get("cursor"));
   if (!cur_logo)
   {
        cur_logo = eo_add(ELM_IMAGE_CLASS, (Eo *) base_obj);
        eo_do(cur_logo, evas_obj_size_set(sz, sz));
        eo_do(cur_logo, elm_obj_image_resizable_set(EINA_TRUE, EINA_TRUE));
        char path[100];
        getcwd(path, sizeof(path));
        sprintf(path, "%s/data/images/resize_red.png", path);
        eo_do(cur_logo, efl_file_set(path, NULL));
        eo_do(base_obj, eo_key_data_set("cursor", cur_logo, NULL));

        Elm_Transit *trans;
        trans = elm_transit_add();
        elm_transit_object_add(trans, cur_logo);

        elm_transit_effect_resizing_add(trans, sz, sz, trans_size, trans_size);
        elm_transit_duration_set(trans, 0.3);
        elm_transit_auto_reverse_set(trans, EINA_TRUE);
        elm_transit_repeat_times_set(trans, -1);
        elm_transit_go(trans);
     }
   eo_do(cur_logo, evas_obj_visibility_set(EINA_TRUE));
   eo_do(cur_logo, evas_obj_raise());
   eo_do(cur_logo, evas_obj_position_set(ev->canvas.x + 7, ev->canvas.y + 8));

   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_marker_mouse_out(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eo *cur_logo = NULL;
   const Gui_Widget *wdg = _editor_wdg_selected_get();

   const Eo *base_obj;
   if (IS_MAIN(wdg))
     {
        base_obj = canvas_get();
     }
   else
     {
        const Gui_Widget *win_wdg = wdg_main_wdg_get(wdg);
        const Gui_Session *session = gui_context_editor_session_get(_active_context_get());
        base_obj = session_eo_get(session, win_wdg);
     }

   eo_do(base_obj, cur_logo = eo_key_data_get("cursor"));

   if (!cur_logo)
     return EO_CALLBACK_CONTINUE;

   eo_do(cur_logo, evas_obj_visibility_set(EINA_FALSE));
   return EO_CALLBACK_CONTINUE;
}

static void
_frame_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Gui_Widget *wdg;
   eo_do(obj, evas_obj_raise());
   eo_do(obj, evas_obj_focus_set(EINA_TRUE));

   eo_do(obj, wdg = eo_key_data_get("winwdg"));
   eo_do(obj, evas_obj_focus_set(EINA_TRUE));

   _editor_wdg_selected_set(wdg);
   objtree_item_selected_set(wdg);

   evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _frame_mouse_move, NULL);
}

static Eina_Bool
_frame_mouse_up(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE, _frame_mouse_move);
   return EO_CALLBACK_CONTINUE;
}

/* Second parameter is used only as parent for INLINED windows*/
static void
_iter_widget_create(Gui_Widget *wdg, const Eo *parent_win)
{
   Eina_List *children = NULL, *l;
   Dep_Id *wid;

   /* Windows are iterated separately. If parent is NULL, means that current object is not win.
    * If iterated object is win, I create it as inlined_image and add frame to simulate win.*/
   Eina_Bool created;
   Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(_active_context_get());
   created = manager_widget_create(session, wdg, MODE_EDITOR, (void *)parent_win);

   if (created)
     {
        manager_widget_configure(session, wdg, MODE_EDITOR, NULL);
        children = wdg_children_list_get(wdg);
        EINA_LIST_FOREACH(children, l, wid)
          {
             Gui_Widget *w = wdg_get(wid);
             /* Window can not have child windows, so pass NULL. */
             if (w) _iter_widget_create(w, NULL);
          }
     }
}

static Eina_Bool
_wdg_resize(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Coord ow = 0, oh = 0, minw = 0, minh = 0;

   const Gui_Context *ctx = _active_context_get();
   Gui_Widget *wdg = wdg_find_by_eo(gui_context_editor_session_get(ctx), ctx, obj);
   Gui_Widget *selected_wdg = gui_context_data_get(ctx, SELECTED_WDG);
   if (wdg != selected_wdg)
     return EO_CALLBACK_CONTINUE;

   eo_do(obj, evas_obj_size_hint_min_get(&minw, &minh));
   eo_do(obj, evas_obj_size_get(&ow, &oh));
   if (ow < minw) ow = minw;
   if (oh < minh) oh = minh;
   eo_do(obj, evas_obj_size_set(ow, oh));

   /* This is commented here because, it makes unavailable
    * change position and size from Proverty View.
    * This is going to be in _marker_mouse_move() for a while*/
#if 0
   if (wdg)
     {
        Gui_Widget_Property *prop;
        Gui_Value *val;
        prop = wdg_prop_get(wdg, SIZE_SET);
        if (prop)
          {
             val = prop_value_nth_get(prop, 0);
             gui_value_set(val, GUI_TYPE_SINT, &ow);
             val = prop_value_nth_get(prop, 1);
             gui_value_set(val, GUI_TYPE_SINT, &oh);
             propview_item_update(prop);
          }

        int ox, oy;
        eo_do(obj, evas_obj_position_get(&ox, &oy));
        prop = wdg_prop_get(wdg, POSITION_SET);
        if (prop)
          {
             val = prop_value_nth_get(prop, 0);
             gui_value_set(val, GUI_TYPE_SINT, &ox);
             val = prop_value_nth_get(prop, 1);
             gui_value_set(val, GUI_TYPE_SINT, &oy);
             propview_item_update(prop);
          }
     }
#endif
   return EO_CALLBACK_CONTINUE;
}

/* Function, to check if content is already set to "new_part_name",
 * in CONTAINER. */
static Eina_Bool
_has_part(const Gui_Widget *wdg, const char *new_part_name, Object_Container_Item **item)
{
   Eina_List *contents = wdg_obj_container_contents_list_get(wdg);
   Eina_List *itr;
   Object_Container_Item *ci;
   Gui_Value *val;
   const char *part;
   EINA_LIST_FOREACH(contents, itr, ci)
     {
        Gui_Widget_Property *prop = obj_container_item_prop_get(ci);
        val = prop_value_nth_get(prop, 0);
        part = STRING_GET(val);
        if ((!part) && !strcmp("", new_part_name))
          {
             return EINA_TRUE;
          }
        if ((part) && !strcmp(part, new_part_name))
          {
             if (item) *item = ci;
             return EINA_TRUE;
          }
     }
   return EINA_FALSE;
}

static Eina_Bool
_win_resize(void *data EINA_UNUSED, Eo *o, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Coord ow = 0, oh = 0, minw = 0, minh = 0;
   Eo *fr = NULL;

   eo_do(o, evas_obj_size_hint_min_get(&minw, &minh));
   eo_do(o, evas_obj_size_get(&ow, &oh));
   if (ow < minw) ow = minw;
   if (oh < minh) oh = minh;

   if (eo_isa(o, ELM_WIN_CLASS))
     {
        Eo *inwin_img = elm_win_inlined_image_object_get(o);
        /* FIXME: comment it? */
        eo_do(inwin_img, evas_obj_size_set(ow, oh));
     }
   eo_do(o, fr = eo_key_data_get("__editor_frame"));

   intptr_t dw, dh;
   eo_do(fr, dw = (intptr_t) eo_key_data_get("dw"));
   eo_do(fr, dh = (intptr_t) eo_key_data_get("dh"));
   eo_do(fr, evas_obj_size_set(ow + dw, oh + dh));

   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_widget_prop_add(Gui_Session *session, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data EINA_UNUSED)
{
   Eina_Bool ret = _ffi_eo_do(session, wdg, prop);

   if (IS_MAIN(wdg))
     {
        Eo *o = session_eo_get(session, wdg), *win = NULL, *fr = NULL;
        if (!IS_WIN(wdg))
          {
             win = eo_do(o, eo_key_data_get("__editor_win"));
             fr = eo_do(win, eo_key_data_get("__editor_frame"));
          }
        else fr = eo_do(o, eo_key_data_get("__editor_frame"));
        if (IS_WIN(wdg) && !strcmp(prop_name_get(prop), TITLE_SET))
          {
             Gui_Value *v = prop_value_nth_get(wdg_prop_get(wdg, DB_DEF_WIN_CLASS, TITLE_SET), 0);
             const char *title = STRING_GET(v);
             eo_do(fr, elm_obj_widget_part_text_set(NULL, title));
          }
        if (!strcmp(prop_name_get(prop), VISIBILITY_SET))
          {
             Eina_Bool visibility;
             eo_do(o, visibility = evas_obj_visibility_get());
             eo_do(fr, evas_obj_visibility_set(visibility));
             /* Always show windows in editor. This made for the case, when eo_do call
              * is going on file load*/
             eo_do(o, evas_obj_visibility_set(EINA_TRUE));
             if (win) eo_do(win, evas_obj_visibility_set(EINA_TRUE));
             eo_do(fr, evas_obj_visibility_set(EINA_TRUE));
          }
     }
   if (IS_LAYOUT(wdg) && !strcmp(prop_name_get(prop), FILE_SET))
     {
        Gui_Value *v = prop_value_nth_get(prop, 0);
        Dep_Id *res_id = DEP_ID_GET(v);
        const Gui_Resource *res = gui_context_resource_get(res_id);
        if (resource_type_get(res) == RESOURCE_EDJE)
          {
             v = prop_value_nth_get(prop, 1);
             const char *group = STRING_GET(v);
             if (group)
               {
                  Eo *o = session_eo_get(session, wdg);
                  Evas *e = evas_object_evas_get(o);
                  Evas_Object *layout = eo_add(EDJE_EDIT_CLASS, e);
                  if (eo_do(layout, efl_file_set(resource_value_get(res), group)))
                    {
                       Eina_List *parts = edje_edit_parts_list_get(layout);
                       Eina_Stringshare *part_name;
                       int i = 0;
                       EINA_LIST_FREE(parts, part_name)
                         {
                            if (edje_edit_part_type_get(layout, part_name) == EDJE_PART_TYPE_SWALLOW)
                              {
                                 if (!_has_part(wdg, part_name, NULL))
                                   {
                                      Op_Desc *op_desc = db_mro_op_desc_get(wdg_class_name_get(wdg), DB_DEF_CONTAINER_CLASS, CONTENT_SET);
                                      Gui_Widget_Property *new_prop = prop_create_for_op(op_desc);
                                      Gui_Value *val = prop_value_nth_get(new_prop, 0);
                                      gui_value_string_set(val, strdup(part_name));
                                      Object_Container_Item *ci = obj_container_item_new(new_prop, NULL);
                                      wdg_obj_container_item_add((Gui_Widget *) wdg, ci, i);
                                   }
                                 i++;
                              }
                            eina_stringshare_del(part_name);
                         }
                    }
                  eo_del(layout);
               }
          }
     }
   return ret;
}

static Eina_Bool
_widget_item_add(Gui_Session *session, const Gui_Widget *wdg, const Item_Container_Item *wit, void *data)
{
   Elm_Object_Item *it = NULL;
   Eina_List *itr;
   it = _ffi_eo_item_add(session, wdg, wit, data);
   session_item_set(session, wit, it);

   /* FIXME: Delete together with call in manager_widget_configure */
   Dep_Id *dep_id_itr;
   EINA_LIST_FOREACH(item_container_item_subitems_get(wit), itr, dep_id_itr)
     {
        Item_Container_Item *witr = item_container_item_get(dep_id_itr);
        _widget_item_add(session, wdg, witr, data);
     }
   return EINA_TRUE;
}

static Eina_Bool
_content_set(Gui_Session *session, const Gui_Widget *container, const Gui_Widget_Property *prop, void *data EINA_UNUSED)
{
   Eina_Bool ret = _ffi_eo_do_content(session, container, prop, prop_op_desc_get(prop));
   return ret;
}

static Eina_Bool
_widget_del(Gui_Session *session, const Gui_Widget *wdg, void *data EINA_UNUSED)
{
   Eo *o = session_eo_get(session, wdg);
   objtree_item_remove(wdg);
   session_wdg_existence_set(session, wdg, EINA_FALSE);
   eo_del(o);
   return EINA_TRUE;
}

static Eina_Bool
_widget_add(Gui_Session *session, const Gui_Widget *wdg, void *data)
{
   if (!IS_MAIN(wdg))
     {
        Eo *o = _ffi_eo_add(session, wdg, NULL);
        if (!o) return EINA_FALSE;
        evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, _key_down, wdg_context_get(wdg));
        evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, wdg_context_get(wdg));
        //evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, NULL);
        eo_do(o, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, _mouse_up, NULL));
        /* To avoid dragging box, when want to drag button. */
        evas_object_propagate_events_set(o, EINA_FALSE);
        /* Add callbacks to show widget resize arrows */
#if 0
        evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_IN, _mouse_in, NULL);
        evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_OUT, _mouse_out, NULL);
#endif
        eo_do(o, eo_event_callback_add(EVAS_OBJECT_EVENT_RESIZE, _wdg_resize, NULL));
        /* Add specific callbacks, related to UI. */
        session_eo_set(session, wdg, o);
     }
   else
     {
        Eo *fr;
        Eo *parent_win = data;

        Eo *win = eo_add(ELM_WIN_CLASS, parent_win, elm_obj_win_constructor(NULL, ELM_WIN_INLINED_IMAGE));
        if (!win) return EINA_FALSE;
        if (!IS_WIN(wdg))
          {
             Eo *o = _ffi_eo_add(session, wdg, win);
             if (!o) return EINA_FALSE;
             eo_do(win, elm_obj_win_resize_object_add(o));
             eo_do(o, eo_key_data_set("__editor_win", win, NULL));
             session_eo_set(session, wdg, o);
          }
        else
          {
             session_eo_set(session, wdg, win);
          }

        Eo *iwin = elm_win_inlined_image_object_get(win);
        eo_do(iwin, evas_obj_propagate_events_set(EINA_FALSE));

        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);

        if (!wi)
          {
             Evas_Coord x, y, x_par, y_par;
             fr = eo_add(ELM_FRAME_CLASS, parent_win);
             /* This frame does not have any smart as parent. So in order to show menu above the frame,
              * we add this frame as a member of smart object. */

             Eo *smart_parent = evas_object_smart_parent_get(g->main_win->main_box);
             eo_do(smart_parent, evas_obj_smart_member_add(fr));
             eo_do(smart_parent, evas_obj_position_get(&x_par, &y_par));

             /* Before elm run, smart_parent will have some weird position, so need to make correction. */
             _canvas_free_coords_get(wdg_context_get(wdg), x_par, y_par, &x, &y);
             eo_do(fr, evas_obj_position_set(x, y));

             wi = main_wdg_info_new();
             main_wdg_info_frame_set(wi, fr);
             wdg_data_set(wdg, MAIN_WDG_INFO, wi);


             //evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
             //evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
             const char *fr_title = wdg_name_get(wdg);
             if (IS_WIN(wdg))
                fr_title = elm_win_title_get(win);

             elm_object_text_set(fr, fr_title);
             eo_do(fr,
                   evas_obj_visibility_set(EINA_TRUE),
                   elm_obj_frame_autocollapse_set(EINA_TRUE));

             evas_object_event_callback_add(fr, EVAS_CALLBACK_MOUSE_DOWN, _frame_mouse_down, NULL);
             eo_do(fr, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, _frame_mouse_up, NULL));
             eo_do(fr, eo_key_data_set("winwdg", wdg, NULL));
          }
        fr = main_wdg_info_frame_get(wi);
        eo_do(fr, evas_obj_visibility_set(EINA_TRUE));
        eo_do(win, eo_key_data_set("__editor_frame", fr, NULL));
        elm_object_content_set(fr, iwin);

        eo_do(win, eo_event_callback_add(EVAS_OBJECT_EVENT_RESIZE, _win_resize, NULL));
        /* Get size from properties of window. */
        Evas_Coord ox = 150, oy = 50;
        eo_do(fr, evas_obj_position_get(&ox, &oy));
        eo_do(iwin, evas_obj_position_set(ox, oy));

          {
             /* When set image as content to frame, image is smaller then frame.
              * So we want to calculate delta, to resize in proper way.
              * For this simulate resizing of image and frame.
              * Suppose 50, 50 is desired size for window,
              * and frame can be a litter bit smaller.*/
             Evas_Coord dw, dh;
             Evas_Coord im_w, im_h;
             Evas_Coord ow = 50, oh = 50;
             /* Set desired size.*/
             eo_do(iwin, evas_obj_size_set(ow, oh));
             eo_do(fr, evas_obj_size_set(ow, oh));
             /* Get size of image (which is smaller, because frame is 50, 50)*/
             eo_do(iwin, evas_obj_size_get(&im_w, &im_h));
             /* Calculate deltas*/
             dw = ow - im_w;
             dh = oh - im_h;
             /* Save deltas in frame data*/
             eo_do(fr, eo_key_data_set("dw", (void *) (intptr_t) dw, NULL));
             eo_do(fr, eo_key_data_set("dh", (void *) (intptr_t) dh, NULL));
             /* Resize properly. */
             eo_do(fr, evas_obj_size_set(ow + dw, oh + dh));
             eo_do(iwin, evas_obj_size_set(ow, oh));
          }
     }

   return EINA_TRUE;
}

/* Remove only Eo objects or also widgets*/
static Eina_Bool
_editor_layout_clear(const Gui_Context *ctx)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);

   Eina_List *list, *itr, *itr2;
   Dep_Id *wdg_id;

   /* in editor, we iterate only over windows which don't have parent. */
   list = gui_context_main_widgets_get(ctx);
   EINA_LIST_FOREACH_SAFE(list, itr, itr2, wdg_id)
     {
        Gui_Widget *wdg = wdg_get(wdg_id);
        if (wdg) _iter_widget_delete(wdg);
     }
   return EINA_TRUE;
}

/* Remove only Eo object for current widget. */
static Eina_Bool
_editor_widget_clear(Gui_Widget *wdg)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(wdg, EINA_FALSE);
   _iter_widget_delete(wdg);
   return EINA_TRUE;
}

static void
_wdg_parent_win_reload(const Gui_Widget *wdg)
{
   Dep_Id *wdg_id = wdg_dep_id_get(wdg);
   if (!wdg_get(wdg_id)) return;
   Gui_Widget *pwin = (Gui_Widget *) wdg_main_wdg_get(wdg);
   if (!pwin) return;
   /* Remove all Eo of current window. */
   _editor_widget_clear(pwin);
   /* Create window from beginning. */
   _iter_widget_create(pwin, canvas_get());
   /* Hide border of window, which is drawn when win is recreated and resized */
   _wdg_border_draw(NULL, EINA_FALSE);
}

static void
_update_widget_on_undoredo(const Gui_Context *ctx, Dep_Id *wdg_id, Eina_Bool state)
{
   const Gui_Widget *parent; /* We need the parent to reload the win */
   Gui_Widget *wdg = wdg_get(wdg_id);
   if (wdg) /* On widget deletion, we delete the Eo object first */
     {
        parent = (Gui_Widget *) wdg_parent_get(wdg);
        _editor_widget_clear(wdg);
     }
   gui_context_dep_data_active_set(ctx, wdg_id, state);

   wdg = wdg_get(wdg_id);
   if (wdg) parent = wdg_main_wdg_get(wdg);
   if (parent) _wdg_parent_win_reload(parent);
   objtree_item_selected_set(wdg?wdg:parent);
   _editor_wdg_selected_set(wdg?wdg:parent);
   propview_build(wdg?wdg:parent);
}

/* Undo last action */
static Eina_Bool
_editor_undo(const Gui_Context *ctx)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
   const Gui_Memento *memento, *head_memento;
   /* Save head memento for post function. */
   head_memento = memento = gui_context_current_memento_get(ctx);

   while (memento)
     {
        Gui_Memento_Type type = gui_memento_type_get(memento);
        switch (type)
          {
           case MEMENTO_PROPERTY:
                {
                   Gui_Widget_Property *old_prop, *new_prop;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);
                   const Op_Desc *op_desc = NULL;

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   old_prop = gui_memento_old_pointer_get(memento);
                   new_prop = gui_memento_new_pointer_get(memento);
                   /* If last action was 'Drop prop', new_prop is NULL. */
                   if (new_prop)
                     {
                        op_desc = prop_op_desc_get(new_prop);
                        wdg_prop_remove(wdg, new_prop);
                     }

                   propsview_view_switch(PROPERTY_TYPE);
                   if (old_prop)
                     {
                        op_desc = prop_op_desc_get(old_prop);
                        wdg_prop_add(wdg, old_prop);
                        Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
                        manager_widget_property_add(session, wdg, old_prop, MODE_EDITOR, NULL);
                        if (_editor_wdg_selected_get() != wdg)
                          {
                             objtree_item_selected_set(wdg);
                          }
                        propview_item_update(old_prop);
                     }
                   /* If old_property == NULL, need to reload widget. */
                   else
                     {
                        _wdg_parent_win_reload(wdg);
                        objtree_item_selected_set(wdg);
                     }
                   if (op_desc)
                     propview_item_selected_set(op_desc);
                   break;
                }
           case MEMENTO_OBJ_CONTAINER_ITEM:
                {
                   Object_Container *old_container;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   old_container = gui_memento_old_pointer_get(memento);

                   wdg_obj_container_unset(wdg);
                   wdg_obj_container_set(wdg, old_container);
                   break;
                }
           case MEMENTO_ITEM_CONTAINER_ITEM:
                {
                   Item_Container_Item *old_it;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   old_it = gui_memento_old_pointer_get(memento);

                   Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(old_it));
                   dep_data_item_set(dep_data, old_it);
                   break;
                }
           case MEMENTO_CALLBACK:
                {
                   Gui_Widget_Callback *old_cb;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   old_cb = gui_memento_old_pointer_get(memento);
                   Dep_Id *cb_dep_id = cb_dep_id_get(old_cb);

                   Dep_Data *dep_data = gui_context_dep_data_get(cb_dep_id);
                   dep_data_cb_set(dep_data, old_cb);

                   propsview_view_switch(CALLBACK_TYPE);
                   _editor_wdg_selected_set(wdg);
                   cbview_item_selected_set(cb_dep_id);
                   break;
                }
           case MEMENTO_CALLBACK_ADD_DEL:
                {
                   Callback_Container *old_cc;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }
                   old_cc = gui_memento_old_pointer_get(memento);
                   wdg_cb_container_unset(wdg);
                   wdg_cb_container_set(wdg, old_cc);
                   break;
                }
           case MEMENTO_WIDGET:
                {
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);
                   Eina_Bool old_state = (intptr_t) gui_memento_old_pointer_get(memento);
                   _update_widget_on_undoredo(ctx, wdg_id, old_state);
                   break;
                }
           case MEMENTO_NONE:
                {
                   break;
                }
           default:
              ERR("case - default");
          }
        memento = gui_memento_next(memento);
     }

   /* Update propview. */
   _editor_undo_redo_post(head_memento);

   gui_context_memento_prev((Gui_Context *) ctx);

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE);

   return EINA_TRUE;
}

/* Redo last action */
static Eina_Bool
_editor_redo(const Gui_Context *ctx)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
   const Gui_Memento *memento, *head_memento;
   gui_context_memento_next((Gui_Context *) ctx);
   /* Save head memento for post function. */
   head_memento = memento = gui_context_current_memento_get(ctx);

   while (memento)
     {
        Gui_Memento_Type type = gui_memento_type_get(memento);
        switch (type)
          {
           case MEMENTO_PROPERTY:
                {
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);
                   const Op_Desc *op_desc = NULL;

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   Gui_Widget_Property *new_prop, *old_prop;
                   old_prop = gui_memento_old_pointer_get(memento);
                   new_prop = gui_memento_new_pointer_get(memento);

                   if (old_prop)
                     {
                        wdg_prop_remove(wdg, old_prop);
                        op_desc = prop_op_desc_get(old_prop);
                     }

                   propsview_view_switch(PROPERTY_TYPE);
                   if (new_prop)
                     {
                        op_desc = prop_op_desc_get(new_prop);
                        wdg_prop_add(wdg, new_prop);
                        Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
                        manager_widget_property_add(session, wdg, new_prop, MODE_EDITOR, NULL);
                        if (_editor_wdg_selected_get() != wdg)
                          {
                             objtree_item_selected_set(wdg);
                          }
                        propview_item_update(new_prop);
                     }
                   else
                     {
                        _wdg_parent_win_reload(wdg);
                        objtree_item_selected_set(wdg);
                     }
                   if (op_desc)
                     propview_item_selected_set(op_desc);
                   break;
                }
           case MEMENTO_CALLBACK:
                {
                   Gui_Widget_Callback *new_cb;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   new_cb = gui_memento_new_pointer_get(memento);
                   Dep_Id *cb_dep_id = cb_dep_id_get(new_cb);

                   Dep_Data *dep_data = gui_context_dep_data_get(cb_dep_id);
                   dep_data_cb_set(dep_data, new_cb);

                   propsview_view_switch(CALLBACK_TYPE);
                   _editor_wdg_selected_set(wdg);
                   cbview_item_selected_set(cb_dep_id);
                   break;
                }
           case MEMENTO_CALLBACK_ADD_DEL:
                {
                   Callback_Container *new_cc;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }
                   new_cc = gui_memento_new_pointer_get(memento);
                   wdg_cb_container_unset(wdg);
                   wdg_cb_container_set(wdg, new_cc);

                   propsview_view_switch(CALLBACK_TYPE);
                   _editor_wdg_selected_set(wdg);
                   break;
                }
           case MEMENTO_OBJ_CONTAINER_ITEM:
                {
                   Object_Container *new_container;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   new_container = gui_memento_new_pointer_get(memento);

                   wdg_obj_container_unset(wdg);
                   wdg_obj_container_set(wdg, new_container);
                   break;
                }
           case MEMENTO_ITEM_CONTAINER_ITEM:
                {
                   Item_Container_Item *new_it;
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);

                   Gui_Widget *wdg = wdg_get(wdg_id);
                   if (!wdg)
                     {
                        ERR("wdg not found");
                        return EINA_FALSE;
                     }

                   new_it = gui_memento_new_pointer_get(memento);

                   Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(new_it));
                   dep_data_item_set(dep_data, new_it);
                   break;
                }
           case MEMENTO_WIDGET:
                {
                   Dep_Id *wdg_id = gui_memento_wdg_get(memento);
                   Eina_Bool new_state = (intptr_t) gui_memento_new_pointer_get(memento);
                   _update_widget_on_undoredo(ctx, wdg_id, new_state);
                   break;
                }
           case MEMENTO_NONE:
                {
                   break;
                }
           default:
              ERR("case - default");
          }
        memento = gui_memento_next(memento);
     }
   /* Update propview. */
   _editor_undo_redo_post(head_memento);

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE);

   return EINA_TRUE;
}

static void
_editor_undo_redo_post(const Gui_Memento *memento)
{
   Gui_Memento_Type head_memento_type = gui_memento_type_get(memento);
   Gui_Widget *head_memento_wdg = wdg_get(gui_memento_wdg_get(memento));

   switch (head_memento_type)
     {
      case MEMENTO_PROPERTY:
           {
              break;
           }
      case MEMENTO_OBJ_CONTAINER_ITEM:
      case MEMENTO_ITEM_CONTAINER_ITEM:
           {
              propsview_view_switch(CONTENT_TYPE);
              _wdg_parent_win_reload(head_memento_wdg);
              _editor_wdg_selected_set(head_memento_wdg);
              objtree_item_selected_set(head_memento_wdg);
              break;
           }
      case MEMENTO_CALLBACK:
           {
              break;
           }
      case MEMENTO_CALLBACK_ADD_DEL:
           {
              propsview_view_switch(CALLBACK_TYPE);
              _editor_wdg_selected_set(head_memento_wdg);
              break;
           }
      case MEMENTO_WIDGET:
           {
              break;
           }
      case MEMENTO_NONE:
           {
              break;
           }
      default:
         ERR("case - default");
     }
}

static Eina_Bool
_editor_ctx_call(const Gui_Context *ctx)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);

   Eina_List *list, *l;
   Dep_Id *wdg_id;

   /* in editor, we iterate only over windows which don't have parent. */
   list = gui_context_main_widgets_get(ctx);
   EINA_LIST_FOREACH(list, l, wdg_id)
     {
        Gui_Widget *wdg = wdg_get(wdg_id);
        if (!wdg) continue;
        /* if window has parent widget, it will be iterated as child*/
        if (wdg_parent_get(wdg))
          {
             ERR("Window: \"%s\" has parent. It should not happen. We have bug!", wdg_name_get(wdg));
             continue;
          }

        /* All windows should be shown in main gui window. */
        _iter_widget_create(wdg, canvas_get());
     }
   /* During context call _win_resize() will be called.
    * It will draw border around win, but widget was not selected yet.
    * So need to hide border. */
   _editor_wdg_selected_set(NULL);
   propview_build(NULL);
   objtree_item_selected_set(NULL);

   return EINA_TRUE;
}

static void
_editor_selected_wdg_del_cb()
{
   Gui_Widget *wdg = (Gui_Widget *) _editor_wdg_selected_get();
   Gui_Context *ctx = _active_context_get();
   if (!wdg) return;
   const Gui_Widget *parent_wdg = wdg_parent_get((Gui_Widget *) wdg);
   _editor_wdg_selected_set(NULL);
   _editor_widget_clear(wdg);

   gui_context_dep_data_active_set(ctx, wdg_dep_id_get(wdg), EINA_FALSE);
   Gui_Memento *memento;
   memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_WIDGET,  (void *) (intptr_t) EINA_TRUE, (void *) (intptr_t) EINA_FALSE);
   gui_context_memento_add((Gui_Context *) ctx, memento);

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   /* if parent_wdg is not NULL, it's not window, so it has parent.
    * if parent wdg is NULL, wdg is window, so just delete it. */
   if (parent_wdg)
     {
        _wdg_parent_win_reload(parent_wdg);
     }
   else
     {
        _wdg_parent_win_reload(wdg);
     }
   propview_build(NULL);

   /* Set selected widget: t.e. if I delete button, box will be selected after.
    * If I delete window, main item will be selected. */
   objtree_item_selected_set(parent_wdg);
   _editor_wdg_selected_set(parent_wdg);
}

static void
_editor_factory_wdg_create(const char *class_name, const Gui_Widget *focused_wdg)
{
   const Gui_Widget *parent_win = NULL;
   const char *parent_name = NULL;
   Gui_Widget *wdg;
   const Gui_Context *ctx = _active_context_get();
   Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);

   if (!ctx)
     {
        ERR("No active context");
        return;
     }

   char *new_name = gui_context_free_name_get(ctx, class_name);

   Dep_Id *dep_id = gui_context_dep_data_set(ctx, new_name, DEP_TYPE_WIDGET);
   wdg = wdg_new((Gui_Context *) ctx, class_name, dep_id);
   free(new_name);

   /* If a widget is selected during creation */
   if (focused_wdg)
     {
        parent_win = wdg_main_wdg_get(focused_wdg);
        /* FIXME: We have to check the parent validity. This is not fully operational.
         * What happens is that button, check... can be containers and so be considered
         * as parents. We need to find a way to forbid that.
         */
        if (IS_WIN(wdg) || (!IS_WIN(parent_win) && !IS_CONTAINER(parent_win))) parent_win = NULL;
        else parent_name = wdg_name_get(parent_win);
     }

   wdg_parent_set(wdg, parent_name);

   Gui_Memento *memento;
   memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_WIDGET,  (void *) (intptr_t) EINA_FALSE, (void *) (intptr_t) EINA_TRUE);
   gui_context_memento_add((Gui_Context *) ctx, memento);

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   /*Add default visibility property*/
   Gui_Widget_Property *prop;
   Gui_Value *val;
   Op_Desc *op;

   if (IS_WIN(wdg))
     {
        /* By default, the window is created in the first action */
        Dep_Id *seq_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR);
        if (!seq_id)
          {
             Gui_Resource *gui_res = gui_context_resource_new((Gui_Context *) ctx, RESOURCE_SEQUENCE, BIGBANG_STR);
             if (!gui_res)
               {
                  ERR("Cannot create resource of type: %d", RESOURCE_SEQUENCE);
               }
             resource_value_set(gui_res, BIGBANG_STR);
             seq_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR);
          }
        Gui_Sequence *seq = sequence_get(seq_id);
        /* Generate BigBand action if does not exist */
        if (!seq)
          {
             seq = sequence_new(ctx, seq_id);
          }
        Gui_Action *action = action_new(seq);
        action_creation_set(action, wdg_dep_id_get(wdg));
        seqview_fill(ctx);

        wdg_data_set(wdg, CONSTRUCTOR, strdup(ELM_OBJ_WIN_CONSTRUCTOR));
        op = db_mro_op_desc_get(class_name, DB_DEF_WIN_CLASS, ELM_OBJ_WIN_CONSTRUCTOR);
        prop = prop_create_for_op(op);
        val = prop_value_nth_get(prop, 0);
        gui_value_string_set(val, NULL);
        val = prop_value_nth_get(prop, 1);
        gui_value_string_set(val, strdup("ELM_WIN_BASIC"));
        wdg_prop_add(wdg, prop);

        op = db_mro_op_desc_get(class_name, DB_DEF_WIN_CLASS, TITLE_SET);
        prop = prop_create_for_op(op);
        val = prop_value_nth_get(prop, 0);
        gui_value_string_set(val, strdup(dep_name_get(wdg_dep_id_get(wdg))));
        wdg_prop_add(wdg, prop);
     }
   else
     {
        op = db_mro_op_desc_get(class_name, DB_DEF_WIDGET_CLASS, PART_TEXT_SET);
        prop = prop_create_for_op(op);
        val = prop_value_nth_get(prop, 0);
        gui_value_string_set(val, NULL);
        val = prop_value_nth_get(prop, 1);
        gui_value_string_set(val, strdup(wdg_name_get(wdg)));
        wdg_prop_add(wdg, prop);
     }

   // Set default property values
   Eina_List *kl_list = eo_class_mro_get(class_name), *itr;
   const char *kl_name;

   EINA_LIST_REVERSE_FOREACH(kl_list, itr, kl_name)
     {
        const Eina_List *defaults = db_default_prop_values_get(kl_name);
        const Eina_List  *l = NULL;
        Gui_Widget_Property *defprop = NULL;
        EINA_LIST_FOREACH(defaults, l, defprop)
          {
             Gui_Widget_Property *newprop = prop_copy(defprop);
             wdg_prop_add(wdg, newprop);
          }
     }
   eina_list_free(kl_list);

   Eo *pw = NULL;
   if (!parent_win) pw = (Eo *)canvas_get();
   manager_widget_create(session, wdg, MODE_EDITOR, pw);

   _editor_wdg_selected_set(wdg);
   objtree_item_selected_set(wdg);
   manager_widget_configure(session, wdg, MODE_EDITOR, NULL);

   /* PoC: add main menu to each window. */
   if (IS_WIN(wdg))
     {
        char menu_name[20] = {'\0'};
        sprintf(menu_name, "%s_%s", wdg_name_get(wdg), "main_menu");
        dep_id = gui_context_dep_data_set(ctx, menu_name, DEP_TYPE_WIDGET);

        Gui_Widget *mmenu = wdg_new((Gui_Context *) ctx, DB_DEF_MENU_CLASS, dep_id);
        wdg_parent_set(mmenu, wdg_name_get(wdg));

        manager_widget_create(session, mmenu, MODE_EDITOR, NULL);
        manager_widget_configure(session, mmenu, MODE_EDITOR, NULL);
     }
}

void
editor_shutdown()
{
   target_db_shutdown();
   seqview_shutdown();
   propview_shutdown();
   itemview_shutdown();
   objtree_list_unset();

   void *p = (void *) propview_cbs_get();
   free(p);
   p = (void *) guilogic_cbs_get();
   free(p);
   p = (void *) objtree_cbs_get();
   free(p);
   p = (void *) itemview_cbs_get();
   free(p);
}

static void
_wdg_update(void *data, Dep_Id *subject_id EINA_UNUSED)
{
   _wdg_parent_win_reload(data);
}

/* onChange callback for all properties edit fields.
 * If currently there is no such property in the widget, it will be added.
 * The given object is the one created in the properties view for each parameter.
 */
static Eina_Bool
_prop_update_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
   Par_Field_Data *pfd = NULL;
   const Eo_Class *kl = eo_class_get(obj);
   const Op_Desc *op;
   const Gui_Widget *wdg;
   Gui_Widget_Property *prop, *old_property = NULL;
   int idx;
   Gui_Value *val;
   Eina_Bool reload_win = EINA_FALSE;
   Gui_Context *ctx = _active_context_get();

   /* Get data for changed field. */
   eo_do(obj, pfd = eo_key_data_get(_STR_EDITOR));
   op = pfd->it_data->op_desc;
   wdg = pfd->it_data->wdg;
   prop = (Gui_Widget_Property *)pfd->it_data->prop;
   idx = pfd->par_idx;
   /* propdata box, change its color then value changed from default. */
   Eo *box = pfd->it_data->box;

   /* If property doesn't exist, create it with some default values. */
   if (!prop)
     {
        ERR("this can not happen");
        prop = prop_create_for_op(op);
        /* Raise flag, that property is newly created and must be added to widget. */
        eo_do(box, evas_obj_color_set(255, 255, 255, 255));
     }

   /* Save old property to be able to add it to UndoRedo stack. */
   old_property = prop;
   /* Every time value is changed, crete new property. */
   prop = prop_copy(prop);

   /* Get value which need to be changed.*/
   val = prop_value_nth_get(prop, idx);

   /* Get new value from edit field.
    * And update Gui_Value with new value. */
   Gui_Type type = db_op_desc_nth_par_type_get(op, idx);
   if (kl == ELM_ENTRY_CLASS)
     {
        const char *entry_data = elm_entry_entry_get(obj);
        if (type == GUI_TYPE_STRING)
          {
             /* FIXME: part_text_set can receive NULL as parameter.
              * But because of this, I can't write "null"*/
             if (!strcmp(entry_data, ""))
               {
                  gui_value_string_free(val);
                  gui_value_string_set(val, NULL);
               }
             else
               {
                  gui_value_string_free(val);
                  gui_value_string_set(val, strdup(entry_data));
               }
          }
        else if (type == GUI_TYPE_SINT)
          {
             int number = atoi(entry_data);
             gui_value_int_set(val, number);
          }
        else if (type == GUI_TYPE_DOUBLE)
          {
             double number = atof(entry_data);
             gui_value_double_set(val, number);
          }
     }
   if (kl == ELM_CHECK_CLASS)
     {
        Eina_Bool state;
        eo_do(obj, state = elm_obj_check_state_get());
        gui_value_bool_set(val, state);
     }
   if (kl == ELM_HOVERSEL_CLASS)
     {
        const char *new_enum_value = elm_object_item_part_text_get(event_info, NULL);
        const char *old_enum_value = NULL;
        eo_do(obj, old_enum_value = elm_obj_widget_part_text_get(NULL));

        /* An old value can be null, when changing default property. */
        if (old_enum_value && !strcmp(old_enum_value, new_enum_value))
          {
             /* Delete property, which was created before. It won't be used. */
             prop_ref(prop);
             prop_unref(prop);
             goto end;
          }
        /* Get new value depending on type of edit field.
         * And update value. */
        if (type == GUI_TYPE_ENUM)
          {
             gui_value_string_free(val);
             gui_value_enum_set(val, strdup(new_enum_value));
          }
        /* FIXME: there is problem with content_set; because prev content must be unset; or need to redraw from the beginning*/
        else if (type == GUI_TYPE_OBJECT)
          {
             Dep_Id *old_dep_id = DEP_ID_GET(val);
             Dep_Id *new_dep_id = gui_context_dep_id_by_name_get(ctx, new_enum_value);
             if (!new_dep_id)
               {
                  ERR("Resource not exist for: \"%s\"", new_enum_value);
               }
             /* FIXME: need to check if widget wasn't deleted yet*/
             const char *cur_param = old_dep_id ? dep_name_get(old_dep_id) : NULL;
             Gui_Widget *cur_param_wdg = wdg_get(old_dep_id);
             Gui_Widget *new_param_wdg = wdg_get(new_dep_id);
             /* GUI_TYPE_OBJECT ops depend on other widgets, check that widget exists.
              * or new one not equal old one.*/
             if ((!new_param_wdg) || (cur_param_wdg == new_param_wdg))
               {
                  ERR("I don't know the usecase when it comes here. So if you see this, check.");
                  goto end;
               }
             /* If I simply change value in prop: t.e. "but1"->"but2" change parent of "but1".*/
             /* and change dependencies. */
             gui_value_name_id_set(val, type, new_dep_id);

             if (cur_param) reload_win = EINA_TRUE;
          }
        else if (type == GUI_TYPE_FILE)
          {
             Dep_Id *old_dep_id = DEP_ID_GET(val);
             if (old_dep_id) gui_context_dep_observer_del(old_dep_id, _wdg_update, (void *)wdg);
             if (!strcmp(new_enum_value, PROP_HOVERSEL_NONE_VALUE))
               {
                  gui_value_name_id_set(val, type, 0);
               }
             else
               {
                  Dep_Id *new_id = gui_context_dep_id_by_name_get(ctx, new_enum_value);
                  gui_context_dep_observer_add(new_id, _wdg_update, (void *)wdg);
                  gui_value_name_id_set(val, type, new_id);
               }
             reload_win = EINA_TRUE;
          }
        else
          {
             ERR("Type '%s' is not handled in HOVERSEL", db_gui_type_name_get(type));
          }

        /* Set selected string on hover */
        eo_do(obj, elm_obj_widget_part_text_set(NULL, new_enum_value));
     }

   Gui_Memento *memento = NULL;
   /* If new property was previously assigned to widget, delete it from widget.
    * I need to write gui_memento_new twice, because wdg_prop_remove will do unref and prop will be deleted. */
   if (prop_wdg_get(old_property))
     {
        memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_PROPERTY, old_property, prop);
        wdg_prop_remove((Gui_Widget *) wdg, old_property);
     }
   /* If not, this prop is default property which was fetched from _ffi_eo_do, don't need to save it,
    * but need to make it white.
    * This happens only when value is changed for the first time. */
   else
     {
        eo_do(box, evas_obj_color_set(255, 255, 255, 255));
        prop_ref(old_property);
        prop_unref(old_property);
        old_property = NULL;
        memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_PROPERTY, old_property, prop);
     }
   gui_context_memento_add(ctx, memento);

   /* Assign new prop to widget */
   wdg_prop_add((Gui_Widget *) wdg, prop);
   /* Save new prop in item. */
   pfd->it_data->prop = prop;

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   /* Validate property and call for eo_func of current prop,
    * in order to update layout. */
   if (reload_win)
     {
        _wdg_parent_win_reload(wdg);
        propview_build(NULL);
        _editor_wdg_selected_set(wdg);
        objtree_item_selected_set(wdg);
     }
   else
     {
        /* Don't do anything with win if prop is VISIBILITY*/
        if (IS_MAIN(wdg) && (!strcmp(prop_name_get(prop), VISIBILITY_SET)))
          {
          }
        else
          {
             Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
             manager_widget_property_add(session, wdg, prop, MODE_EDITOR, NULL);
          }
     }
   return EO_CALLBACK_CONTINUE;
   /* FIXME: add return here? */
end:
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_prop_del_from_propview(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *ev EINA_UNUSED)
{
   const Gui_Widget *wdg = _editor_wdg_selected_get();
   Gui_Widget_Property *prop = data;

   wdg_prop_remove((Gui_Widget *) wdg, prop);

   _wdg_parent_win_reload(wdg);

   propview_build(NULL);

   _editor_wdg_selected_set(wdg);
   objtree_item_selected_set(wdg);
   return EO_CALLBACK_CONTINUE;
}

/* Callback to dissmiss "Drop Property" ctxpopup */
static void
_ctxpopup_dismissed(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   eo_del(obj);
}

/* Callback which will be called, when "Drop Property" clicked. */
static void
_drop_property_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   It_Data *it_data = data;
   Gui_Widget_Property *prop = (Gui_Widget_Property *) it_data->prop;
   Gui_Context *ctx = _active_context_get();
   if (prop)
     {
        const Gui_Widget *wdg = prop_wdg_get(prop);
        if (wdg)
          {
             Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_PROPERTY, prop, NULL);
             gui_context_memento_add(ctx, memento);

             elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
             elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

             wdg_prop_remove((Gui_Widget *) wdg, (Gui_Widget_Property *) prop);
             _wdg_parent_win_reload(wdg);
             propview_build(NULL);
             _editor_wdg_selected_set(wdg);
             objtree_item_selected_set(wdg);
          }
     }
   eo_do(obj, elm_obj_ctxpopup_dismiss());
}

/* callback to provide Context menu, when "..." button clicked for property. */
static Eina_Bool
_prop_ctx_menu_cb_func(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   It_Data *it_data;
   Elm_Object_Item *it = NULL;
   eo_do(obj, it_data = eo_key_data_get(_STR_EDITOR));

   Eo *ctxpopup = elm_ctxpopup_add(g->main_win->propsview_table);
   evas_object_smart_callback_add(ctxpopup, "dismissed", _ctxpopup_dismissed, NULL);
   it = elm_ctxpopup_item_append(ctxpopup, "Drop Property", NULL, _drop_property_cb, it_data);
   /* If property not connected to widget, this is default property so can not be dropped. */
   if (it_data->prop && !prop_wdg_get(it_data->prop))
     {
        elm_object_item_disabled_set(it, EINA_TRUE);
     }
   Evas_Coord x, y;
   eo_do(evas_object_evas_get(g->main_win->main_win), evas_canvas_pointer_canvas_xy_get(&x, &y));
   eo_do(ctxpopup, evas_obj_size_hint_max_set(240, 240));
   eo_do(ctxpopup, evas_obj_position_set(x, y));
   eo_do(ctxpopup, evas_obj_visibility_set(EINA_TRUE));

   return EO_CALLBACK_CONTINUE;
}

/************************ Itemview Callbacks *******************************/

/* Callback to update item's 'public' state*/
static Eina_Bool
_item_public_update_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eina_Bool state;
   const Gui_Context *ctx = _active_context_get();
   Gui_Widget *wdg = (Gui_Widget *) _editor_wdg_selected_get();

   Item_Container_Item *item = data, *new_item;
   eo_do(obj, state = elm_obj_check_state_get());
   new_item = item_container_item_copy(item);
   item_container_item_public_set(new_item, state);

   Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(item));

   Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, item, new_item);
   gui_context_memento_add((Gui_Context *) ctx, memento);

   dep_data_item_set(dep_data, new_item);

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);
   return EO_CALLBACK_CONTINUE;
}

/* Callback to update item's label and callback */
static Eina_Bool
_field_update_from_itemview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Par_Field_Data *pfd = NULL;
   const Eo_Class *kl = eo_class_get(obj);
   const Op_Desc *op;
   const Gui_Widget *wdg = _editor_wdg_selected_get();
   const Gui_Context *ctx = _active_context_get();
   const Item_Container_Item *wit;
   Item_Container_Item *new_wit;
   const Gui_Widget_Property *prop, *new_prop;
   int idx;
   Gui_Value *val;

   /* Get data for changed field. */
   eo_do(obj, pfd = eo_key_data_get(_STR_EDITOR));
   op = pfd->it_data->op_desc;
   wit = pfd->it_data->item;
   idx = pfd->par_idx;
   prop = pfd->it_data->prop;

   /* Copy item with old property. Property inside item will be ref()ed*/
   new_wit = item_container_item_copy(wit);
   /* Copy property */
   new_prop = prop_copy(prop);
   /* Assign property to item, old property will be unref()ed. */
   item_container_item_prop_set(new_wit, new_prop);

   /* Create memento. */
   Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(wit));
   Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, (void *) wit, new_wit);
   gui_context_memento_add((Gui_Context *) ctx, memento);

   /* Change item in Dep_Data*/
   dep_data_item_set(dep_data, new_wit);

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   /* Get value which need to be changed.*/
   val = prop_value_nth_get(new_prop, idx);

   /* Get new value from edit field.
    * And update Gui_Value with new value. */
   Gui_Type type = db_op_desc_nth_par_type_get(op, idx);
   if (kl == ELM_ENTRY_CLASS)
     {
        const char *entry_data = elm_entry_entry_get(obj);
        if (type == GUI_TYPE_STRING)
          {
             gui_value_string_free(val);
             gui_value_string_set(val, strdup(entry_data));

             /* Reloading all window. */
             _wdg_parent_win_reload(wdg);
             propview_build(NULL);
             _editor_wdg_selected_set(wdg);
             objtree_item_selected_set(wdg);
             itemview_item_selected_set(new_wit);
          }
     }
   /* Currently hoversel is used only for callback name
    * and Object of icon*/
   if (kl == ELM_HOVERSEL_CLASS)
     {
        const char *old_value;
        eo_do(obj, old_value = elm_obj_widget_part_text_get(NULL));
        const char *new_value = elm_object_item_part_text_get(event_info, NULL);
        if (!strcmp(new_value, old_value))
          return EO_CALLBACK_CONTINUE;
        eo_do(obj, elm_obj_widget_part_text_set(NULL, new_value));
        if (!strcmp(new_value, PROP_HOVERSEL_NONE_VALUE))
          {
             gui_value_name_id_set(val, type, 0);
          }
        else
          {
             Dep_Id *name_id = gui_context_dep_id_by_name_get(_active_ctx, new_value);
             gui_value_name_id_set(val, type, name_id);
          }
     }
   return EO_CALLBACK_CONTINUE;
}

static void
_itemview_item_selected(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   const Gui_Context *ctx = _active_context_get();
   Item_Container_Item *wit  = item_container_item_get((Dep_Id *)elm_object_item_data_get(event_info));
   Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
   Elm_Object_Item *menu_it = session_item_get(session, wit);
   elm_menu_item_selected_set(menu_it, EINA_TRUE);
}

static Eina_Bool
_itemview_item_do_(unsigned int type)
{
   static int i = -1;
   i++;
   Item_Container_Item *wit = NULL, *parent_it = NULL;
   Item_Container_Item *new_parent_item = NULL;
   Gui_Widget *wdg = (Gui_Widget *) _editor_wdg_selected_get();
   const Gui_Context *ctx = wdg_context_get(wdg);
   Gui_Value *val = NULL;

   Dep_Id *selected_item_id = itemview_item_selected_get();
   wit = item_container_item_get(selected_item_id);

   Item_Container_Item *it = NULL;
   if ((type == ITEM_ADD) || (type == ITEM_ADD_NESTED) || (type == SEPARATOR_ADD))
     {
        if (wit)
          {
             /* If adding item, new item will have the same parent. */
             if ((type == ITEM_ADD) || (type == SEPARATOR_ADD))
               {
                  parent_it = (Item_Container_Item *) item_container_item_parent_item_get(wit);
               }
             else
               {
                  /* If adding nested item, current item will be the parent. */
                  parent_it = wit;
                  wit = NULL;
               }
          }
        else
          {
             parent_it = (Item_Container_Item *) wdg_item_container_root_get(wdg);
          }

        /* create Id for new parent item. */
        new_parent_item = item_container_item_copy(parent_it);
        Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(parent_it));

        Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item);
        gui_context_memento_add((Gui_Context *) ctx, memento);

        dep_data_item_set(dep_data, new_parent_item);

        Op_Desc *op = (Op_Desc *) db_container_desc_op_desc_get(db_container_desc_get(wdg_class_name_get(wdg)), CONTAINER_PACK);
        Gui_Widget_Property *prop = prop_create_for_op(op);

        char str[NAME_MAX] = {'\0'};
        sprintf(str, "%s_%s%d", wdg_name_get(wdg), "it", i);
        /* Check that newly generated name is not used. */
        while (gui_context_dep_id_by_name_get(ctx, str))
          {
             i++;
             sprintf(str, "%s_%s%d", wdg_name_get(wdg), "it", i);
          }

        if (type == SEPARATOR_ADD)
          {
             it = item_container_item_new(ctx, ITEM_SEPARATOR, prop, str);
             sprintf(str, "%s", "Separator");
          }
        else
          {
             it = item_container_item_new(ctx, ITEM_REGULAR, prop, str);
             sprintf(str, "%s %d", "New Item", i);
          }

        /* Assign label "New Item" to new item*/
        if (!strcmp(wdg_class_name_get(wdg), DB_DEF_MENU_CLASS))
          {
             val = prop_value_nth_get(prop, 0);
             Dep_Id *new_parent_dep_id = new_parent_item ? item_container_item_dep_id_get(new_parent_item) : 0;
             gui_value_name_id_set(val, GUI_TYPE_OBJECT_ITEM, new_parent_dep_id);

             val = prop_value_nth_get(prop, 2);
             gui_value_string_set(val, strdup(str));
          }
        else if (!strcmp(wdg_class_name_get(wdg), DB_DEF_DISKSELECTOR_CLASS) ||
                 !strcmp(wdg_class_name_get(wdg), DB_DEF_CTXPOPUP_CLASS) ||
                 !strcmp(wdg_class_name_get(wdg), DB_DEF_NAVIFRAME_CLASS))
          {
             val = prop_value_nth_get(prop, 0);
             gui_value_string_set(val, strdup(str));
          }
        else if (!strcmp(wdg_class_name_get(wdg), DB_DEF_TOOLBAR_CLASS))
          {
             val = prop_value_nth_get(prop, 1);
             gui_value_string_set(val, strdup(str));
          }
     }
   else if (type == ITEM_DELETE)
     {
        if (!wit) return EINA_FALSE;
        parent_it = (Item_Container_Item *) item_container_item_parent_item_get(wit);

        new_parent_item = item_container_item_copy(parent_it);
        Dep_Data *dep_data = gui_context_dep_data_get(item_container_item_dep_id_get(parent_it));

        Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_ITEM_CONTAINER_ITEM, parent_it, new_parent_item);
        gui_context_memento_add((Gui_Context *) ctx, memento);

        dep_data_item_set(dep_data, new_parent_item);
     }

   /* Adding item to widget and parent item
    * If some item is selected and we add item, we add it after. */
   if (type == ITEM_DELETE)
     {
        itemview_item_del(wit);
        wdg_item_remove(selected_item_id);
     }
   else
     {
        wdg_item_insert_after(wdg, new_parent_item, wit, it);
        /* Insert 'it' after selected 'wit' in the Items List.
         * if wit == NULL, item will be added in the end. */
        itemview_insert_after(item_container_item_dep_id_get(parent_it),
                              item_container_item_dep_id_get(wit),
                              item_container_item_dep_id_get(it));
     }

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   _wdg_parent_win_reload(wdg);
   propview_build(NULL);
   _editor_wdg_selected_set(wdg);
   objtree_item_selected_set(wdg);
   itemview_item_selected_set(it);

   return EO_CALLBACK_CONTINUE;
}

/************************ Content view Callbacks *******************************/

/* Called when X button is pressed to delete item from container. */
static Eina_Bool
_content_del_from_propview(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   const Gui_Widget *wdg = _editor_wdg_selected_get();
   intptr_t idx = (intptr_t) data;
   Gui_Context *ctx = _active_context_get();

   /* Need to remove parent container from widget. */
   Object_Container_Item *ci = wdg_obj_container_item_get(wdg, idx, NULL);
   Dep_Id *name_id = obj_container_item_dep_id_get(ci);

   Gui_Widget *param_wdg = wdg_get(name_id);
   /* Need to change parent for content being unset from container.
    * Set parent window as parent for widget. */
   if (param_wdg)
     {
        const Gui_Widget *parent_win = wdg_main_wdg_get(param_wdg);
        /* Do it to update list. */
        wdg_parent_set(param_wdg, wdg_name_get(parent_win));
        objtree_item_selected_set(wdg);
     }
   Object_Container *_old_container, *_new_container;
   _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg);
   _new_container = obj_container_copy(_old_container);

   Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
   gui_context_memento_add(ctx, memento);

   wdg_obj_container_unset((Gui_Widget *) wdg);
   wdg_obj_container_set((Gui_Widget *) wdg, _new_container);

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   /* Delete content from container data. */
   wdg_obj_container_item_remove(wdg, ci);
   /* Reload window when unpacking something. */
   _wdg_parent_win_reload(wdg);
   _editor_wdg_selected_set(wdg);
   objtree_item_selected_set(wdg);

   return EO_CALLBACK_CONTINUE;
}

/* Called when Up/Down buttons are pressed to reorder contents of box*/
static Eina_Bool
_content_reorder_from_propview(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
   const Gui_Widget *wdg = _editor_wdg_selected_get();
   intptr_t idx = (intptr_t) data;
   intptr_t button_dir = (intptr_t)event_info;

   if (wdg_obj_container_class_name_get(wdg) &&
        (!strcmp(wdg_obj_container_class_name_get(wdg), DB_DEF_BOX_CLASS) ||
         !strcmp(wdg_obj_container_class_name_get(wdg), DB_DEF_WIN_CLASS)))
     {
        Object_Container *_old_container, *_new_container;
        _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg);
        _new_container = obj_container_copy(_old_container);

        obj_container_ref(_old_container);
        wdg_obj_container_unset((Gui_Widget *) wdg);
        wdg_obj_container_set((Gui_Widget *) wdg, _new_container);

        /* If anything was reordered, need to reload content. */
        if (wdg_obj_container_content_reorder(wdg, idx, button_dir))
          {
             Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
             gui_context_memento_add(_active_context_get(), memento);

             elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
             elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

             /* Reload all the win when content reordered */
              _wdg_parent_win_reload(wdg);
             /* Update propview. */
             _editor_wdg_selected_set(wdg);
             objtree_item_selected_set(wdg);
          }
        obj_container_unref(_old_container);
     }
   return EO_CALLBACK_CONTINUE;
}

/* Called when different element is choosen in hooversel */
static Eina_Bool
_content_change_from_propview(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Context *ctx = _active_context_get();
   Par_Field_Data *pfd = NULL;
   const Eo_Class *kl = eo_class_get(obj);
   /* Get data for changed field. */
   eo_do(obj, pfd = eo_key_data_get(_STR_EDITOR));

   const Gui_Widget *wdg = pfd->it_data->wdg;
   int par_idx = pfd->par_idx;
   Gui_Value *val = NULL;
   Gui_Type type = GUI_TYPE_NONE;
   Gui_Widget_Property *prop, *new_prop;

   /* in it_data we save CONTENT_PACK op_id. */
   const Op_Desc *op_desc = pfd->it_data->op_desc;
   const char *container_class_name = db_op_desc_class_name_get(op_desc);

   /* Get nth property by index. */
   Object_Container_Item *ci = wdg_obj_container_item_get(wdg, pfd->it_data->idx, NULL);

   /* No values_lst means we are adding new element.
    * And if first input is not object, go away. */
   if ((!ci) && (kl != ELM_HOVERSEL_CLASS))
     return EO_CALLBACK_CONTINUE;

   /* Initial check for Hoversel case. */
   if (kl == ELM_HOVERSEL_CLASS)
     {
        const char *old_value;
        const char *new_value = elm_object_item_part_text_get(event_info, NULL);
        eo_do(obj, old_value = elm_obj_widget_part_text_get(NULL));
        if (!strcmp(new_value, old_value))
          return EO_CALLBACK_CONTINUE;
     }

   /* Initial check for part name for "Container"*/
   if ((kl == ELM_ENTRY_CLASS) &&
       (!strcmp(container_class_name, DB_DEF_CONTAINER_CLASS)))
     {
        const char *entry_data;
        eo_do(obj, entry_data = elm_obj_layout_text_get(NULL));
        Object_Container_Item *oci = wdg_obj_container_item_get(wdg, pfd->it_data->idx, NULL);
        Gui_Widget_Property *pr = oci ? obj_container_item_prop_get(oci) : NULL;
        Gui_Value *v = prop_value_nth_get(pr, par_idx);
        if (_has_part(wdg, entry_data, NULL))
          {
             char *str = STRING_GET(v);
             eo_do(obj, elm_obj_layout_text_set(NULL, str));
             return EO_CALLBACK_CONTINUE;
          }
     }

   /* No way back from here, so copy container.*/
   Object_Container *_old_container, *_new_container;
   _old_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) wdg);
   _new_container = obj_container_copy(_old_container);

   Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_OBJ_CONTAINER_ITEM, _old_container, _new_container);
   gui_context_memento_add(ctx, memento);
   gui_memento_append(NULL, memento);

   wdg_obj_container_unset((Gui_Widget *) wdg);
   wdg_obj_container_set((Gui_Widget *) wdg, _new_container);

   /* Take prop from new_container. */
   ci = wdg_obj_container_item_get(wdg, pfd->it_data->idx, NULL);
   prop = ci ? obj_container_item_prop_get(ci) : NULL;

   if (prop)
     {
        new_prop = prop_copy(prop);
     }
   else
     {
        new_prop = prop_create_for_op(op_desc);
        unsigned int i, param_count = db_op_desc_param_number_get(op_desc);
        for (i = 0; i < param_count; i++)
          {
             val = prop_value_nth_get(new_prop, i);
             /*These parameters for table must be > 0 */
             if (wdg_obj_container_class_name_get(wdg) &&
                 !strcmp(wdg_obj_container_class_name_get(wdg), DB_DEF_TABLE_CLASS) && (i >= 3))
               {
                  ERR("Fix container_class_name");
                  int x = 1;
                  gui_value_int_set(val, x);
               }
          }
     }

   val = prop_value_nth_get(new_prop, par_idx);
   type = db_op_desc_nth_par_type_get(op_desc, par_idx);
   if (kl == ELM_ENTRY_CLASS)
     {
        const char *entry_data;
        eo_do(obj, entry_data = elm_obj_layout_text_get(NULL));
        Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);

        /* Run CONTENT_PACK for table in order to reset with new coordinates. */
        if (!strcmp(container_class_name, DB_DEF_TABLE_CLASS))
          {
             int number = atoi(entry_data);
             /* Value can't be less then 1 for width and height params. */
             if ((par_idx >= 3) && (number < 1))
               {
                  char str[12];
                  number = INT_GET(val);
                  sprintf(str, "%d", number);
                  eo_do(obj, elm_obj_layout_text_set(NULL, str));
               }
             gui_value_int_set(val, number);

             Dep_Id *dep_id = obj_container_item_dep_id_get(ci);
             wdg_obj_container_item_remove(wdg, ci);

             ci = obj_container_item_new(new_prop, dep_id);
             wdg_obj_container_item_add((Gui_Widget *) wdg, ci, pfd->it_data->idx);
             manager_widget_content_reset(session, wdg, new_prop, MODE_EDITOR, NULL);
          }

        if (!strcmp(container_class_name, DB_DEF_CONTAINER_CLASS))
          {
             if (!_has_part(wdg, entry_data, NULL))
               {
                  /* Empty string "" - will be set as NULL.*/
                  if (!strcmp(entry_data, ""))
                    {
                       gui_value_string_free(val);
                       gui_value_string_set(val, NULL);
                    }
                  else
                    {
                       gui_value_string_free(val);
                       gui_value_string_set(val, strdup(entry_data));
                    }
                  Dep_Id *dep_id = obj_container_item_dep_id_get(ci);
                  wdg_obj_container_item_remove(wdg, ci);

                  ci = obj_container_item_new(new_prop, dep_id);
                  wdg_obj_container_item_add((Gui_Widget *) wdg, ci, pfd->it_data->idx);

                  /* FIXME: Hack. I need to reload window, because there are clashes in when part name is NULL.
                   * Check ToDo. */
                  _wdg_parent_win_reload(wdg);
                  _editor_wdg_selected_set(wdg);
                  objtree_item_selected_set(wdg);
               }
          }
     }

   /* Hoversel is used mainly to choose objects.
    * So here need to make most of the work on objects: adding, change dependencies, change parent, etc. */
   if (kl == ELM_HOVERSEL_CLASS)
     {
        const char *new_value = elm_object_item_part_text_get(event_info, NULL);
        Dep_Id *new_name_id = gui_context_dep_id_by_name_get(ctx, new_value);
        eo_do(obj, elm_obj_widget_part_text_set(NULL, new_value));

        if (type == GUI_TYPE_ENUM)
          {
             gui_value_string_free(val);
             gui_value_enum_set(val, strdup(new_value));
          }
        if (type == GUI_TYPE_OBJECT)
          {
             Gui_Widget *new_param_wdg = wdg_get(new_name_id);

             /* Check if new_widget was packed previously: take it's parent and check
              * if widget is packed into it's parent.
              * If so, we need to unpack widget and delete from contents*/
             Gui_Widget *prev_wdg_container = (Gui_Widget *) wdg_parent_get(new_param_wdg);
             if (!wdg_obj_container_item_get(prev_wdg_container, -1, new_value))
               prev_wdg_container = NULL;

             Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
             if (prev_wdg_container)
               {
                  Object_Container *_old_prev_container, *_new_prev_container;
                  _old_prev_container = (Object_Container *) wdg_obj_container_get((Gui_Widget *) prev_wdg_container);
                  _new_prev_container = obj_container_copy(_old_prev_container);

                  Gui_Memento *memento_next = gui_memento_new(wdg_dep_id_get(prev_wdg_container),
                                                              MEMENTO_OBJ_CONTAINER_ITEM,
                                                              _old_prev_container, _new_prev_container);
                  gui_memento_append(memento, memento_next);
                  wdg_obj_container_unset((Gui_Widget *) prev_wdg_container);
                  wdg_obj_container_set((Gui_Widget *) prev_wdg_container, _new_prev_container);


                  /* Take old container's class name from content-property. */
                  Object_Container_Item *_ci = wdg_obj_container_item_get(prev_wdg_container, -1, new_value);
                  Gui_Widget_Property *old_prop = obj_container_item_prop_get(_ci);

                  const Op_Desc *old_op_desc = prop_op_desc_get(old_prop);
                  const char *old_container_name = db_op_desc_class_name_get(old_op_desc);

                  manager_widget_content_unset(session, prev_wdg_container, old_container_name, old_prop, MODE_EDITOR, NULL);
                  wdg_obj_container_item_remove(prev_wdg_container, _ci);
               }

             Dep_Id *dep_id = wdg_dep_id_get(new_param_wdg);
             gui_value_name_id_set(val, type, dep_id);

             if (ci)
               {
                  wdg_obj_container_item_remove(wdg, ci);
               }
             ci = obj_container_item_new(new_prop, dep_id);
             wdg_obj_container_item_add((Gui_Widget *) wdg, ci, pfd->it_data->idx);

             /* Need to reload all window, because previously packed widgets will stay at their places. */
              _wdg_parent_win_reload(wdg);
             /* Update propview. */
             _editor_wdg_selected_set(wdg);
             objtree_item_selected_set(wdg);
          }
     }

   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   return EO_CALLBACK_CONTINUE;
}

static void
_widget_selected_from_objtree(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Gui_Widget *wdg  = elm_object_item_data_get(event_info);
   _editor_wdg_selected_set(wdg);
   propview_build(wdg);

   /* Make menu shown, when it is selected from objtree. */
   if (wdg_is_container(wdg, DB_DEF_MENU_CLASS))
     {
        const Gui_Session *session = gui_context_editor_session_get(_active_context_get());
        Eo *eo = (Eo *) session_eo_get(session, wdg);
        eo_do(eo, evas_obj_visibility_set(EINA_TRUE));
     }
}

static void
_project_close(const Gui_Context *ctx)
{
   /* Clear lists. */
   objtree_context_set(NULL);
   propview_build(NULL);
   seqview_fill(NULL);
   if (ctx)
     {
        /* Get list of simulate sessions in progress. */
        Eina_List *simulate_sessions = gui_context_simulate_session_list_get(ctx);
        if (simulate_sessions)
          {
             Eina_List *s_itr1, *s_itr2;
             Gui_Session *session;
             /* Delete iterate sessions which are in progress.
              * FOREACH_SAFE - because data is being deleted from this list during iterations. */
             EINA_LIST_FOREACH_SAFE(simulate_sessions, s_itr1, s_itr2, session)
               {
                  Eina_List *wins = session_wins_get(session);
                  Eina_List *itr, *itr2;
                  Gui_Widget *wdg;
                  EINA_LIST_FOREACH_SAFE(wins, itr, itr2, wdg)
                    {
                       manager_widget_delete(session, wdg, MODE_SIMULATOR, NULL);
                    }
               }
          }

        /* Set selected widget to NULL, in order to hide border. */
        _editor_wdg_selected_set(NULL);
        _editor_layout_clear(_active_ctx);

        /* Iterate over windows and delete Main_Wdg_Info */
        Eina_List *list, *itr, *itr2;
        Dep_Id *wdg_id;
        list = gui_context_main_widgets_get(_active_ctx);
        EINA_LIST_FOREACH_SAFE(list, itr, itr2, wdg_id)
          {
             Gui_Widget *wdg = wdg_get(wdg_id);
             if (wdg)
               {
                  Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
                  eo_del(wi->frame);
                  free(wi);
               }
          }

        session_del((Gui_Session *) gui_context_editor_session_get(ctx));
        gui_context_del((Gui_Context *) ctx);
     }
   _active_context_set(NULL);
}

static Eina_Bool
_observers_init(const Gui_Context *ctx)
{
   Eina_List *wdgs_itr;
   Dep_Id *wdg_id;
   EINA_LIST_FOREACH(gui_context_wdg_list_get(ctx), wdgs_itr, wdg_id)
     {
        Eina_List *props_itr;
        const Gui_Widget_Property *prop;
        const Gui_Widget *wdg = wdg_get(wdg_id);
        if (!wdg) continue;
        EINA_LIST_FOREACH(wdg_prop_list_get(wdg), props_itr, prop)
          {
             Eina_List *values = prop_value_get(prop), *values_itr;
             Gui_Value *value;
             EINA_LIST_FOREACH(values, values_itr, value)
               {
                  Gui_Type type = gui_value_type_get(value);
                  switch (type)
                    {
                     case GUI_TYPE_OBJECT:
                     case GUI_TYPE_CB:
                     case GUI_TYPE_FILE:
                        gui_context_dep_observer_add(DEP_ID_GET(value), _wdg_update, (void *)wdg);
                        break;
                     default:
                        break;
                    }
               }
          }
     }
   return EINA_TRUE;
}

static Eina_Bool
_project_new(const char *filename)
{
   Gui_Context *ctx;
   ctx = gui_context_new();
   if (!ctx)
     {
        ERR("Can not create context: %p", ctx);
        return EINA_FALSE;
     }

   if (filename)
     {
        if (!gui_parser_json_file_read(ctx, filename))
          {
             gui_context_del(ctx);
             return EINA_FALSE;
          }
     }

   /* FIXME: handle return values */
   _active_context_set(ctx);
   objtree_context_set(ctx);
   seqview_fill(ctx);

   /* Assign new editor session to context */
   gui_context_editor_session_set(_active_context_get(), session_new());

   _editor_ctx_call(ctx);

   _observers_init(ctx);
   return EINA_TRUE;
}

Eina_Bool
_wdg_border_draw_on_idle(void *data EINA_UNUSED)
{
   const Gui_Widget *wdg = _editor_wdg_selected_get();
   if (wdg)
     {
        _wdg_border_draw(wdg, EINA_TRUE);
     }
   return ECORE_CALLBACK_RENEW;
}

void
editor_init(GuiLogicCbs *_guilogic_cbs)
{
   g = egui_layout_gui_get();
   Action_Functions *funcs = manager_action_functions_get(MODE_EDITOR);
   funcs->wdg_add = _widget_add;
   funcs->wdg_del = _widget_del;
   funcs->prop_add = _widget_prop_add;
   funcs->item_add = _widget_item_add;
   funcs->content_set = _content_set;

   PropViewCbs *prop_cbs = propview_cbs_get();
   prop_cbs->property_update_cb_func = _prop_update_from_propview;
   prop_cbs->property_delete_cb_func = _prop_del_from_propview;
   prop_cbs->property_ctx_menu_cb_func = _prop_ctx_menu_cb_func;
   prop_cbs->content_delete_cb_func = _content_del_from_propview;
   prop_cbs->content_reorder_cb_func = _content_reorder_from_propview;
   prop_cbs->content_change_cb_func = _content_change_from_propview;

   ObjTreeViewCbs *objtree_cbs = objtree_cbs_get();
   objtree_cbs->item_selection_cb_func = _widget_selected_from_objtree;

   ItemViewCbs *itemview_cbs = itemview_cbs_get();
   itemview_cbs->item_selection_cb_func = _itemview_item_selected;
   itemview_cbs->item_update_cb_func = _field_update_from_itemview;
   itemview_cbs->item_public_update_cb_func = _item_public_update_cb;
   itemview_cbs->_itemview_item_do_ = _itemview_item_do_;

   _guilogic_cbs->_editor_undo = _editor_undo;
   _guilogic_cbs->_editor_redo = _editor_redo;
   _guilogic_cbs->_layout_clear = _editor_layout_clear;
   _guilogic_cbs->_editor_ctx_call = _editor_ctx_call;
   _guilogic_cbs->_editor_selected_wdg_del_cb = _editor_selected_wdg_del_cb;
   _guilogic_cbs->_editor_factory_wdg_create = _editor_factory_wdg_create;
   _guilogic_cbs->_editor_selected_wdg_get = _editor_wdg_selected_get;
   _guilogic_cbs->_project_close = _project_close;
   _guilogic_cbs->_project_new = _project_new;

   objtree_list_set(g->main_win->objtree_list);
   propview_init();
   seqview_init(g->main_win->seq_list);
   itemview_init(g->main_win->itemview_list);
   target_db_init();
   ecore_idle_enterer_add(_wdg_border_draw_on_idle, NULL);
}