summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/propview.c
blob: 0140e87498f0405836c95f3c5942d7a7231bbabb (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

#include <Elementary.h>
#include "ffi_glue.h"
#include "egui_log.h"
#include "gui_widget.h"
#include "props_helper.h"
#include "propview.h"
#include "itemview.h"
#include "database.h"

#include "elm_widget.h"
#include "elm_widget_container.h"
#include "elm_interface_scrollable.h"

extern Gui_Context *
_active_context_get();

static Eo *sc_box = NULL;

static PropViewCbs *_view_cbs = NULL;

void
_it_data_free(void *data)
{
   It_Data *it_data = data;

   if (!it_data) return;
   it_data->refs--;
   if (!it_data->refs)
     {
        free(it_data);
        it_data = NULL;
     }
}

void
_pfd_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Par_Field_Data *pfd = NULL;
   eo_do(obj, pfd = eo_key_data_get("editor"));
   if (pfd) _it_data_free(pfd->it_data);
   eo_do(obj, eo_key_data_del("editor"));
}

#define _STR_EDITOR "editor"
#define _PATH_ICON_UP_ARROW "src/data/images/icon_up_arrow.png"
#define _PATH_ICON_DOWN_ARROW "src/data/images/icon_down_arrow.png"

/*
 * Hash table to map op to proplist's item.
 * In order to quickly find item in list, when prop name is known.
 * [Op_Desc]->[Item] */
static Eina_Hash *op_item_table = NULL;

/*
 * Hash table to map callback ptr to its item in callbacks list.
 * In order to quickly find item in list, when cb ptr is known.
 * [Gui_Widget_Callback *]->[Item] */
static Eina_Hash *cb_item_table = NULL;

static Evas_Object *
_item_content_get(It_Data *it_data);

static Eina_Bool
_content_item_content_get(It_Data *it_data, Eo *box)
{
   const Gui_Widget *wdg = it_data->wdg;
   const Gui_Context *ctx = wdg_context_get(wdg);

   unsigned int count, i;
   count = db_op_desc_param_number_get(it_data->op_desc);

   for (i = 0; i < count; i++)
     {
        /* Get value, for which we want to build field.
         * If it is NULL, field will be build, for nth value in Op_Desc*/
        Gui_Value *val = ((it_data->prop) ? prop_value_nth_get(it_data->prop, i) : NULL);
        Eo *obj = props_value_add(box, ctx, wdg, val, it_data->op_desc, i);
        if (obj)
          {
             Par_Field_Data *pfd = calloc (1, sizeof(Par_Field_Data));
             pfd->it_data = it_data;
             pfd->it_data->refs++;
             pfd->par_idx = i;

             eo_do(obj, eo_key_data_set(_STR_EDITOR, pfd, free));
             evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _pfd_del, NULL);

             if (eo_isa(obj, ELM_OBJ_HOVERSEL_CLASS))
               {
                  eo_do(obj, eo_event_callback_add(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED,
                                                   _view_cbs->content_change_cb_func, NULL));
                  eo_do(obj, evas_obj_size_hint_weight_set(0, EVAS_HINT_EXPAND),
                             evas_obj_size_hint_align_set(0, EVAS_HINT_FILL));
               }
             else
               {
                  eo_do(obj, eo_event_callback_add(ELM_ENTRY_EVENT_ACTIVATED, _view_cbs->content_change_cb_func, NULL));
               }
          }
        else
          {
             ERR("Can't create field for %dnth parameter in \"%s\", \
                 probably this parameter is NULL pointer", i + 1, db_op_desc_op_name_get(it_data->op_desc));
          }
     }
   return EINA_TRUE;
}

