the first shelf lives! also view code a bit cleaner as it uses an object to

trap "desktop background" clicks now instead of the raw event handler  so
fixed 2 fixme's whilst there.


SVN revision: 4247
This commit is contained in:
Carsten Haitzler 2001-02-18 02:56:37 +00:00
parent 2378f73f61
commit 20f9b35da8
4 changed files with 436 additions and 88 deletions

Binary file not shown.

12
src/e.h
View File

@ -339,6 +339,8 @@ struct _E_View
int x, y, w, h;
} selection;
Evas_Object obj_bg;
E_Background *bg;
int is_listing;
@ -394,11 +396,21 @@ struct _E_Shelf
OBJ_PROPERTIES;
char *name;
E_View *view;
int x, y, w, h;
struct {
Ebits_Object border;
} bit;
struct {
Evas_Object clipper;
} obj;
int visible;
int icon_count;
struct {
int moving;
int resizing;
} state;
};
struct _E_Background

View File

@ -1,2 +1,278 @@
#include "e.h"
static void e_cb_mouse_in(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh);
static void e_cb_mouse_out(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh);
static void e_cb_mouse_down(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh);
static void e_cb_mouse_up(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh);
static void e_cb_mouse_move(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh);
static int mv_prev_x, mv_prev_y;
static void
e_cb_mouse_in(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh)
{
E_Shelf *sh;
sh = data;
return;
UN(o);
UN(bt);
UN(ox);
UN(oy);
UN(ow);
UN(oh);
}
static void
e_cb_mouse_out(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh)
{
E_Shelf *sh;
sh = data;
return;
UN(o);
UN(bt);
UN(ox);
UN(oy);
UN(ow);
UN(oh);
}
static void
e_cb_mouse_down(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh)
{
E_Shelf *sh;
sh = data;
if (!strcmp(class, "Title_Bar"))
{
mv_prev_x = x;
mv_prev_y = y;
sh->state.moving = 1;
}
return;
UN(o);
UN(bt);
UN(ox);
UN(oy);
UN(ow);
UN(oh);
}
static void
e_cb_mouse_up(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh)
{
E_Shelf *sh;
sh = data;
if (sh->state.moving) sh->state.moving = 0;
return;
UN(o);
UN(bt);
UN(ox);
UN(oy);
UN(ow);
UN(oh);
}
static void
e_cb_mouse_move(void *data, Ebits_Object o, char *class, int bt, int x, int y, int ox, int oy, int ow, int oh)
{
E_Shelf *sh;
sh = data;
if (sh->state.moving)
{
e_shelf_move_by(sh, x - mv_prev_x, y - mv_prev_y);
mv_prev_x = x;
mv_prev_y = y;
}
return;
UN(o);
UN(bt);
UN(ox);
UN(oy);
UN(ow);
UN(oh);
}
void
e_shelf_free(E_Shelf *sh)
{
IF_FREE(sh->name);
FREE(sh);
}
E_Shelf *
e_shelf_new(void)
{
E_Shelf *sh;
sh = NEW(E_Shelf, 1);
ZERO(sh, E_Shelf, 1);
OBJ_INIT(sh, e_shelf_free);
return sh;
}
void
e_shelf_set_name(E_Shelf *sh, char *name)
{
IF_FREE(sh->name);
sh->name = strdup(name);
}
void
e_shelf_set_view(E_Shelf *sh, E_View *v)
{
sh->view = v;
}
void
e_shelf_realize(E_Shelf *sh)
{
int pl, pr, pt, pb;
sh->bit.border = ebits_load(PACKAGE_DATA_DIR"/data/config/appearance/default/shelves/default.bits.db");
if (sh->bit.border)
{
ebits_add_to_evas(sh->bit.border, sh->view->evas);
ebits_move(sh->bit.border, sh->x, sh->y);
ebits_resize(sh->bit.border, sh->w, sh->h);
ebits_set_layer(sh->bit.border, 9);
if (sh->visible)
ebits_show(sh->bit.border);
#define HOOK_CB(_class) \
ebits_set_bit_callback(sh->bit.border, _class, CALLBACK_MOUSE_IN, e_cb_mouse_in, sh); \
ebits_set_bit_callback(sh->bit.border, _class, CALLBACK_MOUSE_OUT, e_cb_mouse_out, sh); \
ebits_set_bit_callback(sh->bit.border, _class, CALLBACK_MOUSE_DOWN, e_cb_mouse_down, sh); \
ebits_set_bit_callback(sh->bit.border, _class, CALLBACK_MOUSE_UP, e_cb_mouse_up, sh); \
ebits_set_bit_callback(sh->bit.border, _class, CALLBACK_MOUSE_MOVE, e_cb_mouse_move, sh);
HOOK_CB("Title_Bar");
HOOK_CB("Resize");
HOOK_CB("Resize_Horizontal");
HOOK_CB("Resize_Vertical");
HOOK_CB("Close");
HOOK_CB("Iconify");
HOOK_CB("Max_Size");
HOOK_CB("Menu");
}
sh->obj.clipper = evas_add_rectangle(sh->view->evas);
evas_set_layer(sh->view->evas, sh->obj.clipper, 9);
evas_set_color(sh->view->evas, sh->obj.clipper, 255, 255, 255, 255);
pl = pr = pt = pb = 0;
if (sh->bit.border) ebits_get_insets(sh->bit.border, &pl, &pr, &pt, &pb);
evas_move(sh->view->evas, sh->obj.clipper, sh->x + pl, sh->y + pt);
evas_resize(sh->view->evas, sh->obj.clipper, sh->w - pl - pr, sh->h - pt - pb);
if ((sh->visible) && (sh->icon_count > 0))
evas_show(sh->view->evas, sh->obj.clipper);
}
void
e_shelf_show(E_Shelf *sh)
{
if (sh->visible) return;
sh->visible = 1;
}
void
e_shelf_hide(E_Shelf *sh)
{
if (!sh->visible) return;
sh->visible = 0;
}
void
e_shelf_move(E_Shelf *sh, int x, int y)
{
int dx, dy;
dx = x - sh->x;
dy = y - sh->y;
e_shelf_move_by(sh, dx, dy);
}
void
e_shelf_move_by(E_Shelf *sh, int dx, int dy)
{
Evas_List l;
sh->x += dx;
sh->y += dy;
if (sh->bit.border) ebits_move(sh->bit.border, sh->x, sh->y);
if (sh->obj.clipper)
{
int pl, pr, pt, pb;
pl = pr = pt = pb = 0;
if (sh->bit.border) ebits_get_insets(sh->bit.border, &pl, &pr, &pt, &pb);
evas_move(sh->view->evas, sh->obj.clipper, sh->x + pl, sh->y + pt);
}
return;
for (l = sh->view->icons; l; l = l->next)
{
E_Icon *icon;
int x, y;
icon = l->data;
if (icon->shelf == sh)
{
e_icon_get_xy(icon, &x, &y);
e_icon_set_xy(icon, x + dx, y + dy);
}
}
}
void
e_shelf_resize(E_Shelf *sh, int w, int h)
{
sh->w = w;
sh->h = h;
if (sh->bit.border) ebits_resize(sh->bit.border, sh->w, sh->h);
if (sh->obj.clipper)
{
int pl, pr, pt, pb;
pl = pr = pt = pb = 0;
if (sh->bit.border) ebits_get_insets(sh->bit.border, &pl, &pr, &pt, &pb);
evas_resize(sh->view->evas, sh->obj.clipper, sh->w - pl - pr, sh->h - pt - pb);
}
}
void
e_shelf_resize_by(E_Shelf *sh, int dw, int dh)
{
e_shelf_resize(sh, sh->w + dw, sh->h + dh);
}
void
e_shelf_add_icon(E_Shelf *sh, E_Icon *icon)
{
if (icon->shelf)
e_shelf_del_icon(icon->shelf, icon);
icon->shelf = sh;
sh->icon_count++;
if (sh->icon_count > 0)
evas_show(sh->view->evas, sh->obj.clipper);
evas_set_clip(sh->view->evas, icon->obj.icon, sh->obj.clipper);
evas_set_clip(sh->view->evas, icon->obj.filename, sh->obj.clipper);
evas_set_clip(sh->view->evas, icon->obj.sel1, sh->obj.clipper);
evas_set_clip(sh->view->evas, icon->obj.sel2, sh->obj.clipper);
}
void
e_shelf_del_icon(E_Shelf *sh, E_Icon *icon)
{
if (icon->shelf != sh) return;
icon->shelf = NULL;
if (sh->icon_count <= 0)
evas_hide(sh->view->evas, sh->obj.clipper);
evas_unset_clip(sh->view->evas, icon->obj.icon);
evas_unset_clip(sh->view->evas, icon->obj.filename);
evas_unset_clip(sh->view->evas, icon->obj.sel1);
evas_unset_clip(sh->view->evas, icon->obj.sel2);
}

