summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/props_helper.c
blob: 154dad28ba425ca9fc0f6418dca66a7f7ea3c017 (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
#include <Elementary.h>
#include <Eolian.h>
#include "elm_widget.h"
#include "elm_interface_scrollable.h"
#include "props_helper.h"
#include "egui_log.h"
#include "database.h"

extern Gui_Context *
_active_context_get();

/* Wrapper to add entry to property item.
 * Receives initial string and data for propertie's edit field
 * (wdg, op, par idx). */
Eo *
props_entry_add(Eo *box, const char *str, Gui_Type type)
{
   Eo *en = eo_add(ELM_ENTRY_CLASS, box);
   eo_do(en,
         elm_obj_entry_scrollable_set(EINA_TRUE),
         evas_obj_size_hint_weight_set(0.5, 0.0),
         evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0.5),
         elm_obj_widget_part_text_set(NULL, str),
         elm_interface_scrollable_policy_set(ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF),
         elm_obj_entry_single_line_set(EINA_TRUE),
         elm_obj_entry_text_style_user_push("DEFAULT='color=#FFFFFF'"),
         evas_obj_visibility_set(EINA_TRUE));

//   Gui_Type type = db_op_desc_nth_par_type_get(pfd->it_data->op_desc, pfd->par_idx);

   /* Filter to allow digits only. */
   if (type == GUI_TYPE_SINT)
     {
        static Elm_Entry_Filter_Accept_Set digits_filter_data;
        digits_filter_data.accepted = "-0123456789";
        digits_filter_data.rejected = NULL;
        elm_entry_markup_filter_append(en, elm_entry_filter_accept_set, &digits_filter_data);
     }

   eo_do(box, elm_obj_box_pack_end(en));

   return en;
}

Eo *
props_label_add(Eo *box, const char *str)
{
   Eo *label = eo_add(ELM_LABEL_CLASS, box);
   eo_do(label, evas_obj_visibility_set(EINA_TRUE));
   if (str)
     eo_do(label, elm_obj_widget_part_text_set(NULL, str));
   eo_do(box, elm_obj_box_pack_end(label));
   return label;
}

/* Wrapper to add check to property item.
 * Receives initial state and data for propertie's edit field
 * (wdg, op, par idx). */
Eo *
props_check_add(Eo *box, Eina_Bool state)
{
   Eo *ck = eo_add(ELM_CHECK_CLASS, box);
   eo_do(ck,
            evas_obj_visibility_set(EINA_TRUE),
            elm_obj_check_state_set(state));

   eo_do(box, elm_obj_box_pack_end(ck));
   return ck;
}

Eo *
props_button_add(Eo *box, char *text)
{
   Eo *bt = eo_add(ELM_BUTTON_CLASS, box);
   eo_do(bt, evas_obj_visibility_set(EINA_TRUE));
   if (text)
     eo_do(bt, elm_obj_widget_part_text_set(NULL, text));

   eo_do(box, elm_obj_box_pack_end(bt));
   return bt;
}

Eo *
props_hoversel_enums_add(Eo *box, Eo *hover_parent, const char *default_val, const char **enums_lst)
{
   Eo *hoversel = eo_add(ELM_HOVERSEL_CLASS, box);
   eo_do(hoversel, elm_obj_hoversel_hover_parent_set(hover_parent));

   if (!default_val)
     {
        default_val = PROP_HOVERSEL_NONE_VALUE;
     }
   elm_object_text_set(hoversel, default_val);
   /* Add items to Hoversel. */
   if (enums_lst)
     {
        while (*enums_lst != NULL)
          {
             eo_do(hoversel, elm_obj_hoversel_item_add(*enums_lst, NULL, ELM_ICON_NONE, NULL, NULL));
             enums_lst++;
          }
     }

   eo_do(hoversel, evas_obj_size_hint_weight_set(0.0, 0.0));
   eo_do(hoversel, evas_obj_size_hint_align_set(0.5, 0.5));
   eo_do(box, elm_obj_box_pack_end(hoversel));
   eo_do(hoversel, evas_obj_visibility_set(EINA_TRUE));
   return hoversel;
}

