Combo work... selecting doesn't seem to work at the moment, and there are valgrind errors. Getting there though.

This commit is contained in:
Jaime Thomas 2008-12-20 06:06:31 +00:00
parent 43dcb1820f
commit 0ac3dc2f40
4 changed files with 291 additions and 50 deletions

View File

@ -1,6 +1,7 @@
/* vim: set sw=3 ts=3 sts=3 expandtab: */
group {
name: "ecdb/button";
min: 50 30;
parts {
part {

View File

@ -26,7 +26,7 @@ group {
description {
state: "active" 0.0;
inherit: "default" 0.0;
color: 0 0 0 128;
color: 0 0 0 90;
}
}
}
@ -204,6 +204,37 @@ group {
}
}
}
part {
name: "ecdb.header";
type: TEXT;
description {
state: "default" 0.0;
color: 60 60 60 255;
align: 0.0 0.5;
rel1 {
to: "combo_button";
relative: 0.0 0.0;
offset: 9 0;
}
rel2 {
to: "combo_button";
relative: 1.0 1.0;
offset: -1 -1;
}
text {
text: "";
font: "ecdb/default";
min: 1 1;
size: 11;
align: 0.0 0.5;
}
}
}
}
programs {
@ -242,7 +273,7 @@ group {
program {
name: "collapse";
signal: "ecdb,combo,collapse";
signal: "ecdb,combo,default";
source: "ecdb";
action: STATE_SET "default" 0.0;
target: "combo_button";
@ -250,7 +281,7 @@ group {
program {
name: "expand";
signal: "ecdb,combo,expand";
signal: "ecdb,combo,active";
source: "ecdb";
action: STATE_SET "clicked" 0.0;
target: "combo_button";
@ -289,4 +320,97 @@ group {
target: "combo_button";
}
}
}
group {
name: "ecdb/combo/popup";
parts {
part {
name: "base";
type: IMAGE;
description {
state: "default" 0.0;
min: 1 1;
max: 1 1;
color: 255 255 255 0;
visible: 1;
rel1 {
relative: 0.0 0.0;
offset: 0 0;
}
rel2 {
relative: 1.0 1.0;
offset: -1 -1;
}
image {
normal: "background.png";
}
}
description {
state: "active" 0.0;
inherit: "default" 0.0;
color: 255 255 255 200;
max: 9999 9999;
}
}
part {
name: "ecdb.box";
type: BOX;
description {
state: "default" 0.0;
color: 255 255 255 0;
rel1 {
to: "base";
}
rel2 {
to: "base";
}
box {
layout: "min_size";
padding: 1 1;
align: 0.0 0.5;
}
}
description {
state: "active" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
}
}
programs {
program {
name: "expand";
signal: "ecdb,combo,popup,show,*";
source: "ecdb";
action: STATE_SET "active" 0.0;
target: "base";
target: "ecdb.box";
transition: DECELERATE 0.2;
}
program {
name: "collapse";
signal: "ecdb,combo,popup,hide,*";
source: "ecdb";
action: STATE_SET "default" 0.0;
target: "base";
target: "ecdb.box";
transition: DECELERATE 0.2;
}
}
}

View File

@ -775,8 +775,8 @@ ecdb_erase_page_show(void)
EINA_LIST_FOREACH(em->drives, l, drive)
{
d = ecdb_button_add(swallow, NULL);
ecdb_button_label_set(d, drive->location);
d = ecdb_button_add(b, NULL);
ecdb_button_label_set(d, drive->product);
ecdb_combo_append(b, d);
evas_object_show(d);
}

View File

@ -282,6 +282,45 @@ ecdb_entry_text_get(Evas_Object *e)
/****************************** COMBO ****************************************/
typedef struct _Combo_Data Combo_Data;
struct _Combo_Data
{
Evas_Object *parent;
Evas_Object *back;
Evas_Object *popup;
unsigned int expanded;
unsigned int count;
const char *name;
};
static void
_combo_min_size(Evas_Object *o, Evas_Object_Box_Data *p, void *data)
{
Eina_List *l;
Evas_Object_Box_Option *opt;
int offset_x, offset_y;
int w, h, y;
int wt, ht, xt, yt;
if (eina_list_count(p->children) <= 0)
return;
evas_object_geometry_get(o, &offset_x, &offset_y, &w, &h);
y = offset_y + (h / 2);
EINA_LIST_FOREACH(p->children, l, opt)
{
edje_object_size_min_get(eina_list_nth(p->children, 0), NULL, &h);
evas_object_geometry_get(opt->obj, &xt, &yt, &wt, &ht);
if ((wt != w) || (ht != h))
evas_object_resize(opt->obj, w, h);
if ((xt != 0) || (yt != y))
evas_object_move(opt->obj, offset_x, y);
y += h;
}
}
// Axis preferential -- for now vertical
const char *
_combo_best_location(Evas_Object *c)
@ -292,7 +331,7 @@ _combo_best_location(Evas_Object *c)
ecore_evas_geometry_get(em->main_win_ee, NULL, NULL, &ww, &wh);
evas_object_geometry_get(c, &x, &y, &w, &h);
if ((w) > (ww - x - w))
if ((h) > (wh - y - h))
{
return "top";
}
@ -302,67 +341,107 @@ _combo_best_location(Evas_Object *c)
}
}
static void
_combo_del(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Combo_Data *cd;
cd = evas_object_data_get(data, "cd");
eina_stringshare_del(cd->name);
FREE(cd);
}
static void
_combo_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Object *c, *back;
int w, h;
Combo_Data *cd;
// Deal with popup?
c = data;
back = evas_object_data_get(c, "back");
evas_object_move(back, 0, 0);
ecore_evas_geometry_get(em->main_win_ee, NULL, NULL, &w, &h);
evas_object_resize(back, w, h);
cd = evas_object_data_get(data, "cd");
if (cd->expanded)
ecdb_combo_collapse(data);
}
static void
_combo_hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Combo_Data *cd;
cd = evas_object_data_get(data, "cd");
if (cd->expanded)
ecdb_combo_collapse(data);
}
static void
_combo_clicked(void *data, Evas_Object *obj, void *event_info)
{
printf("object clicked...");
}
static void
_combo_moveable_click_cb(void *data, Evas_Object *obj, const char *emission,
const char *source)
{
Combo_Data *cd;
cd = evas_object_data_get(data, "cd");
if (cd->expanded)
ecdb_combo_collapse(data);
}
void
static void
_combo_click_cb(void *data, Evas_Object *obj, const char *emission,
const char *source)
{
evas_object_smart_callback_call(obj, "clicked", NULL);
ecdb_combo_expand(obj);
}
Evas_Object *c;
Combo_Data *cd;
void
_combo_back_clicked_cb(void *data, Evas_Object *obj, const char *emission,
const char *source)
{
ecdb_combo_collapse(data);
c = data;
cd = evas_object_data_get(c, "cd");
if ((cd) && (!cd->expanded))
ecdb_combo_expand(c);
else
ecdb_combo_collapse(c);
evas_object_smart_callback_call(c, "clicked", NULL);
}
Evas_Object *
ecdb_combo_add(Evas_Object *parent, const char *name)
{
Evas_Object *c, *back;
Evas_Object *c;
Combo_Data *cd;
c = ecdb_widget_add(parent, name);
edje_object_file_set(c, em->theme_path, "ecdb/combo");
evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _combo_resize,
c);
evas_object_event_callback_add(parent, EVAS_CALLBACK_HIDE, _combo_hide, c);
evas_object_event_callback_add(c, EVAS_CALLBACK_DEL, _combo_del, c);
edje_object_signal_callback_add(c, "ecdb,combo,clicked", "ecdb",
_combo_click_cb, c);
back = edje_object_add(evas_object_evas_get(parent));
edje_object_file_set(back, em->theme_path, "ecdb/combo/background");
edje_object_signal_callback_add(back, "ecdb,combo,back,dismiss", "ecdb",
_combo_back_clicked_cb, c);
evas_object_data_set(c, "back", back);
evas_object_pass_events_set(back, 1);
evas_object_show(back);
cd = calloc(1, sizeof(Combo_Data));
cd->back = edje_object_add(evas_object_evas_get(parent));
edje_object_file_set(cd->back, em->theme_path, "ecdb/combo/background");
edje_object_signal_callback_add(cd->back, "ecdb,combo,back,dismiss", "ecdb",
_combo_moveable_click_cb, c);
evas_object_pass_events_set(cd->back, 1);
evas_object_show(cd->back);
cd->popup = edje_object_add(evas_object_evas_get(parent));
edje_object_file_set(cd->popup, em->theme_path, "ecdb/combo/popup");
edje_object_signal_callback_add(cd->back, "ecdb,combo,back,dismiss", "ecdb",
_combo_moveable_click_cb, c);
edje_box_layout_register("min_size", _combo_min_size, NULL, NULL, NULL,
NULL);
evas_object_pass_events_set(cd->popup, 1);
evas_object_show(cd->popup);
cd->parent = parent;
cd->name = eina_stringshare_add(name);
evas_object_data_set(c, "cd", cd);
return c;
}
@ -376,38 +455,75 @@ ecdb_combo_header_set(Evas_Object *c, const char *text)
void
ecdb_combo_append(Evas_Object *c, Evas_Object *o)
{
edje_object_part_box_append(c, "ecdb.box", o);
Combo_Data *cd;
cd = evas_object_data_get(c, "cd");
cd->count++;
edje_object_part_box_append(cd->popup, "ecdb.box", o);
evas_object_smart_callback_add(o, "clicked", _combo_clicked, c);
}
void
ecdb_combo_expand(Evas_Object *c)
{
Evas_Object *back;
Combo_Data *cd;
const char *location;
//char buf[1024];
int w, h;
char buf[1024];
int x, y, w, h, h2;
int box_height = 30;
cd = evas_object_data_get(c, "cd");
edje_object_signal_emit(c, "ecdb,combo,active", "ecdb");
evas_object_move(cd->back, 0, 0);
ecore_evas_geometry_get(em->main_win_ee, NULL, NULL, &w, &h);
evas_object_resize(cd->back, w, h);
evas_object_pass_events_set(cd->back, 0);
evas_object_layer_set(cd->back, evas_object_layer_get(c) + 1);
edje_object_signal_emit(cd->back, "ecdb,combo,back,show", "ecdb");
location = _combo_best_location(c);
edje_object_signal_emit(c, "ecdb,combo,expand", "ecdb");
snprintf(buf, sizeof(buf), "ecdb,combo,popup,show,%s", location);
evas_object_geometry_get(c, &x, &y, &w, &h);
back = evas_object_data_get(c, "back");
evas_object_move(back, 0, 0);
ecore_evas_geometry_get(em->main_win_ee, NULL, NULL, &w, &h);
evas_object_resize(back, w, h);
evas_object_pass_events_set(back, 0);
evas_object_layer_set(back, evas_object_layer_get(c) + 1);
edje_object_signal_emit(back, "ecdb,combo,back,show", "ecdb");
h2 = box_height * cd->count;
if (!strcmp(location, "top"))
evas_object_move(cd->popup, x, y - h2);
else
evas_object_move(cd->popup, x, y + h);
evas_object_resize(cd->popup, w, h2);
evas_object_pass_events_set(cd->popup, 0);
evas_object_layer_set(cd->popup, evas_object_layer_get(cd->back) + 1);
edje_object_signal_emit(cd->popup, buf, "ecdb");
cd->expanded = 1;
}
void
ecdb_combo_collapse(Evas_Object *c)
{
Evas_Object *back;
Combo_Data *cd;
const char *location;
char buf[1024];
back = evas_object_data_get(c, "back");
edje_object_signal_emit(back, "ecdb,combo,back,hide", "ecdb");
evas_object_pass_events_set(back, 1);
edje_object_signal_emit(c, "ecdb,combo,collapse", "ecdb");
// If we close the window
if ((!em) || (!em->main_win_ee))
return;
cd = evas_object_data_get(c, "cd");
edje_object_signal_emit(cd->back, "ecdb,combo,back,hide", "ecdb");
evas_object_pass_events_set(cd->back, 1);
edje_object_signal_emit(c, "ecdb,combo,default", "ecdb");
location = _combo_best_location(c);
snprintf(buf, sizeof(buf), "ecdb,combo,popup,hide,%s", location);
evas_object_pass_events_set(cd->popup, 1);
edje_object_signal_emit(cd->popup, buf, "ecdb");
cd->expanded = 0;
}