View File

@ -1,7 +1,10 @@
#include "e.h"
static Evas_List views = NULL;
static Eevent *current_ev = NULL;
static void e_bg_down_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y);
static void e_bg_up_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y);
static void e_idle(void *data);
static void e_wheel(Eevent * ev);
static void e_key_down(Eevent * ev);
@ -14,6 +17,100 @@ static void e_mouse_out(Eevent * ev);
static void e_window_expose(Eevent * ev);
static void e_view_handle_fs(EfsdEvent *ev);
static void
e_bg_down_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
{
Ev_Mouse_Down *ev;
E_View *v;
ev = current_ev->event;
v = _data;
if (_b == 1)
{
v->selection.on = 1;
v->selection.start_x = _x;
v->selection.start_y = _y;
v->selection.x = _x;
v->selection.y = _y;
v->selection.w = 1;
v->selection.h = 1;
if (!v->selection.obj_rect)
{
v->selection.obj_rect = evas_add_rectangle(v->evas);
v->selection.obj_l1 = evas_add_line(v->evas);
v->selection.obj_l2 = evas_add_line(v->evas);
v->selection.obj_l3 = evas_add_line(v->evas);
v->selection.obj_l4 = evas_add_line(v->evas);
evas_set_color(v->evas, v->selection.obj_rect, 255, 255, 255, 100);
evas_set_color(v->evas, v->selection.obj_l1, 0, 0, 0, 200);
evas_set_color(v->evas, v->selection.obj_l2, 0, 0, 0, 200);
evas_set_color(v->evas, v->selection.obj_l3, 0, 0, 0, 200);
evas_set_color(v->evas, v->selection.obj_l4, 0, 0, 0, 200);
evas_set_layer(v->evas, v->selection.obj_rect, 100);
evas_set_layer(v->evas, v->selection.obj_l1, 100);
evas_set_layer(v->evas, v->selection.obj_l2, 100);
evas_set_layer(v->evas, v->selection.obj_l3, 100);
evas_set_layer(v->evas, v->selection.obj_l4, 100);
}
e_view_update_selection(v, _x, _y);
}
}
static void
e_bg_up_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y)
{
Ev_Mouse_Up *ev;
E_View *v;
ev = current_ev->event;
v = _data;
if ((v->selection.w < 6) && (v->selection.h < 6))
{
if (_b == 1)
{
static E_Build_Menu *buildmenu = NULL;
if (!buildmenu)
{
char *apps_menu_db;
apps_menu_db = e_config_get("apps_menu");
if (apps_menu_db) buildmenu = e_build_menu_new_from_db(apps_menu_db);
}
if (buildmenu)
{
static E_Menu *menu = NULL;
menu = buildmenu->menu;
if (menu)
e_menu_show_at_mouse(menu, ev->rx, ev->ry, ev->time);
}
}
else if (_b == 3)
{
static E_Menu *menu = NULL;
if (!menu)
{
E_Menu_Item *menuitem;
menu = e_menu_new();
e_menu_set_padding_icon(menu, 8);
e_menu_set_padding_state(menu, 8);
menuitem = e_menu_item_new("Enlightenment "VERSION);
e_menu_item_set_icon(menuitem, PACKAGE_DATA_DIR"/data/images/e_logo.png");
e_menu_add_item(menu, menuitem);
}
if (menu)
e_menu_show_at_mouse(menu, ev->rx, ev->ry, ev->time);
}
}
if (ev->button == 1)
{
v->selection.on = 0;
e_view_update_selection(v, _x, _y);
}
}
static void
e_idle(void *data)
{
@ -116,6 +213,7 @@ e_mouse_down(Eevent * ev)
Evas_List l;
e = ev->event;
current_ev = ev;
for (l = views; l; l = l->next)
{
E_View *v;
@ -123,42 +221,12 @@ e_mouse_down(Eevent * ev)
v = l->data;
if (e->win == v->win.main)
{
/* FIXME: */
/* normally would handle selection in evasa object callbacks */
/* but for now it's handled here */
if (e->button == 1)
{
v->selection.on = 1;
v->selection.start_x = e->x;
v->selection.start_y = e->y;
v->selection.x = e->x;
v->selection.y = e->y;
v->selection.w = 1;
v->selection.h = 1;
if (!v->selection.obj_rect)
{
v->selection.obj_rect = evas_add_rectangle(v->evas);
v->selection.obj_l1 = evas_add_line(v->evas);
v->selection.obj_l2 = evas_add_line(v->evas);
v->selection.obj_l3 = evas_add_line(v->evas);
v->selection.obj_l4 = evas_add_line(v->evas);
evas_set_color(v->evas, v->selection.obj_rect, 255, 255, 255, 100);
evas_set_color(v->evas, v->selection.obj_l1, 0, 0, 0, 200);
evas_set_color(v->evas, v->selection.obj_l2, 0, 0, 0, 200);
evas_set_color(v->evas, v->selection.obj_l3, 0, 0, 0, 200);
evas_set_color(v->evas, v->selection.obj_l4, 0, 0, 0, 200);
evas_set_layer(v->evas, v->selection.obj_rect, 100);
evas_set_layer(v->evas, v->selection.obj_l1, 100);
evas_set_layer(v->evas, v->selection.obj_l2, 100);
evas_set_layer(v->evas, v->selection.obj_l3, 100);
evas_set_layer(v->evas, v->selection.obj_l4, 100);
}
e_view_update_selection(v, e->x, e->y);
}
evas_event_button_down(v->evas, e->x, e->y, e->button);
current_ev = NULL;
return;
}
}
current_ev = NULL;
}
static void
@ -168,6 +236,7 @@ e_mouse_up(Eevent * ev)
Evas_List l;
e = ev->event;
current_ev = ev;
for (l = views; l; l = l->next)
{
E_View *v;
@ -175,57 +244,12 @@ e_mouse_up(Eevent * ev)
v = l->data;
if (e->win == v->win.main)
{
/* FIXME: temporary for now- should only do this if its a deskop */
/* view and desktops accept focus on click. */
/* e_focus_to_window(e->win); */
if ((v->selection.w < 6) && (v->selection.h < 6))
{
if (e->button == 1)
{
static E_Build_Menu *buildmenu = NULL;
if (!buildmenu)
{
char *apps_menu_db;
apps_menu_db = e_config_get("apps_menu");
if (apps_menu_db) buildmenu = e_build_menu_new_from_db(apps_menu_db);
}
if (buildmenu)
{
static E_Menu *menu = NULL;
menu = buildmenu->menu;
if (menu)
e_menu_show_at_mouse(menu, e->rx, e->ry, e->time);
}
}
else if (e->button == 3)
{
static E_Menu *menu = NULL;
if (!menu)
{
E_Menu_Item *menuitem;
menu = e_menu_new();
e_menu_set_padding_icon(menu, 8);
e_menu_set_padding_state(menu, 8);
menuitem = e_menu_item_new("Enlightenment "VERSION);
e_menu_item_set_icon(menuitem, PACKAGE_DATA_DIR"/data/images/e_logo.png");
e_menu_add_item(menu, menuitem);
}
if (menu)
e_menu_show_at_mouse(menu, e->rx, e->ry, e->time);
}
}
if (e->button == 1)
{
v->selection.on = 0;
e_view_update_selection(v, e->x, e->y);
}
evas_event_button_up(v->evas, e->x, e->y, e->button);
current_ev = NULL;
return;
}
}
current_ev = NULL;
}
static void
@ -603,6 +627,19 @@ e_view_new(void)
v->options.back_pixmap = 0;
#endif
views = evas_list_append(views, v);
{
E_Shelf *sh;
sh = e_shelf_new();
e_shelf_set_name(sh, "Test Shelf");
e_shelf_set_view(sh, v);
e_shelf_show(sh);
e_shelf_move(sh, 10, 10);
e_shelf_resize(sh, 200, 150);
v->shelves = evas_list_append(v->shelves, sh);
}
return v;
}
@ -700,6 +737,15 @@ e_view_realize(E_View *v)
v->bg->geom.h = v->size.h;
e_background_realize(v->bg, v->evas);
}
v->obj_bg = evas_add_rectangle(v->evas);
evas_callback_add(v->evas, v->obj_bg, CALLBACK_MOUSE_DOWN, e_bg_down_cb, v);
evas_callback_add(v->evas, v->obj_bg, CALLBACK_MOUSE_UP, e_bg_up_cb, v);
evas_set_layer(v->evas, v->obj_bg, 1);
evas_move(v->evas, v->obj_bg, 0, 0);
evas_resize(v->evas, v->obj_bg, 999999, 999999);
evas_set_color(v->evas, v->obj_bg, 0, 0, 0, 0);
evas_show(v->evas, v->obj_bg);
e_window_set_events(v->win.main,
XEV_EXPOSE | XEV_MOUSE_MOVE |
XEV_BUTTON | XEV_IN_OUT | XEV_KEY);
@ -712,6 +758,19 @@ e_view_realize(E_View *v)
e_view_set_dir(v, dir);
IF_FREE(dir);
}
if (v->shelves)
{
Evas_List l;
for (l = v->shelves; l; l = l->next)
{
E_Shelf *sh;
sh = l->data;
e_shelf_realize(sh);
}
}
v->changed = 1;
}
@ -726,14 +785,15 @@ e_view_update(E_View *v)
{
Evas_List l;
if (!v->changed) return;
for (l = v->icons; l; l = l->next)
if (v->changed)
{
E_Icon *icon;
icon = l->data;
e_icon_update(icon);
for (l = v->icons; l; l = l->next)
{
E_Icon *icon;
icon = l->data;
e_icon_update(icon);
}
}
if (v->options.back_pixmap)
{
@ -756,7 +816,7 @@ e_view_update(E_View *v)
}
else
evas_render(v->evas);
/* v->changed = 0;*/
v->changed = 0;
}
void