utils.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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: utils.c /main/5 1996/10/17 09:36:36 mustafa $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. *
  27. * FILE: utils.c
  28. *
  29. *
  30. * DESCRIPTION: Utility routines
  31. *
  32. * FUNCTIONS: Create_Action_Area
  33. * Display_Help
  34. * Get_Help_Dialog
  35. * Help
  36. * _DtChildPosition
  37. * help_callback
  38. * help_close_callback
  39. * help_hyperyperlink_callback
  40. *
  41. * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
  42. * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
  43. * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
  44. * (c) Copyright 1993, 1994, 1995 Novell, Inc.
  45. *
  46. ****************************************************************************
  47. ************************************<+>*************************************/
  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/VendorSEP.h>
  54. #include <Xm/PushB.h>
  55. #include <Xm/Form.h>
  56. #include <Xm/BulletinB.h>
  57. #include <Xm/TextF.h>
  58. /* Copied from Xm/BaseClassI.h */
  59. extern XmWidgetExtData _XmGetWidgetExtData(
  60. Widget widget,
  61. #if NeedWidePrototypes
  62. unsigned int extType) ;
  63. #else
  64. unsigned char extType) ;
  65. #endif /* NeedWidePrototypes */
  66. #include <Dt/HelpDialog.h>
  67. #include "dtcopy.h"
  68. #include "sharedFuncs.h"
  69. /*............... definitions for Help .............................*/
  70. void
  71. Help(
  72. char *helpVolume,
  73. char *locationId);
  74. void
  75. Display_Help(
  76. char *helpVolume,
  77. char *locationId);
  78. /* Help volume tags used to attach a certian help volume
  79. * to a particular call back. Look to function help_callback
  80. * for more code. MJT
  81. */
  82. #define HELP_USING_HELP_VOLUME "Help4Help"
  83. #define HELP_USING_STR "_HomeTopic"
  84. #define HELP_VOLUME "Filemgr"
  85. #define HELP_HELP_MENU_STR "Reference"
  86. #define HELP_INTRODUCTION_STR "_HomeTopic"
  87. #define HELP_DIR_COPY_STR "FMCopyDirDialogStatusDE"
  88. #define HELP_DIR_ERROR_STR "FMCopyDIrDialogErrorDE"
  89. #define HELP_OVERWRITE_STR "FMCopyDirOverDialogDE"
  90. #define HELP_VERSION_STR "FMHelpMenuDE"
  91. #define STOPW_HELP_STR "FMCopyFoldWarnDialogDE"
  92. /*--------------------------------------------------------------------
  93. * Callback routines
  94. *------------------------------------------------------------------*/
  95. void
  96. help_close_callback(
  97. Widget widget,
  98. XtPointer client_data,
  99. XtPointer call_data)
  100. {
  101. XtUnmapWidget(XtParent(widget));
  102. }
  103. void
  104. help_hyperyperlink_callback(
  105. Widget widget,
  106. XtPointer client_data,
  107. XtPointer call_data)
  108. {
  109. DtHelpDialogCallbackStruct *pHyper = (DtHelpDialogCallbackStruct *) call_data;
  110. switch(pHyper->hyperType)
  111. {
  112. case DtHELP_LINK_JUMP_NEW:
  113. Display_Help(pHyper->helpVolume, pHyper->locationId);
  114. break;
  115. default:
  116. ;
  117. }
  118. }
  119. void
  120. help_callback(
  121. Widget widget,
  122. XtPointer client_data,
  123. XtPointer call_data)
  124. {
  125. char *helpVolume, *locationId;
  126. int topic;
  127. topic = (int)(XtArgVal) client_data;
  128. helpVolume = HELP_VOLUME;
  129. switch (topic)
  130. {
  131. case HELP_HELP_MENU:
  132. locationId = HELP_HELP_MENU_STR;
  133. break;
  134. case HELP_INTRODUCTION:
  135. locationId = HELP_INTRODUCTION_STR;
  136. break;
  137. case HELP_DIR_COPY:
  138. locationId = HELP_DIR_COPY_STR;
  139. break;
  140. case HELP_DIR_ERROR:
  141. locationId = HELP_DIR_ERROR_STR;
  142. break;
  143. case HELP_OVERWRITE:
  144. locationId = HELP_OVERWRITE_STR;
  145. break;
  146. case HELP_USING:
  147. locationId = HELP_USING_STR;
  148. helpVolume = HELP_USING_HELP_VOLUME;
  149. break;
  150. case HELP_VERSION:
  151. locationId = HELP_VERSION_STR;
  152. break;
  153. case STOPW_HELP_DIALOG:
  154. locationId = STOPW_HELP_STR;
  155. break;
  156. default:
  157. locationId = HELP_USING_STR;
  158. helpVolume = HELP_USING_HELP_VOLUME;
  159. break;
  160. }
  161. Help(helpVolume, locationId);
  162. }
  163. /*--------------------------------------------------------------------
  164. * _DtChildPosition
  165. *------------------------------------------------------------------*/
  166. void
  167. _DtChildPosition(
  168. Widget w,
  169. Widget parent,
  170. Position *newX,
  171. Position *newY)
  172. {
  173. Position pY, pX;
  174. XmVendorShellExtObject vendorExt;
  175. XmWidgetExtData extData;
  176. int xOffset, yOffset;
  177. int pHeight, myHeight, sHeight;
  178. int pWidth, myWidth, sWidth;
  179. enum { posRight, posBelow, posLeft, posAbove } pos;
  180. int space;
  181. /* get x, y offsets for the parent's window frame */
  182. extData = _XmGetWidgetExtData(parent, XmSHELL_EXTENSION);
  183. if (extData)
  184. {
  185. vendorExt = (XmVendorShellExtObject)extData->widget;
  186. xOffset = vendorExt->vendor.xOffset;
  187. yOffset = vendorExt->vendor.yOffset;
  188. }
  189. else
  190. xOffset = yOffset = 0;
  191. /* get size/position of screen, parent, and widget */
  192. sHeight = HeightOfScreen(XtScreen(parent));;
  193. sWidth = WidthOfScreen(XtScreen(parent));
  194. pX = XtX(parent) - xOffset;
  195. pY = XtY(parent) - yOffset;
  196. pHeight = XtHeight(parent) + yOffset + xOffset;
  197. pWidth = XtWidth(parent) + 2*xOffset;
  198. myHeight = XtHeight(w) + yOffset + xOffset;
  199. myWidth = XtWidth(w) + 2*xOffset;
  200. {
  201. XWindowAttributes attr;
  202. XGetWindowAttributes(XtDisplay(parent), XtWindow(parent), &attr);
  203. }
  204. /*
  205. * Determine how much space would be left if the child was positioned
  206. * to the right, below, left, or above the parent. Choose the child
  207. * positioning so that the maximum space is left.
  208. */
  209. pos = posRight;
  210. space = sWidth - (pX + pWidth + myWidth);
  211. if (sHeight - (pY + pHeight + myHeight) > space)
  212. {
  213. pos = posBelow;
  214. space = sHeight - (pY + pHeight + myHeight);
  215. }
  216. if (pX - myWidth > space)
  217. {
  218. pos = posLeft;
  219. space = pX - myWidth;
  220. }
  221. if (pY - myHeight > space)
  222. {
  223. pos = posAbove;
  224. space = pY - myHeight;
  225. }
  226. /* Given relative positioning, determine x, y coordinates for the child */
  227. switch (pos)
  228. {
  229. case posRight:
  230. *newX = pX + pWidth + 5;
  231. *newY = pY + (pHeight - myHeight)/2;
  232. break;
  233. case posBelow:
  234. *newX = pX + (pWidth - myWidth)/2;
  235. *newY = pY + pHeight + 5;
  236. break;
  237. case posLeft:
  238. *newX = pX - myWidth - 5;
  239. *newY = pY + (pHeight - myHeight)/2;
  240. break;
  241. case posAbove:
  242. *newX = pX + (pWidth - myWidth)/2;
  243. *newY = pY - myHeight - 5;
  244. break;
  245. }
  246. }
  247. static Widget
  248. Get_Help_Dialog(void)
  249. {
  250. Widget dialog;
  251. Arg args[5];
  252. int n;
  253. n = 0;
  254. XtSetArg(args[n], XmNtitle, GETMESSAGE(6, 5, "Directory Copy Help")); n++;
  255. dialog = DtCreateHelpDialog(G_toplevel, "helpDlg", args, n);
  256. XtAddCallback(dialog, DtNhyperLinkCallback,
  257. (XtCallbackProc)help_hyperyperlink_callback, NULL);
  258. XtAddCallback(dialog, DtNcloseCallback,
  259. (XtCallbackProc)help_close_callback, NULL);
  260. return dialog;
  261. }
  262. void
  263. Display_Help(
  264. char *helpVolume,
  265. char *locationId)
  266. {
  267. Arg args[10];
  268. int n;
  269. G_help_dialog = Get_Help_Dialog();
  270. n = 0;
  271. XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
  272. XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
  273. XtSetArg(args[n], DtNlocationId, locationId); n++;
  274. XtSetValues(G_help_dialog, args, n);
  275. XtManageChild(G_help_dialog);
  276. XtMapWidget(XtParent(G_help_dialog));
  277. }
  278. void
  279. Help(
  280. char *helpVolume,
  281. char *locationId)
  282. {
  283. Arg args[10];
  284. int n;
  285. if(G_help_dialog == NULL)
  286. {
  287. n = 0;
  288. XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
  289. XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
  290. XtSetArg(args[n], DtNlocationId, locationId); n++;
  291. XtSetArg (args[n], XmNtitle, GETMESSAGE(6, 5, "Directory Copy Help")); n++;
  292. G_help_dialog = DtCreateHelpDialog(G_toplevel, "helpDlg", args, n);
  293. XtAddCallback(G_help_dialog, DtNhyperLinkCallback,
  294. (XtCallbackProc)help_hyperyperlink_callback, NULL);
  295. XtAddCallback(G_help_dialog, DtNcloseCallback,
  296. (XtCallbackProc)help_close_callback, NULL);
  297. XtManageChild(G_help_dialog);
  298. }
  299. else
  300. {
  301. n = 0;
  302. XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
  303. XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
  304. XtSetArg(args[n], DtNlocationId, locationId); n++;
  305. XtSetValues(G_help_dialog, args, n);
  306. }
  307. XtMapWidget(XtParent(G_help_dialog));
  308. }
  309. /*--------------------------------------------------------------------
  310. *
  311. * Create Action Area
  312. *
  313. * Use of this function requires #include "sharedFuncs.h"
  314. * The source for Create_Action_Area is in dtfile/OverWrite.c and
  315. * dtfile/dtcopy/utils.c. Because it uses GETMESSAGE, it could not
  316. * be placed in dtcopy/sharedFunc.c.
  317. *
  318. *------------------------------------------------------------------*/
  319. Widget
  320. Create_Action_Area(
  321. Widget parent_widget,
  322. ActionAreaDefn actions,
  323. Widget *pushbutton_array)
  324. {
  325. Widget action_area, widget;
  326. int i;
  327. int fractbase_value;
  328. XmString xm_string;
  329. if (actions.defaultAction < 0 || actions.defaultAction > actions.numActions-1)
  330. actions.defaultAction = 0;
  331. fractbase_value = (TIGHTNESS * actions.numActions) - 1;
  332. action_area = XtVaCreateManagedWidget("action_area", xmFormWidgetClass ,parent_widget,
  333. XmNfractionBase, fractbase_value,
  334. XmNleftAttachment, XmATTACH_FORM,
  335. XmNrightAttachment, XmATTACH_FORM,
  336. XmNbottomAttachment, XmATTACH_FORM,
  337. NULL);
  338. for (i=0; i < actions.numActions ;i++ )
  339. {
  340. xm_string = XmStringCreateLocalized(GETMESSAGE(actions.actionList[i].msg_set,
  341. actions.actionList[i].msg_num,
  342. actions.actionList[i].label));
  343. widget = XtVaCreateManagedWidget(actions.actionList[i].label,
  344. xmPushButtonWidgetClass, action_area,
  345. XmNleftAttachment, (i ? XmATTACH_POSITION: XmATTACH_FORM),
  346. XmNleftPosition, (TIGHTNESS * i),
  347. XmNtopAttachment, XmATTACH_FORM,
  348. XmNbottomAttachment, XmATTACH_FORM,
  349. XmNrightAttachment,
  350. ((i != (actions.numActions - 1)) ? XmATTACH_POSITION: XmATTACH_FORM),
  351. XmNrightPosition, ((TIGHTNESS*i) + (TIGHTNESS - 1)),
  352. XmNshowAsDefault, (i == actions.defaultAction),
  353. XmNdefaultButtonShadowThickness, 1,
  354. XmNlabelString, xm_string,
  355. NULL);
  356. XmStringFree(xm_string);
  357. if (actions.actionList[i].callback)
  358. {
  359. XtAddCallback(widget, XmNactivateCallback,
  360. actions.actionList[i].callback, actions.actionList[i].data);
  361. }
  362. if (i == actions.defaultAction)
  363. {
  364. XtArgVal arg;
  365. Dimension height, h;
  366. XtVaGetValues (action_area, XmNmarginHeight, &arg, NULL);
  367. h = (Dimension)arg;
  368. XtVaGetValues (widget, XmNheight, &arg, NULL);
  369. height = (Dimension)arg;
  370. height +=2 * h;
  371. XtVaSetValues (action_area,
  372. XmNdefaultButton, widget,
  373. XmNpaneMaximum, height,
  374. XmNpaneMinimum, height,
  375. NULL);
  376. }
  377. if (pushbutton_array != NULL)
  378. pushbutton_array[i] = widget;
  379. } /* endfor */
  380. XtManageChild(action_area);
  381. return action_area;
  382. } /* end Create_Action_Area */