/*
 * $Source: $
 * $Revision: $
 * $Date: $
 * $State: $
 * $Author: $
 *
 *
 * $Log: $
 * Revision 3.1  3/10/92 wade
 * Added Baylor's changes
 * enum and #define's for gif
 *
 * added IMAGE_MASK, IMAGE_TYPE and IMGAE_ICON
 *
 * 6/20/92 - wade
 * Added POP_UP_MENU	407 to define pop-up menu
 */

/*------------------------------------------------------------------------------
# pips.h

 *	Copyright (c) 1991 by the Massachusetts Institute of Technology,
 *	For copying and distribution information, see the file
 *	"mit-copyright.h".

#
------------------------------------------------------------------------------*/

/*	Determining an application's minimum size to request from MultiFinder depends
	on many things, each of which can be unique to an application's function,
	the anticipated environment, the developer's attitude of what constitutes
	reasonable functionality and performance, etc. Here is a list of some things to
	consider when determining the minimum size (and preferred size) for your
	application. The list is pretty much in order of importance, but by no means
	complete.
	
	1.	What is the minimum size needed to give almost 100 percent assurance
		that the application won't crash because it ran out of memory? This
		includes not only things that you do have direct control over such as
		checking for NIL handles and pointers, but also things that some
		feel are not so much under their control such as QuickDraw and the
		Segment Loader.
		
	2.	What kind of performance can a user expect from the application when
		it is running in the minimum memory configuration? Performance includes
		not only speed in handling data, but also things like how many documents
		can be opened, etc.
		
	3.	What are the typical sizes of scraps is a boy dog that a user might
		wish to work with when lauching or switching to your application? If
		the amount of memory is too small, scraps will have to be shot. This
		can be quite frustrating to the user.
		
	4.	The previous items have concentrated on topics that tend to cause an
		increase in the minimum size to request from MultiFinder. On the flip
		side, however, should be the consideration of what environments the
		application may be running in. There may be a high probability that
		many users with relatively small memory configurations will want to
		avail themselves of your application. Or, many users might want to use it
		while several other, possibly related/complementary applications are
		running. If that is the case, it would be helpful to have a fairly
		small minimum size.
	
	
		We determined the smallest heap size that TESample could have and still
		run (22K). For the preferred size we added enough space to permit:
			a. a maximum size TextEdit text handle (32000 characters)
			b. a maximum usable TextEdit scrap (32000 characters)
			b. a maximum scrap as a result of Copy (32000 characters)
			d. a little performance cushion (see 2, above) (10K)
		Result: 122K for preferred size
		
		For the minimum size we took the 22K and then scaled down our requirements
		for a,b, and c above. We thought that providing 16K more would be lean
		and mean (see 4, above).
		Result: 38K for minimum size
*/
 
#define kPrefSize				122
#define kMinSize				38

/* for positioning the disk initialization dialog */
#define kDITop					0x0050
#define kDILeft					0x0070

/* number of allowed open documents; we use this in the window's menu list */
#define MAX_OPEN_DOCUMENTS		10
	

/*	kControlInvisible is used to 'turn off' controls (i.e., cause the control not
	to be redrawn as a result of some Control Manager call such as SetCtlValue)
	by being put into the contrlVis field of the record. kControlVisible is used
	the same way to 'turn on' the control. */
#define kControlInvisible		0
#define kControlVisible			0xFF

/*	kScrollbarAdjust and kScrollbarWidth are used in calculating
	values for control positioning and sizing. */
#define kScrollbarWidth			16
#define kScrollbarAdjust		(kScrollbarWidth - 1)
#define SCROLL_BAR_PIXELS		15

/*	kScrollTweek compensates for off-by-one requirements of the scrollbars
 to have borders coincide with the growbox. */
#define kScrollTweek			2
	
/*	kCrChar is used to match with a carriage return when calculating the
	number of lines in the TextEdit record. kDelChar is used to check for
	delete in keyDowns. */
#define kCrChar					13
#define kDelChar				8
#define kTabChar				9
	
/*	kButtonScroll is how many pixels to scroll horizontally when the button part
	of the horizontal scrollbar is pressed. */
#define kButtonScroll			4
	
/*	kMaxTELength is an arbitrary number used to limit the length of text in the TERec
	so that various errors won't occur from too many characters in the text. */
#define	kMaxTELength			32000



/* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
   by MultiFinder. Once we determine that an event is an OSEvent, we look at the
   high byte of the message sent to determine which kind it is. To differentiate
   suspend and resume events we check the resumeMask bit. */
#define	kOSEvent				app4Evt	/* event used by MultiFinder */
#define	kSuspendResumeMessage	1		/* high byte of suspend/resume event message */
#define	kResumeMask				1		/* bit of message field for resume vs. suspend */
#define	kMouseMovedMessage		0xFA	/* high byte of mouse-moved event message */

/* 1.01 - kMinHeap - This is the minimum result from the following
	 equation:
			
			ORD(GetApplLimit) - ORD(ApplicZone)
			
	 for the application to run. It will insure that enough memory will
	 be around for reasonable-sized scraps, FKEYs, etc. to exist with the
	 application, and still give the application some 'breathing room'.
	 To derive this number, we ran under a MultiFinder partition that was
	 our requested minimum size, as given in the 'SIZE' resource. */
	 
#define	MIN_HEAP				 (29 * 1024)
	
/* 1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
	 at initialization time, for the application to run. This number acts
	 as a double-check to insure that there really is enough memory for the
	 application to run, including what has been taken up already by
	 pre-loaded resources, the scrap, code, and other sundry memory blocks. */
	 
#define	MIN_SPACE				(20 * 1024)

/*	kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
#define kExtremeNeg				-32768
#define kExtremePos				(32767 - 1) /* required to address an old region bug */
	
/* kTESlop provides some extra security when pre-flighting edit commands. */
#define	kTESlop					1024

#define	rUserAlert	129				/* user error alert */
#define	rVScroll	128				/* vertical scrollbar control */
#define	rHScroll	129				/* horizontal scrollbar control */
#define	kErrStrings	128				/* error string list */

/* 
 *	System stuff 
 *
 */
 
#define	SYS_ENVIRONS_VERSION	1	/* used to find which version of the SysEnvRec we understand */

/*
 * Network stuff
 *
 */
#define PIPS_IP_ADDR  			"TISERVE.MIT.EDU"
#define PIPS_PORT     			"9000"
#define BANNER_SIZE	   		256
#define	MESSAGE_RECEIVE_SIZE 		2048
#define DELIM 				":"
#define DELIM_CHAR			':'
#define	NETWORK_RECEIVE_SIZE		25000

/* 
 *	Icon stuff 
 *
 *	ie. a marked filled in folder icon would be 601 (500 + 100 + 1)
 *
 */
 #define FOLDER_ICON			130
 #define DOCUMENT_ICON			500
 #define FILLED_ICON			100
 #define PHONE_ICON			129
 #define PIPS_ICON			128
 #define IMAGE_ICON			501

/*
 * menu stuff
 *
 */
#define	MAX_CELL_SIZE		700			/* number of pixels each cell will contain */
#define DEFAULT_MENU_TOP	GetMBarHeight() + 20
#define DEFAULT_MENU_LEFT	2
#define DEFAULT_MENU_BOTTOM 238
#define DEFAULT_MENU_RIGHT	418

/*
 *
 * Window stuff 
 *
 */
#define LIST_WINDOW_ID		400
#define NIL_POINTER			0L
#define TEXT_FONT_SIZE     	12

/* Define HiWrd and LoWrd macros for efficiency. */
#define HiWrd(aLong)	(((aLong) >> 16) & 0xFFFF)
#define LoWrd(aLong)	((aLong) & 0xFFFF)

enum {message, command, local, list=8, text=9, gif=10, getinfo=11};	/* mec 911107 */
enum {close_window, hide_window};		/* close box in some windows means hide and
										   not close, which terminates storage */

/* 	MinDocDim is used to limit the minimum dimension of a window when GrowWindow
	is called. */
#define	MINDOCDIM				64

/*
 *
 * Text stuff 
 *
 */
#define TEXT_SIZE 				32701	/* size of text buffer including terminating null char */
#define TEXT_MARGIN				2		/* number of pixels left blank at the edge of the window */
#define	MAX_DOC_WIDTH			576		/* width of the TERec's destinaton rectangle for word wrap */
#define	DOC_WINDOW				128		/* text window */

/*
 *
 * Menu stuff 
 *
 */
#define	BROWSER_BAR				128		/* Browser menu bar  */

#define	APPLE					128		/* Apple menu */
#define	ABOUT					1

