[med-svn] r121 - trunk/packages/seaview/trunk

Charles Plessy charles-guest at costa.debian.org
Fri Sep 22 05:38:12 UTC 2006


Author: charles-guest
Date: 2006-09-22 05:38:11 +0000 (Fri, 22 Sep 2006)
New Revision: 121

Added:
   trunk/packages/seaview/trunk/Makefile
   trunk/packages/seaview/trunk/README
   trunk/packages/seaview/trunk/custom.cxx
   trunk/packages/seaview/trunk/pdf.cxx
   trunk/packages/seaview/trunk/postscript.cxx
Removed:
   trunk/packages/seaview/trunk/makefile
   trunk/packages/seaview/trunk/old_file_chooser.cxx
Modified:
   trunk/packages/seaview/trunk/align.cxx
   trunk/packages/seaview/trunk/chooser_plus.cxx
   trunk/packages/seaview/trunk/load_seq.cxx
   trunk/packages/seaview/trunk/mac_pc_extras.cxx
   trunk/packages/seaview/trunk/nexus.cxx
   trunk/packages/seaview/trunk/resource.cxx
   trunk/packages/seaview/trunk/seaview.cxx
   trunk/packages/seaview/trunk/seaview.h
   trunk/packages/seaview/trunk/seaview.help
   trunk/packages/seaview/trunk/seaview_align.sh
   trunk/packages/seaview/trunk/use_mase_files.cxx
Log:
new upstream version

Copied: trunk/packages/seaview/trunk/Makefile (from rev 116, trunk/packages/seaview/branches/upstream/current/Makefile)
===================================================================
--- trunk/packages/seaview/trunk/Makefile	                        (rev 0)
+++ trunk/packages/seaview/trunk/Makefile	2006-09-22 05:38:11 UTC (rev 121)
@@ -0,0 +1,49 @@
+#this makefile has 2 targets
+#seaview    (default target) for standard unix/linux compilation
+#seaviewps  does not use the PDFLibLite library and outputs postscript 
+
+#customize these next 3 lines
+FLTK = ../fltk-1.1.6
+PDF = ../PDFlib-Lite-6.0.1/libs/pdflib
+X11 = /usr/X11R6
+
+#comment out and customize next line to set helpfile name at compile-time
+#HELP_NOT_IN_PATH = -DDEFAULT_HELPFILE=\"/bge/mgouy/seaview/seaview.help\"
+
+CXX = g++
+
+OPT = $(shell if [ '$(DEBUG)' = '' ]; then echo '-O2'; else echo '-O0'; fi)
+
+STDCFLAGS  = -Dunix  -c $(OPT) -I$(FLTK) -I$(X11)/include $(DEBUG) $(HELP_NOT_IN_PATH)
+
+CFLAGS = $(STDCFLAGS) -I$(PDF)
+PDFLIBS = -L$(PDF) -lpdf 
+
+
+#conditional macros 
+seaviewps : CFLAGS = $(STDCFLAGS) -DNO_PDF -DNO_CLUSTALW
+
+
+OBJECTS = custom.o use_mase_files.o regions.o load_seq.o align.o xfmatpt.o comlines.o chooser_plus.o resource.o nexus.o
+
+
+seaview : seaview.o $(OBJECTS) pdf.o
+	$(CXX) $(DEBUG)  seaview.o $(OBJECTS) pdf.o \
+			-L$(FLTK)/lib -lfltk \
+			$(PDFLIBS)   \
+             -L$(X11)/lib -lX11 \
+             -o seaview \
+             -lm        
+
+seaviewps : seaview.o $(OBJECTS) postscript.o
+	$(CXX) $(DEBUG)  seaview.o $(OBJECTS) postscript.o \
+			-L$(FLTK)/lib -lfltk \
+             -L$(X11)/lib -lX11 \
+             -o seaview \
+             -lm        
+
+
+.SUFFIXES:	.cxx .h .o
+
+.cxx.o :
+	$(CXX) $(CFLAGS) $<

Copied: trunk/packages/seaview/trunk/README (from rev 116, trunk/packages/seaview/branches/upstream/current/README)
===================================================================
--- trunk/packages/seaview/trunk/README	                        (rev 0)
+++ trunk/packages/seaview/trunk/README	2006-09-22 05:38:11 UTC (rev 121)
@@ -0,0 +1,13 @@
+Compilation instructions under unix/linux
+
+- the FLTK library is needed
+
+- optionally, the PDFLib Lite library is used: 
+	make 
+will use it but 
+	make seaviewps 
+will not to use it and will create a postscript-producing executable.
+
+- modify the Makefile to reflect locations of FLTK, PDFLib Lite include files and libraries.
+
+- optionally, comment out and customize the HELP_NOT_IN_PATH line in Makefile to set helpfile name at compile-time. If not done, file seaview.help is searched in all directories of the PATH.

Modified: trunk/packages/seaview/trunk/align.cxx
===================================================================
--- trunk/packages/seaview/trunk/align.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/align.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -1,9 +1,15 @@
 #include "seaview.h"
 #include <stdlib.h>
 #include <ctype.h>
+#ifdef unix
+#include <unistd.h>
+#endif
 #ifndef WIN32
 #include <FL/x.H>
+#endif
+#if defined(__APPLE__) && TARGET_RT_MAC_MACHO
 #include <unistd.h>
+#include <sys/stat.h>
 #endif
 
 
@@ -11,8 +17,9 @@
 int save_part_as_pir(int debut, int fin, char **sequence, char **seqname, 
 	int *sel_seqs, int tot_seqs, char *fname, int *withU, int *empty_seq,
 	int *num_longest, int protein);
-int replace_align_part(SEA_VIEW *view, int debut, int fin, char *fname, int withU, int num_longest);
-void align_selected_parts(SEA_VIEW *view);
+int replace_align_part(SEA_VIEW *view, int debut, int fin, char *fname, int withU, int num_longest,
+	int has_phylip_format);
+void align_selected_parts(SEA_VIEW *view, int align_algorithm);
 int calc_gap_sites(char *old_seq, char *new_seq, int lold, int lnew, 
 	gap_site *gap_sites, int maxsites);
 int insert_gaps_new_align(char **seq, int site, int number, int numseqs, 
@@ -28,12 +35,14 @@
 int mysystem(const char *command);
 }
 #elif defined(__APPLE__)
+#if TARGET_RT_MAC_MACHO
+int my_system_macho(char *command, char *base_fname);
+extern "C" { char *MG_GetBundleResourcesDir(void); }
+#else
 void *my_run_program(char *prog, char *arguments, int flavor);
 void loop_till_program_ends(void *psn);
-extern "C" {
-	void MG_FSSpecToPathname (FSSpec *myFSS, char *fname, int maxl);
-	char *get_prog_dir(void);
-	}
+extern "C" { char *get_prog_dir(void); }
+#endif
 #else
 void change_attr(Fl_Window *w);
 #endif
@@ -95,36 +104,37 @@
 return retval;		
 }
 
-static char tmpdir[] = "/tmp/seaviewXXXXXX";
 
