/*
 * Copyright 1990 by Baylor College of Medicine ALL RIGHTS RESERVED. 
 *
 * This program is subject to a license agreement between 
 * Baylor College of Medicine and MIT. Any use inconsistent with
 * said license and any use by persons other than the faculty, 
 * students and staff at MIT or any use on a computer not operated 
 * as part of the Athena Computing Environment (ACE) is expressly 
 * prohibited.
 */
/****************************************************************
 * File: Vns.h 
 * Date: 05/07/91
 *
 * Description:
 *   This file is the public header file for the VNS library.
 *
 * Notes:
 *
 * Revisions:
 ****************************************************************/
#ifndef _VNS_H_
#define _VNS_H_

#include <X11/Intrinsic.h>
#include <srvlib.h>

/****************************************************************
 * VNS version and release numbers:
 ****************************************************************/

#define VNS_MAJOR_VERSION 2
#define VNS_MINOR_VERSION 1
#define VNS_RELEASE       6

/****************************************************************
 * Callback definitions:
 ****************************************************************/

#define CB_NOTEBOOK_CREATE   "NotebookCreate"
#define CB_NOTEBOOK_MODIFY   "NotebookModify"
#define CB_NOTEBOOK_DELETE   "NotebookDelete"
#define CB_PAGE_CREATE       "PageCreate"
#define CB_PAGE_MODIFY       "PageModify"
#define CB_PAGE_DELETE       "PageDelete"

/****************************************************************
 * Macros:
 ****************************************************************/

#define DbToSrv(db)            ((db)->srv)
#define DbToVns(db)            ((db)->vns)

#define NoteToSrv(note)        ((note)->db->srv)
#define NoteToVns(note)        ((note)->db->vns)
#define NoteToDb(note)         ((note)->db)

#define PageToSrv(page)        ((page)->parent->db->srv)
#define PageToVns(page)        ((page)->parent->db->vns)
#define PageToDb(page)         ((page)->parent->db)
#define PageToNote(page)       ((page)->parent)

#define ObjectToSrv(obj)       ((obj)->parent->parent->db->srv)
#define ObjectToVns(obj)       ((obj)->parent->parent->db->vns)
#define ObjectToDb(obj)        ((obj)->parent->parent->db)
#define ObjectToNote(obj)      ((obj)->parent->parent)
#define ObjectToPage(obj)      ((obj)->parent)

/****************************************************************
 * Type definitions:
 ****************************************************************/

typedef struct _VnsDatabase VnsDatabase;
typedef struct _VnsCallbackList VnsCallbackList;
typedef struct _VnsNotebook VnsNotebook;
typedef struct _VnsPage VnsPage;
typedef struct _VnsObject VnsObject;
typedef struct _Session Session;
typedef struct _VnsAuthor VnsAuthor;
typedef struct _VnsPaste VnsPaste;
typedef struct _VnsCallback VnsCallbackRec;
typedef void (*VnsCallbackProc)();
typedef char* VnsPointer;

/****************************************************************
 * Structures:
 ****************************************************************/

typedef struct _VnsContext
{
	char *app_name;             /* application name */
	Widget toplevel;            /* the toplevel widget shell */
	Widget browser;             /* browser widget */
	Widget prop_mgr;            /* property manager shell widget */
	Display *dpy;               /* pointer to the X display */
	VnsDatabase *first_db;      /* list of databases */
	VnsDatabase *current_db;    /* pointer to current database */
	VnsPage *first_page;        /* pointer to full list of pages */
	VnsPage *stacking_page;     /* pointer to current stacking page */
	VnsPage *tunnel_page;       /* pointer to current tunnel page */
	VnsCallbackList *callbacks; /* pointer to list of callbacks */
	Session *session;           /* session data */
	int (*link_callback)();     /* pointer to link_here callback */
	XtPointer link_data;        /* pointer to link_here callback data */
	char last_font[256];        /* storage for last_font used */
	char last_color[256];       /* storate for last color used */
	VnsPaste *clip_board;       /* clip board for cut/copy objects */
	String default_font;        /* default font from resource file */
	String site_printer_file;   /* path to site printer file */
} VnsContext;

typedef struct _VnsDatabase
{
	SrvContext *srv;            /* pointer to connection infromation */
	char *host;                 /* hostname where database resides */
	int port;                   /* port number */
	char *name;                 /* database name */
	VnsContext *vns;            /* pointer to vns context (parent) */
	VnsNotebook *first_note;    /* pointer to the first notebook */
	VnsAuthor *first_author;    /* pointer to first author for database */
	VnsDatabase *next;          /* pointer to the next database record */
};

typedef struct _VnsNotebook
{
	int nid;                    /* Notebook Id */
	Notebook_Info info;         /* Properties of the notebook */
	VnsDatabase *db;            /* parent database of notebook */
	VnsPage *first_page;        /* First opened page in the notebook */
	VnsNotebook *next;          /* Next notebook */
	int last_page;              /* Last page in the notebook */
};

typedef struct _VnsCallback
{
	VnsCallbackProc proc;       /* pointer to the callback function */
	VnsPointer data;            /* user callback data */
	VnsCallbackRec *next;       /* pointer to next callback entry */
};

typedef struct _VnsCallbackList
{
	char *name;                 /* name of the callback list */
	VnsCallbackRec *list;       /* list of callbacks */
	VnsCallbackList *next;      /* pointer to next callback list */
};

