home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / popups / Docs / ExampleSrc / c / _Print < prev    next >
Encoding:
Text File  |  1993-05-23  |  4.8 KB  |  154 lines

  1. /*  File:     _Print.c
  2.  *  Purpose:  Supplies functionality for a PopUp
  3.  *  Author:   © Copyright 1993 Jason Williams
  4.  *            All rights reserved
  5.  */
  6.  
  7. #include "DeskLib:GFX.h"
  8. #include "DeskLib:Icon.h"
  9. #include "DeskLib:PDriver.h"
  10. #include "DeskLib:WimpSWIs.h"
  11. #include "DeskLib:SWI.h"
  12. #include "DeskLib:Template.h"
  13.  
  14.  
  15. #include "Server.h"
  16.  
  17.  
  18. typedef struct
  19. {
  20.   int numcopies;
  21. } print_data;
  22.  
  23.  
  24. /*  First of all, we define a handler_info structure for our PopUp handler
  25.  *  which describes it to the manager. This is referenced externally
  26.  *  by the server to find the procedure to call with events for any PopUp
  27.  *  of this type, etc.
  28.  *  (We also prototype the handler function so we can reference it here)
  29.  */
  30.  
  31. static int Handler_Print(int, ctrl_block *, void *, event_pollblock *);
  32.  
  33. handler_info HandlerInfo_Print =
  34. {
  35.   "Print",                                   /* PopUp type/name string       */
  36.   0x00000001,                                /* Flag word (MENU only)        */
  37.   Handler_Print,                             /* Handler procedure            */
  38.   0                                          /* Instantiation workspace size */
  39. };
  40.  
  41.  
  42.  
  43. static BOOL printerpresent = FALSE;          /* Is a pdriver present?        */
  44.  
  45.  
  46. /*  The Handler_ function referenced in the above info struct will handle all
  47.  *  calls from the server during normal operation...
  48.  */
  49.  
  50. static BOOL Handler_Print(int reasoncode, ctrl_block *ctrl,
  51.                           void *privateworkspace, event_pollblock *event)
  52. {
  53.   switch(reasoncode)
  54.   {
  55.     case REASON_OPEN:
  56.       {
  57.         window_handle windowhandle;
  58.         window_block  *window;
  59.         print_data    *info;
  60.         char          *printername;
  61.  
  62.         /*  Find the template. NOTE that if you provide a STATIC popup, you
  63.          *  MUST support multiple instantiations, so MUST use Template_Clone()
  64.          *  Also note that if bringing up a MENU LEAF window, we must clone
  65.          *  our template data into the RMA so the WIMP does not crash! ;-(
  66.           */
  67.  
  68.         info = (print_data *) (((int)event) + POPUP_DATA_OFFSET);
  69.  
  70.         if ((ctrl->appflags & APPFLAGS_ISLEAF) == 0)
  71.           window = Template_Find("Print");
  72.           /* (The close icon is there already) */
  73.         else
  74.         {
  75.           window = Template_RMAFind("Print");
  76.           window->flags.data.closeicon = FALSE;
  77.           /* (Remove the close icon. NOTE that this is a COPY of the window
  78.            * so does not permanently remove the icon from the template)
  79.            */
  80.         }
  81.  
  82.         if (window == NULL) break;
  83.  
  84.         /*  Create the window, and fill in it's icons with the data given
  85.          *  to us in the pollblock. (DATA_BASE is defined above)
  86.          */
  87.         Wimp_CreateWindow(window, &windowhandle);
  88.  
  89.         printername    = PDriver_PrinterName();
  90.         printerpresent = (printername != NULL);
  91.         if (printerpresent)
  92.           SetIconText(windowhandle, 1, printername);
  93.         else
  94.           SetIconText(windowhandle, 1, "No printer present");
  95.         Icon_SetInteger(windowhandle, 3, info->numcopies);
  96.  
  97.         ctrl->pollmask.value = ~( (1 << event_CLOSE)  |
  98.                                   (1 << event_CLICK) );
  99.         ctrl->basewindow = windowhandle;     /* Let server know windowhandle */
  100.       }
  101.       return(TRUE);
  102.  
  103.  
  104.     case REASON_CLOSE:                            /* Quietly kill our window */
  105.       Wimp_DeleteWindow(ctrl->basewindow);                   
  106.       return(TRUE);
  107.  
  108.  
  109.     case REASON_EVENT:                                /* Handle a WIMP Event */
  110.       switch(event->type)
  111.       {
  112.         case event_CLOSE:
  113.           if (event->data.openblock.window == ctrl->basewindow)
  114.           {
  115.             /*  *ONLY* if this is our window, we kill the current menu, kill
  116.              *  our window, and return TRUE to indicate that we have processed
  117.              *  the event (so no other handlers should get it)
  118.              */
  119.             Wimp_CreateMenu((menu_block *) -1, 0, 0);
  120.             Wimp_DeleteWindow(ctrl->basewindow);
  121.             KillMe();         /* Inform server that we have closed ourselves */
  122.             return(TRUE);
  123.           }
  124.           break;
  125.  
  126.  
  127.         case event_CLICK:
  128.           if (event->data.mouse.window == ctrl->basewindow)
  129.           {
  130.             if (event->data.mouse.icon == 0)
  131.             {
  132.               if (printerpresent)        /* Is driver present to print with? */
  133.               {
  134.                 int numcopies;
  135.  
  136.                 numcopies = Icon_GetInteger(ctrl->basewindow, 3);
  137.                 SendState(&numcopies, sizeof(int));
  138.               }
  139.  
  140.               Wimp_CreateMenu((menu_block *) -1, 0, 0);
  141.               Wimp_DeleteWindow(ctrl->basewindow);
  142.               KillMe();
  143.             }
  144.             return(TRUE);
  145.           }
  146.           break;
  147.       }
  148.       break;
  149.   }
  150.  
  151.   return(FALSE);          /* If we didn't handle this call, we MUST return 0 */
  152. }
  153.  
  154.