-static void remove_tmpdir(void)
+void align_selected_parts(SEA_VIEW *view, int align_algorithm)
 {
-rmdir(tmpdir);
-}
-
-void align_selected_parts(SEA_VIEW *view)
-{
 int debut, fin, status, withU, empty_seq, num_longest, l;
 char *p, *q;
 static char base_fname[100], commande[300];
 FILE *in;
-static int first = TRUE;
 static char *prog_path;
+static char algo_name[2][20] = {"clustalw", "muscle"};
 
-if(first) { /* check for presence of xterm + clustalw + seaview_align.sh */
-	if(mkdtemp(tmpdir) == NULL || atexit(remove_tmpdir)) {
-		fl_alert("Cannot create temporary directory");
-		return;
-		}
-	sprintf(base_fname, "%s/align", tmpdir);
-	first = FALSE;
+/* check for presence of xterm + clustalw/muscle + seaview_align.sh */
 #ifdef WIN32
-	status = check_path("clustalw.exe");
-#elif defined(__APPLE__) // need clustalw in same directory as seaview
+	p = (char *)(align_algorithm == CLUSTALW ? "clustalw.exe" : "muscle.exe" ); 
+	status = check_path( p ); 
+#elif defined(__APPLE__) /* need clustalw in same directory as seaview */
+#if TARGET_RT_MAC_MACHO
+	p = MG_GetBundleResourcesDir();
+#else
 	p = get_prog_dir();
+#endif
 	if(p == NULL) status = 1;
 	else	{
-		strcpy(commande, p); strcat(commande, ":clustalw");
+		strcpy(commande, p); 
+#if TARGET_RT_MAC_MACHO
+switch ( align_algorithm ) {
+	case CLUSTALW : strcat(commande, "/clustalw"); break;
+	default : strcat(commande, "/muscle");
+	}
+#else
+		strcat(commande, align_algorithm == CLUSTALW ? ":clustalw" : ":muscle");
+#endif
 		in = fopen(commande, "r");
 		status = (in == NULL);
 		fclose(in);
@@ -132,9 +142,9 @@
 		strcpy(prog_path, commande);
 		}
 #else
-	status = check_path("clustalw");
+	status = check_path((char*)(align_algorithm == CLUSTALW ? "clustalw" : "muscle"));
 	if(status == 0) {
-		status = check_path("x-terminal-emulator");
+		status = check_path("xterm");
 		}
 	if(status == 0) {
 		status = check_path("seaview_align.sh");
@@ -143,18 +153,17 @@
 	if(status != 0) {
 		fl_message("Alignment operation is impossible because\n"
 #ifdef WIN32
-		  "program clustalw.exe\n"
+		  "program clustalw.exe/muscle.exe\n"
 #elif defined(__APPLE__)
-		  "program clustalw\n"
+		  "program clustalw/muscle\n"
 #else
-		  "one of the programs x-terminal-emulator, clustalw, seaview_align.sh\n"
+		  "one of the programs xterm, clustalw, muscle, seaview_align.sh\n"
 #endif
 		  "is missing");
 		((Fl_Menu_ *)view->menu_edit)->mode(ALIGN_SEQS,
 			FL_MENU_INACTIVE);
 		return;
 		}
-	}
 if(view->active_region == NULL || view->active_region->list == NULL ||
 	view->active_region->list->next != NULL || view->tot_sel_seqs <= 1) {
 	fl_message("Need to have exactly one block of selected sites\n"
@@ -162,12 +171,22 @@
 	return;
 	}
 #if !( defined(WIN32) || defined(__APPLE__) )
-// mettre fenetres en Backing Store State: WhenMapped
+/* mettre fenetres en Backing Store State: WhenMapped */
 change_attr( view->DNA_obj->window() ); 
 change_attr( view->dnawin ); 
 #endif
 debut = view->active_region->list->debut;
 fin = view->active_region->list->fin;
+#if  defined(WIN32) || defined(__APPLE__) 
+tmpnam(base_fname); 
+#else
+strcpy(base_fname, "/tmp/seaview.XXXXXX");
+if(mktemp(base_fname) == NULL) return;
+#endif
+/* 
+convertir en minuscules car clustalw n'accepte pas les majuscules ds filenames
+*/
+p = base_fname - 1; while( *(++p) != 0) *p = tolower( *p);
 #ifdef WIN32 /* pas de . et pas plus de 8 car */
 p = base_fname; while( ( q = strchr(p, '\\')) != NULL ) p = q + 1;
 p[8] = 0;
@@ -202,32 +221,61 @@
 
 /* pour memoire: clustalw retourne 1 ou -1 si erreur, autre chose = succes */
 #ifdef WIN32
-sprintf(commande, 
-	"clustalw.exe /align /infile=%s.pir /outfile=%s.phy /output=phylip /outorder=input ", 
-	base_fname, base_fname);
+switch (align_algorithm) {
+	case CLUSTALW : 
+		sprintf(commande, 
+		"clustalw.exe /align /infile=%s.pir /outfile=%s.out /output=phylip /outorder=input ", 
+		base_fname, base_fname); break;
+	default:
+		sprintf(commande, 
+		"muscle.exe  -in %s.pir -out %s.out -stable ", 
+		base_fname, base_fname); break;
+	}
 #elif defined(__APPLE__)
-
+#if TARGET_RT_MAC_MACHO
+switch (align_algorithm) {
+	case CLUSTALW : 
+		sprintf(commande, 
+	"#!/bin/sh\n\"%s\" -align -infile=%s.pir -outfile=%s.out -output=phylip -outorder=input ", 
+		prog_path, base_fname, base_fname); break;
+	default : 
+		sprintf(commande, 
+	"#!/bin/sh\n\"%s\" -in %s.pir -out %s.out  -stable ", 
+		prog_path, base_fname, base_fname);
+	}
+#else
 sprintf(commande, 
-	"/align /infile=%s.pir /outfile=%s.phy /output=phylip /outorder=input ", 
+	"/align /infile=%s.pir /outfile=%s.out /output=phylip /outorder=input ", 
 	base_fname, base_fname);
-
+#endif
 #else
-strcpy(commande, "x-terminal-emulator -T \"clustalw alignment\" -n clustalw -sb -sl 2000 "
-	"-e seaview_align.sh " );
+sprintf(commande, "xterm -T \"%s alignment\" -n %s -sb -sl 2000 "
+	"-e seaview_align.sh %s ", algo_name[align_algorithm], algo_name[align_algorithm], 
+	algo_name[align_algorithm]);
 l = strlen(commande);
-sprintf(commande + l, 
-	" %s -infile=%s.pir -outfile=%s.phy -output=phylip -outorder=input ", 
-	base_fname, base_fname, base_fname);
+switch (align_algorithm) {
+	case CLUSTALW : 
+		sprintf(commande + l, 
+		" %s -infile=%s.pir -outfile=%s.out -output=phylip -outorder=input ", 
+		base_fname, base_fname, base_fname); break;
+	default: 
+		sprintf(commande + l, 
+		" %s -in %s.pir -out %s.out -stable ", 
+		base_fname, base_fname, base_fname); break;
+	}
 #endif
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)view->bouton_props;
 props_menu_parts *props_parts = 
 		(props_menu_parts *)menu_props->user_data();
-status = menu_props->mode(props_parts->clustalopt) & FL_MENU_VALUE;
+status = menu_props->mode(props_parts->clustalopt + 2) & FL_MENU_VALUE;
 if(view->clustal_options != NULL && status ) 
 	sprintf(commande + strlen(commande), "%s", view->clustal_options);
 #ifdef WIN32
 status = mysystem(commande);
 #elif defined(__APPLE__)
+#if TARGET_RT_MAC_MACHO
+status = my_system_macho(commande, base_fname);
+#else
 void *psn = my_run_program(prog_path, commande, 'SvCw');
 if(psn != NULL) loop_till_program_ends(psn);
 status = 0;
@@ -235,6 +283,7 @@
 in = fopen(commande, "r");
 if(in == NULL) status = 1;
 else fclose(in);
+#endif
 #else
 status = system(commande);
 if( status == 0 ) {
@@ -248,7 +297,7 @@
 	else	status = 1;
 	}
 #endif
-sprintf(commande, "%s.phy", base_fname);
+sprintf(commande, "%s.out", base_fname);
 if( status == 0 ) {
 	in = fopen(commande, "r");
 	if(in != NULL) {
@@ -261,16 +310,19 @@
 if( status != 0 )
 	fl_message("Alignment operation ignored");
 else	{
-	status = replace_align_part(view, debut, fin, commande, withU, num_longest);
+	status = replace_align_part(view, debut, fin, commande, withU, num_longest,
+		(align_algorithm == CLUSTALW ? TRUE : FALSE) );
 	if(status) fl_alert("Not enough memory\nor\n" 
 		"max sequence length reached");
 	}
 sprintf(commande, "%s.pir", base_fname);
 remove(commande);
-sprintf(commande, "%s.phy", base_fname);
+sprintf(commande, "%s.out", base_fname);
 remove(commande);
-sprintf(commande, "%s.dnd", base_fname);
-remove(commande);
+if(align_algorithm == CLUSTALW) {
+	sprintf(commande, "%s.dnd", base_fname);
+	remove(commande);
+	}
 #ifndef WIN32
 sprintf(commande, "%s.status", base_fname);
 remove(commande);
@@ -314,7 +366,7 @@
 
 
 int replace_align_part(SEA_VIEW *view, int debut, int fin, char *fname, 
-	int withU, int num_longest)
+	int withU, int num_longest, int has_phylip_format)
 /* returns TRUE if error, FALSE if ok */
 {
 int num, lfrag, lpart, i, col, rang, retval, newlength, lfrag2;
@@ -326,7 +378,11 @@
 view->cursor_in_comment = FALSE;
 view->cursor_seq = view->first_seq;
 /* lecture de l'alignement multiple produit par clustalw */
-num = read_phylip_align(fname, &seq, &seqname, &comments, &pheader, &err_message);
+num = (has_phylip_format ?
+	read_phylip_align(fname, &seq, &seqname, &comments, &pheader, &err_message)
+	:
+	read_fasta_align(fname, &seq, &seqname, &comments, &pheader, &err_message)
+	);
 for(i = 0; i < num; i++) free(seqname[i]);
 if(num > 0) { free(seqname); free(comments); }
 if(num != view->tot_sel_seqs) { if(num > 0) free(seq); return TRUE; }
@@ -547,6 +603,45 @@
 
 #if defined(__APPLE__)
 
+#if TARGET_RT_MAC_MACHO
+
+int my_system_macho(char *command, char *base_fname)
+{
+char comfile[300];
+FILE *out;
+FSRef myref, myterm, frontproc;
+LSLaunchFSRefSpec mylaunch;
+OSStatus status;
+ProcessSerialNumber newpsn;
+
+sprintf(comfile, "%s.command", base_fname);
+out = fopen(comfile, "w");
+fprintf(out, "%s\n", command);
+fclose(out);
+chmod(comfile, S_IRUSR|S_IXUSR);
+status = FSPathMakeRef((const UInt8 *)comfile, &myref, NULL);
+LSFindApplicationForInfo(kLSUnknownCreator, CFSTR("com.apple.terminal"), NULL, &myterm, NULL);
+mylaunch.appRef = &myterm; // FSRef to the Terminal application
+mylaunch.numDocs = 1;
+mylaunch.itemRefs = &myref;
+mylaunch.passThruParams = NULL;
+mylaunch.launchFlags =  kLSLaunchNewInstance ; // run a new Terminal instance
+mylaunch.asyncRefCon = NULL;
+status = LSOpenFromRefSpec(&mylaunch, &frontproc); // frontproc becomes FSRef to newly started Terminal
+if(status == noErr) {
+	GetFrontProcess(&newpsn); // the newly started Terminal
+    sleep(2);
+	fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_BLACK);
+	status = fl_ask("Wait for alignment completion in Terminal window.\nIs it completed ?") ? 0 : 1 ; 
+	// try to kill only a newly started Terminal and not something else
+	if( FSCompareFSRefs(&frontproc, &myterm) == noErr) KillProcess(&newpsn);
+	}
+unlink(comfile);
+return status != noErr;
+}
+
+#else
+
 void loop_till_program_ends(void *psn)
 {
 ProcessInfoRec pinfo;
@@ -597,6 +692,7 @@
 return ( err == noErr ? pinfo : NULL) ;
 }
 
+#endif
 
 #elif !defined(WIN32)
 

Modified: trunk/packages/seaview/trunk/chooser_plus.cxx
===================================================================
--- trunk/packages/seaview/trunk/chooser_plus.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/chooser_plus.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -1,78 +1,69 @@
 #include "seaview.h"
-#include "FL/Fl_Group.H"
-#include "FL/Fl_Menu.H"
-#include "FL/Fl_Menu_.H"
-#include "FL/Fl_Browser_.H"
-#include "FL/filename.H"
-#include "FL/Fl_Button.H"
-#include "FL/Fl_Check_Button.H"
+#include <FL/Fl_File_Chooser.H>
+#include <FL/Fl_Choice.H>
 
-
 /* included functions */
-char* fl_file_chooser_plus(const char* message, const char* pat, 
-	const char* fname, int use_only_button);
 char* fl_file_chooser_save_as(const char* message, const char* pat, 
 	const char* fname, void *view);
 #ifdef __APPLE__
+char* fl_file_chooser_plus(const char* message, const char* pat, 
+	const char* fname, int use_only_button);
 int MG_GetOutputFName_Popup(char *fname, int maxl, char *dfault, void *data, int defaultformat);
-int MG_GetOutputFName_Plus(char *fname, int maxl, char *dfault, char *message);
-#else
-int change_bouton_label(Fl_Widget *obj, char *message);
-void change_block(Fl_Widget *obj, void *data);
-void change_cpl(Fl_Widget *obj, void *data);
-void change_lpp(Fl_Widget *obj, void *data);
-void change_vary(Fl_Widget *obj, void *data);
+int MG_GetOutputFName_Plus(char *fname, int maxl, char *dfault, char *message, int);
+#elif defined(WIN32)
+char *MG_win32_file_chooser(const char* message,
+        const char* pattern,
+        const char* fname,
+        const char* defext, // default filename extension or NULL
+        bool save, int *pfilterindex);
 #endif
 
 
 
 // needed functions
+extern void set_save_format(SEA_VIEW *view, int val);
 #ifdef __APPLE__
+extern int set_res_value(const char *name, const char *value);
 extern "C" {  
-	void MG_FSSpecToPathname (FSSpec *myFSS, char *fname, int maxl);
 	void PtoC(const void *in, void *out);
 	void CtoP(const void *in, void *out);
-	}
-extern void set_save_format(SEA_VIEW *view, int val);
+#if TARGET_RT_MAC_MACHO
+#	define mac_os_x()  1
 #else
-extern void change_format(Fl_Widget *obj, void *data);
+	int mac_os_x(void);
 #endif
+	}
+#endif
 
 extern int nbr_formats;
 extern char *f_format_names[];
-extern int printout_block, printout_cpl, printout_lpp;
-extern int printout_vary;
+extern int printout_block, printout_fontsize;
+extern int printout_vary, printout_black;
+extern paperformat printout_pageformat;
 
 
 #ifdef __APPLE__
 
-
 static pascal void MyNavEventProc_popup (NavEventCallbackMessage callBackSelector,
                                    NavCBRecPtr callBackParms,
                                    NavCallBackUserData callBackUD)
 {
-NavMenuItemSpec *p;
 SEA_VIEW *view;
 int num;
-char f_name[20];
 OSErr err;
+NavMenuItemSpec tempitem, *p;
 
 view = (SEA_VIEW *)callBackUD;
-if(callBackSelector == kNavCBStart) {
-/*	il faut beaucoup d'imagination pour arriver à faire marcher ce call */
-	NavMenuItemSpec item;
-	CtoP(f_format_names[view->format_for_save], item.menuItemName);
-	item.version = kNavMenuItemSpecVersion;
-	item.menuCreator = 'extn';  // nécessaire
-	item.menuType = view->format_for_save ;
-	err = NavCustomControl(callBackParms->context, kNavCtlSelectCustomType, &item ); 
+if(callBackSelector == kNavCBStart) { // fixer la valeur montrŽe du menu popup format: 
+	tempitem.version = kNavMenuItemSpecVersion; //procedure non documentee mais qui semble correcte
+	tempitem.menuCreator = 'extn';
+	tempitem.menuType = view->format_for_save;
+	*(tempitem.menuItemName) = '\0';	// needed on 10.3+
+	err = NavCustomControl(callBackParms->context, kNavCtlSelectCustomType, (void *)&tempitem );
 	}
-else if(callBackSelector == kNavCBPopupMenuSelect) {
+else if(callBackSelector == kNavCBPopupMenuSelect) { // action sur le menu format: 
 	p = (NavMenuItemSpec *)(callBackParms->eventData.eventDataParms.param);
-	PtoC(p->menuItemName, f_name);
-	for(num = 0; num < nbr_formats; num++ ) {
-		if(strcmp(f_format_names[num], f_name) == 0) break;
-		}
+	num = p->menuType;
 	set_save_format(view, num);
 	}
 return;
@@ -82,91 +73,58 @@
 int MG_GetOutputFName_Popup(char *fname, int maxl, char *dfault, void *data, int defaultformat)
 {
     OSErr               anErr = noErr;
+	Boolean ok;
     NavReplyRecord      reply;
-    NavDialogOptions    dialogOptions;
-    FSSpec              fss;
+static NavDialogCreationOptions    dialogOptions;
     OSType              fileTypeToSave = 'TEXT';
     OSType              creatorType;
-    NavEventUPP         eventProc = NewNavEventUPP (MyNavEventProc_popup);
-	char                filename [256];
- 	Handle h; 
- 	NavMenuItemSpec *p;
-	int    i, rsult = FALSE;
+static NavEventUPP  eventProc;
+    int  i, rsult = FALSE;
+  NavDialogRef        navDialog;
+static CFArrayRef formatitems=NULL; 
+  CFStringRef *typeitem;
 
-    anErr = NavGetDefaultDialogOptions (&dialogOptions);
-    if (anErr == noErr)
-    {
-    CtoP("seaview : save", dialogOptions.windowTitle);
-    dialogOptions.dialogOptionFlags &= ~ kNavNoTypePopup;
-    dialogOptions.dialogOptionFlags &= ~ kNavAllowStationery;
-	h = NewHandle(nbr_formats * sizeof(NavMenuItemSpec));
-	HLock(h);	p = (NavMenuItemSpec *)*h;
-	for(i = 0; i < nbr_formats; i++) {
-		p->version = kNavMenuItemSpecVersion;
-		CtoP(f_format_names[i], p->menuItemName);
-		p->menuCreator = 'extn';  // nécessaire
-		p->menuType = i ;  // nécessaire
-		p++;
-		}
-	HUnlock(h);
-    dialogOptions.popupExtension = (NavMenuItemSpecArrayHandle)h;
-    reply.translationNeeded = false;
-
-
-            //  One way to get the name for the file to be saved.
-			CtoP(dfault, dialogOptions.savedFileName);
-
-            creatorType = kNavGenericSignature;
-            anErr = NavPutFile( NULL, &reply, &dialogOptions, eventProc,
-                                fileTypeToSave, creatorType, data );
-            if (anErr == noErr && reply.validRecord)
-            {
-                AEKeyword   theKeyword;
-                DescType    actualType;
-                Size        actualSize;
-                FSSpec      documentFSSpec;
-
-                anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS,
-                                    &theKeyword, &actualType,
-                                    &documentFSSpec, sizeof(documentFSSpec),
-                                    &actualSize );
+if(formatitems == NULL) { /* initialisation */
+    anErr = NavGetDefaultDialogCreationOptions (&dialogOptions);
+    if (anErr != noErr) return FALSE;    
+    dialogOptions.windowTitle = CFStringCreateWithCString(NULL, "seaview: Choose file and format", kCFStringEncodingMacRoman);
+    dialogOptions.optionFlags &= ~ kNavNoTypePopup;
+    dialogOptions.optionFlags &= ~ kNavAllowStationery;
+	typeitem = (CFStringRef *)malloc(sizeof(CFStringRef) * nbr_formats);
+    for(i = 0; i < nbr_formats; i++)     
+		typeitem[i] = CFStringCreateWithCString(NULL, f_format_names[i], kCFStringEncodingMacRoman);
+    formatitems = CFArrayCreate(NULL, (const void **)typeitem, nbr_formats, NULL);
+    dialogOptions.popupExtension = formatitems;
+    eventProc = NewNavEventUPP (MyNavEventProc_popup);
+    }
+  dialogOptions.saveFileName = CFStringCreateWithCString(NULL, dfault, kCFStringEncodingUTF8); 
+creatorType = kNavGenericSignature;
+  anErr = NavCreatePutFileDialog( &dialogOptions, fileTypeToSave, creatorType, eventProc, data, &navDialog );
+  CFRelease(dialogOptions.saveFileName);
+  if(anErr != noErr) return FALSE;
+  
+  anErr = NavDialogRun( navDialog );
+  if(anErr != noErr) return FALSE;
+  
+  anErr = NavDialogGetReply( navDialog, &reply );
+  if ( reply.validRecord && anErr == noErr ) {
+				FSRef fileRef;
+				CFURLRef directoryURL, fileURL;
+				
+				anErr = AEGetNthPtr( &reply.selection, 1, typeFSRef, NULL, NULL, &fileRef, sizeof( FSRef ), NULL );
                 if (anErr == noErr)
                 {
-                    if (reply.replacing)
-                    { /* compute the pathname of the pre-existing file */
-                        MG_FSSpecToPathname (&documentFSSpec, fname, maxl);
-                        rsult = TRUE;
-                    }
-                    else
-                    { /* the chosen file is new, compute pathname to its directory
-                    and append new filename */
-                        char empty[256];
-                        FSSpec pfss;
-                        empty[0] = 0;
-                   /* make an FSSpec from volume + parentID of documentFSSpec
-                   */
-                        FSMakeFSSpec(documentFSSpec.vRefNum, documentFSSpec.parID,
-                        	(StringPtr) empty, &pfss);
-                   /* compute pathname for this FSSpec
-                   */
-                        MG_FSSpecToPathname (&pfss, fname, maxl);
-                        /* append : new filename to this path
-                        */
-                        strcat(fname, ":");
-                        PtoC(documentFSSpec.name, fname + strlen(fname) );
-
-                        rsult = TRUE;
-                    }
-
-                        // DO NOT call NavCompleteSave() to complete
-                         anErr = NavCompleteSave(&reply,
-                                                kNavTranslateInPlace); 
+						directoryURL = CFURLCreateFromFSRef( kCFAllocatorDefault, &fileRef );
+                        // append new filename to this path
+						fileURL = CFURLCreateCopyAppendingPathComponent( kCFAllocatorDefault, directoryURL, reply.saveFileName, false );
+						ok = CFURLGetFileSystemRepresentation(fileURL, true, (UInt8 *)fname, maxl);
+						CFRelease(fileURL); CFRelease(directoryURL);
+                        if(ok) rsult = TRUE;
                 }
-                (void) NavDisposeReply(&reply);
-            }
-        DisposeNavEventUPP(eventProc);
-    }
-    return rsult;
+	}
+NavDisposeReply(&reply);
+if(!rsult) set_save_format((SEA_VIEW *)data, defaultformat);
+return rsult;
 }
 
 
@@ -175,7 +133,7 @@
 {
 	static char pathname[FL_PATH_MAX];
 	SEA_VIEW *view = (SEA_VIEW *)data;
-	if( MG_GetOutputFName_Popup(pathname, FL_PATH_MAX, (char *)fname, data, 
+	if( MG_GetOutputFName_Popup(pathname, FL_PATH_MAX, extract_filename((char *)fname), data, 
 						view->format_for_save) ) return pathname;
 	else return NULL;
 }
@@ -186,17 +144,18 @@
                                    NavCallBackUserData callBackUD)
 {
 OSErr err;
-static Handle gDitlList;
+static Handle gDitlList = NULL;
 static DialogItemIndex index;
 static DialogRef ref;
-Rect rect; Handle h; DialogItemType dtype; Str255 text;
+static ControlRef var_control = NULL;
+Rect rect; Handle h; DialogItemType dtype; Str255 text; ControlRef control;
 char text2[256];
 
 if(callBackSelector == kNavCBCustomize) {
 	if(callBackParms->customRect.bottom == 0) 
 			callBackParms->customRect.bottom = callBackParms->customRect.top + 35;
 	if(callBackParms->customRect.right == 0) 
-			callBackParms->customRect.right = callBackParms->customRect.left + 400;
+			callBackParms->customRect.right = callBackParms->customRect.left + 425;
 	}
 else if(callBackSelector == kNavCBStart) {
 	gDitlList = GetResource ('DITL', 128);
@@ -205,114 +164,131 @@
     err = NavCustomControl(callBackParms->context, kNavCtlGetFirstControlID, &index);
     index++;
     ref = GetDialogFromWindow(callBackParms->window);
-	sprintf(text2,"%3d", printout_block);
+	sprintf(text2,"%2d", printout_block);
 	CtoP(text2, text);
 	GetDialogItem(ref, index + 1, &dtype, &h, &rect);
 	SetDialogItemText(h, text);
-	sprintf(text2,"%3d", printout_cpl);
+	sprintf(text2,"%2d", printout_fontsize);
 	CtoP(text2, text);
 	GetDialogItem(ref, index + 3, &dtype, &h, &rect);
 	SetDialogItemText(h, text);
-	sprintf(text2,"%3d", printout_lpp);
-	CtoP(text2, text);
-	GetDialogItem(ref, index + 5, &dtype, &h, &rect);
-	SetDialogItemText(h, text);
+	err = GetDialogItemAsControl(ref, index + 4, &control);
+	if(err == 0) SetControl32BitValue(control, printout_black);
+	
+	err = GetDialogItemAsControl(ref, index + 5, &control);
+	if(err == 0) SetControl32BitValue(control, printout_pageformat == 0);
+	err = GetDialogItemAsControl(ref, index + 6, &control);
+	if(err == 0) SetControl32BitValue(control, printout_pageformat == 1);
+
+	err = GetDialogItemAsControl(ref, index + 7, &var_control);
+	if(err == 0) SetControl32BitValue(var_control, printout_vary);
+	if(*(int *)callBackUD) ActivateControl(var_control);
+	else DeactivateControl(var_control);
 	}
 else if(callBackSelector == kNavCBTerminate) {
-	GetDialogItem(ref, index + 1, &dtype, &h, &rect);
-	GetDialogItemText(h, text);
-	PtoC(text, text2);
-	sscanf(text2,"%d", &printout_block);
-	GetDialogItem(ref, index + 3, &dtype, &h, &rect);
-	GetDialogItemText(h, text);
-	PtoC(text, text2);
-	sscanf(text2,"%d", &printout_cpl);
-	GetDialogItem(ref, index + 5, &dtype, &h, &rect);
-	GetDialogItemText(h, text);
-	PtoC(text, text2);
-	sscanf(text2,"%d", &printout_lpp);
-	if(gDitlList != NULL) ReleaseResource( gDitlList );
+	if(gDitlList != NULL) {
+		GetDialogItem(ref, index + 1, &dtype, &h, &rect);
+		GetDialogItemText(h, text);
+		PtoC(text, text2);
+		sscanf(text2,"%d", &printout_block);
+		GetDialogItem(ref, index + 3, &dtype, &h, &rect);
+		GetDialogItemText(h, text);
+		PtoC(text, text2);
+		sscanf(text2,"%d", &printout_fontsize);
+		set_res_value("printoutfontsize", text2);
+		ReleaseResource( gDitlList );
+		}
+	var_control = NULL;
 	}
+else if(callBackSelector == kNavCBEvent ) {
+	if(var_control != NULL && callBackParms->eventData.itemHit == index + 7) {
+		static int count = 0; /* MacOS 9: passe 2 fois a chaque click sur check box */
+		if( mac_os_x() || (++count) % 2 == 0 ) {
+			printout_vary = (printout_vary + 1) % 2;
+			SetControl32BitValue(var_control, printout_vary);
+			}
+		}
+	else if(callBackParms->eventData.itemHit == index + 4) {
+		static int count = 0; /* MacOS 9: passe 2 fois a chaque click sur check box */
+		if( mac_os_x() || (++count) % 2 == 0 ) {
+			printout_black = (printout_black + 1) % 2;
+			GetDialogItemAsControl(ref, index + 4, &control);
+			SetControl32BitValue(control, printout_black);
+			}
+		}
+	else if(callBackParms->eventData.itemHit == index + 5) {
+		if(printout_pageformat == LETTER) {
+				GetDialogItemAsControl(ref, index + 5, &control);
+				SetControl32BitValue(control, 1);
+				GetDialogItemAsControl(ref, index + 6, &control);
+				SetControl32BitValue(control, 0);
+				printout_pageformat = A4;
+				}
+		}
+	else if(callBackParms->eventData.itemHit == index + 6) {
+		if(printout_pageformat == A4) {
+				GetDialogItemAsControl(ref, index + 6, &control);
+				SetControl32BitValue(control, 1);
+				GetDialogItemAsControl(ref, index + 5, &control);
+				SetControl32BitValue(control, 0);
+				printout_pageformat = LETTER;
+				}
+		}
+	}
 return;
 }
 
 
-int MG_GetOutputFName_Plus(char *fname, int maxl, char *dfault, char *message)
+int MG_GetOutputFName_Plus(char *fname, int maxl, char *dfault, char *message, int use_only_button)
 {
     OSErr               anErr = noErr;
     NavReplyRecord      reply;
-    NavDialogOptions    dialogOptions;
-    FSSpec              fss;
+    NavDialogRef        navDialog;
+    NavDialogCreationOptions    dialogOptions;
     OSType              fileTypeToSave = 'TEXT';
     OSType              creatorType;
     NavEventUPP         eventProc = NewNavEventUPP (MyNavEventProc_Plus);
-	char                filename [256];
- 	NavMenuItemSpec *p;
-	int    i, rsult = FALSE;
+	int    rsult = FALSE;
+	static int *p_use;
+    Boolean ok;
 
-    anErr = NavGetDefaultDialogOptions (&dialogOptions);
-    if (anErr == noErr)
-    {
-    CtoP(message, dialogOptions.windowTitle);
-    dialogOptions.dialogOptionFlags |= kNavNoTypePopup;
-    dialogOptions.dialogOptionFlags &= ~ kNavAllowStationery;
-    reply.translationNeeded = false;
+    anErr = NavGetDefaultDialogCreationOptions (&dialogOptions);
+	if(anErr != noErr) return FALSE;
+    dialogOptions.windowTitle = CFStringCreateWithCString(NULL, message, kCFStringEncodingMacRoman);
+    dialogOptions.optionFlags |= kNavNoTypePopup;
+    dialogOptions.optionFlags &= ~ kNavAllowStationery;
+    dialogOptions.saveFileName = CFStringCreateWithCString(NULL, dfault, kCFStringEncodingUTF8); 
 
-
-            //  One way to get the name for the file to be saved.
-			CtoP(dfault, dialogOptions.savedFileName);
-
-            creatorType = kNavGenericSignature;
-            anErr = NavPutFile( NULL, &reply, &dialogOptions, eventProc,
-                                fileTypeToSave, creatorType, NULL );
-            if (anErr == noErr && reply.validRecord)
-            {
-                AEKeyword   theKeyword;
-                DescType    actualType;
-                Size        actualSize;
-                FSSpec      documentFSSpec;
-
-                anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS,
-                                    &theKeyword, &actualType,
-                                    &documentFSSpec, sizeof(documentFSSpec),
-                                    &actualSize );
+	creatorType = kNavGenericSignature;
+	p_use = &use_only_button;
+  anErr = NavCreatePutFileDialog( &dialogOptions, fileTypeToSave, creatorType, eventProc, p_use, &navDialog );
+  CFRelease(dialogOptions.saveFileName);
+  if(anErr != noErr) return FALSE;
+  
+  anErr = NavDialogRun( navDialog );
+  if(anErr != noErr) return FALSE;
+  
+  anErr = NavDialogGetReply( navDialog, &reply );
+  
+ if (anErr == noErr && reply.validRecord) {
+				FSRef fileRef;
+				CFURLRef directoryURL, fileURL;
+				
+				anErr = AEGetNthPtr( &reply.selection, 1, typeFSRef, NULL, NULL, &fileRef, sizeof( FSRef ), NULL );
                 if (anErr == noErr)
                 {
-                    if (reply.replacing)
-                    { /* compute the pathname of the pre-existing file */
-                        MG_FSSpecToPathname (&documentFSSpec, fname, maxl);
-                        rsult = TRUE;
-                    }
-                    else
-                    { /* the chosen file is new, compute pathname to its directory
-                    and append new filename */
-                        char empty[256];
-                        FSSpec pfss;
-                        empty[0] = 0;
-                   /* make an FSSpec from volume + parentID of documentFSSpec
-                   */
-                        FSMakeFSSpec(documentFSSpec.vRefNum, documentFSSpec.parID,
-                        	(StringPtr) empty, &pfss);
-                   /* compute pathname for this FSSpec
-                   */
-                        MG_FSSpecToPathname (&pfss, fname, maxl);
-                        /* append : new filename to this path
-                        */
-                        strcat(fname, ":");
-                        PtoC(documentFSSpec.name, fname + strlen(fname) );
-
-                        rsult = TRUE;
-                    }
-
-                        // DO NOT call NavCompleteSave() to complete
-                         anErr = NavCompleteSave(&reply,
-                                                kNavTranslateInPlace); 
+						directoryURL = CFURLCreateFromFSRef( kCFAllocatorDefault, &fileRef );
+                        // append new filename to this path
+						fileURL = CFURLCreateCopyAppendingPathComponent( kCFAllocatorDefault, directoryURL, reply.saveFileName, false );
+						ok = CFURLGetFileSystemRepresentation(fileURL, true, (UInt8 *)fname, maxl);
+						CFRelease(fileURL); CFRelease(directoryURL);
+                        if(ok) rsult = TRUE;
                 }
-                (void) NavDisposeReply(&reply);
-            }
-        DisposeNavEventUPP(eventProc);
-    }
-    return rsult;
+	}
+  DisposeNavEventUPP(eventProc);
+  NavDisposeReply( &reply );
+  NavDialogDispose( navDialog );
+return rsult;
 }
 
 
@@ -320,281 +296,126 @@
 	const char* fname, int use_only_button)
 {
 	static char pathname[FL_PATH_MAX];
-	if( MG_GetOutputFName_Plus(pathname, FL_PATH_MAX, (char *)fname, (char *)message ) ) return pathname;
+	if( MG_GetOutputFName_Plus(pathname, FL_PATH_MAX, (char *)fname, (char *)message, use_only_button) 
+		) return pathname;
 	else return NULL;
 }
 
 
-#else
+#elif defined(WIN32)
 
+extern char *f_format_names[];
+extern char *f_format_exts[];
+extern int nbr_formats;
 
-
-class FCB : public Fl_Browser_ {
-  void* item_first() const ;
-  void* item_next(void*) const ;
-  void* item_prev(void*) const ;
-  int item_height(const dirent*, int) const ;
-  int item_height(void*) const ;
-  int item_width(const dirent*) const ;
-  int item_width(void*) const ;
-  int item_quick_height(void*) const ;
-  int incr_height() const ;
-  void item_draw(void*, int, int, int, int) const ;
-  int checkdir(const dirent*, char*) const ;
-  void draw();
-  void clear_prev();
-public:
-  char listed[FL_PATH_MAX];// current dir & starname
-  int dirend;		// points after last / before starname
-  int nameend;		// length to trailing '*' or '\0'
-  const char* pattern;	// default pattern
-  dirent** list;	// the file names
-  dirent** last;	// pointer after end of list
-  const char* message;	// message if no file names
-  char preved[FL_PATH_MAX];// directory listed in prev
-  dirent** prev;	// cached list of another directory
-  dirent** prev_last;	// end of that list
-  int prev_count;
-  FCB(int x, int y, int w, int h) : Fl_Browser_(x, y, w, h, 0) {
-    type(FL_HOLD_BROWSER);
-    listed[0] = 0;
-    dirend = nameend = 1;
-    pattern = 0;
-    list = prev = 0;
-    message = 0;
-  }
-  // ~FCB nyi
-  void clear();
-  void set(const char*);
-  int get(char*);
-};
-
-class FCW : public Fl_Window {
-public:
-  int handle(int);
-  Fl_Input input;
-  Fl_Button* ok_button;
-  Fl_Button* cancel_button;
-  Fl_Button* normal_button;
-  Fl_Button* cwd_button;
-  FCB browser;
-  FCW() ;
-};
-
-#define PRINTOUT_LABEL_SIZE 30
-static char printout_label_block[PRINTOUT_LABEL_SIZE] = "block size=";
-static char printout_label_cpl[PRINTOUT_LABEL_SIZE] = "chars/line=";
-static char printout_label_lpp[PRINTOUT_LABEL_SIZE] = "lines/page=";
-static char printout_label_vary[PRINTOUT_LABEL_SIZE] = "variable sites only";
-
-
-int change_bouton_label(Fl_Widget *obj, char *message)
+char* fl_file_chooser_save_as(const char* message, const char* pat, 
+	const char* fname, void *view)
 {
-char *p, defaut[PRINTOUT_LABEL_SIZE], *b_label;
-int old_val, new_val;
-p = (char *)obj->label();
-p = strchr(p, '=') + 1;
-sscanf(p, "%d", &old_val);
-sprintf(defaut, "%d", old_val);
-p = (char *)fl_input(message, defaut);
-if(p == NULL) return old_val;
-new_val = -1; sscanf(p, "%d", &new_val);
-if( new_val == old_val || new_val <= 0) return old_val;
-b_label = (char *)malloc(PRINTOUT_LABEL_SIZE);
-strcpy(b_label, obj->label());
-p = strchr(b_label, '=') + 1;
-sprintf(p, "%d", new_val);
-free( (void *)obj->label() );
-obj->label(b_label);
-return new_val;
-}
+int filterindex;
+char *outfname, *p, types_list[500];
 
-void change_block(Fl_Widget *obj, void *data)
-{
-printout_block = change_bouton_label(obj, "Enter desired printout block size");
-}
+p = types_list;
+for(int f = 0; f < nbr_formats; f++) {
+	sprintf(p, "%s format (*.%s)%c*.%s%c", 
+		f_format_names[f], f_format_exts[f], 0, f_format_exts[f], 0);
+	p += strlen(p) + 1;
+	p += strlen(p) + 1;
+	}
+*p = 0;
 
-void change_cpl(Fl_Widget *obj, void *data)
-{
-printout_cpl = change_bouton_label(obj, 
-	"Enter desired number of residues per line");
+filterindex = ((SEA_VIEW *)view)->format_for_save + 1;
+outfname = MG_win32_file_chooser(message, 
+			types_list,
+			fname, 
+			memcmp(pat, "*.", 2) == 0 ? pat+2 : NULL,
+			TRUE, &filterindex);
+if(outfname != NULL) set_save_format((SEA_VIEW *)view, filterindex - 1);
+return outfname;
 }
 
-void change_lpp(Fl_Widget *obj, void *data)
-{
-printout_lpp = change_bouton_label(obj, 
-	"Enter desired number of lines per page");
-}
 
+#else
 
-void change_vary(Fl_Widget *obj, void *data)
-{
-Fl_Button *b = (Fl_Button *)obj;
-int etat = b->value();
-printout_vary = etat;
-}
 
 
 #define labelSize 10
 #define calc_width(nom) \
 	(fl_font(FL_HELVETICA, labelSize), (int)fl_width(nom) + 20)
+	
 
-
-char* fl_file_chooser_save_as(const char* message, const char* pat, 
-	const char* fname, void *view)
+void change_format(Fl_Widget *obj, void *data)
 {
-  static FCW* f; if (!f) f = new FCW();
-  f->ok_button->label(fl_ok);
-  f->cancel_button->label(fl_cancel);
+SEA_VIEW *view = (SEA_VIEW *)data;
+int reponse = ((Fl_Choice *)obj)->value();
+if(view->format_for_save != reponse) set_save_format(view, reponse);
+return;
+}
 
-  if (pat && !*pat) pat = 0;
-  if (fname && *fname) {
-    f->input.value(fname);
-  } else if (f->browser.pattern != pat && (!pat || !f->browser.pattern ||
-					   strcmp(pat,f->browser.pattern))) {
-    // if pattern is different, remove name but leave old directory:
-    const char* p = f->input.value();
-    const char* q = fl_filename_name(p);
-    f->input.value(p, q-p);
-  }
-  f->browser.pattern = pat;
-  f->normal_button->label(pat ? pat : "visible files");
-  f->browser.set(f->input.value());
-  f->input.position(10000, f->browser.dirend);
 
-  f->label(message);
-  f->hotspot(f);
+char *					// O - Filename or NULL
+fl_file_chooser_save_as(const char *message,	// I - Message in titlebar
+                const char *pat,	// I - Filename pattern
+		const char *fname,	// I - Initial filename selection
+		void        *data) 
+{	
+  static char	retname[1024];		// Returned filename
+static Fl_File_Chooser *fc;
+SEA_VIEW *view = (SEA_VIEW *)data;
+static Fl_Choice *mychoice;
 
-Fl_Button *bouton;
+  if (!fc) {
+      if (!fname || !*fname) fname = ".";
 
-bouton = new Fl_Button(2, f->ok_button->y(), 5, f->ok_button->h());
-char b_label[] = "change file format";
-fl_font(f->ok_button->labelfont(), f->ok_button->labelsize()); 
-bouton->size( (int)fl_width(b_label) + 10 , bouton->h() );
-bouton->label(b_label);
-bouton->callback(change_format, view);
-f->add(bouton);
+      fc = new Fl_File_Chooser(fname, pat, Fl_File_Chooser::CREATE, message);
+ 	  fc->preview(0);
+ 	  fc->previewButton->hide();
+ 	  static char c_label[] = "Format:";
+ 	  int y = fc->previewButton->y();
+	  fc->previewButton->parent()->begin();
+	  mychoice = new Fl_Choice(10 + calc_width(c_label), y, 150, fc->previewButton->h());
+ 	  fc->previewButton->parent()->end();
+	  for(int i=0; i < nbr_formats; i++) mychoice->add(f_format_names[i], 0, 0, 0, 0);
+      mychoice->label(c_label);
+      mychoice->callback(change_format, view);
+  } else {
+    fc->type(Fl_File_Chooser::CREATE);
+    fc->filter(pat);
+    fc->label(message);
 
+    if (!fname || !*fname) {
+      if (fc->filter() != pat && (!pat || !fc->filter() ||
+          strcmp(pat, fc->filter())) && fc->value()) {
+	// if pattern is different, remove name but leave old directory:
+	strcpy(retname, fc->value() );
 
-  f->show();
-  int ok = 0;
-  for (;;) {
-    Fl::wait();
-    Fl_Widget* o = Fl::readqueue();
-    if (o == f->ok_button) {ok = 1; break;}
-    else if (o == f->cancel_button || o == f) break;
-  }
-  f->hide();
-  f->browser.clear();
+	char *p = strrchr(retname, '/');
 
-  if (!ok) return 0;
-  const char* r = f->input.value();
-  const char *p;
-  for (p=r+f->browser.dirend; *p; p++)
-    if (*p=='*' || *p=='?' || *p=='[' || *p=='{') return 0;
-  static char final[FL_PATH_MAX];
-  strcpy(final, r);
-  return final;
-}
+        if (p) {
+	  // If the filename is "/foo", then the directory will be "/", not
+	  // ""...
+	  if (p == retname)
+	    retname[1] = '\0';
+	  else
+	    *p = '\0';
+	}
 
-
-char* fl_file_chooser_plus(const char* message, const char* pat, 
-	const char* fname, int use_only_button)
-{
-static int first = TRUE;
-static Fl_Button *b_vary;
-  static FCW* f; if (!f) f = new FCW();
-  f->ok_button->label(fl_ok);
-  f->cancel_button->label(fl_cancel);
-
-  if (pat && !*pat) pat = 0;
-  if (fname && *fname) {
-    f->input.value(fname);
-  } else if (f->browser.pattern != pat && (!pat || !f->browser.pattern ||
-					   strcmp(pat,f->browser.pattern))) {
-    // if pattern is different, remove name but leave old directory:
-    const char* p = f->input.value();
-    const char* q = fl_filename_name(p);
-    f->input.value(p, q-p);
+	// Set the directory...
+	fc->directory(retname);
+      }
+    }
+    else
+      fc->value(fname);
   }
-  f->browser.pattern = pat;
-  f->normal_button->label(pat ? pat : "visible files");
-  f->browser.set(f->input.value());
-  f->input.position(10000, f->browser.dirend);
 
-  f->label(message);
-  f->hotspot(f);
+  mychoice->value(view->format_for_save);
+  fc->show();
 
-if(first) {
-	first = FALSE;
-	int gauche = 2; char *q; Fl_Button *bouton; char *b_label;
-	
-	bouton = new Fl_Button(gauche, f->ok_button->y(), 5, f->ok_button->h());
-	b_label = (char *)malloc(50);
-	strcpy(b_label, printout_label_block);
-	q = strchr(b_label,'=');
-	sprintf(q+1, "%d", printout_block);
-	bouton->size( calc_width(b_label) , bouton->h() );
-	bouton->label(b_label);
-	bouton->callback(change_block, NULL);
-	bouton->labelsize(labelSize);
-	f->add(bouton);
-	gauche += bouton->w() + 2;
-	
-	bouton = new Fl_Button(gauche, f->ok_button->y(), 5, f->ok_button->h());
-	b_label = (char *)malloc(50);
-	strcpy(b_label, printout_label_cpl);
-	q = strchr(b_label,'=');
-	sprintf(q+1, "%d", printout_cpl);
-	bouton->size( calc_width(b_label) , bouton->h() );
-	bouton->label(b_label);
-	bouton->callback(change_cpl, NULL);
-	bouton->labelsize(labelSize);
-	f->add(bouton);
-	gauche += bouton->w() + 2;
-	
-	bouton = new Fl_Button(gauche, f->ok_button->y(), 5, f->ok_button->h());
-	b_label = (char *)malloc(50);
-	strcpy(b_label, printout_label_lpp);
-	q = strchr(b_label,'=');
-	sprintf(q+1, "%d", printout_lpp);
-	bouton->size( calc_width(b_label) , bouton->h() );
-	bouton->label(b_label);
-	bouton->callback(change_lpp, NULL);
-	bouton->labelsize(labelSize);
-	f->add(bouton);
-	gauche += bouton->w() + 2;
-	
-	b_vary = new Fl_Check_Button(gauche, f->ok_button->y(), 5, 
-		f->ok_button->h());
-	b_vary->size( calc_width(printout_label_vary) , bouton->h() );
-	b_vary->label(printout_label_vary);
-	b_vary->callback(change_vary, NULL);
-	b_vary->labelsize(labelSize);
-	b_vary->value(printout_vary);
-	f->add(b_vary);
-}
-
-f->show();
-if(use_only_button) b_vary->show();
-else b_vary->hide();
-
-  int ok = 0;
-  for (;;) {
+  while (fc->shown())
     Fl::wait();
-    Fl_Widget* o = Fl::readqueue();
-    if (o == f->ok_button) {ok = 1; break;}
-    else if (o == f->cancel_button || o == f) break;
-  }
-  f->hide();
-  f->browser.clear();
 
-  if (!ok) return 0;
-  const char* r = f->input.value();
-  const char *p;
-  for (p=r+f->browser.dirend; *p; p++)
-    if (*p=='*' || *p=='?' || *p=='[' || *p=='{') return 0;
-  return (char*)r;
+  if (fc->value()) return (char *)fc->value();
+  else return 0;
 }
 
+
 #endif

Copied: trunk/packages/seaview/trunk/custom.cxx (from rev 116, trunk/packages/seaview/branches/upstream/current/custom.cxx)
===================================================================
--- trunk/packages/seaview/trunk/custom.cxx	                        (rev 0)
+++ trunk/packages/seaview/trunk/custom.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -0,0 +1,479 @@
+#include "seaview.h"
+#include <FL/Fl_Color_Chooser.H>
+#include <FL/Fl_Slider.H>
+#include <FL/Fl_Check_Button.H>
+
+
+void custom_callback(Fl_Widget *obj, void *data);
+void my_colorchooser(Fl_Widget *obj, void *data);
+void my_colorchooser_callback(Fl_Widget *obj, void *data);
+void slider_cb(Fl_Widget *obj, void *data);
+void ignore_cb(Fl_Widget *obj, void *data);
+void accept_cb(Fl_Widget *obj, void *data);
+void permanent_cb(Fl_Widget *obj, void *data);
+void reset_color_callback(Fl_Widget *obj, void *data);
+void accept_color_callback(Fl_Widget *obj, void *data);
+void reset_callback(Fl_Widget *obj, void *data);
+
+
+/* private global variables */
+static Fl_Button *A, *C, *G, *T;
+static Fl_Slider *bgrnd, *s_bgrnd;
+static Fl_Input *protgroups, *s_protgroups, *movekeys;
+static Fl_Button **protcol;
+static Fl_Check_Button *lowercase, *inverted;
+static Fl_Choice *pdfformat, *saveformat, *alignment_algo;
+
+
+/* extern variables & functions */
+extern int *def_protcolors, max_protcolors;
+extern char def_stdcolorgroups[];
+extern char *f_format_names[];
+extern int nbr_formats;
+extern paperformat printout_pageformat;
+extern void mod_multipl(SEA_VIEW *view, int newval);
+extern void set_aa_color_mode(color_choice choice);
+extern color_choice prep_aa_color_code(char *list_std, char *list_alt, 
+	int maxprotcolors, int *numb_stdprotcolors, int *numb_altprotcolors);
+extern int set_res_value(const char *name, const char *value);
+extern int save_resources(void);
+extern void minuscules(char *);
+
+
+void custom_callback(Fl_Widget *obj, void *data)
+{
+static Fl_Window *win = NULL;
+int x, y, w, h, c;
+SEA_VIEW *view = (SEA_VIEW *)data;
+Fl_Button *reset;
+
+if(win == NULL) {
+	win = new Fl_Window(310, 530, "Customization");
+	
+	x = 9; y = 20; w = 160; h = 20;
+	bgrnd = new Fl_Slider(x,y,w,h, "background grey");
+	bgrnd->type(FL_HOR_NICE_SLIDER);
+	bgrnd->bounds(32., 55.);
+	bgrnd->color2( FL_BLACK );
+	bgrnd->precision(0);
+	bgrnd->align(FL_ALIGN_TOP);
+	bgrnd->callback(slider_cb);
+	y += bgrnd->h() + 25;
+
+	s_bgrnd = new Fl_Slider(x,y,w,h, "sites background grey");
+	s_bgrnd->type(FL_HOR_NICE_SLIDER);
+	s_bgrnd->bounds(32., 55.);
+	s_bgrnd->color2( FL_BLACK );
+	s_bgrnd->precision(0);
+	s_bgrnd->align(FL_ALIGN_TOP);
+	s_bgrnd->callback(slider_cb);
+	
+	reset = new Fl_Button(bgrnd->x() + bgrnd->w() + 40, s_bgrnd->y() - 20, 50, 20, "reset");
+	reset->color(FL_LIGHT2);
+	reset->callback(reset_callback, bgrnd);
+	new Fl_Box(FL_DOWN_FRAME, 5, 3,
+		win->w() - 8, 90 , "");
+	
+	y += s_bgrnd->h() + 20;
+	w=40; h=w;
+	A = new Fl_Button(x, y, w, h, "A");
+	A->callback(my_colorchooser );
+	
+	x += A->w() + 10;
+	C = new Fl_Button(x, y, w, h, "C");
+	C->callback(my_colorchooser );
+
+	x += A->w() + 10;
+	G = new Fl_Button(x, y, w, h, "G");
+	G->callback(my_colorchooser );
+
+	x += A->w() + 10;
+	T = new Fl_Button(x, y, w, h, "T/U");
+	T->callback(my_colorchooser );
+	
+	x += A->w() + 30;
+	reset = new Fl_Button(x, y + 10, 50, 20, "reset");
+	reset->color(FL_LIGHT2);
+	reset->callback(reset_callback, A);
+	new Fl_Box(FL_DOWN_FRAME, 5, A->y() - 5,
+		win->w() - 8, A->h() + 10 , "");
+	
+	x = A->x();
+	y += A->h() + 35;
+	int topbox = y - 25;
+	protgroups = new Fl_Input(x,y,280, 20, "aa coloring scheme");
+	protgroups->align(FL_ALIGN_TOP);
+
+	y += protgroups->h() + 20;
+	s_protgroups = new Fl_Input(x,y,280, 20, "alternate aa coloring scheme");
+	s_protgroups->align(FL_ALIGN_TOP);
+	
+	y += s_protgroups->h() + 10;
+	new Fl_Box(x, y, win->w(), 20, "catalog of amino acid colors");
+	y += 20;
+	w = h = 25;
+	protcol = (Fl_Button **)malloc(max_protcolors * sizeof(Fl_Button *));
+	for(c=1; c < max_protcolors; c++) {
+		protcol[c] = new Fl_Button(x, y, w, h, "");
+		protcol[c]->callback(my_colorchooser);
+		x += w + 5;
+		}
+	y += h + 10;
+	reset = new Fl_Button(win->w() / 2 - 25, y, 50, 20, "reset");
+	reset->color(FL_LIGHT2);
+	reset->callback(reset_callback, protgroups);
+	new Fl_Box(FL_DOWN_FRAME, 5, topbox,
+		win->w() - 8, y + reset->h() + 5 - topbox, "");
+
+	x = A->x();
+	y += protcol[1]->h() + 30; 
+	movekeys = new Fl_Input(x,y, 50, 20, "left-right movement keys");
+	movekeys->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
+	reset = new Fl_Button(x + movekeys->w() + 5, y, 50, 20, "reset");
+	reset->color(FL_LIGHT2);
+	reset->callback(reset_callback, movekeys);
+
+	w = 130;
+	x = win->w() - w - 5;
+	pdfformat = new Fl_Choice(x,y,w,h, PDF_OR_PS" page format");
+	pdfformat->align(FL_ALIGN_TOP);
+	for(c=0; c < nbr_formats; c++) pdfformat->add("A4|LETTER");
+	pdfformat->selection_color(pdfformat->color());
+	
+	x = A->x();
+	y += movekeys->h() + 10; 
+	lowercase = new Fl_Check_Button(x,y,140,20, "display lowercase");
+
+	y += lowercase->h(); 
+	inverted = new Fl_Check_Button(x,y,140,20, "inverted");
+	
+	x = win->w() - w - 5;
+	y = movekeys->y() + movekeys->h() + 20;
+	saveformat = new Fl_Choice(x,y,w,h, "default save format");
+	saveformat->align(FL_ALIGN_TOP);
+	for(c=0; c < nbr_formats; c++) saveformat->add(f_format_names[c]);
+	saveformat->selection_color(saveformat->color());
+	
+	x = A->x();
+	y = inverted->y() + inverted->h() + 20; 
+	alignment_algo = new Fl_Choice(x,y,w,h, "alignment algorithm");
+	alignment_algo->align(FL_ALIGN_TOP);
+	alignment_algo->add("Clustalw");
+	alignment_algo->add("Muscle");
+#ifdef NO_CLUSTALW
+	alignment_algo->deactivate();
+#endif
+	
+	x = A->x();
+	y += alignment_algo->h() + 10;
+	h = 40;
+	w = 95;
+	Fl_Button *accept = new Fl_Button(x,y,w,h, "Apply");
+	accept->callback(accept_cb, view);
+	accept->color(FL_LIGHT2);
+	x += w + 5;
+	Fl_Button *permanent = new Fl_Button(x,y,w,h, "Set changes\npermanent");
+	permanent->callback(permanent_cb, view);
+	permanent->color(FL_LIGHT2);
+	w = 45;
+	y += 10;
+	Fl_Button *ignore = new Fl_Button(win->w() - w - 5,y,w,20, "Close");
+	ignore->color(FL_LIGHT2);
+	ignore->callback(ignore_cb);
+	win->end();
+	win->resizable(NULL);
+	}
+
+bgrnd->value( view->DNA_obj->color() );
+bgrnd->color( view->DNA_obj->color() );
+s_bgrnd->value( view->DNA_obj->color2() );
+s_bgrnd->color( view->DNA_obj->color2() );
+A->color(view->dnacolors[1], view->dnacolors[1]);
+C->color(view->dnacolors[2], view->dnacolors[2]);
+G->color(view->dnacolors[3], view->dnacolors[3]);
+T->color(view->dnacolors[4], view->dnacolors[4]);
+char *p, aagroups[30];
+p = aagroups;
+set_aa_color_mode(USING_STANDARD_COLORS);
+for(c=1; c < view->numb_stdprotcolors; c++) {
+	for(char aa='A'; aa<='Z';aa++) {
+		if(get_color_for_aa(aa) == c) *(p++) = aa;
+		}
+	if(c+1< view->numb_stdprotcolors) strcpy(p++, ",");
+	}
+*p = 0;
+protgroups->value(aagroups);
+if(view->numb_altprotcolors <= 1) s_protgroups->value("");
+else {
+	p = aagroups;
+	set_aa_color_mode(USING_ALT_COLORS);
+	for(c=1; c < view->numb_altprotcolors; c++) {
+		for(char aa='A'; aa<='Z';aa++) {
+			if(get_color_for_aa(aa) == c) *(p++) = aa;
+			}
+		if(c+1< view->numb_altprotcolors) strcpy(p++, ",");
+		}
+	*p = 0;
+	s_protgroups->value(aagroups);
+	}
+if(view->curr_colors == view->stdprotcolors) set_aa_color_mode(USING_STANDARD_COLORS);
+else set_aa_color_mode(USING_ALT_COLORS);
+
+for(c=1; c < max_protcolors; c++) {
+	protcol[c]->color(view->stdprotcolors[c], view->stdprotcolors[c]);
+	}
+movekeys->value( view->movekeys );
+lowercase->value(view->allow_lower);
+inverted->value(view->inverted_colors);
+pdfformat->value(printout_pageformat);
+saveformat->value(view->format_for_save);
+alignment_algo->value(view->alignment_algorithm);
+
+win->show();
+return;
+}
+
+
+void ignore_cb(Fl_Widget *obj, void *data)
+{
+obj->window()->hide();
+}
+
+
+void accept_cb(Fl_Widget *obj, void *data)
+{
+SEA_VIEW *view = (SEA_VIEW *)data;
+Fl_Menu_Button *menu_props = (Fl_Menu_Button *)view->bouton_props;
+props_menu_parts *props_parts = (props_menu_parts *)menu_props->user_data();
+char *p;
+Fl_Menu_Item *item;
+
+my_watch_cursor(view->dnawin);
+view->DNA_obj->color((int)(bgrnd->value() + 0.5));
+view->DNA_obj->color2((int)(s_bgrnd->value() + 0.5));
+view->DNA_obj->parent()->color( view->DNA_obj->color() );
+view->dnacolors[1] = A->color();
+view->dnacolors[2] = C->color();
+view->dnacolors[3] = G->color();
+view->dnacolors[4] = T->color();
+for(int c=1; c < max_protcolors; c++) view->stdprotcolors[c] = protcol[c]->color();
+
+p = strdup(protgroups->value());
+majuscules(p);
+protgroups->value(p);
+free(p);
+p = strdup(s_protgroups->value());
+majuscules(p);
+s_protgroups->value(p);
+free(p);
+prep_aa_color_code((char *)protgroups->value(), (char *)s_protgroups->value(), max_protcolors, 
+	&view->numb_stdprotcolors, &view->numb_altprotcolors);
+int etat = menu_props->mode(props_parts->colors + 2);
+if(view->numb_altprotcolors > 1) menu_props->mode(props_parts->colors + 2, etat & ~FL_MENU_INACTIVE);
+else menu_props->mode(props_parts->colors + 2, etat | FL_MENU_INACTIVE);
+if(view->protein) {
+	view->alt_colors = (color_choice)-1; /* to force redraw of sequences */
+	menu_props->value(props_parts->colors + 1);
+	item = (Fl_Menu_Item *)menu_props->menu() + props_parts->colors;
+	item->do_callback(menu_props);
+	(item+1)->setonly();
+	if(view->numb_altprotcolors > 1) view->alt_colors = USING_STANDARD_COLORS;
+	else view->alt_colors = NO_ALT_COLORS;
+	}
+
+if(strlen(movekeys->value()) != 4)  movekeys->value(view->movekeys);
+else {
+	strcpy(view->movekeys, movekeys->value() ); 
+	mod_multipl(view, view->multipl->argument() );
+	view->multipl->redraw();
+	}
+
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->allow_lower;
+view->allow_lower = ! lowercase->value(); /* because callback toggles it */
+item->do_callback(menu_props);
+if(view->allow_lower) item->set();
+else item->clear();
+
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->inverted;
+view->inverted_colors = ! inverted->value(); /* because callback toggles it */
+menu_props->value(props_parts->inverted);
+item->do_callback(menu_props);
+if(view->inverted_colors) item->set();
+else item->clear();
+
+printout_pageformat = (paperformat)pdfformat->value();
+
+view->format_for_save = (known_format)saveformat->value();
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->saveformat;
+(item+view->format_for_save)->setonly();
+
+view->alignment_algorithm = alignment_algo->value();
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->clustalopt;
+(item+view->alignment_algorithm)->setonly();
+
+if(!view->protein) view->DNA_obj->redraw();
+fl_reset_cursor(view->dnawin);
+}
+
+
+void permanent_cb(Fl_Widget *obj, void *data)
+{
+char txt[150];
+int v;
+uchar r, g, b;
+
+accept_cb(obj, data);
+
+v = (int)(bgrnd->value() + 0.5);
+sprintf(txt, "%d", v );
+set_res_value("background", txt );
+v = (int)(s_bgrnd->value() + 0.5);
+sprintf(txt, "%d", v );
+set_res_value("sites_background", txt );
+
+Fl::get_color( A->color(), r, g, b);
+sprintf(txt, "%d %d %d,", r, g, b);
+Fl::get_color( C->color(), r, g, b);
+sprintf(txt + strlen(txt), "%d %d %d,", r, g, b);
+Fl::get_color( G->color(), r, g, b);
+sprintf(txt + strlen(txt), "%d %d %d,", r, g, b);
+Fl::get_color( T->color(), r, g, b);
+sprintf(txt + strlen(txt), "%d %d %d", r, g, b);
+set_res_value("dnacolors", txt);
+
+set_res_value("stdcolorgroups", (char *)protgroups->value());
+set_res_value("altcolorgroups", (char *)s_protgroups->value());
+
+txt[0] = 0;
+for(int c=1; c < max_protcolors; c++) {
+	Fl::get_color( protcol[c]->color(), r, g, b);
+	sprintf(txt + strlen(txt), "%d %d %d,", r, g, b);
+	}
+txt[strlen(txt) - 1] = 0;
+set_res_value("protcolors", txt);
+
+set_res_value("movekeys", movekeys->value() );
+set_res_value("lowercase", lowercase->value() ? "true" : "false");
+set_res_value("inverted", inverted->value() ? "true" : "false");
+set_res_value("printoutpageformat", printout_pageformat == A4 ? "A4" : "LETTER" );
+
+strcpy(txt, f_format_names[saveformat->value()] );
+minuscules(txt);
+set_res_value("save", txt );
+
+v = alignment_algo->value();
+sprintf(txt, "%d", v );
+set_res_value("alignment", txt);
+
+save_resources();
+obj->window()->hide();
+}
+
+
+void reset_callback(Fl_Widget *obj, void *data)
+{
+if(data == A) {
+	A->color(FL_RED, FL_RED);
+	C->color(FL_GREEN, FL_GREEN);
+	G->color(FL_YELLOW, FL_YELLOW);
+	T->color(FL_BLUE, FL_BLUE);
+	}
+else if(data == bgrnd) {
+	int back_color, region_back_color;
+#ifdef WIN32
+	back_color = FL_DARK1; region_back_color = 43;
+#else
+	back_color = FL_GRAY; region_back_color = FL_DARK2;
+#endif
+	bgrnd->value( back_color );
+	bgrnd->color( back_color );
+	s_bgrnd->value( region_back_color );
+	s_bgrnd->color( region_back_color );
+	}
+else if(data == movekeys) {
+	movekeys->value(MOVEKEYS_DEFAULT);
+	}
+else if(data == protgroups) {
+	protgroups->value(def_stdcolorgroups);
+	s_protgroups->value("");
+	for(int c=1; c < max_protcolors; c++) {
+		protcol[c]->color(def_protcolors[c], def_protcolors[c]);
+		}
+	}
+obj->window()->redraw();
+}
+
+
+void my_colorchooser(Fl_Widget *obj, void *data)
+{
+static Fl_Window *win = NULL;
+static Fl_Color_Chooser *ch;
+uchar r, g, b;
+static Fl_Color initial;
+
+if(win == NULL) {
+	win = new Fl_Window(205, 125, "Color chooser");
+	ch = new Fl_Color_Chooser(1, 1, 200, 95);
+	ch->callback(my_colorchooser_callback);
+	Fl_Button *reset = new Fl_Button(5, 100, 40, 20, "reset");
+	reset->callback(reset_color_callback, ch);
+	Fl_Button *ok = new Fl_Button(160, 100, 40, 20, "OK");
+	ok->callback(accept_color_callback, ch);
+	win->end();
+	win->resizable(NULL);
+	win->set_modal();
+	win->callback(reset_color_callback, ch);
+}
+if(win->shown()) return;
+Fl::get_color( obj->color(), r, g, b);
+ch->rgb(r/255., g/255., b/255.);
+ch->user_data(obj);
+obj->user_data(&initial);
+initial = obj->color();
+win->show();
+return;
+}
+
+
+void my_colorchooser_callback(Fl_Widget *obj, void *data)
+{
+int r, g, b;
+Fl_Button *but = (Fl_Button *)data;
+Fl_Color_Chooser *ch = (Fl_Color_Chooser *)obj;
+r = (int)(ch->r() * 255 + 0.5);
+g = (int)(ch->g() * 255 + 0.5);
+b = (int)(ch->b() * 255 + 0.5);
+Fl_Color c = fl_rgb_color(r, g, b);
+but->color(c, c);
+but->redraw();
+}
+
+
+void reset_color_callback(Fl_Widget *obj, void *data)
+{
+Fl_Color_Chooser *ch = (Fl_Color_Chooser *)data;
+Fl_Widget *from = (Fl_Widget *)(ch->user_data());
+Fl_Color c = *(Fl_Color *)(from->user_data());
+uchar r, g, b;
+
+from->color(c, c);
+from->redraw();
+if(obj->window() == NULL) ((Fl_Window *)obj)->hide();
+else {
+	Fl::get_color( c, r, g, b);
+	ch->rgb(r/255., g/255., b/255.);
+	}
+}
+
+
+void accept_color_callback(Fl_Widget *obj, void *data)
+{
+obj->window()->hide();
+}
+
+
+void slider_cb(Fl_Widget *obj, void *data)
+{
+Fl_Valuator *v = (Fl_Valuator *)obj;
+v->color( (int)(v->value() + 0.5) );
+}

Modified: trunk/packages/seaview/trunk/load_seq.cxx
===================================================================
--- trunk/packages/seaview/trunk/load_seq.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/load_seq.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -210,8 +210,10 @@
 	curr_y += top->h() + 15;
 	seq_input = new 
 		Fl_Input(top->x(), curr_y, load_form->w() - 2 * top->x(), 450,
-#if defined(WIN32) || defined(__APPLE__)
-	    "Type sequence or paste it with CRTL-v in panel below"
+#if defined(__APPLE__)
+	    ""
+#elif defined(WIN32) 
+	    "Type sequence or paste it with CRTL-V in panel below"
 #else
 	    "Type or paste sequence with middle mouse button in panel below"
 #endif
@@ -220,7 +222,6 @@
 	seq_input->align(FL_ALIGN_TOP);
 	seq_input->textfont(FL_COURIER);
 	seq_input->textsize(12);
-	
 	fin = top->x();
 	curr_y += seq_input->h() + 5;
 	Fl_Group *bottom = new Fl_Group(fin, curr_y, top->w(), top->h() );
@@ -262,6 +263,10 @@
 	}
 seq_name_input->value("");
 seq_input->value("");
+#if defined(__APPLE__)
+	seq_input->value("\n\n\n\n\n\nType sequence or paste it with CRTL-V\n\n\n");
+	seq_input->position(seq_input->size(), 0);
+#endif	
 seq_input->take_focus();
 load_form->show();
 }
@@ -452,6 +457,10 @@
 
 ob->window()->hide();
 view = ((view_name_struct *)data)->view;
+if(view->comments == NULL) {
+	view->comments = (char **)calloc(view->tot_seqs , sizeof(char *));
+	if(view->comments == NULL) return;
+	}
 comments_input = ((view_name_struct *)data)->seq_field;
 num = comments_input->argument();
 num_l = 0;
@@ -492,7 +501,7 @@
 input->argument( num);
 name->label(view->seqname[num]);
 name->redraw();
-if( view->comments[num] == NULL) {
+if( view->comments == NULL || view->comments[num] == NULL) {
 	input->value("");
 	return FALSE;
 	}
@@ -517,8 +526,8 @@
 {
 char *newseq, *p, *residues, unknown;
 int pos, num, total, kind, dernier, maxi, vu;
-static char dna_residues[]="ACGTU";
-static const char prot_residues[] = "EDQNHRKILMVAPSGTFYWC";
+static char dna_residues[]="ACGTU-";
+static const char prot_residues[] = "EDQNHRKILMVAPSGTFYWC-";
 static int freqs[30];
 
 newseq = (char *)malloc(view->seq_length + 1);
@@ -539,7 +548,7 @@
 		if( !view->sel_seqs[num] ) continue;
 		if(pos >= view->each_length[num]) continue;
 		vu++;
-		if(view->sequence[num][pos] == '-') continue;
+		if(view->sequence[num][pos] == '-' && ! view->consensus_allowgaps) continue;
 		total++;
 		p = strchr(residues, toupper(view->sequence[num][pos]));
 		if(p == NULL) kind = 0;

Modified: trunk/packages/seaview/trunk/mac_pc_extras.cxx
===================================================================
--- trunk/packages/seaview/trunk/mac_pc_extras.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/mac_pc_extras.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -4,36 +4,44 @@
 #include <string.h>
 #include <stdio.h>
 #include <FL/Fl_Sys_Menu_Bar.H>
+#include <FL/filename.H>
+#include <config.H>
 
 // included functions
+int MG_GetInputFName(char *fname, int maxl, char *title);
+char *mac_fname_to_roman(char *in);
 extern "C" {
-char *my_fgets(char *s, int n, FILE *f);
 void *memccpy(void *s1, const void *s2, int c, size_t n);
+#if ! TARGET_RT_MAC_MACHO
+char *OSXpathtoOS9path(const char *newpath);
 char *get_prog_dir(void);
-void MG_FSSpecToPathname (FSSpec *myFSS, char *fname, int maxl);
+#else
+char *MG_GetBundleResourcesDir(void);
+#endif
 void PtoC(const void *in, void *out);
 void CtoP(const void *in, void *out);
 void MGinit_apple_events(SEA_VIEW *);
-void add_apropos(char *progname);
+void add_apropos(char *progname, void *data);
 void show_apropos(Fl_Widget *, void *);
-pascal Boolean myfilter(DialogRef dptr, EventRecord *event, DialogItemIndex *item);
 Boolean AppleEventsInstalled ();
-pascal OSErr  MyHandleODoc (const AppleEvent *theAppleEvent, AppleEvent* reply,  UInt32 handlerRefCon);
-pascal OSErr  MyHandlePDoc (const AppleEvent *theAppleEvent, AppleEvent *reply, UInt32 handlerRefCon);
-pascal OSErr  MyHandleOApp (const AppleEvent *theAppleEvent, AppleEvent *reply, UInt32 handlerRefCon);
-pascal OSErr  MyHandleQApp (const AppleEvent *theAppleEvent, AppleEvent *reply, UInt32 handlerRefCon);
+OSErr  MyHandleODoc (const AppleEvent *theAppleEvent, AppleEvent* reply, long handlerRefCon);
+OSErr  MyHandlePDoc (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon);
+OSErr  MyHandleOApp (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon);
+OSErr myQuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, long refcon );
 OSErr MyGotRequiredParams (const AppleEvent *theAppleEvent);
+void MG_apple_inits(void);
 }
 
 static SEA_VIEW *view;
 extern void use_initial_file(SEA_VIEW *view, char *masename);
+extern char *get_next_help_line(void *in, char *line, int lline);
 
 #elif defined(WIN32)
 
 #include <stdarg.h>
-#include <windef.h>
-#include <winbase.h>
+#include <Windows.h>
 #include <string.h>
+#include <direct.h>
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -45,6 +53,12 @@
 char *get_prog_dir(void);
 void add_to_path(char *dir);
 }
+char *MG_win32_file_chooser(const char* message, // title of dialog window
+        const char* pattern, // optional "mase format\0*.mase\0MSF format\0*.msf\0"
+        const char* fname, // default file name
+        const char* defext, // default filename extension or NULL
+        bool save, // TRUE iff output file selection
+        int *pfilterindex); // (inout) pointer to index (from 1) in series of file types in pattern
 #endif
 
 
@@ -62,68 +76,89 @@
 
 
 #ifdef __APPLE__
-/* version de fgets qui accepte les formats CR, LF, ou CR+LF sur Mac.
-!!!!!!!!!!! sur Mac, fgets échange les \r et \n lus dans les fichiers !!!!!!!!!!!!!
-!!!!!!!!!!! donc le format PC des fichiers apparait comme LF+CR !!!!!!!!!!!!!!
-!!!!!!!!!!! et le format unix comme CR !!!!!!!!!!!!!
-*/
 
-char *my_fgets(char *s, int n, FILE *f)
+int MG_GetInputFName(char *fname, int maxl, char *title)
 {
-int next_char;
-char *p;
+  OSStatus          err;
+  NavDialogCreationOptions  options;
+  NavDialogRef        navDialog;
+  NavReplyRecord        navReply;
+int         rsult = FALSE;
+FSRef fileRef;
 
-p = s;
-while(--n > 0) {
-	next_char = getc(f);
-	if( next_char == '\r' ) {
-		*(p++) = '\n';
-		break;
-		}
-	else if( next_char == '\n' ) {
-		*(p++) = '\n';
-		next_char = getc(f);
-		if(next_char != '\r' && next_char != EOF) {
-			ungetc(next_char, f);
-			}
-		break;
-		}
- 	else if (next_char == EOF) 
-		break;
-	*(p++) = next_char;
-	}
-*p = 0;
-return (p == s ? NULL : s);
+  err = NavGetDefaultDialogCreationOptions( &options );
+  if(err != noErr) return FALSE;
+  options.optionFlags &= !kNavAllowMultipleFiles;
+  options.windowTitle = CFStringCreateWithCString(NULL, title, kCFStringEncodingMacRoman);
+  err = NavCreateChooseFileDialog( &options, NULL, NULL, NULL, NULL, NULL, &navDialog );
+  if(err != noErr) return FALSE;
+
+  // choose the file
+  err = NavDialogRun( navDialog );
+  CFRelease(options.windowTitle);
+  if(err != noErr) return FALSE;
+  
+  err = NavDialogGetReply( navDialog, &navReply );
+  
+  // create url to chosen file
+  if (err == noErr && navReply.validRecord )
+  {    
+	err = AEGetNthPtr( &navReply.selection, 1, typeFSRef, NULL, NULL, &fileRef, sizeof( FSRef ), NULL );
+    if(err == noErr) {
+				err = FSRefMakePath(&fileRef, (UInt8 *)fname, maxl);
+				if (err == noErr) rsult = TRUE;
+                }
+  }  
+  NavDisposeReply( &navReply );
+  NavDialogDispose( navDialog );
+  return rsult;
 }
 
 
-char *get_prog_dir(void)
-/* returns the pathname of the directory containing the running program
+char* MAC_file_chooser(const char* message, const char* pat, const char* fname)
+{
+	static char pathname[FL_PATH_MAX];
+	if( MG_GetInputFName(pathname, FL_PATH_MAX, (char *)message) ) return pathname;
+	else return NULL;
+}
+
+
+char *mac_fname_to_roman(char *in)
+/* passage codage pathname vers codage MacRoman qui semble nŽcessaire pour display Žcran 
 */
 {
-FSSpec fspec;
-ProcessInfoRec info;
+static char out[250];
+CFStringRef mycfs;
+Boolean ok;
+/* j'ai cru comprendre que les pathnames sont codŽs en UTF8 */
+mycfs = CFStringCreateWithCString(NULL, in, kCFStringEncodingUTF8);
+/* et que MacRoman est utilisŽ pour display */
+ok = CFStringGetCString(mycfs, out, sizeof(out), kCFStringEncodingMacRoman);
+CFRelease(mycfs);
+return (ok ? out : in);
+}
+
+
+
+#if TARGET_RT_MAC_MACHO
+
+char *MG_GetBundleResourcesDir(void)
+{
 ProcessSerialNumber psn;
-OSErr err;
-static char myname[300];
-char *p;
+FSRef fsref;
+static char fname[300];
+CFURLRef myurl;
 
-info.processInfoLength = sizeof(ProcessInfoRec);
-info.processName = NULL;
-info.processAppSpec = &fspec;
-err = GetCurrentProcess(&psn);
-if(err != noErr) return NULL;
-err = GetProcessInformation(&psn, &info);
-if(err != noErr) return NULL;
-MG_FSSpecToPathname(&fspec, myname, sizeof(myname) );
-p = strrchr(myname, ':');
-if(p == NULL) return NULL;
-*p = 0;
-return myname;
+GetCurrentProcess(&psn);
+GetProcessBundleLocation(&psn, &fsref);
+FSRefMakePath(&fsref, (UInt8 *)fname, sizeof(fname)-1);
+strcat(fname, "/Contents/Resources"); 
+return fname;
 }
 
+#else
 
-void MG_FSSpecToPathname (FSSpec *myFSS, char *fname, int maxl)
+static void MG_FSSpecToPathname (FSSpec *myFSS, char *fname, int maxl)
 {
 FSRef myFSRef, pFSRef;
 FSCatalogInfo myinfo;
@@ -155,7 +190,46 @@
 }
 
 
+char *get_prog_dir(void)
+/* returns the pathname of the directory containing the running program
+*/
+{
+FSSpec fspec;
+ProcessInfoRec info;
+ProcessSerialNumber psn;
+OSErr err;
+static char myname[300];
+char *p;
 
+info.processInfoLength = sizeof(ProcessInfoRec);
+info.processName = NULL;
+info.processAppSpec = &fspec;
+err = GetCurrentProcess(&psn);
+if(err != noErr) return NULL;
+err = GetProcessInformation(&psn, &info);
+if(err != noErr) return NULL;
+MG_FSSpecToPathname(&fspec, myname, sizeof(myname) );
+p = strrchr(myname, ':');
+if(p == NULL) return NULL;
+*p = 0;
+return myname;
+}
+
+
+char *OSXpathtoOS9path(const char *OSXpath /* syntax /disk/dir/fname */)
+{
+static char OS9path[1000];
+FSRef myref;
+FSSpec fsspec;
+
+FSPathMakeRef((const unsigned char *)OSXpath, &myref, NULL);
+FSGetCatalogInfo(&myref, 0, NULL, NULL, &fsspec, NULL);
+MG_FSSpecToPathname(&fsspec, OS9path, sizeof(OS9path));
+return OS9path; /* syntax disk:dir:fname */
+}
+#endif
+
+
 void PtoC(const void *in, void *out)
 {
 char *vin = (char *)in;
@@ -179,24 +253,24 @@
 vout[0] = l;
 }
 
+extern void fl_open_display(void);
 
 void MGinit_apple_events(SEA_VIEW *v)
 {
-//	long gestaltAnswer;
-	OSErr gestaltErr, theResult;
 	OSErr err;
-
 	AEEventHandlerUPP	gAEEventHandlerUPPODoc;
 	AEEventHandlerUPP	gAEEventHandlerUPPOApp;
 	AEEventHandlerUPP	gAEEventHandlerUPPPDoc;
 	AEEventHandlerUPP	gAEEventHandlerUPPQApp;
-Boolean aEvents;
+    Boolean aEvents;
+	
+	fl_open_display();
 	aEvents = AppleEventsInstalled();
 	if (aEvents) {
 		gAEEventHandlerUPPODoc = NewAEEventHandlerUPP(MyHandleODoc);
 		gAEEventHandlerUPPOApp = NewAEEventHandlerUPP(MyHandleOApp);
 		gAEEventHandlerUPPPDoc = NewAEEventHandlerUPP(MyHandlePDoc);
-		gAEEventHandlerUPPQApp = NewAEEventHandlerUPP(MyHandleQApp);
+		gAEEventHandlerUPPQApp = NewAEEventHandlerUPP(myQuitAppleEventHandler);
 		err = AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, gAEEventHandlerUPPODoc,0, 0);
 		err = AEInstallEventHandler (kCoreEventClass, kAEOpenApplication, gAEEventHandlerUPPOApp,0, 0);
 		err = AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments, gAEEventHandlerUPPPDoc,0, 0);
@@ -206,7 +280,16 @@
 }
 
 
-void add_apropos(char *progname)
+// repairs FLK bug with cmd-Q that freezes if window close is refused 
+OSErr myQuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, long refcon )
+{
+if(view) view->dnawin->do_callback();
+Fl::e_state = 0; //against bug where cmd-key modifier stays
+return noErr;
+}
+
+
+void add_apropos(char *progname, void *data)
 {  
 static Fl_Menu_Item item = {"", 0, show_apropos, 0, 0};
 OSStatus err;
@@ -221,35 +304,51 @@
 smb->menu( &empty ); // indispensable pour initialiser fl_sys_menu_bar
 mr = NewMenu(1, apple_glyph);
 InsertMenu(mr, 0);
-sprintf(title, "About %sŠ", progname);
+sprintf(title, "About %s", progname);
 CtoP(title, ptitle);
 err = InsertMenuItemText(mr, ptitle, 0);
 err = SetMenuItemRefCon(mr, 1, (UInt32) (&item));
+item.user_data_ = data;
 }
 
 
+
 void show_apropos(Fl_Widget *w, void *data)
 {
-DialogItemIndex tmp;
-DialogRef dptr;
+static Fl_Window *about = NULL;
+char line[100], *p;
 
-dptr = GetNewDialog(129, NULL, (WindowPtr)-1L);
-ModalDialog(  NewModalFilterUPP(myfilter), &tmp);
-DisposeDialog(dptr);
+if(about == NULL) {
+	about = new Fl_Window(600, 400, "About seaview");
+	Fl_Browser *br = new Fl_Browser(1, 1, about->w() - 2, about->h() - 2);
+	about->end();
+	br->add("");
+#if TARGET_RT_MAC_MACHO
+	data = (void *)fopen((char *)data, "r");
+	if(data == NULL) return;
+#else
+	get_next_help_line(data, NULL, 0);
+#endif
+	get_next_help_line(data, line, sizeof(line));
+	if(strncmp(line, ">>>", 3) != 0) br->add(line);
+	while(TRUE) {
+		get_next_help_line(data, line, sizeof(line));
+		if(strncmp(line, ">>>", 3) == 0) break;
+		while( (p=strchr(line,'\r')) != NULL) *p = 0;
+		while( (p=strchr(line,'\n')) != NULL) *p = 0;
+		br->add(line);
+		}
+#if TARGET_RT_MAC_MACHO
+	fclose((FILE*)data);
+#else
+	get_next_help_line(data, NULL, 0);
+#endif
+	}
+about->show();
 }
 
 
-pascal Boolean myfilter(DialogPtr dptr, EventRecord *event, DialogItemIndex *item)
-{
-if(event->what == mouseDown) {
-	*item = 1;
-	return TRUE;
-	}
-else 
-	return FALSE;
-}
 
-
 /***********************************************************************/
 Boolean AppleEventsInstalled ()
 {
@@ -264,19 +363,14 @@
 }
 
 /***********************************************************************/
-pascal OSErr  MyHandleODoc (const AppleEvent *theAppleEvent, AppleEvent* reply, UInt32 handlerRefCon)
+pascal OSErr  MyHandleODoc (const AppleEvent *theAppleEvent, AppleEvent* reply, long handlerRefCon)
 {
-	FSSpec	myFSS;
+	FSRef myFSRef;	
 	AEDescList	docList;
 	OSErr	err;
-	long	index, itemsInList;
+	long	itemsInList;
 	Size	actualSize;
-	AEKeyword	keywd;
-	DescType	returnedType;
-	FSRef myFSRef;
-	FSCatalogInfo myinfo;
 	char masename[300];
-	known_format defaultformat;
 
 	err = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList,
 			&docList);
@@ -287,29 +381,22 @@
 
 	err = AECountItems (&docList, &itemsInList);
 
-	index = 1;
-	err = AEGetNthPtr (&docList, index, typeFSS, &keywd,
-		&returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize);
+	err = AEGetNthPtr (&docList, 1, typeFSRef, NULL,
+		NULL,  &myFSRef, sizeof(FSRef), NULL);
 	if (err) return err;
 	
-	MG_FSSpecToPathname(&myFSS, masename, sizeof(masename) );
+	err = FSRefMakePath(&myFSRef, (UInt8 *)masename, sizeof(masename));
 	use_initial_file(view, masename);
 	err = AEDisposeDesc (&docList);
 	return noErr;
 }
 
 /***********************************************************************/
