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

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