1 #ifndef lint
2 static char rcsid[] = "modal.c,v 2.0 1994/05/19 02:01:20 dan Exp";
3 #endif
4 
5 /*
6  * Copyright (c) 1994    Daniel Williams
7  *
8  * The X Consortium, and any party obtaining a copy of these files from
9  * the X Consortium, directly or indirectly, is granted, free of charge,
10  * a full and unrestricted irrevocable, world-wide, paid up,
11  * royalty-free, nonexclusive right and license to deal in this software
12  * and documentation files (the "Software"), including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute,
14  * sublicense, and/or sell copies of the Software, and to permit persons
15  * who receive copies from any such party to do so.  This license
16  * includes without limitation a license to do the foregoing actions
17  * under any patents of the party supplying this software to the X
18  * Consortium.  The following conditions apply:
19  *
20  * The above copyright notice and this permission notice shall be
21  * included in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26  * IN NO EVENT SHALL DANIEL WILLIAMS OR SYSTEMS & SCIENTIFIC SOFTWARE BE
27  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30  */
31 
32 /*
33  * this module is derived from code in "Motif Programming Manual"
34  * which bears the following notice:
35  *
36  * Written by Dan Heller.  Copyright 1991, O'Reilly & Associates.
37  * This program is freely distributable without licensing fees and
38  * is provided without guarantee or warrantee expressed or implied.
39  * This program is -not- in the public domain.
40  */
41 
42 #include <stdio.h>
43 #include <Xm/MessageB.h>
44 #include "mgdiff.h"
45 #include "externs.h"
46 
47 static void ok_cb (Widget w, XtPointer closure, XtPointer call_data);
48 static void cancel_cb (Widget w, XtPointer closure, XtPointer call_data);
49 
50 typedef enum {
51     Busy, Ok, Cancel
52 } State;
53 
54 /* ARGSUSED */
ok_cb(Widget w,XtPointer closure,XtPointer call_data)55 static void ok_cb (Widget w, XtPointer closure, XtPointer call_data)
56 {
57     *((State *) closure) = Ok;
58     XtDestroyWidget (get_top_shell (w));
59 }
60 
61 /* ARGSUSED */
cancel_cb(Widget w,XtPointer closure,XtPointer call_data)62 static void cancel_cb (Widget w, XtPointer closure, XtPointer call_data)
63 {
64     *((State *) closure) = Cancel;
65     XtDestroyWidget (get_top_shell (w));
66 }
67 
68 /*
69  * pop up a modal QuestionDialog and return True for user's choice of
70  * "OK" and False for "Cancel"
71  */
modal_question(Widget parent,char * title,char * question)72 int modal_question (Widget parent, char *title, char *question)
73 {
74     static Arg args[] = {{XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL}};
75     XtAppContext app = XtWidgetToApplicationContext (parent);
76     State answer = Busy;
77     Widget dialog;
78 
79     dialog = XmCreateQuestionDialog (parent, "question", args, XtNumber (args));
80     XtAddCallback (dialog, XmNokCallback, ok_cb, &answer);
81     XtAddCallback (dialog, XmNcancelCallback, cancel_cb, &answer);
82     XtVaSetValues (dialog,
83 		   XtVaTypedArg, XmNmessageString, XmRString, question, strlen (question)+1,
84 		   XtVaTypedArg, XmNdialogTitle, XmRString, title, strlen (title)+1,
85 		   NULL);
86 
87     XtSetSensitive (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON), False);
88     XtManageChild (dialog);
89 
90     while ((answer == Busy) || XtAppPending (app))
91 	XtAppProcessEvent (app, XtIMAll);
92     return (answer == Ok);
93 }
94