af_aux.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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: af_aux.c /main/6 1998/04/06 13:14:19 mgreess $ */
  24. /******************************************************************************/
  25. /* */
  26. /* af_aux - auxiliary functions for add filetype */
  27. /* */
  28. /* Functions to get/set values from/to interface. */
  29. /* Callback routines for AF interface. */
  30. /* */
  31. /******************************************************************************/
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <sys/signal.h>
  35. #include <errno.h>
  36. #include <unistd.h>
  37. #include <X11/cursorfont.h>
  38. #include <X11/Xlib.h>
  39. #include <X11/Xatom.h>
  40. #include <Xm/Xm.h>
  41. #include <Xm/TextF.h>
  42. #include <Xm/RowColumnP.h>
  43. #include <Xm/MessageB.h>
  44. #include <Xm/FileSB.h>
  45. #include <Xm/List.h>
  46. #include <sys/stat.h>
  47. #if defined(AIXV3)
  48. # include <sys/dir.h>
  49. #else
  50. # if defined(__linux__)
  51. # include <dirent.h>
  52. # else
  53. # include <sys/dirent.h>
  54. # endif
  55. #endif
  56. #include <Dt/Icon.h>
  57. #include "dtcreate.h"
  58. #include "af_aux.h"
  59. #include "cmncbs.h"
  60. #include "cmnutils.h"
  61. #include "cmnrtns.h"
  62. #include "ErrorDialog.h"
  63. #include "FileCharacteristics.h"
  64. /******************************************************************************/
  65. /* */
  66. /* External Variables */
  67. /* */
  68. /******************************************************************************/
  69. /******************************************************************************/
  70. /* */
  71. /* Variables */
  72. /* */
  73. /******************************************************************************/
  74. /******************************************************************************/
  75. /* */
  76. /* CALLBACK FUNCTIONS */
  77. /* */
  78. /******************************************************************************/
  79. /******************************************************************************/
  80. /* */
  81. /* get_selected_filetype_icon - determines which filetype icon is currently */
  82. /* selected. */
  83. /* */
  84. /* INPUT: none */
  85. /* OUTPUT: Widget wid - id of selected icon gadget */
  86. /* */
  87. /******************************************************************************/
  88. Widget get_selected_filetype_icon (void)
  89. {
  90. if (!last_filetype_pushed) {
  91. last_filetype_pushed = AF_MED_IconGadget;
  92. }
  93. return (last_filetype_pushed);
  94. }
  95. /******************************************************************************/
  96. /* */
  97. /* activateCB_filetype_icon */
  98. /* */
  99. /* INPUT: Widget wid - id of icon gadget */
  100. /* XtPointer client_data - not used */
  101. /* XmPushButtonCallbackStruct *cbs - not used */
  102. /* OUTPUT: none */
  103. /* */
  104. /******************************************************************************/
  105. void activateCB_filetype_icon (Widget wid, XtPointer client_data,
  106. DtIconCallbackStruct *cbs)
  107. {
  108. Time lts, mct = 0;
  109. static Time prev_lts = 0;
  110. if (cbs->reason == XmCR_ACTIVATE) {
  111. #ifdef DEBUG
  112. printf("In activate_filetype_icon callback.\n");
  113. #endif
  114. if (last_filetype_pushed && (last_filetype_pushed != wid)) {
  115. XtVaSetValues(XtParent(last_filetype_pushed), XmNborderWidth, 0, NULL);
  116. }
  117. XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
  118. last_filetype_pushed = wid;
  119. /********************************************************************/
  120. /* This is the support needed to provide double-click functionality */
  121. /* to the icon gadgets. When double-clicked, the icon editor will */
  122. /* be launched. */
  123. /********************************************************************/
  124. XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
  125. lts = XtLastTimestampProcessed(XtDisplay(wid));
  126. mct = XtGetMultiClickTime(XtDisplay(wid));
  127. if ((prev_lts + mct) > lts) {
  128. prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
  129. } else {
  130. prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
  131. return;
  132. }
  133. #ifdef DEBUG
  134. printf("DblClick icon callback.\n");
  135. #endif
  136. activateCB_edit_icon(wid, (XtPointer)CA_FILETYPE_ICONS,
  137. (XmPushButtonCallbackStruct *)cbs /* unused anyway */);
  138. }
  139. return;
  140. }
  141. /******************************************************************************/
  142. /* */
  143. /* readAFFromGUI - */
  144. /* */
  145. /* */
  146. /* */
  147. /******************************************************************************/
  148. void readAFFromGUI (FiletypeData *pFiletypedata)
  149. {
  150. getAF_FiletypeName(pFiletypedata);
  151. getAF_HelpText(pFiletypedata);
  152. getAF_OpenCmd(pFiletypedata);
  153. getAF_PrintCmd(pFiletypedata);
  154. getAF_Icons(pFiletypedata);
  155. return;
  156. }
  157. /******************************************************************************/
  158. /* */
  159. /* getAF_FiletypeName - get name of filetype family */
  160. /* */
  161. /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
  162. /* OUTPUT: none */
  163. /* */
  164. /******************************************************************************/
  165. void getAF_FiletypeName (FiletypeData *pFiletypedata)
  166. {
  167. GetWidgetTextString(AF_FileTypeNameTextField, &(pFiletypedata->pszName));
  168. return;
  169. }
  170. /******************************************************************************/
  171. /* */
  172. /* getAF_HelpText - retrieve the Help text for the filetype */
  173. /* */
  174. /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
  175. /* OUTPUT: none */
  176. /* */
  177. /******************************************************************************/
  178. void getAF_HelpText (FiletypeData *pFiletypedata)
  179. {
  180. GetWidgetTextString(AF_FiletypeHelpText, &(pFiletypedata->pszHelp));
  181. return;
  182. }
  183. /******************************************************************************/
  184. /* */
  185. /* getAF_Icons - store temporary icon names. */
  186. /* */
  187. /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
  188. /* OUTPUT: none */
  189. /* */
  190. /******************************************************************************/
  191. void getAF_Icons(FiletypeData *pFiletypedata)
  192. {
  193. IconData *pIconData;
  194. /***************************************************************/
  195. /* Medium Pixmap */
  196. /***************************************************************/
  197. pIconData = GetIconDataFromWid(AF_MED_IconGadget);
  198. if ( (pIconData->pmDirtyBit) &&
  199. (pIconData->pmFileName) &&
  200. (strlen(pIconData->pmFileName)) ) {
  201. pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
  202. if (pFiletypedata->pszMedPmIcon) {
  203. strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
  204. }
  205. }
  206. pIconData->pmDirtyBit = False;
  207. strcpy(pIconData->pmFileName, "");
  208. /***************************************************************/
  209. /* Medium Bitmap */
  210. /***************************************************************/
  211. if ( (pIconData->bmDirtyBit) &&
  212. (pIconData->bmFileName) &&
  213. (strlen(pIconData->bmFileName)) ) {
  214. pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
  215. if (pFiletypedata->pszMedBmIcon) {
  216. strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
  217. }
  218. }
  219. pIconData->bmDirtyBit = False;
  220. strcpy(pIconData->bmFileName, "");
  221. /***************************************************************/
  222. /* Tiny Pixmap */
  223. /***************************************************************/
  224. pIconData = GetIconDataFromWid(AF_TINY_IconGadget);
  225. if ( (pIconData->pmDirtyBit) &&
  226. (pIconData->pmFileName) &&
  227. (strlen(pIconData->pmFileName)) ) {
  228. pFiletypedata->pszTinyPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
  229. if (pFiletypedata->pszTinyPmIcon) {
  230. strcpy(pFiletypedata->pszTinyPmIcon, pIconData->pmFileName);
  231. }
  232. }
  233. pIconData->pmDirtyBit = False;
  234. strcpy(pIconData->pmFileName, "");
  235. /***************************************************************/
  236. /* Tiny Bitmap */
  237. /***************************************************************/
  238. if ( (pIconData->bmDirtyBit) &&
  239. (strlen(pIconData->bmFileName)) ) {
  240. pFiletypedata->pszTinyBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
  241. if (pFiletypedata->pszTinyBmIcon) {
  242. strcpy(pFiletypedata->pszTinyBmIcon, pIconData->bmFileName);
  243. }
  244. }
  245. pIconData->bmDirtyBit = False;
  246. strcpy(pIconData->bmFileName, "");
  247. #if 0
  248. Widget AF_wids[2];
  249. int i;
  250. AF_wids[0] = AF_MED_IconGadget;
  251. AF_wids[1] = AF_TINY_IconGadget;
  252. for (i=0; i < 2; i++) {
  253. /* pixmap */
  254. pIconData = GetIconDataFromWid(AF_wids[i]);
  255. if ( (pIconData->pmDirtyBit) &&
  256. (pIconData->pmFileName) &&
  257. (strlen(pIconData->pmFileName)) ) {
  258. pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
  259. if (pFiletypedata->pszMedPmIcon) {
  260. strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
  261. }
  262. }
  263. pIconData->pmDirtyBit = False;
  264. strcpy(pIconData->pmFileName, "");
  265. /* bitmap */
  266. if ( (pIconData->bmDirtyBit) &&
  267. (pIconData->bmFileName) &&
  268. (strlen(pIconData->bmFileName)) ) {
  269. pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
  270. if (pFiletypedata->pszMedBmIcon) {
  271. strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
  272. }
  273. }
  274. pIconData->bmDirtyBit = False;
  275. strcpy(pIconData->bmFileName, "");
  276. }
  277. #endif
  278. }
  279. /******************************************************************************/
  280. /* */
  281. /* getAF_OpenCmd - retrieve the Open command string */
  282. /* */
  283. /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
  284. /* OUTPUT: none */
  285. /* */
  286. /******************************************************************************/
  287. void getAF_OpenCmd (FiletypeData *pFiletypedata)
  288. {
  289. GetWidgetTextString(AF_OpenCmdText, &(pFiletypedata->pszOpenCmd));
  290. return;
  291. }
  292. /******************************************************************************/
  293. /* */
  294. /* getAF_PrintCmd - retrieve Print command string */
  295. /* */
  296. /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
  297. /* OUTPUT: none */
  298. /* */
  299. /******************************************************************************/
  300. void getAF_PrintCmd (FiletypeData *pFiletypedata)
  301. {
  302. GetWidgetTextString(AF_FiletypePrintCmdTextField, &(pFiletypedata->pszPrintCmd));
  303. return;
  304. }
  305. /******************************************************************************/
  306. /* */
  307. /* init_AddFiletype_dialog_fields */
  308. /* */
  309. /* INPUT: FiletypeData * - pointer to FiletypeData structure */
  310. /* OUTPUT: none */
  311. /* */
  312. /******************************************************************************/
  313. void init_AddFiletype_dialog_fields(FiletypeData *pFtD)
  314. {
  315. char *pszIconFileName = (char *)NULL;
  316. char *pszTmpFile;
  317. if (pFtD->pszName) {
  318. PutWidgetTextString(AF_FileTypeNameTextField, pFtD->pszName);
  319. }
  320. ParseAndUpdateID(pFtD);
  321. if (pFtD->pszHelp) {
  322. PutWidgetTextString(AF_FiletypeHelpText, pFtD->pszHelp);
  323. }
  324. if (pFtD->pszIcon) {
  325. if (bShowPixmaps) {
  326. /*************************/
  327. /* Medium Pixmap */
  328. /*************************/
  329. if (pFtD->pszMedPmIcon) {
  330. SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedPmIcon);
  331. } else {
  332. pszIconFileName = (char *)NULL;
  333. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
  334. pszTmpFile = GetCorrectIconType(pszIconFileName);
  335. SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
  336. if (pszIconFileName) XtFree(pszIconFileName);
  337. if (pszTmpFile) XtFree(pszTmpFile);
  338. }
  339. /*************************/
  340. /* Tiny Pixmap */
  341. /*************************/
  342. if (pFtD->pszTinyPmIcon) {
  343. SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyPmIcon);
  344. } else {
  345. pszIconFileName = (char *)NULL;
  346. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
  347. pszTmpFile = GetCorrectIconType(pszIconFileName);
  348. SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
  349. if (pszIconFileName) XtFree(pszIconFileName);
  350. if (pszTmpFile) XtFree(pszTmpFile);
  351. }
  352. } else {
  353. /*************************/
  354. /* Medium Pixmap */
  355. /*************************/
  356. if (pFtD->pszMedBmIcon) {
  357. SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedBmIcon);
  358. } else {
  359. pszIconFileName = (char *)NULL;
  360. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
  361. pszTmpFile = GetCorrectIconType(pszIconFileName);
  362. SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
  363. if (pszIconFileName) XtFree(pszIconFileName);
  364. if (pszTmpFile) XtFree(pszTmpFile);
  365. }
  366. /*************************/
  367. /* Tiny Pixmap */
  368. /*************************/
  369. if (pFtD->pszTinyBmIcon) {
  370. SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyBmIcon);
  371. } else {
  372. pszIconFileName = (char *)NULL;
  373. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
  374. pszTmpFile = GetCorrectIconType(pszIconFileName);
  375. SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
  376. if (pszIconFileName) XtFree(pszIconFileName);
  377. if (pszTmpFile) XtFree(pszTmpFile);
  378. }
  379. }
  380. #if 0
  381. /*************************/
  382. /* Tiny Pixmap */
  383. /*************************/
  384. pszIconFileName = (char *)NULL;
  385. if (pFtD->pszTinyPmIcon) {
  386. pszTmpFile = pFtD->pszTinyPmIcon;
  387. } else {
  388. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
  389. pszTmpFile = pszIconFileName;
  390. }
  391. SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
  392. if (pszIconFileName) XtFree(pszIconFileName);
  393. } else {
  394. /*************************/
  395. /* Medium Bitmap */
  396. /*************************/
  397. pszIconFileName = (char *)NULL;
  398. if (pFtD->pszMedBmIcon) {
  399. pszTmpFile = pFtD->pszMedBmIcon;
  400. } else {
  401. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
  402. pszTmpFile = pszIconFileName;
  403. }
  404. SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
  405. if (pszIconFileName) XtFree(pszIconFileName);
  406. /*************************/
  407. /* Tiny Bitmap */
  408. /*************************/
  409. pszIconFileName = (char *)NULL;
  410. if (pFtD->pszTinyBmIcon) {
  411. pszTmpFile = pFtD->pszTinyBmIcon;
  412. } else {
  413. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
  414. pszTmpFile = pszIconFileName;
  415. }
  416. SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
  417. if (pszIconFileName) XtFree(pszIconFileName);
  418. }
  419. #endif
  420. }
  421. if (pFtD->pszOpenCmd) {
  422. PutWidgetTextString(AF_OpenCmdText, pFtD->pszOpenCmd);
  423. }
  424. if (pFtD->pszPrintCmd) {
  425. PutWidgetTextString(AF_FiletypePrintCmdTextField, pFtD->pszPrintCmd);
  426. }
  427. return;
  428. }
  429. /******************************************************************************/
  430. /* */
  431. /* clear_AddFiletype_dialog_fields */
  432. /* */
  433. /* INPUT: FiletypeData * - pointer to FiletypeData structure */
  434. /* OUTPUT: none */
  435. /* */
  436. /******************************************************************************/
  437. void clear_AddFiletype_dialog_fields(void)
  438. {
  439. /*char pszFile[MAXBUFSIZE];*/
  440. clear_text(AF_FileTypeNameTextField);
  441. clear_text(AF_IdCharacteristicsText);
  442. clear_text(AF_FiletypeHelpText);
  443. createCB_IconGadget(AF_MED_IconGadget, FALSE, Medium_Icon);
  444. createCB_IconGadget(AF_TINY_IconGadget, FALSE, Tiny_Icon);
  445. /*
  446. SET_ICONGADGET_ICON_AND_EXT(AF_MED_IconGadget, af_med_icon_default, pszFile);
  447. SET_ICONGADGET_ICON_AND_EXT(AF_TINY_IconGadget, af_tiny_icon_default, pszFile);
  448. */
  449. clear_text(AF_OpenCmdText);
  450. clear_text(AF_FiletypePrintCmdTextField);
  451. return;
  452. }
  453. /******************************************************************************/
  454. /* */
  455. /* free_Filetypedata */
  456. /* */
  457. /* INPUT: FiletypeData * - pointer to FiletypeData structure */
  458. /* OUTPUT: none */
  459. /* */
  460. /******************************************************************************/
  461. void free_Filetypedata(FiletypeData *pFtD)
  462. {
  463. char buffer[MAXFILENAME];
  464. #ifdef DEBUG
  465. printf("Free FiletypeData structure\n"); /* debug */
  466. #endif
  467. if (pFtD->pszName) XtFree(pFtD->pszName);
  468. #if DEBUG
  469. printf("Freed Name\n");
  470. #endif
  471. if (pFtD->pszIcon) XtFree(pFtD->pszIcon);
  472. if (pFtD->pszMedPmIcon) {
  473. #if DEBUG
  474. printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedPmIcon); /* debug */
  475. #endif
  476. unlink(pFtD->pszMedPmIcon);
  477. XtFree(pFtD->pszMedPmIcon);
  478. }
  479. if (pFtD->pszMedBmIcon) {
  480. #if DEBUG
  481. printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedBmIcon); /* debug */
  482. #endif
  483. unlink(pFtD->pszMedBmIcon);
  484. /**** remove the mask if it exists ****/
  485. sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
  486. unlink(buffer);
  487. XtFree(pFtD->pszMedBmIcon);
  488. }
  489. if (pFtD->pszTinyPmIcon) {
  490. #if DEBUG
  491. printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyPmIcon); /* debug */
  492. #endif
  493. unlink(pFtD->pszTinyPmIcon);
  494. XtFree(pFtD->pszTinyPmIcon);
  495. }
  496. if (pFtD->pszTinyBmIcon) {
  497. #if DEBUG
  498. printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyBmIcon); /* debug */
  499. #endif
  500. unlink(pFtD->pszTinyBmIcon);
  501. /**** remove the mask if it exists ****/
  502. sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
  503. unlink(buffer);
  504. XtFree(pFtD->pszTinyBmIcon);
  505. }
  506. if (pFtD->pszHelp) XtFree(pFtD->pszHelp);
  507. if (pFtD->pszOpenCmd) XtFree(pFtD->pszOpenCmd);
  508. if (pFtD->pszPrintCmd) XtFree(pFtD->pszPrintCmd);
  509. if (pFtD->pszPattern) XtFree(pFtD->pszPattern);
  510. if (pFtD->pszPermissions) XtFree(pFtD->pszPermissions);
  511. if (pFtD->pszContents) XtFree(pFtD->pszContents);
  512. XtFree((char *) pFtD);
  513. return;
  514. }
  515. /******************************************************************************/
  516. /* */
  517. /* AddFiletypeToList */
  518. /* */
  519. /* INPUT: none */
  520. /* OUTPUT: none */
  521. /* */
  522. /******************************************************************************/
  523. void AddFiletypeToList(void)
  524. {
  525. if (!XmListItemExists(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)))) {
  526. XmListAddItem(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)), 0);
  527. }
  528. }
  529. /******************************************************************************/
  530. /* */
  531. /* UpdateFiletypeDataArray */
  532. /* */
  533. /* INPUT: none */
  534. /* OUTPUT: none */
  535. /* */
  536. /******************************************************************************/
  537. void UpdateFiletypeDataArray(FiletypeData *pFtD)
  538. {
  539. FiletypeData **papArray;
  540. int i;
  541. /**************************************************************************/
  542. /* Add this structure to the filetype array in the ActionData structure. */
  543. /**************************************************************************/
  544. papArray = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (AD.cFiletypes + 1));
  545. for (i=0; i < AD.cFiletypes; i++) {
  546. papArray[i] = AD.papFiletypes[i];
  547. }
  548. papArray[AD.cFiletypes] = pFtD;
  549. if (AD.papFiletypes) {
  550. XtFree((char *) AD.papFiletypes);
  551. }
  552. AD.papFiletypes = papArray;
  553. AD.cFiletypes++;
  554. }
  555. /******************************************************************************/
  556. /* */
  557. /* AddFiletypeCheckFields */
  558. /* */
  559. /* INPUT: none */
  560. /* OUTPUT: FALSE - no errors found */
  561. /* TRUE - found errors */
  562. /* */
  563. /******************************************************************************/
  564. Boolean AddFiletypeCheckFields(void)
  565. {
  566. char *ptr = (char *)NULL;
  567. Boolean bError = FALSE;
  568. char *msgPtr, *errPtr;
  569. /**************************************************************************/
  570. /* Check if filetype name is present. */
  571. /**************************************************************************/
  572. if (!bError) {
  573. ptr = (char *)NULL;
  574. GetWidgetTextString(AF_FileTypeNameTextField, &ptr);
  575. #ifdef DEBUG
  576. printf("Filetype Family Name = '%s'\n", ptr);
  577. #endif
  578. if (!ptr) {
  579. msgPtr = GETMESSAGE(8, 10, "The Datatype Family Name is missing.\n\
  580. Enter a name in the 'Name of Datatype Family' field.");
  581. errPtr = XtNewString(msgPtr);
  582. display_error_message(AddFiletype, errPtr);
  583. XtFree(errPtr);
  584. XmProcessTraversal(AF_FileTypeNameTextField, XmTRAVERSE_CURRENT);
  585. bError = TRUE;
  586. } else {
  587. XtFree(ptr);
  588. }
  589. }
  590. /**************************************************************************/
  591. /* Check if identifying characteristics are present. */
  592. /**************************************************************************/
  593. if (!bError) {
  594. ptr = (char *)NULL;
  595. GetWidgetTextString(AF_IdCharacteristicsText, &ptr);
  596. #ifdef DEBUG
  597. printf("Identifying Chars = '%s'\n", ptr);
  598. #endif
  599. if (!ptr) {
  600. msgPtr = GETMESSAGE(8, 15,
  601. "The Identifying Characteristics are missing.\n\
  602. You must specify the characteristics before the datatype\n\
  603. can be created. Select the Edit button next to the\n\
  604. Identifying Characteristics list to specify the characteristics.");
  605. errPtr = XtNewString(msgPtr);
  606. display_error_message(AddFiletype, errPtr);
  607. XtFree(errPtr);
  608. XmProcessTraversal(AF_IdCharacteristicsEdit, XmTRAVERSE_CURRENT);
  609. bError = TRUE;
  610. } else {
  611. XtFree(ptr);
  612. }
  613. }
  614. return(bError);
  615. }