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

  1. /* > $.CLIB.C.pollmenu
  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 menu related reason code returns from
  21.  *     SWI(Wimp_Poll)
  22.  */
  23. #include "c.poll_h"
  24.  
  25. int haswin_poll_menu(int (*user)(int, buffer *), buffer *pbuf) {
  26.  
  27.         char                    menutitle[12], menustr[1024];
  28.         icon                    *iptr;
  29.         pointer                 *mouse;
  30.         _kernel_swi_regs        regs;
  31.         buffer                  buff;
  32.  
  33.         if (!haswin_menu.actual) {
  34.                 haswin_internalerror("cannot find a menu to select from");
  35.                 return(HASWIN_FALSE);
  36.         }
  37.         mouse = haswin_getpointerinfo(0);
  38.         strncpy(menutitle, (char *)haswin_menu.actual, 12);
  39.         regs.r[1] = (int)haswin_menu.actual;
  40.         regs.r[2] = (int)pbuf;
  41.         regs.r[3] = (int)menustr;
  42.         if (!haswin_swi(HASWIN_Decode_menu, ®s))
  43.                 return(HASWIN_FALSE);
  44.  
  45.         asciilen(menustr);
  46.         if (haswin_menu.wfrom != 0) {
  47.                 /* this came from an icon on the menu bar or in a
  48.                    window, or just a window */
  49.                 pbuf->i[0] = (int)&haswin_menu;
  50.                 pbuf->i[2] = pbuf->i[5] = 0;
  51.                 pbuf->i[3] = haswin_menu.wfrom;
  52.                 pbuf->i[4] = haswin_menu.ifrom;
  53.                 if (!strncmp(menustr, "Quit", 4)) {
  54. /* inform the userpoll routine that we are about to QUIT */
  55.                         if ((user) && (!(*user)(HASWIN_POLL_poll_UQuit, pbuf)))
  56.                                 return(HASWIN_FALSE);
  57.                         if ((haswin_menu.wfrom == -2) || (haswin_ok_cancel("Quit from an icon not on the menu bar ?") == HASWIN_OK))
  58.                                 haswin_exit(HASWIN_FALSE);
  59.                 } else if (!strncmp(menustr, "Window.Open", 11)) {
  60.                         iptr = haswin_findiconhandle(haswin_findwindowhandle(haswin_menu.wfrom), haswin_menu.ifrom);
  61.                         if ((iptr) && (iptr->window)) {
  62. /* inform the userpoll routine that we are about to open a window */
  63.                                 pbuf->i[6] = iptr->window->handle;
  64.                                 if ((user) && (!(*user)(HASWIN_POLL_poll_Open, pbuf)))
  65.                                         return(HASWIN_FALSE);
  66.                                 haswin_reopenwindow(iptr->window);
  67.                         } else
  68.                                 haswin_internalerror("This MENU has no window to open");
  69.                 } else if (!strncmp(menustr, "Window.Close", 12)) {
  70.                         iptr = haswin_findiconhandle(haswin_findwindowhandle(haswin_menu.wfrom), haswin_menu.ifrom);
  71.                         if ((iptr) && (iptr->window)) {
  72.                                 pbuf->i[6] = iptr->window->handle;
  73. /* inform the userpoll routine that we are about to close a window */
  74.                                 if ((user) && (!(*user)(HASWIN_POLL_poll_Close, pbuf)))
  75.                                         return(HASWIN_FALSE);
  76.                                 haswin_closewindow(iptr->window);
  77.                         } else
  78.                                 haswin_internalerror("This MENU has no window to close");
  79.                 } else if (!strncmp(menustr, "Files.Load", 10)) {
  80.                         /*
  81.                            pretend that we have pressed the Load File window
  82.                            OK icon.  Build the mouse pressed data block.
  83.                          */
  84.                         buff.i[0] = 0;
  85.                         buff.i[1] = 0;
  86.                         buff.i[2] = HASWIN_MOUSE_L;
  87.                         buff.i[3] = haswin_loadiconok->whandle;
  88.                         buff.i[4] = haswin_loadiconok->ihandle;
  89.                         filemousebutton(haswin_loadiconok, &buff);
  90.                 } else if (!strncmp(menustr, "Files.Save", 10)) {
  91.                         /*
  92.                            pretend that we have pressed the Save File window
  93.                            OK icon.  Build the mouse pressed data block.
  94.                          */
  95.                         buff.i[0] = 0;
  96.                         buff.i[1] = 0;
  97.                         buff.i[2] = HASWIN_MOUSE_L;
  98.                         buff.i[3] = haswin_saveiconok->whandle;
  99.                         buff.i[4] = haswin_saveiconok->ihandle;
  100.                         filemousebutton(haswin_saveiconok, &buff);
  101.                 } else if (!strncmp(menustr, "Files.Options.Add", 17)) {
  102.                         haswin_fileoptions |= HASWIN_OPTIONS_ADD;
  103.                 } else if (!strncmp(menustr, "Files.Options.Replace", 21)) {
  104.                         haswin_fileoptions &= ~HASWIN_OPTIONS_ADD;
  105.                 } else if (!strncmp(menustr, "Help.Window", 11)) {
  106.                         haswin_reopenwindow(haswin_menu.whelp);
  107.                 } else if (!strncmp(menustr, "Help.Icon", 9)) {
  108.                         haswin_reopenwindow(haswin_menu.ihelp);
  109.                 } else if (!strncmp(menustr, "Help.Menu", 9)) {
  110.                         haswin_reopenwindow(haswin_menu.mhelp);
  111.                 } else if (haswin_menu.domenu) {
  112.                         (*haswin_menu.domenu)(menustr,&haswin_menu); 
  113.                 } else {
  114.                         haswin_interrorprintf("Menu selection %s has no action", menustr);
  115.                 }
  116.         } else {
  117.                 if (haswin_menu.domenu) {
  118.                         (*haswin_menu.domenu)(menustr,&haswin_menu); 
  119.                 } else {
  120.                         haswin_interrorprintf("Menu selection %s has no action", menustr);
  121.                 }
  122.         }
  123.         if ((mouse->buttons&POINTER_MOUSEBUTTONS) == POINTER_MOUSE_R) {
  124.                 /* recreate menu because ADJUST button means don't close */
  125. /* inform the userpoll routine that a menu is about to be re-opened */
  126.                 if ((user) && (!(*user)(HASWIN_POLL_poll_Re_Menu, pbuf)))
  127.                         return(HASWIN_FALSE);
  128. /* call the menu creation routine in the menu block if it exists */
  129.                 if ((haswin_menu.makemenu) && (!(*haswin_menu.makemenu)(&haswin_menu)))
  130.                         return(HASWIN_FALSE);
  131. /* now we actually remake the menu */
  132.                 haswin_recreatemenu();
  133.         }
  134.         return(HASWIN_TRUE);
  135. }
  136.  
  137.