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 librararies 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 /*****************************************************************************/
34 #include <X11/cursorfont.h>
38 #include "CreateActionAppShell.h"
42 /*****************************************************************************/
46 /*****************************************************************************/
47 char * GetBaseName(char *pszFileName)
51 name = strrchr(pszFileName, '/');
53 name = strtok(name, "/");
60 /*****************************************************************************/
64 /*****************************************************************************/
65 char * ReplaceSpaces(char *pszName)
70 newName = (char *)XtMalloc(strlen(pszName) + 1);
71 memset(newName, 0, sizeof(newName));
72 strcpy(newName, pszName);
73 ptr = strrchr(newName, ' ');
76 while ((*ptr) && (ptr = strchr(ptr, ' '))) {
85 /*****************************************************************************/
89 /*****************************************************************************/
90 char * GetExtName(char *pszFileName)
94 type = strrchr(pszFileName, '.');
96 type = strtok(type, ".");
105 /*****************************************************************************/
109 /*****************************************************************************/
110 char * GetPathName(char *pszFileName)
115 pszPath = (char *)malloc(strlen(pszFileName) + 1);
116 strcpy(pszPath, pszFileName);
117 ptr = strrchr(pszPath, '/');
122 pszPath = (char *)NULL;
129 /*****************************************************************************/
131 /* Change_IconGadget_IconType */
133 /*****************************************************************************/
134 void Change_IconGadget_IconType(Widget widIconGadget, char *pszNewType)
137 char pszNewName[MAXBUFSIZE];
141 XtVaGetValues(widIconGadget, XmNimageName, &pszOldName, NULL);
143 tmpptr = strrchr(pszOldName, '.');
145 sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
147 printf("monochrome name is '%s'\n", pszNewName); /* debug */
149 if (check_file_exists(pszNewName)) {
150 SET_ICONGADGET_ICON(widIconGadget, pszNewName);
152 SET_ICONGADGET_ICON(widIconGadget, "");
159 /*****************************************************************************/
161 /* Change_IconName_IconType */
163 /*****************************************************************************/
164 char * Change_IconName_IconType(char *pszOldName, char *pszNewType)
168 char *pszNewName = (char *)NULL;
171 pszNewName = (char *)malloc(strlen(pszOldName) + 10);
172 tmpptr = strrchr(pszOldName, '.');
174 sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
176 printf("new icon name is '%s'\n", pszNewName);
178 if (!check_file_exists(pszNewName)) {
180 pszNewName = (char *)NULL;
187 /******************************************************************************/
191 /******************************************************************************/
192 char * GetCoreName(char *pszFullName)
198 name = strrchr(pszFullName, '/');
200 name = strtok(name, "/");
204 newName = (char *)malloc(strlen(name) + 1);
205 memset(newName, 0, sizeof(newName));
206 strcpy(newName, name);
207 ptr = strrchr(newName, '.');
214 /******************************************************************************/
216 /* load_icons - puts selected icons into the appropriate icon gadget. */
218 /* INPUT: Widget wid - OK button on Open File dialog, */
219 /* XtPointer client_data */
220 /* XmFileSelectionBoxCallbackStruct *cbs */
223 /******************************************************************************/
224 void load_icons (Widget wid, XtPointer client_data,
225 XmFileSelectionBoxCallbackStruct *cbs)
227 char *full_name, *path_and_base_name, *type_name, *size_name;
233 /*****************************************/
234 /* Get icon name and separate into parts */
235 /*****************************************/
236 full_name = (char *)client_data;
237 path_and_base_name = (char *)malloc(strlen(full_name)+1);
238 strcpy(path_and_base_name, full_name);
240 /*****************************************/
241 /* Strip off icon type extension. */
242 /*****************************************/
243 ptr = strrchr(path_and_base_name, '.');
245 type_name = strtok(ptr, ".");
248 type_name = (char *)NULL;
251 /*****************************************/
252 /* Get size extention. */
253 /*****************************************/
254 ptr = strrchr(path_and_base_name, '.');
256 size_name = strtok(ptr, ".");
259 size_name = (char *)NULL;
263 printf("path&base = %s\n", path_and_base_name); /* debug */
264 printf("type = %s\n", type_name); /* debug */
265 printf("size = %s\n", size_name); /* debug */
268 /* ***** cmvc 6715 *****
269 if ((!path_and_base_name) || (!type_name) || (!size_name)) {
270 printf ("'%s' is not a proper icon file name!\n", full_name);
275 XtVaGetValues(IconSelector, XmNuserData, &iSource, NULL);
276 base_name = GetBaseName(path_and_base_name);
277 ptr = XtMalloc(strlen(base_name) + 1);
278 strcpy(ptr, base_name);
280 case CA_ACTION_ICONS:
282 SetIconData(CA_LRG_IconGadget, path_and_base_name, Large_Icon);
283 SetIconData(CA_MED_IconGadget, path_and_base_name, Medium_Icon);
284 SetIconData(CA_TINY_IconGadget, path_and_base_name, Tiny_Icon);
286 case CA_FILETYPE_ICONS:
287 XtVaGetValues(AddFiletype, XmNuserData, &pFtD, NULL);
289 SetIconData(AF_MED_IconGadget, path_and_base_name, Medium_Icon);
290 SetIconData(AF_TINY_IconGadget, path_and_base_name, Tiny_Icon);
294 free(path_and_base_name);
298 /******************************************************************************/
300 /* GetWidgetTextString */
302 /* INPUT: Widget wid - TextField widget to get string from. */
303 /* Pointer to variable to store string */
307 /******************************************************************************/
308 void GetWidgetTextString (Widget wid, char **ppszText)
314 *ppszText = (char *)NULL;
316 if (XmIsTextField(wid)) {
317 pszTmp = XmTextFieldGetString (wid);
318 } else if (XmIsText(wid)) {
319 pszTmp = XmTextGetString (wid);
323 if (!strcmp(pszTmp, "")) {
325 pszTmp = (char *)NULL;
331 /******************************************************************************/
333 /* PutWidgetTextString */
335 /* INPUT: Widget wid - Widget whose text string is being set */
336 /* Pointer to text string. */
340 /******************************************************************************/
341 void PutWidgetTextString (Widget wid, char *pszText)
344 if (XmIsTextField(wid)) {
345 XmTextFieldSetString (wid, pszText);
346 } else if (XmIsText(wid)) {
347 XmTextSetString (wid, pszText);
352 /******************************************************************************/
354 /* GetIconSearchPathList */
360 /******************************************************************************/
361 char **GetIconSearchPathList(void)
363 char *iconpath = (char *)NULL;
374 static char *default_list1[] = {"~/.dt/icons", "/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
375 static char *default_list2[] = {"/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
380 /**************************************************************************/
381 /* Get contents of icon search path environment variable. */
382 /**************************************************************************/
383 pszEnvVar = getenv("XMICONSEARCHPATH");
384 if ( pszEnvVar && strlen(pszEnvVar) ) {
385 iconpath = (char *)malloc(strlen(pszEnvVar) + 1);
386 strcpy(iconpath, pszEnvVar);
389 /**************************************************************************/
390 /* If no iconpath then return an appropriate default. */
391 /**************************************************************************/
393 pszEnvVar = getenv("HOME");
394 if (pszEnvVar && strlen(pszEnvVar)) {
395 default_list = default_list1;
396 count = sizeof(default_list1)/sizeof(void *);
398 default_list = default_list2;
399 count = sizeof(default_list2)/sizeof(void *);
401 pplist = (char **)calloc((count + 1), sizeof(void *));
402 for (i=0; i < count; i++) {
403 if (strchr(default_list[i], '~')) {
404 if (pszEnvVar && strlen(pszEnvVar)) {
405 pplist[i] = calloc(strlen(default_list[i]) + strlen(pszEnvVar) + 1, sizeof(char));
406 strcpy(pplist[i], pszEnvVar);
408 pplist[i] = calloc(strlen(default_list[i]) + 1, sizeof(char));
410 strcat(pplist[i], &(default_list[i][1]));
412 pplist[i] = calloc(strlen(default_list[i]) + 1,sizeof(char));
413 strcpy(pplist[i], default_list[i]);
420 printf("Path = %s\n", iconpath);
423 /**************************************************************************/
424 /* Iterate through the search path once to get total count of individual */
425 /* paths within the search path. */
426 /**************************************************************************/
431 ptr = strchr(ptr, ':');
432 /*printf("ptr = %s\n", ptr);*/
435 if ((ptr) && (ptr[1] != '\0')) {
436 for (; ptr[0] == ':'; ptr++);
443 /**************************************************************************/
444 /* Debug information. */
445 /**************************************************************************/
447 printf("IconSearchPath = %s\n", iconpath);
448 printf("# of paths = %d\n", count);
451 /**************************************************************************/
452 /* Get contents of lang environment variable. */
453 /**************************************************************************/
454 lang = getenv("LANG");
456 langsize = strlen(lang);
461 /**************************************************************************/
462 /* Allocate the array of pointers to store the individual path strings. */
463 /**************************************************************************/
464 pplist = (char **)calloc((count+1), sizeof(void *));
466 /**************************************************************************/
467 /* Iterate through again to allocate space for each individual path and */
468 /* store that path. */
469 /**************************************************************************/
474 ptr = strchr(ptr, ':');
476 /*********************************************************************/
477 /* Make tmpptr the path. Also move to the next path in the search */
479 /*********************************************************************/
481 if ((ptr) && (ptr[1] != '\0')) {
482 for (; ptr[0] == ':'; ptr++);
491 /*********************************************************************/
492 /* If %L in path, then add size of lang variable to it when */
493 /* allocating array for path. */
494 /*********************************************************************/
495 if (strip = strstr(tmpptr, "%L")) {
496 path = malloc(strlen(tmpptr) + langsize + 1);
498 path = malloc(strlen(tmpptr) + 1);
500 strcpy(path, tmpptr);
502 /*********************************************************************/
503 /* Strip off the /%B... stuff off of the path if there is some. */
504 /*********************************************************************/
505 if (strip = strstr(path, "%B")) {
509 /*********************************************************************/
510 /* Now replace %L with lang variable. */
511 /*********************************************************************/
512 if (strip = strstr(path, "%L")) {
519 /*********************************************************************/
520 /* Remove slash from end of path if there is one. */
521 /*********************************************************************/
524 if (path[size - 1] == '/') {
525 path[size - 1] = '\0';
529 printf("new path = %s\n", path);
532 /***************************************************************/
533 /* See if path is already in our list. */
534 /***************************************************************/
536 for (i=0; (i < count) && (!bFound); i++) {
537 if (!(strcmp(pplist[i], path))) {
541 /***************************************************************/
542 /* If not in list, then add to list. */
543 /***************************************************************/
545 pplist[count] = path;
547 /***************************************************************/
548 /* Else, just free resources. */
549 /***************************************************************/
556 printf("Path%d = %s\n", count, pplist[count]);
560 **** moving this up a bit in the code ****
562 /*********************************************************************/
563 /* Get the next path in the icon search path. */
564 /*********************************************************************/
565 if ((ptr) && (ptr[1] != '\0')) {
566 for (; ptr[0] == ':'; ptr++);
577 /******************************************************************************/
579 /* FreeIconSearchPathList */
585 /******************************************************************************/
586 void FreeIconSearchPathList(char **pplist)
591 /**************************************************************************/
592 /* Iterate through the search path once to get total count of individual */
593 /* paths within the search path. */
594 /**************************************************************************/
596 for (i = 0; pplist[i]; free(pplist[i]), i++);
606 /******************************************************************************/
608 /* TurnOnHourGlassAllWindows */
614 /******************************************************************************/
615 void TurnOnHourGlassAllWindows()
617 _DtTurnOnHourGlass(CreateActionAppShell);
618 if ( (AddFiletype) &&
619 (XtIsRealized(AddFiletype)) &&
620 (XtIsManaged(AddFiletype)) ) {
621 _DtTurnOnHourGlass(AddFiletype);
623 if ( (FileCharacteristics) &&
624 (XtIsRealized(FileCharacteristics)) &&
625 (XtIsManaged(FileCharacteristics)) ) {
626 _DtTurnOnHourGlass(FileCharacteristics);
628 if ( (IconSelector) &&
629 (XtIsRealized(IconSelector)) &&
630 (XtIsManaged(IconSelector)) ) {
631 _DtTurnOnHourGlass(IconSelector);
634 (XtIsRealized(OpenFile)) &&
635 (XtIsManaged(OpenFile)) ) {
636 _DtTurnOnHourGlass(OpenFile);
639 /******************************************************************************/
641 /* TurnOffHourGlassAllWindows */
647 /******************************************************************************/
648 void TurnOffHourGlassAllWindows()
650 _DtTurnOffHourGlass(CreateActionAppShell);
651 if ( (AddFiletype) &&
652 (XtIsRealized(AddFiletype)) &&
653 (XtIsManaged(AddFiletype)) ) {
654 _DtTurnOffHourGlass(AddFiletype);
656 if ( (FileCharacteristics) &&
657 (XtIsRealized(FileCharacteristics)) &&
658 (XtIsManaged(FileCharacteristics)) ) {
659 _DtTurnOffHourGlass(FileCharacteristics);
661 if ( (IconSelector) &&
662 (XtIsRealized(IconSelector)) &&
663 (XtIsManaged(IconSelector)) ) {
664 _DtTurnOffHourGlass(IconSelector);
667 (XtIsRealized(OpenFile)) &&
668 (XtIsManaged(OpenFile)) ) {
669 _DtTurnOffHourGlass(OpenFile);
672 /******************************************************************************/
676 /* INPUT: icon gadget widget id */
677 /* icon file base name */
681 /******************************************************************************/
682 void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSize)
684 char pmFileName[MAXBUFSIZE];
685 char bmFileName[MAXBUFSIZE];
686 char pszSize[MAX_EXT_SIZE];
691 switch (enumIconSize) {
693 strcpy(pszSize, LARGE_EXT);
696 strcpy(pszSize, MEDIUM_EXT);
699 strcpy(pszSize, TINY_EXT);
703 sprintf(pmFileName, "%s%s%s", pszIconFile, pszSize, PIXMAP_EXT );
704 sprintf(bmFileName, "%s%s%s", pszIconFile, pszSize, BITMAP_EXT );
707 pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, PIXMAP_EXT, FALSE);
708 strcpy(pmFileName, pszName);
709 if (pszName) XtFree(pszName);
711 pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, BITMAP_EXT, FALSE);
712 strcpy(bmFileName, pszName);
713 if (pszName) XtFree(pszName);
715 pIconData = GetIconDataFromWid(wid);
717 if ( (pIconData->pmDirtyBit) &&
718 (pIconData->pmFileName) &&
719 (strlen(pIconData->pmFileName)) ) {
721 printf("SetIconData: unlink '%s'\n", pIconData->pmFileName); /* debug */
723 unlink(pIconData->pmFileName);
724 pIconData->pmDirtyBit = False;
726 strcpy(pIconData->pmFileName, pmFileName);
728 if ( (pIconData->bmDirtyBit) &&
729 (pIconData->bmFileName) &&
730 (strlen(pIconData->bmFileName)) ) {
732 printf("SetIconData: unlink '%s'\n", pIconData->bmFileName); /* debug */
734 unlink(pIconData->bmFileName);
735 pIconData->bmDirtyBit = False;
737 strcpy(pIconData->bmFileName, bmFileName);
740 SET_ICONGADGET_ICON(wid, pmFileName);
742 SET_ICONGADGET_ICON(wid, bmFileName);
746 /******************************************************************************/
748 /* GetCorrectIconType */
750 /* INPUT: icon file name */
752 /* OUTPUT: correct icon type of icon file name passed */
754 /******************************************************************************/
755 char * GetCorrectIconType(char *pszIconFile)
759 char pszNewType[MAX_EXT_SIZE];
762 strcpy(pszNewType, PIXMAP_EXT);
764 strcpy(pszNewType, BITMAP_EXT);
768 pszTmp = XtMalloc(strlen(pszIconFile) + strlen(pszNewType) + 1);
769 if (!pszTmp) return((char *)NULL);
770 strcpy(pszTmp, pszIconFile);
771 ptr = strrchr(pszTmp, '.');
773 strcpy(ptr, pszNewType);
776 pszTmp = (char *)NULL;
780 /******************************************************************************/
784 /* INPUT: icon file name */
786 /* OUTPUT: mask file name for icon name passed in */
788 /******************************************************************************/
789 char * CreateMaskName(char *pszIconName)
796 char type_ext[MAX_EXT_SIZE + 2];
797 char size_ext[MAX_EXT_SIZE + 2];
800 /***************************************************************/
801 /* initialize temp arrays */
802 /***************************************************************/
806 /***************************************************************/
807 /* alloc memory for temporary name */
808 /***************************************************************/
809 pszTmpName = (char *)XtMalloc(strlen(pszIconName) + 1);
811 strcpy(pszTmpName, pszIconName);
813 return((char *)NULL);
816 /*****************************************/
817 /* Strip off icon type extension. */
818 /*****************************************/
819 ptr = strrchr(pszTmpName, '.');
821 type_name = strtok(ptr, ".");
824 type_name = (char *)NULL;
827 /*****************************************/
828 /* Get size extention. */
829 /*****************************************/
830 ptr = strrchr(pszTmpName, '.');
832 size_name = strtok(ptr, ".");
835 size_name = (char *)NULL;
838 /*****************************************/
839 /* Alloc the storage for the new name */
840 /*****************************************/
841 bytesneeded += ((pszTmpName) ? strlen(pszTmpName) : 0);
842 bytesneeded += strlen("_m..");
843 bytesneeded += ((size_name) ? strlen(size_name) : 0);
844 bytesneeded += ((type_name) ? strlen(type_name) : 0);
845 pszNewName = (char *)XtMalloc(bytesneeded + 1);
847 /*****************************************/
848 /* Create extension names */
849 /*****************************************/
851 sprintf(size_ext, ".%s", size_name);
854 sprintf(type_ext, ".%s", type_name);
856 /*****************************************/
857 /* And construct the new name from pieces*/
858 /*****************************************/
861 sprintf(pszNewName, "%s%s_m%s", pszTmpName, size_ext, type_ext);
863 sprintf(pszNewName, "%s_m%s%s", pszTmpName, size_ext, type_ext);
866 if (pszTmpName) XtFree(pszTmpName);
869 printf("Mask file name = '%s'\n", pszNewName); /* debug */