home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / g / gs / !GS / ps / Source / WimpPlus / c / wimpmain < prev   
Encoding:
Text File  |  1991-03-26  |  4.1 KB  |  158 lines

  1. /* wimpmain.c */
  2.  
  3. /* If you include this in your build, then your program will start by
  4. putting an icon on the icom bar. This can then be used as an entry to a user
  5. program. If the icon is clicked, then user_main is called; if a file is
  6. dropped on the icon, then user_main is called with the name of the file as
  7. the first parameter. In both cases, a dummy zeroth parameter is passed to
  8. user_main. Thus, by taking a command line program, and replacing main by
  9. user_main, you can turn it into a WIMP program. If user_main returns, then
  10. it can be called again.
  11. A further click or file will be ignored until user_main returns, in case
  12. user_main calls the event processor.
  13. Some strings are expected to exist:
  14.   char *taskname, char *resources, char *iconname, char *Version_String
  15.  
  16. *** NB. Dropping of files on the icon bar has not yet been implemented. It
  17.     may follow in later releases
  18. ***
  19.  
  20. */
  21.  
  22. #include "resspr.h"
  23. #include "baricon.h"
  24. #include "event.h"
  25. #include "menu.h"
  26. #include "dbox.h"
  27. #include "win.h"
  28.  
  29. #include "wimpc.h"
  30.  
  31. extern char *taskname;
  32. extern char *resources;
  33. extern char *iconname;
  34. extern char *Version_String;
  35. extern int  user_main(int argc, char *argv[]);
  36.  
  37.  
  38. static BOOL running = TRUE;
  39. static BOOL user_called = FALSE;
  40.  
  41. char *arguments[2];
  42.  
  43. /* Menu items */
  44. #define menu_info     1
  45. #define menu_quit     2
  46.  
  47. /* Info box field for the version string */
  48. #define info_field    4
  49.  
  50. /* The top of the menu tree */
  51. static menu icon_menu;
  52.  
  53. /*--- Event handler called on a left click on the icon. ---*/
  54. /* On each click, we call the tester */
  55. static void iconclick(wimp_i icon)
  56. {
  57.     icon = icon; /* We don't need the handle: this stops compiler warning */
  58.     if (!user_called)
  59.     {
  60.         arguments[0] = taskname;
  61.         user_called = TRUE;
  62.         user_main(1, arguments);
  63.         user_called = FALSE;
  64.     }
  65. }
  66.  
  67. /*--- Display the program info box - called from the menu processor. ---*/
  68. static void info_about_program(void)
  69. {
  70.   dbox  d;  /* Dialogue box handle */
  71.  
  72.   /* Create the dialogue box */
  73.   if (d = dbox_new("ProgInfo"), d != NULL)
  74.   {
  75.     /* Fill in the version number */
  76.     dbox_setfield(d, info_field, Version_String);
  77.  
  78.     /* Show the dialogue box */
  79.     dbox_show(d);
  80.  
  81.     /* Keep it on the screen as long as needed */
  82.     dbox_fillin(d);
  83.  
  84.     /* Dispose of the dialogue box */
  85.     dbox_dispose(&d);
  86.   }
  87. }
  88.  
  89. /*--- Event handler for the menu. ---*/
  90. static void icon_menuproc(void *handle, char *hit)
  91. {
  92.   handle = handle; /* We don't need handle: this stops compiler warning */
  93.  
  94.   /* Find which menu item was hit and take action as appropriate */
  95.   switch (hit[0])
  96.   {
  97.     case menu_info:
  98.       info_about_program();
  99.       break;
  100.  
  101.     case menu_quit:
  102.       running = FALSE;
  103.       break;
  104.   }
  105. }
  106.  
  107. #ifdef DROPS
  108. /* Background event handler - used for drops onto icon */
  109. static void bkg_events (wimp_eventstr *e, void *handle)
  110. {
  111.     handle = handle ; /* avoid not used warning */
  112.  
  113.     switch (e->e)
  114.     {   case wimp_ESEND:
  115.         case wimp_ESENDWANTACK:
  116.         {   wimp_msgstr *msg = &e->data.msg;       /* Make access easier */
  117.  
  118.             switch (msg->hdr.action)
  119.             {
  120. /* Response to help could be inserted here */
  121.  
  122.                 case wimp_MDATASAVE:
  123.                 case wimp_MDATALOAD:
  124.                 case wimp_MDATAOPEN:
  125.                     err = load_file (NULL, NULL, &zero, msg->hdr.action!=wimp_MDATALOAD);
  126.                     break;
  127.             }
  128.         }
  129.     }
  130. }
  131. #endif
  132.  
  133.  
  134. int main()
  135. {
  136.     /* Start up the wimp */
  137.     wimpc_init(taskname, resources);
  138.  
  139.     /* Create the menu tree */
  140.     if (icon_menu = menu_new(taskname, ">Info,Quit"), icon_menu == NULL)
  141.       return FALSE; /* Menu create failed */
  142.  
  143.     /* Place icon on the icon bar and register an event handler for it */
  144.     baricon(iconname, (int)resspr_area(), iconclick);
  145.     if (!event_attachmenu(win_ICONBAR, icon_menu, icon_menuproc, 0))
  146.         return 1; /* Unable to attach menu */
  147.  
  148. #ifdef DROPS
  149.     /* Set up a dummy window event handler to get icon messages */
  150.     win_register_event_handler (win_ICONBARLOAD, bkg_events, 0);
  151.     win_claim_unknown_events (win_ICONBARLOAD);
  152. #endif
  153.  
  154.     /* Process events */
  155.     while (running) event_process();
  156.     return 0;
  157. }
  158.