cmncbs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. /* $TOG: cmncbs.c /main/8 1999/09/17 15:44:29 mgreess $ */
  24. /*****************************************************************************/
  25. /* */
  26. /* cmncbs.c */
  27. /* */
  28. /* Common callbacks */
  29. /* */
  30. /*****************************************************************************/
  31. #include <stdio.h>
  32. #include <sys/types.h>
  33. #include <sys/signal.h>
  34. #include <X11/cursorfont.h>
  35. #include <Dt/Icon.h>
  36. #include <Dt/Help.h>
  37. #include <Dt/HelpDialog.h>
  38. #include "dtcreate.h"
  39. #include "OpenFile.h"
  40. #include "cmncbs.h"
  41. #include "cmnrtns.h"
  42. #include "CreateActionAppShell.h"
  43. #include "af_aux.h"
  44. #include "ca_aux.h"
  45. #include "icon_selection_dialog.h"
  46. /* from main.c */
  47. extern void UxDoEditPixmap(Widget wid, char *fname);
  48. /******************************************************************************/
  49. /* Initialize global values. */
  50. /******************************************************************************/
  51. Boolean bRegisteredSignal = FALSE;
  52. int (*sigchildRoutine)();
  53. /******************************************************************************/
  54. /* activateCB_open_FindSet - Callback for the "Find Set" button on */
  55. /* CreateActionAppShell and AddFiletype windows. */
  56. /* This callback will pop up the Icon Selection */
  57. /* dialog box. */
  58. /* */
  59. /* INPUT: Widget filesel - file selection box widget id */
  60. /* XtPointer cdata - client data */
  61. /* XmFileSelectionBoxCallbackStruct *cbstruct - callback data */
  62. /* */
  63. /* OUTPUT: none */
  64. /* */
  65. /******************************************************************************/
  66. void activateCB_open_FindSet (Widget find_set_button, XtPointer cdata,
  67. XmFileSelectionBoxCallbackStruct *cbstruct)
  68. {
  69. Widget filter;
  70. XtArgVal /* Boolean */ use_bm = False;
  71. static char *use_bm_filter = "*.m.bm";
  72. static char *use_pm_filter = "*.m.pm";
  73. char *search_path;
  74. char *filter_field_title = NULL;
  75. int use_filter_field = False;
  76. char *file_filter;
  77. char **directories_list = GetIconSearchPathList();
  78. int numberOfTopButtons = 0;
  79. void *top_button_one_cb = NULL;
  80. void *top_button_two_cb = NULL;
  81. void *top_button_three_cb = NULL;
  82. char *top_button_one_label = NULL;
  83. char *top_button_two_label = NULL;
  84. char *top_button_three_label = NULL;
  85. int use_icon_name_field = True;
  86. int numberOfBottomButtons = 3;
  87. void *bottom_button_one_cb = (void *)load_icons;
  88. void *bottom_button_two_cb = NULL;
  89. void *bottom_button_three_cb = NULL;
  90. void *bottom_button_four_cb = NULL;
  91. char *bottom_button_one_label = NULL; /* use default */
  92. char *bottom_button_two_label = NULL; /* use default */
  93. char *bottom_button_three_label = NULL; /* use default */
  94. char *bottom_button_four_label = NULL; /* use default */
  95. char *name_field_title;
  96. char *container_title;
  97. char *directory_title;
  98. char *dialog_title, *pre, *suf;
  99. name_field_title = XtNewString(GETMESSAGE(11, 12, "Enter Icon Filename"));
  100. container_title = XtNewString(GETMESSAGE(11, 11, "Icon Files"));
  101. directory_title = XtNewString(GETMESSAGE(11, 30, "Icon Folders"));
  102. pre = GETMESSAGE(3, 10, "Create Action");
  103. suf = GETMESSAGE(6, 18, "Find Set");
  104. dialog_title = XtMalloc(strlen(pre) + strlen(suf) + 4);
  105. sprintf(dialog_title, "%s - %s", pre, suf);
  106. #ifdef DEBUG
  107. printf("activate Find Set button; client_data = %p\n", cdata); /* debug */
  108. #endif
  109. XtVaGetValues (COLOR_MONO_OPTION, XmNset, &use_bm, NULL);
  110. if (use_bm) file_filter = use_bm_filter;
  111. else file_filter = use_pm_filter;
  112. #ifndef _ICONSELECTOR_DESTROY_ENABLED
  113. if (!IconSelector) {
  114. #endif /* _ICONSELECTOR_DESTROY_ENABLED */
  115. IconSelector = create_icon_selection_dialog ((swidget) CreateActionAppShell,
  116. (unsigned char *)dialog_title,
  117. (unsigned char *)filter_field_title,
  118. use_filter_field,
  119. (unsigned char *)file_filter,
  120. (unsigned char *)directory_title,
  121. (unsigned char **)directories_list,
  122. (unsigned char *)container_title,
  123. numberOfTopButtons,
  124. (unsigned char *)top_button_one_label,
  125. (void (*)())top_button_one_cb,
  126. (unsigned char *)top_button_two_label,
  127. (void (*)())top_button_two_cb,
  128. (unsigned char *)top_button_three_label,
  129. (void (*)())top_button_three_cb,
  130. use_icon_name_field,
  131. (unsigned char *)name_field_title,
  132. numberOfBottomButtons,
  133. (unsigned char *)bottom_button_one_label,
  134. (void (*)())bottom_button_one_cb,
  135. (unsigned char *)bottom_button_two_label,
  136. (void (*)())bottom_button_two_cb,
  137. (unsigned char *)bottom_button_three_label,
  138. (void (*)())bottom_button_three_cb,
  139. (unsigned char *)bottom_button_four_label,
  140. (void (*)())bottom_button_four_cb);
  141. #ifndef _ICONSELECTOR_DESTROY_ENABLED
  142. }
  143. #endif /* _ICONSELECTOR_DESTROY_ENABLED */
  144. XtFree(name_field_title);
  145. XtFree(container_title);
  146. XtFree(directory_title);
  147. XtFree(dialog_title);
  148. FreeIconSearchPathList(directories_list);
  149. XtVaSetValues (IconSelector, XmNuserData, cdata, NULL);
  150. UxPopupInterface (IconSelector, no_grab);
  151. XmProcessTraversal(ISD_SelectedIconTextField, XmTRAVERSE_CURRENT);
  152. return;
  153. }
  154. /******************************************************************************/
  155. /* */
  156. /* createCB_IconGadget */
  157. /* */
  158. /* INPUT: Widget wid - icon gadget windet id */
  159. /* Boolean bActionIcons - is this an action widget */
  160. /* enum icon_size_range - size of icon this widget represents */
  161. /* */
  162. /* OUTPUT: none */
  163. /* */
  164. /******************************************************************************/
  165. void createCB_IconGadget(Widget wid,
  166. Boolean bActionIcons,
  167. enum icon_size_range IconSize)
  168. {
  169. SetIconData(wid,
  170. (char *)((bActionIcons) ?
  171. ca_full_icon_default : af_full_icon_default),
  172. IconSize);
  173. }
  174. /******************************************************************************/
  175. /* activateCB_edit_icon - brings up icon editor with selected icon */
  176. /* */
  177. /* INPUT: Widget wid - widget id */
  178. /* XtPointer cd - client data */
  179. /* XmPushButtonCallbackStruct *cbs - callback data */
  180. /* OUTPUT: none */
  181. /* */
  182. /******************************************************************************/
  183. void activateCB_edit_icon (Widget wid, XtPointer client_data,
  184. XmPushButtonCallbackStruct *cbs)
  185. {
  186. char *pszIconToEdit;
  187. Boolean IsActionIcons;
  188. if (bIconEditorDisplayed) return;
  189. if ((int)(XtArgVal)client_data == CA_ACTION_ICONS) {
  190. IsActionIcons = True;
  191. widSelectedIcon = get_selected_action_icon();
  192. widEditSource = CreateActionAppShell;
  193. } else {
  194. IsActionIcons = False;
  195. widSelectedIcon = (Widget)get_selected_filetype_icon();
  196. widEditSource = AddFiletype;
  197. }
  198. XtVaGetValues (widSelectedIcon, XmNimageName, &pszIconToEdit, NULL);
  199. /***************************************************************/
  200. /* Call routine to send tooltalk message to start icon editor. */
  201. /***************************************************************/
  202. UxDoEditPixmap(widSelectedIcon, pszIconToEdit);
  203. return;
  204. }
  205. /* We use this so we can reuse an open help dialog window. */
  206. static Widget mainHelpDialog = NULL;
  207. /******************************************************************************/
  208. /* */
  209. /* closeCB_mainHelpDialog */
  210. /* */
  211. /* INPUT: Widget wid - widget id */
  212. /* XtPointer cd - client data */
  213. /* XtPointer cbs - callback data */
  214. /* OUTPUT: none */
  215. /* */
  216. /******************************************************************************/
  217. void closeCB_mainHelpDialog(Widget wid, XtPointer client_data,
  218. XtPointer *cbs)
  219. {
  220. XtDestroyWidget(wid);
  221. mainHelpDialog = NULL;
  222. }
  223. /******************************************************************************/
  224. /* */
  225. /* DisplayHelpDialog */
  226. /* */
  227. /* INPUT: Widget wid - widget id */
  228. /* XtPointer cd - client data */
  229. /* XtPointer cbs - callback data */
  230. /* OUTPUT: none */
  231. /* */
  232. /******************************************************************************/
  233. void DisplayHelpDialog(Widget wid, XtPointer client_data, XtPointer cbs)
  234. {
  235. Widget parent;
  236. int i;
  237. Arg args[10];
  238. char pszTitle[MAXBUFSIZE];
  239. char pszTopic[MAXBUFSIZE];
  240. i = 0;
  241. /***********************************************************************/
  242. /* Get help dialog window title. */
  243. /***********************************************************************/
  244. /*
  245. sprintf(pszTitle, "%s - %s", GETMESSAGE(3, 10, "Create Action"),
  246. GETMESSAGE(2, 53, "Help"));
  247. */
  248. snprintf(pszTitle, sizeof(pszTitle), "%s - %s", GETMESSAGE(3, 10, "Create Action"), GETMESSAGE(2, 53, "Help"));
  249. XtSetArg(args[i], XmNtitle, pszTitle); i++;
  250. /***********************************************************************/
  251. /* Now set the particular helpvolume and topic to view */
  252. /***********************************************************************/
  253. XtSetArg(args[i], DtNhelpType, DtHELP_TYPE_TOPIC); i++;
  254. XtSetArg(args[i], DtNhelpVolume, "CreatAct"); i++;
  255. XtSetArg(args[i], DtNlocationId, pszTopic); i++;
  256. switch ((XtArgVal)client_data) {
  257. case HELP_OVERVIEW:
  258. strcpy(pszTopic, "_hometopic");
  259. break;
  260. case HELP_TASKS:
  261. strcpy(pszTopic, "Tasks");
  262. break;
  263. case HELP_REFERENCE:
  264. strcpy(pszTopic, "Reference");
  265. break;
  266. case HELP_USING:
  267. strcpy(pszTopic, "_HOMETOPIC");
  268. XtSetArg(args[i], DtNhelpVolume, "Help4Help"); i++;
  269. break;
  270. case HELP_ABOUT:
  271. strcpy(pszTopic, "_copyright");
  272. break;
  273. case HELP_ONITEM:
  274. strcpy(pszTopic, "CreateActionMainWindow");
  275. break;
  276. case HELP_ADDFILETYPE:
  277. strcpy(pszTopic, "AddDatatypeWindow");
  278. break;
  279. case HELP_FILECHAR:
  280. strcpy(pszTopic, "DatatypeCriteriaWindow");
  281. break;
  282. case HELP_ICONSELECTOR:
  283. strcpy(pszTopic, "FindIconSetDialog");
  284. break;
  285. case HELP_OPENFILE:
  286. strcpy(pszTopic, "openDialog");
  287. break;
  288. }
  289. /***********************************************************************/
  290. /* Create the Help dialog. */
  291. /***********************************************************************/
  292. /* **** old method of getting parent ****
  293. XtVaGetValues(wid, XmNuserData, &parent, NULL);
  294. if (!parent) {
  295. parent = wid;
  296. }
  297. */
  298. parent = GetTrueToplevel(wid);
  299. TurnOnHourGlassAllWindows();
  300. if ( mainHelpDialog == NULL ) {
  301. mainHelpDialog = DtCreateHelpDialog(parent, "mainHelpDialog", args, i);
  302. XtAddCallback(mainHelpDialog, DtNcloseCallback,
  303. (void (*)())closeCB_mainHelpDialog,
  304. (XtPointer)NULL);
  305. XtManageChild(mainHelpDialog);
  306. } else {
  307. XtSetValues( mainHelpDialog, args, i );
  308. }
  309. TurnOffHourGlassAllWindows();
  310. }
  311. /******************************************************************************/
  312. /* */
  313. /* helpCB_general */
  314. /* */
  315. /* INPUT: Widget wid - widget id */
  316. /* XtPointer cd - client data */
  317. /* XtPointer cbs - callback data */
  318. /* OUTPUT: none */
  319. /* */
  320. /******************************************************************************/
  321. void helpCB_general(Widget UxWidget,
  322. XtPointer UxClientData,
  323. XtPointer UxCallbackArg)
  324. {
  325. DisplayHelpDialog(UxWidget, UxClientData, UxCallbackArg);
  326. }