2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: icon_selection_dialog.c /main/10 1996/10/15 13:39:13 rswiston $ */
24 /*******************************************************************************
25 icon_selection_dialog.c
27 Associated Header file: icon_selection_dialog.h
28 *******************************************************************************/
35 #if defined(USL) || defined(__uxp__)
36 #define S_ISLNK(mode) ((mode & S_IFMT) == S_IFLNK)
40 #include <Xm/MwmUtil.h>
41 #include <Xm/DialogS.h>
42 #include <Xm/MenuShell.h>
44 #include <Xm/ScrolledW.h>
48 #include <Xm/SeparatoG.h>
51 #include <Xm/RowColumn.h>
52 #include <Xm/MessageB.h>
53 #include <Xm/XmPrivate.h> /* XmeFlushIconFileCache */
54 #include <X11/cursorfont.h>
64 #include "ErrorDialog.h"
66 /*******************************************************************************
67 Includes, Defines, and Global variables from the Declarations Editor:
68 *******************************************************************************/
70 #include <sys/types.h> /* for directory routines */
74 #include <dirent.h> /* includes sys/dir.h */
76 #include <Xm/ScrolledW.h>
78 /*#include "Container.h"*/
80 static char *selected_icon_name = (char *)NULL;
81 static Widget selected_icon = (Widget)NULL;
82 static int icon_count = 0;
84 char *file_filter_global;
85 DtIconGadget **icons_in_container = NULL;
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);
109 /*******************************************************************************
110 The following header file defines the context structure.
111 *******************************************************************************/
113 #define CONTEXT_MACRO_ACCESS 1
114 #include "icon_selection_dialog.h"
115 #undef CONTEXT_MACRO_ACCESS
118 /*******************************************************************************
119 Auxiliary code from the Declarations Editor:
120 *******************************************************************************/
122 /*********************************************************************/
123 /* auxfuncs - icon selection dialog auxiliary functions */
124 /*********************************************************************/
126 /***************************************************************************/
130 /***************************************************************************/
131 int myscandir(char *pszDirName, struct dirent ***NameList, int Select(), int Compare())
136 struct dirent *dptmp;
139 struct dirent **adirent;
140 #define AINCREMENT ((int)512)
141 int sizeArray = AINCREMENT;
142 char *msgPtr, *fmtPtr, *errPtr;
144 if (!(dirptr = opendir(pszDirName))) {
145 /* INTERNATIONALIZE */
146 msgPtr = "Could not open the following directory:";
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);
157 size = sizeof(void *) * 1024;
158 *NameList = (struct dirent **)malloc(sizeof(void *) * 1024);
161 adirent = (struct dirent **)malloc(sizeof(void *) * sizeArray);
162 for (dp = readdir(dirptr); dp != NULL; dp = readdir(dirptr)) {
165 if ((*Select)(dp, pszDirName)) {
166 (*NameList)[count] = dp;
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;
176 if (count == (sizeArray - 1)) {
177 adirent = (struct dirent **)realloc(adirent, (sizeof(void *) * (sizeArray + AINCREMENT)));
179 sizeArray += AINCREMENT;
190 /***************************************************************************/
192 /* build_dirent_list - builds a list of icon files to be displayed */
194 /* Input: char *filter - directory in which to search for files */
195 /* Output: struct dirent **namelist - list of files */
197 /***************************************************************************/
198 struct dirent **build_dirent_list (char *filter, int *filecount)
201 char *dirname, *dirname_end;
203 struct dirent **namelist;
204 char *msgPtr, *fmtPtr, *errPtr;
206 /********************************************************************/
207 /* initialize filecount and namelist */
208 /********************************************************************/
212 /********************************************************************/
213 /* get length of file filter and create a copy */
214 /********************************************************************/
215 dirname = (char *)calloc (strlen(filter)+1, sizeof(char));
219 printf("error callocing memory for dirname\n");
220 printf("dirname of size: %i\n", strlen(dirname));
224 dirname = strcpy (dirname, filter);
226 /********************************************************************/
227 /* strip wildcard from end of directory name */
228 /********************************************************************/
229 dirname_end = strrchr (dirname, '/');
230 dirname_end[1] = '\0';
232 /********************************************************************/
233 /* build list of file name that match the wildcard string */
234 /********************************************************************/
235 dirptr = (DIR *)opendir (dirname);
239 *filecount = myscandir (dirname, &namelist, new_name_select, NULL);
242 printf("# of icons = %d\n", *filecount);
246 /* INTERNATIONALIZE */
247 msgPtr = "Could not open the following directory:";
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);
258 printf ("Freeing dirname, sizeof: %ld\n", (long)sizeof(dirname));
265 /***************************************************************************/
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 */
272 /***************************************************************************/
273 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
275 struct stat stat_buffer;
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)) ) {
294 /***********************************************************************/
295 /* This is the new filter to get all three sizes of icons. */
296 /***********************************************************************/
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)) ) {
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)) ) {
328 /***************************************************************************/
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 */
335 /***************************************************************************/
336 int new_name_select (struct dirent *dir_entry, char *pszdir_name)
338 struct stat stat_buffer;
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)) ) {
354 /***************************************************************************/
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 */
360 /***************************************************************************/
361 int get_top_b1_position (int buttoncount)
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;
375 /***************************************************************************/
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 */
381 /***************************************************************************/
382 int get_top_b2_position (int buttoncount)
386 switch (buttoncount) {
387 case 2: position = 60; break;
388 case 3: position = 40; break;
389 default : position = 0;
395 /***************************************************************************/
397 /* void load_directories_list - load scrolled list with directory */
399 /* Input: char **dirlist - list of text strings */
402 /***************************************************************************/
403 void load_directories_list (char **dirlist)
405 XmStringTable xmstringlist;
409 /******************************************************************/
410 /* get number of directories in list */
411 /******************************************************************/
412 stringcount = countItems (dirlist);
414 /******************************************************************/
415 /* convert strings to xmstrings */
416 /******************************************************************/
417 xmstringlist = (XmStringTable) TextStringsToXmStrings (dirlist);
419 /******************************************************************/
420 /* put xmstrings in list */
421 /******************************************************************/
422 XtVaSetValues (dir_scrolled_list, XmNitems, xmstringlist,
423 XmNitemCount, stringcount, NULL);
425 XmListSelectPos(dir_scrolled_list, 1, False);
426 /******************************************************************/
427 /* free xmstrings array */
428 /******************************************************************/
429 for (i=0; i < stringcount; i++) {
430 XmStringFree(xmstringlist[i]);
437 /***************************************************************************/
439 /* void initialize_filter - build path/wildcard filter */
441 /* Output: char *initial_filter */
443 /***************************************************************************/
444 char *initialize_filter (char *filter_end)
446 char *filter, *initial_filter;
447 int filter_length, filter_end_length;
450 /******************************************************************/
451 /* initial filter string is first directory in list */
452 /******************************************************************/
453 filter = get_initial_filter ();
455 /******************************************************************/
456 /* determine space needed */
457 /******************************************************************/
458 filter_length = strlen(filter);
459 if ((filter[filter_length-1] == '/') && (filter_end[0] == '/')) {
462 if (!(filter[filter_length-1] == '/') && !(filter_end[0] == '/')) {
468 filter_end_length = strlen(filter_end);
470 /******************************************************************/
471 /* allocate space and put string in initial filter */
472 /******************************************************************/
473 initial_filter = (char *)calloc (filter_length + filter_end_length + 1,
476 if (!initial_filter) printf("Error callocing memory in initialize_filter.\n");
478 initial_filter = strcpy (initial_filter, filter);
479 if (add_slash) initial_filter[filter_length-1] = '/';
480 initial_filter = strcat (initial_filter, filter_end);
482 return(initial_filter);
485 /***************************************************************************/
487 /* char *get_initial_filter - get value of first file filter */
489 /* Output: char *new_filter - string containing filter */
491 /***************************************************************************/
492 char *get_initial_filter (void)
496 /******************************************************************/
497 /* initial filter is first one in directory list */
498 /******************************************************************/
499 new_filter = (char *)directories_list[0];
503 /***************************************************************************/
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 */
509 /***************************************************************************/
510 char *update_filter (char *filter)
512 char *filter_end, *new_filter, *main_end;
513 char *fe_ptr, *ffg_ptr;
515 /******************************************************************/
517 /******************************************************************/
518 main_end = strrchr (main_filter, '/');
519 filter_end = (char *)calloc(strlen(main_end)+1, sizeof(char));
523 printf("Error callocing memory for filter_end in update_filter.\n");
526 filter_end = strcpy (filter_end, main_end);
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);
534 if ((int)strlen(fe_ptr) >= (int)strlen(PIXMAP_EXT)) {
535 strcpy(fe_ptr, PIXMAP_EXT);
537 if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(PIXMAP_EXT)) ) {
538 strcpy(ffg_ptr, PIXMAP_EXT);
541 if ((int)strlen(fe_ptr) >= (int)strlen(BITMAP_EXT)) {
542 strcpy(fe_ptr, BITMAP_EXT);
544 if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(BITMAP_EXT)) ) {
545 strcpy(ffg_ptr, BITMAP_EXT);
550 /******************************************************************/
551 /* find old end on main filter and delete it */
552 /******************************************************************/
553 main_end = memset (main_end, '\0', strlen(main_end));
555 /******************************************************************/
556 /* allocate space for new filter */
557 /******************************************************************/
558 new_filter = (char *)calloc (strlen(filter) +
559 strlen(filter_end) + 1, sizeof(char));
562 printf("Error callocing memory for new_filter in update_filter.\n");
565 new_filter = strcpy (new_filter, filter);
567 /******************************************************************/
568 /* put new end on filter */
569 /******************************************************************/
570 new_filter = strcat (new_filter, filter_end);
572 /******************************************************************/
573 /* display new file filter in text field */
574 /******************************************************************/
575 load_filter_text_field (new_filter);
577 /******************************************************************/
579 /******************************************************************/
585 /***************************************************************************/
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 */
592 /***************************************************************************/
593 void apply_filter (char *filter)
597 /******************************************************************/
598 /* Get length of main file filter and create a copy */
599 /******************************************************************/
600 old_main = (char *)calloc (strlen(main_filter)+1, sizeof(char));
603 if (!old_main) printf("Calloc error for old_main, in apply filter.\n");
606 old_main = strcpy (old_main, main_filter);
608 /******************************************************************/
609 /* Update main filter to reflect changes made by user */
610 /******************************************************************/
611 main_filter = update_filter (filter);
613 /******************************************************************/
614 /* if the filter has changed, update container with new icons */
615 /******************************************************************/
616 if (strcmp (old_main, main_filter)) {
618 /******************************************************************/
619 /* Turn on the hour glass */
620 /******************************************************************/
621 TurnOnHourGlassAllWindows();
623 /******************************************************************/
624 /* Since we are changing to a new directory, clear out the */
625 /* globals and clear the selected icon text string. */
626 /******************************************************************/
628 _DtIconSetState(selected_icon, FALSE, FALSE);
629 selected_icon = (Widget)NULL;
631 if (selected_icon_name) {
632 XtFree(selected_icon_name);
633 selected_icon_name = (char *)NULL;
635 XmTextFieldSetString (icon_name_text_field, "");
637 /******************************************************************/
638 /* Update the container icon gadgets */
639 /******************************************************************/
640 update_container_contents (main_filter);
642 /******************************************************************/
643 /* Turn off the hour glass */
644 /******************************************************************/
645 TurnOffHourGlassAllWindows();
649 printf ("Freeing old_main, sizeof: %ld\n", (long)sizeof(old_main));
657 /***************************************************************************/
659 /* void load_filter_text_field - display file filter text */
660 /* Input: char *filter - file filter text string */
663 /***************************************************************************/
664 void load_filter_text_field (char *filter)
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));
676 /***************************************************************************/
678 /* void update_container_contents - create new icon gadgets which */
679 /* correspont to the new filter */
680 /* Input: char *filter - file filter text string */
683 /***************************************************************************/
684 void update_container_contents (char *filter)
686 char *path, *pathend;
687 char iconfile[MAXFILENAME];
689 struct dirent **filelist;
690 int count, old_count;
696 XtUnmanageChild (icon_scrolled_container);
697 /* free_container_contents (); */
699 path = (char *)calloc (strlen(filter)+1, sizeof(char));
702 if (!path) printf("Calloc error for path, in update_container_contents.\n");
705 path = strcpy (path, filter);
706 pathend = strrchr (path, '/');
709 /******************************************************************/
710 /* Get number of icon files and list of file names */
711 /******************************************************************/
712 filelist = build_dirent_list (filter, &namecount);
714 /******************************************************************/
715 /* Set up argument list */
716 /******************************************************************/
719 XtSetArg(args[n], XmNimageName, "/usr/dt/appconfig/icons/C/Dtactn.m.pm"); n++;
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++;
728 /******************************************************************/
729 /* Need at least one icon for the empty directory icon. */
730 /******************************************************************/
737 /******************************************************************/
738 /* create any additional icon gadgets */
739 /******************************************************************/
740 if (count > icon_count) {
741 old_count = icon_count;
743 icons_in_container = (DtIconGadget **)realloc
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,
753 XtAddCallback((Widget) icons_in_container[lcv], XmNcallback,
754 (XtCallbackProc) selectionCB_icon_scrolled_container,
758 if (!icons_in_container[lcv])
759 printf("Error creating icon gadget, in update_container_contents\n");
763 if (!icons_in_container[lcv]) {
764 printf ("Could not allocate memory to create new icon\n", lcv);
770 printf ("Created icon #%i\n", lcv);
775 } /* end if (count > icon_count) */
777 /******************************************************************/
778 /* load icon gadgets with information */
779 /******************************************************************/
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);
792 for (lcv = 0; lcv < count; lcv++) {
793 snprintf(iconfile, sizeof(iconfile), "%s%s", path, filelist[lcv]->d_name);
794 ptr = strstr(filelist[lcv]->d_name, ".m.");
798 xmstring = XmStringCreateLocalized(filelist[lcv]->d_name);
799 XtVaSetValues ((Widget) icons_in_container[lcv],
801 XmNimageName, iconfile,
803 XtManageChild((Widget) icons_in_container [lcv]);
804 XmStringFree(xmstring);
807 printf ("Loading icon gadget #%i\n", lcv);
812 /******************************************************************/
813 /* This is the empty directory case */
814 /******************************************************************/
816 snprintf(iconfile, sizeof(iconfile), "%s", GETMESSAGE(11, 60, "[Empty]"));
817 xmstring = XmStringCreateLocalized(iconfile);
818 XtVaSetValues ((Widget) icons_in_container[0],
820 XmNimageName, (char *)NULL,
822 XtManageChild((Widget) icons_in_container[0]);
823 XmStringFree(xmstring);
826 /******************************************************************/
827 /* unmanage any spare icon gadgets */
828 /******************************************************************/
829 for (lcv = count; lcv < icon_count; lcv++) {
830 XtUnmanageChild ((Widget) icons_in_container[lcv]);
833 /******************************************************************/
834 /* free dirent list */
835 /******************************************************************/
836 for (lcv = 0; lcv < namecount; lcv++) {
837 free (filelist[lcv]);
843 XtManageChild (icon_scrolled_container);
849 #ifdef _ICONSELECTOR_DESTROY_ENABLED
850 /***************************************************************************/
852 /* void free_container_contents - free icon gadgets in container */
856 /***************************************************************************/
857 void free_container_contents (void)
864 if (icons_in_container) {
865 screen_id = XtScreen (icons_in_container[0]);
867 while (icons_in_container[lcv]) {
869 XtVaGetValues (icons_in_container[lcv], XmNimageName, &filename,
870 XmNpixmap, &icon_pixmap, NULL);
871 XmDestroyPixmap (screen_id, icon_pixmap);
873 XtVaSetValues (icons_in_container[lcv], XmNpixmap, NULL, NULL);
875 XtDestroyWidget (icons_in_container[lcv]);
877 icons_in_container[lcv]=NULL;
880 } /* end while icons_in_container */
881 free (icons_in_container);
882 icons_in_container = NULL;
886 printf ("In free_container_contents...\n");
887 printf ("Just destroyed all %i icons.\n", lcv);
897 /***************************************************************************/
899 /* void load_new_filter - displays selected directory string as */
900 /* new filter base */
901 /* Input: char *new_filter - new directory string to use as filter */
904 /***************************************************************************/
905 void load_new_filter (char *new_filter)
907 /* no longer need old filter */
910 /* create space for new filter */
911 main_filter = (char *)calloc (strlen(new_filter)+3, sizeof (char));
913 if (!main_filter) printf("Calloc error for main_filter, in load_new_filter.\n");
915 /* copy new filter and add filter end */
916 main_filter = strcpy (main_filter, new_filter);
917 main_filter = strcat (main_filter, "/*");
918 /* display new filter */
919 load_filter_text_field (main_filter);
925 /*****************************************************************************/
926 /* The following are callback functions. */
927 /*****************************************************************************/
929 /***************************************************************************/
931 /* calc_bottom_attachment */
934 /***************************************************************************/
935 static void calc_bottom_attachment( Widget UxWidget,
936 XtPointer UxClientData,
937 XtPointer UxCallbackArg )
939 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
941 UxSaveCtx = UxIcon_selection_dialogContext;
942 UxIcon_selection_dialogContext = UxContext =
943 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
945 if (numberOfTopButtons > 0) {
946 XtVaSetValues (UxWidget, XmNbottomWidget, top_button_form, NULL);
947 } else if (use_icon_name_field) {
948 XtVaSetValues (UxWidget, XmNbottomWidget, icon_name_textfield_label, NULL);
949 } else XtVaSetValues (UxWidget, XmNbottomWidget, separatorGadget1, NULL);
954 /***************************************************************************/
956 /* activateCB_bottom_button */
959 /***************************************************************************/
960 /* default cb for bottom buttons */
961 static void activateCB_bottom_button( Widget UxWidget,
962 XtPointer UxClientData,
963 XtPointer UxCallbackArg )
965 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
967 UxSaveCtx = UxIcon_selection_dialogContext;
968 UxIcon_selection_dialogContext = UxContext =
969 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
975 /******************************************************************************/
976 /* activateCB_NoFindIconDialog_ChangeNameButton */
977 /******************************************************************************/
978 void activateCB_NoFindIconDialog_ChangeNameButton( Widget UxWidget,
979 XtPointer UxClientData,
980 XtPointer UxCallbackArg)
983 XtDestroyWidget(UxWidget);
986 /******************************************************************************/
987 /* activateCB_NoFindIconDialog_NameOKButton */
988 /******************************************************************************/
989 void activateCB_NoFindIconDialog_NameOKButton( Widget UxWidget,
990 XtPointer UxClientData,
991 XtPointer UxCallbackArg)
994 char *basename = (char *)NULL;
996 TurnOnHourGlassAllWindows();
997 if (bottom_button_one_cb) {
998 GetWidgetTextString(icon_name_text_field, &basename);
999 bottom_button_one_cb(UxWidget,
1000 (XtPointer)basename, UxCallbackArg);
1001 if (basename) XtFree(basename);
1003 TurnOffHourGlassAllWindows();
1004 UxPopdownInterface (IconSelector);
1005 XtDestroyWidget(UxWidget);
1008 /******************************************************************************/
1009 /* display_nofindicon_message - display cant find icons error dialog */
1010 /* INPUT: Widget parent - parent to position error dialog new */
1012 /******************************************************************************/
1013 void display_nofindicon_message (Widget parent)
1019 dialog = XmCreateErrorDialog(parent, "nofindiconDialog", NULL, 0);
1021 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
1022 XtVaSetValues(widChild,
1023 RES_CONVERT( XmNlabelString, "Change Name"),
1026 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
1027 XtVaSetValues(widChild,
1028 RES_CONVERT( XmNlabelString, "Name OK"),
1031 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
1033 XtAddCallback( dialog, XmNokCallback,
1034 (XtCallbackProc) activateCB_NoFindIconDialog_ChangeNameButton,
1036 XtAddCallback( dialog, XmNcancelCallback,
1037 (XtCallbackProc) activateCB_NoFindIconDialog_NameOKButton,
1040 /********* WARNING - this needs to be translated !!! ***********/
1041 strcpy(buffer, "There is no set of icons with that filename in the icon folders.\n");
1042 strcat(buffer, "Move the icons into one of the icon folders, then select \"Name OK\".\n");
1043 strcat(buffer, "Or, to select a different set of icons, select \"Change Name\".\n");
1044 strcat(buffer, "\nIf you are a software developer creating a registration package,\n");
1045 strcat(buffer, "ignore this message and select \"Name OK\".");
1046 XtVaSetValues (dialog,
1047 RES_CONVERT(XmNdialogTitle, GETMESSAGE(6, 31, "Create Action - Error")),
1048 RES_CONVERT(XmNmessageString, buffer),
1051 XtManageChild (dialog);
1055 /***************************************************************************/
1057 /* activateCB_bottom_button1 */
1060 /***************************************************************************/
1061 /* cb for bottom button 1 = OK */
1062 static void activateCB_bottom_button1( Widget UxWidget,
1063 XtPointer UxClientData,
1064 XtPointer UxCallbackArg )
1066 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1068 UxSaveCtx = UxIcon_selection_dialogContext;
1069 UxIcon_selection_dialogContext = UxContext =
1070 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1072 char *basename = (char *)NULL;
1073 char *fullname = (char *)NULL;
1074 char *msgPtr, *errPtr;
1076 GetWidgetTextString(icon_name_text_field, &basename);
1078 if (strchr(basename, '/')) {
1079 /**** WARNING - this needs to be in a message catalog in the future ****/
1080 /* INTERNATIONALIZE */
1081 msgPtr = "Invalid Icon filename.\n\
1082 Pathnames are not valid in the \"Enter Icon Filename\" field.\n\
1083 Enter only the name of the icon without the path or extensions.";
1084 errPtr = XtNewString(msgPtr);
1085 display_error_message(IconSelector, errPtr);
1088 FIND_ICONGADGET_ICON(basename, fullname, DtMEDIUM);
1089 if ( (fullname) && (check_file_exists(fullname)) ) {
1090 TurnOnHourGlassAllWindows();
1091 if (bottom_button_one_cb) {
1092 bottom_button_one_cb(UxWidget,
1093 (XtPointer)fullname, UxCallbackArg);
1095 TurnOffHourGlassAllWindows();
1096 UxPopdownInterface (IconSelector);
1097 if (basename) XtFree(basename);
1099 display_nofindicon_message(IconSelector);
1103 msgPtr = GETMESSAGE(11, 50, "The Icon Filename is invalid.\n\
1104 Please enter a valid icon file name in the\n'Enter Icon Filename' field.");
1105 errPtr = XtNewString(msgPtr);
1106 display_error_message(IconSelector, errPtr);
1112 #if 0 /************* old code *********************/
1113 char *pszIconFileName = (char *)NULL;
1114 char buffer[MAXBUFSIZE];
1116 GetWidgetTextString(icon_name_text_field, &pszIconFileName);
1117 if ( (pszIconFileName) && (check_file_exists(pszIconFileName)) ) {
1118 TurnOnHourGlassAllWindows();
1119 if (bottom_button_one_cb) {
1120 bottom_button_one_cb(UxWidget,
1121 (XtPointer)pszIconFileName, UxCallbackArg);
1123 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1124 free_container_contents ();
1125 if (selected_icon_name) {
1126 XtFree(selected_icon_name);
1128 selected_icon_name = (char *)NULL;
1129 XtDestroyWidget (XtParent(icon_selection_dialog));
1130 IconSelector = (Widget)NULL;
1131 TurnOffHourGlassAllWindows();
1133 TurnOffHourGlassAllWindows();
1134 UxPopdownInterface (IconSelector);
1135 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1136 XtFree(pszIconFileName);
1138 strcpy(buffer, GETMESSAGE(11, 50, "The Icon Filename is invalid.\nPlease enter a valid icon file name in the\n'Enter Icon Filename' field."));
1139 display_error_message(IconSelector, buffer);
1144 if (selected_icon_name) {
1145 TurnOnHourGlassAllWindows();
1146 if (bottom_button_one_cb) {
1147 bottom_button_one_cb(UxWidget,
1148 (XtPointer)selected_icon_name, UxCallbackArg);
1150 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1151 free_container_contents ();
1152 XtFree(selected_icon_name);
1153 selected_icon_name = (char *)NULL;
1154 XtDestroyWidget (XtParent(icon_selection_dialog));
1155 IconSelector = (Widget)NULL;
1156 TurnOffHourGlassAllWindows();
1158 TurnOffHourGlassAllWindows();
1159 UxPopdownInterface (IconSelector);
1160 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1165 #endif /************* old code *********************/
1169 /***************************************************************************/
1171 /* activateCB_bottom_button2 */
1174 /***************************************************************************/
1175 /* cb for bottom button 2 = CANCEL */
1176 static void activateCB_bottom_button2( Widget UxWidget,
1177 XtPointer UxClientData,
1178 XtPointer UxCallbackArg )
1180 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1182 UxSaveCtx = UxIcon_selection_dialogContext;
1183 UxIcon_selection_dialogContext = UxContext =
1184 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1186 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1187 free_container_contents ();
1188 XtDestroyWidget (XtParent(icon_selection_dialog));
1189 IconSelector = (Widget)NULL;
1191 UxPopdownInterface (IconSelector);
1192 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1197 /***************************************************************************/
1199 /* activateCB_bottom_button3 */
1202 /***************************************************************************/
1203 /* default cb for bottom button3 = HELP */
1204 static void activateCB_bottom_button3( Widget UxWidget,
1205 XtPointer UxClientData,
1206 XtPointer UxCallbackArg )
1208 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1210 UxSaveCtx = UxIcon_selection_dialogContext;
1211 UxIcon_selection_dialogContext = UxContext =
1212 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1214 DisplayHelpDialog(UxWidget, (XtPointer)HELP_ICONSELECTOR, UxCallbackArg);
1219 /***************************************************************************/
1221 /* activateCB_filter_text_field */
1224 /***************************************************************************/
1225 static void activateCB_filter_text_field( Widget UxWidget,
1226 XtPointer UxClientData,
1227 XtPointer UxCallbackArg )
1229 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1230 UxSaveCtx = UxIcon_selection_dialogContext;
1231 UxIcon_selection_dialogContext = UxContext =
1232 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1236 filter = XmTextFieldGetString (UxWidget);
1237 apply_filter (filter);
1239 UxIcon_selection_dialogContext = UxSaveCtx;
1242 /***************************************************************************/
1244 /* defaultActionCB_dir_scrolled_list */
1247 /***************************************************************************/
1248 static void defaultActionCB_dir_scrolled_list( Widget UxWidget,
1249 XtPointer UxClientData,
1250 XtPointer UxCallbackArg )
1252 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1254 UxSaveCtx = UxIcon_selection_dialogContext;
1255 UxIcon_selection_dialogContext = UxContext =
1256 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1258 XmListCallbackStruct *listcb;
1261 listcb = (XmListCallbackStruct *) UxCallbackArg;
1262 filter = (char *)XmStringToText (listcb->item);
1263 apply_filter (filter);
1264 /* XtManageChild (icon_scrolled_win); */
1267 UxIcon_selection_dialogContext = UxSaveCtx;
1270 /***************************************************************************/
1272 /* selectionCB_icon_scrolled_container */
1274 /***************************************************************************/
1275 static void selectionCB_icon_scrolled_container ( Widget UxWidget,
1276 XtPointer UxClientData,
1277 XtPointer UxCallbackArg )
1280 XmString xmbasename;
1283 XtVaGetValues (UxWidget, XmNimageName, &filename, NULL);
1285 printf("In icon callback for '%s'\n", filename);
1287 if (use_icon_name_field) {
1288 XtVaGetValues (UxWidget, XmNstring, &xmbasename, NULL);
1289 basename = XmStringToText(xmbasename);
1290 XmTextFieldSetString (icon_name_text_field, basename);
1291 if (basename) free(basename);
1293 if (selected_icon_name) {
1294 if (selected_icon != UxWidget) {
1295 _DtIconSetState(selected_icon, FALSE, FALSE);
1297 XtFree(selected_icon_name);
1298 selected_icon_name = (char *)NULL;
1301 selected_icon_name = XtMalloc(strlen(filename) + 1);
1302 selected_icon_name = strcpy(selected_icon_name, filename);
1304 selected_icon_name = (char *)NULL;
1306 selected_icon = UxWidget;
1311 /***************************************************************************/
1313 /* resizeCB_clipWindow */
1315 /***************************************************************************/
1316 void resizeCB_clipWindow( Widget UxWidget,
1317 XtPointer UxClientData,
1318 XtPointer UxCallbackArg )
1320 Widget widvScrollbar;
1321 Widget widRowColumn;
1323 XtArgVal /* Dimension */ height;
1325 XtVaGetValues(XtParent(UxWidget), XmNverticalScrollBar, &widvScrollbar, NULL);
1326 widRowColumn = (Widget)UxClientData;
1327 XtVaGetValues(widRowColumn, XmNheight, &height, NULL);
1330 printf("height = %d\n", height);
1331 printf("icon_count = %d\n", icon_count);
1334 increment = (int)height / icon_count;
1335 XtVaSetValues(widvScrollbar, XmNincrement, increment, NULL);
1341 /***************************************************************************/
1343 /* _Uxbuild_icon_selection_dialog */
1346 /***************************************************************************/
1347 static Widget _Uxbuild_icon_selection_dialog(void)
1352 int ntotalbuttons = numberOfBottomButtons;
1353 #define TIGHTNESS 20
1356 Widget widclipWindow;
1358 /* Creation of icon_selection_dialog */
1359 _UxParent = UxParent;
1360 if ( _UxParent == NULL )
1362 _UxParent = UxTopLevel;
1365 _UxParent = XtVaCreatePopupShell( "icon_selection_dialog_shell",
1366 xmDialogShellWidgetClass, _UxParent,
1371 XmNshellUnitType, XmPIXELS,
1372 XmNkeyboardFocusPolicy, XmEXPLICIT,
1373 XmNtitle, "icon_selection_dialog",
1376 UxTmp0 = dialog_title ? (char *)dialog_title : "Icon Selection Window";
1378 icon_selection_dialog = XtVaCreateWidget( "icon_selection_dialog",
1381 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1384 XmNunitType, XmPIXELS,
1385 RES_CONVERT( XmNdialogTitle, UxTmp0 ),
1386 XmNautoUnmanage, FALSE,
1387 XmNdefaultPosition, FALSE,
1389 UxPutContext( icon_selection_dialog, (char *) UxIcon_selection_dialogContext );
1391 /*******************************************************************/
1392 /* Set up help callback */
1393 /*******************************************************************/
1394 XtAddCallback( icon_selection_dialog, XmNhelpCallback,
1395 (XtCallbackProc) helpCB_general,
1396 (XtPointer) HELP_ICONSELECTOR );
1399 /* Creation of bottom_button_form */
1400 bottom_button_form = XtVaCreateManagedWidget( "bottom_button_form",
1402 icon_selection_dialog,
1403 XmNskipAdjust, TRUE,
1404 XmNfractionBase, ((TIGHTNESS * ntotalbuttons) - 1),
1407 XmNleftAttachment, XmATTACH_FORM,
1409 XmNrightAttachment, XmATTACH_FORM,
1410 XmNbottomOffset, 20,
1411 XmNbottomAttachment, XmATTACH_FORM,
1414 UxPutContext( bottom_button_form, (char *) UxIcon_selection_dialogContext );
1417 UxTmp0 = bottom_button_one_label ? (char *)bottom_button_one_label : GETMESSAGE(6, 10, "OK");
1419 /* Creation of bottom_button1 = OK */
1420 bottom_button1 = XtVaCreateManagedWidget( "bottom_button1",
1421 xmPushButtonWidgetClass,
1423 RES_CONVERT( XmNlabelString, UxTmp0 ),
1425 XmNleftAttachment, nbutton ?
1426 XmATTACH_POSITION : XmATTACH_FORM,
1427 XmNleftPosition, TIGHTNESS * nbutton,
1428 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1429 XmATTACH_POSITION : XmATTACH_FORM,
1430 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1434 XtAddCallback( bottom_button1, XmNactivateCallback,
1435 (XtCallbackProc) activateCB_bottom_button1,
1438 UxPutContext( bottom_button1, (char *) UxIcon_selection_dialogContext );
1440 UxTmp0 = bottom_button_two_label ? (char *)bottom_button_two_label : GETMESSAGE(6, 12, "Cancel");
1442 /* Creation of bottom_button2 = CANCEL */
1443 bottom_button2 = XtVaCreateManagedWidget( "bottom_button2",
1444 xmPushButtonWidgetClass,
1446 RES_CONVERT( XmNlabelString, UxTmp0 ),
1448 XmNleftAttachment, nbutton ?
1449 XmATTACH_POSITION : XmATTACH_FORM,
1450 XmNleftPosition, TIGHTNESS * nbutton,
1451 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1452 XmATTACH_POSITION : XmATTACH_FORM,
1453 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1457 XtAddCallback( bottom_button2, XmNactivateCallback,
1458 (XtCallbackProc) bottom_button_two_cb ?
1459 bottom_button_two_cb : activateCB_bottom_button2,
1460 (XtPointer) UxIcon_selection_dialogContext );
1462 UxPutContext( bottom_button2, (char *) UxIcon_selection_dialogContext );
1464 UxTmp0 = bottom_button_three_label ? (char *)bottom_button_three_label : GETMESSAGE(6, 13, "Help");
1466 /* Creation of bottom_button3 = HELP */
1467 bottom_button3 = XtVaCreateManagedWidget( "bottom_button3",
1468 xmPushButtonWidgetClass,
1470 RES_CONVERT( XmNlabelString, UxTmp0 ),
1471 XmNuserData, icon_selection_dialog,
1473 XmNleftAttachment, nbutton ?
1474 XmATTACH_POSITION : XmATTACH_FORM,
1475 XmNleftPosition, TIGHTNESS * nbutton,
1476 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1477 XmATTACH_POSITION : XmATTACH_FORM,
1478 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1482 XtAddCallback( bottom_button3, XmNactivateCallback,
1483 (XtCallbackProc) bottom_button_three_cb ?
1484 bottom_button_three_cb : activateCB_bottom_button3,
1485 (XtPointer) UxIcon_selection_dialogContext );
1487 UxPutContext( bottom_button3, (char *) UxIcon_selection_dialogContext );
1489 UxTmp0 = bottom_button_four_label ? (char *)bottom_button_four_label : GETMESSAGE(12, 10, "Filter");
1491 /* Creation of bottom_button4 */
1492 bottom_button4 = XtVaCreateManagedWidget( "bottom_button4",
1493 xmPushButtonWidgetClass,
1495 RES_CONVERT( XmNlabelString, UxTmp0 ),
1497 XmNleftAttachment, nbutton ?
1498 XmATTACH_POSITION : XmATTACH_FORM,
1499 XmNleftPosition, TIGHTNESS * nbutton,
1500 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1501 XmATTACH_POSITION : XmATTACH_FORM,
1502 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1506 XtAddCallback( bottom_button4, XmNactivateCallback,
1507 (XtCallbackProc) bottom_button_four_cb ?
1508 bottom_button_four_cb : activateCB_bottom_button,
1509 (XtPointer) UxIcon_selection_dialogContext );
1511 UxPutContext( bottom_button4, (char *) UxIcon_selection_dialogContext );
1514 /* Creation of separatorGadget1 */
1515 separatorGadget1 = XtVaCreateManagedWidget( "separatorGadget1",
1516 xmSeparatorGadgetClass,
1517 icon_selection_dialog,
1521 XmNrightAttachment, XmATTACH_FORM,
1523 XmNleftAttachment, XmATTACH_FORM,
1524 XmNbottomOffset, 10,
1525 XmNbottomWidget, bottom_button_form,
1526 XmNbottomAttachment, XmATTACH_WIDGET,
1528 UxPutContext( separatorGadget1, (char *) UxIcon_selection_dialogContext );
1531 /* Creation of icon_name_text_field */
1532 icon_name_text_field = XtVaCreateManagedWidget( "icon_name_text_field",
1533 xmTextFieldWidgetClass,
1534 icon_selection_dialog,
1537 XmNbottomOffset, 10,
1538 XmNbottomWidget, separatorGadget1,
1539 XmNbottomAttachment, XmATTACH_WIDGET,
1541 XmNrightAttachment, XmATTACH_FORM,
1543 XmNleftAttachment, XmATTACH_FORM,
1545 UxPutContext( icon_name_text_field, (char *) UxIcon_selection_dialogContext );
1546 ISD_SelectedIconTextField = icon_name_text_field;
1548 UxTmp0 = name_field_title ? (char *)name_field_title : GETMESSAGE(11, 12, "Enter Icon Filename");
1550 /* Creation of icon_name_textfield_label */
1551 icon_name_textfield_label = XtVaCreateManagedWidget( "icon_name_textfield_label",
1553 icon_selection_dialog,
1556 RES_CONVERT( XmNlabelString, UxTmp0 ),
1558 XmNbottomWidget, icon_name_text_field,
1559 XmNbottomAttachment, XmATTACH_WIDGET,
1561 XmNleftWidget, icon_name_text_field,
1562 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1563 XmNalignment, XmALIGNMENT_BEGINNING,
1565 UxPutContext( icon_name_textfield_label, (char *) UxIcon_selection_dialogContext );
1567 UxTmp0 = filter_field_title ? (char *)filter_field_title : GETMESSAGE(12, 10, "Filter");
1569 /* Creation of filter_textfield_label */
1570 filter_textfield_label = XtVaCreateManagedWidget( "filter_textfield_label",
1572 icon_selection_dialog,
1575 RES_CONVERT( XmNlabelString, UxTmp0 ),
1576 XmNalignment, XmALIGNMENT_BEGINNING,
1578 XmNtopAttachment, XmATTACH_FORM,
1580 XmNleftAttachment, XmATTACH_FORM,
1582 UxPutContext( filter_textfield_label, (char *) UxIcon_selection_dialogContext );
1585 /* Creation of filter_text_field */
1586 filter_text_field = XtVaCreateManagedWidget( "filter_text_field",
1587 xmTextFieldWidgetClass,
1588 icon_selection_dialog,
1592 XmNtopWidget, filter_textfield_label,
1593 XmNtopAttachment, XmATTACH_WIDGET,
1595 XmNrightAttachment, XmATTACH_FORM,
1597 XmNleftAttachment, XmATTACH_FORM,
1599 XtAddCallback( filter_text_field, XmNactivateCallback,
1600 (XtCallbackProc) activateCB_filter_text_field,
1601 (XtPointer) UxIcon_selection_dialogContext );
1603 UxPutContext( filter_text_field, (char *) UxIcon_selection_dialogContext );
1605 UxTmp0 = directory_title ? (char *)directory_title : GETMESSAGE(11, 30, "Icon Folders");
1607 /* Creation of directory_list_label */
1608 directory_list_label = XtVaCreateManagedWidget( "directory_list_label",
1610 icon_selection_dialog,
1613 XmNlabelType, XmSTRING,
1614 RES_CONVERT( XmNlabelString, UxTmp0 ),
1615 XmNalignment, XmALIGNMENT_BEGINNING,
1617 XmNtopWidget, filter_text_field,
1618 XmNtopAttachment, use_filter_field ? XmATTACH_WIDGET : XmATTACH_FORM,
1620 XmNleftAttachment, XmATTACH_FORM,
1622 UxPutContext( directory_list_label, (char *) UxIcon_selection_dialogContext );
1624 UxTmp0 = container_title ? (char *)container_title : GETMESSAGE(11, 11, "Icon Files");
1626 /* Creation of icon_container_label */
1627 icon_container_label = XtVaCreateManagedWidget( "icon_container_label",
1629 icon_selection_dialog,
1632 XmNlabelType, XmSTRING,
1633 RES_CONVERT( XmNlabelString, UxTmp0 ),
1634 XmNalignment, XmALIGNMENT_BEGINNING,
1636 XmNtopWidget, filter_text_field,
1637 XmNtopAttachment, XmATTACH_WIDGET,
1638 XmNleftAttachment, XmATTACH_POSITION,
1639 XmNleftPosition, 55,
1641 UxPutContext( icon_container_label, (char *) UxIcon_selection_dialogContext );
1644 /* Creation of top_button_form */
1645 top_button_form = XtVaCreateManagedWidget( "top_button_form",
1647 icon_selection_dialog,
1648 XmNresizePolicy, XmRESIZE_NONE,
1651 XmNbottomOffset, 10,
1652 XmNbottomWidget, use_icon_name_field ? icon_name_textfield_label : separatorGadget1,
1653 XmNbottomAttachment, XmATTACH_WIDGET,
1655 XmNrightAttachment, XmATTACH_FORM,
1657 XmNleftAttachment, XmATTACH_FORM,
1659 UxPutContext( top_button_form, (char *) UxIcon_selection_dialogContext );
1661 UxTmp0 = top_button_one_label ? (char *)top_button_one_label : "No_Label";
1663 /* Creation of top_button1 */
1664 top_button1 = XtVaCreateManagedWidget( "top_button1",
1665 xmPushButtonWidgetClass,
1670 XmNbottomAttachment, XmATTACH_FORM,
1671 XmNleftAttachment, XmATTACH_POSITION,
1673 XmNleftPosition, get_top_b1_position (numberOfTopButtons),
1674 RES_CONVERT( XmNlabelString, UxTmp0 ),
1676 XtAddCallback( top_button1, XmNactivateCallback,
1677 (XtCallbackProc) top_button_one_cb,
1678 (XtPointer) UxIcon_selection_dialogContext );
1680 UxPutContext( top_button1, (char *) UxIcon_selection_dialogContext );
1682 UxTmp0 = top_button_two_label ? (char *)top_button_two_label : "No_Label";
1684 /* Creation of top_button2 */
1685 top_button2 = XtVaCreateManagedWidget( "top_button2",
1686 xmPushButtonWidgetClass,
1692 XmNleftPosition, get_top_b2_position (numberOfTopButtons),
1693 XmNbottomAttachment, XmATTACH_FORM,
1694 XmNleftAttachment, XmATTACH_POSITION,
1695 RES_CONVERT( XmNlabelString, UxTmp0 ),
1697 XtAddCallback( top_button2, XmNactivateCallback,
1698 (XtCallbackProc) top_button_two_cb,
1699 (XtPointer) UxIcon_selection_dialogContext );
1701 UxPutContext( top_button2, (char *) UxIcon_selection_dialogContext );
1703 UxTmp0 = top_button_three_label ? (char *)top_button_three_label : "No_Label";
1705 /* Creation of top_button3 */
1706 top_button3 = XtVaCreateManagedWidget( "top_button3",
1707 xmPushButtonWidgetClass,
1711 RES_CONVERT( XmNlabelString, UxTmp0 ),
1712 XmNleftPosition, 72,
1714 XmNleftAttachment, XmATTACH_POSITION,
1716 XmNbottomAttachment, XmATTACH_FORM,
1718 XtAddCallback( top_button3, XmNactivateCallback,
1719 (XtCallbackProc) top_button_three_cb,
1720 (XtPointer) UxIcon_selection_dialogContext );
1722 UxPutContext( top_button3, (char *) UxIcon_selection_dialogContext );
1724 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1726 /* Creation of dir_scrolled_list */
1727 XtSetArg(args[i], XmNshadowThickness, 2); i++;
1728 XtSetArg(args[i], XmNlistSizePolicy, XmCONSTANT); i++;
1730 XtSetArg(args[i], XmNleftOffset, 10); i++;
1731 XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1732 XtSetArg(args[i], XmNtopOffset, 0); i++;
1733 XtSetArg(args[i], XmNtopWidget, directory_list_label); i++;
1734 XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1735 XtSetArg(args[i], XmNrightOffset, 20); i++;
1736 XtSetArg(args[i], XmNrightWidget, icon_container_label); i++;
1737 XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
1739 XtSetArg(args[i], XmNbottomOffset, 10); i++;
1740 if (numberOfTopButtons > 0) {
1741 XtSetArg(args[i], XmNbottomWidget, top_button_form); i++;
1742 } else if (use_icon_name_field) {
1743 XtSetArg(args[i], XmNbottomWidget, icon_name_textfield_label); i++;
1745 XtSetArg(args[i], XmNbottomWidget, separatorGadget1); i++;
1747 XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
1749 dir_scrolled_list = XmCreateScrolledList(icon_selection_dialog,
1750 "dir_scrolled_list",
1753 XtVaSetValues(dir_scrolled_list,
1754 XmNselectionPolicy, XmBROWSE_SELECT,
1755 XmNvisibleItemCount, 15,
1757 XtManageChild(dir_scrolled_list);
1759 UxPutContext( dir_scrolled_list, (char *) UxIcon_selection_dialogContext );
1760 calc_bottom_attachment (dir_scrolled_list,
1761 (XtPointer) UxIcon_selection_dialogContext,
1763 XtAddCallback( dir_scrolled_list, XmNdefaultActionCallback,
1764 (XtCallbackProc) defaultActionCB_dir_scrolled_list,
1765 (XtPointer) UxIcon_selection_dialogContext );
1767 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1769 /* Creation of icon_scrolled_win */
1770 icon_scrolled_win = XtVaCreateManagedWidget( "icon_scrolled_win",
1771 xmScrolledWindowWidgetClass,
1772 icon_selection_dialog,
1773 XmNscrollingPolicy, XmAUTOMATIC,
1774 /* XmNnavigationType, XmTAB_GROUP, */
1777 XmNscrollBarDisplayPolicy, XmAS_NEEDED,
1779 XmNrightAttachment, XmATTACH_FORM,
1781 XmNtopWidget, icon_container_label,
1782 XmNtopAttachment, XmATTACH_WIDGET,
1784 XmNleftWidget, icon_container_label,
1785 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1786 XmNbottomOffset, 10,
1787 XmNbottomWidget, None,
1788 XmNbottomAttachment, XmATTACH_WIDGET,
1794 UxPutContext( icon_scrolled_win, (char *) UxIcon_selection_dialogContext );
1795 calc_bottom_attachment (icon_scrolled_win,
1796 (XtPointer) UxIcon_selection_dialogContext,
1799 /* Creation of icon_scrolled_container */
1800 icon_scrolled_container = XtVaCreateManagedWidget( "icon_scrolled_container",
1801 xmRowColumnWidgetClass,
1803 XmNnavigationType, XmTAB_GROUP,
1804 /*XmNborderWidth, 1,*/
1805 /*XmNnumColumns, 2,*/
1807 XmNorientation, XmVERTICAL,
1808 XmNpacking, XmPACK_COLUMN,
1809 XmNshadowThickness, 1,
1812 XtVaSetValues(icon_selection_dialog,
1813 XmNcancelButton, bottom_button2,
1816 XtAddCallback( icon_selection_dialog, XmNdestroyCallback,
1817 (XtCallbackProc) UxDestroyContextCB,
1818 (XtPointer) UxIcon_selection_dialogContext);
1820 XtVaGetValues (icon_scrolled_win, XmNclipWindow, &widclipWindow, NULL);
1821 XtAddCallback( widclipWindow, XmNresizeCallback,
1822 (XtCallbackProc) resizeCB_clipWindow,
1823 (XtPointer) icon_scrolled_container );
1825 return ( icon_selection_dialog );
1828 /*******************************************************************************
1829 The following is the 'Interface function' which is the
1830 external entry point for creating this interface.
1831 This function should be called from your application or from
1832 a callback function.
1833 *******************************************************************************/
1835 Widget create_icon_selection_dialog(swidget _UxUxParent,
1836 unsigned char *_Uxdialog_title,
1837 unsigned char *_Uxfilter_field_title,
1838 int _Uxuse_filter_field,
1839 unsigned char *_Uxfile_filter,
1840 unsigned char *_Uxdirectory_title,
1841 unsigned char **_Uxdirectories_list,
1842 unsigned char *_Uxcontainer_title,
1843 int _UxnumberOfTopButtons,
1844 unsigned char *_Uxtop_button_one_label,
1845 void (*_Uxtop_button_one_cb)(),
1846 unsigned char *_Uxtop_button_two_label,
1847 void (*_Uxtop_button_two_cb)(),
1848 unsigned char *_Uxtop_button_three_label,
1849 void (*_Uxtop_button_three_cb)(),
1850 int _Uxuse_icon_name_field,
1851 unsigned char *_Uxname_field_title,
1852 int _UxnumberOfBottomButtons,
1853 unsigned char *_Uxbottom_button_one_label,
1854 void (*_Uxbottom_button_one_cb)(),
1855 unsigned char *_Uxbottom_button_two_label,
1856 void (*_Uxbottom_button_two_cb)(),
1857 unsigned char *_Uxbottom_button_three_label,
1858 void (*_Uxbottom_button_three_cb)(),
1859 unsigned char *_Uxbottom_button_four_label,
1860 void (*_Uxbottom_button_four_cb)() )
1864 char *initial_filter;
1865 char *icon_file_name;
1868 _UxCicon_selection_dialog *UxContext;
1870 UxIcon_selection_dialogContext = UxContext =
1871 (_UxCicon_selection_dialog *) UxNewContext( sizeof(_UxCicon_selection_dialog), False );
1873 UxParent = _UxUxParent;
1874 dialog_title = _Uxdialog_title;
1875 filter_field_title = _Uxfilter_field_title;
1876 use_filter_field = _Uxuse_filter_field;
1877 file_filter = _Uxfile_filter;
1878 directory_title = _Uxdirectory_title;
1879 directories_list = _Uxdirectories_list;
1880 container_title = _Uxcontainer_title;
1881 numberOfTopButtons = _UxnumberOfTopButtons;
1882 top_button_one_label = _Uxtop_button_one_label;
1883 top_button_one_cb = _Uxtop_button_one_cb;
1884 top_button_two_label = _Uxtop_button_two_label;
1885 top_button_two_cb = _Uxtop_button_two_cb;
1886 top_button_three_label = _Uxtop_button_three_label;
1887 top_button_three_cb = _Uxtop_button_three_cb;
1888 use_icon_name_field = _Uxuse_icon_name_field;
1889 name_field_title = _Uxname_field_title;
1890 numberOfBottomButtons = _UxnumberOfBottomButtons;
1891 bottom_button_one_label = _Uxbottom_button_one_label;
1892 bottom_button_one_cb = _Uxbottom_button_one_cb;
1893 bottom_button_two_label = _Uxbottom_button_two_label;
1894 bottom_button_two_cb = _Uxbottom_button_two_cb;
1895 bottom_button_three_label = _Uxbottom_button_three_label;
1896 bottom_button_three_cb = _Uxbottom_button_three_cb;
1897 bottom_button_four_label = _Uxbottom_button_four_label;
1898 bottom_button_four_cb = _Uxbottom_button_four_cb;
1900 rtrn = _Uxbuild_icon_selection_dialog();
1902 switch (numberOfTopButtons){
1903 case 0 : XtUnmanageChild (top_button_form); break;
1904 case 1 : XtUnmanageChild (top_button2);
1905 case 2 : XtUnmanageChild (top_button3);
1908 if (numberOfBottomButtons == 3)
1909 XtUnmanageChild (bottom_button4);
1911 if (!use_filter_field) {
1912 XtUnmanageChild (filter_textfield_label);
1913 XtUnmanageChild (filter_text_field);
1916 if (!use_icon_name_field) {
1917 XtUnmanageChild (icon_name_textfield_label);
1918 XtUnmanageChild (icon_name_text_field);
1921 TurnOnHourGlassAllWindows();
1923 /******************************************************************/
1924 /* save file_filter */
1925 /******************************************************************/
1926 file_filter_global = (char *)calloc(strlen((char *)file_filter)+1, sizeof(char));
1929 if (!file_filter_global) printf("Calloc error for file_filter_global, in create_icon_selection_dialog.\n");
1932 if (file_filter[0] == '*')
1933 file_filter_global = strcpy(file_filter_global, (char *)&file_filter[1]);
1935 file_filter_global = strcpy(file_filter_global, (char *)file_filter);
1937 load_directories_list ((char **)directories_list);
1938 initial_filter = initialize_filter ((char *)file_filter);
1940 /******************************************************************/
1941 /* save main_filter */
1942 /******************************************************************/
1943 main_filter = (char *)calloc(strlen(initial_filter)+1, sizeof(char));
1946 if (!main_filter) printf("Calloc error for main_filter, in create_icon_selection_dialog.\n");
1949 main_filter = strcpy(main_filter, initial_filter);;
1951 icons_in_container = NULL;
1954 update_container_contents (initial_filter);
1956 /******************************************************************/
1957 /* set selected_icon_name to first name in list */
1958 /******************************************************************/
1960 if (icons_in_container) {
1961 XtVaGetValues (icons_in_container[0], XmNimageName, &icon_file_name, NULL);
1962 XmTextFieldSetString (icon_name_text_field, icon_file_name);
1963 selected_icon_name = XtMalloc(strlen(icon_file_name) + 1);
1964 if (selected_icon_name)
1965 selected_icon_name = strcpy(selected_icon_name, icon_file_name);
1969 load_filter_text_field (initial_filter);
1971 TurnOffHourGlassAllWindows();