#define	EDIT					130		/* Edit menu */
#define UNDO					1
#define	CUT						3
#define	COPY					4
#define	PASTE					5

#define POP_UP_MENU				131		/* pop up menu for window history function */

#define	FILEM					129		/* File menu */
#define CLOSE					1
#define SAVE_TEXT				2
/* line							3*/
#define PAGE					4
#define PRINT					5
/* line							6*/
#define HELP					7
#define GETINFO					8
/* line							9*/
#define USERSTARTUP				10
#define PREFERENCE				11
/* line							12*/
#define PROVIDER_MENU			13
/* line							14 */
#define	QUIT					15

#define	BROWSER					402		/* Browser menu */
#define MAIN					1
#define BACK					2
#define SHOW					3
#define OUTLINE					4
#define SHOW_PATH				5
/* line							6*/
#define WORD					7
#define AGAIN					8
#define KEYWORD					9
#define WINDOW_LIST				10

#define	TOYS					403		/* toys menu */
#define	DEBUG					1
#define CONFIGURE				2
#define SEND					3
/* line 						4*/
#define DIRECTORY				5
#define WORLDWIDE				6		/* worldwide TechInfo servers */

#define	SPECIAL					400		/* special menu */
#define DIRECTORY				1
#define WORLDWIDE				2		/* worldwide TechInfo servers */
#ifdef GIFSTUFF
#define GIFFILEREAD				3		/* read GIF File from disk */
#endif

#define	PROVIDER				406		/* provider menu */
#define CLEAR_DOCUMENT			1
#define OPEN_DOCUMENT			2
#define SEND_DOCUMENT			3
/* line 						4*/
#define DEFINE_MENU_ITEM		5
/* line							6*/
#define MODIFY_ITEM				7
#define REMOVE_ITEM				8
/* line							9*/
#define PROVIDER_OPTIONS		10
#define SOURCE_INFO				11
/* line							12*/
#define CLOSE_SESSION			13

/*
 *
 * Dialog stuff 
 *
 */
 
enum{ add, modify, describe };

/* generic statements */
#define NIL_POINTER				0L
#define OK_BUTTON				1
#define	CANCEL_BUTTON			2
#define OFF                		0
#define ON						1

#define	DEFINE_ITEM_DIALOG1		405		/* define menu item dialog */
/* #define OK_BUTTON			1		   already defined */
/* #define CANCEL_BUTTON		2	       already defined */
#define MORE_BUTTON			3
#define TITLE_FIELD			4
#define KEYWORDS_FIELD			5
#define SOURCE_FIELD			6
#define PARENT_TITLE_FIELD		7
#define FOLDER_RADIO_BUTTON		12
#define DOCUMENT_RADIO_BUTTON		13
#define IMAGE_RADIO_BUTTON		15

#define	DEFINE_ITEM_DIALOG2		406		/* define menu item dialog */
/* #define OK_BUTTON			1		   already defined */
/* #define CANCEL_BUTTON		2	       already defined */
#define FILENAME_FIELD			3
#define PATH_FIELD				4
#define LOCKER_FIELD			5

#define ASK_ID					469		/* Ask ID & password Dialog */
#define USERNAME_TAG			3
#define USERNAME				4
#define PASSWORD_TAG			5
#define PASSWORD				6

#define SEND_DIALOG				404		/* Send String Dialog */

#define MESSAGE_DIALOG			401		/* Message Dialog */

#define KEYWORD_DIALOG			400		/* Keyword/topic Topic Dialog */
/* #define OK_BUTTON			1			reused field */
/* #define	CANCEL_BUTTON		2			reused field */
#define USER_INPUT				3
#define SEARCH_ALL_RADIO		5
#define SEARCH_CURRENT_RADIO	6

#define PHONE_DIALOG			507		/* Phone Dialog */
/* #define OK_BUTTON			1			reused field */
/* #define	CANCEL_BUTTON		2			reused field */
/* #define USER_INPUT			3			reused field */

#define NETWORK_DIALOG			402		/* Network Dialog */
#define HOST_DLOG				4
#define PORT_DLOG				5
#define BANNER_ITEM				9

#define FIND_STRING_DIALOG		470		/* find string dialog */
#define STRING					3
#define CASE_CHECKBOX			4
#define BEGINNING_CHECKBOX		6

#define GETINFO_DIALOG			5120

