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