-pascal OSErr  MyHandlePDoc (const AppleEvent *theAppleEvent, AppleEvent *reply, UInt32 handlerRefCon)
+pascal OSErr  MyHandlePDoc (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
 {
-	FSSpec	myFSS;
 	AEDescList	docList;
 	OSErr	err;
-	long	index,
-					itemsInList;
-	Size	actualSize;
-	AEKeyword	keywd;
-	DescType	returnedType;
-	char		fname[256], dirname[256];
+	long	itemsInList;
 	
 	// get the direct parameter--a descriptor list--and put it into a docList
 	err = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList,
@@ -333,14 +420,14 @@
 }
 
 /***********************************************************************/
-pascal OSErr  MyHandleOApp (const AppleEvent *theAppleEvent, AppleEvent *reply, UInt32 handlerRefCon)
+pascal OSErr  MyHandleOApp (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
 {
 	// Ouverture de l'appli
 	return noErr;
 }
 
 /***********************************************************************/
-pascal OSErr  MyHandleQApp (const AppleEvent *theAppleEvent, AppleEvent *reply, UInt32 handlerRefCon)
+pascal OSErr  MyHandleQApp (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefCon)
 {
 	// Quitte l'appli
 //	quitAEReceived = 1;
@@ -367,10 +454,21 @@
 }
 
 
+void MG_apple_inits(void)
+{
+#ifdef __APPLE_QD__
+Fl::set_font(FL_COURIER," Courier");
+Fl::set_font(FL_COURIER_BOLD,"BCourier");
+#else
+Fl::set_font(FL_COURIER,"Courier");
+Fl::set_font(FL_COURIER_BOLD,"Courier Bold");
 #endif
+}
 
+#endif
 
 
+
 #ifdef WIN32
 
 
@@ -445,6 +543,40 @@
 Beep(0,0);
 }
 
+char *MG_win32_file_chooser(const char* message, // title of dialog window
+        const char* pattern, // optional "mase format\0*.mase\0MSF format\0*.msf\0"
+        const char* fname, // default file name
+        const char* defext, // default filename extension or NULL
+        bool save, // TRUE iff output file selection
+        int *pfilterindex) // (inout) pointer to index (from 1) in series of file types in pattern
+ {
+     static char filenamebuffer[MAX_PATH];
+     static OPENFILENAME wreq;
+     bool retval;
+     
+     memset(&wreq, 0, sizeof(wreq));
+     wreq.lStructSize = sizeof(OPENFILENAME); 
+     wreq.lpstrFilter = pattern;
+     if(pattern == NULL) wreq.nFilterIndex = 0;
+     else if(pfilterindex != NULL) wreq.nFilterIndex = *pfilterindex;
+     else wreq.nFilterIndex = 1;
+     if(defext != NULL) wreq.lpstrDefExt = defext;
+     wreq.lpstrFile = filenamebuffer;
+     wreq.nMaxFile = MAX_PATH;
+     wreq.lpstrTitle = message ? message : "Select the filename";
+     if(fname) {
+       memset(filenamebuffer, 0, MAX_PATH);
+       if((filenamebuffer[1] == ':') && (_getdrive() + 'A' - 1 == filenamebuffer[0]))
+   strncpy(filenamebuffer, fname + 2, MAX_PATH);
+       else
+   strncpy(filenamebuffer, fname, MAX_PATH);
+     }
+     wreq.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
+     retval = (save ? GetSaveFileName(&wreq) : GetOpenFileName(&wreq));
+     if(save && (pfilterindex != NULL) ) *pfilterindex = wreq.nFilterIndex;
+     return retval == 0 ? NULL : wreq.lpstrFile;
+ }
+ 
 
 /*
 char **split_args(char *all, int *pargc)

Deleted: trunk/packages/seaview/trunk/makefile
===================================================================
--- trunk/packages/seaview/trunk/makefile	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/makefile	2006-09-22 05:38:11 UTC (rev 121)
@@ -1,19 +0,0 @@
-FLTK = ../fltk-1.1.0
-
-OBJECTS = seaview.o use_mase_files.o regions.o load_seq.o align.o xfmatpt.o comlines.o chooser_plus.o resource.o nexus.o old_file_chooser.o
-
-CFLAGS  = -c $(OPT) -I. $(DEBUG)
-
-CXX = g++
-
-seaview : $(OBJECTS) 
-	$(CXX) $(DEBUG) -o $@ $(OBJECTS) `fltk-config --ldflags`
-
-
-.SUFFIXES:	.cxx .h .o
-
-.cxx.o :
-	$(CXX) $(CFLAGS) $<
-
-clean :
-	rm -f seaview $(OBJECTS)

Modified: trunk/packages/seaview/trunk/nexus.cxx
===================================================================
--- trunk/packages/seaview/trunk/nexus.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/nexus.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -16,7 +16,7 @@
 	list_regions **charsets, int *pnum_species_sets,
 	int ***list_species_sets, char ***name_species_sets,
 	int *ptot_comment_lines, char ***comment_name, char ***comment_line,
-	int **comment_length);
+	int **comment_length, int *protein);
 int read_nexus_file(FILE *in, char ***pseqs, int *nchars, int *protein,
 	char ***taxnames, char ***notes, char **header,
 	int *pnum_species_sets, int ***list_species_sets, 
@@ -299,9 +299,9 @@
 		}
 	else if(strcmp(p, "GAP") == 0) {
 		next_token(in); /* skip = */
-		p = next_token(in);
-		if(p == NULL) break;
-		gap = *p;
+		do gap = fgetc(in);
+		while(isspace(gap));
+		if(gap == EOF) break;
 		}
 	else if(strcmp(p, "MATCHCHAR") == 0) {
 		next_token(in); /* skip = */
@@ -311,9 +311,9 @@
 		}
 	else if(strcmp(p, "MISSING") == 0) {
 		next_token(in); /* skip = */
-		p = next_token(in);
-		if(p == NULL) break;
-		*missing = *p;
+		do *missing = fgetc(in);
+		while(isspace(*missing));
+		if(*missing == EOF) break;
 		}
 	else if(strcmp(p, "INTERLEAVE") == 0) {
 		*interleave = TRUE;
@@ -408,7 +408,7 @@
 {
 char *p;
 list_segments *list = NULL, *next, *elt;
-int num, previous = -1, need_range = FALSE;
+int num, previous = -1, need_range = FALSE, debut, fin;
 
 while(TRUE) {
 	p = next_token(in);
@@ -418,6 +418,25 @@
 		continue;
 		}
 	if(strcmp(p, ".") == 0) num = maxi;
+	else if(strcmp(p, "\\") == 0) { /* process syntax: from-to\step */
+		p = next_token(in);
+		if(p == NULL) return NULL;
+		num = -1; sscanf(p, "%d", &num); /* num has the step value */
+		if(num == -1 || list == NULL) { skip_command(in); return NULL; }
+		debut = next->debut; fin = next->fin;
+		next->fin = debut;
+		debut += num;
+		while(debut <= fin) {
+			elt = (list_segments *)malloc(sizeof(list_segments));
+			if(elt == NULL) { skip_command(in); return NULL; }
+			elt->debut = elt->fin = debut;
+			elt->next = NULL;
+			next->next = elt;
+			next = elt;
+			debut += num;
+			}
+		continue;
+		}
 	else {num = -1; sscanf(p, "%d", &num); }
 	if(num == -1) { skip_command(in); return NULL; }
 	if(need_range) {
@@ -493,6 +512,7 @@
 		while(*(++p) != 0) if(*p == matchchar) *p = seq[0][p - seq[num]];
 		}
 	}
+/*
 if(missing != 0) {
 	char miss_char = (protein ? 'X' : 'N');
 	for(num = 0; num < ntaxa; num++) {
@@ -500,6 +520,7 @@
 		while(*(++p) != 0) if(*p == missing) *p = miss_char;
 		}
 	}
+*/
 return seq;
 }
 
@@ -508,10 +529,10 @@
 	char **taxnames, int define_taxlabels, int matchchar, int missing,
 	int protein)
 {
-int num, c, newtaxa = 0;
+int num, c, newtaxa = 0, offset;
 char *p, **seq;
 
-seq = (char **)malloc(ntaxa * sizeof(char *));
+seq = (char **)calloc(ntaxa , sizeof(char *));
 if(seq == NULL) { skip_command(in); return NULL;}
 for(num = 0; num < ntaxa; num++) seq[num] = NULL;
 while(TRUE) {
@@ -528,13 +549,20 @@
 				}
 			}
 		}
-	else num = find_by_name_num(p, ntaxa, taxnames);
+	else 	{
+		offset = 0;
+		do 	{/* handle repetitions of names */
+			num = find_by_name_num(p, ntaxa - offset, taxnames + offset);
+			if(num != -1) num += offset;			
+			offset = num + 1;
+			}
+		while(num != -1 && seq[num] != NULL);
+		}
 	if(num == -1) { /* bad format */
 		skip_command(in);
 		free(seq);
 		return NULL;
 		}
-	if(seq[num] != NULL) free(seq[num]);
 	seq[num] = (char *)malloc(nsites + 1);
 	if(seq[num] == NULL)  { skip_command(in); free(seq); return NULL;}
 	p = seq[num];
@@ -567,6 +595,7 @@
 		while(*(++p) != 0) if(*p == matchchar) *p = seq[0][p - seq[num]];
 		}
 	}
+/*
 if(missing != 0) {
 	char miss_char = (protein ? 'X' : 'N');
 	for(num = 0; num < ntaxa; num++) {
@@ -574,6 +603,7 @@
 		while(*(++p) != 0) if(*p == missing) *p = miss_char;
 		}
 	}
+*/
 return seq;
 }
 
@@ -977,16 +1007,16 @@
 	list_regions **charsets, int *pnum_species_sets,
 	int ***list_species_sets, char ***name_species_sets,
 	int *ptot_comment_lines, char ***comment_name, char ***comment_line,
