From bca4e798f164516f51a34df72d9ebec5d97a33a8 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 21 Jan 2006 12:44:48 +0000 Subject: [PATCH] Add a close button callback hook at the request of devilhorns. If the callback returns zero, the dialog is NOT closed. Seems that every user of config_dialog allocates E_Config_Dialog_View on the stack and doesn't clear it, so I can't rely on the close_cfdata member being NULL. I currently set it to NULL in e_config_dialog_new() and if you want to use it, set it in create_widgets(); I suspect that allocating a structure on the stack that lives beyond the function call is just asking for trouble. SVN revision: 19945 --- src/bin/e_config_dialog.c | 25 ++++++++++++++++++++++++- src/bin/e_config_dialog.h | 5 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/bin/e_config_dialog.c b/src/bin/e_config_dialog.c index 397d661..e3f0f07 100644 --- a/src/bin/e_config_dialog.c +++ b/src/bin/e_config_dialog.c @@ -12,6 +12,7 @@ static void _e_config_dialog_cb_apply(void *data, E_Dialog *dia); static void _e_config_dialog_cb_advanced(void *data, void *data2); static void _e_config_dialog_cb_basic(void *data, void *data2); static void _e_config_dialog_cb_changed(void *data, Evas_Object *obj); +static void _e_config_dialog_cb_close(void *data, E_Dialog *dia); /* local subsystem globals */ @@ -22,8 +23,16 @@ e_config_dialog_new(E_Container *con, char *title, char *icon, int icon_size, E_ { E_Config_Dialog *cfd; + cfd = E_OBJECT_ALLOC(E_Config_Dialog, E_CONFIG_DIALOG_TYPE, _e_config_dialog_free); cfd->view = *view; + /* Seems that every user of this allocates view it on the stack and doesn't clear it, + * so I can't rely on this being NULL. I currently set it to NULL in e_config_dialog_new() + * and if you want to use it, set it in create_widgets(); + * I suspect that allocating a structure on the stack that lives beyond the function + * call is just asking for trouble. + */ + cfd->view.close_cfdata = NULL; cfd->con = con; cfd->title = evas_stringshare_add(title); if (icon) @@ -122,7 +131,7 @@ _e_config_dialog_go(E_Config_Dialog *cfd, E_Config_Dialog_CFData_Type type) e_dialog_button_disable_num_set(cfd->dia, 0, 1); e_dialog_button_disable_num_set(cfd->dia, 1, 1); } - e_dialog_button_add(cfd->dia, _("Close"), NULL, NULL, NULL); + e_dialog_button_add(cfd->dia, _("Close"), NULL, _e_config_dialog_cb_close, cfd); if (!pdia) { e_win_centered_set(cfd->dia->win, 1); @@ -239,3 +248,17 @@ _e_config_dialog_cb_changed(void *data, Evas_Object *obj) e_dialog_button_disable_num_set(cfd->dia, 1, 0); } } + +static void +_e_config_dialog_cb_close(void *data, E_Dialog *dia) +{ + E_Config_Dialog *cfd; + int ok = 1; + + cfd = dia->data; + if (cfd->view.close_cfdata) + ok = cfd->view.close_cfdata(cfd, cfd->cfdata); + + if (ok) + e_object_del(E_OBJECT(dia)); +} diff --git a/src/bin/e_config_dialog.h b/src/bin/e_config_dialog.h index bbe31be..23f7965 100644 --- a/src/bin/e_config_dialog.h +++ b/src/bin/e_config_dialog.h @@ -23,6 +23,11 @@ struct _E_Config_Dialog_View { void *(*create_cfdata) (E_Config_Dialog *cfd); void (*free_cfdata) (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); + /* Seems that every user of this structure allocates it on the stack and doesn't clear it, + * so I can't rely on this being NULL. I currently set it to NULL in e_config_dialog_new() + * and if you want to use it, set it in create_widgets(); + */ + int (*close_cfdata) (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); struct { int (*apply_cfdata) (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); Evas_Object *(*create_widgets) (E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); -- 2.7.4