cmnrtns.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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: cmnrtns.c /main/4 1995/11/01 16:11:08 rswiston $ */
  24. /*****************************************************************************/
  25. /* */
  26. /* cmnrnts.c */
  27. /* */
  28. /* Common routines */
  29. /* */
  30. /*****************************************************************************/
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <unistd.h>
  34. #include <Dt/Icon.h>
  35. #include <X11/cursorfont.h>
  36. #include "UxXt.h"
  37. #include <libgen.h>
  38. #include <Dt/HourGlass.h>
  39. #include "dtcreate.h"
  40. #include "CreateActionAppShell.h"
  41. #include "fileio.h"
  42. #include "cmnrtns.h"
  43. /*****************************************************************************/
  44. /* */
  45. /* ReplaceSpaces */
  46. /* */
  47. /*****************************************************************************/
  48. char * ReplaceSpaces(char *pszName)
  49. {
  50. char *newName;
  51. char *ptr;
  52. newName = (char *)XtMalloc(strlen(pszName) + 1);
  53. memset(newName, 0, strlen(pszName) + 1);
  54. strcpy(newName, pszName);
  55. ptr = strrchr(newName, ' ');
  56. if (ptr) {
  57. ptr = newName;
  58. while ((*ptr) && (ptr = strchr(ptr, ' '))) {
  59. *ptr = '_';
  60. ptr++;
  61. }
  62. }
  63. return(newName);
  64. }
  65. #if 0
  66. /*****************************************************************************/
  67. /* */
  68. /* GetExtName */
  69. /* */
  70. /*****************************************************************************/
  71. char * GetExtName(char *pszFileName)
  72. {
  73. char *type;
  74. type = strrchr(pszFileName, '.');
  75. if (type) {
  76. type = strtok(type, ".");
  77. return(type);
  78. } else {
  79. return(NULL);
  80. }
  81. }
  82. #endif
  83. #if 0
  84. /*****************************************************************************/
  85. /* */
  86. /* GetPathName */
  87. /* */
  88. /*****************************************************************************/
  89. char * GetPathName(char *pszFileName)
  90. {
  91. char *ptr;
  92. char *pszPath;
  93. pszPath = (char *)malloc(strlen(pszFileName) + 1);
  94. strcpy(pszPath, pszFileName);
  95. ptr = strrchr(pszPath, '/');
  96. if (ptr) {
  97. *ptr = '\0';
  98. } else {
  99. free(pszPath);
  100. pszPath = (char *)NULL;
  101. }
  102. return(pszPath);
  103. }
  104. #endif
  105. #if 0
  106. /*****************************************************************************/
  107. /* */
  108. /* Change_IconGadget_IconType */
  109. /* */
  110. /*****************************************************************************/
  111. void Change_IconGadget_IconType(Widget widIconGadget, char *pszNewType)
  112. {
  113. char *pszOldName;
  114. char pszNewName[MAXBUFSIZE];
  115. char *tmpptr;
  116. ushort rc;
  117. XtVaGetValues(widIconGadget, XmNimageName, &pszOldName, NULL);
  118. if (pszOldName) {
  119. tmpptr = strrchr(pszOldName, '.');
  120. *tmpptr = '\0';
  121. sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
  122. #ifdef DEBUG
  123. printf("monochrome name is '%s'\n", pszNewName); /* debug */
  124. #endif
  125. if (check_file_exists(pszNewName)) {
  126. SET_ICONGADGET_ICON(widIconGadget, pszNewName);
  127. } else {
  128. SET_ICONGADGET_ICON(widIconGadget, "");
  129. }
  130. }
  131. }
  132. #endif
  133. #if 0
  134. /*****************************************************************************/
  135. /* */
  136. /* Change_IconName_IconType */
  137. /* */
  138. /*****************************************************************************/
  139. char * Change_IconName_IconType(char *pszOldName, char *pszNewType)
  140. {
  141. char *tmpptr;
  142. ushort rc;
  143. char *pszNewName = (char *)NULL;
  144. if (pszOldName) {
  145. pszNewName = (char *)malloc(strlen(pszOldName) + 10);
  146. tmpptr = strrchr(pszOldName, '.');
  147. *tmpptr = '\0';
  148. sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
  149. #ifdef DEBUG
  150. printf("new icon name is '%s'\n", pszNewName);
  151. #endif
  152. if (!check_file_exists(pszNewName)) {
  153. free(pszNewName);
  154. pszNewName = (char *)NULL;
  155. }
  156. }
  157. return(pszNewName);
  158. }
  159. #endif
  160. /******************************************************************************/
  161. /* */
  162. /* GetCoreName */
  163. /* */
  164. /******************************************************************************/
  165. char * GetCoreName(char *pszFullName)
  166. {
  167. char *name;
  168. char *ptr;
  169. char *newName;
  170. name = strrchr(pszFullName, '/');
  171. if (name) {
  172. name = strtok(name, "/");
  173. } else {
  174. name = pszFullName;
  175. }
  176. newName = (char *)malloc(strlen(name) + 1);
  177. memset(newName, 0, strlen(name) + 1);
  178. strcpy(newName, name);
  179. ptr = strrchr(newName, '.');
  180. if (ptr) {
  181. *ptr = '\0';
  182. }
  183. return(newName);
  184. }
  185. /******************************************************************************/
  186. /* */
  187. /* load_icons - puts selected icons into the appropriate icon gadget. */
  188. /* */
  189. /* INPUT: Widget wid - OK button on Open File dialog, */
  190. /* XtPointer client_data */
  191. /* XmFileSelectionBoxCallbackStruct *cbs */
  192. /* OUTPUT: none */
  193. /* */
  194. /******************************************************************************/
  195. void load_icons (Widget wid, XtPointer client_data,
  196. XmFileSelectionBoxCallbackStruct *cbs)
  197. {
  198. char *full_name, *path_and_base_name, *type_name, *size_name;
  199. char *base_name;
  200. char *ptr;
  201. XtArgVal /* int */ iSource;
  202. FiletypeData *pFtD;
  203. /*****************************************/
  204. /* Get icon name and separate into parts */
  205. /*****************************************/
  206. full_name = (char *)client_data;
  207. path_and_base_name = (char *)malloc(strlen(full_name)+1);
  208. strcpy(path_and_base_name, full_name);
  209. /*****************************************/
  210. /* Strip off icon type extension. */
  211. /*****************************************/
  212. ptr = strrchr(path_and_base_name, '.');
  213. if (ptr) {
  214. type_name = strtok(ptr, ".");
  215. *ptr = '\0';
  216. } else {
  217. type_name = (char *)NULL;
  218. }
  219. /*****************************************/
  220. /* Get size extention. */
  221. /*****************************************/
  222. ptr = strrchr(path_and_base_name, '.');
  223. if (ptr) {
  224. size_name = strtok(ptr, ".");
  225. *ptr = '\0';
  226. } else {
  227. size_name = (char *)NULL;
  228. }
  229. #ifdef DEBUG
  230. printf("path&base = %s\n", path_and_base_name); /* debug */
  231. printf("type = %s\n", type_name); /* debug */
  232. printf("size = %s\n", size_name); /* debug */
  233. #endif
  234. /* ***** cmvc 6715 *****
  235. if ((!path_and_base_name) || (!type_name) || (!size_name)) {
  236. printf ("'%s' is not a proper icon file name!\n", full_name);
  237. }
  238. else
  239. */
  240. {
  241. XtVaGetValues(IconSelector, XmNuserData, &iSource, NULL);
  242. base_name = basename(path_and_base_name);
  243. ptr = XtMalloc(strlen(base_name) + 1);
  244. strcpy(ptr, base_name);
  245. switch (iSource) {
  246. case CA_ACTION_ICONS:
  247. AD.pszIcon = ptr;
  248. SetIconData(CA_LRG_IconGadget, path_and_base_name, Large_Icon);
  249. SetIconData(CA_MED_IconGadget, path_and_base_name, Medium_Icon);
  250. SetIconData(CA_TINY_IconGadget, path_and_base_name, Tiny_Icon);
  251. break;
  252. case CA_FILETYPE_ICONS:
  253. XtVaGetValues(AddFiletype, XmNuserData, &pFtD, NULL);
  254. pFtD->pszIcon = ptr;
  255. SetIconData(AF_MED_IconGadget, path_and_base_name, Medium_Icon);
  256. SetIconData(AF_TINY_IconGadget, path_and_base_name, Tiny_Icon);
  257. break;
  258. }
  259. }
  260. free(path_and_base_name);
  261. return;
  262. }
  263. /******************************************************************************/
  264. /* */
  265. /* GetWidgetTextString */
  266. /* */
  267. /* INPUT: Widget wid - TextField widget to get string from. */
  268. /* Pointer to variable to store string */
  269. /* */
  270. /* OUTPUT: none */
  271. /* */
  272. /******************************************************************************/
  273. void GetWidgetTextString (Widget wid, char **ppszText)
  274. {
  275. char *pszTmp = NULL;
  276. if (*ppszText) {
  277. XtFree(*ppszText);
  278. *ppszText = (char *)NULL;
  279. }
  280. if (XmIsTextField(wid)) {
  281. pszTmp = XmTextFieldGetString (wid);
  282. } else if (XmIsText(wid)) {
  283. pszTmp = XmTextGetString (wid);
  284. }
  285. if (pszTmp) {
  286. if (!strcmp(pszTmp, "")) {
  287. XtFree(pszTmp);
  288. pszTmp = (char *)NULL;
  289. }
  290. *ppszText = pszTmp;
  291. }
  292. }
  293. /******************************************************************************/
  294. /* */
  295. /* PutWidgetTextString */
  296. /* */
  297. /* INPUT: Widget wid - Widget whose text string is being set */
  298. /* Pointer to text string. */
  299. /* */
  300. /* OUTPUT: none */
  301. /* */
  302. /******************************************************************************/
  303. void PutWidgetTextString (Widget wid, char *pszText)
  304. {
  305. if (pszText) {
  306. if (XmIsTextField(wid)) {
  307. XmTextFieldSetString (wid, pszText);
  308. } else if (XmIsText(wid)) {
  309. XmTextSetString (wid, pszText);
  310. }
  311. }
  312. }
  313. /******************************************************************************/
  314. /* */
  315. /* GetIconSearchPathList */
  316. /* */
  317. /* INPUT: none */
  318. /* */
  319. /* OUTPUT: none */
  320. /* */
  321. /******************************************************************************/
  322. char **GetIconSearchPathList(void)
  323. {
  324. char *iconpath = (char *)NULL;
  325. char *ptr;
  326. char *tmpptr;
  327. char *strip;
  328. char *path;
  329. int i;
  330. int count;
  331. int size;
  332. char **pplist;
  333. char *lang;
  334. int langsize;
  335. static char *default_list1[] = {"~/.dt/icons", "/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
  336. static char *default_list2[] = {"/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
  337. char **default_list;
  338. Boolean bFound;
  339. char *pszEnvVar;
  340. /**************************************************************************/
  341. /* Get contents of icon search path environment variable. */
  342. /**************************************************************************/
  343. pszEnvVar = getenv("XMICONSEARCHPATH");
  344. if ( pszEnvVar && strlen(pszEnvVar) ) {
  345. iconpath = (char *)malloc(strlen(pszEnvVar) + 1);
  346. strcpy(iconpath, pszEnvVar);
  347. }
  348. /**************************************************************************/
  349. /* If no iconpath then return an appropriate default. */
  350. /**************************************************************************/
  351. if (!iconpath) {
  352. pszEnvVar = getenv("HOME");
  353. if (pszEnvVar && strlen(pszEnvVar)) {
  354. default_list = default_list1;
  355. count = sizeof(default_list1)/sizeof(void *);
  356. } else {
  357. default_list = default_list2;
  358. count = sizeof(default_list2)/sizeof(void *);
  359. }
  360. pplist = (char **)calloc((count + 1), sizeof(void *));
  361. for (i=0; i < count; i++) {
  362. if (strchr(default_list[i], '~')) {
  363. if (pszEnvVar && strlen(pszEnvVar)) {
  364. pplist[i] = calloc(strlen(default_list[i]) + strlen(pszEnvVar) + 1, sizeof(char));
  365. strcpy(pplist[i], pszEnvVar);
  366. } else {
  367. pplist[i] = calloc(strlen(default_list[i]) + 1, sizeof(char));
  368. }
  369. strcat(pplist[i], &(default_list[i][1]));
  370. } else {
  371. pplist[i] = calloc(strlen(default_list[i]) + 1,sizeof(char));
  372. strcpy(pplist[i], default_list[i]);
  373. }
  374. }
  375. return(pplist);
  376. }
  377. #ifdef DEBUG
  378. printf("Path = %s\n", iconpath);
  379. #endif
  380. /**************************************************************************/
  381. /* Iterate through the search path once to get total count of individual */
  382. /* paths within the search path. */
  383. /**************************************************************************/
  384. count = 0;
  385. ptr = iconpath;
  386. while (ptr) {
  387. tmpptr = ptr;
  388. ptr = strchr(ptr, ':');
  389. /*printf("ptr = %s\n", ptr);*/
  390. if (tmpptr != ptr) {
  391. count++;
  392. if ((ptr) && (ptr[1] != '\0')) {
  393. for (; ptr[0] == ':'; ptr++);
  394. } else {
  395. ptr = (char *)NULL;
  396. }
  397. }
  398. }
  399. /**************************************************************************/
  400. /* Debug information. */
  401. /**************************************************************************/
  402. #ifdef DEBUG
  403. printf("IconSearchPath = %s\n", iconpath);
  404. printf("# of paths = %d\n", count);
  405. #endif
  406. /**************************************************************************/
  407. /* Get contents of lang environment variable. */
  408. /**************************************************************************/
  409. lang = getenv("LANG");
  410. if (lang) {
  411. langsize = strlen(lang);
  412. } else {
  413. langsize = 0;
  414. }
  415. /**************************************************************************/
  416. /* Allocate the array of pointers to store the individual path strings. */
  417. /**************************************************************************/
  418. pplist = (char **)calloc((count+1), sizeof(void *));
  419. /**************************************************************************/
  420. /* Iterate through again to allocate space for each individual path and */
  421. /* store that path. */
  422. /**************************************************************************/
  423. count = 0;
  424. ptr = iconpath;
  425. while (ptr) {
  426. tmpptr = ptr;
  427. ptr = strchr(ptr, ':');
  428. if (tmpptr != ptr) {
  429. /*********************************************************************/
  430. /* Make tmpptr the path. Also move to the next path in the search */
  431. /* path. */
  432. /*********************************************************************/
  433. strip = ptr;
  434. if ((ptr) && (ptr[1] != '\0')) {
  435. for (; ptr[0] == ':'; ptr++);
  436. *strip = '\0';
  437. } else {
  438. if (ptr) {
  439. *strip = '\0';
  440. }
  441. ptr = (char *)NULL;
  442. }
  443. /*********************************************************************/
  444. /* If %L in path, then add size of lang variable to it when */
  445. /* allocating array for path. */
  446. /*********************************************************************/
  447. if (strip = strstr(tmpptr, "%L")) {
  448. path = malloc(strlen(tmpptr) + langsize + 1);
  449. } else {
  450. path = malloc(strlen(tmpptr) + 1);
  451. }
  452. strcpy(path, tmpptr);
  453. /*********************************************************************/
  454. /* Strip off the /%B... stuff off of the path if there is some. */
  455. /*********************************************************************/
  456. if (strip = strstr(path, "%B")) {
  457. *strip = '\0';
  458. }
  459. /*********************************************************************/
  460. /* Now replace %L with lang variable. */
  461. /*********************************************************************/
  462. if (strip = strstr(path, "%L")) {
  463. *strip = '\0';
  464. if (langsize) {
  465. strcat(path, lang);
  466. }
  467. }
  468. /*********************************************************************/
  469. /* Remove slash from end of path if there is one. */
  470. /*********************************************************************/
  471. size = strlen(path);
  472. if (size > 0) {
  473. if (path[size - 1] == '/') {
  474. path[size - 1] = '\0';
  475. }
  476. #ifdef DEBUG
  477. printf("new path = %s\n", path);
  478. #endif
  479. /***************************************************************/
  480. /* See if path is already in our list. */
  481. /***************************************************************/
  482. bFound = FALSE;
  483. for (i=0; (i < count) && (!bFound); i++) {
  484. if (!(strcmp(pplist[i], path))) {
  485. bFound = TRUE;
  486. }
  487. }
  488. /***************************************************************/
  489. /* If not in list, then add to list. */
  490. /***************************************************************/
  491. if (!bFound) {
  492. pplist[count] = path;
  493. count++;
  494. /***************************************************************/
  495. /* Else, just free resources. */
  496. /***************************************************************/
  497. } else {
  498. free(path);
  499. }
  500. }
  501. #ifdef DEBUG
  502. printf("Path%d = %s\n", count, pplist[count]);
  503. #endif
  504. #if 0
  505. **** moving this up a bit in the code ****
  506. /*********************************************************************/
  507. /* Get the next path in the icon search path. */
  508. /*********************************************************************/
  509. if ((ptr) && (ptr[1] != '\0')) {
  510. for (; ptr[0] == ':'; ptr++);
  511. } else {
  512. ptr = (char *)NULL;
  513. }
  514. #endif
  515. }
  516. }
  517. free(iconpath);
  518. return(pplist);
  519. }
  520. /******************************************************************************/
  521. /* */
  522. /* FreeIconSearchPathList */
  523. /* */
  524. /* INPUT: none */
  525. /* */
  526. /* OUTPUT: none */
  527. /* */
  528. /******************************************************************************/
  529. void FreeIconSearchPathList(char **pplist)
  530. {
  531. char *ptr;
  532. int i;
  533. /**************************************************************************/
  534. /* Iterate through the search path once to get total count of individual */
  535. /* paths within the search path. */
  536. /**************************************************************************/
  537. if (pplist) {
  538. for (i = 0; pplist[i]; free(pplist[i]), i++);
  539. /*
  540. i = 0;
  541. while (pplist[i]) {
  542. free(pplist[i]);
  543. }
  544. */
  545. free(pplist);
  546. }
  547. }
  548. /******************************************************************************/
  549. /* */
  550. /* TurnOnHourGlassAllWindows */
  551. /* */
  552. /* INPUT: none */
  553. /* */
  554. /* OUTPUT: none */
  555. /* */
  556. /******************************************************************************/
  557. void TurnOnHourGlassAllWindows(void)
  558. {
  559. _DtTurnOnHourGlass(CreateActionAppShell);
  560. if ( (AddFiletype) &&
  561. (XtIsRealized(AddFiletype)) &&
  562. (XtIsManaged(AddFiletype)) ) {
  563. _DtTurnOnHourGlass(AddFiletype);
  564. }
  565. if ( (FileCharacteristics) &&
  566. (XtIsRealized(FileCharacteristics)) &&
  567. (XtIsManaged(FileCharacteristics)) ) {
  568. _DtTurnOnHourGlass(FileCharacteristics);
  569. }
  570. if ( (IconSelector) &&
  571. (XtIsRealized(IconSelector)) &&
  572. (XtIsManaged(IconSelector)) ) {
  573. _DtTurnOnHourGlass(IconSelector);
  574. }
  575. if ( (OpenFile) &&
  576. (XtIsRealized(OpenFile)) &&
  577. (XtIsManaged(OpenFile)) ) {
  578. _DtTurnOnHourGlass(OpenFile);
  579. }
  580. }
  581. /******************************************************************************/
  582. /* */
  583. /* TurnOffHourGlassAllWindows */
  584. /* */
  585. /* INPUT: none */
  586. /* */
  587. /* OUTPUT: none */
  588. /* */
  589. /******************************************************************************/
  590. void TurnOffHourGlassAllWindows(void)
  591. {
  592. _DtTurnOffHourGlass(CreateActionAppShell);
  593. if ( (AddFiletype) &&
  594. (XtIsRealized(AddFiletype)) &&
  595. (XtIsManaged(AddFiletype)) ) {
  596. _DtTurnOffHourGlass(AddFiletype);
  597. }
  598. if ( (FileCharacteristics) &&
  599. (XtIsRealized(FileCharacteristics)) &&
  600. (XtIsManaged(FileCharacteristics)) ) {
  601. _DtTurnOffHourGlass(FileCharacteristics);
  602. }
  603. if ( (IconSelector) &&
  604. (XtIsRealized(IconSelector)) &&
  605. (XtIsManaged(IconSelector)) ) {
  606. _DtTurnOffHourGlass(IconSelector);
  607. }
  608. if ( (OpenFile) &&
  609. (XtIsRealized(OpenFile)) &&
  610. (XtIsManaged(OpenFile)) ) {
  611. _DtTurnOffHourGlass(OpenFile);
  612. }
  613. }
  614. /******************************************************************************/
  615. /* */
  616. /* SetIconData */
  617. /* */
  618. /* INPUT: icon gadget widget id */
  619. /* icon file base name */
  620. /* */
  621. /* OUTPUT: none */
  622. /* */
  623. /******************************************************************************/
  624. void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSize)
  625. {
  626. char pmFileName[MAXBUFSIZE];
  627. char bmFileName[MAXBUFSIZE];
  628. char pszSize[MAX_EXT_SIZE];
  629. IconData *pIconData;
  630. char *pszName;
  631. #if 0
  632. switch (enumIconSize) {
  633. case Large_Icon :
  634. strcpy(pszSize, LARGE_EXT);
  635. break;
  636. case Medium_Icon :
  637. strcpy(pszSize, MEDIUM_EXT);
  638. break;
  639. case Tiny_Icon :
  640. strcpy(pszSize, TINY_EXT);
  641. break;
  642. }
  643. sprintf(pmFileName, "%s%s%s", pszIconFile, pszSize, PIXMAP_EXT );
  644. sprintf(bmFileName, "%s%s%s", pszIconFile, pszSize, BITMAP_EXT );
  645. #endif
  646. pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, PIXMAP_EXT, FALSE);
  647. snprintf(pmFileName, sizeof(pmFileName), "%s", pszName);
  648. XtFree(pszName);
  649. pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, BITMAP_EXT, FALSE);
  650. snprintf(bmFileName, sizeof(bmFileName), "%s", pszName);
  651. XtFree(pszName);
  652. pIconData = GetIconDataFromWid(wid);
  653. if (pIconData) {
  654. if ( (pIconData->pmDirtyBit) &&
  655. (pIconData->pmFileName) &&
  656. (strlen(pIconData->pmFileName)) ) {
  657. #ifdef DEBUG
  658. printf("SetIconData: unlink '%s'\n", pIconData->pmFileName); /* debug */
  659. #endif
  660. unlink(pIconData->pmFileName);
  661. pIconData->pmDirtyBit = False;
  662. }
  663. strcpy(pIconData->pmFileName, pmFileName);
  664. if ( (pIconData->bmDirtyBit) &&
  665. (strlen(pIconData->bmFileName)) ) {
  666. #ifdef DEBUG
  667. printf("SetIconData: unlink '%s'\n", pIconData->bmFileName); /* debug */
  668. #endif
  669. unlink(pIconData->bmFileName);
  670. pIconData->bmDirtyBit = False;
  671. }
  672. strcpy(pIconData->bmFileName, bmFileName);
  673. if (bShowPixmaps) {
  674. SET_ICONGADGET_ICON(wid, pmFileName);
  675. } else {
  676. SET_ICONGADGET_ICON(wid, bmFileName);
  677. }
  678. }
  679. }
  680. /******************************************************************************/
  681. /* */
  682. /* GetCorrectIconType */
  683. /* */
  684. /* INPUT: icon file name */
  685. /* */
  686. /* OUTPUT: correct icon type of icon file name passed */
  687. /* */
  688. /******************************************************************************/
  689. char * GetCorrectIconType(char *pszIconFile)
  690. {
  691. char *pszTmp;
  692. char *ptr;
  693. char pszNewType[MAX_EXT_SIZE];
  694. if (bShowPixmaps) {
  695. strcpy(pszNewType, PIXMAP_EXT);
  696. } else {
  697. strcpy(pszNewType, BITMAP_EXT);
  698. }
  699. if (pszIconFile) {
  700. pszTmp = XtMalloc(strlen(pszIconFile) + strlen(pszNewType) + 1);
  701. if (!pszTmp) return((char *)NULL);
  702. strcpy(pszTmp, pszIconFile);
  703. ptr = strrchr(pszTmp, '.');
  704. if (ptr) {
  705. strcpy(ptr, pszNewType);
  706. }
  707. } else {
  708. pszTmp = (char *)NULL;
  709. }
  710. return (pszTmp);
  711. }
  712. /******************************************************************************/
  713. /* */
  714. /* CreateMaskName */
  715. /* */
  716. /* INPUT: icon file name */
  717. /* */
  718. /* OUTPUT: mask file name for icon name passed in */
  719. /* */
  720. /******************************************************************************/
  721. char * CreateMaskName(char *pszIconName)
  722. {
  723. char *pszTmpName;
  724. char *ptr;
  725. char *pszNewName;
  726. char *type_name;
  727. char *size_name;
  728. char type_ext[MAX_EXT_SIZE + 2];
  729. char size_ext[MAX_EXT_SIZE + 2];
  730. int bytesneeded = 0;
  731. /***************************************************************/
  732. /* initialize temp arrays */
  733. /***************************************************************/
  734. type_ext[0] = '\0';
  735. size_ext[0] = '\0';
  736. /***************************************************************/
  737. /* alloc memory for temporary name */
  738. /***************************************************************/
  739. pszTmpName = (char *)XtMalloc(strlen(pszIconName) + 1);
  740. if (pszTmpName) {
  741. strcpy(pszTmpName, pszIconName);
  742. } else {
  743. return((char *)NULL);
  744. }
  745. /*****************************************/
  746. /* Strip off icon type extension. */
  747. /*****************************************/
  748. ptr = strrchr(pszTmpName, '.');
  749. if (ptr) {
  750. type_name = strtok(ptr, ".");
  751. *ptr = '\0';
  752. } else {
  753. type_name = (char *)NULL;
  754. }
  755. /*****************************************/
  756. /* Get size extention. */
  757. /*****************************************/
  758. ptr = strrchr(pszTmpName, '.');
  759. if (ptr) {
  760. size_name = strtok(ptr, ".");
  761. *ptr = '\0';
  762. } else {
  763. size_name = (char *)NULL;
  764. }
  765. /*****************************************/
  766. /* Alloc the storage for the new name */
  767. /*****************************************/
  768. bytesneeded += ((pszTmpName) ? strlen(pszTmpName) : 0);
  769. bytesneeded += strlen("_m..");
  770. bytesneeded += ((size_name) ? strlen(size_name) : 0);
  771. bytesneeded += ((type_name) ? strlen(type_name) : 0);
  772. pszNewName = (char *)XtMalloc(bytesneeded + 1);
  773. /*****************************************/
  774. /* Create extension names */
  775. /*****************************************/
  776. if (size_name) {
  777. sprintf(size_ext, ".%s", size_name);
  778. }
  779. if (type_name) {
  780. sprintf(type_ext, ".%s", type_name);
  781. }
  782. /*****************************************/
  783. /* And construct the new name from pieces*/
  784. /*****************************************/
  785. if (pszNewName) {
  786. if (size_name) {
  787. sprintf(pszNewName, "%s%s_m%s", pszTmpName, size_ext, type_ext);
  788. } else {
  789. sprintf(pszNewName, "%s_m%s%s", pszTmpName, size_ext, type_ext);
  790. }
  791. }
  792. if (pszTmpName) XtFree(pszTmpName);
  793. #ifdef DEBUG
  794. printf("Mask file name = '%s'\n", pszNewName); /* debug */
  795. #endif
  796. return(pszNewName);
  797. }