/* Generated by wbuild from "Pager.w"
** (generator version $Revision: 1.17 $ of $Date: 92/12/07 19:32:00 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 775 "Pager.w"
#include "flip_back.xpm"
#line 776 "Pager.w"
#include "flip_forward.xpm"
#line 777 "Pager.w"
#include <Xfwf/Icon.h>
#line 778 "Pager.w"
#include <stdlib.h>
#line 779 "Pager.w"
#include <fcntl.h>
#line 780 "Pager.w"
#include <stdio.h>
#include <Xfwf/PagerP.h>
#line 354 "Pager.w"
static void previous_page(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);
#line 359 "Pager.w"
static void next_page(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);

static XtActionsRec actionsList[] = {
{"previous_page", previous_page},
{"next_page", next_page},
};

static char defaultTranslations[] = "\
<Key>Prior: previous_page() \n\
<Key>BackSpace: previous_page() \n\
<Key>Next: next_page() \n\
<Key>space: next_page() \n\
";
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 177 "Pager.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 231 "Pager.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 274 "Pager.w"
static void resize(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 300 "Pager.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 370 "Pager.w"
#define INCREMENT 2048 


#line 371 "Pager.w"
#define mrealloc(ptr, size) (void *)XtRealloc ((char *)ptr ,size )


#line 373 "Pager.w"
static void read_from_file(
#if NeedFunctionPrototypes
Widget,String 
#endif
);
#line 394 "Pager.w"
static void read_from_pipe(
#if NeedFunctionPrototypes
Widget,String 
#endif
);
#line 417 "Pager.w"
static void init_text(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 438 "Pager.w"
static void split_text(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 489 "Pager.w"
static void scale_fonts(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 551 "Pager.w"
static void create_romangc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 563 "Pager.w"
static void create_italicgc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 575 "Pager.w"
static void create_boldgc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 592 "Pager.w"
static void forward_CB(
#if NeedFunctionPrototypes
Widget ,XtPointer ,XtPointer 
#endif
);
#line 607 "Pager.w"
static void backwards_CB(
#if NeedFunctionPrototypes
Widget ,XtPointer ,XtPointer 
#endif
);
#line 627 "Pager.w"
static Boolean  infer_roman(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 664 "Pager.w"
static Boolean  infer_italic(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 702 "Pager.w"
static Boolean  infer_bold(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 735 "Pager.w"
static void guess_bold(
#if NeedFunctionPrototypes
Widget,int ,XrmValue *
#endif
);
#line 745 "Pager.w"
static void guess_italic(
#if NeedFunctionPrototypes
Widget,int ,XrmValue *
#endif
);
#line 759 "Pager.w"
static void guess_roman(
#if NeedFunctionPrototypes
Widget,int ,XrmValue *
#endif
);
#line 373 "Pager.w"
/*ARGSUSED*/static void read_from_file(self,filename)Widget self;String  filename;
{
    int fd, len = 0, nbytes;

    if ((fd = open(filename, O_RDONLY)) < 0) {
	perror(filename);
	return;
    }
    do {
	((XfwfPagerWidget)self)->xfwfPager.fulltext = mrealloc(((XfwfPagerWidget)self)->xfwfPager.fulltext, len + INCREMENT + 1);
	nbytes = read(fd, ((XfwfPagerWidget)self)->xfwfPager.fulltext + len, INCREMENT);
	if (nbytes < 0) perror(filename); else len += nbytes;
    } while (nbytes > 0);
    ((XfwfPagerWidget)self)->xfwfPager.fulltext[len] = '\0';
    (void) close(fd);
}
#line 394 "Pager.w"
/*ARGSUSED*/static void read_from_pipe(self,cmd)Widget self;String  cmd;
{
    int len = 0, nbytes;
    FILE *stream;

    if ((stream = popen(cmd, "r")) == NULL) {
	perror(cmd);
	return;
    }
    do {
	((XfwfPagerWidget)self)->xfwfPager.fulltext = mrealloc(((XfwfPagerWidget)self)->xfwfPager.fulltext, sizeof(char) * (len + INCREMENT + 1));
	nbytes = fread(((XfwfPagerWidget)self)->xfwfPager.fulltext + len, sizeof(char), INCREMENT, stream);
	if (nbytes < 0) perror(cmd); else len += nbytes;
    } while (nbytes > 0);
    ((XfwfPagerWidget)self)->xfwfPager.fulltext[len] = '\0';
    (void) pclose(stream);
}
#line 417 "Pager.w"
/*ARGSUSED*/static void init_text(self)Widget self;
{
    XtFree(((XfwfPagerWidget)self)->xfwfPager.fulltext); ((XfwfPagerWidget)self)->xfwfPager.fulltext = NULL;
    XtFree((char*) ((XfwfPagerWidget)self)->xfwfPager.page); ((XfwfPagerWidget)self)->xfwfPager.page = NULL;
    if (((XfwfPagerWidget)self)->xfwfPager.text == NULL) return;
    /*
     * Initialize $fulltext
     */
    switch (((XfwfPagerWidget)self)->xfwfPager.text[0]) {
    case '@': read_from_file(self, ((XfwfPagerWidget)self)->xfwfPager.text + 1); break;
    case '`': read_from_pipe(self, ((XfwfPagerWidget)self)->xfwfPager.text + 1); break;
    default: ((XfwfPagerWidget)self)->xfwfPager.fulltext = XtNewString(((XfwfPagerWidget)self)->xfwfPager.text);
    }
}
#line 438 "Pager.w"
/*ARGSUSED*/static void split_text(self)Widget self;
{
    int i, j, n, h;
    Position x, y;
    Dimension wd, ht;
    char prev = '\0';

    ((XfwfPagerWidget)self)->xfwfPager.page = mrealloc(((XfwfPagerWidget)self)->xfwfPager.page, 3 * sizeof(((XfwfPagerWidget)self)->xfwfPager.page[0]));
    ((XfwfPagerWidget)self)->xfwfPager.page[1] = 0;
    j = 2;
    /* Wrapping is not implemented yet */
    if (((XfwfPagerWidget)self)->xfwfPager.lines > 0 && ((XfwfPagerWidget)self)->xfwfPager.fulltext != NULL) {
	/* Count lines until n == $lines */
	n = 0;
	for (i = 0; ((XfwfPagerWidget)self)->xfwfPager.fulltext[i]; prev = ((XfwfPagerWidget)self)->xfwfPager.fulltext[i], i++) {
	    if (prev == '\n') {
		n++;
		if (n == ((XfwfPagerWidget)self)->xfwfPager.lines) {
		    ((XfwfPagerWidget)self)->xfwfPager.page = mrealloc(((XfwfPagerWidget)self)->xfwfPager.page, (j+2) * sizeof(((XfwfPagerWidget)self)->xfwfPager.page[0]));
		    ((XfwfPagerWidget)self)->xfwfPager.page[j++] = i;
		    n = 0;
		}
	    }
	}
    } else if (((XfwfPagerWidget)self)->xfwfPager.fulltext != NULL) {
	/* Determine page length with actual height of the text */
	((XfwfPagerWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &wd, &ht);
	h = y + ((XfwfPagerWidget)self)->xfwfPager.margin + ((XfwfPagerWidget)self)->xfwfPager.baselineskip;
	ht = y + ht - 50;
	for (i = 0; ((XfwfPagerWidget)self)->xfwfPager.fulltext[i]; prev = ((XfwfPagerWidget)self)->xfwfPager.fulltext[i], i++) {
	    if (prev == '\n') {
		h += ((XfwfPagerWidget)self)->xfwfPager.baselineskip;
		if (h + ((XfwfPagerWidget)self)->xfwfPager.roman->descent >= ht) {
		    ((XfwfPagerWidget)self)->xfwfPager.page[j++] = i;
		    h = y + ((XfwfPagerWidget)self)->xfwfPager.margin + ((XfwfPagerWidget)self)->xfwfPager.baselineskip;
		}
	    }
	}
    }
    ((XfwfPagerWidget)self)->xfwfPager.page[j] = -1;
    ((XfwfPagerWidget)self)->xfwfPager.pageno = 1;
}
#line 489 "Pager.w"
/*ARGSUSED*/static void scale_fonts(self)Widget self;
{
    Position x, y;
    Dimension w, h;
    int pixels;
    char s[250], *p;
    XFontStruct *fs;

    ((XfwfPagerWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &w, &h);
    ((XfwfPagerWidget)self)->xfwfPager.baselineskip = (h - 50 - ((XfwfPagerWidget)self)->xfwfPager.margin) / ((XfwfPagerWidget)self)->xfwfPager.lines;
    if (((XfwfPagerWidget)self)->xfwfPager.roman_name == NULL) { /* Font name is unknown */
        ((XfwfPagerWidget)self)->xfwfPager.baseline = ((XfwfPagerWidget)self)->xfwfPager.baselineskip / (float) (((XfwfPagerWidget)self)->xfwfPager.roman->ascent + ((XfwfPagerWidget)self)->xfwfPager.roman->descent);
        return;
    }
    p = strstr(((XfwfPagerWidget)self)->xfwfPager.roman_name, "-0-0-0-0-");
    if (p == NULL) { /* Font is not scalable */
        ((XfwfPagerWidget)self)->xfwfPager.baseline = ((XfwfPagerWidget)self)->xfwfPager.baselineskip / (float) (((XfwfPagerWidget)self)->xfwfPager.roman->ascent + ((XfwfPagerWidget)self)->xfwfPager.roman->descent);
        return;
    }
    pixels = ((XfwfPagerWidget)self)->xfwfPager.baselineskip/((XfwfPagerWidget)self)->xfwfPager.baseline;

    *p = '\0';
    (void) sprintf(s, "%s-%d-*-*-*-%s", ((XfwfPagerWidget)self)->xfwfPager.roman_name, pixels, p + 9);
    *p = '-';
    /* (void) fprintf(stderr, "scaled roman = %s\n", s); */
    if ((fs = XLoadQueryFont(XtDisplay(self), s)) != NULL) {
        XFreeFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.roman);
        ((XfwfPagerWidget)self)->xfwfPager.roman = fs;
        create_romangc(self);
    }

    if (((XfwfPagerWidget)self)->xfwfPager.italic_name != NULL) {
        p = strstr(((XfwfPagerWidget)self)->xfwfPager.italic_name, "-0-0-0-0-");
        if (p != NULL) {
            *p = '\0';
            (void) sprintf(s, "%s-%d-*-*-*-%s", ((XfwfPagerWidget)self)->xfwfPager.italic_name, pixels, p + 9);
            *p = '-';
	    /* (void) fprintf(stderr, "scaled italic = %s\n", s); */
            if ((fs = XLoadQueryFont(XtDisplay(self), s)) != NULL) {
                XFreeFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.italic);
                ((XfwfPagerWidget)self)->xfwfPager.italic = fs;
                create_italicgc(self);
            }
        }
    }

    if (((XfwfPagerWidget)self)->xfwfPager.bold_name != NULL) {
        p = strstr(((XfwfPagerWidget)self)->xfwfPager.bold_name, "-0-0-0-0-");
        if (p != NULL) {
            *p = '\0';
            (void) sprintf(s, "%s-%d-*-*-*-%s", ((XfwfPagerWidget)self)->xfwfPager.bold_name, pixels, p + 9);
            *p = '-';
	    /* (void) fprintf(stderr, "scaled bold = %s\n", s); */
            if ((fs = XLoadQueryFont(XtDisplay(self), s)) != NULL) {
                XFreeFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.bold);
                ((XfwfPagerWidget)self)->xfwfPager.bold = fs;
                create_boldgc(self);
            }
        }
    }
}
#line 551 "Pager.w"
/*ARGSUSED*/static void create_romangc(self)Widget self;
{
    XGCValues val;
    XtGCMask mask = GCForeground | GCBackground | GCFont;

    if (((XfwfPagerWidget)self)->xfwfPager.romangc != NULL) XtReleaseGC(self, ((XfwfPagerWidget)self)->xfwfPager.romangc);
    val.foreground = ((XfwfPagerWidget)self)->xfwfPager.foreground;
    val.background = ((XfwfPagerWidget)self)->core.background_pixel;
    val.font = ((XfwfPagerWidget)self)->xfwfPager.roman->fid;
    ((XfwfPagerWidget)self)->xfwfPager.romangc = XtGetGC(self, mask, &val);
}
#line 563 "Pager.w"
/*ARGSUSED*/static void create_italicgc(self)Widget self;
{
    XGCValues val;
    XtGCMask mask = GCForeground | GCBackground | GCFont;

    if (((XfwfPagerWidget)self)->xfwfPager.italicgc != NULL) XtReleaseGC(self, ((XfwfPagerWidget)self)->xfwfPager.italicgc);
    val.foreground = ((XfwfPagerWidget)self)->xfwfPager.foreground;
    val.background = ((XfwfPagerWidget)self)->core.background_pixel;
    val.font = ((XfwfPagerWidget)self)->xfwfPager.italic->fid;
    ((XfwfPagerWidget)self)->xfwfPager.italicgc = XtGetGC(self, mask, &val);
}
#line 575 "Pager.w"
/*ARGSUSED*/static void create_boldgc(self)Widget self;
{
    XGCValues val;
    XtGCMask mask = GCForeground | GCBackground | GCFont;

    if (((XfwfPagerWidget)self)->xfwfPager.boldgc != NULL) XtReleaseGC(self, ((XfwfPagerWidget)self)->xfwfPager.boldgc);
    val.foreground = ((XfwfPagerWidget)self)->xfwfPager.foreground;
    val.background = ((XfwfPagerWidget)self)->core.background_pixel;
    val.font = ((XfwfPagerWidget)self)->xfwfPager.bold->fid;
    ((XfwfPagerWidget)self)->xfwfPager.boldgc = XtGetGC(self, mask, &val);
}
#line 592 "Pager.w"
/*ARGSUSED*/static void forward_CB(w,client_data,call_data)Widget  w;XtPointer  client_data;XtPointer  call_data;
{
    Widget self = (Widget) client_data;

    if (((XfwfPagerWidget)self)->xfwfPager.page[((XfwfPagerWidget)self)->xfwfPager.pageno+1] >= 0) {
	((XfwfPagerWidget)self)->xfwfPager.pageno++;
	XClearWindow(XtDisplay(self), XtWindow(self));
	((XfwfPagerWidgetClass)self->core.widget_class)->core_class.expose(self, NULL, NULL);
    }
}
#line 607 "Pager.w"
/*ARGSUSED*/static void backwards_CB(w,client_data,call_data)Widget  w;XtPointer  client_data;XtPointer  call_data;
{
    Widget self = (Widget) client_data;

    if (((XfwfPagerWidget)self)->xfwfPager.pageno > 1) {
	((XfwfPagerWidget)self)->xfwfPager.pageno--;
	XClearWindow(XtDisplay(self), XtWindow(self));
	((XfwfPagerWidgetClass)self->core.widget_class)->core_class.expose(self, NULL, NULL);
    }
}
#line 627 "Pager.w"
/*ARGSUSED*/static Boolean  infer_roman(self)Widget self;
{
    char **fonts;
    int n, i;

    XtFree(((XfwfPagerWidget)self)->xfwfPager.roman_name); ((XfwfPagerWidget)self)->xfwfPager.roman_name = NULL;
    if (((XfwfPagerWidget)self)->xfwfPager.fontFamily == NULL) return False;
    fonts = XListFonts(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.fontFamily, 1000, &n);
    if (n == 0) return False;
    for (i = 0; i < n; i++)
	if (strstr(fonts[i], "normal-r") || strstr(fonts[i], "medium-r")) {
	    ((XfwfPagerWidget)self)->xfwfPager.roman_name = XtNewString(fonts[i]);
	    break;
	}
    if (((XfwfPagerWidget)self)->xfwfPager.roman_name == NULL)
	for (i = 0; i < n; i++)
	    if (strstr(fonts[i], "-r-")) {
		((XfwfPagerWidget)self)->xfwfPager.roman_name = XtNewString(fonts[i]);
		break;
	    }
    if (((XfwfPagerWidget)self)->xfwfPager.roman_name == NULL)
	((XfwfPagerWidget)self)->xfwfPager.roman_name = XtNewString(fonts[0]);
    ((XfwfPagerWidget)self)->xfwfPager.roman = XLoadQueryFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.roman_name);
    XFreeFontNames(fonts);
    /* (void) fprintf(stderr, "roman name = %s\n", $roman_name); */
    return True;
}
#line 664 "Pager.w"
/*ARGSUSED*/static Boolean  infer_italic(self)Widget self;
{
    char **fonts;
    int n, i;

    XtFree(((XfwfPagerWidget)self)->xfwfPager.italic_name); ((XfwfPagerWidget)self)->xfwfPager.italic_name = NULL;
    if (((XfwfPagerWidget)self)->xfwfPager.fontFamily == NULL) return False;
    fonts = XListFonts(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.fontFamily, 1000, &n);
    if (n == 0) return False;
    for (i = 0; i < n; i++)
	if (strstr(fonts[i], "normal-i") || strstr(fonts[i], "medium-i")
	    || strstr(fonts[i], "normal-o") || strstr(fonts[i], "medium-o")) {
	    ((XfwfPagerWidget)self)->xfwfPager.italic_name = XtNewString(fonts[i]);
	    break;
	}
    if (((XfwfPagerWidget)self)->xfwfPager.italic_name == NULL)
	for (i = 0; i < n; i++)
	    if (strstr(fonts[i], "-r-") || strstr(fonts[i], "-o-")) {
		((XfwfPagerWidget)self)->xfwfPager.italic_name = XtNewString(fonts[i]);
		break;
	    }
    if (((XfwfPagerWidget)self)->xfwfPager.italic_name == NULL)
	((XfwfPagerWidget)self)->xfwfPager.italic_name = XtNewString(fonts[0]);
    ((XfwfPagerWidget)self)->xfwfPager.italic = XLoadQueryFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.italic_name);
    XFreeFontNames(fonts);
    /* (void) fprintf(stderr, "italic name = %s\n", $italic_name); */
    return True;
}
#line 702 "Pager.w"
/*ARGSUSED*/static Boolean  infer_bold(self)Widget self;
{
    char **fonts;
    int n, i;

    XtFree(((XfwfPagerWidget)self)->xfwfPager.bold_name); ((XfwfPagerWidget)self)->xfwfPager.bold_name = NULL;
    if (((XfwfPagerWidget)self)->xfwfPager.fontFamily == NULL) return False;
    fonts = XListFonts(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.fontFamily, 1000, &n);
    if (n == 0) return False;
    for (i = 0; i < n; i++)
	if (strstr(fonts[i], "-bold-r-")) {
	    ((XfwfPagerWidget)self)->xfwfPager.bold_name = XtNewString(fonts[i]);
	    break;
	}
    if (((XfwfPagerWidget)self)->xfwfPager.bold_name == NULL)
	for (i = 0; i < n; i++)
	    if (strstr(fonts[i], "-bold-")) {
		((XfwfPagerWidget)self)->xfwfPager.bold_name = XtNewString(fonts[i]);
		break;
	    }
    if (((XfwfPagerWidget)self)->xfwfPager.bold_name == NULL)
	((XfwfPagerWidget)self)->xfwfPager.bold_name = XtNewString(fonts[0]);
    ((XfwfPagerWidget)self)->xfwfPager.bold = XLoadQueryFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.bold_name);
    XFreeFontNames(fonts);
    /* (void) fprintf(stderr, "bold name = %s\n", $bold_name); */
    return True;
}
#line 735 "Pager.w"
/*ARGSUSED*/static void guess_bold(self,offset,value)Widget self;int  offset;XrmValue * value;
{
    ((XfwfPagerWidget)self)->xfwfPager.bold_name = NULL;
    if (infer_bold(self))
	value->addr = (XtPointer) &((XfwfPagerWidget)self)->xfwfPager.bold;
    else
	value->addr = (XtPointer) &((XfwfPagerWidget)self)->xfwfPager.roman;
}
#line 745 "Pager.w"
/*ARGSUSED*/static void guess_italic(self,offset,value)Widget self;int  offset;XrmValue * value;
{
    ((XfwfPagerWidget)self)->xfwfPager.italic_name = NULL;
    if (infer_italic(self))
	value->addr = (XtPointer) &((XfwfPagerWidget)self)->xfwfPager.italic;
    else
	value->addr = (XtPointer) &((XfwfPagerWidget)self)->xfwfPager.roman;
}
#line 759 "Pager.w"
/*ARGSUSED*/static void guess_roman(self,offset,value)Widget self;int  offset;XrmValue * value;
{
    static XFontStruct *fixed;

    ((XfwfPagerWidget)self)->xfwfPager.roman_name = NULL;
    if (infer_roman(self))
	value->addr = (XtPointer) &((XfwfPagerWidget)self)->xfwfPager.roman;
    else {
	fixed = XLoadQueryFont(XtDisplay(self), "fixed");
	value->addr = (XtPointer) &fixed;
    }
}