-	int **comment_length)
+	int **comment_length, int *protein)
 {
 FILE *in;
-int lseqs, protein, i, tot;
+int lseqs, i, tot;
 
 if( (in = is_nexus_file(fname) ) == NULL) {
 	*err_message = "not a NEXUS file";
 	return 0;
 	}
-tot = read_nexus_file(in, pseqs, &lseqs, &protein, pseqnames, 
+tot = read_nexus_file(in, pseqs, &lseqs, protein, pseqnames, 
 	pcomments, pheader,
 	pnum_species_sets, list_species_sets, name_species_sets,
 	charsets, ptot_comment_lines, comment_name, comment_line);

Deleted: trunk/packages/seaview/trunk/old_file_chooser.cxx
===================================================================
--- trunk/packages/seaview/trunk/old_file_chooser.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/old_file_chooser.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -1,738 +0,0 @@
-//
-// "$Id: fl_file_chooser.cxx,v 1.10.2.7 2000/12/06 15:45:13 easysw Exp $"
-//
-// File chooser widget for the Fast Light Tool Kit (FLTK).
-//
-// Copyright 1998-2000 by Bill Spitzak and others.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA.
-//
-// Please report all bugs and problems to "fltk-bugs at fltk.org".
-//
-
-#include <config.h>
-
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-#include <FL/Fl_Box.H>
-#include <FL/Fl_Button.H>
-#include <FL/Fl_Return_Button.H>
-#include <FL/Fl_Browser_.H>
-#include <FL/Fl_Input.H>
-#include <FL/fl_draw.H>
-#include <FL/filename.H>
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-
-#ifdef __APPLE__
-#define fl_filename_isdir filename_isdir_mac
-extern "C" { 
-	int filename_isdir_mac( const char *dirname ); 
-	void CtoP(const void *in, void *out);
-	void MG_FSSpecToPathname (FSSpec *myFSS, char *fname, int maxl);
-	}
-#endif
-
-static void default_callback(const char*) {}
-static void (*current_callback)(const char*) = default_callback;
-void fl_file_chooser_callback(void (*cb)(const char*)) {
-  current_callback = cb ? cb : default_callback;
-}
-
-
-// "File Chooser Browser" widget:
-class FCB : public Fl_Browser_ {
-  void* item_first() const ;
-  void* item_next(void*) const ;
-  void* item_prev(void*) const ;
-  int item_height(const dirent*, int) const ;
-  int item_height(void*) const ;
-  int item_width(const dirent*) const ;
-  int item_width(void*) const ;
-  int item_quick_height(void*) const ;
-  int incr_height() const ;
-  void item_draw(void*, int, int, int, int) const ;
-  int checkdir(const dirent*, char*) const ;
-  void draw();
-  void clear_prev();
-public:
-  char listed[FL_PATH_MAX];// current dir & starname
-  int dirend;		// points after last / before starname
-  int nameend;		// length to trailing '*' or '\0'
-  const char* pattern;	// default pattern
-  dirent** list;	// the file names
-  dirent** last;	// pointer after end of list
-  const char* message;	// message if no file names
-  char preved[FL_PATH_MAX];// directory listed in prev
-  dirent** prev;	// cached list of another directory
-  dirent** prev_last;	// end of that list
-  int prev_count;
-  FCB(int x, int y, int w, int h) : Fl_Browser_(x, y, w, h, 0) {
-    type(FL_HOLD_BROWSER);
-    listed[0] = 0;
-    dirend = nameend = 1;
-    pattern = 0;
-    list = prev = 0;
-    message = 0;
-  }
-  // ~FCB nyi
-  void clear();
-  void set(const char*);
-  int get(char*);
-};
-
-// "File Chooser Window" widget:
-class FCW : public Fl_Window {
-public:
-  int handle(int);
-  Fl_Input input;
-  Fl_Button* ok_button;
-  Fl_Button* cancel_button;
-  Fl_Button* normal_button;
-  Fl_Button* cwd_button; // + MG
-  FCB browser;
-  FCW();
-};
-
-#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
-// ':' needs very special handling!
-static inline int isdirsep(char c) {return c=='/' || c=='\\';}
-#elif defined(__APPLE__)
-#define isdirsep(c) ((c)=='/')
-#else
-#define isdirsep(c) ((c)=='/')
-#endif
-
-#if defined(__APPLE__)
-#define dirsep '/'
-#else
-#define dirsep '/'
-#endif
-
-
-/* Files are marked as being directories by replacing the trailing null
-   with a '/' if it is a directory, a '\001' if it is *not* a directory.
-   An item has height (and is thus selectable) if it is either a directory
-   or if it matches the pattern.  Quick-height assummes all unknown files
-   are directories, and thus saves the time needed to do a stat().
-*/
-
-// return pointer to last character:
-static const char* end_of_name(const dirent* d) {
-#if HAVE_DIRENT_H || defined(__APPLE__) || defined(WIN32)
-  const char* e;
-  for (e = d->d_name; ;e++) switch (*e) {
-  case 0: case 1: 
-#ifdef __APPLE__
-  case '/': 
-#else
-  case '/': 
-#endif
-  return e;
-  }
-#else
-  // warning: clobbers byte after end of name
-  return d->d_name + d->d_namelen;
-#endif
-}
-
-// return true if item is directory, when given pointer to last character:
-int FCB::checkdir(const dirent* d, char* e) const {
-  if (*e == 1) return 0;
-#ifdef __APPLE__
-  if (*e == '/') return 1;
-#else
-  if (*e == '/') return 1;
-#endif
-  char buf[FL_PATH_MAX];
-  memcpy(buf, listed, dirend);
-  memcpy(buf+dirend, d->d_name, e-d->d_name);
-  *(buf+dirend+(e-d->d_name)) = 0;
-  if (fl_filename_isdir(buf)) {
-    *e = '/';
-    return 1;
-  } else {
-    *e = 1; return 0;
-  }
-}
-
-void* FCB::item_first() const {return list;}
-
-void* FCB::item_next(void* p) const {
-  if ((dirent**)p+1 >= last) return 0;
-  return (dirent**)p+1;
-}
-
-void* FCB::item_prev(void* p) const {
-  if ((dirent**)p <= list) return 0;
-  return ((dirent**)p)-1;
-}
-
-#ifdef _MSC_VER
-#pragma optimize("a",off) // without this it does not change *e
-#endif
-static int ido_matching(const dirent* p, const char* e, const char* n) {
-  // replace / or 1 at end with 0 and do match, then put back.  yukko
-  int save = *e; *(char*)e = 0;
-  int r = fl_filename_match(p->d_name, n);
-  *(char*)e = save;
-  return(r);
-}
-#ifdef _MSC_VER
-#pragma optimize("",on)
-#endif
-
-int FCB::incr_height() const {return textsize()+2;}
-
-int FCB::item_height(const dirent* p, int slow) const {
-  const char* e = end_of_name(p);
-  if (listed[dirend]) {
-//  if (p->d_name[0]=='.' && listed[dirend]!='.') return 0;
-    if (isdirsep( listed[nameend-1] )) {
-      if (slow ? !checkdir(p, (char*)e) : *e==1) return 0;
-      ((char*)listed)[nameend-1] = 0;
-      int r = ido_matching(p, e, listed+dirend);
-      ((char*)listed)[nameend-1] = dirsep;
-      if (!r) return 0;
-    } else {
-      if (!ido_matching(p, e, listed+dirend)) return 0;
-    }
-  } else {
-    if (p->d_name[0]=='.') return 0;
-    if (pattern && (slow ? !checkdir(p, (char*)e) : *e==1) &&
-	!ido_matching(p, e, pattern)) return 0;
-  }
-  return textsize()+2;
-}
-
-int FCB::item_height(void* x) const {
-  return item_height(*(const dirent**)x, 1);
-}
-
-int FCB::item_quick_height(void* x) const {
-  return item_height(*(const dirent**)x, 0);
-}
-
-void FCB::item_draw(void* v, int x, int y, int, int h) const {
-  const dirent* p = *(const dirent**)v;
-  const char* e = end_of_name(p);
-  if (checkdir(p, (char*)e)) e++;
-  if (v == selection()) fl_color(fl_contrast(textcolor(), selection_color()));
-  else fl_color(textcolor());
-  fl_font(textfont(), textsize());
-  fl_draw(p->d_name, e-p->d_name, x+4, y+h-3);
-}
-
-int FCB::item_width(const dirent* p) const {
-  const char* e = end_of_name(p); if (isdirsep( *e) ) e++;
-  fl_font(textfont(), textsize());
-  return (int)fl_width(p->d_name, e-p->d_name)+4;
-}
-
-int FCB::item_width(void* x) const {
-  return item_width(*(const dirent**)x);
-}
-
-// "get" the current value by copying the name of the selected file
-// or if none are selected, by copying as many common letters as
-// possible of the matched file list:
-int FCB::get(char* buf) {
-  dirent** q = (dirent**)selection(); // the file to copy from
-  int n = 0;	// number of letters
-  if (q) {	// a file is selected
-    const char* e = end_of_name(*q);
-    n = e - (*q)->d_name;
-    if (isdirsep(*e)) n++;
-  } else {	// do filename completion
-    for (q = list; q < last && !item_height(*q, 0); q++);
-    if (q < last) {
-      const char* e = end_of_name(*q);
-      n = e - (*q)->d_name;
-      if (isdirsep(*e)) n++;
-      for (dirent** r = q+1; n && r < last; r++) {
-	if (!item_height(*r, 0)) continue;
-	int i;
-#if defined(_WIN32) || defined(WIN32) || defined(__APPLE__)
-	for (i=0; i<n && tolower((*q)->d_name[i])==tolower((*r)->d_name[i]); i++) {}
-#else
-	for (i=0; i<n && (*q)->d_name[i]==(*r)->d_name[i]; i++) {}
-#endif
-	n = i;
-      }
-    }
-  }
-  if (n) {
-    memcpy(buf, listed, dirend);
-    memcpy(buf+dirend, (*q)->d_name, n);
-    buf[dirend+n]=0;
-  }
-  return n;
-}
-
-// "set" the current value by changing the directory being listed and
-// changing the highlighted item, if possible:
-void FCB::set(const char* buf) {
-
-  int bufdirend;
-  int ispattern = 0;
-  const char* c = buf;
-  for (bufdirend=0; *c;) switch(*c++) {
-  case '?': case '[': case '*': case '{': ispattern = 1; goto BREAK;
-#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
-  case '\\':
-#endif
-  case '/': bufdirend=c-buf; break;
-  }
-#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
-  if ((!bufdirend) && isalpha(buf[0]) && (buf[1]==':')) bufdirend = 2;
-#endif
- BREAK:
-  int bufend = strlen(buf);
-  if (bufend<=bufdirend) ispattern = 1;
-
-  // if directory is different, change list to xxx/ :
-  if (bufdirend != dirend || strncmp(buf, listed, bufdirend)) {
-    if (prev &&
-	preved[bufdirend]==0 && !strncmp(buf, preved, bufdirend)) {
-      strcpy(preved, listed); preved[dirend] = 0;
-      dirent** t;
-      t = prev; prev = list; list = t;
-      t = prev_last; prev_last = last; last = t;
-      strcpy(listed, buf);
-      dirend = nameend = bufdirend;
-      message = 0;
-    } else {
-      if (list) {
-	clear_prev();
-	strcpy(preved, listed); preved[dirend]=0;
-	prev = list;
-	prev_last = last;
-      }
-      list = last = 0;
-      message = "reading..."; redraw(); Fl::flush(); redraw();
-      strcpy(listed, buf);
-      dirend = nameend = bufdirend;
-      listed[dirend] = listed[dirend+1] = 0;
-      int n = fl_filename_list( dirend ? listed : "." , &list, NULL);
-      if (n < 0) {
-#ifndef __APPLE__
-	if (errno==ENOENT) 
-	  message = "No such directory";
-	else 
-#endif
-	  message = strerror(errno);
-	n = 0; list = 0;
-      } else message = 0;
-      last = list+n;
-    }
-    if (list && last <= list+2) message = "Empty directory";
-    new_list();
-  }
-
-  dirent** q = 0; // will point to future selection
-  int any = 0; // true if any names shown
-
-  // do we match one item in the previous list?
-  if (!ispattern && bufend >= nameend) {
-    for (q = list; ; q++) {
-      if (q >= last) {q = 0; break;}
-      if (item_height(*q, 0)==0) continue;
-      any = 1;
-      const char* a = (*q)->d_name;
-      const char* b = buf+bufdirend;
-#if ( defined(WIN32) && !defined(__CYGWIN__) ) || defined ( __APPLE__ )
-      while (*b && tolower(*a)==tolower(*b)) {a++; b++;}
-#else
-      while (*b && *a==*b) {a++; b++;}
-#endif
-      if (!*b && (*a==0 || /* *a=='/' ||*/ *a==1)) break;
-    }
-  }
-
-  // no, change the list pattern to the new text + a star:
-  if (!q) {
-    strcpy(listed+dirend, buf+bufdirend);
-    nameend = bufend;
-    if (!ispattern) {listed[nameend]='*'; listed[nameend+1]=0;}
-    any = 0;
-    // search again for an exact match:
-    for (q = list; ; q++) {
-      if (q >= last) {q = 0; break;}
-      if (item_height(*q, 0)==0) continue;
-      any = 1;
-      const char* a = (*q)->d_name;
-      const char* b = buf+bufdirend;
-#if ( defined(WIN32) && !defined(__CYGWIN__) ) || defined ( __APPLE__ )
-      while (*b && tolower(*a)==tolower(*b)) {a++; b++;}
-#else
-      while (*b && *a==*b) {a++; b++;}
-#endif
-      if (!*b && (*a==0 || /* *a=='/' ||*/ *a==1)) break;
-    }
-    new_list();
-  }
-
-  if (any) message = 0;
-  else if (!message) message = "No matching files";
-  select_only(q);
-  if (q) current_callback(buf);
-}
-
-void FCB::draw() {
-  if (!message) {
-    Fl_Browser_::draw();
-    if (full_height() > 0) return;
-    message = "No matching files";
-  }
-  Fl_Boxtype b = box(); if (!b) b = FL_DOWN_BOX;
-  draw_box(b,color());
-  fl_color(FL_INACTIVE_COLOR);
-  fl_font(textfont(), textsize());
-  fl_draw(message, x()+7, y()+3, w(), h()-3, FL_ALIGN_TOP_LEFT);
-  // insure scrollbars are redrawn if error message goes away:
-  scrollbar.redraw();
-  hscrollbar.redraw();
-}
-
-void FCB::clear_prev() {
-  if (prev) {
-    for (dirent**p=prev_last-1; p>=prev; p--) free((void*)*p);
-    free((void*)prev);
-    prev = prev_last = 0;
-  }
-}
-
-void FCB::clear() {
-  if (list) {
-    for (dirent**p=last-1; p>=list; p--) free((void*)*p);
-    free((void*)list);
-    list = last = 0;
-  }
-  clear_prev();
-  listed[0] = 0; dirend = 1;
-}
-
-////////////////////////////////////////////////////////////////
-
-static void fcb_cb(Fl_Widget*, void* v) {
-  FCW* w = (FCW*)v;
-  char buf[FL_PATH_MAX];
-  if (w->browser.get(buf)) {
-    w->input.value(buf);
-    w->input.position(10000);
-//  w->input.position(10000, w->browser.dirend);
-    if (Fl::event_button()==1) {
-      if (Fl::event_clicks()) w->ok_button->do_callback();
-      else w->browser.set(buf);
-    } else {
-      current_callback(buf);
-    }
-  }
-}
-
-static void tab_cb(Fl_Widget*, void* v) {
-  FCW* w = (FCW*)v;
-  char buf[FL_PATH_MAX];
-  if (w->browser.get(buf)) {
-    w->input.value(buf);
-    w->input.position(10000);
-    w->browser.set(buf);
-  }
-}
-
-
-static void input_cb(Fl_Widget*, void* v) {
-  FCW* w = (FCW*)v;
-  const char* buf = w->input.value();
-  char localbuf[FL_PATH_MAX];
-  if (buf[0] && isdirsep(buf[w->input.size()-1])
-      && fl_filename_expand(localbuf, buf)) {
-    buf = localbuf;
-    w->input.value(localbuf);
-    w->input.position(10000);
-  }
-  w->browser.set(buf);
-}
-
-static void up_cb(Fl_Widget*, void* v) { // the .. button
-  FCW* w = (FCW*)v;
-  char* p;
-  const char* newname;
-  char buf[FL_PATH_MAX];
-  p = w->browser.listed+w->browser.dirend-1; // point right before last '/'
-  if (p < w->browser.listed)
-    newname = "../"; // go up from current directory
-  else {
-    for (; p>w->browser.listed; p--) if (isdirsep(*(p-1))) break;
-    if (isdirsep(*p) || *p=='.' &&
-	(isdirsep(p[1]) || p[1]=='.' && isdirsep(p[2]))) {
-      p = w->browser.listed+w->browser.dirend;
-      memcpy(buf, w->browser.listed, p-w->browser.listed);
-      strcpy(buf+(p-w->browser.listed), "../");
-    } else {
-      memcpy(buf, w->browser.listed, p-w->browser.listed);
-      buf[p-w->browser.listed] = 0;
-    }
-    newname = buf;
-  }
-  w->input.value(newname);
-  w->input.position(10000);
-  w->browser.set(newname);
-}
-
-static void dir_cb(Fl_Widget* obj, void* v) { // directory buttons
-  FCW* w = (FCW*)v;
-  const char* p = obj->label(); if (*p=='&') p++;
-  char buf[FL_PATH_MAX];
-  char* q; for (q=buf; *p && *p!=' '; *q++ = *p++); *q = 0;
-  fl_filename_expand(buf, buf);
-  w->input.value(buf);
-  w->input.position(10000);
-  w->browser.set(buf);
-}
-
-static void working_cb(Fl_Widget*, void* v) { // directory buttons
-  FCW*w = (FCW*)v;
-  char buf[FL_PATH_MAX];
-  fl_filename_absolute(buf, 100, "");
-  w->input.value(buf);
-  w->input.position(10000);
-  w->browser.set(buf);
-}
-
-static void files_cb(Fl_Widget* obj, void* v) { // file pattern buttons
-  FCW* w = (FCW*)v;
-  char buf[FL_PATH_MAX];
-  strcpy(buf, w->input.value());
-  char* q = buf+w->browser.dirend;
-  if (obj != w->normal_button) {	// tack on first word of label
-    const char* p = obj->label(); if (*p=='&') p++;
-    for (; *p && *p!=' '; *q++ = *p++);
-  }
-  *q = 0;
-  w->input.value(buf);
-  w->input.position(10000, w->browser.dirend);
-  w->browser.set(buf);
-}
-
-/*----------------------- The Main Routine ----------------------*/
-#define HEIGHT_BOX	(4*WIDTH_SPC+HEIGHT_BUT+HEIGHT_INPUT+HEIGHT_BROWSER)
-#define HEIGHT_BUT	23
-#define HEIGHT_INPUT	23
-#define HEIGHT_BROWSER	(9*HEIGHT_BUT+2) // must be > buttons*HEIGHT_BUT
-#define WIDTH_BOX	(3*WIDTH_SPC+WIDTH_BUT+WIDTH_BROWSER)
-#define WIDTH_BROWSER	350
-#define WIDTH_BUT	125
-#define WIDTH_OK	60
-#define WIDTH_SPC	5
-
-int FCW::handle(int event) {
-  if (Fl_Window::handle(event)) return 1;
-  if (event==FL_KEYBOARD && Fl::event_key()==FL_Tab) {
-    tab_cb(this, this);
-    return 1;
-  }
-  return 0;
-}
-
-// set this to make extra directory-jumping button:
-const char* fl_file_chooser_button;
-extern const char* fl_ok;
-extern const char* fl_cancel;
-
-FCW::FCW() : Fl_Window(WIDTH_BOX, HEIGHT_BOX),
-	input(WIDTH_SPC, HEIGHT_BOX-HEIGHT_BUT-2*WIDTH_SPC-HEIGHT_INPUT,
-	      WIDTH_BOX-2*WIDTH_SPC, HEIGHT_INPUT, 0),
-	browser(2*WIDTH_SPC+WIDTH_BUT, WIDTH_SPC,
-		WIDTH_BROWSER, HEIGHT_BROWSER)
-{
-  int but_y = WIDTH_SPC;
-  input.callback(input_cb, this);
-  input.when(FL_WHEN_CHANGED);
-  //  add(browser);
-  browser.callback(fcb_cb, this);
-
-  begin();
-  Fl_Widget* obj;
-  obj = ok_button = new Fl_Return_Button(
-    WIDTH_BOX-2*(WIDTH_SPC+WIDTH_OK), HEIGHT_BOX-WIDTH_SPC-HEIGHT_BUT,
-    WIDTH_OK, HEIGHT_BUT, fl_ok);
-  obj = cancel_button = new Fl_Button(
-    WIDTH_BOX-WIDTH_SPC-WIDTH_OK, HEIGHT_BOX-WIDTH_SPC-HEIGHT_BUT,
-    WIDTH_OK, HEIGHT_BUT, fl_cancel);
-  cancel_button->shortcut("^[");
-
-  obj=new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT, "&Up one directory");
-  obj->callback(up_cb, this);
-  but_y += HEIGHT_BUT;
-#ifndef __APPLE__
-  obj = new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, "&~/ Home");
-  obj->callback(dir_cb, this);
-  but_y += HEIGHT_BUT;
-#endif
-  obj = new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, "&/ Root");
-  obj->callback(dir_cb, this);
-  but_y += HEIGHT_BUT;
-
-  cwd_button = new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, "&Current dir");
-  cwd_button->callback(working_cb, this);
-  but_y += HEIGHT_BUT;
-
-  if (fl_file_chooser_button) {
-    obj=new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT,fl_file_chooser_button);
-    obj->callback(dir_cb, this);
-    but_y += HEIGHT_BUT;
-  }
-
-  normal_button = new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, "");
-  normal_button->callback(files_cb, this);
-  but_y += HEIGHT_BUT;
-
-  obj = new Fl_Button(WIDTH_SPC,but_y, WIDTH_BUT, HEIGHT_BUT, "* &All files");
-  obj->callback(files_cb, this);
-  but_y += HEIGHT_BUT;
-#ifndef __APPLE__
-  obj = new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT, ". &Hidden files");
-  obj->callback(files_cb, this);
-  but_y += HEIGHT_BUT;
-#endif
-
-  obj = new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT, "*/ &Directories");
-  obj->callback(files_cb, this);
-  but_y += HEIGHT_BUT;
-
-  resizable(new Fl_Box(browser.x(), but_y,
-		       ok_button->x()-browser.x(),
-		       browser.y()+browser.h()-but_y));
-  // add(input); // put last for better draw() speed
-  end();
-  set_modal();
-}
-
-
-#ifdef __APPLE__
-
-static pascal void MyNavEventProc (NavEventCallbackMessage callBackSelector,
-                                   NavCBRecPtr callBackParms,
-                                   NavCallBackUserData callBackUD)
-{
-return;
-}
-
-
-int MG_GetInputFName(char *fname, int maxl, char *title)
-{
-    NavEventUPP         eventProc = NewNavEventUPP(MyNavEventProc);
-    OSErr               anErr = noErr;
-    FSSpec              fss;
-	int         rsult = FALSE;
-    NavReplyRecord reply;
-    NavDialogOptions options;
-    NavGetDefaultDialogOptions(&options);
-    CtoP(title, options.windowTitle);
-    options.dialogOptionFlags &= ~ kNavAllowPreviews;
-    options.dialogOptionFlags &= ~ kNavAllowMultipleFiles;
-    options.dialogOptionFlags |=   kNavNoTypePopup;
-
-
-            anErr = NavChooseFile (NULL  , &reply, &options, eventProc, NULL, NULL,
-                                   NULL , 0);
-            if (anErr == noErr && reply.validRecord)
-            {
-                        AEKeyword   theKeyword;
-                        DescType    actualType;
-                        Size        actualSize;
-                        FSSpec      documentFSSpec;
-
-                        anErr = AEGetNthPtr(&(reply.selection), 1,
-                                            typeFSS, &theKeyword,
-                                            &actualType,&documentFSSpec,
-                                            sizeof(documentFSSpec),
-                                            &actualSize);
-                        if (anErr == noErr)
-                        {
-                            MG_FSSpecToPathname (&documentFSSpec, fname, maxl);
-                            rsult = TRUE;
-                        }
-                //  Dispose of NavReplyRecord, resources, descriptors
-                anErr = NavDisposeReply(&reply);
-            }
-    DisposeNavEventUPP(eventProc);
-    return rsult;
-}
-
-
-char* fl_file_chooser(const char* message, const char* pat, const char* fname)
-{
-	static char pathname[FL_PATH_MAX];
-	if( MG_GetInputFName(pathname, FL_PATH_MAX, (char *)message) ) return pathname;
-	else return NULL;
-}
-
-#else
-
-char* fl_file_chooser(const char* message, const char* pat, const char* fname)
-{
-  static FCW* f; if (!f) f = new FCW();
-  f->ok_button->label(fl_ok);
-  f->cancel_button->label(fl_cancel);
-
-  if (pat && !*pat) pat = 0;
-  if (fname && *fname) {
-    f->input.value(fname);
-  } else if (f->browser.pattern != pat && (!pat || !f->browser.pattern ||
-					   strcmp(pat,f->browser.pattern))) {
-    // if pattern is different, remove name but leave old directory:
-    const char* p = f->input.value();
-    const char* q = fl_filename_name(p);
-    f->input.value(p, q-p);
-  }
-  f->browser.pattern = pat;
-  f->normal_button->label(pat ? pat : "visible files");
-  f->browser.set(f->input.value());
-  f->input.position(10000, f->browser.dirend);
-
-  f->label(message);
-  f->hotspot(f);
-  f->show();
-  int ok = 0;
-  for (;;) {
-    Fl::wait();
-    Fl_Widget* o = Fl::readqueue();
-    if (o == f->ok_button) {ok = 1; break;}
-    else if (o == f->cancel_button || o == f) break;
-  }
-  f->hide();
-  f->browser.clear();
-
-  if (!ok) return 0;
-  const char* r = f->input.value();
-  const char* p;
-  for (p=r+f->browser.dirend; *p; p++)
-    if (*p=='*' || *p=='?' || *p=='[' || *p=='{') return 0;
-  static char final[FL_PATH_MAX];
-  strcpy(final, r);
-  return final;
-}
-
-
-#endif
-//
-// End of "$Id: fl_file_chooser.cxx,v 1.10.2.7 2000/12/06 15:45:13 easysw Exp $".
-//

Copied: trunk/packages/seaview/trunk/pdf.cxx (from rev 116, trunk/packages/seaview/branches/upstream/current/pdf.cxx)
===================================================================
--- trunk/packages/seaview/trunk/pdf.cxx	                        (rev 0)
+++ trunk/packages/seaview/trunk/pdf.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -0,0 +1,317 @@
+#include "pdflib.h"
+#include "seaview.h"
+#include <time.h>
+#include <ctype.h>
+#include <FL/Fl_Round_Button.H>
+#include <FL/Fl_Check_Button.H>
+
+extern int printout_block, printout_fontsize, printout_black, printout_vary;
+extern paperformat printout_pageformat;
+
+
+int pdf_printout(SEA_VIEW *view, const char *filename, 
+	int fontsize, int block_size, paperformat pageformat, int vary_only, int ref0, int blackonly);
+static void color_pdf_display(PDF *pdf, SEA_VIEW *view, int (*calc_color_function)( int ), char *oneline, 
+	int widnames, double x, double y, int fontsize, double char_width, double descender);
+static int calc_vary_lines(int *vary_pos, int widpos);
+static void out_vary_pos(int *vary_pos, int widnames, int widpos, int nl, PDF *pdf);
+
+
+int pdf_printout(SEA_VIEW *view, const char *filename, 
+	int fontsize, int block_size, paperformat pageformat, int vary_only, int ref0, int blackonly)
+{
+int num, i, j, k, current, max_seq_length, fin, curr_lines, widnames, 
+	res_per_line, nl, firstpage, lines_per_page;
+time_t heure;
+static char unnamed[] = "<unnamed>";
+static char num_line[200];
+int lettre, char_per_line;
+short *vary_need = NULL;
+int *vary_pos; /* rang ds alignement de la colonne imprimée */
+char oneline[500];
+int (*calc_color_function)(int);
+PDF *pdf;
+double	char_width, width, height, descender, margin = 25;
+char	*fontname, *encoding;
+int		font;
+
+    fontname	= "Courier";
+#ifdef __APPLE__
+    encoding	= "macroman";
+#else
+    encoding	= "iso8859-1";
+#endif
+if(view->tot_seqs == 0) return 0;
+if(view->protein) calc_color_function = get_color_for_aa;
+else  calc_color_function = get_color_for_base;
+if(pageformat == A4) { width = a4_width; height = a4_height; }
+else /* LETTER */ { width = letter_width; height = letter_height; }
+lines_per_page = (int)((height - 2*margin) / fontsize + 0.5);
+
+pdf = PDF_new();
+if(pdf == NULL) return TRUE;
+
+if( PDF_begin_document(pdf, filename, 0, "compatibility=1.3") == -1) {
+	PDF_delete(pdf);
+	return TRUE;
+	}
+
+PDF_TRY(pdf) {
+
+PDF_set_info(pdf, "Title", PREPARE_LABEL(view->masename) );
+PDF_set_info(pdf, "Creator", "seaview");
+font = PDF_load_font(pdf, fontname, 0, encoding, "");
+char_width = PDF_stringwidth(pdf, "X", font, (double)fontsize);
+char_per_line = (int)((width - 2*margin) / char_width + 0.5);
+descender = PDF_get_value(pdf, "descender", font) * fontsize;
+
+PDF_begin_page_ext(pdf, width, height, "");
+PDF_setfont(pdf, font, (double)fontsize);
+PDF_set_text_pos(pdf, margin, height - margin);
+firstpage = TRUE;
+
+if(ref0 < 0) vary_only = FALSE;
+time(&heure);
+sprintf(oneline,"Alignment: %s", view->masename == NULL ? unnamed : PREPARE_LABEL(view->masename) );
+PDF_continue_text(pdf, oneline);
+curr_lines = 1;
+if(vary_only) {
+	PDF_continue_text(pdf, "Displaying variable sites only.");
+	++curr_lines;
+	}
+sprintf(oneline,"Seaview [blocks=%d fontsize=%d %s] on %s",
+		block_size, fontsize, pageformat == A4 ? "A4" : "LETTER", ctime(&heure));
+PDF_continue_text(pdf, oneline);
+PDF_continue_text(pdf, "");
+curr_lines += 2;
+max_seq_length = 0; widnames = 0;
+for(i=0; i < view->tot_seqs; i++) {
+	if(view->each_length[i] > max_seq_length) max_seq_length = view->each_length[i];
+	if( ( fin=strlen(view->seqname[i]) ) > widnames) widnames = fin;
+	}
+widnames += 2;
+if(vary_only) {
+	vary_need = (short *)calloc(max_seq_length, sizeof(short));
+	if(vary_need == NULL) return TRUE;
+	vary_pos = (int *)calloc(char_per_line, sizeof(int));
+	if(vary_pos == NULL) return TRUE;
+	for(i = 0; i < max_seq_length; i++) {
+		for(num = 0; num < view->tot_seqs; num++) {
+			if( toupper(view->sequence[num][i]) != toupper(view->sequence[ref0][i]) ) { 
+				vary_need[i] = TRUE;
+				break;
+				}
+			}
+		}
+	}
+/* nombre max de blocks qui tiennent sur une ligne de cpl chars */
+fin = (char_per_line - widnames + 1) / (block_size + 1);
+if(fin < 1) { /* garde fou */
+	fin = 1; block_size = char_per_line - widnames;
+	}
+res_per_line = fin * block_size;
+current = 0; 
+while( current < max_seq_length ) {
+	nl = 1;
+	if(vary_only) { 
+		memset(vary_pos, 0, res_per_line * sizeof(int) );
+		i = -1; j = 0; k = 0;
+		while( j < res_per_line) {
+			if(current + i >= max_seq_length) break;
+			if( !vary_need[current + ++i] ) continue;
+			j++;
+			vary_pos[k++] = current + i + 1;
+			if( j % block_size == 0) k++;
+			}
+		nl = calc_vary_lines(vary_pos,  k);
+		}
+	if( (!firstpage) && curr_lines + view->tot_seqs + nl > lines_per_page) {
+		PDF_end_page_ext(pdf, "");
+		PDF_begin_page_ext(pdf, width, height, "");
+		PDF_setfont(pdf, font, (double)fontsize);
+		PDF_set_text_pos(pdf, margin, height - margin);
+		curr_lines = 0;
+		}
+	if(vary_only) {
+		out_vary_pos(vary_pos, widnames, k, nl, pdf);
+		curr_lines += nl;
+		}
+	else	{
+		sprintf(num_line, "%d", current + 1);
+		fin = strlen(num_line);
+		memmove(num_line + widnames - fin + 1, num_line, fin+1);
+		if(fin <= widnames) memset(num_line, ' ', widnames - fin + 1);
+		PDF_continue_text(pdf, num_line);
+		++curr_lines;
+		}
+	for(num=0; num < view->tot_seqs; num++) {
+		k = 0;
+		for(j = 0; j < widnames; j++) {
+			if(view->seqname[num][j] == 0) break;
+			oneline[k++] = view->seqname[num][j];
+			}
+		while( j < widnames) {
+			j++;
+			oneline[k++] = ' ';
+			}
+		if(vary_only) {
+			i = -1; j = 0;
+			while( j < res_per_line) {
+				if(current + i >= max_seq_length) break;
+				if( !vary_need[current + ++i] ) continue;
+				j++;
+				if(current + i < view->each_length[num]) {
+					if(num != ref0) lettre = ( toupper(view->sequence[num][current+i]) == 
+						toupper(view->sequence[ref0][current+i]) ? '.' : view->sequence[num][current+i] );
+					else lettre = view->sequence[ref0][current+i];
+					oneline[k++] = lettre;
+					}
+				if( j % block_size == 0) oneline[k++] = ' ';
+				}
+			if(num == view->tot_seqs - 1) current = current + i + 1;
+			}
+
+		else	{
+			fin = res_per_line;
+			if(current+fin > view->each_length[num]) 
+				fin = view->each_length[num] - current;
+			if(ref0 != -1 && num != ref0) {
+				/* ecriture par reference a seq ref0 */
+				for(i=0; i<fin; i++) {
+					lettre = ( toupper(view->sequence[num][current+i]) == 
+						toupper(view->sequence[ref0][current+i]) ? '.' : view->sequence[num][current+i] );
+					oneline[k++] = lettre;
+					if( i < fin-1 && (i+1)%block_size == 0) 
+						oneline[k++] = ' ';
+					}
+				}
+			else	{ /* ecriture normale de seq */
+				for(i=0; i<fin; i++) {
+					oneline[k++] = view->sequence[num][current+i];
+					if( i < fin-1 && (i+1)%block_size == 0) 
+						oneline[k++] = ' ';
+					}
+				}
+			}
+		oneline[k] = 0;
+		if(curr_lines >= lines_per_page) {
+			PDF_end_page_ext(pdf, "");
+			PDF_begin_page_ext(pdf, width, height, "");
+			PDF_setfont(pdf, font, (double)fontsize);
+			PDF_set_text_pos(pdf, margin, height - margin);
+			curr_lines = 0;
+			}
+		if(blackonly) {
+			PDF_show_xy(pdf, oneline, margin, height - margin - (curr_lines+1) * fontsize);
+			}
+		else 
+			color_pdf_display(pdf, view, calc_color_function, oneline, widnames, margin, 
+				height - margin - (curr_lines+1) * fontsize, fontsize, char_width, descender);
+		++curr_lines;
+		firstpage = FALSE;
+		}
+	if(curr_lines + 1 <= lines_per_page) {
+		PDF_continue_text(pdf, "");
+		++curr_lines;
+		}
+	if( ! vary_only ) current += res_per_line;
+	}
+PDF_end_page_ext(pdf, "");
+PDF_end_document(pdf, "");
+PDF_delete(pdf);
+} /* end of PDF_TRY */
+PDF_CATCH(pdf) {
+        fl_alert("Error while writing pdf file:\n"
+       	 "[%d] %s: %s\n",
+	  	  PDF_get_errnum(pdf), PDF_get_apiname(pdf), PDF_get_errmsg(pdf) );
+        PDF_delete(pdf);
+        return TRUE; 
+}
+return FALSE;
+}
+
+
+static void color_pdf_display(PDF *pdf, SEA_VIEW *view, int (*calc_color_function)( int ), char *oneline, 
+	int widnames, double x, double y, int fontsize, double char_width, double descender)
+{
+uchar red, green, blue;
+double r, g, b, xx;
+int c, l;
+char *p, **clines;
+
+clines = (char **)malloc(sizeof(char *) * view->numb_gc); if(clines==NULL) return;
+l = strlen(oneline);
+for(c = 1; c < view->numb_gc; c++) {
+	clines[c] = (char *)malloc(l + 1); if(clines[c] == NULL) return;
+	memset(clines[c], ' ', l); clines[c][l] = 0;
+	}
+for(p = oneline + widnames; *p != 0; p++) {
+	c = calc_color_function(*p);
+	if(c > 0) clines[c][p - oneline] = 'X';
+	}
+for(c = 1; c < view->numb_gc; c++) {
+	if(strchr(clines[c], 'X') == NULL) continue;
+	Fl::get_color((Fl_Color)view->curr_colors[c], red, green, blue);
+	r = red/255.; g = green/255.; b = blue/255.;
+	PDF_setcolor(pdf, "fillstroke", "rgb", r, g, b, 0);
+	for(xx = x + widnames*char_width, p = clines[c] + widnames; *p != 0; p++, xx += char_width) {
+		if(*p == ' ') continue;
+		PDF_rect(pdf, xx, y + descender, char_width, (double)fontsize);
+		}
+	PDF_fill_stroke(pdf);
+	}
+PDF_setcolor(pdf, "fillstroke", "rgb", 0, 0, 0, 0);
+PDF_show_xy(pdf, oneline, x, y);
+for(c = 1; c < view->numb_gc; c++) free(clines[c]);
+free(clines);
+}
+
+
+static int calc_vary_lines(int *vary_pos, int widpos)
+{
+int maxi = 0, num, nl;
+
+for(num = 0; num < widpos; num++) 
+	if(vary_pos[num] > maxi) maxi = vary_pos[num];
+if(maxi >= 100000)
+	 nl = 6;
+else if(maxi >= 10000)
+	 nl = 5;
+else if(maxi >= 1000)
+	 nl = 4;
+else if(maxi >= 100)
+	 nl = 3;
+else if(maxi >= 10)
+	 nl = 2;
+else 	
+	 nl = 1;
+return nl;
+}
+
+
+static void out_vary_pos(int *vary_pos, int widnames, int widpos, int nl, PDF *pdf)
+{
+int num, l, k, echelle, digit, val;
+static char chiffre[] = "0123456789";
+char oneline[300];
+
+echelle = 1; k = 0;
+for(l = 2; l <= nl; l++) echelle *= 10;
+for(l = nl; l > 0; l--) {
+	for(num = 0; num < widnames; num++) oneline[k++] = ' ';
+	for(num = 0; num < widpos; num++) {
+		val = vary_pos[num];
+		if(val < echelle)
+			oneline[k++] = ' ';
+		else	{
+			digit = (val / echelle) % 10 ;
+			oneline[k++] = *(chiffre + digit);
+			}
+		}
+	oneline[k] = 0;
+	PDF_continue_text(pdf, oneline);
+	k = 0;
+	echelle /= 10;
+	}
+}
+

