2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: cmnrtns.c /main/4 1995/11/01 16:11:08 rswiston $ */
24 /*****************************************************************************/
30 /*****************************************************************************/
35 #include <X11/cursorfont.h>
38 #include <Dt/HourGlass.h>
41 #include "CreateActionAppShell.h"
45 /*****************************************************************************/
49 /*****************************************************************************/
50 char * ReplaceSpaces(char *pszName)
55 newName = (char *)XtMalloc(strlen(pszName) + 1);
56 memset(newName, 0, strlen(pszName) + 1);
57 strcpy(newName, pszName);
58 ptr = strrchr(newName, ' ');
61 while ((*ptr) && (ptr = strchr(ptr, ' '))) {
70 /*****************************************************************************/
74 /*****************************************************************************/
75 char * GetExtName(char *pszFileName)
79 type = strrchr(pszFileName, '.');
81 type = strtok(type, ".");
90 /*****************************************************************************/
94 /*****************************************************************************/
95 char * GetPathName(char *pszFileName)
100 pszPath = (char *)malloc(strlen(pszFileName) + 1);
101 strcpy(pszPath, pszFileName);
102 ptr = strrchr(pszPath, '/');
107 pszPath = (char *)NULL;
114 /*****************************************************************************/
116 /* Change_IconGadget_IconType */
118 /*****************************************************************************/
119 void Change_IconGadget_IconType(Widget widIconGadget, char *pszNewType)
122 char pszNewName[MAXBUFSIZE];
126 XtVaGetValues(widIconGadget, XmNimageName, &pszOldName, NULL);
128 tmpptr = strrchr(pszOldName, '.');
130 sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
132 printf("monochrome name is '%s'\n", pszNewName); /* debug */
134 if (check_file_exists(pszNewName)) {
135 SET_ICONGADGET_ICON(widIconGadget, pszNewName);
137 SET_ICONGADGET_ICON(widIconGadget, "");
144 /*****************************************************************************/
146 /* Change_IconName_IconType */
148 /*****************************************************************************/
149 char * Change_IconName_IconType(char *pszOldName, char *pszNewType)
153 char *pszNewName = (char *)NULL;
156 pszNewName = (char *)malloc(strlen(pszOldName) + 10);
157 tmpptr = strrchr(pszOldName, '.');
159 sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
161 printf("new icon name is '%s'\n", pszNewName);
163 if (!check_file_exists(pszNewName)) {
165 pszNewName = (char *)NULL;
172 /******************************************************************************/
176 /******************************************************************************/
177 char * GetCoreName(char *pszFullName)
183 name = strrchr(pszFullName, '/');
185 name = strtok(name, "/");
189 newName = (char *)malloc(strlen(name) + 1);
190 memset(newName, 0, strlen(name) + 1);
191 strcpy(newName, name);
192 ptr = strrchr(newName, '.');
199 /******************************************************************************/
201 /* load_icons - puts selected icons into the appropriate icon gadget. */
203 /* INPUT: Widget wid - OK button on Open File dialog, */
204 /* XtPointer client_data */
205 /* XmFileSelectionBoxCallbackStruct *cbs */
208 /******************************************************************************/
209 void load_icons (Widget wid, XtPointer client_data,
210 XmFileSelectionBoxCallbackStruct *cbs)
212 char *full_name, *path_and_base_name, *type_name, *size_name;
215 XtArgVal /* int */ iSource;
218 /*****************************************/
219 /* Get icon name and separate into parts */
220 /*****************************************/
221 full_name = (char *)client_data;
222 path_and_base_name = (char *)malloc(strlen(full_name)+1);
223 strcpy(path_and_base_name, full_name);
225 /*****************************************/
226 /* Strip off icon type extension. */
227 /*****************************************/
228 ptr = strrchr(path_and_base_name, '.');
230 type_name = strtok(ptr, ".");
233 type_name = (char *)NULL;
236 /*****************************************/
237 /* Get size extention. */
238 /*****************************************/
239 ptr = strrchr(path_and_base_name, '.');
241 size_name = strtok(ptr, ".");
244 size_name = (char *)NULL;
248 printf("path&base = %s\n", path_and_base_name); /* debug */
249 printf("type = %s\n", type_name); /* debug */
250 printf("size = %s\n", size_name); /* debug */
253 /* ***** cmvc 6715 *****
254 if ((!path_and_base_name) || (!type_name) || (!size_name)) {
255 printf ("'%s' is not a proper icon file name!\n", full_name);
260 XtVaGetValues(IconSelector, XmNuserData, &iSource, NULL);
261 base_name = basename(path_and_base_name);
262 ptr = XtMalloc(strlen(base_name) + 1);
263 strcpy(ptr, base_name);
265 case CA_ACTION_ICONS:
267 SetIconData(CA_LRG_IconGadget, path_and_base_name, Large_Icon);
268 SetIconData(CA_MED_IconGadget, path_and_base_name, Medium_Icon);
269 SetIconData(CA_TINY_IconGadget, path_and_base_name, Tiny_Icon);
271 case CA_FILETYPE_ICONS:
272 XtVaGetValues(AddFiletype, XmNuserData, &pFtD, NULL);
274 SetIconData(AF_MED_IconGadget, path_and_base_name, Medium_Icon);
275 SetIconData(AF_TINY_IconGadget, path_and_base_name, Tiny_Icon);
279 free(path_and_base_name);
283 /******************************************************************************/
285 /* GetWidgetTextString */
287 /* INPUT: Widget wid - TextField widget to get string from. */
288 /* Pointer to variable to store string */
292 /******************************************************************************/
293 void GetWidgetTextString (Widget wid, char **ppszText)
299 *ppszText = (char *)NULL;
301 if (XmIsTextField(wid)) {
302 pszTmp = XmTextFieldGetString (wid);
303 } else if (XmIsText(wid)) {
304 pszTmp = XmTextGetString (wid);
308 if (!strcmp(pszTmp, "")) {
310 pszTmp = (char *)NULL;
316 /******************************************************************************/
318 /* PutWidgetTextString */
320 /* INPUT: Widget wid - Widget whose text string is being set */
321 /* Pointer to text string. */
325 /******************************************************************************/
326 void PutWidgetTextString (Widget wid, char *pszText)
329 if (XmIsTextField(wid)) {
330 XmTextFieldSetString (wid, pszText);
331 } else if (XmIsText(wid)) {
332 XmTextSetString (wid, pszText);
337 /******************************************************************************/
339 /* GetIconSearchPathList */
345 /******************************************************************************/
346 char **GetIconSearchPathList(void)
348 char *iconpath = (char *)NULL;
359 static char *default_list1[] = {"~/.dt/icons", "/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
360 static char *default_list2[] = {"/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
365 /**************************************************************************/
366 /* Get contents of icon search path environment variable. */
367 /**************************************************************************/
368 pszEnvVar = getenv("XMICONSEARCHPATH");
369 if ( pszEnvVar && strlen(pszEnvVar) ) {
370 iconpath = (char *)malloc(strlen(pszEnvVar) + 1);
371 strcpy(iconpath, pszEnvVar);
374 /**************************************************************************/
375 /* If no iconpath then return an appropriate default. */
376 /**************************************************************************/
378 pszEnvVar = getenv("HOME");
379 if (pszEnvVar && strlen(pszEnvVar)) {
380 default_list = default_list1;
381 count = sizeof(default_list1)/sizeof(void *);
383 default_list = default_list2;
384 count = sizeof(default_list2)/sizeof(void *);
386 pplist = (char **)calloc((count + 1), sizeof(void *));
387 for (i=0; i < count; i++) {
388 if (strchr(default_list[i], '~')) {
389 if (pszEnvVar && strlen(pszEnvVar)) {
390 pplist[i] = calloc(strlen(default_list[i]) + strlen(pszEnvVar) + 1, sizeof(char));
391 strcpy(pplist[i], pszEnvVar);
393 pplist[i] = calloc(strlen(default_list[i]) + 1, sizeof(char));
395 strcat(pplist[i], &(default_list[i][1]));
397 pplist[i] = calloc(strlen(default_list[i]) + 1,sizeof(char));
398 strcpy(pplist[i], default_list[i]);
405 printf("Path = %s\n", iconpath);
408 /**************************************************************************/
409 /* Iterate through the search path once to get total count of individual */
410 /* paths within the search path. */
411 /**************************************************************************/
416 ptr = strchr(ptr, ':');
417 /*printf("ptr = %s\n", ptr);*/
420 if ((ptr) && (ptr[1] != '\0')) {
421 for (; ptr[0] == ':'; ptr++);
428 /**************************************************************************/
429 /* Debug information. */
430 /**************************************************************************/
432 printf("IconSearchPath = %s\n", iconpath);
433 printf("# of paths = %d\n", count);
436 /**************************************************************************/
437 /* Get contents of lang environment variable. */
438 /**************************************************************************/
439 lang = getenv("LANG");
441 langsize = strlen(lang);
446 /**************************************************************************/
447 /* Allocate the array of pointers to store the individual path strings. */
448 /**************************************************************************/
449 pplist = (char **)calloc((count+1), sizeof(void *));
451 /**************************************************************************/
452 /* Iterate through again to allocate space for each individual path and */
453 /* store that path. */
454 /**************************************************************************/
459 ptr = strchr(ptr, ':');
461 /*********************************************************************/
462 /* Make tmpptr the path. Also move to the next path in the search */
464 /*********************************************************************/
466 if ((ptr) && (ptr[1] != '\0')) {
467 for (; ptr[0] == ':'; ptr++);
476 /*********************************************************************/
477 /* If %L in path, then add size of lang variable to it when */
478 /* allocating array for path. */
479 /*********************************************************************/
480 if (strip = strstr(tmpptr, "%L")) {
481 path = malloc(strlen(tmpptr) + langsize + 1);
483 path = malloc(strlen(tmpptr) + 1);
485 strcpy(path, tmpptr);
487 /*********************************************************************/
488 /* Strip off the /%B... stuff off of the path if there is some. */
489 /*********************************************************************/
490 if (strip = strstr(path, "%B")) {
494 /*********************************************************************/
495 /* Now replace %L with lang variable. */
496 /*********************************************************************/
497 if (strip = strstr(path, "%L")) {
504 /*********************************************************************/
505 /* Remove slash from end of path if there is one. */
506 /*********************************************************************/
509 if (path[size - 1] == '/') {
510 path[size - 1] = '\0';
514 printf("new path = %s\n", path);
517 /***************************************************************/
518 /* See if path is already in our list. */
519 /***************************************************************/
521 for (i=0; (i < count) && (!bFound); i++) {
522 if (!(strcmp(pplist[i], path))) {
526 /***************************************************************/
527 /* If not in list, then add to list. */
528 /***************************************************************/
530 pplist[count] = path;
532 /***************************************************************/
533 /* Else, just free resources. */
534 /***************************************************************/
541 printf("Path%d = %s\n", count, pplist[count]);
545 **** moving this up a bit in the code ****
547 /*********************************************************************/
548 /* Get the next path in the icon search path. */
549 /*********************************************************************/
550 if ((ptr) && (ptr[1] != '\0')) {
551 for (; ptr[0] == ':'; ptr++);
562 /******************************************************************************/
564 /* FreeIconSearchPathList */
570 /******************************************************************************/
571 void FreeIconSearchPathList(char **pplist)
576 /**************************************************************************/
577 /* Iterate through the search path once to get total count of individual */
578 /* paths within the search path. */
579 /**************************************************************************/
581 for (i = 0; pplist[i]; free(pplist[i]), i++);
591 /******************************************************************************/
593 /* TurnOnHourGlassAllWindows */
599 /******************************************************************************/
600 void TurnOnHourGlassAllWindows(void)
602 _DtTurnOnHourGlass(CreateActionAppShell);
603 if ( (AddFiletype) &&
604 (XtIsRealized(AddFiletype)) &&
605 (XtIsManaged(AddFiletype)) ) {
606 _DtTurnOnHourGlass(AddFiletype);
608 if ( (FileCharacteristics) &&
609 (XtIsRealized(FileCharacteristics)) &&
610 (XtIsManaged(FileCharacteristics)) ) {
611 _DtTurnOnHourGlass(FileCharacteristics);
613 if ( (IconSelector) &&
614 (XtIsRealized(IconSelector)) &&
615 (XtIsManaged(IconSelector)) ) {
616 _DtTurnOnHourGlass(IconSelector);
619 (XtIsRealized(OpenFile)) &&
620 (XtIsManaged(OpenFile)) ) {
621 _DtTurnOnHourGlass(OpenFile);
624 /******************************************************************************/
626 /* TurnOffHourGlassAllWindows */
632 /******************************************************************************/
633 void TurnOffHourGlassAllWindows(void)
635 _DtTurnOffHourGlass(CreateActionAppShell);
636 if ( (AddFiletype) &&
637 (XtIsRealized(AddFiletype)) &&
638 (XtIsManaged(AddFiletype)) ) {
639 _DtTurnOffHourGlass(AddFiletype);
641 if ( (FileCharacteristics) &&
642 (XtIsRealized(FileCharacteristics)) &&
643 (XtIsManaged(FileCharacteristics)) ) {
644 _DtTurnOffHourGlass(FileCharacteristics);
646 if ( (IconSelector) &&
647 (XtIsRealized(IconSelector)) &&
648 (XtIsManaged(IconSelector)) ) {
649 _DtTurnOffHourGlass(IconSelector);
652 (XtIsRealized(OpenFile)) &&
653 (XtIsManaged(OpenFile)) ) {
654 _DtTurnOffHourGlass(OpenFile);
657 /******************************************************************************/
661 /* INPUT: icon gadget widget id */
662 /* icon file base name */
666 /******************************************************************************/
667 void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSize)
669 char pmFileName[MAXBUFSIZE];
670 char bmFileName[MAXBUFSIZE];
671 char pszSize[MAX_EXT_SIZE];
676 switch (enumIconSize) {
678 strcpy(pszSize, LARGE_EXT);
681 strcpy(pszSize, MEDIUM_EXT);
684 strcpy(pszSize, TINY_EXT);
688 sprintf(pmFileName, "%s%s%s", pszIconFile, pszSize, PIXMAP_EXT );
689 sprintf(bmFileName, "%s%s%s", pszIconFile, pszSize, BITMAP_EXT );
692 pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, PIXMAP_EXT, FALSE);
693 snprintf(pmFileName, sizeof(pmFileName), "%s", pszName);
696 pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, BITMAP_EXT, FALSE);
697 snprintf(bmFileName, sizeof(bmFileName), "%s", pszName);
700 pIconData = GetIconDataFromWid(wid);
702 if ( (pIconData->pmDirtyBit) &&
703 (pIconData->pmFileName) &&
704 (strlen(pIconData->pmFileName)) ) {
706 printf("SetIconData: unlink '%s'\n", pIconData->pmFileName); /* debug */
708 unlink(pIconData->pmFileName);
709 pIconData->pmDirtyBit = False;
711 strcpy(pIconData->pmFileName, pmFileName);
713 if ( (pIconData->bmDirtyBit) &&
714 (strlen(pIconData->bmFileName)) ) {
716 printf("SetIconData: unlink '%s'\n", pIconData->bmFileName); /* debug */
718 unlink(pIconData->bmFileName);
719 pIconData->bmDirtyBit = False;
721 strcpy(pIconData->bmFileName, bmFileName);
724 SET_ICONGADGET_ICON(wid, pmFileName);
726 SET_ICONGADGET_ICON(wid, bmFileName);
730 /******************************************************************************/
732 /* GetCorrectIconType */
734 /* INPUT: icon file name */
736 /* OUTPUT: correct icon type of icon file name passed */
738 /******************************************************************************/
739 char * GetCorrectIconType(char *pszIconFile)
743 char pszNewType[MAX_EXT_SIZE];
746 strcpy(pszNewType, PIXMAP_EXT);
748 strcpy(pszNewType, BITMAP_EXT);
752 pszTmp = XtMalloc(strlen(pszIconFile) + strlen(pszNewType) + 1);
753 if (!pszTmp) return((char *)NULL);
754 strcpy(pszTmp, pszIconFile);
755 ptr = strrchr(pszTmp, '.');
757 strcpy(ptr, pszNewType);
760 pszTmp = (char *)NULL;
764 /******************************************************************************/
768 /* INPUT: icon file name */
770 /* OUTPUT: mask file name for icon name passed in */
772 /******************************************************************************/
773 char * CreateMaskName(char *pszIconName)
780 char type_ext[MAX_EXT_SIZE + 2];
781 char size_ext[MAX_EXT_SIZE + 2];
784 /***************************************************************/
785 /* initialize temp arrays */
786 /***************************************************************/
790 /***************************************************************/
791 /* alloc memory for temporary name */
792 /***************************************************************/
793 pszTmpName = (char *)XtMalloc(strlen(pszIconName) + 1);
795 strcpy(pszTmpName, pszIconName);
797 return((char *)NULL);
800 /*****************************************/
801 /* Strip off icon type extension. */
802 /*****************************************/
803 ptr = strrchr(pszTmpName, '.');
805 type_name = strtok(ptr, ".");
808 type_name = (char *)NULL;
811 /*****************************************/
812 /* Get size extention. */
813 /*****************************************/
814 ptr = strrchr(pszTmpName, '.');
816 size_name = strtok(ptr, ".");
819 size_name = (char *)NULL;
822 /*****************************************/
823 /* Alloc the storage for the new name */
824 /*****************************************/
825 bytesneeded += ((pszTmpName) ? strlen(pszTmpName) : 0);
826 bytesneeded += strlen("_m..");
827 bytesneeded += ((size_name) ? strlen(size_name) : 0);
828 bytesneeded += ((type_name) ? strlen(type_name) : 0);
829 pszNewName = (char *)XtMalloc(bytesneeded + 1);
831 /*****************************************/
832 /* Create extension names */
833 /*****************************************/
835 sprintf(size_ext, ".%s", size_name);
838 sprintf(type_ext, ".%s", type_name);
840 /*****************************************/
841 /* And construct the new name from pieces*/
842 /*****************************************/
845 sprintf(pszNewName, "%s%s_m%s", pszTmpName, size_ext, type_ext);
847 sprintf(pszNewName, "%s_m%s%s", pszTmpName, size_ext, type_ext);
850 if (pszTmpName) XtFree(pszTmpName);
853 printf("Mask file name = '%s'\n", pszNewName); /* debug */