#define DISCLAIMER_DIALOG		501
#define STOP_BUTTON				2
#define CONTINUE_BUTTON			1
#define LOGO					3

#define DELETE_DIALOG			502		/* delete dialog */
#define CANCEL_REMOVE			1
#define OK_REMOVE				2
#define REMOVE_WHAT				4

#define THERMOMETER_DIALOG		503		/* thermometer dialog */
#define MESSAGE_BOX				1
#define TITLE_BOX				2
#define CONTROL					3
#define ABORT_BUTTON			4

#define REPLACE_DIALOG			504		/* delete dialog */
#define CANCEL_REPLACE			1
#define OK_REPLACE				2
#define REPLACE_WHAT			4

#define PREFERENCES_DIALOG		505		/* preference dialog */
/* #define OK_BUTTON			1 		already defined */
/* #define CANCEL_BUTTON		2		already defined */
#define HOST_ITEM				10
#define PORT_ITEM				7
#define DISCLAIMER_ITEM			8
#define OUTLINE_ITEM			3
#define WINDOW_SETTINGS			11

#define SETSTARTUP_DIALOG		506		/* preference dialog */
/* #define OK_BUTTON			1 		already defined */
/* #define CANCEL_BUTTON		2		already defined */
#define RADIO_LIST				5		/* list radio button */
#define RADIO_TEXT				6		/* text radio button */

#define PROVIDER_OPTIONS_DIALOG	508		/* provider options dialog */
/* #define OK_BUTTON			1 		already defined */
/* #define CANCEL_BUTTON		2		already defined */
#define STORE_DIRECTORY			3		/* edit data path field */
#define TAB_SETTING_VALUE		6

#define SEND_DOCUMENT_DIALOG	509		/* send dialog dialog */
/* #define OK_BUTTON			1 		already defined */
/* #define CANCEL_BUTTON		2		already defined */
#define DOCUMENT_NAME			3		

#define SOURCE_INFO_DIALOG		510		/* source info dialog */
/* #define OK_BUTTON			1 		already defined */
/* #define CANCEL_BUTTON		2		already defined */
#define SOURCE_SHORT_NAME_F		14	
#define SOURCE_LONG_NAME_F		3
#define SOURCE_CONTACT_NAME_F	4
#define SOURCE_PHONE_F			5
#define SOURCE_EMAIL_F			12

#define VERSION_DIALOG			511		/* source info dialog */
/* #define OK_BUTTON			1 		already defined */
/* #define CANCEL_BUTTON		2		already defined */
#define VERSION_MSG				3	

/*
 *
 * Alert stuff 
 *
 */
#define	ABOUT_ALERT				128		/* about alert */
#define NOTE_ID					400		/* Note alert for warning messges */
#define HELP_ID					500		/* Help alert */
/*
 *
 * String stuff 
 *
 */
#define MESSAGES				400		/* warning messages for Note alert */

/* the folowing are warning messages from STR# resource */
 
 #define NO_TOPIC				1
 #define LIST_TRUNCATED			2
 #define NETWORK_ALERT			3
 #define BAD_PROVIDER			4
 #define PUBLISH_ERROR			5
 #define FILE_ERROR				6
 #define OPEN_WARNING			7
 #define NOT_AUTHORIZED			8
 #define WRITE_ERROR			9
 #define PRINT_ERROR			10
 #define NO_DIALOG				11
 #define BAD_VERSION			12
 #define REMOVE_ERROR			13
 #define REORDER_ERROR			14
 #define FIELD_ENTRY_ERROR1		15
 #define FIELD_ENTRY_ERROR2		16
 #define FIELD_ENTRY_ERROR3		17
 #define UNKNOWN_NODEID			18
 #define ALREADY_OPEN			19 /* file is open by another application */
 #define TECHINFO_MSG			20
 #define FIELD_ENTRY_ERROR4		21
 #define FIELD_ENTRY_ERROR5		22
 #define MEMORY_ERROR			23

 
/* The following are indicies into severe (stop) STR# resources. */
#define	WRONG_MACHINE			1
#define	SMALL_SIZE			2
#define	NO_MEMORY			3
#define	NO_SPACE_CUT			4
#define	NO_CUT				5
#define	NO_COPY				6
#define	EXCEED_PASTE			7
#define	NO_SPACE_PASTE			8
#define	NO_WINDOW			9
#define	EXCEED_CHAR			10
#define	NO_PASTE			11
#define OBTAIN_VERSION			12
#define NO_RESOURCE			13
#define SMALL_BUFFER			14