static Eina_Bool
_property_item_content_get(It_Data *it_data, Eo *box)
{
   const Op_Desc *op = it_data->op_desc;
   const Gui_Widget_Property *prop = it_data->prop;
   /* Add label with op name. */
   props_label_add(box, op);
   unsigned int count, i;
   count = db_op_desc_param_number_get(op);

   for (i = 0; i < count; i++)
     {
        /* Get value, for which we want to build field.
         * If it is NULL, field will be build, for nth value in Op_Desc*/
        Gui_Value *value = ((prop && prop_value_get(prop)) ? prop_value_nth_get(prop, i) : NULL);
        Eo *obj = props_value_add(box, wdg_context_get(it_data->wdg), it_data->wdg, value, op, i);
        if (obj)
          {
             Par_Field_Data *pfd = calloc (1, sizeof(Par_Field_Data));
             pfd->it_data = it_data;
             pfd->it_data->refs++;
             pfd->par_idx = i;

             eo_do(obj, eo_key_data_set(_STR_EDITOR, pfd, free));
             evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _pfd_del, NULL);

             /* forbid changing of value in "resize_object_add"*/
             if (prop && value && (!strcmp(prop_name_get(prop), RESIZE_OBJECT_ADD)))
               {
                  eo_do(obj, elm_obj_widget_disabled_set(EINA_TRUE));
               }

             if (eo_isa(obj, ELM_OBJ_HOVERSEL_CLASS))
               {
                  eo_do(obj, eo_event_callback_add(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED, _view_cbs->property_update_cb_func, NULL));
               }
             else
               {
                  if (db_op_desc_flag_get(op) & CHANGE_ON_ACTIVATE)
                    {
                       eo_do(obj, eo_event_callback_add(ELM_ENTRY_EVENT_ACTIVATED, _view_cbs->property_update_cb_func, NULL));
                    }
                  else
                    {
                       eo_do(obj, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED, _view_cbs->property_update_cb_func, NULL));
                    }
               }
          }
        else
          {
             /*
             ERR("Can't create field for %dnth parameter in \"%s\", \
                 probably this parameter is NULL pointer", i + 1, db_op_desc_op_name_get(op));
                 */
          }
     }

   Op_Flag flag = db_op_desc_flag_get(op);
   if ((flag & MULTI_PROPERTY) && prop)
     {
        Eo *obj = props_button_add(box, "X");
        eo_do(obj, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _view_cbs->property_delete_cb_func, prop));
     }
   return EINA_TRUE;
}

static void
_cb_name_modify(void *data, Eo *obj, void *event_info EINA_UNUSED)
{
   Gui_Widget_Callback *cb = data;
   const char *event_name = elm_object_item_part_text_get(event_info, NULL);
   elm_object_text_set(obj, event_name);
   cb_modify(cb, event_name, cb_sequence_id_get(cb));
}

static void
_cb_sequence_modify(void *data, Eo *obj, void *event_info)
{
   Gui_Widget_Callback *cb = data;
   const char *seq_name = elm_object_item_part_text_get(event_info, NULL);
   Dep_Id dep_id = gui_context_dep_data_get_id_by_name(_active_context_get(), seq_name);
   elm_object_text_set(obj, seq_name);
   cb_modify(cb, cb_type_get(cb), dep_id);
}

static void
_cb_add(void *data, Eo *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Widget_Callback *cb_before = data;
   Gui_Widget_Callback *cb = cb_new(NULL, 0);
   cb_add_after(cb_before, cb);
   Gui_Widget *wdg = cb_wdg_get(cb);
   It_Data *it_data = IT_DATA_BUILD(CALLBACK_TYPE, wdg);
   it_data->cb = cb;

   Eo *it_box = _item_content_get(it_data);
   Eo *it_box_before = eina_hash_find(cb_item_table, &cb_before);
   eo_do(sc_box, elm_obj_box_pack_after(it_box, it_box_before));
   eina_hash_set(cb_item_table, &cb, it_box);
}

static void
_cb_del(void *data, Eo *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Widget_Callback *cb = data;
   Gui_Widget *wdg = cb_wdg_get(cb);
   Eo *it_box = eina_hash_find(cb_item_table, &cb);
   if (it_box)
     {
        eo_do(sc_box, elm_obj_box_unpack(it_box));
        eina_hash_del(cb_item_table, &cb, it_box);
        eo_ref(it_box);
        eo_del(it_box);
     }
   wdg_cb_del(wdg, cb);
   cb_del(cb);
}

