It's possible to add several types for one drop handler.

SVN revision: 17204
This commit is contained in:
sebastid 2005-10-05 17:56:35 +00:00 committed by sebastid
parent b94b928490
commit 93a3c07ea8
6 changed files with 139 additions and 194 deletions

View File

@ -38,7 +38,7 @@ static Evas_List *_drop_handlers = NULL;
static Ecore_X_Window _drag_win = 0;
static Evas_List *_drag_list = NULL;
static E_Drag *_drag_current = NULL;
static E_Drag *_drag_current = NULL;
static XDnd *_xdnd;
@ -253,6 +253,7 @@ void
e_drag_start(E_Drag *drag, int x, int y)
{
Evas_List *l;
int i;
_drag_win = ecore_x_window_input_new(drag->container->win,
drag->container->x, drag->container->y,
@ -270,7 +271,12 @@ e_drag_start(E_Drag *drag, int x, int y)
h = l->data;
h->active = !strcmp(h->type, drag->type);
h->active = 0;
for (i = 0; i < h->num_types; i++)
{
if (!strcmp(h->types[i], drag->type))
h->active = 1;
}
h->entered = 0;
}
@ -317,18 +323,18 @@ e_drag_update(int x, int y)
if (!h->entered)
{
if (h->cb.enter)
h->cb.enter(h->data, h->type, enter_ev);
h->cb.enter(h->cb.data, _drag_current->type, enter_ev);
h->entered = 1;
}
if (h->cb.move)
h->cb.move(h->data, h->type, move_ev);
h->cb.move(h->cb.data, _drag_current->type, move_ev);
}
else
{
if (h->entered)
{
if (h->cb.leave)
h->cb.leave(h->data, h->type, leave_ev);
h->cb.leave(h->cb.data, _drag_current->type, leave_ev);
h->entered = 0;
}
}
@ -344,6 +350,7 @@ e_drag_end(int x, int y)
{
Evas_List *l;
E_Event_Dnd_Drop *ev;
const char *type;
if (_drag_current)
{
@ -357,9 +364,15 @@ e_drag_end(int x, int y)
ev = E_NEW(E_Event_Dnd_Drop, 1);
if (_drag_current)
ev->data = _drag_current->data;
{
ev->data = _drag_current->data;
type = _drag_current->type;
}
else if (_xdnd)
ev->data = _xdnd->data;
{
ev->data = _xdnd->data;
type = _xdnd->type;
}
ev->x = x;
ev->y = y;
@ -380,7 +393,7 @@ e_drag_end(int x, int y)
if ((h->cb.drop)
&& E_INSIDE(x, y, h->x, h->y, h->w, h->h))
{
h->cb.drop(h->data, h->type, ev);
h->cb.drop(h->cb.data, type, ev);
dropped = 1;
}
}
@ -414,7 +427,7 @@ e_drag_end(int x, int y)
if (h->entered)
{
if (h->cb.leave)
h->cb.leave(h->data, h->type, leave_ev);
h->cb.leave(h->cb.data, type, leave_ev);
h->entered = 0;
}
}
@ -429,19 +442,26 @@ e_drop_handler_add(void *data,
void (*move_cb)(void *data, const char *type, void *event),
void (*leave_cb)(void *data, const char *type, void *event),
void (*drop_cb)(void *data, const char *type, void *event),
const char *type, int x, int y, int w, int h)
const char **types, unsigned int num_types, int x, int y, int w, int h)
{
E_Drop_Handler *handler;
int i;
handler = E_NEW(E_Drop_Handler, 1);
if (!handler) return NULL;
handler->data = data;
handler->cb.data = data;
handler->cb.enter = enter_cb;
handler->cb.move = move_cb;
handler->cb.leave = leave_cb;
handler->cb.drop = drop_cb;
handler->type = strdup(type);
handler->num_types = num_types;
if (num_types)
{
handler->types = malloc(num_types * sizeof(char *));
for (i = 0; i < num_types; i++)
handler->types[i] = strdup(types[i]);
}
handler->x = x;
handler->y = y;
handler->w = w;
@ -464,8 +484,15 @@ e_drop_handler_geometry_set(E_Drop_Handler *handler, int x, int y, int w, int h)
void
e_drop_handler_del(E_Drop_Handler *handler)
{
int i;
_drop_handlers = evas_list_remove(_drop_handlers, handler);
free(handler->type);
if (handler->types)
{
for (i = 0; i < handler->num_types; i++)
free(handler->types[i]);
free(handler->types);
}
free(handler);
}
@ -602,7 +629,7 @@ _e_dnd_cb_event_dnd_enter(void *data, int type, void *event)
Ecore_X_Event_Xdnd_Enter *ev;
E_Container *con;
Evas_List *l;
int i;
int i, j;
ev = event;
con = data;
@ -630,7 +657,13 @@ _e_dnd_cb_event_dnd_enter(void *data, int type, void *event)
h = l->data;
h->active = !strcmp(h->type, "enlightenment/x-file");
h->active = 0;
for (j = 0; j < h->num_types; j++)
{
if (!strcmp(h->types[j], _xdnd->type))
h->active = 1;
}
h->entered = 0;
}
break;
@ -674,25 +707,25 @@ _e_dnd_cb_event_dnd_leave(void *data, int type, void *event)
leave_ev->x = 0;
leave_ev->y = 0;
for (l = _drop_handlers; l; l = l->next)
{
E_Drop_Handler *h;
h = l->data;
if (!h->active)
continue;
if (h->entered)
{
if (h->cb.leave)
h->cb.leave(h->data, h->type, leave_ev);
h->entered = 0;
}
}
if (_xdnd)
{
for (l = _drop_handlers; l; l = l->next)
{
E_Drop_Handler *h;
h = l->data;
if (!h->active)
continue;
if (h->entered)
{
if (h->cb.leave)
h->cb.leave(h->cb.data, _xdnd->type, leave_ev);
h->entered = 0;
}
}
free(_xdnd->type);
free(_xdnd);
_xdnd = NULL;
@ -780,7 +813,7 @@ _e_dnd_cb_event_dnd_selection(void *data, int type, void *event)
files = ev->data;
for (i = 0; i < files->num_files; i++)
l = evas_list_append(l, files->files[i]);
l = evas_list_append(l, files->files[i]), printf("file: %s\n", files->files[i]);
_xdnd->data = l;
e_drag_end(_xdnd->x, _xdnd->y);
evas_list_free(l);

View File

@ -46,14 +46,17 @@ struct _E_Drag
struct _E_Drop_Handler
{
void *data;
struct {
void (*enter)(void *data, const char *type, void *event);
void (*move)(void *data, const char *type, void *event);
void (*leave)(void *data, const char *type, void *event);
void (*drop)(void *data, const char *type, void *event);
void *data;
} cb;
char *type;
char **types;
unsigned int num_types;
int x, y, w, h;
unsigned char active : 1;
unsigned char entered : 1;
@ -106,7 +109,8 @@ EAPI E_Drop_Handler *e_drop_handler_add(void *data,
void (*move_cb)(void *data, const char *type, void *event),
void (*leave_cb)(void *data, const char *type, void *event),
void (*drop_cb)(void *data, const char *type, void *event),
const char *type, int x, int y, int w, int h);
const char **types, unsigned int num_types,
int x, int y, int w, int h);
EAPI void e_drop_handler_geometry_set(E_Drop_Handler *handler, int x, int y, int w, int h);
EAPI void e_drop_handler_del(E_Drop_Handler *handler);

View File

@ -72,9 +72,7 @@ static void _ibar_bar_cb_enter(void *data, const char *type, void *event);
static void _ibar_bar_cb_move(void *data, const char *type, void *event);
static void _ibar_bar_cb_leave(void *data, const char *type, void *event);
static void _ibar_bar_cb_drop_eapp(void *data, const char *type, void *event);
static void _ibar_bar_cb_drop_border(void *data, const char *type, void *event);
static void _ibar_bar_cb_drop_file(void *data, const char *type, void *event);
static void _ibar_bar_cb_drop(void *data, const char *type, void *event);
static void _ibar_bar_cb_finished(E_Drag *drag, int dropped);
static void _ibar_icon_cb_intercept_move(void *data, Evas_Object *o, Evas_Coord x, Evas_Coord y);
@ -463,6 +461,7 @@ _ibar_bar_new(IBar *ib, E_Container *con)
Evas_Object *o;
E_Gadman_Policy policy;
Evas_Coord x, y, w, h;
const char *drop[] = { "enlightenment/eapp", "enlightenment/border", "text/uri-list" };
ibb = E_NEW(IBar_Bar, 1);
if (!ibb) return NULL;
@ -552,27 +551,13 @@ _ibar_bar_new(IBar *ib, E_Container *con)
ibb->icon_inset.b = 100 - (y + h);
evas_object_del(o);
ibb->drop_eapp = e_drop_handler_add(ibb,
_ibar_bar_cb_enter, _ibar_bar_cb_move,
_ibar_bar_cb_leave, _ibar_bar_cb_drop_eapp,
"enlightenment/eapp",
ibb->x + ibb->bar_inset.l, ibb->y + ibb->bar_inset.t,
ibb->w - (ibb->bar_inset.l + ibb->bar_inset.r),
ibb->h - (ibb->bar_inset.t + ibb->bar_inset.b));
ibb->drop_border = e_drop_handler_add(ibb,
_ibar_bar_cb_enter, _ibar_bar_cb_move,
_ibar_bar_cb_leave, _ibar_bar_cb_drop_border,
"enlightenment/border",
ibb->x + ibb->bar_inset.l, ibb->y + ibb->bar_inset.t,
ibb->w - (ibb->bar_inset.l + ibb->bar_inset.r),
ibb->h - (ibb->bar_inset.t + ibb->bar_inset.b));
ibb->drop_file = e_drop_handler_add(ibb,
_ibar_bar_cb_enter, _ibar_bar_cb_move,
_ibar_bar_cb_leave, _ibar_bar_cb_drop_file,
"enlightenment/x-file",
ibb->x + ibb->bar_inset.l, ibb->y + ibb->bar_inset.t,
ibb->w - (ibb->bar_inset.l + ibb->bar_inset.r),
ibb->h - (ibb->bar_inset.t + ibb->bar_inset.b));
ibb->drop_handler = e_drop_handler_add(ibb,
_ibar_bar_cb_enter, _ibar_bar_cb_move,
_ibar_bar_cb_leave, _ibar_bar_cb_drop,
drop, 3,
ibb->x + ibb->bar_inset.l, ibb->y + ibb->bar_inset.t,
ibb->w - (ibb->bar_inset.l + ibb->bar_inset.r),
ibb->h - (ibb->bar_inset.t + ibb->bar_inset.b));
ibb->gmc = e_gadman_client_new(ibb->con->gadman);
e_gadman_client_domain_set(ibb->gmc, "module.ibar", bar_count++);
@ -613,9 +598,7 @@ _ibar_bar_free(IBar_Bar *ibb)
while (ibb->icons)
_ibar_icon_free(ibb->icons->data);
e_drop_handler_del(ibb->drop_eapp);
e_drop_handler_del(ibb->drop_border);
e_drop_handler_del(ibb->drop_file);
e_drop_handler_del(ibb->drop_handler);
if (ibb->timer) ecore_timer_del(ibb->timer);
if (ibb->animator) ecore_animator_del(ibb->animator);
@ -1634,122 +1617,62 @@ _ibar_bar_cb_leave(void *data, const char *type, void *event)
}
static void
_ibar_bar_cb_drop_eapp(void *data, const char *type, void *event)
_ibar_bar_cb_drop(void *data, const char *type, void *event)
{
E_Event_Dnd_Drop *ev;
E_App *app;
E_App *app = NULL;
Evas_List *l = NULL;
IBar_Bar *ibb;
IBar_Icon *ic;
ev = event;
ibb = data;
app = ev->data;
/* add dropped element */
ic = _ibar_icon_pos_find(ibb, ev->x, ev->y);
/* remove drag marker */
e_box_freeze(ibb->box_object);
e_box_unpack(ibb->drag_object);
evas_object_del(ibb->drag_object);
ibb->drag_object = NULL;
evas_object_del(ibb->drag_object_overlay);
ibb->drag_object_overlay = NULL;
e_box_thaw(ibb->box_object);
_ibar_bar_frame_resize(ibb);
if (ic)
if (!strcmp(type, "enlightenment/eapp"))
{
/* Add new eapp before this icon */
e_app_prepend_relative(app, ic->app);
app = ev->data;
}
else
else if (!strcmp(type, "enlightenment/border"))
{
/* Add at the end */
e_app_append(app, ibb->ibar->apps);
E_Border *bd;
bd = ev->data;
app = bd->app;
if (!app)
{
app = e_app_window_name_class_title_role_find(bd->client.icccm.name,
bd->client.icccm.class,
e_border_name_get(bd),
bd->client.icccm.window_role);
}
if (!app)
{
app = e_app_launch_id_pid_find(bd->client.netwm.startup_id,
bd->client.netwm.pid);
}
if (!app)
{
E_Dialog *dia;
dia = e_dialog_new(e_container_current_get(e_manager_current_get()));
e_dialog_title_set(dia, _("Cannot add icon"));
e_dialog_text_set(dia,
_("You tried to drop an icon of an application that<br>"
"does not have a matching application file.<br>"
"<br>"
"The icon cannot be added to IBar."
));
e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
e_dialog_button_focus_num(dia, 1);
e_win_centered_set(dia->win, 1);
e_dialog_show(dia);
return;
}
}
}
static void
_ibar_bar_cb_drop_border(void *data, const char *type, void *event)
{
E_Event_Dnd_Drop *ev;
E_App *app;
IBar_Bar *ibb;
IBar_Icon *ic;
E_Border *bd;
const char *title;
ev = event;
ibb = data;
bd = ev->data;
title = e_border_name_get(bd);
app = e_app_window_name_class_title_role_find(bd->client.icccm.name,
bd->client.icccm.class,
title, bd->client.icccm.window_role);
if (!app)
else if (!strcmp(type, "text/uri-list"))
{
app = e_app_launch_id_pid_find(bd->client.netwm.startup_id,
bd->client.netwm.pid);
l = ev->data;
}
if (!app)
{
E_Dialog *dia;
dia = e_dialog_new(e_container_current_get(e_manager_current_get()));
e_dialog_title_set(dia, _("Cannot add icon"));
e_dialog_text_set(dia,
_("You tried to drop an icon of an application that<br>"
"does not have a matching application file.<br>"
"<br>"
"The icon cannot be added to IBar."
));
e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
e_dialog_button_focus_num(dia, 1);
e_win_centered_set(dia->win, 1);
e_dialog_show(dia);
return;
}
/* add dropped element */
ic = _ibar_icon_pos_find(ibb, ev->x, ev->y);
if (!ic) return;
/* remove drag marker */
e_box_freeze(ibb->box_object);
e_box_unpack(ibb->drag_object);
evas_object_del(ibb->drag_object);
ibb->drag_object = NULL;
evas_object_del(ibb->drag_object_overlay);
ibb->drag_object_overlay = NULL;
e_box_thaw(ibb->box_object);
_ibar_bar_frame_resize(ibb);
if (ic)
{
/* Add new eapp before this icon */
e_app_prepend_relative(app, ic->app);
}
else
{
/* Add at the end */
e_app_append(app, ibb->ibar->apps);
}
}
static void
_ibar_bar_cb_drop_file(void *data, const char *type, void *event)
{
E_Event_Dnd_Drop *ev;
IBar_Bar *ibb;
IBar_Icon *ic;
Evas_List *l;
ev = event;
ibb = data;
l = ev->data;
/* add dropped element */
ic = _ibar_icon_pos_find(ibb, ev->x, ev->y);
@ -1768,12 +1691,18 @@ _ibar_bar_cb_drop_file(void *data, const char *type, void *event)
if (ic)
{
/* Add new eapp before this icon */
e_app_files_prepend_relative(l, ic->app);
if (app)
e_app_prepend_relative(app, ic->app);
else if (l)
e_app_files_prepend_relative(l, ic->app);
}
else
{
/* Add at the end */
e_app_files_append(l, ibb->ibar->apps);
if (app)
e_app_append(app, ibb->ibar->apps);
else if (l)
e_app_files_append(l, ibb->ibar->apps);
}
}
@ -1809,15 +1738,7 @@ _ibar_bar_cb_gmc_change(void *data, E_Gadman_Client *gmc, E_Gadman_Change change
_ibar_bar_follower_reset(ibb);
_ibar_bar_timer_handle(ibb);
e_drop_handler_geometry_set(ibb->drop_eapp,
ibb->x + ibb->bar_inset.l, ibb->y + ibb->bar_inset.t,
ibb->w - (ibb->bar_inset.l + ibb->bar_inset.r),
ibb->h - (ibb->bar_inset.t + ibb->bar_inset.b));
e_drop_handler_geometry_set(ibb->drop_border,
ibb->x + ibb->bar_inset.l, ibb->y + ibb->bar_inset.t,
ibb->w - (ibb->bar_inset.l + ibb->bar_inset.r),
ibb->h - (ibb->bar_inset.t + ibb->bar_inset.b));
e_drop_handler_geometry_set(ibb->drop_file,
e_drop_handler_geometry_set(ibb->drop_handler,
ibb->x + ibb->bar_inset.l, ibb->y + ibb->bar_inset.t,
ibb->w - (ibb->bar_inset.l + ibb->bar_inset.r),
ibb->h - (ibb->bar_inset.t + ibb->bar_inset.b));

View File

@ -73,9 +73,7 @@ struct _IBar_Bar
Config_Bar *conf;
E_Drop_Handler *drop_eapp;
E_Drop_Handler *drop_border;
E_Drop_Handler *drop_file;
E_Drop_Handler *drop_handler;
};
struct _IBar_Icon

View File

@ -506,6 +506,7 @@ _pager_face_new(Pager *pager, E_Zone *zone, Evas *evas)
Evas_Object *o;
Evas_Coord x, y, w, h;
double aspect;
const char *drop[] = { "enlightenment/border", "enlightenment/pager_win" };
face = E_NEW(Pager_Face, 1);
if (!face) return NULL;
@ -539,15 +540,9 @@ _pager_face_new(Pager *pager, E_Zone *zone, Evas *evas)
face->drop_handler = e_drop_handler_add(face,
_pager_face_cb_enter, _pager_face_cb_move,
_pager_face_cb_leave, _pager_face_cb_drop,
"enlightenment/border",
drop, 2,
face->fx, face->fy, face->fw, face->fh);
face->drop_handler_win = e_drop_handler_add(face,
_pager_face_cb_enter, _pager_face_cb_move,
_pager_face_cb_leave, _pager_face_cb_drop,
"enlightenment/pager_win",
face->fx, face->fy, face->fw, face->fh);
face->gmc = e_gadman_client_new(zone->container->gadman);
_pager_face_zone_set(face, zone);
@ -591,7 +586,6 @@ _pager_face_free(Pager_Face *face)
e_object_del(E_OBJECT(face->gmc));
e_drop_handler_del(face->drop_handler);
e_drop_handler_del(face->drop_handler_win);
_pager_face_zone_unset(face);
@ -994,10 +988,6 @@ _pager_face_cb_gmc_change(void *data, E_Gadman_Client *gmc, E_Gadman_Change chan
face->fx + face->inset.l, face->fy + face->inset.t,
face->fw - (face->inset.l + face->inset.r),
face->fh - (face->inset.t + face->inset.b));
e_drop_handler_geometry_set(face->drop_handler_win,
face->fx + face->inset.l, face->fy + face->inset.t,
face->fw - (face->inset.l + face->inset.r),
face->fh - (face->inset.t + face->inset.b));
switch (change)
{
case E_GADMAN_CHANGE_MOVE_RESIZE:
@ -2204,7 +2194,7 @@ _pager_face_cb_drop(void *data, const char *type, void *event_info)
desk = e_desk_at_xy_get(face->zone, x, y);
//printf("drop %s\n", type);
printf("drop %s\n", type);
if (!strcmp(type, "enlightenment/pager_win"))
{

View File

@ -95,7 +95,6 @@ struct _Pager_Face
Config_Face *conf;
E_Drop_Handler *drop_handler;
E_Drop_Handler *drop_handler_win;
Pager_Popup *current_popup;