home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
APPS
/
DVI_MGR
/
dvimgr_s.lzh
/
dvi_fbi_hh
/
DVIDECW
/
dvidecw.c
next >
Wrap
Text File
|
1993-05-06
|
36KB
|
974 lines
/************************************************************************/
/* Filename: DVIDECW.C */
/* Function: Program to view TeX DVI ouput file in a DEC-Windows Envir- */
/* onment */
/* (c) 1990 by Christian MARKUS, Fachbereich Informatik, */
/* Schlueterstr. 70, D 2000 Hamburg 13, Fed.Rep.of Germany */
/* */
/* EMAIL : via friesland@rz.informatik.uni-hamburg.dbp.de */
/*----------------------------------------------------------------------*/
/* Program History: */
/* */
/* Ver#: ! Date: !Comment: !Author: */
/* ------+--------+-------------------------------------+-------------- */
/* 1.0 !04.07.89!First version !Ch. Markus */
/* 1.1 !09.03.90!Corrected and updated !Ch. Markus */
/* !- get/set bit/byte order correctly ! */
/* !- one window/automatically adjusted ! */
/* !- window size can be changed ! */
/* !- Scrollbars available ! */
/* !- Title contains info ! */
/* !- Copy to Clipboard ! */
/* 1.2 !19.06.90!- adaption for ANSI-C/VAX-C 3.1 !Ch. Markus */
/*----------------------------------------------------------------------*/
/* Program description: */
/* */
/* This driver works in a DECWindows environment and is based on TEX */
/* DVI-driver family developed by N.Beebe, Utah, USA. The include files */
/* are taken from version 2.10, the driver DVIDECW is based on the */
/* DVIBIT driver. Instead of using download fonts it creates a bitmap */
/* (similar to DVIJET) and displays it in the output window upon a */
/* window exposure event. Upon each interactive command, the bitmap is */
/* created again. */
/*----------------------------------------------------------------------*/
/* Installation guide: */
/* */
/* - modify the TEXVIEW.COM file to suit your system's paths */
/* - in FileView, select the Customize/Verbs and Menus option */
/* - enter a new verb name 'TeX Preview' below the verb names box and */
/* click on enter button upon completition */
/* - enter the DCL command for the 'Tex Preview' verb, that is entering */
/* somewhat like @<path>texview.com and clicking on the 'enter' button*/
/* - select a menu from the 'Menu Names' box and click on the 'Add' */
/* button below the 'Verbs in Menu' list box. */
/* - press 'Apply' and 'Ok' button to install new item in menu bar */
/* - select the Customize/File Types option and install the .DVI file */
/* type. */
/*----------------------------------------------------------------------*/
/* Quick guide to operations: */
/* */
/* Invoke DVIDecw in four different ways: */
/* - from a DECTerm terminal window */
/* -> just type the command,options and filename to be processed */
/* - from the FileView DCL Command window */
/* -> just type the command,options and filename to be processed */
/* - by selecting a FileView menu item (if TEXVIEW.COM is installed) */
/* -> a dialog box pops up asking for a filename, a second box will */
/* ask for any processing parameters */
/* - by double-clicking on any .DVI file (if TEXVIEW.COM is installed */
/* and the File Types box is set for .DVI files */
/* -> a dialog box pops up asking for processing parameters */
/* */
/* All options of DVIBIT are accepted, but the -o option (order pages) */
/* is ignored, DVIDecw will only pick the first selected page */
/* The program will create a command and an output window and display */
/* the first selected page. */
/* All interactive commands can be selected from menus and should be */
/* easy to understand. */
/* If the TeX Preview window has the 'Input focus' key equivalents */
/* provide a shortcut for some menu commands. To set the input focus, */
/* just click into the Tex Preview window, the window title will change */
/* to the highlight color. */
/*----------------------------------------------------------------------*/
/* The following files taken from the original BEEBE driver have been */
/* modified (using #if compiler switches) for DECWINDOWS: */
/* */
/* DISPCHAR.H -> make up for reversed Y-coordinate origin */
/* DVIFILE.H -> change program structure to event-driven calls */
/* FATAL.H -> don't perform resetterm() function in DECW environment */
/* GBLPROCS.H -> modifications to conform with ANSI-C (Vax C 3.1) */
/* MACHDEFS.H -> changed FONTPATH, FONTLIST and DVIHELP for OS_VMS */
/* OPENFONT.H -> allow open files according to MAXOPEN,quota and avail. */
/* PRTPAGE.H -> changes in EOP case and keyboard status request */
/* SETCHAR.H -> make up for reversed Y-coordinate origin */
/* SETRULE.H -> make up for reversed Y-coordinate origin */
/*----------------------------------------------------------------------*/
/* The DVIDecw package contains the files listed below: */
/* */
/* DVIDOC_D.DVI Installation/User's Guide in GERMAN */
/* DVIDOC_E.DVI Installation/User's Guide in ENGLISH */
/* DVIDECW.C Main C source code, all DECWindows specific coding */
/* DVIDECW.UIL User Interface description file */
/* DVIDECW.COM Compile,UIL and link command procedure */
/* DVILINK.COM Link DVIDECW for other VMS versions */
/* TEXVIEW.COM Command procedure for FileView invocation of DVIDECW */
/* xxxxxxx.H Include files (listed above) modified for DVIDECW */
/************************************************************************/
#include <stdio.h> /* Standard definitions */
/************************************************************************/
/* DECWINDOWS definitions */
/************************************************************************/
#ifdef VMS /* Toolkit definitions */
#include <decw$include/DwtAppl.h> /* using MIT-Binding */
#include <decw$include/Xlib.h>
#include <decw$include/Xutil.h>
#else
#include <X11/DwtAppl.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#endif
#define APP_ID "TeX Preview" /* Application name */
#define CLPBRD_FORMAT "XYBitmap" /* Clipboard data format */
/*----------------------------------------------------------------------*/
/* Constants for object identificationv (similar to .UIL file) */
/*----------------------------------------------------------------------*/
#define k_menu_bar 1
#define k_file_pdme 2
#define k_edit_pdme 3
#define k_page_pdme 4
#define k_move_pdme 5
#define k_option_pdme 6
#define k_file_menu 7
#define k_edit_menu 8
#define k_page_menu 9
#define k_move_menu 10
#define k_option_menu 11
#define k_about_me 12
#define k_quit_me 13
#define k_undo_me 14
#define k_cut_me 15
#define k_copy_me 16
#define k_paste_me 17
#define k_clear_me 18
#define k_s_all_me 19
#define k_prevpage_me 20
#define k_nextpage_me 21
#define k_gotopage_me 22
#define k_zoom_in_me 23
#define k_zoom_out_me 24
#define k_curs_up_me 25
#define k_curs_down_me 26
#define k_curs_left_me 27
#define k_curs_right_me 28
#define k_top_page_me 29
#define k_bot_page_me 30
#define k_offset_me 31
#define k_move_speed_me 32
#define k_reset_pos_me 33
#define k_clipboard_msg 34
#define k_about_msg 35
#define k_about_button 36
#define k_goto_page_dlg 37
#define k_goto_page_label 38
#define k_pagenumber 39
#define k_ok_button 40
#define k_goto_button 41
#define k_cancel_button 42
#define k_lastpage_msg 43
#define k_firstpage_msg 44
#define k_zoomrange_msg 45
#define k_output 46
#define k_scroll_x 47
#define k_scroll_y 48
#define k_max_widget 48
#define MAX_WIDGETS (k_max_widget + 1)
/*----------------------------------------------------------------------*/
/* Global data declarations */
/*----------------------------------------------------------------------*/
static Widget toplevel_widget, /* Root widget ID of application*/
main_window_widget, /* Root widget ID main DRM fetch*/
widget_array[MAX_WIDGETS]; /* Place for other widget IDs*/
static DRMHierarchy s_DRMHierarchy; /* DRM database hierarchy ID */
static DRMType *dummy_class; /* and class variable. */
static char *db_filename_vec[] = /* DRM hierarchy file list. */
{"TEX_INPUTS:dvidecw.uid" /* Fetch resource from path */
}; /* TEX_INPUTS defined as global */
static int db_filename_num =
(sizeof db_filename_vec / sizeof db_filename_vec [0]);
static Display *display; /* Display handle */
static Window top_wi,out_wi; /* Window handles */
static GC gc; /* Graphic context handle */
static Screen *screen; /* Screen handle */
static XImage *out_img; /* XImage Data block */
static Arg arglist[5]; /* Arguments for SetValue */
static int x_windsize; /* Window workarea size in pixel*/
static int y_windsize;
static int x_pagesize; /* Virtual page size in pixel */
static int y_pagesize;
static DwtCompString slow_move;
static DwtCompString fast_move;
static DwtCompString no_offset;
static DwtCompString use_offset;
static DwtCompString discard_dlg;
static DwtCompString gotopage_dlg;
/*----------------------------------------------------------------------*/
/* forward declaration of DECWINDOWS routines */
/*----------------------------------------------------------------------*/
static void s_error(char *problem_string);
static void prtbmap(void);
static void w_print(int line,char *string);
static void clrbmap(void);
static void send_redraw(void);
static void create_proc(Widget w,int *tag,unsigned long *reason);
static void activate_proc(Widget w,int *tag,unsigned long *reason);
static void output_exp_proc(Widget w,int *tag,
DwtAnyCallbackStruct *callback_data);
static void scroll_bar_proc(Widget w,int *tag,unsigned long *reason);
/*----------------------------------------------------------------------*/
/* Names of callback routines to be registered to DECWINDOWS */
/*----------------------------------------------------------------------*/
static DRMRegisterArg reglist[] =
{
{"create_proc", (caddr_t) create_proc},
{"activate_proc", (caddr_t) activate_proc},
{"scroll_bar_proc", (caddr_t) scroll_bar_proc},
{"output_exp_proc", (caddr_t) output_exp_proc}
};
static int reglist_num = (sizeof reglist / sizeof reglist [0]);
/************************************************************************/
/* DVI-BEEBE driver definitions */
/************************************************************************/
#include <dvihead.h>
/*----------------------------------------------------------------------*/
/* Device specific definitions */
/*----------------------------------------------------------------------*/
#define DECWINDOWS 1 /* cond. compilations flag */
#define BBNBITGRAPH 1 /* BITGRAPH driver as base */
#define VERSION_NO "2.10" /* DVI driver version number */
#define DEVICE_ID "DVI DECWindows 69 dpi"
/* String printed at runtime */
#define OUTFILE_EXT "DEC" /* Not used here (dummy) */
#define BYTE_SIZE 8 /* Not used here (dummy) */
/*----------------------------------------------------------------------*/
/* These constants are special to DVIBIT and are not req. by DVIDECW */
/*----------------------------------------------------------------------*/
#define FIRSTBGCHAR 32
#define LASTBGCHAR 127
#define NBGFONTS 3
/*----------------------------------------------------------------------*/
/* Page dimension definition */
/* Bitmap window size: 10" * 8" or 830 * 664 pixel (83 dpi) */
/* Bitmap window size: 12" * 9" or 828 * 621 pixel (69 dpi) */
/*----------------------------------------------------------------------*/
#define XDPI 69 /* horizontal dots/inch */
#define XPSIZE 9 /* horizontal screen size in " */
#define XSIZE (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
(2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
#define XWORDS ((XSIZE + HOST_WORD_SIZE -1)/HOST_WORD_SIZE)
#define YDPI 69 /* vertical dots/inch */
#define YPSIZE 12 /* vertical screen size in inch */
#define YSIZE (YDPI*YPSIZE) /* number vertical pixel */
#define XBIT ((1+2*XWORDS)/2) /* Printer bitmap (even col) */
#define YBIT YSIZE
#define MIN_DPI 69 /* Lowest resolution to display */
#define MAX_DPI 144 /* Highest res. to display */
/*----------------------------------------------------------------------*/
/* General definitions superseeding previous definitions */
/*----------------------------------------------------------------------*/
#undef STDRES /* 0 for low resolution device */
#define STDRES 0
/*----------------------------------------------------------------------*/
/* Coding starts here... */
/*----------------------------------------------------------------------*/
#include <bitmap.h> /* Bitmap definitions */
#include <main.h>
#if DECWINDOWS /* redefine STDMAG previously */
#undef STDMAG /* define in MAIN.H */
#if STDRES
#define STDMAG 500
#else /* STDMAG = dpi * 5 */
#define STDMAG 347 /* 83 dpi : STDMAG = 417 */
/* 69 dpi : STDMAG = 347 */
#endif /* STDRES */
#endif /* DECWINDOWS */
#include <abortrun.h>
#include <actfact.h>
#include <alldone.h>
/*----------------------------------------------------------------------*/
/* BOPACT begin of page actions */
/*----------------------------------------------------------------------*/
void bopact()
{
(void)clrbmap(); /* Clear bitmap memory */
pbghpos = pbgvpos = -99; /* set global values */
cpagep = (long)FTELL(dvifp) -1L;
ppagep = (long)nosignex(dvifp,(BYTE)4);
}
#include <chargf.h>
#include <charpk.h>
#include <charpxl.h>
#include <clrbmap.h>
#include <clrrow.h>
#include <dbgopen.h>
/*----------------------------------------------------------------------*/
/* DEVINIT initialize DEC Windows output */
/*----------------------------------------------------------------------*/
void devinit(argc,argv)
int argc; /* Command line argument count. */
char *argv[]; /* Pointers to command line args*/
{
int k;
XSizeHints xsh;
DwtInitializeDRM(); /* Init DRM first */
/* Init X Toolkit */
toplevel_widget = XtInitialize(APP_ID,"DVIDecw",NULL,
0,&argc,argv);
/* Open the UID file */
if(DwtOpenHierarchy(db_filename_num,db_filename_vec,NULL,
&s_DRMHierarchy) != DRMSuccess)
s_error("can't open hierarchy");
for (k=0;k<MAX_WIDGETS;k++) /* Init data structures */
widget_array[k] = NULL;
/* Register names to DRM */
DwtRegisterDRMNames(reglist, reglist_num);
/* Fetch all widgets */
if (DwtFetchWidget(s_DRMHierarchy, "TheMainWindow", toplevel_widget,
&main_window_widget, &dummy_class) != DRMSuccess)
s_error("can't fetch main window");
if (DwtFetchWidget(s_DRMHierarchy, "ClipboardMsg", toplevel_widget,
&widget_array[k_clipboard_msg], &dummy_class) != DRMSuccess)
s_error("can't fetch clipboard msg widget");
if (DwtFetchWidget(s_DRMHierarchy, "GotopageDlg", toplevel_widget,
&widget_array[k_goto_page_dlg], &dummy_class) != DRMSuccess)
s_error("can't fetch dialog box widget");
if (DwtFetchWidget(s_DRMHierarchy, "AboutMsg", toplevel_widget,
&widget_array[k_about_msg], &dummy_class) != DRMSuccess)
s_error("can't fetch info dialog box widget");
if (DwtFetchWidget(s_DRMHierarchy, "LastpageMsg", toplevel_widget,
&widget_array[k_lastpage_msg], &dummy_class) != DRMSuccess)
s_error("can't fetch lastpage msg box widget");
if (DwtFetchWidget(s_DRMHierarchy, "FirstpageMsg", toplevel_widget,
&widget_array[k_firstpage_msg], &dummy_class) != DRMSuccess)
s_error("can't fetch firstpage msg box widget");
if (DwtFetchWidget(s_DRMHierarchy, "ZoomrangeMsg", toplevel_widget,
&widget_array[k_zoomrange_msg], &dummy_class) != DRMSuccess)
s_error("can't fetch zoomrange msg box widget");
/* Manage all widgets */
XtManageChild(main_window_widget);
/* Display all widgets */
XtRealizeWidget(toplevel_widget);
/* Install accelerators */
XtInstallAllAccelerators(main_window_widget,main_window_widget);
/* Query handles */
display = XtDisplay(main_window_widget);
screen = XDefaultScreenOfDisplay(display);
gc = XDefaultGCOfScreen(screen);
top_wi = XtWindow(toplevel_widget);
/* Define fore/background colors*/
XSetForeground(display,gc,XBlackPixelOfScreen(screen));
XSetBackground(display,gc,XWhitePixelOfScreen(screen));
/* Set Position and Size */
xsh.x=1;
xsh.y=1;
/* Fit window width in screen */
if(XWidthOfScreen(screen) > XSIZE)
xsh.width=XSIZE;
else
xsh.width=XWidthOfScreen(screen);
/* Fit window height in screen */
if(XHeightOfScreen(screen) > YSIZE)
xsh.height=YSIZE;
else
xsh.height=XHeightOfScreen(screen);
xsh.flags=PPosition|PSize; /* Set Modification flag */
XSetNormalHints(display,top_wi,&xsh);
(void)getbmap(); /* Allocate bitmap memory */
/* Create X Image structure */
out_img = XCreateImage(display,XDefaultVisualOfScreen(screen),
1,XYBitmap,0,bitmap,XSIZE,YSIZE,
XBitmapPad(display),0);
/* Set image byte and bit order */
/* Comment Values are for VAX WS*/
out_img->byte_order = XImageByteOrder(display); /* LSBFirst*/
out_img->bitmap_bit_order = XBitmapBitOrder(display);/* MSBFirst*/
/* Mirror BitmapBitOrder bugfix */
if(out_img->bitmap_bit_order == MSBFirst)
out_img->bitmap_bit_order = LSBFirst;
else
out_img->bitmap_bit_order = MSBFirst;
/* Fetch text strings for menu */
slow_move = DwtLatin1String("Slow move");
fast_move = DwtLatin1String("Fast move");
no_offset = DwtLatin1String("No offset");
use_offset = DwtLatin1String("Use offset");
discard_dlg = DwtLatin1String("Discard Goto...");
gotopage_dlg = DwtLatin1String("Goto ...");
}
/*----------------------------------------------------------------------*/
/* DEVTERM terminate DEC Windows output */
/*----------------------------------------------------------------------*/
void devterm()
{
/* Terminate output window */
XDestroyImage(out_img);
XUnmapWindow(display,out_wi);
XDestroyWindow(display,out_wi);
}
#include <dispchar.h>
#include <dvifile.h>
#include <dviinit.h>
#include <dviterm.h>
#include <f20open.h>
#include <fatal.h>
#include <fillrect.h>
#include <findpost.h>
#include <fixpos.h>
#include <fontfile.h>
#include <fontsub.h>
#include <getbmap.h>
#include <getbytes.h>
#include <getfntdf.h>
#include <getpgtab.h>
#include <inch.h>
#include <initglob.h>
#include <loadchar.h>
#include <movedown.h>
#include <moveover.h>
#include <moveto.h>
/*----------------------------------------------------------------------*/
/* NEWFONT dummy routine called form readxx routines */
/*----------------------------------------------------------------------*/
void newfont()
{
}
#include <nosignex.h>
#include <openfont.h>
#include <option.h>
/*----------------------------------------------------------------------*/
/* PRTBMAP display created bitmap in output window */
/*----------------------------------------------------------------------*/
void prtbmap()
{
/*Copy bitmap to window */
XPutImage(display,out_wi,gc,out_img,0,0,0,0,
x_windsize,y_windsize);
}
#include <outrow.h>
#include <prtpage.h>
#include <readfont.h>
#include <readgf.h>
#include <readpk.h>
#include <readpost.h>
#include <readpxl.h>
#include <reldfont.h>
#include <rulepxl.h>
#include <setchar.h>
#include <setfntnm.h>
#include <setrule.h>
#include <signex.h>
#include <skgfspec.h>
#include <skipfont.h>
#include <skpkspec.h>
#include <special.h>
#include <strchr.h>
#include <strcm2.h>
#include <strid2.h>
#include <strrchr.h>
#include <tctos.h>
/*----------------------------------------------------------------------*/
/* UNLOADFONTS mark all fonts as unloaded */
/*----------------------------------------------------------------------*/
void unloadfonts() /* mark all fonts as not loaded */
{ /* and set no current fonts */
INT16 k; /* loop index */
for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
fontptr = fontptr->next)
{
for (k = 0; k < NPXLCHARS; ++k)
fontptr->ch[k].isloaded = FALSE;
if (fontptr->font_file_id != (FILE*)NULL)
{
(void)fclose(fontptr->font_file_id);
fontptr->font_file_id = (FILE*)NULL;
}
}
fontfp = (FILE*)NULL; /* no current font file */
for ( ; nopen > 0; --nopen) /* clear font file cache */
{
font_files[nopen].font_id = (FILE*)NULL;
font_files[nopen].use_count = (INT16)0;
}
/* NB: It is important here that the loop index be global; the relation
of fontptr to pfontptr is used by openfont() to decide whether the font
file is already open. */
for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
fontptr = fontptr->next)
{
pfontptr = (struct font_entry *)(NULL);
/* so reldfont() calls openfont() */
(void)reldfont(fontptr); /* get new font metrics */
}
}
#include <usage.h>
#include <warning.h>
/************************************************************************/
/* Service routines for DECWINDOWS environment */
/************************************************************************/
/*----------------------------------------------------------------------*/
/* S_ERROR put up an severe error message */
/*----------------------------------------------------------------------*/
static void s_error(char *problem_string)
{
printf("%s\n", problem_string);
exit(0);
}
/*----------------------------------------------------------------------*/
/* SCROLL_BAR callback routine to handle scrollbar event */
/*----------------------------------------------------------------------*/
static void scroll_bar_proc(Widget w,int *tag,unsigned long *reason)
{
int widget_num = *tag;
switch(widget_num)
{
case k_scroll_y: /* Get vertical slider position */
XtSetArg(arglist[0],DwtNvalue,&yscreen);
XtGetValues(w,arglist,1);
send_redraw();
break;
case k_scroll_x: /* Get horizontal slider position*/
XtSetArg(arglist[0],DwtNvalue,&xscreen);
XtGetValues(w,arglist,1);
send_redraw();
break;
default: /* Event is unknown */
break;
}
}
/*----------------------------------------------------------------------*/
/* CREATE_PROC callback routine to handle an create reason from UIL */
/*----------------------------------------------------------------------*/
static void create_proc(Widget w,int *tag,unsigned long *reason)
{
int widget_num = *tag; /* Convert tag to widget number.*/
widget_array[widget_num]= w; /* register widget handle */
}
/*----------------------------------------------------------------------*/
/* ACTIVATE_PROC callback routine to handle an activate reason from UIL */
/*----------------------------------------------------------------------*/
static void activate_proc(Widget w,int *tag,unsigned long *reason)
{
int widget_num = *tag; /* Convert tag to widget number.*/
int i, value;
int new_page_number; /* destination page number */
char *new_page_string; /* page number in string form */
int move_step_x; /* current step width for moves */
int move_step_y;
static BOOLEAN move_fast=FALSE;
static BOOLEAN offset=TRUE;
unsigned long data_id; /* Item/data identifier for */
unsigned long item_id; /* Clipboard operations */
unsigned long status; /* Clipboard operation status */
if(move_fast) /* Adjust step width for moves */
{
move_step_y = y_windsize;
move_step_x = x_windsize;
}
else
{
move_step_y = y_windsize/10;
move_step_x = x_windsize/10;
}
switch (widget_num)
{
case k_about_me: /* show info on DVIDECW */
XtManageChild(widget_array[k_about_msg]);
break;
case k_about_button: /* close info on DVIDECW */
XtUnmanageChild(widget_array[k_about_msg]);
break;
case k_quit_me: /* Menu File/Quit */
(void)devterm(); /* terminate device output */
(void)dviterm(); /* terminate DVI file processing*/
(void)alldone(); /* this will never return */
break;
case k_copy_me: /* perform copy to clibboard */
status=DwtBeginCopyToClipboard(display,out_wi,APP_ID,
(Widget)0,(VoidProc)0,&item_id);
if(status != ClipboardSuccess)
{
XtManageChild(widget_array[k_clipboard_msg]);
break;
}
status=DwtCopyToClipboard(display,out_wi,item_id,
CLPBRD_FORMAT,bitmap,
(unsigned long)(XSIZE*YSIZE),
0,&data_id);
if(status != ClipboardSuccess)
{
XtManageChild(widget_array[k_clipboard_msg]);
break;
}
status=DwtEndCopyToClipboard(display,out_wi,item_id);
if(status != ClipboardSuccess)
{
XtManageChild(widget_array[k_clipboard_msg]);
}
break;
case k_prevpage_me: /* goto previous page (if avail)*/
if(cur_index > 0)
{
cur_index--;
cur_page_number--;
send_redraw();
}
else /* first page reached already */
XtManageChild(widget_array[k_firstpage_msg]);
break;
case k_nextpage_me: /* goto next page (if avail) */
if(cur_index < page_count-1)
{
cur_index++;
cur_page_number++;
send_redraw();
}
else /* last page reached already */
XtManageChild(widget_array[k_lastpage_msg]);
break;
case k_gotopage_me: /* open gotopage dialog box */
if(XtIsManaged(widget_array[k_goto_page_dlg]))
{
XtUnmanageChild(widget_array[k_goto_page_dlg]);
XtSetArg(arglist[0],DwtNlabel,gotopage_dlg);
XtSetValues(widget_array[k_gotopage_me],arglist,1);
}
else
{
XtManageChild(widget_array[k_goto_page_dlg]);
XtSetArg(arglist[0],DwtNlabel,discard_dlg);
XtSetValues(widget_array[k_gotopage_me],arglist,1);
}
break;
case k_ok_button: /* dialog box left by ok button */
new_page_string = DwtSTextGetString(widget_array[k_pagenumber]);
new_page_number = 0;
sscanf(new_page_string,"%d",&new_page_number);
if(new_page_number > page_count)
new_page_number = page_count;
if(new_page_number < 1)
new_page_number = 1;
cur_index = new_page_number - 1;
cur_page_number = new_page_number;
sprintf(new_page_string,"%d",new_page_number);
DwtSTextSetString(widget_array[k_pagenumber],new_page_string);
XtUnmanageChild(widget_array[k_goto_page_dlg]);
XtSetArg(arglist[0],DwtNlabel,gotopage_dlg);
XtSetValues(widget_array[k_gotopage_me],arglist,1);
send_redraw();
break;
case k_goto_button: /* dialog box left by go button */
new_page_string = DwtSTextGetString(widget_array[k_pagenumber]);
new_page_number = 0;
sscanf(new_page_string,"%d",&new_page_number);
if(new_page_number > page_count)
new_page_number = page_count;
if(new_page_number < 1)
new_page_number = 1;
cur_index = new_page_number - 1;
cur_page_number = new_page_number;
sprintf(new_page_string,"%d",new_page_number);
DwtSTextSetString(widget_array[k_pagenumber],new_page_string);
send_redraw();
break;
case k_cancel_button: /* dialog box cancelled */
XtUnmanageChild(widget_array[k_goto_page_dlg]);
XtSetArg(arglist[0],DwtNlabel,gotopage_dlg);
XtSetValues(widget_array[k_gotopage_me],arglist,1);
break;
case k_zoom_out_me: /* Zoom down one magstep */
runmag=MAGSIZE(actfact((UNSIGN32)((5*runmag)/6)));
conv = ((float)num/(float)den) *
((float)runmag/(float)STDMAG) *
#if USEGLOBALMAG
actfact(mag) *
#endif
((float)RESOLUTION/254000.0);
/* Constrain resolution range */
if((int)((runmag*10/5+5)/10) < MIN_DPI)
XtManageChild(widget_array[k_zoomrange_msg]);
(void)unloadfonts();
send_redraw();
break;
case k_zoom_in_me: /* Zoom up one magstep */
runmag=MAGSIZE(actfact((UNSIGN32)((6*runmag)/5)));
conv = ((float)num/(float)den) *
((float)runmag/(float)STDMAG) *
#if USEGLOBALMAG
actfact(mag) *
#endif
((float)RESOLUTION/254000.0);
/* Constrain resolution range */
if((int)((runmag*10/5+5)/10) > MAX_DPI)
XtManageChild(widget_array[k_zoomrange_msg]);
(void)unloadfonts();
send_redraw();
break;
case k_bot_page_me: /* goto bottom of page */
yscreen = y_pagesize - y_windsize;
send_redraw();
break;
case k_top_page_me: /* goto top of page */
yscreen = 0;
send_redraw();
break;
case k_curs_up_me: /* move up one step */
yscreen -= move_step_y;
send_redraw();
break;
case k_curs_down_me: /* move down one step */
yscreen += move_step_y;
send_redraw();
break;
case k_curs_left_me: /* move left one step */
xscreen -= move_step_x;
send_redraw();
break;
case k_curs_right_me: /* move right one step */
xscreen += move_step_x;
send_redraw();
break;
case k_offset_me: /* toggle use/dont't use offs */
if(offset == TRUE)
{
lmargin = (COORDINATE)(0.1*((float)XDPI));
tmargin = (COORDINATE)(0.1*((float)YDPI));
XtSetArg(arglist[0],DwtNlabel,use_offset);
XtSetValues(widget_array[k_offset_me],arglist,1);
offset=FALSE;
send_redraw();
}
else
{
lmargin = (COORDINATE)(leftmargin*((float)XDPI));
tmargin = (COORDINATE)(topmargin *((float)YDPI));
XtSetArg(arglist[0],DwtNlabel,no_offset);
XtSetValues(widget_array[k_offset_me],arglist,1);
offset=TRUE;
send_redraw();
}
break;
case k_move_speed_me: /* toggle fast/slow cursor moves*/
if(move_fast == TRUE)
{
XtSetArg(arglist[0],DwtNlabel,fast_move);
XtSetValues(widget_array[k_move_speed_me],arglist,1);
move_fast = FALSE;
}
else
{
XtSetArg(arglist[0],DwtNlabel,slow_move);
XtSetValues(widget_array[k_move_speed_me],arglist,1);
move_fast = TRUE;
}
break;
case k_reset_pos_me: /* reset position after moves */
xscreen = 0;
yscreen = 0;
send_redraw();
break;
default: /* event is unknown */
break;
}
}
/*----------------------------------------------------------------------*/
/* SEND_REDRAW sends a redraw message to output window */
/*----------------------------------------------------------------------*/
void send_redraw()
{
XEvent event; /* event record for send event */
event.type = Expose;
event.xexpose.send_event = TRUE;
event.xexpose.display = display;
event.xexpose.window = out_wi;
event.xexpose.x = 0;
event.xexpose.y = 0;
event.xexpose.width = x_windsize;
event.xexpose.height = y_windsize;
event.xexpose.count = 0;
XSendEvent(display,out_wi,TRUE,ExposureMask,&event);
}
/*----------------------------------------------------------------------*/
/* OUTPUT_EXPOSED_PROC react on Tex Output window exposure event */
/*----------------------------------------------------------------------*/
static void output_exp_proc(Widget w,int *tag,
DwtAnyCallbackStruct *callback_data)
{
static BOOLEAN first = TRUE; /* Flag for first time execution*/
char out_string[128]; /* string for messages */
XWindowAttributes xwa; /* Window attrib. structure */
XSizeHints xsh;
int x_top_windsize;
int y_top_windsize;
if(first) /* Do this only once */
{
first = FALSE;
out_wi = XtWindow(w); /* Inquire window handle */
XMapWindow(display,out_wi); /* Set mapping */
XClearWindow(display,out_wi); /* Clear window */
}
/* Get windowsize in pxl */
XGetWindowAttributes(display,out_wi,&xwa);
x_windsize = xwa.width;
y_windsize = xwa.height;
/* Get topwindow size in pxl */
XGetWindowAttributes(display,top_wi,&xwa);
x_top_windsize = xwa.width;
y_top_windsize = xwa.height;
/* Get pagesize in pxl */
x_pagesize = (int)((runmag*10/5+5)/10)*XPSIZE;
y_pagesize = (int)((runmag*10/5+5)/10)*YPSIZE;
/* Resize window if required */
if(x_top_windsize > x_pagesize || y_top_windsize > y_pagesize)
{ /* Fit window width in screen */
if(x_top_windsize > x_pagesize && y_top_windsize <= y_pagesize)
XResizeWindow(display,out_wi,x_pagesize,y_top_windsize);
if(x_top_windsize <= x_pagesize && y_top_windsize > y_pagesize)
XResizeWindow(display,out_wi,x_top_windsize,y_pagesize);
if(x_top_windsize > x_pagesize && y_top_windsize > y_pagesize)
XResizeWindow(display,out_wi,x_pagesize,y_pagesize);
}
/* Constrain view range */
if(xscreen < 0)
xscreen = 0;
if(xscreen > (x_pagesize - x_windsize))
xscreen = x_pagesize - x_windsize;
if(yscreen < 0)
yscreen = 0;
if(yscreen > (y_pagesize-y_windsize))
yscreen = y_pagesize-y_windsize;
/* Set horiz. scrollbar values */
XtSetArg(arglist[0],DwtNshown,x_windsize);
XtSetArg(arglist[1],DwtNmaxValue,x_pagesize);
XtSetArg(arglist[2],DwtNvalue,xscreen);
XtSetArg(arglist[3],DwtNinc,x_windsize/10);
XtSetArg(arglist[4],DwtNpageInc,x_windsize);
XtSetValues(widget_array[k_scroll_x],arglist,5);
/* Set vertic. scrollbar values */
XtSetArg(arglist[0],DwtNshown,y_windsize);
XtSetArg(arglist[1],DwtNmaxValue,y_pagesize);
XtSetArg(arglist[2],DwtNvalue,yscreen);
XtSetArg(arglist[3],DwtNinc,y_windsize/10);
XtSetArg(arglist[4],DwtNpageInc,y_windsize);
XtSetValues(widget_array[k_scroll_y],arglist,5);
/* Prepare window title bar */
/* Create page image bitmap */
prtpage(page_ptr[cur_index]);
/* Display page image bitmap */
sprintf(out_string,"TeX Preview - Page %d/%d TeX-Page[%s] %d dpi",
cur_index+1,page_count,tctos(),(int)((runmag*10/5+5)/10));
XStoreName(display,top_wi,out_string);
prtbmap();
}
/************************************************************************/
/* END of source file */
/************************************************************************/