static Eina_Bool
_callback_item_content_get(It_Data *it_data, Eo *box)
{
   Gui_Widget_Callback *cb = it_data->cb;

   Eo *events_list = props_hoversel_events_add(box, elm_widget_top_get(sc_box), cb);
   evas_object_smart_callback_add(events_list, "selected", _cb_name_modify, cb);

   Dep_Id dep_id = cb_sequence_id_get(cb);
   const char *default_str = gui_context_dep_data_get(_active_context_get(), dep_id);
   Eo *seqs_list = props_hoversel_seqs_add(box, elm_widget_top_get(sc_box), wdg_context_get(it_data->wdg), default_str, EINA_FALSE);
   evas_object_smart_callback_add(seqs_list, "selected", _cb_sequence_modify, cb);

   /* Add callbacks from resources. */
   Eina_List *res_lst = (Eina_List *) gui_context_resource_list_get(wdg_context_get(it_data->wdg), RESOURCE_EO_CALLBACK);
   Eina_List *itr;
   Gui_Resource *res;
   EINA_LIST_FOREACH(res_lst, itr, res)
     {
        elm_hoversel_item_add(seqs_list, resource_name_get(res), NULL, ELM_ICON_NONE, NULL, NULL);
     }

   Eo *add_but = props_button_add(box, "+");
   evas_object_smart_callback_add(add_but, "clicked", _cb_add, cb);
   evas_object_size_hint_weight_set(add_but, 1.0, 1.0);
   evas_object_size_hint_align_set(add_but, 1.0, -1.0);
   Eo *del_but = props_button_add(box, "-");
   evas_object_smart_callback_add(del_but, "clicked", _cb_del, cb);
   return EINA_TRUE;
}

static void
_wdg_public_change_cb(void *data, Eo *obj, void *event_info EINA_UNUSED)
{
   Eina_Bool state;
   eo_do(obj, state = elm_obj_check_state_get());
   wdg_public_set(data, state);
}

static void
_wdg_name_change_cb(void *data, Eo *obj, void *event_info EINA_UNUSED)
{
   Gui_Widget *wdg = data;
   const char *str = NULL;
   eo_do(obj, str = elm_obj_widget_part_text_get(NULL));
   if (!gui_context_dep_data_update(wdg_context_get(wdg), wdg_dep_id_get(wdg), str))
     {
        ERR("Name \"%s\" already exists!", str);
     }
}

static Eina_Bool
_description_item_content_get(It_Data *it_data, Eo *box)
{
   Eo *label = eo_add(ELM_OBJ_LABEL_CLASS, box);
   eo_unref(label);
   eo_do(label, evas_obj_visibility_set(EINA_TRUE),
                elm_obj_widget_part_text_set(NULL, it_data->desc));
   eo_do(box, elm_obj_box_pack_end(label));

   if (!strcmp(it_data->desc, DB_DEF_PUBLIC))
     {
        Eo *ck = props_check_add(box, wdg_public_get(it_data->wdg));
        evas_object_smart_callback_add(ck, "changed", _wdg_public_change_cb, it_data->wdg);
     }
   else if (!strcmp(it_data->desc, DB_DEF_NAME))
     {
        Eo *entry = props_entry_add(box, wdg_name_get(it_data->wdg), GUI_TYPE_STRING);
        evas_object_smart_callback_add(entry, "activated", _wdg_name_change_cb, it_data->wdg);
     }
   else if (!strcmp(it_data->desc, DB_DEF_CLASS))
     {
        Eo *entry = props_entry_add(box, wdg_class_name_get(it_data->wdg), GUI_TYPE_STRING);
        elm_object_disabled_set(entry, EINA_TRUE);
     }
   return EINA_TRUE;
}

