summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/prop_layout.c
blob: 9efe2a876f5eb0c27b7fafabd64fc8ab37f8df0b (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
#include <Elementary.h>
#include <Eolian.h>
#include "ffi_glue.h"
#include "egui_log.h"
#include "props_helper.h"
#include "egui_logic_private.h"

#include "propview.h"
#include "contentview.h"
#include "descview.h"
#include "cbview.h"
#include "prop_layout.h"
#include "itemview.h"

#include "elm_widget_container.h"

Elm_Genlist_Item_Class *_itc_class = NULL;
Elm_Genlist_Item_Class *_itc_notfound = NULL;

extern Gui_Context *
_active_context_get();

static It_Data_Type _proplayout_toolbar_selected_item_type = DESCRIPTION_TYPE;
static It_Data_Type _new_type = DESCRIPTION_TYPE;

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

   if (!it_data) return;

   /* If property wasn't assigned to any widget, this is property with default values.
    * Delete it. */
   if ((it_data->type == PROPERTY_TYPE) && (it_data->prop) && !prop_wdg_get(it_data->prop))
     {
        prop_ref((Gui_Widget_Property *) it_data->prop);
        prop_unref((Gui_Widget_Property *) it_data->prop);
        it_data->prop = NULL;
     }

   free(it_data);
   it_data = NULL;
}

static char *
_class_item_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   Classname_Data *cl = data;
   return strdup(cl->classname);
}

static char *
_notfound_item_text_get(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   return strdup("No search results");
}

static void
_class_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
   Classname_Data *cl = data;
   free(cl->classname);
   free(cl);
}

/* This callback is called in the end of propview_build()
 * in order to switch between scrollbox for properties
 * and genlist for items. */
