From: rephorm Date: Thu, 1 Dec 2005 04:07:27 +0000 (+0000) Subject: E_Gadget X-Git-Tag: submit/efl/20131021.015651~14451 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3a28bf9d0036fc37a282fece0e99a88bc588b11;p=platform%2Fupstream%2Fenlightenment.git E_Gadget -------- a quick set of convenience functions for creating gadgets (desktop modules). see gadget_test for an example. documentation still to come :) i still need to comb over and make sure i didn't miss freeing anything... SVN revision: 18742 --- diff --git a/configure.in b/configure.in index 2d303cf..19f0a56 100644 --- a/configure.in +++ b/configure.in @@ -283,6 +283,7 @@ src/lib/Makefile src/bin/Makefile src/modules/Makefile src/modules/test/Makefile +src/modules/gadget_test/Makefile src/modules/ibar/Makefile src/modules/dropshadow/Makefile src/modules/clock/Makefile diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index f290718..aa68afb 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -50,6 +50,7 @@ e_resist.h \ e_startup.h \ e_hints.h \ e_gadman.h \ +e_gadget.h \ e_signals.h \ e_xinerama.h \ e_table.h \ @@ -151,6 +152,7 @@ e_resist.c \ e_startup.c \ e_hints.c \ e_gadman.c \ +e_gadget.c \ e_signals.c \ e_xinerama.c \ e_table.c \ diff --git a/src/bin/e_gadget.c b/src/bin/e_gadget.c new file mode 100644 index 0000000..52ebade --- /dev/null +++ b/src/bin/e_gadget.c @@ -0,0 +1,253 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" + +static void _e_gadget_menu_init(E_Gadget *gad); +static void _e_gadget_cb_menu_edit(void *data, E_Menu *m, E_Menu_Item *mi); +static void _e_gadget_free(E_Gadget *gad); +static void _e_gadget_face_cb_gmc_change(void * data, E_Gadman_Client *gmc, E_Gadman_Change change); +static void _e_gadget_menu_init(E_Gadget *gad); +static void _e_gadget_face_menu_init(E_Gadget_Face *face); +static void _e_gadget_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info); + + +E_Gadget * +e_gadget_new(E_Module *module, + const char *name, + void (*func_face_init) (void *data, E_Gadget_Face *gadget_face), + void (*func_face_free) (void *data, E_Gadget_Face *gadget_face), + void (*func_change) (void *data, E_Gadget_Face *gadget_face, E_Gadman_Client *gmc, E_Gadman_Change change), + void (*func_menu_init) (void *data, E_Gadget *gadget), + void (*func_face_menu_init) (void *data, E_Gadget_Face *gadget_face), + void *data) +{ + E_Gadget *gad; + Evas_List *managers, *l = NULL, *l2 = NULL; + char buf[1024]; + int gadget_count = 0; + + gad = E_OBJECT_ALLOC(E_Gadget, E_GADGET_TYPE, _e_gadget_free); + if (!gad) return NULL; + + gad->module = module; + e_object_ref(E_OBJECT(gad->module)); + + if(!name) return NULL; + gad->name = strdup(name); + + gad->funcs.face_init = func_face_init; + gad->funcs.face_free = func_face_free; + gad->funcs.change = func_change; + gad->funcs.menu_init = func_menu_init; + gad->funcs.face_menu_init = func_face_menu_init; + gad->data = data; + + + /* get all desktop evases, and call init function on them */ + managers = e_manager_list(); + for(l = managers; l; l = l->next) + { + E_Manager *man; + + man = l->data; + for(l2 = man->containers; l2; l2 = l2->next) + { + E_Container *con; + E_Gadget_Face *face; + E_Gadget_Change *change; + Evas_Object *o; + + con = l2->data; + face = E_NEW(E_Gadget_Face, 1); + if (!face) continue; + + face->gad = gad; + face->con = con; + e_object_ref(E_OBJECT(con)); + face->evas = con->bg_evas; + + evas_event_freeze(face->evas); + + /* create an event object */ + + o = evas_object_rectangle_add(con->bg_evas); + face->event_obj = o; + evas_object_layer_set(o, 2); + evas_object_repeat_events_set(o, 1); + evas_object_color_set(o, 0, 0, 0, 0); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_gadget_cb_mouse_down, face); + evas_object_show(o); + + /* create a gadman client */ + snprintf(buf, sizeof(buf), "module.%s", gad->name); + face->gmc = e_gadman_client_new(con->gadman); + e_gadman_client_domain_set(face->gmc, buf, gadget_count++); + + /* call the user init */ + if (gad->funcs.face_init) (gad->funcs.face_init)(gad->data, face); + + _e_gadget_face_menu_init(face); + + change = E_NEW(E_Gadget_Change, 1); + if (change) + { + printf("set change func\n"); + change->gadget = gad; + change->face = face; + } + + /* set up some gadman defaults */ + e_gadman_client_policy_set(face->gmc, + E_GADMAN_POLICY_ANYWHERE | + E_GADMAN_POLICY_HMOVE | + E_GADMAN_POLICY_VMOVE | + E_GADMAN_POLICY_HSIZE | + E_GADMAN_POLICY_VSIZE ); + e_gadman_client_min_size_set(face->gmc, 4, 4); + e_gadman_client_max_size_set(face->gmc, 128, 128); + e_gadman_client_auto_size_set(face->gmc, 40, 40); + e_gadman_client_align_set(face->gmc, 1.0, 1.0); + e_gadman_client_resize(face->gmc, 40, 40); + e_gadman_client_change_func_set(face->gmc, _e_gadget_face_cb_gmc_change, change); + e_gadman_client_load(face->gmc); + evas_event_thaw(face->evas); + + gad->faces = evas_list_append(gad->faces, face); + } + } + _e_gadget_menu_init(gad); + + return gad; +} + +void +e_gadget_face_theme_set(E_Gadget_Face *face, char *category, char *group) +{ + Evas_Object *o; + Evas_Coord x, y, w, h; + if(!face) return; + + o = edje_object_add(face->evas); + face->main_obj = o; + e_theme_edje_object_set(o, category, group); + evas_object_show(o); +} + +static void +_e_gadget_menu_init(E_Gadget *gad) +{ + gad->module->config_menu = gad->menu = e_menu_new(); + if (gad->funcs.menu_init) (gad->funcs.menu_init)(gad->data, gad); +} + +static void +_e_gadget_face_menu_init(E_Gadget_Face *face) +{ + E_Menu_Item *mi; + + face->menu = e_menu_new(); + + mi = e_menu_item_new(face->menu); + e_menu_item_label_set(mi, _("Edit Mode")); + e_menu_item_callback_set(mi, _e_gadget_cb_menu_edit, face); + + if (face->gad->funcs.face_menu_init) (face->gad->funcs.face_menu_init)(face->gad->data, face); +} + +static void +_e_gadget_cb_menu_edit(void *data, E_Menu *m, E_Menu_Item *mi) +{ + E_Gadget_Face *face; + + face = data; + e_gadman_mode_set(face->gmc->gadman, E_GADMAN_MODE_EDIT); +} + +static void +_e_gadget_free(E_Gadget *gad) +{ + Evas_List *l; + + if (!gad) return; + + for (l = gad->faces; l; l = l->next) { + E_Gadget_Face *face = l->data; + + e_object_unref(E_OBJECT(face->con)); + e_object_del(E_OBJECT(face->gmc)); + e_object_del(E_OBJECT(face->menu)); + + if (face->main_obj) evas_object_del(face->main_obj); + if (face->event_obj) evas_object_del(face->event_obj); + if(gad->funcs.face_free) (gad->funcs.face_free)(gad->data, face); + } + + evas_list_free(gad->faces); + gad->module->config_menu = NULL; + e_object_unref(E_OBJECT(gad->module)); + e_object_del(E_OBJECT(gad->menu)); + free(gad->name); + free(gad); + +} + +static void +_e_gadget_face_cb_gmc_change(void * data, E_Gadman_Client *gmc, E_Gadman_Change change) +{ + E_Gadget_Change *gdc = data; + E_Gadget_Face *face; + Evas_Coord x, y, w, h; + + if(!gdc || !gdc->gadget || !gdc->face) return; + + face = gdc->face; + + switch(change) + { + case E_GADMAN_CHANGE_MOVE_RESIZE: + e_gadman_client_geometry_get(face->gmc, &x, &y, &w, &h); + if (face->main_obj) + { + evas_object_move(face->main_obj, x, y); + evas_object_resize(face->main_obj, w, h); + } + if (face->event_obj) + { + evas_object_move(face->event_obj, x, y); + evas_object_resize(face->event_obj, w, h); + } + break; + case E_GADMAN_CHANGE_RAISE: + if (face->main_obj) + { + evas_object_raise(face->main_obj); + } + if (face->event_obj) + { + evas_object_raise(face->event_obj); + } + break; + } + + if (gdc->gadget->funcs.change) (gdc->gadget->funcs.change)(gdc->gadget->data, gdc->face, gmc, change); +} + +static void +_e_gadget_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Down *ev; + E_Gadget_Face *face; + + ev = event_info; + face = data; + if (!face) return; + + if (ev->button == 3 && face->gad->menu) + { + e_menu_activate_mouse(face->menu, e_zone_current_get(face->con), + ev->output.x, ev->output.y, 1, 1, + E_MENU_POP_DIRECTION_DOWN, ev->timestamp); + e_util_container_fake_mouse_up_all_later(face->con); + } +} diff --git a/src/bin/e_gadget.h b/src/bin/e_gadget.h new file mode 100644 index 0000000..0293074 --- /dev/null +++ b/src/bin/e_gadget.h @@ -0,0 +1,67 @@ +#ifdef E_TYPEDEFS + +typedef struct _E_Gadget E_Gadget; +typedef struct _E_Gadget_Face E_Gadget_Face; +typedef struct _E_Gadget_Change E_Gadget_Change; + +#else +#ifndef E_GADGET_H +#define E_GADGET_H + +#define E_GADGET_TYPE 0xE0b01021 + +struct _E_Gadget +{ + E_Object e_obj_inherit; + Evas_List *faces; + + E_Module *module; + char *name; + E_Menu *menu; + + struct { + void (*face_init) (void *data, E_Gadget_Face *gadget_face); + void (*face_free) (void *data, E_Gadget_Face *gadget_face); + void (*change) (void *data, E_Gadget_Face *gadget_face, E_Gadman_Client *gmc, E_Gadman_Change change); + void (*menu_init) (void *data, E_Gadget *gadget); + void (*face_menu_init) (void *data, E_Gadget_Face *gadget_face); + } funcs; + + void *data; +}; + +struct _E_Gadget_Face +{ + E_Gadget *gad; + E_Container *con; + Evas *evas; + + E_Menu *menu; + void *conf; + + Evas_Object *main_obj; + Evas_Object *event_obj; + E_Gadman_Client *gmc; + + void *data; +}; + +struct _E_Gadget_Change +{ + E_Gadget *gadget; + E_Gadget_Face *face; +}; + +E_Gadget *e_gadget_new(E_Module *module, + const char *name, + void (*func_face_init) (void *data, E_Gadget_Face *gadget_face), + void (*func_face_free) (void *data, E_Gadget_Face *gadget_face), + void (*func_change) (void *data, E_Gadget_Face *gadget_face, E_Gadman_Client *gmc, E_Gadman_Change change), + void (*func_menu_init) (void *data, E_Gadget *gadget), + void (*func_face_menu_init) (void *data, E_Gadget_Face *gadget_face), + void *data); + +void e_gadget_face_theme_set(E_Gadget_Face *face, char *category, char *group); + +#endif +#endif diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h index bb97b44..be9245a 100644 --- a/src/bin/e_includes.h +++ b/src/bin/e_includes.h @@ -31,6 +31,7 @@ #include "e_startup.h" #include "e_hints.h" #include "e_gadman.h" +#include "e_gadget.h" #include "e_signals.h" #include "e_xinerama.h" #include "e_table.h"