From 63978e9abb4ee7df1c6cd63dcee3a6164f7b1130 Mon Sep 17 00:00:00 2001 From: rephorm Date: Sun, 20 Aug 2006 21:18:30 +0000 Subject: [PATCH] add gradient bg dialog. finish up the color selector widgets (plug some leaks) TODO: * color_dialog needs a way of specifying initial color * color_well needs to use this when showing its color dialog * the grad dialog should remember the last selected colors * the color dialog whould probably keep a list of favorite / recent colors Also, it looks like there's a leak (according to valgrind at least) in e_editable.c when you set the text and it reallocs. SVN revision: 24953 --- src/bin/Makefile.am | 6 +- src/bin/e_color_dialog.c | 95 ++++++ src/bin/e_color_dialog.h | 36 ++ src/bin/e_includes.h | 1 + src/bin/e_int_config_wallpaper.c | 30 +- src/bin/e_int_config_wallpaper_gradient.c | 383 ++++++++++++++++++++++ src/bin/e_int_config_wallpaper_gradient.h | 10 + src/bin/e_spectrum.c | 2 + src/bin/e_test.c | 32 +- src/bin/e_widget_color_well.c | 74 ++++- src/bin/e_widget_color_well.h | 4 +- src/bin/e_widget_csel.c | 47 ++- src/bin/e_widget_cslider.c | 1 - src/bin/e_widget_spectrum.c | 1 + 14 files changed, 671 insertions(+), 51 deletions(-) create mode 100644 src/bin/e_color_dialog.c create mode 100644 src/bin/e_color_dialog.h create mode 100644 src/bin/e_int_config_wallpaper_gradient.c create mode 100644 src/bin/e_int_config_wallpaper_gradient.h diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 278455864..715b2f94e 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -172,7 +172,9 @@ e_widget_cslider.h \ e_widget_csel.h \ e_widget_color_well.h \ e_int_config_wallpaper.h \ -e_int_config_wallpaper_import.h +e_int_config_wallpaper_import.h \ +e_int_config_wallpaper_gradient.h \ +e_color_dialog.h enlightenment_src = \ e_user.c \ @@ -321,6 +323,8 @@ e_widget_csel.c \ e_widget_color_well.c \ e_int_config_wallpaper.c \ e_int_config_wallpaper_import.c \ +e_int_config_wallpaper_gradient.c \ +e_color_dialog.c \ $(ENLIGHTENMENTHEADERS) enlightenment_SOURCES = \ diff --git a/src/bin/e_color_dialog.c b/src/bin/e_color_dialog.c new file mode 100644 index 000000000..370139874 --- /dev/null +++ b/src/bin/e_color_dialog.c @@ -0,0 +1,95 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ + +#include "e.h" + +static void _e_color_dialog_button1_click(void *data, E_Dialog *edia); +static void _e_color_dialog_button2_click(void *data, E_Dialog *edia); +static void _e_color_dialog_free(E_Color_Dialog *dia); + +E_Color_Dialog * +e_color_dialog_new (E_Container *con) +{ + E_Color_Dialog *dia; + Evas_Object *o; + Evas_Coord mw, mh; + + dia = E_OBJECT_ALLOC(E_File_Dialog, E_COLOR_DIALOG_TYPE, _e_color_dialog_free); + if(!dia) return NULL; + dia->dia = e_dialog_new(con, "E", "_test"); + e_dialog_title_set(dia->dia, "Color Selector"); + + dia->color = calloc(1, sizeof(E_Color)); + dia->color->a = 255; + + o = e_widget_csel_add(dia->dia->win->evas, dia->color); + evas_object_show(o); + e_widget_min_size_get(o, &mw, &mh); + e_dialog_content_set(dia->dia, o, 460, 260); + + /* buttons at the bottom */ + e_dialog_button_add(dia->dia, "OK", NULL, _e_color_dialog_button1_click, dia); + e_dialog_button_add(dia->dia, "Cancel", NULL, _e_color_dialog_button2_click, dia); + e_dialog_resizable_set(dia->dia, 1); + e_win_centered_set(dia->dia->win, 1); + + return dia; +} + +void +e_color_dialog_show (E_Color_Dialog *dia) +{ + e_dialog_show(dia->dia); +} + +void +e_color_dialog_title_set (E_Color_Dialog *dia, const char *title) +{ + e_dialog_title_set(dia->dia, title); +} + +void +e_color_dialog_select_callback_add(E_Color_Dialog *dia, void (*func)(E_Color_Dialog *dia, E_Color *color, void *data), void *data) +{ + dia->select_func = func; + dia->select_data = data; +} + +void +e_color_dialog_cancel_callback_add(E_Color_Dialog *dia, void (*func)(E_Color_Dialog *dia, E_Color *color, void *data), void *data) +{ + dia->cancel_func = func; + dia->cancel_data = data; +} + +static void +_e_color_dialog_button1_click(void *data, E_Dialog *edia) +{ + E_Color_Dialog *dia; + + dia = data; + if(dia->select_func && dia->color) + dia->select_func(dia, dia->color, dia->select_data); + _e_color_dialog_free(dia); +} + +static void +_e_color_dialog_button2_click(void *data, E_Dialog *edia) +{ + E_Color_Dialog *dia; + + dia = data; + if(dia->cancel_func && dia->color) + dia->cancel_func(dia, dia->color, dia->cancel_data); + _e_color_dialog_free(data); +} + +static void +_e_color_dialog_free(E_Color_Dialog *dia) +{ + printf("DIALOG FREE!\n"); + e_object_unref(E_OBJECT(dia->dia)); + E_FREE(dia->color); + E_FREE(dia); +} diff --git a/src/bin/e_color_dialog.h b/src/bin/e_color_dialog.h new file mode 100644 index 000000000..8256b3976 --- /dev/null +++ b/src/bin/e_color_dialog.h @@ -0,0 +1,36 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#ifdef E_TYPEDEFS + +typedef struct _E_Color_Dialog E_Color_Dialog; + +#else +#ifndef E_COLOR_DIALOG_H +#define E_COLOR_DIALOG_H + +#define E_COLOR_DIALOG_TYPE 0xE0b01026 + +struct _E_Color_Dialog +{ + E_Object e_obj_inherit; + + E_Container *con; + E_Dialog *dia; + + E_Color *color; + + void (*select_func)(E_Color_Dialog *dia, E_Color *color, void *data); + void *select_data; + void (*cancel_func)(E_Color_Dialog *dia, E_Color *color, void *data); + void *cancel_data; +}; + +EAPI E_Color_Dialog *e_color_dialog_new (E_Container *con); +EAPI void e_color_dialog_show (E_Color_Dialog *dia); +EAPI void e_color_dialog_title_set (E_Color_Dialog *dia, const char *title); +EAPI void e_color_dialog_select_callback_add(E_Color_Dialog *dia, void (*func)(E_Color_Dialog *dia, E_Color *color, void *data), void *data); +EAPI void e_color_dialog_cancel_callback_add(E_Color_Dialog *dia, void (*func)(E_Color_Dialog *dia, E_Color *color, void *data), void *data); + +#endif +#endif diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h index 20327602a..62cdacc3c 100644 --- a/src/bin/e_includes.h +++ b/src/bin/e_includes.h @@ -149,3 +149,4 @@ #include "e_widget_cslider.h" #include "e_widget_color_well.h" #include "e_widget_csel.h" +#include "e_color_dialog.h" diff --git a/src/bin/e_int_config_wallpaper.c b/src/bin/e_int_config_wallpaper.c index a58fbb581..c55dd3f47 100644 --- a/src/bin/e_int_config_wallpaper.c +++ b/src/bin/e_int_config_wallpaper.c @@ -30,6 +30,7 @@ struct _E_Config_Dialog_Data int all_this_desk_screen; /* dialogs */ E_Win *win_import; + E_Dialog *dia_gradient; }; EAPI E_Config_Dialog * @@ -91,6 +92,15 @@ e_int_config_wallpaper_import_done(E_Config_Dialog *dia) cfdata->win_import = NULL; } +EAPI void +e_int_config_wallpaper_gradient_done(E_Config_Dialog *dia) +{ + E_Config_Dialog_Data *cfdata; + + cfdata = dia->cfdata; + cfdata->dia_gradient = NULL; +} + static void _cb_button_up(void *data1, void *data2) @@ -163,7 +173,6 @@ _cb_files_selected(void *data, Evas_Object *obj, void *event_info) E_Config_Dialog_Data *cfdata; cfdata = data; - printf("SEL\n"); } static void @@ -255,8 +264,18 @@ _cb_import(void *data1, void *data2) else cfdata->win_import = e_int_config_wallpaper_import(cfdata->cfd); } - - +static void +_cb_gradient(void *data1, void *data2) +{ + E_Config_Dialog_Data *cfdata; + + cfdata = data1; + if (cfdata->dia_gradient) + { + e_win_raise(cfdata->dia_gradient->win); + } + else cfdata->dia_gradient = e_int_config_wallpaper_gradient(cfdata->cfd); +} static void _fill_data(E_Config_Dialog_Data *cfdata) @@ -324,6 +343,7 @@ static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) { if (cfdata->win_import) e_int_config_wallpaper_del(cfdata->win_import); + //if (cfdata->dia_gradient) e_int_config_wallpaper_gradient_del(cfdata->dia_gradient); E_FREE(cfdata->bg); free(cfdata); } @@ -424,7 +444,7 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf _cb_import, cfdata, NULL); e_widget_list_object_append(ol, o, 1, 0, 0.5); o = e_widget_button_add(evas, _("Gradient..."), "enlightenment/gradient", - NULL, cfdata, NULL); + _cb_gradient, cfdata, NULL); e_widget_list_object_append(ol, o, 1, 0, 0.5); e_widget_list_object_append(il, ol, 1, 0, 0.5); e_widget_list_object_append(of, il, 1, 0, 0.0); @@ -564,7 +584,7 @@ _advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data _cb_import, cfdata, NULL); e_widget_list_object_append(ol, o, 1, 0, 0.5); o = e_widget_button_add(evas, _("Gradient..."), "enlightenment/gradient", - NULL, cfdata, NULL); + _cb_gradient, cfdata, NULL); e_widget_list_object_append(ol, o, 1, 0, 0.5); e_widget_list_object_append(il, ol, 1, 0, 0.5); e_widget_list_object_append(of, il, 1, 0, 0.0); diff --git a/src/bin/e_int_config_wallpaper_gradient.c b/src/bin/e_int_config_wallpaper_gradient.c new file mode 100644 index 000000000..6a93ba1f3 --- /dev/null +++ b/src/bin/e_int_config_wallpaper_gradient.c @@ -0,0 +1,383 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" + +#define GRAD_H 0 +#define GRAD_V 1 +#define GRAD_DU 2 +#define GRAD_DD 3 +#define GRAD_RAD 4 + +typedef struct _Import Import; + +struct _Import +{ + E_Config_Dialog *parent; + E_Config_Dialog_Data *cfdata; + + E_Dialog *dia; + Evas_Object *bg_obj; + Evas_Object *box_obj; + Evas_Object *content_obj; + Evas_Object *fsel_obj; + + Evas_Object *ok_obj; + Evas_Object *close_obj; + + Evas_Object *fill_h_obj; + Evas_Object *fill_v_obj; + Evas_Object *fill_du_obj; + Evas_Object *fill_dd_obj; + Evas_Object *fill_rad_obj; + Evas_Object *spread_obj; + Evas_Object *frame_obj; + + Ecore_Exe *exe; + Ecore_Event_Handler *exe_handler; + char *tmpf; + char *fdest; +}; + +struct _E_Config_Dialog_Data +{ + char *name; + int mode; + int spread; + + E_Color *color1, *color2; +}; + +static Ecore_Event_Handler *_import_edje_cc_exit_handler = NULL; + +static void _import_opt_disabled_set(Import *import, int disabled); +static void _import_path_save(Import *import); +static void _import_edj_gen(Import *import); +static int _import_cb_edje_cc_exit(void *data, int type, void *event); +static void _import_cb_delete(E_Win *win); +static void _import_cb_close(void *data, E_Dialog *dia); +static void _import_cb_ok(void *data, E_Dialog *dia); + +EAPI E_Dialog * +e_int_config_wallpaper_gradient(E_Config_Dialog *parent) +{ + Evas *evas; + E_Dialog *dia; + Import *import; + Evas_Object *o, *ol, *of, *ord, *ot; + Evas_Coord mw, mh; + E_Radio_Group *rg; + Evas_Coord w, h; + E_Config_Dialog_Data *cfdata; + + import = E_NEW(Import, 1); + if (!import) return NULL; + + dia = e_dialog_new(parent->con, "E", "_wallpaper_gradient_dialog"); + if (!dia) + { + free(import); + return NULL; + } + + dia->win->data = import; + + cfdata = E_NEW(E_Config_Dialog_Data, 1); + cfdata->mode = GRAD_H; + cfdata->spread = 0; + import->cfdata = cfdata; + import->dia = dia; + + cfdata->name = strdup("gradient"); + + evas = e_win_evas_get(dia->win); + + import->parent = parent; + + e_dialog_title_set(dia, _("Create a gradient...")); + // e_win_delete_callback_set(dia->win, _import_cb_delete); + + cfdata->color1 = calloc(1, sizeof(E_Color)); + cfdata->color1->a = 255; + cfdata->color2 = calloc(1, sizeof(E_Color)); + cfdata->color2->a = 255; + + // XXX load last used colors from config. + + ol = e_widget_list_add(evas, 0, 0); + + ot = e_widget_table_add(evas, 0); + evas_object_show(ot); + + o = e_widget_label_add(evas, _("Name:")); + evas_object_show(o); + e_widget_table_object_append(ot, o, 1, 1, 1, 1, 0, 1, 0, 1); + + o = e_widget_label_add(evas, _("Color 1:")); + evas_object_show(o); + e_widget_table_object_append(ot, o, 1, 2, 1, 1, 0, 1, 0, 1); + + o = e_widget_label_add(evas, _("Color 2:")); + evas_object_show(o); + e_widget_table_object_append(ot, o, 1, 3, 1, 1, 0, 1, 0, 1); + + o = e_widget_entry_add(evas, &(cfdata->name)); + evas_object_show(o); + e_widget_table_object_append(ot, o, 2, 1, 1, 1, 1, 1, 1, 1); + + o = e_widget_entry_add(evas, &(cfdata->name)); + evas_object_show(o); + e_widget_table_object_append(ot, o, 2, 1, 1, 1, 1, 1, 1, 1); + + o = e_widget_color_well_add(evas, cfdata->color1, parent->con); + evas_object_show(o); + e_widget_table_object_append(ot, o, 2, 2, 1, 1, 1, 1, 1, 1); + + o = e_widget_color_well_add(evas, cfdata->color2, parent->con); + evas_object_show(o); + e_widget_table_object_append(ot, o, 2, 3, 1, 1, 1, 1, 1, 1); + + e_widget_list_object_append(ol, ot, 1, 1, 0.5); + + of = e_widget_framelist_add(evas, "Fill and Spread Options", 1); + + rg = e_widget_radio_group_new(&(cfdata->mode)); + + ord = e_widget_radio_icon_add(evas, _("Horizontal"), "enlightenment/gradient_h", 24, 24, GRAD_H, rg); + import->fill_h_obj = ord; + e_widget_framelist_object_append(of, ord); + + ord = e_widget_radio_icon_add(evas, _("Vertical"), "enlightenment/gradient_v", 24, 24, GRAD_V, rg); + import->fill_h_obj = ord; + e_widget_framelist_object_append(of, ord); + + ord = e_widget_radio_icon_add(evas, _("Diagonal Up"), "enlightenment/gradient_du", 24, 24, GRAD_DU, rg); + import->fill_h_obj = ord; + e_widget_framelist_object_append(of, ord); + + ord = e_widget_radio_icon_add(evas, _("Diagonal Down"), "enlightenment/gradient_dd", 24, 24, GRAD_DD, rg); + import->fill_h_obj = ord; + e_widget_framelist_object_append(of, ord); + + ord = e_widget_radio_icon_add(evas, _("Radial"), "enlightenment/gradient_rad", 24, 24, GRAD_RAD, rg); + import->fill_h_obj = ord; + e_widget_framelist_object_append(of, ord); + + e_widget_list_object_append(ol, of, 1, 1, 0.5); + + e_widget_min_size_get(ol, &mw, &mh); + e_dialog_content_set(dia, ol, mw, mh); + + e_dialog_button_add(dia, _("OK"), NULL, _import_cb_ok, cfdata); + e_dialog_button_add(dia, _("Cancel"), NULL, _import_cb_close, cfdata); + + _import_opt_disabled_set(import, 1); + e_dialog_resizable_set(dia, 1); + e_dialog_show(dia); + return dia; +} + +void +e_int_config_wallpaper_gradient_del(E_Dialog *dia) +{ + Import *import; + + import = dia->win->data; + + if (import->exe_handler) ecore_event_handler_del(import->exe_handler); + import->exe_handler = NULL; + if (import->tmpf) unlink(import->tmpf); + E_FREE(import->tmpf); + E_FREE(import->fdest); + import->exe = NULL; + + e_int_config_wallpaper_gradient_done(import->parent); + E_FREE(import->cfdata->name); + E_FREE(import->cfdata->color1); + E_FREE(import->cfdata->color2); + E_FREE(import->cfdata); + E_FREE(import); + e_object_unref(E_OBJECT(dia)); + +} + +static void +_import_opt_disabled_set(Import *import, int disabled) +{ +} + +static void +_import_config_save(Import *import) +{ + // XXX save last used colors + e_config_save_queue(); +} + +static void +_import_edj_gen(Import *import) +{ + Evas *evas; + Evas_Object *img; + int fd, num = 1; + int w = 0, h = 0; + const char *file; + char buf[4096], cmd[4096], tmpn[4096], ipart[4096], enc[128]; + char *imgdir = NULL, *homedir, *fstrip; + int cr = 255, cg = 255, cb = 255, ca = 255; + FILE *f; + + int angle; + float fill_origin_x, fill_origin_y; + char *type; + + evas = e_win_evas_get(import->dia->win); + + file = import->cfdata->name; + homedir = e_user_homedir_get(); + if (!homedir) return; + fstrip = ecore_file_strip_ext(file); + if (!fstrip) + { + free(homedir); + return; + } + snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s.edj", homedir, fstrip); + while (ecore_file_exists(buf)) + { + snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s-%i.edj", homedir, fstrip, num); + num++; + } + free(fstrip); + free(homedir); + strcpy(tmpn, "/tmp/e_bgdlg_new.edc-tmp-XXXXXX"); + fd = mkstemp(tmpn); + if (fd < 0) + { + printf("Error Creating tmp file: %s\n", strerror(errno)); + return; + } + close(fd); + + f = fopen(tmpn, "w"); + if (!f) + { + printf("Cannot open %s for writing\n", tmpn); + return; + } + + fstrip = strdup(e_util_filename_escape(file)); + + type = "linear"; + angle = 0; + fill_origin_x = 0; + fill_origin_y = 0; + switch (import->cfdata->mode) + { + case GRAD_H: + angle = 270; + break; + case GRAD_V: + angle = 0; + break; + case GRAD_DU: + angle = 225; + break; + case GRAD_DD: + angle = 315; + break; + case GRAD_RAD: + fill_origin_x = 0.5; + fill_origin_y = 0.5; + type = "radial"; + break; + default: + /* won't happen */ + break; + } + + fprintf(f, + "spectra { spectrum { name: \"gradient\"; color: %d %d %d 255 1; color: %d %d %d 255 1; } }\n" + "collections {\n" + "group {\n" + "name: \"desktop/background\";\n" + "parts {\n" + "part {\n" + " name: \"gradient\";\n" + " type: GRADIENT;\n" + " description {\n" + " state: \"default\" 0.0;\n" + " gradient.spectrum: \"gradient\";\n" + " fill.angle: %d;\n" + " gradient.type: \"%s\";\n" + " fill.origin.relative: %.2f %.2f;\n" + " }\n" + "}\n" + "}\n", + import->cfdata->color1->r, import->cfdata->color1->g, import->cfdata->color1->b, + import->cfdata->color2->r, import->cfdata->color2->g, import->cfdata->color2->b, + angle, + type, + fill_origin_x, fill_origin_y); + + + free(fstrip); + + fclose(f); + + snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s", + tmpn, e_util_filename_escape(buf)); + + import->tmpf = strdup(tmpn); + import->fdest = strdup(buf); + import->exe_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _import_cb_edje_cc_exit, import); + import->exe = ecore_exe_run(cmd, NULL); +} + +static int +_import_cb_edje_cc_exit(void *data, int type, void *event) +{ + Import *import; + Ecore_Exe_Event_Del *ev; + + ev = event; + import = data; + if (ev->exe != import->exe) return 1; + + if (ev->exit_code != 0) + { + e_util_dialog_show(_("Gradient Creation Error"), + _("For some reason, Enlightenment was unable to create a gradient.")); + } + + e_int_config_wallpaper_update(import->parent, import->fdest); + + e_int_config_wallpaper_gradient_del(import->dia); + return 0; +} + +static void +_import_cb_delete(E_Win *win) +{ +} + +static void +_import_cb_close(void *data, E_Dialog *dia) +{ + e_int_config_wallpaper_gradient_del(dia); +} + +static void +_import_cb_ok(void *data, E_Dialog *dia) +{ + Import *import; + + import = dia->win->data; + + if (dia && import->cfdata->name) + { + _import_edj_gen(import); + return; + } + e_int_config_wallpaper_gradient_del(dia); +} + diff --git a/src/bin/e_int_config_wallpaper_gradient.h b/src/bin/e_int_config_wallpaper_gradient.h new file mode 100644 index 000000000..7bf25879a --- /dev/null +++ b/src/bin/e_int_config_wallpaper_gradient.h @@ -0,0 +1,10 @@ +#ifdef E_TYPEDEFS +#else +#ifndef E_INT_CONFIG_WALLPAPER_GRADIENT_H +#define E_INT_CONFIG_WALLPAPER_GRADIENT_H + +EAPI E_Dialog *e_int_config_wallpaper_gradient(E_Config_Dialog *parent); +EAPI void e_int_config_wallpaper_gradient_del(E_Dialog *dia); + +#endif +#endif diff --git a/src/bin/e_spectrum.c b/src/bin/e_spectrum.c index 961d9b83b..5d71320b6 100644 --- a/src/bin/e_spectrum.c +++ b/src/bin/e_spectrum.c @@ -55,6 +55,8 @@ _e_spectrum_smart_del(Evas_Object *o) evas_object_del(sp->o_cursor); if (sp->draw_timer) ecore_timer_del(sp->draw_timer); + + E_FREE(sp); } static void diff --git a/src/bin/e_test.c b/src/bin/e_test.c index 6cb341f04..9f9e9cace 100644 --- a/src/bin/e_test.c +++ b/src/bin/e_test.c @@ -652,39 +652,19 @@ _e_test_internal(E_Container *con) #elif 0 static void -_e_test_cb_change(void *data, Evas_Object *obj) +_e_test_cb_ok(E_Color_Dialog *dia, E_Color *color, void *data) { - E_Color *c = data; - printf("Current color: %d, %d, %d\n", c->r, c->g, c->b); + printf("Current color: %d, %d, %d\n", color->r, color->g, color->b); } static void _e_test_internal(E_Container *con) { - E_Dialog *dia; - Evas_Object *o; - Evas_Coord mw, mh; - E_Color *color; + E_Color_Dialog *d; - dia = e_dialog_new(con, "E", "_test"); - e_dialog_title_set(dia, "Test Color Selector"); - - color = calloc(1, sizeof(E_Color)); - color->a = 255; - - o = e_widget_csel_add(dia->win->evas, color); - evas_object_show(o); - e_widget_on_change_hook_set(o, _e_test_cb_change, color); - e_widget_min_size_get(o, &mw, &mh); - e_dialog_content_set(dia, o, mw, mh); - - /* buttons at the bottom */ - e_dialog_button_add(dia, "Cancel", NULL, NULL, NULL); - e_dialog_button_add(dia, "OK", NULL, NULL, NULL); - e_dialog_resizable_set(dia, 1); - e_win_centered_set(dia->win, 1); - e_dialog_show(dia); - e_win_resize(dia->win, 460, 260); + d = e_color_dialog_new(con); + e_color_dialog_show(d); + e_color_dialog_select_callback_add(d, _e_test_cb_ok, NULL); } #else diff --git a/src/bin/e_widget_color_well.c b/src/bin/e_widget_color_well.c index 3fe80b3ac..bdd136394 100644 --- a/src/bin/e_widget_color_well.c +++ b/src/bin/e_widget_color_well.c @@ -9,9 +9,17 @@ struct _E_Widget_Data Evas_Object *obj; Evas_Object *o_edje; Evas_Object *o_rect; + + E_Color_Dialog *dia; E_Color *color; + E_Container *con; // container to pop a color dialog up on }; +static void _e_wid_update(E_Widget_Data *wd); +static void _e_wid_signal_cb1(void *data, Evas_Object *obj, const char *emission, const char *source); +static void _e_wid_color_select_cb(E_Color_Dialog *dia, E_Color *color, void *data); +static void _e_wid_color_cancel_cb(E_Color_Dialog *dia, E_Color *color, void *data); + static void _e_wid_update(E_Widget_Data *wd) { @@ -21,26 +29,82 @@ _e_wid_update(E_Widget_Data *wd) e_widget_change(wd->obj); } +static void +_e_wid_signal_cb1(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + Evas_Object *wid; + E_Widget_Data *wd; + + wid = data; + wd = e_widget_data_get(wid); + + if (!wd->con) return; + if (!wd->dia) + { + wd->dia = e_color_dialog_new(wd->con); + e_color_dialog_select_callback_add(wd->dia, _e_wid_color_select_cb, wd); + e_color_dialog_cancel_callback_add(wd->dia, _e_wid_color_cancel_cb, wd); + } + e_color_dialog_show(wd->dia); +} + +static void +_e_wid_color_select_cb(E_Color_Dialog *dia, E_Color *color, void *data) +{ + E_Widget_Data *wd; + wd = data; + e_color_copy(color, wd->color); + _e_wid_update(wd); + wd->dia = NULL; +} + +static void +_e_wid_color_cancel_cb(E_Color_Dialog *dia, E_Color *color, void *data) +{ + E_Widget_Data *wd; + wd = data; + wd->dia = NULL; +} + +static void +_e_wid_del_hook(Evas_Object *obj) +{ + E_Widget_Data *wd; + int i; + + wd = e_widget_data_get(obj); + if (!wd) return; + + E_FREE(wd); +} + +/** + * Add a color well widget to an evas. + * An optional E_Container may be passed in. If not NULL, when clicked a color dialog will pop up. + */ Evas_Object * -e_widget_color_well_add(Evas *evas, E_Color *color) +e_widget_color_well_add(Evas *evas, E_Color *color, E_Container *con) { Evas_Object *obj, *o; Evas_Coord mw, mh; E_Widget_Data *wd; obj = e_widget_add(evas); + e_widget_del_hook_set(obj, _e_wid_del_hook); wd = calloc(1, sizeof(E_Widget_Data)); e_widget_data_set(obj, wd); - wd->color = color; wd->obj = obj; + wd->color = color; + wd->con = con; + o = edje_object_add(evas); e_widget_sub_object_add(obj, o); e_widget_resize_object_set(obj, o); e_theme_edje_object_set(o, "base/theme/widgets", "widgets/color_well"); - + edje_object_signal_callback_add(o, "click", "", _e_wid_signal_cb1, obj); evas_object_show(o); wd->o_edje = o; @@ -57,6 +121,9 @@ e_widget_color_well_add(Evas *evas, E_Color *color) return obj; } +/** + * Let the color well know that its color data has changed. + */ void e_widget_color_well_update(Evas_Object *obj) { @@ -67,4 +134,3 @@ e_widget_color_well_update(Evas_Object *obj) } - diff --git a/src/bin/e_widget_color_well.h b/src/bin/e_widget_color_well.h index ec6a17623..3333beebd 100644 --- a/src/bin/e_widget_color_well.h +++ b/src/bin/e_widget_color_well.h @@ -1,7 +1,7 @@ #ifndef E_WIDGET_COLOR_WELL_H #define E_WIDGET_COLOR_WELL_H -void e_widget_color_well_update(Evas_Object *obj); -Evas_Object *e_widget_color_well_add(Evas *evas, E_Color *color); +EAPI Evas_Object *e_widget_color_well_add (Evas *evas, E_Color *color, E_Container *con); +EAPI void e_widget_color_well_update (Evas_Object *obj); #endif diff --git a/src/bin/e_widget_csel.c b/src/bin/e_widget_csel.c index 112b26f59..a8641579e 100644 --- a/src/bin/e_widget_csel.c +++ b/src/bin/e_widget_csel.c @@ -16,6 +16,27 @@ struct _E_Widget_Data int changing; }; +static void +_e_wid_del_hook(Evas_Object *obj) +{ + E_Widget_Data *wd; + int i; + + wd = e_widget_data_get(obj); + if (!wd) return; + + for (i = 0; i < E_COLOR_COMPONENT_MAX; i++) + { + E_FREE(wd->values[i]); + } + E_FREE(wd->values); + + evas_list_free(wd->sliders); + evas_list_free(wd->entries); + + E_FREE(wd); +} + static void _e_wid_cb_radio_changed(void *data, Evas_Object *o) { @@ -148,18 +169,19 @@ e_widget_csel_add(Evas *evas, E_Color *color) { Evas_Object *obj, *o; Evas_Object *frame, *table; - E_Color*cv; int i; E_Radio_Group *grp = NULL; char *labels[6] = { "R", "G", "B", "H", "S", "V" }; E_Widget_Data *wd; obj = e_widget_add(evas); + e_widget_del_hook_set(obj, _e_wid_del_hook); wd = calloc(1, sizeof(E_Widget_Data)); wd->mode = 1; wd->cv = color; wd->obj = obj; + e_widget_data_set(obj, wd); table = e_widget_table_add(evas, 0); e_widget_sub_object_add(obj, table); @@ -177,22 +199,22 @@ e_widget_csel_add(Evas *evas, E_Color *color) switch(i) { case E_COLOR_COMPONENT_R: - snprintf(wd->values[i], 10, "%i", cv->r); + snprintf(wd->values[i], 10, "%i", wd->cv->r); break; case E_COLOR_COMPONENT_G: - snprintf(wd->values[i], 10, "%i", cv->g); + snprintf(wd->values[i], 10, "%i", wd->cv->g); break; case E_COLOR_COMPONENT_B: - snprintf(wd->values[i], 10, "%i", cv->b); + snprintf(wd->values[i], 10, "%i", wd->cv->b); break; case E_COLOR_COMPONENT_H: - snprintf(wd->values[i], 10, "%.0f", cv->h); + snprintf(wd->values[i], 10, "%.0f", wd->cv->h); break; case E_COLOR_COMPONENT_S: - snprintf(wd->values[i], 10, "%.2f", cv->s); + snprintf(wd->values[i], 10, "%.2f", wd->cv->s); break; case E_COLOR_COMPONENT_V: - snprintf(wd->values[i], 11, "%.2f", cv->v); + snprintf(wd->values[i], 11, "%.2f", wd->cv->v); break; } @@ -201,7 +223,7 @@ e_widget_csel_add(Evas *evas, E_Color *color) e_widget_on_change_hook_set(o, _e_wid_cb_radio_changed, wd); e_widget_frametable_object_append(frame, o, 0, i, 1, 1, 1, 1, 0, 0); - o = e_widget_cslider_add(evas, i, cv, 0, 0); + o = e_widget_cslider_add(evas, i, wd->cv, 0, 0); e_widget_sub_object_add(obj, o); evas_object_show(o); wd->sliders = evas_list_append(wd->sliders, o); @@ -217,23 +239,24 @@ e_widget_csel_add(Evas *evas, E_Color *color) } - o = e_widget_spectrum_add(evas, wd->mode, cv); + o = e_widget_spectrum_add(evas, wd->mode, wd->cv); e_widget_sub_object_add(obj, o); evas_object_show(o); e_widget_on_change_hook_set(o, _e_wid_cb_color_changed, wd); wd->spectrum = o; e_widget_table_object_append(table, o, 1, 1, 1, 1, 1, 1, 1, 1); - o = e_widget_cslider_add(evas, wd->mode, cv, 1, 1); + o = e_widget_cslider_add(evas, wd->mode, wd->cv, 1, 1); e_widget_sub_object_add(obj, o); e_widget_on_change_hook_set(o, _e_wid_cb_color_changed, wd); + e_widget_min_size_set(o, 30, 50); evas_object_show(o); wd->vert = o; - e_widget_table_object_append(table, o, 2, 1, 1, 1, 1, 1, 0, 1); + e_widget_table_object_append(table, o, 2, 1, 1, 1, 0, 1, 0, 1); e_widget_table_object_append(table, frame, 3, 1, 1, 1, 1, 1, 1, 1); - o = e_widget_color_well_add(evas, cv); + o = e_widget_color_well_add(evas, wd->cv, NULL); e_widget_sub_object_add(obj, o); evas_object_show(o); wd->well = o; diff --git a/src/bin/e_widget_cslider.c b/src/bin/e_widget_cslider.c index 94bfeb0f9..9b6fa4137 100644 --- a/src/bin/e_widget_cslider.c +++ b/src/bin/e_widget_cslider.c @@ -15,7 +15,6 @@ struct _E_Widget_Data int fixed; E_Color_Component mode; int valnum; - //int r, g, b, a; E_Color *color; int dragging; diff --git a/src/bin/e_widget_spectrum.c b/src/bin/e_widget_spectrum.c index 22aa6eb54..0735097d9 100644 --- a/src/bin/e_widget_spectrum.c +++ b/src/bin/e_widget_spectrum.c @@ -77,6 +77,7 @@ e_widget_spectrum_add(Evas *evas, E_Color_Component mode, E_Color *cv) o = evas_object_rectangle_add(evas); evas_object_color_set(o, 0, 0, 0, 0); + e_widget_sub_object_add(obj, o); evas_object_show(o); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_wid_cb_down, obj); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _e_wid_cb_move, obj);