static XtResource resources[] = {
#line 36 "Pager.w"
{XtNtext,XtCText,XtRString,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.text),XtOffsetOf(XfwfPagerRec,xfwfPager.text),XtRImmediate,(XtPointer)NULL },
#line 45 "Pager.w"
{XtNfontFamily,XtCFontFamily,XtRString,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.fontFamily),XtOffsetOf(XfwfPagerRec,xfwfPager.fontFamily),XtRImmediate,(XtPointer)NULL },
#line 54 "Pager.w"
{XtNroman,XtCRoman,XtRFontStruct,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.roman),XtOffsetOf(XfwfPagerRec,xfwfPager.roman),XtRCallProc,(XtPointer)guess_roman },
#line 61 "Pager.w"
{XtNitalic,XtCItalic,XtRFontStruct,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.italic),XtOffsetOf(XfwfPagerRec,xfwfPager.italic),XtRCallProc,(XtPointer)guess_italic },
#line 67 "Pager.w"
{XtNbold,XtCBold,XtRFontStruct,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.bold),XtOffsetOf(XfwfPagerRec,xfwfPager.bold),XtRCallProc,(XtPointer)guess_bold },
#line 74 "Pager.w"
{XtNlines,XtCLines,XtRInt,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.lines),XtOffsetOf(XfwfPagerRec,xfwfPager.lines),XtRImmediate,(XtPointer)0 },
#line 81 "Pager.w"
{XtNwrap,XtCWrap,XtRBoolean,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.wrap),XtOffsetOf(XfwfPagerRec,xfwfPager.wrap),XtRImmediate,(XtPointer)False },
#line 92 "Pager.w"
{XtNbaseline,XtCBaseline,XtRFloat,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.baseline),XtOffsetOf(XfwfPagerRec,xfwfPager.baseline),XtRString,(XtPointer)"1.2"},
#line 97 "Pager.w"
{XtNmargin,XtCMargin,XtRInt,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.margin),XtOffsetOf(XfwfPagerRec,xfwfPager.margin),XtRImmediate,(XtPointer)5 },
#line 102 "Pager.w"
{XtNforeground,XtCForeground,XtRPixel,sizeof(((XfwfPagerRec*)NULL)->xfwfPager.foreground),XtOffsetOf(XfwfPagerRec,xfwfPager.foreground),XtRString,(XtPointer)"black"},
#line 108 "Pager.w"
{XtNbackground,XtCBackground,XtRPixel,sizeof(((XfwfPagerRec*)NULL)->core.background_pixel),XtOffsetOf(XfwfPagerRec,core.background_pixel),XtRString,(XtPointer)"white"},
#line 112 "Pager.w"
{XtNframeType,XtCFrameType,XtRFrameType,sizeof(((XfwfPagerRec*)NULL)->xfwfFrame.frameType),XtOffsetOf(XfwfPagerRec,xfwfFrame.frameType),XtRImmediate,(XtPointer)XfwfSunken },
};

