home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1821.lha / XDME / menucontrol.c < prev    next >
C/C++ Source or Header  |  1993-03-09  |  5KB  |  207 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     menucontrol.c
  5.  
  6.     DESCRIPTION
  7.     [X]DME intuition interface to menustrips.c
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.     none known
  13.  
  14.     TODO
  15.     handling for MENU_HELP
  16.  
  17.     EXAMPLES
  18.  
  19.     SEE ALSO
  20.     mainloop
  21.  
  22.     INDEX
  23.  
  24.     HISTORY
  25.     18 Dec 1992 b_null created
  26.     11 Feb 1993 modifcations
  27.  
  28. ******************************************************************************/
  29.  
  30. /**************************************
  31.         Includes
  32. **************************************/
  33. #include "defs.h"
  34. #include "menubase.h"
  35.  
  36.  
  37. /**************************************
  38.         Globale Variable
  39. **************************************/
  40. Prototype APTR menu_cmd (struct IntuiMessage * im);
  41. /* Prototype void menu_cmd (struct IntuiMessage * im); */
  42.  
  43.  
  44. /**************************************
  45.       Interne Defines & Strukturen
  46. **************************************/
  47.  
  48. typedef struct INode {
  49.     struct MinNode node;
  50.  /* XITEM     * item; */
  51.     int        len;
  52.     char       com[0];  /* that means : the rest of that node contains a string */
  53. } IINODE;
  54.  
  55.  
  56. /**************************************
  57.         Interne Variable
  58. **************************************/
  59.  
  60.  
  61. /**************************************
  62.        Interne Prototypes
  63. **************************************/
  64.  
  65.  
  66. #ifndef NOT_DEF
  67.  
  68. /*****************************************************************************
  69.  
  70.     NAME
  71.     menu_cmd
  72.  
  73.     PARAMETER
  74.     struct IntuiMessage * im
  75.  
  76.     RESULT
  77.     -/-
  78.  
  79.     RETURN
  80.     void
  81.  
  82.     DESCRIPTION
  83.     work on all menuselections done;
  84.     first set them all into a new queue, that does not
  85.     change if we modify currentmenu, then pass 'em to the
  86.     parser (or better a duplicate of them)
  87.  
  88.     NOTES
  89.     that method disables use of MENU_HELP
  90.     we should be able to do almost everything to our menus, also during
  91.     work on multiselections!
  92.  
  93.     THAT FUNCTION SHOULD BE RE-ENTRANT
  94.  
  95.     BUGS
  96.     what, if we close our window during that operation ????
  97.  
  98.     WARN: that function was neither compiled nor tested up to now
  99.           (we still use the function at the end of this file)
  100.  
  101.     EXAMPLES
  102.  
  103.     SEE ALSO
  104.     main/main
  105.  
  106.     INTERNALS
  107.     our method is horrible - it takes lots of resources,
  108.     but I think, this is the easiest way (else we had to lock our menustrip
  109.     and then queue up all operations to it)
  110.  
  111.     HISTORY
  112.     18 Dec 1992 b_null created
  113.     09 Feb 1993 b_null multiselection added
  114.     11 Feb 1993 b_null BUG FIX : all selections are done "buffered"
  115.  
  116. ******************************************************************************/
  117.  
  118. APTR /* void */ menu_cmd (struct IntuiMessage * im)
  119. {
  120.     MENUSTRIP * ms = currentmenu();
  121.     struct MinList buffs;
  122.  
  123.     NewList ((struct List *)&buffs);
  124.     if (im != NULL && im->Class == IDCMP_MENUPICK && ms != NULL) {
  125.     long           code = im->Code;
  126.     XITEM         * item;
  127.     IINODE         * in;
  128.  
  129.     while (item = (XITEM *)ItemAddress (ms->data, code)) {
  130.         if (item->com != NULL) {
  131.         int len = sizeof (IINODE) + strlen (item->com) + 1;
  132.  
  133.         if (in = AllocFunc (len, MEMF_ANY)) {
  134.             in->len = len;         /* we MUST remember the size here, as do_command might destroy the string-contents */
  135.             strcpy (in->com, item->com);
  136.          /* in->item = item; */
  137.             AddTail ((struct List *)&buffs, (struct Node *)in);
  138.         } /* if malloced */
  139.         } /* if command carrier */
  140.         code = item->item.NextSelect;
  141.     } /* while pending selections */
  142.  
  143.     while (in = (IINODE *)RemHead ((struct List *)&buffs)) {
  144.         do_command (in->com);
  145.         FreeFunc (in, in->len);
  146.     } /* while commands left in queue */
  147.  
  148. #ifdef NOT_DEF
  149.     /* that method has one serious bug: we can not be sure to hit the right items */
  150.     char buffer[LINE_LENGTH];
  151.     while (item = (XITEM *)ItemAddress (ms->data, code)) {
  152.         if (item->com) {
  153.         strcpy (buffer, item->com);
  154.         do_command (buffer);
  155.         clearbreaks ();
  156.         } /* if item->com */
  157.     } /* while item */
  158. #endif
  159.     } /* if im */
  160.  
  161.     return (NULL);
  162. } /* menu_cmd */
  163.  
  164. #else
  165.  
  166. /*****************************************************************************
  167.  
  168.     RESULT
  169.     address of a command that is referred by the
  170.     selected menu;
  171.  
  172.     RETURN
  173.     APTR
  174.  
  175.     DESCRIPTION
  176.     we simply check if the command was a correct
  177.     menu-selection and return some data that was
  178.     stored together with the Intuition-structure
  179.  
  180.     NOTES
  181.     we don not know, the structure of that data;
  182.     so user might have to call macroname, macrobody
  183.     or something like that before he is getting the wanted data
  184.  
  185.     INTERNALS
  186.     falls korrekter Menueaufruf
  187.         gib entsprechendes Macro zurueck
  188.     sonst gib NULL zurueck
  189.  
  190. ******************************************************************************/
  191.  
  192. APTR menu_cmd (struct IntuiMessage * im)
  193. {
  194.     XITEM *item;
  195.  
  196.     if (item = (XITEM *)ItemAddress (((MENUSTRIP *)currentmenu())->data, im->Code)) {
  197.     return (item->com);
  198.     } /* if found item */
  199.     return (NULL);
  200. } /* menu_cmd */
  201.  
  202. #endif
  203.  
  204. /******************************************************************************
  205. *****  ENDE menucontrol.c
  206. ******************************************************************************/
  207.