Work on a combo
This commit is contained in:
@ -733,8 +733,10 @@ ecdb_erase_page_show(void)
|
||||
|
||||
if (!swallow)
|
||||
{
|
||||
Evas_Object *b;
|
||||
Evas_Object *b, *d;
|
||||
Evas_Coord x, y, w, h;
|
||||
Eina_List *l;
|
||||
Ecdb_Drive_Info *drive;
|
||||
|
||||
swallow = edje_object_add(ecore_evas_get(em->main_win_ee));
|
||||
edje_object_file_set(swallow, em->theme_path, "ecdb/erase_page");
|
||||
@ -767,6 +769,17 @@ ecdb_erase_page_show(void)
|
||||
b = ecdb_check_add(swallow, "ecdb/erase/speed");
|
||||
ecdb_check_label_set(b, "Quick Erase");
|
||||
evas_object_show(b);
|
||||
|
||||
b = ecdb_combo_add(swallow, "ecdb/erase/drive");
|
||||
ecdb_combo_header_set(b, "Drive");
|
||||
|
||||
EINA_LIST_FOREACH(em->drives, l, drive)
|
||||
{
|
||||
d = ecdb_button_add(swallow, NULL);
|
||||
ecdb_button_label_set(d, drive->location);
|
||||
ecdb_combo_append(b, d);
|
||||
evas_object_show(d);
|
||||
}
|
||||
}
|
||||
|
||||
else if (edje_object_part_swallow_get(gui, "action_area") != swallow)
|
||||
|
@ -1,9 +1,6 @@
|
||||
/* vim: set sw=3 ts=3 sts=3 expandtab: */
|
||||
#include "ecdb.h"
|
||||
|
||||
static char *ecdb_entry_markup_to_text(const char *mkup);
|
||||
static char *_str_append(char *str, const char *txt, int *len, int *alloc);
|
||||
|
||||
Evas_Object *
|
||||
ecdb_widget_add(Evas_Object *parent, const char *name)
|
||||
{
|
||||
@ -11,15 +8,28 @@ ecdb_widget_add(Evas_Object *parent, const char *name)
|
||||
int x, y, w, h;
|
||||
|
||||
o = edje_object_add(evas_object_evas_get(parent));
|
||||
evas_object_name_set(o, name);
|
||||
edje_object_part_geometry_get(parent, name, &x, &y, &w, &h);
|
||||
evas_object_move(o, x, y);
|
||||
evas_object_resize(o, w, h);
|
||||
edje_object_part_swallow(parent, name, o);
|
||||
|
||||
if (name)
|
||||
{
|
||||
evas_object_name_set(o, name);
|
||||
edje_object_part_geometry_get(parent, name, &x, &y, &w, &h);
|
||||
evas_object_move(o, x, y);
|
||||
evas_object_resize(o, w, h);
|
||||
edje_object_part_swallow(parent, name, o);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/************************** BUTTON ******************************************/
|
||||
|
||||
void
|
||||
_button_click_cb_call(void *data, Evas_Object *obj, const char *emission,
|
||||
const char *source)
|
||||
{
|
||||
evas_object_smart_callback_call(obj, "clicked", NULL);
|
||||
}
|
||||
|
||||
Evas_Object *
|
||||
ecdb_button_add(Evas_Object *parent, const char *name)
|
||||
{
|
||||
@ -27,6 +37,8 @@ ecdb_button_add(Evas_Object *parent, const char *name)
|
||||
|
||||
b = ecdb_widget_add(parent, name);
|
||||
edje_object_file_set(b, em->theme_path, "ecdb/button");
|
||||
edje_object_signal_callback_add(b, "ecdb,button,clicked", "ecdb",
|
||||
_button_click_cb_call, b);
|
||||
|
||||
return b;
|
||||
}
|
||||
@ -47,6 +59,8 @@ ecdb_button_icon_set(Evas_Object *b, const char *group)
|
||||
evas_object_show(icon);
|
||||
}
|
||||
|
||||
/************************* CHECK *********************************************/
|
||||
|
||||
Evas_Object *
|
||||
ecdb_check_add(Evas_Object *parent, const char *name)
|
||||
{
|
||||
@ -84,34 +98,32 @@ ecdb_check_state_set(Evas_Object *c, int state)
|
||||
}
|
||||
}
|
||||
|
||||
Evas_Object *
|
||||
ecdb_entry_add(Evas_Object *parent, const char *name)
|
||||
{
|
||||
Evas_Object *e;
|
||||
|
||||
e = ecdb_widget_add(parent, name);
|
||||
edje_object_file_set(e, em->theme_path, "ecdb/entry");
|
||||
em->dnd_candidates = eina_list_append(em->dnd_candidates, e);
|
||||
evas_object_data_set(e, "dnd_call_func", ecdb_dnd_entry_dnd_set);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
void
|
||||
ecdb_entry_text_set(Evas_Object *e, const char *text)
|
||||
{
|
||||
edje_object_part_text_set(e, "ecdb.text", text);
|
||||
}
|
||||
|
||||
char *
|
||||
ecdb_entry_text_get(Evas_Object *e)
|
||||
{
|
||||
return ecdb_entry_markup_to_text(edje_object_part_text_get(e, "ecdb.text"));
|
||||
}
|
||||
/************************** ENTRY *******************************************/
|
||||
|
||||
/* Shamelessly stolen from Elementary... */
|
||||
static char *
|
||||
ecdb_entry_markup_to_text(const char *mkup)
|
||||
_entry_str_append(char *str, const char *txt, int *len, int *alloc)
|
||||
{
|
||||
int txt_len = strlen(txt);
|
||||
if (txt_len <= 0) return str;
|
||||
if ((*len + txt_len) >= *alloc)
|
||||
{
|
||||
char *str2;
|
||||
int alloc2;
|
||||
|
||||
alloc2 = *alloc + txt_len + 128;
|
||||
str2 = realloc(str, alloc2);
|
||||
if (!str2) return str;
|
||||
*alloc = alloc2;
|
||||
str = str2;
|
||||
}
|
||||
strcpy(str + *len, txt);
|
||||
*len += txt_len;
|
||||
return str;
|
||||
}
|
||||
|
||||
static char *
|
||||
_entry_markup_to_text(const char *mkup)
|
||||
{
|
||||
char *str = NULL;
|
||||
int str_len = 0, str_alloc = 0;
|
||||
@ -142,13 +154,17 @@ ecdb_entry_markup_to_text(const char *mkup)
|
||||
str = _str_append(str, "\n", &str_len, &str_alloc);
|
||||
*/
|
||||
if (!strcmp(ttag, "\n"))
|
||||
str = _str_append(str, "\n", &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, "\n", &str_len,
|
||||
&str_alloc);
|
||||
else if (!strcmp(ttag, "\\n"))
|
||||
str = _str_append(str, "\n", &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, "\n", &str_len,
|
||||
&str_alloc);
|
||||
else if (!strcmp(ttag, "\t"))
|
||||
str = _str_append(str, "\t", &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, "\t", &str_len,
|
||||
&str_alloc);
|
||||
else if (!strcmp(ttag, "\\t"))
|
||||
str = _str_append(str, "\t", &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, "\t", &str_len,
|
||||
&str_alloc);
|
||||
free(ttag);
|
||||
}
|
||||
tag_start = tag_end = NULL;
|
||||
@ -163,7 +179,8 @@ ecdb_entry_markup_to_text(const char *mkup)
|
||||
ts[esc_end - esc_start] = 0;
|
||||
esc = evas_textblock_escape_string_get(ts);
|
||||
if (esc)
|
||||
str = _str_append(str, esc, &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, esc, &str_len,
|
||||
&str_alloc);
|
||||
free(ts);
|
||||
}
|
||||
esc_start = esc_end = NULL;
|
||||
@ -175,7 +192,7 @@ ecdb_entry_markup_to_text(const char *mkup)
|
||||
{
|
||||
strncpy(ts, s, p - s);
|
||||
ts[p - s] = 0;
|
||||
str = _str_append(str, ts, &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, ts, &str_len, &str_alloc);
|
||||
free(ts);
|
||||
}
|
||||
s = NULL;
|
||||
@ -194,7 +211,7 @@ ecdb_entry_markup_to_text(const char *mkup)
|
||||
{
|
||||
strncpy(ts, s, p - s);
|
||||
ts[p - s] = 0;
|
||||
str = _str_append(str, ts, &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, ts, &str_len, &str_alloc);
|
||||
free(ts);
|
||||
}
|
||||
s = NULL;
|
||||
@ -219,7 +236,7 @@ ecdb_entry_markup_to_text(const char *mkup)
|
||||
{
|
||||
strncpy(ts, s, p - s);
|
||||
ts[p - s] = 0;
|
||||
str = _str_append(str, ts, &str_len, &str_alloc);
|
||||
str = _entry_str_append(str, ts, &str_len, &str_alloc);
|
||||
free(ts);
|
||||
}
|
||||
s = NULL;
|
||||
@ -238,23 +255,138 @@ ecdb_entry_markup_to_text(const char *mkup)
|
||||
return str;
|
||||
}
|
||||
|
||||
static char *
|
||||
_str_append(char *str, const char *txt, int *len, int *alloc)
|
||||
Evas_Object *
|
||||
ecdb_entry_add(Evas_Object *parent, const char *name)
|
||||
{
|
||||
int txt_len = strlen(txt);
|
||||
if (txt_len <= 0) return str;
|
||||
if ((*len + txt_len) >= *alloc)
|
||||
{
|
||||
char *str2;
|
||||
int alloc2;
|
||||
|
||||
alloc2 = *alloc + txt_len + 128;
|
||||
str2 = realloc(str, alloc2);
|
||||
if (!str2) return str;
|
||||
*alloc = alloc2;
|
||||
str = str2;
|
||||
}
|
||||
strcpy(str + *len, txt);
|
||||
*len += txt_len;
|
||||
return str;
|
||||
Evas_Object *e;
|
||||
|
||||
e = ecdb_widget_add(parent, name);
|
||||
edje_object_file_set(e, em->theme_path, "ecdb/entry");
|
||||
em->dnd_candidates = eina_list_append(em->dnd_candidates, e);
|
||||
evas_object_data_set(e, "dnd_call_func", ecdb_dnd_entry_dnd_set);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
void
|
||||
ecdb_entry_text_set(Evas_Object *e, const char *text)
|
||||
{
|
||||
edje_object_part_text_set(e, "ecdb.text", text);
|
||||
}
|
||||
|
||||
char *
|
||||
ecdb_entry_text_get(Evas_Object *e)
|
||||
{
|
||||
return _entry_markup_to_text(edje_object_part_text_get(e, "ecdb.text"));
|
||||
}
|
||||
|
||||
/****************************** COMBO ****************************************/
|
||||
|
||||
// Axis preferential -- for now vertical
|
||||
const char *
|
||||
_combo_best_location(Evas_Object *c)
|
||||
{
|
||||
int x, y, w, h;
|
||||
int ww, wh;
|
||||
|
||||
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))
|
||||
{
|
||||
return "top";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "bottom";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_combo_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
Evas_Object *c, *back;
|
||||
int w, h;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
static void
|
||||
_combo_hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
ecdb_combo_collapse(data);
|
||||
}
|
||||
|
||||
static void
|
||||
_combo_clicked(void *data, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
ecdb_combo_collapse(data);
|
||||
}
|
||||
|
||||
Evas_Object *
|
||||
ecdb_combo_add(Evas_Object *parent, const char *name)
|
||||
{
|
||||
Evas_Object *c, *back;
|
||||
|
||||
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(parent, EVAS_CALLBACK_HIDE, _combo_hide, c);
|
||||
|
||||
back = edje_object_add(evas_object_evas_get(parent));
|
||||
edje_object_file_set(back, em->theme_path, "ecdb/combo/background");
|
||||
evas_object_data_set(c, "back", back);
|
||||
evas_object_show(back);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
ecdb_combo_header_set(Evas_Object *c, const char *text)
|
||||
{
|
||||
edje_object_part_text_set(c, "ecdb.header", text);
|
||||
}
|
||||
|
||||
void
|
||||
ecdb_combo_append(Evas_Object *c, Evas_Object *o)
|
||||
{
|
||||
edje_object_part_box_append(c, "ecdb.box", o);
|
||||
evas_object_smart_callback_add(o, "clicked", _combo_clicked, c);
|
||||
}
|
||||
|
||||
void
|
||||
ecdb_combo_expand(Evas_Object *c)
|
||||
{
|
||||
Evas_Object *back;
|
||||
const char *location;
|
||||
char buf[1024];
|
||||
int w, h;
|
||||
|
||||
location = _combo_best_location(c);
|
||||
snprintf(buf, sizeof(buf), "ecdb,combo,expand,%s", location);
|
||||
edje_object_signal_emit(c, buf, "ecdb");
|
||||
|
||||
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);
|
||||
edje_object_signal_emit(back, "ecdb,combo,back,show", "ecdb");
|
||||
}
|
||||
|
||||
void
|
||||
ecdb_combo_collapse(Evas_Object *c)
|
||||
{
|
||||
Evas_Object *back;
|
||||
|
||||
back = evas_object_data_get(c, "back");
|
||||
edje_object_signal_emit(back, "ecdb,combo,back,hide", "ecdb");
|
||||
edje_object_signal_emit(c, "ecdb,combo,collapse", "ecdb");
|
||||
}
|
||||
|
||||
|
@ -16,4 +16,12 @@ Evas_Object *ecdb_entry_add(Evas_Object *parent, const char *name);
|
||||
void ecdb_entry_text_set(Evas_Object *e, const char *text);
|
||||
char *ecdb_entry_text_get(Evas_Object *e);
|
||||
|
||||
// I am unsure about whether to use elementary here or not... It would be nice
|
||||
Evas_Object *ecdb_combo_add(Evas_Object *parent, const char *name);
|
||||
void ecdb_combo_header_set(Evas_Object *c, const char *text);
|
||||
void ecdb_combo_append(Evas_Object *c, Evas_Object *o);
|
||||
void ecdb_combo_expand(Evas_Object *c);
|
||||
void ecdb_combo_collapse(Evas_Object *c);
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user