clean up gadcon dnd code to not use static variables

SVN revision: 76757
This commit is contained in:
Mike Blumenkrantz 2012-09-17 12:23:55 +00:00
parent 7a59e58273
commit 040b87a604
2 changed files with 103 additions and 100 deletions

View File

@ -196,11 +196,6 @@ static Eina_List *gadcon_locations = NULL;
static Ecore_Event_Handler *_module_init_end_handler = NULL; static Ecore_Event_Handler *_module_init_end_handler = NULL;
static Eina_Bool _modules_loaded = EINA_FALSE; static Eina_Bool _modules_loaded = EINA_FALSE;
/* This is the gadcon client which is currently dragged */
static E_Gadcon_Client *drag_gcc = NULL;
/* This is the gadcon client created on entering a new shelf */
static E_Gadcon_Client *new_gcc = NULL;
static inline void static inline void
_eina_list_free(Eina_List *l) _eina_list_free(Eina_List *l)
{ {
@ -2191,12 +2186,15 @@ _e_gadcon_client_drag_begin(E_Gadcon_Client *gcc, int x, int y)
E_Drag *drag; E_Drag *drag;
Evas_Object *o = NULL; Evas_Object *o = NULL;
Evas_Coord w = 0, h = 0; Evas_Coord w = 0, h = 0;
Eina_List *l;
E_Gadcon *gc;
const char *drag_types[] = { "enlightenment/gadcon_client" }; const char *drag_types[] = { "enlightenment/gadcon_client" };
if ((drag_gcc) || (!gcc->gadcon->zone) || (!gcc->gadcon->zone->container)) if ((gcc->gadcon->drag_gcc) || (!gcc->gadcon->zone) || (!gcc->gadcon->zone->container))
return; return;
drag_gcc = gcc; EINA_LIST_FOREACH(gadcons, l, gc)
gc->drag_gcc = gcc;
e_object_ref(E_OBJECT(gcc)); e_object_ref(E_OBJECT(gcc));
/* Remove this config from the current gadcon */ /* Remove this config from the current gadcon */
@ -2213,24 +2211,23 @@ _e_gadcon_client_drag_begin(E_Gadcon_Client *gcc, int x, int y)
gcc->drag.drag = drag = e_drag_new(gcc->gadcon->zone->container, x, y, gcc->drag.drag = drag = e_drag_new(gcc->gadcon->zone->container, x, y,
drag_types, 1, gcc, -1, NULL, drag_types, 1, gcc, -1, NULL,
_e_gadcon_cb_drag_finished); _e_gadcon_cb_drag_finished);
if (drag) if (!drag) return;
o = gcc->client_class->func.icon((E_Gadcon_Client_Class *)gcc->client_class,
e_drag_evas_get(drag));
if (o)
evas_object_geometry_get(o, NULL, NULL, &w, &h);
else
{ {
o = gcc->client_class->func.icon((E_Gadcon_Client_Class *)gcc->client_class, /* FIXME: fallback icon for drag */
e_drag_evas_get(drag)); o = evas_object_rectangle_add(e_drag_evas_get(drag));
if (o) evas_object_color_set(o, 255, 255, 255, 100);
evas_object_geometry_get(o, NULL, NULL, &w, &h);
else
{
/* FIXME: fallback icon for drag */
o = evas_object_rectangle_add(e_drag_evas_get(drag));
evas_object_color_set(o, 255, 255, 255, 100);
}
if (w < 10)
w = h = 50;
e_drag_object_set(drag, o);
e_drag_resize(drag, w, h);
e_drag_start(drag, x + w / 2, y + h / 2);
} }
if (w < 10)
w = h = 50;
e_drag_object_set(drag, o);
e_drag_resize(drag, w, h);
e_drag_start(drag, x + w / 2, y + h / 2);
} }
static void static void
@ -2777,9 +2774,11 @@ static void
_e_gadcon_cb_drag_finished(E_Drag *drag, int dropped) _e_gadcon_cb_drag_finished(E_Drag *drag, int dropped)
{ {
E_Gadcon_Client *gcc; E_Gadcon_Client *gcc;
Eina_List *l;
E_Gadcon *gc;
gcc = drag->data; gcc = drag->data;
drag_gcc->drag.drag = NULL; gcc->drag.drag = NULL;
if (!dropped) if (!dropped)
{ {
/* free client config */ /* free client config */
@ -2789,14 +2788,10 @@ _e_gadcon_cb_drag_finished(E_Drag *drag, int dropped)
/* TODO: Clean up module config too? */ /* TODO: Clean up module config too? */
e_object_del(E_OBJECT(gcc)); e_object_del(E_OBJECT(gcc));
} }
else if (new_gcc) EINA_LIST_FOREACH(gadcons, l, gc)
{ gc->drag_gcc = NULL;
/* dropped on new gadcon, delete this one as it is no longer in use */ gcc->gadcon->new_gcc = NULL;
e_object_del(E_OBJECT(gcc));
}
e_object_unref(E_OBJECT(gcc)); e_object_unref(E_OBJECT(gcc));
new_gcc = NULL;
drag_gcc = NULL;
} }
static void static void
@ -2808,16 +2803,14 @@ _e_gadcon_cb_dnd_enter(void *data, const char *type __UNUSED__, void *event)
ev = event; ev = event;
gc = data; gc = data;
if (gc->drag) return; INF("DND ENTER");
//INF("DND ENTER");
e_gadcon_layout_freeze(gc->o_container); e_gadcon_layout_freeze(gc->o_container);
gcc = drag_gcc; gcc = gc->drag_gcc;
if (new_gcc) if (gc->new_gcc)
{ {
new_gcc->gadcon->drag = NULL; e_object_del(E_OBJECT(gc->new_gcc));
e_object_del(E_OBJECT(new_gcc)); gc->new_gcc = NULL;
new_gcc = NULL;
} }
if (ev->data) if (ev->data)
@ -2830,50 +2823,60 @@ _e_gadcon_cb_dnd_enter(void *data, const char *type __UNUSED__, void *event)
if (cc) if (cc)
{ {
if (!gcc->style) if (!gcc->style)
new_gcc = cc->func.init(gc, gcc->name, gcc->cf->id, gc->new_gcc = cc->func.init(gc, gcc->name, gcc->cf->id,
cc->default_style); cc->default_style);
else else
new_gcc = cc->func.init(gc, gcc->name, gcc->cf->id, gc->new_gcc = cc->func.init(gc, gcc->name, gcc->cf->id,
gcc->style); gcc->style);
if (new_gcc) if (gc->new_gcc)
{ {
gc->drag = new_gcc; gc->new_gcc->cf = gcc->cf;
new_gcc->cf = gcc->cf; gc->new_gcc->client_class = cc;
new_gcc->client_class = cc; gc->new_gcc->config.pos = gcc->config.pos;
new_gcc->config.pos = gcc->config.pos; gc->new_gcc->config.size = gcc->config.size;
new_gcc->config.size = gcc->config.size; gc->new_gcc->config.res = gcc->config.res;
new_gcc->config.res = gcc->config.res; gc->new_gcc->state_info.seq = gcc->state_info.seq;
new_gcc->state_info.seq = gcc->state_info.seq; gc->new_gcc->state_info.flags = gcc->state_info.flags;
new_gcc->state_info.flags = gcc->state_info.flags; if (gc->new_gcc->client_class->func.orient)
if (new_gcc->o_frame)
e_gadcon_layout_pack_options_set(new_gcc->o_frame, new_gcc);
else if (new_gcc->o_base)
{ {
e_gadcon_layout_pack_options_set(new_gcc->o_base, new_gcc); if (gc->orient == E_GADCON_ORIENT_FLOAT)
if (!gc->o_container)
{ {
int w, h; gc->new_gcc->client_class->func.orient(gc->new_gcc, gcc->gadcon->orient);
evas_object_hide(drag_gcc->drag.drag->object); gc->new_gcc->cf->orient = gcc->gadcon->orient;
evas_output_size_get(gc->evas, &w, &h); }
new_gcc->config.pos_x = (double)ev->x / (double)w; else
new_gcc->config.pos_y = (double)ev->y / (double)h; {
new_gcc->config.size_w = (double)new_gcc->config.size / (double)w; gc->new_gcc->client_class->func.orient(gc->new_gcc, gc->orient);
new_gcc->config.size_h = (double)new_gcc->config.size / (double)h; gc->new_gcc->cf->orient = gc->orient;
evas_object_resize(new_gcc->o_base, new_gcc->config.size, new_gcc->config.size); }
evas_object_move(new_gcc->o_base, ev->x, ev->y); }
if (gc->new_gcc->o_frame)
e_gadcon_layout_pack_options_set(gc->new_gcc->o_frame, gc->new_gcc);
else if (gc->new_gcc->o_base)
{
e_gadcon_layout_pack_options_set(gc->new_gcc->o_base, gc->new_gcc);
if (!gc->o_container)
{
int w, h, gw, gh;
evas_object_hide(gc->drag_gcc->drag.drag->object);
w = gc->zone->w;
h = gc->zone->h;
gc->new_gcc->config.pos_x = (double)ev->x / (double)w;
gc->new_gcc->config.pos_y = (double)ev->y / (double)h;
evas_object_geometry_get(gcc->o_frame ?: gcc->o_base, NULL, NULL, &gw, &gh);
gc->new_gcc->config.size_w = (double)gw / (double)w;
gc->new_gcc->config.size_h = (double)gh / (double)h;
evas_object_resize(gc->new_gcc->o_base, gw, gh);
evas_object_move(gc->new_gcc->o_base, ev->x, ev->y);
} }
} }
if (gc->o_container)
evas_object_show(drag_gcc->drag.drag->object);
e_gadcon_client_autoscroll_set(new_gcc, gcc->autoscroll); e_gadcon_client_autoscroll_set(gc->new_gcc, gcc->autoscroll);
/* e_gadcon_client_resizable_set(new_gcc, gcc->resizable);*/ /* e_gadcon_client_resizable_set(gc->new_gcc, gcc->resizable);*/
if (new_gcc->client_class->func.orient) gc->new_gcc->state_info.resist = 1;
new_gcc->client_class->func.orient(new_gcc, gc->orient);
new_gcc->state_info.resist = 1;
if (gc->instant_edit) if (gc->instant_edit)
e_gadcon_client_util_menu_attach(new_gcc); e_gadcon_client_util_menu_attach(gc->new_gcc);
} }
} }
} }
@ -2896,11 +2899,7 @@ _e_gadcon_cb_dnd_move(void *data, const char *type __UNUSED__, void *event)
ev = event; ev = event;
gc = data; gc = data;
/* If we move in the same gadcon as the client originates */ gcc = gc->new_gcc;
if (drag_gcc->gadcon == gc) gcc = drag_gcc;
/* If we move in the newly entered gadcon */
else if (new_gcc && (new_gcc->gadcon == gc))
gcc = new_gcc;
if (!gcc) return; if (!gcc) return;
if (gcc->state_info.resist > 0) if (gcc->state_info.resist > 0)
@ -2917,12 +2916,14 @@ _e_gadcon_cb_dnd_move(void *data, const char *type __UNUSED__, void *event)
if (!gcc->gadcon->o_container) if (!gcc->gadcon->o_container)
{ {
int w, h; int w, h;
evas_output_size_get(gc->evas, &w, &h); w = gc->zone->w;
new_gcc->config.pos_x = (double)ev->x / (double)w; h = gc->zone->h;
new_gcc->config.pos_y = (double)ev->y / (double)h; gc->new_gcc->config.pos_x = (double)ev->x / (double)w;
gc->new_gcc->config.pos_y = (double)ev->y / (double)h;
if (gcc->o_base) evas_object_move(gcc->o_base, ev->x, ev->y); if (gcc->o_base) evas_object_move(gcc->o_base, ev->x, ev->y);
} }
evas_object_geometry_get(gc->o_container, &dx, &dy, NULL, NULL); else
evas_object_geometry_get(gc->o_container, &dx, &dy, NULL, NULL);
_e_gadcon_client_inject(gc, gcc, ev->x + dx, ev->y + dy); _e_gadcon_client_inject(gc, gcc, ev->x + dx, ev->y + dy);
o = gcc->o_frame ? gcc->o_frame : gcc->o_base; o = gcc->o_frame ? gcc->o_frame : gcc->o_base;
@ -2944,19 +2945,16 @@ _e_gadcon_cb_dnd_leave(void *data, const char *type __UNUSED__, void *event __UN
E_Gadcon *gc; E_Gadcon *gc;
gc = data; gc = data;
//INF("DND LEAVE"); INF("DND LEAVE");
gc->drag = NULL;
/* If we exit the starting container hide the gadcon visual */ /* If we exit the starting container hide the gadcon visual */
if (drag_gcc->gadcon == gc) e_gadcon_client_hide(drag_gcc); if (gc->drag_gcc->gadcon == gc) e_gadcon_client_hide(gc->drag_gcc);
/* Delete temporary object */ /* Delete temporary object */
if (new_gcc) if (!gc->new_gcc) return;
{
//INF("DELETING new_gcc"); INF("DELETING new_gcc");
new_gcc->gadcon->drag = NULL; e_object_del(E_OBJECT(gc->new_gcc));
e_object_del(E_OBJECT(new_gcc)); gc->new_gcc = NULL;
new_gcc = NULL;
}
} }
static void static void
@ -2966,25 +2964,30 @@ _e_gadcon_cb_drop(void *data, const char *type __UNUSED__, void *event __UNUSED_
E_Gadcon_Client *gcc = NULL; E_Gadcon_Client *gcc = NULL;
gc = data; gc = data;
//INF("DND DROP"); INF("DND DROP");
new_gcc->gadcon->drag = NULL; /* still has refcount from drag */
gcc = new_gcc; e_object_del(E_OBJECT(gc->drag_gcc));
gcc = gc->new_gcc;
gc->cf->clients = eina_list_append(gc->cf->clients, gcc->cf); gc->cf->clients = eina_list_append(gc->cf->clients, gcc->cf);
if (!new_gcc->gadcon->o_container) if (!gc->o_container)
{ {
/* FIXME: gadman sucks and should probably use a regular gadcon layout, but it doesn't /* FIXME: gadman sucks and should probably use a regular gadcon layout, but it doesn't
* so we need to repop here * so we need to repop here
*/ */
new_gcc->cf = gcc->cf; gcc->cf = gc->drag_gcc->cf;
_e_gadcon_client_save(new_gcc); INF("CF=%p", gcc->cf);
new_gcc->cf = NULL; _e_gadcon_client_save(gc->new_gcc);
e_object_del(E_OBJECT(new_gcc)); // we don't null new_gcc here since it gets checked in _drag_finished e_object_del(E_OBJECT(gc->new_gcc));
gc->new_gcc = NULL;
/* this little hack prevents the dead gcc from overwriting our config */
gc->drag_gcc->moving = 0;
e_gadcon_custom_populate_request(gc); e_gadcon_custom_populate_request(gc);
e_config_save_queue(); e_config_save_queue();
return; return;
} }
if (gc->editing) e_gadcon_client_edit_begin(gcc); if (gc->editing) e_gadcon_client_edit_begin(gc->new_gcc);
gc->new_gcc = NULL;
e_config_save_queue(); e_config_save_queue();
} }

View File

@ -129,7 +129,7 @@ struct _E_Gadcon
E_Gadcon_Location *location; E_Gadcon_Location *location;
E_Drop_Handler *drop_handler; E_Drop_Handler *drop_handler;
E_Gadcon_Client *drag; E_Gadcon_Client *drag_gcc, *new_gcc;
E_Config_Gadcon *cf; E_Config_Gadcon *cf;