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 sprintf (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 strcpy(iconfile, 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);
848 #ifdef _ICONSELECTOR_DESTROY_ENABLED
849 /***************************************************************************/
851 /* void free_container_contents - free icon gadgets in container */
855 /***************************************************************************/
856 void free_container_contents (void)
863 if (icons_in_container) {
864 screen_id = XtScreen (icons_in_container[0]);
866 while (icons_in_container[lcv]) {
868 XtVaGetValues (icons_in_container[lcv], XmNimageName, &filename,
869 XmNpixmap, &icon_pixmap, NULL);
870 XmDestroyPixmap (screen_id, icon_pixmap);
872 XtVaSetValues (icons_in_container[lcv], XmNpixmap, NULL, NULL);
874 XtDestroyWidget (icons_in_container[lcv]);
876 icons_in_container[lcv]=NULL;
879 } /* end while icons_in_container */
880 free (icons_in_container);
881 icons_in_container = NULL;
885 printf ("In free_container_contents...\n");
886 printf ("Just destroyed all %i icons.\n", lcv);
896 /***************************************************************************/
898 /* void load_new_filter - displays selected directory string as */
899 /* new filter base */
900 /* Input: char *new_filter - new directory string to use as filter */
903 /***************************************************************************/
904 void load_new_filter (char *new_filter)
906 /* no longer need old filter */
909 /* create space for new filter */
910 main_filter = (char *)calloc (strlen(new_filter)+3, sizeof (char));
912 if (!main_filter) printf("Calloc error for main_filter, in load_new_filter.\n");
914 /* copy new filter and add filter end */
915 main_filter = strcpy (main_filter, new_filter);
916 main_filter = strcat (main_filter, "/*");
917 /* display new filter */
918 load_filter_text_field (main_filter);
924 /*****************************************************************************/
925 /* The following are callback functions. */
926 /*****************************************************************************/
928 /***************************************************************************/
930 /* calc_bottom_attachment */
933 /***************************************************************************/
934 static void calc_bottom_attachment( Widget UxWidget,
935 XtPointer UxClientData,
936 XtPointer UxCallbackArg )
938 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
940 UxSaveCtx = UxIcon_selection_dialogContext;
941 UxIcon_selection_dialogContext = UxContext =
942 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
944 if (numberOfTopButtons > 0) {
945 XtVaSetValues (UxWidget, XmNbottomWidget, top_button_form, NULL);
946 } else if (use_icon_name_field) {
947 XtVaSetValues (UxWidget, XmNbottomWidget, icon_name_textfield_label, NULL);
948 } else XtVaSetValues (UxWidget, XmNbottomWidget, separatorGadget1, NULL);
953 /***************************************************************************/
955 /* activateCB_bottom_button */
958 /***************************************************************************/
959 /* default cb for bottom buttons */
960 static void activateCB_bottom_button( Widget UxWidget,
961 XtPointer UxClientData,
962 XtPointer UxCallbackArg )
964 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
966 UxSaveCtx = UxIcon_selection_dialogContext;
967 UxIcon_selection_dialogContext = UxContext =
968 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
974 /******************************************************************************/
975 /* activateCB_NoFindIconDialog_ChangeNameButton */
976 /******************************************************************************/
977 void activateCB_NoFindIconDialog_ChangeNameButton( Widget UxWidget,
978 XtPointer UxClientData,
979 XtPointer UxCallbackArg)
982 XtDestroyWidget(UxWidget);
985 /******************************************************************************/
986 /* activateCB_NoFindIconDialog_NameOKButton */
987 /******************************************************************************/
988 void activateCB_NoFindIconDialog_NameOKButton( Widget UxWidget,
989 XtPointer UxClientData,
990 XtPointer UxCallbackArg)
993 char *basename = (char *)NULL;
995 TurnOnHourGlassAllWindows();
996 if (bottom_button_one_cb) {
997 GetWidgetTextString(icon_name_text_field, &basename);
998 bottom_button_one_cb(UxWidget,
999 (XtPointer)basename, UxCallbackArg);
1000 if (basename) XtFree(basename);
1002 TurnOffHourGlassAllWindows();
1003 UxPopdownInterface (IconSelector);
1004 XtDestroyWidget(UxWidget);
1007 /******************************************************************************/
1008 /* display_nofindicon_message - display cant find icons error dialog */
1009 /* INPUT: Widget parent - parent to position error dialog new */
1011 /******************************************************************************/
1012 void display_nofindicon_message (Widget parent)
1018 dialog = XmCreateErrorDialog(parent, "nofindiconDialog", NULL, 0);
1020 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
1021 XtVaSetValues(widChild,
1022 RES_CONVERT( XmNlabelString, "Change Name"),
1025 widChild = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
1026 XtVaSetValues(widChild,
1027 RES_CONVERT( XmNlabelString, "Name OK"),
1030 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
1032 XtAddCallback( dialog, XmNokCallback,
1033 (XtCallbackProc) activateCB_NoFindIconDialog_ChangeNameButton,
1035 XtAddCallback( dialog, XmNcancelCallback,
1036 (XtCallbackProc) activateCB_NoFindIconDialog_NameOKButton,
1039 /********* WARNING - this needs to be translated !!! ***********/
1040 strcpy(buffer, "There is no set of icons with that filename in the icon folders.\n");
1041 strcat(buffer, "Move the icons into one of the icon folders, then select \"Name OK\".\n");
1042 strcat(buffer, "Or, to select a different set of icons, select \"Change Name\".\n");
1043 strcat(buffer, "\nIf you are a software developer creating a registration package,\n");
1044 strcat(buffer, "ignore this message and select \"Name OK\".");
1045 XtVaSetValues (dialog,
1046 RES_CONVERT(XmNdialogTitle, GETMESSAGE(6, 31, "Create Action - Error")),
1047 RES_CONVERT(XmNmessageString, buffer),
1050 XtManageChild (dialog);
1054 /***************************************************************************/
1056 /* activateCB_bottom_button1 */
1059 /***************************************************************************/
1060 /* cb for bottom button 1 = OK */
1061 static void activateCB_bottom_button1( Widget UxWidget,
1062 XtPointer UxClientData,
1063 XtPointer UxCallbackArg )
1065 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1067 UxSaveCtx = UxIcon_selection_dialogContext;
1068 UxIcon_selection_dialogContext = UxContext =
1069 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1071 char *basename = (char *)NULL;
1072 char *fullname = (char *)NULL;
1073 char *msgPtr, *errPtr;
1075 GetWidgetTextString(icon_name_text_field, &basename);
1077 if (strchr(basename, '/')) {
1078 /**** WARNING - this needs to be in a message catalog in the future ****/
1079 /* INTERNATIONALIZE */
1080 msgPtr = "Invalid Icon filename.\n\
1081 Pathnames are not valid in the \"Enter Icon Filename\" field.\n\
1082 Enter only the name of the icon without the path or extensions.";
1083 errPtr = XtNewString(msgPtr);
1084 display_error_message(IconSelector, errPtr);
1087 FIND_ICONGADGET_ICON(basename, fullname, DtMEDIUM);
1088 if ( (fullname) && (check_file_exists(fullname)) ) {
1089 TurnOnHourGlassAllWindows();
1090 if (bottom_button_one_cb) {
1091 bottom_button_one_cb(UxWidget,
1092 (XtPointer)fullname, UxCallbackArg);
1094 TurnOffHourGlassAllWindows();
1095 UxPopdownInterface (IconSelector);
1096 if (basename) XtFree(basename);
1098 display_nofindicon_message(IconSelector);
1102 msgPtr = GETMESSAGE(11, 50, "The Icon Filename is invalid.\n\
1103 Please enter a valid icon file name in the\n'Enter Icon Filename' field.");
1104 errPtr = XtNewString(msgPtr);
1105 display_error_message(IconSelector, errPtr);
1111 #if 0 /************* old code *********************/
1112 char *pszIconFileName = (char *)NULL;
1113 char buffer[MAXBUFSIZE];
1115 GetWidgetTextString(icon_name_text_field, &pszIconFileName);
1116 if ( (pszIconFileName) && (check_file_exists(pszIconFileName)) ) {
1117 TurnOnHourGlassAllWindows();
1118 if (bottom_button_one_cb) {
1119 bottom_button_one_cb(UxWidget,
1120 (XtPointer)pszIconFileName, UxCallbackArg);
1122 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1123 free_container_contents ();
1124 if (selected_icon_name) {
1125 XtFree(selected_icon_name);
1127 selected_icon_name = (char *)NULL;
1128 XtDestroyWidget (XtParent(icon_selection_dialog));
1129 IconSelector = (Widget)NULL;
1130 TurnOffHourGlassAllWindows();
1132 TurnOffHourGlassAllWindows();
1133 UxPopdownInterface (IconSelector);
1134 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1135 XtFree(pszIconFileName);
1137 strcpy(buffer, GETMESSAGE(11, 50, "The Icon Filename is invalid.\nPlease enter a valid icon file name in the\n'Enter Icon Filename' field."));
1138 display_error_message(IconSelector, buffer);
1143 if (selected_icon_name) {
1144 TurnOnHourGlassAllWindows();
1145 if (bottom_button_one_cb) {
1146 bottom_button_one_cb(UxWidget,
1147 (XtPointer)selected_icon_name, UxCallbackArg);
1149 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1150 free_container_contents ();
1151 XtFree(selected_icon_name);
1152 selected_icon_name = (char *)NULL;
1153 XtDestroyWidget (XtParent(icon_selection_dialog));
1154 IconSelector = (Widget)NULL;
1155 TurnOffHourGlassAllWindows();
1157 TurnOffHourGlassAllWindows();
1158 UxPopdownInterface (IconSelector);
1159 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1164 #endif /************* old code *********************/
1168 /***************************************************************************/
1170 /* activateCB_bottom_button2 */
1173 /***************************************************************************/
1174 /* cb for bottom button 2 = CANCEL */
1175 static void activateCB_bottom_button2( Widget UxWidget,
1176 XtPointer UxClientData,
1177 XtPointer UxCallbackArg )
1179 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1181 UxSaveCtx = UxIcon_selection_dialogContext;
1182 UxIcon_selection_dialogContext = UxContext =
1183 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1185 #ifdef _ICONSELECTOR_DESTROY_ENABLED
1186 free_container_contents ();
1187 XtDestroyWidget (XtParent(icon_selection_dialog));
1188 IconSelector = (Widget)NULL;
1190 UxPopdownInterface (IconSelector);
1191 #endif /* _ICONSELECTOR_DESTROY_ENABLED */
1196 /***************************************************************************/
1198 /* activateCB_bottom_button3 */
1201 /***************************************************************************/
1202 /* default cb for bottom button3 = HELP */
1203 static void activateCB_bottom_button3( Widget UxWidget,
1204 XtPointer UxClientData,
1205 XtPointer UxCallbackArg )
1207 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1209 UxSaveCtx = UxIcon_selection_dialogContext;
1210 UxIcon_selection_dialogContext = UxContext =
1211 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1213 DisplayHelpDialog(UxWidget, (XtPointer)HELP_ICONSELECTOR, UxCallbackArg);
1218 /***************************************************************************/
1220 /* activateCB_filter_text_field */
1223 /***************************************************************************/
1224 static void activateCB_filter_text_field( Widget UxWidget,
1225 XtPointer UxClientData,
1226 XtPointer UxCallbackArg )
1228 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1229 UxSaveCtx = UxIcon_selection_dialogContext;
1230 UxIcon_selection_dialogContext = UxContext =
1231 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1235 filter = XmTextFieldGetString (UxWidget);
1236 apply_filter (filter);
1238 UxIcon_selection_dialogContext = UxSaveCtx;
1241 /***************************************************************************/
1243 /* defaultActionCB_dir_scrolled_list */
1246 /***************************************************************************/
1247 static void defaultActionCB_dir_scrolled_list( Widget UxWidget,
1248 XtPointer UxClientData,
1249 XtPointer UxCallbackArg )
1251 _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
1253 UxSaveCtx = UxIcon_selection_dialogContext;
1254 UxIcon_selection_dialogContext = UxContext =
1255 (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
1257 XmListCallbackStruct *listcb;
1260 listcb = (XmListCallbackStruct *) UxCallbackArg;
1261 filter = (char *)XmStringToText (listcb->item);
1262 apply_filter (filter);
1263 /* XtManageChild (icon_scrolled_win); */
1265 UxIcon_selection_dialogContext = UxSaveCtx;
1268 /***************************************************************************/
1270 /* selectionCB_icon_scrolled_container */
1272 /***************************************************************************/
1273 static void selectionCB_icon_scrolled_container ( Widget UxWidget,
1274 XtPointer UxClientData,
1275 XtPointer UxCallbackArg )
1278 XmString xmbasename;
1281 XtVaGetValues (UxWidget, XmNimageName, &filename, NULL);
1283 printf("In icon callback for '%s'\n", filename);
1285 if (use_icon_name_field) {
1286 XtVaGetValues (UxWidget, XmNstring, &xmbasename, NULL);
1287 basename = XmStringToText(xmbasename);
1288 XmTextFieldSetString (icon_name_text_field, basename);
1289 if (basename) free(basename);
1291 if (selected_icon_name) {
1292 if (selected_icon != UxWidget) {
1293 _DtIconSetState(selected_icon, FALSE, FALSE);
1295 XtFree(selected_icon_name);
1296 selected_icon_name = (char *)NULL;
1299 selected_icon_name = XtMalloc(strlen(filename) + 1);
1300 selected_icon_name = strcpy(selected_icon_name, filename);
1302 selected_icon_name = (char *)NULL;
1304 selected_icon = UxWidget;
1309 /***************************************************************************/
1311 /* resizeCB_clipWindow */
1313 /***************************************************************************/
1314 void resizeCB_clipWindow( Widget UxWidget,
1315 XtPointer UxClientData,
1316 XtPointer UxCallbackArg )
1318 Widget widvScrollbar;
1319 Widget widRowColumn;
1321 XtArgVal /* Dimension */ height;
1323 XtVaGetValues(XtParent(UxWidget), XmNverticalScrollBar, &widvScrollbar, NULL);
1324 widRowColumn = (Widget)UxClientData;
1325 XtVaGetValues(widRowColumn, XmNheight, &height, NULL);
1328 printf("height = %d\n", height);
1329 printf("icon_count = %d\n", icon_count);
1332 increment = (int)height / icon_count;
1333 XtVaSetValues(widvScrollbar, XmNincrement, increment, NULL);
1339 /***************************************************************************/
1341 /* _Uxbuild_icon_selection_dialog */
1344 /***************************************************************************/
1345 static Widget _Uxbuild_icon_selection_dialog(void)
1350 int ntotalbuttons = numberOfBottomButtons;
1351 #define TIGHTNESS 20
1354 Widget widclipWindow;
1356 /* Creation of icon_selection_dialog */
1357 _UxParent = UxParent;
1358 if ( _UxParent == NULL )
1360 _UxParent = UxTopLevel;
1363 _UxParent = XtVaCreatePopupShell( "icon_selection_dialog_shell",
1364 xmDialogShellWidgetClass, _UxParent,
1369 XmNshellUnitType, XmPIXELS,
1370 XmNkeyboardFocusPolicy, XmEXPLICIT,
1371 XmNtitle, "icon_selection_dialog",
1374 UxTmp0 = dialog_title ? (char *)dialog_title : "Icon Selection Window";
1376 icon_selection_dialog = XtVaCreateWidget( "icon_selection_dialog",
1379 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1382 XmNunitType, XmPIXELS,
1383 RES_CONVERT( XmNdialogTitle, UxTmp0 ),
1384 XmNautoUnmanage, FALSE,
1385 XmNdefaultPosition, FALSE,
1387 UxPutContext( icon_selection_dialog, (char *) UxIcon_selection_dialogContext );
1389 /*******************************************************************/
1390 /* Set up help callback */
1391 /*******************************************************************/
1392 XtAddCallback( icon_selection_dialog, XmNhelpCallback,
1393 (XtCallbackProc) helpCB_general,
1394 (XtPointer) HELP_ICONSELECTOR );
1397 /* Creation of bottom_button_form */
1398 bottom_button_form = XtVaCreateManagedWidget( "bottom_button_form",
1400 icon_selection_dialog,
1401 XmNskipAdjust, TRUE,
1402 XmNfractionBase, ((TIGHTNESS * ntotalbuttons) - 1),
1405 XmNleftAttachment, XmATTACH_FORM,
1407 XmNrightAttachment, XmATTACH_FORM,
1408 XmNbottomOffset, 20,
1409 XmNbottomAttachment, XmATTACH_FORM,
1412 UxPutContext( bottom_button_form, (char *) UxIcon_selection_dialogContext );
1415 UxTmp0 = bottom_button_one_label ? (char *)bottom_button_one_label : GETMESSAGE(6, 10, "OK");
1417 /* Creation of bottom_button1 = OK */
1418 bottom_button1 = XtVaCreateManagedWidget( "bottom_button1",
1419 xmPushButtonWidgetClass,
1421 RES_CONVERT( XmNlabelString, UxTmp0 ),
1423 XmNleftAttachment, nbutton ?
1424 XmATTACH_POSITION : XmATTACH_FORM,
1425 XmNleftPosition, TIGHTNESS * nbutton,
1426 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1427 XmATTACH_POSITION : XmATTACH_FORM,
1428 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1432 XtAddCallback( bottom_button1, XmNactivateCallback,
1433 (XtCallbackProc) activateCB_bottom_button1,
1436 UxPutContext( bottom_button1, (char *) UxIcon_selection_dialogContext );
1438 UxTmp0 = bottom_button_two_label ? (char *)bottom_button_two_label : GETMESSAGE(6, 12, "Cancel");
1440 /* Creation of bottom_button2 = CANCEL */
1441 bottom_button2 = XtVaCreateManagedWidget( "bottom_button2",
1442 xmPushButtonWidgetClass,
1444 RES_CONVERT( XmNlabelString, UxTmp0 ),
1446 XmNleftAttachment, nbutton ?
1447 XmATTACH_POSITION : XmATTACH_FORM,
1448 XmNleftPosition, TIGHTNESS * nbutton,
1449 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1450 XmATTACH_POSITION : XmATTACH_FORM,
1451 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1455 XtAddCallback( bottom_button2, XmNactivateCallback,
1456 (XtCallbackProc) bottom_button_two_cb ?
1457 bottom_button_two_cb : activateCB_bottom_button2,
1458 (XtPointer) UxIcon_selection_dialogContext );
1460 UxPutContext( bottom_button2, (char *) UxIcon_selection_dialogContext );
1462 UxTmp0 = bottom_button_three_label ? (char *)bottom_button_three_label : GETMESSAGE(6, 13, "Help");
1464 /* Creation of bottom_button3 = HELP */
1465 bottom_button3 = XtVaCreateManagedWidget( "bottom_button3",
1466 xmPushButtonWidgetClass,
1468 RES_CONVERT( XmNlabelString, UxTmp0 ),
1469 XmNuserData, icon_selection_dialog,
1471 XmNleftAttachment, nbutton ?
1472 XmATTACH_POSITION : XmATTACH_FORM,
1473 XmNleftPosition, TIGHTNESS * nbutton,
1474 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1475 XmATTACH_POSITION : XmATTACH_FORM,
1476 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1480 XtAddCallback( bottom_button3, XmNactivateCallback,
1481 (XtCallbackProc) bottom_button_three_cb ?
1482 bottom_button_three_cb : activateCB_bottom_button3,
1483 (XtPointer) UxIcon_selection_dialogContext );
1485 UxPutContext( bottom_button3, (char *) UxIcon_selection_dialogContext );
1487 UxTmp0 = bottom_button_four_label ? (char *)bottom_button_four_label : GETMESSAGE(12, 10, "Filter");
1489 /* Creation of bottom_button4 */
1490 bottom_button4 = XtVaCreateManagedWidget( "bottom_button4",
1491 xmPushButtonWidgetClass,
1493 RES_CONVERT( XmNlabelString, UxTmp0 ),
1495 XmNleftAttachment, nbutton ?
1496 XmATTACH_POSITION : XmATTACH_FORM,
1497 XmNleftPosition, TIGHTNESS * nbutton,
1498 XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
1499 XmATTACH_POSITION : XmATTACH_FORM,
1500 XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
1504 XtAddCallback( bottom_button4, XmNactivateCallback,
1505 (XtCallbackProc) bottom_button_four_cb ?
1506 bottom_button_four_cb : activateCB_bottom_button,
1507 (XtPointer) UxIcon_selection_dialogContext );
1509 UxPutContext( bottom_button4, (char *) UxIcon_selection_dialogContext );
1512 /* Creation of separatorGadget1 */
1513 separatorGadget1 = XtVaCreateManagedWidget( "separatorGadget1",
1514 xmSeparatorGadgetClass,
1515 icon_selection_dialog,
1519 XmNrightAttachment, XmATTACH_FORM,
1521 XmNleftAttachment, XmATTACH_FORM,
1522 XmNbottomOffset, 10,
1523 XmNbottomWidget, bottom_button_form,
1524 XmNbottomAttachment, XmATTACH_WIDGET,
1526 UxPutContext( separatorGadget1, (char *) UxIcon_selection_dialogContext );
1529 /* Creation of icon_name_text_field */
1530 icon_name_text_field = XtVaCreateManagedWidget( "icon_name_text_field",
1531 xmTextFieldWidgetClass,
1532 icon_selection_dialog,
1535 XmNbottomOffset, 10,
1536 XmNbottomWidget, separatorGadget1,
1537 XmNbottomAttachment, XmATTACH_WIDGET,
1539 XmNrightAttachment, XmATTACH_FORM,
1541 XmNleftAttachment, XmATTACH_FORM,
1543 UxPutContext( icon_name_text_field, (char *) UxIcon_selection_dialogContext );
1544 ISD_SelectedIconTextField = icon_name_text_field;
1546 UxTmp0 = name_field_title ? (char *)name_field_title : GETMESSAGE(11, 12, "Enter Icon Filename");
1548 /* Creation of icon_name_textfield_label */
1549 icon_name_textfield_label = XtVaCreateManagedWidget( "icon_name_textfield_label",
1551 icon_selection_dialog,
1554 RES_CONVERT( XmNlabelString, UxTmp0 ),
1556 XmNbottomWidget, icon_name_text_field,
1557 XmNbottomAttachment, XmATTACH_WIDGET,
1559 XmNleftWidget, icon_name_text_field,
1560 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1561 XmNalignment, XmALIGNMENT_BEGINNING,
1563 UxPutContext( icon_name_textfield_label, (char *) UxIcon_selection_dialogContext );
1565 UxTmp0 = filter_field_title ? (char *)filter_field_title : GETMESSAGE(12, 10, "Filter");
1567 /* Creation of filter_textfield_label */
1568 filter_textfield_label = XtVaCreateManagedWidget( "filter_textfield_label",
1570 icon_selection_dialog,
1573 RES_CONVERT( XmNlabelString, UxTmp0 ),
1574 XmNalignment, XmALIGNMENT_BEGINNING,
1576 XmNtopAttachment, XmATTACH_FORM,
1578 XmNleftAttachment, XmATTACH_FORM,
1580 UxPutContext( filter_textfield_label, (char *) UxIcon_selection_dialogContext );
1583 /* Creation of filter_text_field */
1584 filter_text_field = XtVaCreateManagedWidget( "filter_text_field",
1585 xmTextFieldWidgetClass,
1586 icon_selection_dialog,
1590 XmNtopWidget, filter_textfield_label,
1591 XmNtopAttachment, XmATTACH_WIDGET,
1593 XmNrightAttachment, XmATTACH_FORM,
1595 XmNleftAttachment, XmATTACH_FORM,
1597 XtAddCallback( filter_text_field, XmNactivateCallback,
1598 (XtCallbackProc) activateCB_filter_text_field,
1599 (XtPointer) UxIcon_selection_dialogContext );
1601 UxPutContext( filter_text_field, (char *) UxIcon_selection_dialogContext );
1603 UxTmp0 = directory_title ? (char *)directory_title : GETMESSAGE(11, 30, "Icon Folders");
1605 /* Creation of directory_list_label */
1606 directory_list_label = XtVaCreateManagedWidget( "directory_list_label",
1608 icon_selection_dialog,
1611 XmNlabelType, XmSTRING,
1612 RES_CONVERT( XmNlabelString, UxTmp0 ),
1613 XmNalignment, XmALIGNMENT_BEGINNING,
1615 XmNtopWidget, filter_text_field,
1616 XmNtopAttachment, use_filter_field ? XmATTACH_WIDGET : XmATTACH_FORM,
1618 XmNleftAttachment, XmATTACH_FORM,
1620 UxPutContext( directory_list_label, (char *) UxIcon_selection_dialogContext );
1622 UxTmp0 = container_title ? (char *)container_title : GETMESSAGE(11, 11, "Icon Files");
1624 /* Creation of icon_container_label */
1625 icon_container_label = XtVaCreateManagedWidget( "icon_container_label",
1627 icon_selection_dialog,
1630 XmNlabelType, XmSTRING,
1631 RES_CONVERT( XmNlabelString, UxTmp0 ),
1632 XmNalignment, XmALIGNMENT_BEGINNING,
1634 XmNtopWidget, filter_text_field,
1635 XmNtopAttachment, XmATTACH_WIDGET,
1636 XmNleftAttachment, XmATTACH_POSITION,
1637 XmNleftPosition, 55,
1639 UxPutContext( icon_container_label, (char *) UxIcon_selection_dialogContext );
1642 /* Creation of top_button_form */
1643 top_button_form = XtVaCreateManagedWidget( "top_button_form",
1645 icon_selection_dialog,
1646 XmNresizePolicy, XmRESIZE_NONE,
1649 XmNbottomOffset, 10,
1650 XmNbottomWidget, use_icon_name_field ? icon_name_textfield_label : separatorGadget1,
1651 XmNbottomAttachment, XmATTACH_WIDGET,
1653 XmNrightAttachment, XmATTACH_FORM,
1655 XmNleftAttachment, XmATTACH_FORM,
1657 UxPutContext( top_button_form, (char *) UxIcon_selection_dialogContext );
1659 UxTmp0 = top_button_one_label ? (char *)top_button_one_label : "No_Label";
1661 /* Creation of top_button1 */
1662 top_button1 = XtVaCreateManagedWidget( "top_button1",
1663 xmPushButtonWidgetClass,
1668 XmNbottomAttachment, XmATTACH_FORM,
1669 XmNleftAttachment, XmATTACH_POSITION,
1671 XmNleftPosition, get_top_b1_position (numberOfTopButtons),
1672 RES_CONVERT( XmNlabelString, UxTmp0 ),
1674 XtAddCallback( top_button1, XmNactivateCallback,
1675 (XtCallbackProc) top_button_one_cb,
1676 (XtPointer) UxIcon_selection_dialogContext );
1678 UxPutContext( top_button1, (char *) UxIcon_selection_dialogContext );
1680 UxTmp0 = top_button_two_label ? (char *)top_button_two_label : "No_Label";
1682 /* Creation of top_button2 */
1683 top_button2 = XtVaCreateManagedWidget( "top_button2",
1684 xmPushButtonWidgetClass,
1690 XmNleftPosition, get_top_b2_position (numberOfTopButtons),
1691 XmNbottomAttachment, XmATTACH_FORM,
1692 XmNleftAttachment, XmATTACH_POSITION,
1693 RES_CONVERT( XmNlabelString, UxTmp0 ),
1695 XtAddCallback( top_button2, XmNactivateCallback,
1696 (XtCallbackProc) top_button_two_cb,
1697 (XtPointer) UxIcon_selection_dialogContext );
1699 UxPutContext( top_button2, (char *) UxIcon_selection_dialogContext );
1701 UxTmp0 = top_button_three_label ? (char *)top_button_three_label : "No_Label";
1703 /* Creation of top_button3 */
1704 top_button3 = XtVaCreateManagedWidget( "top_button3",
1705 xmPushButtonWidgetClass,
1709 RES_CONVERT( XmNlabelString, UxTmp0 ),
1710 XmNleftPosition, 72,
1712 XmNleftAttachment, XmATTACH_POSITION,
1714 XmNbottomAttachment, XmATTACH_FORM,
1716 XtAddCallback( top_button3, XmNactivateCallback,
1717 (XtCallbackProc) top_button_three_cb,
1718 (XtPointer) UxIcon_selection_dialogContext );
1720 UxPutContext( top_button3, (char *) UxIcon_selection_dialogContext );
1722 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1724 /* Creation of dir_scrolled_list */
1725 XtSetArg(args[i], XmNshadowThickness, 2); i++;
1726 XtSetArg(args[i], XmNlistSizePolicy, XmCONSTANT); i++;
1728 XtSetArg(args[i], XmNleftOffset, 10); i++;
1729 XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1730 XtSetArg(args[i], XmNtopOffset, 0); i++;
1731 XtSetArg(args[i], XmNtopWidget, directory_list_label); i++;
1732 XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1733 XtSetArg(args[i], XmNrightOffset, 20); i++;
1734 XtSetArg(args[i], XmNrightWidget, icon_container_label); i++;
1735 XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
1737 XtSetArg(args[i], XmNbottomOffset, 10); i++;
1738 if (numberOfTopButtons > 0) {
1739 XtSetArg(args[i], XmNbottomWidget, top_button_form); i++;
1740 } else if (use_icon_name_field) {
1741 XtSetArg(args[i], XmNbottomWidget, icon_name_textfield_label); i++;
1743 XtSetArg(args[i], XmNbottomWidget, separatorGadget1); i++;
1745 XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
1747 dir_scrolled_list = XmCreateScrolledList(icon_selection_dialog,
1748 "dir_scrolled_list",
1751 XtVaSetValues(dir_scrolled_list,
1752 XmNselectionPolicy, XmBROWSE_SELECT,
1753 XmNvisibleItemCount, 15,
1755 XtManageChild(dir_scrolled_list);
1757 UxPutContext( dir_scrolled_list, (char *) UxIcon_selection_dialogContext );
1758 calc_bottom_attachment (dir_scrolled_list,
1759 (XtPointer) UxIcon_selection_dialogContext,
1761 XtAddCallback( dir_scrolled_list, XmNdefaultActionCallback,
1762 (XtCallbackProc) defaultActionCB_dir_scrolled_list,
1763 (XtPointer) UxIcon_selection_dialogContext );
1765 UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
1767 /* Creation of icon_scrolled_win */
1768 icon_scrolled_win = XtVaCreateManagedWidget( "icon_scrolled_win",
1769 xmScrolledWindowWidgetClass,
1770 icon_selection_dialog,
1771 XmNscrollingPolicy, XmAUTOMATIC,
1772 /* XmNnavigationType, XmTAB_GROUP, */
1775 XmNscrollBarDisplayPolicy, XmAS_NEEDED,
1777 XmNrightAttachment, XmATTACH_FORM,
1779 XmNtopWidget, icon_container_label,
1780 XmNtopAttachment, XmATTACH_WIDGET,
1782 XmNleftWidget, icon_container_label,
1783 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
1784 XmNbottomOffset, 10,
1785 XmNbottomWidget, None,
1786 XmNbottomAttachment, XmATTACH_WIDGET,
1792 UxPutContext( icon_scrolled_win, (char *) UxIcon_selection_dialogContext );
1793 calc_bottom_attachment (icon_scrolled_win,
1794 (XtPointer) UxIcon_selection_dialogContext,
1797 /* Creation of icon_scrolled_container */
1798 icon_scrolled_container = XtVaCreateManagedWidget( "icon_scrolled_container",
1799 xmRowColumnWidgetClass,
1801 XmNnavigationType, XmTAB_GROUP,
1802 /*XmNborderWidth, 1,*/
1803 /*XmNnumColumns, 2,*/
1805 XmNorientation, XmVERTICAL,
1806 XmNpacking, XmPACK_COLUMN,
1807 XmNshadowThickness, 1,
1810 XtVaSetValues(icon_selection_dialog,
1811 XmNcancelButton, bottom_button2,
1814 XtAddCallback( icon_selection_dialog, XmNdestroyCallback,
1815 (XtCallbackProc) UxDestroyContextCB,
1816 (XtPointer) UxIcon_selection_dialogContext);
1818 XtVaGetValues (icon_scrolled_win, XmNclipWindow, &widclipWindow, NULL);
1819 XtAddCallback( widclipWindow, XmNresizeCallback,
1820 (XtCallbackProc) resizeCB_clipWindow,
1821 (XtPointer) icon_scrolled_container );
1823 return ( icon_selection_dialog );
1826 /*******************************************************************************
1827 The following is the 'Interface function' which is the
1828 external entry point for creating this interface.
1829 This function should be called from your application or from
1830 a callback function.
1831 *******************************************************************************/
1833 Widget create_icon_selection_dialog(swidget _UxUxParent,
1834 unsigned char *_Uxdialog_title,
1835 unsigned char *_Uxfilter_field_title,
1836 int _Uxuse_filter_field,
1837 unsigned char *_Uxfile_filter,
1838 unsigned char *_Uxdirectory_title,
1839 unsigned char **_Uxdirectories_list,
1840 unsigned char *_Uxcontainer_title,
1841 int _UxnumberOfTopButtons,
1842 unsigned char *_Uxtop_button_one_label,
1843 void (*_Uxtop_button_one_cb)(),
1844 unsigned char *_Uxtop_button_two_label,
1845 void (*_Uxtop_button_two_cb)(),
1846 unsigned char *_Uxtop_button_three_label,
1847 void (*_Uxtop_button_three_cb)(),
1848 int _Uxuse_icon_name_field,
1849 unsigned char *_Uxname_field_title,
1850 int _UxnumberOfBottomButtons,
1851 unsigned char *_Uxbottom_button_one_label,
1852 void (*_Uxbottom_button_one_cb)(),
1853 unsigned char *_Uxbottom_button_two_label,
1854 void (*_Uxbottom_button_two_cb)(),
1855 unsigned char *_Uxbottom_button_three_label,
1856 void (*_Uxbottom_button_three_cb)(),
1857 unsigned char *_Uxbottom_button_four_label,
1858 void (*_Uxbottom_button_four_cb)() )
1862 char *initial_filter;
1863 char *icon_file_name;
1866 _UxCicon_selection_dialog *UxContext;
1868 UxIcon_selection_dialogContext = UxContext =
1869 (_UxCicon_selection_dialog *) UxNewContext( sizeof(_UxCicon_selection_dialog), False );
1871 UxParent = _UxUxParent;
1872 dialog_title = _Uxdialog_title;
1873 filter_field_title = _Uxfilter_field_title;
1874 use_filter_field = _Uxuse_filter_field;
1875 file_filter = _Uxfile_filter;
1876 directory_title = _Uxdirectory_title;
1877 directories_list = _Uxdirectories_list;
1878 container_title = _Uxcontainer_title;
1879 numberOfTopButtons = _UxnumberOfTopButtons;
1880 top_button_one_label = _Uxtop_button_one_label;
1881 top_button_one_cb = _Uxtop_button_one_cb;
1882 top_button_two_label = _Uxtop_button_two_label;
1883 top_button_two_cb = _Uxtop_button_two_cb;
1884 top_button_three_label = _Uxtop_button_three_label;
1885 top_button_three_cb = _Uxtop_button_three_cb;
1886 use_icon_name_field = _Uxuse_icon_name_field;
1887 name_field_title = _Uxname_field_title;
1888 numberOfBottomButtons = _UxnumberOfBottomButtons;
1889 bottom_button_one_label = _Uxbottom_button_one_label;
1890 bottom_button_one_cb = _Uxbottom_button_one_cb;
1891 bottom_button_two_label = _Uxbottom_button_two_label;
1892 bottom_button_two_cb = _Uxbottom_button_two_cb;
1893 bottom_button_three_label = _Uxbottom_button_three_label;
1894 bottom_button_three_cb = _Uxbottom_button_three_cb;
1895 bottom_button_four_label = _Uxbottom_button_four_label;
1896 bottom_button_four_cb = _Uxbottom_button_four_cb;
1898 rtrn = _Uxbuild_icon_selection_dialog();
1900 switch (numberOfTopButtons){
1901 case 0 : XtUnmanageChild (top_button_form); break;
1902 case 1 : XtUnmanageChild (top_button2);
1903 case 2 : XtUnmanageChild (top_button3);
1906 if (numberOfBottomButtons == 3)
1907 XtUnmanageChild (bottom_button4);
1909 if (!use_filter_field) {
1910 XtUnmanageChild (filter_textfield_label);
1911 XtUnmanageChild (filter_text_field);
1914 if (!use_icon_name_field) {
1915 XtUnmanageChild (icon_name_textfield_label);
1916 XtUnmanageChild (icon_name_text_field);
1919 TurnOnHourGlassAllWindows();
1921 /******************************************************************/
1922 /* save file_filter */
1923 /******************************************************************/
1924 file_filter_global = (char *)calloc(strlen((char *)file_filter)+1, sizeof(char));
1927 if (!file_filter_global) printf("Calloc error for file_filter_global, in create_icon_selection_dialog.\n");
1930 if (file_filter[0] == '*')
1931 file_filter_global = strcpy(file_filter_global, (char *)&file_filter[1]);
1933 file_filter_global = strcpy(file_filter_global, (char *)file_filter);
1935 load_directories_list ((char **)directories_list);
1936 initial_filter = initialize_filter ((char *)file_filter);
1938 /******************************************************************/
1939 /* save main_filter */
1940 /******************************************************************/
1941 main_filter = (char *)calloc(strlen(initial_filter)+1, sizeof(char));
1944 if (!main_filter) printf("Calloc error for main_filter, in create_icon_selection_dialog.\n");
1947 main_filter = strcpy(main_filter, initial_filter);;
1949 icons_in_container = NULL;
1952 update_container_contents (initial_filter);
1954 /******************************************************************/
1955 /* set selected_icon_name to first name in list */
1956 /******************************************************************/
1958 if (icons_in_container) {
1959 XtVaGetValues (icons_in_container[0], XmNimageName, &icon_file_name, NULL);
1960 XmTextFieldSetString (icon_name_text_field, icon_file_name);
1961 selected_icon_name = XtMalloc(strlen(icon_file_name) + 1);
1962 if (selected_icon_name)
1963 selected_icon_name = strcpy(selected_icon_name, icon_file_name);
1967 load_filter_text_field (initial_filter);
1969 TurnOffHourGlassAllWindows();