Spelling fixes
[oweals/cde.git] / cde / programs / dtfile / dtcopy / errordialog.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: errordialog.c /main/6 1996/10/17 09:36:14 mustafa $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  *
27  *   FILE:           errordialog.c
28  *
29  *
30  *   DESCRIPTION:    Routines to create dialogs for error messages
31  *
32  *   FUNCTIONS: create_error_dialog
33  *              error_cancel_callback
34  *              ok_callback
35  *              toggle_callback
36  *
37  *   (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
38  *   (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
39  *   (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
40  *   (c) Copyright 1993, 1994, 1995 Novell, Inc.
41  *
42  ****************************************************************************
43  ************************************<+>*************************************/
44
45 #include <stdio.h>
46 #include <fcntl.h>
47 #include <signal.h>
48 #include <sys/wait.h>
49 #include <time.h>
50 #include <X11/Intrinsic.h>
51 #include <X11/StringDefs.h>
52 #include <Xm/XmP.h>
53 #include <Xm/Xm.h>
54 #include <Xm/PushB.h>
55 #include <Xm/DialogS.h>
56 #include <Xm/Form.h>
57 #include <Xm/Frame.h>
58 #include <Xm/BulletinB.h>
59 #include <Xm/Label.h>
60 #include <Xm/Text.h>
61 #include <Xm/TextF.h>
62 #include <Xm/ToggleB.h>
63 #include <Xm/Separator.h>
64
65 #include "dtcopy.h"
66 #include "sharedFuncs.h"
67
68 #define VERTICAL_SPACING  5
69 #define HORIZONTAL_SPACING  8
70 #define TOP_SPACING  (VERTICAL_SPACING + 3)
71 #define INDENTED_SPACING (HORIZONTAL_SPACING + 5)
72
73 /*--------------------------------------------------------------------
74  * callbacks
75  *------------------------------------------------------------------*/
76
77 static void
78 ok_callback(
79         Widget w,
80         XtPointer client_data,
81         XtPointer call_data)
82 {
83   XtDestroyWidget(G_error_dialog);
84   G_wait_on_input = FALSE;
85   G_error_status = 0;
86   G_error_dialog = NULL;
87   return;
88
89 }
90
91
92 static void
93 error_cancel_callback(
94         Widget w,
95         XtPointer client_data,
96         XtPointer call_data)
97 {
98    display_cancel_warning(G_error_dialog);
99
100    G_pause_copy = TRUE;
101 }
102
103
104 /*-------------------------------------------------
105  *
106  *  The toggle shows up in more than one dialog
107  *  thus the state of the two widgets must be
108  *  synchronized.
109  *
110  *------------------------------------------------*/
111 void
112 toggle_callback(
113         Widget w,
114         XtPointer client_data,
115         XtPointer call_data)
116 {
117
118
119   G_ignore_errors = !G_ignore_errors;
120
121   if (w == G_toggle_main)
122   {
123      if (G_error_dialog != NULL)
124         XtVaSetValues(G_toggle_error,
125                       XmNset, !G_ignore_errors,
126                       NULL);
127   }
128   else
129   {
130      XtVaSetValues(G_toggle_main,
131                    XmNset, !G_ignore_errors,
132                    NULL);
133   }
134   return;
135 }
136
137
138 /*--------------------------------------------------------------------
139  * create error dialog
140  *------------------------------------------------------------------*/
141
142 void
143 create_error_dialog(
144         Widget parent_widget,
145         char *op,
146         char *filename,
147         int errnum)
148 {
149    char  buf[1024];
150    char *msg;
151
152    Arg args[10];
153    int n;
154    XmString xm_string;
155    Widget form, outerFrame;
156    Widget icon, error_header_label, error_text_label;
157    Widget separator, action_area;
158    Pixel background, foreground;
159    Pixmap px;
160    Position x, y;
161
162    static ActionAreaItem copy_action_items[] = {
163      {"Continue",    6, 6, ok_callback,           NULL},
164      {"Cancel Copy", 6, 7, error_cancel_callback, NULL},
165      {"Help",        6, 4, help_callback,         (XtPointer) HELP_DIR_ERROR},
166    };
167
168   ActionAreaDefn copyActions = {
169      XtNumber(copy_action_items),
170      0,                      /* Ok is default action */
171      copy_action_items
172   };
173
174    static ActionAreaItem move_action_items[] = {
175      {"Continue",    6, 6, ok_callback,           NULL},
176      {"Cancel Move", 6, 8, error_cancel_callback, NULL},
177      {"Help",        6, 4, help_callback,         (XtPointer) HELP_DIR_ERROR},
178    };
179
180   ActionAreaDefn moveActions = {
181      XtNumber(move_action_items),
182      0,                      /* Ok is default action */
183      move_action_items
184   };
185
186
187    /* Create the dialog shell for the dialog */
188    n=0;
189    XtSetArg (args[n], XmNallowShellResize, True); n++;
190    XtSetArg (args[n], XmNmappedWhenManaged, False); n++;
191    if (G_move)
192    {
193       XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 4, "Folder Move - Error")); n++;
194    }
195    else
196    {
197       XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 3, "Folder Copy - Error")); n++;
198    }
199
200    G_error_dialog = XmCreateDialogShell (G_copy_dialog, "dialog_shell", args, n);
201
202    /* create a frame around the dialog for better separation from window border */
203    outerFrame = XtVaCreateManagedWidget("outerFrame",
204                                xmFrameWidgetClass, G_error_dialog,
205                                XmNshadowThickness, 3,
206                                XmNshadowType, XmSHADOW_ETCHED_IN,
207                                NULL);
208
209
210    /* Create the Manager Widget, form, for the copy error dialog */
211    form  = XtVaCreateManagedWidget ("dialog_form",
212                               xmFormWidgetClass,
213                               outerFrame,
214                               XmNverticalSpacing,   VERTICAL_SPACING,
215                               XmNhorizontalSpacing, HORIZONTAL_SPACING,
216                               NULL);
217
218    /* create the action area of the Error Dialog */
219    if (G_move)
220       action_area = Create_Action_Area(form, moveActions, NULL);
221    else
222       action_area = Create_Action_Area(form, copyActions, NULL);
223
224    /* create the separator widget */
225    separator  =  XtVaCreateManagedWidget("separator",
226                               xmSeparatorWidgetClass,
227                               form,
228                               XmNbottomAttachment,  XmATTACH_WIDGET,
229                               XmNbottomWidget,      action_area,
230                               XmNleftAttachment,    XmATTACH_FORM,
231                               XmNrightAttachment,   XmATTACH_FORM,
232                               NULL);
233
234
235
236    /* Create the error dialog icon */
237    n = 0;
238    XtSetArg (args[n], XmNbackground, &background); n++;
239    XtSetArg (args[n], XmNforeground, &foreground); n++;
240    XtGetValues (form, args, n);
241    px = XmGetPixmapByDepth(XtScreen(form), "xm_error",
242                            foreground, background, form->core.depth);
243    if (px == XmUNSPECIFIED_PIXMAP)
244      px = XmGetPixmapByDepth(XtScreen(form), "default_xm_error",
245                       foreground, background, form->core.depth);
246
247    icon = XtVaCreateManagedWidget("error_icon",
248                               xmLabelWidgetClass,
249                               form,
250                               XmNlabelType,        XmPIXMAP,
251                               XmNlabelPixmap,      px,
252                               XmNtopAttachment,    XmATTACH_FORM,
253                               XmNbottomAttachment, XmATTACH_WIDGET,
254                               XmNbottomWidget,     separator,
255                               XmNleftAttachment,   XmATTACH_FORM,
256                               NULL);
257
258    /* Create the first error message label */
259    sprintf(buf,GETMESSAGE(4, 1, "Error %s\n%s"), op, filename);
260    xm_string = XmStringCreateLocalized(buf);
261    error_header_label = XtVaCreateManagedWidget("msg_header",
262                               xmLabelWidgetClass,
263                               form,
264                               XmNlabelString,     xm_string,
265                               XmNtopAttachment,   XmATTACH_FORM,
266                               XmNleftAttachment,  XmATTACH_WIDGET,
267                               XmNleftWidget,      icon,
268                               XmNrightAttachment, XmATTACH_FORM,
269                               XmNalignment,       XmALIGNMENT_BEGINNING,
270                               NULL);
271    XmStringFree(xm_string);
272
273    /* Create the second error message label */
274    msg =  strerror(errnum);
275    xm_string = XmStringCreateLocalized(msg);
276    error_text_label = XtVaCreateManagedWidget("msg_text",
277                               xmLabelWidgetClass,
278                               form,
279                               XmNlabelString,      xm_string,
280                               XmNtopAttachment,    XmATTACH_WIDGET,
281                               XmNtopWidget,        error_header_label,
282                               XmNleftAttachment,   XmATTACH_WIDGET,
283                               XmNleftWidget,       icon,
284                               XmNrightAttachment,  XmATTACH_FORM,
285                               XmNalignment,        XmALIGNMENT_BEGINNING,
286                               NULL);
287    XmStringFree(xm_string);
288
289    /* create the toggle button */
290    xm_string = XmStringCreateLocalized(GETMESSAGE(4, 2, "Pause for errors"));
291    G_toggle_error = XtVaCreateManagedWidget("toggle",
292                               xmToggleButtonWidgetClass,
293                               form,
294                               XmNlabelString,      xm_string,
295                               XmNset,              !G_ignore_errors,
296                               XmNtopAttachment,    XmATTACH_WIDGET,
297                               XmNtopWidget,        error_text_label,
298                               XmNleftAttachment,   XmATTACH_WIDGET,
299                               XmNleftWidget,       icon,
300                               XmNbottomAttachment, XmATTACH_WIDGET,
301                               XmNbottomWidget,     separator,
302                               XmNalignment,        XmALIGNMENT_BEGINNING,
303                               NULL);
304    XtAddCallback(G_toggle_error, XmNvalueChangedCallback, toggle_callback, NULL);
305    XmStringFree(xm_string);
306    /* set initial keyborad focus to the action button area */
307    XtSetArg (args[0], XmNinitialFocus, action_area);
308    XtSetValues(form, args, 1);
309
310    /* Manage the Dialog */
311    XtManageChild(form);
312
313
314    /* Choose a window position */
315    _DtChildPosition(G_error_dialog, G_toplevel, &x, &y);
316    n=0;
317    XtSetArg (args[n], XmNx, x); n++;
318    XtSetArg (args[n], XmNy, y); n++;
319    XtSetValues(G_error_dialog, args, n);
320
321    /* Now that we have a window postion, mapp the dialog shell */
322    XtMapWidget(G_error_dialog);
323
324    return;
325 }
326