1 /* $XConsortium: icon_selection_dialog.c /main/10 1996/10/15 13:39:13 rswiston $ */
2 /*******************************************************************************
3 icon_selection_dialog.c
5 Associated Header file: icon_selection_dialog.h
6 *******************************************************************************/
13 #if defined(USL) || defined(__uxp__)
14 #define S_ISLNK(mode) ((mode & S_IFMT) == S_IFLNK)
18 #include <Xm/MwmUtil.h>
19 #include <Xm/DialogS.h>
20 #include <Xm/MenuShell.h>
22 #include <Xm/ScrolledW.h>
26 #include <Xm/SeparatoG.h>
29 #include <Xm/RowColumn.h>
30 #include <Xm/MessageB.h>
31 #include <X11/cursorfont.h>
41 /*******************************************************************************
42 Includes, Defines, and Global variables from the Declarations Editor:
43 *******************************************************************************/
45 #include <sys/types.h> /* for directory routines */
49 #include <dirent.h> /* includes sys/dir.h */
51 #include <Xm/ScrolledW.h>
53 /*#include "Container.h"*/
55 static char *selected_icon_name = (char *)NULL;
56 static Widget selected_icon = (Widget)NULL;
57 static int icon_count = 0;
59 char *file_filter_global;
60 DtIconGadget **icons_in_container = NULL;
63 int myscandir(char *, struct dirent ***, int (), int ());
64 int get_top_b1_position (int buttoncount);
65 int get_top_b2_position (int buttoncount);
66 void load_directories_list (char **dirlist);
67 char *get_initial_filter (void);
68 void load_filter_text_field (char *filter);
69 char *update_filter (char *filter);
70 void apply_filter (char *filter);
71 char *initialize_filter (char *filter_end);
72 struct dirent **build_dirent_list (char *filter, int *filecount);
73 void update_container_contents (char *filter);
74 void free_container_contents (void);
75 int new_name_select(struct dirent *, char *);
76 /*int name_select(struct dirent *);*/
77 static void selectionCB_icon_scrolled_container ( Widget UxWidget,
78 XtPointer UxClientData,
79 XtPointer UxCallbackArg);
80 static void calc_bottom_attachment( Widget UxWidget,
81 XtPointer UxClientData,
82 XtPointer UxCallbackArg);
84 /*******************************************************************************
85 The following header file defines the context structure.
86 *******************************************************************************/
88 #define CONTEXT_MACRO_ACCESS 1
89 #include "icon_selection_dialog.h"
90 #undef CONTEXT_MACRO_ACCESS
93 /*******************************************************************************
94 Auxiliary code from the Declarations Editor:
95 *******************************************************************************/
97 /*********************************************************************/
98 /* auxfuncs - icon selection dialog auxiliary functions */
99 /*********************************************************************/
101 /***************************************************************************/
105 /***************************************************************************/
106 int myscandir(char *pszDirName, struct dirent ***NameList, int Select(), int Compare())
111 struct dirent *dptmp;
114 struct dirent **adirent;
115 #define AINCREMENT ((int)512)
116 int sizeArray = AINCREMENT;
117 char *msgPtr, *fmtPtr, *errPtr;
119 if (!(dirptr = opendir(pszDirName))) {
120 /* INTERNATIONALIZE */
121 msgPtr = "Could not open the following directory:";
123 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
124 strlen(pszDirName) + 1) * sizeof(char));
125 sprintf(errPtr, fmtPtr, msgPtr, pszDirName);
126 display_error_message(CreateActionAppShell, errPtr);
132 size = sizeof(void *) * 1024;
133 *NameList = (struct dirent **)malloc(sizeof(void *) * 1024);
136 adirent = (struct dirent **)malloc(sizeof(void *) * sizeArray);
137 for (dp = readdir(dirptr); dp != NULL; dp = readdir(dirptr)) {
140 if ((*Select)(dp, pszDirName)) {
141 (*NameList)[count] = dp;
145 if ((*Select)(dp, pszDirName)) {
146 dptmp = (struct dirent *)malloc(sizeof(struct dirent) + strlen(dp->d_name) + 1);
147 memcpy(dptmp, dp, sizeof(struct dirent));
148 strcpy(dptmp->d_name, dp->d_name);
149 adirent[count] = dptmp;
151 if (count == (sizeArray - 1)) {
152 adirent = (struct dirent **)realloc(adirent, (sizeof(void *) * (sizeArray + AINCREMENT)));
154 sizeArray += AINCREMENT;
165 /***************************************************************************/
167 /* build_dirent_list - builds a list of icon files to be displayed */
169 /* Input: char *filter - directory in which to search for files */
170 /* Output: struct dirent **namelist - list of files */
172 /***************************************************************************/
173 struct dirent **build_dirent_list (char *filter, int *filecount)
176 char *dirname, *dirname_end;
178 struct dirent **namelist;
179 char *msgPtr, *fmtPtr, *errPtr;
181 /********************************************************************/
182 /* initialize filecount and namelist */
183 /********************************************************************/
187 /********************************************************************/
188 /* get length of file filter and create a copy */
189 /********************************************************************/
190 dirname = (char *)calloc (strlen(filter)+1, sizeof(char));
194 printf("error callocing memory for dirname\n");
195 printf("dirname of size: %i\n", strlen(dirname));
199 dirname = strcpy (dirname, filter);
201 /********************************************************************/
202 /* strip wildcard from end of directory name */
203 /********************************************************************/
204 dirname_end = strrchr (dirname, '/');
205 dirname_end[1] = '\0';
207 /********************************************************************/
208 /* build list of file name that match the wildcard string */
209 /********************************************************************/
210 dirptr = (DIR *)opendir (dirname);
214 *filecount = myscandir (dirname, &namelist, new_name_select, NULL);
217 printf("# of icons = %d\n", *filecount);
221 /* INTERNATIONALIZE */
222 msgPtr = "Could not open the following directory:";
224 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
225 strlen(dirname) + 1) * sizeof(char));
226 sprintf(errPtr, fmtPtr, msgPtr, dirname);
227 display_error_message(CreateActionAppShell, errPtr);
233 printf ("Freeing dirname, sizeof: %ld\n", (long)sizeof(dirname));
240 /***************************************************************************/
242 /* new_name_select - determines if file is included in list of icon */
243 /* files to be displayed in a container */
244 /* Input: struct dirent *dir_entry - directory entry structure */
245 /* Output: (int)found - >0 if file name accepted, 0 otherwise */
247 /***************************************************************************/
248 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
250 struct stat stat_buffer;
253 /***********************************************************************/
254 /* This will only filter the icons of the filter size which by default */
255 /* is medium icons. */
256 /***********************************************************************/
257 if (strstr(dir_entry->d_name, file_filter_global)) {
258 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
259 if (!stat(filename, &stat_buffer)) {
260 if ( (S_ISREG(stat_buffer.st_mode)) ||
261 (S_ISLNK(stat_buffer.st_mode)) ) {
269 /***********************************************************************/
270 /* This is the new filter to get all three sizes of icons. */
271 /***********************************************************************/
273 if ( (strstr(dir_entry->d_name, ".l.pm")) ||
274 (strstr(dir_entry->d_name, ".m.pm")) ||
275 (strstr(dir_entry->d_name, ".t.pm")) ) {
276 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
277 if (!stat(filename, &stat_buffer)) {
278 if ( (S_ISREG(stat_buffer.st_mode)) ||
279 (S_ISLNK(stat_buffer.st_mode)) ) {
285 if ( (strstr(dir_entry->d_name, ".l.bm")) ||
286 (strstr(dir_entry->d_name, ".m.bm")) ||
287 (strstr(dir_entry->d_name, ".t.bm")) ) {
288 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
289 if (!stat(filename, &stat_buffer)) {
290 if ( (S_ISREG(stat_buffer.st_mode)) ||
291 (S_ISLNK(stat_buffer.st_mode)) ) {
303 /***************************************************************************/
305 /* new_name_select - determines if file is included in list of icon */
306 /* files to be displayed in a container */
307 /* Input: struct dirent *dir_entry - directory entry structure */
308 /* Output: (int)found - >0 if file name accepted, 0 otherwise */
310 /***************************************************************************/
311 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
313 struct stat stat_buffer;
316 if (strstr(dir_entry->d_name, file_filter_global)) {
317 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
318 if (!stat(filename, &stat_buffer)) {
319 if ( (S_ISREG(stat_buffer.st_mode)) ||
320 (S_ISLNK(stat_buffer.st_mode)) ) {
329 /***************************************************************************/
331 /* int get_top_b1_position - determine position of button */
332 /* INPUT: int buttoncount - number of buttons in row */
333 /* OUTPUT: int position - position of left edge of button */
335 /***************************************************************************/
336 int get_top_b1_position (int buttoncount)
340 switch (buttoncount) {
341 case 1: position = 38; break;
342 case 2: position = 14; break;
343 case 3: position = 8; break;
344 default : position = 0;
350 /***************************************************************************/
352 /* int get_top_b2_position - determine position of button */
353 /* INPUT: int buttoncount - number of buttons in row */
354 /* OUTPUT: int position - position of left edge of button */
356 /***************************************************************************/
357 int get_top_b2_position (int buttoncount)
361 switch (buttoncount) {
362 case 2: position = 60; break;
363 case 3: position = 40; break;
364 default : position = 0;
370 /***************************************************************************/
372 /* void load_directories_list - load scrolled list with directory */
374 /* Input: char **dirlist - list of text strings */
377 /***************************************************************************/
378 void load_directories_list (char **dirlist)
380 XmStringTable xmstringlist;
384 /******************************************************************/
385 /* get number of directories in list */
386 /******************************************************************/
387 stringcount = countItems (dirlist);
389 /******************************************************************/
390 /* convert strings to xmstrings */
391 /******************************************************************/
392 xmstringlist = (XmStringTable) TextStringsToXmStrings (dirlist);
394 /******************************************************************/
395 /* put xmstrings in list */
396 /******************************************************************/
397 XtVaSetValues (dir_scrolled_list, XmNitems, xmstringlist,
398 XmNitemCount, stringcount, NULL);
400 XmListSelectPos(dir_scrolled_list, 1, False);
401 /******************************************************************/
402 /* free xmstrings array */
403 /******************************************************************/
404 for (i=0; i < stringcount; i++) {
405 XmStringFree(xmstringlist[i]);
412 /***************************************************************************/
414 /* void initialize_filter - build path/wildcard filter */
416 /* Output: char *initial_filter */
418 /***************************************************************************/
419 char *initialize_filter (char *filter_end)
421 char *filter, *initial_filter;
422 int filter_length, filter_end_length;
425 /******************************************************************/
426 /* initial filter string is first directory in list */
427 /******************************************************************/
428 filter = get_initial_filter ();
430 /******************************************************************/
431 /* determine space needed */
432 /******************************************************************/
433 filter_length = strlen(filter);
434 if ((filter[filter_length-1] == '/') && (filter_end[0] == '/')) {
437 if (!(filter[filter_length-1] == '/') && !(filter_end[0] == '/')) {
443 filter_end_length = strlen(filter_end);
445 /******************************************************************/
446 /* allocate space and put string in initial filter */
447 /******************************************************************/
448 initial_filter = (char *)calloc (filter_length + filter_end_length + 1,
451 if (!initial_filter) printf("Error callocing memory in initialize_filter.\n");
453 initial_filter = strcpy (initial_filter, filter);
454 if (add_slash) initial_filter[filter_length-1] = '/';
455 initial_filter = strcat (initial_filter, filter_end);
457 return(initial_filter);
460 /***************************************************************************/
462 /* char *get_initial_filter - get value of first file filter */
464 /* Output: char *new_filter - string containing filter */
466 /***************************************************************************/
467 char *get_initial_filter (void)
471 /******************************************************************/
472 /* initial filter is first one in directory list */
473 /******************************************************************/
474 new_filter = (char *)directories_list[0];
478 /***************************************************************************/
480 /* char *update_filter - put main filter end on new main filter */
481 /* Input: char *filter - new filter from which gets main filter end */
482 /* Output: char *new_filter - new main filter */
484 /***************************************************************************/
485 char *update_filter (char *filter)
487 char *filter_end, *new_filter, *main_end;
488 char *fe_ptr, *ffg_ptr;
490 /******************************************************************/
492 /******************************************************************/
493 main_end = strrchr (main_filter, '/');
494 filter_end = (char *)calloc(strlen(main_end)+1, sizeof(char));
498 printf("Error callocing memory for filter_end in update_filter.\n");
501 filter_end = strcpy (filter_end, main_end);
503 /******************************************************************/
504 /* determine what filter should be depending on icon type (pm/bm) */
505 /******************************************************************/
506 if (fe_ptr = strrchr(filter_end, EXT_DELIMITER)) {
507 ffg_ptr = strrchr(file_filter_global, EXT_DELIMITER);
509 if ((int)strlen(fe_ptr) >= (int)strlen(PIXMAP_EXT)) {
510 strcpy(fe_ptr, PIXMAP_EXT);
512 if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(PIXMAP_EXT)) ) {
513 strcpy(ffg_ptr, PIXMAP_EXT);
516 if ((int)strlen(fe_ptr) >= (int)strlen(BITMAP_EXT)) {
517 strcpy(fe_ptr, BITMAP_EXT);
519 if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(BITMAP_EXT)) ) {
520 strcpy(ffg_ptr, BITMAP_EXT);
525 /******************************************************************/
526 /* find old end on main filter and delete it */
527 /******************************************************************/
528 main_end = memset (main_end, '\0', strlen(main_end));
530 /******************************************************************/
531 /* allocate space for new filter */
532 /******************************************************************/
533 new_filter = (char *)calloc (strlen(filter) +
534 strlen(filter_end) + 1, sizeof(char));
537 printf("Error callocing memory for new_filter in update_filter.\n");
540 new_filter = strcpy (new_filter, filter);
542 /******************************************************************/
543 /* put new end on filter */
544 /******************************************************************/
545 new_filter = strcat (new_filter, filter_end);
547 /******************************************************************/
548 /* display new file filter in text field */
549 /******************************************************************/
550 load_filter_text_field (new_filter);
552 /******************************************************************/
554 /******************************************************************/
560 /***************************************************************************/
562 /* void apply_filter - apply filter to create a list of files and */
563 /* display files in scrolled list */
564 /* Input: char *filter - file filter to use */
567 /***************************************************************************/
568 void apply_filter (char *filter)
572 /******************************************************************/
573 /* Get length of main file filter and create a copy */
574 /******************************************************************/
575 old_main = (char *)calloc (strlen(main_filter)+1, sizeof(char));
578 if (!old_main) printf("Calloc error for old_main, in apply filter.\n");
581 old_main = strcpy (old_main, main_filter);
583 /******************************************************************/
584 /* Update main filter to reflect changes made by user */
585 /******************************************************************/
586 main_filter = update_filter (filter);
588 /******************************************************************/
589 /* if the filter has changed, update container with new icons */
590 /******************************************************************/
591 if (strcmp (old_main, main_filter)) {
593 /******************************************************************/
594 /* Turn on the hour glass */
595 /******************************************************************/
596 TurnOnHourGlassAllWindows();
598 /******************************************************************/
599 /* Since we are changing to a new directory, clear out the */
600 /* globals and clear the selected icon text string. */
601 /******************************************************************/
603 _DtIconSetState(selected_icon, FALSE, FALSE);
604 selected_icon = (Widget)NULL;
606 if (selected_icon_name) {
607 XtFree(selected_icon_name);
608 selected_icon_name = (char *)NULL;
610 XmTextFieldSetString (icon_name_text_field, "");
612 /******************************************************************/
613 /* Update the container icon gadgets */
614 /******************************************************************/
615 update_container_contents (main_filter);
617 /******************************************************************/
618 /* Turn off the hour glass */
619 /******************************************************************/
620 TurnOffHourGlassAllWindows();
624 printf ("Freeing old_main, sizeof: %ld\n", (long)sizeof(old_main));
632 /***************************************************************************/
634 /* void load_filter_text_field - display file filter text */
635 /* Input: char *filter - file filter text string */
638 /***************************************************************************/
639 void load_filter_text_field (char *filter)
641 if (use_filter_field) {
642 /* display file filter in text field */
643 XmTextFieldSetString (filter_text_field, filter);
644 /* set cursor to end of string */
645 XmTextSetInsertionPosition (filter_text_field, strlen(filter));
651 /***************************************************************************/
653 /* void update_container_contents - create new icon gadgets which */
654 /* correspont to the new filter */
655 /* Input: char *filter - file filter text string */
658 /***************************************************************************/
659 void update_container_contents (char *filter)
661 char *path, *pathend;
662 char iconfile[MAXFILENAME];
664 struct dirent **filelist;
665 int count, old_count;
671 XtUnmanageChild (icon_scrolled_container);
672 /* free_container_contents (); */
674 path = (char *)calloc (strlen(filter)+1, sizeof(char));
677 if (!path) printf("Calloc error for path, in update_container_contents.\n");
680 path = strcpy (path, filter);
681 pathend = strrchr (path, '/');
684 /******************************************************************/
685 /* Get number of icon files and list of file names */
686 /******************************************************************/
687 filelist = build_dirent_list (filter, &namecount);
689 /******************************************************************/
690 /* Set up argument list */
691 /******************************************************************/
694 XtSetArg(args[n], XmNimageName, "/usr/dt/appconfig/icons/C/Dtactn.m.pm"); n++;
696 XtSetArg(args[n], XmNimageName, NULL); n++;
697 XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
698 XtSetArg(args[n], XmNbehavior, XmICON_TOGGLE); n++;
699 XtSetArg(args[n], XmNrecomputeSize, TRUE); n++;
700 XtSetArg(args[n], XmNfillOnArm, TRUE); n++;
701 XtSetArg(args[n], XmNtraversalOn, TRUE); n++;
703 /******************************************************************/
704 /* Need at least one icon for the empty directory icon. */
705 /******************************************************************/
712 /******************************************************************/
713 /* create any additional icon gadgets */
714 /******************************************************************/
715 if (count > icon_count) {
716 old_count = icon_count;
718 icons_in_container = (DtIconGadget **)realloc
720 (icon_count+1) * sizeof(DtIconGadget *));
721 /*memset(&(icons_in_container[icon_count]), 0, sizeof(DtIconGadget *));*/
722 for (lcv = old_count; lcv < icon_count; lcv++) {
723 icons_in_container[lcv] =
724 /*(DtIconGadget *)XtCreateManagedWidget (filelist[lcv]->d_name,*/
725 (DtIconGadget *)XtCreateManagedWidget ("IconGadget",
726 dtIconGadgetClass, (Widget)icon_scrolled_container,
728 XtAddCallback((Widget) icons_in_container[lcv], XmNcallback,
729 (XtCallbackProc) selectionCB_icon_scrolled_container,
733 if (!icons_in_container[lcv])
734 printf("Error creating icon gadget, in update_container_contents\n");
738 if (!icons_in_container[lcv]) {
739 printf ("Could not allocate memory to create new icon\n", lcv);
745 printf ("Created icon #%i\n", lcv);
750 } /* end if (count > icon_count) */
752 /******************************************************************/
753 /* load icon gadgets with information */
754 /******************************************************************/
756 /****************************************************************/
757 /* The following flush call is a work-around for a known motif */
758 /* bug. This is here in the application because motif will not */
759 /* correct this bug because doing so would impair performance. */
760 /* Therefore, I am forced to add this call to the code. */
761 /* The problem this fixes is that when new icons are added to */
762 /* the filesystem after the application is already up and */
763 /* running, the icon gadgets to not see them. */
764 /****************************************************************/
765 XmeFlushIconFileCache(NULL);
767 for (lcv = 0; lcv < count; lcv++) {
768 sprintf (iconfile, "%s%s", path, filelist[lcv]->d_name);
769 ptr = strstr(filelist[lcv]->d_name, ".m.");
773 xmstring = XmStringCreateLocalized(filelist[lcv]->d_name);
774 XtVaSetValues ((Widget) icons_in_container[lcv],
776 XmNimageName, iconfile,
778 XtManageChild((Widget) icons_in_container [lcv]);
779 XmStringFree(xmstring);
782 printf ("Loading icon gadget #%i\n", lcv);
787 /******************************************************************/
788 /* This is the empty directory case */
789 /******************************************************************/
791 strcpy(iconfile, GETMESSAGE(11, 60, "[Empty]"));
792 xmstring = XmStringCreateLocalized(iconfile);
793 XtVaSetValues ((Widget) icons_in_container[0],
795 XmNimageName, (char *)NULL,
797 XtManageChild((Widget) icons_in_container[0]);
798 XmStringFree(xmstring);
801 /******************************************************************/
802 /* unmanage any spare icon gadgets */
803 /******************************************************************/
804 for (lcv = count; lcv < icon_count; lcv++) {
805 XtUnmanageChild ((Widget) icons_in_container[lcv]);
808 /******************************************************************/
809 /* free dirent list */
810 /******************************************************************/
811 for (lcv = 0; lcv < namecount; lcv++) {
812 free (filelist[lcv]);
818 XtManageChild (icon_scrolled_container);
823 #ifdef _ICONSELECTOR_DESTROY_ENABLED
824 /***************************************************************************/
826 /* void free_container_contents - free icon gadgets in container */
830 /***************************************************************************/
831 void free_container_contents (void)
838 if (icons_in_container) {
839 screen_id = XtScreen (icons_in_container[0]);
841 while (icons_in_container[lcv]) {
843 XtVaGetValues (icons_in_container[lcv], XmNimageName, &filename,
844 XmNpixmap, &icon_pixmap, NULL);
845 XmDestroyPixmap (screen_id, icon_pixmap);
847 XtVaSetValues (icons_in_container[lcv], XmNpixmap, NULL, NULL);
849 XtDestroyWidget (icons_in_container[lcv]);
851 icons_in_container[lcv]=NULL;
854 } /* end while icons_in_container */
855 free (icons_in_container);
856 icons_in_container = NULL;
860 printf ("In free_container_contents...\n");
861 printf ("Just destroyed all %i icons.\n", lcv);
871 /***************************************************************************/
873 /* void load_new_filter - displays selected directory string as */
874 /* new filter base */
875 /* Input: char *new_filter - new directory string to use as filter */
878 /***************************************************************************/
879 void load_new_filter (char *new_filter)
881 /* no longer need old filter */
884 /* create space for new filter */
885 main_filter = (char *)calloc (strlen(new_filter)+3, sizeof (char));
887 if (!main_filter) printf("Calloc error for main_filter, in load_new_filter.\n");
889 /* copy new filter and add filter end */
890 main_filter = strcpy (main_filter, new_filter);
891 main_filter = strcat (main_filter, "/*");
892 /* display new filter */
893 load_filter_text_field (main_filter);
899 /*****************************************************************************/
900 /* The following are callback functions. */
901 /*****************************************************************************/
903 /***************************************************************************/
905 /* calc_bottom_attachment */
908 /***************************************************************************/
909 static void calc_bottom_attachment( Widget UxWidget,
910 XtPointer UxClientData,
911 XtPointer UxCallbackArg )
913 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
915 UxSaveCtx = UxIcon_selection_dialogContext;
916 UxIcon_selection_dialogContext = UxContext =
917 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
919 if (numberOfTopButtons > 0) {
920 XtVaSetValues (UxWidget, XmNbottomWidget, top_button_form, NULL);
921 } else if (use_icon_name_field) {
922 XtVaSetValues (UxWidget, XmNbottomWidget, icon_name_textfield_label, NULL);
923 } else XtVaSetValues (UxWidget, XmNbottomWidget, separatorGadget1, NULL);
928 /***************************************************************************/
930 /* activateCB_bottom_button */
933 /***************************************************************************/
934 /* default cb for bottom buttons */
935 static void activateCB_bottom_button( Widget UxWidget,
936 XtPointer UxClientData,
937 XtPointer UxCallbackArg )
939 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
941 UxSaveCtx = UxIcon_selection_dialogContext;
942 UxIcon_selection_dialogContext = UxContext =
943 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
949 /******************************************************************************/
950 /* activateCB_NoFindIconDialog_ChangeNameButton */
951 /******************************************************************************/
952 void activateCB_NoFindIconDialog_ChangeNameButton( Widget UxWidget,
953 XtPointer UxClientData,
954 XtPointer UxCallbackArg)
957 XtDestroyWidget(UxWidget);
960 /******************************************************************************/
961 /* activateCB_NoFindIconDialog_NameOKButton */
962 /******************************************************************************/
963 void activateCB_NoFindIconDialog_NameOKButton( Widget UxWidget,
964 XtPointer UxClientData,
965 XtPointer UxCallbackArg)
968 char *basename = (char *)NULL;
970 TurnOnHourGlassAllWindows();
971 if (bottom_button_one_cb) {
972 GetWidgetTextString(icon_name_text_field, &basename);
973 bottom_button_one_cb(UxWidget,
974 (XtPointer)basename, UxCallbackArg);
975 if (basename) XtFree(basename);
977 TurnOffHourGlassAllWindows();
978 UxPopdownInterface (IconSelector);
979 XtDestroyWidget(UxWidget);
982 /******************************************************************************/
983 /* display_nofindicon_message - display cant find icons error dialog */
984 /* INPUT: Widget parent - parent to position error dialog new */
986 /******************************************************************************/
987 void display_nofindicon_message (Widget parent)
993 dialog = XmCreateErrorDialog(parent, "nofindiconDialog", NULL, 0);
995 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
996 XtVaSetValues(widChild,
997 RES_CONVERT( XmNlabelString, "Change Name"),
1000 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
1001 XtVaSetValues(widChild,
1002 RES_CONVERT( XmNlabelString, "Name OK"),
1005 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
1007 XtAddCallback( dialog, XmNokCallback,
1008 (XtCallbackProc) activateCB_NoFindIconDialog_ChangeNameButton,
1010 XtAddCallback( dialog, XmNcancelCallback,
1011 (XtCallbackProc) activateCB_NoFindIconDialog_NameOKButton,
1014 /********* WARNING - this needs to be translated !!! ***********/
1015 strcpy(buffer, "There is no set of icons with that filename in the icon folders.\n");
1016 strcat(buffer, "Move the icons into one of the icon folers, then select \"Name OK\".\n");
1017 strcat(buffer, "Or, to select a different set of icons, select \"Change Name\".\n");
1018 strcat(buffer, "\nIf you are a software developer creating a registration package,\n");
1019 strcat(buffer, "ignore this message and select \"Name OK\".");
1020 XtVaSetValues (dialog,
1021 RES_CONVERT(XmNdialogTitle, GETMESSAGE(6, 31, "Create Action - Error")),
1022 RES_CONVERT(XmNmessageString, buffer),
1025 XtManageChild (dialog);
1029 /***************************************************************************/
1031 /* activateCB_bottom_button1 */
1034 /***************************************************************************/
1035 /* cb for bottom button 1 = OK */
1036 static void activateCB_bottom_button1( Widget UxWidget,
1037 XtPointer UxClientData,
1038 XtPointer UxCallbackArg )
1040 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1042 UxSaveCtx = UxIcon_selection_dialogContext;
1043 UxIcon_selection_dialogContext = UxContext =
1044 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1046 char *basename = (char *)NULL;
1047 char *fullname = (char *)NULL;
1048 char *msgPtr, *errPtr;
1050 GetWidgetTextString(icon_name_text_field, &basename);
1052 if (strchr(basename, '/')) {
1053 /**** WARNING - this needs to be in a message catalog in the future ****/
1054 /* INTERNATIONALIZE */
1055 msgPtr = "Invalid Icon filename.\n\
1056 Pathnames are not valid in the \"Enter Icon Filename\" field.\n\
1057 Enter only the name of the icon without the path or extensions.";
1058 errPtr = XtNewString(msgPtr);
1059 display_error_message(IconSelector, errPtr);
1062 FIND_ICONGADGET_ICON(basename, fullname, DtMEDIUM);
1063 if ( (fullname) && (check_file_exists(fullname)) ) {
1064 TurnOnHourGlassAllWindows();
1065 if (bottom_button_one_cb) {
1066 bottom_button_one_cb(UxWidget,
1067 (XtPointer)fullname, UxCallbackArg);
1069 TurnOffHourGlassAllWindows();
1070 UxPopdownInterface (IconSelector);
1071 if (basename) XtFree(basename);
1073 display_nofindicon_message(IconSelector);
1077 msgPtr = GETMESSAGE(11, 50, "The Icon Filename is invalid.\n\
1078 Please enter a valid icon file name in the\n'Enter Icon Filename' field.");
1079 errPtr = XtNewString(msgPtr);
1080 display_error_message(IconSelector, errPtr);
1086 #if 0 /************* old code *********************/
1087 char *pszIconFileName = (char *)NULL;
1088 char buffer[MAXBUFSIZE];
1090 GetWidgetTextString(icon_name_text_field, &pszIconFileName);
1091 if ( (pszIconFileName) && (check_file_exists(pszIconFileName)) ) {
1092 TurnOnHourGlassAllWindows();
1093 if (bottom_button_one_cb) {
1094 bottom_button_one_cb(UxWidget,
1095 (XtPointer)pszIconFileName, UxCallbackArg);
1097 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1098 free_container_contents ();
1099 if (selected_icon_name) {
1100 XtFree(selected_icon_name);
1102 selected_icon_name = (char *)NULL;
1103 XtDestroyWidget (XtParent(icon_selection_dialog));
1104 IconSelector = (Widget)NULL;
1105 TurnOffHourGlassAllWindows();
1107 TurnOffHourGlassAllWindows();
1108 UxPopdownInterface (IconSelector);
1109 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1110 XtFree(pszIconFileName);
1112 strcpy(buffer, GETMESSAGE(11, 50, "The Icon Filename is invalid.\nPlease enter a valid icon file name in the\n'Enter Icon Filename' field."));
1113 display_error_message(IconSelector, buffer);
1118 if (selected_icon_name) {
1119 TurnOnHourGlassAllWindows();
1120 if (bottom_button_one_cb) {
1121 bottom_button_one_cb(UxWidget,
1122 (XtPointer)selected_icon_name, UxCallbackArg);
1124 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1125 free_container_contents ();
1126 XtFree(selected_icon_name);
1127 selected_icon_name = (char *)NULL;
1128 XtDestroyWidget (XtParent(icon_selection_dialog));
1129 IconSelector = (Widget)NULL;
1130 TurnOffHourGlassAllWindows();
1132 TurnOffHourGlassAllWindows();
1133 UxPopdownInterface (IconSelector);
1134 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1139 #endif /************* old code *********************/
1143 /***************************************************************************/
1145 /* activateCB_bottom_button2 */
1148 /***************************************************************************/
1149 /* cb for bottom button 2 = CANCEL */
1150 static void activateCB_bottom_button2( Widget UxWidget,
1151 XtPointer UxClientData,
1152 XtPointer UxCallbackArg )
1154 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1156 UxSaveCtx = UxIcon_selection_dialogContext;
1157 UxIcon_selection_dialogContext = UxContext =
1158 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1160 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1161 free_container_contents ();
1162 XtDestroyWidget (XtParent(icon_selection_dialog));
1163 IconSelector = (Widget)NULL;
1165 UxPopdownInterface (IconSelector);
1166 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1171 /***************************************************************************/
1173 /* activateCB_bottom_button3 */
1176 /***************************************************************************/
1177 /* default cb for bottom button3 = HELP */
1178 static void activateCB_bottom_button3( Widget UxWidget,
1179 XtPointer UxClientData,
1180 XtPointer UxCallbackArg )
1182 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1184 UxSaveCtx = UxIcon_selection_dialogContext;
1185 UxIcon_selection_dialogContext = UxContext =
1186 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1188 DisplayHelpDialog(UxWidget, (XtPointer)HELP_ICONSELECTOR, UxCallbackArg);
1193 /***************************************************************************/
1195 /* activateCB_filter_text_field */
1198 /***************************************************************************/
1199 static void activateCB_filter_text_field( Widget UxWidget,
1200 XtPointer UxClientData,
1201 XtPointer UxCallbackArg )
1203 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1204 UxSaveCtx = UxIcon_selection_dialogContext;
1205 UxIcon_selection_dialogContext = UxContext =
1206 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1210 filter = XmTextFieldGetString (UxWidget);
1211 apply_filter (filter);
1213 UxIcon_selection_dialogContext = UxSaveCtx;
1216 /***************************************************************************/
1218 /* defaultActionCB_dir_scrolled_list */
1221 /***************************************************************************/
1222 static void defaultActionCB_dir_scrolled_list( Widget UxWidget,
1223 XtPointer UxClientData,
1224 XtPointer UxCallbackArg )
1226 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1228 UxSaveCtx = UxIcon_selection_dialogContext;
1229 UxIcon_selection_dialogContext = UxContext =
1230 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1232 XmListCallbackStruct *listcb;
1235 listcb = (XmListCallbackStruct *) UxCallbackArg;
1236 filter = (char *)XmStringToText (listcb->item);
1237 apply_filter (filter);
1238 /* XtManageChild (icon_scrolled_win); */
1240 UxIcon_selection_dialogContext = UxSaveCtx;
1243 /***************************************************************************/
1245 /* selectionCB_icon_scrolled_container */
1247 /***************************************************************************/
1248 static void selectionCB_icon_scrolled_container ( Widget UxWidget,
1249 XtPointer UxClientData,
1250 XtPointer UxCallbackArg )
1253 XmString xmbasename;
1256 XtVaGetValues (UxWidget, XmNimageName, &filename, NULL);
1258 printf("In icon callback for '%s'\n", filename);
1260 if (use_icon_name_field) {
1261 XtVaGetValues (UxWidget, XmNstring, &xmbasename, NULL);
1262 basename = XmStringToText(xmbasename);
1263 XmTextFieldSetString (icon_name_text_field, basename);
1264 if (basename) free(basename);
1266 if (selected_icon_name) {
1267 if (selected_icon != UxWidget) {
1268 _DtIconSetState(selected_icon, FALSE, FALSE);
1270 XtFree(selected_icon_name);
1271 selected_icon_name = (char *)NULL;
1274 selected_icon_name = XtMalloc(strlen(filename) + 1);
1275 selected_icon_name = strcpy(selected_icon_name, filename);
1277 selected_icon_name = (char *)NULL;
1279 selected_icon = UxWidget;
1284 /***************************************************************************/
1286 /* resizeCB_clipWindow */
1288 /***************************************************************************/
1289 void resizeCB_clipWindow( Widget UxWidget,
1290 XtPointer UxClientData,
1291 XtPointer UxCallbackArg )
1293 Widget widvScrollbar;
1294 Widget widRowColumn;
1298 XtVaGetValues(XtParent(UxWidget), XmNverticalScrollBar, &widvScrollbar, NULL);
1299 widRowColumn = (Widget)UxClientData;
1300 XtVaGetValues(widRowColumn, XmNheight, &height, NULL);
1303 printf("height = %d\n", height);
1304 printf("icon_count = %d\n", icon_count);
1307 increment = (int)height / icon_count;
1308 XtVaSetValues(widvScrollbar, XmNincrement, increment, NULL);
1314 /***************************************************************************/
1316 /* _Uxbuild_icon_selection_dialog */
1319 /***************************************************************************/
1320 static Widget _Uxbuild_icon_selection_dialog(void)
1325 int ntotalbuttons = numberOfBottomButtons;
1326 #define TIGHTNESS 20
1329 Widget widclipWindow;
1331 /* Creation of icon_selection_dialog */
1332 _UxParent = UxParent;
1333 if ( _UxParent == NULL )
1335 _UxParent = UxTopLevel;
1338 _UxParent = XtVaCreatePopupShell( "icon_selection_dialog_shell",
1339 xmDialogShellWidgetClass, _UxParent,
1344 XmNshellUnitType, XmPIXELS,
1345 XmNkeyboardFocusPolicy, XmEXPLICIT,
1346 XmNtitle, "icon_selection_dialog",
1349 UxTmp0 = dialog_title ? (char *)dialog_title : "Icon Selection Window";
1351 icon_selection_dialog = XtVaCreateWidget( "icon_selection_dialog",
1354 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1357 XmNunitType, XmPIXELS,
1358 RES_CONVERT( XmNdialogTitle, UxTmp0 ),
1359 XmNautoUnmanage, FALSE,
1360 XmNdefaultPosition, FALSE,
1362 UxPutContext( icon_selection_dialog, (char *) UxIcon_selection_dialogContext );
1364 /*******************************************************************/
1365 /* Set up help callback */
1366 /*******************************************************************/
1367 XtAddCallback( icon_selection_dialog, XmNhelpCallback,
1368 (XtCallbackProc) helpCB_general,
1369 (XtPointer) HELP_ICONSELECTOR );
1372 /* Creation of bottom_button_form */
1373 bottom_button_form = XtVaCreateManagedWidget( "bottom_button_form",
1375 icon_selection_dialog,
1376 XmNskipAdjust, TRUE,
1377 XmNfractionBase, ((TIGHTNESS * ntotalbuttons) - 1),
1380 XmNleftAttachment, XmATTACH_FORM,
1382 XmNrightAttachment, XmATTACH_FORM,
1383 XmNbottomOffset, 20,
1384 XmNbottomAttachment, XmATTACH_FORM,
1387 UxPutContext( bottom_button_form, (char *) UxIcon_selection_dialogContext );
1390 UxTmp0 = bottom_button_one_label ? (char *)bottom_button_one_label : GETMESSAGE(6, 10, "OK");
1392 /* Creation of bottom_button1 = OK */
1393 bottom_button1 = XtVaCreateManagedWidget( "bottom_button1",
1394 xmPushButtonWidgetClass,
1396 RES_CONVERT( XmNlabelString, UxTmp0 ),
1398 XmNleftAttachment, nbutton ?
1399 XmATTACH_POSITION : XmATTACH_FORM,
1400 XmNleftPosition, TIGHTNESS * nbutton,
1401 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1402 XmATTACH_POSITION : XmATTACH_FORM,
1403 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1407 XtAddCallback( bottom_button1, XmNactivateCallback,
1408 (XtCallbackProc) activateCB_bottom_button1,
1411 UxPutContext( bottom_button1, (char *) UxIcon_selection_dialogContext );
1413 UxTmp0 = bottom_button_two_label ? (char *)bottom_button_two_label : GETMESSAGE(6, 12, "Cancel");
1415 /* Creation of bottom_button2 = CANCEL */
1416 bottom_button2 = XtVaCreateManagedWidget( "bottom_button2",
1417 xmPushButtonWidgetClass,
1419 RES_CONVERT( XmNlabelString, UxTmp0 ),
1421 XmNleftAttachment, nbutton ?
1422 XmATTACH_POSITION : XmATTACH_FORM,
1423 XmNleftPosition, TIGHTNESS * nbutton,
1424 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1425 XmATTACH_POSITION : XmATTACH_FORM,
1426 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1430 XtAddCallback( bottom_button2, XmNactivateCallback,
1431 (XtCallbackProc) bottom_button_two_cb ?
1432 bottom_button_two_cb : activateCB_bottom_button2,
1433 (XtPointer) UxIcon_selection_dialogContext );
1435 UxPutContext( bottom_button2, (char *) UxIcon_selection_dialogContext );
1437 UxTmp0 = bottom_button_three_label ? (char *)bottom_button_three_label : GETMESSAGE(6, 13, "Help");
1439 /* Creation of bottom_button3 = HELP */
1440 bottom_button3 = XtVaCreateManagedWidget( "bottom_button3",
1441 xmPushButtonWidgetClass,
1443 RES_CONVERT( XmNlabelString, UxTmp0 ),
1444 XmNuserData, icon_selection_dialog,
1446 XmNleftAttachment, nbutton ?
1447 XmATTACH_POSITION : XmATTACH_FORM,
1448 XmNleftPosition, TIGHTNESS * nbutton,
1449 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1450 XmATTACH_POSITION : XmATTACH_FORM,
1451 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1455 XtAddCallback( bottom_button3, XmNactivateCallback,
1456 (XtCallbackProc) bottom_button_three_cb ?
1457 bottom_button_three_cb : activateCB_bottom_button3,
1458 (XtPointer) UxIcon_selection_dialogContext );
1460 UxPutContext( bottom_button3, (char *) UxIcon_selection_dialogContext );
1462 UxTmp0 = bottom_button_four_label ? (char *)bottom_button_four_label : GETMESSAGE(12, 10, "Filter");
1464 /* Creation of bottom_button4 */
1465 bottom_button4 = XtVaCreateManagedWidget( "bottom_button4",
1466 xmPushButtonWidgetClass,
1468 RES_CONVERT( XmNlabelString, UxTmp0 ),
1470 XmNleftAttachment, nbutton ?
1471 XmATTACH_POSITION : XmATTACH_FORM,
1472 XmNleftPosition, TIGHTNESS * nbutton,
1473 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1474 XmATTACH_POSITION : XmATTACH_FORM,
1475 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1479 XtAddCallback( bottom_button4, XmNactivateCallback,
1480 (XtCallbackProc) bottom_button_four_cb ?
1481 bottom_button_four_cb : activateCB_bottom_button,
1482 (XtPointer) UxIcon_selection_dialogContext );
1484 UxPutContext( bottom_button4, (char *) UxIcon_selection_dialogContext );
1487 /* Creation of separatorGadget1 */
1488 separatorGadget1 = XtVaCreateManagedWidget( "separatorGadget1",
1489 xmSeparatorGadgetClass,
1490 icon_selection_dialog,
1494 XmNrightAttachment, XmATTACH_FORM,
1496 XmNleftAttachment, XmATTACH_FORM,
1497 XmNbottomOffset, 10,
1498 XmNbottomWidget, bottom_button_form,
1499 XmNbottomAttachment, XmATTACH_WIDGET,
1501 UxPutContext( separatorGadget1, (char *) UxIcon_selection_dialogContext );
1504 /* Creation of icon_name_text_field */
1505 icon_name_text_field = XtVaCreateManagedWidget( "icon_name_text_field",
1506 xmTextFieldWidgetClass,
1507 icon_selection_dialog,
1510 XmNbottomOffset, 10,
1511 XmNbottomWidget, separatorGadget1,
1512 XmNbottomAttachment, XmATTACH_WIDGET,
1514 XmNrightAttachment, XmATTACH_FORM,
1516 XmNleftAttachment, XmATTACH_FORM,
1518 UxPutContext( icon_name_text_field, (char *) UxIcon_selection_dialogContext );
1519 ISD_SelectedIconTextField = icon_name_text_field;
1521 UxTmp0 = name_field_title ? (char *)name_field_title : GETMESSAGE(11, 12, "Enter Icon Filename");
1523 /* Creation of icon_name_textfield_label */
1524 icon_name_textfield_label = XtVaCreateManagedWidget( "icon_name_textfield_label",
1526 icon_selection_dialog,
1529 RES_CONVERT( XmNlabelString, UxTmp0 ),
1531 XmNbottomWidget, icon_name_text_field,
1532 XmNbottomAttachment, XmATTACH_WIDGET,
1534 XmNleftWidget, icon_name_text_field,
1535 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1536 XmNalignment, XmALIGNMENT_BEGINNING,
1538 UxPutContext( icon_name_textfield_label, (char *) UxIcon_selection_dialogContext );
1540 UxTmp0 = filter_field_title ? (char *)filter_field_title : GETMESSAGE(12, 10, "Filter");
1542 /* Creation of filter_textfield_label */
1543 filter_textfield_label = XtVaCreateManagedWidget( "filter_textfield_label",
1545 icon_selection_dialog,
1548 RES_CONVERT( XmNlabelString, UxTmp0 ),
1549 XmNalignment, XmALIGNMENT_BEGINNING,
1551 XmNtopAttachment, XmATTACH_FORM,
1553 XmNleftAttachment, XmATTACH_FORM,
1555 UxPutContext( filter_textfield_label, (char *) UxIcon_selection_dialogContext );
1558 /* Creation of filter_text_field */
1559 filter_text_field = XtVaCreateManagedWidget( "filter_text_field",
1560 xmTextFieldWidgetClass,
1561 icon_selection_dialog,
1565 XmNtopWidget, filter_textfield_label,
1566 XmNtopAttachment, XmATTACH_WIDGET,
1568 XmNrightAttachment, XmATTACH_FORM,
1570 XmNleftAttachment, XmATTACH_FORM,
1572 XtAddCallback( filter_text_field, XmNactivateCallback,
1573 (XtCallbackProc) activateCB_filter_text_field,
1574 (XtPointer) UxIcon_selection_dialogContext );
1576 UxPutContext( filter_text_field, (char *) UxIcon_selection_dialogContext );
1578 UxTmp0 = directory_title ? (char *)directory_title : GETMESSAGE(11, 30, "Icon Folders");
1580 /* Creation of directory_list_label */
1581 directory_list_label = XtVaCreateManagedWidget( "directory_list_label",
1583 icon_selection_dialog,
1586 XmNlabelType, XmSTRING,
1587 RES_CONVERT( XmNlabelString, UxTmp0 ),
1588 XmNalignment, XmALIGNMENT_BEGINNING,
1590 XmNtopWidget, filter_text_field,
1591 XmNtopAttachment, use_filter_field ? XmATTACH_WIDGET : XmATTACH_FORM,
1593 XmNleftAttachment, XmATTACH_FORM,
1595 UxPutContext( directory_list_label, (char *) UxIcon_selection_dialogContext );
1597 UxTmp0 = container_title ? (char *)container_title : GETMESSAGE(11, 11, "Icon Files");
1599 /* Creation of icon_container_label */
1600 icon_container_label = XtVaCreateManagedWidget( "icon_container_label",
1602 icon_selection_dialog,
1605 XmNlabelType, XmSTRING,
1606 RES_CONVERT( XmNlabelString, UxTmp0 ),
1607 XmNalignment, XmALIGNMENT_BEGINNING,
1609 XmNtopWidget, filter_text_field,
1610 XmNtopAttachment, XmATTACH_WIDGET,
1611 XmNleftAttachment, XmATTACH_POSITION,
1612 XmNleftPosition, 55,
1614 UxPutContext( icon_container_label, (char *) UxIcon_selection_dialogContext );
1617 /* Creation of top_button_form */
1618 top_button_form = XtVaCreateManagedWidget( "top_button_form",
1620 icon_selection_dialog,
1621 XmNresizePolicy, XmRESIZE_NONE,
1624 XmNbottomOffset, 10,
1625 XmNbottomWidget, use_icon_name_field ? icon_name_textfield_label : separatorGadget1,
1626 XmNbottomAttachment, XmATTACH_WIDGET,
1628 XmNrightAttachment, XmATTACH_FORM,
1630 XmNleftAttachment, XmATTACH_FORM,
1632 UxPutContext( top_button_form, (char *) UxIcon_selection_dialogContext );
1634 UxTmp0 = top_button_one_label ? (char *)top_button_one_label : "No_Label";
1636 /* Creation of top_button1 */
1637 top_button1 = XtVaCreateManagedWidget( "top_button1",
1638 xmPushButtonWidgetClass,
1643 XmNbottomAttachment, XmATTACH_FORM,
1644 XmNleftAttachment, XmATTACH_POSITION,
1646 XmNleftPosition, get_top_b1_position (numberOfTopButtons),
1647 RES_CONVERT( XmNlabelString, UxTmp0 ),
1649 XtAddCallback( top_button1, XmNactivateCallback,
1650 (XtCallbackProc) top_button_one_cb,
1651 (XtPointer) UxIcon_selection_dialogContext );
1653 UxPutContext( top_button1, (char *) UxIcon_selection_dialogContext );
1655 UxTmp0 = top_button_two_label ? (char *)top_button_two_label : "No_Label";
1657 /* Creation of top_button2 */
1658 top_button2 = XtVaCreateManagedWidget( "top_button2",
1659 xmPushButtonWidgetClass,
1665 XmNleftPosition, get_top_b2_position (numberOfTopButtons),
1666 XmNbottomAttachment, XmATTACH_FORM,
1667 XmNleftAttachment, XmATTACH_POSITION,
1668 RES_CONVERT( XmNlabelString, UxTmp0 ),
1670 XtAddCallback( top_button2, XmNactivateCallback,
1671 (XtCallbackProc) top_button_two_cb,
1672 (XtPointer) UxIcon_selection_dialogContext );
1674 UxPutContext( top_button2, (char *) UxIcon_selection_dialogContext );
1676 UxTmp0 = top_button_three_label ? (char *)top_button_three_label : "No_Label";
1678 /* Creation of top_button3 */
1679 top_button3 = XtVaCreateManagedWidget( "top_button3",
1680 xmPushButtonWidgetClass,
1684 RES_CONVERT( XmNlabelString, UxTmp0 ),
1685 XmNleftPosition, 72,
1687 XmNleftAttachment, XmATTACH_POSITION,
1689 XmNbottomAttachment, XmATTACH_FORM,
1691 XtAddCallback( top_button3, XmNactivateCallback,
1692 (XtCallbackProc) top_button_three_cb,
1693 (XtPointer) UxIcon_selection_dialogContext );
1695 UxPutContext( top_button3, (char *) UxIcon_selection_dialogContext );
1697 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1699 /* Creation of dir_scrolled_list */
1700 XtSetArg(args[i], XmNshadowThickness, 2); i++;
1701 XtSetArg(args[i], XmNlistSizePolicy, XmCONSTANT); i++;
1703 XtSetArg(args[i], XmNleftOffset, 10); i++;
1704 XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1705 XtSetArg(args[i], XmNtopOffset, 0); i++;
1706 XtSetArg(args[i], XmNtopWidget, directory_list_label); i++;
1707 XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1708 XtSetArg(args[i], XmNrightOffset, 20); i++;
1709 XtSetArg(args[i], XmNrightWidget, icon_container_label); i++;
1710 XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
1712 XtSetArg(args[i], XmNbottomOffset, 10); i++;
1713 if (numberOfTopButtons > 0) {
1714 XtSetArg(args[i], XmNbottomWidget, top_button_form); i++;
1715 } else if (use_icon_name_field) {
1716 XtSetArg(args[i], XmNbottomWidget, icon_name_textfield_label); i++;
1718 XtSetArg(args[i], XmNbottomWidget, separatorGadget1); i++;
1720 XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
1722 dir_scrolled_list = XmCreateScrolledList(icon_selection_dialog,
1723 "dir_scrolled_list",
1726 XtVaSetValues(dir_scrolled_list,
1727 XmNselectionPolicy, XmBROWSE_SELECT,
1728 XmNvisibleItemCount, 15,
1730 XtManageChild(dir_scrolled_list);
1732 UxPutContext( dir_scrolled_list, (char *) UxIcon_selection_dialogContext );
1733 calc_bottom_attachment (dir_scrolled_list,
1734 (XtPointer) UxIcon_selection_dialogContext,
1736 XtAddCallback( dir_scrolled_list, XmNdefaultActionCallback,
1737 (XtCallbackProc) defaultActionCB_dir_scrolled_list,
1738 (XtPointer) UxIcon_selection_dialogContext );
1740 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1742 /* Creation of icon_scrolled_win */
1743 icon_scrolled_win = XtVaCreateManagedWidget( "icon_scrolled_win",
1744 xmScrolledWindowWidgetClass,
1745 icon_selection_dialog,
1746 XmNscrollingPolicy, XmAUTOMATIC,
1747 /* XmNnavigationType, XmTAB_GROUP, */
1750 XmNscrollBarDisplayPolicy, XmAS_NEEDED,
1752 XmNrightAttachment, XmATTACH_FORM,
1754 XmNtopWidget, icon_container_label,
1755 XmNtopAttachment, XmATTACH_WIDGET,
1757 XmNleftWidget, icon_container_label,
1758 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1759 XmNbottomOffset, 10,
1760 XmNbottomWidget, XmATTACH_NONE,
1761 XmNbottomAttachment, XmATTACH_WIDGET,
1767 UxPutContext( icon_scrolled_win, (char *) UxIcon_selection_dialogContext );
1768 calc_bottom_attachment (icon_scrolled_win,
1769 (XtPointer) UxIcon_selection_dialogContext,
1772 /* Creation of icon_scrolled_container */
1773 icon_scrolled_container = XtVaCreateManagedWidget( "icon_scrolled_container",
1774 xmRowColumnWidgetClass,
1776 XmNnavigationType, XmTAB_GROUP,
1777 /*XmNborderWidth, 1,*/
1778 /*XmNnumColumns, 2,*/
1780 XmNorientation, XmVERTICAL,
1781 XmNpacking, XmPACK_COLUMN,
1782 XmNshadowThickness, 1,
1785 XtVaSetValues(icon_selection_dialog,
1786 XmNcancelButton, bottom_button2,
1789 XtAddCallback( icon_selection_dialog, XmNdestroyCallback,
1790 (XtCallbackProc) UxDestroyContextCB,
1791 (XtPointer) UxIcon_selection_dialogContext);
1793 XtVaGetValues (icon_scrolled_win, XmNclipWindow, &widclipWindow, NULL);
1794 XtAddCallback( widclipWindow, XmNresizeCallback,
1795 (XtCallbackProc) resizeCB_clipWindow,
1796 (XtPointer) icon_scrolled_container );
1798 return ( icon_selection_dialog );
1801 /*******************************************************************************
1802 The following is the 'Interface function' which is the
1803 external entry point for creating this interface.
1804 This function should be called from your application or from
1805 a callback function.
1806 *******************************************************************************/
1808 Widget create_icon_selection_dialog(swidget _UxUxParent,
1809 unsigned char *_Uxdialog_title,
1810 unsigned char *_Uxfilter_field_title,
1811 int _Uxuse_filter_field,
1812 unsigned char *_Uxfile_filter,
1813 unsigned char *_Uxdirectory_title,
1814 unsigned char **_Uxdirectories_list,
1815 unsigned char *_Uxcontainer_title,
1816 int _UxnumberOfTopButtons,
1817 unsigned char *_Uxtop_button_one_label,
1818 void (*_Uxtop_button_one_cb)(),
1819 unsigned char *_Uxtop_button_two_label,
1820 void (*_Uxtop_button_two_cb)(),
1821 unsigned char *_Uxtop_button_three_label,
1822 void (*_Uxtop_button_three_cb)(),
1823 int _Uxuse_icon_name_field,
1824 unsigned char *_Uxname_field_title,
1825 int _UxnumberOfBottomButtons,
1826 unsigned char *_Uxbottom_button_one_label,
1827 void (*_Uxbottom_button_one_cb)(),
1828 unsigned char *_Uxbottom_button_two_label,
1829 void (*_Uxbottom_button_two_cb)(),
1830 unsigned char *_Uxbottom_button_three_label,
1831 void (*_Uxbottom_button_three_cb)(),
1832 unsigned char *_Uxbottom_button_four_label,
1833 void (*_Uxbottom_button_four_cb)() )
1837 char *initial_filter;
1838 char *icon_file_name;
1841 _UxCicon_selection_dialog *UxContext;
1843 UxIcon_selection_dialogContext = UxContext =
1844 (_UxCicon_selection_dialog *) UxNewContext( sizeof(_UxCicon_selection_dialog), False );
1846 UxParent = _UxUxParent;
1847 dialog_title = _Uxdialog_title;
1848 filter_field_title = _Uxfilter_field_title;
1849 use_filter_field = _Uxuse_filter_field;
1850 file_filter = _Uxfile_filter;
1851 directory_title = _Uxdirectory_title;
1852 directories_list = _Uxdirectories_list;
1853 container_title = _Uxcontainer_title;
1854 numberOfTopButtons = _UxnumberOfTopButtons;
1855 top_button_one_label = _Uxtop_button_one_label;
1856 top_button_one_cb = _Uxtop_button_one_cb;
1857 top_button_two_label = _Uxtop_button_two_label;
1858 top_button_two_cb = _Uxtop_button_two_cb;
1859 top_button_three_label = _Uxtop_button_three_label;
1860 top_button_three_cb = _Uxtop_button_three_cb;
1861 use_icon_name_field = _Uxuse_icon_name_field;
1862 name_field_title = _Uxname_field_title;
1863 numberOfBottomButtons = _UxnumberOfBottomButtons;
1864 bottom_button_one_label = _Uxbottom_button_one_label;
1865 bottom_button_one_cb = _Uxbottom_button_one_cb;
1866 bottom_button_two_label = _Uxbottom_button_two_label;
1867 bottom_button_two_cb = _Uxbottom_button_two_cb;
1868 bottom_button_three_label = _Uxbottom_button_three_label;
1869 bottom_button_three_cb = _Uxbottom_button_three_cb;
1870 bottom_button_four_label = _Uxbottom_button_four_label;
1871 bottom_button_four_cb = _Uxbottom_button_four_cb;
1873 rtrn = _Uxbuild_icon_selection_dialog();
1875 switch (numberOfTopButtons){
1876 case 0 : XtUnmanageChild (top_button_form); break;
1877 case 1 : XtUnmanageChild (top_button2);
1878 case 2 : XtUnmanageChild (top_button3);
1881 if (numberOfBottomButtons == 3)
1882 XtUnmanageChild (bottom_button4);
1884 if (!use_filter_field) {
1885 XtUnmanageChild (filter_textfield_label);
1886 XtUnmanageChild (filter_text_field);
1889 if (!use_icon_name_field) {
1890 XtUnmanageChild (icon_name_textfield_label);
1891 XtUnmanageChild (icon_name_text_field);
1894 TurnOnHourGlassAllWindows();
1896 /******************************************************************/
1897 /* save file_filter */
1898 /******************************************************************/
1899 file_filter_global = (char *)calloc(strlen((char *)file_filter)+1, sizeof(char));
1902 if (!file_filter_global) printf("Calloc error for file_filter_global, in create_icon_selection_dialog.\n");
1905 if (file_filter[0] == '*')
1906 file_filter_global = strcpy(file_filter_global, (char *)&file_filter[1]);
1908 file_filter_global = strcpy(file_filter_global, (char *)file_filter);
1910 load_directories_list ((char **)directories_list);
1911 initial_filter = initialize_filter ((char *)file_filter);
1913 /******************************************************************/
1914 /* save main_filter */
1915 /******************************************************************/
1916 main_filter = (char *)calloc(strlen(initial_filter)+1, sizeof(char));
1919 if (!main_filter) printf("Calloc error for main_filter, in create_icon_selection_dialog.\n");
1922 main_filter = strcpy(main_filter, initial_filter);;
1924 icons_in_container = NULL;
1927 update_container_contents (initial_filter);
1929 /******************************************************************/
1930 /* set selected_icon_name to first name in list */
1931 /******************************************************************/
1933 if (icons_in_container) {
1934 XtVaGetValues (icons_in_container[0], XmNimageName, &icon_file_name, NULL);
1935 XmTextFieldSetString (icon_name_text_field, icon_file_name);
1936 selected_icon_name = XtMalloc(strlen(icon_file_name) + 1);
1937 if (selected_icon_name)
1938 selected_icon_name = strcpy(selected_icon_name, icon_file_name);
1942 load_filter_text_field (initial_filter);
1944 TurnOffHourGlassAllWindows();