/* The following are indicies for the STR resource. */
#define APPLICATION_NAME	128
#define	SERVER_NAME		400
#define	SERVER_PORT		401
#define SHOW_DISCLAIMER		403
#define OUTLINE_DEPTH		404
#define STARTUP_ID		405
#define WINDOW_STARTUP		406
#define STORE_DIRECTORY_STR	407
#define NAMESERVER_HOST		408
#define NAMESERVER_PORT		409
#define TAB_SETTING		410

/* 
 * Command Stuff
 *
 */
enum{off,on};
enum{store,retrieve};
enum{edit_nil,edit_cut,edit_paste,edit_move,edit_copy};  /* functions available for edit undo */

/* item type */
#define TEXT_ITEM 't'
#define MENU_ITEM 's'
#define PHONE_ITEM 'p'
#define SERVER_ITEM 'z'
#define IMAGE_ITEM 'i'

#define ACK	"OK"
#define MARK  0x01
#define FRAME 0x02
#define SEL_HIGH 0x04  /* select top of cell */
#define SEL_LOW  0x08  /* select bottom of cell */

#define IMAGE_MASK 0x40  /* determines if the type of an item */

/* Meta data dictionary stuff from a traversal "w" transaction*/
#define TYPE					0
#define LEVEL					1
#define NODE					2
#define	FLAGS					3
#define DATE					4
#define TOPIC					5
#define TITLE					6
#define SOURCE					7
#define LOCKER					8
#define PATH					9

/* Meta data dictionary stuff for a "m" transaction - server list */
#define NOTUSED1				0
#define NOTUSED2				1
#define TI_PORT					2
#define SERVER_ID				3
#define	NOTUSED4				4
#define NOTUSED5				5
#define TI_TITLE				6
#define TI_HOST_NAME				7
#define NOTUSED6				8
#define TI_KEY					9	/* this is should be set to "PIPS" */

/* Meta data dictionary stuff from a show "s" transaction*/
#define S_TYPE					-1  /* needs to be different from TYPE field */
#define S_NODE					1
#define	S_FLAGS					2
#define S_DATE					3
#define S_TOPIC					4
#define S_TITLE					5
#define S_SOURCE				6
#define S_LOCKER				7
#define S_PATH					8
#define S_CHILDREN				9

/* Meta data dictionary for the source record */
#define SOURCE_SHORT			1  
#define SOURCE_LONG				2
#define SOURCE_NAME				3
#define	SOURCE_PHONE			4
#define SOURCE_EMAIL			5

/* server return messages */
#define MSGNUMBER				1
#define MSGTEXT					2
#define DISPLAY_MSG				101		/* from server so msg gets displayed */
#define SHUTDOWN_MSG				100		/* server shutdown message */

/* version stuff */
#define PROVIDER_VERSION		"3.0"

/* edit data structure */
typedef struct {
	int	  type;			/* see enum enum{edit_nil,edit_cut,edit_paste, .. */
	short desc;			/* did we do somthing with the last cell          */
	char node_a[6];		/* dependent on operation - type                  */
	char node_b[6];
	char node_c[6];
} data_edit;

/* some helpfull bsd compatible routines */
/* #define index strchr */
/* #define rindex strrchr */
#define bzero(ptr, len) memset ((ptr), 0, (len))
#define bcopy(s,d,n) memcpy(d,s,n)

#define PHONE_KEY "phone"	/* used as a flag to set item type */
#define SERVER_KEY "pips"	/* used as a flag to set item type */
#define IMAGE_KEY 0x40		/* used as a flag to set item gif type */
#define TEXT_KEY 0x10		/* used as a flag to set item to text type */

#define NODE_LENGTH 6		/* size of a node, assuming range [0:99999] */

/* some gif stuff */
enum{gif_init, gif_get_data, gif_close, gif_correct_size};
#define GIF_BUF_SIZE 25000	/* this is the number of requested bytes from the server */

/* structure to hold parsed node info */
typedef struct node_info{
	char	node_id[NODE_LENGTH];
	Str255	title;
	Str255	source;
	Str255	path;
	Str255	type;
	Str255	source_long;
	Str255	source_name;
	Str255	source_email;
	Str255	source_phone;
	Str255	source_topic;
} NODE_INFO;