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: icon_selection_dialog.c /main/10 1996/10/15 13:39:13 rswiston $ */
24 /*******************************************************************************
25 icon_selection_dialog.c
27 Associated Header file: icon_selection_dialog.h
28 *******************************************************************************/
35 #if defined(USL) || defined(__uxp__)
36 #define S_ISLNK(mode) ((mode & S_IFMT) == S_IFLNK)
40 #include <Xm/MwmUtil.h>
41 #include <Xm/DialogS.h>
42 #include <Xm/MenuShell.h>
44 #include <Xm/ScrolledW.h>
48 #include <Xm/SeparatoG.h>
51 #include <Xm/RowColumn.h>
52 #include <Xm/MessageB.h>
53 #include <X11/cursorfont.h>
63 /*******************************************************************************
64 Includes, Defines, and Global variables from the Declarations Editor:
65 *******************************************************************************/
67 #include <sys/types.h> /* for directory routines */
71 #include <dirent.h> /* includes sys/dir.h */
73 #include <Xm/ScrolledW.h>
75 /*#include "Container.h"*/
77 static char *selected_icon_name = (char *)NULL;
78 static Widget selected_icon = (Widget)NULL;
79 static int icon_count = 0;
81 char *file_filter_global;
82 DtIconGadget **icons_in_container = NULL;
85 int myscandir(char *, struct dirent ***, int (), int ());
86 int get_top_b1_position (int buttoncount);
87 int get_top_b2_position (int buttoncount);
88 void load_directories_list (char **dirlist);
89 char *get_initial_filter (void);
90 void load_filter_text_field (char *filter);
91 char *update_filter (char *filter);
92 void apply_filter (char *filter);
93 char *initialize_filter (char *filter_end);
94 struct dirent **build_dirent_list (char *filter, int *filecount);
95 void update_container_contents (char *filter);
96 void free_container_contents (void);
97 int new_name_select(struct dirent *, char *);
98 /*int name_select(struct dirent *);*/
99 static void selectionCB_icon_scrolled_container ( Widget UxWidget,
100 XtPointer UxClientData,
101 XtPointer UxCallbackArg);
102 static void calc_bottom_attachment( Widget UxWidget,
103 XtPointer UxClientData,
104 XtPointer UxCallbackArg);
106 /*******************************************************************************
107 The following header file defines the context structure.
108 *******************************************************************************/
110 #define CONTEXT_MACRO_ACCESS 1
111 #include "icon_selection_dialog.h"
112 #undef CONTEXT_MACRO_ACCESS
115 /*******************************************************************************
116 Auxiliary code from the Declarations Editor:
117 *******************************************************************************/
119 /*********************************************************************/
120 /* auxfuncs - icon selection dialog auxiliary functions */
121 /*********************************************************************/
123 /***************************************************************************/
127 /***************************************************************************/
128 int myscandir(char *pszDirName, struct dirent ***NameList, int Select(), int Compare())
133 struct dirent *dptmp;
136 struct dirent **adirent;
137 #define AINCREMENT ((int)512)
138 int sizeArray = AINCREMENT;
139 char *msgPtr, *fmtPtr, *errPtr;
141 if (!(dirptr = opendir(pszDirName))) {
142 /* INTERNATIONALIZE */
143 msgPtr = "Could not open the following directory:";
145 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
146 strlen(pszDirName) + 1) * sizeof(char));
147 sprintf(errPtr, fmtPtr, msgPtr, pszDirName);
148 display_error_message(CreateActionAppShell, errPtr);
154 size = sizeof(void *) * 1024;
155 *NameList = (struct dirent **)malloc(sizeof(void *) * 1024);
158 adirent = (struct dirent **)malloc(sizeof(void *) * sizeArray);
159 for (dp = readdir(dirptr); dp != NULL; dp = readdir(dirptr)) {
162 if ((*Select)(dp, pszDirName)) {
163 (*NameList)[count] = dp;
167 if ((*Select)(dp, pszDirName)) {
168 dptmp = (struct dirent *)malloc(sizeof(struct dirent) + strlen(dp->d_name) + 1);
169 memcpy(dptmp, dp, sizeof(struct dirent));
170 strcpy(dptmp->d_name, dp->d_name);
171 adirent[count] = dptmp;
173 if (count == (sizeArray - 1)) {
174 adirent = (struct dirent **)realloc(adirent, (sizeof(void *) * (sizeArray + AINCREMENT)));
176 sizeArray += AINCREMENT;
187 /***************************************************************************/
189 /* build_dirent_list - builds a list of icon files to be displayed */
191 /* Input: char *filter - directory in which to search for files */
192 /* Output: struct dirent **namelist - list of files */
194 /***************************************************************************/
195 struct dirent **build_dirent_list (char *filter, int *filecount)
198 char *dirname, *dirname_end;
200 struct dirent **namelist;
201 char *msgPtr, *fmtPtr, *errPtr;
203 /********************************************************************/
204 /* initialize filecount and namelist */
205 /********************************************************************/
209 /********************************************************************/
210 /* get length of file filter and create a copy */
211 /********************************************************************/
212 dirname = (char *)calloc (strlen(filter)+1, sizeof(char));
216 printf("error callocing memory for dirname\n");
217 printf("dirname of size: %i\n", strlen(dirname));
221 dirname = strcpy (dirname, filter);
223 /********************************************************************/
224 /* strip wildcard from end of directory name */
225 /********************************************************************/
226 dirname_end = strrchr (dirname, '/');
227 dirname_end[1] = '\0';
229 /********************************************************************/
230 /* build list of file name that match the wildcard string */
231 /********************************************************************/
232 dirptr = (DIR *)opendir (dirname);
236 *filecount = myscandir (dirname, &namelist, new_name_select, NULL);
239 printf("# of icons = %d\n", *filecount);
243 /* INTERNATIONALIZE */
244 msgPtr = "Could not open the following directory:";
246 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
247 strlen(dirname) + 1) * sizeof(char));
248 sprintf(errPtr, fmtPtr, msgPtr, dirname);
249 display_error_message(CreateActionAppShell, errPtr);
255 printf ("Freeing dirname, sizeof: %ld\n", (long)sizeof(dirname));
262 /***************************************************************************/
264 /* new_name_select - determines if file is included in list of icon */
265 /* files to be displayed in a container */
266 /* Input: struct dirent *dir_entry - directory entry structure */
267 /* Output: (int)found - >0 if file name accepted, 0 otherwise */
269 /***************************************************************************/
270 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
272 struct stat stat_buffer;
275 /***********************************************************************/
276 /* This will only filter the icons of the filter size which by default */
277 /* is medium icons. */
278 /***********************************************************************/
279 if (strstr(dir_entry->d_name, file_filter_global)) {
280 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
281 if (!stat(filename, &stat_buffer)) {
282 if ( (S_ISREG(stat_buffer.st_mode)) ||
283 (S_ISLNK(stat_buffer.st_mode)) ) {
291 /***********************************************************************/
292 /* This is the new filter to get all three sizes of icons. */
293 /***********************************************************************/
295 if ( (strstr(dir_entry->d_name, ".l.pm")) ||
296 (strstr(dir_entry->d_name, ".m.pm")) ||
297 (strstr(dir_entry->d_name, ".t.pm")) ) {
298 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
299 if (!stat(filename, &stat_buffer)) {
300 if ( (S_ISREG(stat_buffer.st_mode)) ||
301 (S_ISLNK(stat_buffer.st_mode)) ) {
307 if ( (strstr(dir_entry->d_name, ".l.bm")) ||
308 (strstr(dir_entry->d_name, ".m.bm")) ||
309 (strstr(dir_entry->d_name, ".t.bm")) ) {
310 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
311 if (!stat(filename, &stat_buffer)) {
312 if ( (S_ISREG(stat_buffer.st_mode)) ||
313 (S_ISLNK(stat_buffer.st_mode)) ) {
325 /***************************************************************************/
327 /* new_name_select - determines if file is included in list of icon */
328 /* files to be displayed in a container */
329 /* Input: struct dirent *dir_entry - directory entry structure */
330 /* Output: (int)found - >0 if file name accepted, 0 otherwise */
332 /***************************************************************************/
333 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
335 struct stat stat_buffer;
338 if (strstr(dir_entry->d_name, file_filter_global)) {
339 sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
340 if (!stat(filename, &stat_buffer)) {
341 if ( (S_ISREG(stat_buffer.st_mode)) ||
342 (S_ISLNK(stat_buffer.st_mode)) ) {
351 /***************************************************************************/
353 /* int get_top_b1_position - determine position of button */
354 /* INPUT: int buttoncount - number of buttons in row */
355 /* OUTPUT: int position - position of left edge of button */
357 /***************************************************************************/
358 int get_top_b1_position (int buttoncount)
362 switch (buttoncount) {
363 case 1: position = 38; break;
364 case 2: position = 14; break;
365 case 3: position = 8; break;
366 default : position = 0;
372 /***************************************************************************/
374 /* int get_top_b2_position - determine position of button */
375 /* INPUT: int buttoncount - number of buttons in row */
376 /* OUTPUT: int position - position of left edge of button */
378 /***************************************************************************/
379 int get_top_b2_position (int buttoncount)
383 switch (buttoncount) {
384 case 2: position = 60; break;
385 case 3: position = 40; break;
386 default : position = 0;
392 /***************************************************************************/
394 /* void load_directories_list - load scrolled list with directory */
396 /* Input: char **dirlist - list of text strings */
399 /***************************************************************************/
400 void load_directories_list (char **dirlist)
402 XmStringTable xmstringlist;
406 /******************************************************************/
407 /* get number of directories in list */
408 /******************************************************************/
409 stringcount = countItems (dirlist);
411 /******************************************************************/
412 /* convert strings to xmstrings */
413 /******************************************************************/
414 xmstringlist = (XmStringTable) TextStringsToXmStrings (dirlist);
416 /******************************************************************/
417 /* put xmstrings in list */
418 /******************************************************************/
419 XtVaSetValues (dir_scrolled_list, XmNitems, xmstringlist,
420 XmNitemCount, stringcount, NULL);
422 XmListSelectPos(dir_scrolled_list, 1, False);
423 /******************************************************************/
424 /* free xmstrings array */
425 /******************************************************************/
426 for (i=0; i < stringcount; i++) {
427 XmStringFree(xmstringlist[i]);
434 /***************************************************************************/
436 /* void initialize_filter - build path/wildcard filter */
438 /* Output: char *initial_filter */
440 /***************************************************************************/
441 char *initialize_filter (char *filter_end)
443 char *filter, *initial_filter;
444 int filter_length, filter_end_length;
447 /******************************************************************/
448 /* initial filter string is first directory in list */
449 /******************************************************************/
450 filter = get_initial_filter ();
452 /******************************************************************/
453 /* determine space needed */
454 /******************************************************************/
455 filter_length = strlen(filter);
456 if ((filter[filter_length-1] == '/') && (filter_end[0] == '/')) {
459 if (!(filter[filter_length-1] == '/') && !(filter_end[0] == '/')) {
465 filter_end_length = strlen(filter_end);
467 /******************************************************************/
468 /* allocate space and put string in initial filter */
469 /******************************************************************/
470 initial_filter = (char *)calloc (filter_length + filter_end_length + 1,
473 if (!initial_filter) printf("Error callocing memory in initialize_filter.\n");
475 initial_filter = strcpy (initial_filter, filter);
476 if (add_slash) initial_filter[filter_length-1] = '/';
477 initial_filter = strcat (initial_filter, filter_end);
479 return(initial_filter);
482 /***************************************************************************/
484 /* char *get_initial_filter - get value of first file filter */
486 /* Output: char *new_filter - string containing filter */
488 /***************************************************************************/
489 char *get_initial_filter (void)
493 /******************************************************************/
494 /* initial filter is first one in directory list */
495 /******************************************************************/
496 new_filter = (char *)directories_list[0];
500 /***************************************************************************/
502 /* char *update_filter - put main filter end on new main filter */
503 /* Input: char *filter - new filter from which gets main filter end */
504 /* Output: char *new_filter - new main filter */
506 /***************************************************************************/
507 char *update_filter (char *filter)
509 char *filter_end, *new_filter, *main_end;
510 char *fe_ptr, *ffg_ptr;
512 /******************************************************************/
514 /******************************************************************/
515 main_end = strrchr (main_filter, '/');
516 filter_end = (char *)calloc(strlen(main_end)+1, sizeof(char));
520 printf("Error callocing memory for filter_end in update_filter.\n");
523 filter_end = strcpy (filter_end, main_end);
525 /******************************************************************/
526 /* determine what filter should be depending on icon type (pm/bm) */
527 /******************************************************************/
528 if (fe_ptr = strrchr(filter_end, EXT_DELIMITER)) {
529 ffg_ptr = strrchr(file_filter_global, EXT_DELIMITER);
531 if ((int)strlen(fe_ptr) >= (int)strlen(PIXMAP_EXT)) {
532 strcpy(fe_ptr, PIXMAP_EXT);
534 if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(PIXMAP_EXT)) ) {
535 strcpy(ffg_ptr, PIXMAP_EXT);
538 if ((int)strlen(fe_ptr) >= (int)strlen(BITMAP_EXT)) {
539 strcpy(fe_ptr, BITMAP_EXT);
541 if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(BITMAP_EXT)) ) {
542 strcpy(ffg_ptr, BITMAP_EXT);
547 /******************************************************************/
548 /* find old end on main filter and delete it */
549 /******************************************************************/
550 main_end = memset (main_end, '\0', strlen(main_end));
552 /******************************************************************/
553 /* allocate space for new filter */
554 /******************************************************************/
555 new_filter = (char *)calloc (strlen(filter) +
556 strlen(filter_end) + 1, sizeof(char));
559 printf("Error callocing memory for new_filter in update_filter.\n");
562 new_filter = strcpy (new_filter, filter);
564 /******************************************************************/
565 /* put new end on filter */
566 /******************************************************************/
567 new_filter = strcat (new_filter, filter_end);
569 /******************************************************************/
570 /* display new file filter in text field */
571 /******************************************************************/
572 load_filter_text_field (new_filter);
574 /******************************************************************/
576 /******************************************************************/
582 /***************************************************************************/
584 /* void apply_filter - apply filter to create a list of files and */
585 /* display files in scrolled list */
586 /* Input: char *filter - file filter to use */
589 /***************************************************************************/
590 void apply_filter (char *filter)
594 /******************************************************************/
595 /* Get length of main file filter and create a copy */
596 /******************************************************************/
597 old_main = (char *)calloc (strlen(main_filter)+1, sizeof(char));
600 if (!old_main) printf("Calloc error for old_main, in apply filter.\n");
603 old_main = strcpy (old_main, main_filter);
605 /******************************************************************/
606 /* Update main filter to reflect changes made by user */
607 /******************************************************************/
608 main_filter = update_filter (filter);
610 /******************************************************************/
611 /* if the filter has changed, update container with new icons */
612 /******************************************************************/
613 if (strcmp (old_main, main_filter)) {
615 /******************************************************************/
616 /* Turn on the hour glass */
617 /******************************************************************/
618 TurnOnHourGlassAllWindows();
620 /******************************************************************/
621 /* Since we are changing to a new directory, clear out the */
622 /* globals and clear the selected icon text string. */
623 /******************************************************************/
625 _DtIconSetState(selected_icon, FALSE, FALSE);
626 selected_icon = (Widget)NULL;
628 if (selected_icon_name) {
629 XtFree(selected_icon_name);
630 selected_icon_name = (char *)NULL;
632 XmTextFieldSetString (icon_name_text_field, "");
634 /******************************************************************/
635 /* Update the container icon gadgets */
636 /******************************************************************/
637 update_container_contents (main_filter);
639 /******************************************************************/
640 /* Turn off the hour glass */
641 /******************************************************************/
642 TurnOffHourGlassAllWindows();
646 printf ("Freeing old_main, sizeof: %ld\n", (long)sizeof(old_main));
654 /***************************************************************************/
656 /* void load_filter_text_field - display file filter text */
657 /* Input: char *filter - file filter text string */
660 /***************************************************************************/
661 void load_filter_text_field (char *filter)
663 if (use_filter_field) {
664 /* display file filter in text field */
665 XmTextFieldSetString (filter_text_field, filter);
666 /* set cursor to end of string */
667 XmTextSetInsertionPosition (filter_text_field, strlen(filter));
673 /***************************************************************************/
675 /* void update_container_contents - create new icon gadgets which */
676 /* correspont to the new filter */
677 /* Input: char *filter - file filter text string */
680 /***************************************************************************/
681 void update_container_contents (char *filter)
683 char *path, *pathend;
684 char iconfile[MAXFILENAME];
686 struct dirent **filelist;
687 int count, old_count;
693 XtUnmanageChild (icon_scrolled_container);
694 /* free_container_contents (); */
696 path = (char *)calloc (strlen(filter)+1, sizeof(char));
699 if (!path) printf("Calloc error for path, in update_container_contents.\n");
702 path = strcpy (path, filter);
703 pathend = strrchr (path, '/');
706 /******************************************************************/
707 /* Get number of icon files and list of file names */
708 /******************************************************************/
709 filelist = build_dirent_list (filter, &namecount);
711 /******************************************************************/
712 /* Set up argument list */
713 /******************************************************************/
716 XtSetArg(args[n], XmNimageName, "/usr/dt/appconfig/icons/C/Dtactn.m.pm"); n++;
718 XtSetArg(args[n], XmNimageName, NULL); n++;
719 XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
720 XtSetArg(args[n], XmNbehavior, XmICON_TOGGLE); n++;
721 XtSetArg(args[n], XmNrecomputeSize, TRUE); n++;
722 XtSetArg(args[n], XmNfillOnArm, TRUE); n++;
723 XtSetArg(args[n], XmNtraversalOn, TRUE); n++;
725 /******************************************************************/
726 /* Need at least one icon for the empty directory icon. */
727 /******************************************************************/
734 /******************************************************************/
735 /* create any additional icon gadgets */
736 /******************************************************************/
737 if (count > icon_count) {
738 old_count = icon_count;
740 icons_in_container = (DtIconGadget **)realloc
742 (icon_count+1) * sizeof(DtIconGadget *));
743 /*memset(&(icons_in_container[icon_count]), 0, sizeof(DtIconGadget *));*/
744 for (lcv = old_count; lcv < icon_count; lcv++) {
745 icons_in_container[lcv] =
746 /*(DtIconGadget *)XtCreateManagedWidget (filelist[lcv]->d_name,*/
747 (DtIconGadget *)XtCreateManagedWidget ("IconGadget",
748 dtIconGadgetClass, (Widget)icon_scrolled_container,
750 XtAddCallback((Widget) icons_in_container[lcv], XmNcallback,
751 (XtCallbackProc) selectionCB_icon_scrolled_container,
755 if (!icons_in_container[lcv])
756 printf("Error creating icon gadget, in update_container_contents\n");
760 if (!icons_in_container[lcv]) {
761 printf ("Could not allocate memory to create new icon\n", lcv);
767 printf ("Created icon #%i\n", lcv);
772 } /* end if (count > icon_count) */
774 /******************************************************************/
775 /* load icon gadgets with information */
776 /******************************************************************/
778 /****************************************************************/
779 /* The following flush call is a work-around for a known motif */
780 /* bug. This is here in the application because motif will not */
781 /* correct this bug because doing so would impair performance. */
782 /* Therefore, I am forced to add this call to the code. */
783 /* The problem this fixes is that when new icons are added to */
784 /* the filesystem after the application is already up and */
785 /* running, the icon gadgets to not see them. */
786 /****************************************************************/
787 XmeFlushIconFileCache(NULL);
789 for (lcv = 0; lcv < count; lcv++) {
790 sprintf (iconfile, "%s%s", path, filelist[lcv]->d_name);
791 ptr = strstr(filelist[lcv]->d_name, ".m.");
795 xmstring = XmStringCreateLocalized(filelist[lcv]->d_name);
796 XtVaSetValues ((Widget) icons_in_container[lcv],
798 XmNimageName, iconfile,
800 XtManageChild((Widget) icons_in_container [lcv]);
801 XmStringFree(xmstring);
804 printf ("Loading icon gadget #%i\n", lcv);
809 /******************************************************************/
810 /* This is the empty directory case */
811 /******************************************************************/
813 strcpy(iconfile, GETMESSAGE(11, 60, "[Empty]"));
814 xmstring = XmStringCreateLocalized(iconfile);
815 XtVaSetValues ((Widget) icons_in_container[0],
817 XmNimageName, (char *)NULL,
819 XtManageChild((Widget) icons_in_container[0]);
820 XmStringFree(xmstring);
823 /******************************************************************/
824 /* unmanage any spare icon gadgets */
825 /******************************************************************/
826 for (lcv = count; lcv < icon_count; lcv++) {
827 XtUnmanageChild ((Widget) icons_in_container[lcv]);
830 /******************************************************************/
831 /* free dirent list */
832 /******************************************************************/
833 for (lcv = 0; lcv < namecount; lcv++) {
834 free (filelist[lcv]);
840 XtManageChild (icon_scrolled_container);
845 #ifdef _ICONSELECTOR_DESTROY_ENABLED
846 /***************************************************************************/
848 /* void free_container_contents - free icon gadgets in container */
852 /***************************************************************************/
853 void free_container_contents (void)
860 if (icons_in_container) {
861 screen_id = XtScreen (icons_in_container[0]);
863 while (icons_in_container[lcv]) {
865 XtVaGetValues (icons_in_container[lcv], XmNimageName, &filename,
866 XmNpixmap, &icon_pixmap, NULL);
867 XmDestroyPixmap (screen_id, icon_pixmap);
869 XtVaSetValues (icons_in_container[lcv], XmNpixmap, NULL, NULL);
871 XtDestroyWidget (icons_in_container[lcv]);
873 icons_in_container[lcv]=NULL;
876 } /* end while icons_in_container */
877 free (icons_in_container);
878 icons_in_container = NULL;
882 printf ("In free_container_contents...\n");
883 printf ("Just destroyed all %i icons.\n", lcv);
893 /***************************************************************************/
895 /* void load_new_filter - displays selected directory string as */
896 /* new filter base */
897 /* Input: char *new_filter - new directory string to use as filter */
900 /***************************************************************************/
901 void load_new_filter (char *new_filter)
903 /* no longer need old filter */
906 /* create space for new filter */
907 main_filter = (char *)calloc (strlen(new_filter)+3, sizeof (char));
909 if (!main_filter) printf("Calloc error for main_filter, in load_new_filter.\n");
911 /* copy new filter and add filter end */
912 main_filter = strcpy (main_filter, new_filter);
913 main_filter = strcat (main_filter, "/*");
914 /* display new filter */
915 load_filter_text_field (main_filter);
921 /*****************************************************************************/
922 /* The following are callback functions. */
923 /*****************************************************************************/
925 /***************************************************************************/
927 /* calc_bottom_attachment */
930 /***************************************************************************/
931 static void calc_bottom_attachment( Widget UxWidget,
932 XtPointer UxClientData,
933 XtPointer UxCallbackArg )
935 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
937 UxSaveCtx = UxIcon_selection_dialogContext;
938 UxIcon_selection_dialogContext = UxContext =
939 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
941 if (numberOfTopButtons > 0) {
942 XtVaSetValues (UxWidget, XmNbottomWidget, top_button_form, NULL);
943 } else if (use_icon_name_field) {
944 XtVaSetValues (UxWidget, XmNbottomWidget, icon_name_textfield_label, NULL);
945 } else XtVaSetValues (UxWidget, XmNbottomWidget, separatorGadget1, NULL);
950 /***************************************************************************/
952 /* activateCB_bottom_button */
955 /***************************************************************************/
956 /* default cb for bottom buttons */
957 static void activateCB_bottom_button( Widget UxWidget,
958 XtPointer UxClientData,
959 XtPointer UxCallbackArg )
961 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
963 UxSaveCtx = UxIcon_selection_dialogContext;
964 UxIcon_selection_dialogContext = UxContext =
965 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
971 /******************************************************************************/
972 /* activateCB_NoFindIconDialog_ChangeNameButton */
973 /******************************************************************************/
974 void activateCB_NoFindIconDialog_ChangeNameButton( Widget UxWidget,
975 XtPointer UxClientData,
976 XtPointer UxCallbackArg)
979 XtDestroyWidget(UxWidget);
982 /******************************************************************************/
983 /* activateCB_NoFindIconDialog_NameOKButton */
984 /******************************************************************************/
985 void activateCB_NoFindIconDialog_NameOKButton( Widget UxWidget,
986 XtPointer UxClientData,
987 XtPointer UxCallbackArg)
990 char *basename = (char *)NULL;
992 TurnOnHourGlassAllWindows();
993 if (bottom_button_one_cb) {
994 GetWidgetTextString(icon_name_text_field, &basename);
995 bottom_button_one_cb(UxWidget,
996 (XtPointer)basename, UxCallbackArg);
997 if (basename) XtFree(basename);
999 TurnOffHourGlassAllWindows();
1000 UxPopdownInterface (IconSelector);
1001 XtDestroyWidget(UxWidget);
1004 /******************************************************************************/
1005 /* display_nofindicon_message - display cant find icons error dialog */
1006 /* INPUT: Widget parent - parent to position error dialog new */
1008 /******************************************************************************/
1009 void display_nofindicon_message (Widget parent)
1015 dialog = XmCreateErrorDialog(parent, "nofindiconDialog", NULL, 0);
1017 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
1018 XtVaSetValues(widChild,
1019 RES_CONVERT( XmNlabelString, "Change Name"),
1022 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
1023 XtVaSetValues(widChild,
1024 RES_CONVERT( XmNlabelString, "Name OK"),
1027 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
1029 XtAddCallback( dialog, XmNokCallback,
1030 (XtCallbackProc) activateCB_NoFindIconDialog_ChangeNameButton,
1032 XtAddCallback( dialog, XmNcancelCallback,
1033 (XtCallbackProc) activateCB_NoFindIconDialog_NameOKButton,
1036 /********* WARNING - this needs to be translated !!! ***********/
1037 strcpy(buffer, "There is no set of icons with that filename in the icon folders.\n");
1038 strcat(buffer, "Move the icons into one of the icon folers, then select \"Name OK\".\n");
1039 strcat(buffer, "Or, to select a different set of icons, select \"Change Name\".\n");
1040 strcat(buffer, "\nIf you are a software developer creating a registration package,\n");
1041 strcat(buffer, "ignore this message and select \"Name OK\".");
1042 XtVaSetValues (dialog,
1043 RES_CONVERT(XmNdialogTitle, GETMESSAGE(6, 31, "Create Action - Error")),
1044 RES_CONVERT(XmNmessageString, buffer),
1047 XtManageChild (dialog);
1051 /***************************************************************************/
1053 /* activateCB_bottom_button1 */
1056 /***************************************************************************/
1057 /* cb for bottom button 1 = OK */
1058 static void activateCB_bottom_button1( Widget UxWidget,
1059 XtPointer UxClientData,
1060 XtPointer UxCallbackArg )
1062 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1064 UxSaveCtx = UxIcon_selection_dialogContext;
1065 UxIcon_selection_dialogContext = UxContext =
1066 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1068 char *basename = (char *)NULL;
1069 char *fullname = (char *)NULL;
1070 char *msgPtr, *errPtr;
1072 GetWidgetTextString(icon_name_text_field, &basename);
1074 if (strchr(basename, '/')) {
1075 /**** WARNING - this needs to be in a message catalog in the future ****/
1076 /* INTERNATIONALIZE */
1077 msgPtr = "Invalid Icon filename.\n\
1078 Pathnames are not valid in the \"Enter Icon Filename\" field.\n\
1079 Enter only the name of the icon without the path or extensions.";
1080 errPtr = XtNewString(msgPtr);
1081 display_error_message(IconSelector, errPtr);
1084 FIND_ICONGADGET_ICON(basename, fullname, DtMEDIUM);
1085 if ( (fullname) && (check_file_exists(fullname)) ) {
1086 TurnOnHourGlassAllWindows();
1087 if (bottom_button_one_cb) {
1088 bottom_button_one_cb(UxWidget,
1089 (XtPointer)fullname, UxCallbackArg);
1091 TurnOffHourGlassAllWindows();
1092 UxPopdownInterface (IconSelector);
1093 if (basename) XtFree(basename);
1095 display_nofindicon_message(IconSelector);
1099 msgPtr = GETMESSAGE(11, 50, "The Icon Filename is invalid.\n\
1100 Please enter a valid icon file name in the\n'Enter Icon Filename' field.");
1101 errPtr = XtNewString(msgPtr);
1102 display_error_message(IconSelector, errPtr);
1108 #if 0 /************* old code *********************/
1109 char *pszIconFileName = (char *)NULL;
1110 char buffer[MAXBUFSIZE];
1112 GetWidgetTextString(icon_name_text_field, &pszIconFileName);
1113 if ( (pszIconFileName) && (check_file_exists(pszIconFileName)) ) {
1114 TurnOnHourGlassAllWindows();
1115 if (bottom_button_one_cb) {
1116 bottom_button_one_cb(UxWidget,
1117 (XtPointer)pszIconFileName, UxCallbackArg);
1119 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1120 free_container_contents ();
1121 if (selected_icon_name) {
1122 XtFree(selected_icon_name);
1124 selected_icon_name = (char *)NULL;
1125 XtDestroyWidget (XtParent(icon_selection_dialog));
1126 IconSelector = (Widget)NULL;
1127 TurnOffHourGlassAllWindows();
1129 TurnOffHourGlassAllWindows();
1130 UxPopdownInterface (IconSelector);
1131 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1132 XtFree(pszIconFileName);
1134 strcpy(buffer, GETMESSAGE(11, 50, "The Icon Filename is invalid.\nPlease enter a valid icon file name in the\n'Enter Icon Filename' field."));
1135 display_error_message(IconSelector, buffer);
1140 if (selected_icon_name) {
1141 TurnOnHourGlassAllWindows();
1142 if (bottom_button_one_cb) {
1143 bottom_button_one_cb(UxWidget,
1144 (XtPointer)selected_icon_name, UxCallbackArg);
1146 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1147 free_container_contents ();
1148 XtFree(selected_icon_name);
1149 selected_icon_name = (char *)NULL;
1150 XtDestroyWidget (XtParent(icon_selection_dialog));
1151 IconSelector = (Widget)NULL;
1152 TurnOffHourGlassAllWindows();
1154 TurnOffHourGlassAllWindows();
1155 UxPopdownInterface (IconSelector);
1156 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1161 #endif /************* old code *********************/
1165 /***************************************************************************/
1167 /* activateCB_bottom_button2 */
1170 /***************************************************************************/
1171 /* cb for bottom button 2 = CANCEL */
1172 static void activateCB_bottom_button2( Widget UxWidget,
1173 XtPointer UxClientData,
1174 XtPointer UxCallbackArg )
1176 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1178 UxSaveCtx = UxIcon_selection_dialogContext;
1179 UxIcon_selection_dialogContext = UxContext =
1180 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1182 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1183 free_container_contents ();
1184 XtDestroyWidget (XtParent(icon_selection_dialog));
1185 IconSelector = (Widget)NULL;
1187 UxPopdownInterface (IconSelector);
1188 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1193 /***************************************************************************/
1195 /* activateCB_bottom_button3 */
1198 /***************************************************************************/
1199 /* default cb for bottom button3 = HELP */
1200 static void activateCB_bottom_button3( Widget UxWidget,
1201 XtPointer UxClientData,
1202 XtPointer UxCallbackArg )
1204 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1206 UxSaveCtx = UxIcon_selection_dialogContext;
1207 UxIcon_selection_dialogContext = UxContext =
1208 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1210 DisplayHelpDialog(UxWidget, (XtPointer)HELP_ICONSELECTOR, UxCallbackArg);
1215 /***************************************************************************/
1217 /* activateCB_filter_text_field */
1220 /***************************************************************************/
1221 static void activateCB_filter_text_field( Widget UxWidget,
1222 XtPointer UxClientData,
1223 XtPointer UxCallbackArg )
1225 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1226 UxSaveCtx = UxIcon_selection_dialogContext;
1227 UxIcon_selection_dialogContext = UxContext =
1228 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1232 filter = XmTextFieldGetString (UxWidget);
1233 apply_filter (filter);
1235 UxIcon_selection_dialogContext = UxSaveCtx;
1238 /***************************************************************************/
1240 /* defaultActionCB_dir_scrolled_list */
1243 /***************************************************************************/
1244 static void defaultActionCB_dir_scrolled_list( Widget UxWidget,
1245 XtPointer UxClientData,
1246 XtPointer UxCallbackArg )
1248 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1250 UxSaveCtx = UxIcon_selection_dialogContext;
1251 UxIcon_selection_dialogContext = UxContext =
1252 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1254 XmListCallbackStruct *listcb;
1257 listcb = (XmListCallbackStruct *) UxCallbackArg;
1258 filter = (char *)XmStringToText (listcb->item);
1259 apply_filter (filter);
1260 /* XtManageChild (icon_scrolled_win); */
1262 UxIcon_selection_dialogContext = UxSaveCtx;
1265 /***************************************************************************/
1267 /* selectionCB_icon_scrolled_container */
1269 /***************************************************************************/
1270 static void selectionCB_icon_scrolled_container ( Widget UxWidget,
1271 XtPointer UxClientData,
1272 XtPointer UxCallbackArg )
1275 XmString xmbasename;
1278 XtVaGetValues (UxWidget, XmNimageName, &filename, NULL);
1280 printf("In icon callback for '%s'\n", filename);
1282 if (use_icon_name_field) {
1283 XtVaGetValues (UxWidget, XmNstring, &xmbasename, NULL);
1284 basename = XmStringToText(xmbasename);
1285 XmTextFieldSetString (icon_name_text_field, basename);
1286 if (basename) free(basename);
1288 if (selected_icon_name) {
1289 if (selected_icon != UxWidget) {
1290 _DtIconSetState(selected_icon, FALSE, FALSE);
1292 XtFree(selected_icon_name);
1293 selected_icon_name = (char *)NULL;
1296 selected_icon_name = XtMalloc(strlen(filename) + 1);
1297 selected_icon_name = strcpy(selected_icon_name, filename);
1299 selected_icon_name = (char *)NULL;
1301 selected_icon = UxWidget;
1306 /***************************************************************************/
1308 /* resizeCB_clipWindow */
1310 /***************************************************************************/
1311 void resizeCB_clipWindow( Widget UxWidget,
1312 XtPointer UxClientData,
1313 XtPointer UxCallbackArg )
1315 Widget widvScrollbar;
1316 Widget widRowColumn;
1320 XtVaGetValues(XtParent(UxWidget), XmNverticalScrollBar, &widvScrollbar, NULL);
1321 widRowColumn = (Widget)UxClientData;
1322 XtVaGetValues(widRowColumn, XmNheight, &height, NULL);
1325 printf("height = %d\n", height);
1326 printf("icon_count = %d\n", icon_count);
1329 increment = (int)height / icon_count;
1330 XtVaSetValues(widvScrollbar, XmNincrement, increment, NULL);
1336 /***************************************************************************/
1338 /* _Uxbuild_icon_selection_dialog */
1341 /***************************************************************************/
1342 static Widget _Uxbuild_icon_selection_dialog(void)
1347 int ntotalbuttons = numberOfBottomButtons;
1348 #define TIGHTNESS 20
1351 Widget widclipWindow;
1353 /* Creation of icon_selection_dialog */
1354 _UxParent = UxParent;
1355 if ( _UxParent == NULL )
1357 _UxParent = UxTopLevel;
1360 _UxParent = XtVaCreatePopupShell( "icon_selection_dialog_shell",
1361 xmDialogShellWidgetClass, _UxParent,
1366 XmNshellUnitType, XmPIXELS,
1367 XmNkeyboardFocusPolicy, XmEXPLICIT,
1368 XmNtitle, "icon_selection_dialog",
1371 UxTmp0 = dialog_title ? (char *)dialog_title : "Icon Selection Window";
1373 icon_selection_dialog = XtVaCreateWidget( "icon_selection_dialog",
1376 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1379 XmNunitType, XmPIXELS,
1380 RES_CONVERT( XmNdialogTitle, UxTmp0 ),
1381 XmNautoUnmanage, FALSE,
1382 XmNdefaultPosition, FALSE,
1384 UxPutContext( icon_selection_dialog, (char *) UxIcon_selection_dialogContext );
1386 /*******************************************************************/
1387 /* Set up help callback */
1388 /*******************************************************************/
1389 XtAddCallback( icon_selection_dialog, XmNhelpCallback,
1390 (XtCallbackProc) helpCB_general,
1391 (XtPointer) HELP_ICONSELECTOR );
1394 /* Creation of bottom_button_form */
1395 bottom_button_form = XtVaCreateManagedWidget( "bottom_button_form",
1397 icon_selection_dialog,
1398 XmNskipAdjust, TRUE,
1399 XmNfractionBase, ((TIGHTNESS * ntotalbuttons) - 1),
1402 XmNleftAttachment, XmATTACH_FORM,
1404 XmNrightAttachment, XmATTACH_FORM,
1405 XmNbottomOffset, 20,
1406 XmNbottomAttachment, XmATTACH_FORM,
1409 UxPutContext( bottom_button_form, (char *) UxIcon_selection_dialogContext );
1412 UxTmp0 = bottom_button_one_label ? (char *)bottom_button_one_label : GETMESSAGE(6, 10, "OK");
1414 /* Creation of bottom_button1 = OK */
1415 bottom_button1 = XtVaCreateManagedWidget( "bottom_button1",
1416 xmPushButtonWidgetClass,
1418 RES_CONVERT( XmNlabelString, UxTmp0 ),
1420 XmNleftAttachment, nbutton ?
1421 XmATTACH_POSITION : XmATTACH_FORM,
1422 XmNleftPosition, TIGHTNESS * nbutton,
1423 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1424 XmATTACH_POSITION : XmATTACH_FORM,
1425 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1429 XtAddCallback( bottom_button1, XmNactivateCallback,
1430 (XtCallbackProc) activateCB_bottom_button1,
1433 UxPutContext( bottom_button1, (char *) UxIcon_selection_dialogContext );
1435 UxTmp0 = bottom_button_two_label ? (char *)bottom_button_two_label : GETMESSAGE(6, 12, "Cancel");
1437 /* Creation of bottom_button2 = CANCEL */
1438 bottom_button2 = XtVaCreateManagedWidget( "bottom_button2",
1439 xmPushButtonWidgetClass,
1441 RES_CONVERT( XmNlabelString, UxTmp0 ),
1443 XmNleftAttachment, nbutton ?
1444 XmATTACH_POSITION : XmATTACH_FORM,
1445 XmNleftPosition, TIGHTNESS * nbutton,
1446 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1447 XmATTACH_POSITION : XmATTACH_FORM,
1448 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1452 XtAddCallback( bottom_button2, XmNactivateCallback,
1453 (XtCallbackProc) bottom_button_two_cb ?
1454 bottom_button_two_cb : activateCB_bottom_button2,
1455 (XtPointer) UxIcon_selection_dialogContext );
1457 UxPutContext( bottom_button2, (char *) UxIcon_selection_dialogContext );
1459 UxTmp0 = bottom_button_three_label ? (char *)bottom_button_three_label : GETMESSAGE(6, 13, "Help");
1461 /* Creation of bottom_button3 = HELP */
1462 bottom_button3 = XtVaCreateManagedWidget( "bottom_button3",
1463 xmPushButtonWidgetClass,
1465 RES_CONVERT( XmNlabelString, UxTmp0 ),
1466 XmNuserData, icon_selection_dialog,
1468 XmNleftAttachment, nbutton ?
1469 XmATTACH_POSITION : XmATTACH_FORM,
1470 XmNleftPosition, TIGHTNESS * nbutton,
1471 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1472 XmATTACH_POSITION : XmATTACH_FORM,
1473 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1477 XtAddCallback( bottom_button3, XmNactivateCallback,
1478 (XtCallbackProc) bottom_button_three_cb ?
1479 bottom_button_three_cb : activateCB_bottom_button3,
1480 (XtPointer) UxIcon_selection_dialogContext );
1482 UxPutContext( bottom_button3, (char *) UxIcon_selection_dialogContext );
1484 UxTmp0 = bottom_button_four_label ? (char *)bottom_button_four_label : GETMESSAGE(12, 10, "Filter");
1486 /* Creation of bottom_button4 */
1487 bottom_button4 = XtVaCreateManagedWidget( "bottom_button4",
1488 xmPushButtonWidgetClass,
1490 RES_CONVERT( XmNlabelString, UxTmp0 ),
1492 XmNleftAttachment, nbutton ?
1493 XmATTACH_POSITION : XmATTACH_FORM,
1494 XmNleftPosition, TIGHTNESS * nbutton,
1495 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1496 XmATTACH_POSITION : XmATTACH_FORM,
1497 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1501 XtAddCallback( bottom_button4, XmNactivateCallback,
1502 (XtCallbackProc) bottom_button_four_cb ?
1503 bottom_button_four_cb : activateCB_bottom_button,
1504 (XtPointer) UxIcon_selection_dialogContext );
1506 UxPutContext( bottom_button4, (char *) UxIcon_selection_dialogContext );
1509 /* Creation of separatorGadget1 */
1510 separatorGadget1 = XtVaCreateManagedWidget( "separatorGadget1",
1511 xmSeparatorGadgetClass,
1512 icon_selection_dialog,
1516 XmNrightAttachment, XmATTACH_FORM,
1518 XmNleftAttachment, XmATTACH_FORM,
1519 XmNbottomOffset, 10,
1520 XmNbottomWidget, bottom_button_form,
1521 XmNbottomAttachment, XmATTACH_WIDGET,
1523 UxPutContext( separatorGadget1, (char *) UxIcon_selection_dialogContext );
1526 /* Creation of icon_name_text_field */
1527 icon_name_text_field = XtVaCreateManagedWidget( "icon_name_text_field",
1528 xmTextFieldWidgetClass,
1529 icon_selection_dialog,
1532 XmNbottomOffset, 10,
1533 XmNbottomWidget, separatorGadget1,
1534 XmNbottomAttachment, XmATTACH_WIDGET,
1536 XmNrightAttachment, XmATTACH_FORM,
1538 XmNleftAttachment, XmATTACH_FORM,
1540 UxPutContext( icon_name_text_field, (char *) UxIcon_selection_dialogContext );
1541 ISD_SelectedIconTextField = icon_name_text_field;
1543 UxTmp0 = name_field_title ? (char *)name_field_title : GETMESSAGE(11, 12, "Enter Icon Filename");
1545 /* Creation of icon_name_textfield_label */
1546 icon_name_textfield_label = XtVaCreateManagedWidget( "icon_name_textfield_label",
1548 icon_selection_dialog,
1551 RES_CONVERT( XmNlabelString, UxTmp0 ),
1553 XmNbottomWidget, icon_name_text_field,
1554 XmNbottomAttachment, XmATTACH_WIDGET,
1556 XmNleftWidget, icon_name_text_field,
1557 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1558 XmNalignment, XmALIGNMENT_BEGINNING,
1560 UxPutContext( icon_name_textfield_label, (char *) UxIcon_selection_dialogContext );
1562 UxTmp0 = filter_field_title ? (char *)filter_field_title : GETMESSAGE(12, 10, "Filter");
1564 /* Creation of filter_textfield_label */
1565 filter_textfield_label = XtVaCreateManagedWidget( "filter_textfield_label",
1567 icon_selection_dialog,
1570 RES_CONVERT( XmNlabelString, UxTmp0 ),
1571 XmNalignment, XmALIGNMENT_BEGINNING,
1573 XmNtopAttachment, XmATTACH_FORM,
1575 XmNleftAttachment, XmATTACH_FORM,
1577 UxPutContext( filter_textfield_label, (char *) UxIcon_selection_dialogContext );
1580 /* Creation of filter_text_field */
1581 filter_text_field = XtVaCreateManagedWidget( "filter_text_field",
1582 xmTextFieldWidgetClass,
1583 icon_selection_dialog,
1587 XmNtopWidget, filter_textfield_label,
1588 XmNtopAttachment, XmATTACH_WIDGET,
1590 XmNrightAttachment, XmATTACH_FORM,
1592 XmNleftAttachment, XmATTACH_FORM,
1594 XtAddCallback( filter_text_field, XmNactivateCallback,
1595 (XtCallbackProc) activateCB_filter_text_field,
1596 (XtPointer) UxIcon_selection_dialogContext );
1598 UxPutContext( filter_text_field, (char *) UxIcon_selection_dialogContext );
1600 UxTmp0 = directory_title ? (char *)directory_title : GETMESSAGE(11, 30, "Icon Folders");
1602 /* Creation of directory_list_label */
1603 directory_list_label = XtVaCreateManagedWidget( "directory_list_label",
1605 icon_selection_dialog,
1608 XmNlabelType, XmSTRING,
1609 RES_CONVERT( XmNlabelString, UxTmp0 ),
1610 XmNalignment, XmALIGNMENT_BEGINNING,
1612 XmNtopWidget, filter_text_field,
1613 XmNtopAttachment, use_filter_field ? XmATTACH_WIDGET : XmATTACH_FORM,
1615 XmNleftAttachment, XmATTACH_FORM,
1617 UxPutContext( directory_list_label, (char *) UxIcon_selection_dialogContext );
1619 UxTmp0 = container_title ? (char *)container_title : GETMESSAGE(11, 11, "Icon Files");
1621 /* Creation of icon_container_label */
1622 icon_container_label = XtVaCreateManagedWidget( "icon_container_label",
1624 icon_selection_dialog,
1627 XmNlabelType, XmSTRING,
1628 RES_CONVERT( XmNlabelString, UxTmp0 ),
1629 XmNalignment, XmALIGNMENT_BEGINNING,
1631 XmNtopWidget, filter_text_field,
1632 XmNtopAttachment, XmATTACH_WIDGET,
1633 XmNleftAttachment, XmATTACH_POSITION,
1634 XmNleftPosition, 55,
1636 UxPutContext( icon_container_label, (char *) UxIcon_selection_dialogContext );
1639 /* Creation of top_button_form */
1640 top_button_form = XtVaCreateManagedWidget( "top_button_form",
1642 icon_selection_dialog,
1643 XmNresizePolicy, XmRESIZE_NONE,
1646 XmNbottomOffset, 10,
1647 XmNbottomWidget, use_icon_name_field ? icon_name_textfield_label : separatorGadget1,
1648 XmNbottomAttachment, XmATTACH_WIDGET,
1650 XmNrightAttachment, XmATTACH_FORM,
1652 XmNleftAttachment, XmATTACH_FORM,
1654 UxPutContext( top_button_form, (char *) UxIcon_selection_dialogContext );
1656 UxTmp0 = top_button_one_label ? (char *)top_button_one_label : "No_Label";
1658 /* Creation of top_button1 */
1659 top_button1 = XtVaCreateManagedWidget( "top_button1",
1660 xmPushButtonWidgetClass,
1665 XmNbottomAttachment, XmATTACH_FORM,
1666 XmNleftAttachment, XmATTACH_POSITION,
1668 XmNleftPosition, get_top_b1_position (numberOfTopButtons),
1669 RES_CONVERT( XmNlabelString, UxTmp0 ),
1671 XtAddCallback( top_button1, XmNactivateCallback,
1672 (XtCallbackProc) top_button_one_cb,
1673 (XtPointer) UxIcon_selection_dialogContext );
1675 UxPutContext( top_button1, (char *) UxIcon_selection_dialogContext );
1677 UxTmp0 = top_button_two_label ? (char *)top_button_two_label : "No_Label";
1679 /* Creation of top_button2 */
1680 top_button2 = XtVaCreateManagedWidget( "top_button2",
1681 xmPushButtonWidgetClass,
1687 XmNleftPosition, get_top_b2_position (numberOfTopButtons),
1688 XmNbottomAttachment, XmATTACH_FORM,
1689 XmNleftAttachment, XmATTACH_POSITION,
1690 RES_CONVERT( XmNlabelString, UxTmp0 ),
1692 XtAddCallback( top_button2, XmNactivateCallback,
1693 (XtCallbackProc) top_button_two_cb,
1694 (XtPointer) UxIcon_selection_dialogContext );
1696 UxPutContext( top_button2, (char *) UxIcon_selection_dialogContext );
1698 UxTmp0 = top_button_three_label ? (char *)top_button_three_label : "No_Label";
1700 /* Creation of top_button3 */
1701 top_button3 = XtVaCreateManagedWidget( "top_button3",
1702 xmPushButtonWidgetClass,
1706 RES_CONVERT( XmNlabelString, UxTmp0 ),
1707 XmNleftPosition, 72,
1709 XmNleftAttachment, XmATTACH_POSITION,
1711 XmNbottomAttachment, XmATTACH_FORM,
1713 XtAddCallback( top_button3, XmNactivateCallback,
1714 (XtCallbackProc) top_button_three_cb,
1715 (XtPointer) UxIcon_selection_dialogContext );
1717 UxPutContext( top_button3, (char *) UxIcon_selection_dialogContext );
1719 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1721 /* Creation of dir_scrolled_list */
1722 XtSetArg(args[i], XmNshadowThickness, 2); i++;
1723 XtSetArg(args[i], XmNlistSizePolicy, XmCONSTANT); i++;
1725 XtSetArg(args[i], XmNleftOffset, 10); i++;
1726 XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1727 XtSetArg(args[i], XmNtopOffset, 0); i++;
1728 XtSetArg(args[i], XmNtopWidget, directory_list_label); i++;
1729 XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1730 XtSetArg(args[i], XmNrightOffset, 20); i++;
1731 XtSetArg(args[i], XmNrightWidget, icon_container_label); i++;
1732 XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
1734 XtSetArg(args[i], XmNbottomOffset, 10); i++;
1735 if (numberOfTopButtons > 0) {
1736 XtSetArg(args[i], XmNbottomWidget, top_button_form); i++;
1737 } else if (use_icon_name_field) {
1738 XtSetArg(args[i], XmNbottomWidget, icon_name_textfield_label); i++;
1740 XtSetArg(args[i], XmNbottomWidget, separatorGadget1); i++;
1742 XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
1744 dir_scrolled_list = XmCreateScrolledList(icon_selection_dialog,
1745 "dir_scrolled_list",
1748 XtVaSetValues(dir_scrolled_list,
1749 XmNselectionPolicy, XmBROWSE_SELECT,
1750 XmNvisibleItemCount, 15,
1752 XtManageChild(dir_scrolled_list);
1754 UxPutContext( dir_scrolled_list, (char *) UxIcon_selection_dialogContext );
1755 calc_bottom_attachment (dir_scrolled_list,
1756 (XtPointer) UxIcon_selection_dialogContext,
1758 XtAddCallback( dir_scrolled_list, XmNdefaultActionCallback,
1759 (XtCallbackProc) defaultActionCB_dir_scrolled_list,
1760 (XtPointer) UxIcon_selection_dialogContext );
1762 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1764 /* Creation of icon_scrolled_win */
1765 icon_scrolled_win = XtVaCreateManagedWidget( "icon_scrolled_win",
1766 xmScrolledWindowWidgetClass,
1767 icon_selection_dialog,
1768 XmNscrollingPolicy, XmAUTOMATIC,
1769 /* XmNnavigationType, XmTAB_GROUP, */
1772 XmNscrollBarDisplayPolicy, XmAS_NEEDED,
1774 XmNrightAttachment, XmATTACH_FORM,
1776 XmNtopWidget, icon_container_label,
1777 XmNtopAttachment, XmATTACH_WIDGET,
1779 XmNleftWidget, icon_container_label,
1780 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1781 XmNbottomOffset, 10,
1782 XmNbottomWidget, XmATTACH_NONE,
1783 XmNbottomAttachment, XmATTACH_WIDGET,
1789 UxPutContext( icon_scrolled_win, (char *) UxIcon_selection_dialogContext );
1790 calc_bottom_attachment (icon_scrolled_win,
1791 (XtPointer) UxIcon_selection_dialogContext,
1794 /* Creation of icon_scrolled_container */
1795 icon_scrolled_container = XtVaCreateManagedWidget( "icon_scrolled_container",
1796 xmRowColumnWidgetClass,
1798 XmNnavigationType, XmTAB_GROUP,
1799 /*XmNborderWidth, 1,*/
1800 /*XmNnumColumns, 2,*/
1802 XmNorientation, XmVERTICAL,
1803 XmNpacking, XmPACK_COLUMN,
1804 XmNshadowThickness, 1,
1807 XtVaSetValues(icon_selection_dialog,
1808 XmNcancelButton, bottom_button2,
1811 XtAddCallback( icon_selection_dialog, XmNdestroyCallback,
1812 (XtCallbackProc) UxDestroyContextCB,
1813 (XtPointer) UxIcon_selection_dialogContext);
1815 XtVaGetValues (icon_scrolled_win, XmNclipWindow, &widclipWindow, NULL);
1816 XtAddCallback( widclipWindow, XmNresizeCallback,
1817 (XtCallbackProc) resizeCB_clipWindow,
1818 (XtPointer) icon_scrolled_container );
1820 return ( icon_selection_dialog );
1823 /*******************************************************************************
1824 The following is the 'Interface function' which is the
1825 external entry point for creating this interface.
1826 This function should be called from your application or from
1827 a callback function.
1828 *******************************************************************************/
1830 Widget create_icon_selection_dialog(swidget _UxUxParent,
1831 unsigned char *_Uxdialog_title,
1832 unsigned char *_Uxfilter_field_title,
1833 int _Uxuse_filter_field,
1834 unsigned char *_Uxfile_filter,
1835 unsigned char *_Uxdirectory_title,
1836 unsigned char **_Uxdirectories_list,
1837 unsigned char *_Uxcontainer_title,
1838 int _UxnumberOfTopButtons,
1839 unsigned char *_Uxtop_button_one_label,
1840 void (*_Uxtop_button_one_cb)(),
1841 unsigned char *_Uxtop_button_two_label,
1842 void (*_Uxtop_button_two_cb)(),
1843 unsigned char *_Uxtop_button_three_label,
1844 void (*_Uxtop_button_three_cb)(),
1845 int _Uxuse_icon_name_field,
1846 unsigned char *_Uxname_field_title,
1847 int _UxnumberOfBottomButtons,
1848 unsigned char *_Uxbottom_button_one_label,
1849 void (*_Uxbottom_button_one_cb)(),
1850 unsigned char *_Uxbottom_button_two_label,
1851 void (*_Uxbottom_button_two_cb)(),
1852 unsigned char *_Uxbottom_button_three_label,
1853 void (*_Uxbottom_button_three_cb)(),
1854 unsigned char *_Uxbottom_button_four_label,
1855 void (*_Uxbottom_button_four_cb)() )
1859 char *initial_filter;
1860 char *icon_file_name;
1863 _UxCicon_selection_dialog *UxContext;
1865 UxIcon_selection_dialogContext = UxContext =
1866 (_UxCicon_selection_dialog *) UxNewContext( sizeof(_UxCicon_selection_dialog), False );
1868 UxParent = _UxUxParent;
1869 dialog_title = _Uxdialog_title;
1870 filter_field_title = _Uxfilter_field_title;
1871 use_filter_field = _Uxuse_filter_field;
1872 file_filter = _Uxfile_filter;
1873 directory_title = _Uxdirectory_title;
1874 directories_list = _Uxdirectories_list;
1875 container_title = _Uxcontainer_title;
1876 numberOfTopButtons = _UxnumberOfTopButtons;
1877 top_button_one_label = _Uxtop_button_one_label;
1878 top_button_one_cb = _Uxtop_button_one_cb;
1879 top_button_two_label = _Uxtop_button_two_label;
1880 top_button_two_cb = _Uxtop_button_two_cb;
1881 top_button_three_label = _Uxtop_button_three_label;
1882 top_button_three_cb = _Uxtop_button_three_cb;
1883 use_icon_name_field = _Uxuse_icon_name_field;
1884 name_field_title = _Uxname_field_title;
1885 numberOfBottomButtons = _UxnumberOfBottomButtons;
1886 bottom_button_one_label = _Uxbottom_button_one_label;
1887 bottom_button_one_cb = _Uxbottom_button_one_cb;
1888 bottom_button_two_label = _Uxbottom_button_two_label;
1889 bottom_button_two_cb = _Uxbottom_button_two_cb;
1890 bottom_button_three_label = _Uxbottom_button_three_label;
1891 bottom_button_three_cb = _Uxbottom_button_three_cb;
1892 bottom_button_four_label = _Uxbottom_button_four_label;
1893 bottom_button_four_cb = _Uxbottom_button_four_cb;
1895 rtrn = _Uxbuild_icon_selection_dialog();
1897 switch (numberOfTopButtons){
1898 case 0 : XtUnmanageChild (top_button_form); break;
1899 case 1 : XtUnmanageChild (top_button2);
1900 case 2 : XtUnmanageChild (top_button3);
1903 if (numberOfBottomButtons == 3)
1904 XtUnmanageChild (bottom_button4);
1906 if (!use_filter_field) {
1907 XtUnmanageChild (filter_textfield_label);
1908 XtUnmanageChild (filter_text_field);
1911 if (!use_icon_name_field) {
1912 XtUnmanageChild (icon_name_textfield_label);
1913 XtUnmanageChild (icon_name_text_field);
1916 TurnOnHourGlassAllWindows();
1918 /******************************************************************/
1919 /* save file_filter */
1920 /******************************************************************/
1921 file_filter_global = (char *)calloc(strlen((char *)file_filter)+1, sizeof(char));
1924 if (!file_filter_global) printf("Calloc error for file_filter_global, in create_icon_selection_dialog.\n");
1927 if (file_filter[0] == '*')
1928 file_filter_global = strcpy(file_filter_global, (char *)&file_filter[1]);
1930 file_filter_global = strcpy(file_filter_global, (char *)file_filter);
1932 load_directories_list ((char **)directories_list);
1933 initial_filter = initialize_filter ((char *)file_filter);
1935 /******************************************************************/
1936 /* save main_filter */
1937 /******************************************************************/
1938 main_filter = (char *)calloc(strlen(initial_filter)+1, sizeof(char));
1941 if (!main_filter) printf("Calloc error for main_filter, in create_icon_selection_dialog.\n");
1944 main_filter = strcpy(main_filter, initial_filter);;
1946 icons_in_container = NULL;
1949 update_container_contents (initial_filter);
1951 /******************************************************************/
1952 /* set selected_icon_name to first name in list */
1953 /******************************************************************/
1955 if (icons_in_container) {
1956 XtVaGetValues (icons_in_container[0], XmNimageName, &icon_file_name, NULL);
1957 XmTextFieldSetString (icon_name_text_field, icon_file_name);
1958 selected_icon_name = XtMalloc(strlen(icon_file_name) + 1);
1959 if (selected_icon_name)
1960 selected_icon_name = strcpy(selected_icon_name, icon_file_name);
1964 load_filter_text_field (initial_filter);
1966 TurnOffHourGlassAllWindows();