mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Remove query-user.[ch] cruft.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2737 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
a0e4b34fbf
commit
f4b80ac0ba
@ -34,186 +34,6 @@
|
|||||||
static short module = MOD_GUI;
|
static short module = MOD_GUI;
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************
|
|
||||||
gnc_foundation_query_dialog
|
|
||||||
|
|
||||||
A flexible user dialog that allows you to set up which buttons you
|
|
||||||
want at the bottom, and whatever contents you want inside the main
|
|
||||||
portion of the window.
|
|
||||||
|
|
||||||
This function creates a dialog with the requested buttons. Clicking
|
|
||||||
yes or ok will set *dialog_result to GNC_QUERY_YES, no to
|
|
||||||
GNC_QUERY_NO and cancel to GNC_QUERY_CANCEL. These values are all
|
|
||||||
negative; positive values are reserved for the caller.
|
|
||||||
|
|
||||||
Each of the *_allowed arguments indicates whether or not the dialog
|
|
||||||
should contain a button of that type. default_answer may be set to
|
|
||||||
GNC_QUERY_YES for "yes" (or OK), GNC_QUERY_NO for "no", and
|
|
||||||
GNC_QUERY_CANCEL for "cancel". If you allow both yes and OK buttons,
|
|
||||||
and set GNC_QUERY_YES as the default answer, which button is the
|
|
||||||
default is undefined, but the result is the same either way, and why
|
|
||||||
would you be doing that anyhow?
|
|
||||||
|
|
||||||
The function returns the created dialog, or NULL if there was a
|
|
||||||
problem.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int delete_result;
|
|
||||||
int * dialog_result;
|
|
||||||
} FoundationCBData;
|
|
||||||
|
|
||||||
static void
|
|
||||||
foundation_query_yes_cb(GtkWidget *w, gpointer data)
|
|
||||||
{
|
|
||||||
int *result = (int *) data;
|
|
||||||
*result = GNC_QUERY_YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
foundation_query_no_cb(GtkWidget *w, gpointer data)
|
|
||||||
{
|
|
||||||
int *result = (int *) data;
|
|
||||||
*result = GNC_QUERY_NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
foundation_query_cancel_cb(GtkWidget *w, gpointer data)
|
|
||||||
{
|
|
||||||
int *result = (int *) data;
|
|
||||||
*result = GNC_QUERY_CANCEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
foundation_query_delete_cb(GtkWidget *w, GdkEvent *event, gpointer data)
|
|
||||||
{
|
|
||||||
FoundationCBData * cb_data = (FoundationCBData *) data;
|
|
||||||
*(cb_data->dialog_result) = cb_data->delete_result;
|
|
||||||
return(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
|
||||||
foundation_query_close_cb(GtkWidget *w, gpointer data)
|
|
||||||
{
|
|
||||||
g_free(data);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkWidget *
|
|
||||||
gnc_foundation_query_dialog(gncUIWidget parent,
|
|
||||||
const gchar *title,
|
|
||||||
GtkWidget *contents,
|
|
||||||
int default_answer,
|
|
||||||
gboolean yes_allowed,
|
|
||||||
gboolean ok_allowed,
|
|
||||||
gboolean no_allowed,
|
|
||||||
gboolean cancel_allowed,
|
|
||||||
int *dialog_result) {
|
|
||||||
|
|
||||||
FoundationCBData * cb_data;
|
|
||||||
GtkWidget *query_dialog = NULL;
|
|
||||||
|
|
||||||
const gchar *button_names[5] = {NULL, NULL, NULL, NULL, NULL};
|
|
||||||
GtkSignalFunc button_func[5] = {NULL, NULL, NULL, NULL, NULL};
|
|
||||||
|
|
||||||
int button_count = 0;
|
|
||||||
int default_button = 0;
|
|
||||||
int delete_result = 0;
|
|
||||||
|
|
||||||
/* Validate our arguments */
|
|
||||||
assert(yes_allowed || ok_allowed || no_allowed || cancel_allowed);
|
|
||||||
assert((default_answer == GNC_QUERY_YES) ||
|
|
||||||
(default_answer == GNC_QUERY_NO) ||
|
|
||||||
(default_answer == GNC_QUERY_CANCEL));
|
|
||||||
assert((default_answer != GNC_QUERY_YES) || (yes_allowed || ok_allowed));
|
|
||||||
assert((default_answer != GNC_QUERY_NO) || no_allowed);
|
|
||||||
assert((default_answer != GNC_QUERY_CANCEL) || cancel_allowed);
|
|
||||||
assert(dialog_result != NULL);
|
|
||||||
|
|
||||||
/* Setup buttons */
|
|
||||||
if(yes_allowed) {
|
|
||||||
button_names[button_count] = GNOME_STOCK_BUTTON_YES;
|
|
||||||
button_func[button_count] = GTK_SIGNAL_FUNC(foundation_query_yes_cb);
|
|
||||||
if(GNC_QUERY_YES == default_answer) default_button = button_count;
|
|
||||||
delete_result = GNC_QUERY_YES;
|
|
||||||
button_count++;
|
|
||||||
}
|
|
||||||
if(ok_allowed) {
|
|
||||||
button_names[button_count] = GNOME_STOCK_BUTTON_OK;
|
|
||||||
button_func[button_count] = GTK_SIGNAL_FUNC(foundation_query_yes_cb);
|
|
||||||
if(GNC_QUERY_YES == default_answer) default_button = button_count;
|
|
||||||
delete_result = GNC_QUERY_YES;
|
|
||||||
button_count++;
|
|
||||||
}
|
|
||||||
if(no_allowed) {
|
|
||||||
button_names[button_count] = GNOME_STOCK_BUTTON_NO;
|
|
||||||
button_func[button_count] = GTK_SIGNAL_FUNC(foundation_query_no_cb);
|
|
||||||
if(GNC_QUERY_NO == default_answer) default_button = button_count;
|
|
||||||
delete_result = GNC_QUERY_NO;
|
|
||||||
button_count++;
|
|
||||||
}
|
|
||||||
if(cancel_allowed) {
|
|
||||||
button_names[button_count] = GNOME_STOCK_BUTTON_CANCEL;
|
|
||||||
button_func[button_count] = GTK_SIGNAL_FUNC(foundation_query_cancel_cb);
|
|
||||||
if(GNC_QUERY_CANCEL == default_answer) default_button = button_count;
|
|
||||||
delete_result = GNC_QUERY_CANCEL;
|
|
||||||
button_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate our resources */
|
|
||||||
cb_data = g_new(FoundationCBData, 1);
|
|
||||||
|
|
||||||
query_dialog = gnome_dialog_newv(title, button_names);
|
|
||||||
|
|
||||||
if (query_dialog == NULL) {
|
|
||||||
g_free(cb_data);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Connect button signals */
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < button_count; i++) {
|
|
||||||
gnome_dialog_button_connect(GNOME_DIALOG(query_dialog), i,
|
|
||||||
GTK_SIGNAL_FUNC(button_func[i]),
|
|
||||||
(gpointer) dialog_result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup the delete and close callbacks */
|
|
||||||
cb_data->delete_result = delete_result;
|
|
||||||
cb_data->dialog_result = dialog_result;
|
|
||||||
|
|
||||||
gtk_signal_connect(GTK_OBJECT(query_dialog),
|
|
||||||
"delete_event",
|
|
||||||
GTK_SIGNAL_FUNC(foundation_query_delete_cb),
|
|
||||||
cb_data);
|
|
||||||
|
|
||||||
gtk_signal_connect(GTK_OBJECT(query_dialog),
|
|
||||||
"close",
|
|
||||||
GTK_SIGNAL_FUNC(foundation_query_close_cb),
|
|
||||||
cb_data);
|
|
||||||
|
|
||||||
/* Setup window settings */
|
|
||||||
gtk_window_set_modal(GTK_WINDOW(query_dialog), TRUE);
|
|
||||||
gnome_dialog_set_default(GNOME_DIALOG(query_dialog), default_button);
|
|
||||||
gnome_dialog_set_close(GNOME_DIALOG(query_dialog), TRUE);
|
|
||||||
if (parent != NULL)
|
|
||||||
gnome_dialog_set_parent(GNOME_DIALOG(query_dialog), GTK_WINDOW(parent));
|
|
||||||
else
|
|
||||||
gnome_dialog_set_parent(GNOME_DIALOG(query_dialog),
|
|
||||||
GTK_WINDOW(gnc_get_ui_data()));
|
|
||||||
|
|
||||||
/* Add in the user-supplied widget */
|
|
||||||
if(contents)
|
|
||||||
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(query_dialog)->vbox),
|
|
||||||
contents, FALSE, FALSE, 0);
|
|
||||||
|
|
||||||
return query_dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* gnc_ok_cancel_dialog_parented *
|
* gnc_ok_cancel_dialog_parented *
|
||||||
* display a message, and asks the user to press "Ok" or "Cancel" *
|
* display a message, and asks the user to press "Ok" or "Cancel" *
|
||||||
@ -473,178 +293,6 @@ gnc_error_dialog_parented(GtkWindow *parent, const char *message)
|
|||||||
gnome_dialog_run_and_close(GNOME_DIALOG(error_box));
|
gnome_dialog_run_and_close(GNOME_DIALOG(error_box));
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************
|
|
||||||
gnc_choose_one_from_list_dialog
|
|
||||||
|
|
||||||
This function is primarily intended to be called from scheme.
|
|
||||||
|
|
||||||
Returns ('result . value) if the user selects an item, 'cancel if the
|
|
||||||
user selects cancel, and #f if there was a failure of some kind.
|
|
||||||
|
|
||||||
list_items must be a scheme list of pairs. Each pair must contain a
|
|
||||||
list item name (as a string) followed by a thunk to call when that
|
|
||||||
item is selected. The thunk should take no arguments. If the thunk
|
|
||||||
does not return #f, then the dialog box will be closed and this
|
|
||||||
function will return that thunk's result in a pair ('result . value).
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *name;
|
|
||||||
SCM closure;
|
|
||||||
int *dialog_result;
|
|
||||||
SCM *scm_result;
|
|
||||||
GnomeDialog *dialog;
|
|
||||||
} ChooseItemCBData;
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_choose_item_cb(GtkWidget *w, gpointer p)
|
|
||||||
{
|
|
||||||
if (p == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
{
|
|
||||||
ChooseItemCBData *d = (ChooseItemCBData *) p;
|
|
||||||
SCM result = gh_call0(d->closure);
|
|
||||||
|
|
||||||
if(result != SCM_BOOL_F) {
|
|
||||||
*(d->dialog_result) = 1;
|
|
||||||
*(d->scm_result) = result;
|
|
||||||
gnome_dialog_close(d->dialog);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
|
||||||
gnc_choose_item_from_list_dialog(const char *title, SCM list_items)
|
|
||||||
{
|
|
||||||
ChooseItemCBData *cb_data = NULL;
|
|
||||||
int dialog_result = 0;
|
|
||||||
SCM scm_result = SCM_BOOL_F;
|
|
||||||
int result;
|
|
||||||
unsigned long num_items;
|
|
||||||
GtkWidget *vbox;
|
|
||||||
GtkWidget *query_box;
|
|
||||||
SCM listcursor;
|
|
||||||
gboolean status_ok;
|
|
||||||
unsigned long i;
|
|
||||||
|
|
||||||
if(title == NULL)
|
|
||||||
return SCM_BOOL_F;
|
|
||||||
if(!gh_list_p(list_items))
|
|
||||||
return SCM_BOOL_F;
|
|
||||||
|
|
||||||
num_items = gh_length(list_items);
|
|
||||||
|
|
||||||
cb_data = g_new(ChooseItemCBData, num_items);
|
|
||||||
|
|
||||||
/* Convert the scm data to C callback structs */
|
|
||||||
i = 0;
|
|
||||||
status_ok = TRUE;
|
|
||||||
listcursor = list_items;
|
|
||||||
while(status_ok && !gh_null_p(listcursor)) {
|
|
||||||
SCM scm_item = gh_car(listcursor);
|
|
||||||
|
|
||||||
if(!gh_pair_p(scm_item)) {
|
|
||||||
fprintf(stderr, "Dying: not a pair.\n");
|
|
||||||
status_ok = FALSE;
|
|
||||||
} else {
|
|
||||||
SCM item_scm_name = gh_car(scm_item);
|
|
||||||
SCM item_scm_thunk = gh_cdr(scm_item);
|
|
||||||
|
|
||||||
if(!(gh_string_p(item_scm_name) && gh_procedure_p(item_scm_thunk))) {
|
|
||||||
fprintf(stderr, "Dying: bad pair item(s).\n");
|
|
||||||
status_ok = FALSE;
|
|
||||||
} else {
|
|
||||||
cb_data[i].name = gh_scm2newstr(item_scm_name, NULL);
|
|
||||||
cb_data[i].closure = item_scm_thunk;
|
|
||||||
cb_data[i].dialog_result = &dialog_result;
|
|
||||||
cb_data[i].scm_result = &scm_result;
|
|
||||||
|
|
||||||
if(!cb_data[i].name) {
|
|
||||||
fprintf(stderr, "Dying: no C name.\n");
|
|
||||||
status_ok = FALSE;
|
|
||||||
} else {
|
|
||||||
listcursor = gh_cdr(listcursor);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!status_ok) {
|
|
||||||
fprintf(stderr, "Dying after copy.\n");
|
|
||||||
g_free(cb_data);
|
|
||||||
return SCM_BOOL_F;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Build the list */
|
|
||||||
vbox = gtk_vbox_new(TRUE, 0);
|
|
||||||
|
|
||||||
for(i = 0; i < num_items; i++) {
|
|
||||||
GtkWidget *b = gtk_button_new_with_label(cb_data[i].name);
|
|
||||||
if(b == NULL) {
|
|
||||||
status_ok = FALSE;
|
|
||||||
} else {
|
|
||||||
gtk_signal_connect(GTK_OBJECT(b), "clicked",
|
|
||||||
GTK_SIGNAL_FUNC(gnc_choose_item_cb),
|
|
||||||
(gpointer) &(cb_data[i]));
|
|
||||||
gtk_box_pack_start(GTK_BOX(vbox), b, TRUE, TRUE, 0);
|
|
||||||
gtk_widget_show(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!status_ok) {
|
|
||||||
fprintf(stderr, "Dying after buttons.\n");
|
|
||||||
gtk_widget_unref(vbox);
|
|
||||||
g_free(cb_data);
|
|
||||||
return SCM_BOOL_F;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_show(vbox);
|
|
||||||
|
|
||||||
query_box = gnc_foundation_query_dialog(NULL,
|
|
||||||
title,
|
|
||||||
vbox,
|
|
||||||
GNC_QUERY_CANCEL, /* cancel */
|
|
||||||
FALSE, /* yes_allowed */
|
|
||||||
FALSE, /* ok_allowed */
|
|
||||||
FALSE, /* no_allowed */
|
|
||||||
TRUE, /* cancel_allowed */
|
|
||||||
&dialog_result);
|
|
||||||
|
|
||||||
if(query_box == NULL) {
|
|
||||||
g_free(cb_data);
|
|
||||||
return SCM_BOOL_F;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < num_items; i++)
|
|
||||||
cb_data[i].dialog = GNOME_DIALOG(query_box);
|
|
||||||
|
|
||||||
gnome_dialog_run_and_close(GNOME_DIALOG(query_box));
|
|
||||||
|
|
||||||
switch(dialog_result) {
|
|
||||||
case 1:
|
|
||||||
result = gh_cons(gh_symbol2scm("result"), scm_result);
|
|
||||||
break;
|
|
||||||
case GNC_QUERY_YES:
|
|
||||||
case GNC_QUERY_NO:
|
|
||||||
result = SCM_BOOL_F;
|
|
||||||
break;
|
|
||||||
case GNC_QUERY_CANCEL:
|
|
||||||
result = gh_symbol2scm("cancel");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
result = SCM_BOOL_F;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(cb_data);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gnc_choose_radio_button_cb(GtkWidget *w, gpointer data)
|
gnc_choose_radio_button_cb(GtkWidget *w, gpointer data)
|
||||||
@ -671,14 +319,14 @@ gnc_choose_radio_option_dialog_parented(gncUIWidget parent,
|
|||||||
int default_value,
|
int default_value,
|
||||||
char **radio_list)
|
char **radio_list)
|
||||||
{
|
{
|
||||||
int dialog_result;
|
|
||||||
int radio_result = 0; /* initial selected value is first one */
|
int radio_result = 0; /* initial selected value is first one */
|
||||||
GtkWidget *vbox;
|
GtkWidget *vbox;
|
||||||
GtkWidget *main_vbox;
|
GtkWidget *main_vbox;
|
||||||
GtkWidget *query_box;
|
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *frame;
|
GtkWidget *frame;
|
||||||
GtkWidget *radio_button;
|
GtkWidget *radio_button;
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GtkWidget *dvbox;
|
||||||
GSList *group = NULL;
|
GSList *group = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -720,17 +368,22 @@ gnc_choose_radio_option_dialog_parented(gncUIWidget parent,
|
|||||||
&radio_result);
|
&radio_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
query_box = gnc_foundation_query_dialog(parent,
|
dialog = gnome_dialog_new(title,
|
||||||
title,
|
GNOME_STOCK_BUTTON_OK,
|
||||||
main_vbox,
|
NULL);
|
||||||
GNC_QUERY_YES, /* ok */
|
|
||||||
FALSE, /* yes_allowed */
|
|
||||||
TRUE, /* ok_allowed */
|
|
||||||
FALSE, /* no_allowed */
|
|
||||||
FALSE, /* cancel_allowed */
|
|
||||||
&dialog_result);
|
|
||||||
|
|
||||||
gnome_dialog_run_and_close(GNOME_DIALOG(query_box));
|
/* default to ok */
|
||||||
|
gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
|
||||||
|
|
||||||
|
/* destroy, don't hide */
|
||||||
|
gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE);
|
||||||
|
|
||||||
|
dvbox = GNOME_DIALOG(dialog)->vbox;
|
||||||
|
|
||||||
|
gtk_box_pack_start(GTK_BOX(dvbox), main_vbox, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
if (gnome_dialog_run_and_close(GNOME_DIALOG(dialog)) != 0)
|
||||||
|
radio_result = -1;
|
||||||
|
|
||||||
return radio_result;
|
return radio_result;
|
||||||
}
|
}
|
||||||
|
@ -23,16 +23,6 @@
|
|||||||
#ifndef __QUERY_USER_H__
|
#ifndef __QUERY_USER_H__
|
||||||
#define __QUERY_USER_H__
|
#define __QUERY_USER_H__
|
||||||
|
|
||||||
#include <guile/gh.h>
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
GNC_QUERY_YES = -1,
|
|
||||||
GNC_QUERY_NO = -2,
|
|
||||||
GNC_QUERY_CANCEL = -3
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
gboolean gnc_verify_dialog_parented(GtkWindow *parent, const char *message,
|
gboolean gnc_verify_dialog_parented(GtkWindow *parent, const char *message,
|
||||||
gboolean yes_is_default);
|
gboolean yes_is_default);
|
||||||
|
|
||||||
@ -43,6 +33,4 @@ void gnc_warning_dialog(const char *message);
|
|||||||
|
|
||||||
void gnc_error_dialog_parented(GtkWindow *parent, const char *message);
|
void gnc_error_dialog_parented(GtkWindow *parent, const char *message);
|
||||||
|
|
||||||
SCM gnc_choose_item_from_list_dialog(const char *title, SCM list_items);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user