summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/props_helper.c
blob: 572a8072d196a1f2e577834b2089fc15e65d0cff (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
#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_OBJ_ENTRY_CLASS, box);
   eo_unref(en);
   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 Op_Desc *op)
{
   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, db_op_desc_prop_display_name_get(op)));
   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_OBJ_CHECK_CLASS, box);
   eo_unref(ck);
   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_OBJ_BUTTON_CLASS, box);
   eo_unref(bt);
   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_OBJ_HOVERSEL_CLASS, box);
   eo_unref(hoversel);
   elm_hoversel_hover_parent_set(hoversel, 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)
          {
             elm_hoversel_item_add(hoversel, *enums_lst, NULL, ELM_ICON_NONE, NULL, NULL);
             enums_lst++;
          }
     }

   evas_object_size_hint_weight_set(hoversel, 0.0, 0.0);
   evas_object_size_hint_align_set(hoversel, 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 Gui_Context *ctx, const Gui_Widget *wdg)
{
   Eo *hoversel = eo_add(ELM_OBJ_HOVERSEL_CLASS, box);
   eo_unref(hoversel);
   elm_hoversel_hover_parent_set(hoversel, hover_parent);

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

   if (default_val) elm_object_text_set(hoversel, default_val);
   Eina_List *itr;
   Gui_Widget *w;
   EINA_LIST_FOREACH(gui_context_wdg_list_get(ctx), itr, w)
     {
        if (!wdg || ((w != wdg) &&
            (wdg_parent_win_wdg_get(wdg) == wdg_parent_win_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) &&
                 ((wdg == wdg_data_get(w, CONTAINER)) ||
                    /*check, if wdg is content of w on any level. */
                   (wdg_is_content_of(w, wdg))))
               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;
             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;

             elm_hoversel_item_add(hoversel, wdg_name_get(w), NULL, ELM_ICON_NONE, NULL, NULL);
          }
     }

   evas_object_size_hint_weight_set(hoversel, 0.0, 0.0);
   evas_object_size_hint_align_set(hoversel, 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_OBJ_HOVERSEL_CLASS, box);
   eo_unref(hoversel);
   elm_hoversel_hover_parent_set(hoversel, hover_parent);

   if (default_val) elm_object_text_set(hoversel, 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)
          {
             const char *op_name = db_op_desc_op_name_get(op);
             elm_hoversel_item_add(hoversel, op_name, NULL, ELM_ICON_NONE, NULL, NULL);
          }
     }
   evas_object_size_hint_weight_set(hoversel, 0.0, 0.0);
   evas_object_size_hint_align_set(hoversel, 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_events_add(Eo *box, Eo *hover_parent, const Gui_Widget_Callback *cb)
{
   Eina_List *classes = eo_class_mro_get(wdg_class_name_get(cb_wdg_get(cb)));
   const char *classname;

   Eo *hoversel = eo_add(ELM_OBJ_HOVERSEL_CLASS, box);
   eo_unref(hoversel);
   elm_hoversel_hover_parent_set(hoversel, hover_parent);
   const char *dflt_val = PROP_HOVERSEL_NONE_VALUE;
   if (cb_type_get(cb)) dflt_val = cb_type_get(cb);
   elm_object_text_set(hoversel, dflt_val);

   EINA_LIST_FREE(classes, classname)
     {
        Eolian_Class class = eolian_class_find_by_name(classname);
        const Eina_List *events = eolian_class_events_list_get(class), *itr;
        Eolian_Event event;
        EINA_LIST_FOREACH(events, itr, event)
          {
             const char *event_name;
             eolian_class_event_information_get(event, &event_name, NULL, NULL);
             elm_hoversel_item_add(hoversel, event_name, NULL, ELM_ICON_NONE, NULL, NULL);
          }
     }
   evas_object_size_hint_weight_set(hoversel, 0.0, 0.0);
   evas_object_size_hint_align_set(hoversel, 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)
{
   Gui_Sequence *seq;
   Eina_List *itr;
   Eo *hoversel = eo_add(ELM_OBJ_HOVERSEL_CLASS, box);
   eo_unref(hoversel);
   elm_hoversel_hover_parent_set(hoversel, hover_parent);

   if (add_empty_field)
     elm_hoversel_item_add(hoversel, 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);
   EINA_LIST_FOREACH(gui_context_seq_list_get(ctx), itr, seq)
     {
        elm_hoversel_item_add(hoversel, sequence_name_get(seq), NULL, ELM_ICON_NONE, NULL, NULL);
     }
   evas_object_size_hint_weight_set(hoversel, 0.0, 0.0);
   evas_object_size_hint_align_set(hoversel, 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);
                   default_str = gui_context_dep_data_get(wdg_context_get(wdg), dep_id);
                   if (!default_str)
                     {
                        ERR("looks like widget was deleted. Handle this case.");
                     }
                }
              new_obj = props_hoversel_objects_add(box, elm_widget_top_get(box), default_str, 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_IMAGE:
           {
              Eina_List *itr;
              Gui_Resource *res;
              Eina_List *res_lst = (Eina_List *) gui_context_resource_list_get(wdg_context_get(wdg), RESOURCE_IMAGE);

              const char *default_str = PROP_HOVERSEL_NONE_VALUE;
              if (value)
                {
                   Dep_Id dep_id = DEP_ID_GET(value);
                   default_str = gui_context_dep_data_get(_active_context_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);
              EINA_LIST_FOREACH(res_lst, itr, res)
                {
                   elm_hoversel_item_add(new_obj, resource_name_get(res), NULL, ELM_ICON_NONE, NULL, NULL);
                }
              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;
}