static void
_proplayout_build_post_cb(const Gui_Widget *wdg, It_Data_Type new_type)
{
   Egui_Layout_Widgets *g = egui_layout_gui_get();
   /* Unsetting view according to old selected toolbar's item. */
   switch (_proplayout_toolbar_selected_item_type)
     {
      case DESCRIPTION_TYPE:
           {
              break;
           }
      case PROPERTY_TYPE:
           {
              break;
           }
      case CALLBACK_TYPE:
           {
              break;
           }
      case CONTENT_TYPE:
           {
              break;
           }
      case ITEM_TYPE:
           {
              eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_TRUE));
              eo_do(g->main_win->itemview_box, evas_obj_visibility_set(EINA_FALSE));
              break;
           }
     }

   _proplayout_toolbar_selected_item_type = new_type;

   /* Setting view according to new selected toolbar's item. */
   eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->properties_list, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->itemview_box, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->callbacksview_box, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->description_list, evas_obj_visibility_set(EINA_FALSE));

   switch (new_type)
     {
      case DESCRIPTION_TYPE:
           {
              eo_do(g->main_win->description_list, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case PROPERTY_TYPE:
           {
              eo_do(g->main_win->properties_list, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case CALLBACK_TYPE:
           {
              eo_do(g->main_win->callbacksview_box, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case CONTENT_TYPE:
           {
              eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case ITEM_TYPE:
           {
              eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_FALSE));
              eo_do(g->main_win->itemview_box, evas_obj_visibility_set(EINA_TRUE));

              if (wdg_is_container(wdg, DB_DEF_MENU_CLASS))
                {
                   eo_do(g->main_win->itemview_add_item_nested_but, elm_obj_widget_disabled_set(EINA_FALSE));
                   eo_do(g->main_win->itemview_add_separator_but, elm_obj_widget_disabled_set(EINA_FALSE));
                }
              else if (wdg_is_container(wdg, DB_DEF_DISKSELECTOR_CLASS) ||
                       wdg_is_container(wdg, DB_DEF_CTXPOPUP_CLASS) ||
                       wdg_is_container(wdg, DB_DEF_TOOLBAR_CLASS) ||
                       wdg_is_container(wdg, DB_DEF_NAVIFRAME_CLASS))
                {
                   eo_do(g->main_win->itemview_add_item_nested_but, elm_obj_widget_disabled_set(EINA_TRUE));
                   eo_do(g->main_win->itemview_add_separator_but, elm_obj_widget_disabled_set(EINA_TRUE));
                }
              break;
           }
     }
}

/* 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
proplayout_build(const Gui_Widget *wdg)
{
   It_Data_Type type = _new_type;

   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) ||
       wdg_is_container(wdg, DB_DEF_TOOLBAR_CLASS) ||
       wdg_is_container(wdg, DB_DEF_NAVIFRAME_CLASS)))
     {
        type = ITEM_TYPE;
     }

   switch(type)
     {
      case DESCRIPTION_TYPE:
           {
              descview_build(wdg);
              break;
           }
      case PROPERTY_TYPE:
           {
              propview_build(wdg);
              break;
           }
      case CALLBACK_TYPE:
           {
              cbview_build(wdg);
              break;
           }
      case CONTENT_TYPE:
           {
              contentview_build(wdg);
              break;
           }
      case ITEM_TYPE:
           {
              itemview_clear();
              itemview_build(wdg);
              break;
           }
      default:
         ERR("switch default");
     }
   _proplayout_build_post_cb(wdg, type);
}

/* FIXME: need to change signature to Eo_Callback, when it will be supported.
 * This callback is used in Egui Layout JSON. */
void
_proplayout_toolbar_clicked(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
//(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *it = event_info;
   elm_toolbar_item_selected_set(it, EINA_TRUE);
   const Gui_Context *ctx = _active_context_get();
   if (!ctx) return;
   const Gui_Widget *wdg  = gui_context_data_get(ctx, SELECTED_WDG);
   _new_type = (int) (intptr_t) elm_object_item_data_get(it);
   proplayout_build(wdg);
}

/* API to switch proplayout Description->Properties->Callbacks->Contents */
void
proplayout_view_switch(It_Data_Type type)
{
   Elm_Object_Item *it;
   Egui_Layout_Widgets *g = egui_layout_gui_get();
   switch (type)
     {
      case PROPERTY_TYPE:
           {
              it = g->main_win->propsview_toolbar_prop_it;
              break;
           }
      case CALLBACK_TYPE:
           {
              it = g->main_win->propsview_toolbar_cb_it;
              break;
           }
      case DESCRIPTION_TYPE:
           {
              it = g->main_win->propsview_toolbar_desc_it;
              break;
           }
         /* Currently ITEM_TYPE cannot appear here.
          * This case is only to shut compiler up. */
      case ITEM_TYPE:
      case CONTENT_TYPE:
           {
              it = g->main_win->propsview_toolbar_cont_it;
              break;
           }
     }
   _proplayout_toolbar_clicked(NULL, NULL, it);
}

static Eina_Bool
_proplayout_filter_entry_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                                  const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   const Gui_Context *ctx = _active_context_get();
   if (!ctx) return EO_CALLBACK_CONTINUE;
   const Gui_Widget *wdg  = gui_context_data_get(ctx, SELECTED_WDG);
   proplayout_build(wdg);

   return EO_CALLBACK_CONTINUE;
}

void
proplayout_init()
{
   if (!_itc_class)
     {
        _itc_class = elm_genlist_item_class_new();
        _itc_class->item_style = "default";
        _itc_class->func.text_get = _class_item_label_get;
        _itc_class->func.del = _class_item_del;
     }

   if (!_itc_notfound)
     {
        _itc_notfound = elm_genlist_item_class_new();
        _itc_notfound->item_style = "default";
        _itc_notfound->func.text_get = _notfound_item_text_get;
     }

   Egui_Layout_Widgets *g = egui_layout_gui_get();

   cbview_init();
   descview_init();
   contentview_init();
   propview_init();
   itemview_init();

   /* Put it here, because it Enums defined in propsview.h */
   elm_object_item_data_set(g->main_win->propsview_toolbar_desc_it, (void *) (intptr_t) DESCRIPTION_TYPE);
   elm_object_item_data_set(g->main_win->propsview_toolbar_prop_it, (void *) (intptr_t) PROPERTY_TYPE);
   elm_object_item_data_set(g->main_win->propsview_toolbar_cb_it, (void *) (intptr_t) CALLBACK_TYPE);
   elm_object_item_data_set(g->main_win->propsview_toolbar_cont_it, (void *) (intptr_t) CONTENT_TYPE);

   eo_do(g->main_win->propsview_filter_entry,
         eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED_USER,
                               _proplayout_filter_entry_changed_cb,
                               NULL));

   _mempool_cache_init();
}

void
proplayout_shutdown()
{
   elm_genlist_item_class_free(_itc_class);
   _itc_class = NULL;
   elm_genlist_item_class_free(_itc_notfound);
   _itc_notfound = NULL;

   cbview_shutdown();
   descview_shutdown();
   contentview_shutdown();
   propview_shutdown();
   itemview_shutdown();

   _mempool_cache_free();
}