Eo *
props_hoversel_objects_add(Eo *box, Eo *hover_parent, const char *default_val, const Eina_List *wdgs_list, const Gui_Widget *wdg)
{
   Eo *hoversel = eo_add(ELM_HOVERSEL_CLASS, box);
   eo_do(hoversel, elm_obj_hoversel_hover_parent_set(hover_parent));

   if ((wdg) &&
       (!strcmp(wdg_class_name_get(wdg), DB_DEF_CTXPOPUP_CLASS) ||
       !strcmp(wdg_class_name_get(wdg), DB_DEF_DISKSELECTOR_CLASS)))
     {
        eo_do(hoversel, elm_obj_hoversel_item_add(PROP_HOVERSEL_NONE_VALUE, NULL, ELM_ICON_NONE, NULL, NULL));
     }

   if (!default_val)
     {
        default_val = PROP_HOVERSEL_NONE_VALUE;
     }
   elm_object_text_set(hoversel, default_val);

   const Eina_List *itr;
   Dep_Id *wid;
   EINA_LIST_FOREACH(wdgs_list, itr, wid)
     {
        Gui_Widget *w = wdg_get(wid);
        if (!w) continue;
        if (!wdg || ((w != wdg) &&
            (wdg_main_wdg_get(wdg) == wdg_main_wdg_get(w)) &&
            (!IS_WIN(w))))
          {
             /* w - iterated widget;
              * wdg - container
              * If
              *  - wdg is direct container for w;
              *  - w is container for wdg;
              *    don't add it to hoversel. */
             if (IS_CONTAINER(wdg))
               {
                  /*check, if wdg is content of w on any level. */
                  Eina_Bool found = EINA_FALSE;
                  if (wdg_is_content_of(w, wdg)) continue;
                  Eina_List *itr2;
                  Object_Container_Item *ci;
                  EINA_LIST_FOREACH(wdg_obj_container_contents_list_get(wdg), itr2, ci)
                    {
                       if (obj_container_item_dep_id_get(ci) == wid) found = EINA_TRUE;
                    }
                  if (found) continue;
               }

             /* if widget already has this resize object, don't add it to hoversel*/
             Eina_List *itr2;
             Gui_Widget_Property *prop;
             Eina_Bool dont_add_this_widget = EINA_FALSE;
             if (wdg)
               {
                  EINA_LIST_FOREACH(wdg_prop_list_get(wdg), itr2, prop)
                    {
                       if (!strcmp(prop_name_get(prop), RESIZE_OBJECT_ADD))
                         {
                            Gui_Value *val = prop_value_nth_get(prop, 0);
                            if (DEP_ID_GET(val) == wdg_dep_id_get(w))
                              dont_add_this_widget = EINA_TRUE;
                         }
                    }
               }
             if (dont_add_this_widget) continue;
             eo_do(hoversel, elm_obj_hoversel_item_add(wdg_name_get(w), NULL, ELM_ICON_NONE, NULL, NULL));
          }
     }

   eo_do(hoversel, evas_obj_size_hint_weight_set(0.0, 0.0));
   eo_do(hoversel, evas_obj_size_hint_align_set(0.5, 0.5));
   eo_do(box, elm_obj_box_pack_end(hoversel));
   eo_do(hoversel, evas_obj_visibility_set(EINA_TRUE));
   return hoversel;
}

Eo *
props_hoversel_object_ops_add(Eo *box, Eo *hover_parent, const char *default_val, const Gui_Widget *wdg)
{
   Eina_List *kl_list = NULL, *op_itr;
   Eo *hoversel = eo_add(ELM_HOVERSEL_CLASS, box);
   eo_do(hoversel, elm_obj_hoversel_hover_parent_set(hover_parent));

   if (default_val) eo_do(hoversel, elm_obj_widget_part_text_set(NULL, default_val));

   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;
   EINA_LIST_FREE(kl_list, kl)
     {
        Eina_List *kl_ops_lst = db_class_op_desc_list_get(kl);
        Op_Desc *op;
        EINA_LIST_FOREACH(kl_ops_lst, op_itr, op)
          {
             eo_do(hoversel, elm_obj_hoversel_item_add(db_op_desc_op_name_full_get(op), NULL, ELM_ICON_NONE, NULL, NULL));
          }
     }
   eo_do(hoversel, evas_obj_size_hint_weight_set(0.0, 0.0));
   eo_do(hoversel, evas_obj_size_hint_align_set(0.5, 0.5));
   eo_do(box, elm_obj_box_pack_end(hoversel));
   eo_do(hoversel, evas_obj_visibility_set(EINA_TRUE));
   return hoversel;
}

Eo *
props_hoversel_seqs_add(Eo *box, Eo *hover_parent, const Gui_Context *ctx, const char *default_val, Eina_Bool add_empty_field)
{
   Dep_Id *seq_id;
   Eina_List *itr;
   Eo *hoversel = eo_add(ELM_HOVERSEL_CLASS, box);
   eo_do(hoversel, elm_obj_hoversel_hover_parent_set(hover_parent));

   if (add_empty_field)
     eo_do(hoversel, elm_obj_hoversel_item_add(PROP_HOVERSEL_NONE_VALUE, NULL, ELM_ICON_NONE, NULL, NULL));

   if (!default_val)
     {
        default_val = PROP_HOVERSEL_NONE_VALUE;
     }
   eo_do(hoversel, elm_obj_widget_part_text_set(NULL, default_val));
   EINA_LIST_FOREACH(gui_context_seq_list_get(ctx), itr, seq_id)
     {
        Gui_Sequence *seq = sequence_get(seq_id);
        if (seq) eo_do(hoversel, elm_obj_hoversel_item_add(sequence_name_get(seq), NULL, ELM_ICON_NONE, NULL, NULL));
     }
   eo_do(hoversel, evas_obj_size_hint_weight_set(0.0, 0.0));
   eo_do(hoversel, evas_obj_size_hint_align_set(0.5, 0.5));
   eo_do(box, elm_obj_box_pack_end(hoversel));
   eo_do(hoversel, evas_obj_visibility_set(EINA_TRUE));
   return hoversel;
}

