*** Imakefile	2004/10/30 22:12:42	1.1
--- Imakefile	2004/10/30 22:12:58
***************
*** 101,113 ****
  # DEPTHDEF = -DEIGHTBIT
  #endif
  
  # RasMol's on-line help direcory
  #   e.g. /usr/local/lib/rasmol/rasmol.hlp
  RASMOLDIR = $(USRLIBDIR)/rasmol/
  
  
  
! DEFINES = -DRASMOLDIR=\"$(RASMOLDIR)\" $(DEPTHDEF) -D_USE_RASMOL_H_
  
  SRCS = rasmol.c rasmol.h molecule.c molecule.h abstree.c abstree.h \
         cmndline.c cmndline.h command.c command.h tokens.h transfor.c \
--- 101,119 ----
  # DEPTHDEF = -DEIGHTBIT
  #endif
  
+ # using xform library to show GUI dialog
+ # Use the first form for Mac OS X, the second for Linux x86
+ # XFORMSLIB = -lXpm -L/usr/local/lib -lforms
+ XFORMSLIB = -lXpm -L/usr/local/lib -lforms -Wl,-rpath,/usr/local/lib
+ GUIOPTION = -DXFORMSLIB
+ 
  # RasMol's on-line help direcory
  #   e.g. /usr/local/lib/rasmol/rasmol.hlp
  RASMOLDIR = $(USRLIBDIR)/rasmol/
  
  
  
! DEFINES = -DRASMOLDIR=\"$(RASMOLDIR)\" $(DEPTHDEF) -D_USE_RASMOL_H_ $(GUIOPTION)
  
  SRCS = rasmol.c rasmol.h molecule.c molecule.h abstree.c abstree.h \
         cmndline.c cmndline.h command.c command.h tokens.h transfor.c \
***************
*** 129,135 ****
  # Additional RS6000 AIX MITSHM Library
  # LDLIBS = -lm -lXi -lXextSam $(XLIB)
  
! LDLIBS = -lm -lXi $(XLIB) $(EXTRA_LIBRARIES)
  
  
  
--- 135,141 ----
  # Additional RS6000 AIX MITSHM Library
  # LDLIBS = -lm -lXi -lXextSam $(XLIB)
  
! LDLIBS = -lm -lXi $(XLIB) $(EXTRA_LIBRARIES) $(XFORMSLIB)
  
  
  
*** rasmol.c	2004/10/30 22:12:42	1.1
--- rasmol.c	2004/10/30 22:13:04
***************
*** 187,192 ****
--- 184,197 ----
  #include <netdb.h>
  #endif
  
+ #ifdef XFORMSLIB
+ #include <sys/stat.h>
+ #include <forms.h>
+ #define	XFORMS_FONTSIZE		14
+ #define	XFORMS_OPENDIALOG	0
+ #define	XFORMS_SAVEDIALOG	1
+ #endif
+ 
  #define IsIdentChar(x)  ((isalnum(x))||((x)=='_')||((x)=='$'))
  #define TwoPi           2.0*PI
  
***************
*** 820,825 ****
--- 825,965 ----
          LoadScriptFile(initrc,fname);
  }
  
