/*
 *	@(#)view_private.h 1.17 91/09/14 Copyright 1990-91 Sun Microsystems
 *
 * This file is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify this file without charge, but are not authorized to
 * license or distribute it to anyone else except as part of a product
 * or program developed by the user.
 * 
 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * This file is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even
 * if Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

#if !defined (VIEW_PRIVATE_H)
#define VIEW_PRIVATE_H

/* The set of procedure passed to scan_and_apply. */

typedef struct {
    int	(*handlestring)();
    int (*handlebol)();
    int	(*handleeol)();
} Jot_formatter_ops;

#include <jot/cps.h>

/* extra state information used by the formatter */
typedef struct {
    fixed       x0;		/* The x position of the string currently
				 * being assembled */
    fixed       x, y;		/* The current coordinate */
    fixed       spshim;		/* The size of the shim being added to spaces */
    fixed	xoffset;	/* Indentation that applies to this line */
    short       nsp;		/* The number of spaces in the line */
    short	ntabs;		/* number of tabs in a line */
    int         posatlastbreak;	/* The position in the text at the last
				 * word break */
    fixed       xatlastbreak;	/* The x coordinate at the last word break */
    Jot_formatter_info  fiatlastbreak;
    short	ascentatlastbreak;
    short	descentatlastbreak;
    JotView	*v;		/* view we're in */
} Jot_formatter_state;

typedef struct {		/* information about one line visible in a
				 * view */
    JotSpan	*text;		/* The text in the line */
    short	linelength;	/* The number of characters in the line */
    short	usedlength;	/* number of chars involved in line */
    unsigned	modified:1;	/* true iff this line has to be redrawn */
    unsigned	hascaret:1;	/* caret on this line? */
    unsigned	hasselection:1;	/* has one of the selections? */
    unsigned	partially_visible:1;	/* line is off bottom of view */
    Jot_formatter_info fi;	/* properties at the beginning of the line */
    Jot_formatter_state	fs;	/* formatter state information */
    fixed       cx0,
                cx1;		/* The first and last x coordinates on this
				 * line, for use in drawing selections */
    fixed	modx;		/* x position of first modified char in line */
    int		modpos;		/* position of first modification in line */
    short	lineascent;	/* maximum font ascent for this line */
    short	linedescent;	/* maximum font descent for this line */
} Jot_lineinfo;

/* position in a view */
typedef struct {
    int		    pos;	/* pos we're matching against */
    struct {
	fixed       x, y;
    } p;
    Jot_lineinfo    *where;	/* the relevant line */
} Jot_view_coord;

typedef struct {
    Jot_view_coord  begin;
    Jot_view_coord  end;
    int		    style;	/* INVERT, UNDERLINE, STRIKETHRU */
} Jot_view_region;

/* two types of devices we do output to */
#define Jot_Printer	0
#define Jot_NeWS	1

#ifdef __STDC__
#   define jot_proto(p) p
#else
#   define jot_proto(p) ()
#endif

typedef struct {
    void    (*show) jot_proto((JotView *v, char *string, int length));
    void    (*widthshow) jot_proto((JotView *v, char *string, int length, fixed spshim));
    void    (*setcolor) jot_proto((JotView *v, JotColor *color));
    void    (*usefont) jot_proto((JotView *v, struct Jot_font *font));
    void    (*moveto) jot_proto((JotView *v, fixed x, fixed y));
    void    (*lineto) jot_proto((JotView *v, fixed x, fixed y));
    void    (*stroke) jot_proto((JotView *v));
} Jot_device_ops;

typedef struct {
    JotColor	    *color;
    struct Jot_font *font;
} Jot_graphics_state;

typedef struct {
    void    (*kbd) jot_proto((JotView *v, int c));
    void    (*kbd_shift) jot_proto((JotView *v, int c, int shift_state));
    void    (*mouse) jot_proto((JotView *v, int button, int action, int pos));
    boolean (*selection_start) jot_proto((JotView *v, int position));
    void    (*selection_alter) jot_proto((JotView *v, int rank));
    void    (*undo) jot_proto((JotView *v));
    void    (*redo) jot_proto((JotView *v));
    void    (*find) jot_proto((JotView *v, int rank, int direction));
    void    (*again) jot_proto((JotView *v));
} Jot_controllers;

#define JotView_show(v, str, len)   (*(v)->device->show)(v, str, len)
#define JotView_widthshow(v, str, len, shim) \
    (*(v)->device->widthshow)(v, str, len, shim)
#define JotView_setcolor(v, c)	    (*(v)->device->setcolor)(v, c)
#define JotView_usefont(v, f)	    (*(v)->device->usefont)(v, f)
#define JotView_moveto(v, x, y)	    (*(v)->device->moveto)(v, x, y)
#define JotView_lineto(v, x, y)	    (*(v)->device->lineto)(v, x, y)
#define JotView_stroke(v)	    (*(v)->device->stroke)(v)

#define JotView_File(v)	    ((v)->device_info.LaserWriter.fp)

EXTERN_FUNCTION(void JotView_SetDevice, (JotView *v, int type));
EXTERN_FUNCTION(char *JotPrint_OpEncoding, (char *op));

#endif	/* VIEW_PRIVATE_H */
