1 /*----------------------------------------------------------------------------
2 --
3 --  Module:           xitQuestDia
4 --
5 --  Project:          xit  - X Internal Toolkit
6 --  System:           xit  - X Internal Toolkit
7 --    Subsystem:      <>
8 --    Function block: <>
9 --
10 --  Description:
11 --    Manages an question dialog where Enter and Return are used as
12 --    activate keys.
13 --
14 --  Filename:         xitQuestDia.c
15 --
16 --  Authors:          Roger Larsson, Ulrika Bornetun
17 --  Creation date:    1991-10-20
18 --
19 --
20 --  (C) Copyright Ulrika Bornetun, Roger Larsson (1995)
21 --      All rights reserved
22 --
23 --  Permission to use, copy, modify, and distribute this software and its
24 --  documentation for any purpose and without fee is hereby granted,
25 --  provided that the above copyright notice appear in all copies. Ulrika
26 --  Bornetun and Roger Larsson make no representations about the usability
27 --  of this software for any purpose. It is provided "as is" without express
28 --  or implied warranty.
29 ----------------------------------------------------------------------------*/
30 
31 /* SCCS module identifier. */
32 static char SCCSID[] = "@(#) Module: xitQuestDia.c, Version: 1.1, Date: 95/02/18 15:10:45";
33 
34 
35 /*----------------------------------------------------------------------------
36 --  Include files
37 ----------------------------------------------------------------------------*/
38 
39 #include <X11/Intrinsic.h>
40 #include <X11/Shell.h>
41 
42 #include <Xm/Xm.h>
43 #include <Xm/MessageB.h>
44 
45 #include "xitTools.h"
46 
47 
48 /*----------------------------------------------------------------------------
49 --  Macro definitions
50 ----------------------------------------------------------------------------*/
51 
52 
53 /*----------------------------------------------------------------------------
54 --  Type declarations
55 ----------------------------------------------------------------------------*/
56 
57 
58 /*----------------------------------------------------------------------------
59 --  Global definitions
60 ----------------------------------------------------------------------------*/
61 
62 
63 /*----------------------------------------------------------------------------
64 --  Function prototypes
65 ----------------------------------------------------------------------------*/
66 
67 static void
68   removeCB( Widget               widget,
69             Widget               toplevel_widget,
70             XmAnyCallbackStruct  *call_data );
71 
72 
73 /*----------------------------------------------------------------------------
74 --  Functions
75 ----------------------------------------------------------------------------*/
76 
77 Widget
xitCreateQuestionDialog(Widget parent,char * dialog_name,char * title,char * message,void (* okCB)(),void * ok_client_data,void (* cancelCB)(),void * cancel_client_data)78   xitCreateQuestionDialog( Widget parent,
79                            char   *dialog_name,
80                            char   *title,
81                            char   *message,
82                            void   (*okCB) (),
83                            void   *ok_client_data,
84                            void   (*cancelCB) (),
85                            void   *cancel_client_data )
86 {
87 
88   /* Variables. */
89   Arg        args[ 5 ];
90   Cardinal   n;
91   Widget     button;
92   Widget     w;
93   XmString   xstr;
94 
95 
96   /* Code. */
97 
98   n = 0;
99   XtSetArg( args[ n ], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL ); n++;
100   XtSetArg( args[ n ], XmNautoUnmanage, False ); n++;
101   XtSetArg( args[ n ], XmNnoResize, True ); n++;
102 
103   w = XmCreateQuestionDialog( parent, dialog_name, args, n );
104 
105   if( strlen( message ) > 0 ) {
106     xstr = XmStringCreateLtoR( message, CS );
107 
108     n = 0;
109     XtSetArg( args[ n ], XmNmessageString, xstr ); n++;
110     XtSetValues( w, args, n );
111     XmStringFree( xstr );
112   }
113 
114   if( strlen( title ) > 0 ) {
115     xstr = XmStringCreateLtoR( title, CS );
116 
117     n = 0;
118     XtSetArg( args[ n ], XmNdialogTitle, xstr ); n++;
119     XtSetValues( w, args, n );
120     XmStringFree( xstr );
121   }
122 
123   /* Unmanage the help button. */
124   button = XmMessageBoxGetChild( w, XmDIALOG_HELP_BUTTON );
125   XtUnmanageChild( button );
126 
127   /* Add callbacks. */
128   if( okCB != NULL ) {
129     XtAddCallback( w, XmNokCallback,
130                    (XtCallbackProc) okCB, (XtPointer) ok_client_data );
131     XtAddCallback( w, XmNokCallback,
132                    (XtCallbackProc) removeCB, (XtPointer) w );
133   } else {
134     XtAddCallback( w, XmNokCallback,
135                    (XtCallbackProc) removeCB, (XtPointer) w );
136   }
137 
138   if( cancelCB != NULL ) {
139     XtAddCallback( w, XmNcancelCallback,
140                    (XtCallbackProc) cancelCB, (XtPointer) cancel_client_data );
141     XtAddCallback( w, XmNcancelCallback,
142                    (XtCallbackProc) removeCB, (XtPointer) w );
143   } else {
144     XtAddCallback( w, XmNcancelCallback,
145                    (XtCallbackProc) removeCB, (XtPointer) w );
146   }
147 
148   XtManageChild( w );
149 
150   return( w );
151 
152 } /* xitCreateQuestionDialog */
153 
154 
155 /*----------------------------------------------------------------------*/
156 
157 static void
removeCB(Widget widget,Widget toplevel_widget,XmAnyCallbackStruct * call_data)158   removeCB( Widget               widget,
159             Widget               toplevel_widget,
160             XmAnyCallbackStruct  *call_data )
161 {
162 
163   /* Code. */
164 
165   XtDestroyWidget( toplevel_widget );
166 
167   return;
168 
169 } /* removeCB */
170