XfwfPagerClassRec xfwfPagerClassRec = {
{ /* core_class part */
(WidgetClass) &xfwfBoardClassRec,
"XfwfPager",
sizeof(XfwfPagerRec),
NULL,
_resolve_inheritance,
FALSE,
initialize,
NULL,
XtInheritRealize,
actionsList,
2,
resources,
12,
NULLQUARK,
False ,
FALSE ,
False ,
False ,
NULL,
resize,
expose,
set_values,
NULL,
XtInheritSetValuesAlmost,
NULL,
XtInheritAcceptFocus,
XtVersion,
NULL,
defaultTranslations,
XtInheritQueryGeometry,
XtInheritDisplayAccelerator,
NULL 
},
{ /* composite_class part */
XtInheritGeometryManager,
XtInheritChangeManaged,
XtInheritInsertChild,
XtInheritDeleteChild,
NULL
},
{ /* XfwfCommon_class part */
XtInherit_compute_inside,
XtInherit_highlight_border,
XtInherit_unhighlight_border,
XtInherit_would_accept_focus,
XtInherit_traverse,
XtInherit_choose_color,
XtInherit_lighter_color,
XtInherit_darker_color,
NULL ,
},
{ /* XfwfFrame_class part */
0
},
{ /* XfwfBoard_class part */
XtInherit_set_abs_location,
},
{ /* XfwfPager_class part */
0
},
};
WidgetClass xfwfPagerWidgetClass = (WidgetClass) &xfwfPagerClassRec;
/*ARGSUSED*/
#line 354 "Pager.w"
static void previous_page(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    backwards_CB(self, self, NULL);
}