Eo *
props_value_add(Eo *box, const Gui_Context *ctx, const Gui_Widget *wdg, const Gui_Value *value, const Op_Desc *op, unsigned int par_idx)
{
   Eo *new_obj = NULL;

   Gui_Type t;
   /* If value exists take everything from value.
    * Value doesn't exist, when create field for empty property, so Op_Desc is used*/

   t = value ? gui_value_type_get(value) : db_op_desc_nth_par_type_get(op, par_idx);

   switch (t)
     {
      case GUI_TYPE_SINT:
           {
              char str[15] = {'\0'};
              if (value)
                {
                   int i = INT_GET(value);
                   sprintf(str, "%d", i);
                }
              new_obj = props_entry_add(box, str, t);
              break;
           }
      case GUI_TYPE_STRING:
           {
              char *str = NULL;
              if (value)
                {
                   str = STRING_GET(value);
                }
              new_obj = props_entry_add(box, str, t);
              break;
           }
      case GUI_TYPE_OBJECT:
           {
              const char *default_str = PROP_HOVERSEL_NONE_VALUE;
              if (value)
                {
                   Dep_Id *dep_id = DEP_ID_GET(value);
                   if (dep_id)
                     default_str = dep_name_get(dep_id);
                }
              new_obj = props_hoversel_objects_add(box, elm_widget_top_get(box), default_str, gui_context_wdg_list_get(ctx), wdg);
              break;
           }
      case GUI_TYPE_DOUBLE:
           {
              char str[30] = {'\0'};
              if (value)
                {
                   double pi;
                   pi = DOUBLE_GET(value);
                   sprintf(str, "%f", pi);
                }
              new_obj = props_entry_add(box, str, t);
              break;
           }
      case GUI_TYPE_BOOL:
           {
              Eina_Bool state = EINA_FALSE;
              if (value)
                {
                   state = BOOL_GET(value);
                }
              new_obj = props_check_add(box, state);
              break;
           }
      case GUI_TYPE_ENUM:
           {
              char *default_str = NULL;
              if (value)
                {
                   default_str = STRING_GET(value);
                }
              const char **enums_list = db_op_desc_nth_par_enum_list_get(op, par_idx);
              new_obj = props_hoversel_enums_add(box, elm_widget_top_get(box), default_str, enums_list);
              break;
           }
      case GUI_TYPE_FILE:
           {
              const Eina_List *itr, *res_lst;
              Dep_Id *res_id;

              const char *default_str = PROP_HOVERSEL_NONE_VALUE;
              if (value)
                {
                   Dep_Id *dep_id = DEP_ID_GET(value);
                   if (dep_id) default_str = dep_name_get(dep_id);
                   if (!default_str)
                     {
                        ERR("Looks like resource image vas deleted. Handle this.");
                     }
                }

              /* Create empty list. */
              new_obj = props_hoversel_enums_add(box, elm_widget_top_get(box), default_str, NULL);
              elm_hoversel_item_add(new_obj, PROP_HOVERSEL_NONE_VALUE, NULL, ELM_ICON_NONE, NULL, NULL);

              res_lst = gui_context_resource_list_get(wdg_context_get(wdg), RESOURCE_IMAGE);
              EINA_LIST_FOREACH(res_lst, itr, res_id)
                {
                   const Gui_Resource *res = gui_context_resource_get(res_id);
                   elm_hoversel_item_add(new_obj, resource_name_get(res), NULL, ELM_ICON_NONE, NULL, NULL);
                }

              res_lst = gui_context_resource_list_get(wdg_context_get(wdg), RESOURCE_EDJE);
              EINA_LIST_FOREACH(res_lst, itr, res_id)
                {
                   const Gui_Resource *res = gui_context_resource_get(res_id);
                   if (res) elm_hoversel_item_add(new_obj, resource_name_get(res), NULL, ELM_ICON_NONE, NULL, NULL);
                }
              break;
           }
      case GUI_TYPE_OBJECT_ITEM:
         /* FIXME: add handler for calback's data if needed*/
      case GUI_TYPE_VOID:
         break;
      default:
         ERR("switch default for type: %s; op_name: %s", db_gui_type_name_get(t), db_op_desc_op_name_get(op));
     }
   return new_obj;
}