1 /*----------------------------------------------------------------------------
2 --
3 --  Module:           xitErrDia
4 --
5 --  Project:          xit  - X Internal Toolkit
6 --  System:           xit  - X Internal Toolkit
7 --    Subsystem:      <>
8 --    Function block: <>
9 --
10 --  Description:
11 --    Manages an error dialog where Enter and Return are used as
12 --    activate keys.
13 --
14 --  Filename:         xitErrDia.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: xitErrDia.c, Version: 1.1, Date: 95/02/18 15:10:28";
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
xitCreateErrorDialog(Widget parent,char * dialog_name,char * title,char * message,void (* okCB)(),void * ok_client_data)78   xitCreateErrorDialog( Widget  parent,
79                         char   *dialog_name,
80                         char   *title,
81                         char   *message,
82                         void   (*okCB) (),
83                         void   *ok_client_data )
84 {
85 
86   /* Variables. */
87   Arg       args[ 5 ];
88   Cardinal  n;
89   Widget    button;
90   Widget    w;
91   XmString  xstr;
92 
93 
94   /* Code. */
95 
96   n = 0;
97   XtSetArg( args[ n ], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL ); n++;
98   XtSetArg( args[ n ], XmNnoResize, True ); n++;
99   XtSetArg( args[ n ], XmNautoUnmanage, False ); n++;
100 
101   w = XmCreateErrorDialog( parent, dialog_name, args, n );
102 
103   if( strlen( message ) > 0 ) {
104     xstr = XmStringCreateLtoR( message, CS );
105 
106     n = 0;
107     XtSetArg( args[ n ], XmNmessageString, xstr ); n++;
108     XtSetValues( w, args, n );
109     XmStringFree( xstr );
110   }
111 
112   if( strlen( title ) > 0 ) {
113     xstr = XmStringCreateLtoR( title, CS );
114 
115     n = 0;
116     XtSetArg( args[ n ], XmNdialogTitle, xstr ); n++;
117     XtSetValues( w, args, n );
118     XmStringFree( xstr );
119   }
120 
121   /* Unmanage the cancel and help buttons. */
122   button = XmMessageBoxGetChild( w, XmDIALOG_CANCEL_BUTTON );
123   XtUnmanageChild( button );
124 
125   button = XmMessageBoxGetChild( w, XmDIALOG_HELP_BUTTON );
126   XtUnmanageChild( button );
127 
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   XtManageChild( w );
139 
140   return( w );
141 
142 } /* xitCreateErrorDialog */
143 
144 
145 /*----------------------------------------------------------------------*/
146 
147 static void
removeCB(Widget widget,Widget toplevel_widget,XmAnyCallbackStruct * call_data)148   removeCB( Widget               widget,
149             Widget               toplevel_widget,
150             XmAnyCallbackStruct  *call_data )
151 {
152 
153   /* Code. */
154 
155   XtDestroyWidget( toplevel_widget );
156 
157 
158   return;
159 
160 } /* removeCB */
161