Copied: trunk/packages/seaview/trunk/postscript.cxx (from rev 116, trunk/packages/seaview/branches/upstream/current/postscript.cxx)
===================================================================
--- trunk/packages/seaview/trunk/postscript.cxx	                        (rev 0)
+++ trunk/packages/seaview/trunk/postscript.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -0,0 +1,321 @@
+#include "seaview.h"
+#include <time.h>
+#include <ctype.h>
+
+extern int printout_block, printout_fontsize, printout_black, printout_vary;
+extern paperformat printout_pageformat;
+
+
+int pdf_printout(SEA_VIEW *view, const char *filename, 
+	int fontsize, int block_size, paperformat pageformat, int vary_only, int ref0, int blackonly);
+static void color_ps_display(FILE *psout, SEA_VIEW *view, int (*calc_color_function)( int ), char *oneline, 
+	int widnames, int x, int y, int fontsize, int char_width, int descender);
+static int calc_vary_lines(int *vary_pos, int widpos);
+static void out_vary_pos(int *vary_pos, int widnames, int widpos, int nl, FILE *psout, 
+	int x, int y, int yoffset);
+
+
+int pdf_printout(SEA_VIEW *view, const char *filename, 
+	int fontsize, int block_size, paperformat pageformat, int vary_only, int ref0, int blackonly)
+{
+int num, i, j, k, current, max_seq_length, fin, curr_lines, widnames, 
+	res_per_line, nl, firstpage, lines_per_page;
+time_t heure;
+static char unnamed[] = "<unnamed>";
+static char num_line[200];
+int lettre, char_per_line;
+short *vary_need = NULL;
+int *vary_pos; /* rang ds alignement de la colonne imprimée */
+char oneline[500];
+int (*calc_color_function)(int);
+FILE *psout;
+int	char_width, width, height, descender, margin = 25;
+float postscript_ratio;
+char	*fontname;
+int		font, curpage, erreur = FALSE;
+const int a4_width = 595;
+const int a4_height = 842;
+const int letter_width = 612;
+const int letter_height = 792;
+
+    fontname	= "Courier-Bold";
+if(view->tot_seqs == 0) return 0;
+if(view->protein) calc_color_function = get_color_for_aa;
+else  calc_color_function = get_color_for_base;
+if(pageformat == A4) { width = a4_width; height = a4_height; }
+else /* LETTER */ { width = letter_width; height = letter_height; }
+lines_per_page = (height - 2*margin) / fontsize ;
+
+psout = fopen(filename, "w");
+if(psout == NULL) return TRUE;
+
+fprintf(psout,"%%!PS-Adobe-3.0\n"
+	"%%%%DocumentFonts: %s \n"
+	"%%%%Creator: seaview\n"
+	"%%%%Pages: (atend)\n"
+	"%%%%Title: %s\n"
+	"%%%%BeginFeature: *PageSize \n"
+ 	"%s\n"
+	"%%%%EndFeature\n"
+	"%%%%EndComments\n", fontname,
+	 PREPARE_LABEL(view->masename), pageformat == A4 ? "a4" : "letter" );
+
+
+postscript_ratio = 0.60;
+char_width = (int)(fontsize * postscript_ratio + 0.5);
+char_per_line = (width - 2*margin) / char_width ;
+descender = - (int)(fontsize * 0.20 + 0.5); 
+
+fprintf(psout,"%%%%BeginProlog\n/uniqfont /%s findfont %d scalefont def\n%%%%EndProlog\n", 
+	fontname, fontsize);
+
+curpage = 1;
+fprintf(psout,"%%%%Page: ? 1\n");
+
+fprintf(psout,"uniqfont setfont\n");
+fprintf(psout,"%d %d moveto\n", margin, height - margin - fontsize);
+firstpage = TRUE;
+
+if(ref0 < 0) vary_only = FALSE;
+time(&heure);
+sprintf(oneline,"Alignment: %s", view->masename == NULL ? unnamed : PREPARE_LABEL(view->masename) );
+fprintf(psout,"(%s) show\n", oneline);
+curr_lines = 1;
+if(vary_only) {
+	fprintf(psout,"%d %d moveto\n", margin, height - margin - (++curr_lines) * fontsize);
+	fprintf(psout,"(Displaying variable sites only.) show\n");
+	}
+sprintf(oneline,"Seaview [blocks=%d fontsize=%d %s] on %s",
+		block_size, fontsize, pageformat == A4 ? "A4" : "LETTER", ctime(&heure));
+fprintf(psout,"%d %d moveto\n", margin, height - margin - (++curr_lines) * fontsize);
+fprintf(psout,"(%s) show\n", oneline);
+++curr_lines;
+max_seq_length = 0; widnames = 0;
+for(i=0; i < view->tot_seqs; i++) {
+	if(view->each_length[i] > max_seq_length) max_seq_length = view->each_length[i];
+	if( ( fin=strlen(view->seqname[i]) ) > widnames) widnames = fin;
+	}
+widnames += 2;
+if(vary_only) {
+	vary_need = (short *)calloc(max_seq_length, sizeof(short));
+	if(vary_need == NULL) return TRUE;
+	vary_pos = (int *)calloc(char_per_line, sizeof(int));
+	if(vary_pos == NULL) return TRUE;
+	for(i = 0; i < max_seq_length; i++) {
+		for(num = 0; num < view->tot_seqs; num++) {
+			if( toupper(view->sequence[num][i]) != toupper(view->sequence[ref0][i]) ) { 
+				vary_need[i] = TRUE;
+				break;
+				}
+			}
+		}
+	}
+/* nombre max de blocks qui tiennent sur une ligne de cpl chars */
+fin = (char_per_line - widnames + 1) / (block_size + 1);
+if(fin < 1) { /* garde fou */
+	fin = 1; block_size = char_per_line - widnames;
+	}
+res_per_line = fin * block_size;
+current = 0; 
+while( current < max_seq_length ) {
+	nl = 1;
+	if(vary_only) { 
+		memset(vary_pos, 0, res_per_line * sizeof(int) );
+		i = -1; j = 0; k = 0;
+		while( j < res_per_line) {
+			if(current + i >= max_seq_length) break;
+			if( !vary_need[current + ++i] ) continue;
+			j++;
+			vary_pos[k++] = current + i + 1;
+			if( j % block_size == 0) k++;
+			}
+		nl = calc_vary_lines(vary_pos,  k);
+		}
+	if( (!firstpage) && curr_lines + view->tot_seqs + nl > lines_per_page) {
+		fprintf(psout,"showpage\n");
+		fprintf(psout,"%%%%Page: ? %d\n", ++curpage);
+		fprintf(psout,"uniqfont setfont\n");
+		curr_lines = 0;
+		}
+	if(vary_only) {
+		out_vary_pos(vary_pos, widnames, k, nl, psout, margin, height - margin - (curr_lines+1) * fontsize, fontsize);
+		curr_lines += nl;
+		}
+	else	{
+		sprintf(num_line, "%d", current + 1);
+		fin = strlen(num_line);
+		memmove(num_line + widnames - fin + 1, num_line, fin+1);
+		if(fin <= widnames) memset(num_line, ' ', widnames - fin + 1);
+		fprintf(psout,"%d %d moveto\n", margin, height - margin - (curr_lines+1) * fontsize);
+		fprintf(psout,"(%s) show\n", num_line);
+		++curr_lines;
+		}
+	for(num=0; num < view->tot_seqs; num++) {
+		k = 0;
+		for(j = 0; j < widnames; j++) {
+			if(view->seqname[num][j] == 0) break;
+			oneline[k++] = view->seqname[num][j];
+			}
+		while( j < widnames) {
+			j++;
+			oneline[k++] = ' ';
+			}
+		if(vary_only) {
+			i = -1; j = 0;
+			while( j < res_per_line) {
+				if(current + i >= max_seq_length) break;
+				if( !vary_need[current + ++i] ) continue;
+				j++;
+				if(current + i < view->each_length[num]) {
+					if(num != ref0) lettre = ( toupper(view->sequence[num][current+i]) == 
+						toupper(view->sequence[ref0][current+i]) ? '.' : view->sequence[num][current+i] );
+					else lettre = view->sequence[ref0][current+i];
+					oneline[k++] = lettre;
+					}
+				if( j % block_size == 0) oneline[k++] = ' ';
+				}
+			if(num == view->tot_seqs - 1) current = current + i + 1;
+			}
+
+		else	{
+			fin = res_per_line;
+			if(current+fin > view->each_length[num]) 
+				fin = view->each_length[num] - current;
+			if(ref0 != -1 && num != ref0) {
+				/* ecriture par reference a seq ref0 */
+				for(i=0; i<fin; i++) {
+					lettre = ( toupper(view->sequence[num][current+i]) == 
+						toupper(view->sequence[ref0][current+i]) ? '.' : view->sequence[num][current+i] );
+					oneline[k++] = lettre;
+					if( i < fin-1 && (i+1)%block_size == 0) 
+						oneline[k++] = ' ';
+					}
+				}
+			else	{ /* ecriture normale de seq */
+				for(i=0; i<fin; i++) {
+					oneline[k++] = view->sequence[num][current+i];
+					if( i < fin-1 && (i+1)%block_size == 0) 
+						oneline[k++] = ' ';
+					}
+				}
+			}
+		oneline[k] = 0;
+		if(curr_lines >= lines_per_page) {
+			fprintf(psout,"showpage\n");
+			fprintf(psout,"%%%%Page: ? %d\n", ++curpage);
+			fprintf(psout,"uniqfont setfont\n");
+			curr_lines = 0;
+			}
+		if(blackonly) {
+			fprintf(psout,"%d %d moveto\n", margin, height - margin - (curr_lines+1) * fontsize);
+			fprintf(psout,"(%s) show\n", oneline);
+			}
+		else 
+			color_ps_display(psout, view, calc_color_function, oneline, widnames, margin, 
+				height - margin - (curr_lines+1) * fontsize, fontsize, char_width, descender);
+		++curr_lines;
+		firstpage = FALSE;
+		}
+	if(curr_lines + 1 <= lines_per_page) {
+		++curr_lines;
+		}
+	if( ! vary_only ) current += res_per_line;
+	}
+fprintf(psout,"showpage\n");
+fprintf(psout, "%%%%Trailer\n%%%%Pages: %d\n%%%%EOF\n", curpage);
+if(ferror(psout)) erreur = TRUE;
+if(fclose(psout) != 0) erreur = TRUE;
+return erreur;
+}
+
+
+static void color_ps_display(FILE *psout, SEA_VIEW *view, int (*calc_color_function)( int ), char *oneline, 
+	int widnames, int x, int y, int fontsize, int char_width, int descender)
+{
+uchar red, green, blue;
+double r, g, b;
+int xx;
+int c, l;
+char *p, **clines;
+
+clines = (char **)malloc(sizeof(char *) * view->numb_gc); if(clines==NULL) return;
+l = strlen(oneline);
+for(c = 1; c < view->numb_gc; c++) {
+	clines[c] = (char *)malloc(l + 1); if(clines[c] == NULL) return;
+	memset(clines[c], ' ', l); clines[c][l] = 0;
+	}
+for(p = oneline + widnames; *p != 0; p++) {
+	c = calc_color_function(*p);
+	if(c > 0) clines[c][p - oneline] = 'X';
+	}
+for(c = 1; c < view->numb_gc; c++) {
+	if(strchr(clines[c], 'X') == NULL) continue;
+	Fl::get_color((Fl_Color)view->curr_colors[c], red, green, blue);
+	r = red/255.; g = green/255.; b = blue/255.;
+	fprintf(psout,"%f %f %f setrgbcolor\n", r, g, b);
+	for(xx = x + widnames*char_width, p = clines[c] + widnames; *p != 0; p++, xx += char_width) {
+		if(*p == ' ') continue;
+		fprintf(psout, "%d %d %d %d rectfill\n", 
+			xx, y+descender, char_width, fontsize);	
+		}
+	}
+fprintf(psout,"0 setgray\n");
+fprintf(psout,"%d %d moveto\n", x, y);
+fprintf(psout,"(%s) show\n", oneline);
+for(c = 1; c < view->numb_gc; c++) free(clines[c]);
+free(clines);
+}
+
+
+static int calc_vary_lines(int *vary_pos, int widpos)
+{
+int maxi = 0, num, nl;
+
+for(num = 0; num < widpos; num++) 
+	if(vary_pos[num] > maxi) maxi = vary_pos[num];
+if(maxi >= 100000)
+	 nl = 6;
+else if(maxi >= 10000)
+	 nl = 5;
+else if(maxi >= 1000)
+	 nl = 4;
+else if(maxi >= 100)
+	 nl = 3;
+else if(maxi >= 10)
+	 nl = 2;
+else 	
+	 nl = 1;
+return nl;
+}
+
+
+static void out_vary_pos(int *vary_pos, int widnames, int widpos, int nl, FILE *psout, 
+	int x, int y, int yoffset)
+{
+int num, l, k, echelle, digit, val;
+static char chiffre[] = "0123456789";
+char oneline[300];
+
+echelle = 1; k = 0;
+for(l = 2; l <= nl; l++) echelle *= 10;
+for(l = nl; l > 0; l--) {
+	for(num = 0; num < widnames; num++) oneline[k++] = ' ';
+	for(num = 0; num < widpos; num++) {
+		val = vary_pos[num];
+		if(val < echelle)
+			oneline[k++] = ' ';
+		else	{
+			digit = (val / echelle) % 10 ;
+			oneline[k++] = *(chiffre + digit);
+			}
+		}
+	oneline[k] = 0;
+	fprintf(psout,"%d %d moveto\n", x, y); y -= yoffset;
+	fprintf(psout,"(%s) show\n", oneline);
+	k = 0;
+	echelle /= 10;
+	}
+}
+
+
+

Modified: trunk/packages/seaview/trunk/resource.cxx
===================================================================
--- trunk/packages/seaview/trunk/resource.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/resource.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -1,24 +1,30 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <ctype.h>
 
 // included functions
-void decodecolorname(char *colname, int *r, int *g, int *b);
 void *load_resources(char *progname);
 char *get_res_value(char *name, char *def_value, void *v_db);
 int int_res_value(char *name, int def_value, void *v_db);
 int bool_res_value(char *name, int def_value, void *v_db);
+int set_res_value(const char *name, const char *value);
+int save_resources(void);
 
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) && ! TARGET_RT_MAC_MACHO
 
+extern "C" {
+extern void PtoC(const void *in, void *out);
+extern void CtoP(const void *in, void *out);
+}
+
 char *load1res(char *resname)
 {
 	char **h, *p, pname[256]; 
 	int l;
 
-	strcpy(pname + 1, resname);
-	pname[0] = strlen(resname);
+	CtoP(resname, pname);
 	h = GetNamedResource('TEXT', (ConstStr255Param)pname );
 	if(h == NULL) return NULL;
 	else	{
@@ -51,125 +57,187 @@
 else return def_value;
 }
 
-void decodecolorname(char *colname, int *r, int *g, int *b)
+
+int set_res_value(const char *name, const char *value)
+/* returns 0 iff no error */
 {
-;
+Str255 pname;
+Handle h;
+short id;
+OSErr err;
+int l;
+
+CtoP(name, pname);
+l = strlen(value);
+h = GetNamedResource('TEXT', pname);
+if(h == NULL) { // resource not yet exists
+	if(ResError() != resNotFound) return 1;
+	id = Unique1ID('TEXT');
+	h = NewHandle(l);
+	if(h == NULL) return 1;
+	HLock(h);
+	memcpy(*h, value, l);
+	HUnlock(h);
+	AddResource(h, 'TEXT', id, pname);
+	if( ResError() != noErr) return 1;
+	}
+else {// resource already exists
+	if(l == GetHandleSize(h)) {
+		HLock(h);
+		err = memcmp(*h, value, l);
+		HUnlock(h);
+		if(err == 0) return 0; // same value already, stop here
+		}
+	SetHandleSize(h, l);
+	if( MemError() != noErr) return 1;
+	HLock(h);
+	memcpy(*h, value, l);
+	HUnlock(h);
+	ChangedResource(h);
+	if( ResError() != noErr) return 1;
+	}
+ReleaseResource(h);
+err = ResError();
+return err != noErr ;
 }
 
 
-#elif defined(WIN32) 
+int save_resources(void)
+{ // nothing to do, taken care of by the system
+}
 
-#include <fcntl.h>
 
-void decodecolorname(char *colname, int *r, int *g, int *b)
+#else /* for X11 and win32 and MacOS-machO */
+
+typedef struct _item {
+	struct _item *before;
+	char *name;
+	char *value;
+	struct _item *next;
+	} item;
+
+static item *firstitem = NULL;
+
+extern "C" { 
+	char *get_prog_dir(void); 
+#if defined(__APPLE__) && TARGET_RT_MAC_MACHO
+	char *MG_GetBundleResourcesDir(void);
+#endif
+	}
+
+char *res_filename(void)
 {
-;
-}
+static char fname[FILENAME_MAX];
+char *p;
 
-extern "C" {
-char *get_prog_dir(void);
+#ifdef WIN32
+p = get_prog_dir();
+if(p == NULL) return NULL;
+strcpy(fname, p);
+strcat(fname, "\\seaview.ini");
+#elif defined(__APPLE__) && TARGET_RT_MAC_MACHO
+p = MG_GetBundleResourcesDir();
+strcpy(fname, p);
+strcat(fname, "/seaview.ini");
+#else
+p = getenv("HOME");
+if(p == NULL) return NULL;
+strcpy(fname, p);
+strcat(fname, "/.seaviewrc");
+#endif
+return fname;
 }
 
-/* !!! en debut de programme, l'utilisation de stdio fait planter le progr !!! */
+
 void *load_resources(char *progname)
 {
-char fname[200];
-char *buf;
-int in, total;
-strcpy(fname, get_prog_dir());
-strcat(fname, "seaview.ini");
-in = open(fname, O_RDONLY);
-if(in == -1) return NULL;
-total = lseek(in, 0, SEEK_END);
-buf = (char *)malloc(total + 1);
-if(buf != NULL) {
-	lseek(in, 0, SEEK_SET);
-	read(in, buf, total);
-	buf[total] = 0;
+FILE *in;
+char *fname, *p, line[500];
+item *elt, *last = NULL;
+
+fname = res_filename();
+if(fname == NULL) return NULL;
+in = fopen(fname, "r");
+if(in == NULL) return NULL;
+while((p = fgets(line, sizeof(line), in)) != NULL) {
+	p = strchr(line, '\n'); if(p != NULL) *p = 0;
+	p = strchr(line, '=');
+	if(p == NULL) continue;
+	*(p++) = 0; while(isspace(*p))  p++;
+	if(*p == 0) continue;
+	elt = (item *)malloc(sizeof(item));
+	if(elt == NULL) break;
+	elt->name = strdup(line);
+	elt->value = strdup(p);
+	if(elt->name == NULL || elt->value == NULL) break;
+	if(last != NULL) last->next = elt;
+	else firstitem = elt;
+	elt->before = last;
+	last = elt;
+	elt->next = NULL;
 	}
-close(in);
-return (void *)buf;
+fclose(in);
+return firstitem;
 }
 
+
 char *get_res_value(char *name, char *def_value, void *v_db)
 {
-char *p, *q, *db = (char *)v_db;
-static char value[200];
-int l;
-if(db == NULL) return def_value;
-p = db; l = strlen(name);
-while(strncmp(p, name, l) != 0 || (*(p + l) != '=' && *(p + l) != ' ') ) {
-	p = strchr(p, '\n');
-	if(p == NULL) return def_value;
-	p++;
+if(v_db == NULL) return def_value;
+item *elt = (item *)v_db;
+
+while(elt != NULL) {
+	if(strcmp(name, elt->name) == 0) return elt->value;
+	elt = elt->next;
 	}
-p += l;
-while( *p == ' ' || *p == '=' ) p++;
-q = strchr(p, '\n');
-if(q == NULL) q = p + strlen(p);
-memcpy(value, p, q - p); value[q - p] = 0; if(value[q - p - 1] == '\r') value[q - p - 1] = 0;
-return value;
+return def_value;
 }
 
-#else
 
-#include <X11/Xlib.h>
-#include <X11/Xresource.h>
-#include <FL/x.H>
-#include <ctype.h>
-
-void decodecolorname(char *colname, int *r, int *g, int *b)
-/* decodes color name and returns rgb in [0,255] */
+int set_res_value(const char *name, const char *value)
 {
-int status;
-XColor exact, couleur;
-status = XLookupColor(fl_display, fl_colormap, colname, &exact, &couleur);
-if(status == 0) return;
-*r = couleur.red >> 8;
-*g = couleur.green >> 8;
-*b = couleur.blue >> 8;
-}
+item *elt, *last = NULL;
 
-
-void *load_resources(char *progname)
-{
-XrmDatabase db = NULL;
-char *rm, fname[100], Pname[50];
-strcpy(Pname, progname); Pname[0] = toupper(Pname[0]);
-fl_open_display();
-XrmInitialize();
-strcpy(fname, "/usr/lib/X11/app-defaults/");
-strcat(fname, Pname);
-XrmCombineFileDatabase(fname, &db, 1);
-rm = getenv("XAPPLRESDIR");
-if(rm != NULL) {
-	strcpy(fname, rm);
-	strcat(fname, "/");
-	strcat(fname, Pname);
-	XrmCombineFileDatabase(fname, &db, 1);
+elt = firstitem;
+while(elt != NULL) {
+	if(strcmp(elt->name, name) == 0) {
+		free(elt->value);
+		elt->value = strdup(value);
+		return 0;
+		}
+	last = elt;
+	elt = elt->next;
 	}
-// ajouter resources de xrdb
-rm = XResourceManagerString(fl_display);
-if(rm != NULL) XrmMergeDatabases(XrmGetStringDatabase(rm), &db);
-rm = XScreenResourceString(ScreenOfDisplay(fl_display, fl_screen));
-if(rm != NULL) {
-	XrmMergeDatabases(XrmGetStringDatabase(rm), &db);
-	XFree(rm);
-	}
-return (void *)db;
+elt = (item *)malloc(sizeof(item));
+if(elt == NULL) return 1;
+elt->name = strdup(name);
+elt->value = strdup(value);
+if(elt->name == NULL || elt->value == NULL) return 1;
+if(last != NULL) last->next = elt;
+else firstitem = elt;
+elt->before = last;
+elt->next = NULL;
+return 0;
 }
 
 
-char *get_res_value(char *name, char *def_value, void *v_db)
-{
-static char full_name[100] = "Seaview.";
-static const int pre_len = (int)strlen(full_name);
-XrmDatabase db = (XrmDatabase)v_db;
-char *res_type;
-XrmValue valeur;
-strcpy(full_name + pre_len, name);
-int status = XrmGetResource(db, full_name, NULL, &res_type, &valeur);
-return (status ? valeur.addr : def_value);
+int save_resources(void)
+{ 
+char *fname;
+item *elt;
+FILE *out;
+
+fname = res_filename();
+if(fname == NULL) return 1;
+out = fopen(fname, "w");
+if(out == NULL) return 1;
+elt = firstitem;
+while(elt != NULL) {
+	fprintf(out, "%s=%s\n", elt->name, elt->value);
+	elt = elt->next;
+	}
+fclose(out);
+return 0;
 }
 
 #endif

Modified: trunk/packages/seaview/trunk/seaview.cxx
===================================================================
--- trunk/packages/seaview/trunk/seaview.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/seaview.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -1,3 +1,25 @@
+//
+// Copyright 1996-2005 by Manolo Gouy.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// A copy of the GNU General Public License is available
+// from http://www.gnu.org/licenses/gpl.txt or by mail from the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to "mgouy at biomserv.univ-lyon1.fr".
+//
+
+
 #include "seaview.h"
 #include <string.h>
 #include <stdio.h>
@@ -5,8 +27,26 @@
 #include <ctype.h>
 #include "FL/Fl_Double_Window.H"
 #include "FL/Fl_Pack.H"
+#include "FL/Fl_Hold_Browser.H"
+#include <FL/Fl_Round_Button.H>
+#include <FL/Fl_Check_Button.H>
 
 
+// myFL_CTRL is the modifier for menu shortcuts (Meta on Apple and Ctrl otherwise)
+#if defined(__APPLE__) 
+#if	(FL_MAJOR_VERSION*10000 + FL_MINOR_VERSION*100 + FL_PATCH_VERSION) >= 10106
+#define myFL_CTRL FL_META
+#else //on old fltk versions, Ctrl and Meta keyw are exchanged
+#undef FL_CTRL
+#define FL_CTRL 0x00400000
+#define myFL_CTRL 0x00040000
+#endif
+#else
+#define myFL_CTRL FL_CTRL
+#endif
+
+
+
 /* allongement maximal prevu pour les seqs suite a edition */
 #define MAX_SEQ_ALLONG 5000
 #define MINI_MAX_LENGTH  10000 /* pour depart avec fichier vide */
@@ -52,7 +92,9 @@
 		int numb_stdprotcolors, int *stdprotcolors,
 		int numb_altprotcolors, int *altprotcolors,
 		color_choice curr_color_choice, char *progname, char *movekeys,
-		char *win_size, int allow_lower, char *help_file);
+		char *win_size, int allow_lower, char *help_file,
+		int back_color, int region_back_color, int defaultfontsize,
+		int alignment_algo);
 int prep_custom_colors(int *colors, char *customcolors, 
 	int max_colors);
 color_choice prep_aa_color_code(char *list_std, char *list_alt, 
@@ -68,6 +110,8 @@
 int delete_gaps_before(SEA_VIEW *view, int numseq, int numsite, int total);
 void set_save_format(SEA_VIEW *view, int val);
 void use_initial_file(SEA_VIEW *view, char *masename);
+int ask_with_custom_yesno(const char *text, const char *yes, const char *no);
+void pdfps_options_dialog(SEA_VIEW *view);
 
 /* external functions */
 void draw_comment_lines(Fl_Widget *ob, SEA_VIEW *view);
@@ -81,30 +125,62 @@
 char* fl_file_chooser_save_as(const char* message, const char* pat, 
 	const char* fname, void *view);
 void *load_resources(char *progname);
+int save_resources(void);
 char *get_res_value(char *name, char *def_value, void *v_db);
 int int_res_value(char *name, int def_value, void *v_db);
 int bool_res_value(char *name, int def_value, void *v_db);
-void decodecolorname(char *colname, int *r, int *g, int *b);
 void minuscules(char *);
 known_format what_format(const char *filename);
+void custom_callback(Fl_Widget *obj, void *data);
+void adjust_menu_edit_modes(SEA_VIEW *view);
+extern void mainwin_close_callback(Fl_Widget *form, void *data);
 #ifdef __APPLE__
+extern char* MAC_file_chooser(const char* message, const char* pat, const char* fname);
+int set_res_value(const char *name, const char *value);
 extern "C" { 
-	void MGinit_apple_events(SEA_VIEW *view); 
-	void add_apropos(char *progname);
+	void MGinit_apple_events(SEA_VIEW *view);
+	void add_apropos(char *progname, void *data);
+#if !TARGET_RT_MAC_MACHO
+	char *OSXpathtoOS9path(const char *OSXpath);
+#else
+	char *MG_GetBundleResourcesDir(void);
+#endif
+	void MG_apple_inits(void);
 	}
+#elif defined(WIN32)
+extern char *MG_win32_file_chooser(const char* message,
+        const char* pattern,
+        const char* fname,
+        const char* defext,
+        bool save, int *pfilterindex);
 #endif
+extern int pdf_printout(SEA_VIEW *view, const char *filename, 
+	int fontsize, int block_size, paperformat pageformat, int vary_only, int ref0, 
+	int blackonly);
+extern char* fl_file_chooser(const char* message, const char* pat, const char* fname, int);
 
 /* variables globales */
 /* pour controle parametres option printout */
-int printout_block;
-int printout_cpl;
-int printout_lpp;
+paperformat printout_pageformat;
+int printout_block, printout_fontsize, printout_black = FALSE;
 int printout_vary = FALSE;
 char *f_format_names[] = {"Mase", "Phylip", "Clustal", "MSF", "Fasta", "NEXUS"};
+char *f_format_exts[] = {"mase", "phy", "aln", "msf", "fst", "nxs"};
 int nbr_formats = sizeof(f_format_names)/sizeof(char *);
 int emul_3_buttons;
+//char def_stdcolorgroups[] = "EDQNHRKBZ,ILMV,APSGT,FY,WC";
+char def_stdcolorgroups[] = "KR,AFILMVW,NQST,HY,C,DE,P,G";
+//int def_protcolors[] =
+//	{ FL_WHITE, FL_RED, FL_GREEN, FL_YELLOW, FL_BLUE, FL_CYAN,
+//	FL_MAGENTA, 9/*salmon*/, 13/*purple*/, 14/*aquamarine*/, 8/*darkgray*/};
+int *def_protcolors;
+int def_protcolors_rgb[] = 
+	{255,255,255, /* white */
+	230,51,25,   25,128,230,   25,204,25,   25,179,179,   230,128,128,
+	204,77,204,   204,204,0,   230,153,77,
+	128,128,128,    100,100,100 };
+int max_protcolors = sizeof(def_protcolors_rgb) / sizeof(int) / 3;
 
-
 #ifdef WIN32
 #define LINE_HEIGHT_FACTOR  0.85
 #else
@@ -114,29 +190,29 @@
 
 int main(int argc, char *argv[])
 {
-char *masename, *progname;
+char *masename, *progname, *p;
 known_format defaultformat;
+char **possible_formats; 
 static int dnacolors[] =
 	{ FL_WHITE, FL_RED, FL_GREEN, FL_YELLOW, FL_BLUE };
 int numb_dnacolors = sizeof(dnacolors) / sizeof(int);
-static int protcolors[] =
-	{ FL_WHITE, FL_RED, FL_GREEN, FL_YELLOW, FL_BLUE, FL_CYAN,
-	FL_MAGENTA, 9/*salmon*/, 13/*purple*/, 14/*aquamarine*/, 8/*darkgray*/};
-int max_protcolors = sizeof(protcolors) / sizeof(int);
-static char def_stdcolorgroups[] = "EDQNHRKBZ,ILMV,APSGT,FY,WC";
-int numb_stdprotcolors, numb_altprotcolors, i;
+int numb_stdprotcolors, numb_altprotcolors, i, back_color, region_back_color;
 color_choice curr_color_choice;
 
-static int quick_and_dirty, inverted, allow_lower; 
+static int quick_and_dirty, inverted, allow_lower, alignment_algo; 
 static char stdcolorgroups[50], altcolorgroups[50];
 static char customdnacolors[200];
 static char customprotcolors[300];
-char **possible_formats; 
-int def_format = 0;
 static char save_format[10];
 static char movekeys[5], win_size[12];
 static char *help_file;
 void *resources;
+int defaultfontsize = 
+#ifdef WIN32
+			12;
+#else
+			14;
+#endif
 
 progname = (char *)"seaview";
 resources = load_resources(progname);
@@ -150,27 +226,36 @@
 
 /* access to resources */
 quick_and_dirty = bool_res_value("fast", 0, resources);
-inverted = bool_res_value("inverted", 0, resources);
-strcpy(save_format, get_res_value("save", possible_formats[def_format], resources) );
+inverted = bool_res_value("inverted", TRUE, resources);
+strcpy(save_format, get_res_value("save", possible_formats[NEXUS_FORMAT], resources) );
 strcpy(stdcolorgroups, 
 	get_res_value("stdcolorgroups", def_stdcolorgroups, resources) );
 strcpy(altcolorgroups, get_res_value("altcolorgroups", "", resources) );
 printout_block = int_res_value("printoutblock", 10, resources);
-printout_cpl = int_res_value("printoutcpl", 80, resources);
-printout_lpp = int_res_value("printoutlpp", 66, resources);
+printout_fontsize = int_res_value("printoutfontsize", 10, resources);
+if(strcmp( get_res_value("printoutpageformat", "A4", resources) , "A4") == 0)
+	printout_pageformat = A4;
+else printout_pageformat = LETTER;
 allow_lower = bool_res_value("lowercase", 0, resources);
-help_file = get_res_value("helpfile", 
-#ifdef WIN32
-	"seaview.hlp", 
-#elif defined(__APPLE__)
-	NULL,
+alignment_algo = int_res_value("alignment", DEFAULT_ALIGN_ALGO, resources);
+#if defined(__APPLE__)
+MG_apple_inits();
+#if TARGET_RT_MAC_MACHO
+p = MG_GetBundleResourcesDir();
+help_file = (char *)malloc(strlen(p) + 20);
+strcpy(help_file, p );
+strcat(help_file, "/seaview.help");
 #else
-	"/usr/share/seaview/seaview.help", 
+help_file = get_res_value("helpfile", 	NULL, 	resources );
 #endif
-	resources );
+#elif defined(DEFAULT_HELPFILE)   /* to ease FreeBSD port */
+help_file = get_res_value("helpfile", 	DEFAULT_HELPFILE, 	resources );
+#else
+help_file = get_res_value("helpfile", 	"seaview.help", 	resources );
+#endif
 strcpy(customdnacolors, get_res_value("dnacolors", "", resources) );
 strcpy(customprotcolors, get_res_value("protcolors", "", resources) );
-strcpy(movekeys, get_res_value("movekeys", "][><", resources) );
+strcpy(movekeys, get_res_value("movekeys", MOVEKEYS_DEFAULT, resources) );
 strcpy(win_size, get_res_value("window", 
 #if defined(WIN32) || defined(__APPLE__)
 	"700x500", 
@@ -183,14 +268,28 @@
 #else
 	emul_3_buttons = bool_res_value("emulate_3_b", FALSE, resources);
 #endif
+#ifdef WIN32
+back_color = FL_DARK1; region_back_color = 43;
+#else
+back_color = FL_GRAY; region_back_color = FL_DARK2;
+#endif
+back_color = int_res_value("background", back_color, resources);
+region_back_color = int_res_value("sites_background", region_back_color, 
+	resources);
 
 /* process custom color settings */
 prep_custom_colors(dnacolors, customdnacolors, numb_dnacolors);
-max_protcolors = prep_custom_colors(protcolors, customprotcolors, 
+int *protcolors = (int *)malloc(sizeof(def_protcolors_rgb) / 3);
+def_protcolors = (int *)malloc(sizeof(def_protcolors_rgb) / 3);
+for(i=0; i<max_protcolors; i++) def_protcolors[i] = 
+	fl_rgb_color(def_protcolors_rgb[3*i], def_protcolors_rgb[3*i+1], def_protcolors_rgb[3*i+2]);
+
+memcpy(protcolors, def_protcolors, sizeof(def_protcolors_rgb) / 3 );
+int cur_protcolors = prep_custom_colors(protcolors, customprotcolors, 
 	max_protcolors);
 /* process resource-read stdcolorgroups and altcolorgroups */
 curr_color_choice = prep_aa_color_code(stdcolorgroups, altcolorgroups, 
-		max_protcolors, &numb_stdprotcolors, &numb_altprotcolors);
+		cur_protcolors, &numb_stdprotcolors, &numb_altprotcolors);
 
 /* argument processing */
 masename = NULL;
@@ -199,8 +298,12 @@
 	if(argv[i][0] != '-') masename = argv[i];
 	if(strcmp(argv[i], "-fast") == 0) quick_and_dirty = TRUE;
 	if(strcmp(argv[i], "-inverted") == 0) inverted = TRUE;
-	if(strcmp(argv[i], "-save") == 0) 
+	if(strcmp(argv[i], "-save") == 0) {
 		if(++i < argc) strcpy(save_format, argv[i]);
+		}
+	if(strcmp(argv[i], "-fontsize") == 0) {
+		if(++i < argc) sscanf(argv[i], "%d", &defaultfontsize);
+		}
 	i++;
 	}
 for( i=0; i < nbr_formats; i++) 
@@ -216,21 +319,24 @@
 	defaultformat, numb_dnacolors, dnacolors, 
 	numb_stdprotcolors, protcolors,
 	numb_altprotcolors, protcolors, curr_color_choice, 
-	progname, movekeys, win_size, allow_lower, help_file);
+	progname, movekeys, win_size, allow_lower, help_file,
+	back_color, region_back_color, defaultfontsize, alignment_algo);
 #ifdef __APPLE__ 
 MGinit_apple_events(view);
-add_apropos(progname);
+add_apropos(progname, help_file);
 #else
 if(masename != NULL) use_initial_file(view, masename);
 #endif
 view->dnawin->show();
+view->DNA_obj->take_focus();
 fl_reset_cursor(view->dnawin);
-// Fl::run(); ici bug ou focus est perdu des que autre fenetre utilisee
-while( Fl::wait() ) { // reparation du bug
+Fl::run(); 
+/*
+while( Fl::wait() ) { // reparation du bug focus perdu
 	if(Fl::focus() == NULL) {
 		view->DNA_obj->take_focus();
 		}
-	}
+	} */
 return 0;
 }
 
@@ -242,7 +348,7 @@
 defaultformat = what_format(masename);
 if(defaultformat >= 0) {
 		set_save_format(view, defaultformat);
-		load_alignment_file(view, masename, NULL, NULL, defaultformat);
+		load_alignment_file(view, masename, NULL, defaultformat);
 		}
 else
 		fl_alert("File %s\nis not of a format readable by seaview", masename);
@@ -307,7 +413,7 @@
 	if(p == NULL) p = strchr(q,':'); 
 #elif defined(WIN32)
 	p = strchr(q,'\\'); 
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && !TARGET_RT_MAC_MACHO
 	p = strchr(q,':'); 
 #else
 	p = strchr(q,'/'); 
@@ -356,11 +462,13 @@
 static int *current_aa_color;
 
 
-int decode_color_scheme(char *list,  char *aminoacids, int *aa_color,
+int decode_color_scheme(char *vlist,  char *aminoacids, int *aa_color,
 	int maxprotcolors)
 {
 int nbr_colors = 1, current = 0, i;
-char *p;
+char *p, *list;
+list = strdup(vlist);
+if(list == NULL) return 1;
 aminoacids[0] = 0;
 p=strtok(list,",");
 while( p!= NULL && nbr_colors < maxprotcolors) {
@@ -370,6 +478,7 @@
 	nbr_colors++;
 	p=strtok(NULL,",");
 	}
+free(list);
 return nbr_colors;
 }
 
@@ -386,10 +495,8 @@
 while(nom != NULL && rank < max_colors - 1) {
 	r = g = b = -1;
 	sscanf(nom, "%d%d%d", &r, &g, &b);
-	if( r<0 || g<0 || b<0 ) decodecolorname(nom, &r, &g, &b);
 	if( r>=0 && g>=0 && b>=0 ) 
-		col = fl_color_cube(r*FL_NUM_RED/256, g*FL_NUM_GREEN/256, 
-			b*FL_NUM_BLUE/256);
+		col = fl_rgb_color(r, g, b);
 	else col = FL_BLACK;
 	colors[++rank] = (int)col;
 	nom = strtok(NULL, ",");
@@ -409,6 +516,7 @@
 *numb_stdprotcolors = 
 	decode_color_scheme(list_std, std_aminoacids, std_aa_color,
 		maxprotcolors);
+*numb_altprotcolors = 0;
 if(*list_alt == 0) return NO_ALT_COLORS;
 /* decodage du coloriage alternatif des proteines */
 *numb_altprotcolors = 
@@ -854,7 +962,9 @@
 int save_col0;
 static char up_line[1000]; char *p, *q; int i;
 
-if(view->tot_seqs == 0) return;
+if(view->tot_seqs == 0) {
+	return;
+	}
 fl_font(ob->labelfont(), ob->labelsize() );
 save_col0 = view->curr_colors[0];
 view->curr_colors[0] = ob->color();
@@ -1020,19 +1130,23 @@
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)view->bouton_props;
 props_menu_parts *props_parts = 
 		(props_menu_parts *)menu_props->user_data();
+Fl_Menu_Item *item;
 
 view->header = header;
 view->tot_seqs = totseqs;
 view->seq_length = 0;
 view->protein = protein;
 view->allow_seq_edit = FALSE;
-menu_props->mode(props_parts->edit, FL_MENU_TOGGLE );
-menu_props->mode(props_parts->keys, FL_MENU_RADIO);
-menu_props->mode(props_parts->keys + 1, FL_MENU_RADIO);
-menu_props->mode(props_parts->keys + 2, FL_MENU_RADIO);
-if(protein) menu_props->mode(props_parts->keys - 1,
-			FL_SUBMENU | FL_MENU_INACTIVE);
-else menu_props->mode(props_parts->keys - 1, FL_SUBMENU );
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->edit;
+item->activate(); item->clear();
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->keys;
+item->clear(); (item + 1)->clear(); (item + 2)->clear(); 
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->keys - 1;
+if(protein) item->deactivate();
+else item->activate();
+item = (Fl_Menu_Item *)menu_props->menu() + props_parts->reference;
+item->clear();
+item->deactivate();
 view->hjkl = FALSE;
 view->modif_but_not_saved = FALSE;
 if(masename != NULL) {
@@ -1069,30 +1183,24 @@
 	view->each_length, view->tot_comment_lines, view->comment_line);
 if(view->numb_dnacolors > 1 && view->bouton_props != NULL) { 
 	/* DNA/prot modes useful only with colors */
-	menu_props->mode(props_parts->colors, FL_MENU_RADIO );
-	menu_props->mode(props_parts->colors + 1, FL_MENU_RADIO );
-	if(view->alt_colors != NO_ALT_COLORS) {
-		menu_props->mode(props_parts->colors + 2, FL_MENU_RADIO);
-		}
+	item = (Fl_Menu_Item *)menu_props->menu() + props_parts->colors;
+	if(view->alt_colors != NO_ALT_COLORS) (item+2)->activate();
 	if(protein) {
 		if(view->alt_colors == USING_ALT_COLORS) {
-			menu_props->mode(props_parts->colors + 2, 
-				FL_MENU_RADIO | FL_MENU_VALUE);
+			(item+2)->setonly();
 			set_aa_color_mode(USING_ALT_COLORS);
 			view->numb_gc = view->numb_altprotcolors;
 			view->curr_colors = view->altprotcolors;
 			}
 		else	{
-			menu_props->mode(props_parts->colors + 1, 
-				FL_MENU_RADIO | FL_MENU_VALUE);
+			(item+1)->setonly();
 			set_aa_color_mode(USING_STANDARD_COLORS);
 			view->numb_gc = view->numb_stdprotcolors;
 			view->curr_colors = view->stdprotcolors;
 			}
 		}
 	else	{
-		menu_props->mode(props_parts->colors,
-			FL_MENU_RADIO | FL_MENU_VALUE);
+		item->setonly();
 		view->numb_gc = view->numb_dnacolors;
 		view->curr_colors = view->dnacolors;
 		}
@@ -1272,20 +1380,25 @@
 void **temp_data;
 int new_tot_seqs, i, j, c, *temp_int, numset;
 new_tot_seqs = view->tot_seqs - view->tot_sel_seqs;
-temp_data = (void **)malloc(new_tot_seqs * sizeof(void *));
-if(temp_data == NULL) return TRUE;
-temp_int = (int *)malloc(new_tot_seqs * sizeof(int));
-if(temp_int == NULL) return TRUE;
+if(new_tot_seqs > 0) {
+	temp_data = (void **)malloc(new_tot_seqs * sizeof(void *));
+	if(temp_data == NULL) return TRUE;
+	temp_int = (int *)malloc(new_tot_seqs * sizeof(int));
+	if(temp_int == NULL) return TRUE;
+	}
 
 for(i = 0, j = 0; i<  view->tot_seqs; i++) /* process sequences */
 	if( ! view->sel_seqs[i] ) temp_data[j++] = (void *) view->sequence[i];
 	else free(view->sequence[i]);
 memcpy(view->sequence , temp_data, new_tot_seqs * sizeof(char *) );
 
-for(i = 0, j = 0; i<  view->tot_seqs; i++) /* process comments */
-	if( ! view->sel_seqs[i] ) temp_data[j++] = (void *) view->comments[i];
-	else free(view->comments[i]);
-memcpy(view->comments , temp_data, new_tot_seqs * sizeof(char *) );
+if(view->comments != NULL) {
+	for(i = 0, j = 0; i<  view->tot_seqs; i++) /* process comments */
+		if( ! view->sel_seqs[i] ) temp_data[j++] = 
+						(void *) view->comments[i];
+		else free(view->comments[i]);
+	memcpy(view->comments , temp_data, new_tot_seqs * sizeof(char *) );
+	}
 
 for(i = 0, j = 0; i<  view->tot_seqs; i++) /* process seq names */
 	if( ! view->sel_seqs[i] ) temp_data[j++] = (void *) view->seqname[i];
@@ -1386,6 +1499,7 @@
 	view->draw_names = 0;
 	if(old != new_val) view->DNA_obj->damage(1);
 	}
+view->DNA_obj->take_focus();
 }
 
 
@@ -1419,6 +1533,7 @@
 	if(which <= 3)  view->draw_names = 0;
 	view->DNA_obj->damage(view->draw_names ? FL_DAMAGE_ALL : 1);
 	}
+view->DNA_obj->take_focus();
 }
 
 
@@ -1436,6 +1551,7 @@
 compute_size_params(view, TRUE);
 view->DNA_obj->parent()->redraw();
 fl_reset_cursor(view->dnawin);
+view->DNA_obj->take_focus();
 }
 
 
@@ -1446,13 +1562,8 @@
 int reponse =  ((Fl_Menu_Button *)ob)->value();
 int previous_format = view->format_for_save + debut;
 if(previous_format == reponse) return;
-view->format_for_save = (known_format)(reponse - debut);
-Fl_Menu_Item *items = (Fl_Menu_Item *) ((Fl_Menu_ *)view->menu_file)->menu();
-items[SAVE].deactivate();
-if(view->masename != NULL) {
-	free(view->masename);
-	view->masename = NULL;
-	}
+set_save_format(view, reponse - debut);
+view->DNA_obj->take_focus();
 }
 
 
