home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / apps / dtp / ghost / gs301src / atari / gp_atar4.c < prev    next >
C/C++ Source or Header  |  1994-09-17  |  25KB  |  1,068 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gp_atar4.c */
  20.  
  21. /*
  22.  * This file contains callback functions for the user interface of
  23.  * the Atari platform.
  24.  */
  25.  
  26. #include "gp_atar4.h"
  27.  
  28. extern VWRK VWork;                /* from gp_atar1.h */
  29. extern PSTATE State;                /* from gp_atar1.h */
  30. extern OBJECT menuobj[], aboutobj[], iconobj[];    /* from gp_atar1.h */
  31. extern OBJECT resobj[], devobj[], sizobj[];    /* from gp_atar1.h */
  32. extern OBJECT printobj[];            /* from gp_atar1.h */
  33.  
  34. extern WINLIST *WinListDelete();        /* from gp_atar3.c */
  35.  
  36. extern WINLIST *WList;                /* from gp_atar2.c */
  37. extern WINDOW conswin, printwin;        /* from gp_atar2.c */
  38. extern WINDOW aboutwin, reswin, pagewin;    /* from gp_atar2.c */
  39. extern WINDOW iconwin, devwin, sizwin;            /* from gp_atar2.c */
  40.  
  41. extern EVENT Event;                /* from gp_atar2.c */
  42.  
  43. extern char devices[DEVICES][DNAMELEN];         /* gp_atar1.h */
  44.  
  45. int LastPrnOutButton=0;
  46.  
  47.  
  48. int
  49. res_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
  50.     PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
  51. {
  52.  
  53.     char *sptr, nl[2]="";
  54.  
  55.     byte cone, cten, chun;
  56.  
  57.     short  cindex=0, done=0, redraw=1;
  58.     static short applied=0;
  59.  
  60.     int Resolution, Width, Height;
  61.  
  62.     static unsigned long oldone=0x30FF1100L;
  63.     static unsigned long oldten=0x38FF1100L;
  64.     static unsigned long oldhun=0x30FF1100L;
  65.  
  66.     WINTEXT *text = conswin.obj;
  67.  
  68.     int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
  69.  
  70.     if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
  71.     strcpy(nl, "\n");
  72.     }
  73.  
  74.     switch (index) {
  75.  
  76.     case RES_OUP:
  77.     if (!cindex) cindex = RES_ONE;
  78.  
  79.     case RES_TUP:
  80.     if (!cindex) cindex = RES_TEN;
  81.  
  82.     case RES_HUP:
  83.     if (!cindex) cindex = RES_HUN;
  84.  
  85.     if (object[cindex].ob_spec < 0x39000000L) {
  86.         object[cindex].ob_spec += 0x01000000L;
  87.     }
  88.     else {
  89.         object[cindex].ob_spec -= 0x09000000L;
  90.     }
  91.  
  92.     objc_draw(object, cindex, 0,
  93.         owin->canvas.g_x, owin->canvas.g_y,
  94.         owin->canvas.g_w, owin->canvas.g_h);
  95.  
  96.     applied = 0;
  97.     break;
  98.  
  99.     case RES_ODN:
  100.     if (!cindex) cindex = RES_ONE;
  101.  
  102.     case RES_TDN:
  103.     if (!cindex) cindex = RES_TEN;
  104.  
  105.     case RES_HDN:
  106.     if (!cindex) cindex = RES_HUN;
  107.  
  108.     if (object[cindex].ob_spec > 0x31000000L) {
  109.         object[cindex].ob_spec -= 0x01000000L;
  110.     }
  111.     else {
  112.         object[cindex].ob_spec += 0x09000000L;
  113.     }
  114.  
  115.     objc_draw(object, cindex, 0,
  116.         owin->canvas.g_x, owin->canvas.g_y,
  117.         owin->canvas.g_w, owin->canvas.g_h);
  118.  
  119.     applied = 0;
  120.     break;
  121.  
  122.     case RES_DEF:
  123.     object[RES_ONE].ob_spec = 0x30FF1100L;
  124.     object[RES_TEN].ob_spec = 0x38FF1100L;
  125.     object[RES_HUN].ob_spec = 0x30FF1100L;
  126.  
  127.     objc_draw(object, RES_HUN, 0,
  128.         owin->canvas.g_x, owin->canvas.g_y,
  129.         owin->canvas.g_w, owin->canvas.g_h);
  130.  
  131.     objc_draw(object, RES_TEN, 0,
  132.         owin->canvas.g_x, owin->canvas.g_y,
  133.         owin->canvas.g_w, owin->canvas.g_h);
  134.  
  135.     objc_draw(object, RES_ONE, 0,
  136.         owin->canvas.g_x, owin->canvas.g_y,
  137.         owin->canvas.g_w, owin->canvas.g_h);
  138.  
  139.     applied = 0;
  140.     break;
  141.  
  142.     case RES_CAN:
  143.     object[RES_ONE].ob_spec = oldone;
  144.     object[RES_TEN].ob_spec = oldten;
  145.     object[RES_HUN].ob_spec = oldhun;
  146.     WinClose(owin);
  147.     WList = WinListDelete(WList, owin);
  148.     redraw = 0;
  149.     break;
  150.  
  151.     case RES_DONE:
  152.     if (applied) {
  153.         WinClose(owin);
  154.         WList = WinListDelete(WList, owin);
  155.         redraw = 0;
  156.         break;
  157.     }
  158.     done = 1;
  159.  
  160.     case RES_APP:
  161.     if (done) {
  162.         WinClose(owin);
  163.         WList = WinListDelete(WList, owin);
  164.         redraw = 0;
  165.     }
  166.  
  167.     oldone = object[RES_ONE].ob_spec;
  168.     oldten = object[RES_TEN].ob_spec;
  169.     oldhun = object[RES_HUN].ob_spec;
  170.  
  171.     cone = *(byte *)(&object[RES_ONE].ob_spec);
  172.     cten = *(byte *)(&object[RES_TEN].ob_spec);
  173.     chun = *(byte *)(&object[RES_HUN].ob_spec);
  174.  
  175.     Resolution = 100 * (chun-'0') + 10 * (cten-'0') + (cone-'0');
  176.  
  177.     Width =  nint(((float)Resolution * gr->Width) / gr->XRes);
  178.     Height = nint((Resolution * vw->AspectRatio * gr->Height) / gr->YRes);
  179.  
  180.     gr->XRes = Resolution;
  181.     gr->YRes = nint(Resolution * vw->AspectRatio);
  182.  
  183.     sprintf(st->Command,
  184.         "%smark /HWResolution [%d %d] /HWSize [%d %d] currentdevice putdeviceprops pop\n",
  185.         nl, gr->XRes, gr->YRes, Width, Height);
  186.  
  187.     SendCommand(st, pw, dest);
  188.  
  189.     applied = 1;
  190.     break;
  191.  
  192.     }
  193.  
  194.     objc_change(object, index, 0,
  195.     owin->canvas.g_x, owin->canvas.g_y,
  196.     owin->canvas.g_w, owin->canvas.g_h,
  197.     (object[index].ob_state ^ SELECTED), redraw);
  198.  
  199.     return 0;
  200. }
  201.  
  202. int
  203. abo_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
  204.     PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
  205. {
  206.  
  207.     short redraw=1;
  208.  
  209.     objc_change(object, index, 0,
  210.     owin->canvas.g_x, owin->canvas.g_y,
  211.     owin->canvas.g_w, owin->canvas.g_h,
  212.     (object[index].ob_state ^ SELECTED), redraw);
  213.  
  214.     switch (index) {
  215.  
  216.     case ABO_GEN:
  217.     HandleHelp(GENHELP, vw, st, pw, dest);
  218.     break;
  219.  
  220.     case ABO_FONT:
  221.     HandleHelp(FONTHELP, vw, st, pw, dest);
  222.     break;
  223.  
  224.     case ABO_ERR:
  225.     HandleHelp(ERRHELP, vw, st, pw, dest);
  226.     break;
  227.  
  228.     case ABO_FEAT:
  229.     HandleHelp(FEATHELP, vw, st, pw, dest);
  230.     break;
  231.     }
  232.  
  233.     return 0;
  234. }
  235.  
  236. int
  237. dev_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
  238.     PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
  239. {
  240.  
  241.     char *sptr, nl[2]="";
  242.  
  243.     short done=0, redraw=1;
  244.     static short applied=0;
  245.     unsigned short state, screendev;
  246.  
  247.     WINTEXT *text = conswin.obj;
  248.  
  249.     int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
  250.  
  251.     if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
  252.     strcpy(nl, "\n");
  253.     }
  254.  
  255.     switch (index) {
  256.  
  257.     case DEV_DEF:
  258.  
  259.     objc_change(object, index, 0,
  260.         owin->canvas.g_x, owin->canvas.g_y,
  261.         owin->canvas.g_w, owin->canvas.g_h,
  262.         (object[index].ob_state ^ SELECTED), 1);
  263.  
  264.     index = FIRSTDEV;
  265.  
  266.     objc_change(object, index, 0,
  267.         owin->canvas.g_x, owin->canvas.g_y,
  268.         owin->canvas.g_w, owin->canvas.g_h,
  269.         (object[index].ob_state ^ SELECTED), 1);
  270.  
  271.     /* Intentional fall through. */
  272.  
  273.     default:
  274.         
  275.     objc_change(object, st->Device, 0,
  276.         owin->canvas.g_x, owin->canvas.g_y,
  277.         owin->canvas.g_w, owin->canvas.g_h,
  278.         (object[st->Device].ob_state ^ SELECTED), 1);
  279.  
  280.     st->Device = index;
  281.     applied = 0;
  282.     break;
  283.  
  284.     case DEV_CAN:
  285.  
  286.     objc_change(object, st->Device, 0,
  287.         owin->canvas.g_x, owin->canvas.g_y,
  288.         owin->canvas.g_w, owin->canvas.g_h,
  289.         (object[st->Device].ob_state ^ SELECTED), 1);
  290.  
  291.     objc_change(object, st->LastDevice, 0,
  292.         owin->canvas.g_x, owin->canvas.g_y,
  293.         owin->canvas.g_w, owin->canvas.g_h,
  294.         (object[st->LastDevice].ob_state ^ SELECTED), 1);
  295.  
  296.     objc_change(object, index, 0,
  297.         owin->canvas.g_x, owin->canvas.g_y,
  298.         owin->canvas.g_w, owin->canvas.g_h,
  299.         (object[index].ob_state ^ SELECTED), 0);
  300.  
  301.     WinClose(owin);
  302.     WList = WinListDelete(WList, owin);
  303.     st->Device = st->LastDevice;
  304.  
  305.     break;
  306.  
  307.     case DEV_DONE:
  308.     if (applied) {
  309.         WinClose(owin);
  310.         WList = WinListDelete(WList, owin);
  311.  
  312.         objc_change(object, index, 0,
  313.         owin->canvas.g_x, owin->canvas.g_y,
  314.         owin->canvas.g_w, owin->canvas.g_h,
  315.         (object[index].ob_state ^ SELECTED), 0);
  316.  
  317.         break;
  318.     }
  319.     done = 1;
  320.  
  321.     /* Intentional fall-through. */
  322.  
  323.     case DEV_APP:
  324.  
  325.     /* Close the window if we are done. */
  326.  
  327.     if (done) {
  328.         WinClose(owin);
  329.         WList = WinListDelete(WList, owin);
  330.         redraw = 0;
  331.     }
  332.  
  333.     /* Update the print dialog and redraw if it is open. */
  334.  
  335.     strcpy(st->DevString, (char *)object[st->Device].ob_spec);
  336.  
  337.     if (printwin.opened) {
  338.       st->Event->Message[3] = printwin.handle;
  339.  
  340.       objc_offset(printobj, PR_DSTR,
  341.               &st->Event->Message[4], &st->Event->Message[5]);
  342.       st->Event->Message[6] = printobj[PR_DSTR].ob_width;
  343.       st->Event->Message[7] = printobj[PR_DSTR].ob_height;
  344.       objw_redraw(0, st);
  345.  
  346.     }
  347.  
  348.     if (LastPrnOutButton) {
  349.       objc_change(printobj, LastPrnOutButton, 0,
  350.         printwin.canvas.g_x, printwin.canvas.g_y,
  351.         printwin.canvas.g_w, printwin.canvas.g_h,
  352.         (printobj[LastPrnOutButton].ob_state ^ SELECTED),
  353.         printwin.opened);
  354.     }
  355.  
  356.     screendev = !strcmp(st->DevString, "stvdi");
  357.  
  358.     state = printobj[PR_PRN].ob_state;
  359.     objc_change(printobj, PR_PRN, 0,
  360.         printwin.canvas.g_x, printwin.canvas.g_y,
  361.         printwin.canvas.g_w, printwin.canvas.g_h,
  362.         ((screendev) ? state | DISABLED : state & ~ DISABLED),
  363.         printwin.opened);
  364.  
  365.     state = printobj[PR_CEN].ob_state;
  366.     objc_change(printobj, PR_CEN, 0,
  367.         printwin.canvas.g_x, printwin.canvas.g_y,
  368.         printwin.canvas.g_w, printwin.canvas.g_h,
  369.         ((screendev) ? state | DISABLED : state & ~ DISABLED),
  370.         printwin.opened);
  371.  
  372.     state = printobj[PR_OFILE].ob_state;
  373.     objc_change(printobj, PR_OFILE, 0,
  374.         printwin.canvas.g_x, printwin.canvas.g_y,
  375.         printwin.canvas.g_w, printwin.canvas.g_h,
  376.         ((screendev) ? state | DISABLED : state & ~ DISABLED),
  377.         printwin.opened);
  378.  
  379.     LastPrnOutButton = 0;
  380.  
  381.     /* Send the command to change the device to the interpreter. */
  382.  
  383.     sprintf(st->Command, "%s(%s) selectdevice\n",
  384.         nl, (char *)object[st->Device].ob_spec);
  385.  
  386.     SendCommand(st, pw, dest);
  387.  
  388.     redraw = 1;
  389.     applied = 1;
  390.     st->LastDevice = st->Device;
  391.  
  392.     objc_change(object, index, 0,
  393.         owin->canvas.g_x, owin->canvas.g_y,
  394.         owin->canvas.g_w, owin->canvas.g_h,
  395.         (object[index].ob_state ^ SELECTED), redraw);
  396.  
  397.     break;
  398.  
  399.     }
  400.  
  401.     return 0;
  402.  
  403. }
  404.  
  405. int
  406. siz_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
  407.     PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
  408. {
  409.  
  410.     char *sptr, nl[2]="";
  411.  
  412.     short done=0, redraw=1;
  413.     static short applied=0, select=6, oldselect=6;
  414.  
  415.     WINTEXT *text = conswin.obj;
  416.  
  417.     int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
  418.  
  419.     if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
  420.     strcpy(nl, "\n");
  421.     }
  422.  
  423.     switch (index) {
  424.  
  425.     case SIZ_DEF:
  426.  
  427.     objc_change(object, index, 0,
  428.         owin->canvas.g_x, owin->canvas.g_y,
  429.         owin->canvas.g_w, owin->canvas.g_h,
  430.         (object[index].ob_state ^ SELECTED), 1);
  431.  
  432.     index = 6;
  433.  
  434.     objc_change(object, index, 0,
  435.         owin->canvas.g_x, owin->canvas.g_y,
  436.         owin->canvas.g_w, owin->canvas.g_h,
  437.         (object[index].ob_state ^ SELECTED), 1);
  438.  
  439.     default:
  440.         
  441.     objc_change(object, select, 0,
  442.         owin->canvas.g_x, owin->canvas.g_y,
  443.         owin->canvas.g_w, owin->canvas.g_h,
  444.         (object[select].ob_state ^ SELECTED), 1);
  445.  
  446.     select = index;
  447.     applied = 0;
  448.  
  449.     break;
  450.  
  451.     case SIZ_CAN:
  452.  
  453.     objc_change(object, select, 0,
  454.         owin->canvas.g_x, owin->canvas.g_y,
  455.         owin->canvas.g_w, owin->canvas.g_h,
  456.         (object[select].ob_state ^ SELECTED), 1);
  457.  
  458.     objc_change(object, oldselect, 0,
  459.         owin->canvas.g_x, owin->canvas.g_y,
  460.         owin->canvas.g_w, owin->canvas.g_h,
  461.         (object[oldselect].ob_state ^ SELECTED), 1);
  462.  
  463.     objc_change(object, index, 0,
  464.         owin->canvas.g_x, owin->canvas.g_y,
  465.         owin->canvas.g_w, owin->canvas.g_h,
  466.         (object[index].ob_state ^ SELECTED), 0);
  467.  
  468.     WinClose(owin);
  469.     WList = WinListDelete(WList, owin);
  470.     select = oldselect;
  471.  
  472.     break;
  473.  
  474.     case SIZ_DONE:
  475.     if (applied) {
  476.         WinClose(owin);
  477.         WList = WinListDelete(WList, owin);
  478.  
  479.         objc_change(object, index, 0,
  480.         owin->canvas.g_x, owin->canvas.g_y,
  481.         owin->canvas.g_w, owin->canvas.g_h,
  482.         (object[index].ob_state ^ SELECTED), 0);
  483.  
  484.         break;
  485.     }
  486.     done = 1;
  487.  
  488.     case SIZ_APP:
  489.  
  490.     if (done) {
  491.         WinClose(owin);
  492.         WList = WinListDelete(WList, owin);
  493.         redraw = 0;
  494.     }
  495.  
  496.     sprintf(st->Command, "%s%s\n",
  497.         nl, (char *)object[select].ob_spec);
  498.  
  499.     SendCommand(st, pw, dest);
  500.  
  501.     redraw = 1;
  502.     applied = 1;
  503.     oldselect = select;
  504.  
  505.     objc_change(object, index, 0,
  506.         owin->canvas.g_x, owin->canvas.g_y,
  507.         owin->canvas.g_w, owin->canvas.g_h,
  508.         (object[index].ob_state ^ SELECTED), redraw);
  509.  
  510.     break;
  511.  
  512.     }
  513.  
  514.     return 0;
  515. }
  516.  
  517. int
  518. prn_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
  519.     PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
  520. {
  521.  
  522.     char *sptr, nl[2]="";
  523.  
  524.     unsigned short state, screendev;
  525.  
  526.     int Select=1, Deselect=0;
  527.  
  528.     WINTEXT *text = conswin.obj;
  529.  
  530.     int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
  531.  
  532.     if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
  533.     strcpy(nl, "\n");
  534.     }
  535.  
  536.     switch (index) {
  537.  
  538.     case PR_DEF:
  539.  
  540.         *st->Command = '\0';
  541.  
  542.         if (st->Device != FIRSTDEV + 1) {
  543.       st->Device = FIRSTDEV + 1;
  544.       strcpy(st->DevString, devices[1]);
  545.       sprintf(st->Command, "%s(%s) selectdevice\n", nl, devices[1]);
  546.     }
  547.  
  548.     if (printwin.opened) {
  549.       st->Event->Message[3] = printwin.handle;
  550.       objc_offset(printobj, PR_DSTR,
  551.               &st->Event->Message[4], &st->Event->Message[5]);
  552.       st->Event->Message[6] = printobj[PR_DSTR].ob_width;
  553.       st->Event->Message[7] = printobj[PR_DSTR].ob_height;
  554.  
  555.       objw_redraw(0, st);
  556.     }
  557.  
  558.     if (printobj[PR_PRN].ob_state & DISABLED) {
  559.  
  560.       objc_change(printobj, PR_PRN, 0,
  561.         printwin.canvas.g_x, printwin.canvas.g_y,
  562.         printwin.canvas.g_w, printwin.canvas.g_h,
  563.         (printobj[PR_PRN].ob_state & ~ DISABLED),
  564.         printwin.opened);
  565.  
  566.       objc_change(printobj, PR_CEN, 0,
  567.         printwin.canvas.g_x, printwin.canvas.g_y,
  568.         printwin.canvas.g_w, printwin.canvas.g_h,
  569.         (printobj[PR_CEN].ob_state & ~ DISABLED),
  570.         printwin.opened);
  571.  
  572.       objc_change(printobj, PR_OFILE, 0,
  573.         printwin.canvas.g_x, printwin.canvas.g_y,
  574.         printwin.canvas.g_w, printwin.canvas.g_h,
  575.         (printobj[PR_OFILE].ob_state & ~ DISABLED),
  576.         printwin.opened);
  577.     }
  578.  
  579.         if (LastPrnOutButton != PR_CEN) {
  580.  
  581.       if (LastPrnOutButton) {
  582.         objc_change(object, LastPrnOutButton, 0,
  583.             owin->canvas.g_x, owin->canvas.g_y,
  584.             owin->canvas.g_w, owin->canvas.g_h,
  585.             (object[LastPrnOutButton].ob_state ^ SELECTED), 1);
  586.       }
  587.  
  588.       objc_change(object, PR_CEN, 0,
  589.               owin->canvas.g_x, owin->canvas.g_y,
  590.               owin->canvas.g_w, owin->canvas.g_h,
  591.               (object[PR_CEN].ob_state ^ SELECTED), 1);
  592.  
  593.       LastPrnOutButton = PR_CEN;
  594.  
  595.       strcpy(st->Outfile, "CEN:");
  596.  
  597.       strcat(st->Command,
  598.          "mark /OutputFile (CEN:) currentdevice putdeviceprops pop\n");
  599.  
  600.     }
  601.  
  602.     if (strlen(st->Command)) {
  603.       SendCommand(st, pw, dest);
  604.     }
  605.  
  606.     DevObjUpdate(st);
  607.     Deselect = 1;
  608.         break;
  609.  
  610.     case PR_CAN:
  611.     WinClose(owin);
  612.     WList = WinListDelete(WList, owin);
  613.     Deselect = 1;
  614.         break;
  615.  
  616.     case PR_PR:
  617.     sprintf(st->Command, "%s(%s%s) run\n", nl, st->DirSpec, st->Infile);
  618.     SendCommand(st, pw, dest);
  619.     Deselect = 1;
  620.         break;
  621.  
  622.     case PR_DEV:
  623.     WinListAdd(WList, &devwin);
  624.     ObjWinOpen(devobj, &devwin, vw, st);
  625.     Deselect = 1;
  626.         break;
  627.  
  628.     case PR_IFILE:
  629.     /* Use any previously selected input file as the default. */
  630.  
  631.     if (strlen(st->Infile)) {
  632.         strcpy(st->FileSel, st->Infile);
  633.     }
  634.     else {
  635.         strcpy(st->FileSel, "");
  636.     }
  637.  
  638.     if ((Select = GetFile(st, "*.*")) != 0) {
  639.         strcpy(st->Infile, st->FileSel);
  640.     }
  641.  
  642.     if (printwin.opened) {
  643.       st->Event->Message[3] = printwin.handle;
  644.       objc_offset(printobj, PR_FSTR,
  645.               &st->Event->Message[4], &st->Event->Message[5]);
  646.       st->Event->Message[6] = printobj[PR_FSTR].ob_width;
  647.       st->Event->Message[7] = printobj[PR_FSTR].ob_height;
  648.  
  649.       objw_redraw(0, st);
  650.     }
  651.  
  652.     Deselect = 1;
  653.     break;
  654.  
  655.     case PR_CEN:    /* directly to centronics hardware */
  656.  
  657.     if (LastPrnOutButton != PR_CEN) {
  658.  
  659.       if (LastPrnOutButton) {
  660.         objc_change(object, LastPrnOutButton, 0,
  661.             owin->canvas.g_x, owin->canvas.g_y,
  662.             owin->canvas.g_w, owin->canvas.g_h,
  663.             (object[index].ob_state ^ SELECTED), 1);
  664.       }
  665.       
  666.       LastPrnOutButton = PR_CEN;
  667.     }
  668.     else {
  669.       objc_change(object, PR_CEN, 0,
  670.               owin->canvas.g_x, owin->canvas.g_y,
  671.               owin->canvas.g_w, owin->canvas.g_h,
  672.               (object[index].ob_state ^ SELECTED), 1);
  673.     }
  674.  
  675.     if (strcmp(st->Outfile, "CEN:")) {
  676.       strcpy(st->Outfile, "CEN:");
  677.       sprintf(st->Command,
  678.         "%smark /OutputFile (CEN:) currentdevice putdeviceprops pop\n",nl);
  679.       SendCommand(st, pw, dest);
  680.         }
  681.  
  682.     break;
  683.  
  684.     case PR_PRN:    /* centronics port via gemdos */
  685.  
  686.     if (LastPrnOutButton != PR_PRN) {
  687.  
  688.       if (LastPrnOutButton) {
  689.         objc_change(object, LastPrnOutButton, 0,
  690.             owin->canvas.g_x, owin->canvas.g_y,
  691.             owin->canvas.g_w, owin->canvas.g_h,
  692.             (object[index].ob_state ^ SELECTED), 1);
  693.       }
  694.  
  695.       LastPrnOutButton = PR_PRN;
  696.  
  697.     }
  698.     else {
  699.       objc_change(object, PR_PRN, 0,
  700.               owin->canvas.g_x, owin->canvas.g_y,
  701.               owin->canvas.g_w, owin->canvas.g_h,
  702.               (object[index].ob_state ^ SELECTED), 1);
  703.     }
  704.     
  705.     if (strcmp(st->Outfile, "PRN:")) {
  706.       strcpy(st->Outfile, "PRN:");
  707.       sprintf(st->Command,
  708.         "%smark /OutputFile (PRN:) currentdevice putdeviceprops pop\n",nl);
  709.       SendCommand(st, pw, dest);
  710.     }
  711.  
  712.     break;
  713.  
  714.     case PR_OFILE:    /* output to 'Outfile' */
  715.  
  716.     if (LastPrnOutButton != PR_OFILE) {
  717.  
  718.       if (LastPrnOutButton) {
  719.         objc_change(object, LastPrnOutButton, 0,
  720.             owin->canvas.g_x, owin->canvas.g_y,
  721.             owin->canvas.g_w, owin->canvas.g_h,
  722.             (object[index].ob_state ^ SELECTED), 1);
  723.       }
  724.  
  725.       LastPrnOutButton = PR_OFILE;
  726.     }
  727.     else {
  728.       objc_change(object, PR_OFILE, 0,
  729.               owin->canvas.g_x, owin->canvas.g_y,
  730.               owin->canvas.g_w, owin->canvas.g_h,
  731.               (object[index].ob_state ^ SELECTED), 1);
  732.     }
  733.  
  734.     /* Use any previously selected output file as the default. */
  735.  
  736.     if (strlen(st->Outfile)) {
  737.         strcpy(st->FileSel, st->Outfile);
  738.     }
  739.     else {
  740.         strcpy(st->FileSel, "");
  741.     }
  742.  
  743.     if ((Select = GetFile(st, "*.*")) != 0) {
  744.         strcpy(st->Outfile, st->FileSel);
  745.         sprintf(st->Command, 
  746.         "%smark /OutputFile (%s%s) currentdevice putdeviceprops pop\n",
  747.         nl, st->DirSpec, st->Outfile);
  748.         SendCommand(st, pw, dest);
  749.     }
  750.  
  751.     break;
  752.     }
  753.  
  754.     if (Deselect) {
  755.       objc_change(object, index, 0,
  756.       owin->canvas.g_x, owin->canvas.g_y,
  757.       owin->canvas.g_w, owin->canvas.g_h,
  758.       (object[index].ob_state ^ SELECTED), 1);
  759.     }
  760.  
  761.  
  762.     return 0;
  763. }
  764.  
  765. int
  766. pag_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
  767.     PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
  768. {
  769.     objc_change(object, index, 0,
  770.     owin->canvas.g_x, owin->canvas.g_y,
  771.     owin->canvas.g_w, owin->canvas.g_h,
  772.     (object[index].ob_state ^ SELECTED), 1);
  773.  
  774.     graf_mouse(BUSY_BEE, 0L);
  775.     HandlePageSelect(vw, st, pw, dest, index);
  776.     graf_mouse(ARROW, 0L);
  777.  
  778.     return 0;
  779. }
  780.  
  781.  
  782. int
  783. ign_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
  784.     PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
  785. {
  786.     objc_change(object, index, 0,
  787.     owin->canvas.g_x, owin->canvas.g_y,
  788.     owin->canvas.g_w, owin->canvas.g_h,
  789.     (object[index].ob_state ^ SELECTED), 1);
  790.  
  791.     return 0;
  792. }
  793.  
  794. OBJECT *
  795. CreatePageObj(int pages)
  796. {
  797.     char (*str)[4], *itoa();
  798.  
  799.     int i, j, count, rows, cols, prod;
  800.  
  801.     OBJECT *pobj;
  802.     TEDINFO *tinf;
  803.  
  804.     rows = cols = (int)(pow(pages, .5) + .1);
  805.  
  806.     while (rows*cols < pages) {
  807.     ++cols;
  808.     }
  809.  
  810.     prod = rows * cols;
  811.  
  812.     /* Put some error checks here! */
  813.  
  814.     pobj = (OBJECT *)gs_malloc((uint)(prod+1), sizeof(OBJECT), "page object");
  815.     tinf = (TEDINFO *)gs_malloc((uint)pages, sizeof(TEDINFO), "page tedinfo");
  816.     str  = (char (*)[4])gs_malloc((uint)pages, 4, "page strings");
  817.  
  818.     AssignObj(&pobj[0], -1, 1, prod, G_BOX, HIDETREE, OUTLINED, 0x11100L,
  819.     0, 0, 4*cols, 2*rows);
  820.  
  821.     for (j=0, count=0; j<rows; ++j) {
  822.     for (i=0; i<cols; ++i) {
  823.         if (++count <= pages) {
  824.         itoa(count, str[count-1]);
  825.  
  826.         AssignTinf(&tinf[count-1], str[count-1] , "", "",
  827.             3, 6, 2, 0x1100, 0x0, 1, 2, 1);
  828.  
  829.         AssignObj(&pobj[count], count+1, -1, -1, G_BOXTEXT, SELECTABLE,
  830.             NORMAL, &tinf[count-1], 4*i, 2*j, 4, 2);
  831.         }
  832.         else {
  833.         AssignObj(&pobj[count], count+1, -1, -1, G_BOX, NONE,
  834.             NORMAL, 0x11131L, 4*i, 2*j, 4, 2);
  835.         }
  836.     }
  837.     }
  838.  
  839.     pobj[prod].ob_next = 0;
  840.     pobj[prod].ob_flags |= LASTOB;
  841.  
  842.     i=-1;
  843.     do {
  844.     ++i;
  845.     rsrc_obfix(pobj, i);
  846.     } while (!(pobj[i].ob_flags & LASTOB));
  847.  
  848.     return pobj;
  849. }
  850.  
  851. int
  852. DeletePageObj(PSTATE *st, WINDOW *pwin)
  853. {
  854.     int rows, cols, prod;
  855.     OBJECT *pobj = (OBJECT *)pwin->obj;
  856.     TEDINFO *tinf = (TEDINFO *)pobj[1].ob_spec;
  857.  
  858.     rows = cols = (int)(pow(st->Doc->numpages, .5) + .1);
  859.  
  860.     while (rows*cols < st->Doc->numpages) {
  861.     ++cols;
  862.     }
  863.  
  864.     prod = rows * cols;
  865.  
  866.     if (pwin->opened || pwin->iconified) {
  867.     WinClose(pwin);
  868.     WList = WinListDelete(WList, pwin);
  869.     }
  870.  
  871.     gs_free((char *)tinf->te_ptext, st->Doc->numpages, 4, "page strings");
  872.  
  873.     gs_free((char *)tinf, st->Doc->numpages, sizeof(TEDINFO), "page tedinfo");
  874.  
  875.     gs_free((char *)pobj, prod+1, sizeof(OBJECT), "page object");
  876.  
  877.     pwin->obj = NULL;
  878.     pwin->frame.g_x = 0;
  879.     pwin->frame.g_y = 0;
  880.     pwin->frame.g_w = 0;
  881.     pwin->frame.g_h = 0;
  882.  
  883.     st->Doc->name[0] = '\0';
  884.     st->Doc->maxpages = 0;
  885.     st->Doc->numpages = 0;
  886.     st->Doc->currentpage = 0;
  887.  
  888.     return 0;
  889. }
  890.  
  891. int
  892. AssignObj(OBJECT *obj, int next, int head, int tail, int type, int flags,
  893.     int state, unsigned long spec, int x, int y, int width, int height)
  894. {
  895.     obj->ob_next = (short)next;
  896.     obj->ob_head = (short)head;
  897.     obj->ob_tail = (short)tail;
  898.     obj->ob_type = (unsigned short)type;
  899.     obj->ob_flags = (unsigned short)flags;
  900.     obj->ob_state = (unsigned short)state;
  901.     obj->ob_spec = spec;
  902.     obj->ob_x = (short)x;
  903.     obj->ob_y = (short)y;
  904.     obj->ob_width = (short)width;
  905.     obj->ob_height = (short)height;
  906.  
  907.     return 0;
  908. }
  909.  
  910. int
  911. AssignTinf(TEDINFO *inf, char *ptext, char *ptmplt, char *pvalid,
  912.     int font, int junk1, int just, int color, int junk2,
  913.     int thickness, int txtlen, int tmplen)
  914. {
  915.     inf->te_ptext = ptext;
  916.     inf->te_ptmplt = ptmplt;
  917.     inf->te_pvalid = pvalid;
  918.     inf->te_font = (short)font;
  919.     inf->te_junk1 = (short)junk1;
  920.     inf->te_just = (short)just;
  921.     inf->te_color = (short)color;
  922.     inf->te_junk2 = (short)junk2;
  923.     inf->te_thickness = (short)thickness;
  924.     inf->te_txtlen = (short)txtlen;
  925.     inf->te_tmplen = (short)tmplen;
  926.  
  927.     return 0;
  928. }
  929.  
  930. int
  931. PageFilter(char* InputName, DOCUMENT *doc)
  932. {
  933.     char *sptr, line[MAXLEN];
  934.  
  935.     int PageCount=0, length=0, maxpages=20;
  936.  
  937.     fpos_t EndPosition;
  938.  
  939.     FILE *InFile;
  940.  
  941.     PAGEINFO *temp;
  942.  
  943.     if ((InFile = fopen(InputName, "r")) == NULL) {
  944.     return -1;
  945.     }
  946.  
  947.     strcpy((char *)doc->name, InputName);
  948.     doc->maxpages = maxpages;
  949.  
  950.     if (doc->pageinf == NULL) {
  951.     doc->pageinf = (PAGEINFO *)gs_malloc(maxpages, sizeof(PAGEINFO),
  952.     "page info");
  953.     memset(doc->pageinf, 0, maxpages*sizeof(PAGEINFO));
  954.     }
  955.  
  956.     fgetpos(InFile, &doc->pageinf[PageCount].start);
  957.  
  958.     while (fgets(line, MAXLEN, InFile) != NULL) {
  959.     length += strlen(line);
  960.     if (strncmp(line, "%%", 2) == 0) {
  961.  
  962.         if (strncmp(line, "%%Page:", 7) == 0 ||
  963.         strncmp(line, "%%Trailer", 9) == 0) {
  964.  
  965.         if (doc->pageinf[PageCount].extracted == 1) {
  966.         doc->pageinf[PageCount].extracted = -1;
  967.         }
  968.  
  969.         doc->pageinf[PageCount].length = length;
  970.         length = 0;
  971.  
  972.         if (++PageCount > maxpages) {
  973.         int oldsize = maxpages;
  974.         maxpages += 20;
  975.  
  976.         /* Allocate a larger buffer. */
  977.         temp = (PAGEINFO *)gs_malloc(maxpages, sizeof(PAGEINFO),
  978.             "page info");
  979.  
  980.         memset(doc->pageinf, 0, maxpages*sizeof(PAGEINFO));
  981.  
  982.         /* Copy the old buffer to the new one. */
  983.         memcpy(temp, doc->pageinf,
  984.             (MIN(oldsize, maxpages))*sizeof(PAGEINFO));
  985.  
  986.         /* Free the old buffer. */
  987.         gs_free((char *)doc->pageinf, oldsize, sizeof(PAGEINFO),
  988.             "page info");
  989.  
  990.         doc->pageinf = temp;
  991.         doc->maxpages = maxpages;
  992.         }
  993.  
  994.         fgetpos(InFile, &doc->pageinf[PageCount].start);
  995.     }
  996.     }
  997.     }
  998.  
  999.     doc->pageinf[PageCount].length = length;
  1000.  
  1001.     doc->numpages = PageCount-1;
  1002.  
  1003.     fclose(InFile);
  1004.  
  1005.     return PageCount-1;
  1006. }
  1007.  
  1008. int PageCopy(int page, char *OutName, DOCUMENT *doc)
  1009. {
  1010.     char *itoa(), temp[MAXLEN], *buffer;
  1011.  
  1012.     int count, ch, ret;
  1013.  
  1014.     FILE *InFile, *OutFile;
  1015.  
  1016.     if (doc->numpages <= 1) {
  1017.     return -1;
  1018.     }
  1019.  
  1020.     if (page != 0) {
  1021.     itoa(page, temp);
  1022.     strcat(OutName, temp);
  1023.     }
  1024.  
  1025.     strcat(OutName, ".ps");
  1026.  
  1027.     if (doc->pageinf[page].extracted == 1) {
  1028.     return 0;
  1029.     }
  1030.  
  1031.     if ((InFile = fopen(doc->name, "r")) == NULL) {
  1032.     return -1;
  1033.     }
  1034.  
  1035.     if ((OutFile = fopen(OutName, "wb")) == NULL) {
  1036.     return -1;
  1037.     }
  1038.  
  1039.     fsetpos(InFile, &doc->pageinf[page].start);
  1040.  
  1041.     count = doc->pageinf[page].length;
  1042.  
  1043.     if ((buffer = (char *)gs_malloc(count, 1, "copy buffer")) != NULL) {
  1044.  
  1045.     if ((ret = fread(buffer, 1, count, InFile)) != count)
  1046.         eprintf("PageCopy: Read Error!");
  1047.  
  1048.     if ((ret = fwrite(buffer, 1, count, OutFile)) != count) 
  1049.         eprintf("PageCopy: Write Error!");
  1050.  
  1051.     gs_free(buffer, count, 1, "copy buffer");
  1052.  
  1053.     }
  1054.     else {
  1055.  
  1056.     while (count--) {
  1057.         ch = fgetc(InFile);
  1058.         fputc(ch, OutFile);
  1059.     }
  1060.  
  1061.     }
  1062.  
  1063.     doc->pageinf[page].extracted = 1;
  1064.  
  1065.     fclose(InFile);
  1066.     fclose(OutFile);
  1067. }
  1068.