home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / CreativeComputers.iso / shareware / text / dvi_3.62 / source / dvisrc.lha / dvimotif.c < prev    next >
C/C++ Source or Header  |  1994-01-11  |  30KB  |  1,025 lines

  1. /*
  2. ** Datei: DVIMOTIF.C
  3. ** Autor: Ingo Eichenseher
  4. **        Gerhard Wilhelms, 27.8.92
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdarg.h>
  9. #include <setjmp.h>
  10. #include <stdlib.h>
  11. #include <Xm/Xm.h>
  12.  
  13. #include <X11/Xlib.h>
  14. #include <X11/Xutil.h>
  15.  
  16. #include <X11/Shell.h>
  17. #include <Xm/ArrowB.h>
  18. #include <Xm/CascadeB.h>
  19. #include <Xm/DrawingA.h>
  20. #include <Xm/FileSB.h>
  21. #include <Xm/Form.h>
  22. #include <Xm/Frame.h>
  23. #include <Xm/Label.h>
  24. #include <Xm/MainW.h>
  25. #include <Xm/MenuShell.h>
  26. #include <Xm/PushB.h>
  27. #include <Xm/RowColumn.h>
  28. #include <Xm/ScrollBar.h>
  29. #include <Xm/ScrolledW.h>
  30. #include <Xm/SelectioB.h>
  31. #include <Xm/Separator.h>
  32. #include <Xm/Text.h>
  33. #include <Xm/ToggleB.h>
  34.  
  35. #include "dvi.h"
  36. #include "dvidvi.h"
  37. #include "dviframe.h"
  38. #include "dvihdcp.h"
  39. #include "dvimisc.h"
  40. #include "dvisplin.h"
  41. #include "dvidraw.h"
  42.  
  43. #define APPL_CLASS "XDvi"
  44. #define X_MAGIC 0x21021961
  45. #define DEFAULT_WIDTH   800
  46. #define DEFAULT_HEIGHT  900
  47.  
  48. static char *thePath;
  49. static int theScreen;
  50. static Widget graphicW, textW, fileSelW, nameW, dispShell,PopupMenuW;
  51. static Widget traceMemW, traceFontsW, dviMemW, traceCharsW;
  52. static Widget sh_NULLW, sh_p6lowW, sh_p6highW, sh_p6midW, sh_fx80W,
  53.           sh_shipfileW, sh_hpljW, sh_hpljlowW, sh_bj300W,
  54.           sh_null_deviceW;
  55. static GC theGC;
  56. static Display *theDisplay;
  57. static XImage *theImage = NULL;
  58. static int last_page = 0;
  59. static XmString theString;
  60. static int PageIsOpen = 0;
  61. static Screen *defaultScreen;
  62. static int Image_x=0, Image_y=0;
  63. static int Press_x, Press_y, Ipress_x, Ipress_y;
  64.  
  65. static void initImage(void);
  66. void initWidgetBaum();
  67. void initDviOutWindow();
  68. void exitDviOutWindow();
  69. void initPopupMenu();
  70. void exposeCB(Widget widget, caddr_t clientDaten, caddr_t aufrufDaten);
  71. void destroyCB();
  72. void resizeCB(Widget widget, caddr_t clientDaten, caddr_t aufrufDaten);
  73. void inversCB();
  74. void exitCB(Widget widget, caddr_t clientDaten, caddr_t aufrufDaten);
  75. void moveImageCB();
  76.  
  77. char printer_filename[512]; /****/
  78.  
  79. typedef struct
  80. {
  81.     char   *mask;
  82.     void   (*callback)(char *name);
  83. } fileSel_t;
  84.  
  85. typedef struct
  86. {
  87.     void (*callback)(char *string);
  88.     char *str_to_change;
  89.     long *long_to_change;
  90.     real *dimen_to_change;
  91.     int  clean;
  92. } dialog_t;
  93.  
  94. typedef struct
  95. {
  96.     int (*function)(void);
  97. } driver_t;
  98.  
  99. Widget initForm(Widget);
  100. Widget initDispForm(Widget);
  101. Widget initMenu(Widget);
  102. Widget initFileSelector(Widget);
  103.  
  104. static driver_t null_d = { NULL };
  105. static driver_t p6low_d = { p6low };
  106. static driver_t p6mid_d = { p6mid };
  107. static driver_t p6high_d = { p6high };
  108. static driver_t fx80_d = { fx80 };
  109. static driver_t shipfile_d = { shipfile };
  110. static driver_t hplj_d = { hplj };
  111. static driver_t hpljlow_d = { hpljlow };
  112. static driver_t bj300_d = { bj300 };
  113. static driver_t null_device_d = { null_device };
  114.  
  115.  
  116. static void new_dvi_file(char *name);
  117. static void read_opt_file(char *name);
  118. static void write_opt_file(char *name);
  119. static void new_log_file(char *name);
  120. static void pageCB(char *string);
  121. static void formatCB(char *string);
  122.  
  123. static dialog_t printer_dialog = { NULL, printer_filename, NULL, NULL, 0};/****/
  124. static dialog_t page_dialog = { pageCB, NULL, NULL, NULL, 0 };
  125. static dialog_t maximum_dialog = { NULL, NULL, &op.maxmem, NULL, 1 };
  126. static dialog_t clippath_dialog = { NULL, NULL, &op.pathmem, NULL, 1 };
  127. static dialog_t pkpath_dialog = { NULL, op.pk_path, NULL, NULL, 1 }; 
  128. static dialog_t tfmpath_dialog = { NULL, op.tfm_path, NULL, NULL, 1 }; 
  129. static dialog_t vfpath_dialog = { NULL, op.vf_path, NULL, NULL, 1 }; 
  130. static dialog_t dvipath_dialog = { NULL, op.dvi_path, NULL, NULL, 1 }; 
  131. static dialog_t imgpath_dialog = { NULL, op.img_path, NULL, NULL, 0 }; 
  132. static dialog_t grpath_dialog = { NULL, op.input_path, NULL, NULL, 0 }; 
  133. static dialog_t mag_dialog = { NULL, NULL, &op.new_mag, NULL, 1 };
  134. static dialog_t hres_dialog = { NULL, NULL, &op.hres, NULL, 1 };
  135. static dialog_t vres_dialog = { NULL, NULL, &op.vres, NULL, 1 };
  136. static dialog_t hoff_dialog = { NULL, NULL, NULL, &op.hoffset, 1 };
  137. static dialog_t voff_dialog = { NULL, NULL, NULL, &op.voffset, 1 };
  138. static dialog_t hspread_dialog = { NULL, NULL, NULL, &op.hspread, 1 };
  139. static dialog_t vspread_dialog = { NULL, NULL, NULL, &op.vspread, 1 };
  140. static dialog_t format_dialog = { formatCB, NULL, NULL, NULL, 0 };
  141.  
  142. static fileSel_t fileSelDvi = { "*.dvi",  new_dvi_file };
  143. static fileSel_t fileSelRopt = { "*.dvo",  read_opt_file };
  144. static fileSel_t fileSelWopt = { "*.dvo",  write_opt_file };
  145. static fileSel_t fileSelLog = { "*.log", new_log_file };
  146. static void (*currentFileSelCB)(char *name) = NULL;
  147.  
  148. static jmp_buf halt_jmp;
  149.  
  150. void halt(char *format, ...)
  151. {
  152.     va_list l;
  153.     va_start(l,format);
  154.     vprint(format,l);
  155.     va_end(l);
  156.     longjmp(halt_jmp,1);
  157. }
  158.  
  159. void set_filename(char *name)
  160. {
  161.     static char *old_name = NULL, *short_name = NULL;
  162.  
  163.     Arg         args[10];
  164.     Cardinal    n;
  165.  
  166.     if (old_name!=NULL) XtFree(old_name);
  167.     if (short_name!=NULL) XtFree(short_name);
  168.     old_name = XtNewString(name);
  169.     short_name = XtNewString(fname(name));
  170.  
  171.     n = 0;
  172.     XtSetArg(args[n],XmNtitle,old_name); n++;
  173.     XtSetArg(args[n],XmNiconName,short_name); n++;
  174.     XtSetValues(dispShell,args,n);
  175. }
  176.  
  177. void out_string(char *string)
  178. {
  179.     int     n;
  180.     Arg     args[10];
  181.     XmTextPosition pos;
  182.  
  183.     pos = XmTextGetLastPosition(textW);
  184.     XmTextInsert(textW,pos,string);
  185.     XmTextShowPosition(textW,pos);
  186.     XmTextSetInsertionPosition(textW,pos);
  187. }
  188.  
  189. void out_newline(void)
  190. {
  191.     out_string("\n");
  192. }
  193.  
  194. void prbyte(int c) /****/
  195. {
  196.     static FILE *printer_fp = NULL;
  197.  
  198. /*
  199.     if (printer_fp==NULL)
  200.     {
  201.     printer_fp = popen(printer_filename, "w");
  202.     if (printer_fp==NULL)
  203.     {
  204.         fprintf(stderr, "Cannot pipe to %s\n", printer_filename);
  205.         exit(1);
  206.     }
  207.     puts("Printer open");
  208.     }
  209.     putchar('*');
  210.     putc(c, printer_fp);
  211. */
  212. }
  213.  
  214. int stop_key(void)
  215. {
  216.     return 0;
  217. }
  218.  
  219. int wait_for_sheet(void)
  220. {
  221.     return 0;
  222. }
  223.  
  224. real get_dimen(char *string, real old_value)
  225. {
  226.     char c, *s;
  227.     real r, dimen;
  228.  
  229.     while(isspace(*string)) string++;
  230.     s = string;
  231.     while(isdigit(*s) || *s=='.') s++;
  232.     if (s==string) return old_value;
  233.  
  234.     strlwr(s); c = *s; *s = 0; r = atof(string); *s = c;
  235.     while(isspace(*s)) s++;
  236.     if (r==0.0 && *s=='\0') dimen = 0.0;
  237.     else if (!strcmp(s,"in")) dimen = r;
  238.     else if (!strcmp(s,"cm")) dimen = r/2.54;
  239.     else if (!strcmp(s,"pt")) dimen = r/72.27;
  240.     else if (!strcmp(s,"pc")) dimen = r*12.0/72.27;
  241.     else if (!strcmp(s,"bp")) dimen = r/72.0;
  242.     else if (!strcmp(s,"mm")) dimen = r/25.4;
  243.     else if (!strcmp(s,"dd")) dimen = r*1238.0/72.27;
  244.     else if (!strcmp(s,"cc")) dimen = r*12*1238.0/72.27;
  245.     else if (!strcmp(s,"sp")) dimen = r/72.27/65536.0;
  246.     else return old_value;
  247.  
  248.     return dimen;
  249. }
  250.  
  251. static void print_pages(int first, int last, int step)
  252. {
  253.     if (*dvi_name=='\0') return;
  254.     last_page = format_pages(first,last,step);
  255.  
  256.     if (shipout==NULL) 
  257.     {
  258.     initDviOutWindow();
  259.     exposeCB(graphicW,(XtPointer)NULL,(XtPointer)NULL);
  260.     }
  261.     else exitDviOutWindow();
  262. }
  263.  
  264. int main(int argc, char **argv)
  265. {
  266.     XtAppContext    kontext;
  267.     Widget          applShell;
  268.     Cardinal        argcTmp;
  269.     String         *argvTmp;
  270.     int             i;
  271.     Arg             args[10];
  272.     char        ver[64];
  273.     Cardinal        n;
  274.  
  275.     char            *opt_name = "dvi.dvo";
  276.  
  277.     thePath = getenv("PATH");
  278.     sprintf(ver,"Dvi (Version %s)",version_string);
  279.  
  280.     if( !gr_install() )
  281.         exit(1);
  282.  
  283.     XtToolkitInitialize();
  284.     kontext = XtCreateApplicationContext();
  285.     argcTmp = argc;
  286.     argvTmp = (String*)XtMalloc((Cardinal)(argc*sizeof(String)));
  287.     for (i=0; i<argc; i++)
  288.     argvTmp[i] = XtNewString(argv[i]);
  289.  
  290.     theDisplay = XtOpenDisplay(kontext,(String)NULL,(String)NULL,
  291.     APPL_CLASS,(XrmOptionDescRec*)NULL,(Cardinal)0,(&argc),argv);
  292.  
  293.     defaultScreen = DefaultScreenOfDisplay(theDisplay);
  294.  
  295.     if (theDisplay==NULL)
  296.     {
  297.     fprintf(stderr,"Cannot open display\n");
  298.     exit(1);
  299.     }
  300.  
  301.     n = 0;
  302.     XtSetArg(args[n], XmNargc, argcTmp); n++;
  303.     XtSetArg(args[n], XmNargv, argvTmp); n++;
  304.     XtSetArg(args[n], XmNiconName,"Dvi"); n++;
  305.     XtSetArg(args[n], XmNtitle,ver); n++;
  306.     XtSetArg(args[n], XmNscreen, defaultScreen); n++;
  307.     applShell = XtAppCreateShell("dviPanel", APPL_CLASS,
  308.     applicationShellWidgetClass, theDisplay, args, n);
  309.  
  310.     theScreen = DefaultScreen(theDisplay);
  311.  
  312.     initWidgetBaum(applShell);
  313.  
  314.     theGC = DefaultGCOfScreen(defaultScreen);
  315.  
  316.     XtRealizeWidget(applShell);
  317.  
  318.     argc--; argv++;
  319.  
  320.     while(argc>0 && **argv=='-')
  321.     {
  322.     switch(tolower(argv[0][1]))
  323.     {
  324.         case 'o' :
  325.         opt_name = argv[0]+2;
  326.         break;
  327.     }
  328.     argc--; argv++;
  329.     }
  330.  
  331.     if (argc>0)
  332.     {
  333.     strcpy(dvi_name,*argv);
  334.     argc--; argv++;
  335.     }
  336.  
  337.     read_opt_file(opt_name);
  338.  
  339.     if (setjmp(halt_jmp)==0)
  340.     if (*dvi_name && shipout==NULL)
  341.        print_pages(1,1,1);
  342.  
  343.     XtAppMainLoop(kontext);
  344.  
  345.     dvi_clean();
  346.  
  347.     gr_destall();
  348.  
  349.     exit(0);
  350. }
  351.  
  352.  
  353. static void initImage(void)
  354. {
  355.     Image_x = Image_y = 0;
  356.  
  357.     theImage = XCreateImage(theDisplay,
  358.     DefaultVisual(theDisplay,theScreen),1,XYBitmap,
  359.         0,(char*)frame_buffer,frame_width*8,frame_height,16,frame_width);
  360. }
  361.  
  362.  
  363. static void exitImage(void)
  364. {
  365.     if (theImage!=NULL) XDestroyImage(theImage);
  366.     theImage = NULL;
  367. }
  368.  
  369. static void next_page(int diff)
  370. {
  371.     if (shipout==NULL)
  372.     {
  373.     int first;
  374.  
  375.     if (frame_valid && last_page && last_page+diff>0 && dvi_info.valid)
  376.         first = last_page + diff;
  377.     else first = 1;
  378.     print_pages(first,first,1);
  379.     }
  380. }
  381.  
  382. static void prevPageCB(Widget w, caddr_t clientData, caddr_t callData)
  383. {
  384.     next_page(-1);
  385. }
  386.  
  387. static void nextPageCB(Widget w, caddr_t clientData, caddr_t callData)
  388. {
  389.     next_page(1);
  390. }
  391.  
  392. void toggle_traceFonts(Widget w, caddr_t clientData, caddr_t callData)
  393. {
  394.     XmToggleButtonCallbackStruct *cb = (XmToggleButtonCallbackStruct*)callData;
  395.     op.showfonts = cb->set ? 1:0;
  396. }
  397.  
  398. void toggle_traceMemory(Widget w, caddr_t clientData, caddr_t callData)
  399. {
  400.     XmToggleButtonCallbackStruct *cb = (XmToggleButtonCallbackStruct*)callData;
  401.     op.tracemem = cb->set ? 1:0;
  402. }
  403.  
  404. void toggle_dviMemory(Widget w, caddr_t clientData, caddr_t callData)
  405. {
  406.     XmToggleButtonCallbackStruct *cb = (XmToggleButtonCallbackStruct*)callData;
  407.     op.dvimemory = cb->set ? 1:0;
  408. }
  409.  
  410. void toggle_traceChars(Widget w, caddr_t clientData, caddr_t callData)
  411. {
  412.     XmToggleButtonCallbackStruct *cb = (XmToggleButtonCallbackStruct*)callData;
  413.     op.tracechars = cb->set ? 1:0;
  414. }
  415.  
  416. void set_toggles(void)
  417. {
  418.     Arg args[1];
  419.     Cardinal n = 1;
  420.  
  421.     XtSetArg(args[0], XmNset, op.showfonts ? True:False);
  422.     XtSetValues(traceFontsW, args, n);
  423.     XtSetArg(args[0], XmNset, op.tracemem ? True:False);
  424.     XtSetValues(traceMemW, args, n);
  425.     XtSetArg(args[0], XmNset, op.dvimemory ? True:False);
  426.     XtSetValues(dviMemW, args, n);
  427.     XtSetArg(args[0], XmNset, op.tracechars ? True:False);
  428.     XtSetValues(traceCharsW, args, n);
  429.     XtSetArg(args[0], XmNset, shipout==NULL ? True:False); 
  430.     XtSetValues(sh_NULLW, args, n);
  431.     XtSetArg(args[0], XmNset, shipout==p6low ? True:False); 
  432.     XtSetValues(sh_p6lowW, args, n);
  433.     XtSetArg(args[0], XmNset, shipout==p6high ? True:False); 
  434.     XtSetValues(sh_p6highW, args, n);
  435.     XtSetArg(args[0], XmNset, shipout==p6mid ? True:False); 
  436.     XtSetValues(sh_p6midW, args, n);
  437.     XtSetArg(args[0], XmNset, shipout==fx80 ? True:False); 
  438.     XtSetValues(sh_fx80W, args, n);
  439.     XtSetArg(args[0], XmNset, shipout==shipfile ? True:False); 
  440.     XtSetValues(sh_shipfileW, args, n);
  441.     XtSetArg(args[0], XmNset, shipout==hplj ? True:False); 
  442.     XtSetValues(sh_hpljW, args, n);
  443.     XtSetArg(args[0], XmNset, shipout==hpljlow ? True:False); 
  444.     XtSetValues(sh_hpljlowW, args, n);
  445.     XtSetArg(args[0], XmNset, shipout==bj300 ? True:False); 
  446.     XtSetValues(sh_bj300W, args, n);
  447.     XtSetArg(args[0], XmNset, shipout==null_device ? True:False); 
  448.     XtSetValues(sh_null_deviceW, args, n);
  449. }
  450.  
  451. static void pageCB(char *string)
  452. {
  453.     if (shipout==NULL)
  454.     {
  455.     int no = atoi(string);
  456.     if (no>0) print_pages(no,no,1);
  457.     }
  458. }
  459.  
  460. void shipoutCB(Widget w, caddr_t clientData, caddr_t callData)
  461. {
  462.     XmToggleButtonCallbackStruct *t = (XmToggleButtonCallbackStruct*)callData;
  463.     if (t->set) shipout = ((driver_t*)clientData)->function;
  464. }
  465.  
  466. static void formatCB(char *string)
  467. {
  468.     int first, last, step=1;
  469.     char *p = strtok(string," \t\n,");
  470.     if (p==NULL) first = 1, last = 9999;
  471.     else 
  472.     {
  473.     first = atoi(p);
  474.     if (first<1) first = 1;
  475.     last = first;
  476.     step = 1;
  477.     if ( (p=strtok(NULL," \t\n,"))!=NULL)
  478.     {
  479.         last = atoi(p);
  480.         if (last<first) last = first;
  481.         if ( (p=strtok(NULL," \t\n,"))!=NULL)
  482.         {
  483.         step = atoi(p);
  484.         if (step<1) step = 1;
  485.         }
  486.     }
  487.     }
  488.     print_pages(first,last,step);
  489. }
  490.  
  491. void updateCB(Widget w, caddr_t clientData, caddr_t callData)
  492. {
  493.     dvi_clean();
  494.     exitImage();
  495.     if (shipout==NULL)
  496.     {
  497.     if (last_page<=0) last_page = 1;
  498.     print_pages(last_page,last_page,1);
  499.     }
  500. }
  501.  
  502. static void new_dvi_file(char *name)
  503. {
  504.     exitDviOutWindow();
  505.     strcpy(dvi_name,name);
  506.     if (shipout==NULL) print_pages(1,1,1);
  507. }
  508.  
  509. static void new_log_file(char *name)
  510. {
  511.     dvi_clean();
  512.     strcpy(op.log_name,name);
  513. }
  514.  
  515. static void write_opt_file(char *name)
  516. {
  517.     FILE *fp = fopen(name,"wb");
  518.  
  519.     if (fp!=NULL)
  520.     {
  521.     op.magic = X_MAGIC;
  522.     if (shipout==p6low) op.shipno=1;
  523.     else if (shipout==p6high) op.shipno=2;
  524.     else if (shipout==p6mid) op.shipno=3;
  525.     else if (shipout==fx80) op.shipno=4;
  526.     else if (shipout==shipfile) op.shipno=5;
  527.     else if (shipout==hplj) op.shipno=6;
  528.     else if (shipout==hpljlow) op.shipno=7;
  529.     else if (shipout==bj300) op.shipno=8;
  530.     else if (shipout==null_device) op.shipno=9;
  531.     else op.shipno=0;
  532.     fwrite(&op,sizeof(op),1,fp);
  533.     fclose(fp);
  534.     }
  535. }
  536.  
  537. static void read_opt_file(char *name)
  538. {
  539.     FILE *fp = fopene(name,"rb",thePath,(char*)NULL);
  540.  
  541.     if (fp!=NULL)
  542.     {
  543.     options new_op;
  544.     size_t bytes = fread(&new_op,sizeof(op),1,fp);
  545.     if (bytes!=1 || new_op.magic!=X_MAGIC)
  546.     {
  547.         print("Invalid optionfile %s",name);
  548.     }
  549.     else
  550.     {
  551.         op = new_op;
  552.         dvi_clean();
  553.         set_toggles();
  554.         switch(op.shipno)
  555.         {
  556.         case 1: shipout=p6low; break;
  557.         case 2: shipout=p6high; break;
  558.         case 3: shipout=p6mid; break;
  559.         case 4: shipout=fx80; break;
  560.         case 5: shipout=shipfile; break;
  561.         case 6: shipout=hplj; break;
  562.         case 7: shipout=hpljlow; break;
  563.         case 8: shipout=bj300; break;
  564.         case 9: shipout=null_device; break;
  565.         default: shipout=NULL;
  566.         }
  567.     }
  568.     }
  569.     else print("Cannot read Optionfile %s",name);
  570. }
  571.  
  572. void eingabeCB(Widget widget, caddr_t clientData, caddr_t callData)
  573. {
  574.     XmSelectionBoxCallbackStruct *SBinfos;
  575.     String input_string;
  576.     dialog_t *d = *(dialog_t**)clientData;
  577.  
  578.     SBinfos = (XmSelectionBoxCallbackStruct*)callData;
  579.     XmStringGetLtoR(SBinfos->value,XmSTRING_DEFAULT_CHARSET, &input_string);
  580.     if (d->callback!=NULL) (*d->callback)(input_string);
  581.     if (d->str_to_change!=NULL) strcpy(d->str_to_change,input_string);
  582.     if (d->long_to_change!=NULL) *(d->long_to_change) = atol(input_string);
  583.     if (d->dimen_to_change!=NULL) *(d->dimen_to_change) = 
  584.     get_dimen(input_string,*(d->dimen_to_change));
  585.     XtFree(input_string);
  586.     if (d->clean) exitDviOutWindow();
  587. }
  588.  
  589. void doDialog(Widget widget, caddr_t clientData, caddr_t callData)
  590. {
  591.     static Widget eingabeW = NULL, textW;
  592.     static dialog_t *currentClientData;
  593.     char default_text[128];
  594.     Arg           args[10];
  595.     Cardinal      n;
  596.  
  597.     currentClientData = (dialog_t*)clientData;
  598.  
  599.     if (eingabeW==NULL)
  600.     {
  601.     n = 0;
  602.     XtSetArg(args[n], XmNautoUnmanage, True); n++;
  603.     XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++;
  604.     eingabeW = XmCreatePromptDialog(widget,"Input",args,n);
  605.     XtAddCallback(eingabeW,XmNokCallback, (XtCallbackProc)eingabeCB, (XtPointer)¤tClientData);
  606.     XtUnmanageChild(XmSelectionBoxGetChild(eingabeW,XmDIALOG_HELP_BUTTON));
  607.     textW = XmSelectionBoxGetChild(eingabeW,XmDIALOG_TEXT);
  608.     }
  609.     if (currentClientData->str_to_change!=NULL) 
  610.     strcpy(default_text,currentClientData->str_to_change);
  611.     else if (currentClientData->long_to_change!=NULL)
  612.     sprintf(default_text,"%ld",*currentClientData->long_to_change);
  613.     else if (currentClientData->dimen_to_change!=NULL)
  614.     sprintf(default_text,"%fin",(double)*currentClientData->dimen_to_change);
  615.     else *default_text = '\0';
  616.     XmTextSetString(textW,default_text);
  617.     XtManageChild(eingabeW);
  618. }
  619.  
  620. void unmanageCB(Widget w, caddr_t clientData, caddr_t callData)
  621. {
  622.     XtUnmanageChild(w);
  623. }
  624.  
  625. void fileSelectedCB(Widget w, caddr_t clientData, caddr_t callData)
  626. {
  627.     XmFileSelectionBoxCallbackStruct *FSBinfos;
  628.     String dateiname;
  629.  
  630.     FSBinfos = (XmFileSelectionBoxCallbackStruct*)callData;
  631.     XmStringGetLtoR(FSBinfos->value,XmSTRING_DEFAULT_CHARSET,&dateiname);
  632.     if (currentFileSelCB!=NULL) (*currentFileSelCB)(dateiname);
  633.     XtFree(dateiname);
  634. }
  635.  
  636. Widget initFileSelector(Widget parent)
  637. {
  638.     Arg           args[10];
  639.     Cardinal      n;
  640.  
  641.     n = 0;
  642.     XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++;
  643.     fileSelW = XmCreateFileSelectionDialog(parent,"Load",args,n);
  644.     XtAddCallback(fileSelW,XmNokCallback,(XtCallbackProc)fileSelectedCB,(XtPointer)NULL);
  645.     XtAddCallback(fileSelW,XmNokCallback,(XtCallbackProc)unmanageCB,(XtPointer)NULL);
  646.     XtAddCallback(fileSelW,XmNcancelCallback,(XtCallbackProc)unmanageCB,(XtPointer)NULL);
  647.     XtUnmanageChild(XmSelectionBoxGetChild(fileSelW,XmDIALOG_HELP_BUTTON));
  648.     return fileSelW;
  649. }
  650.  
  651. void doFileSelectorCB(Widget widget, caddr_t clientData, caddr_t callData)
  652. {
  653.     Arg           args[10];
  654.     Cardinal      n;
  655.     XmString      tcs;
  656.     fileSel_t     *fs = (fileSel_t*)clientData;
  657.  
  658.     tcs = XmStringLtoRCreate(fs->mask,XmSTRING_DEFAULT_CHARSET);
  659.     currentFileSelCB = fs->callback;
  660.     n = 0;
  661.     XtSetArg(args[n], XmNdirMask, tcs); n++;
  662.     XtSetValues(fileSelW, args, n);
  663.     XtManageChild(fileSelW);
  664.     XmStringFree(tcs);
  665. }
  666.  
  667. static void PostPopupMenu(Widget popup, XButtonPressedEvent *event)
  668. {
  669.     XmMenuPosition(popup,event);
  670.     XtManageChild(popup);
  671. }
  672.  
  673. void moveImageCB(Widget w, XtPointer client_data, XEvent *e, Boolean *ctdp)
  674. {
  675.     int diff_x, diff_y;
  676.  
  677.     Arg           args[10];
  678.     Cardinal      n;   
  679.     Dimension     width, height;
  680.  
  681.  
  682.     n = 0;
  683.     XtSetArg(args[n],XmNwidth,&width); n++;
  684.     XtSetArg(args[n],XmNheight,&height); n++;
  685.     XtGetValues(graphicW,args,n);
  686.  
  687.     switch(e->type)
  688.     {
  689.     case ButtonPress:
  690.     if (e->xbutton.button==1)
  691.     {
  692.     Press_x = e->xbutton.x;
  693.     Press_y = e->xbutton.y;
  694.     Ipress_x = Image_x;
  695.     Ipress_y = Image_y;
  696.     }
  697.     else PostPopupMenu(PopupMenuW,&e->xbutton);
  698.     break;
  699.  
  700.     case MotionNotify: 
  701.     diff_x = e->xbutton.x - Press_x;
  702.     diff_y = e->xbutton.y - Press_y;
  703.     Image_x = Ipress_x - diff_x;
  704.     Image_y = Ipress_y - diff_y;
  705.     if (frame_width*8-Image_x<width)
  706.     Image_x = frame_width*8 - width;
  707.     if (frame_height-Image_y<height)
  708.     Image_y = frame_height - height;
  709.     if (Image_x<0) Image_x = 0;
  710.     if (Image_y<0) Image_y = 0;
  711.  
  712.     exposeCB(graphicW,(XtPointer)NULL,(XtPointer)NULL);
  713.     break;
  714.     }
  715. }
  716.  
  717. Widget initGraphic(Widget scrollW)
  718. {
  719.     Arg         args[10];
  720.     Cardinal    n;
  721.     Widget      frameW;
  722.  
  723.     n = 0;
  724.     frameW = XtCreateManagedWidget("GraphicFrame",xmFrameWidgetClass,
  725.     scrollW,args,n);
  726.  
  727.     n = 0;
  728.     graphicW = XtCreateManagedWidget("Graphic",xmDrawingAreaWidgetClass,
  729.     frameW,args,n);
  730.  
  731.     XtAddCallback(graphicW,XmNexposeCallback,(XtCallbackProc)exposeCB,(XtPointer)NULL);
  732.     XtAddCallback(graphicW,XmNresizeCallback,(XtCallbackProc)resizeCB,(XtPointer)NULL);
  733.  
  734.     return frameW;
  735. }
  736.  
  737. Widget initTitle(Widget menuBarW, char *name)
  738. {
  739.     Arg         args[10];
  740.     Cardinal    n;
  741.     Widget  title;
  742.  
  743.     n = 0;
  744.     title = XmCreatePulldownMenu(menuBarW,name,args,n);
  745.     n = 0;
  746.     XtSetArg(args[n], XmNsubMenuId, title); n++;
  747.     XtCreateManagedWidget(name,xmCascadeButtonWidgetClass,menuBarW,args,n);
  748.  
  749.     return title;
  750. }
  751.  
  752. Widget initItem(Widget title, char *name, XtCallbackProc cb, XtPointer p)
  753. {
  754.     Arg         args[10];
  755.     Cardinal    n;
  756.     Widget  item;
  757.  
  758.     n = 0;
  759.     item = XtCreateManagedWidget(name,xmPushButtonWidgetClass,title,args,n);
  760.     XtAddCallback(item,XmNactivateCallback,cb,p);
  761.  
  762.     return item;
  763. }
  764.  
  765. Widget initToggleItem(Widget title, int one_of_many,
  766.     char *name, XtCallbackProc cb, XtPointer p)
  767. {
  768.     Arg         args[10];
  769.     Cardinal    n;
  770.     Widget  item;
  771.  
  772.     n = 0;
  773.     if (one_of_many)
  774.     {
  775.     XtSetArg(args[n], XmNindicatorType, XmONE_OF_MANY); n++;
  776.     }
  777.     XtSetArg(args[n], XmNvisibleWhenOff, True); n++;
  778.     item = XtCreateManagedWidget(name,xmToggleButtonWidgetClass,title,args,n);
  779.     XtAddCallback(item,XmNvalueChangedCallback,cb,p);
  780.  
  781.     return item;
  782. }
  783.  
  784. void initPopupMenu(Widget parent)
  785. {
  786.     PopupMenuW = XmCreatePopupMenu(parent,"PopupMenu",NULL,0);
  787.     initItem(PopupMenuW,"Next Page",(XtCallbackProc)nextPageCB,(XtPointer)NULL);
  788.     initItem(PopupMenuW,"Prev Page",(XtCallbackProc)prevPageCB,(XtPointer)NULL);
  789.     initItem(PopupMenuW,"Goto Page ...",(XtCallbackProc)doDialog,(XtPointer)&page_dialog);
  790.     initItem(PopupMenuW,"Update Page",(XtCallbackProc)updateCB,(XtPointer)NULL);
  791.     XtCreateManagedWidget("Separator",xmSeparatorWidgetClass,PopupMenuW,NULL,0);
  792.     initItem(PopupMenuW,"Quit",(XtCallbackProc)exitCB,(XtPointer)NULL);
  793. }
  794.  
  795. Widget initMenu(Widget parent)
  796. {
  797.     Widget      menuBarW, fileW, printW, setupW, margW, optionW, devW;
  798.     Arg         args[10];
  799.     Cardinal    n;
  800.  
  801.     n = 0;
  802.     menuBarW = XmCreateMenuBar(parent,"MenuBar",args,n);
  803.     XtManageChild(menuBarW);
  804.  
  805.     fileW = initTitle(menuBarW,"File");
  806.     printW = initTitle(menuBarW,"Print");
  807.     setupW = initTitle(menuBarW,"Setup");
  808.     margW = initTitle(menuBarW,"Margins");
  809.     optionW = initTitle(menuBarW,"Options");
  810.     devW = initTitle(menuBarW,"Devices");
  811.  
  812.     n=0;
  813.     XtSetArg(args[n],XmNradioBehavior,True); n++;
  814.     XtSetValues(devW,args,n);
  815.  
  816.     initItem(fileW,"Select File ...",(XtCallbackProc)doFileSelectorCB,(XtPointer)&fileSelDvi);
  817.     XtCreateManagedWidget("Separator",xmSeparatorWidgetClass,fileW,NULL,0);
  818.     initItem(fileW,"Load Options ...",(XtCallbackProc)doFileSelectorCB,(XtPointer)&fileSelRopt);    
  819.     initItem(fileW,"Save Options ...",(XtCallbackProc)doFileSelectorCB,(XtPointer)&fileSelWopt);
  820.     XtCreateManagedWidget("Separator",xmSeparatorWidgetClass,fileW,NULL,0);
  821.     initItem(fileW,"Log File ...",(XtCallbackProc)doFileSelectorCB,(XtPointer)&fileSelLog);
  822.     XtCreateManagedWidget("Separator",xmSeparatorWidgetClass,fileW,NULL,0);
  823.     initItem(fileW,"Quit",(XtCallbackProc)exitCB,(XtPointer)NULL);
  824.  
  825.     initItem(printW,"Format Pages ...",(XtCallbackProc)doDialog,(XtPointer)&format_dialog);
  826.     initItem(printW,"Magnification ...",(XtCallbackProc)doDialog,(XtPointer)&mag_dialog);
  827.  
  828.     initItem(setupW,"Clippath Memory ...",(XtCallbackProc)doDialog,(XtPointer)&clippath_dialog);
  829.     initItem(setupW,"Maximum  Memory ...",(XtCallbackProc)doDialog,(XtPointer)&maximum_dialog);
  830.     XtCreateManagedWidget("Separator",xmSeparatorWidgetClass,setupW,NULL,0);
  831.     initItem(setupW,"PK  Font Path ...",(XtCallbackProc)doDialog,(XtPointer)&pkpath_dialog);
  832.     initItem(setupW,"VF  Font Path ...",(XtCallbackProc)doDialog,(XtPointer)&vfpath_dialog);
  833.     initItem(setupW,"TFM Font Path ...",(XtCallbackProc)doDialog,(XtPointer)&tfmpath_dialog);
  834.     initItem(setupW,"IMG Image Path ...",(XtCallbackProc)doDialog,(XtPointer)&imgpath_dialog);
  835.     initItem(setupW,"GR  Input Path ...",(XtCallbackProc)doDialog,(XtPointer)&grpath_dialog);
  836.     initItem(setupW,"DVI Input Path ...",(XtCallbackProc)doDialog,(XtPointer)&dvipath_dialog);
  837.  
  838.     XtCreateManagedWidget("Separator",xmSeparatorWidgetClass,setupW,NULL,0);        /****/
  839.     initItem(setupW,"Printer ...",(XtCallbackProc)doDialog,(XtPointer)&printer_dialog); /****/
  840.     initItem(margW,"H-Offset ...",(XtCallbackProc)doDialog,(XtPointer)&hoff_dialog);
  841.     initItem(margW,"V-Offset ...",(XtCallbackProc)doDialog,(XtPointer)&voff_dialog);
  842.     initItem(margW,"H-Spread ...",(XtCallbackProc)doDialog,(XtPointer)&hspread_dialog);
  843.     initItem(margW,"V-Spread ...",(XtCallbackProc)doDialog,(XtPointer)&vspread_dialog);
  844.  
  845.     initItem(optionW,"H-Resolution ...",(XtCallbackProc)doDialog,(XtPointer)&hres_dialog);
  846.     initItem(optionW,"V-Resolution ...",(XtCallbackProc)doDialog,(XtPointer)&vres_dialog);
  847.     XtCreateManagedWidget("Separator",xmSeparatorWidgetClass,optionW,NULL,0);
  848.     dviMemW = initToggleItem(optionW,0,"Dvi in memory",(XtCallbackProc)toggle_dviMemory,(XtPointer)NULL);
  849.     traceFontsW = initToggleItem(optionW,0,"Trace Fonts",(XtCallbackProc)toggle_traceFonts,(XtPointer)NULL);
  850.     traceMemW = initToggleItem(optionW,0,"Trace Memory",(XtCallbackProc)toggle_traceMemory,(XtPointer)NULL);
  851.     traceCharsW = initToggleItem(optionW,0,"Trace Chars",(XtCallbackProc)toggle_traceChars,(XtPointer)NULL);
  852.  
  853.     sh_NULLW = initToggleItem(devW,1,"Screen",(XtCallbackProc)shipoutCB,(XtPointer)&null_d);
  854.     sh_p6lowW = initToggleItem(devW,1,"P6 Low",(XtCallbackProc)shipoutCB,(XtPointer)&p6low_d);
  855.     sh_p6midW = initToggleItem(devW,1,"P6 Med",(XtCallbackProc)shipoutCB,(XtPointer)&p6mid_d);
  856.     sh_p6highW = initToggleItem(devW,1,"P6 High",(XtCallbackProc)shipoutCB,(XtPointer)&p6high_d);
  857.     sh_fx80W = initToggleItem(devW,1,"Epson FX 80",(XtCallbackProc)shipoutCB,(XtPointer)&fx80_d);
  858.     sh_shipfileW = initToggleItem(devW,1,"File",(XtCallbackProc)shipoutCB,(XtPointer)&shipfile_d);
  859.     sh_hpljW = initToggleItem(devW,1,"HP Laserjet",(XtCallbackProc)shipoutCB,(XtPointer)&hplj_d);
  860.     sh_hpljlowW = initToggleItem(devW,1,"HP Laserjet Low",(XtCallbackProc)shipoutCB,(XtPointer)&hpljlow_d);
  861.     sh_bj300W = initToggleItem(devW,1,"Canon BJ300",(XtCallbackProc)shipoutCB,(XtPointer)&bj300_d);
  862.     sh_null_deviceW = initToggleItem(devW,1,"NULL Device",(XtCallbackProc)shipoutCB,(XtPointer)&null_device_d);
  863.  
  864.     initFileSelector(menuBarW);
  865.  
  866.     return menuBarW;
  867. }
  868.  
  869. Widget initForm(Widget parent)
  870. {
  871.     Arg         args[10];
  872.     static char ver[64];
  873.     Cardinal    n;
  874.  
  875.  
  876.     n = 0;
  877.     XtSetArg(args[n],XmNeditMode,XmMULTI_LINE_EDIT); n++;
  878.     XtSetArg(args[n],XmNeditable,False); n++;
  879.     XtSetArg(args[n],XmNautoShowCursorPosition,True); n++;
  880.     XtSetArg(args[n],XmNcolumns,64); n++;
  881.     XtSetArg(args[n],XmNrows,10); n++;
  882.     XtSetArg(args[n],XmNcursorPositionVisible,False); n++;
  883.     textW = XmCreateScrolledText(parent,"Text",args,n);
  884.     XtManageChild(textW);
  885.  
  886.     return XtParent(textW);
  887. }
  888.  
  889. void initWidgetBaum(Widget applShell)
  890. {
  891.     Widget mainW, formW, menuW;
  892.  
  893.     mainW = XtCreateManagedWidget("Main",xmMainWindowWidgetClass,applShell,(Arg*)NULL,0);
  894.     formW = initForm(mainW);
  895.     menuW = initMenu(mainW);
  896.  
  897.     XmMainWindowSetAreas(mainW,menuW,(Widget)NULL,(Widget)NULL,(Widget)NULL,formW);
  898. }
  899.  
  900. void destroyCB(Widget w, XtPointer client_data, XtPointer call_data)
  901. {
  902.     PageIsOpen = 0;
  903.     dvi_clean();
  904.     exitImage();
  905. }
  906.  
  907. void initDviOutWindow(void)
  908. {
  909.     Arg         args[10];
  910.     Cardinal    n;
  911.     Widget  mainW, formW, hscrollW, vscrollW;
  912.  
  913.     if (!PageIsOpen)
  914.     {
  915.     n = 0;
  916.     /*
  917.     XtSetArg(args[n], XmNargc, argcTmp); n++;
  918.     XtSetArg(args[n], XmNargv, argvTmp); n++;
  919.     XtSetArg(args[n], XmNdeleteResponse,XmDO_NOTHING); n++;
  920.     */
  921.     XtSetArg(args[n], XmNiconName,"Dvi"); n++;
  922.     XtSetArg(args[n], XmNscreen, defaultScreen); n++;
  923.     dispShell = XtAppCreateShell("dviPage", APPL_CLASS,
  924.     topLevelShellWidgetClass, theDisplay, args, n);
  925.  
  926.     XtAddCallback(dispShell,XmNdestroyCallback,(XtCallbackProc)destroyCB,NULL);
  927.  
  928.     if (dvi_name) set_filename(dvi_name);
  929.  
  930.     n = 0;
  931.     mainW = XtCreateManagedWidget("Main",xmMainWindowWidgetClass,
  932.     dispShell,args,n);
  933.     initGraphic(mainW);
  934.     initPopupMenu(graphicW);
  935.     XtAddEventHandler(graphicW,Button1MotionMask|ButtonPressMask,
  936.           False,moveImageCB,NULL);
  937.  
  938.     XtRealizeWidget(dispShell);
  939.     PageIsOpen = 1;
  940.     }
  941.     if (theImage==NULL) initImage();
  942. }
  943.  
  944. void exitDviOutWindow(void)
  945. {
  946.     if (PageIsOpen)
  947.     {
  948.     XtDestroyWidget(dispShell);
  949.     dvi_clean();
  950.     }
  951. }
  952.  
  953. void resizeCB(Widget widget, caddr_t clientDaten, caddr_t aufrufDaten)
  954. {
  955.     Arg           args[10];
  956.     Cardinal      n;   
  957.     Dimension     width, height;
  958.     int       expose = 0;
  959.  
  960.     n = 0;
  961.     XtSetArg(args[n],XmNwidth,&width); n++;
  962.     XtSetArg(args[n],XmNheight,&height); n++;
  963.     XtGetValues(graphicW,args,n);
  964.     if (frame_width*8-Image_x<width) 
  965.     Image_x = frame_width*8 - width, expose=1;
  966.     if (frame_height-Image_y<height) 
  967.     Image_y = frame_height - height, expose=1;
  968.     if (Image_x<0) Image_x = 0, expose=1;
  969.     if (Image_y<0) Image_y = 0, expose=1;
  970.     if (expose) exposeCB(graphicW,(XtPointer)NULL,(XtPointer)NULL);
  971. }
  972.  
  973. void exposeCB(Widget widget, caddr_t clientDaten, caddr_t aufrufDaten)
  974. {
  975.     Arg           args[10];
  976.     Cardinal      n;   
  977.     Dimension     width, height;
  978.  
  979.     n = 0;
  980.     XtSetArg(args[n],XmNwidth,&width); n++;
  981.     XtSetArg(args[n],XmNheight,&height); n++;
  982.     XtGetValues(graphicW,args,n);
  983.  
  984.     if (theImage!=NULL)
  985.     {
  986.     int draw_width, draw_height;
  987.     draw_width = width>frame_width*8-Image_x ? frame_width*8-Image_x:width;
  988.     draw_height = height>frame_height-Image_y ? frame_height-Image_y:height;
  989.     if (draw_width<width)
  990.     XClearArea(XtDisplay(widget),XtWindow(widget),draw_width,0,0,0,False);
  991.     if (draw_height<height)
  992.     XClearArea(XtDisplay(widget),XtWindow(widget),0,draw_height,0,0,False);
  993.  
  994.     XPutImage(XtDisplay(widget),XtWindow(widget),theGC,
  995.     theImage,Image_x,Image_y,0,0,draw_width,draw_height);
  996.     }
  997.     else
  998.     {
  999.     XClearWindow(XtDisplay(widget),XtWindow(widget));
  1000.     }
  1001. }
  1002.  
  1003. void inversCB(Widget widget, caddr_t clientDaten, caddr_t aufrufDaten)
  1004. {
  1005.     Arg         args[10];
  1006.     Cardinal    n;
  1007.     Pixel       fg, bg;
  1008.  
  1009.     n = 0;
  1010.     XtSetArg(args[n], XmNforeground, &fg); n++;
  1011.     XtSetArg(args[n], XmNbackground, &bg); n++;
  1012.     XtGetValues(widget, args, n);
  1013.  
  1014.     n = 0;
  1015.     XtSetArg(args[n], XmNforeground, bg); n++;
  1016.     XtSetArg(args[n], XmNbackground, fg); n++;
  1017.     XtSetValues(widget, args, n);
  1018. }
  1019.  
  1020. void exitCB(Widget widget, caddr_t clientDaten, caddr_t aufrufDaten)
  1021. {
  1022.     dvi_clean();
  1023.     exit(0);
  1024. }
  1025.