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