/* Object description for object in VNS */
typedef struct _VnsObject
{
	int oid;                    /* Object Id */
	Widget owd;                 /* Object widget */
	Widget resize;              /* Object resize widget */
	Object_Info info;           /* Object properties */
	union
	{
		struct {
			Widget wd;          /* The actual text widget */
		} txt;
		struct {
			Widget wd;          /* The title of the link widget */
			Widget button;      /* The link label button */
		} link;
		struct {
			Widget wd;          /* The actual image widget */
			Rast_Img img;       /* The image represented by the widget */
		} img;
	} auxil;
	VnsPage *parent;            /* Page that contains object */
	VnsObject *next;            /* Next object on page */
	int selected;               /* True if the object is selected */
};

/*
 * Describes page representation in VNS for a page 
 * that may or may not be opened.
 */
typedef struct
{
	VnsNotebook *nl;            /* Notebook of page */
	int pid;                    /* Page id */
} Page_Id;

/* Structure for reprenting a path for returning */
struct return_page
{
	Page_Id pid;                /* Page id of return */
	struct return_page *next;   /* Next return */
	int count;                  /* Count of references to this node */
};

/* Page description for opened page in VNS */
typedef struct _VnsPage
{
	int pid;                    /* Page id */
	Widget pwd;                 /* Shell widget of page */
	Widget form;                /* Child of Shell */
	Widget nname;               /* Notebook name widget */
	Widget sw;                  /* scrollable viewport */
	Widget comp;                /* Object area (VnsBackground) */
	Widget link_here;           /* "Link Here" Widget */
	Page_Info info;             /* Page properties */
	VnsObject *selected_object; /* Last selected object */
	int nselected;              /* current number of selected objects */
	VnsObject *first_object;    /* First object */
	VnsNotebook *parent;        /* Notebook that page resides in */
	VnsPage *next;              /* Next page in notebook list */
	VnsPage *npage;             /* Next page in overall list */
	struct return_page *retrn;  /* Return pages */
	unsigned long col;          /* X representation of page color */
	Widget stack;               /* Stacking toggle widget */
	Widget tunnel;              /* Tunnel toggle widget */
	Widget w_pagenum;           /* Page number widget */
	Widget header;              /* page header widget */
	Widget footer;              /* page footer widget */
	Widget w_retrn;             /* "Return" widget */
	Widget w_undo;              /* Undo Menu selection */
	Widget w_cut;               /* Cut object menu selection */
	Widget w_paste;             /* Paste Object Menu widget */
	Widget w_x_paste;           /* X Paste Menu selection */
	Widget w_create_menu;       /* Create Menu widget */
	Widget w_create_page;       /* create page menu item */
	Widget w_import_menu;       /* Import Menu widget */
	Widget w_edit;              /* Edit Menu widget */
	Widget w_object_del;        /* "Object Cut" Menu selection */
	Widget w_menu;              /* popup menu (button 3) */
	char geom[256];             /* Temporary holding cell for shell geometry */
	Widget hbar;                /* horizontal scrollbar for page */
	Widget vbar;                /* vertical scrollbar for page */

	Pixmap exit_pixmap;
	Pixmap home_pixmap;
	Pixmap link_here_pixmap;
	Pixmap link_here_pixmap_s;
	Pixmap return_pixmap;
	Pixmap return_pixmap_s;
	Pixmap tunnel_pixmap;
	Pixmap tunnel_pixmap_s;
	Pixmap stack_pixmap;
	Pixmap stack_pixmap_s;
};

typedef struct _VnsAuthor
{
	int aid;                    /* author id (uid) */
	VnsNotebook *nl;            /* ponter to current notebook */
	int current_access;         /* access for currently selected notebook */
	int active;                 /* flag if author is an active or not */
	Widget name;                /* widget for author name */
	Widget read_only;           /* widget for read only column */
	Widget read_write;          /* widget for read/write column */
	VnsAuthor *next;            /* pointer to next author */
};

typedef struct _VnsPaste
{
	Object_Type type;                 /* type of object */
	long width;                       /* width of object */
	long height;                      /* height of object */
	long x;                           /* x location */
	long y;                           /* y location */
	union {
	    struct {
	        char *txt;                /* pointer to text for text object */
	        Txt_Info info;            /* info on text object */
	    } text;
	    Link_Info link;               /* link information */
	    Action_Link_Info alink;       /* action link information */
	    struct {
	        Rast_Img img;             /* actual image */
	        Img_Info info;            /* image information */
	    } image;
	} data;
	VnsPaste *next;                   /* pointer to the next object in buffer */
};

typedef struct _OpenPage OpenPage;

typedef struct _OpenPage
{
	char notebook[256];
	int page;
	char geom[256];
	OpenPage *next;
};

typedef struct _Session
{
	int show_grid;
	int snap_to_grid;
	int show_outlines;
	int auto_page_open;
	char panel_geom[256];
	OpenPage *pages;
};

/****************************************************************
 * Public Functions:
 ****************************************************************/

VnsContext *VnsInitialize();
void VnsDoEverything();
void VnsMainLoop();
Widget VnsGetBrowserWidget();
int VnsMajorVersion();
int VnsMinorVersion();
int VnsRelease();
void VnsPrintVersion();
void VnsPrintCopyright();

void VnsCreateCallbackList();
void VnsAddCallback();
void VnsCallCallbacks();

VnsDatabase *VnsAddDatabase();
void VnsDeleteDatabase();
Boolean VnsConnect();
void VnsDisconnect();

VnsNotebook **VnsFindNotebook();
VnsPage **VnsFindPage();
VnsObject **VnsFindObject();

VnsPage *VnsAddPage();

void VnsBuildCommandPanel();
Widget VnsBuildBrowser();
unsigned long VnsAllocNamedColor();

/* functions to be phased out */
struct return_page *add_page_to_path();
VnsPage *add_page();
VnsNotebook **find_note();
VnsNotebook *add_notebook();
void del_notebook();
VnsObject *add_object();
VnsObject *add_object2();
XFontStruct *alloc_named_font();

#endif /* _VNS_H_ */