/* Content set for property view.
 * Used to show properties and actions
 */
static Evas_Object *
_item_content_get(It_Data *it_data)
{
   Eo *box = NULL;

   box = eo_add(ELM_OBJ_BOX_CLASS, sc_box);
   eo_unref(box);
   eo_do(box, evas_obj_visibility_set(EINA_TRUE),
         elm_obj_box_horizontal_set(EINA_TRUE),
         elm_obj_box_padding_set(5, 0),
         evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0),
         evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0)
//         evas_obj_size_hint_min_set(32 * elm_config_scale_get(),
//                                    18 * elm_config_scale_get())
        );

   /* set item data to box, so it will be automatically free. */
   eo_do(box, eo_key_data_set(_STR_EDITOR, it_data, _it_data_free));
   switch (it_data->type)
     {
      case PROPERTY_TYPE:
         _property_item_content_get(it_data, box);
         break;
      case CALLBACK_TYPE:
         _callback_item_content_get(it_data, box);
         break;
      case DESCRIPTION_TYPE:
         _description_item_content_get(it_data, box);
         break;
         /* Currently ITEM_TYPE cannot appear here.
          * This case is only to shut compiler up. */
      case ITEM_TYPE:
      case CONTENT_TYPE:
         _content_item_content_get(it_data, box);
         break;
     }

   return box;
}

PropViewCbs *propview_cbs_get()
{
   if (!_view_cbs) _view_cbs = calloc(1, sizeof(*_view_cbs));
   return _view_cbs;
}

static void
_properties_build(const Gui_Widget *wdg)
{
   Eina_List *wdg_prop_lst = wdg_prop_list_get(wdg);
   Eina_List *itr2, *itr3, *kl_list = NULL;
   Op_Desc *op;
   eina_hash_free(op_item_table);

   op_item_table = eina_hash_string_superfast_new(NULL);

   if (wdg)
     {
        /* FIXME: this will be fixed, when Eolian will be used for MRO.
         * Eo will not be needed for MRO. */
        const Gui_Session *session = gui_context_editor_session_get(_active_context_get());
        kl_list = eo_class_mro_get(eo_class_name_get(session_eo_get(session, wdg)));
     }
   const char *kl;

   /* Iterate over each parent class. */
   EINA_LIST_FREE(kl_list, kl)
     {
        /* iterate over each operation of class. */
        Eina_List *llst = db_class_op_desc_list_get(kl);
        EINA_LIST_FOREACH(llst, itr2, op)
          {
             Eo *it_box;
             Gui_Widget_Property *prop;
             It_Data *it_data;
             Op_Flag flag = db_op_desc_flag_get(op);

             /* Don't add property to propview, if it is container property,
              * or op flag is not EGUI_EO_DO_CALL */
             if ((db_op_desc_group_type_get(op) == GROUP_CONTAINER) || (!(flag & EGUI_EO_DO_CALL)))
               continue;
             const char *op_name = db_op_desc_op_name_get(op);

             EINA_LIST_FOREACH(wdg_prop_lst, itr3, prop)
               {
                  const char *prop_name = prop_name_get(prop);
                  if (!strcmp(op_name, prop_name))
                    {
                       it_data = IT_DATA_BUILD(PROPERTY_TYPE, wdg);
                       it_data->op_desc = op;
                       it_data->prop = prop;
                       /* map current item with its prop name. */
                       it_box = _item_content_get(it_data);
                       eina_hash_add(op_item_table, db_op_desc_op_name_get(op), it_box);
                       eo_do(sc_box, elm_obj_box_pack_end(it_box));
                    }
               }

             /* If the property can be multi, we add a row with empty values.
              * If widget doesn't contatin current prop, add empty prop. */
             if ((flag & MULTI_PROPERTY) || (!wdg_prop_get(wdg, op_name)))
               {
                  it_data = IT_DATA_BUILD(PROPERTY_TYPE, wdg);
                  it_data->op_desc = op;
                  it_data->prop = NULL;
                  /* map current item with its prop name. */
                  it_box = _item_content_get(it_data);
                  eina_hash_add(op_item_table, db_op_desc_op_name_get(op), it_box);
                  eo_do(sc_box, elm_obj_box_pack_end(it_box));
               }
          }
     }
}