/*ARGSUSED*/
#line 359 "Pager.w"
static void next_page(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    forward_CB(self, self, NULL);
}

static void _resolve_inheritance(class)
WidgetClass class;
{
  XfwfPagerWidgetClass c = (XfwfPagerWidgetClass) class;
  XfwfPagerWidgetClass super;
  if (class == xfwfPagerWidgetClass) return;
  super = (XfwfPagerWidgetClass) c->core_class.superclass;
}
#line 177 "Pager.w"
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    int status;

    ((XfwfPagerWidget)self)->xfwfPager.f_back.attributes.valuemask = XpmSize;
    status = XpmCreatePixmapFromData
	(XtDisplay(self), DefaultRootWindow(XtDisplay(self)), flip_back,
	 &((XfwfPagerWidget)self)->xfwfPager.f_back.pixmap, &((XfwfPagerWidget)self)->xfwfPager.f_back.mask, &((XfwfPagerWidget)self)->xfwfPager.f_back.attributes);
    switch (status) {
    case XpmNoMemory: XtError("Out of memory");
    case XpmColorFailed: XtError("Failed to allocate color for pixmap");
    case XpmColorError: XtWarning("Not all pixmap colors found");
    default: ; /* skip */
    }
    ((XfwfPagerWidget)self)->xfwfPager.flip_back = XtVaCreateManagedWidget
	("_flip_back", xfwfIconWidgetClass, self,
	 XtNlocation, "1.0-50 1.0-50 50 50", XtNimage, &((XfwfPagerWidget)self)->xfwfPager.f_back,
	 XtNhighlightThickness, 0, XtNtraversalOn, False, NULL);
    XtAddCallback(((XfwfPagerWidget)self)->xfwfPager.flip_back, XtNactivate, backwards_CB, self);

    ((XfwfPagerWidget)self)->xfwfPager.f_forward.attributes.valuemask = XpmSize;
    status = XpmCreatePixmapFromData
	(XtDisplay(self), DefaultRootWindow(XtDisplay(self)), flip_forward,
	 &((XfwfPagerWidget)self)->xfwfPager.f_forward.pixmap, &((XfwfPagerWidget)self)->xfwfPager.f_forward.mask, &((XfwfPagerWidget)self)->xfwfPager.f_forward.attributes);
    switch (status) {
    case XpmNoMemory: XtError("Out of memory");
    case XpmColorFailed: XtError("Failed to allocate color for pixmap");
    case XpmColorError: XtWarning("Not all pixmap colors found");
    default: ; /* skip */
    }
    ((XfwfPagerWidget)self)->xfwfPager.flip_forward = XtVaCreateManagedWidget
	("_flip_forward", xfwfIconWidgetClass, self,
	 XtNlocation, "1.0-50 1.0-50 50 50", XtNimage, &((XfwfPagerWidget)self)->xfwfPager.f_forward,
	 XtNhighlightThickness, 0, XtNtraversalOn, False, NULL);
    XtAddCallback(((XfwfPagerWidget)self)->xfwfPager.flip_forward, XtNactivate, forward_CB, self);

    create_romangc(self);
    create_italicgc(self);
    create_boldgc(self);
    ((XfwfPagerWidget)self)->xfwfPager.baselineskip = 0.5 + ((XfwfPagerWidget)self)->xfwfPager.baseline * (((XfwfPagerWidget)self)->xfwfPager.roman->ascent + ((XfwfPagerWidget)self)->xfwfPager.roman->descent);
    ((XfwfPagerWidget)self)->xfwfPager.fulltext = NULL;
    ((XfwfPagerWidget)self)->xfwfPager.page = NULL;
    init_text(self);
    split_text(self);
    if (((XfwfPagerWidget)self)->xfwfPager.lines > 0) scale_fonts(self);
}
#line 231 "Pager.w"
/*ARGSUSED*/static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    Boolean need_redisplay = False;

    if (((XfwfPagerWidget)old)->xfwfPager.fontFamily != ((XfwfPagerWidget)self)->xfwfPager.fontFamily) {
	XtFree(((XfwfPagerWidget)old)->xfwfPager.fontFamily);
	((XfwfPagerWidget)self)->xfwfPager.fontFamily = XtNewString(((XfwfPagerWidget)self)->xfwfPager.fontFamily);
	XFreeFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.roman);
	XFreeFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.italic);
	XFreeFont(XtDisplay(self), ((XfwfPagerWidget)self)->xfwfPager.bold);
	(void) infer_roman(self);
	(void) infer_italic(self);
	(void) infer_bold(self);
    }
    if (((XfwfPagerWidget)old)->xfwfPager.text != ((XfwfPagerWidget)self)->xfwfPager.text) {
	XtFree(((XfwfPagerWidget)old)->xfwfPager.text);
	((XfwfPagerWidget)self)->xfwfPager.text = XtNewString(((XfwfPagerWidget)self)->xfwfPager.text);
	init_text(self);
	split_text(self);
	need_redisplay = True;
    }
    if (((XfwfPagerWidget)old)->xfwfPager.roman != ((XfwfPagerWidget)self)->xfwfPager.roman
	|| ((XfwfPagerWidget)old)->xfwfPager.italic != ((XfwfPagerWidget)self)->xfwfPager.italic
	|| ((XfwfPagerWidget)old)->xfwfPager.bold != ((XfwfPagerWidget)self)->xfwfPager.bold
	|| ((XfwfPagerWidget)old)->xfwfPager.lines != ((XfwfPagerWidget)self)->xfwfPager.lines
	|| ((XfwfPagerWidget)old)->xfwfPager.wrap != ((XfwfPagerWidget)self)->xfwfPager.wrap
	|| ((XfwfPagerWidget)old)->xfwfPager.baseline != ((XfwfPagerWidget)self)->xfwfPager.baseline
	|| (((XfwfPagerWidget)old)->core.width != ((XfwfPagerWidget)self)->core.width && ((XfwfPagerWidget)self)->xfwfPager.lines == 0)
	|| (((XfwfPagerWidget)old)->core.height != ((XfwfPagerWidget)self)->core.height && ((XfwfPagerWidget)self)->xfwfPager.lines == 0)) {
	split_text(self);
	need_redisplay = True;
    }
    if (((XfwfPagerWidget)old)->core.height != ((XfwfPagerWidget)self)->core.height && ((XfwfPagerWidget)self)->xfwfPager.lines > 0) {
	scale_fonts(self);
	need_redisplay = True;
    }
    return need_redisplay;
}
#line 274 "Pager.w"
/*ARGSUSED*/static void resize(self)Widget self;
{
    xfwfBoardClassRec.core_class.resize(self);
    if (((XfwfPagerWidget)self)->xfwfPager.lines > 0) scale_fonts(self); else split_text(self);
}
#line 300 "Pager.w"
/*ARGSUSED*/static void expose(self,event,region)Widget self;XEvent * event;Region  region;
{
    Region reg;
    XRectangle rect;
    Position y;
    char *p, *q, h[20];
    Display *dpy = XtDisplay(self);
    Window win = XtWindow(self);

    if (! XtIsRealized(self)) return;
    if (! ((XfwfPagerWidget)self)->xfwfPager.fulltext) { xfwfBoardClassRec.core_class.expose(self, event, region); return; }
    ((XfwfPagerWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &rect.x, &rect.y, &rect.width, &rect.height);
    reg = XCreateRegion();
    XUnionRectWithRegion(&rect, reg, reg);
    if (region) XIntersectRegion(reg, region, reg);
    XSetRegion(dpy, ((XfwfPagerWidget)self)->xfwfPager.romangc, reg);
    /* XSetRegion(dpy, $italicgc, reg); */
    /* XSetRegion(dpy, $boldgc, reg); */
    y = ((XfwfPagerWidget)self)->xfwfPager.margin + ((XfwfPagerWidget)self)->xfwfPager.baselineskip - ((XfwfPagerWidget)self)->xfwfPager.roman->descent;
    if (((XfwfPagerWidget)self)->xfwfPager.wrap) {
        /* wrapping mode not implemented yet */
    } else {
        p = ((XfwfPagerWidget)self)->xfwfPager.fulltext + ((XfwfPagerWidget)self)->xfwfPager.page[((XfwfPagerWidget)self)->xfwfPager.pageno];
        while (True) {
            if (y + ((XfwfPagerWidget)self)->xfwfPager.roman->descent >= rect.y + rect.height - 50) break;
            for (q = p; *q != '\0' && *q != '\n' && *q != '\f'; q++) ;
            XDrawImageString(dpy, win, ((XfwfPagerWidget)self)->xfwfPager.romangc, rect.x+((XfwfPagerWidget)self)->xfwfPager.margin, y, p, q-p);
            if (*q == '\0' || *q == '\f') break;
            y += ((XfwfPagerWidget)self)->xfwfPager.baselineskip;
            p = q + 1;
        }
    }
    /* Draw page number */
    sprintf(h, "%d", ((XfwfPagerWidget)self)->xfwfPager.pageno);
    XDrawImageString(dpy, win, ((XfwfPagerWidget)self)->xfwfPager.romangc, rect.x + rect.width/2, rect.y +
		     rect.height - ((XfwfPagerWidget)self)->xfwfPager.roman->descent, h, strlen(h));

    XSetClipMask(dpy, ((XfwfPagerWidget)self)->xfwfPager.romangc, None);
    /* XSetClipMask(dpy, $italicgc, None); */
    /* XSetClipMask(dpy, $boldgc, None); */
    xfwfBoardClassRec.core_class.expose(self, event, region);
}
