diff options
author | David Walter Seikel | 2014-05-12 08:29:43 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-05-12 08:29:43 +1000 |
commit | 3314ac30f127e43d279b4e4384ee98389c4b137a (patch) | |
tree | 00b2ff8471dc33a745036857dc8da47716e6ec6c /src/libraries | |
parent | widgetAdd now does the box / grid decision, and some oter things moved into it. (diff) | |
download | SledjHamr-3314ac30f127e43d279b4e4384ee98389c4b137a.zip SledjHamr-3314ac30f127e43d279b4e4384ee98389c4b137a.tar.gz SledjHamr-3314ac30f127e43d279b4e4384ee98389c4b137a.tar.bz2 SledjHamr-3314ac30f127e43d279b4e4384ee98389c4b137a.tar.xz |
Move poor mans introspection into winFang.c, and use it in purkle.
Diffstat (limited to 'src/libraries')
-rw-r--r-- | src/libraries/SledjHamr.h | 3 | ||||
-rw-r--r-- | src/libraries/winFang.c | 92 | ||||
-rw-r--r-- | src/libraries/winFang.h | 29 |
3 files changed, 103 insertions, 21 deletions
diff --git a/src/libraries/SledjHamr.h b/src/libraries/SledjHamr.h index 956b37e..aee845d 100644 --- a/src/libraries/SledjHamr.h +++ b/src/libraries/SledjHamr.h | |||
@@ -14,6 +14,9 @@ | |||
14 | #include <Elementary.h> | 14 | #include <Elementary.h> |
15 | 15 | ||
16 | 16 | ||
17 | #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) | ||
18 | |||
19 | |||
17 | void HamrTime(void *elm_main, char *domain); | 20 | void HamrTime(void *elm_main, char *domain); |
18 | 21 | ||
19 | #endif | 22 | #endif |
diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index 4eb4a7b..d7feb39 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c | |||
@@ -1,6 +1,8 @@ | |||
1 | #include "winFang.h" | 1 | #include "winFang.h" |
2 | 2 | ||
3 | 3 | ||
4 | |||
5 | |||
4 | static void _checkWindowBounds(winFang *win, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) | 6 | static void _checkWindowBounds(winFang *win, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) |
5 | { | 7 | { |
6 | Evas_Object *test; | 8 | Evas_Object *test; |
@@ -341,43 +343,93 @@ void winFangDel(winFang *win) | |||
341 | EINA_CLIST_FOR_EACH_ENTRY(wid, &win->widgets, Widget, node) | 343 | EINA_CLIST_FOR_EACH_ENTRY(wid, &win->widgets, Widget, node) |
342 | { | 344 | { |
343 | if (wid->on_del) wid->on_del(wid, wid->obj, NULL); | 345 | if (wid->on_del) wid->on_del(wid, wid->obj, NULL); |
346 | widgetDel(wid); | ||
344 | eo_unref(wid->obj); | 347 | eo_unref(wid->obj); |
345 | } | 348 | } |
346 | if (win->on_del) win->on_del(win, win->win, NULL); | 349 | if (win->on_del) win->on_del(win, win->win, NULL); |
347 | evas_object_del(win->win); | 350 | evas_object_del(win->win); |
348 | } | 351 | } |
349 | 352 | ||
350 | Widget *widgetAdd(winFang *win, const Eo_Class *klass, char *title, int x, int y, int w, int h) | 353 | |
354 | static widgetSpec widgetClasses[15]; | ||
355 | |||
356 | Widget *widgetAdd(winFang *win, char *type , char *title, int x, int y, int w, int h) | ||
351 | { | 357 | { |
352 | Widget *result; | 358 | Widget *result; |
359 | const Eo_Class *klass = NULL; | ||
360 | int i; | ||
353 | 361 | ||
354 | result = calloc(1, sizeof(Widget)); | 362 | // Poor mans introspection. |
355 | strcpy(result->magic, "Widget"); | 363 | if (NULL == widgetClasses[0].name) |
356 | eina_clist_add_head(&win->widgets, &result->node); | 364 | { |
357 | 365 | i = 0; | |
358 | result->obj = eo_add(klass, win->win, | 366 | widgetClasses[i].name = WT_CHECK; widgetClasses[i++].klass = ELM_OBJ_CHECK_CLASS; |
359 | evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), | 367 | widgetClasses[i].name = WT_BOX; widgetClasses[i++].klass = ELM_OBJ_BOX_CLASS; |
360 | evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), | 368 | widgetClasses[i].name = WT_BUTTON; widgetClasses[i++].klass = ELM_OBJ_BUTTON_CLASS; |
361 | evas_obj_visibility_set(EINA_TRUE), | 369 | widgetClasses[i].name = WT_ENTRY; widgetClasses[i++].klass = ELM_OBJ_ENTRY_CLASS; |
362 | eo_key_data_set("Widget", result, NULL) | 370 | widgetClasses[i].name = WT_FILES; widgetClasses[i++].klass = ELM_OBJ_FILESELECTOR_CLASS; |
363 | ); | 371 | widgetClasses[i].name = WT_GRID; widgetClasses[i++].klass = ELM_OBJ_GRID_CLASS; |
372 | widgetClasses[i].name = WT_HOVER; widgetClasses[i++].klass = ELM_OBJ_HOVERSEL_CLASS; | ||
373 | widgetClasses[i].name = WT_IMAGE; widgetClasses[i++].klass = ELM_OBJ_IMAGE_CLASS; | ||
374 | widgetClasses[i].name = WT_LABEL; widgetClasses[i++].klass = ELM_OBJ_LABEL_CLASS; | ||
375 | widgetClasses[i].name = WT_LAYOUT; widgetClasses[i++].klass = ELM_OBJ_LAYOUT_CLASS; | ||
376 | widgetClasses[i].name = WT_RADIO; widgetClasses[i++].klass = ELM_OBJ_RADIO_CLASS; | ||
377 | widgetClasses[i].name = WT_RECT; widgetClasses[i++].klass = EVAS_OBJ_RECTANGLE_CLASS; | ||
378 | widgetClasses[i].name = WT_TEXT; widgetClasses[i++].klass = EVAS_OBJ_TEXT_CLASS; | ||
379 | widgetClasses[i].name = WT_TEXTBOX; widgetClasses[i++].klass = ELM_OBJ_ENTRY_CLASS; | ||
380 | widgetClasses[i].name = WT_TOOLBAR; widgetClasses[i++].klass = ELM_OBJ_TOOLBAR_CLASS; | ||
381 | } | ||
364 | 382 | ||
365 | if (x < 0) | 383 | for (i = 0; i < ARRAY_LENGTH(widgetClasses); i++) |
366 | elm_layout_box_append(win->win, WF_BOX, result->obj); | 384 | { |
367 | else | 385 | if (strcmp(type, widgetClasses[i].name) == 0) |
368 | elm_grid_pack(win->grid, result->obj, x, y, w, h); | 386 | { |
369 | winFangCalcMinSize(win); | 387 | klass = widgetClasses[i].klass; |
388 | break; | ||
389 | } | ||
390 | } | ||
370 | 391 | ||
371 | if (title) | 392 | if (klass) |
372 | { | 393 | { |
373 | result->label = strdup(title); | 394 | result = calloc(1, sizeof(Widget)); |
374 | elm_object_text_set(result->obj, result->label); | 395 | strcpy(result->magic, "Widget"); |
375 | evas_object_name_set(result->obj, title); | 396 | strcpy(result->type, type); |
397 | eina_clist_add_head(&win->widgets, &result->node); | ||
398 | |||
399 | result->obj = eo_add(klass, win->win, | ||
400 | evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), | ||
401 | evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), | ||
402 | evas_obj_visibility_set(EINA_TRUE), | ||
403 | eo_key_data_set("Widget", result, NULL) | ||
404 | ); | ||
405 | |||
406 | if (x < 0) | ||
407 | elm_layout_box_append(win->win, WF_BOX, result->obj); | ||
408 | else | ||
409 | elm_grid_pack(win->grid, result->obj, x, y, w, h); | ||
410 | winFangCalcMinSize(win); | ||
411 | |||
412 | if (title) | ||
413 | { | ||
414 | result->label = strdup(title); | ||
415 | elm_object_text_set(result->obj, result->label); | ||
416 | evas_object_name_set(result->obj, title); | ||
417 | } | ||
376 | } | 418 | } |
377 | 419 | ||
378 | return result; | 420 | return result; |
379 | } | 421 | } |
380 | 422 | ||
423 | void widgetDel(Widget *wid) | ||
424 | { | ||
425 | if (wid) | ||
426 | { | ||
427 | // TODO - This is to work around a bug in Elm entry, remove it when the bug is fixed. | ||
428 | // The bug is that editable entry widgets cause the app to hang on exit. | ||
429 | if (strcmp(WT_ENTRY, wid->type) == 0) | ||
430 | elm_entry_editable_set(wid->obj, EINA_FALSE); | ||
431 | } | ||
432 | } | ||
381 | 433 | ||
382 | /* CALLBACK types | 434 | /* CALLBACK types |
383 | 435 | ||
diff --git a/src/libraries/winFang.h b/src/libraries/winFang.h index 1bdef20..edec11b 100644 --- a/src/libraries/winFang.h +++ b/src/libraries/winFang.h | |||
@@ -8,6 +8,8 @@ | |||
8 | /* Enable access to unstable EFL EO API. */ | 8 | /* Enable access to unstable EFL EO API. */ |
9 | #define EFL_EO_API_SUPPORT 1 | 9 | #define EFL_EO_API_SUPPORT 1 |
10 | 10 | ||
11 | #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) | ||
12 | |||
11 | 13 | ||
12 | #include <Eo.h> | 14 | #include <Eo.h> |
13 | #include <Eina.h> | 15 | #include <Eina.h> |
@@ -24,6 +26,29 @@ | |||
24 | #define WF_SWALLOW "winFang/content" | 26 | #define WF_SWALLOW "winFang/content" |
25 | 27 | ||
26 | 28 | ||
29 | typedef struct _widgetSpec | ||
30 | { | ||
31 | char *name; | ||
32 | const Eo_Class *klass; | ||
33 | } widgetSpec; | ||
34 | |||
35 | #define WT_CHECK "check" | ||
36 | #define WT_BOX "box" | ||
37 | #define WT_BUTTON "button" | ||
38 | #define WT_FILES "files" | ||
39 | #define WT_ENTRY "entry" | ||
40 | #define WT_GRID "grid" | ||
41 | #define WT_HOVER "hoversel" | ||
42 | #define WT_IMAGE "image" | ||
43 | #define WT_LABEL "label" | ||
44 | #define WT_LAYOUT "layout" | ||
45 | #define WT_RADIO "radio" | ||
46 | #define WT_RECT "rectangle" | ||
47 | #define WT_TEXT "text" | ||
48 | #define WT_TEXTBOX "textbox" | ||
49 | #define WT_TOOLBAR "toolbar" | ||
50 | |||
51 | |||
27 | typedef struct _winFang | 52 | typedef struct _winFang |
28 | { | 53 | { |
29 | Evas *e; | 54 | Evas *e; |
@@ -48,6 +73,7 @@ typedef struct _winFang | |||
48 | typedef struct _Widget | 73 | typedef struct _Widget |
49 | { | 74 | { |
50 | char magic[8]; | 75 | char magic[8]; |
76 | char type[16]; | ||
51 | Evas_Object *obj; | 77 | Evas_Object *obj; |
52 | 78 | ||
53 | char *label, *look, *action, *help; | 79 | char *label, *look, *action, *help; |
@@ -67,6 +93,7 @@ void winFangShow(winFang *win); | |||
67 | void winFangCalcMinSize(winFang *win); | 93 | void winFangCalcMinSize(winFang *win); |
68 | void winFangDel(winFang *win); | 94 | void winFangDel(winFang *win); |
69 | 95 | ||
70 | Widget *widgetAdd(winFang *win, const Eo_Class *klass, char *title, int x, int y, int w, int h); | 96 | Widget *widgetAdd(winFang *win, char *type, char *title, int x, int y, int w, int h); |
97 | void widgetDel(Widget *wid); | ||
71 | 98 | ||
72 | #endif | 99 | #endif |