static void
_content_build(const Gui_Widget *wdg)
{
   eina_hash_free(op_item_table);
   op_item_table = NULL;

   Eina_List *items_lst = wdg_container_contents_list_get(wdg);
   Eina_List *itr1;
   Gui_Widget_Property *prop;
   int i = 0;
   if (items_lst)
     {
        EINA_LIST_FOREACH(items_lst, itr1, prop)
          {
             Eo *it_box;
             It_Data *it_data = IT_DATA_BUILD(CONTENT_TYPE, wdg);
             it_data->idx = i;
             it_data->prop = prop;
             it_data->op_desc = (Op_Desc *) prop_op_desc_get(prop);

             it_box = _item_content_get(it_data);

             eo_do(sc_box, elm_obj_box_pack_end(it_box));

             if (wdg_container_class_name_get(wdg) &&
                 !strcmp(wdg_container_class_name_get(wdg), DB_DEF_BOX_CLASS))
               {
                  Eo *up_down_box, *button_up, *button_down, *ic;
                  up_down_box = eo_add(ELM_OBJ_BOX_CLASS, it_box);
                  eo_unref(up_down_box);
                  eo_do(up_down_box, evas_obj_visibility_set(EINA_TRUE),
                        elm_obj_box_horizontal_set(EINA_FALSE),
                        elm_obj_box_padding_set(0, 0),
                        evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0),
                        evas_obj_size_hint_align_set(0, 0)
                       );
                  eo_do(it_box, elm_obj_box_pack_end(up_down_box));

                  button_up = props_button_add(up_down_box, "Up");
                  eo_do(button_up, evas_obj_size_hint_align_set(EVAS_HINT_FILL, 1),
                        evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0));
                  ic = eo_add(ELM_OBJ_ICON_CLASS, it_box);
                  eo_unref(ic);
                  eo_do(ic, elm_obj_image_file_set(_PATH_ICON_UP_ARROW, NULL));
                  eo_do(button_up, elm_obj_container_content_set("icon", ic));

                  button_down = props_button_add(up_down_box, "Down");
                  eo_do(button_down, evas_obj_size_hint_align_set(0, 0));
                  ic = eo_add(ELM_OBJ_ICON_CLASS, it_box);
                  eo_unref(ic);
                  eo_do(ic, elm_obj_image_file_set(_PATH_ICON_DOWN_ARROW, NULL));
                  eo_do(button_down, elm_obj_container_content_set("icon", ic));

                  eo_do(button_up, eo_key_data_set(CONTAINER_REORDER_BUTTON_DIR, (void *) (intptr_t) UP, NULL));
                  eo_do(button_down, eo_key_data_set(CONTAINER_REORDER_BUTTON_DIR, (void *) (intptr_t) DOWN, NULL));
                  eo_do(button_up, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _view_cbs->content_reorder_cb_func, (void *) (intptr_t) i));
                  eo_do(button_down, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _view_cbs->content_reorder_cb_func, (void *) (intptr_t) i));
               }
             Eo *ic, *button_x = props_button_add(it_box, NULL);
             ic = eo_add(ELM_OBJ_ICON_CLASS, it_box);
             eo_unref(ic);
             eo_do(ic, elm_obj_image_file_set("src/data/images/icon_close.png", NULL));
             eo_do(button_x, elm_obj_container_content_set("icon", ic));
             eo_do(button_x,
                   evas_obj_size_hint_weight_set(0, EVAS_HINT_EXPAND),
                   evas_obj_size_hint_align_set(0, EVAS_HINT_FILL)
                  );
             /* i is an index of content inside container list. */
             eo_do(button_x, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _view_cbs->content_delete_cb_func, (void *) (intptr_t) i));
             i++;
          }
     }
 /*  Add empty fields. */
     {
        const char *wdg_class_name = wdg_class_name_get(wdg);
        Eina_List *itr;
        const char *name;
        /* Add empty field for each type of container. */
        EINA_LIST_FOREACH(db_class_inherit_containers_list_get(wdg_class_name), itr, name)
          {
             const Op_Desc *op_desc = db_container_desc_op_desc_get(db_container_desc_get(name), CONTAINER_PACK);
             It_Data *it_data = IT_DATA_BUILD(CONTENT_TYPE, wdg);
             it_data->idx = i;
             it_data->op_desc = op_desc;
             it_data->prop = NULL;

             Eo *it_box = _item_content_get(it_data);
             eo_do(sc_box, elm_obj_box_pack_end(it_box));
          }
     }
}

