errordialog.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. #include <stdio.h>
  45. #include <fcntl.h>
  46. #include <signal.h>
  47. #include <sys/wait.h>
  48. #include <time.h>
  49. #include <X11/Intrinsic.h>
  50. #include <X11/StringDefs.h>
  51. #include <Xm/XmP.h>
  52. #include <Xm/Xm.h>
  53. #include <Xm/PushB.h>
  54. #include <Xm/DialogS.h>
  55. #include <Xm/Form.h>
  56. #include <Xm/Frame.h>
  57. #include <Xm/BulletinB.h>
  58. #include <Xm/Label.h>
  59. #include <Xm/Text.h>
  60. #include <Xm/TextF.h>
  61. #include <Xm/ToggleB.h>
  62. #include <Xm/Separator.h>
  63. #include "dtcopy.h"
  64. #include "sharedFuncs.h"
  65. #define VERTICAL_SPACING 5
  66. #define HORIZONTAL_SPACING 8
  67. #define TOP_SPACING (VERTICAL_SPACING + 3)
  68. #define INDENTED_SPACING (HORIZONTAL_SPACING + 5)
  69. /*--------------------------------------------------------------------
  70. * callbacks
  71. *------------------------------------------------------------------*/
  72. static void
  73. ok_callback(
  74. Widget w,
  75. XtPointer client_data,
  76. XtPointer call_data)
  77. {
  78. XtDestroyWidget(G_error_dialog);
  79. G_wait_on_input = FALSE;
  80. G_error_status = 0;
  81. G_error_dialog = NULL;
  82. return;
  83. }
  84. static void
  85. error_cancel_callback(
  86. Widget w,
  87. XtPointer client_data,
  88. XtPointer call_data)
  89. {
  90. display_cancel_warning(G_error_dialog);
  91. G_pause_copy = TRUE;
  92. }
  93. /*-------------------------------------------------
  94. *
  95. * The toggle shows up in more than one dialog
  96. * thus the state of the two widgets must be
  97. * synchronized.
  98. *
  99. *------------------------------------------------*/
  100. void
  101. toggle_callback(
  102. Widget w,
  103. XtPointer client_data,
  104. XtPointer call_data)
  105. {
  106. G_ignore_errors = !G_ignore_errors;
  107. if (w == G_toggle_main)
  108. {
  109. if (G_error_dialog != NULL)
  110. XtVaSetValues(G_toggle_error,
  111. XmNset, !G_ignore_errors,
  112. NULL);
  113. }
  114. else
  115. {
  116. XtVaSetValues(G_toggle_main,
  117. XmNset, !G_ignore_errors,
  118. NULL);
  119. }
  120. return;
  121. }
  122. /*--------------------------------------------------------------------
  123. * create error dialog
  124. *------------------------------------------------------------------*/
  125. void
  126. create_error_dialog(
  127. Widget parent_widget,
  128. char *op,
  129. char *filename,
  130. int errnum)
  131. {
  132. char buf[1024];
  133. char *msg;
  134. Arg args[10];
  135. int n;
  136. XmString xm_string;
  137. Widget form, outerFrame;
  138. Widget icon, error_header_label, error_text_label;
  139. Widget separator, action_area;
  140. Pixel background, foreground;
  141. Pixmap px;
  142. Position x, y;
  143. static ActionAreaItem copy_action_items[] = {
  144. {"Continue", 6, 6, ok_callback, NULL},
  145. {"Cancel Copy", 6, 7, error_cancel_callback, NULL},
  146. {"Help", 6, 4, help_callback, (XtPointer) HELP_DIR_ERROR},
  147. };
  148. ActionAreaDefn copyActions = {
  149. XtNumber(copy_action_items),
  150. 0, /* Ok is default action */
  151. copy_action_items
  152. };
  153. static ActionAreaItem move_action_items[] = {
  154. {"Continue", 6, 6, ok_callback, NULL},
  155. {"Cancel Move", 6, 8, error_cancel_callback, NULL},
  156. {"Help", 6, 4, help_callback, (XtPointer) HELP_DIR_ERROR},
  157. };
  158. ActionAreaDefn moveActions = {
  159. XtNumber(move_action_items),
  160. 0, /* Ok is default action */
  161. move_action_items
  162. };
  163. /* Create the dialog shell for the dialog */
  164. n=0;
  165. XtSetArg (args[n], XmNallowShellResize, True); n++;
  166. XtSetArg (args[n], XmNmappedWhenManaged, False); n++;
  167. if (G_move)
  168. {
  169. XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 4, "Folder Move - Error")); n++;
  170. }
  171. else
  172. {
  173. XtSetArg (args[n], XmNtitle, GETMESSAGE(4, 3, "Folder Copy - Error")); n++;
  174. }
  175. G_error_dialog = XmCreateDialogShell (G_copy_dialog, "dialog_shell", args, n);
  176. /* create a frame around the dialog for better separation from window border */
  177. outerFrame = XtVaCreateManagedWidget("outerFrame",
  178. xmFrameWidgetClass, G_error_dialog,
  179. XmNshadowThickness, 3,
  180. XmNshadowType, XmSHADOW_ETCHED_IN,
  181. NULL);
  182. /* Create the Manager Widget, form, for the copy error dialog */
  183. form = XtVaCreateManagedWidget ("dialog_form",
  184. xmFormWidgetClass,
  185. outerFrame,
  186. XmNverticalSpacing, VERTICAL_SPACING,
  187. XmNhorizontalSpacing, HORIZONTAL_SPACING,
  188. NULL);
  189. /* create the action area of the Error Dialog */
  190. if (G_move)
  191. action_area = Create_Action_Area(form, moveActions, NULL);
  192. else
  193. action_area = Create_Action_Area(form, copyActions, NULL);
  194. /* create the separator widget */
  195. separator = XtVaCreateManagedWidget("separator",
  196. xmSeparatorWidgetClass,
  197. form,
  198. XmNbottomAttachment, XmATTACH_WIDGET,
  199. XmNbottomWidget, action_area,
  200. XmNleftAttachment, XmATTACH_FORM,
  201. XmNrightAttachment, XmATTACH_FORM,
  202. NULL);
  203. /* Create the error dialog icon */
  204. n = 0;
  205. XtSetArg (args[n], XmNbackground, &background); n++;
  206. XtSetArg (args[n], XmNforeground, &foreground); n++;
  207. XtGetValues (form, args, n);
  208. px = XmGetPixmapByDepth(XtScreen(form), "xm_error",
  209. foreground, background, form->core.depth);
  210. if (px == XmUNSPECIFIED_PIXMAP)
  211. px = XmGetPixmapByDepth(XtScreen(form), "default_xm_error",
  212. foreground, background, form->core.depth);
  213. icon = XtVaCreateManagedWidget("error_icon",
  214. xmLabelWidgetClass,
  215. form,
  216. XmNlabelType, XmPIXMAP,
  217. XmNlabelPixmap, px,
  218. XmNtopAttachment, XmATTACH_FORM,
  219. XmNbottomAttachment, XmATTACH_WIDGET,
  220. XmNbottomWidget, separator,
  221. XmNleftAttachment, XmATTACH_FORM,
  222. NULL);
  223. /* Create the first error message label */
  224. sprintf(buf,GETMESSAGE(4, 1, "Error %s\n%s"), op, filename);
  225. xm_string = XmStringCreateLocalized(buf);
  226. error_header_label = XtVaCreateManagedWidget("msg_header",
  227. xmLabelWidgetClass,
  228. form,
  229. XmNlabelString, xm_string,
  230. XmNtopAttachment, XmATTACH_FORM,
  231. XmNleftAttachment, XmATTACH_WIDGET,
  232. XmNleftWidget, icon,
  233. XmNrightAttachment, XmATTACH_FORM,
  234. XmNalignment, XmALIGNMENT_BEGINNING,
  235. NULL);
  236. XmStringFree(xm_string);
  237. /* Create the second error message label */
  238. msg = strerror(errnum);
  239. xm_string = XmStringCreateLocalized(msg);
  240. error_text_label = XtVaCreateManagedWidget("msg_text",
  241. xmLabelWidgetClass,
  242. form,
  243. XmNlabelString, xm_string,
  244. XmNtopAttachment, XmATTACH_WIDGET,
  245. XmNtopWidget, error_header_label,
  246. XmNleftAttachment, XmATTACH_WIDGET,
  247. XmNleftWidget, icon,
  248. XmNrightAttachment, XmATTACH_FORM,
  249. XmNalignment, XmALIGNMENT_BEGINNING,
  250. NULL);
  251. XmStringFree(xm_string);
  252. /* create the toggle button */
  253. xm_string = XmStringCreateLocalized(GETMESSAGE(4, 2, "Pause for errors"));
  254. G_toggle_error = XtVaCreateManagedWidget("toggle",
  255. xmToggleButtonWidgetClass,
  256. form,
  257. XmNlabelString, xm_string,
  258. XmNset, !G_ignore_errors,
  259. XmNtopAttachment, XmATTACH_WIDGET,
  260. XmNtopWidget, error_text_label,
  261. XmNleftAttachment, XmATTACH_WIDGET,
  262. XmNleftWidget, icon,
  263. XmNbottomAttachment, XmATTACH_WIDGET,
  264. XmNbottomWidget, separator,
  265. XmNalignment, XmALIGNMENT_BEGINNING,
  266. NULL);
  267. XtAddCallback(G_toggle_error, XmNvalueChangedCallback, toggle_callback, NULL);
  268. XmStringFree(xm_string);
  269. /* set initial keyborad focus to the action button area */
  270. XtSetArg (args[0], XmNinitialFocus, action_area);
  271. XtSetValues(form, args, 1);
  272. /* Manage the Dialog */
  273. XtManageChild(form);
  274. /* Choose a window position */
  275. _DtChildPosition(G_error_dialog, G_toplevel, &x, &y);
  276. n=0;
  277. XtSetArg (args[n], XmNx, x); n++;
  278. XtSetArg (args[n], XmNy, y); n++;
  279. XtSetValues(G_error_dialog, args, n);
  280. /* Now that we have a window postion, mapp the dialog shell */
  281. XtMapWidget(G_error_dialog);
  282. return;
  283. }