dtwm: basic multihead(xinerama only) support
[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        sprintf (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        strcpy(iconfile, 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   return;
845
846 }
847
848 #ifdef _ICONSELECTOR_DESTROY_ENABLED
849 /***************************************************************************/
850 /*                                                                         */
851 /*  void free_container_contents - free icon gadgets in container          */
852 /*  Input: none                                                            */
853 /*  Output: none                                                           */
854 /*                                                                         */
855 /***************************************************************************/
856 void  free_container_contents (void)
857 {
858   int    lcv = 0;
859   char   *filename;
860   Pixmap icon_pixmap;
861   Screen *screen_id;
862
863   if (icons_in_container) {
864      screen_id = XtScreen (icons_in_container[0]);
865      lcv = 0;
866      while (icons_in_container[lcv]) {
867 #if 0
868        XtVaGetValues (icons_in_container[lcv], XmNimageName, &filename,
869                       XmNpixmap, &icon_pixmap, NULL);
870        XmDestroyPixmap (screen_id, icon_pixmap);
871
872        XtVaSetValues (icons_in_container[lcv], XmNpixmap, NULL, NULL);
873 #endif
874        XtDestroyWidget (icons_in_container[lcv]);
875        /*
876        icons_in_container[lcv]=NULL;
877        */
878        lcv++;
879      }  /* end while icons_in_container */
880      free (icons_in_container);
881      icons_in_container = NULL;
882   }
883
884 #ifdef DEBUG
885   printf ("In free_container_contents...\n");
886   printf ("Just destroyed all %i icons.\n", lcv);
887 #endif
888
889   icon_count = 0;
890
891   return;
892 }
893 #endif
894
895 #if 0
896 /***************************************************************************/
897 /*                                                                         */
898 /*  void load_new_filter - displays selected directory string as           */
899 /*                         new filter base                                 */
900 /*  Input: char *new_filter - new directory string to use as filter        */
901 /*  Output: none                                                           */
902 /*                                                                         */
903 /***************************************************************************/
904 void load_new_filter (char *new_filter)
905 {
906 /* no longer need old filter */
907 free (main_filter);
908
909 /* create space for new filter */
910 main_filter = (char *)calloc (strlen(new_filter)+3, sizeof (char));
911 #ifdef DEBUG
912 if (!main_filter) printf("Calloc error for main_filter, in load_new_filter.\n");
913 #endif
914 /* copy new filter and add filter end */
915 main_filter = strcpy (main_filter, new_filter);
916 main_filter = strcat (main_filter, "/*");
917 /* display new filter */
918 load_filter_text_field (main_filter);
919
920 return;
921 }
922 #endif
923
924 /*****************************************************************************/
925 /*       The following are callback functions.                               */
926 /*****************************************************************************/
927
928 /***************************************************************************/
929 /*                                                                         */
930 /*   calc_bottom_attachment                                                */
931 /*                                                                         */
932 /*                                                                         */
933 /***************************************************************************/
934 static  void    calc_bottom_attachment( Widget UxWidget,
935                                              XtPointer UxClientData,
936                                              XtPointer UxCallbackArg )
937 {
938   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
939
940   UxSaveCtx = UxIcon_selection_dialogContext;
941   UxIcon_selection_dialogContext = UxContext =
942                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
943   {
944     if (numberOfTopButtons > 0) {
945        XtVaSetValues (UxWidget, XmNbottomWidget, top_button_form, NULL);
946     } else if (use_icon_name_field) {
947        XtVaSetValues (UxWidget, XmNbottomWidget, icon_name_textfield_label, NULL);
948     } else XtVaSetValues (UxWidget, XmNbottomWidget, separatorGadget1, NULL);
949   }
950   return;
951 }
952
953 /***************************************************************************/
954 /*                                                                         */
955 /*  activateCB_bottom_button                                               */
956 /*                                                                         */
957 /*                                                                         */
958 /***************************************************************************/
959 /* default cb for bottom buttons */
960 static  void    activateCB_bottom_button( Widget UxWidget,
961                                              XtPointer UxClientData,
962                                              XtPointer UxCallbackArg )
963 {
964   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
965
966   UxSaveCtx = UxIcon_selection_dialogContext;
967   UxIcon_selection_dialogContext = UxContext =
968                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
969   {
970
971   }
972   return;
973 }
974 /******************************************************************************/
975 /* activateCB_NoFindIconDialog_ChangeNameButton                               */
976 /******************************************************************************/
977 void    activateCB_NoFindIconDialog_ChangeNameButton( Widget  UxWidget,
978                                         XtPointer UxClientData,
979                                         XtPointer UxCallbackArg)
980
981 {
982   XtDestroyWidget(UxWidget);
983 }
984
985 /******************************************************************************/
986 /* activateCB_NoFindIconDialog_NameOKButton                                   */
987 /******************************************************************************/
988 void    activateCB_NoFindIconDialog_NameOKButton( Widget  UxWidget,
989                                         XtPointer UxClientData,
990                                         XtPointer UxCallbackArg)
991
992 {
993   char *basename = (char *)NULL;
994
995   TurnOnHourGlassAllWindows();
996   if (bottom_button_one_cb) {
997      GetWidgetTextString(icon_name_text_field, &basename);
998      bottom_button_one_cb(UxWidget,
999                          (XtPointer)basename, UxCallbackArg);
1000      if (basename) XtFree(basename);
1001   }
1002   TurnOffHourGlassAllWindows();
1003   UxPopdownInterface (IconSelector);
1004   XtDestroyWidget(UxWidget);
1005 }
1006
1007 /******************************************************************************/
1008 /* display_nofindicon_message - display cant find icons error dialog          */
1009 /* INPUT:  Widget parent - parent to position error dialog new                */
1010 /* OUTPIT: none                                                               */
1011 /******************************************************************************/
1012 void display_nofindicon_message (Widget parent)
1013 {
1014   Widget dialog;
1015   Widget widChild;
1016   char   buffer[512];
1017
1018   dialog = XmCreateErrorDialog(parent, "nofindiconDialog", NULL, 0);
1019
1020   widChild = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
1021   XtVaSetValues(widChild,
1022                 RES_CONVERT( XmNlabelString, "Change Name"),
1023                 NULL);
1024
1025   widChild = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
1026   XtVaSetValues(widChild,
1027                 RES_CONVERT( XmNlabelString, "Name OK"),
1028                 NULL);
1029
1030   XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
1031
1032   XtAddCallback( dialog, XmNokCallback,
1033           (XtCallbackProc) activateCB_NoFindIconDialog_ChangeNameButton,
1034           (XtPointer) NULL );
1035   XtAddCallback( dialog, XmNcancelCallback,
1036           (XtCallbackProc) activateCB_NoFindIconDialog_NameOKButton,
1037           (XtPointer) NULL );
1038
1039   /*********  WARNING - this needs to be translated !!! ***********/
1040   strcpy(buffer, "There is no set of icons with that filename in the icon folders.\n");
1041   strcat(buffer, "Move the icons into one of the icon folers, then select \"Name OK\".\n");
1042   strcat(buffer, "Or, to select a different set of icons, select \"Change Name\".\n");
1043   strcat(buffer, "\nIf you are a software developer creating a registration package,\n");
1044   strcat(buffer, "ignore this message and select \"Name OK\".");
1045   XtVaSetValues (dialog,
1046                  RES_CONVERT(XmNdialogTitle, GETMESSAGE(6, 31, "Create Action - Error")),
1047                  RES_CONVERT(XmNmessageString, buffer),
1048                  NULL);
1049
1050   XtManageChild (dialog);
1051   return;
1052 }
1053
1054 /***************************************************************************/
1055 /*                                                                         */
1056 /*  activateCB_bottom_button1                                              */
1057 /*                                                                         */
1058 /*                                                                         */
1059 /***************************************************************************/
1060 /*  cb for bottom button 1 = OK */
1061 static  void    activateCB_bottom_button1( Widget UxWidget,
1062                                              XtPointer UxClientData,
1063                                              XtPointer UxCallbackArg )
1064 {
1065   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1066
1067   UxSaveCtx = UxIcon_selection_dialogContext;
1068   UxIcon_selection_dialogContext = UxContext =
1069                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1070   {
1071     char *basename = (char *)NULL;
1072     char *fullname = (char *)NULL;
1073     char *msgPtr, *errPtr;
1074
1075     GetWidgetTextString(icon_name_text_field, &basename);
1076     if (basename) {
1077        if (strchr(basename, '/')) {
1078           /**** WARNING - this needs to be in a message catalog in the future ****/
1079           /* INTERNATIONALIZE */
1080           msgPtr = "Invalid Icon filename.\n\
1081 Pathnames are not valid in the \"Enter Icon Filename\" field.\n\
1082 Enter only the name of the icon without the path or extensions.";
1083           errPtr = XtNewString(msgPtr);
1084           display_error_message(IconSelector, errPtr);
1085           XtFree(errPtr);
1086        } else {
1087           FIND_ICONGADGET_ICON(basename, fullname, DtMEDIUM);
1088           if ( (fullname) && (check_file_exists(fullname)) ) {
1089              TurnOnHourGlassAllWindows();
1090              if (bottom_button_one_cb) {
1091                 bottom_button_one_cb(UxWidget,
1092                                     (XtPointer)fullname, UxCallbackArg);
1093              }
1094              TurnOffHourGlassAllWindows();
1095              UxPopdownInterface (IconSelector);
1096              if (basename) XtFree(basename);
1097           } else {
1098              display_nofindicon_message(IconSelector);
1099           }
1100        }
1101     } else {
1102        msgPtr = GETMESSAGE(11, 50, "The Icon Filename is invalid.\n\
1103 Please enter a valid icon file name in the\n'Enter Icon Filename' field.");
1104        errPtr = XtNewString(msgPtr);
1105        display_error_message(IconSelector, errPtr);
1106        XtFree(errPtr);
1107     }
1108   }
1109   return;
1110
1111 #if 0   /*************  old code *********************/
1112     char *pszIconFileName = (char *)NULL;
1113     char    buffer[MAXBUFSIZE];
1114
1115     GetWidgetTextString(icon_name_text_field, &pszIconFileName);
1116     if ( (pszIconFileName) && (check_file_exists(pszIconFileName)) ) {
1117        TurnOnHourGlassAllWindows();
1118        if (bottom_button_one_cb) {
1119           bottom_button_one_cb(UxWidget,
1120                               (XtPointer)pszIconFileName, UxCallbackArg);
1121        }
1122 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1123        free_container_contents ();
1124        if (selected_icon_name) {
1125           XtFree(selected_icon_name);
1126        }
1127        selected_icon_name = (char *)NULL;
1128        XtDestroyWidget (XtParent(icon_selection_dialog));
1129        IconSelector = (Widget)NULL;
1130        TurnOffHourGlassAllWindows();
1131 #else
1132        TurnOffHourGlassAllWindows();
1133        UxPopdownInterface (IconSelector);
1134 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
1135        XtFree(pszIconFileName);
1136     } else {
1137        strcpy(buffer, GETMESSAGE(11, 50, "The Icon Filename is invalid.\nPlease enter a valid icon file name in the\n'Enter Icon Filename' field."));
1138        display_error_message(IconSelector, buffer);
1139     }
1140   }
1141
1142 #if 0
1143     if (selected_icon_name) {
1144       TurnOnHourGlassAllWindows();
1145       if (bottom_button_one_cb) {
1146          bottom_button_one_cb(UxWidget,
1147                              (XtPointer)selected_icon_name, UxCallbackArg);
1148       }
1149 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1150       free_container_contents ();
1151       XtFree(selected_icon_name);
1152       selected_icon_name = (char *)NULL;
1153       XtDestroyWidget (XtParent(icon_selection_dialog));
1154       IconSelector = (Widget)NULL;
1155       TurnOffHourGlassAllWindows();
1156 #else
1157       TurnOffHourGlassAllWindows();
1158       UxPopdownInterface (IconSelector);
1159 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
1160     }
1161   }
1162 #endif
1163   return;
1164 #endif  /*************  old code *********************/
1165
1166 }
1167
1168 /***************************************************************************/
1169 /*                                                                         */
1170 /*   activateCB_bottom_button2                                             */
1171 /*                                                                         */
1172 /*                                                                         */
1173 /***************************************************************************/
1174 /*  cb for bottom button 2 = CANCEL */
1175 static  void    activateCB_bottom_button2( Widget UxWidget,
1176                                              XtPointer UxClientData,
1177                                              XtPointer UxCallbackArg )
1178 {
1179   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1180
1181   UxSaveCtx = UxIcon_selection_dialogContext;
1182   UxIcon_selection_dialogContext = UxContext =
1183                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1184   {
1185 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1186     free_container_contents ();
1187     XtDestroyWidget (XtParent(icon_selection_dialog));
1188     IconSelector = (Widget)NULL;
1189 #else
1190     UxPopdownInterface (IconSelector);
1191 #endif  /* _ICONSELECTOR_DESTROY_ENABLED */
1192   }
1193   return;
1194 }
1195
1196 /***************************************************************************/
1197 /*                                                                         */
1198 /*  activateCB_bottom_button3                                              */
1199 /*                                                                         */
1200 /*                                                                         */
1201 /***************************************************************************/
1202 /* default cb for bottom button3 = HELP */
1203 static  void    activateCB_bottom_button3( Widget UxWidget,
1204                                              XtPointer UxClientData,
1205                                              XtPointer UxCallbackArg )
1206 {
1207   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1208
1209   UxSaveCtx = UxIcon_selection_dialogContext;
1210   UxIcon_selection_dialogContext = UxContext =
1211                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1212   {
1213     DisplayHelpDialog(UxWidget, (XtPointer)HELP_ICONSELECTOR, UxCallbackArg);
1214   }
1215   return;
1216 }
1217
1218 /***************************************************************************/
1219 /*                                                                         */
1220 /*   activateCB_filter_text_field                                          */
1221 /*                                                                         */
1222 /*                                                                         */
1223 /***************************************************************************/
1224 static  void    activateCB_filter_text_field( Widget UxWidget,
1225                                              XtPointer UxClientData,
1226                                              XtPointer UxCallbackArg )
1227 {
1228   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1229   UxSaveCtx = UxIcon_selection_dialogContext;
1230   UxIcon_selection_dialogContext = UxContext =
1231                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1232   {
1233     char *filter;
1234
1235     filter = XmTextFieldGetString (UxWidget);
1236     apply_filter (filter);
1237   }
1238   UxIcon_selection_dialogContext = UxSaveCtx;
1239 }
1240
1241 /***************************************************************************/
1242 /*                                                                         */
1243 /*  defaultActionCB_dir_scrolled_list                                      */
1244 /*                                                                         */
1245 /*                                                                         */
1246 /***************************************************************************/
1247 static  void    defaultActionCB_dir_scrolled_list( Widget UxWidget,
1248                                                   XtPointer UxClientData,
1249                                                   XtPointer UxCallbackArg )
1250 {
1251   _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1252
1253   UxSaveCtx = UxIcon_selection_dialogContext;
1254   UxIcon_selection_dialogContext = UxContext =
1255                   (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1256   {
1257     XmListCallbackStruct *listcb;
1258     char *filter;
1259
1260     listcb = (XmListCallbackStruct *) UxCallbackArg;
1261     filter = (char *)XmStringToText (listcb->item);
1262     apply_filter (filter);
1263  /* XtManageChild (icon_scrolled_win);  */
1264   }
1265   UxIcon_selection_dialogContext = UxSaveCtx;
1266 }
1267
1268 /***************************************************************************/
1269 /*                                                                         */
1270 /*  selectionCB_icon_scrolled_container                                    */
1271 /*                                                                         */
1272 /***************************************************************************/
1273 static  void    selectionCB_icon_scrolled_container ( Widget UxWidget,
1274                                                   XtPointer UxClientData,
1275                                                   XtPointer UxCallbackArg )
1276 {
1277   char     *filename;
1278   XmString  xmbasename;
1279   char     *basename;
1280
1281   XtVaGetValues (UxWidget, XmNimageName, &filename, NULL);
1282 #ifdef DEBUG
1283   printf("In icon callback for '%s'\n", filename);
1284 #endif
1285   if (use_icon_name_field) {
1286      XtVaGetValues (UxWidget, XmNstring, &xmbasename, NULL);
1287      basename = XmStringToText(xmbasename);
1288      XmTextFieldSetString (icon_name_text_field, basename);
1289      if (basename) free(basename);
1290   }
1291   if (selected_icon_name) {
1292      if (selected_icon != UxWidget) {
1293         _DtIconSetState(selected_icon, FALSE, FALSE);
1294      }
1295      XtFree(selected_icon_name);
1296      selected_icon_name = (char *)NULL;
1297   }
1298   if (filename) {
1299      selected_icon_name = XtMalloc(strlen(filename) + 1);
1300      selected_icon_name = strcpy(selected_icon_name, filename);
1301   } else {
1302      selected_icon_name = (char *)NULL;
1303   }
1304   selected_icon = UxWidget;
1305
1306   return;
1307 }
1308
1309 /***************************************************************************/
1310 /*                                                                         */
1311 /*  resizeCB_clipWindow                                                    */
1312 /*                                                                         */
1313 /***************************************************************************/
1314 void    resizeCB_clipWindow( Widget UxWidget,
1315                              XtPointer UxClientData,
1316                              XtPointer UxCallbackArg )
1317 {
1318   Widget     widvScrollbar;
1319   Widget     widRowColumn;
1320   int        increment;
1321   XtArgVal /* Dimension */  height;
1322
1323   XtVaGetValues(XtParent(UxWidget), XmNverticalScrollBar, &widvScrollbar, NULL);
1324   widRowColumn = (Widget)UxClientData;
1325   XtVaGetValues(widRowColumn, XmNheight, &height, NULL);
1326
1327 #ifdef DEBUG
1328   printf("height = %d\n", height);
1329   printf("icon_count = %d\n", icon_count);
1330 #endif
1331
1332   increment = (int)height / icon_count;
1333   XtVaSetValues(widvScrollbar, XmNincrement, increment, NULL);
1334
1335   return;
1336
1337 }
1338
1339 /***************************************************************************/
1340 /*                                                                         */
1341 /*  _Uxbuild_icon_selection_dialog                                         */
1342 /*                                                                         */
1343 /*                                                                         */
1344 /***************************************************************************/
1345 static Widget   _Uxbuild_icon_selection_dialog(void)
1346 {
1347         Widget          _UxParent;
1348         char            *UxTmp0;
1349         int             nbutton = 0;
1350         int             ntotalbuttons = numberOfBottomButtons;
1351 #define TIGHTNESS       20
1352         Arg             args[20];
1353         int             i=0;
1354         Widget          widclipWindow;
1355
1356         /* Creation of icon_selection_dialog */
1357         _UxParent = UxParent;
1358         if ( _UxParent == NULL )
1359         {
1360                 _UxParent = UxTopLevel;
1361         }
1362
1363         _UxParent = XtVaCreatePopupShell( "icon_selection_dialog_shell",
1364                         xmDialogShellWidgetClass, _UxParent,
1365                         XmNx, 18,
1366                         XmNy, 116,
1367                         XmNwidth, 610,
1368                         XmNheight, 534,
1369                         XmNshellUnitType, XmPIXELS,
1370                         XmNkeyboardFocusPolicy, XmEXPLICIT,
1371                         XmNtitle, "icon_selection_dialog",
1372                         NULL );
1373
1374         UxTmp0 = dialog_title ? (char *)dialog_title : "Icon Selection Window";
1375
1376         icon_selection_dialog = XtVaCreateWidget( "icon_selection_dialog",
1377                         xmFormWidgetClass,
1378                         _UxParent,
1379                         XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1380                         XmNwidth, 550,
1381                         XmNheight, 534,
1382                         XmNunitType, XmPIXELS,
1383                         RES_CONVERT( XmNdialogTitle, UxTmp0 ),
1384                         XmNautoUnmanage, FALSE,
1385                         XmNdefaultPosition, FALSE,
1386                         NULL );
1387         UxPutContext( icon_selection_dialog, (char *) UxIcon_selection_dialogContext );
1388
1389         /*******************************************************************/
1390         /* Set up help callback                                            */
1391         /*******************************************************************/
1392         XtAddCallback( icon_selection_dialog, XmNhelpCallback,
1393                 (XtCallbackProc) helpCB_general,
1394                 (XtPointer) HELP_ICONSELECTOR );
1395
1396
1397         /* Creation of bottom_button_form */
1398         bottom_button_form = XtVaCreateManagedWidget( "bottom_button_form",
1399                         xmFormWidgetClass,
1400                         icon_selection_dialog,
1401                         XmNskipAdjust, TRUE,
1402                         XmNfractionBase, ((TIGHTNESS * ntotalbuttons) - 1),
1403
1404                         XmNleftOffset, 10,
1405                         XmNleftAttachment, XmATTACH_FORM,
1406                         XmNrightOffset, 10,
1407                         XmNrightAttachment, XmATTACH_FORM,
1408                         XmNbottomOffset, 20,
1409                         XmNbottomAttachment, XmATTACH_FORM,
1410
1411                         NULL );
1412         UxPutContext( bottom_button_form, (char *) UxIcon_selection_dialogContext );
1413
1414
1415         UxTmp0 = bottom_button_one_label ? (char *)bottom_button_one_label : GETMESSAGE(6, 10, "OK");
1416
1417         /* Creation of bottom_button1 = OK */
1418         bottom_button1 = XtVaCreateManagedWidget( "bottom_button1",
1419                         xmPushButtonWidgetClass,
1420                         bottom_button_form,
1421                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1422
1423                         XmNleftAttachment, nbutton ?
1424                                             XmATTACH_POSITION : XmATTACH_FORM,
1425                         XmNleftPosition, TIGHTNESS * nbutton,
1426                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1427                                              XmATTACH_POSITION : XmATTACH_FORM,
1428                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1429
1430                         NULL );
1431         nbutton++;
1432         XtAddCallback( bottom_button1, XmNactivateCallback,
1433                 (XtCallbackProc) activateCB_bottom_button1,
1434                 (XtPointer) NULL );
1435
1436         UxPutContext( bottom_button1, (char *) UxIcon_selection_dialogContext );
1437
1438         UxTmp0 = bottom_button_two_label ? (char *)bottom_button_two_label : GETMESSAGE(6, 12, "Cancel");
1439
1440         /* Creation of bottom_button2 = CANCEL */
1441         bottom_button2 = XtVaCreateManagedWidget( "bottom_button2",
1442                         xmPushButtonWidgetClass,
1443                         bottom_button_form,
1444                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1445
1446                         XmNleftAttachment, nbutton ?
1447                                             XmATTACH_POSITION : XmATTACH_FORM,
1448                         XmNleftPosition, TIGHTNESS * nbutton,
1449                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1450                                              XmATTACH_POSITION : XmATTACH_FORM,
1451                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1452
1453                         NULL );
1454         nbutton++;
1455         XtAddCallback( bottom_button2, XmNactivateCallback,
1456                 (XtCallbackProc) bottom_button_two_cb ?
1457                       bottom_button_two_cb : activateCB_bottom_button2,
1458                 (XtPointer) UxIcon_selection_dialogContext );
1459
1460         UxPutContext( bottom_button2, (char *) UxIcon_selection_dialogContext );
1461
1462         UxTmp0 = bottom_button_three_label ? (char *)bottom_button_three_label : GETMESSAGE(6, 13, "Help");
1463
1464         /* Creation of bottom_button3 = HELP */
1465         bottom_button3 = XtVaCreateManagedWidget( "bottom_button3",
1466                         xmPushButtonWidgetClass,
1467                         bottom_button_form,
1468                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1469                         XmNuserData, icon_selection_dialog,
1470
1471                         XmNleftAttachment, nbutton ?
1472                                             XmATTACH_POSITION : XmATTACH_FORM,
1473                         XmNleftPosition, TIGHTNESS * nbutton,
1474                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1475                                              XmATTACH_POSITION : XmATTACH_FORM,
1476                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1477
1478                         NULL );
1479         nbutton++;
1480         XtAddCallback( bottom_button3, XmNactivateCallback,
1481                 (XtCallbackProc) bottom_button_three_cb ?
1482                       bottom_button_three_cb : activateCB_bottom_button3,
1483                 (XtPointer) UxIcon_selection_dialogContext );
1484
1485         UxPutContext( bottom_button3, (char *) UxIcon_selection_dialogContext );
1486
1487         UxTmp0 = bottom_button_four_label ? (char *)bottom_button_four_label : GETMESSAGE(12, 10, "Filter");
1488
1489         /* Creation of bottom_button4 */
1490         bottom_button4 = XtVaCreateManagedWidget( "bottom_button4",
1491                         xmPushButtonWidgetClass,
1492                         bottom_button_form,
1493                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1494
1495                         XmNleftAttachment, nbutton ?
1496                                             XmATTACH_POSITION : XmATTACH_FORM,
1497                         XmNleftPosition, TIGHTNESS * nbutton,
1498                         XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1499                                              XmATTACH_POSITION : XmATTACH_FORM,
1500                         XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1501
1502                         NULL );
1503         nbutton++;
1504         XtAddCallback( bottom_button4, XmNactivateCallback,
1505                 (XtCallbackProc) bottom_button_four_cb ?
1506                       bottom_button_four_cb : activateCB_bottom_button,
1507                 (XtPointer) UxIcon_selection_dialogContext );
1508
1509         UxPutContext( bottom_button4, (char *) UxIcon_selection_dialogContext );
1510
1511
1512         /* Creation of separatorGadget1 */
1513         separatorGadget1 = XtVaCreateManagedWidget( "separatorGadget1",
1514                         xmSeparatorGadgetClass,
1515                         icon_selection_dialog,
1516                         XmNx, 0,
1517                         XmNy, 490,
1518                         XmNrightOffset, 1,
1519                         XmNrightAttachment, XmATTACH_FORM,
1520                         XmNleftOffset, 1,
1521                         XmNleftAttachment, XmATTACH_FORM,
1522                         XmNbottomOffset, 10,
1523                         XmNbottomWidget, bottom_button_form,
1524                         XmNbottomAttachment, XmATTACH_WIDGET,
1525                         NULL );
1526         UxPutContext( separatorGadget1, (char *) UxIcon_selection_dialogContext );
1527
1528
1529         /* Creation of icon_name_text_field */
1530         icon_name_text_field = XtVaCreateManagedWidget( "icon_name_text_field",
1531                         xmTextFieldWidgetClass,
1532                         icon_selection_dialog,
1533                         XmNx, 9,
1534                         XmNy, 440,
1535                         XmNbottomOffset, 10,
1536                         XmNbottomWidget, separatorGadget1,
1537                         XmNbottomAttachment, XmATTACH_WIDGET,
1538                         XmNrightOffset, 10,
1539                         XmNrightAttachment, XmATTACH_FORM,
1540                         XmNleftOffset, 10,
1541                         XmNleftAttachment, XmATTACH_FORM,
1542                         NULL );
1543         UxPutContext( icon_name_text_field, (char *) UxIcon_selection_dialogContext );
1544         ISD_SelectedIconTextField = icon_name_text_field;
1545
1546         UxTmp0 = name_field_title ? (char *)name_field_title : GETMESSAGE(11, 12, "Enter Icon Filename");
1547
1548         /* Creation of icon_name_textfield_label */
1549         icon_name_textfield_label = XtVaCreateManagedWidget( "icon_name_textfield_label",
1550                         xmLabelWidgetClass,
1551                         icon_selection_dialog,
1552                         XmNx, 9,
1553                         XmNy, 410,
1554                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1555                         XmNbottomOffset, 0,
1556                         XmNbottomWidget, icon_name_text_field,
1557                         XmNbottomAttachment, XmATTACH_WIDGET,
1558                         XmNleftOffset, 0,
1559                         XmNleftWidget, icon_name_text_field,
1560                         XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1561                         XmNalignment, XmALIGNMENT_BEGINNING,
1562                         NULL );
1563         UxPutContext( icon_name_textfield_label, (char *) UxIcon_selection_dialogContext );
1564
1565         UxTmp0 = filter_field_title ? (char *)filter_field_title : GETMESSAGE(12, 10, "Filter");
1566
1567         /* Creation of filter_textfield_label */
1568         filter_textfield_label = XtVaCreateManagedWidget( "filter_textfield_label",
1569                         xmLabelWidgetClass,
1570                         icon_selection_dialog,
1571                         XmNx, 10,
1572                         XmNy, 10,
1573                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1574                         XmNalignment, XmALIGNMENT_BEGINNING,
1575                         XmNtopOffset, 10,
1576                         XmNtopAttachment, XmATTACH_FORM,
1577                         XmNleftOffset, 10,
1578                         XmNleftAttachment, XmATTACH_FORM,
1579                         NULL );
1580         UxPutContext( filter_textfield_label, (char *) UxIcon_selection_dialogContext );
1581
1582
1583         /* Creation of filter_text_field */
1584         filter_text_field = XtVaCreateManagedWidget( "filter_text_field",
1585                         xmTextFieldWidgetClass,
1586                         icon_selection_dialog,
1587                         XmNx, 10,
1588                         XmNy, 40,
1589                         XmNtopOffset, 0,
1590                         XmNtopWidget, filter_textfield_label,
1591                         XmNtopAttachment, XmATTACH_WIDGET,
1592                         XmNrightOffset, 10,
1593                         XmNrightAttachment, XmATTACH_FORM,
1594                         XmNleftOffset, 10,
1595                         XmNleftAttachment, XmATTACH_FORM,
1596                         NULL );
1597         XtAddCallback( filter_text_field, XmNactivateCallback,
1598                 (XtCallbackProc) activateCB_filter_text_field,
1599                 (XtPointer) UxIcon_selection_dialogContext );
1600
1601         UxPutContext( filter_text_field, (char *) UxIcon_selection_dialogContext );
1602
1603         UxTmp0 = directory_title ? (char *)directory_title : GETMESSAGE(11, 30, "Icon Folders");
1604
1605         /* Creation of directory_list_label */
1606         directory_list_label = XtVaCreateManagedWidget( "directory_list_label",
1607                         xmLabelWidgetClass,
1608                         icon_selection_dialog,
1609                         XmNx, 0,
1610                         XmNy, 90,
1611                         XmNlabelType, XmSTRING,
1612                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1613                         XmNalignment, XmALIGNMENT_BEGINNING,
1614                         XmNtopOffset, 10,
1615                         XmNtopWidget, filter_text_field,
1616                         XmNtopAttachment, use_filter_field ? XmATTACH_WIDGET : XmATTACH_FORM,
1617                         XmNleftOffset, 10,
1618                         XmNleftAttachment, XmATTACH_FORM,
1619                         NULL );
1620         UxPutContext( directory_list_label, (char *) UxIcon_selection_dialogContext );
1621
1622         UxTmp0 = container_title ? (char *)container_title : GETMESSAGE(11, 11, "Icon Files");
1623
1624         /* Creation of icon_container_label */
1625         icon_container_label = XtVaCreateManagedWidget( "icon_container_label",
1626                         xmLabelWidgetClass,
1627                         icon_selection_dialog,
1628                         XmNx, 281,
1629                         XmNy, 90,
1630                         XmNlabelType, XmSTRING,
1631                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1632                         XmNalignment, XmALIGNMENT_BEGINNING,
1633                         XmNtopOffset, 10,
1634                         XmNtopWidget, filter_text_field,
1635                         XmNtopAttachment, XmATTACH_WIDGET,
1636                         XmNleftAttachment, XmATTACH_POSITION,
1637                         XmNleftPosition, 55,
1638                         NULL );
1639         UxPutContext( icon_container_label, (char *) UxIcon_selection_dialogContext );
1640
1641
1642         /* Creation of top_button_form */
1643         top_button_form = XtVaCreateManagedWidget( "top_button_form",
1644                         xmFormWidgetClass,
1645                         icon_selection_dialog,
1646                         XmNresizePolicy, XmRESIZE_NONE,
1647                         XmNx, 10,
1648                         XmNy, 290,
1649                         XmNbottomOffset, 10,
1650                         XmNbottomWidget, use_icon_name_field ? icon_name_textfield_label : separatorGadget1,
1651                         XmNbottomAttachment, XmATTACH_WIDGET,
1652                         XmNrightOffset, 1,
1653                         XmNrightAttachment, XmATTACH_FORM,
1654                         XmNleftOffset, 1,
1655                         XmNleftAttachment, XmATTACH_FORM,
1656                         NULL );
1657         UxPutContext( top_button_form, (char *) UxIcon_selection_dialogContext );
1658
1659         UxTmp0 = top_button_one_label ? (char *)top_button_one_label : "No_Label";
1660
1661         /* Creation of top_button1 */
1662         top_button1 = XtVaCreateManagedWidget( "top_button1",
1663                         xmPushButtonWidgetClass,
1664                         top_button_form,
1665                         XmNx, 40,
1666                         XmNy, 0,
1667                         XmNleftOffset, 0,
1668                         XmNbottomAttachment, XmATTACH_FORM,
1669                         XmNleftAttachment, XmATTACH_POSITION,
1670                         XmNtopOffset, 0,
1671                         XmNleftPosition, get_top_b1_position (numberOfTopButtons),
1672                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1673                         NULL );
1674         XtAddCallback( top_button1, XmNactivateCallback,
1675                 (XtCallbackProc) top_button_one_cb,
1676                 (XtPointer) UxIcon_selection_dialogContext );
1677
1678         UxPutContext( top_button1, (char *) UxIcon_selection_dialogContext );
1679
1680         UxTmp0 = top_button_two_label ? (char *)top_button_two_label : "No_Label";
1681
1682         /* Creation of top_button2 */
1683         top_button2 = XtVaCreateManagedWidget( "top_button2",
1684                         xmPushButtonWidgetClass,
1685                         top_button_form,
1686                         XmNx, 220,
1687                         XmNy, 0,
1688                         XmNleftOffset, 0,
1689                         XmNtopOffset, 0,
1690                         XmNleftPosition, get_top_b2_position (numberOfTopButtons),
1691                         XmNbottomAttachment, XmATTACH_FORM,
1692                         XmNleftAttachment, XmATTACH_POSITION,
1693                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1694                         NULL );
1695         XtAddCallback( top_button2, XmNactivateCallback,
1696                 (XtCallbackProc) top_button_two_cb,
1697                 (XtPointer) UxIcon_selection_dialogContext );
1698
1699         UxPutContext( top_button2, (char *) UxIcon_selection_dialogContext );
1700
1701         UxTmp0 = top_button_three_label ? (char *)top_button_three_label : "No_Label";
1702
1703         /* Creation of top_button3 */
1704         top_button3 = XtVaCreateManagedWidget( "top_button3",
1705                         xmPushButtonWidgetClass,
1706                         top_button_form,
1707                         XmNx, 310,
1708                         XmNy, 0,
1709                         RES_CONVERT( XmNlabelString, UxTmp0 ),
1710                         XmNleftPosition, 72,
1711                         XmNleftOffset, 1,
1712                         XmNleftAttachment, XmATTACH_POSITION,
1713                         XmNbottomOffset, 0,
1714                         XmNbottomAttachment, XmATTACH_FORM,
1715                         NULL );
1716         XtAddCallback( top_button3, XmNactivateCallback,
1717                 (XtCallbackProc) top_button_three_cb,
1718                 (XtPointer) UxIcon_selection_dialogContext );
1719
1720         UxPutContext( top_button3, (char *) UxIcon_selection_dialogContext );
1721
1722         UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1723
1724         /* Creation of dir_scrolled_list */
1725         XtSetArg(args[i], XmNshadowThickness, 2); i++;
1726         XtSetArg(args[i], XmNlistSizePolicy, XmCONSTANT); i++;
1727
1728         XtSetArg(args[i], XmNleftOffset, 10); i++;
1729         XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1730         XtSetArg(args[i], XmNtopOffset, 0); i++;
1731         XtSetArg(args[i], XmNtopWidget, directory_list_label); i++;
1732         XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1733         XtSetArg(args[i], XmNrightOffset, 20); i++;
1734         XtSetArg(args[i], XmNrightWidget, icon_container_label); i++;
1735         XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
1736
1737         XtSetArg(args[i], XmNbottomOffset, 10); i++;
1738         if (numberOfTopButtons > 0) {
1739            XtSetArg(args[i], XmNbottomWidget, top_button_form); i++;
1740         } else if (use_icon_name_field) {
1741            XtSetArg(args[i], XmNbottomWidget, icon_name_textfield_label); i++;
1742         } else {
1743            XtSetArg(args[i], XmNbottomWidget, separatorGadget1); i++;
1744         }
1745         XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
1746
1747         dir_scrolled_list = XmCreateScrolledList(icon_selection_dialog,
1748                                                 "dir_scrolled_list",
1749                                                 args,
1750                                                 i);
1751         XtVaSetValues(dir_scrolled_list,
1752                         XmNselectionPolicy, XmBROWSE_SELECT,
1753                         XmNvisibleItemCount, 15,
1754                         NULL );
1755         XtManageChild(dir_scrolled_list);
1756
1757         UxPutContext( dir_scrolled_list, (char *) UxIcon_selection_dialogContext );
1758         calc_bottom_attachment (dir_scrolled_list,
1759                                (XtPointer) UxIcon_selection_dialogContext,
1760                                (XtPointer) NULL);
1761         XtAddCallback( dir_scrolled_list, XmNdefaultActionCallback,
1762                 (XtCallbackProc) defaultActionCB_dir_scrolled_list,
1763                 (XtPointer) UxIcon_selection_dialogContext );
1764
1765         UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1766
1767         /* Creation of icon_scrolled_win */
1768         icon_scrolled_win = XtVaCreateManagedWidget( "icon_scrolled_win",
1769                         xmScrolledWindowWidgetClass,
1770                         icon_selection_dialog,
1771                         XmNscrollingPolicy, XmAUTOMATIC,
1772 /*                      XmNnavigationType, XmTAB_GROUP, */
1773                         XmNx, 282,
1774                         XmNy, 84,
1775                         XmNscrollBarDisplayPolicy, XmAS_NEEDED,
1776                         XmNrightOffset, 10,
1777                         XmNrightAttachment, XmATTACH_FORM,
1778                         XmNtopOffset, 0,
1779                         XmNtopWidget, icon_container_label,
1780                         XmNtopAttachment, XmATTACH_WIDGET,
1781                         XmNleftOffset, 0,
1782                         XmNleftWidget, icon_container_label,
1783                         XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1784                         XmNbottomOffset, 10,
1785                         XmNbottomWidget, None,
1786                         XmNbottomAttachment, XmATTACH_WIDGET,
1787                         NULL );
1788
1789
1790
1791
1792         UxPutContext( icon_scrolled_win, (char *) UxIcon_selection_dialogContext );
1793         calc_bottom_attachment (icon_scrolled_win,
1794                                (XtPointer) UxIcon_selection_dialogContext,
1795                                (XtPointer) NULL);
1796
1797         /* Creation of icon_scrolled_container */
1798         icon_scrolled_container = XtVaCreateManagedWidget( "icon_scrolled_container",
1799                         xmRowColumnWidgetClass,
1800                         icon_scrolled_win,
1801                         XmNnavigationType, XmTAB_GROUP,
1802                       /*XmNborderWidth, 1,*/
1803                       /*XmNnumColumns, 2,*/
1804                         XmNnumColumns, 1,
1805                         XmNorientation, XmVERTICAL,
1806                         XmNpacking, XmPACK_COLUMN,
1807                         XmNshadowThickness, 1,
1808                         NULL );
1809
1810         XtVaSetValues(icon_selection_dialog,
1811                         XmNcancelButton, bottom_button2,
1812                         NULL );
1813
1814         XtAddCallback( icon_selection_dialog, XmNdestroyCallback,
1815                       (XtCallbackProc) UxDestroyContextCB,
1816                       (XtPointer) UxIcon_selection_dialogContext);
1817
1818         XtVaGetValues (icon_scrolled_win, XmNclipWindow, &widclipWindow, NULL);
1819         XtAddCallback( widclipWindow, XmNresizeCallback,
1820                 (XtCallbackProc) resizeCB_clipWindow,
1821                 (XtPointer) icon_scrolled_container );
1822
1823         return ( icon_selection_dialog );
1824 }
1825
1826 /*******************************************************************************
1827        The following is the 'Interface function' which is the
1828        external entry point for creating this interface.
1829        This function should be called from your application or from
1830        a callback function.
1831 *******************************************************************************/
1832
1833 Widget  create_icon_selection_dialog(swidget    _UxUxParent,
1834         unsigned char   *_Uxdialog_title,
1835         unsigned char   *_Uxfilter_field_title,
1836         int     _Uxuse_filter_field,
1837         unsigned char   *_Uxfile_filter,
1838         unsigned char   *_Uxdirectory_title,
1839         unsigned char   **_Uxdirectories_list,
1840         unsigned char   *_Uxcontainer_title,
1841         int     _UxnumberOfTopButtons,
1842         unsigned char   *_Uxtop_button_one_label,
1843         void    (*_Uxtop_button_one_cb)(),
1844         unsigned char   *_Uxtop_button_two_label,
1845         void    (*_Uxtop_button_two_cb)(),
1846         unsigned char   *_Uxtop_button_three_label,
1847         void    (*_Uxtop_button_three_cb)(),
1848         int     _Uxuse_icon_name_field,
1849         unsigned char   *_Uxname_field_title,
1850         int     _UxnumberOfBottomButtons,
1851         unsigned char   *_Uxbottom_button_one_label,
1852         void    (*_Uxbottom_button_one_cb)(),
1853         unsigned char   *_Uxbottom_button_two_label,
1854         void    (*_Uxbottom_button_two_cb)(),
1855         unsigned char   *_Uxbottom_button_three_label,
1856         void    (*_Uxbottom_button_three_cb)(),
1857         unsigned char   *_Uxbottom_button_four_label,
1858         void    (*_Uxbottom_button_four_cb)() )
1859
1860
1861 {
1862         char                   *initial_filter;
1863         char                   *icon_file_name;
1864         Widget                  rtrn;
1865         int                     lcv;
1866         _UxCicon_selection_dialog *UxContext;
1867
1868         UxIcon_selection_dialogContext = UxContext =
1869                 (_UxCicon_selection_dialog *) UxNewContext( sizeof(_UxCicon_selection_dialog), False );
1870
1871         UxParent = _UxUxParent;
1872         dialog_title = _Uxdialog_title;
1873         filter_field_title = _Uxfilter_field_title;
1874         use_filter_field = _Uxuse_filter_field;
1875         file_filter = _Uxfile_filter;
1876         directory_title = _Uxdirectory_title;
1877         directories_list = _Uxdirectories_list;
1878         container_title = _Uxcontainer_title;
1879         numberOfTopButtons = _UxnumberOfTopButtons;
1880         top_button_one_label = _Uxtop_button_one_label;
1881         top_button_one_cb = _Uxtop_button_one_cb;
1882         top_button_two_label = _Uxtop_button_two_label;
1883         top_button_two_cb = _Uxtop_button_two_cb;
1884         top_button_three_label = _Uxtop_button_three_label;
1885         top_button_three_cb = _Uxtop_button_three_cb;
1886         use_icon_name_field = _Uxuse_icon_name_field;
1887         name_field_title = _Uxname_field_title;
1888         numberOfBottomButtons = _UxnumberOfBottomButtons;
1889         bottom_button_one_label = _Uxbottom_button_one_label;
1890         bottom_button_one_cb = _Uxbottom_button_one_cb;
1891         bottom_button_two_label = _Uxbottom_button_two_label;
1892         bottom_button_two_cb = _Uxbottom_button_two_cb;
1893         bottom_button_three_label = _Uxbottom_button_three_label;
1894         bottom_button_three_cb = _Uxbottom_button_three_cb;
1895         bottom_button_four_label = _Uxbottom_button_four_label;
1896         bottom_button_four_cb = _Uxbottom_button_four_cb;
1897
1898         rtrn = _Uxbuild_icon_selection_dialog();
1899
1900         switch (numberOfTopButtons){
1901                 case 0 : XtUnmanageChild (top_button_form); break;
1902                 case 1 : XtUnmanageChild (top_button2);
1903                 case 2 : XtUnmanageChild (top_button3);
1904         };
1905
1906         if (numberOfBottomButtons == 3)
1907            XtUnmanageChild (bottom_button4);
1908
1909         if (!use_filter_field) {
1910            XtUnmanageChild (filter_textfield_label);
1911            XtUnmanageChild (filter_text_field);
1912         }
1913
1914         if (!use_icon_name_field) {
1915            XtUnmanageChild (icon_name_textfield_label);
1916            XtUnmanageChild (icon_name_text_field);
1917         }
1918
1919         TurnOnHourGlassAllWindows();
1920
1921         /******************************************************************/
1922         /* save file_filter */
1923         /******************************************************************/
1924         file_filter_global = (char *)calloc(strlen((char *)file_filter)+1, sizeof(char));
1925
1926 #ifdef DEBUG
1927         if (!file_filter_global) printf("Calloc error for file_filter_global, in create_icon_selection_dialog.\n");
1928 #endif
1929
1930         if (file_filter[0] == '*')
1931            file_filter_global = strcpy(file_filter_global, (char *)&file_filter[1]);
1932         else
1933            file_filter_global = strcpy(file_filter_global, (char *)file_filter);
1934
1935         load_directories_list ((char **)directories_list);
1936         initial_filter = initialize_filter ((char *)file_filter);
1937
1938         /******************************************************************/
1939         /* save main_filter */
1940         /******************************************************************/
1941         main_filter = (char *)calloc(strlen(initial_filter)+1, sizeof(char));
1942
1943 #ifdef DEBUG
1944         if (!main_filter) printf("Calloc error for main_filter, in create_icon_selection_dialog.\n");
1945 #endif
1946
1947         main_filter = strcpy(main_filter, initial_filter);;
1948
1949         icons_in_container = NULL;
1950         icon_count = 0;
1951
1952         update_container_contents (initial_filter);
1953
1954         /******************************************************************/
1955         /* set selected_icon_name to first name in list                   */
1956         /******************************************************************/
1957 #if 0
1958         if (icons_in_container) {
1959            XtVaGetValues (icons_in_container[0], XmNimageName, &icon_file_name, NULL);
1960            XmTextFieldSetString (icon_name_text_field, icon_file_name);
1961            selected_icon_name = XtMalloc(strlen(icon_file_name) + 1);
1962            if (selected_icon_name)
1963               selected_icon_name = strcpy(selected_icon_name, icon_file_name);
1964         }
1965 #endif
1966
1967         load_filter_text_field (initial_filter);
1968
1969         TurnOffHourGlassAllWindows();
1970
1971         return(rtrn);
1972 }