/* This function now is called for meny only */
static void
_item_build(const Gui_Widget *wdg)
{
   itemview_build(wdg);
}

static void
_description_build(const Gui_Widget *wdg)
{
   It_Data *it_data;

   it_data = IT_DATA_BUILD(DESCRIPTION_TYPE, wdg);
   it_data->desc = DB_DEF_NAME;
   eo_do(sc_box, elm_obj_box_pack_end(_item_content_get(it_data)));

   it_data = IT_DATA_BUILD(DESCRIPTION_TYPE, wdg);
   it_data->desc = DB_DEF_CLASS;
   eo_do(sc_box, elm_obj_box_pack_end(_item_content_get(it_data)));

   it_data = IT_DATA_BUILD(DESCRIPTION_TYPE, wdg);
   it_data->desc = DB_DEF_PUBLIC;
   eo_do(sc_box, elm_obj_box_pack_end(_item_content_get(it_data)));
}

static void
_callbacks_build(const Gui_Widget *wdg)
{
   eina_hash_free(cb_item_table);
#ifdef __LP64__
   cb_item_table = eina_hash_int64_new(NULL);
#else
   cb_item_table = eina_hash_int32_new(NULL);
#endif

   Eina_List *itr, *itr2;
   Eo *it_box;
   Eina_List *cbs_list = wdg_cb_list_get(wdg);
   if (cbs_list)
     {
        Gui_Widget_Callback *cb = NULL;
        EINA_LIST_FOREACH_SAFE(cbs_list, itr, itr2, cb)
          {
             It_Data *it_data = IT_DATA_BUILD(CALLBACK_TYPE, wdg);
             it_data->cb = cb;
             it_box = _item_content_get(it_data);
             eo_do(sc_box, elm_obj_box_pack_end(it_box));
             eina_hash_set(cb_item_table, &cb, it_box);
          }
     }
   else
     {
        It_Data *it_data = IT_DATA_BUILD(CALLBACK_TYPE, wdg);
        it_data->cb = cb_new(NULL, 0);
        wdg_cb_add((Gui_Widget *) wdg, it_data->cb);
        it_box = _item_content_get(it_data);
        eo_do(sc_box, elm_obj_box_pack_end(it_box));
        eina_hash_set(cb_item_table, &(it_data->cb), it_box);
     }
}

/* Build property view for current widget.
 * Show propeties, which defined in class hyerarchy
 * for current widget's class. And fill fields, if property
 * is defined for current widget.(or put default values into fields.)
 * Called, when item in objtree is selected. */
