X-Git-Url: https://git.distorted.org.uk/~mdw/mgLib/blobdiff_plain/e962a3e27e7c974790296a8651de442bd6634a88..HEAD:/msg.c diff --git a/msg.c b/msg.c index eb386e1..2623225 100644 --- a/msg.c +++ b/msg.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: msg.c,v 1.6 1999/05/06 19:51:48 mdw Exp $ + * $Id$ * * Display a message and get an answer * @@ -27,32 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: msg.c,v $ - * Revision 1.6 1999/05/06 19:51:48 mdw - * Reformatted the LGPL notice a little bit. - * - * Revision 1.5 1999/05/05 18:52:45 mdw - * Change licensing conditions to LGPL. - * - * Revision 1.4 1999/04/29 20:48:13 mdw - * Add documentation for `msg'. - * - * Revision 1.3 1999/03/25 23:36:10 mdw - * Compile to nothing in absence of GTK, for the benefit of parent packages - * which contain non-GTK-dependent parts. - * - * Revision 1.2 1998/12/15 23:48:06 mdw - * Use `dstr_putf' for formatting, rather than `sprintf'. - * - * Revision 1.1 1998/12/11 09:44:21 mdw - * Initial version. - * - */ - -#ifdef HAVE_GTK - /*----- Header files ------------------------------------------------------*/ #include @@ -78,8 +52,9 @@ static int creply; /* --- @msg@ --- * * - * Arguments: @char *buttons@ = the button strings to display - * @char *msg@ = the message skeleton string + * Arguments: @const char *title@ = the title for the message box + * @const char *buttons@ = the button strings to display + * @const char *msg@ = the message skeleton string * * Returns: Index of the button selected. * @@ -108,13 +83,14 @@ static void click(GtkWidget *w, gpointer p) gtk_main_quit(); } -int msg(const char *buttons, const char *msg, ...) +int msg(const char *title, const char *buttons, const char *msg, ...) { GtkWidget *dbox, *w; /* --- Make most of the dialogue box --- */ dbox = gtk_dialog_new(); + gtk_window_set_title(GTK_WINDOW(dbox), title); gtk_signal_connect(GTK_OBJECT(dbox), "delete_event", GTK_SIGNAL_FUNC(close), 0); gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(dbox)->action_area), 0); @@ -122,14 +98,14 @@ int msg(const char *buttons, const char *msg, ...) /* --- Set up the message string --- */ { - dstr d; + dstr d = DSTR_INIT; va_list ap; va_start(ap, msg); - dstr_create(&d); - dstr_vputf(&d, msg, ap); + dstr_vputf(&d, msg, &ap); va_end(ap); w = gtk_label_new(d.buf); + gtk_label_set_justify(GTK_LABEL(w), GTK_JUSTIFY_LEFT); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dbox)->vbox), w, 1, 1, 0); gtk_window_position(GTK_WINDOW(dbox), GTK_WIN_POS_MOUSE); gtk_widget_show(w); @@ -144,11 +120,9 @@ int msg(const char *buttons, const char *msg, ...) unsigned f = 0; int i = 0; - enum { - f_ok = 1, - f_cancel = 2, - f_mdwfocus = 4 - }; +#define f_ok 1u +#define f_cancel 2u +#define f_mdwfocus 4u if (*p == '!') { f |= f_mdwfocus; @@ -179,7 +153,7 @@ int msg(const char *buttons, const char *msg, ...) cancel(GTK_WINDOW(dbox), w); gtk_widget_show(w); } - free(p); + xfree(p); /* --- Preflight checklist --- */ @@ -187,6 +161,9 @@ int msg(const char *buttons, const char *msg, ...) if (f & f_mdwfocus) mdwfocus(dbox); +#undef f_ok +#undef f_cancel +#undef f_mdwfocus } /* --- Ready --- */ @@ -200,7 +177,3 @@ int msg(const char *buttons, const char *msg, ...) } /*----- That's all, folks -------------------------------------------------*/ - -#else - int mgLib_msg = 0; -#endif