1 /* $XConsortium: SharedProcs.c /main/7 1996/08/28 17:19:21 drk $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
4 * (c) Copyright 1993, 1994 International Business Machines Corp. *
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
6 * (c) Copyright 1993, 1994 Novell, Inc. *
8 /*************************************<+>*************************************
9 *****************************************************************************
11 ** File: SharedProcs.c
15 ** Description: Contains the set of functions which are of general
16 ** use to all DT clients.
19 ****************************************************************************
20 ************************************<+>*************************************/
22 #include <sys/types.h>
32 #include <Xm/VendorSEP.h>
33 #include <Xm/MessageB.h>
34 #include <Xm/RowColumn.h>
35 #include <Xm/MwmUtil.h>
36 #include <Xm/Protocols.h>
37 #include <X11/ShellP.h>
38 #include <X11/Shell.h>
39 #include <X11/Xatom.h>
43 #include <Dt/Connect.h>
44 #include <Dt/DtNlUtils.h>
46 #include "SharedProcs.h"
50 #define RW_ALL S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
53 /******** Static Function Declarations ********/
56 /******** End Static Function Declarations ********/
59 /************************************************************************
63 * Strip all leading and trailing spaces.
65 ************************************************************************/
79 /* Strip off leading spaces first */
83 (!is_multibyte || (mblen(string + i, MB_CUR_MAX) == 1)) &&
85 isspace((u_char)string[i]))
90 /* Copy over the leading spaces */
91 strcpy(string, string + i);
93 /* Drop out, if the string is now empty */
94 if ((i = strlen(string) - 1) < 0)
97 /* Strip off trailing spaces */
102 /* No multibyte; simply work back through the string */
103 while ((i >= 0) && (isspace((u_char)string[i])))
105 string[i + 1] = '\0';
110 /* Work forward, looking for a trailing space of spaces */
118 if (((len = mblen(string + i, MB_CUR_MAX)) == 1) && isspace((u_char)string[i]))
127 /* if there is an invalid character, treat as a valid one-byte */
143 /************************************************************************
146 * Create and display an error message.
148 ************************************************************************/
156 void (*helpCallback)() )
159 _DtMessageDialog(w, title, message_text, helpIdStr, False,
160 NULL, _DtMessageOK, _DtMessageClose, helpCallback, True,
165 /************************************************************************
167 * Generic warning/error dialog creation function.
169 ************************************************************************/
178 void (*cancel_callback)(),
179 void (*ok_callback)(),
180 void (*close_callback)(),
181 void (*help_callback)(),
182 Boolean deleteOnClose,
188 XmString message_string;
189 XWindowAttributes attributes;
191 XmString okString, cancelString, helpString;
193 okString = XmStringCreateLocalized((Dt11GETMESSAGE(28,1, "OK")));
194 cancelString = XmStringCreateLocalized((Dt11GETMESSAGE(28,2, "Cancel")));
195 helpString = XmStringCreateLocalized((Dt11GETMESSAGE(28,3, "Help")));
197 XtSetArg (args[0], XmNautoUnmanage, False);
198 XtSetArg (args[1], XmNcancelLabelString, cancelString);
199 XtSetArg (args[2], XmNokLabelString, okString);
200 XtSetArg (args[3], XmNhelpLabelString, helpString);
201 XtSetArg (args[4], XmNuseAsyncGeometry, True);
203 /* Search up to get the topmost shell */
205 while (XtParent (w) != NULL && !(XtIsSubclass (w, shellWidgetClass)))
211 message = XmCreateErrorDialog(w, title, args, 5);
215 message = XmCreateWarningDialog(w, title, args, 5);
218 case QUESTION_DIALOG:
219 message = XmCreateQuestionDialog(w, title, args, 5);
222 if (XtWindow (w) != 0)
223 XGetWindowAttributes(XtDisplay (w), XtWindow (w), &attributes);
225 attributes.map_state = IsUnmapped;
227 if (attributes.map_state == IsUnmapped)
229 XtSetArg(args[0], XmNx, (WidthOfScreen(XtScreen (w)) - 350) / 2);
230 XtSetArg(args[1], XmNy, (HeightOfScreen(XtScreen (w)) - 200) / 2);
231 XtSetArg(args[2], XmNdefaultPosition, False);
232 XtSetValues(message, args, 3);
236 /* Adjust the decorations and title for the dialog shell of the dialog */
238 XtSetArg(args[0], XmNtitle, title);
239 XtSetArg(args[1], XmNmwmFunctions, MWM_FUNC_MOVE);
240 XtSetArg(args[2], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE);
241 XtSetValues(XtParent (message), args, 3);
243 widget = XmMessageBoxGetChild(message, XmDIALOG_CANCEL_BUTTON);
245 XtUnmanageChild(widget);
246 else if (cancel_callback)
248 XtAddCallback(widget, XmNactivateCallback, cancel_callback,
250 XtSetArg(args[0], XmNcancelButton, widget);
251 XtSetValues(message, args, 1);
254 widget = XmMessageBoxGetChild(message, XmDIALOG_OK_BUTTON);
255 XtSetArg(args[0], XmNmarginWidth, 10);
256 XtSetArg(args[1], XmNmarginHeight, 2);
257 XtSetValues(widget, args, 2);
258 XtAddCallback(widget, XmNactivateCallback, ok_callback, (caddr_t) message);
260 widget = XmMessageBoxGetChild(message, XmDIALOG_HELP_BUTTON);
261 if (helpIdStr != NULL)
265 XtAddCallback(widget, XmNactivateCallback, help_callback,
266 (caddr_t) helpIdStr);
268 XtSetValues(widget, args, 2);
271 XtUnmanageChild(widget);
273 widget = XmMessageBoxGetChild(message, XmDIALOG_MESSAGE_LABEL);
274 message_string = XmStringCreateLocalized(message_text);
275 XtSetArg(args[0], XmNlabelString, message_string);
276 XtSetValues(widget, args, 1);
277 XmStringFree(message_string);
279 XtManageChild(message);
283 if (close_callback == NULL)
284 close_callback = _DtMessageClose;
286 XtAddEventHandler(XtParent (message), StructureNotifyMask, True,
287 (XtEventHandler)close_callback, message);
290 XmStringFree(okString);
291 XmStringFree(cancelString);
292 XmStringFree(helpString);
300 /************************************************************************
303 * Close the error message box.
305 ************************************************************************/
311 XtPointer client_data,
312 XtPointer call_data )
315 XtUnmanageChild(client_data);
321 /************************************************************************
324 * Close the error message box.
326 ************************************************************************/
331 XtPointer client_data,
335 if (event->type == UnmapNotify)
337 XtRemoveEventHandler(XtParent(client_data), StructureNotifyMask,
338 True, (XtEventHandler)_DtMessageClose, client_data);
340 XtUnmanageChild(client_data);