dtcreate: Resolve coverity issues
[oweals/cde.git] / cde / programs / dtcreate / icon_selection_dialog.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: icon_selection_dialog.c /main/10 1996/10/15 13:39:13 rswiston $ */
24 /*******************************************************************************
25         icon_selection_dialog.c
26
27        Associated Header file: icon_selection_dialog.h
28 *******************************************************************************/
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <sys/stat.h>
34
35 #if defined(USL) || defined(__uxp__)
36 #define S_ISLNK(mode) ((mode & S_IFMT) == S_IFLNK)
37 #endif
38
39 #include <Xm/Xm.h>
40 #include <Xm/MwmUtil.h>
41 #include <Xm/DialogS.h>
42 #include <Xm/MenuShell.h>
43 #include <Xm/List.h>
44 #include <Xm/ScrolledW.h>
45 #include <Xm/Label.h>
46 #include <Xm/Text.h>
47 #include <Xm/TextF.h>
48 #include <Xm/SeparatoG.h>
49 #include <Xm/PushB.h>
50 #include <Xm/Form.h>
51 #include <Xm/RowColumn.h>
52 #include <Xm/MessageB.h>
53 #include <Xm/XmPrivate.h> /* XmeFlushIconFileCache */
54 #include <X11/cursorfont.h>
55
56 #include <Dt/Icon.h>
57
58 #include "dtcreate.h"
59 #include "UxXt.h"
60 #include "cmncbs.h"
61 #include "cmnrtns.h"
62 #include "cmnutils.h"
63 #include "fileio.h"
64 #include "ErrorDialog.h"
65
66 /*******************************************************************************
67        Includes, Defines, and Global variables from the Declarations Editor:
68 *******************************************************************************/
69
70 #include <sys/types.h> /* for directory routines */
71 #ifdef _KERNEL
72 #undef _KERNEL
73 #endif
74 #include <dirent.h>    /* includes sys/dir.h */
75
76 #include <Xm/ScrolledW.h>
77 #include <Dt/Icon.h>
78 /*#include "Container.h"*/
79
80 static  char *selected_icon_name = (char *)NULL;
81 static  Widget selected_icon = (Widget)NULL;
82 static  int icon_count = 0;
83 char    *main_filter;
84 char    *file_filter_global;
85 DtIconGadget **icons_in_container = NULL;
86
87
88 int myscandir(char *, struct dirent ***, int (), int ());
89 int get_top_b1_position (int buttoncount);
90 int get_top_b2_position (int buttoncount);
91 void load_directories_list (char **dirlist);
92 char *get_initial_filter (void);
93 void load_filter_text_field (char *filter);
94 char *update_filter (char *filter);
95 void apply_filter (char *filter);
96 char *initialize_filter (char *filter_end);
97 struct dirent **build_dirent_list (char *filter, int *filecount);
98 void update_container_contents (char *filter);
99 void free_container_contents (void);
100 int new_name_select(struct dirent *, char *);
101 /*int name_select(struct dirent *);*/
102 static  void    selectionCB_icon_scrolled_container ( Widget UxWidget,
103                                                   XtPointer UxClientData,
104                                                   XtPointer UxCallbackArg);
105 static  void    calc_bottom_attachment( Widget UxWidget,
106                                         XtPointer UxClientData,
107                                         XtPointer UxCallbackArg);
108
109 /*******************************************************************************
110        The following header file defines the context structure.
111 *******************************************************************************/
112
113 #define CONTEXT_MACRO_ACCESS 1
114 #include "icon_selection_dialog.h"
115 #undef CONTEXT_MACRO_ACCESS
116
117
118 /*******************************************************************************
119 Auxiliary code from the Declarations Editor:
120 *******************************************************************************/
121
122 /*********************************************************************/
123 /* auxfuncs - icon selection dialog auxiliary functions              */
124 /*********************************************************************/
125
126 /***************************************************************************/
127 /*                                                                         */
128 /*  myscandir                                                              */
129 /*                                                                         */
130 /***************************************************************************/
131 int myscandir(char *pszDirName, struct dirent ***NameList, int Select(), int Compare())
132
133 {
134   DIR            *dirptr;
135   struct dirent  *dp;
136   struct dirent  *dptmp;
137   int            count = 0;
138   /* int            size = 0; */
139   struct dirent  **adirent;
140 #define          AINCREMENT  ((int)512)
141   int            sizeArray = AINCREMENT;
142   char           *msgPtr, *fmtPtr, *errPtr;
143
144   if (!(dirptr = opendir(pszDirName))) {
145      /* INTERNATIONALIZE */
146      msgPtr = "Could not open the following directory:";
147      fmtPtr = "%s\n   %s";
148      errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
149                         strlen(pszDirName) + 1) * sizeof(char));
150      sprintf(errPtr, fmtPtr, msgPtr, pszDirName);
151      display_error_message(CreateActionAppShell, errPtr);
152      XtFree(errPtr);
153      return(0);
154   }
155
156 #if 0
157   size = sizeof(void *) * 1024;
158   *NameList = (struct dirent **)malloc(sizeof(void *) * 1024);
159 #endif
160
161   adirent = (struct dirent **)malloc(sizeof(void *) * sizeArray);
162   for (dp = readdir(dirptr); dp != NULL; dp = readdir(dirptr)) {
163
164 #if 0
165      if ((*Select)(dp, pszDirName)) {
166         (*NameList)[count] = dp;
167      if ((*Select)(dp)) {
168 #endif
169
170      if ((*Select)(dp, pszDirName)) {
171         dptmp = (struct dirent *)malloc(sizeof(struct dirent) + strlen(dp->d_name) + 1);
172         memcpy(dptmp, dp, sizeof(struct dirent));
173         strcpy(dptmp->d_name, dp->d_name);
174         adirent[count] = dptmp;
175         count++;
176         if (count == (sizeArray - 1)) {
177            adirent = (struct dirent **)realloc(adirent, (sizeof(void *) * (sizeArray + AINCREMENT)));
178            if (adirent) {
179               sizeArray += AINCREMENT;
180            }
181         }
182      }
183   }
184
185   *NameList = adirent;
186   closedir(dirptr);
187   return(count);
188 }
189
190 /***************************************************************************/
191 /*                                                                         */
192 /* build_dirent_list - builds a list of icon files to be displayed         */
193 /*                   in a container                                        */
194 /* Input: char *filter - directory in which to search for files            */
195 /* Output: struct dirent **namelist - list of files                        */
196 /*                                                                         */
197 /***************************************************************************/
198 struct dirent **build_dirent_list (char *filter, int *filecount)
199
200 {
201   char           *dirname, *dirname_end;
202   DIR            *dirptr;
203   struct dirent  **namelist;
204   char           *msgPtr, *fmtPtr, *errPtr;
205
206   /********************************************************************/
207   /* initialize filecount and namelist                                */
208   /********************************************************************/
209   *filecount = 0;
210   namelist = NULL;
211
212   /********************************************************************/
213   /* get length of file filter and create a copy                      */
214   /********************************************************************/
215   dirname = (char *)calloc (strlen(filter)+1, sizeof(char));
216
217 #ifdef DEBUG
218   if (!dirname) {
219     printf("error callocing memory for dirname\n");
220     printf("dirname of size: %i\n", strlen(dirname));
221   }
222 #endif
223
224   dirname = strcpy (dirname, filter);
225
226   /********************************************************************/
227   /* strip wildcard from end of directory name                        */
228   /********************************************************************/
229   dirname_end = strrchr (dirname, '/');
230   dirname_end[1] = '\0';
231
232   /********************************************************************/
233   /* build list of file name that match the wildcard string           */
234   /********************************************************************/
235   dirptr = (DIR *)opendir (dirname);
236
237   if (dirptr) {
238
239      *filecount = myscandir (dirname, &namelist, new_name_select, NULL);
240
241 #ifdef DEBUG
242      printf("# of icons = %d\n", *filecount);
243 #endif
244      closedir (dirptr);
245   } else {
246      /* INTERNATIONALIZE */
247      msgPtr = "Could not open the following directory:";
248      fmtPtr = "%s\n   %s";
249      errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
250                         strlen(dirname) + 1) * sizeof(char));
251      sprintf(errPtr, fmtPtr, msgPtr, dirname);
252      display_error_message(CreateActionAppShell, errPtr);
253      XtFree(errPtr);
254      namelist = NULL;
255   }
256
257 #ifdef DEBUG
258   printf ("Freeing dirname, sizeof: %ld\n", (long)sizeof(dirname));
259 #endif
260
261   free (dirname);
262   return (namelist);
263 }
264
265 /***************************************************************************/
266 /*                                                                         */
267 /*  new_name_select - determines if file is included in list of icon       */
268 /*                files to be displayed in a container                     */
269 /*  Input: struct dirent *dir_entry - directory entry structure            */
270 /*  Output: (int)found - >0 if file name accepted, 0 otherwise             */
271 /*                                                                         */
272 /***************************************************************************/
273 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
274 {
275   struct stat stat_buffer;
276   char        filename[256];
277
278   /***********************************************************************/
279   /* This will only filter the icons of the filter size which by default */
280   /* is medium icons.                                                    */
281   /***********************************************************************/
282   if (strstr(dir_entry->d_name, file_filter_global)) {
283      sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
284      if (!stat(filename, &stat_buffer)) {
285         if ( (S_ISREG(stat_buffer.st_mode)) ||
286              (S_ISLNK(stat_buffer.st_mode)) ) {
287            return(1);
288         }
289      }
290   }
291   return(0);
292
293 #if 0
294   /***********************************************************************/
295   /* This is the new filter to get all three sizes of icons.             */
296   /***********************************************************************/
297   if (bShowPixmaps) {
298     if ( (strstr(dir_entry->d_name, ".l.pm")) ||
299          (strstr(dir_entry->d_name, ".m.pm")) ||
300          (strstr(dir_entry->d_name, ".t.pm")) ) {
301        sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
302        if (!stat(filename, &stat_buffer)) {
303           if ( (S_ISREG(stat_buffer.st_mode)) ||
304                (S_ISLNK(stat_buffer.st_mode)) ) {
305              return(1);
306           }
307        }
308     }
309   } else {
310     if ( (strstr(dir_entry->d_name, ".l.bm")) ||
311          (strstr(dir_entry->d_name, ".m.bm")) ||
312          (strstr(dir_entry->d_name, ".t.bm")) ) {
313        sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
314        if (!stat(filename, &stat_buffer)) {
315           if ( (S_ISREG(stat_buffer.st_mode)) ||
316                (S_ISLNK(stat_buffer.st_mode)) ) {
317              return(1);
318           }
319        }
320     }
321   }
322   return(0);
323 #endif
324
325 }
326
327 #if 0
328 /***************************************************************************/
329 /*                                                                         */
330 /*  new_name_select - determines if file is included in list of icon       */
331 /*                files to be displayed in a container                     */
332 /*  Input: struct dirent *dir_entry - directory entry structure            */
333 /*  Output: (int)found - >0 if file name accepted, 0 otherwise             */
334 /*                                                                         */
335 /***************************************************************************/
336 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
337 {
338   struct stat stat_buffer;
339   char        filename[256];
340
341   if (strstr(dir_entry->d_name, file_filter_global)) {
342      sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
343      if (!stat(filename, &stat_buffer)) {
344         if ( (S_ISREG(stat_buffer.st_mode)) ||
345              (S_ISLNK(stat_buffer.st_mode)) ) {
346            return(1);
347         }
348      }
349   }
350   return(0);
351 }
352 #endif
353
354 /***************************************************************************/
355 /*                                                                         */
356 /* int get_top_b1_position - determine position of button                  */
357 /* INPUT: int buttoncount - number of buttons in row                       */
358 /* OUTPUT: int position - position of left edge of button                  */
359 /*                                                                         */
360 /***************************************************************************/
361 int get_top_b1_position (int buttoncount)
362 {
363   int position;
364
365   switch (buttoncount) {
366           case 1: position = 38; break;
367           case 2: position = 14; break;
368           case 3: position =  8; break;
369           default : position = 0;
370           };
371   return (position);
372 }
373
374
375 /***************************************************************************/
376 /*                                                                         */
377 /* int get_top_b2_position - determine position of button                  */
378 /* INPUT: int buttoncount - number of buttons in row                       */
379 /* OUTPUT: int position - position of left edge of button                  */
380 /*                                                                         */
381 /***************************************************************************/
382 int get_top_b2_position (int buttoncount)
383 {
384   int position;
385
386   switch (buttoncount) {
387           case 2: position = 60; break;
388           case 3: position = 40; break;
389           default : position = 0;
390           };
391   return (position);
392 }
393
394
395 /***************************************************************************/
396 /*                                                                         */
397 /*  void load_directories_list - load scrolled list with directory         */
398 /*                               names                                     */
399 /*  Input: char **dirlist - list of text strings                           */
400 /*  Output: none                                                           */
401 /*                                                                         */
402 /***************************************************************************/
403 void load_directories_list (char **dirlist)
404 {
405   XmStringTable xmstringlist;
406   int stringcount = 0;
407   int i;
408
409   /******************************************************************/
410   /* get number of directories in list                              */
411   /******************************************************************/
412   stringcount = countItems (dirlist);
413
414   /******************************************************************/
415   /* convert strings to xmstrings                                   */
416   /******************************************************************/
417   xmstringlist = (XmStringTable) TextStringsToXmStrings (dirlist);
418
419   /******************************************************************/
420   /* put xmstrings in list                                          */
421   /******************************************************************/
422   XtVaSetValues (dir_scrolled_list, XmNitems, xmstringlist,
423                  XmNitemCount, stringcount, NULL);
424
425   XmListSelectPos(dir_scrolled_list, 1, False);
426   /******************************************************************/
427   /* free xmstrings array                                           */
428   /******************************************************************/
429   for (i=0; i < stringcount; i++) {
430      XmStringFree(xmstringlist[i]);
431   }
432   free(xmstringlist);
433
434   return;
435 }
436
437 /***************************************************************************/
438 /*                                                                         */
439 /*  void initialize_filter - build path/wildcard filter                    */
440 /*  Input: none                                                            */
441 /*  Output: char *initial_filter                                           */
442 /*                                                                         */
443 /***************************************************************************/
444 char *initialize_filter (char *filter_end)
445 {
446   char *filter, *initial_filter;
447   int filter_length, filter_end_length;
448   int add_slash = 0;
449
450   /******************************************************************/
451   /* initial filter string is first directory in list               */
452   /******************************************************************/
453   filter = get_initial_filter ();
454
455   /******************************************************************/
456   /* determine space needed                                         */
457   /******************************************************************/
458   filter_length = strlen(filter);
459   if ((filter[filter_length-1] == '/') && (filter_end[0] == '/')) {
460      filter_end++;
461   } else {
462      if (!(filter[filter_length-1] == '/') && !(filter_end[0] == '/')) {
463          add_slash = 1;
464          filter_length++;
465      }
466   }
467
468   filter_end_length = strlen(filter_end);
469
470   /******************************************************************/
471   /* allocate space and put string in initial filter                */
472   /******************************************************************/
473   initial_filter = (char *)calloc (filter_length + filter_end_length + 1,
474                                  sizeof(char));
475 #ifdef DEBUG
476   if (!initial_filter) printf("Error callocing memory in initialize_filter.\n");
477 #endif
478   initial_filter = strcpy (initial_filter, filter);
479   if (add_slash) initial_filter[filter_length-1] = '/';
480   initial_filter = strcat (initial_filter, filter_end);
481
482   return(initial_filter);
483 }
484
485 /***************************************************************************/
486 /*                                                                         */
487 /*  char *get_initial_filter - get value of first file filter              */
488 /*  Input: none                                                            */
489 /*  Output: char *new_filter - string containing filter                    */
490 /*                                                                         */
491 /***************************************************************************/
492 char *get_initial_filter (void)
493 {
494   char *new_filter;
495
496   /******************************************************************/
497   /* initial filter is first one in directory list                  */
498   /******************************************************************/
499   new_filter = (char *)directories_list[0];
500   return (new_filter);
501 }
502
503 /***************************************************************************/
504 /*                                                                         */
505 /*  char *update_filter - put main filter end on new main filter           */
506 /*  Input: char *filter - new filter from which gets main filter end       */
507 /*  Output: char *new_filter - new main filter                             */
508 /*                                                                         */
509 /***************************************************************************/
510 char *update_filter (char *filter)
511 {
512   char *filter_end, *new_filter, *main_end;
513   char *fe_ptr, *ffg_ptr;
514
515   /******************************************************************/
516   /* get new end                                                    */
517   /******************************************************************/
518   main_end = strrchr (main_filter, '/');
519   filter_end = (char *)calloc(strlen(main_end)+1, sizeof(char));
520
521 #ifdef DEBUG
522   if (!filter_end)
523      printf("Error callocing memory for filter_end in update_filter.\n");
524 #endif
525
526   filter_end = strcpy (filter_end, main_end);
527
528   /******************************************************************/
529   /* determine what filter should be depending on icon type (pm/bm) */
530   /******************************************************************/
531   if (fe_ptr = strrchr(filter_end, EXT_DELIMITER)) {
532      ffg_ptr = strrchr(file_filter_global, EXT_DELIMITER);
533      if (bShowPixmaps) {
534         if ((int)strlen(fe_ptr) >= (int)strlen(PIXMAP_EXT)) {
535            strcpy(fe_ptr, PIXMAP_EXT);
536         }
537         if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(PIXMAP_EXT)) ) {
538            strcpy(ffg_ptr, PIXMAP_EXT);
539         }
540      } else {
541         if ((int)strlen(fe_ptr) >= (int)strlen(BITMAP_EXT)) {
542            strcpy(fe_ptr, BITMAP_EXT);
543         }
544         if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(BITMAP_EXT)) ) {
545            strcpy(ffg_ptr, BITMAP_EXT);
546         }
547      }
548   }
549
550   /******************************************************************/
551   /* find old end on main filter and delete it                      */
552   /******************************************************************/
553   main_end = memset (main_end, '\0', strlen(main_end));
554
555   /******************************************************************/
556   /* allocate space for new filter                                  */
557   /******************************************************************/
558   new_filter = (char *)calloc (strlen(filter) +
559                              strlen(filter_end) + 1, sizeof(char));
560 #ifdef DEBUG
561   if (!new_filter)
562      printf("Error callocing memory for new_filter in update_filter.\n");
563 #endif
564
565   new_filter = strcpy (new_filter, filter);
566
567   /******************************************************************/
568   /* put new end on filter                                          */
569   /******************************************************************/
570   new_filter = strcat (new_filter, filter_end);
571
572   /******************************************************************/
573   /* display new file filter in text field                          */
574   /******************************************************************/
575   load_filter_text_field (new_filter);
576
577   /******************************************************************/
578   /* free resources                                                 */
579   /******************************************************************/
580   free(filter_end);
581
582   return (new_filter);
583 }
584
585 /***************************************************************************/
586 /*                                                                         */
587 /*  void apply_filter - apply filter to create a list of files and         */
588 /*                      display files in scrolled list                     */
589 /*  Input: char *filter - file filter to use                               */
590 /*  Output: none                                                           */
591 /*                                                                         */
592 /***************************************************************************/
593 void apply_filter (char *filter)
594 {
595   char *old_main;
596
597   /******************************************************************/
598   /* Get length of main file filter and create a copy               */
599   /******************************************************************/
600   old_main = (char *)calloc (strlen(main_filter)+1, sizeof(char));
601
602 #ifdef DEBUG
603   if (!old_main) printf("Calloc error for old_main, in apply filter.\n");
604 #endif
605
606   old_main = strcpy (old_main, main_filter);
607
608   /******************************************************************/
609   /* Update main filter to reflect changes made by user             */
610   /******************************************************************/
611   main_filter = update_filter (filter);
612
613   /******************************************************************/
614   /* if the filter has changed, update container with new icons     */
615   /******************************************************************/
616   if (strcmp (old_main, main_filter)) {
617
618      /******************************************************************/
619      /* Turn on the hour glass                                         */
620      /******************************************************************/
621      TurnOnHourGlassAllWindows();
622
623      /******************************************************************/
624      /* Since we are changing to a new directory, clear out the        */
625      /* globals and clear the selected icon text string.               */
626      /******************************************************************/
627      if (selected_icon) {
628         _DtIconSetState(selected_icon, FALSE, FALSE);
629         selected_icon = (Widget)NULL;
630      }
631      if (selected_icon_name) {
632         XtFree(selected_icon_name);
633         selected_icon_name = (char *)NULL;
634      }
635      XmTextFieldSetString (icon_name_text_field, "");
636
637      /******************************************************************/
638      /* Update the container icon gadgets                              */
639      /******************************************************************/
640      update_container_contents (main_filter);
641
642      /******************************************************************/
643      /* Turn off the hour glass                                        */
644      /******************************************************************/
645      TurnOffHourGlassAllWindows();
646   }
647
648 #ifdef DEBUG
649   printf ("Freeing old_main, sizeof: %ld\n", (long)sizeof(old_main));
650 #endif
651
652   free (old_main);
653   return;
654 }
655
656
657 /***************************************************************************/
658 /*                                                                         */
659 /*  void load_filter_text_field - display file filter text                 */
660 /*  Input: char *filter - file filter text string                          */
661 /*  Output: none                                                           */
662 /*                                                                         */
663 /***************************************************************************/
664 void load_filter_text_field (char *filter)
665 {
666   if (use_filter_field) {
667      /* display file filter in text field */
668      XmTextFieldSetString (filter_text_field, filter);
669      /* set cursor to end of string */
670      XmTextSetInsertionPosition (filter_text_field, strlen(filter));
671   }
672   return;
673 }
674
675
676 /***************************************************************************/
677 /*                                                                         */
678 /*  void update_container_contents - create new icon gadgets which         */
679 /*                             correspont to the new filter                */
680 /*  Input: char *filter - file filter text string                          */
681 /*  Output: none                                                           */
682 /*                                                                         */
683 /***************************************************************************/
684 void  update_container_contents (char *filter)
685 {
686   char          *path, *pathend;
687   char          iconfile[MAXFILENAME];
688   int           namecount, lcv;
689   struct dirent **filelist;
690   int           count, old_count;
691   int           n;
692   Arg           args[10];
693   XmString      xmstring;
694   char          *ptr;
695
696   XtUnmanageChild (icon_scrolled_container);
697   /* free_container_contents (); */
698
699   path = (char *)calloc (strlen(filter)+1, sizeof(char));
700
701 #ifdef DEBUG
702   if (!path) printf("Calloc error for path, in update_container_contents.\n");
703 #endif
704
705   path = strcpy (path, filter);
706   pathend = strrchr (path, '/');
707   pathend[1] = '\0';
708
709   /******************************************************************/
710   /* Get number of icon files and list of file names                */
711   /******************************************************************/
712   filelist = build_dirent_list (filter, &namecount);
713
714   /******************************************************************/
715   /* Set up argument list                                           */
716   /******************************************************************/
717   n = 0;
718   /*
719   XtSetArg(args[n], XmNimageName, "/usr/dt/appconfig/icons/C/Dtactn.m.pm"); n++;
720   */
721   XtSetArg(args[n], XmNimageName, NULL); n++;
722   XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
723   XtSetArg(args[n], XmNbehavior, XmICON_TOGGLE); n++;
724   XtSetArg(args[n], XmNrecomputeSize, TRUE); n++;
725   XtSetArg(args[n], XmNfillOnArm, TRUE); n++;
726   XtSetArg(args[n], XmNtraversalOn, TRUE); n++;
727
728   /******************************************************************/
729   /* Need at least one icon for the empty directory icon.           */
730   /******************************************************************/
731   if (namecount) {
732      count = namecount;
733   } else {
734      count = 1;
735   }
736
737   /******************************************************************/
738   /* create any additional icon gadgets                             */
739   /******************************************************************/
740   if (count > icon_count) {
741      old_count = icon_count;
742      icon_count = count;
743      icons_in_container = (DtIconGadget **)realloc
744                                       (icons_in_container,
745                                       (icon_count+1) * sizeof(DtIconGadget *));
746      /*memset(&(icons_in_container[icon_count]), 0, sizeof(DtIconGadget *));*/
747      for (lcv = old_count; lcv < icon_count; lcv++) {
748         icons_in_container[lcv] =
749         /*(DtIconGadget *)XtCreateManagedWidget (filelist[lcv]->d_name,*/
750           (DtIconGadget *)XtCreateManagedWidget ("IconGadget",
751                             dtIconGadgetClass, (Widget)icon_scrolled_container,
752                             args, n);
753           XtAddCallback((Widget) icons_in_container[lcv], XmNcallback,
754                        (XtCallbackProc) selectionCB_icon_scrolled_container,
755                        (XtPointer) NULL);
756
757 #ifdef DEBUG
758        if (!icons_in_container[lcv])
759           printf("Error creating icon gadget, in update_container_contents\n");
760 #endif
761
762 #if 0
763        if (!icons_in_container[lcv]) {
764           printf ("Could not allocate memory to create new icon\n", lcv);
765        }
766 #endif
767
768 #ifdef DEBUG
769        } else {
770           printf ("Created icon #%i\n", lcv);
771        }
772 #endif
773
774      }  /* end for */
775   }     /* end if (count > icon_count) */
776
777   /******************************************************************/
778   /* load icon gadgets with information                             */
779   /******************************************************************/
780   if (namecount) {
781     /****************************************************************/
782     /* The following flush call is a work-around for a known motif  */
783     /* bug.  This is here in the application because motif will not */
784     /* correct this bug because doing so would impair performance.  */
785     /* Therefore, I am forced to add this call to the code.         */
786     /* The problem this fixes is that when new icons are added to   */
787     /* the filesystem after the application is already up and       */
788     /* running, the icon gadgets to not see them.                   */
789     /****************************************************************/
790     XmeFlushIconFileCache(NULL);
791
792     for (lcv = 0; lcv < count; lcv++) {
793        snprintf(iconfile, sizeof(iconfile), "%s%s", path, filelist[lcv]->d_name);
794        ptr = strstr(filelist[lcv]->d_name, ".m.");
795        if (ptr) {
796           *ptr = '\0';
797        }
798        xmstring = XmStringCreateLocalized(filelist[lcv]->d_name);
799        XtVaSetValues ((Widget) icons_in_container[lcv],
800                              XmNstring,        xmstring,
801                              XmNimageName,     iconfile,
802                              NULL);
803        XtManageChild((Widget) icons_in_container [lcv]);
804        XmStringFree(xmstring);
805
806 #ifdef DEBUG
807       printf ("Loading icon gadget #%i\n", lcv);
808 #endif
809
810     }  /* end for */
811
812   /******************************************************************/
813   /* This is the empty directory case                               */
814   /******************************************************************/
815   } else {
816        snprintf(iconfile, sizeof(iconfile), "%s", GETMESSAGE(11, 60, "[Empty]"));
817        xmstring = XmStringCreateLocalized(iconfile);
818        XtVaSetValues ((Widget) icons_in_container[0],
819                              XmNstring,        xmstring,
820                              XmNimageName,     (char *)NULL,
821                              NULL);
822        XtManageChild((Widget) icons_in_container[0]);
823        XmStringFree(xmstring);
824   }
825
826   /******************************************************************/
827   /* unmanage any spare icon gadgets                                */
828   /******************************************************************/
829   for (lcv = count; lcv < icon_count; lcv++) {
830      XtUnmanageChild ((Widget) icons_in_container[lcv]);
831   }
832
833   /******************************************************************/
834   /* free dirent list                                               */
835   /******************************************************************/
836   for (lcv = 0; lcv < namecount; lcv++) {
837      free (filelist[lcv]);
838   }
839   if (namecount) {
840      free (filelist);
841   }
842
843   XtManageChild (icon_scrolled_container);
844   free(path);
845   return;
846
847 }
848
849 #ifdef _ICONSELECTOR_DESTROY_ENABLED
850 /***************************************************************************/
851 /*                                                                         */
852 /*  void free_container_contents - free icon gadgets in container          */
853 /*  Input: none                                                            */
854 /*  Output: none                                                           */
855 /*                                                                         */
856 /***************************************************************************/
857 void  free_container_contents (void)
858 {
859   int    lcv = 0;
860   char   *filename;
861   Pixmap icon_pixmap;
862   Screen *screen_id;
863
864   if (icons_in_container) {
865      screen_id = XtScreen (icons_in_container[0]);
866      lcv = 0;
867      while (icons_in_container[lcv]) {
868 #if 0
869        XtVaGetValues (icons_in_container[lcv], XmNimageName, &filename,
870                       XmNpixmap, &icon_pixmap, NULL);
871        XmDestroyPixmap (screen_id, icon_pixmap);
872
873        XtVaSetValues (icons_in_container[lcv], XmNpixmap, NULL, NULL);
874 #endif
875        XtDestroyWidget (icons_in_container[lcv]);
876        /*
877        icons_in_container[lcv]=NULL;
878        */
879        lcv++;
880      }  /* end while icons_in_container */
881      free (icons_in_container);
882      icons_in_container = NULL;
883   }
884
885 #ifdef DEBUG
886   printf ("In free_container_contents...\n");
887   printf ("Just destroyed all %i icons.\n", lcv);
888 #endif
889
890   icon_count = 0;
891
892   return;
893 }
894 #endif
895
896 #if 0
897 /***************************************************************************/
898 /*                                                                         */
899 /*  void load_new_filter - displays selected directory string as           */
900 /*                         new filter base                                 */
901 /*  Input: char *new_filter - new directory string to use as filter        */
902 /*  Output: none                                                           */
903 /*                                                                         */
904 /***************************************************************************/
905 void load_new_filter (char *new_filter)
906 {
907 /* no longer need old filter */
908 free (main_filter);
909
910 /* create space for new filter */
911 main_filter = (char *)calloc (strlen(new_filter)+3, sizeof (char));
912 #ifdef DEBUG
913 if (!main_filter) printf("Calloc error for main_filter, in load_new_filter.\n");
914 #endif
915 /* copy new filter and add filter end */
916 main_filter = strcpy (main_filter, new_filter);
917 main_filter = strcat (main_filter, "/*");
918 /* display new filter */
919 load_filter_text_field (main_filter);
920
921 return;
922 }
923 #endif
924
925 /*****************************************************************************/
926 /*       The following are callback functions.                               */
927 /*****************************************************************************/
928
929 /***************************************************************************/
930 /*                                                                         */
931 /*   calc_bottom_attachment                                                */
932 /*                                                                         */
933 /*                                                                         */
934 /***************************************************************************/
935 static  void    calc_bottom_attachment( Widget UxWidget,
936                                              XtPointer UxClientData,
937                                              XtPointer UxCallbackArg )
938 {
939   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
940
941   UxSaveCtx = UxIcon_selection_dialogContext;
942   UxIcon_selection_dialogContext = UxContext =
943                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
944   {
945     if (numberOfTopButtons > 0) {
946        XtVaSetValues (UxWidget, XmNbottomWidget, top_button_form, NULL);
947     } else if (use_icon_name_field) {
948        XtVaSetValues (UxWidget, XmNbottomWidget, icon_name_textfield_label, NULL);
949     } else XtVaSetValues (UxWidget, XmNbottomWidget, separatorGadget1, NULL);
950   }
951   return;
952 }
953
954 /***************************************************************************/
955 /*                                                                         */
956 /*  activateCB_bottom_button                                               */
957 /*                                                                         */
958 /*                                                                         */
959 /***************************************************************************/
960 /* default cb for bottom buttons */
961 static  void    activateCB_bottom_button( Widget UxWidget,
962                                              XtPointer UxClientData,
963                                              XtPointer UxCallbackArg )
964 {
965   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
966
967   UxSaveCtx = UxIcon_selection_dialogContext;
968   UxIcon_selection_dialogContext = UxContext =
969                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
970   {
971
972   }
973   return;
974 }
975 /******************************************************************************/
976 /* activateCB_NoFindIconDialog_ChangeNameButton                               */
977 /******************************************************************************/
978 void    activateCB_NoFindIconDialog_ChangeNameButton( Widget  UxWidget,
979                                         XtPointer UxClientData,
980                                         XtPointer UxCallbackArg)
981
982 {
983   XtDestroyWidget(UxWidget);
984 }
985
986 /******************************************************************************/
987 /* activateCB_NoFindIconDialog_NameOKButton                                   */
988 /******************************************************************************/
989 void    activateCB_NoFindIconDialog_NameOKButton( Widget  UxWidget,
990                                         XtPointer UxClientData,
991                                         XtPointer UxCallbackArg)
992
993 {
994   char *basename = (char *)NULL;
995
996   TurnOnHourGlassAllWindows();
997   if (bottom_button_one_cb) {
998      GetWidgetTextString(icon_name_text_field, &basename);
999      bottom_button_one_cb(UxWidget,
1000                          (XtPointer)basename, UxCallbackArg);
1001      if (basename) XtFree(basename);
1002   }
1003   TurnOffHourGlassAllWindows();
1004   UxPopdownInterface (IconSelector);
1005   XtDestroyWidget(UxWidget);
1006 }
1007
1008 /******************************************************************************/
1009 /* display_nofindicon_message - display cant find icons error dialog          */
1010 /* INPUT:  Widget parent - parent to position error dialog new                */
1011 /* OUTPIT: none                                                               */
1012 /******************************************************************************/
1013 void display_nofindicon_message (Widget parent)
1014 {
1015   Widget dialog;
1016   Widget widChild;
1017   char   buffer[512];
1018
1019   dialog = XmCreateErrorDialog(parent, "nofindiconDialog", NULL, 0);
1020
1021   widChild = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
1022   XtVaSetValues(widChild,
1023                 RES_CONVERT( XmNlabelString, "Change Name"),
1024                 NULL);
1025
1026   widChild = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
1027   XtVaSetValues(widChild,
1028                 RES_CONVERT( XmNlabelString, "Name OK"),
1029                 NULL);
1030
1031   XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
1032
1033   XtAddCallback( dialog, XmNokCallback,
1034           (XtCallbackProc) activateCB_NoFindIconDialog_ChangeNameButton,
1035           (XtPointer) NULL );
1036   XtAddCallback( dialog, XmNcancelCallback,
1037           (XtCallbackProc) activateCB_NoFindIconDialog_NameOKButton,
1038           (XtPointer) NULL );
1039
1040   /*********  WARNING - this needs to be translated !!! ***********/
1041   strcpy(buffer, "There is no set of icons with that filename in the icon folders.\n");
1042   strcat(buffer, "Move the icons into one of the icon folders, then select \"Name OK\".\n");
1043   strcat(buffer, "Or, to select a different set of icons, select \"Change Name\".\n");
1044   strcat(buffer, "\nIf you are a software developer creating a registration package,\n");
1045   strcat(buffer, "ignore this message and select \"Name OK\".");
1046   XtVaSetValues (dialog,
1047                  RES_CONVERT(XmNdialogTitle, GETMESSAGE(6, 31, "Create Action - Error")),
1048                  RES_CONVERT(XmNmessageString, buffer),
1049                  NULL);
1050
1051   XtManageChild (dialog);
1052   return;
1053 }
1054
1055 /***************************************************************************/
1056 /*                                                                         */
1057 /*  activateCB_bottom_button1                                              */
1058 /*                                                                         */
1059 /*                                                                         */
1060 /***************************************************************************/
1061 /*  cb for bottom button 1 = OK */
1062 static  void    activateCB_bottom_button1( Widget UxWidget,
1063                                              XtPointer UxClientData,
1064                                              XtPointer UxCallbackArg )
1065 {
1066   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1067
1068   UxSaveCtx = UxIcon_selection_dialogContext;
1069   UxIcon_selection_dialogContext = UxContext =
1070                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1071   {
1072     char *basename = (char *)NULL;
1073     char *fullname = (char *)NULL;
1074     char *msgPtr, *errPtr;
1075
1076     GetWidgetTextString(icon_name_text_field, &basename);
1077     if (basename) {
1078        if (strchr(basename, '/')) {
1079           /**** WARNING - this needs to be in a message catalog in the future ****/
1080           /* INTERNATIONALIZE */
1081           msgPtr = "Invalid Icon filename.\n\
1082 Pathnames are not valid in the \"Enter Icon Filename\" field.\n\
1083 Enter only the name of the icon without the path or extensions.";
1084           errPtr = XtNewString(msgPtr);
1085           display_error_message(IconSelector, errPtr);
1086           XtFree(errPtr);
1087        } else {
1088           FIND_ICONGADGET_ICON(basename, fullname, DtMEDIUM);
1089           if ( (fullname) && (check_file_exists(fullname)) ) {
1090              TurnOnHourGlassAllWindows();
1091              if (bottom_button_one_cb) {
1092                 bottom_button_one_cb(UxWidget,
1093                                     (XtPointer)fullname, UxCallbackArg);
1094              }
1095              TurnOffHourGlassAllWindows();
1096              UxPopdownInterface (IconSelector);
1097              if (basename) XtFree(basename);
1098           } else {
1099              display_nofindicon_message(IconSelector);
1100           }
1101        }
1102     } else {
1103        msgPtr = GETMESSAGE(11, 50, "The Icon Filename is invalid.\n\
1104 Please enter a valid icon file name in the\n'Enter Icon Filename' field.");
1105        errPtr = XtNewString(msgPtr);
1106        display_error_message(IconSelector, errPtr);
1107        XtFree(errPtr);
1108     }
1109   }
1110   return;
1111
1112 #if 0   /*************  old code *********************/
1113     char *pszIconFileName = (char *)NULL;
1114     char    buffer[MAXBUFSIZE];
1115
1116     GetWidgetTextString(icon_name_text_field, &pszIconFileName);
1117     if ( (pszIconFileName) && (check_file_exists(pszIconFileName)) ) {
1118        TurnOnHourGlassAllWindows();
1119        if (bottom_button_one_cb) {
1120           bottom_button_one_cb(UxWidget,
1121                               (XtPointer)pszIconFileName, UxCallbackArg);
1122        }
1123 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1124        free_container_contents ();
1125        if (selected_icon_name) {
1126           XtFree(selected_icon_name);
1127        }
1128        selected_icon_name = (char *)NULL;
1129        XtDestroyWidget (XtParent(icon_selection_dialog));
1130        IconSelector = (Widget)NULL;
1131        TurnOffHourGlassAllWindows();
1132 #else
1133        TurnOffHourGlassAllWindows();
1134        UxPopdownInterface (IconSelector);
1135 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
1136        XtFree(pszIconFileName);
1137     } else {
1138        strcpy(buffer, GETMESSAGE(11, 50, "The Icon Filename is invalid.\nPlease enter a valid icon file name in the\n'Enter Icon Filename' field."));
1139        display_error_message(IconSelector, buffer);
1140     }
1141   }
1142
1143 #if 0
1144     if (selected_icon_name) {
1145       TurnOnHourGlassAllWindows();
1146       if (bottom_button_one_cb) {
1147          bottom_button_one_cb(UxWidget,
1148                              (XtPointer)selected_icon_name, UxCallbackArg);
1149       }
1150 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1151       free_container_contents ();
1152       XtFree(selected_icon_name);
1153       selected_icon_name = (char *)NULL;
1154       XtDestroyWidget (XtParent(icon_selection_dialog));
1155       IconSelector = (Widget)NULL;
1156       TurnOffHourGlassAllWindows();
1157 #else
1158       TurnOffHourGlassAllWindows();
1159       UxPopdownInterface (IconSelector);
1160 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
1161     }
1162   }
1163 #endif
1164   return;
1165 #endif  /*************  old code *********************/
1166
1167 }
1168
1169 /***************************************************************************/
1170 /*                                                                         */
1171 /*   activateCB_bottom_button2                                             */
1172 /*                                                                         */
1173 /*                                                                         */
1174 /***************************************************************************/
1175 /*  cb for bottom button 2 = CANCEL */
1176 static  void    activateCB_bottom_button2( Widget UxWidget,
1177                                              XtPointer UxClientData,
1178                                              XtPointer UxCallbackArg )
1179 {
1180   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1181
1182   UxSaveCtx = UxIcon_selection_dialogContext;
1183   UxIcon_selection_dialogContext = UxContext =
1184                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1185   {
1186 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1187     free_container_contents ();
1188     XtDestroyWidget (XtParent(icon_selection_dialog));
1189     IconSelector = (Widget)NULL;
1190 #else
1191     UxPopdownInterface (IconSelector);
1192 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
1193   }
1194   return;
1195 }
1196
1197 /***************************************************************************/
1198 /*                                                                         */
1199 /*  activateCB_bottom_button3                                              */
1200 /*                                                                         */
1201 /*                                                                         */
1202 /***************************************************************************/
1203 /* default cb for bottom button3 = HELP */
1204 static  void    activateCB_bottom_button3( Widget UxWidget,
1205                                              XtPointer UxClientData,
1206                                              XtPointer UxCallbackArg )
1207 {
1208   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1209
1210   UxSaveCtx = UxIcon_selection_dialogContext;
1211   UxIcon_selection_dialogContext = UxContext =
1212                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1213   {
1214     DisplayHelpDialog(UxWidget, (XtPointer)HELP_ICONSELECTOR, UxCallbackArg);
1215   }
1216   return;
1217 }
1218
1219 /***************************************************************************/
1220 /*                                                                         */
1221 /*   activateCB_filter_text_field                                          */
1222 /*                                                                         */
1223 /*                                                                         */
1224 /***************************************************************************/
1225 static  void    activateCB_filter_text_field( Widget UxWidget,
1226                                              XtPointer UxClientData,
1227                                              XtPointer UxCallbackArg )
1228 {
1229   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1230   UxSaveCtx = UxIcon_selection_dialogContext;
1231   UxIcon_selection_dialogContext = UxContext =
1232                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1233   {
1234     char *filter;
1235
1236     filter = XmTextFieldGetString (UxWidget);
1237     apply_filter (filter);
1238   }
1239   UxIcon_selection_dialogContext = UxSaveCtx;
1240 }
1241
1242 /***************************************************************************/
1243 /*                                                                         */
1244 /*  defaultActionCB_dir_scrolled_list                                      */
1245 /*                                                                         */
1246 /*                                                                         */
1247 /***************************************************************************/
1248 static  void    defaultActionCB_dir_scrolled_list( Widget UxWidget,
1249                                                   XtPointer UxClientData,
1250                                                   XtPointer UxCallbackArg )
1251 {
1252   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1253
1254   UxSaveCtx = UxIcon_selection_dialogContext;
1255   UxIcon_selection_dialogContext = UxContext =
1256                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1257   {
1258     XmListCallbackStruct *listcb;
1259     char *filter;
1260
1261     listcb = (XmListCallbackStruct *) UxCallbackArg;
1262     filter = (char *)XmStringToText (listcb->item);
1263     apply_filter (filter);
1264  /* XtManageChild (icon_scrolled_win);  */
1265     free(filter);
1266   }
1267   UxIcon_selection_dialogContext = UxSaveCtx;
1268 }
1269
1270 /***************************************************************************/
1271 /*                                                                         */
1272 /*  selectionCB_icon_scrolled_container                                    */
1273 /*                                                                         */
1274 /***************************************************************************/
1275 static  void    selectionCB_icon_scrolled_container ( Widget UxWidget,
1276                                                   XtPointer UxClientData,
1277                                                   XtPointer UxCallbackArg )
1278 {
1279   char     *filename;
1280   XmString  xmbasename;
1281   char     *basename;
1282
1283   XtVaGetValues (UxWidget, XmNimageName, &filename, NULL);
1284 #ifdef DEBUG
1285   printf("In icon callback for '%s'\n", filename);
1286 #endif
1287   if (use_icon_name_field) {
1288      XtVaGetValues (UxWidget, XmNstring, &xmbasename, NULL);
1289      basename = XmStringToText(xmbasename);
1290      XmTextFieldSetString (icon_name_text_field, basename);
1291      if (basename) free(basename);
1292   }
1293   if (selected_icon_name) {
1294      if (selected_icon != UxWidget) {
1295         _DtIconSetState(selected_icon, FALSE, FALSE);
1296      }
1297      XtFree(selected_icon_name);
1298      selected_icon_name = (char *)NULL;
1299   }
1300   if (filename) {
1301      selected_icon_name = XtMalloc(strlen(filename) + 1);
1302      selected_icon_name = strcpy(selected_icon_name, filename);
1303   } else {
1304      selected_icon_name = (char *)NULL;
1305   }
1306   selected_icon = UxWidget;
1307
1308   return;
1309 }
1310
1311 /***************************************************************************/
1312 /*                                                                         */
1313 /*  resizeCB_clipWindow                                                    */
1314 /*                                                                         */
1315 /***************************************************************************/
1316 void    resizeCB_clipWindow( Widget UxWidget,
1317                              XtPointer UxClientData,
1318                              XtPointer UxCallbackArg )
1319 {
1320   Widget     widvScrollbar;
1321   Widget     widRowColumn;
1322   int        increment;
1323   XtArgVal /* Dimension */  height;
1324
1325   XtVaGetValues(XtParent(UxWidget), XmNverticalScrollBar, &widvScrollbar, NULL);
1326   widRowColumn = (Widget)UxClientData;
1327   XtVaGetValues(widRowColumn, XmNheight, &height, NULL);
1328
1329 #ifdef DEBUG
1330   printf("height = %d\n", height);
1331   printf("icon_count = %d\n", icon_count);
1332 #endif
1333
1334   increment = (int)height / icon_count;
1335   XtVaSetValues(widvScrollbar, XmNincrement, increment, NULL);
1336
1337   return;
1338
1339 }
1340
1341 /***************************************************************************/
1342 /*                                                                         */
1343 /*  _Uxbuild_icon_selection_dialog                                         */
1344 /*                                                                         */
1345 /*                                                                         */
1346 /***************************************************************************/
1347 static Widget   _Uxbuild_icon_selection_dialog(void)
1348 {
1349         Widget          _UxParent;
1350         char            *UxTmp0;
1351         int             nbutton = 0;
1352         int             ntotalbuttons = numberOfBottomButtons;
1353 #define TIGHTNESS       20
1354         Arg             args[20];
1355         int             i=0;
1356         Widget          widclipWindow;
1357
1358         /* Creation of icon_selection_dialog */
1359         _UxParent = UxParent;
1360         if ( _UxParent == NULL )
1361         {
1362                 _UxParent = UxTopLevel;
1363         }
1364
1365         _UxParent = XtVaCreatePopupShell( "icon_selection_dialog_shell",
1366                         xmDialogShellWidgetClass, _UxParent,
1367                         XmNx, 18,
1368                         XmNy, 116,
1369                         XmNwidth, 610,
1370                         XmNheight, 534,
1371                         XmNshellUnitType, XmPIXELS,
1372                         XmNkeyboardFocusPolicy, XmEXPLICIT,
1373                         XmNtitle, "icon_selection_dialog",
1374                         NULL );
1375
1376         UxTmp0 = dialog_title ? (char *)dialog_title : "Icon Selection Window";
1377
1378         icon_selection_dialog = XtVaCreateWidget( "icon_selection_dialog",
1379                         xmFormWidgetClass,
1380                         _UxParent,
1381                         XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1382                         XmNwidth, 550,
1383                         XmNheight, 534,
1384                         XmNunitType, XmPIXELS,
1385                         RES_CONVERT( XmNdialogTitle, UxTmp0 ),
1386                         XmNautoUnmanage, FALSE,
1387                         XmNdefaultPosition, FALSE,
1388                         NULL );
1389         UxPutContext( icon_selection_dialog, (char *) UxIcon_selection_dialogContext );
1390
1391         /*******************************************************************/
1392         /* Set up help callback                                            */
1393         /*******************************************************************/
1394         XtAddCallback( icon_selection_dialog, XmNhelpCallback,
1395                 (XtCallbackProc) helpCB_general,
1396                 (XtPointer) HELP_ICONSELECTOR );
1397
1398
1399         /* Creation of bottom_button_form */
1400         bottom_button_form = XtVaCreateManagedWidget( "bottom_button_form",
1401                         xmFormWidgetClass,
1402                         icon_selection_dialog,
1403                         XmNskipAdjust, TRUE,
1404                         XmNfractionBase, ((TIGHTNESS * ntotalbuttons) - 1),
1405
1406                         XmNleftOffset, 10,
1407                         XmNleftAttachment, XmATTACH_FORM,
1408                         XmNrightOffset, 10,
1409                         XmNrightAttachment, XmATTACH_FORM,
1410                         XmNbottomOffset, 20,
1411                         XmNbottomAttachment, XmATTACH_FORM,
1412
1413                         NULL );
1414         UxPutContext( bottom_button_form, (char *) UxIcon_selection_dialogContext );
1415
1416
1417         UxTmp0 = bottom_button_one_label ? (char *)bottom_button_one_label : GETMESSAGE(6, 10, "OK");
1418
1419         /* Creation of bottom_button1 = OK */
1420         bottom_button1 = XtVaCreateManagedWidget( "bottom_button1",
1421                         xmPushButtonWidgetClass,
1422                         bottom_button_form,
1423                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1424
1425                         XmNleftAttachment, nbutton ?
1426                                             XmATTACH_POSITION : XmATTACH_FORM,
1427                         XmNleftPosition, TIGHTNESS * nbutton,
1428                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1429                                              XmATTACH_POSITION : XmATTACH_FORM,
1430                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1431
1432                         NULL );
1433         nbutton++;
1434         XtAddCallback( bottom_button1, XmNactivateCallback,
1435                 (XtCallbackProc) activateCB_bottom_button1,
1436                 (XtPointer) NULL );
1437
1438         UxPutContext( bottom_button1, (char *) UxIcon_selection_dialogContext );
1439
1440         UxTmp0 = bottom_button_two_label ? (char *)bottom_button_two_label : GETMESSAGE(6, 12, "Cancel");
1441
1442         /* Creation of bottom_button2 = CANCEL */
1443         bottom_button2 = XtVaCreateManagedWidget( "bottom_button2",
1444                         xmPushButtonWidgetClass,
1445                         bottom_button_form,
1446                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1447
1448                         XmNleftAttachment, nbutton ?
1449                                             XmATTACH_POSITION : XmATTACH_FORM,
1450                         XmNleftPosition, TIGHTNESS * nbutton,
1451                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1452                                              XmATTACH_POSITION : XmATTACH_FORM,
1453                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1454
1455                         NULL );
1456         nbutton++;
1457         XtAddCallback( bottom_button2, XmNactivateCallback,
1458                 (XtCallbackProc) bottom_button_two_cb ?
1459                       bottom_button_two_cb : activateCB_bottom_button2,
1460                 (XtPointer) UxIcon_selection_dialogContext );
1461
1462         UxPutContext( bottom_button2, (char *) UxIcon_selection_dialogContext );
1463
1464         UxTmp0 = bottom_button_three_label ? (char *)bottom_button_three_label : GETMESSAGE(6, 13, "Help");
1465
1466         /* Creation of bottom_button3 = HELP */
1467         bottom_button3 = XtVaCreateManagedWidget( "bottom_button3",
1468                         xmPushButtonWidgetClass,
1469                         bottom_button_form,
1470                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1471                         XmNuserData, icon_selection_dialog,
1472
1473                         XmNleftAttachment, nbutton ?
1474                                             XmATTACH_POSITION : XmATTACH_FORM,
1475                         XmNleftPosition, TIGHTNESS * nbutton,
1476                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1477                                              XmATTACH_POSITION : XmATTACH_FORM,
1478                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1479
1480                         NULL );
1481         nbutton++;
1482         XtAddCallback( bottom_button3, XmNactivateCallback,
1483                 (XtCallbackProc) bottom_button_three_cb ?
1484                       bottom_button_three_cb : activateCB_bottom_button3,
1485                 (XtPointer) UxIcon_selection_dialogContext );
1486
1487         UxPutContext( bottom_button3, (char *) UxIcon_selection_dialogContext );
1488
1489         UxTmp0 = bottom_button_four_label ? (char *)bottom_button_four_label : GETMESSAGE(12, 10, "Filter");
1490
1491         /* Creation of bottom_button4 */
1492         bottom_button4 = XtVaCreateManagedWidget( "bottom_button4",
1493                         xmPushButtonWidgetClass,
1494                         bottom_button_form,
1495                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1496
1497                         XmNleftAttachment, nbutton ?
1498                                             XmATTACH_POSITION : XmATTACH_FORM,
1499                         XmNleftPosition, TIGHTNESS * nbutton,
1500                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1501                                              XmATTACH_POSITION : XmATTACH_FORM,
1502                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1503
1504                         NULL );
1505         nbutton++;
1506         XtAddCallback( bottom_button4, XmNactivateCallback,
1507                 (XtCallbackProc) bottom_button_four_cb ?
1508                       bottom_button_four_cb : activateCB_bottom_button,
1509                 (XtPointer) UxIcon_selection_dialogContext );
1510
1511         UxPutContext( bottom_button4, (char *) UxIcon_selection_dialogContext );
1512
1513
1514         /* Creation of separatorGadget1 */
1515         separatorGadget1 = XtVaCreateManagedWidget( "separatorGadget1",
1516                         xmSeparatorGadgetClass,
1517                         icon_selection_dialog,
1518                         XmNx, 0,
1519                         XmNy, 490,
1520                         XmNrightOffset, 1,
1521                         XmNrightAttachment, XmATTACH_FORM,
1522                         XmNleftOffset, 1,
1523                         XmNleftAttachment, XmATTACH_FORM,
1524                         XmNbottomOffset, 10,
1525                         XmNbottomWidget, bottom_button_form,
1526                         XmNbottomAttachment, XmATTACH_WIDGET,
1527                         NULL );
1528         UxPutContext( separatorGadget1, (char *) UxIcon_selection_dialogContext );
1529
1530
1531         /* Creation of icon_name_text_field */
1532         icon_name_text_field = XtVaCreateManagedWidget( "icon_name_text_field",
1533                         xmTextFieldWidgetClass,
1534                         icon_selection_dialog,
1535                         XmNx, 9,
1536                         XmNy, 440,
1537                         XmNbottomOffset, 10,
1538                         XmNbottomWidget, separatorGadget1,
1539                         XmNbottomAttachment, XmATTACH_WIDGET,
1540                         XmNrightOffset, 10,
1541                         XmNrightAttachment, XmATTACH_FORM,
1542                         XmNleftOffset, 10,
1543                         XmNleftAttachment, XmATTACH_FORM,
1544                         NULL );
1545         UxPutContext( icon_name_text_field, (char *) UxIcon_selection_dialogContext );
1546         ISD_SelectedIconTextField = icon_name_text_field;
1547
1548         UxTmp0 = name_field_title ? (char *)name_field_title : GETMESSAGE(11, 12, "Enter Icon Filename");
1549
1550         /* Creation of icon_name_textfield_label */
1551         icon_name_textfield_label = XtVaCreateManagedWidget( "icon_name_textfield_label",
1552                         xmLabelWidgetClass,
1553                         icon_selection_dialog,
1554                         XmNx, 9,
1555                         XmNy, 410,
1556                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1557                         XmNbottomOffset, 0,
1558                         XmNbottomWidget, icon_name_text_field,
1559                         XmNbottomAttachment, XmATTACH_WIDGET,
1560                         XmNleftOffset, 0,
1561                         XmNleftWidget, icon_name_text_field,
1562                         XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1563                         XmNalignment, XmALIGNMENT_BEGINNING,
1564                         NULL );
1565         UxPutContext( icon_name_textfield_label, (char *) UxIcon_selection_dialogContext );
1566
1567         UxTmp0 = filter_field_title ? (char *)filter_field_title : GETMESSAGE(12, 10, "Filter");
1568
1569         /* Creation of filter_textfield_label */
1570         filter_textfield_label = XtVaCreateManagedWidget( "filter_textfield_label",
1571                         xmLabelWidgetClass,
1572                         icon_selection_dialog,
1573                         XmNx, 10,
1574                         XmNy, 10,
1575                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1576                         XmNalignment, XmALIGNMENT_BEGINNING,
1577                         XmNtopOffset, 10,
1578                         XmNtopAttachment, XmATTACH_FORM,
1579                         XmNleftOffset, 10,
1580                         XmNleftAttachment, XmATTACH_FORM,
1581                         NULL );
1582         UxPutContext( filter_textfield_label, (char *) UxIcon_selection_dialogContext );
1583
1584
1585         /* Creation of filter_text_field */
1586         filter_text_field = XtVaCreateManagedWidget( "filter_text_field",
1587                         xmTextFieldWidgetClass,
1588                         icon_selection_dialog,
1589                         XmNx, 10,
1590                         XmNy, 40,
1591                         XmNtopOffset, 0,
1592                         XmNtopWidget, filter_textfield_label,
1593                         XmNtopAttachment, XmATTACH_WIDGET,
1594                         XmNrightOffset, 10,
1595                         XmNrightAttachment, XmATTACH_FORM,
1596                         XmNleftOffset, 10,
1597                         XmNleftAttachment, XmATTACH_FORM,
1598                         NULL );
1599         XtAddCallback( filter_text_field, XmNactivateCallback,
1600                 (XtCallbackProc) activateCB_filter_text_field,
1601                 (XtPointer) UxIcon_selection_dialogContext );
1602
1603         UxPutContext( filter_text_field, (char *) UxIcon_selection_dialogContext );
1604
1605         UxTmp0 = directory_title ? (char *)directory_title : GETMESSAGE(11, 30, "Icon Folders");
1606
1607         /* Creation of directory_list_label */
1608         directory_list_label = XtVaCreateManagedWidget( "directory_list_label",
1609                         xmLabelWidgetClass,
1610                         icon_selection_dialog,
1611                         XmNx, 0,
1612                         XmNy, 90,
1613                         XmNlabelType, XmSTRING,
1614                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1615                         XmNalignment, XmALIGNMENT_BEGINNING,
1616                         XmNtopOffset, 10,
1617                         XmNtopWidget, filter_text_field,
1618                         XmNtopAttachment, use_filter_field ? XmATTACH_WIDGET : XmATTACH_FORM,
1619                         XmNleftOffset, 10,
1620                         XmNleftAttachment, XmATTACH_FORM,
1621                         NULL );
1622         UxPutContext( directory_list_label, (char *) UxIcon_selection_dialogContext );
1623
1624         UxTmp0 = container_title ? (char *)container_title : GETMESSAGE(11, 11, "Icon Files");
1625
1626         /* Creation of icon_container_label */
1627         icon_container_label = XtVaCreateManagedWidget( "icon_container_label",
1628                         xmLabelWidgetClass,
1629                         icon_selection_dialog,
1630                         XmNx, 281,
1631                         XmNy, 90,
1632                         XmNlabelType, XmSTRING,
1633                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1634                         XmNalignment, XmALIGNMENT_BEGINNING,
1635                         XmNtopOffset, 10,
1636                         XmNtopWidget, filter_text_field,
1637                         XmNtopAttachment, XmATTACH_WIDGET,
1638                         XmNleftAttachment, XmATTACH_POSITION,
1639                         XmNleftPosition, 55,
1640                         NULL );
1641         UxPutContext( icon_container_label, (char *) UxIcon_selection_dialogContext );
1642
1643
1644         /* Creation of top_button_form */
1645         top_button_form = XtVaCreateManagedWidget( "top_button_form",
1646                         xmFormWidgetClass,
1647                         icon_selection_dialog,
1648                         XmNresizePolicy, XmRESIZE_NONE,
1649                         XmNx, 10,
1650                         XmNy, 290,
1651                         XmNbottomOffset, 10,
1652                         XmNbottomWidget, use_icon_name_field ? icon_name_textfield_label : separatorGadget1,
1653                         XmNbottomAttachment, XmATTACH_WIDGET,
1654                         XmNrightOffset, 1,
1655                         XmNrightAttachment, XmATTACH_FORM,
1656                         XmNleftOffset, 1,
1657                         XmNleftAttachment, XmATTACH_FORM,
1658                         NULL );
1659         UxPutContext( top_button_form, (char *) UxIcon_selection_dialogContext );
1660
1661         UxTmp0 = top_button_one_label ? (char *)top_button_one_label : "No_Label";
1662
1663         /* Creation of top_button1 */
1664         top_button1 = XtVaCreateManagedWidget( "top_button1",
1665                         xmPushButtonWidgetClass,
1666                         top_button_form,
1667                         XmNx, 40,
1668                         XmNy, 0,
1669                         XmNleftOffset, 0,
1670                         XmNbottomAttachment, XmATTACH_FORM,
1671                         XmNleftAttachment, XmATTACH_POSITION,
1672                         XmNtopOffset, 0,
1673                         XmNleftPosition, get_top_b1_position (numberOfTopButtons),
1674                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1675                         NULL );
1676         XtAddCallback( top_button1, XmNactivateCallback,
1677                 (XtCallbackProc) top_button_one_cb,
1678                 (XtPointer) UxIcon_selection_dialogContext );
1679
1680         UxPutContext( top_button1, (char *) UxIcon_selection_dialogContext );
1681
1682         UxTmp0 = top_button_two_label ? (char *)top_button_two_label : "No_Label";
1683
1684         /* Creation of top_button2 */
1685         top_button2 = XtVaCreateManagedWidget( "top_button2",
1686                         xmPushButtonWidgetClass,
1687                         top_button_form,
1688                         XmNx, 220,
1689                         XmNy, 0,
1690                         XmNleftOffset, 0,
1691                         XmNtopOffset, 0,
1692                         XmNleftPosition, get_top_b2_position (numberOfTopButtons),
1693                         XmNbottomAttachment, XmATTACH_FORM,
1694                         XmNleftAttachment, XmATTACH_POSITION,
1695                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1696                         NULL );
1697         XtAddCallback( top_button2, XmNactivateCallback,
1698                 (XtCallbackProc) top_button_two_cb,
1699                 (XtPointer) UxIcon_selection_dialogContext );
1700
1701         UxPutContext( top_button2, (char *) UxIcon_selection_dialogContext );
1702
1703         UxTmp0 = top_button_three_label ? (char *)top_button_three_label : "No_Label";
1704
1705         /* Creation of top_button3 */
1706         top_button3 = XtVaCreateManagedWidget( "top_button3",
1707                         xmPushButtonWidgetClass,
1708                         top_button_form,
1709                         XmNx, 310,
1710                         XmNy, 0,
1711                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1712                         XmNleftPosition, 72,
1713                         XmNleftOffset, 1,
1714                         XmNleftAttachment, XmATTACH_POSITION,
1715                         XmNbottomOffset, 0,
1716                         XmNbottomAttachment, XmATTACH_FORM,
1717                         NULL );
1718         XtAddCallback( top_button3, XmNactivateCallback,
1719                 (XtCallbackProc) top_button_three_cb,
1720                 (XtPointer) UxIcon_selection_dialogContext );
1721
1722         UxPutContext( top_button3, (char *) UxIcon_selection_dialogContext );
1723
1724         UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1725
1726         /* Creation of dir_scrolled_list */
1727         XtSetArg(args[i], XmNshadowThickness, 2); i++;
1728         XtSetArg(args[i], XmNlistSizePolicy, XmCONSTANT); i++;
1729
1730         XtSetArg(args[i], XmNleftOffset, 10); i++;
1731         XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1732         XtSetArg(args[i], XmNtopOffset, 0); i++;
1733         XtSetArg(args[i], XmNtopWidget, directory_list_label); i++;
1734         XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1735         XtSetArg(args[i], XmNrightOffset, 20); i++;
1736         XtSetArg(args[i], XmNrightWidget, icon_container_label); i++;
1737         XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
1738
1739         XtSetArg(args[i], XmNbottomOffset, 10); i++;
1740         if (numberOfTopButtons > 0) {
1741            XtSetArg(args[i], XmNbottomWidget, top_button_form); i++;
1742         } else if (use_icon_name_field) {
1743            XtSetArg(args[i], XmNbottomWidget, icon_name_textfield_label); i++;
1744         } else {
1745            XtSetArg(args[i], XmNbottomWidget, separatorGadget1); i++;
1746         }
1747         XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
1748
1749         dir_scrolled_list = XmCreateScrolledList(icon_selection_dialog,
1750                                                 "dir_scrolled_list",
1751                                                 args,
1752                                                 i);
1753         XtVaSetValues(dir_scrolled_list,
1754                         XmNselectionPolicy, XmBROWSE_SELECT,
1755                         XmNvisibleItemCount, 15,
1756                         NULL );
1757         XtManageChild(dir_scrolled_list);
1758
1759         UxPutContext( dir_scrolled_list, (char *) UxIcon_selection_dialogContext );
1760         calc_bottom_attachment (dir_scrolled_list,
1761                                (XtPointer) UxIcon_selection_dialogContext,
1762                                (XtPointer) NULL);
1763         XtAddCallback( dir_scrolled_list, XmNdefaultActionCallback,
1764                 (XtCallbackProc) defaultActionCB_dir_scrolled_list,
1765                 (XtPointer) UxIcon_selection_dialogContext );
1766
1767         UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1768
1769         /* Creation of icon_scrolled_win */
1770         icon_scrolled_win = XtVaCreateManagedWidget( "icon_scrolled_win",
1771                         xmScrolledWindowWidgetClass,
1772                         icon_selection_dialog,
1773                         XmNscrollingPolicy, XmAUTOMATIC,
1774 /*                      XmNnavigationType, XmTAB_GROUP, */
1775                         XmNx, 282,
1776                         XmNy, 84,
1777                         XmNscrollBarDisplayPolicy, XmAS_NEEDED,
1778                         XmNrightOffset, 10,
1779                         XmNrightAttachment, XmATTACH_FORM,
1780                         XmNtopOffset, 0,
1781                         XmNtopWidget, icon_container_label,
1782                         XmNtopAttachment, XmATTACH_WIDGET,
1783                         XmNleftOffset, 0,
1784                         XmNleftWidget, icon_container_label,
1785                         XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1786                         XmNbottomOffset, 10,
1787                         XmNbottomWidget, None,
1788                         XmNbottomAttachment, XmATTACH_WIDGET,
1789                         NULL );
1790
1791
1792
1793
1794         UxPutContext( icon_scrolled_win, (char *) UxIcon_selection_dialogContext );
1795         calc_bottom_attachment (icon_scrolled_win,
1796                                (XtPointer) UxIcon_selection_dialogContext,
1797                                (XtPointer) NULL);
1798
1799         /* Creation of icon_scrolled_container */
1800         icon_scrolled_container = XtVaCreateManagedWidget( "icon_scrolled_container",
1801                         xmRowColumnWidgetClass,
1802                         icon_scrolled_win,
1803                         XmNnavigationType, XmTAB_GROUP,
1804                       /*XmNborderWidth, 1,*/
1805                       /*XmNnumColumns, 2,*/
1806                         XmNnumColumns, 1,
1807                         XmNorientation, XmVERTICAL,
1808                         XmNpacking, XmPACK_COLUMN,
1809                         XmNshadowThickness, 1,
1810                         NULL );
1811
1812         XtVaSetValues(icon_selection_dialog,
1813                         XmNcancelButton, bottom_button2,
1814                         NULL );
1815
1816         XtAddCallback( icon_selection_dialog, XmNdestroyCallback,
1817                       (XtCallbackProc) UxDestroyContextCB,
1818                       (XtPointer) UxIcon_selection_dialogContext);
1819
1820         XtVaGetValues (icon_scrolled_win, XmNclipWindow, &widclipWindow, NULL);
1821         XtAddCallback( widclipWindow, XmNresizeCallback,
1822                 (XtCallbackProc) resizeCB_clipWindow,
1823                 (XtPointer) icon_scrolled_container );
1824
1825         return ( icon_selection_dialog );
1826 }
1827
1828 /*******************************************************************************
1829        The following is the 'Interface function' which is the
1830        external entry point for creating this interface.
1831        This function should be called from your application or from
1832        a callback function.
1833 *******************************************************************************/
1834
1835 Widget  create_icon_selection_dialog(swidget    _UxUxParent,
1836         unsigned char   *_Uxdialog_title,
1837         unsigned char   *_Uxfilter_field_title,
1838         int     _Uxuse_filter_field,
1839         unsigned char   *_Uxfile_filter,
1840         unsigned char   *_Uxdirectory_title,
1841         unsigned char   **_Uxdirectories_list,
1842         unsigned char   *_Uxcontainer_title,
1843         int     _UxnumberOfTopButtons,
1844         unsigned char   *_Uxtop_button_one_label,
1845         void    (*_Uxtop_button_one_cb)(),
1846         unsigned char   *_Uxtop_button_two_label,
1847         void    (*_Uxtop_button_two_cb)(),
1848         unsigned char   *_Uxtop_button_three_label,
1849         void    (*_Uxtop_button_three_cb)(),
1850         int     _Uxuse_icon_name_field,
1851         unsigned char   *_Uxname_field_title,
1852         int     _UxnumberOfBottomButtons,
1853         unsigned char   *_Uxbottom_button_one_label,
1854         void    (*_Uxbottom_button_one_cb)(),
1855         unsigned char   *_Uxbottom_button_two_label,
1856         void    (*_Uxbottom_button_two_cb)(),
1857         unsigned char   *_Uxbottom_button_three_label,
1858         void    (*_Uxbottom_button_three_cb)(),
1859         unsigned char   *_Uxbottom_button_four_label,
1860         void    (*_Uxbottom_button_four_cb)() )
1861
1862
1863 {
1864         char                   *initial_filter;
1865         char                   *icon_file_name;
1866         Widget                  rtrn;
1867         int                     lcv;
1868         _UxCicon_selection_dialog *UxContext;
1869
1870         UxIcon_selection_dialogContext = UxContext =
1871                 (_UxCicon_selection_dialog *) UxNewContext( sizeof(_UxCicon_selection_dialog), False );
1872
1873         UxParent = _UxUxParent;
1874         dialog_title = _Uxdialog_title;
1875         filter_field_title = _Uxfilter_field_title;
1876         use_filter_field = _Uxuse_filter_field;
1877         file_filter = _Uxfile_filter;
1878         directory_title = _Uxdirectory_title;
1879         directories_list = _Uxdirectories_list;
1880         container_title = _Uxcontainer_title;
1881         numberOfTopButtons = _UxnumberOfTopButtons;
1882         top_button_one_label = _Uxtop_button_one_label;
1883         top_button_one_cb = _Uxtop_button_one_cb;
1884         top_button_two_label = _Uxtop_button_two_label;
1885         top_button_two_cb = _Uxtop_button_two_cb;
1886         top_button_three_label = _Uxtop_button_three_label;
1887         top_button_three_cb = _Uxtop_button_three_cb;
1888         use_icon_name_field = _Uxuse_icon_name_field;
1889         name_field_title = _Uxname_field_title;
1890         numberOfBottomButtons = _UxnumberOfBottomButtons;
1891         bottom_button_one_label = _Uxbottom_button_one_label;
1892         bottom_button_one_cb = _Uxbottom_button_one_cb;
1893         bottom_button_two_label = _Uxbottom_button_two_label;
1894         bottom_button_two_cb = _Uxbottom_button_two_cb;
1895         bottom_button_three_label = _Uxbottom_button_three_label;
1896         bottom_button_three_cb = _Uxbottom_button_three_cb;
1897         bottom_button_four_label = _Uxbottom_button_four_label;
1898         bottom_button_four_cb = _Uxbottom_button_four_cb;
1899
1900         rtrn = _Uxbuild_icon_selection_dialog();
1901
1902         switch (numberOfTopButtons){
1903                 case 0 : XtUnmanageChild (top_button_form); break;
1904                 case 1 : XtUnmanageChild (top_button2);
1905                 case 2 : XtUnmanageChild (top_button3);
1906         };
1907
1908         if (numberOfBottomButtons == 3)
1909            XtUnmanageChild (bottom_button4);
1910
1911         if (!use_filter_field) {
1912            XtUnmanageChild (filter_textfield_label);
1913            XtUnmanageChild (filter_text_field);
1914         }
1915
1916         if (!use_icon_name_field) {
1917            XtUnmanageChild (icon_name_textfield_label);
1918            XtUnmanageChild (icon_name_text_field);
1919         }
1920
1921         TurnOnHourGlassAllWindows();
1922
1923         /******************************************************************/
1924         /* save file_filter */
1925         /******************************************************************/
1926         file_filter_global = (char *)calloc(strlen((char *)file_filter)+1, sizeof(char));
1927
1928 #ifdef DEBUG
1929         if (!file_filter_global) printf("Calloc error for file_filter_global, in create_icon_selection_dialog.\n");
1930 #endif
1931
1932         if (file_filter[0] == '*')
1933            file_filter_global = strcpy(file_filter_global, (char *)&file_filter[1]);
1934         else
1935            file_filter_global = strcpy(file_filter_global, (char *)file_filter);
1936
1937         load_directories_list ((char **)directories_list);
1938         initial_filter = initialize_filter ((char *)file_filter);
1939
1940         /******************************************************************/
1941         /* save main_filter */
1942         /******************************************************************/
1943         main_filter = (char *)calloc(strlen(initial_filter)+1, sizeof(char));
1944
1945 #ifdef DEBUG
1946         if (!main_filter) printf("Calloc error for main_filter, in create_icon_selection_dialog.\n");
1947 #endif
1948
1949         main_filter = strcpy(main_filter, initial_filter);;
1950
1951         icons_in_container = NULL;
1952         icon_count = 0;
1953
1954         update_container_contents (initial_filter);
1955
1956         /******************************************************************/
1957         /* set selected_icon_name to first name in list                   */
1958         /******************************************************************/
1959 #if 0
1960         if (icons_in_container) {
1961            XtVaGetValues (icons_in_container[0], XmNimageName, &icon_file_name, NULL);
1962            XmTextFieldSetString (icon_name_text_field, icon_file_name);
1963            selected_icon_name = XtMalloc(strlen(icon_file_name) + 1);
1964            if (selected_icon_name)
1965               selected_icon_name = strcpy(selected_icon_name, icon_file_name);
1966         }
1967 #endif
1968
1969         load_filter_text_field (initial_filter);
1970
1971         TurnOffHourGlassAllWindows();
1972
1973         return(rtrn);
1974 }