Enlightenment CVS committal Author : onefang Project : e_modules Module : emu
Dir : e_modules/emu/src/modules/emu Modified Files: Makefile.am e_mod_config.c e_mod_main.c e_mod_main.h Added Files: easy_menu.c easy_menu.h Log Message: Make the fancy menu stuff generic. =================================================================== RCS file: /cvsroot/enlightenment/e_modules/emu/src/modules/emu/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- Makefile.am 27 Jan 2006 03:43:32 -0000 1.2 +++ Makefile.am 27 Jan 2006 23:36:40 -0000 1.3 @@ -31,6 +31,8 @@ pkg_LTLIBRARIES = module.la module_la_SOURCES = e_mod_main.c \ e_mod_main.h \ + easy_menu.c \ + easy_menu.h \ e_mod_config.c \ e_mod_config.h module_la_LIBADD = @e_libs@ =================================================================== RCS file: /cvsroot/enlightenment/e_modules/emu/src/modules/emu/e_mod_config.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- e_mod_config.c 27 Jan 2006 03:43:32 -0000 1.1 +++ e_mod_config.c 27 Jan 2006 23:36:40 -0000 1.2 @@ -1,7 +1,4 @@ -#include "e.h" #include "e_mod_main.h" -#include "e_mod_config.h" -#include "config.h" typedef struct _Cfg_File_Data Cfg_File_Data; =================================================================== RCS file: /cvsroot/enlightenment/e_modules/emu/src/modules/emu/e_mod_main.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e_mod_main.c 27 Jan 2006 03:43:32 -0000 1.2 +++ e_mod_main.c 27 Jan 2006 23:36:40 -0000 1.3 @@ -47,7 +47,6 @@ /* Support functions. */ static void _emu_add_face_menu(E_Gadget_Face *face, E_Menu *menu); -static struct _Menu_Data *_emu_add_menus(Emu_Face *emu_face, char *input, char *end, int *i, int level); /* Ecore_Exe callback functions. */ static int _emu_cb_exe_add(void *data, int type, void *ev); @@ -58,12 +57,8 @@ static void _emu_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _emu_menu_cb_post_deactivate(void *data, E_Menu *m); -static void _emu_menu_cb_create(E_Menu *m, void *category_data, void *data); -static void _emu_menu_cb_destroy(void *data); - static void _emu_menu_cb_action(void *data, E_Menu *m, E_Menu_Item *mi); static Evas_Bool _emu_menus_hash_cb_free(Evas_Hash *hash, const char *key, void *data, void *fdata); -static void _emu_menu_cb_free(void *obj); static void _emu_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi); @@ -565,79 +560,45 @@ static void _emu_parse_menu(Emu_Face *emu_face, char *name, int start, int end) { - Emu_Menu_Data *menu; + char *category = NULL; + int length; - menu = E_NEW(Emu_Menu_Data, 1); - if (menu) - { - int i = 0; - int len; - int length; - int level = 0; - Emu_Menu_Data *old_menu; - - if (name == NULL) - { /* Default sub menu item text is the name of the face. */ - name = (char *) emu_face->name; - menu->category = ""; - } - else - i = 1; + /* Calculate the length of the menu data. */ + length = (emu_face->lines[end].line + emu_face->lines[end].size) - emu_face->lines[start].line; - /* Calculate the amount of ram to allocate. */ - len = strlen(name); - length = (emu_face->lines[end].line + emu_face->lines[end].size) - emu_face->lines[start].line; + if (length > 0) + { + Easy_Menu *menu; + if (name == NULL) /* Default sub menu item text is the name of the face. */ + name = (char *) emu_face->name; + else + { /* The category is after the name. */ + category = name; + while ((*category != '|') && (*category != '\0')) + category++; + if (*category == '|') + *category++ = '\0'; + else + category = NULL; + } - if ((len > 0) && (length > 0)) + /* Turn the command data into a menu. */ + menu = easy_add_menus(name, category, emu_face->lines[start].line, length, _emu_menu_cb_action, emu_face->exe); + if (menu) { - /* Allocate the ram. */ - menu->buffer = malloc(length + 1); - menu->name = malloc(len + 1); - - if ((menu->buffer) && (menu->name)) - { - memcpy(menu->buffer, emu_face->lines[start].line, length); - memcpy(menu->name, name, len + 1); + Easy_Menu *old_menu; - /* If the flag is set, find the category. */ - if (i) - { - menu->category = menu->name; - while ((*menu->category != '|') && (*menu->category != '\0')) - menu->category++; - if (*menu->category == '|') - *menu->category++ = '\0'; - else - menu->category = ""; - } - - /* Turn the command data into a menu. */ - i = 0; /* Use this as for the current position tracker now. */ - menu->menu = _emu_add_menus(emu_face, menu->buffer, menu->buffer + length, &i, level); - if (menu->menu) - { - e_object_data_set(E_OBJECT(menu->menu->menu), menu); - e_object_del_attach_func_set(E_OBJECT(menu->menu->menu), _emu_menu_cb_free); - - /* Associate this menu with it's category. Only one menu per category. */ - old_menu = evas_hash_find(emu_face->menus, menu->category); - if (old_menu) - { /* Clean up the old one. */ - emu_face->menus = evas_hash_del(emu_face->menus, menu->category, old_menu); - emu_face->menus = evas_hash_del(emu_face->menus, NULL, old_menu); /* Just to be on the safe side. */ - e_object_del(E_OBJECT(old_menu->menu->menu)); - } - /* evas_hash_direct_add is used because we allocate the key ourselves and don't deallocate it until after removing it. */ - emu_face->menus = evas_hash_direct_add(emu_face->menus, menu->category, menu); - - /* The default category is the empty string, and it's handled differently. */ - if (strlen(menu->category) != 0) - menu->category_cb = e_menu_category_callback_add(menu->category, _emu_menu_cb_create, _emu_menu_cb_destroy, menu); - - menu->valid = 1; - } - } + /* Associate this menu with it's category. Only one menu per category. */ + old_menu = evas_hash_find(emu_face->menus, menu->category); + if (old_menu) + { /* Clean up the old one. */ + emu_face->menus = evas_hash_del(emu_face->menus, menu->category, old_menu); + emu_face->menus = evas_hash_del(emu_face->menus, NULL, old_menu); /* Just to be on the safe side. */ + e_object_del(E_OBJECT(old_menu->menu->menu)); + } + /* evas_hash_direct_add is used because we allocate the key ourselves and don't deallocate it until after removing it. */ + emu_face->menus = evas_hash_direct_add(emu_face->menus, menu->category, menu); } } } @@ -723,119 +684,10 @@ face = data; if (!face) return; emu_face = face->data; - _config_ibar_module(face->con, emu_face->emu); + _config_emu_module(face->con, emu_face->emu); } /** - * Construct a menu. - * - * This is a recursive fyunction that constructs a full menu with sub menus. - * - * @param emu_face the pointer to your face. - * @param input the start of the description of the menu. - * @param end the end of the description of the menu. - * @param i Used to track the currently parsed portion of the menu description during recursion. - * @param level the current menu level. - * @ingroup Emu_Module_Support_Group - */ -static struct _Menu_Data * -_emu_add_menus(Emu_Face *emu_face, char *input, char *end, int *i, int level) -{ - char *oldInput = input; - struct _Menu_Data *menu = calloc(1, sizeof(struct _Menu_Data)); - struct _Menu_Item_Data *item = NULL; - - menu->menu = e_menu_new(); - while (input < end) - { - int count = 0; - - /* Skip spaces, but count them so we know what level this line is at. */ - while (*(input + count) == ' ') - count++; - if (count == level) - { /* Good, we are on the level. */ - input += count; - if(item == NULL) - { /* This is the first one on this level. */ - item = calloc(1, sizeof(struct _Menu_Item_Data)); - menu->items = item; - } - else - { /* Next! */ - item->next = calloc(1, sizeof(struct _Menu_Item_Data)); - item = item->next; - } - - /* Setup the currently known item stuff. */ - item->item = e_menu_item_new(menu->menu); - item->name = input; - item->action = input; - item->exe = emu_face->exe; - - /* Parse the options. */ - while ((input < end) && (*input != '|') && (*input != '\0') && (*input != '\n')) - input++; - if ((input < end) && (*input == '|')) - { /* Found an action. */ - *(input++) = '\0'; - item->action = input; - /* Keep parsing. */ - while ((input < end) && (*input != '|') && (*input != '\0') && (*input != '\n')) - input++; - if ((input < end) && (*input == '|')) - { /* Found an edje. */ - *(input++) = '\0'; - item->edje = input; - /* Now we are just looking for the end of the edge. */ - while ((input < end) && (*input != '\0') && (*input != '\n')) - input++; - } - } - *(input++) = '\0'; - if (menu->name == NULL) - { /* If we haven't done so already, setup the menu name and level. */ - menu->level = level; - menu->name = item->name; - } - - if ((item->name[0] == '-') && (item->name[1] == '\0')) - e_menu_item_separator_set(item->item , 1); - else - { /* Set up the item with our parsed data. */ - e_menu_item_label_set(item->item , _(item->name)); - if (item->edje) - e_util_menu_item_edje_icon_set(item->item , item->edje); - if (item->action) - e_menu_item_callback_set(item->item , _emu_menu_cb_action, item); - } - } - else if (count > level) - { /* We have to add a sub menu here. */ - struct _Menu_Data *last_menu = menu; - - /* Seek out the end of the list, so we can add onto it. */ - while (last_menu->next != NULL) - last_menu = last_menu->next; - - /* A recursing we will go. */ - last_menu->next = _emu_add_menus(emu_face, input, end, i, level + 1); - e_menu_item_submenu_set(item->item , last_menu->next->menu); - /* The recursion completed this much parsing for us, catch up. */ - input = input + (*i); - } - else if (count < level) - /* Finished with this level, go back one. */ - break; - } - - /* Figure out how much we parsed, so the previous level can catch up. */ - (*i) = input - oldInput; - return menu; -} - - -/** * @defgroup Emu_Module_Exe_Group Emu module Ecore_Exe interface * * Structures and functions that deal with the Ecore_Exe API. @@ -1080,7 +932,7 @@ } else if (ev->button == 1) { /* Left click default menu. */ - Emu_Menu_Data *menu; + Easy_Menu *menu; /* Find the default menu, if there is one. */ menu = evas_hash_find(emu_face->menus, ""); @@ -1113,56 +965,6 @@ /** - * Handle sub menu creation for a menu category. - * - * @param m the menu. - * @param category_data unused. - * @param data the pointer you passed to e_menu_category_callback_add(). - * @ingroup Emu_Module_Menu_Group - */ -static void -_emu_menu_cb_create(E_Menu *m, void *category_data, void *data) -{ - Emu_Menu_Data *menu; - - menu = data; - if ((menu) && (m) && (menu->valid)) - { - /* Since this is created relative to the possed in menu, we teed to create it each time. */ - menu->item = e_menu_item_new(m); - if (menu->item) - { - /* Tack on the sub menu. */ - e_menu_item_label_set(menu->item , menu->name); - e_menu_item_submenu_set(menu->item , menu->menu->menu); - } - } -} - -/** - * Handle sub menu destruction for a menu category. - * - * @param data the pointer you passed to e_menu_category_callback_add(). - * @ingroup Emu_Module_Menu_Group - */ -static void -_emu_menu_cb_destroy(void *data) -{ - Emu_Menu_Data *menu; - - menu = data; - if (menu) - { - if (menu->item) - { - e_object_del(E_OBJECT(menu->item)); - menu->item = NULL; - } - } -} - - -/** * Handle menu item activation. * * @param data the pointer you passed to e_menu_item_callback_set(). @@ -1176,10 +978,13 @@ struct _Menu_Item_Data *item; item = data; - if (item->exe) + if (item->data) { - ecore_exe_send(item->exe, item->action, strlen(item->action)); - ecore_exe_send(item->exe, "\n", 1); + Ecore_Exe *exe; + + exe = item->data; + ecore_exe_send(exe, item->action, strlen(item->action)); + ecore_exe_send(exe, "\n", 1); } } @@ -1198,7 +1003,7 @@ static Evas_Bool _emu_menus_hash_cb_free(Evas_Hash *hash, const char *key, void *data, void *fdata) { - Emu_Menu_Data *menu; + Easy_Menu *menu; menu = data; if ((menu) && (menu->menu) && (menu->menu->menu)) @@ -1206,71 +1011,6 @@ return 1; } -/** - * Handle menu freeing. - * - * @param obj the pointer you passed to e_object_data_set(). - * @ingroup Emu_Module_Menu_Group - */ -static void -_emu_menu_cb_free(void *obj) -{ - Emu_Menu_Data *menu; - - menu = e_object_data_get(E_OBJECT(obj)); - if (menu) - { - int first = TRUE; - - menu->valid = 0; /* TO be on the safe side. */ - - /* Unlink it from the menu category. */ - if (menu->category_cb) - e_menu_category_callback_del(menu->category_cb); - - if (menu->item) - { - e_object_del(E_OBJECT(menu->item)); - menu->item = NULL; - } - - /* Go through the attached menu structure, freeing it all. */ - if (menu->menu) - { - struct _Menu_Data *next = NULL; - struct _Menu_Data *men; - - men = menu->menu; - while (men != NULL) - { - struct _Menu_Item_Data *item = men->items; - struct _Menu_Item_Data *next_item = NULL; - - next = men->next; - while (item != NULL) - { - next_item = item->next; - e_object_del(E_OBJECT(item->item)); - free(item); - item = next_item; - } - if (first) /* The first one is ourself, we are already being deleted, so don't delete us again. */ - first = FALSE; - else - e_object_del(E_OBJECT(men->menu)); - free(men); - men = next; - } - menu->menu = NULL; - } - - E_FREE(menu->name); - E_FREE(menu->buffer); - E_FREE(menu); - } -} - - void _emu_cb_config_updated(void *data) { =================================================================== RCS file: /cvsroot/enlightenment/e_modules/emu/src/modules/emu/e_mod_main.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e_mod_main.h 27 Jan 2006 03:43:32 -0000 1.2 +++ e_mod_main.h 27 Jan 2006 23:36:40 -0000 1.3 @@ -1,3 +1,8 @@ +#include "e.h" +#include "easy_menu.h" +#include "e_mod_config.h" +#include "config.h" + #ifndef E_MOD_MAIN_H #define E_MOD_MAIN_H @@ -25,38 +30,6 @@ unsigned char enabled; }; -struct _Menu_Item_Data -{ - E_Menu_Item *item; - char *name; - char *action; - char *edje; /* FIXME: make this similar to the e_modapi_info() shit. */ - Ecore_Exe *exe; - struct _Menu_Item_Data *next; -}; - -struct _Menu_Data -{ - E_Menu *menu; - int level; - char *name; - struct _Menu_Data *next; - struct _Menu_Item_Data *items; -}; - -typedef struct _Emu_Menu_Data Emu_Menu_Data; -struct _Emu_Menu_Data -{ - struct _Menu_Data *menu; - E_Menu_Category_Callback *category_cb; - char *buffer; - - char *name; - char *category; - E_Menu_Item *item; - int valid; /* Probably just being paranoid. This prevents this structure from being used when it isn't complete. */ -}; - typedef struct _Emu Emu; struct _Emu ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs