X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mgLib/blobdiff_plain/8e77431249a6351d09ad472dfdbd9fe33b4e1d1b..d1495df30e8ff73a7e5c35d0a049afa9e996d766:/msg.c diff --git a/msg.c b/msg.c index ff317e9..ccd59ae 100644 --- a/msg.c +++ b/msg.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: msg.c,v 1.3 1999/03/25 23:36:10 mdw Exp $ + * $Id: msg.c,v 1.9 2002/01/13 14:32:22 mdw Exp $ * * Display a message and get an answer * @@ -12,23 +12,42 @@ * This file is part of the mgLib GTK utilities library. * * mgLib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. * * mgLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU Library General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with mgLib; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Library General Public + * License along with mgLib; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. */ /*----- Revision history --------------------------------------------------* * * $Log: msg.c,v $ + * Revision 1.9 2002/01/13 14:32:22 mdw + * Allow control over the message box title. + * + * Revision 1.8 1999/11/11 19:54:37 mdw + * Prep for standalone release. + * + * Revision 1.7 1999/05/21 22:08:20 mdw + * Take advantage of new dynamic string macros. + * + * 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. @@ -41,8 +60,6 @@ * */ -#ifdef HAVE_GTK - /*----- Header files ------------------------------------------------------*/ #include @@ -68,13 +85,22 @@ 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. * * Use: Displays a message to the user in a nice dialogue box and * returns the index of the button selected. + * + * The @msg@ argument is a @printf@-style format string, which + * contains the message to actually be shown. The @buttons@ + * argument is a comma-separated list of buttons to be drawn, + * from right to left. A button name can be preceded with `:' + * to indicate that it's the default, or `~' if it's the + * `cancel' button. The return value is the zero-based index + * of the button selected. */ static int close(GtkWidget *w, gpointer p) @@ -90,13 +116,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); @@ -104,11 +131,10 @@ 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); va_end(ap); w = gtk_label_new(d.buf); @@ -126,11 +152,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; @@ -169,6 +193,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 --- */ @@ -182,7 +209,3 @@ int msg(const char *buttons, const char *msg, ...) } /*----- That's all, folks -------------------------------------------------*/ - -#else - int mgLib_msg = 0; -#endif