home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / pollmsgs < prev    next >
Encoding:
Text File  |  1991-02-04  |  26.9 KB  |  538 lines

  1. /* > $.CLIB.C.pollmsgs
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      routine to perform the messages related return codes from
  21.  *      SWI(Wimp_Poll)
  22.  */
  23. #include "c.poll_h"
  24. #include <stdio.h>
  25.  
  26. int haswin_poll_message_ack(int (*user)(int, buffer *), buffer *pbuf) {
  27.  
  28.  
  29.         if (user)
  30.                 (*user)(HASWIN_POLL_Message_Ack, pbuf);
  31.         switch (pbuf->i[4]) {
  32.         }
  33.         return(HASWIN_TRUE);
  34. }
  35.  
  36. int haswin_poll_message(int (*user)(int, buffer *), buffer *pbuf) {
  37.  
  38.         _kernel_swi_regs  regs;
  39.         window            *wptr;
  40.         icon              *iptr;
  41.         char              tmp[256], *ptr;
  42.         int               i, len;
  43.  
  44.         if (pbuf->i[1] == haswin_taskid)
  45.                 return(HASWIN_TRUE);
  46.         switch (pbuf->i[4]) {
  47.         case MESSAGE_Quit:
  48.                 if (user)
  49.                         (*user)(HASWIN_POLL_poll_MQuit, pbuf);
  50.                 /* NB: we MUST quit now */
  51.                 haswin_exit(HASWIN_TRUE);
  52.                 break;
  53.         case MESSAGE_PreQuit:
  54. /*
  55.  *               haswin_quitfrom = pbuf->i[1];
  56.  *               haswin_flags |= HASWIN_FLAGS_QUITING;
  57.  *               regs.r[0] = HASWIN_POLL_Message_Ack;
  58.  *               regs.r[1] = (int)pbuf;
  59.  *               regs.r[2] = haswin_quitfrom;
  60.  *               pbuf->i[3] = pbuf->i[2];
  61.  *               haswin_swi(HASWIN_Send_message, ®s);
  62.  *               haswin_reopenwindow(haswin_quitwin);
  63.  */
  64.                 break;
  65.         case MESSAGE_SetSlot:
  66.                 if ((pbuf->i[6] == haswin_taskid) && (haswin_flags & HASWIN_FLAGS_SETSLOT)) {
  67.                         if (pbuf->i[5] >= haswin_getprogramtop()) {
  68.                                 haswin_initialiseuserheap(pbuf->i[5]-haswin_getprogramtop());
  69.                         }
  70.                         /* acknowledge the slot size change */
  71.                         regs.r[0] = HASWIN_POLL_Message_Ack;
  72.                         regs.r[1] = (int)pbuf;
  73.                         regs.r[2] = pbuf->i[1];
  74.                         pbuf->i[3] = pbuf->i[2];
  75.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  76.                                 return(HASWIN_FALSE);
  77.                 }
  78.                 break;
  79.                 /*
  80.                  * DataLoad message.  Call the dataload routine and
  81.                  * then acknowledge it if it returns TRUE.  If we are
  82.                  * using <Wimp$Scrap> then HASWIN_FLAGS_KILLWS will be
  83.                  * true, so remove <Wimp$Scrap>.
  84.                  */
  85.         case MESSAGE_DataLoad:
  86.                 if ((user) && (!((*user)(HASWIN_POLL_poll_Load, pbuf))))
  87.                         return(HASWIN_FALSE);
  88.                 if (haswin_loadfileroutine) {
  89.                         if ((*haswin_loadfileroutine)(&pbuf->c[44], pbuf)) {
  90.                                 if (haswin_flags & HASWIN_FLAGS_KILLWS) {
  91.                                         /* delete the file <Wimp$Scrap>    */
  92.                                         haswin_flags &= ~HASWIN_FLAGS_KILLWS;
  93.                                         if (remove("<Wimp$Scrap>") != 0)
  94.                                                 break;
  95.                                 }
  96.                                 regs.r[0] = HASWIN_POLL_Message;
  97.                                 regs.r[1] = (int)pbuf;
  98.                                 regs.r[2] = pbuf->i[1];
  99.                                 pbuf->i[3] = pbuf->i[2];
  100.                                 pbuf->i[4] = MESSAGE_DataLoadAck;
  101.                                 if (!haswin_swi(HASWIN_Send_message, ®s))
  102.                                         return(HASWIN_FALSE);
  103.                         }
  104.                 }
  105.                 break;
  106.                 /*
  107.                  * DataLoadAck message.  If we are loading call the
  108.                  * dataload routine with the filename but no buffer.
  109.                  * If we are saving call the datasave routine with the
  110.                  * filename but no buffer.  If we are printing call the
  111.                  * print routine with the filename but no buffer.  This is
  112.                  * for the load/save/print routines to clear away files.
  113.                  */
  114.         case MESSAGE_DataLoadAck:
  115.                 if (haswin_flags & HASWIN_FLAGS_SAVING) {
  116.                         if (haswin_savefileroutine)
  117.                                 if ((*haswin_savefileroutine)(&pbuf->c[44], (buffer *)0))
  118.                                         haswin_setfiletype(&pbuf->c[44], pbuf->i[10]);
  119.                         haswin_flags &= ~HASWIN_FLAGS_SAVING;
  120.                 } else if (haswin_flags & HASWIN_FLAGS_LOADING) {
  121.                         if (haswin_loadfileroutine)
  122.                                 (*haswin_loadfileroutine)(&pbuf->c[44], (buffer *)0);
  123.                         haswin_flags &= ~HASWIN_FLAGS_LOADING;
  124.                 } else if (haswin_flags & HASWIN_FLAGS_PRINTING) {
  125.                         if (haswin_printfileroutine)
  126.                                 (*haswin_printfileroutine)(&pbuf->c[44], (buffer *)0);
  127.                         haswin_flags &= ~HASWIN_FLAGS_PRINTING;
  128.                 }
  129.                 break;
  130.                 /*
  131.                  * DataSave message.  If we can handle Ram receive
  132.                  * transfers then set the RAMGO flag and acknowledge with
  133.                  * a RAMFetch message giving the buffer and its size.
  134.                  */
  135.         case MESSAGE_DataSave:
  136.                 if (haswin_ramrxroutine) {
  137.                         if ((user) && (!((*user)(HASWIN_POLL_poll_RAMrx, pbuf))))
  138.                                 return(HASWIN_FALSE);
  139.                         /* can do a ram transfer, so go for it */
  140.                         regs.r[0] = HASWIN_POLL_Message_Rec;
  141.                         regs.r[1] = (int)pbuf;
  142.                         regs.r[2] = pbuf->i[1];
  143.                         pbuf->i[0] = 28;
  144.                         pbuf->i[3] = pbuf->i[2];
  145.                         pbuf->i[4] = MESSAGE_RAMFetch;
  146.                         pbuf->i[5] = (int)haswin_ramrxbuffer;
  147.                         pbuf->i[6] = haswin_ramrxlength;
  148.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  149.                                 return(HASWIN_FALSE);
  150.                         haswin_flags |= HASWIN_FLAGS_RAMGO;
  151.                         haswin_ramrxbytes = 0;
  152.                 } else {
  153.                         if ((user) && (!((*user)(HASWIN_POLL_poll_Save, pbuf))))
  154.                                 return(HASWIN_FALSE);
  155.                         regs.r[0] = HASWIN_POLL_Message;
  156.                         regs.r[1] = (int)pbuf;
  157.                         regs.r[2] = pbuf->i[1];
  158.                         pbuf->i[0] = 60;
  159.                         pbuf->i[3] = pbuf->i[2];
  160.                         pbuf->i[4] = MESSAGE_DataSaveAck;
  161.                         pbuf->i[9] = -1;
  162.                         strcpy(&(pbuf->c[44]), "<Wimp$Scrap>");
  163.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  164.                                 return(HASWIN_FALSE);
  165.                         haswin_flags |= HASWIN_FLAGS_KILLWS;
  166.                 }
  167.                 break;
  168.         case MESSAGE_DataSaveAck:
  169.                 if (haswin_flags & HASWIN_FLAGS_SAVING) {
  170.                         strncpy(haswin_defaultsavefile, &(pbuf->c[44]), 256);
  171.                         haswin_seticondata(haswin_saveiconname, haswin_defaultsavefile);
  172.                         if (haswin_savefileroutine) {
  173.                                 if ((*haswin_savefileroutine)(&(pbuf->c[44]), pbuf)) {
  174.                                         regs.r[0] = HASWIN_POLL_Message_Rec;
  175.                                         regs.r[1] = (int)pbuf;
  176.                                         regs.r[2] = pbuf->i[1];
  177.                                         pbuf->i[3] = pbuf->i[2];
  178.                                         pbuf->i[4] = MESSAGE_DataLoad;
  179.                                         if (!haswin_swi(HASWIN_Send_message, ®s))
  180.                                                 return(HASWIN_FALSE);
  181.                                 }
  182.                         }
  183.                         break;
  184.                 }
  185.                 if (haswin_flags & HASWIN_FLAGS_LOADING) {
  186.                         strncpy(haswin_defaultloadfile, &(pbuf->c[44]), 256);
  187.                         haswin_seticondata(haswin_loadiconname, haswin_defaultloadfile);
  188.                         regs.r[0] = HASWIN_POLL_Message_Ack;
  189.                         regs.r[1] = (int)pbuf;
  190.                         regs.r[2] = pbuf->i[1];
  191.                         pbuf->i[3] = pbuf->i[2];
  192.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  193.                                 return(HASWIN_FALSE);
  194.                         haswin_flags &= ~HASWIN_FLAGS_LOADING;
  195.                 }
  196.                 break;
  197.         case MESSAGE_DataOpen:
  198.                 if ((haswin_autoloadroutine) && (haswin_autoloadtype == pbuf->i[10])) {
  199.                         /* we have a routine, and correct type, so
  200.                            acknowledge it */
  201.                         regs.r[0] = HASWIN_POLL_Message_Ack;
  202.                         regs.r[1] = (int)pbuf;
  203.                         regs.r[2] = pbuf->i[1];
  204.                         pbuf->i[3] = pbuf->i[2];
  205.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  206.                                 return(HASWIN_FALSE);
  207.                         /* now try to load it */
  208.                         (*haswin_autoloadroutine)(&(pbuf->c[44]), pbuf);
  209.                 }
  210.                 break;
  211.         case MESSAGE_RAMFetch:
  212.                 if (haswin_ramtxroutine) {
  213.                         haswin_ramtxbuffer = haswin_realloc(haswin_ramtxbuffer, pbuf->i[6], "haswin_poll_message", "RAMTransmit buffer");
  214.                         if ((user) && (!((*user)(HASWIN_POLL_poll_RAMtx, pbuf))))
  215.                                 return(HASWIN_FALSE);
  216.                         len=haswin_ramtxroutine(haswin_ramtxbuffer, pbuf->i[6], haswin_ramtxbytes, pbuf);
  217.                         if (len >= 0) {
  218.                                 /* copy the data in the transmit buffer to
  219.                                    the other application */
  220.                                 regs.r[0] = haswin_gettaskid();
  221.                                 regs.r[1] = (int)haswin_ramtxbuffer;
  222.                                 regs.r[2] = pbuf->i[1];
  223.                                 regs.r[3] = pbuf->i[5];
  224.                                 regs.r[4] = len;
  225.                                 if (!haswin_swi(HASWIN_Transfer_block,®s))
  226.                                         return(HASWIN_FALSE);
  227.                                 haswin_ramtxbytes += len;
  228.                                 haswin_flags |= HASWIN_FLAGS_RAMGO;
  229.                                 /* reply with a RAMTransmit */
  230.                                 if (len == pbuf->i[6])
  231.                                         /* not last transfer */
  232.                                         regs.r[0] = HASWIN_POLL_Message_Rec;
  233.                                 else {
  234.                                         /* last transfer */
  235.                                         regs.r[0] = HASWIN_POLL_Message;
  236.                                         haswin_ramtxbytes = 0;
  237.                                 }
  238.                                 regs.r[1] = (int)pbuf;
  239.                                 regs.r[2] = pbuf->i[1];
  240.                                 pbuf->i[0] = 28;
  241.                                 pbuf->i[3] = pbuf->i[2];
  242.                                 pbuf->i[4] = MESSAGE_RAMTransmit;
  243.                                 pbuf->i[6] = len;
  244.                                 if (!haswin_swi(HASWIN_Send_message, ®s))
  245.                                         return(HASWIN_FALSE);
  246.                         } else {
  247.                                 haswin_ramtxbytes = 0;
  248.                                 haswin_flags &= ~HASWIN_FLAGS_RAMGO;
  249.                         }
  250.                 }
  251.                 break;
  252.         case MESSAGE_RAMTransmit:
  253.                 if (!(haswin_flags & HASWIN_FLAGS_RAMGO)) {
  254.                         haswin_internalerror("got a RAM transmit message with nothing to do!");
  255.                         return(HASWIN_FALSE);
  256.                 }
  257.                 /* transfer the data into our buffer */
  258.                 regs.r[0] = pbuf->i[1];
  259.                 regs.r[1] = pbuf->i[5];
  260.                 regs.r[2] = haswin_gettaskid();
  261.                 regs.r[3] = (int)haswin_ramrxbuffer;
  262.                 regs.r[4] = pbuf->i[6];
  263.                 if (!haswin_swi(HASWIN_Transfer_block, ®s))
  264.                         return(HASWIN_FALSE);
  265.                 /* pass this buffer to the user routine to deal with */
  266.                 if ((haswin_ramrxroutine) && 
  267.                     (*haswin_ramrxroutine)(haswin_ramrxbuffer, pbuf->i[6], haswin_ramrxbytes, pbuf) && (pbuf->i[6] == haswin_ramrxlength)) {
  268.                         /* User routine returned true and the buffers are
  269.                            transferring full, try for more data */
  270.                         haswin_ramrxbytes += pbuf->i[6];
  271.                         regs.r[0] = HASWIN_POLL_Message_Rec;
  272.                         regs.r[1] = (int)pbuf;
  273.                         regs.r[2] = pbuf->i[1];
  274.                         pbuf->i[0] = 28;
  275.                         pbuf->i[3] = pbuf->i[2];
  276.                         pbuf->i[4] = MESSAGE_RAMFetch;
  277.                         pbuf->i[5] = (int)haswin_ramrxbuffer;
  278.                         pbuf->i[6] = haswin_ramrxlength;
  279.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  280.                                 return(HASWIN_FALSE);
  281.                 } else {
  282.                         haswin_ramrxbytes = 0;
  283.                         haswin_flags &= ~HASWIN_FLAGS_RAMGO;
  284.                 }
  285.                 break;
  286.         case MESSAGE_Palette:
  287.                 if (user)
  288.                         return((*user)(HASWIN_POLL_Message, pbuf));
  289.                 break;
  290.         case MESSAGE_Notify:
  291.                 if (user)
  292.                         return((*user)(HASWIN_POLL_Message, pbuf));
  293.                 break;
  294.         case MESSAGE_MenuWarning:
  295.                 if ((haswin_menu.actual) && (haswin_menu.message))
  296.                         return((*haswin_menu.message)(pbuf, &haswin_menu));
  297.                 if ((user) && (!((*user)(HASWIN_POLL_Message, pbuf))))
  298.                         return(HASWIN_FALSE);
  299.                 break;
  300.         case MESSAGE_ModeChange:
  301.                 haswin_updateallvduvariables(0);
  302.                 if (user)
  303.                         return((*user)(HASWIN_POLL_Message, pbuf));
  304.                 break;
  305.         case MESSAGE_HelpRequest:
  306.                 wptr = haswin_findwindowhandle(pbuf->i[8]);
  307.                 iptr = haswin_findiconhandle(wptr, pbuf->i[9]);
  308.                 tmp[0] = 0;
  309.                 if ((haswin_flags & HASWIN_FLAGS_HELPFUL) &&
  310.                     ((int)wptr > 0) && (wptr->flags & WINDOW_HELPFUL)) {
  311.                         /* we are being helpful, so look for icon */
  312.                         if (iptr) {
  313.                                 /* got one, if helpmsg then use it else
  314.                                    say something helpful */
  315.                                 if (iptr->helpmsg)
  316.                                         strcpy(tmp, iptr->helpmsg);
  317.                                 else {
  318.                                         sprintf(tmp, "This is Icon '%s' in Window '%s'|M", haswin_geticontitle(iptr), haswin_getwindowtitle(wptr));
  319.                                         if (iptr->window) {
  320.                                                 strcat(tmp, "Click SELECT to open Window ");
  321.                                                 strcat(tmp, haswin_getwindowtitle(iptr->window));
  322.                                                 strcat(tmp, "|M");
  323.                                         }
  324.                                         i = 0;
  325.                                         if (iptr->menu)
  326.                                                 i += 1;
  327.                                         if (iptr->help)
  328.                                                 i += 2;
  329.                                         if (iptr->flags & ICON_CANQUIT)
  330.                                                 i += 4;
  331.                                         if (i == 1) {
  332.                                                 strcat(tmp, "Click MENU for a menu|M");
  333.                                         } else if (i > 1) {
  334.                                                 strcat(tmp, "Click MENU for a menu to");
  335.                                                 if (i & 2)
  336.                                                         strcat(tmp, " get help,");
  337.                                                 if (i & 4)
  338.                                                         strcat(tmp, " quit,");
  339.                                                 i = strlen(tmp);
  340.                                                 tmp[i-1] = '|';
  341.                                                 tmp[i] = 'M';
  342.                                                 tmp[i+1] = '\0';
  343.                                         }
  344.                                         if (iptr->mousebutton)
  345.                                                 strcat(tmp,"Click ADJUST for action|M");
  346.                                 }
  347.                         } else {
  348.                                 /* got a window instead, one, if helpmsg
  349.                                    then use it else say something helpful */
  350.                                 if (wptr->helpmsg)
  351.                                         strcpy(tmp, wptr->helpmsg);
  352.                                 else {
  353.                                         sprintf(tmp, "This is Window '%s'|M", haswin_getwindowtitle(wptr));
  354.                                         if (wptr->mousebutton)
  355.                                                 strcat(tmp,"Click SELECT for action|M");
  356.                                         i = 0;
  357.                                         if (wptr->menu)
  358.                                                 i += 1;
  359.                                         if (wptr->help)
  360.                                                 i += 2;
  361.                                         switch (i) {
  362.                                         case 0:
  363.                                                 break;
  364.                                         case 1:
  365.                                                 strcat(tmp, "Click MENU for a menu|M");
  366.                                                 break;
  367.                                         case 2:
  368.                                         case 3:
  369.                                                 strcat(tmp, "Click MENU for a menu to get help|M");
  370.                                                 break;
  371.                                         }
  372.                                         if (wptr->mousebutton)
  373.                                                 strcat(tmp,"Click ADJUST for action|M");
  374.                                 }
  375.                         }
  376.                 } else if ((haswin_flags & HASWIN_FLAGS_HELPFUL) &&
  377.                     ((int)wptr < 0) && (iptr)) {
  378.                         /* got icon on icon bar, if helpmsg then use it else
  379.                            say something helpful */
  380.                         if (iptr->helpmsg)
  381.                                 strcpy(tmp, iptr->helpmsg);
  382.                         else {
  383.                                 sprintf(tmp, "This is the %s Icon|M", haswin_gettaskname());
  384.                                 if (iptr->window) {
  385.                                         strcat(tmp, "Click SELECT to open Window ");
  386.                                         strcat(tmp, haswin_getwindowtitle(iptr->window));
  387.                                         strcat(tmp, "|M");
  388.                                 }
  389.                                 i = 0;
  390.                                 if (iptr->menu)
  391.                                         i += 1;
  392.                                 if (iptr->help)
  393.                                         i += 2;
  394.                                 if (iptr->flags & ICON_CANQUIT)
  395.                                         i += 4;
  396.                                 if (haswin_flags & HASWIN_FLAGS_FILEMENU) {
  397.                                         if (haswin_loadfileroutine)
  398.                                                 i += 8;
  399.                                         if (haswin_savefileroutine)
  400.                                                 i += 16;
  401.                                 }
  402.                                 if (i == 1) {
  403.                                         strcat(tmp, "Click MENU for a menu|M");
  404.                                 } else if (i > 1) {
  405.                                         strcat(tmp, "Click MENU for a menu to");
  406.                                         if (i & 2)
  407.                                                 strcat(tmp, " get help,");
  408.                                         if (i & 8)
  409.                                                 strcat(tmp, " load files,");
  410.                                         if (i & 16)
  411.                                                 strcat(tmp, " save files,");
  412.                                         if (i & 4)
  413.                                                 strcat(tmp, " quit,");
  414.                                         i = strlen(tmp);
  415.                                         tmp[i-1] = '|';
  416.                                         tmp[i] = 'M';
  417.                                         tmp[i+1] = '\0';
  418.                                 }
  419.                                 if (iptr->mousebutton)
  420.                                         strcat(tmp,"Click ADJUST for action|M");
  421.                         }
  422.                 } else {
  423.                         /* we are not helpful, so print helpmsg if there is
  424.                            any, but don't do anything else */
  425.                         if ((iptr) && (iptr->helpmsg))
  426.                                 strcpy(tmp, iptr->helpmsg);
  427.                         else if (((int)wptr > 0) && (wptr->helpmsg))
  428.                                 strcpy(tmp, wptr->helpmsg);
  429.                 }
  430.                 if (tmp[0] != 0) {
  431.                         ptr = tmp;
  432.                         i = 20;
  433.                         while (*ptr) {
  434.                                 if (*ptr == '\n') {
  435.                                         pbuf->c[i++] = '|';
  436.                                         pbuf->c[i++] = 'M';
  437.                                 } else
  438.                                         pbuf->c[i++] = *ptr++;
  439.                         }
  440.                         pbuf->c[i] = 0;
  441.                         regs.r[0] = HASWIN_POLL_Message;
  442.                         regs.r[1] = (int)pbuf;
  443.                         regs.r[2] = pbuf->i[1];
  444.                         pbuf->i[3] = pbuf->i[2];
  445.                         pbuf->i[4] = MESSAGE_HelpReply;
  446.                         pbuf->i[0] = (i+4) & 0xFFFFFFFC;
  447.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  448.                                 return(HASWIN_FALSE);
  449.                 }
  450.                 break;
  451.         case MESSAGE_TaskNameRq:
  452.                 break;
  453.         case MESSAGE_TaskNameIs:
  454.                 if (haswin_flags & HASWIN_FLAGS_TASKIS) {
  455.                         strcpy(haswin_tasknameis, &pbuf->c[28]);
  456.                         haswin_flags &= ~HASWIN_FLAGS_TASKIS;
  457.                 } else if (user)
  458.                         return((*user)(HASWIN_POLL_Message, pbuf));
  459.                 break;
  460.         case MESSAGE_TaskInitialise:
  461.                 if (user)
  462.                         return((*user)(HASWIN_POLL_Message, pbuf));
  463.                 break;
  464.         case MESSAGE_TaskClosedown:
  465.                 if (user)
  466.                         return((*user)(HASWIN_POLL_Message, pbuf));
  467.                 break;
  468.         case MESSAGE_PrintFile:
  469.                 /*
  470.                  * this message is the reply the Printer Driver sends if we
  471.                  * drop a file on it, or ask it to print in some other way.
  472.                  * If the user program has not provided anything to print
  473.                  * the file with we will soon get a MESSAGE_DataSaveAck from
  474.                  * the printer driver so we need do nothing special to get a
  475.                  * go at a normal save to the printer driver.
  476.                  */
  477.                 haswin_flags &= ~(HASWIN_FLAGS_SAVING|HASWIN_FLAGS_LOADING);
  478.                 haswin_flags |= HASWIN_FLAGS_PRINTING;
  479.                 if ((user) && (!((*user)(HASWIN_POLL_poll_Print, pbuf))))
  480.                         return(HASWIN_FALSE);
  481.                 if (haswin_printfileroutine) {
  482.                         regs.r[0] = HASWIN_POLL_Message_Rec;
  483.                         regs.r[1] = (int)pbuf;
  484.                         regs.r[2] = pbuf->i[1];
  485.                         pbuf->i[3] = pbuf->i[2];
  486.                         pbuf->i[4] = MESSAGE_DataLoad;
  487.                         if (!haswin_swi(HASWIN_Send_message, ®s))
  488.                                 return(HASWIN_FALSE);
  489.                 }
  490.                 break;
  491.         case MESSAGE_WillPrint:
  492.                 haswin_errorprintf("WillPrint from id=%d", pbuf->i[1]);
  493.                 break;
  494.         case MESSAGE_PrintSave:
  495.                 haswin_errorprintf("PrintSave from id=%d", pbuf->i[1]);
  496.                 break;
  497.         case MESSAGE_SetPrinter:
  498.         case MESSAGE_PrintInit:
  499.                 haswin_initialisepdriver();
  500.                 break;
  501.         case MESSAGE_PrintBusy:
  502.                 haswin_errorprintf("PrintBusy from id=%d", pbuf->i[1]);
  503.                 break;
  504.         case MESSAGE_PrintTypeOdd:
  505.                 /*
  506.                  * we get this when the printer driver wants to know how to
  507.                  * print a file.  We ask the user print routine if it knows
  508.                  * the filetype and send a MESSAGE_PrintTypeKnown if it does
  509.                  * The user print routine must actually print to the file if
  510.                  * it knows how to.
  511.                  */
  512.                 if (haswin_printfileroutine) {
  513.                         strcpy(tmp, "<Printer$Temp>");
  514.                         if ((*haswin_printfileroutine)(tmp, pbuf)) {
  515.                                 regs.r[0] = HASWIN_POLL_Message_Rec;
  516.                                 regs.r[1] = (int)pbuf;
  517.                                 regs.r[2] = pbuf->i[1];
  518.                                 pbuf->i[3] = pbuf->i[2];
  519.                                 pbuf->i[4] = MESSAGE_PrintTypeKnown;
  520.                                 strcpy(&(pbuf->c[44]), tmp);
  521.                                 pbuf->i[0] = (44 + strlen(tmp)) & 0xFFFFFFFC;
  522.                                 if (!haswin_swi(HASWIN_Send_message, ®s))
  523.                                         return(HASWIN_FALSE);
  524.                         }
  525.                 }
  526.                 break;
  527.         case MESSAGE_PrintTypeKnown:
  528.                 haswin_errorprintf("PrintTypeKnown from id=%d", pbuf->i[1]);
  529.                 break;
  530.         default:
  531.                 if (user)
  532.                         return((*user)(HASWIN_POLL_Message, pbuf));
  533.                 break;
  534.         }
  535.         return(HASWIN_TRUE);
  536. }
  537.  
  538.