@@ -1477,34 +1588,13 @@
 }
 
 
-void change_format(Fl_Widget *obj, void *data)
-{
-SEA_VIEW *view = (SEA_VIEW *)data;
-int current = view->format_for_save;
-Fl_Menu_Button *menu_props = (Fl_Menu_Button *)view->bouton_props;
-props_menu_parts *props_parts = 
-		(props_menu_parts *)menu_props->user_data();
-Fl_Menu_Item *saveas_popup = 
-	(Fl_Menu_Item *)menu_props->menu() + props_parts->saveformat;
-const Fl_Menu_Item *reponse = saveas_popup->popup(Fl::event_x(), Fl::event_y(),
-	"Choose format");
-if(reponse == NULL) return;
-if(current == reponse - saveas_popup) return;
-current = reponse - saveas_popup;
-set_save_format(view, current);
-char *p = (char *)obj->window()->label();
-sprintf(p, "Choose a %s file name", f_format_names[current] );
-obj->window()->label(p);
-return;
-}
-
-
 void colors_callback(Fl_Widget *ob, void *data)
 {
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)ob;
 props_menu_parts *parts = (props_menu_parts *)data;
 SEA_VIEW *view = parts->view;
 int reponse =  menu_props->value();
+Fl_Menu_Item *item;
 
 /* processing inverted colors */
 if(reponse == parts->inverted) {
@@ -1520,6 +1610,9 @@
 	view->DNA_obj->labelfont(style);
 	view->DNA_obj->redraw();
 	fl_reset_cursor(view->dnawin);
+	item = (Fl_Menu_Item *)menu_props->menu() + parts->reference;
+	if( (!view->inverted_colors) && view->tot_sel_seqs == 1) item->activate();
+	else item->deactivate();
 	return;
 	}
 
@@ -1542,22 +1635,25 @@
 		free(view->col_seq[num]);
 		}
 	}
+item = (Fl_Menu_Item *)menu_props->menu() + parts->keys - 1;
 if(reponse == DNARNA) {
 	view->numb_gc = view->numb_dnacolors;
 	view->curr_colors = view->dnacolors;
-	menu_props->mode(parts->keys - 1, FL_SUBMENU);
+	item->activate();
+	adjust_menu_edit_modes(view);
 	}
 else if(reponse == Protein) {
 	set_aa_color_mode(USING_STANDARD_COLORS);
 	view->numb_gc = view->numb_stdprotcolors;
 	view->curr_colors = view->stdprotcolors;
-	menu_props->mode(parts->keys - 1, FL_SUBMENU | FL_MENU_INACTIVE);
+	item->deactivate();
+	adjust_menu_edit_modes(view);
 	}
 else if(reponse == Alt) {
 	set_aa_color_mode(USING_ALT_COLORS);
 	view->numb_gc = view->numb_altprotcolors;
 	view->curr_colors = view->altprotcolors;
-	menu_props->mode(parts->keys - 1, FL_SUBMENU | FL_MENU_INACTIVE);
+	item->deactivate();
 	}
 view->col_seq = prepcolseqs(view->sequence, view->tot_seqs, 
 	view->max_seq_length, view->each_length, 
@@ -1577,24 +1673,38 @@
 props_menu_parts *parts = (props_menu_parts *)data;
 SEA_VIEW *view = parts->view;
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)ob;
+Fl_Menu_Item *item = (Fl_Menu_Item *)menu_props->menu() + parts->edit;
+
 view->allow_seq_edit = !view->allow_seq_edit;
 if(view->allow_seq_edit) 
-	menu_props->mode(parts->edit, FL_MENU_TOGGLE | FL_MENU_VALUE);
+	item->set();
 else
-	menu_props->mode(parts->edit, FL_MENU_TOGGLE);
+	item->clear();
 }
 
 
+void consensus_allowgaps_callback(Fl_Widget *ob, void *data)
+{
+int *poption = (int *)data;
+Fl_Menu_Item *item = (Fl_Menu_Item *)( ((Fl_Menu_ *)ob)->mvalue() );
+*poption = !(*poption);
+}
+
+
 void slow_fast_callback(Fl_Widget *ob, void *data)
 {
 props_menu_parts *parts = (props_menu_parts *)data;
 SEA_VIEW *view = parts->view;
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)ob;
+Fl_Menu_Item *item = (Fl_Menu_Item *)menu_props->menu() + parts->slow_fast;
 view->double_buffer = !view->double_buffer;
 if(!view->double_buffer) 
-	menu_props->mode(parts->slow_fast, FL_MENU_TOGGLE | FL_MENU_VALUE);
+	item->set();
 else
-	menu_props->mode(parts->slow_fast, FL_MENU_TOGGLE);
+	item->clear();
+#ifdef __APPLE__
+set_res_value("fast", view->double_buffer ? "false" : "true");
+#endif
 Fl_Window *win = (Fl_Window *)view->DNA_obj->parent();
 Fl_Group *win_parent = (Fl_Group *)win->parent();
 int x,y,w,h;
@@ -1630,12 +1740,13 @@
 SEA_VIEW *view = parts->view;
 int num, col, pos; char c;
 int (*calc_color_function)(int);
+Fl_Menu_Item *item = (Fl_Menu_Item *)menu_props->menu() + parts->allow_lower;
 
 view->allow_lower = !view->allow_lower;
 if(view->allow_lower) 
-	menu_props->mode(parts->allow_lower, FL_MENU_TOGGLE | FL_MENU_VALUE);
+	item->set();
 else
-	menu_props->mode(parts->allow_lower, FL_MENU_TOGGLE);
+	item->clear();
 my_watch_cursor(view->dnawin);
 calc_color_function = view->protein ? get_color_for_aa : get_color_for_base;
 if(view->allow_lower) {
@@ -1671,16 +1782,16 @@
 props_menu_parts *parts = (props_menu_parts *)data;
 SEA_VIEW *view = parts->view;
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)ob;
-on =  menu_props->mode(parts->reference) & FL_MENU_VALUE ;
+Fl_Menu_Item *item = (Fl_Menu_Item *)menu_props->menu() + parts->edit;
+on = (menu_props->menu() + parts->reference)->value();
 reference_toggle(view, on);
 if(on) 	{
-	etat = menu_props->mode(parts->allow_lower);
-	menu_props->mode(parts->allow_lower, etat | FL_MENU_INACTIVE );
+	item->deactivate();
 	}
 else	{
-	etat = FL_MENU_TOGGLE;
-	if(view->allow_lower) etat |= FL_MENU_VALUE;
-	menu_props->mode(parts->allow_lower, etat );
+	item->activate();
+	if(view->allow_seq_edit) item->set();
+	else item->clear();
 	}
 }
 
@@ -1695,7 +1806,7 @@
 	view->hjkl = reponse + 1;
 	}
 else if(view->hjkl == reponse + 1) { /* desactiver choix courant */
-	menu_props->mode(parts->keys + reponse, FL_MENU_RADIO );
+	((Fl_Menu_Item *)menu_props->mvalue())->clear();
 	view->hjkl = 0;
 	}
 else	{ /* changer de choix */
@@ -1710,17 +1821,18 @@
 SEA_VIEW *view = parts->view;
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)ob;
 int reponse =  menu_props->value();
