You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

5921 lines
187 KiB

#include "e.h"
/*
* TODO: gadcon client ordering on drop
*/
#define E_LAYOUT_ITEM_DRAG_RESIST_LEVEL 10
static void _e_gadcon_event_populate(E_Gadcon *gc);
static Eina_Bool _e_gadcon_client_populate(E_Gadcon *gc, const E_Gadcon_Client_Class *cc, E_Config_Gadcon_Client *cf_gcc);
static void _e_gadcon_client_unpopulate(E_Gadcon_Client *gcc);
static void _e_gadcon_free(E_Gadcon *gc);
static void _e_gadcon_client_free(E_Gadcon_Client *gcc);
static void _e_gadcon_moveresize_handle(E_Gadcon_Client *gcc);
static Eina_Bool _e_gadcon_cb_client_scroll_timer(void *data);
static void _e_gadcon_client_scroll_state_update(E_Gadcon_Client *gcc);
static Eina_Bool _e_gadcon_cb_client_scroll_animator(void *data);
static void _e_gadcon_cb_client_frame_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_client_frame_moveresize(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_gadcon_client_save(E_Gadcon_Client *gcc);
static void _e_gadcon_client_drag_begin(E_Gadcon_Client *gcc, int x, int y);
static void _e_gadcon_client_inject(E_Gadcon *gc, E_Gadcon_Client *gcc, int x, int y);
static void _e_gadcon_cb_min_size_request(void *data, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_size_request(void *data, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_hide(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_show(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_moveresize(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_parent_resize_cb(E_Gadcon *gc, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static void _e_gadcon_cb_client_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_client_mouse_in(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_client_mouse_out(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_client_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_cb_client_resize(void *data, Evas *evas, Evas_Object *obj, void *event_info);
static void _e_gadcon_client_move_start(E_Gadcon_Client *gcc);
static void _e_gadcon_client_move_stop(E_Gadcon_Client *gcc);
static void _e_gadcon_client_move_go(E_Gadcon_Client *gcc);
static void _e_gadcon_cb_signal_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_move_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_move_go(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_resize_left_start(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_resize_left_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_resize_left_go(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_resize_right_start(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_resize_right_stop(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_signal_resize_right_go(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_gadcon_cb_dnd_enter(void *data, const char *type, void *event);
static void _e_gadcon_cb_dnd_move(void *data, const char *type, void *event);
static void _e_gadcon_cb_dnd_leave(void *data, const char *type, void *event);
static void _e_gadcon_cb_dnd_drop(void *data, const char *type, void *event);
static int _e_gadcon_client_class_feature_check(const E_Gadcon_Client_Class *cc, const char *name, void *feature);
static void _e_gadcon_client_cb_menu_post(void *data, E_Menu *m);
static void _e_gadcon_client_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_gadcon_client_cb_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_gadcon_client_cb_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_gadcon_client_cb_menu_style_plain(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_gadcon_client_cb_menu_style_inset(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_gadcon_client_cb_menu_autoscroll(void *data, E_Menu *m, E_Menu_Item *mi);
/*static void _e_gadcon_client_cb_menu_resizable(void *data, E_Menu *m, E_Menu_Item *mi);*/
static void _e_gadcon_client_cb_menu_edit(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_gadcon_client_cb_menu_remove(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_gadcon_client_cb_menu_pre(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_gadcon_client_delfn(void *d, void *o);
static void _e_gadcon_client_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_gadcon_client_event_free(void *d, void *e);
static Evas_Object *e_gadcon_layout_add(Evas *evas);
static void e_gadcon_layout_orientation_set(Evas_Object *obj, int horizontal);
static int e_gadcon_layout_orientation_get(Evas_Object *obj);
static void e_gadcon_layout_freeze(Evas_Object *obj);
static void e_gadcon_layout_thaw(Evas_Object *obj);
static void e_gadcon_layout_min_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h);
static void e_gadcon_layout_asked_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h);
static int e_gadcon_layout_pack(Evas_Object *obj, Evas_Object *child);
static void e_gadcon_layout_pack_size_set(Evas_Object *obj, int size);
static void e_gadcon_layout_pack_request_set(Evas_Object *obj, int pos, int size);
static void e_gadcon_layout_pack_options_set(Evas_Object *obj, E_Gadcon_Client *gcc);
static void e_gadcon_layout_pack_min_size_set(Evas_Object *obj, int w, int h);
static void e_gadcon_layout_pack_aspect_set(Evas_Object *obj, int w, int h);
static void e_gadcon_layout_pack_aspect_pad_set(Evas_Object *obj, int w, int h);
static void e_gadcon_layout_unpack(Evas_Object *obj);
static void _e_gadcon_provider_populate_request(E_Gadcon *gc, const E_Gadcon_Client_Class *cc);
static void _e_gadcon_provider_populate_unrequest(const E_Gadcon_Client_Class *cc);
static void _e_gadcon_provider_populate_job(void *data);
static void _e_gadcon_event_populate_free(void *data EINA_UNUSED, void *event);
static void _e_gadcon_custom_populate_job(void *data);
static int _e_gadcon_location_change(E_Gadcon_Client *gcc, E_Gadcon_Location *src, E_Gadcon_Location *dst);
typedef struct _E_Smart_Data E_Smart_Data;
typedef struct _E_Layout_Item_Container E_Layout_Item_Container;
static void _e_gadcon_client_current_position_sync(E_Gadcon_Client *gcc);
static void _e_gadcon_layout_smart_sync_clients(E_Gadcon *gc);
static void _e_gadcon_layout_smart_gadcon_position_shrinked_mode(E_Smart_Data *sd);
static void _e_gadcon_layout_smart_gadcons_asked_position_set(E_Smart_Data *sd);
static Eina_List *_e_gadcon_layout_smart_gadcons_wrap(E_Smart_Data *sd);
static void _e_gadcon_layout_smart_gadcons_position(E_Smart_Data *sd, Eina_List **list);
static void _e_gadcon_layout_smart_gadcons_position_static(E_Smart_Data *sd, Eina_List **list);
static E_Layout_Item_Container *_e_gadcon_layout_smart_containers_position_adjust(E_Smart_Data *sd, E_Layout_Item_Container *lc, E_Layout_Item_Container *lc2);
static void _e_gadcon_layout_smart_position_items_inside_container(E_Smart_Data *sd, E_Layout_Item_Container *lc);
static void _e_gadcon_layout_smart_containers_merge(E_Smart_Data *sd, E_Layout_Item_Container *lc, E_Layout_Item_Container *lc2);
static void _e_gadcon_layout_smart_restore_gadcons_position_before_move(E_Smart_Data *sd, E_Layout_Item_Container **lc_moving, E_Layout_Item_Container *lc_back, Eina_List **con_list);
typedef enum _E_Gadcon_Layout_Item_State
{
E_LAYOUT_ITEM_STATE_NONE,
E_LAYOUT_ITEM_STATE_POS_INC,
E_LAYOUT_ITEM_STATE_POS_DEC,
E_LAYOUT_ITEM_STATE_SIZE_MIN_END_INC,
E_LAYOUT_ITEM_STATE_SIZE_MIN_END_DEC,
E_LAYOUT_ITEM_STATE_SIZE_MAX_END_INC,
E_LAYOUT_ITEM_STATE_SIZE_MAX_END_DEC,
} E_Gadcon_Layout_Item_State;
typedef enum _E_Gadcon_Layout_Item_Flags
{
E_GADCON_LAYOUT_ITEM_LOCK_NONE = 0x00000000,
E_GADCON_LAYOUT_ITEM_LOCK_POSITION = 0x00000001,
E_GADCON_LAYOUT_ITEM_LOCK_ABSOLUTE = 0x00000002
} E_Gadcon_Layout_Item_Flags;
typedef enum _E_Layout_Item_Container_State
{
E_LAYOUT_ITEM_CONTAINER_STATE_NONE,
E_LAYOUT_ITEM_CONTAINER_STATE_POS_INC,
E_LAYOUT_ITEM_CONTAINER_STATE_POS_DEC,
E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MIN_END_INC,
E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MIN_END_DEC,
E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MAX_END_INC,
E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MAX_END_DEC,
E_LAYOUT_ITEM_CONTAINER_STATE_POS_LOCKED
} E_Layout_Item_Container_State;
struct _E_Layout_Item_Container
{
int pos, size, prev_pos, prev_size;
struct
{
int min_seq, max_seq;
} state_info;
E_Smart_Data *sd;
Eina_List *items;
E_Layout_Item_Container_State state;
};
#define LC_FREE(__lc) \
if (__lc->items) \
eina_list_free(__lc->items); \
E_FREE(__lc)
#define E_LAYOUT_ITEM_CONTAINER_STATE_SET(__con_state, __bi_state) \
if (__bi_state == E_LAYOUT_ITEM_STATE_NONE) \
__con_state = E_LAYOUT_ITEM_CONTAINER_STATE_NONE; \
else if (__bi_state == E_LAYOUT_ITEM_STATE_POS_INC) \
__con_state = E_LAYOUT_ITEM_CONTAINER_STATE_POS_INC; \
else if (__bi_state == E_LAYOUT_ITEM_STATE_POS_DEC) \
__con_state = E_LAYOUT_ITEM_CONTAINER_STATE_POS_DEC; \
else if (__bi_state == E_LAYOUT_ITEM_STATE_SIZE_MIN_END_INC) \
__con_state = E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MIN_END_INC; \
else if (__bi_state == E_LAYOUT_ITEM_STATE_SIZE_MIN_END_DEC) \
__con_state = E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MIN_END_DEC; \
else if (__bi_state == E_LAYOUT_ITEM_STATE_SIZE_MAX_END_INC) \
__con_state = E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MAX_END_INC; \
else if (__bi_state == E_LAYOUT_ITEM_STATE_SIZE_MAX_END_DEC) \
__con_state = E_LAYOUT_ITEM_CONTAINER_STATE_SIZE_MAX_END_DEC
#define LC_OVERLAP(__lc, __lc2) \
((((__lc2)->pos >= (__lc)->pos) && ((__lc2)->pos < ((__lc)->pos + (__lc)->size))) || \
(((__lc)->pos >= (__lc2)->pos) && ((__lc)->pos < ((__lc2)->pos + (__lc2)->size))))
#define E_LAYOUT_ITEM_CONTAINER_SIZE_CHANGE_BY(__lc, __bi, __increase) \
{ \
if (__increase) \
__lc->size += __bi->w; \
else \
__lc->size -= __bi->w; \
}
/********************/
E_API int E_EVENT_GADCON_CLIENT_CLASS_ADD = -1;
E_API int E_EVENT_GADCON_CLIENT_CLASS_DEL = -1;
E_API int E_EVENT_GADCON_CLIENT_ADD = -1;
E_API int E_EVENT_GADCON_CLIENT_DEL = -1;
E_API int E_EVENT_GADCON_POPULATE = -1;
static Eina_Hash *providers = NULL;
static Eina_List *providers_list = NULL;
static Eina_List *gadcons = NULL;
static Eina_List *dummies = NULL;
static Ecore_Job *populate_job = NULL;
static Eina_List *custom_populate_requests = NULL;
static Ecore_Job *custom_populate_job = NULL;
static Eina_List *gadcon_locations = NULL;
static Ecore_Event_Handler *_module_init_end_handler = NULL;
static Eina_Bool _modules_loaded = EINA_FALSE;
static inline void
_eina_list_free(Eina_List *l)
{
eina_list_free(l);
}
static int
_e_gadcon_provider_list_sort_cb(E_Gadcon_Client_Class *a, E_Gadcon_Client_Class *b)
{
return strcasecmp(a->name, b->name);
}
static Eina_Bool
_module_init_end_cb(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
{
_modules_loaded = EINA_TRUE;
return ECORE_CALLBACK_RENEW;
}
/* externally accessible functions */
EINTERN int
e_gadcon_init(void)
{
E_EVENT_GADCON_CLIENT_CLASS_ADD = ecore_event_type_new();
E_EVENT_GADCON_CLIENT_CLASS_DEL = ecore_event_type_new();
E_EVENT_GADCON_CLIENT_ADD = ecore_event_type_new();
E_EVENT_GADCON_CLIENT_DEL = ecore_event_type_new();
E_EVENT_GADCON_POPULATE = ecore_event_type_new();
_module_init_end_handler = ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _module_init_end_cb, NULL);
return 1;
}
EINTERN int
e_gadcon_shutdown(void)
{
if (populate_job)
{
ecore_job_del(populate_job);
populate_job = NULL;
}
custom_populate_requests = eina_list_free(custom_populate_requests);
if (custom_populate_job)
{
ecore_job_del(custom_populate_job);
custom_populate_job = NULL;
}
_modules_loaded = EINA_FALSE;
if (_module_init_end_handler)
ecore_event_handler_del(_module_init_end_handler);
_module_init_end_handler = NULL;
E_LIST_FOREACH(gadcons, e_gadcon_unpopulate);
return 1;
}
/**
* Registers a new gadget class in e
*
* @param cc version of gadcon, name and callbacks to use
* for handling creation and destroying a gadget
*/
E_API void
e_gadcon_provider_register(const E_Gadcon_Client_Class *cc)
{
E_Gadcon *gc;
Eina_List *l, *ll, *lll;
E_Config_Gadcon_Client *cf_gcc;
EINA_SAFETY_ON_NULL_RETURN(cc->name);
if (!providers) providers = eina_hash_string_superfast_new(NULL);
eina_hash_direct_add(providers, cc->name, cc);
EINA_LIST_FOREACH(gadcons, l, gc)
{
e_gadcon_layout_freeze(gc->o_container);
if (gc->awaiting_classes)
{
ll = eina_hash_find(gc->awaiting_classes, cc->name);
EINA_LIST_FOREACH(ll, lll, cf_gcc)
_e_gadcon_client_populate(gc, cc, cf_gcc);
}
e_gadcon_layout_thaw(gc->o_container);
}
providers_list = eina_list_sorted_insert(providers_list, (Eina_Compare_Cb)_e_gadcon_provider_list_sort_cb, cc);
{
E_Event_Gadcon_Client_Class_Add *ev;
ev = E_NEW(E_Event_Gadcon_Client_Class_Add, 1);
ev->cc = cc;
ecore_event_add(E_EVENT_GADCON_CLIENT_CLASS_ADD, ev, NULL, NULL);
}
}
/**
* unregisters a gadget class in e
*
* @param cc the gadget class that was used to register the gadget
*/
E_API void
e_gadcon_provider_unregister(const E_Gadcon_Client_Class *cc)
{
Eina_List *l, *ll, *dlist = NULL;
E_Gadcon *gc;
E_Gadcon_Client *gcc;
_e_gadcon_provider_populate_unrequest(cc);
EINA_LIST_FOREACH(gadcons, l, gc)
{
EINA_LIST_FOREACH(gc->clients, ll, gcc)
{
if (gcc->client_class == cc)
dlist = eina_list_append(dlist, gcc);
}
gc->populated_classes = eina_list_remove(gc->populated_classes, cc);
}
EINA_LIST_FREE(dlist, gcc)
{
e_gadcon_client_queue(gcc->gadcon, gcc->cf);
gcc->hidden = 0;
e_gadcon_client_hide(gcc);
e_object_del(E_OBJECT(gcc));
}
eina_hash_del(providers, cc->name, cc);
providers_list = eina_list_remove(providers_list, cc);
{
E_Event_Gadcon_Client_Class_Add *ev;
ev = E_NEW(E_Event_Gadcon_Client_Class_Add, 1);
ev->cc = cc;
ecore_event_add(E_EVENT_GADCON_CLIENT_CLASS_DEL, ev, NULL, NULL);
}
}
E_API void
e_gadcon_client_queue(E_Gadcon *gc, E_Config_Gadcon_Client *cf_gcc)
{
Eina_List *l;
if (!gc->awaiting_classes)
gc->awaiting_classes = eina_hash_string_superfast_new((Eina_Free_Cb)_eina_list_free);
l = eina_hash_find(gc->awaiting_classes, cf_gcc->name);
if (eina_list_data_find(l, cf_gcc)) return;
l = eina_list_append(l, cf_gcc);
eina_hash_set(gc->awaiting_classes, cf_gcc->name, l);
}
E_API Eina_List *
e_gadcon_provider_list(void)
{
return providers_list;
}
E_API void
e_gadcon_custom_new(E_Gadcon *gc)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gadcons = eina_list_append(gadcons, gc);
if (!custom_populate_job)
{
custom_populate_job =
ecore_job_add(_e_gadcon_custom_populate_job, NULL);
}
if (!eina_list_data_find(custom_populate_requests, gc))
custom_populate_requests = eina_list_append(custom_populate_requests, gc);
gc->custom = EINA_TRUE;
}
E_API void
e_gadcon_custom_del(E_Gadcon *gc)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (eina_list_data_find(custom_populate_requests, gc))
custom_populate_requests = eina_list_remove(custom_populate_requests, gc);
gadcons = eina_list_remove(gadcons, gc);
}
E_API void
e_gadcon_custom_populate_request(E_Gadcon *gc)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (!gc->custom) return;
if (!custom_populate_job)
{
custom_populate_job =
ecore_job_add(_e_gadcon_custom_populate_job, NULL);
}
if (!eina_list_data_find(custom_populate_requests, gc))
custom_populate_requests = eina_list_append(custom_populate_requests, gc);
}
E_API E_Gadcon *
e_gadcon_dummy_new(int id)
{
E_Gadcon *gc;
gc = E_OBJECT_ALLOC(E_Gadcon, E_GADCON_DUMMY_TYPE, _e_gadcon_free);
if (!gc) return NULL;
gc->id = id;
gc->layout_policy = E_GADCON_LAYOUT_POLICY_PANEL;
gc->location = NULL;
gc->dummy = 1;
gc->orient = E_GADCON_ORIENT_HORIZ;
dummies = eina_list_append(dummies, gc);
return gc;
}
E_API void
e_gadcon_config_del(E_Gadcon *gc)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->cfg_delete = 1;
}
E_API void
e_gadcon_drop_handler_add(E_Gadcon *gc, E_Gadcon_DND_Cb enter, E_Gadcon_DND_Cb leave, E_Gadcon_DND_Cb move, E_Gadcon_DND_Cb drop, int x, int y, int w, int h)
{
const char *drop_types[] = { "enlightenment/gadcon_client" };
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (gc->drop_handler) return;
gc->drop_handler =
e_drop_handler_add(E_OBJECT(gc), NULL, gc,
_e_gadcon_cb_dnd_enter, _e_gadcon_cb_dnd_move,
_e_gadcon_cb_dnd_leave, _e_gadcon_cb_dnd_drop,
drop_types, 1, x, y, w, h);
gc->dnd_enter_cb = enter;
gc->dnd_leave_cb = leave;
gc->dnd_move_cb = move;
gc->dnd_drop_cb = drop;
}
E_API E_Gadcon *
e_gadcon_swallowed_new(const char *name, int id, Evas_Object *obj, const char *swallow_name)
{
E_Gadcon *gc;
E_Config_Gadcon *cf_gc;
Eina_List *l;
Evas_Coord x, y, w, h;
gc = E_OBJECT_ALLOC(E_Gadcon, E_GADCON_TYPE, _e_gadcon_free);
if (!gc) return NULL;
gc->name = eina_stringshare_add(name);
gc->id = id;
gc->layout_policy = E_GADCON_LAYOUT_POLICY_PANEL;
gc->location = NULL;
gc->edje.o_parent = obj;
gc->edje.swallow_name = eina_stringshare_add(swallow_name);
gc->orient = E_GADCON_ORIENT_HORIZ;
gc->evas = evas_object_evas_get(obj);
gc->o_container = e_gadcon_layout_add(gc->evas);
evas_object_geometry_get(gc->o_container, &x, &y, &w, &h);
e_gadcon_drop_handler_add(gc, NULL, NULL, NULL, NULL, x, y, w, h);
evas_object_event_callback_add(gc->o_container, EVAS_CALLBACK_MOVE,
_e_gadcon_cb_moveresize, gc);
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
(Evas_Object_Event_Cb)_e_gadcon_parent_resize_cb, gc);
evas_object_event_callback_add(gc->o_container, EVAS_CALLBACK_RESIZE,
_e_gadcon_cb_moveresize, gc);
evas_object_event_callback_add(gc->o_container, EVAS_CALLBACK_SHOW,
_e_gadcon_cb_show, gc);
evas_object_event_callback_add(gc->o_container, EVAS_CALLBACK_HIDE,
_e_gadcon_cb_hide, gc);
evas_object_smart_callback_add(gc->o_container, "size_request",
_e_gadcon_cb_size_request, gc);
evas_object_smart_callback_add(gc->o_container, "min_size_request",
_e_gadcon_cb_min_size_request, gc);
evas_object_show(gc->o_container);
edje_object_part_swallow(gc->edje.o_parent, gc->edje.swallow_name,
gc->o_container);
gadcons = eina_list_append(gadcons, gc);
EINA_LIST_FOREACH(e_config->gadcons, l, cf_gc)
{
if ((!strcmp(cf_gc->name, gc->name)) && (cf_gc->id == gc->id))
{
gc->cf = cf_gc;
break;
}
}
if (!gc->cf)
{
gc->cf = E_NEW(E_Config_Gadcon, 1);
gc->cf->name = eina_stringshare_add(gc->name);
gc->cf->id = gc->id;
e_config->gadcons = eina_list_append(e_config->gadcons, gc->cf);
e_config_save_queue();
}
return gc;
}
E_API void
e_gadcon_swallowed_min_size_set(E_Gadcon *gc, Evas_Coord w, Evas_Coord h)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (gc->edje.o_parent)
{
evas_object_size_hint_min_set(gc->o_container, w, h);
edje_object_part_swallow(gc->edje.o_parent, gc->edje.swallow_name,
gc->o_container);
}
}
E_API void
e_gadcon_min_size_request_callback_set(E_Gadcon *gc, void (*func)(void *data, E_Gadcon *gc, Evas_Coord w, Evas_Coord h), void *data)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->min_size_request.func = func;
gc->min_size_request.data = data;
}
E_API void
e_gadcon_size_request_callback_set(E_Gadcon *gc, void (*func)(void *data, E_Gadcon *gc, Evas_Coord w, Evas_Coord h), void *data)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->resize_request.func = func;
gc->resize_request.data = data;
}
E_API void
e_gadcon_frame_request_callback_set(E_Gadcon *gc, Evas_Object *(*func)(void *data, E_Gadcon_Client * gcc, const char *style), void *data)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->frame_request.func = func;
gc->frame_request.data = data;
}
E_API void
e_gadcon_populate_callback_set(E_Gadcon *gc, void (*func)(void *data, E_Gadcon *gc, const E_Gadcon_Client_Class *cc), void *data)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->populate_class.func = func;
gc->populate_class.data = data;
}
E_API void
e_gadcon_layout_policy_set(E_Gadcon *gc, E_Gadcon_Layout_Policy layout_policy)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (gc->layout_policy == layout_policy) return;
gc->layout_policy = layout_policy;
/* FIXME: delete container obj, re-pack all clients */
}
E_API Eina_Bool
e_gadcon_populate(E_Gadcon *gc)
{
Eina_List *l;
E_Config_Gadcon_Client *cf_gcc;
E_Gadcon_Client_Class *cc;
int x = 0;
E_OBJECT_CHECK_RETURN(gc, EINA_FALSE);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, EINA_FALSE);
e_gadcon_layout_freeze(gc->o_container);
EINA_LIST_FOREACH(gc->cf->clients, l, cf_gcc)
{
if (!cf_gcc->name) continue;
cc = eina_hash_find(providers, cf_gcc->name);
if (cc)
{
if (!eina_list_data_find(gc->populated_classes, cc))
{
_e_gadcon_provider_populate_request(gc, cc);
cc = NULL;
}
}
if (cc)
_e_gadcon_client_populate(gc, cc, cf_gcc);
else
e_gadcon_client_queue(gc, cf_gcc);
}
if (!gc->toolbar)
{
EINA_LIST_FREE(gc->populate_requests, cc)
{
char buf[256];
e_main_ts(cc->name);
if (gc->populate_class.func)
gc->populate_class.func(gc->populate_class.data, gc, cc);
else
e_gadcon_populate_class(gc, cc);
if (!eina_list_data_find(gc->populated_classes, cc))
{
gc->populated_classes = eina_list_append(gc->populated_classes, cc);
if (gc->cf)
{
Eina_List *ll;
if (!gc->awaiting_classes) continue;
ll = eina_hash_set(gc->awaiting_classes, cc->name, NULL);
EINA_LIST_FREE(ll, cf_gcc)
_e_gadcon_client_populate(gc, cc, cf_gcc);
}
}
snprintf(buf, sizeof(buf), "%s Done", cc->name);
e_main_ts(buf);
x++;
}
if (x && _modules_loaded) _e_gadcon_event_populate(gc);
e_gadcon_layout_thaw(gc->o_container);
}
else
{
e_gadcon_layout_thaw(gc->o_container);
if (gc->populated_classes && (!gc->populate_requests))
_e_gadcon_event_populate(gc);
}
return EINA_TRUE;
}
E_API void
e_gadcon_unpopulate(E_Gadcon *gc)
{
E_Gadcon_Client *gcc;
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
/* Be careful, e_object_del does remove gcc from gc->clients */
if (gc->o_container) e_gadcon_layout_freeze(gc->o_container);
while (gc->clients)
{
gcc = eina_list_data_get(gc->clients);
_e_gadcon_client_unpopulate(gcc);
/* FIXME: this seems to happen under some rare and as-yet
* undetermined circumstances in gadman
*/
if (gcc != eina_list_data_get(gc->clients)) continue;
CRI("DANGLING GADCON CLIENT %p! THIS IS A BUG!!!", gcc);
e_object_unref(E_OBJECT(gcc));
}
if (gc->awaiting_classes)
eina_hash_free(gc->awaiting_classes);
gc->awaiting_classes = NULL;
if (gc->o_container && (!stopping) && (!e_object_is_del(E_OBJECT(gc))))
e_gadcon_layout_thaw(gc->o_container);
}
E_API void
e_gadcon_repopulate(E_Gadcon *gc)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (gc->o_container) e_gadcon_layout_freeze(gc->o_container);
e_gadcon_unpopulate(gc);
e_gadcon_populate(gc);
if (gc->o_container) e_gadcon_layout_thaw(gc->o_container);
}
E_API void
e_gadcon_populate_class(E_Gadcon *gc, const E_Gadcon_Client_Class *cc)
{
Eina_List *l;
E_Config_Gadcon_Client *cf_gcc;
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
e_gadcon_layout_freeze(gc->o_container);
EINA_LIST_FOREACH(gc->cf->clients, l, cf_gcc)
{
if (cf_gcc->name && (!strcmp(cf_gcc->name, cc->name)) &&
(cf_gcc->id) && (cf_gcc->style))
_e_gadcon_client_populate(gc, cc, cf_gcc);
}
e_gadcon_layout_thaw(gc->o_container);
}
E_API void
e_gadcon_orient(E_Gadcon *gc, E_Gadcon_Orient orient)
{
Eina_List *l;
E_Gadcon_Client *gcc;
int horiz = 0;
E_OBJECT_CHECK(gc);
E_OBJECT_IF_NOT_TYPE(gc, E_GADCON_DUMMY_TYPE)
{
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
}
if (gc->orient == orient) return;
gc->orient = orient;
if (gc->dummy) return;
e_gadcon_layout_freeze(gc->o_container);
switch (gc->orient)
{
case E_GADCON_ORIENT_FLOAT:
case E_GADCON_ORIENT_HORIZ:
case E_GADCON_ORIENT_TOP:
case E_GADCON_ORIENT_BOTTOM:
case E_GADCON_ORIENT_CORNER_TL:
case E_GADCON_ORIENT_CORNER_TR:
case E_GADCON_ORIENT_CORNER_BL:
case E_GADCON_ORIENT_CORNER_BR:
horiz = 1;
break;
case E_GADCON_ORIENT_VERT:
case E_GADCON_ORIENT_LEFT:
case E_GADCON_ORIENT_RIGHT:
case E_GADCON_ORIENT_CORNER_LT:
case E_GADCON_ORIENT_CORNER_RT:
case E_GADCON_ORIENT_CORNER_LB:
case E_GADCON_ORIENT_CORNER_RB:
horiz = 0;
break;
default:
break;
}
e_gadcon_layout_orientation_set(gc->o_container, horiz);
EINA_LIST_FOREACH(gc->clients, l, gcc)
{
elm_box_horizontal_set(gcc->o_box, horiz);
if (gcc->client_class->func.orient)
gcc->client_class->func.orient(gcc, gc->orient);
}
e_gadcon_layout_thaw(gc->o_container);
}
E_API void
e_gadcon_edit_begin(E_Gadcon *gc)
{
Eina_List *l;
E_Gadcon_Client *gcc;
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
e_gadcon_layout_freeze(gc->o_container);
e_gadcon_locked_set(gc, 1);
gc->editing = 1;
EINA_LIST_FOREACH(gc->clients, l, gcc)
e_gadcon_client_edit_begin(gcc);
e_gadcon_layout_thaw(gc->o_container);
}
E_API void
e_gadcon_edit_end(E_Gadcon *gc)
{
Eina_List *l;
E_Gadcon_Client *gcc;
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
e_gadcon_layout_freeze(gc->o_container);
gc->editing = 0;
EINA_LIST_FOREACH(gc->clients, l, gcc)
e_gadcon_client_edit_end(gcc);
e_gadcon_layout_thaw(gc->o_container);
e_gadcon_locked_set(gc, 0);
}
E_API void
e_gadcon_all_edit_begin(void)
{
Eina_List *l;
E_Gadcon *gc;
EINA_LIST_FOREACH(gadcons, l, gc)
e_gadcon_edit_begin(gc);
}
E_API void
e_gadcon_all_edit_end(void)
{
Eina_List *l;
E_Gadcon *gc;
EINA_LIST_FOREACH(gadcons, l, gc)
e_gadcon_edit_end(gc);
}
E_API void
e_gadcon_zone_set(E_Gadcon *gc, E_Zone *zone)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->zone = zone;
if (gc->cf) gc->cf->zone = zone->num;
}
E_API E_Zone *
e_gadcon_zone_get(E_Gadcon *gc)
{
E_OBJECT_CHECK_RETURN(gc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, NULL);
if (gc->zone) return gc->zone;
if (!gc->toolbar) return NULL;
return e_win_client_get(gc->toolbar->fwin)->zone;
}
E_API void
e_gadcon_ecore_evas_set(E_Gadcon *gc, Ecore_Evas *ee)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->ecore_evas = ee;
}
E_API int
e_gadcon_canvas_zone_geometry_get(E_Gadcon *gc, int *x, int *y, int *w, int *h)
{
E_OBJECT_CHECK_RETURN(gc, 0);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, 0);
if (!gc->ecore_evas) return 0;
ecore_evas_geometry_get(gc->ecore_evas, x, y, w, h);
*x = 0;
*y = 0;
// so much relies on this down here to have been broken... ie return comp-relative coords.
// if (gc->zone)
// {
// if (x) *x = *x - gc->zone->x;
// if (y) *y = *y - gc->zone->y;
// }
return 1;
}
E_API void
e_gadcon_util_menu_attach_func_set(E_Gadcon *gc, void (*func)(void *data, E_Gadcon_Client *gcc, E_Menu *menu), void *data)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->menu_attach.func = func;
gc->menu_attach.data = data;
}
E_API void
e_gadcon_util_lock_func_set(E_Gadcon *gc, void (*func)(void *data, int lock), void *data)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->locked_set.func = func;
gc->locked_set.data = data;
}
E_API void
e_gadcon_util_urgent_show_func_set(E_Gadcon *gc, void (*func)(void *data), void *data)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->urgent_show.func = func;
gc->urgent_show.data = data;
}
E_API void
e_gadcon_dnd_window_set(E_Gadcon *gc, Ecore_X_Window win)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->dnd_win = win;
}
E_API Ecore_X_Window
e_gadcon_dnd_window_get(E_Gadcon *gc)
{
E_OBJECT_CHECK_RETURN(gc, 0);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, 0);
return gc->dnd_win;
}
E_API void
e_gadcon_xdnd_window_set(E_Gadcon *gc, Ecore_X_Window win)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->xdnd_win = win;
}
E_API Ecore_X_Window
e_gadcon_xdnd_window_get(E_Gadcon *gc)
{
E_OBJECT_CHECK_RETURN(gc, 0);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, 0);
return gc->xdnd_win;
}
E_API void
e_gadcon_name_set(E_Gadcon *gc, const char *name)
{
if (!gc) return;
if (!name) return;
if (gc->name == name) return;
eina_stringshare_replace(&gc->name, name);
eina_stringshare_replace(&gc->cf->name, name);
}
E_API void
e_gadcon_shelf_set(E_Gadcon *gc, E_Shelf *shelf)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->shelf = shelf;
}
E_API E_Shelf *
e_gadcon_shelf_get(E_Gadcon *gc)
{
E_OBJECT_CHECK_RETURN(gc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, NULL);
return gc->shelf;
}
E_API void
e_gadcon_toolbar_set(E_Gadcon *gc, E_Toolbar *toolbar)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
gc->toolbar = toolbar;
}
E_API E_Toolbar *
e_gadcon_toolbar_get(E_Gadcon *gc)
{
E_OBJECT_CHECK_RETURN(gc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, NULL);
return gc->toolbar;
}
E_API E_Config_Gadcon_Client *
e_gadcon_client_config_new(E_Gadcon *gc, const char *name)
{
E_Gadcon_Client_Class *cc;
E_Config_Gadcon_Client *cf_gcc;
E_OBJECT_CHECK_RETURN(gc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, NULL);
if (!name) return NULL;
cc = eina_hash_find(providers, name);
if (!cc) return NULL;
if (!_e_gadcon_client_class_feature_check(cc, "id_new", cc->func.id_new))
return NULL;
cf_gcc = E_NEW(E_Config_Gadcon_Client, 1);
if (!cf_gcc) return NULL;
cf_gcc->id = eina_stringshare_add(cc->func.id_new(cc));
if (!cf_gcc->id)
{
free(cf_gcc);
return NULL;
}
cf_gcc->name = eina_stringshare_add(name);
if (gc->zone)
cf_gcc->geom.res = gc->zone->w;
else if (gc->o_container)
{
int w, h;
evas_object_geometry_get(gc->o_container, NULL, NULL, &w, &h);
switch (gc->orient)
{
case E_GADCON_ORIENT_VERT:
case E_GADCON_ORIENT_LEFT:
case E_GADCON_ORIENT_RIGHT:
case E_GADCON_ORIENT_CORNER_LT:
case E_GADCON_ORIENT_CORNER_RT:
case E_GADCON_ORIENT_CORNER_LB:
case E_GADCON_ORIENT_CORNER_RB:
cf_gcc->geom.res = h;
break;
default:
cf_gcc->geom.res = w;
}
}
else
cf_gcc->geom.res = 800;
cf_gcc->geom.size = 80;
cf_gcc->geom.pos = cf_gcc->geom.res - cf_gcc->geom.size;
cf_gcc->style = NULL;
cf_gcc->autoscroll = 0;
cf_gcc->resizable = 0;
gc->cf->clients = eina_list_append(gc->cf->clients, cf_gcc);
e_config_save_queue();
return cf_gcc;
}
E_API void
e_gadcon_client_config_del(E_Config_Gadcon *cf_gc, E_Config_Gadcon_Client *cf_gcc)
{
E_Gadcon *gc;
Eina_List *l, *ll;
if (!cf_gcc) return;
EINA_LIST_FOREACH(gadcons, l, gc)
{
if (!gc->awaiting_classes) continue;
ll = eina_hash_find(gc->awaiting_classes, cf_gcc->name);
eina_hash_set(gc->awaiting_classes, cf_gcc->name, eina_list_remove(ll, cf_gcc));
}
eina_stringshare_del(cf_gcc->name);
eina_stringshare_del(cf_gcc->id);
eina_stringshare_del(cf_gcc->style);
if (cf_gc) cf_gc->clients = eina_list_remove(cf_gc->clients, cf_gcc);
free(cf_gcc);
}
E_API E_Gadcon_Client *
e_gadcon_client_find(E_Gadcon *gc, E_Config_Gadcon_Client *cf_gcc)
{
E_Gadcon_Client *gcc;
Eina_List *l, *ll;
if (!cf_gcc) return NULL;
if (gc)
{
EINA_LIST_FOREACH(gc->clients, ll, gcc)
if (gcc->cf == cf_gcc) return gcc;
return NULL;
}
EINA_LIST_FOREACH(gadcons, l, gc)
EINA_LIST_FOREACH(gc->clients, ll, gcc)
if (gcc->cf == cf_gcc) return gcc;
return NULL;
}
static void
_e_gadcon_client_box_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
E_Gadcon_Client *gcc = data;
gcc->o_box = NULL;
}
static void
_e_gadcon_client_box_hints_changed(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
E_Gadcon_Client *gcc = data;
if (gcc->autoscroll)
_e_gadcon_client_scroll_state_update(gcc);
}
static void
_e_gadcon_client_frame_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
E_Gadcon_Client *gcc = data;
gcc->o_frame = NULL;
}
E_API void
e_gadcon_drag_finished_cb(E_Drag *drag, int dropped)
{
E_Gadcon_Client *gcc;
gcc = drag->data;
gcc->drag.drag = NULL;
if (!dropped)
{
/* free client config */
e_gadcon_client_config_del(NULL, gcc->cf);
gcc->cf = NULL;
/* delete the gadcon client */
/* TODO: Clean up module config too? */
e_object_del(E_OBJECT(gcc));
}
e_gadcon_client_drag_set(NULL);
gcc->gadcon->new_gcc = NULL;
e_object_unref(E_OBJECT(gcc));
}
/**
* Creates a new gadget
*
* @param gc gadcon pointer
* @param name to use for gadget
* @param id assigned to gadget
* @param style to for gadget
* @param base_obj the evas object that will show up in the shelf or gadget module
* @return returns pointer to created gadget, on failure returns null
*/
E_API E_Gadcon_Client *
e_gadcon_client_new(E_Gadcon *gc, const char *name, const char *id EINA_UNUSED, const char *style, Evas_Object *base_obj)
{
E_Gadcon_Client *gcc;
E_OBJECT_CHECK_RETURN(gc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gc, E_GADCON_TYPE, NULL);
gcc = E_OBJECT_ALLOC(E_Gadcon_Client, E_GADCON_CLIENT_TYPE,
_e_gadcon_client_free);
if (!gcc) return NULL;
e_object_delfn_add(E_OBJECT(gcc), _e_gadcon_client_delfn, NULL);
gcc->name = eina_stringshare_add(name);
gcc->gadcon = gc;
gcc->o_base = base_obj;
if (gc->clients)
gcc->id = E_GADCON_CLIENT(eina_list_last_data_get(gc->clients))->id + 1;
gc->clients = eina_list_append(gc->clients, gcc);
/* This must only be unique during runtime */
if (gcc->o_base)
evas_object_event_callback_add(gcc->o_base, EVAS_CALLBACK_DEL,
_e_gadcon_client_del_hook, gcc);
if ((gc->frame_request.func) && (style))
{
gcc->o_frame = gc->frame_request.func(gc->frame_request.data, gcc, style);
gcc->style = eina_stringshare_add(style);
if (gcc->o_frame)
{
edje_object_size_min_calc(gcc->o_frame, &(gcc->pad.w), &(gcc->pad.h));
gcc->o_box = elm_box_add(e_win_evas_object_win_get(gcc->gadcon->o_container));
evas_object_event_callback_add(gcc->o_box, EVAS_CALLBACK_DEL, _e_gadcon_client_box_del, gcc);
evas_object_event_callback_add(gcc->o_box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _e_gadcon_client_box_hints_changed, gcc);
switch (gcc->gadcon->orient)
{
case E_GADCON_ORIENT_FLOAT:
case E_GADCON_ORIENT_HORIZ:
case E_GADCON_ORIENT_TOP:
case E_GADCON_ORIENT_BOTTOM:
case E_GADCON_ORIENT_CORNER_TL:
case E_GADCON_ORIENT_CORNER_TR:
case E_GADCON_ORIENT_CORNER_BL:
case E_GADCON_ORIENT_CORNER_BR:
elm_box_horizontal_set(gcc->o_box, 1);
break;
case E_GADCON_ORIENT_VERT:
case E_GADCON_ORIENT_LEFT:
case E_GADCON_ORIENT_RIGHT:
case E_GADCON_ORIENT_CORNER_LT:
case E_GADCON_ORIENT_CORNER_RT:
case E_GADCON_ORIENT_CORNER_LB:
case E_GADCON_ORIENT_CORNER_RB:
elm_box_horizontal_set(gcc->o_box, 0);
break;
default:
break;
}
evas_object_event_callback_add(gcc->o_box, EVAS_CALLBACK_MOVE,
_e_gadcon_cb_client_frame_moveresize, gcc);
evas_object_event_callback_add(gcc->o_box, EVAS_CALLBACK_RESIZE,
_e_gadcon_cb_client_frame_moveresize, gcc);
evas_object_event_callback_add(gcc->o_frame, EVAS_CALLBACK_MOUSE_MOVE,
_e_gadcon_cb_client_frame_mouse_move, gcc);
if (gcc->o_base)
{
E_EXPAND(gcc->o_base);
elm_box_pack_end(gcc->o_box, gcc->o_base);
}
edje_object_part_swallow(gcc->o_frame, gc->edje.swallow_name, gcc->o_box);
evas_object_show(gcc->o_box);
evas_object_show(gcc->o_frame);
}
}
if (gcc->o_frame)
{
e_gadcon_layout_pack(gc->o_container, gcc->o_frame);
evas_object_event_callback_add(gcc->o_frame, EVAS_CALLBACK_DEL, _e_gadcon_client_frame_del, gcc);
}
else if (gcc->o_base)
e_gadcon_layout_pack(gc->o_container, gcc->o_base);
if (gcc->o_base) evas_object_show(gcc->o_base);
{
E_Event_Gadcon_Client_Add *ev;
ev = E_NEW(E_Event_Gadcon_Client_Add, 1);
ev->gcc = gcc;
e_object_ref(E_OBJECT(gcc));
ecore_event_add(E_EVENT_GADCON_CLIENT_ADD, ev, _e_gadcon_client_event_free, NULL);
}
return gcc;
}
E_API void
e_gadcon_client_edit_begin(E_Gadcon_Client *gcc)
{
Evas_Coord x, y, w, h;
Evas_Object *base;
int layer;
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (gcc->o_control) return;
base = gcc->o_frame ?: gcc->o_base;
if (!base) return;
layer = evas_object_layer_get(base) + 1;
evas_object_geometry_get(base, &x, &y, &w, &h);
gcc->o_control = edje_object_add(gcc->gadcon->evas);
/* FIXME: should probably be in gadget theme or something */
evas_object_layer_set(gcc->o_control, layer);
e_gadcon_locked_set(gcc->gadcon, 1);
gcc->gadcon->editing = 1;
evas_object_move(gcc->o_control, x, y);
evas_object_resize(gcc->o_control, w, h);
e_theme_edje_object_set(gcc->o_control, "base/theme/gadman",
"e/gadman/control");
if ((gcc->autoscroll) /* || (gcc->resizable)*/)
{
if (elm_box_horizontal_get(gcc->o_box))
edje_object_signal_emit(gcc->o_control, "e,state,hsize,on", "e");
else
edje_object_signal_emit(gcc->o_control, "e,state,vsize,on", "e");
}
else
{
edje_object_signal_emit(gcc->o_control, "e,state,hsize,off", "e");
edje_object_signal_emit(gcc->o_control, "e,state,vsize,off", "e");
}
edje_object_signal_emit(gcc->o_control, "e,state,move,on", "e");
gcc->o_event = evas_object_rectangle_add(gcc->gadcon->evas);
evas_object_color_set(gcc->o_event, 0, 0, 0, 0);
evas_object_repeat_events_set(gcc->o_event, 1);
evas_object_layer_set(gcc->o_event, layer);
evas_object_move(gcc->o_event, x, y);
evas_object_resize(gcc->o_event, w, h);
edje_object_signal_callback_add(gcc->o_control, "e,action,move,start", "",
_e_gadcon_cb_signal_move_start, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,move,stop", "",
_e_gadcon_cb_signal_move_stop, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,move,go", "",
_e_gadcon_cb_signal_move_go, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,left,start", "",
_e_gadcon_cb_signal_resize_left_start, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,left,stop", "",
_e_gadcon_cb_signal_resize_left_stop, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,left,go", "",
_e_gadcon_cb_signal_resize_left_go, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,right,start", "",
_e_gadcon_cb_signal_resize_right_start, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,right,stop", "",
_e_gadcon_cb_signal_resize_right_stop, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,right,go", "",
_e_gadcon_cb_signal_resize_right_go, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,up,start", "",
_e_gadcon_cb_signal_resize_left_start, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,up,stop", "",
_e_gadcon_cb_signal_resize_left_stop, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,up,go", "",
_e_gadcon_cb_signal_resize_left_go, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,down,start", "",
_e_gadcon_cb_signal_resize_right_start, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,down,stop", "",
_e_gadcon_cb_signal_resize_right_stop, gcc);
edje_object_signal_callback_add(gcc->o_control, "e,action,resize,down,go", "",
_e_gadcon_cb_signal_resize_right_go, gcc);
evas_object_event_callback_add(gcc->o_event, EVAS_CALLBACK_MOUSE_DOWN,
_e_gadcon_cb_client_mouse_down, gcc);
evas_object_event_callback_add(gcc->o_event, EVAS_CALLBACK_MOUSE_IN,
_e_gadcon_cb_client_mouse_in, gcc);
evas_object_event_callback_add(gcc->o_event, EVAS_CALLBACK_MOUSE_OUT,
_e_gadcon_cb_client_mouse_out, gcc);
evas_object_event_callback_add(base, EVAS_CALLBACK_MOVE,
_e_gadcon_cb_client_move, gcc);
evas_object_event_callback_add(base, EVAS_CALLBACK_RESIZE,
_e_gadcon_cb_client_resize, gcc);
evas_object_show(gcc->o_event);
evas_object_show(gcc->o_control);
}
E_API void
e_gadcon_client_edit_end(E_Gadcon_Client *gcc)
{
Eina_List *l = NULL;
E_Gadcon_Client *client = NULL;
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (gcc->o_frame)
{
evas_object_event_callback_del(gcc->o_frame, EVAS_CALLBACK_MOVE,
_e_gadcon_cb_client_move);
evas_object_event_callback_del(gcc->o_frame, EVAS_CALLBACK_RESIZE,
_e_gadcon_cb_client_resize);
}
else if (gcc->o_base)
{
evas_object_event_callback_del(gcc->o_base, EVAS_CALLBACK_MOVE,
_e_gadcon_cb_client_move);
evas_object_event_callback_del(gcc->o_base, EVAS_CALLBACK_RESIZE,
_e_gadcon_cb_client_resize);
}
if (gcc->moving)
{
gcc->moving = 0;
if (gcc->cf) _e_gadcon_client_save(gcc);
}
if (gcc->o_event) evas_object_del(gcc->o_event);
gcc->o_event = NULL;
if (gcc->o_control) evas_object_del(gcc->o_control);
gcc->o_control = NULL;
e_gadcon_locked_set(gcc->gadcon, 0);
EINA_LIST_FOREACH(gcc->gadcon->clients, l, client)
{
if (!client) continue;
if (client->o_control) return;
}
gcc->gadcon->editing = 0;
}
E_API void
e_gadcon_client_show(E_Gadcon_Client *gcc)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (!gcc->hidden) return;
if (gcc->o_box) evas_object_show(gcc->o_box);
if (gcc->o_frame) evas_object_show(gcc->o_frame);
if (gcc->o_base) evas_object_show(gcc->o_base);
if (gcc->o_control) evas_object_show(gcc->o_control);
if (gcc->o_event) evas_object_show(gcc->o_event);
if (gcc->o_frame)
{
e_gadcon_layout_pack(gcc->gadcon->o_container, gcc->o_frame);
e_gadcon_layout_pack_options_set(gcc->o_frame, gcc);
}
else if (gcc->o_base)
{
e_gadcon_layout_pack(gcc->gadcon->o_container, gcc->o_base);
e_gadcon_layout_pack_options_set(gcc->o_base, gcc);
}
gcc->hidden = 0;
}
E_API void
e_gadcon_client_hide(E_Gadcon_Client *gcc)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (gcc->hidden) return;
if (gcc->o_box) evas_object_hide(gcc->o_box);
if (gcc->o_frame) evas_object_hide(gcc->o_frame);
if (gcc->o_base) evas_object_hide(gcc->o_base);
if (gcc->o_control) evas_object_hide(gcc->o_control);
if (gcc->o_event) evas_object_hide(gcc->o_event);
if (gcc->o_frame)
e_gadcon_layout_unpack(gcc->o_frame);
else if (gcc->o_base)
e_gadcon_layout_unpack(gcc->o_base);
gcc->hidden = 1;
}
E_API void
e_gadcon_client_size_request(E_Gadcon_Client *gcc, Evas_Coord w, Evas_Coord h)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
switch (gcc->gadcon->orient)
{
case E_GADCON_ORIENT_HORIZ:
case E_GADCON_ORIENT_TOP:
case E_GADCON_ORIENT_BOTTOM:
if (gcc->o_frame)
e_gadcon_layout_pack_size_set(gcc->o_frame, w + gcc->pad.w);
else if (gcc->o_base)
e_gadcon_layout_pack_size_set(gcc->o_base, w);
break;
case E_GADCON_ORIENT_VERT:
case E_GADCON_ORIENT_LEFT:
case E_GADCON_ORIENT_RIGHT:
if (gcc->o_frame)
e_gadcon_layout_pack_size_set(gcc->o_frame, h + gcc->pad.h);
else if (gcc->o_base)
e_gadcon_layout_pack_size_set(gcc->o_base, h);
break;
case E_GADCON_ORIENT_FLOAT:
case E_GADCON_ORIENT_CORNER_TL:
case E_GADCON_ORIENT_CORNER_TR:
case E_GADCON_ORIENT_CORNER_BL:
case E_GADCON_ORIENT_CORNER_BR:
case E_GADCON_ORIENT_CORNER_LT:
case E_GADCON_ORIENT_CORNER_RT:
case E_GADCON_ORIENT_CORNER_LB:
case E_GADCON_ORIENT_CORNER_RB:
default:
break;
}
}
E_API void
e_gadcon_client_min_size_set(E_Gadcon_Client *gcc, Evas_Coord w, Evas_Coord h)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
gcc->min.w = w;
gcc->min.h = h;
/* if (!gcc->resizable)*/
{
if (gcc->o_frame)
e_gadcon_layout_pack_min_size_set(gcc->o_frame, w + gcc->pad.w,
h + gcc->pad.h);
else if (gcc->o_base)
e_gadcon_layout_pack_min_size_set(gcc->o_base, w, h);
}
_e_gadcon_moveresize_handle(gcc);
}
E_API void
e_gadcon_client_aspect_set(E_Gadcon_Client *gcc, int w, int h)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
gcc->aspect.w = w;
gcc->aspect.h = h;
// if ((!gcc->autoscroll)/* && (!gcc->resizable)*/)
{
if (gcc->o_frame)
{
e_gadcon_layout_pack_aspect_pad_set(gcc->o_frame, gcc->pad.w,
gcc->pad.h);
e_gadcon_layout_pack_aspect_set(gcc->o_frame, w, h);
}
else if (gcc->o_base)
e_gadcon_layout_pack_aspect_set(gcc->o_base, w, h);
}
_e_gadcon_moveresize_handle(gcc);
}
E_API void
e_gadcon_client_autoscroll_toggle_disabled_set(E_Gadcon_Client *gcc, Eina_Bool disable)
{
disable = !!disable;
if (gcc->autoscroll_disabled == disable) return;
gcc->autoscroll_disabled = disable;
if (disable) e_gadcon_client_autoscroll_set(gcc, 1);
}
E_API void
e_gadcon_client_autoscroll_set(E_Gadcon_Client *gcc, int autoscroll)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (gcc->autoscroll_disabled && (!autoscroll))
{
e_util_dialog_show(_("Gadget error"), _("%s does not support disabling autoscrolling"), gcc->name);
return;
}
gcc->autoscroll = autoscroll;
gcc->autoscroll_set = 1;
/*
if (gcc->autoscroll)
{
if (gcc->o_frame)
{
e_gadcon_layout_pack_aspect_pad_set(gcc->o_frame, gcc->pad.w,
gcc->pad.h);
e_gadcon_layout_pack_aspect_set(gcc->o_frame, 0, 0);
e_gadcon_layout_pack_min_size_set(gcc->o_frame, 0, 0);
}
else if (gcc->o_base)
{
e_gadcon_layout_pack_aspect_set(gcc->o_base, 0, 0);
e_gadcon_layout_pack_min_size_set(gcc->o_base, 0, 0);
}
}
else
*/
{
if (gcc->o_frame)
{
e_gadcon_layout_pack_aspect_pad_set(gcc->o_frame, gcc->pad.w,
gcc->pad.h);
e_gadcon_layout_pack_aspect_set(gcc->o_frame, gcc->aspect.w,
gcc->aspect.h);
e_gadcon_layout_pack_min_size_set(gcc->o_frame, gcc->min.w,
gcc->min.h);
}
else if (gcc->o_base)
{
e_gadcon_layout_pack_min_size_set(gcc->o_base, gcc->min.w,
gcc->min.h);
e_gadcon_layout_pack_aspect_set(gcc->o_base, gcc->aspect.w,
gcc->aspect.h);
}
}
if (gcc->autoscroll)
_e_gadcon_client_scroll_state_update(gcc);
}
E_API void
e_gadcon_client_resizable_set(E_Gadcon_Client *gcc EINA_UNUSED, int resizable EINA_UNUSED)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
/*
gcc->resizable = resizable;
if (gcc->resizable)
{
if (gcc->o_frame)
{
e_gadcon_layout_pack_aspect_pad_set(gcc->o_frame, gcc->pad.w,
gcc->pad.h);
e_gadcon_layout_pack_aspect_set(gcc->o_frame, 0, 0);
e_gadcon_layout_pack_min_size_set(gcc->o_frame, 0, 0);
}
else if (gcc->o_base)
{
e_gadcon_layout_pack_min_size_set(gcc->o_base, 0, 0);
e_gadcon_layout_pack_aspect_set(gcc->o_base, 0, 0);
}
}
else
{
if (gcc->o_frame)
{
e_gadcon_layout_pack_aspect_pad_set(gcc->o_frame, gcc->pad.w,
gcc->pad.h);
e_gadcon_layout_pack_aspect_set(gcc->o_frame, gcc->aspect.w,
gcc->aspect.h);
e_gadcon_layout_pack_min_size_set(gcc->o_frame, gcc->min.w,
gcc->min.h);
}
else if (gcc->o_base)
{
e_gadcon_layout_pack_min_size_set(gcc->o_base, gcc->min.w,
gcc->min.h);
e_gadcon_layout_pack_aspect_set(gcc->o_base, gcc->aspect.w,
gcc->aspect.h);
}
}
*/
}
E_API int
e_gadcon_client_geometry_get(E_Gadcon_Client *gcc, int *x, int *y, int *w, int *h)
{
int gx = 0, gy = 0;
E_OBJECT_CHECK_RETURN(gcc, 0);
E_OBJECT_TYPE_CHECK_RETURN(gcc, E_GADCON_CLIENT_TYPE, 0);
if (!e_gadcon_canvas_zone_geometry_get(gcc->gadcon, &gx, &gy, NULL, NULL))
return 0;
if (gcc->o_base) evas_object_geometry_get(gcc->o_base, x, y, w, h);
if (x) *x += gx;
if (y) *y += gy;
return 1;
}
E_API int
e_gadcon_client_viewport_geometry_get(E_Gadcon_Client *gcc, int *x, int *y, int *w, int *h)
{
E_OBJECT_CHECK_RETURN(gcc, 0);
E_OBJECT_TYPE_CHECK_RETURN(gcc, E_GADCON_CLIENT_TYPE, 0);
if (gcc->o_box) evas_object_geometry_get(gcc->o_base, x, y, w, h);
else if (gcc->o_base)
evas_object_geometry_get(gcc->o_base, x, y, w, h);
else
{
if (x) *x = 0;
if (y) *y = 0;
if (w) *w = 0;
if (h) *h = 0;
}
return 1;
}
E_API E_Zone *
e_gadcon_client_zone_get(E_Gadcon_Client *gcc)
{
E_OBJECT_CHECK_RETURN(gcc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gcc, E_GADCON_CLIENT_TYPE, NULL);
return e_gadcon_zone_get(gcc->gadcon);
}
static Eina_Bool
_e_gadcon_client_populate(E_Gadcon *gc, const E_Gadcon_Client_Class *cc, E_Config_Gadcon_Client *cf_gcc)
{
E_Gadcon_Client *gcc;
if (!eina_list_data_find(gc->populated_classes, cc))
{
_e_gadcon_provider_populate_request(gc, cc);
return EINA_TRUE;
}
if ((!cf_gcc->id) &&
(_e_gadcon_client_class_feature_check(cc, "id_new", cc->func.id_new)))
cf_gcc->id = eina_stringshare_add(cc->func.id_new(cc));
if (!cf_gcc->style)
gcc = cc->func.init(gc, cf_gcc->name, cf_gcc->id,
cc->default_style);
else
gcc = cc->func.init(gc, cf_gcc->name, cf_gcc->id,
cf_gcc->style);
if (!gcc) return EINA_FALSE;
gcc->cf = cf_gcc;
gcc->client_class = cc;
gcc->config.pos = cf_gcc->geom.pos;
gcc->config.size = cf_gcc->geom.size;
gcc->config.res = cf_gcc->geom.res;
gcc->state_info.seq = cf_gcc->state_info.seq;
gcc->state_info.flags = cf_gcc->state_info.flags;
gcc->config.pos_x = gcc->cf->geom.pos_x;
gcc->config.pos_y = gcc->cf->geom.pos_y;
gcc->config.size_w = gcc->cf->geom.size_w;
gcc->config.size_h = gcc->cf->geom.size_h;
gcc->cf->resizable = 0;
eina_stringshare_replace(&gcc->style, cf_gcc->style);
if (gcc->o_frame)
e_gadcon_layout_pack_options_set(gcc->o_frame, gcc);
else if (gcc->o_base)
e_gadcon_layout_pack_options_set(gcc->o_base, gcc);
if (!gcc->autoscroll_set)
e_gadcon_client_autoscroll_set(gcc, cf_gcc->autoscroll);
// e_gadcon_client_resizable_set(gcc, cf_gcc->resizable);
if (gcc->client_class->func.orient)
gcc->client_class->func.orient(gcc, gc->orient);
e_config_save_queue();
if (gc->editing) e_gadcon_client_edit_begin(gcc);
if (gc->instant_edit)
e_gadcon_client_util_menu_attach(gcc);
return EINA_TRUE;
}
static void
_e_gadcon_client_unpopulate(E_Gadcon_Client *gcc)
{
if (gcc->menu)
{
if (gcc->gadcon->shelf && (gcc->menu == gcc->gadcon->shelf->menu)) gcc->gadcon->shelf->menu = NULL;
e_menu_post_deactivate_callback_set(gcc->menu, NULL, NULL);
e_menu_deactivate(gcc->menu);
e_object_del(E_OBJECT(gcc->menu));
gcc->menu = NULL;
}
e_object_del(E_OBJECT(gcc));
}
static void
_e_gadcon_client_change_gadcon(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi)
{
E_Gadcon_Location *src, *dst;
E_Gadcon_Client *gcc;
gcc = data;
src = gcc->gadcon->location;
dst = e_object_data_get(E_OBJECT(mi));
_e_gadcon_location_change(gcc, src, dst);
}
static void
_e_gadcon_add_locations_menu_for_site(E_Menu *m, E_Gadcon_Client *gcc, E_Gadcon_Site site, int *count)
{
E_Menu_Item *mi;
const Eina_List *l;
E_Gadcon_Location *loc;
int k = *count;
EINA_LIST_FOREACH(gadcon_locations, l, loc)
{
if (loc->site == site)
{
if (loc == gcc->gadcon->location) continue;
if (k)
{
k = 0;
mi = e_menu_item_new(m);
e_menu_item_separator_set(mi, 1);
(*count) = 0;
}
mi = e_menu_item_new(m);
e_menu_item_label_set(mi, loc->name);
e_object_data_set(E_OBJECT(mi), loc);
e_menu_item_callback_set(mi, _e_gadcon_client_change_gadcon, gcc);
if (loc->icon_name)
e_util_menu_item_theme_icon_set(mi, loc->icon_name);
(*count)++;
}
}
}
static void
_e_gadcon_gadget_move_to_pre_cb(void *data, E_Menu *m)
{
E_Gadcon_Client *gcc;
int n = 0;
gcc = data;
e_menu_pre_activate_callback_set(m, NULL, NULL);
if (!gcc->client_class->func.is_site || gcc->client_class->func.is_site(E_GADCON_SITE_SHELF))
_e_gadcon_add_locations_menu_for_site(m, gcc, E_GADCON_SITE_SHELF, &n);
if (!gcc->client_class->func.is_site || gcc->client_class->func.is_site(E_GADCON_SITE_DESKTOP))
_e_gadcon_add_locations_menu_for_site(m, gcc, E_GADCON_SITE_DESKTOP, &n);
if (!gcc->client_class->func.is_site || gcc->client_class->func.is_site(E_GADCON_SITE_TOOLBAR))
_e_gadcon_add_locations_menu_for_site(m, gcc, E_GADCON_SITE_TOOLBAR, &n);
//if (!gcc->client_class->func.is_site || gcc->client_class->func.is_site(E_GADCON_SITE_EFM_TOOLBAR))
//_e_gadcon_add_locations_menu_for_site(m, gcc, E_GADCON_SITE_EFM_TOOLBAR, &n);
_e_gadcon_add_locations_menu_for_site(m, gcc, E_GADCON_SITE_UNKNOWN, &n);
}
E_API void
e_gadcon_client_add_location_menu(E_Gadcon_Client *gcc, E_Menu *menu)
{
E_Menu *mn;
E_Menu_Item *mi;
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (gcc->gadcon->location)
{
mn = e_menu_new();
mi = e_menu_item_new(menu);
e_menu_item_label_set(mi, _("Move to"));
e_util_menu_item_theme_icon_set(mi, "transform-move");
e_menu_item_submenu_set(mi, mn);
e_menu_pre_activate_callback_set(mn, _e_gadcon_gadget_move_to_pre_cb, gcc);
e_object_unref(E_OBJECT(mn));
}
}
E_API E_Menu *
e_gadcon_client_menu_set(E_Gadcon_Client *gcc, E_Menu *m)
{
E_Menu *ret;
E_OBJECT_CHECK_RETURN(gcc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gcc, E_GADCON_CLIENT_TYPE, NULL);
ret = gcc->menu;
if (ret)
e_menu_post_deactivate_callback_set(ret, NULL, NULL);
gcc->menu = m;
if (gcc->gadcon->shelf) gcc->gadcon->shelf->menu = m;
if (m)
e_menu_post_deactivate_callback_set(m, _e_gadcon_client_cb_menu_post, gcc);
return ret;
}
E_API E_Menu *
e_gadcon_client_util_menu_items_append(E_Gadcon_Client *gcc, E_Menu *menu_gadget, int flags EINA_UNUSED)
{
E_Menu *mo, *menu_main = NULL;
E_Menu_Item *mi;
char buf[256];
E_OBJECT_CHECK_RETURN(gcc, NULL);
E_OBJECT_TYPE_CHECK_RETURN(gcc, E_GADCON_CLIENT_TYPE, NULL);
if (e_config->menu_gadcon_client_toplevel)
menu_main = menu_gadget;
else
menu_main = e_menu_new();
e_menu_post_deactivate_callback_set(menu_main, _e_gadcon_client_cb_menu_post, gcc);
gcc->menu = menu_main;
if (gcc->gadcon->shelf)
{
if (e_menu_item_nth(menu_gadget, 0))
{
mi = e_menu_item_new(menu_gadget);
e_menu_item_separator_set(mi, 1);
}
/*
if (!gcc->o_control)
{
mi = e_menu_item_new(menu_gadget);
e_menu_item_label_set(mi, _("Move"));
e_util_menu_item_theme_icon_set(mi, "transform-scale");
e_menu_item_callback_set(mi, _e_gadcon_client_cb_menu_edit, gcc);
}
mi = e_menu_item_new(menu_gadget);
e_menu_item_label_set(mi, _("Resizable"));
e_util_menu_item_theme_icon_set(mi, "transform-scale");
e_menu_item_check_set(mi, 1);
if (gcc->resizable) e_menu_item_toggle_set(mi, 1);
e_menu_item_callback_set(mi, _e_gadcon_client_cb_menu_resizable, gcc);
*/
if (!gcc->autoscroll_disabled)
{
mi = e_menu_item_new(menu_gadget);
e_menu_item_label_set(mi, _("Automatically scroll contents"));
e_util_menu_item_theme_icon_set(mi, "transform-move");
e_menu_item_check_set(mi, 1);
if (gcc->autoscroll) e_menu_item_toggle_set(mi, 1);
e_menu_item_callback_set(mi, _e_gadcon_client_cb_menu_autoscroll, gcc);
}
if (gcc->gadcon->shelf)
{
mo = e_menu_new();
gcc->gadcon->shelf->menu = menu_main;
mi = e_menu_item_new(mo);
e_menu_item_label_set(mi, _("Plain"));
e_util_menu_item_theme_icon_set(mi, "enlightenment/plain");
e_menu_item_radio_group_set(mi, 1);
e_menu_item_radio_set(mi, 1);
if (!e_util_strcmp(gcc->style, E_GADCON_CLIENT_STYLE_PLAIN))
e_menu_item_toggle_set(mi, 1);
else if ((!gcc->style) &&
(!e_util_strcmp(gcc->client_class->default_style, E_GADCON_CLIENT_STYLE_PLAIN)))
e_menu_item_toggle_set(mi, 1);
e_menu_item_callback_set(mi, _e_gadcon_client_cb_menu_style_plain, gcc);
mi = e_menu_item_new(mo);
e_menu_item_label_set(mi, _("Inset"));
e_util_menu_item_theme_icon_set(mi, "enlightenment/inset");
e_menu_item_radio_group_set(mi, 1);
e_menu_item_radio_set(mi, 1);
if (!e_util_strcmp(gcc->style, E_GADCON_CLIENT_STYLE_INSET))
e_menu_item_toggle_set(mi, 1);
else if ((!gcc->style) &&
(!e_util_strcmp(gcc->client_class->default_style, E_GADCON_CLIENT_STYLE_INSET)))
e_menu_item_toggle_set(mi, 1);
e_menu_item_callback_set(mi, _e_gadcon_client_cb_menu_style_inset, gcc);
mi = e_menu_item_new(menu_gadget);
e_menu_item_label_set(mi, _("Look"));
e_util_menu_item_theme_icon_set(mi, "preferences-look");
e_menu_item_submenu_set(mi, mo);
e_object_unref(E_OBJECT(mo));
}
mi = e_menu_item_new(menu_gadget);
e_menu_item_separator_set(mi, 1);
e_gadcon_client_add_location_menu(gcc, menu_gadget);
mi = e_menu_item_new(menu_gadget);
e_menu_item_label_set(mi, _("Remove"));
e_util_menu_item_theme_icon_set(mi, "list-remove");
e_menu_item_callback_set(mi, _e_gadcon_client_cb_menu_remove, gcc);
}
if ((!e_config->menu_gadcon_client_toplevel) && (!gcc->gadcon->toolbar))
{
mi = e_menu_item_new(menu_main);
if (gcc->client_class->func.label)
snprintf(buf, sizeof(buf), "%s",
gcc->client_class->func.label((E_Gadcon_Client_Class *)gcc->client_class));
else
snprintf(buf, sizeof(buf), "%s", gcc->name);
e_menu_item_label_set(mi, _(buf));
e_menu_item_realize_callback_set(mi, _e_gadcon_client_cb_menu_pre, gcc);
e_menu_item_submenu_set(mi, menu_gadget);
e_object_unref(E_OBJECT(menu_gadget));
}
if (gcc->gadcon->menu_attach.func)
{
if ((gcc->gadcon->shelf) || (gcc->gadcon->toolbar))
{
if (e_config->menu_gadcon_client_toplevel)
{
mi = e_menu_item_new(menu_main);
e_menu_item_separator_set(mi, 1);
}
gcc->gadcon->menu_attach.func(gcc->gadcon->menu_attach.data, gcc, menu_main);
}
else
gcc->gadcon->menu_attach.func(gcc->gadcon->menu_attach.data, gcc, menu_gadget);
}
return menu_main;
}
E_API void
e_gadcon_client_util_menu_attach(E_Gadcon_Client *gcc)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (gcc->o_frame)
{
evas_object_event_callback_del_full(gcc->o_frame, EVAS_CALLBACK_MOUSE_DOWN,
_e_gadcon_client_cb_mouse_down, gcc);
evas_object_event_callback_del_full(gcc->o_frame, EVAS_CALLBACK_MOUSE_UP,
_e_gadcon_client_cb_mouse_up, gcc);
evas_object_event_callback_del_full(gcc->o_frame, EVAS_CALLBACK_MOUSE_MOVE,
_e_gadcon_client_cb_mouse_move, gcc);
evas_object_event_callback_add(gcc->o_frame, EVAS_CALLBACK_MOUSE_DOWN,
_e_gadcon_client_cb_mouse_down, gcc);
evas_object_event_callback_add(gcc->o_frame, EVAS_CALLBACK_MOUSE_UP,
_e_gadcon_client_cb_mouse_up, gcc);
evas_object_event_callback_add(gcc->o_frame, EVAS_CALLBACK_MOUSE_MOVE,
_e_gadcon_client_cb_mouse_move, gcc);
}
else if (gcc->o_base)
{
evas_object_event_callback_del_full(gcc->o_base, EVAS_CALLBACK_MOUSE_DOWN,
_e_gadcon_client_cb_mouse_down, gcc);
evas_object_event_callback_del_full(gcc->o_base, EVAS_CALLBACK_MOUSE_UP,
_e_gadcon_client_cb_mouse_up, gcc);
evas_object_event_callback_del_full(gcc->o_base, EVAS_CALLBACK_MOUSE_MOVE,
_e_gadcon_client_cb_mouse_move, gcc);
evas_object_event_callback_add(gcc->o_base, EVAS_CALLBACK_MOUSE_DOWN,
_e_gadcon_client_cb_mouse_down, gcc);
evas_object_event_callback_add(gcc->o_base, EVAS_CALLBACK_MOUSE_UP,
_e_gadcon_client_cb_mouse_up, gcc);
evas_object_event_callback_add(gcc->o_base, EVAS_CALLBACK_MOUSE_MOVE,
_e_gadcon_client_cb_mouse_move, gcc);
}
}
E_API void
e_gadcon_locked_set(E_Gadcon *gc, int lock)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (gc->locked_set.func)
gc->locked_set.func(gc->locked_set.data, lock);
}
E_API void
e_gadcon_urgent_show(E_Gadcon *gc)
{
E_OBJECT_CHECK(gc);
E_OBJECT_TYPE_CHECK(gc, E_GADCON_TYPE);
if (gc->urgent_show.func)
gc->urgent_show.func(gc->urgent_show.data);
}
/*
* NOTE: x & y are relative to the o_box of the gadcon.
*/
E_API void
e_gadcon_client_autoscroll_update(E_Gadcon_Client *gcc, Evas_Coord x, Evas_Coord y)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
if (gcc->autoscroll)
{
Evas_Coord w, h;
double d;
/* TODO: When using gadman there is no o_box! */
evas_object_geometry_get(gcc->o_box, NULL, NULL, &w, &h);
if (elm_box_horizontal_get(gcc->o_box))
{
if (w > 1) d = (double)x / (double)(w - 1);
else d = 0;
}
else
{
if (h > 1) d = (double)y / (double)(h - 1);
else d = 0;
}
if (d < 0.0) d = 0.0;
else if (d > 1.0)
d = 1.0;
if (!gcc->scroll_timer)
gcc->scroll_timer =
ecore_timer_loop_add(0.01, _e_gadcon_cb_client_scroll_timer, gcc);
if (!gcc->scroll_animator)
gcc->scroll_animator =
ecore_animator_add(_e_gadcon_cb_client_scroll_animator, gcc);
gcc->scroll_wanted = d;
}
}
E_API void
e_gadcon_client_autoscroll_cb_set(E_Gadcon_Client *gcc, void (*func)(void *data), void *data)
{
E_OBJECT_CHECK(gcc);
E_OBJECT_TYPE_CHECK(gcc, E_GADCON_CLIENT_TYPE);
gcc->scroll_cb.func = func;
gcc->scroll_cb.data = data;
}
E_API Eina_Bool
e_gadcon_site_is_shelf(E_Gadcon_Site site)
{
return site == E_GADCON_SITE_SHELF;
}
E_API Eina_Bool
e_gadcon_site_is_desktop(E_Gadcon_Site site)
{
return site == E_GADCON_SITE_DESKTOP;
}
E_API Eina_Bool
e_gadcon_site_is_efm_toolbar(E_Gadcon_Site site)
{
return site == E_GADCON_SITE_EFM_TOOLBAR;
}
E_API Eina_Bool
e_gadcon_site_is_any_toolbar(E_Gadcon_Site site)
{
switch (site)
{
// there should be all toolbar sities identifiers
case E_GADCON_SITE_TOOLBAR:
case E_GADCON_SITE_EFM_TOOLBAR:
return EINA_TRUE;
default:
return EINA_FALSE;
}
return EINA_FALSE;
}
E_API Eina_Bool
e_gadcon_site_is_not_toolbar(E_Gadcon_Site site)
{
switch (site)
{
// there should be all toolbar sities identifiers
case E_GADCON_SITE_TOOLBAR:
case E_GADCON_SITE_EFM_TOOLBAR:
return EINA_FALSE;
default:
return EINA_TRUE;
}
return EINA_TRUE;
}
E_API void
e_gadcon_client_drag_set(E_Gadcon_Client *gcc)
{
Eina_List *l;
E_Gadcon *gc;
EINA_LIST_FOREACH(gadcons, l, gc)
gc->drag_gcc = gcc;
}
/* local subsystem functions */
static void
_e_gadcon_free(E_Gadcon *gc)
{
if (gc->dummy)
dummies = eina_list_remove(dummies, gc);
else
{
e_gadcon_unpopulate(gc);
gadcons = eina_list_remove(gadcons, gc);
}
eina_list_free(gc->populated_classes);
if (custom_populate_requests)
custom_populate_requests = eina_list_remove(custom_populate_requests, gc);
if (gc->o_container) evas_object_del(gc->o_container);
eina_stringshare_del(gc->name);
eina_stringshare_del(gc->edje.swallow_name);
if (gc->edje.o_parent)
evas_object_event_callback_del_full(gc->edje.o_parent, EVAS_CALLBACK_RESIZE,
(Evas_Object_Event_Cb)_e_gadcon_parent_resize_cb, gc);
if (gc->config_dialog) e_object_del(E_OBJECT(gc->config_dialog));
if (gc->drop_handler) e_drop_handler_del(gc->drop_handler);
if (gc->cfg_delete)
{
eina_stringshare_del(gc->cf->name);
e_config->gadcons = eina_list_remove(e_config->gadcons, gc->cf);
free(gc->cf);
e_config_save_queue();
}
free(gc);
}
static void
_e_gadcon_client_event_free(void *d EINA_UNUSED, void *e)
{
E_Event_Gadcon_Client_Del *ev = e;
e_object_unref(E_OBJECT(ev->gcc));
free(ev);
}
static void
_e_gadcon_event_populate(E_Gadcon *gc)
{
E_Event_Gadcon_Populate *ev;
ev = E_NEW(E_Event_Gadcon_Populate, 1);
e_object_ref(E_OBJECT(gc));
ev->gc = gc;
ecore_event_add(E_EVENT_GADCON_POPULATE, ev, _e_gadcon_event_populate_free, NULL);
}
static void
_e_gadcon_client_delfn(void *d EINA_UNUSED, void *o)
{
E_Gadcon_Client *gcc = o;
E_Event_Gadcon_Client_Add *ev;
if (gcc->instant_edit_timer)
{
ecore_timer_del(gcc->instant_edit_timer);
gcc->instant_edit_timer = NULL;
}
if (gcc->o_base)
evas_object_event_callback_del(gcc->o_base, EVAS_CALLBACK_DEL,
_e_gadcon_client_del_hook);
if (gcc->menu)
{
if (gcc->gadcon->shelf && (gcc->menu == gcc->gadcon->shelf->menu)) gcc->gadcon->shelf->menu = NULL;
e_menu_post_deactivate_callback_set(gcc->menu, NULL, NULL);
e_menu_deactivate(gcc->menu);
e_object_del(E_OBJECT(gcc->menu));
gcc->menu = NULL;
}
e_gadcon_client_edit_end(gcc);
gcc->client_class->func.shutdown(gcc);
if ((gcc->client_class->func.id_del) && (gcc->cf))
gcc->client_class->func.id_del((E_Gadcon_Client_Class *)gcc->client_class,
gcc->cf->id);
if (gcc->drag.drag)
e_object_del(E_OBJECT(gcc->drag.drag));
gcc->gadcon->clients = eina_list_remove(gcc->gadcon->clients, gcc);
E_FREE_FUNC(gcc->scroll_timer, ecore_timer_del);
E_FREE_FUNC(gcc->scroll_animator, ecore_animator_del);
E_FREE_FUNC(gcc->o_box, evas_object_del);
E_FREE_FUNC(gcc->o_frame, evas_object_del);
e_object_ref(E_OBJECT(gcc));
ev = E_NEW(E_Event_Gadcon_Client_Del, 1);
ev->gcc = gcc;
ecore_event_add(E_EVENT_GADCON_CLIENT_DEL, ev, _e_gadcon_client_event_free, NULL);
}
static void
_e_gadcon_client_free(E_Gadcon_Client *gcc)
{
if (gcc->o_box) evas_object_del(gcc->o_box);
if (gcc->o_frame) evas_object_del(gcc->o_frame);
eina_stringshare_del(gcc->name);
eina_stringshare_del(gcc->style);
if (gcc->menu)
{
e_menu_deactivate(gcc->menu);
e_object_del(E_OBJECT(gcc->menu));
}
free(gcc);
}
static void
_e_gadcon_moveresize_handle(E_Gadcon_Client *gcc)
{
int w, h, mw, mh;
if (!gcc->o_base) return;
evas_object_geometry_get(gcc->o_box, NULL, NULL, &w, &h);
if (gcc->gadcon->edje.o_parent)
evas_object_geometry_get(gcc->gadcon->edje.o_parent, NULL, NULL, &mw, &mh);
else
mw = w, mh = h;
w = MIN(w, mw);
h = MIN(h, mh);
/*
if (gcc->resizable)
{
if (elm_box_horizontal_get(gcc->o_box))
{
if ((gcc->aspect.w > 0) && (gcc->aspect.h > 0))
w = (h * gcc->aspect.w) / gcc->aspect.h;
}
else
{
if ((gcc->aspect.w > 0) && (gcc->aspect.h > 0))
h = (w * gcc->aspect.h) / gcc->aspect.w;
}
}
*/
if (gcc->autoscroll)
{
if (elm_box_horizontal_get(gcc->o_box))
{
if ((gcc->aspect.w > 0) && (gcc->aspect.h > 0))
{
w = (h * gcc->aspect.w) / gcc->aspect.h; // ZZZZ
// w = gcc->min.w;
}
else
{
w = gcc->min.w;
}
}
else
{
if ((gcc->aspect.w > 0) && (gcc->aspect.h > 0))
{
h = (w * gcc->aspect.h) / gcc->aspect.w; // ZZZZ
// h = gcc->min.h;
}
else
{
h = gcc->min.h;
}
}
}
evas_object_size_hint_min_set(gcc->o_base, w, h);
evas_object_size_hint_max_set(gcc->o_base, mw, mh);
evas_object_size_hint_min_set(gcc->o_box, 0, 0);
_e_gadcon_client_scroll_state_update(gcc);
}
static void
_e_gadcon_parent_resize_cb(E_Gadcon *gc, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Eina_List *l;
E_Gadcon_Client *gcc;
EINA_LIST_FOREACH(gc->clients, l, gcc)
_e_gadcon_moveresize_handle(gcc);
}
static Eina_Bool
_e_gadcon_cb_client_scroll_timer(void *data)
{
E_Gadcon_Client *gcc;
double d, v;
gcc = data;
d = gcc->scroll_wanted - gcc->scroll_pos;
if (d < 0) d = -d;
if (d < 0.001)
{
gcc->scroll_pos = gcc->scroll_wanted;
gcc->scroll_timer = NULL;
return ECORE_CALLBACK_CANCEL;
}
v = 0.05;
gcc->scroll_pos = (gcc->scroll_pos * (1.0 - v)) + (gcc->scroll_wanted * v);
return ECORE_CALLBACK_RENEW;
}
static void
_e_gadcon_client_scroll_state_update(E_Gadcon_Client *gcc)
{
Evas_Coord box_w, box_h, base_w, base_h;
if (gcc->o_frame)
{
evas_object_geometry_get(gcc->o_box, NULL, NULL, &box_w, &box_h);
evas_object_geometry_get(gcc->o_base, NULL, NULL, &base_w, &base_h);
if (((elm_box_horizontal_get(gcc->o_box)) && (box_w >= base_w)) ||
((!elm_box_horizontal_get(gcc->o_box)) && (box_h >= base_h)))
{
if (gcc->pscrollstate != 0)
{
edje_object_signal_emit(gcc->o_frame, "e,state,scroll,none", "e");
gcc->pscrollstate = 0;
}
}
else if (gcc->scroll_pos <= 0.01)
{
if (gcc->pscrollstate != 1)
{
edje_object_signal_emit(gcc->o_frame, "e,state,scroll,begin", "e");
gcc->pscrollstate = 1;
}
}
else if (gcc->scroll_pos >= 0.99)
{
if (gcc->pscrollstate != 3)
{
edje_object_signal_emit(gcc->o_frame, "e,state,scroll,end", "e");
gcc->pscrollstate = 3;
}
}
else
{
if (gcc->pscrollstate != 2)
{
edje_object_signal_emit(gcc->o_frame, "e,state,scroll,middle", "e");
gcc->pscrollstate = 2;
}
}