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>
39 #include "CreateActionAppShell.h"
43 /*****************************************************************************/
47 /*****************************************************************************/
48 char * ReplaceSpaces(char *pszName)
53 newName = (char *)XtMalloc(strlen(pszName) + 1);
54 memset(newName, 0, sizeof(newName));
55 strcpy(newName, pszName);
56 ptr = strrchr(newName, ' ');
59 while ((*ptr) && (ptr = strchr(ptr, ' '))) {
68 /*****************************************************************************/
72 /*****************************************************************************/
73 char * GetExtName(char *pszFileName)
77 type = strrchr(pszFileName, '.');
79 type = strtok(type, ".");
88 /*****************************************************************************/
92 /*****************************************************************************/
93 char * GetPathName(char *pszFileName)
98 pszPath = (char *)malloc(strlen(pszFileName) + 1);
99 strcpy(pszPath, pszFileName);
100 ptr = strrchr(pszPath, '/');
105 pszPath = (char *)NULL;
112 /*****************************************************************************/
114 /* Change_IconGadget_IconType */
116 /*****************************************************************************/
117 void Change_IconGadget_IconType(Widget widIconGadget, char *pszNewType)
120 char pszNewName[MAXBUFSIZE];
124 XtVaGetValues(widIconGadget, XmNimageName, &pszOldName, NULL);
126 tmpptr = strrchr(pszOldName, '.');
128 sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
130 printf("monochrome name is '%s'\n", pszNewName); /* debug */
132 if (check_file_exists(pszNewName)) {
133 SET_ICONGADGET_ICON(widIconGadget, pszNewName);
135 SET_ICONGADGET_ICON(widIconGadget, "");
142 /*****************************************************************************/
144 /* Change_IconName_IconType */
146 /*****************************************************************************/
147 char * Change_IconName_IconType(char *pszOldName, char *pszNewType)
151 char *pszNewName = (char *)NULL;
154 pszNewName = (char *)malloc(strlen(pszOldName) + 10);
155 tmpptr = strrchr(pszOldName, '.');
157 sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
159 printf("new icon name is '%s'\n", pszNewName);
161 if (!check_file_exists(pszNewName)) {
163 pszNewName = (char *)NULL;
170 /******************************************************************************/
174 /******************************************************************************/
175 char * GetCoreName(char *pszFullName)
181 name = strrchr(pszFullName, '/');
183 name = strtok(name, "/");
187 newName = (char *)malloc(strlen(name) + 1);
188 memset(newName, 0, sizeof(newName));
189 strcpy(newName, name);
190 ptr = strrchr(newName, '.');
197 /******************************************************************************/
199 /* load_icons - puts selected icons into the appropriate icon gadget. */
201 /* INPUT: Widget wid - OK button on Open File dialog, */
202 /* XtPointer client_data */
203 /* XmFileSelectionBoxCallbackStruct *cbs */
206 /******************************************************************************/
207 void load_icons (Widget wid, XtPointer client_data,
208 XmFileSelectionBoxCallbackStruct *cbs)
210 char *full_name, *path_and_base_name, *type_name, *size_name;
216 /*****************************************/
217 /* Get icon name and separate into parts */
218 /*****************************************/
219 full_name = (char *)client_data;
220 path_and_base_name = (char *)malloc(strlen(full_name)+1);
221 strcpy(path_and_base_name, full_name);
223 /*****************************************/
224 /* Strip off icon type extension. */
225 /*****************************************/
226 ptr = strrchr(path_and_base_name, '.');
228 type_name = strtok(ptr, ".");
231 type_name = (char *)NULL;
234 /*****************************************/
235 /* Get size extention. */
236 /*****************************************/
237 ptr = strrchr(path_and_base_name, '.');
239 size_name = strtok(ptr, ".");
242 size_name = (char *)NULL;
246 printf("path&base = %s\n", path_and_base_name); /* debug */
247 printf("type = %s\n", type_name); /* debug */
248 printf("size = %s\n", size_name); /* debug */
251 /* ***** cmvc 6715 *****
252 if ((!path_and_base_name) || (!type_name) || (!size_name)) {
253 printf ("'%s' is not a proper icon file name!\n", full_name);
258 XtVaGetValues(IconSelector, XmNuserData, &iSource, NULL);
259 base_name = basename(path_and_base_name);
260 ptr = XtMalloc(strlen(base_name) + 1);
261 strcpy(ptr, base_name);
263 case CA_ACTION_ICONS:
265 SetIconData(CA_LRG_IconGadget, path_and_base_name, Large_Icon);
266 SetIconData(CA_MED_IconGadget, path_and_base_name, Medium_Icon);
267 SetIconData(CA_TINY_IconGadget, path_and_base_name, Tiny_Icon);
269 case CA_FILETYPE_ICONS:
270 XtVaGetValues(AddFiletype, XmNuserData, &pFtD, NULL);
272 SetIconData(AF_MED_IconGadget, path_and_base_name, Medium_Icon);
273 SetIconData(AF_TINY_IconGadget, path_and_base_name, Tiny_Icon);
277 free(path_and_base_name);
281 /******************************************************************************/
283 /* GetWidgetTextString */
285 /* INPUT: Widget wid - TextField widget to get string from. */
286 /* Pointer to variable to store string */
290 /******************************************************************************/
291 void GetWidgetTextString (Widget wid, char **ppszText)
297 *ppszText = (char *)NULL;
299 if (XmIsTextField(wid)) {
300 pszTmp = XmTextFieldGetString (wid);
301 } else if (XmIsText(wid)) {
302 pszTmp = XmTextGetString (wid);
306 if (!strcmp(pszTmp, "")) {
308 pszTmp = (char *)NULL;
314 /******************************************************************************/
316 /* PutWidgetTextString */
318 /* INPUT: Widget wid - Widget whose text string is being set */
319 /* Pointer to text string. */
323 /******************************************************************************/
324 void PutWidgetTextString (Widget wid, char *pszText)
327 if (XmIsTextField(wid)) {
328 XmTextFieldSetString (wid, pszText);
329 } else if (XmIsText(wid)) {
330 XmTextSetString (wid, pszText);
335 /******************************************************************************/
337 /* GetIconSearchPathList */
343 /******************************************************************************/
344 char **GetIconSearchPathList(void)
346 char *iconpath = (char *)NULL;
357 static char *default_list1[] = {"~/.dt/icons", "/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
358 static char *default_list2[] = {"/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
363 /**************************************************************************/
364 /* Get contents of icon search path environment variable. */
365 /**************************************************************************/
366 pszEnvVar = getenv("XMICONSEARCHPATH");
367 if ( pszEnvVar && strlen(pszEnvVar) ) {
368 iconpath = (char *)malloc(strlen(pszEnvVar) + 1);
369 strcpy(iconpath, pszEnvVar);
372 /**************************************************************************/
373 /* If no iconpath then return an appropriate default. */
374 /**************************************************************************/
376 pszEnvVar = getenv("HOME");
377 if (pszEnvVar && strlen(pszEnvVar)) {
378 default_list = default_list1;
379 count = sizeof(default_list1)/sizeof(void *);
381 default_list = default_list2;
382 count = sizeof(default_list2)/sizeof(void *);
384 pplist = (char **)calloc((count + 1), sizeof(void *));
385 for (i=0; i < count; i++) {
386 if (strchr(default_list[i], '~')) {
387 if (pszEnvVar && strlen(pszEnvVar)) {
388 pplist[i] = calloc(strlen(default_list[i]) + strlen(pszEnvVar) + 1, sizeof(char));
389 strcpy(pplist[i], pszEnvVar);
391 pplist[i] = calloc(strlen(default_list[i]) + 1, sizeof(char));
393 strcat(pplist[i], &(default_list[i][1]));
395 pplist[i] = calloc(strlen(default_list[i]) + 1,sizeof(char));
396 strcpy(pplist[i], default_list[i]);
403 printf("Path = %s\n", iconpath);
406 /**************************************************************************/
407 /* Iterate through the search path once to get total count of individual */
408 /* paths within the search path. */
409 /**************************************************************************/
414 ptr = strchr(ptr, ':');
415 /*printf("ptr = %s\n", ptr);*/
418 if ((ptr) && (ptr[1] != '\0')) {
419 for (; ptr[0] == ':'; ptr++);
426 /**************************************************************************/
427 /* Debug information. */
428 /**************************************************************************/
430 printf("IconSearchPath = %s\n", iconpath);
431 printf("# of paths = %d\n", count);
434 /**************************************************************************/
435 /* Get contents of lang environment variable. */
436 /**************************************************************************/
437 lang = getenv("LANG");
439 langsize = strlen(lang);
444 /**************************************************************************/
445 /* Allocate the array of pointers to store the individual path strings. */
446 /**************************************************************************/
447 pplist = (char **)calloc((count+1), sizeof(void *));
449 /**************************************************************************/
450 /* Iterate through again to allocate space for each individual path and */
451 /* store that path. */
452 /**************************************************************************/
457 ptr = strchr(ptr, ':');
459 /*********************************************************************/
460 /* Make tmpptr the path. Also move to the next path in the search */
462 /*********************************************************************/
464 if ((ptr) && (ptr[1] != '\0')) {
465 for (; ptr[0] == ':'; ptr++);
474 /*********************************************************************/
475 /* If %L in path, then add size of lang variable to it when */
476 /* allocating array for path. */
477 /*********************************************************************/
478 if (strip = strstr(tmpptr, "%L")) {
479 path = malloc(strlen(tmpptr) + langsize + 1);
481 path = malloc(strlen(tmpptr) + 1);
483 strcpy(path, tmpptr);
485 /*********************************************************************/
486 /* Strip off the /%B... stuff off of the path if there is some. */
487 /*********************************************************************/
488 if (strip = strstr(path, "%B")) {
492 /*********************************************************************/
493 /* Now replace %L with lang variable. */
494 /*********************************************************************/
495 if (strip = strstr(path, "%L")) {
502 /*********************************************************************/
503 /* Remove slash from end of path if there is one. */
504 /*********************************************************************/
507 if (path[size - 1] == '/') {
508 path[size - 1] = '\0';
512 printf("new path = %s\n", path);
515 /***************************************************************/
516 /* See if path is already in our list. */
517 /***************************************************************/
519 for (i=0; (i < count) && (!bFound); i++) {
520 if (!(strcmp(pplist[i], path))) {
524 /***************************************************************/
525 /* If not in list, then add to list. */
526 /***************************************************************/
528 pplist[count] = path;
530 /***************************************************************/
531 /* Else, just free resources. */
532 /***************************************************************/
539 printf("Path%d = %s\n", count, pplist[count]);
543 **** moving this up a bit in the code ****
545 /*********************************************************************/
546 /* Get the next path in the icon search path. */
547 /*********************************************************************/
548 if ((ptr) && (ptr[1] != '\0')) {
549 for (; ptr[0] == ':'; ptr++);
560 /******************************************************************************/
562 /* FreeIconSearchPathList */
568 /******************************************************************************/
569 void FreeIconSearchPathList(char **pplist)
574 /**************************************************************************/
575 /* Iterate through the search path once to get total count of individual */
576 /* paths within the search path. */
577 /**************************************************************************/
579 for (i = 0; pplist[i]; free(pplist[i]), i++);
589 /******************************************************************************/
591 /* TurnOnHourGlassAllWindows */
597 /******************************************************************************/
598 void TurnOnHourGlassAllWindows()
600 _DtTurnOnHourGlass(CreateActionAppShell);
601 if ( (AddFiletype) &&
602 (XtIsRealized(AddFiletype)) &&
603 (XtIsManaged(AddFiletype)) ) {
604 _DtTurnOnHourGlass(AddFiletype);
606 if ( (FileCharacteristics) &&
607 (XtIsRealized(FileCharacteristics)) &&
608 (XtIsManaged(FileCharacteristics)) ) {
609 _DtTurnOnHourGlass(FileCharacteristics);
611 if ( (IconSelector) &&
612 (XtIsRealized(IconSelector)) &&
613 (XtIsManaged(IconSelector)) ) {
614 _DtTurnOnHourGlass(IconSelector);
617 (XtIsRealized(OpenFile)) &&
618 (XtIsManaged(OpenFile)) ) {
619 _DtTurnOnHourGlass(OpenFile);
622 /******************************************************************************/
624 /* TurnOffHourGlassAllWindows */
630 /******************************************************************************/
631 void TurnOffHourGlassAllWindows()
633 _DtTurnOffHourGlass(CreateActionAppShell);
634 if ( (AddFiletype) &&
635 (XtIsRealized(AddFiletype)) &&
636 (XtIsManaged(AddFiletype)) ) {
637 _DtTurnOffHourGlass(AddFiletype);
639 if ( (FileCharacteristics) &&
640 (XtIsRealized(FileCharacteristics)) &&
641 (XtIsManaged(FileCharacteristics)) ) {
642 _DtTurnOffHourGlass(FileCharacteristics);
644 if ( (IconSelector) &&
645 (XtIsRealized(IconSelector)) &&
646 (XtIsManaged(IconSelector)) ) {
647 _DtTurnOffHourGlass(IconSelector);
650 (XtIsRealized(OpenFile)) &&
651 (XtIsManaged(OpenFile)) ) {
652 _DtTurnOffHourGlass(OpenFile);
655 /******************************************************************************/
659 /* INPUT: icon gadget widget id */
660 /* icon file base name */
664 /******************************************************************************/
665 void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSize)
667 char pmFileName[MAXBUFSIZE];
668 char bmFileName[MAXBUFSIZE];
669 char pszSize[MAX_EXT_SIZE];
674 switch (enumIconSize) {
676 strcpy(pszSize, LARGE_EXT);
679 strcpy(pszSize, MEDIUM_EXT);
682 strcpy(pszSize, TINY_EXT);
686 sprintf(pmFileName, "%s%s%s", pszIconFile, pszSize, PIXMAP_EXT );
687 sprintf(bmFileName, "%s%s%s", pszIconFile, pszSize, BITMAP_EXT );
690 pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, PIXMAP_EXT, FALSE);
691 strcpy(pmFileName, pszName);
692 if (pszName) XtFree(pszName);
694 pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, BITMAP_EXT, FALSE);
695 strcpy(bmFileName, pszName);
696 if (pszName) XtFree(pszName);
698 pIconData = GetIconDataFromWid(wid);
700 if ( (pIconData->pmDirtyBit) &&
701 (pIconData->pmFileName) &&
702 (strlen(pIconData->pmFileName)) ) {
704 printf("SetIconData: unlink '%s'\n", pIconData->pmFileName); /* debug */
706 unlink(pIconData->pmFileName);
707 pIconData->pmDirtyBit = False;
709 strcpy(pIconData->pmFileName, pmFileName);
711 if ( (pIconData->bmDirtyBit) &&
712 (pIconData->bmFileName) &&
713 (strlen(pIconData->bmFileName)) ) {
715 printf("SetIconData: unlink '%s'\n", pIconData->bmFileName); /* debug */
717 unlink(pIconData->bmFileName);
718 pIconData->bmDirtyBit = False;
720 strcpy(pIconData->bmFileName, bmFileName);
723 SET_ICONGADGET_ICON(wid, pmFileName);
725 SET_ICONGADGET_ICON(wid, bmFileName);
729 /******************************************************************************/
731 /* GetCorrectIconType */
733 /* INPUT: icon file name */
735 /* OUTPUT: correct icon type of icon file name passed */
737 /******************************************************************************/
738 char * GetCorrectIconType(char *pszIconFile)
742 char pszNewType[MAX_EXT_SIZE];
745 strcpy(pszNewType, PIXMAP_EXT);
747 strcpy(pszNewType, BITMAP_EXT);
751 pszTmp = XtMalloc(strlen(pszIconFile) + strlen(pszNewType) + 1);
752 if (!pszTmp) return((char *)NULL);
753 strcpy(pszTmp, pszIconFile);
754 ptr = strrchr(pszTmp, '.');
756 strcpy(ptr, pszNewType);
759 pszTmp = (char *)NULL;
763 /******************************************************************************/
767 /* INPUT: icon file name */
769 /* OUTPUT: mask file name for icon name passed in */
771 /******************************************************************************/
772 char * CreateMaskName(char *pszIconName)
779 char type_ext[MAX_EXT_SIZE + 2];
780 char size_ext[MAX_EXT_SIZE + 2];
783 /***************************************************************/
784 /* initialize temp arrays */
785 /***************************************************************/
789 /***************************************************************/
790 /* alloc memory for temporary name */
791 /***************************************************************/
792 pszTmpName = (char *)XtMalloc(strlen(pszIconName) + 1);
794 strcpy(pszTmpName, pszIconName);
796 return((char *)NULL);
799 /*****************************************/
800 /* Strip off icon type extension. */
801 /*****************************************/
802 ptr = strrchr(pszTmpName, '.');
804 type_name = strtok(ptr, ".");
807 type_name = (char *)NULL;
810 /*****************************************/
811 /* Get size extention. */
812 /*****************************************/
813 ptr = strrchr(pszTmpName, '.');
815 size_name = strtok(ptr, ".");
818 size_name = (char *)NULL;
821 /*****************************************/
822 /* Alloc the storage for the new name */
823 /*****************************************/
824 bytesneeded += ((pszTmpName) ? strlen(pszTmpName) : 0);
825 bytesneeded += strlen("_m..");
826 bytesneeded += ((size_name) ? strlen(size_name) : 0);
827 bytesneeded += ((type_name) ? strlen(type_name) : 0);
828 pszNewName = (char *)XtMalloc(bytesneeded + 1);
830 /*****************************************/
831 /* Create extension names */
832 /*****************************************/
834 sprintf(size_ext, ".%s", size_name);
837 sprintf(type_ext, ".%s", type_name);
839 /*****************************************/
840 /* And construct the new name from pieces*/
841 /*****************************************/
844 sprintf(pszNewName, "%s%s_m%s", pszTmpName, size_ext, type_ext);
846 sprintf(pszNewName, "%s_m%s%s", pszTmpName, size_ext, type_ext);
849 if (pszTmpName) XtFree(pszTmpName);
852 printf("Mask file name = '%s'\n", pszNewName); /* debug */