2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: SharedProcs.c /main/7 1996/08/28 17:19:21 drk $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
30 /*************************************<+>*************************************
31 *****************************************************************************
33 ** File: SharedProcs.c
37 ** Description: Contains the set of functions which are of general
38 ** use to all DT clients.
41 ****************************************************************************
42 ************************************<+>*************************************/
44 #include <sys/types.h>
54 #include <Xm/VendorSEP.h>
55 #include <Xm/MessageB.h>
56 #include <Xm/RowColumn.h>
57 #include <Xm/MwmUtil.h>
58 #include <Xm/Protocols.h>
59 #include <X11/ShellP.h>
60 #include <X11/Shell.h>
61 #include <X11/Xatom.h>
65 #include <Dt/Connect.h>
66 #include <Dt/DtNlUtils.h>
68 #include "SharedProcs.h"
72 #define RW_ALL S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
75 /******** Static Function Declarations ********/
78 /******** End Static Function Declarations ********/
81 /************************************************************************
85 * Strip all leading and trailing spaces.
87 ************************************************************************/
101 /* Strip off leading spaces first */
105 (!is_multibyte || (mblen(string + i, MB_CUR_MAX) == 1)) &&
107 isspace((u_char)string[i]))
112 /* Copy over the leading spaces */
113 strcpy(string, string + i);
115 /* Drop out, if the string is now empty */
116 if ((i = strlen(string) - 1) < 0)
119 /* Strip off trailing spaces */
124 /* No multibyte; simply work back through the string */
125 while ((i >= 0) && (isspace((u_char)string[i])))
127 string[i + 1] = '\0';
132 /* Work forward, looking for a trailing space of spaces */
140 if (((len = mblen(string + i, MB_CUR_MAX)) == 1) && isspace((u_char)string[i]))
149 /* if there is an invalid character, treat as a valid one-byte */
165 /************************************************************************
168 * Create and display an error message.
170 ************************************************************************/
178 void (*helpCallback)() )
181 _DtMessageDialog(w, title, message_text, helpIdStr, False,
182 NULL, _DtMessageOK, _DtMessageClose, helpCallback, True,
187 /************************************************************************
189 * Generic warning/error dialog creation function.
191 ************************************************************************/
200 void (*cancel_callback)(),
201 void (*ok_callback)(),
202 void (*close_callback)(),
203 void (*help_callback)(),
204 Boolean deleteOnClose,
210 XmString message_string;
211 XWindowAttributes attributes;
213 XmString okString, cancelString, helpString;
215 okString = XmStringCreateLocalized((Dt11GETMESSAGE(28,1, "OK")));
216 cancelString = XmStringCreateLocalized((Dt11GETMESSAGE(28,2, "Cancel")));
217 helpString = XmStringCreateLocalized((Dt11GETMESSAGE(28,3, "Help")));
219 XtSetArg (args[0], XmNautoUnmanage, False);
220 XtSetArg (args[1], XmNcancelLabelString, cancelString);
221 XtSetArg (args[2], XmNokLabelString, okString);
222 XtSetArg (args[3], XmNhelpLabelString, helpString);
223 XtSetArg (args[4], XmNuseAsyncGeometry, True);
225 /* Search up to get the topmost shell */
227 while (XtParent (w) != NULL && !(XtIsSubclass (w, shellWidgetClass)))
233 message = XmCreateErrorDialog(w, title, args, 5);
237 message = XmCreateWarningDialog(w, title, args, 5);
240 case QUESTION_DIALOG:
241 message = XmCreateQuestionDialog(w, title, args, 5);
244 if (XtWindow (w) != 0)
245 XGetWindowAttributes(XtDisplay (w), XtWindow (w), &attributes);
247 attributes.map_state = IsUnmapped;
249 if (attributes.map_state == IsUnmapped)
251 XtSetArg(args[0], XmNx, (WidthOfScreen(XtScreen (w)) - 350) / 2);
252 XtSetArg(args[1], XmNy, (HeightOfScreen(XtScreen (w)) - 200) / 2);
253 XtSetArg(args[2], XmNdefaultPosition, False);
254 XtSetValues(message, args, 3);
258 /* Adjust the decorations and title for the dialog shell of the dialog */
260 XtSetArg(args[0], XmNtitle, title);
261 XtSetArg(args[1], XmNmwmFunctions, MWM_FUNC_MOVE);
262 XtSetArg(args[2], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE);
263 XtSetValues(XtParent (message), args, 3);
265 widget = XmMessageBoxGetChild(message, XmDIALOG_CANCEL_BUTTON);
267 XtUnmanageChild(widget);
268 else if (cancel_callback)
270 XtAddCallback(widget, XmNactivateCallback, cancel_callback,
272 XtSetArg(args[0], XmNcancelButton, widget);
273 XtSetValues(message, args, 1);
276 widget = XmMessageBoxGetChild(message, XmDIALOG_OK_BUTTON);
277 XtSetArg(args[0], XmNmarginWidth, 10);
278 XtSetArg(args[1], XmNmarginHeight, 2);
279 XtSetValues(widget, args, 2);
280 XtAddCallback(widget, XmNactivateCallback, ok_callback, (caddr_t) message);
282 widget = XmMessageBoxGetChild(message, XmDIALOG_HELP_BUTTON);
283 if (helpIdStr != NULL)
287 XtAddCallback(widget, XmNactivateCallback, help_callback,
288 (caddr_t) helpIdStr);
290 XtSetValues(widget, args, 2);
293 XtUnmanageChild(widget);
295 widget = XmMessageBoxGetChild(message, XmDIALOG_MESSAGE_LABEL);
296 message_string = XmStringCreateLocalized(message_text);
297 XtSetArg(args[0], XmNlabelString, message_string);
298 XtSetValues(widget, args, 1);
299 XmStringFree(message_string);
301 XtManageChild(message);
305 if (close_callback == NULL)
306 close_callback = _DtMessageClose;
308 XtAddEventHandler(XtParent (message), StructureNotifyMask, True,
309 (XtEventHandler)close_callback, message);
312 XmStringFree(okString);
313 XmStringFree(cancelString);
314 XmStringFree(helpString);
322 /************************************************************************
325 * Close the error message box.
327 ************************************************************************/
333 XtPointer client_data,
334 XtPointer call_data )
337 XtUnmanageChild(client_data);
343 /************************************************************************
346 * Close the error message box.
348 ************************************************************************/
353 XtPointer client_data,
357 if (event->type == UnmapNotify)
359 XtRemoveEventHandler(XtParent(client_data), StructureNotifyMask,
360 True, (XtEventHandler)_DtMessageClose, client_data);
362 XtUnmanageChild(client_data);