+ #ifdef XFORMSLIB
+ static void HandleFileOpen( void )
+ {
+     char *r;
+ 
+     fl_use_fselector(XFORMS_OPENDIALOG);
+     r = (char *)fl_show_fselector("Open Structure file", "", "", "");
+ 
+     if (r && *r) {
+        WriteString("load ");
+        WriteString(r);
+        WriteChar(' ');
+        if ( FetchFile(FormatPDB,False,r) )
+                DefaultRepresentation();
+        ResetCommandLine(0);
+     }
+ }
+ 
+ static void HandleFileSave( int selector )
+ {
+     char *r;
+     struct stat status;
+     static char * cmd[] = {
+ 	"pdb",
+ 	"gif",
+ 	"epsf",
+ 	"ppm",
+ 	"iris",
+ 	"ras",
+ 	"bpm",
+ 	"pict"
+     };
+     static const char * suffix[] = {
+ 	"*.pdb",
+ 	"*.gif",
+ 	"*.epsf",
+ 	"*.ppm",
+ 	"*.rgb",
+ 	"*.ras",
+ 	"*.bpm",
+ 	"*.pict"
+     };
+     static const char * mesg[] = {
+ 	"Save current molecule as",
+ 	"Save GIF image as",
+ 	"Save EPSF file as",
+ 	"Save PPM image as",
+ 	"Save IRIS image as",
+ 	"Save Raster format as",
+ 	"Save BPM image as",
+ 	"Save PICT file as"
+     };
+ 
+     if (selector < 0 || selector > 7) {
+ 	WriteString("Error: command not supported");
+ 	return;
+     }
+ 
+     fl_use_fselector(XFORMS_SAVEDIALOG);
+     do {
+         r = (char *)fl_show_fselector(mesg[selector], "", suffix[selector], "");
+ 
+         if (r == NULL || *r == 0)
+ 		break;
+ 
+         if (stat(r, &status))
+ 		break;
+ 
+ 	if (status.st_mode & S_IFREG) {
+ 		if (fl_show_question("Overwrite existing file?", 0))
+ 			break;
+ 		continue;
+ 	}
+ 	
+         fl_show_alert("Following name is directory or used for another purpose:", r, "Please chose another.", 0);
+     } while (r);
+ 
+     if (r && *r) {
+        if (selector)
+            WriteString("write ");
+        else
+            WriteString("save ");
+        WriteString(cmd[selector]);
+        WriteChar(' ');
+        WriteString(r);
+        WriteChar(' ');
+        switch (selector) 
+        {   case 1:   WriteGIFFile(r);            break;
+            case 2:   WriteEPSFFile(r,True,True); break;
+            case 3:   WritePPMFile(r,True);       break;
+            case 4:   WriteIRISFile(r);           break;
+            case 5:   WriteRastFile(r,True);      break;
+            case 6:   WriteBMPFile(r);            break;
+            case 7:   WritePICTFile(r);           break;
+            default:  SavePDBMolecule(r);
+                      break;
+        }
+        ResetCommandLine(0);
+     }
+ }
+ 
+ #define	MAX_PATH_LEN	256
+ 
+ static void CreateNewFolder(void * name)
+ {
+ 	char *dir, *parent, *ans;
+ 	long len;
+ 
+ 	do {
+ 		ans = (char *)fl_show_input("Create New Folder as:", name);
+ 		if (ans == NULL)
+ 			break;
+ 		if (strlen(ans) < MAX_PATH_LEN)
+ 			break;
+ 		fl_show_alert("Too long", "", "", 0);
+ 	} while (0);
+ 
+ 	parent = (char *)fl_get_directory();
+ 	len = strlen(parent) + MAX_PATH_LEN;
+ 	dir = malloc(len);
+ 	if (dir == NULL) {
+ 		fl_show_alert("ERROR:", "NO memory", "", 0);
+ 		return;
+ 	}
+ 
+ 	strcpy(dir, parent);
+ 	strcat(dir, "/");
+ 	strcat(dir, ans);
+ 
+ 	if (mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
+ 		fl_show_alert("Cannot create", dir, "", 0);
+ 	free(dir);
+ 	fl_refresh_fselector();
+ }
+ #endif
  
  static void HandleMenu( int hand )
  {
***************
*** 834,845 ****
--- 974,993 ----
                    switch( item )
                    {   case(1):  /* Open */
                                  if( NumMolecules < MAX_MOLECULES )
+ #ifdef XFORMSLIB
+                                     HandleFileOpen();
+ #else
                                      ResetCommandLine(2);
+ #endif
                                  break;
  
                        case(2):  /* Save As */
                                  if( Database )
+ #ifdef	XFORMSLIB
+                                     HandleFileSave(0);
+ #else
                                      ResetCommandLine(4);
+ #endif
                                  break;
  
                        case(3):  /* Close */
***************
*** 1069,1076 ****
--- 1217,1228 ----
                    break;
  
          case(5):  /* Export Menu */
+ #ifdef	XFORMSLIB
+                   HandleFileSave(item);
+ #else
                    ResetCommandLine(3);
                    StateOption = item;
+ #endif
                    break;
  
          case(6):  /* Help Menu */
***************
*** 1450,1455 ****
--- 1602,1635 ----
      }
  }
  
+ #ifdef XFORMSLIB
+ static void InitialiseFSDialogs(void)
+ {
+     FD_FSELECTOR *fs;
+ 
+     if ( ! Interactive )
+ 	return;
+ 
+ /*  fl_initialize(&argc, argv, VersionStr, 0, 0);  */
+     fl_init();
+ 
+     /* Open File Dialog */
+     fl_use_fselector(XFORMS_OPENDIALOG);
+     fl_set_fselector_fontsize(XFORMS_FONTSIZE);
+     fs = fl_get_fselector_fdstruct();
+     fl_set_object_label(fs->ready, "Load");
+     fl_fit_object_label(fs->ready, 1, 1);
+ 
+     /* Save File Dialog */
+     fl_use_fselector(XFORMS_SAVEDIALOG);
+     fl_set_fselector_fontsize(XFORMS_FONTSIZE);
+     fl_add_fselector_appbutton("New Folder", CreateNewFolder, (void *)"Untitled") ;
+     fs = fl_get_fselector_fdstruct();
+     fl_set_object_label(fs->ready, "Save as");
+     fl_fit_object_label(fs->ready, 1, 1);
+ 
+ }
+ #endif
  
  int main( int argc, char *argv[] )
  {
***************
*** 1500,1505 ****
--- 1680,1689 ----
          {   WriteString("No suitable display detected!\n");
          } else WriteString("Display window disabled!\n");
      }
+ 
+ #ifdef XFORMSLIB
+     InitialiseFSDialogs();
+ #endif
  
      InitialiseCmndLine();
      InitialiseCommand();
