summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hirt <daniel.hirt@samsung.com>2015-08-02 18:04:02 +0300
committerDaniel Hirt <daniel.hirt@samsung.com>2015-08-02 18:04:02 +0300
commit11aff4d04d88c374e48c009fc3e7a2fadf1f847a (patch)
treea353f4ed21281547bf0343d929ba01afb1ee61aa
parent3893bc4ec151d1dcb38225fcfc928717eec8ce43 (diff)
eo_preload: revise decoration logic and support initial tooltip
-rw-r--r--src/lib/eo_preload.c369
1 files changed, 246 insertions, 123 deletions
diff --git a/src/lib/eo_preload.c b/src/lib/eo_preload.c
index a7be9b9..1cd2c2c 100644
--- a/src/lib/eo_preload.c
+++ b/src/lib/eo_preload.c
@@ -41,19 +41,25 @@ _init_colors()
41 /* Premuls the colors */ 41 /* Premuls the colors */
42} 42}
43 43
44typedef struct 44typedef struct _Debug_Rect Debug_Rect;
45{
46 EINA_INLIST;
47 Evas_Object *obj; /* Evas_Object (Rectangle) */
48} Debug_Rect;
49 45
50typedef struct 46typedef struct
51{ 47{
52 EINA_INLIST; 48 EINA_INLIST;
53 Evas_Object *obj; 49 Evas_Object *obj;
50 Evas_Object *parent;
51 Evas_Object *obj_in; /* Object the mouse is in at the moment */
54 Debug_Rect *rects; 52 Debug_Rect *rects;
55} Debug_Decorate; 53} Debug_Decorate;
56 54
55struct _Debug_Rect
56{
57 EINA_INLIST;
58 Evas_Object *obj; /* Evas_Object (Rectangle) */
59 void *src_data; /* Data associated with rectangle object */
60 Debug_Decorate *dec;
61};
62
57static Debug_Decorate *g_decor = NULL; 63static Debug_Decorate *g_decor = NULL;
58 64
59EAPI Eina_List * 65EAPI Eina_List *
@@ -61,106 +67,243 @@ _evas_textblock_par_rects_get(const Evas_Object *obj);
61EAPI Eina_List * 67EAPI Eina_List *
62_evas_textblock_items_get(const Evas_Object *obj); 68_evas_textblock_items_get(const Evas_Object *obj);
63 69
64static void 70static Evas_Object *
65_textblock_populate_paragraphs(Debug_Decorate *dec) 71_textblock_item_content_cb(void *data,
72 Evas_Object *obj,
73 Evas_Object *tt)
66{ 74{
67 Eina_List *rects; 75 char buf[1024];
68 Eina_Rectangle *rect; 76 Evas_Object *text = elm_label_add(tt);
69 Evas_Coord ox, oy;
70 evas_object_geometry_get(dec->obj, &ox, &oy, NULL, NULL);
71 77
72 /* Decorate Paragraphs */ 78 evas_object_resize(text, 200, 50);
73 rects = _evas_textblock_par_rects_get(dec->obj);
74 EINA_LIST_FREE(rects, rect)
75 {
76 Debug_Rect *r = malloc(sizeof(Debug_Rect));
77 Rect_Color c = colors[color_idx];
78 CYCLE_ARR(colors, color_idx);
79 79
80 r->obj = evas_object_rectangle_add(dec->obj); 80 /* Print to the buf */
81 evas_object_repeat_events_set(r->obj, EINA_TRUE); 81 sprintf(buf, "Item %p<ps>"
82 evas_object_color_set(r->obj, c.r, c.g, c.b, c.a); 82 "Need info here",
83 // printf("Color set to (%d,%d,%d,%d)\n", c.r, c.g, c.b, c.a); 83 obj);
84 evas_object_resize(r->obj, rect->w, rect->h); 84 elm_object_part_text_set(text, "elm.text", buf);
85 evas_object_move(r->obj, ox + rect->x, oy + rect->y);
86 dec->rects = (Debug_Rect *)eina_inlist_append(
87 EINA_INLIST_GET(dec->rects),
88 EINA_INLIST_GET(r));
89 evas_object_show(r->obj);
90 85
91 eina_rectangle_free(rect); 86 return text;
92 }
93 87
94} 88}
95 89
96static Evas_Object * 90static Evas_Object *
97_textblock_item_content_cb(void *data, 91_elm_parent_get(Evas_Object *obj)
92{
93 Evas_Object *p = NULL;
94 while(!p && obj)
95 {
96 eo_do(obj, p = eo_key_data_get("elm-parent"));
97 if (p) break;
98 obj = evas_object_smart_parent_get(obj);
99 }
100 return p;
101}
102
103typedef struct
104{
105 int idx;
106 Evas_Coord x, y, w, h;
107 Eina_Rectangle *rect;
108} Textblock_Item_Debug_Data;
109
110/******** Tooltip *********/
111
112int g_idx = 0;
113
114static Evas_Object *
115_entry_tooltip_content_cb(void *data,
98 Evas_Object *obj, 116 Evas_Object *obj,
99 Evas_Object *tt) 117 Evas_Object *tt)
100{ 118{
119 printf("Entry Tooltip cb\n");
101 char buf[1024]; 120 char buf[1024];
102 Evas_Object *text = elm_label_add(tt); 121 Evas_Object *text = elm_label_add(tt);
103 122
123 Elm_Wrap_Type wrap = elm_entry_line_wrap_get(data);
124
104 evas_object_resize(text, 200, 50); 125 evas_object_resize(text, 200, 50);
105 126
106 /* Print to the buf */ 127 /* Print to the buf */
107 sprintf(buf, "Item %p<ps>" 128 sprintf(buf, "Entry %p<ps>"
108 "Need info here", 129 "Wrap type: %d<ps>"
109 obj); 130 "Time: %d<ps>",
131 obj, wrap, g_idx++);
110 elm_object_part_text_set(text, "elm.text", buf); 132 elm_object_part_text_set(text, "elm.text", buf);
111 133
112 return text; 134 return text;
135}
136
137static Evas_Object *g_tb_in = NULL;
138static void *g_tb_in_data = NULL;
139
140static void
141_handle_item_in(void *data)
142{
143 char buf[1024];
144 Debug_Rect *r = data;
145 Textblock_Item_Debug_Data *d = r->src_data;
146 printf("Item %d in\n", d->idx);
147
148 sprintf(buf,
149 "Item %d<ps>"
150 "Coords: (%d,%d) Size: %dx%d",
151 d->idx,
152 d->x, d->y, d->w, d->h);
153
154 elm_object_tooltip_text_set(r->dec->obj, buf);
155}
113 156
157static void
158_textblock_handle_mouse_in(void *data)
159{
160 Debug_Rect *r = data;
161 elm_object_tooltip_content_cb_set(r->dec->obj, _entry_tooltip_content_cb, r->dec, NULL);
114} 162}
115 163
116static Eina_Bool 164static Eina_Bool
117_item_mouse_in(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info) 165_item_mouse_in(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
118{ 166{
119 printf("Entered item %lu\n", (size_t)data); 167 _handle_item_in(data);
168 return EINA_TRUE;
169}
170
171static Eina_Bool
172_item_mouse_out(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
173{
174 printf("Item out\n");
175
176 if (g_tb_in)
177 {
178 _textblock_handle_mouse_in(g_tb_in_data);
179 }
180
120 return EINA_TRUE; 181 return EINA_TRUE;
121} 182}
122 183
123static void 184static void
124_textblock_populate_items(Debug_Decorate *dec) 185_textblock_populate_items(Evas_Object *tb, Debug_Decorate *dec)
125{ 186{
126 Eina_List *rects; 187 Eina_List *rects;
127 Eina_Rectangle *rect; 188 Textblock_Item_Debug_Data *d;
128 Evas_Coord ox, oy; 189 Evas_Coord ox, oy;
129 evas_object_geometry_get(dec->obj, &ox, &oy, NULL, NULL); 190 evas_object_geometry_get(tb, &ox, &oy, NULL, NULL);
130 191
131 /* Decorate Items */ 192 /* Decorate Items */
132 size_t it_idx = 0; /* Maybe use this for text elements */ 193 size_t it_idx = 0; /* Maybe use this for text elements */
133 rects = _evas_textblock_items_get(dec->obj); 194 rects = _evas_textblock_items_get(tb);
134 EINA_LIST_FREE(rects, rect) 195 EINA_LIST_FREE(rects, d)
135 { 196 {
136 Debug_Rect *r = malloc(sizeof(Debug_Rect)); 197 Debug_Rect *r = malloc(sizeof(Debug_Rect));
137 Rect_Color c = colors[color_idx]; 198 Rect_Color c = colors[color_idx];
138 CYCLE_ARR(colors, color_idx); 199 CYCLE_ARR(colors, color_idx);
139 200
140 r->obj = evas_object_rectangle_add(dec->obj); 201 r->obj = evas_object_rectangle_add(tb);
141 // elm_object_tooltip_content_cb_set(r->obj, _textblock_item_content_cb, NULL, NULL); 202 r->src_data = d;
203 r->dec = dec;
142 evas_object_repeat_events_set(r->obj, EINA_TRUE); 204 evas_object_repeat_events_set(r->obj, EINA_TRUE);
143 eo_do(r->obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_IN, _item_mouse_in, (void *)it_idx++)); 205 eo_do(r->obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_IN, _item_mouse_in, r));
206 eo_do(r->obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_OUT, _item_mouse_out, r));
144 evas_object_color_set(r->obj, c.r, c.g, c.b, c.a); 207 evas_object_color_set(r->obj, c.r, c.g, c.b, c.a);
208 evas_object_resize(r->obj, d->rect->w, d->rect->h);
209 evas_object_move(r->obj, ox + d->rect->x, oy + d->rect->y);
210 dec->rects = (Debug_Rect *)eina_inlist_append(
211 EINA_INLIST_GET(dec->rects),
212 EINA_INLIST_GET(r));
213 evas_object_show(r->obj);
214 }
215}
216
217static Eina_Bool
218_paragraph_mouse_in(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
219{
220 printf("Paragraph in\n");
221 Debug_Rect *r = data;
222 elm_object_tooltip_content_cb_set(r->dec->obj, _entry_tooltip_content_cb, r->dec, NULL);
223
224 return EINA_TRUE;
225}
226
227static void
228_textblock_populate_paragraphs(Evas_Object *tb, Debug_Decorate *dec)
229{
230 Eina_List *rects;
231 Eina_Rectangle *rect;
232 Evas_Coord ox, oy;
233 evas_object_geometry_get(tb, &ox, &oy, NULL, NULL);
234
235 /* Decorate Paragraphs */
236 rects = _evas_textblock_par_rects_get(tb);
237 EINA_LIST_FREE(rects, rect)
238 {
239 Debug_Rect *r = calloc(1, sizeof(Debug_Rect));
240 Rect_Color c = colors[color_idx];
241 CYCLE_ARR(colors, color_idx);
242
243 r->obj = evas_object_rectangle_add(dec->obj);
244 r->dec = dec;
245 evas_object_repeat_events_set(r->obj, EINA_TRUE);
246 eo_do(r->obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_IN, _paragraph_mouse_in, r));
145 evas_object_resize(r->obj, rect->w, rect->h); 247 evas_object_resize(r->obj, rect->w, rect->h);
248 evas_object_color_set(r->obj, c.r, c.g, c.b, c.a);
146 evas_object_move(r->obj, ox + rect->x, oy + rect->y); 249 evas_object_move(r->obj, ox + rect->x, oy + rect->y);
147 dec->rects = (Debug_Rect *)eina_inlist_append( 250 dec->rects = (Debug_Rect *)eina_inlist_append(
148 EINA_INLIST_GET(dec->rects), 251 EINA_INLIST_GET(dec->rects),
149 EINA_INLIST_GET(r)); 252 EINA_INLIST_GET(r));
150 evas_object_show(r->obj); 253 evas_object_show(r->obj);
151
152 eina_rectangle_free(rect); 254 eina_rectangle_free(rect);
153 } 255 }
256}
257
258static Eina_Bool
259_textblock_mouse_in_cb(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
260{
261 printf("Textblock in\n");
262
263 _textblock_handle_mouse_in(data);
264 g_tb_in = obj;
265 g_tb_in_data = data;
154 266
267 return EINA_TRUE;
155} 268}
269
270
156static void 271static void
157_rects_populate(Debug_Decorate *dec) 272_textblock_bg_add(Evas_Object *tb, Debug_Decorate *dec)
273{
274 Debug_Rect *r = calloc(1, sizeof(Debug_Rect));
275 Evas_Coord ox, oy, ow, oh;
276 Rect_Color c = colors[color_idx];
277 CYCLE_ARR(colors, color_idx);
278 evas_object_geometry_get(tb, &ox, &oy, &ow, &oh);
279 r->obj = evas_object_rectangle_add(tb);
280 r->dec = dec;
281 evas_object_repeat_events_set(r->obj, EINA_TRUE);
282 eo_do(r->obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_IN, _textblock_mouse_in_cb, r));
283 //evas_object_color_set(r->obj, 0, 0, 0, 0);
284 evas_object_color_set(r->obj, c.r, c.g, c.b, c.a);
285 evas_object_resize(r->obj, ow, oh);
286 evas_object_move(r->obj, ox, oy);
287 dec->rects = (Debug_Rect *)eina_inlist_append(
288 EINA_INLIST_GET(dec->rects),
289 EINA_INLIST_GET(r));
290 evas_object_show(r->obj);
291}
292
293static void
294_textblock_rects_populate(Evas_Object *tb, Debug_Decorate *dec)
158{ 295{
159 color_idx = 0; 296 color_idx = 0;
160 _textblock_populate_paragraphs(dec); 297 /* This has to be done in the following order,
161 _textblock_populate_items(dec); 298 * so paragraphs rects are created below items
299 * for in/out events to function like indented in this
300 * tool */
301 _textblock_bg_add(tb, dec);
302 // _textblock_populate_paragraphs(tb, dec);
303 _textblock_populate_items(tb, dec);
162} 304}
163 305
306
164/* Clears debug rectangles for given obj */ 307/* Clears debug rectangles for given obj */
165static void 308static void
166_clear_rects(Debug_Decorate *dec) 309_clear_rects(Debug_Decorate *dec)
@@ -170,59 +313,78 @@ _clear_rects(Debug_Decorate *dec)
170 EINA_INLIST_FREE(EINA_INLIST_GET(dec->rects), rect) 313 EINA_INLIST_FREE(EINA_INLIST_GET(dec->rects), rect)
171 { 314 {
172 evas_object_del(rect->obj); 315 evas_object_del(rect->obj);
316 if (rect->src_data)
317 {
318 free(rect->src_data);
319 }
173 dec->rects = (Debug_Rect *) eina_inlist_remove( 320 dec->rects = (Debug_Rect *) eina_inlist_remove(
174 EINA_INLIST_GET(dec->rects), EINA_INLIST_GET(rect)); 321 EINA_INLIST_GET(dec->rects), EINA_INLIST_GET(rect));
175 free(rect); 322 free(rect);
176 } 323 }
177} 324}
178 325
179static void 326static Debug_Decorate *
180_rects_update(Evas_Object *obj) 327_decorate_find(Evas_Object *obj)
181{ 328{
182 /* Find if obj already has entry */ 329 Debug_Decorate *dec = NULL;
183 Debug_Decorate *dec;
184 EINA_INLIST_FOREACH(EINA_INLIST_GET(g_decor), dec) 330 EINA_INLIST_FOREACH(EINA_INLIST_GET(g_decor), dec)
185 { 331 {
186 if (dec->obj == obj) 332 if (dec->obj == obj)
187 break; 333 break;
188 } 334 }
335 return dec;
336}
337
338
339static Debug_Decorate *
340_decorate_update(Evas_Object *obj)
341{
342 /* Find if obj already has entry */
343 Debug_Decorate *dec;
344 dec = _decorate_find(obj);
345
189 if (!dec) 346 if (!dec)
190 { 347 {
191 dec = calloc(1, sizeof(Debug_Decorate)); 348 printf("Error: Couldn't find decorations for %p\n", obj);
192 dec->obj = obj; 349 return NULL;
193 g_decor = (Debug_Decorate *) eina_inlist_append(
194 EINA_INLIST_GET(g_decor),
195 EINA_INLIST_GET(dec));
196 } 350 }
197 else 351
198 { 352 _clear_rects(dec);
199 _clear_rects(dec); 353 return dec;
200 }
201 _rects_populate(dec);
202} 354}
203 355
204static void 356static void
205_decorate_textblock(Evas_Object *obj) 357_decorate_entry(Evas_Object *obj)
206{ 358{
207 _rects_update(obj); 359 Debug_Decorate *dec = _decorate_update(obj);
360 Evas_Object *tb = elm_entry_textblock_get(obj);
361 _textblock_rects_populate(tb, dec);
208} 362}
209 363
210Eina_Bool
211_timer_cb(void *data)
212{
213 /* Iterate the list and decorate all tracked items */
214 Eina_List *i;
215 Evas_Object *obj; /* ATM all tracked objects are Evas_Objects */
216
217 EINA_LIST_FOREACH(tracked, i, obj)
218 {
219 if (eo_isa(obj, EVAS_TEXTBLOCK_CLASS))
220 _decorate_textblock(obj);
221 }
222 364
365static Eina_Bool
366_on_entry_changed(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
367{
368 printf("Changed\n");
369 Evas_Object *tb = elm_entry_textblock_get(obj);
370 _decorate_entry(obj);
223 return EINA_TRUE; 371 return EINA_TRUE;
224} 372}
225 373
374static Debug_Decorate *
375_decorate_create(Evas_Object *obj)
376{
377 Debug_Decorate *dec;
378 dec = calloc(1, sizeof(Debug_Decorate));
379 dec->obj = obj;
380 g_decor = (Debug_Decorate *) eina_inlist_append(
381 EINA_INLIST_GET(g_decor),
382 EINA_INLIST_GET(dec));
383 return dec;
384}
385
386/******** Handlers ********/
387
226static Eina_Bool 388static Eina_Bool
227_on_obj_del(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info) 389_on_obj_del(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
228{ 390{
@@ -232,32 +394,6 @@ _on_obj_del(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_i
232 394
233static Eina_Bool g_debug_enabled = EINA_TRUE; 395static Eina_Bool g_debug_enabled = EINA_TRUE;
234 396
235/******** Tooltip *********/
236
237static Evas_Object *
238_textblock_tooltip_content_cb(void *data,
239 Evas_Object *obj,
240 Evas_Object *tt)
241{
242 char buf[1024];
243 g_debug_enabled = EINA_FALSE; /* Workaround that indicates when the first
244 tooltip was called so we can stop
245 tracking objects */
246 Evas_Object *text = elm_label_add(tt);
247
248 Elm_Wrap_Type wrap = elm_entry_line_wrap_get(data);
249
250 evas_object_resize(text, 200, 50);
251
252 /* Print to the buf */
253 sprintf(buf, "Entry %p<ps>"
254 "Wrap type: %d<ps>",
255 obj, wrap);
256 elm_object_part_text_set(text, "elm.text", buf);
257
258 return text;
259}
260
261/******** PRELOADS ********/ 397/******** PRELOADS ********/
262 398
263EAPI Eo * 399EAPI Eo *
@@ -268,37 +404,24 @@ _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo
268 404
269 ret = _eo_add_start(file, line, klass_id, parent_id, ref); 405 ret = _eo_add_start(file, line, klass_id, parent_id, ref);
270 406
271 if (g_debug_enabled) 407 if (eo_isa(ret, ELM_ENTRY_CLASS))
272 { 408 {
273 if (eo_isa(ret, EVAS_TEXTBLOCK_CLASS)) 409 Debug_Decorate *dec = _decorate_create(ret);
274 { 410 eo_do(ret, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED, _on_entry_changed, dec));
275 tracked = eina_list_append(tracked, ret); 411 eo_do(ret, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED_USER, _on_entry_changed, dec));
276 eo_do(ret, eo_event_callback_add(EVAS_OBJECT_EVENT_DEL, _on_obj_del, NULL)); 412 eo_do(ret, eo_event_callback_add(EVAS_OBJECT_EVENT_RESIZE, _on_entry_changed, dec));
277 } 413 eo_do(ret, eo_event_callback_add(EVAS_OBJECT_EVENT_DEL, _on_obj_del, dec));
278 if (eo_isa(ret, ELM_ENTRY_CLASS)) 414
279 { 415 elm_object_tooltip_content_cb_set(ret, _entry_tooltip_content_cb, dec, NULL);
280 // elm_object_tooltip_content_cb_set(ret, _textblock_tooltip_content_cb, NULL, NULL); 416 elm_object_tooltip_show_delay_set(ret, 0.0);
281 elm_object_tooltip_show_delay_set(ret, 0.0);
282 eo_do(ret, eo_event_callback_add(EVAS_OBJECT_EVENT_DEL, _on_obj_del, NULL));
283 }
284 } 417 }
285 return ret; 418 return ret;
286} 419}
287 420
288static Eina_Bool
289_timer_disable_debug_cb(void *data)
290{
291 g_debug_enabled = EINA_FALSE;
292 printf("Disabled debug (timeout)\n");
293 return EINA_FALSE;
294}
295
296EAPI void 421EAPI void
297elm_run() 422elm_run()
298{ 423{
299 void (*f)() = dlsym(RTLD_NEXT, __func__); 424 void (*f)() = dlsym(RTLD_NEXT, __func__);
300 _init_colors(); 425 _init_colors();
301 ecore_timer_add(0.1, _timer_cb, NULL);
302// ecore_timer_add(3, _timer_disable_debug_cb, NULL);
303 f(); 426 f();
304} 427}