void
propview_build(const Gui_Widget *wdg, It_Data_Type type)
{
   elm_box_clear(sc_box);
   if (!wdg) return;

   /* type ITEM_TYPE not assigned to any toolbar's item.
    * It's assigned when toolbar's item is CONTENT and widget is menu.
    * So if current type is ITEM_TYPEm we need to assign it to CONTENT_TYPE,
    * and it will be resolved according to widget's type. */
   if (type == ITEM_TYPE) type = CONTENT_TYPE;

   if ((type == CONTENT_TYPE) &&
      (wdg_is_container(wdg, DB_DEF_MENU_CLASS) ||
       wdg_is_container(wdg, DB_DEF_DISKSELECTOR_CLASS) ||
       wdg_is_container(wdg, DB_DEF_CTXPOPUP_CLASS)))
     {
        type = ITEM_TYPE;
     }

   switch(type)
     {
      case DESCRIPTION_TYPE:
           {
              _description_build(wdg);
              break;
           }
      case PROPERTY_TYPE:
           {
              _properties_build(wdg);
              break;
           }
      case CALLBACK_TYPE:
           {
              _callbacks_build(wdg);
              break;
           }
      case CONTENT_TYPE:
           {
              _content_build(wdg);
              break;
           }
      case ITEM_TYPE:
           {
              itemview_clear();
              _item_build(wdg);
              break;
           }
      default:
         ERR("switch default");
     }
   if (_view_cbs->propview_build_post_cb)
     {
        _view_cbs->propview_build_post_cb(wdg, type);
     }
}

/* This func is called, when need to update values in property view.
 * T.e. when size is changed by mouse, update values in view*/
void
propview_item_update(const Gui_Widget_Property *prop)
{
   const char *prop_name;
   Eo *item_box;
   Eina_List *box_list, *par_list, *itr;
   Gui_Value *val;
   int i = 0;

   if (!prop) return;
   prop_name = prop_name_get(prop);
   /* get item_box from hash. */
   item_box = eina_hash_find(op_item_table, prop_name);
   /* if item of genlist is not visible, box will be NULL, so don't need to update prop.*/
   if (!item_box) return;
   /* First element of list is label, after parameter editing fields. */
   box_list = elm_box_children_get(item_box);

   /* For now only size and position are passed here. */
   par_list = prop_value_get(prop);
   EINA_LIST_FOREACH(par_list, itr, val)
     {
        Eo *o = eina_list_nth(box_list, i + 1);
        Gui_Type t = gui_value_type_get(val);

        /* Create edit field for each parameter. */
        switch (t)
          {
           case GUI_TYPE_SINT:
                {
                   char str[15];
                   int int_v = INT_GET(prop_value_nth_get(prop, i));
                   sprintf(str, "%d", int_v);
                   elm_entry_entry_set(o, str);
                   break;
                }
           case GUI_TYPE_STRING:
                {
                   char *str = STRING_GET(prop_value_nth_get(prop, i));
                   elm_entry_entry_set(o, str);
                   break;
                }
           case GUI_TYPE_OBJECT:
                {
                   Dep_Id dep_id = DEP_ID_GET(prop_value_nth_get(prop, i));
                   const char *default_str = gui_context_dep_data_get(_active_context_get(), dep_id);
                   elm_object_text_set(o, default_str);
                   break;
                }
           case GUI_TYPE_DOUBLE:
                {
                   char str[30];
                   double d = DOUBLE_GET(prop_value_nth_get(prop, i));
                   sprintf(str, "%f", d);
                   elm_entry_entry_set(o, str);
                   break;
                }
           case GUI_TYPE_BOOL:
                {
                   Eina_Bool state = BOOL_GET(prop_value_nth_get(prop, i));
                   elm_check_state_set(o, state);
                   break;
                }
           case GUI_TYPE_ENUM:
                {
                   char *default_str = STRING_GET(prop_value_nth_get(prop, i));
                   elm_object_text_set(o, default_str);
                   break;
                }
           default:
              ERR("switch default for type: %s of property %s", db_gui_type_name_get(t), prop_name_get(prop));
          }
        i++; /*Because first item in box list is label*/
     }
}

void
propview_scrollbox_set(Eo *box)
{
   sc_box = box;
}

void
propview_scrollbox_unset()
{
   eo_do(sc_box, elm_obj_box_clear());
   if (op_item_table) eina_hash_free(op_item_table);
   if (cb_item_table) eina_hash_free(cb_item_table);
   sc_box = NULL;
}