[gq-commit] gq/src util.c,1.65,1.66
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-09 05:39:02
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv8333 Modified Files: util.c Log Message: * Got rid of the nasty communication widget used for popup dialogs. I must have been completly mad when I wrote this code initially. Am I glad this is gone! Index: util.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/util.c,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** util.c 9 Oct 2003 05:26:20 -0000 1.65 --- util.c 9 Oct 2003 05:38:58 -0000 1.66 *************** *** 1251,1272 **** } /* gtk2 checked (multiple destroy callbacks safety), confidence 0.7 */ ! static void query_destroy(GtkWidget *button, GtkWidget *comm) { assert(comm); if (!comm) return; ! if (! gtk_object_get_data(GTK_OBJECT(comm), "ended")) gtk_main_quit(); /* quits only nested main loop */ ! ! gtk_object_set_data(GTK_OBJECT(comm), "destroyed", "1"); } ! static void query_ok(GtkWidget *button, GtkObject *comm) { gtk_main_quit(); ! gtk_object_set_data(GTK_OBJECT(comm), "rc", "1"); } ! static void query_cancel(GtkWidget *button, GtkObject *comm) { gtk_main_quit(); ! gtk_object_set_data(GTK_OBJECT(comm), "rc", (void*) NULL); } --- 1251,1290 ---- } + struct popup_comm { + int destroyed; + int ended; + int rc; + }; + + static struct popup_comm *new_popup_comm() + { + struct popup_comm *n = g_malloc0(sizeof(struct popup_comm)); + n->ended = n->destroyed = n->rc = 0; + return n; + } + + static void free_popup_comm(struct popup_comm *c) + { + assert(c); + g_free(c); + } + /* gtk2 checked (multiple destroy callbacks safety), confidence 0.7 */ ! static void query_destroy(GtkWidget *window, struct popup_comm *comm) { assert(comm); if (!comm) return; ! if (!comm->ended) gtk_main_quit(); /* quits only nested main loop */ ! comm->destroyed = 1; } ! static void query_ok(GtkWidget *button, struct popup_comm *comm) { gtk_main_quit(); ! comm->rc = 1; } ! static void query_cancel(GtkWidget *button, struct popup_comm *comm) { gtk_main_quit(); ! comm->rc = 0; } *************** *** 1279,1284 **** int rc; GtkWidget *f = gtk_grab_get_current(); ! GtkWidget *comm; /* communication widget, not shown but used to ! associate data with */ /* This is a BAD hack - it solves a problem with the query popup --- 1297,1301 ---- int rc; GtkWidget *f = gtk_grab_get_current(); ! struct popup_comm *comm = new_popup_comm(); /* This is a BAD hack - it solves a problem with the query popup *************** *** 1293,1298 **** } - comm = gtk_entry_new(); - window = gtk_dialog_new(); gtk_container_border_width(GTK_CONTAINER(window), CONTAINER_BORDER_WIDTH); --- 1310,1313 ---- *************** *** 1323,1327 **** gtk_widget_show(inputbox); gtk_signal_connect(GTK_OBJECT(inputbox), "activate", ! GTK_SIGNAL_FUNC(query_ok), GTK_OBJECT(comm)); gtk_box_pack_end(GTK_BOX(vbox1), inputbox, TRUE, TRUE, 5); --- 1338,1342 ---- gtk_widget_show(inputbox); gtk_signal_connect(GTK_OBJECT(inputbox), "activate", ! GTK_SIGNAL_FUNC(query_ok), comm); gtk_box_pack_end(GTK_BOX(vbox1), inputbox, TRUE, TRUE, 5); *************** *** 1341,1345 **** gtk_signal_connect(GTK_OBJECT(button), "clicked", ! GTK_SIGNAL_FUNC(query_ok), GTK_OBJECT(comm)); gtk_box_pack_start(GTK_BOX(hbox0), button, FALSE, FALSE, 0); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); --- 1356,1360 ---- gtk_signal_connect(GTK_OBJECT(button), "clicked", ! GTK_SIGNAL_FUNC(query_ok), comm); gtk_box_pack_start(GTK_BOX(hbox0), button, FALSE, FALSE, 0); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); *************** *** 1356,1360 **** gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(query_cancel), ! GTK_OBJECT(comm)); gtk_box_pack_end(GTK_BOX(hbox0), button, FALSE, FALSE, 0); --- 1371,1375 ---- gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(query_cancel), ! comm); gtk_box_pack_end(GTK_BOX(hbox0), button, FALSE, FALSE, 0); *************** *** 1370,1388 **** gtk_main(); ! gtk_object_set_data(GTK_OBJECT(comm), "ended", "1"); ! ! rc = gtk_object_get_data(GTK_OBJECT(comm), "rc") != NULL; ! if (! gtk_object_get_data(GTK_OBJECT(comm), "destroyed") && rc) { *outbuf = gtk_editable_get_chars(GTK_EDITABLE(inputbox), 0, -1); } else { - rc = 0; *outbuf = NULL; } ! if (! gtk_object_get_data(GTK_OBJECT(comm), "destroyed")) { gtk_widget_destroy(window); } ! gtk_widget_unref(comm); return rc; --- 1385,1402 ---- gtk_main(); ! comm->ended = 1; ! if (! comm->destroyed && comm->rc) { *outbuf = gtk_editable_get_chars(GTK_EDITABLE(inputbox), 0, -1); } else { *outbuf = NULL; } ! if (! comm->destroyed ) { gtk_widget_destroy(window); } ! ! rc = comm->rc; ! free_popup_comm(comm); return rc; *************** *** 1400,1405 **** GdkBitmap *warning_mask; GtkWidget *f = gtk_grab_get_current(); ! GtkWidget *comm; /* communication widget, not shown but used to ! associate data with */ /* This is a BAD hack - it solves a problem with the query popup --- 1414,1418 ---- GdkBitmap *warning_mask; GtkWidget *f = gtk_grab_get_current(); ! struct popup_comm *comm = new_popup_comm(); /* This is a BAD hack - it solves a problem with the query popup *************** *** 1414,1419 **** } - comm = gtk_entry_new(); - window = gtk_dialog_new(); gtk_container_border_width(GTK_CONTAINER(window), CONTAINER_BORDER_WIDTH); --- 1427,1430 ---- *************** *** 1458,1462 **** button = gq_button_new_with_label(_("_Yes")); gtk_signal_connect(GTK_OBJECT(button), "clicked", ! GTK_SIGNAL_FUNC(query_ok), GTK_OBJECT(comm)); gtk_box_pack_start(GTK_BOX(hbox0), button, FALSE, FALSE, 0); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); --- 1469,1473 ---- button = gq_button_new_with_label(_("_Yes")); gtk_signal_connect(GTK_OBJECT(button), "clicked", ! GTK_SIGNAL_FUNC(query_ok), comm); gtk_box_pack_start(GTK_BOX(hbox0), button, FALSE, FALSE, 0); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); *************** *** 1468,1472 **** gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(query_cancel), ! GTK_OBJECT(comm)); gtk_box_pack_end(GTK_BOX(hbox0), button, FALSE, FALSE, 0); --- 1479,1483 ---- gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(query_cancel), ! comm); gtk_box_pack_end(GTK_BOX(hbox0), button, FALSE, FALSE, 0); *************** *** 1481,1499 **** gtk_main(); ! gtk_object_set_data(GTK_OBJECT(comm), "ended", "1"); ! ! rc = gtk_object_get_data(GTK_OBJECT(comm), "rc") != NULL; ! ! /* if (! gtk_object_get_data(GTK_OBJECT(comm), "destroyed") && rc) { */ ! /* *outbuf = gtk_editable_get_chars(GTK_EDITABLE(inputbox), 0, -1); */ ! /* } else { */ ! /* rc = 0; */ ! /* *outbuf = NULL; */ ! /* } */ ! if (! gtk_object_get_data(GTK_OBJECT(comm), "destroyed")) { gtk_widget_destroy(window); } ! gtk_widget_unref(comm); return rc; --- 1492,1503 ---- gtk_main(); ! comm->ended = 1; ! if (! comm->destroyed) { gtk_widget_destroy(window); } ! ! rc = comm->rc; ! free_popup_comm(comm); return rc; |