-if(reponse == parts->clustalopt) { // toggle use of option
-	; // toggle automatique 
+if(reponse == parts->clustalopt || reponse == parts->clustalopt + 1) { 
+	view->alignment_algorithm = reponse - parts->clustalopt;  
 	}
-else	{ // edit options
+else if(reponse == parts->clustalopt + 3)	{ // edit options
 	const char *rep;
 	int l; 
-	rep = fl_input("Clustal options "
-#if defined(WIN32) || defined(__APPLE__)
+	rep = fl_input("Alignment options "
+#if defined(WIN32) || (defined(__APPLE__) && ! TARGET_RT_MAC_MACHO)
 		"(ex: /gapopen=5 /quicktree)", 
 #else
-		"(ex: -gapopen=5 -quicktree)", 
+		"(Clustal ex: -gapopen=5 -quicktree\n"
+		"Muscle ex: -maxiters 5 -diags)", 
 #endif
 		(view->clustal_options == NULL ? "": view->clustal_options) );
 	if(rep == NULL) return;
@@ -1734,9 +1846,8 @@
 	view->clustal_options = (char *)malloc(l+1);
 	memcpy(view->clustal_options, rep, l);
 	view->clustal_options[l] = 0;
-	menu_props->replace(parts->clustalopt, view->clustal_options);
-	menu_props->mode(parts->clustalopt, 
-		FL_MENU_TOGGLE | FL_MENU_VALUE | FL_MENU_DIVIDER);
+	menu_props->replace(parts->clustalopt + 2, view->clustal_options);
+	menu_props->mode(parts->clustalopt + 2, FL_MENU_TOGGLE | FL_MENU_VALUE | FL_MENU_DIVIDER);
 	}
 }
 
@@ -1747,7 +1858,7 @@
 SEA_VIEW *view = parts->view;
 Fl_Menu_Button *menu_props = (Fl_Menu_Button *)ob;
 int reponse =  menu_props->value();
-if(reponse != parts->consensusopt + 1) return; // securite
+if(reponse != parts->consensusopt + 2) return; // securite
 const char *rep;
 char tmp[100];
 int value;
@@ -1776,6 +1887,7 @@
 
 /* partie Fontsize */
 obj->add("Fontsize", 0, 0, 0, FL_SUBMENU);
+#define NBER_FONTSIZES 10
 parts->fontsize = 
 	obj->add("Fontsize/8", 0, font_callback, parts, FL_MENU_RADIO);
 obj->add("Fontsize/10", 0, font_callback, parts, FL_MENU_RADIO);
@@ -1783,16 +1895,19 @@
 obj->add("Fontsize/14", 0, font_callback, parts, FL_MENU_RADIO );
 obj->add("Fontsize/16", 0, font_callback, parts, FL_MENU_RADIO );
 obj->add("Fontsize/18", 0, font_callback, parts, FL_MENU_RADIO );
-for(defaut = parts->fontsize; defaut < parts->fontsize + 6; defaut++) {
+obj->add("Fontsize/24", 0, font_callback, parts, FL_MENU_RADIO );
+obj->add("Fontsize/28", 0, font_callback, parts, FL_MENU_RADIO );
+obj->add("Fontsize/32", 0, font_callback, parts, FL_MENU_RADIO );
+obj->add("Fontsize/36", 0, font_callback, parts, FL_MENU_RADIO );
+
+for(defaut = parts->fontsize; defaut < parts->fontsize + NBER_FONTSIZES; defaut++) {
 	int taille;
 	sscanf( obj->text(defaut), "%d", &taille);
-	if(taille == def_fontsize) break;
+	if(taille >= def_fontsize) break;
 	}
-if(defaut >= parts->fontsize + 6) defaut = parts->fontsize + 3;
-mode = obj->mode(defaut);
-obj->mode(defaut, mode | FL_MENU_VALUE);
+if(defaut >= parts->fontsize + NBER_FONTSIZES) defaut = parts->fontsize + 3;
+((Fl_Menu_Item *)obj->menu() + defaut)->set();
 
-
 /* partie Save Format */
 obj->add("Save Format", 0, 0, 0, FL_SUBMENU);
 parts->saveformat = obj->add("Save Format/Save as Mase", 0, save_as_callback, 
@@ -1803,8 +1918,7 @@
 obj->add("Save Format/Save as Fasta", 0, save_as_callback, parts,FL_MENU_RADIO);
 obj->add("Save Format/Save as NEXUS", 0, save_as_callback, parts,FL_MENU_RADIO);
 defaut = parts->saveformat + view->format_for_save;
-mode = obj->mode(defaut);
-obj->mode(defaut, mode | FL_MENU_VALUE);
+((Fl_Menu_Item *)obj->menu() + defaut)->set();
 
 /* partie Colors */
 int submenu = obj->add("Colors", 0, 0, 0, FL_SUBMENU);
@@ -1815,15 +1929,14 @@
 	FL_MENU_RADIO | FL_MENU_DIVIDER );
 parts->inverted = obj->add("Colors/Inverted colors", 0, colors_callback, parts, FL_MENU_TOGGLE );
 if(black_and_white) {
-	obj->mode(submenu, FL_SUBMENU | FL_MENU_INACTIVE);
+	((Fl_Menu_Item *)obj->menu() + submenu)->deactivate();
 	}
 else	{
 	defaut = parts->colors; if(view->protein) defaut++;
-	obj->mode(defaut, FL_MENU_RADIO | FL_MENU_VALUE);
+	((Fl_Menu_Item *)obj->menu() + defaut)->set();
 	if(curr_color_choice == NO_ALT_COLORS) 
-		obj->mode(alt, 
-			FL_MENU_RADIO | FL_MENU_DIVIDER | FL_MENU_INACTIVE );
-	if(inverted) obj->mode(parts->inverted, FL_MENU_TOGGLE | FL_MENU_VALUE);
+		((Fl_Menu_Item *)obj->menu() + alt)->deactivate();
+	if(inverted) ((Fl_Menu_Item *)obj->menu() + parts->inverted)->set();
 	}
 
 /* partie Edit */
@@ -1833,11 +1946,11 @@
 /* partie by reference */
 parts->reference = obj->add("by Reference", 0, toggle_reference_callback, 
 	parts, FL_MENU_TOGGLE);
-if(black_and_white) obj->mode(parts->reference, 
-			FL_MENU_TOGGLE | FL_MENU_INACTIVE);
+if(black_and_white) 
+	((Fl_Menu_Item *)obj->menu() + parts->reference)->deactivate();
 else	{
 // bug: FL_ALT ne marche pas, c'est Meta qu'il faut taper a la place
-	obj->shortcut(parts->reference, FL_CTRL | 'r');
+	obj->shortcut(parts->reference, myFL_CTRL | 'r');
 	}
 
 /* partie keys */
@@ -1849,11 +1962,19 @@
 obj->add("DNA keys/hjkl<space> => ACGTN", 0, dnakeys_callback, 
 	parts, FL_MENU_RADIO);
 
-/* partie clustal options */
-obj->add("Clustalw options", 0, 0, 0, FL_SUBMENU);
-parts->clustalopt = obj->add("Clustalw options/<none>", 0, clustal_opt_callback, 
+/* partie alignment options */
+obj->add("Alignment options", 0, 0, 0, FL_SUBMENU);
+parts->clustalopt = obj->add("Alignment options/Clustalw", 0, clustal_opt_callback, 
+	parts, FL_MENU_RADIO);
+obj->add("Alignment options/Muscle", 0, clustal_opt_callback, 
+	parts, FL_MENU_RADIO | FL_MENU_DIVIDER);
+((Fl_Menu_Item *)obj->menu() + parts->clustalopt + view->alignment_algorithm)->set();
+#ifdef NO_CLUSTALW
+((Fl_Menu_Item *)obj->menu() + parts->clustalopt + CLUSTALW)->deactivate();
+#endif
+obj->add("Alignment options/<none>", 0, clustal_opt_callback, 
 	parts, FL_MENU_DIVIDER | FL_MENU_INACTIVE);
-obj->add("Clustalw options/Edit options", 0, clustal_opt_callback, 
+obj->add("Alignment options/Edit options", 0, clustal_opt_callback, 
 	parts, 0);
 
 /* partie consensus options */
@@ -1861,7 +1982,8 @@
 char tmp[50];
 sprintf(tmp, "Consensus options/%d %%", view->consensus_threshold);
 parts->consensusopt = obj->add(tmp, 0, NULL, parts, FL_MENU_DIVIDER);
-obj->add("Consensus options/Edit options", 0, consensus_opt_callback, parts, 0);
+obj->add("Consensus options/allow gaps", 0, consensus_allowgaps_callback, &(view->consensus_allowgaps), FL_MENU_TOGGLE);
+obj->add("Consensus options/Edit threshold", 0, consensus_opt_callback, parts, 0);
 
 /* partie Fast/Slow */
 parts->slow_fast = obj->add("Fast-Rough", 0, slow_fast_callback, parts,
@@ -1870,7 +1992,11 @@
 /* partie allow lower case */
 parts->allow_lower = obj->add("Allow lowercase", 0, allow_lower_callback, parts,
 	view->allow_lower ? FL_MENU_TOGGLE | FL_MENU_VALUE : FL_MENU_TOGGLE );
-if(black_and_white) obj->mode(parts->allow_lower, FL_MENU_INACTIVE);
+if(black_and_white) 
+	((Fl_Menu_Item *)obj->menu() + parts->allow_lower)->deactivate();
+
+/* partie customize */
+parts->custom = obj->add("Customize", 0, custom_callback, view, 0);
 }
 
 
@@ -1889,7 +2015,7 @@
 	char temp[100];
 	sprintf(temp,"Confirm request of deletion of %d sequence(s)",
 		view->tot_sel_seqs);
-	if( fl_ask(temp) ) {
+	if( ask_with_custom_yesno(temp, "Delete", "Cancel") ) { 
 		if( delete_selected_seqs(view) )
 			fl_alert("Not enough memory for this operation");
 		else	{
@@ -1991,7 +2117,7 @@
 	fl_reset_cursor(view->dnawin);
 	}
 else if(reponse == ALIGN_SEQS) { /* align selected sites */
-	align_selected_parts(view);
+	align_selected_parts(view, view->alignment_algorithm);
 	view->DNA_obj->redraw();
 	view->horsli->redraw();
 	fl_reset_cursor(view->dnawin);
@@ -2059,7 +2185,7 @@
 	view->vertsli->Fl_Slider::value(view->first_seq);
 	}
 else if(reponse == DELETE_GAP_ONLY_SITES) {
-	if( !fl_ask("Confirm remove all gap_containing sites?") ) 
+	if( !ask_with_custom_yesno("Confirm remove all gap_containing sites?", "Remove", "Cancel") )  
 		return;
 	my_watch_cursor(view->dnawin);
 	del_gap_only_sites(view);
@@ -2282,7 +2408,7 @@
 for(num = 0; num < view->tot_seqs; num++) {
 	free(view->sequence[num]);
 	free(view->seqname[num]);
-	if(view->comments[num] != NULL) {
+	if(view->comments != NULL && view->comments[num] != NULL) {
 		free(view->comments[num]);
 		view->comments[num] = NULL;
 		}
@@ -2294,7 +2420,7 @@
 if( view->tot_seqs > 0 ) {
 	free(view->sequence);
 	free(view->seqname);
-	free(view->comments);
+	if(view->comments != NULL) free(view->comments);
 	}
 if( view->numb_gc > 1 && view->tot_seqs > 0 ) free(view->col_seq);
 if(view->masename != NULL) {
@@ -2315,6 +2441,7 @@
 view->numb_species_sets = 0;
 view->tot_seqs = 0;
 view->tot_sel_seqs = 0;
+view->cursor_seq = 0;
 free_region(view->active_region);
 view->active_region = NULL;
 if(view->menu_file != NULL) {
@@ -2339,18 +2466,49 @@
 
 
 void load_alignment_file(SEA_VIEW *view, char *filename, char *message, 
-	char *pattern, known_format file_format)
+	known_format file_format)
 {
 char *err_message, *p;
 int protein;
+
 if(view->tot_seqs > 0 && view->modif_but_not_saved) {
-	if( ! fl_ask("Alignment was modified but not saved\n"
-		"Do you want to  read a new alignment?") ) return;
+	if( ! ask_with_custom_yesno("Alignment was modified but not saved\n"
+		"Do you want to  read a new alignment?", "Read", "Cancel") ) return; 
 	}
 if(filename == NULL) {
-	filename = (char *)fl_file_chooser(message,pattern,"");
+#ifdef WIN32
+	char wpattern[100];
+	p = wpattern;
+	if(file_format != -1) {
+		sprintf(wpattern, "%s format (*.%s)%c*.%s%c", 
+			f_format_names[file_format], f_format_exts[file_format], 0, 
+			f_format_exts[file_format], 0);
+		p = wpattern + strlen(wpattern) + 1;
+		p = p + strlen(p) + 1;
+		}
+	sprintf(p, "any%c*%c", 0, 0);
+	filename = MG_win32_file_chooser(message, wpattern, "", 
+		file_format == -1 ? NULL : f_format_exts[file_format], 
+		FALSE, NULL);
+#else
+#ifdef __APPLE__
+	filename = (char *)MAC_file_chooser(message,NULL,"");
+#else
+	char pattern[20];
+	if(file_format != -1) sprintf(pattern, "*.%s", f_format_exts[file_format]); 
+	else strcpy(pattern, "[^.]*");
+	filename = (char *)fl_file_chooser(message,pattern,"",0);
+#endif
+#endif
 	if(filename==NULL) return;
 	}
+if(file_format == -1) {
+	file_format = what_format(filename);
+	if(file_format < 0) {
+			fl_alert("File %s\nis not of a format readable by seaview", filename);
+			return;
+			}
+	}
 my_watch_cursor(view->dnawin);
 if(view->alt_col_seq != NULL) {
 	reference_toggle(view, FALSE);
@@ -2389,7 +2547,7 @@
 		&err_message, &view->regions, &view->numb_species_sets,
 		&list_sp, &name_sp, &view->tot_comment_lines, 
 		&view->comment_name, &view->comment_line, 
-		&view->comment_length);
+		&view->comment_length, &protein);
 	for(i= 0; i < view->numb_species_sets; i++) {
 		view->list_species_sets[i] = list_sp[i];
 		view->name_species_sets[i] = name_sp[i];
@@ -2404,9 +2562,9 @@
 	view->DNA_obj->parent()->redraw();
 	return;
 	}
-protein = is_a_protein_seq(view->sequence[0]);
+if(file_format != NEXUS_FORMAT) protein = is_a_protein_seq(view->sequence[0]);
 p = extract_filename(filename);
-view->dnawin->label(p, p);
+view->dnawin->label(PREPARE_LABEL(p));
 if(view->menu_file != NULL) {
 	Fl_Menu_Item *items = 
 		(Fl_Menu_Item *) ((Fl_Menu_ *)view->menu_file)->menu();
@@ -2425,18 +2583,34 @@
 init_dna_scroller(view, view->tot_seqs, filename, protein, view->header);
 view->DNA_obj->parent()->redraw();
 fl_reset_cursor(view->dnawin);
+view->DNA_obj->take_focus();
 return;
 }
 
 
+int ask_with_custom_yesno(const char *text, const char *yes, const char *no)
+{
+const char *oldyes = fl_yes; const char *oldno = fl_no;
+fl_yes = yes; fl_no = no;
+int rep = fl_ask(text);
+fl_yes = oldyes; fl_no = oldno;
+return rep;
+}
+
+
 void mainwin_close_callback(Fl_Widget *form, void *data)
 {
 SEA_VIEW *view = (SEA_VIEW *)data;
 if(view->modif_but_not_saved) {
-	if( ! fl_ask(
-		"Alignment was modified but not saved\n"
-		"Do you want to quit anyway?") ) return;
+	if(! ask_with_custom_yesno("Alignment was modified but not saved\n"
+		"Do you want to quit anyway?", "Quit", "Cancel") ) return;
 	}
+#ifdef __APPLE__
+char value[50];
+sprintf(value, "%dx%d", view->dnawin->w(),  view->dnawin->h() );
+set_res_value("window", value);
+save_resources();
+#endif
 exit(0);
 }
 
@@ -2444,58 +2618,54 @@
 void file_menu_callback(Fl_Widget *ob, long which)
 {
 SEA_VIEW *view;
-static char *pattern[] = {
-#ifdef WIN32
-	"*.mas"
-#else
-	"*.mase"
-#endif
-	, "*", "*.aln", "*.msf", "*", "*.nx"};
-static char fsel_message[50];
+char pattern[20];
+static char fsel_message[] = "seaview: choose file and format";
 char *filename;
 int reponse = ((Fl_Menu_Button*)ob)->value();
+
 view = (SEA_VIEW *) ob->user_data();
+sprintf(pattern, "*.%s", f_format_exts[view->format_for_save]);
 if(reponse == QUIT) { /* quit */
 	mainwin_close_callback(view->dnawin, view);
 	}
+else if(reponse == OPEN_ANY) { 
+#ifdef __APPLE__
+	Fl::e_state = 0; // contre bug fltk/MacOS qui laisse e_state plein apres cmd-O
+#endif
+	load_alignment_file(view, NULL, 
+		"Choose an alignment file",  (known_format)-1);
+	}
 else if(reponse == OPEN_MASE) { 
 	load_alignment_file(view, NULL, 
-#ifdef WIN32
-		"Choose a .mas file", 
-#else
-		"Choose a .mase file", 
-#endif
-	pattern[0], MASE_FORMAT);
+		"Choose a .mase file",  MASE_FORMAT);
 	}
 else if(reponse == OPEN_PHYLIP )	{  
 	load_alignment_file(view, NULL,
-		"Choose a Phylip file" ,"*",  PHYLIP_FORMAT );
+		"Choose a Phylip file" ,  PHYLIP_FORMAT );
 	}
-else if(reponse == OPEN_FASTA )	{  
-	load_alignment_file(view, NULL,
-		"Choose a Fasta file" ,"*",  FASTA_FORMAT );
-	}
 else if(reponse == OPEN_CLUSTAL )	{  
 	load_alignment_file(view, NULL,
-		"Choose a Clustal file" ,"*.aln",  CLUSTAL_FORMAT );
+		"Choose a Clustal file" ,  CLUSTAL_FORMAT );
 	}
 else if(reponse == OPEN_MSF )	{  
 	load_alignment_file(view, NULL,
-		"Choose an MSF file" ,"*.msf",  MSF_FORMAT );
+		"Choose an MSF file",  MSF_FORMAT );
 	}
+else if(reponse == OPEN_FASTA )	{  
+	load_alignment_file(view, NULL,
+		"Choose a Fasta file",  FASTA_FORMAT );
+	}
 else if(reponse == OPEN_NEXUS )	{  
 	load_alignment_file(view, NULL,
-		"Choose a NEXUS file" ,"*.nx",  NEXUS_FORMAT );
+		"Choose a NEXUS file",  NEXUS_FORMAT );
 	}
 else if(reponse == SAVE || reponse == SAVE_AS) 	{ 
 	char *err;
 	if(reponse == SAVE_AS) { /* Save as */
 		FILE *in;
-		sprintf(fsel_message,"Choose a %s file name", 
-			f_format_names[view->format_for_save]);
 		filename = fl_file_chooser_save_as(fsel_message,
-			pattern[view->format_for_save], 
-			extract_filename(view->masename), view);
+			pattern, 
+			view->masename, view);
 		if(filename==NULL) return;
 #ifndef __APPLE__
 		in = fopen(filename,"r");
@@ -2504,12 +2674,14 @@
 			fclose(in);
 			sprintf(tmp, "This file already exists\n%s\n"
 				"Do you want to overwrite it?", filename);
-			if( ! fl_ask(tmp) )
+			if( ! ask_with_custom_yesno(tmp, "Overwrite", "Cancel") ) 
 				return;
 			}
 #endif
 		}
-	else 	filename = view->masename;
+	else {
+		filename = view->masename;
+		}
 	my_watch_cursor(view->dnawin);
 	save_active_region(view, TRUE);
 	err = save_alignment_or_region(filename, view->sequence, view->comments,
@@ -2527,7 +2699,7 @@
 			view->masename=(char *)malloc(strlen(filename)+1);
 			if(view->masename == NULL) out_of_memory();
 			strcpy(view->masename,filename);
-			view->dnawin->label(extract_filename(filename));
+			view->dnawin->label(PREPARE_LABEL(extract_filename(filename)));
 			Fl_Menu_Item *items = 
 				(Fl_Menu_Item *) ((Fl_Menu_ *)ob)->menu();
 			items[SAVE].activate();
@@ -2541,17 +2713,14 @@
 	static int first = TRUE;
 	if(first) {
 	 	strcpy(regions_only_filename, "regions");
-		if( strchr(pattern[view->format_for_save],'.') != NULL)
+		if( strchr(pattern,'.') != NULL)
 			strcat(regions_only_filename, 
-				pattern[view->format_for_save]+1);
+				pattern+1);
 		first = FALSE;
 		}
 	if(view->active_region == NULL) return;
-	sprintf(fsel_message,"Choose a %s file name", 
-			f_format_names[view->format_for_save]);
 	filename = fl_file_chooser_save_as(fsel_message,
-			pattern[view->format_for_save], 
-			regions_only_filename, view);
+			pattern, regions_only_filename, view);
 	if(filename==NULL) return;
 	my_watch_cursor(view->dnawin);
 	err = save_alignment_or_region(filename, view->sequence, view->comments,
@@ -2566,15 +2735,33 @@
 else if(reponse == PRINTOUT && view->tot_seqs > 0) {
 	int anerr;
 	FILE *in;
-
-	if( view->alt_col_seq != NULL ) {
+	char suggested[200], *p;
+	
+	strcpy(suggested, extract_filename(view->masename) );
+	p = strrchr(suggested, '.');
+	if(p != NULL) *p = 0;
+#ifdef NO_PDF
+	strcat(suggested, ".ps");
+#else
+	strcat(suggested, ".pdf");
+#endif
+if( view->alt_col_seq != NULL ) {
 		for(anerr = 0; anerr < view->tot_seqs; anerr++)
 			if(view->sel_seqs[anerr]) break;
 		}
 	else	anerr = -1;
+#ifdef WIN32
+	filename = MG_win32_file_chooser("Enter a pdf file name", "pdf format\0*.pdf\0", suggested, "pdf",
+		TRUE, NULL);
+#elif defined(__APPLE__)
 	filename = (char *) fl_file_chooser_plus(
-		"Enter a printout file name", "", "", 
+		"Enter a pdf file name", "*.pdf", suggested, 
 		(anerr >= 0 ? TRUE : FALSE) );
+#elif defined(NO_PDF)
+	filename = fl_file_chooser("Enter a ps file name", "*.ps", suggested, 0);
+#else
+	filename = fl_file_chooser("Enter a pdf file name", "*.pdf", suggested, 0);
+#endif
 	if(filename==NULL) return;
 #ifndef __APPLE__
 	in = fopen(filename,"r");
@@ -2583,25 +2770,140 @@
 		fclose(in);
 		sprintf(tmp, "This file already exists\n%s\n"
 				"Do you want to overwrite it?", filename);
-		if( ! fl_ask(tmp) )
+		if( ! ask_with_custom_yesno(tmp, "Overwrite", "Cancel") ) 
 			return;
 		}
 #endif
 	my_watch_cursor(view->dnawin);
-	anerr = prepare_printout(filename, view->sequence, view->tot_seqs,
-		view->seqname, view->each_length, printout_cpl,
-		printout_block, printout_lpp, printout_vary, 
-		view->masename, anerr);
+	anerr = pdf_printout(view, filename, printout_fontsize,
+		printout_block, printout_pageformat, printout_vary, anerr, printout_black);
 	fl_reset_cursor(view->dnawin);
 	if( anerr ) fl_alert("Error while writing to file %s",
 		filename);
 	}
+#if !defined( __APPLE__)
+else if(reponse == PDFOPTIONS ) {
+	pdfps_options_dialog(view);
+	}
+#endif
 }
 
 
 
-#ifdef __APPLE__
+#if !defined( __APPLE__)
 
+static void printout_callback(Fl_Widget *obj, void *data)
+{
+const char *p;
+
+p = ((Fl_Input *)obj)->value();
+sscanf(p, "%d", (int *)data);
+}
+
+
+static void ok_callback(Fl_Widget *obj)
+{
+if(obj->window() == NULL) obj->hide();
+else obj->window()->hide();
+}
+
+
+static void paper_callback(Fl_Widget *obj)
+{
+printout_pageformat = (paperformat)((Fl_Choice *)obj)->value();
+}
+
+static void variable_callback(Fl_Widget *obj)
+{
+printout_vary = ! printout_vary;
+}
+
+
+static void radio_callback(Fl_Widget *obj)
+{
+Fl_Group *group;
+Fl_Round_Button **fils;
+
+if( ! ((Fl_Round_Button *)obj)->value() ) {
+	((Fl_Round_Button *)obj)->value(1);
+	return;
+	}
+printout_black = !printout_black;
+group = obj->parent();
+fils = (Fl_Round_Button **)((Fl_Group *)group)->array();
+fils[0]->value(!printout_black);
+fils[1]->value(printout_black);
+}
+
+void pdfps_options_dialog(SEA_VIEW *view)
+{
+static Fl_Window *pdf_form = NULL;
+static Fl_Input *sizeinput, *blockinput;
+static Fl_Choice *paper;
+static Fl_Round_Button *colorb, *blackb;
+static Fl_Check_Button *variable;
+Fl_Button *ok;
+Fl_Group *radiog;
+int x, y, w, h;
+char txt[20];
+
+if(pdf_form == NULL) {
+fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
+
+pdf_form = new Fl_Window(400,80);
+pdf_form->box(FL_FLAT_BOX);
+pdf_form->label("Set "PDF_OR_PS" output options");
+
+x = 5 + (int)fl_width("block size:"); y = 5; w = 50; h = 25;
+sizeinput = new Fl_Input(x, y, w, h, "font size:");
+sizeinput->callback(printout_callback, &printout_fontsize);
+blockinput = new Fl_Input(x, y + sizeinput->h() + 5 , w, h, "block size:");
+blockinput->callback(printout_callback, &printout_block);
+paper = new Fl_Choice(x + sizeinput->w() + (int)fl_width("paper size:") + 15, y, 
+	(int)fl_width("LETTER") + 30, h, "paper size:");
+paper->add("A4|LETTER");
+paper->callback(paper_callback);
+
+x = paper->x() + paper->w() + 5;
+radiog = new Fl_Group(x, y, (int)fl_width("color") + 25, 2 * h + 3);
+radiog->box(FL_DOWN_FRAME);
+colorb = new Fl_Round_Button(x, y, radiog->w(), h, "color");
+blackb = new Fl_Round_Button(x, y + colorb->h() + 5, radiog->w(), h, "B&&W");
+blackb->value(printout_black);
+colorb->callback(radio_callback);
+blackb->callback(radio_callback);
+radiog->end();
+
+x = blockinput->x() + blockinput->w() + 5;
+variable = new Fl_Check_Button(x, blockinput->y(), (int)fl_width("Variable sites only") + 25, h, "Variable sites only");
+variable->box(FL_DOWN_FRAME);
+variable->callback(variable_callback);
+
+ok = new Fl_Button(radiog->x() + radiog->w() + 5, variable->y(), 25, h, "OK");
+ok->callback(ok_callback);
+
+pdf_form->end();
+pdf_form->resizable(NULL);
+pdf_form->position((Fl::w() - pdf_form->w())/2, (Fl::h() - pdf_form->h())/2);
+pdf_form->set_modal();
+}
+
+sprintf(txt, "%d", printout_fontsize);
+sizeinput->value(txt);
+sprintf(txt, "%d", printout_block);
+blockinput->value(txt);
+paper->value(printout_pageformat);
+colorb->value(!printout_black);
+blackb->value(printout_black);
+variable->value(printout_vary);
+if(view->alt_col_seq != NULL && view->tot_sel_seqs == 1) variable->show();
+else variable->hide();
+pdf_form->show();
+}
+#endif
+
+#if defined(__APPLE__) && ! TARGET_RT_MAC_MACHO
+
 char *read_next_help_line(char *line, int lline, void *v_in)
 {
 static char *pos;
@@ -2626,33 +2928,6 @@
 
 #endif
 
-/*
-char *get_next_help_line(void *in, char *line, int lline)
-{
-#ifdef WIN32
-static const int win32=TRUE;
-#else
-static const int win32=FALSE;
-#endif
-static int accept = TRUE;
-if( read_next_help_line(line, lline, in) == NULL) { accept = TRUE; return NULL; }
-while(*line != '#') {
-	if(accept) return line;
-	if( read_next_help_line(line, lline, in) == NULL) { accept = TRUE; return NULL; }
-	}
-if(strncmp(line, "#ifdef", 6) == 0)
-	accept = win32;
-else if(strncmp(line, "#ifndef", 7) == 0)
-	accept = !win32;
-else if(strncmp(line, "#else", 5) == 0)
-	accept = !accept;
-else if(strncmp(line, "#endif", 6) == 0)
-	accept = TRUE;
-else
-	accept = TRUE;  // should not occur
-return get_next_help_line(in, line, lline);
-}
-*/
 
 char *get_next_help_line(void *in, char *line, int lline)
 {
@@ -2664,7 +2939,7 @@
 static const char match[] = "unix";
 #endif
 static int accept = TRUE;
-static int in_if = FALSE;
+static int found = FALSE;
 if( read_next_help_line(line, lline, in) == NULL) { accept = TRUE; return NULL; }
 while(*line != '#') {
 	if(accept) return line;
@@ -2672,23 +2947,22 @@
 	}
 if(strncmp(line, "#ifdef", 6) == 0 || strncmp(line, "#if ", 4) == 0) {
 	accept =  ( strstr(line, match) != NULL ) ;
-	in_if = TRUE;
+	found = accept;
 	}
-/*
-else if(strncmp(line, "#ifndef", 7) == 0)
-	accept = !win32;
-*/
 else if(strncmp(line, "#elif", 5) == 0) {
-	accept =  ( strstr(line, match) != NULL ) ;
-	if(in_if && !accept) in_if = FALSE;
-	else in_if = TRUE;
+	if(found) accept = FALSE;
+	else if( strstr(line, match) != NULL ) {
+		accept = TRUE; found = TRUE;
+		}
 	}
 else if(strncmp(line, "#else", 5) == 0) {
-	if(in_if) accept = !accept;
+	if(found) accept = FALSE;
+	else {
+		accept = TRUE; found = TRUE;
+		}
 	}
 else if(strncmp(line, "#endif", 6) == 0) {
 	accept = TRUE;
-	in_if = FALSE;
 	}
 else
 	accept = TRUE;  // should not occur
@@ -2715,7 +2989,7 @@
 if(reponse == 0) return;
 br_data = (browser_struct *)data;
 p = ((Fl_Browser*)ob)->text(reponse);
-#ifdef __APPLE__
+#if defined(__APPLE__) && !TARGET_RT_MAC_MACHO
 get_next_help_line(br_data->in, NULL, 0);
 #else
 rewind((FILE *)br_data->in);
@@ -2781,7 +3055,7 @@
 if(on) { /* tenter de passer en mode par reference */
 	if(view ->inverted_colors || view->tot_sel_seqs != 1 || 
 			view->numb_gc == 1) {
-		menu_props->mode(props_parts->reference, FL_MENU_TOGGLE);
+		((Fl_Menu_Item *)menu_props->menu() + props_parts->reference)->clear();
 		return;
 		}
 	my_watch_cursor(view->dnawin);
@@ -2799,17 +3073,15 @@
 	fl_reset_cursor(view->dnawin);
 	if(view->alt_col_seq == NULL) {
 		view->DNA_obj->redraw();
-		menu_props->mode(props_parts->reference, FL_MENU_TOGGLE);
+		((Fl_Menu_Item *)menu_props->menu() + props_parts->reference)->clear();
 		return;
 		}
 	tmp = view->alt_col_seq;
 	view->alt_col_seq = view->col_seq;
 	view->col_seq = tmp;		
 	view->DNA_obj->redraw();
-	menu_props->mode(props_parts->colors - 1, 
-		FL_SUBMENU | FL_MENU_INACTIVE);
-	menu_props->mode(props_parts->reference, 
-		FL_MENU_TOGGLE | FL_MENU_VALUE);
+	((Fl_Menu_Item *)menu_props->menu() + props_parts->colors - 1)->deactivate();
+	((Fl_Menu_Item *)menu_props->menu() + props_parts->reference)->set();
 	view->menu_edit->labelcolor(FL_INACTIVE_COLOR);
 	view->menu_edit->deactivate();
 	view->menu_species->labelcolor(FL_INACTIVE_COLOR);
@@ -2825,8 +3097,8 @@
 	view->alt_col_seq = NULL;
 	deplacer_grp_seqs(view, old_pos + 1);
 	view->DNA_obj->redraw();
-	menu_props->mode(props_parts->colors - 1, FL_SUBMENU);
-	menu_props->mode(props_parts->reference, FL_MENU_TOGGLE);
+	((Fl_Menu_Item *)menu_props->menu() + props_parts->colors - 1)->activate();
+	((Fl_Menu_Item *)menu_props->menu() + props_parts->reference)->clear();
 	view->menu_edit->labelcolor(FL_BLACK);
 	view->menu_edit->activate();
 	view->menu_species->labelcolor(FL_BLACK);
@@ -2848,17 +3120,21 @@
 	Fl_Button *ok_button;
 	Fl_Widget *br_item_label;
 	int titres_width, fin_titres;
-#ifdef __APPLE__
+#if defined(__APPLE__) 
+#if ! TARGET_RT_MAC_MACHO
 	get_next_help_line(data, NULL, 0);
 #else
 	data = (void *)fopen( (char *)data, "r" );
 #endif
+#else
+	data = (void *)open_path( (char *)data );
+#endif
 	if(data == NULL) {
 		fl_alert(
 #ifdef __APPLE__
 	"No help information in program resources"
 #else
-	"Help file %s\nnot found", (char *)data
+	"Help file %s\nnot found in PATH directories nor in current directory", (char *)data
 #endif
 			);
 		return;
@@ -2869,9 +3145,8 @@
 	help_form->box(FL_FLAT_BOX);
 	fl_font(FL_HELVETICA, 12);
 	titres_width = (int)fl_width("XXXXXX"); /* mieux ensuite */
-	browser_titres = new Fl_Browser(5, 20, titres_width, 
+	browser_titres = new Fl_Hold_Browser(5, 20, titres_width, 
 		help_form->h() - 50, "Choose help item");
-	browser_titres->type(FL_HOLD_BROWSER);
 	browser_titres->textsize(12);
 	browser_titres->has_scrollbar(Fl_Browser_::VERTICAL);
 	browser_titres->callback(browser_titres_callback, &browser_data);
@@ -2890,7 +3165,6 @@
 	fin_titres = titres_width + 10;
 	browser_item = new Fl_Browser(fin_titres, 20, 
 		700 - fin_titres, help_form->h() - 25, "");
-	browser_item->type(FL_NORMAL_BROWSER);
 	browser_item->has_scrollbar(Fl_Browser_::VERTICAL);
 	browser_item->align(FL_ALIGN_TOP);
 	browser_item->color(FL_LIGHT1, browser_item->selection_color());
@@ -2987,22 +3261,32 @@
 	if(view->tot_sel_seqs != 0) {
 		items[DELETE_SEQ].activate();
 		items[CONSENSUS_SEQ].activate();
-		if(!view->protein) items[EXCHANGE_UT].activate();
+		if(view->protein) items[EXCHANGE_UT].deactivate();
+		else items[EXCHANGE_UT].activate();
 		}
 	else	{
 		items[DELETE_SEQ].deactivate();
 		items[EXCHANGE_UT].deactivate();
 		}
+Fl_Menu_Button *menu_props = (Fl_Menu_Button *)view->bouton_props;
+props_menu_parts *props_parts = (props_menu_parts *)menu_props->user_data();
+	Fl_Menu_Item *byref = (Fl_Menu_Item *)menu_props->menu() + props_parts->reference;
 	if(view->tot_sel_seqs == 1) {
+		if(!view->inverted_colors) byref->activate();
 		items[RENAME_SEQ].activate();
 		items[DUPLICATE_SEQ].activate();
 		items[EDIT_COMMENTS].activate();
-		if(!view->protein) {
+		if(view->protein) {
+			items[COMPLEMENT_SEQ].deactivate();
+			items[REVERSE_SEQ].deactivate();
+			}
+		else {
 			items[COMPLEMENT_SEQ].activate();
 			items[REVERSE_SEQ].activate();
 			}
 		}
 	else	{
+		byref->deactivate();
 		items[RENAME_SEQ].deactivate();
 		items[DUPLICATE_SEQ].deactivate();
 		items[EDIT_COMMENTS].deactivate();
@@ -3108,10 +3392,12 @@
 for(old = 0; old < view->tot_seqs; old++)
 	aux[new_rank[old]] = view->seqname[old];
 memcpy(view->seqname, aux, view->tot_seqs * sizeof(char *) );
-/* deplacer les commentaires */
-for(old = 0; old < view->tot_seqs; old++)
-	aux[new_rank[old]] = view->comments[old];
-memcpy(view->comments, aux, view->tot_seqs * sizeof(char *) );
+if(view->comments != NULL) {
+	/* deplacer les commentaires */
+	for(old = 0; old < view->tot_seqs; old++)
+		aux[new_rank[old]] = view->comments[old];
+	memcpy(view->comments, aux, view->tot_seqs * sizeof(char *) );
+	}
 /* deplacer les seqs en couleurs */
 if(view->numb_gc > 1) {
 	for(old = 0; old < view->tot_seqs; old++)
@@ -3250,6 +3536,14 @@
 	view->mod_comment_line = FALSE;
 	}
 else	{
+#ifdef __APPLE__
+	if(view->tot_seqs == 0) {
+#define DRAG_MESS "alignment file drag zone"
+		fl_color(FL_WHITE);
+		fl_font(FL_TIMES_BOLD_ITALIC, 28 );
+		fl_draw(DRAG_MESS, this->x()+this->w()/2-fl_width(DRAG_MESS)/2, this->y()+this->h()/2);
+		}
+#endif
 	if(view->inverted_colors)
 		    draw_dna_seqs_inverted(view->DNA_obj, view);
 	else
@@ -3272,11 +3566,7 @@
 
 key = Fl::event_button();  /* key: 1=gauche, 2=centre, 3=droit souris */
 if(emul_3_buttons) {
-#ifdef __APPLE__
-	if(Fl::event_state(FL_META)) key = 2;// bouton du milieu sur Mac controlKey ==> FL_META
-#else
 	if(Fl::event_state(FL_CTRL)) key = 2;// bouton du milieu par Ctrl-Click
-#endif
 	else if(Fl::event_state(FL_SHIFT)) key = 3;// bouton  droit par Shift-Click
 	}
 return key;
@@ -3299,8 +3589,30 @@
 if(view == NULL) return 1;
     switch (event)
     {
+#if defined(__APPLE__) || defined(WIN32)
+// D&D doesn't seem to work under X11, and OK with Win98 but incomplete with WinXP
+    case FL_DND_ENTER:
+   	 	return 1;
+    case FL_DND_DRAG:
+   	 	return 1; 
+    case FL_DND_RELEASE:
+ 		{ Fl_Widget *o = this; while(o->parent()->parent() != NULL) o = o->parent();   
+   	 	Fl::focus(o); } //fltk bug: focus must be to direct child of Fl_Window for D&D 
+   	 	return 1;
+    case FL_PASTE:
+   	 	use_initial_file(view, 
+#if defined(__APPLE__) && !TARGET_RT_MAC_MACHO
+   		 OSXpathtoOS9path( Fl::event_text() )
+#else
+   		 (char *)Fl::event_text() 
+#endif
+    );
+   		Fl::focus(this);
+   		return 1;
+#endif
     case FL_FOCUS: 
-	return 1;
+    case FL_UNFOCUS: 
+		return 1;
     case FL_PUSH: 
 	int key;
 	key = my_event_button();
@@ -3333,7 +3645,7 @@
 		&modifying_segment);
 	break;
      case FL_RELEASE:
-     case FL_LEAVE:
+//     case FL_LEAVE:
 	if(selecting_seqs) {
 		if(sel_seq_move) {
 			select_deselect_seq(view, sel_seq_move);
@@ -3352,16 +3664,21 @@
 		}
 	break;
      case FL_KEYBOARD:
-	if( Fl::event_state(FL_CTRL) ) { /* vrai si touche ctrl */
+	if( Fl::event_state(myFL_CTRL) ) { /* vrai si touche ctrl */
 		return 0; /* ne pas traiter ici car shortcut d'autres widgets */
 		}
-	if(Fl::event_length() > 0) { /* du vrai texte */
+  	if(Fl::event_length() > 0) { /* du vrai texte */
 		handle_keyboard(view, Fl::event_text()[0], TRUE );
 		}
 	else	{ /* une touche genre fleche ou fonction */
 		handle_keyboard(view, Fl::event_key(), FALSE );
 		}
 	break;
+#ifdef __APPLE__
+	 case FL_HIDE:
+	 Fl::e_state = 0; //bug qui conserve cmd modifier apres cmd-H
+	 return 0;
+#endif
     default :
 	return 0;
     }
@@ -3875,6 +4192,11 @@
   user_data_plus *data;
 dna_group = new Fl_Group(x,y,w,h);
 int scroll_w = 15;
+#ifdef __APPLE__
+#define DELTA_G  13 // laisser place pour poignŽe de dimensionnement de fenetre
+#else
+#define DELTA_G  0
+#endif
 /* screen move haut */
 view->up_screen_move = obj = 
 (Fl_Widget*)new Fl_Repeat_Button(x+3, y,scroll_w,scroll_w,"@8>>");
@@ -3931,7 +4253,7 @@
 obj->callback(lrdu_button_callback, data);
 /* ascens. horizontal */ 
 view->horsli =  
-new Fl_Scrollbar(x + x_pos, y_scroll, w - x_pos - scroll_w - 2, scroll_w,"");
+new Fl_Scrollbar(x + x_pos, y_scroll, w - x_pos - scroll_w - 2 - DELTA_G, scroll_w,"");
 view->horsli->type(FL_HORIZONTAL);
 view->horsli->box(FL_DOWN_BOX);
 ((Fl_Scrollbar *)view->horsli)->linesize(1);
@@ -3946,7 +4268,7 @@
 view->horsli->when(FL_WHEN_CHANGED);
 /* screen move a droite */
   view->right_screen_move = obj = 
-(Fl_Widget*)new Fl_Repeat_Button(x+w - scroll_w, y_scroll, scroll_w, scroll_w,"@>>");
+(Fl_Widget*)new Fl_Repeat_Button(x+w - scroll_w - DELTA_G, y_scroll, scroll_w, scroll_w,"@>>");
 obj->labeltype(FL_SYMBOL_LABEL);
 data = new user_data_plus;
 data->p = view;
@@ -3969,7 +4291,7 @@
 
 dna_group->end();
 dna_group->add_resizable(
-	*new Fl_Box(x + x_pos, y + scroll_w + 2, w - x_pos - scroll_w - 2, 
+	*new Fl_Box(x + x_pos, y + scroll_w + 2, w - x_pos - scroll_w - 2 - DELTA_G, 
 		h - 3*scroll_w - 12) );
 view->menu_regions = view->menu_file = view->menu_edit = 
 		view->bouton_props = view->menu_species = NULL;
@@ -3983,7 +4305,9 @@
 		int numb_stdprotcolors, int *stdprotcolors,
 		int numb_altprotcolors, int *altprotcolors,
 		color_choice curr_color_choice, char *progname, char *movekeys,
-		char *win_size, int allow_lower, char *help_file)
+		char *win_size, int allow_lower, char *help_file,
+		int back_color, int region_back_color, int defaultfontsize,
+		int alignment_algo)
 {
 Fl_Group *dna_group;
 Fl_Window *my_form;
@@ -4011,24 +4335,33 @@
 #define add_button(nom) \
 	new Fl_Button(0,0,calc_width(nom),25,nom)
 
-Fl_Pack *menus = new Fl_Pack(5,5,0,25); /* groupe fixe des menus */
+Fl_Pack *menus = new Fl_Pack(5,5,10,25); /* groupe fixe des menus */
 menus->type(FL_HORIZONTAL);
 menus->spacing(2);
 
 /* menu File */
 menu_file = add_menu("File");
 ((Fl_Menu_Button*)menu_file)->add(
-	"Open Mase|Open Phylip|Open Clustal|Open MSF|Open Fasta|Open NEXUS|"
-	"Save|Save as...|Save current sites|Prepare printout|"
+	"Open|Open Mase|Open Phylip|Open Clustal|Open MSF|Open Fasta|Open NEXUS|"
+	"Save|Save as...|Save current sites|Prepare "PDF_OR_PS"|"
+#if ! defined( __APPLE__) 
+	PDF_OR_PS" options...|"
+#endif
 	"Quit");
 menu_file->labelsize(labelSize);
+menu_file->mode(OPEN_ANY, FL_MENU_DIVIDER);
+menu_file->shortcut(OPEN_ANY, myFL_CTRL | 'o');
 menu_file->mode(OPEN_NEXUS, FL_MENU_DIVIDER);
 menu_file->mode(SAVE, FL_MENU_INACTIVE);
-menu_file->shortcut(SAVE, FL_CTRL | 's');
+menu_file->shortcut(SAVE, myFL_CTRL | 's');
 menu_file->mode(SAVE_AS, FL_MENU_INACTIVE);
 menu_file->mode(SAVE_REGIONS, FL_MENU_DIVIDER | FL_MENU_INACTIVE);
+#if defined( __APPLE__) 
 menu_file->mode(PRINTOUT, FL_MENU_DIVIDER);
-menu_file->shortcut(QUIT, FL_CTRL | 'q');
+#else
+menu_file->mode(PDFOPTIONS, FL_MENU_DIVIDER);
+#endif
+menu_file->shortcut(QUIT, myFL_CTRL | 'q');
 menu_file->callback(file_menu_callback, 0);
 menu_file->align((Fl_Align) (FL_ALIGN_INSIDE | FL_ALIGN_LEFT) );
 menu_file->box(FL_UP_BOX);
@@ -4109,6 +4442,7 @@
 bouton_help = add_button("Help");
 bouton_help->labelsize(labelSize);
 bouton_help->callback(help_callback, help_file);
+
 #undef add_menu
 #undef add_button
 #undef calc_width
@@ -4156,6 +4490,8 @@
 view->mod_seq = 0;
 view->mod_comment_line = 0;
 view->consensus_threshold = 60;
+view->consensus_allowgaps = FALSE;
+view->alignment_algorithm = alignment_algo;
 view->dnawin = my_form;
 view->max_seq_length = MINI_MAX_LENGTH;
 mod_multipl(view, 0);
@@ -4169,11 +4505,7 @@
 #endif
 if ( ! black_and_white) { 
 	/* couleurs du fond pour seqs */
-#ifdef WIN32
-  	view->DNA_obj->color(FL_DARK1, 43); 
-#else
-  	view->DNA_obj->color(FL_GRAY, FL_DARK1); 
-#endif
+  	view->DNA_obj->color(back_color, region_back_color); 
 	view->region_color = FL_WHITE;
 	view->inverted_colors = inverted;
 	if(inverted) {
@@ -4194,11 +4526,7 @@
 	}
 view->DNA_obj->parent()->color( view->DNA_obj->color() );
 /* taille par defaut des lettres des sequences */
-#ifdef WIN32
-view->DNA_obj->labelsize(12);
-#else
-view->DNA_obj->labelsize(14);
-#endif
+view->DNA_obj->labelsize(defaultfontsize);
 /* creation du menu Props et de ses sous-menus */
 create_props_menu((Fl_Menu_Button *)bouton_props, view,
 	curr_color_choice, inverted, black_and_white, 
@@ -4216,3 +4544,6 @@
 view->tot_comment_lines = 0;
 return view;
 }
+
+
+

Modified: trunk/packages/seaview/trunk/seaview.h
===================================================================
--- trunk/packages/seaview/trunk/seaview.h	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/seaview.h	2006-09-22 05:38:11 UTC (rev 121)
@@ -21,20 +21,31 @@
 #define TRUE (!FALSE)
 #endif
 
+#ifdef NO_PDF
+#define PDF_OR_PS "ps"
+#else
+#define PDF_OR_PS "pdf"
+#endif
 
+#define fgets(a,b,c) my_fgets(a,b,c)
+extern "C" { char *my_fgets(char *s, int n, FILE *f); }
+
 #ifdef WIN32
 extern "C" { void my_bell(void); }
 #define fl_ringbell(a) my_bell()
 #elif defined __APPLE__
 #define fl_ringbell(a) SysBeep(a)
-#define fgets(a,b,c) my_fgets(a,b,c)
-extern "C" { char *my_fgets(char *s, int n, FILE *f); }
 #else
 #include "FL/x.H"
 #define fl_ringbell(a) XBell(fl_display, a)
 #endif
 #define FL_max(a,b)      ( (a) > (b) ? (a):(b) )
 #define FL_min(a,b)      ( (a) < (b) ? (a):(b) )
+#ifdef __APPLE__
+#define PREPARE_LABEL(p) mac_fname_to_roman(p)
+#else
+#define PREPARE_LABEL(p) p
+#endif
 /* proto manque parfois */
 extern "C" { void *memccpy(void *s1, const void *s2, int c, size_t n); }
 typedef struct _user_data_plus {
@@ -51,6 +62,7 @@
 #define MSF_WID_NAME 15
 #define CLU_BLOCK_LEN 5000 /* block pour allocation mem format Clustal */
 #define MAX_GAP_SITES 1000
+#define MOVEKEYS_DEFAULT "][><"
 
 typedef struct _list_segments { /* one segment + pointer to its successor */
 	int debut, fin;
@@ -77,8 +89,11 @@
 	FASTA_FORMAT, NEXUS_FORMAT } 
 	known_format;
 
-typedef enum {OPEN_MASE, OPEN_PHYLIP, OPEN_CLUSTAL, OPEN_MSF, OPEN_FASTA,
-	OPEN_NEXUS, SAVE, SAVE_AS, SAVE_REGIONS, PRINTOUT,
+typedef enum {OPEN_ANY, OPEN_MASE, OPEN_PHYLIP, OPEN_CLUSTAL, OPEN_MSF, OPEN_FASTA,
+	OPEN_NEXUS, SAVE, SAVE_AS, SAVE_REGIONS, PRINTOUT, 
+#ifndef __APPLE__
+	PDFOPTIONS,
+#endif
 	QUIT} file_menu_choice;
 
 typedef enum {NO_ALT_COLORS, USING_STANDARD_COLORS, USING_ALT_COLORS}
@@ -92,7 +107,16 @@
 
 typedef enum {SHOW_HIDE_FOOTERS, CREATE_FOOTER, DELETE_FOOTER }
 	footers_menu_choice;
+	
+typedef enum {A4, LETTER} paperformat;
 
+enum { CLUSTALW, MUSCLE };
+#ifdef NO_CLUSTALW
+#define DEFAULT_ALIGN_ALGO MUSCLE
+#else
+#define DEFAULT_ALIGN_ALGO CLUSTALW
+#endif
+
 typedef struct {
 	Fl_Widget *DNA_obj; /* free object for names + seqs */
 	Fl_Scrollbar *horsli; /* horizontal scrollbar */
@@ -164,8 +188,10 @@
 	Fl_Window *dnawin; /* window of DNA_obj */
 	int reducefonts; /* TRUE when need smaller fonts (e.g. 100dpi) */
 	int double_buffer; /* true iff DNA_obj is double buffered */
+	int alignment_algorithm;
 	char *clustal_options; /* options for clustalw if != NULL */
 	int consensus_threshold; /* min threshold (%) for residue in consensus*/
+	int consensus_allowgaps; /* TRUE iff gaps count as residue for consensus*/
 	int tot_comment_lines; /* number of comment lines */
 	char **comment_line; /* array of comment lines */
 	char **comment_name; /* array of comment names */
@@ -183,7 +209,7 @@
 
 typedef struct _props_menu_parts {
 	int fontsize, saveformat, colors, inverted, edit, reference, keys,
-		clustalopt, consensusopt, slow_fast, allow_lower;
+		clustalopt, consensusopt, slow_fast, allow_lower, custom;
 	SEA_VIEW *view;
 	} props_menu_parts;
 
@@ -225,7 +251,7 @@
 	list_regions **charsets, int *pnum_species_sets,
 	int ***list_species_sets, char ***name_species_sets,
 	int *ptot_comment_lines, char ***comment_name, char ***comment_line,
-	int **comment_length);
+	int **comment_length, int *protein);
 extern char *save_alignment_or_region(const char *fname, char **seq, 
 	char **comments,
 	char *header, char **seqname, int totseqs, int *eachlength,
@@ -234,7 +260,7 @@
 	char **name_species_sets, int *sel_seqs, int tot_sel_seqs, int protein,
 	int tot_comment_lines, char **comment_name, char **comment_line);
 extern void load_alignment_file(SEA_VIEW *view, char *filename, 
-	char *message, char *pattern, known_format file_format);
+	char *message, known_format file_format);
 extern int is_a_protein_seq(char *seq);
 extern int prepare_printout(const char *filename, char **seq, int totseqs,  
 	char **seqname,
@@ -255,7 +281,7 @@
 extern char complement_base(char old);
 extern void select_deselect_seq(SEA_VIEW *view, int new_seq);
 extern void save_active_region(SEA_VIEW *view, int ask_confirm);
-extern void align_selected_parts(SEA_VIEW *view);
+extern void align_selected_parts(SEA_VIEW *view, int align_algorithm);
 extern void free_region(region *reg);
 extern void my_watch_cursor(Fl_Window *win);
 extern void update_current_seq_length(int newlength, SEA_VIEW *view);
@@ -269,4 +295,8 @@
 extern int insert_gap_all_comments(int numgaps, int pos,  SEA_VIEW *view);
 extern int delete_in_all_comments(int numdels, int pos,  SEA_VIEW *view);
 extern char* fl_file_chooser(const char* message, const char* pat, const char* fname);
+#ifdef __APPLE__
+extern char *mac_fname_to_roman(char *in); 
 #endif
+
+#endif

Modified: trunk/packages/seaview/trunk/seaview.help
===================================================================
--- trunk/packages/seaview/trunk/seaview.help	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/seaview.help	2006-09-22 05:38:11 UTC (rev 121)
@@ -4,10 +4,20 @@
 tools for sequence alignment and molecular phylogeny. Comput. Appl. Biosci., 
 12:543-548.
 
-Seaview is available by anonymous FTP at pbil.univ-lyon1.fr in directory
-/pub/mol_phylogeny/seaview for several unix platforms and for Windows95/98.
+Binaries and full source code available from
+http://pbil.univ-lyon1.fr/software/seaview.html
 
-Seaview uses the FLTK library by Bill Spitzak and others.
+(C) 1996-2005 Manolo Gouy
+Laboratoire de Biometrie et Biologie Evolutive
+CNRS / Universite Lyon I
+Licensed under the GNU General Public Licence
+(http://www.gnu.org/licenses/gpl.txt)
+
+Seaview uses the FLTK project (http://www.fltk.org) for its user interface.
+
+Seaview uses the PDFlib Lite library (http://www.pdflib.com) for pdf output
+under the "Open Source Developer Exemption" of the PDFlib Lite License Agreement.
+
 >>>Alignment panel
 Mouse Use:
 
@@ -17,7 +27,7 @@
   in black background). Alignment operations (gap insertions/deletions) will 
   operate on all grouped sequences simultaneously.
 o Double-click on any name to group all sequences.
-#ifdef WIN32
+#if WIN32 || __APPLE__
 o Ctrl-Click somewhere in sequence names to move grouped sequences to another 
   place in alignment.
 o Shift-Click to deactivate the current grouping; names return in normal print.
@@ -43,14 +53,14 @@
 o 1234567890 (digit keys) allow to compose a number (appearing under
   mult=number at bottom left of panel) used as a multiplier to an operation
   to follow (e.g., keys 4, 5, and - in sequence will insert 45 gaps)
-o Alt+S (both keys together) save the alignment in the current filename using
-  the current file saving format displayed by menu "Props". If format of 
-  the last loaded file does not match the current saving format, this key
-  is not active.
+o ctrl/cmd+S (according to platform) saves the alignment in the current 
+  filename using the current file saving format displayed by menu "Props". 
+  If format of the last loaded file does not match the current saving format, 
+  this key is not active.
 
 Mouse use on the site line (when there is one, white line at bottom):
 
-#ifdef WIN32
+#if WIN32 || __APPLE__
 o  Click mouse to select/unselect a site.
 o  Drag with the mouse button an extremity of a block of sites to extend or 
    reduce it.
@@ -71,9 +81,9 @@
                really useful!). They can also store site sets [see
                item `Sites menu'].
 
-<Ctrl>S Save    when active, saves the alignment in the current file (which
-               name appears as window title), and indicates that keys
-               <Ctrl> + S pressed together will perform this operation.
+Save           when active, saves the alignment in the current file (which
+               name appears as window title). The shortcut for this operation
+               is given.
 
 Save as...     allows to save the alignment under a filename to be chosen
                in the file selector appearing next [Pressing button Rescan
@@ -84,18 +94,20 @@
                in a file only those sites of the sequences where an X is in the
                site line. If some sequences are selected, only these are saved.
 
-Prepare printout
-               Prepares a file adequate for alignment printout on a printer. The
-               file selector appearing next allows to specify 3 parameters:
+#if __APPLE__
+Prepare pdf    Writes the alignment as a pdf file, with optional choices:
+#else
+Prepare pdf    Writes the alignment as a pdf file. See options below.
+pdf options... allows to set several options for "Prepare pdf" menu item
+#endif
+        fontsize       sets the fontsize (font is Courier)
         block size     alignment lines may be divided in blocks (e.g. of size 10
                        for DNA/RNA sequences or 3 for protein coding sequences)
-                       to ease alignment reading.
-        chars/line     the max number of characters that fit on a printer line
-                       (not the desired number of residues per line, which is
-                       set to the largest fitting value by the program).
-        lines/page     the number of lines that fit on a printer page (in order
-                       that blocks of alignment lines are not divided by page
-                       borders).
+                       separated by one space to ease alignment reading.
+        paper size:    two paper formats can be used A4 or LETTER
+        color/B&W      choose between colored alignment or one with all black letters.
+        variable sites only    Available only in reference mode, allows to output
+                       only variable sites of the alignment and their positions.
 
 Quit           guess what?
 >>>Props menu
@@ -125,10 +137,11 @@
 
 by Reference To display the alignment by reference to a particular sequence:
              residues identical to that of the ref. seq. are displayed as dots.
-             Possible only when one sequence, the reference, is selected.
+             Possible only when one sequence, the reference, is selected and
+             if not in inverted color mode.
              Alignment edition is impossible while in the reference mode.
-             When used, File:Prepare printout produces a printout by reference.
-             Combination <Ctrl>+R is a shortcut for calling/exiting this mode.
+             When used, File:Prepare pdf produces an output by reference.
+             Combination ctrl/cmd+R is a shortcut for calling/exiting this mode.
 
 DNA keys     Allows to use keys "hjkl" to enter DNA sequences
              "Allow seq. edition" should be ON for this item to be usable.
@@ -136,9 +149,10 @@
         >    hjkl => GATC, hjkl => TCGA, hjkl => ACGT
              Also, the space bar will be mapped to base N.
 
-Clustalw options
-             Allows to specify options sent to the clustalw alignment program
-             in order to set, e.g., specific alignement parameter values.
+Alignment options
+             Allows to choose the desired alignment program and to specify 
+             options sent to this alignment program in order to use, e.g., 
+             specific alignment parameter values.
              Go to submenu "Edit options" and type desired options in the
              dialog window that appears. 
 #ifdef WIN32
@@ -147,7 +161,7 @@
              An example is to type -gapopen=5 
 #endif
              When an option has been typed it is active unless you switch it off
-             by calling again "Clustalw options" and sliding to the check box.
+             by calling again "Alignment options" and sliding to the check box.
              Thus a set of options can be memorized and turned on and off.
 
 Consensus option
@@ -161,6 +175,13 @@
              If set, lowercase residues will be apparent. If not set, lowercase
              residues in sequence files display as uppercase.
 
+Customize    To change, possibly permanently, various display settings. See 
+             "Miscellaneous options" and "Sequence coloring" help items.
+             Apply: applies changes in current program session.
+             Set changes permanent: applies changes in current and future
+             program sessions.
+             Close: ignores changes.
+
 >>>Sites menu
 Site sets allow to specify parts of a multiple alignment to be retained for
 further analyses (typically, those parts of the alignment taken as 
@@ -275,18 +296,18 @@
 Exchange Us and Ts       Exchange bases Us and Ts in all currently selected 
                          sequences.
 
-Align sites              Runs the clustalw alignment program on the block of 
+Align sites              Runs the selected alignment program on the block of 
                          selected sites and the set of selected sequences.
                          A window will ask for choosing the reference sequence:
-                         gaps present before clustalw alignment in the chosen 
+                         gaps present before alignment in the chosen 
                          sequence will be preserved in the new alignment.
 #ifdef WIN32
-                         Program clustalw will be searched in the directory
+                         Chosen alignment program will be searched in the directory
                          of the seaview program, the current directory and
                          in directories of your PATH variable.
 #else
                          Your PATH should contain the directories of
-                         programs clustalw, xterm and seaview_align.sh.
+                         programs clustalw/muscle, xterm and seaview_align.sh.
 #endif
 
 Dot plot                 Performs a "dot plot" analysis of the two selected 
@@ -352,10 +373,8 @@
 ;; 2, 3, 4, 5
 where "distant outgroup" is the name of the species group and where the series
 of numbers lists the ranks of sequences members of the species group.
->>>Program arguments
-#ifdef WIN32
-Arguments can be used to associate files with the seaview program. 
-#endif
+#if WIN32 || unix
+>>>Program arguments 
 Program is run by command
 seaview [options] [filename]
 
@@ -368,154 +387,71 @@
          [sequences will be displayed faster but less smoothly]
 -inverted
          [residues will appear as black letters on a colored background]
+-fontsize n
+         [sets to integer n the initial fontsize of the alignment panel]
 
 and filename 
 is an optional alignment file to be loaded. The expected format for this file
 is that of the default format for saving operations.
 
-See `Program customization' topic to know how to further customize the program.
->>>Program customization
-#ifdef WIN32
-Seaview can be customized through several options to be put in a text file
-called "seaview.ini" located in the same directory as program seaview itself.
-Next help items describe all these options.
-Each option is specified by a line in this file of the form
-<option-name> = <option-value>
+Use `Props:Customize' menu item to further customize the program.
+#endif
 
-Examples:
-stdcolorgroups  =  AC,DEFGHIK,LMNPQRS,WY,TV
-save            =  clustal
-printoutcpl     =  90
-inverted        =  True
-#else
-Seaview can be customized by several options specified as program resources.
-Next help items describe all these options.
-Each resource is specified by a line of the form
-Seaview.<resource-name>:	<resource-value>
+>>>Sequence coloring
+The "Props:Customize" menu item allows to control colors.
 
-Examples:
-Seaview.dnacolors:		blue,yellow,green,255 0 0
-Seaview.altcolorgroups:		AC,DEFGHIK,LMNPQRS,WY,TV
-Seaview.save:			clustal
-Seaview.printoutcpl:		90
-Seaview.inverted:		True
+                 SETTING DNA/RNA SEQUENCE COLORING
+A,C,G,T/U buttons are colored using current color of the corresponding nucleotide.
+Click on a button to open a color chooser and select the desired color 
+    (OK will accept the new choice; reset will use the starting shade).
+"reset" will use default colors.
+"Apply" or "Set changes permanent" will apply new shades to current alignment.
 
-Resource lines are added by any of 4 means:
-1) in a file called Seaview in directory /usr/lib/X11/app-defaults
-2) in a file called Seaview in any directory pointed to by environment variable
-XAPPLRESDIR
-3) in your $HOME/.Xdefaults file 
-(note that this is effective only if this file is read by your login procedure)
-4) interactively loaded by command
-xrdb -merge fname
-where "fname" is a file containing resource lines
-and checked by command
-xrdb -query
-#endif
->>>Miscellaneous options
-See 'Program customization' topic for how to set these options.
 
-                       MISCELLANEOUS OPTIONS
+                 SETTING PROTEIN SEQUENCE COLORING
+aa coloring scheme: by default, amino acids are split in 8 families each displayed 
+in a different color. These families can be customized, up to a maximum of 10.
+Also, an alternative coloring scheme can be defined, and seaview will
+allow to switch between the first and the alternative coloring schemes.
 
-Purpose        (note)| Name      | Default value | Example of possible value
----------------------|-----------|---------------|-----------------------------
-saving format     (1)| save      | mase          | clustal
-#ifdef WIN32
-name of help file (2)| helpfile  | seaview.hlp   | seaview.aide
-#else
-name of help file (2)| helpfile  | seaview.help  | seaview.aide
-#endif
-fast, rough display  | fast      | false         | true
-colored background   | inverted  | false         | True
-keys to move view    | movekeys  | ][><          | }{.,
-allow lowercase      | lowercase | false         | TRUE
-#ifdef WIN32
-window size          | window    | 900x550       | 800x400
-#else
-window size          | window    | 1000x700      | 800x400
-emul. 3-button mouse |emulate_3_b| false         | True
-                  (3)|           |               |
-#endif
+catalog of amino acid colors: colors used for each amino acid family. 
+Click on any to control the desired shade, as explained above.
+White is used for gaps and for unlisted residues.
 
-Notes: 
-1) Possible file formats are mase, clustal, phylip, msf, fasta, nexus.
-#ifdef WIN32
-2) The help file is sought in the directory containing program seaview.
-#else
-2) The help file is sought in all directories listed in the PATH variable
-and in the current directory.
-3) if yes, use CTRL-click for middle button & SHIFT-click for right button
-#endif
+Example: with the default coloring scheme, groups of amino acids KR and AFILMVW 
+are displayed with the first and second catalog colors, respectively.
 
->>>Coloring schemes
-See 'Program customization' topic for how to set these options.
+Click "reset" to use default amino acid families and color catalog.
+"Apply" or "Set changes permanent" to apply new shades to current alignment.
 
-     SETTING GROUPS OF AMINO ACIDS DISPLAYED WITH THE SAME COLOR
+>>>Miscellaneous options
 
-By default, amino acids are split in 5 families each displayed in a different
-color. These families can be customized, up to a maximum of 10 families.
-Also, an alternative coloring scheme can be defined, and seaview will
-allow to switch between the first and the alternative coloring schemes.
+                       MISCELLANEOUS OPTIONS
 
-Purpose             | Name           | Default value   | Example of value
---------------------|----------------|-----------------|-----------------
-standard coloring   | stdcolorgroups | EDQNHRKBZ,ILMV, | DEBZ,ACWY,FGH
-scheme of aminoacids|                |    APSGT,FY,WC  |   IK,LMNPQRSTV
-                    |                |                 |
-alternate coloring  | altcolorgroups | <none>          | ILMV,ACGPST,DEN
-scheme of aminoacids|                |                 |   QBZ,HKR,FWY
+The "Props:Customize" menu item allows to set these options.
+                      
+[sites] background grey: move the slider to change the grey shade of the alignment
+panel background; the "sites" shade applies to selected sites only; "reset" gives
+default values to both shades.
 
-Note: Default colors are red, green, yellow, blue, cyan, magenta, salmon, 
-purple, aquamarine, and dark-gray. These can be changed (see 'Defining colors').
-White is used for gaps and for unlisted residues.
-The above 2 options allow to set which aminoacids will be painted in what
-of the above colors. The format for these is, e.g.,
-EDQNHRKBZ,ILMV,APSGT,FY,WC
-to specify
-aminoacids | EDQNHRKBZ | ILMV  |  APSGT |  FY  |   WC   | others + gaps |
-color      |    red    | green | yellow | blue |  cyan  |   white       |
-The number of listed groups of aminoacids determines the number of colors used.
->>>Defining colors
-See 'Program customization' topic for how to set these options.
+left-right movement keys: define 4 keys that move cursor right and left 
+by 5 or 50 residues; reset uses default keys.
 
-                 CHANGING COLORS USED TO DISPLAY SEQUENCES
+pdf page format: sets the page format used by the "File:Prepare pdf" menu item.
 
-Purpose         | Name       | Default value              | Example of value
-----------------|------------|----------------------------|---------------------
-#ifdef WIN32
-set DNA colors  | dnacolors  | red,green,yellow,blue      | 100 0 0,0 100 0,0 0
-                |            |                            |       100,100 100 0
-                |            |                            |
-set prot. colors| protcolors | red,green,yellow,blue,     | 100 0 0,0 100 0,
-                |            | cyan,magenta,salmon,purple,|  0 0 100,100 100 0,
-                |            | aquamarine,dark-gray       |  0 100 100,100 0 100
-#else
-set DNA colors  | dnacolors  | red,green,yellow,blue      | blue,yellow,255 0 0,
-                |            |                            |      green 
-                |            |                            |
-set prot. colors| protcolors | red,green,yellow,blue,     | salmon,154 255 154,
-                |            | cyan,magenta,salmon,purple,| lightyellow,lavender
-                |            | aquamarine,dark-gray       |  
-#endif
+display lowercase: select so that lowercase characters present in sequence data
+are not displayed as uppercase.
 
-Notes:
-#ifdef WIN32
-Colors are defined by 3 RGB numbers in range 0-255.
-#else
-Colors are defined either by a name from your rgb.txt file  
-                       or by 3 RGB numbers in range 0-255.
-#endif
-For DNA/RNA, the 4 listed colors apply to A, C, G, and T/U, respectively.
-For proteins, at most 10 colors can be listed.
->>>Printout options
-See 'Program customization' topic for how to set these options.
+inverted: select to display sequences as black letters on colored background.
 
-                     CONTROLING PRINTOUT OPERATION
+default save format: sets the default format of the "File:save as" menu item.
 
-Purpose       | Name          | Default value | Example of possible value
---------------|---------------|---------------|--------------------------
-block size    | printoutblock |   10          |   3
-chars/line    | printoutcpl   |   80          |   90
-lines/page    | printoutlpp   |   66          |   60
-
-Note: the value of printoutcpl stands for the full page width.
+>>>Customization
+#ifdef __APPLE__
+Custom settings are stored as program resources; so settings require write access
+to the seaview program to be permanently changed.
+#elif __WIN32__
+Custom settings are stored in file seaview.ini in the same directory as seaview program.
+#else
+Custom settings are stored in file .seaviewrc in the user's home directory.
+#endif

Modified: trunk/packages/seaview/trunk/seaview_align.sh
===================================================================
--- trunk/packages/seaview/trunk/seaview_align.sh	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/seaview_align.sh	2006-09-22 05:38:11 UTC (rev 121)
@@ -1,16 +1,23 @@
 #!/bin/sh
+algo=$1
+if [ $algo = "clustalw" ]; then
+	regargs=4
+else
+	regargs=5
+fi
+shift 1
 arg1=$1
 shift 1
 args=$*
-if [ $# -gt 4 ]; then
-	shift 4
-	echo used clustalw options: $*
+if [ $# -gt $regargs ]; then
+	shift $regargs
+	echo used $algo options: $*
 fi
-clustalw $args
+$algo $args
 echo ' '
 echo ' '
 echo ' '
-echo 'Program clustalw terminated.'
+echo 'Program' $algo 'terminated.'
 echo -n 'Load new alignment? [(y)/n] '
 read rep
 if [ "$rep" = "n" ]; then

Modified: trunk/packages/seaview/trunk/use_mase_files.cxx
===================================================================
--- trunk/packages/seaview/trunk/use_mase_files.cxx	2006-09-22 05:37:45 UTC (rev 120)
+++ trunk/packages/seaview/trunk/use_mase_files.cxx	2006-09-22 05:38:11 UTC (rev 121)
@@ -58,6 +58,9 @@
 void save_comment_lines(int tot_comment_lines, char **names, char **lines, 
 	FILE *out);
 known_format what_format(const char *filename);
+extern "C" {
+	char *my_fgets(char *s, int n, FILE *f);
+	}
 
 
 
@@ -72,6 +75,7 @@
 
 
 
+
 int read_mase_seqs_header(const char *masefname, char ***pseq, char ***pseqname, 
 		char ***pcomments, char **pheader, char **err_message)
 {
@@ -92,6 +96,10 @@
 want_header = (pheader != NULL);
 
 if(fgets(line, lline, masef)==NULL)goto fini;
+if(strchr(line, '\n') == NULL) {
+	strcpy(ret_message,"Not a mase file!");
+	goto fini;
+	}
 if(strncmp(line,";;",2)==0) {
 	if(want_header) {
 		if( (header=(char *)malloc(MAXLENCOM+1)) ==
@@ -300,8 +308,8 @@
 		lseq += l2;
 		}
 	seq[totseqs][lseq]='\0';
-/* convert all to upper case */
-	p = seq[totseqs] - 1; while( *(++p) != 0 ) *p = toupper(*p);
+/* convert all to upper case 
+	p = seq[totseqs] - 1; while( *(++p) != 0 ) *p = toupper(*p); */
 	}
 fini:
 fclose(in);
@@ -390,7 +398,7 @@
 int i, l, curr_spec, first=TRUE, curr_len, next_len, tot_spec, curr_max_len,
 	carac, wid_name;
 static char ret_message[200];
-char **seq, **comments, **seqname;
+char **seq, **comments, **seqname = NULL;
 
 *ret_message = 0;
 *err_message = ret_message;
@@ -412,7 +420,7 @@
 		carac = getc(in);
 		}
 	}
-while(carac == '\n');
+while(carac == '\n' || carac == '\r');
 ungetc(carac, in); /* back to start of 1st non-empty line */
 tot_spec = curr_spec = -1; curr_len = next_len = 0;
 while( fgets(line, sizeof(line), in) != NULL ) {
@@ -513,7 +521,7 @@
 tot_spec = 0;
 while(fgets(line, sizeof(line), in) != NULL) {
 	if(strncmp(line, "//", 2) == 0) break;
-	if(strncmp(line, " Name: ", 7) == 0) tot_spec++;
+	if(strstr(line, "Name: ") != NULL) tot_spec++;
 	}
 rewind(in);
 seq = (char **)malloc(tot_spec * sizeof(char *));
@@ -528,7 +536,7 @@
 while( fgets(line,sizeof(line),in) != NULL) {
 	if( (p = strstr(line, "MSF: ")) != NULL) break;
 	}
-if(p == NULL) {
+if(p == NULL || tot_spec == 0) {
 	strcpy(ret_message,"File not in MSF format!");
 	tot_spec = -1; goto fini;
 	}
@@ -590,7 +598,7 @@
 static char dna[]="ACGTU";
 int total=0, length=0;
 while(*seq != 0) {
-	if(*seq != '-') {
+	if(*seq != '-' && toupper(*seq) != 'N') { 
 		if( strchr(dna, toupper(*seq)) != NULL ) total++;
 		length++; 
 		}
@@ -611,9 +619,9 @@
 	2 si tentative de depasser la longueur d'une sequence
 */
 {
-const int widphylin = 50;
+const int widphylin = 60;
 FILE *out;
-int lenseqs, i, j, retval = 1, current, save_current, err, vtotseqs;
+int lenseqs, i, j, retval = 1, current, save_current, err, vtotseqs, lu;
 list_segments *psegment, all_sequence, *curr_segment;
 region maregion;
 
@@ -649,10 +657,14 @@
 		putc(seqname[i][j],out);
 		}
 	while(j < PHYNAME) { putc( ' ', out ); j++; }
-	err = output_next_res_from_region(seq[i], eachlength[i], &psegment, 
-		&current, out, widphylin, FALSE);
+	lu = 0;
+	while(lu < widphylin && psegment != NULL) {
+		putc( ' ', out );
+		err = output_next_res_from_region(seq[i], eachlength[i], &psegment, 
+			&current, out, 10, FALSE);
+		lu += err;
+		}
 	putc('\n', out);
-	if(err == -1) { retval = 2; goto fin; }
 	if(ferror(out)) goto fin;
 	}
 while( psegment != NULL ) {
@@ -661,10 +673,15 @@
 	for(i=0; i < totseqs; i++) {
 		if(tot_sel_seqs != 0 && ! sel_seqs[i]) continue;
 		psegment = curr_segment; current = save_current;
-		err = output_next_res_from_region(seq[i], eachlength[i], 
-			&psegment, &current, out, widphylin, FALSE);
+		for(j = 0; j < PHYNAME; j++) putc( ' ', out );
+		lu = 0;
+		while(lu < widphylin && psegment != NULL) {
+			putc( ' ', out );
+			err = output_next_res_from_region(seq[i], eachlength[i], 
+				&psegment, &current, out, 10, FALSE);
+			lu += err;
+			}
 		putc('\n', out);
-		if(err == -1) { retval = 2; goto fin; }
 		if(ferror(out)) goto fin;
 		}
 	}
@@ -682,8 +699,9 @@
 dans une liste de regions. lenseq est la longueur de la sequence seq.
 La position courante est determinee par le segment courant (*segment, qui peut
 etre modifie par la fonction) et par la position (from 0) dans celui-ci (*current
-qui est modifie par la fonction pour etre pret pour l'appel suivant)
-Rend le nombre de residus effectivement ecrits, ou -1 si depassement longueur de seq.
+qui est modifie par la fonction pour etre pret pour l'appel suivant).
+Si le segment demande va au dela de la fin de la seq, des - sont ecrits.
+Rend le nombre de residus effectivement ecrits, qui est tjrs celui demande.
 Doit etre appelle la premiere fois avec *current = 0
 */
 {
@@ -824,7 +842,7 @@
 	if( tot_sel_seqs != 0 && ! sel_seqs[num] ) continue;
 	current = 0; psegment = region_used->list;
 	all_sequence.fin = eachlength[num];
-	if(comments[num] != NULL)
+	if(comments != NULL && comments[num] != NULL)
 		fputs(comments[num], out);
 	else fputs(";no comment\n", out);
 	if(ferror(out)) goto fin;
@@ -1045,7 +1063,7 @@
 	gen_check += check_val[j++];
 	}
 gen_check = gen_check % 10000;
-fprintf(out,"PileUp\n\n\n\n   MSF:%5d  Type: %c    Check:%6d   .. \n\n",
+fprintf(out,"PileUp\n\n\n\n   MSF: %d  Type: %c    Check:%6d   .. \n\n",
 	lenseqs, (protein ? 'P' : 'N'), gen_check);
 for(i = 0 , j = 0; i < totseqs; i++) {
 	if( tot_sel_seqs != 0 && ! sel_seqs[i] ) continue;
@@ -1549,14 +1567,39 @@
 	if(nseq != -1 && lseq != -1) format = PHYLIP_FORMAT; 
 	else {
 		/* try MSF format */
-		do p = fgets(line, sizeof(line), in);
-		while(p != NULL  && *p == '\n');
-		if(p != NULL) {
-			while(*p == ' ') p++;
-			if(strncmp(p, "MSF:", 4) == 0) format = MSF_FORMAT;
+		do 	{
+			p = fgets(line, sizeof(line), in);
+			if(p != NULL && strstr(p, " MSF: ") !=  NULL) format = MSF_FORMAT;
 			}
+		while(p != NULL  && strncmp(p, "//", 2) != 0 );
 		}
 	}
 fclose(in);
 return (known_format)format;
 }
+
+
+char *my_fgets(char *s, int n, FILE *f)
+{
+int next_char, ahead;
+char *p;
+
+p = s;
+while(--n > 0) {
+	next_char = getc(f);
+	if( next_char == '\r' || next_char == '\n' ) {
+		*(p++) = '\n';
+		ahead = getc(f);
+		if(ahead == EOF) break;
+		if( (next_char == '\r' && ahead != '\n') || (next_char == '\n' && ahead != '\r') ) {
+			ungetc(ahead, f);
+			}
+		break;
+		}
+ 	else if (next_char == EOF) 
+		break;
+	*(p++) = next_char;
+	}
+*p = 0;
+return (p == s ? NULL : s);
+}




More information about the debian-med-commit mailing list