home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 144.lha / Leach_v1.3 / menu.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  5KB  |  181 lines

  1.  
  2. #include    <functions.h>
  3. #include    <exec/types.h>
  4. #include     <exec/nodes.h>
  5. #include    <exec/libraries.h>
  6. #include    <graphics/gfx.h>
  7. #include    <graphics/rastport.h>
  8. #include    <graphics/text.h>
  9. #include    <intuition/intuition.h>
  10. #include     <stdio.h>
  11.  
  12. #define    CHARWID 8
  13.  
  14. /**************  LEACH'S MENU SUPPORT STRUCTURES  *******************/
  15.  
  16. struct IntuiText L_MenuText[] =
  17. {
  18.     {
  19.         0, 1,            /* UBYTE    FrontPen, BackPen    */
  20.         JAM1,            /* UBYTE    DrawMode            */
  21.         0, 1,            /* short    LeftEdge, TopEdge    */
  22.         NULL,            /* struct     TextAttr            */
  23.         "LEACH",        /* UBYTE    *IText                */
  24.         NULL            /* struct    IntuiText *NextText    */
  25.     },
  26.     {
  27.         0, 1,            /* UBYTE    FrontPen, BackPen    */
  28.         JAM1,            /* UBYTE    DrawMode            */
  29.         0, 1,            /* short    LeftEdge, TopEdge    */
  30.         NULL,            /* struct     TextAttr            */
  31.         " Scr On",        /* UBYTE    *IText                */
  32.         NULL            /* struct    IntuiText *NextText    */
  33.     },
  34.     {
  35.         0, 1,            /* UBYTE    FrontPen, BackPen    */
  36.         JAM1,            /* UBYTE    DrawMode            */
  37.         0, 1,            /* short    LeftEdge, TopEdge    */
  38.         NULL,            /* struct     TextAttr            */
  39.         " Scr Off",        /* UBYTE    *IText                */
  40.         NULL            /* struct    IntuiText *NextText    */
  41.     }
  42. };
  43.  
  44. /*--------------------------------------------------------------------------*
  45.  * The first structure in this array will be attached to the Host's first
  46.  * menu. The rest of the structures are subitems attached to the item.
  47.  *--------------------------------------------------------------------------*/
  48.  
  49. struct MenuItem     L_MenuItems[] =
  50. {
  51.     {
  52.         NULL,                            /* Next item.                */
  53.         0, 0,                            /* LeftEdge, TopEdge. Set    */
  54.                                         /* at run-time.                */
  55.         0, 12,                            /* Width, Height            */
  56.         ITEMTEXT | ITEMENABLED |        /* Flags                    */
  57.         HIGHCOMP,
  58.         NULL,                            /* Mutual exclude flags.    */
  59.         &L_MenuText[0],                    /* Item text.                */
  60.         NULL,                            /* SelectFill                */
  61.         0,                                /* Shortcut charactor        */
  62.         &L_MenuItems[1],                /* Pointer to Sub items.    */
  63.         0
  64.     },
  65.     {
  66.         &L_MenuItems[2],                /* Next (sub)item.            */
  67.         5 * CHARWID,  0,                /* LeftEdge, TopEdge        */
  68.         9 * CHARWID, 12,                /* Width, Height            */
  69.         ITEMTEXT | ITEMENABLED |        /* Flags                    */
  70.         HIGHCOMP,
  71.         0x02L,                            /* Mutual exclude flags.    */
  72.         &L_MenuText[1],                    /* Item text.                */
  73.         NULL,                            /* SelectFill                */
  74.         0,                                /* Shortcut charactor        */
  75.         NULL,
  76.         0
  77.     },
  78.     {
  79.         NULL,                            /* Next item.                */
  80.         5 * CHARWID,  14,                /* LeftEdge, TopEdge        */
  81.         9 * CHARWID, 12,                /* Width, Height            */
  82.         ITEMTEXT | ITEMENABLED |        /* Flags                    */
  83.         HIGHCOMP,
  84.         0x01L,                            /* Mutual exclude flags.    */
  85.         &L_MenuText[2],                    /* Item text.                */
  86.         NULL,                            /* SelectFill                */
  87.         0,                                /* Shortcut charactor        */
  88.         NULL,
  89.         0
  90.     }
  91. };
  92.  
  93.  
  94. extern struct Menu        *HostMenuStrip;
  95. extern struct Window    *HostWind;
  96. extern UBYTE            L_menu_num;
  97. extern UBYTE            L_menuitem_num;
  98.  
  99.  
  100. /****************************************************************************
  101.  * This function walks down the Host's menu list to the end where it attaches
  102.  * Leach's own menu. 
  103.  ****************************************************************************/
  104.  
  105. install_menu()
  106. {
  107.  
  108. struct MenuItem    *item_ptr;
  109.  
  110. L_menu_num        = 0;
  111. L_menuitem_num    = 0;
  112. item_ptr        = NULL;
  113.  
  114. if (!HostMenuStrip)                /* If the Host has no menus... (unlikly)    */
  115. {
  116.     puts("Leach can not attach itself to Host's with no menus.");
  117.     cleanup(302);
  118. }
  119. else
  120. {
  121.     item_ptr = HostMenuStrip->FirstItem;
  122.  
  123.     if (! item_ptr)
  124.     {
  125.         puts("Host has no first menu item!");
  126.         cleanup(304);
  127.     }
  128.     ++L_menuitem_num;
  129.     while(item_ptr->NextItem)    /* While not the last Host menu item...    */
  130.     {
  131.         ++L_menuitem_num;
  132.         item_ptr = item_ptr->NextItem;
  133.     }
  134.     ClearMenuStrip(HostWind);
  135.  
  136.     L_MenuItems[0].LeftEdge = item_ptr->LeftEdge;
  137.     L_MenuItems[0].Width    = item_ptr->Width;
  138.     L_MenuItems[0].TopEdge    = item_ptr->TopEdge + item_ptr->Height + 2;
  139.  
  140.     L_MenuItems[1].TopEdge    = 0;
  141.     L_MenuItems[1].LeftEdge    = L_MenuItems[0].LeftEdge + L_MenuItems[0].Width -7;
  142.  
  143.     L_MenuItems[2].TopEdge    = L_MenuItems[1].TopEdge + 14;
  144.     L_MenuItems[2].LeftEdge    = L_MenuItems[1].LeftEdge;
  145.  
  146.     item_ptr->NextItem    = L_MenuItems;
  147.     SetMenuStrip(HostWind, HostMenuStrip);
  148. }
  149.  
  150. return;
  151.  
  152. } /*  End of install_menu()  */
  153.  
  154.  
  155. /****************************************************************************
  156.  * If this routine removes Leach's menu item from the Host's MenuStrip.
  157.  ****************************************************************************/
  158.  
  159. remove_menu()
  160. {
  161.  
  162. struct MenuItem        *item_ptr;
  163.  
  164. if (!HostMenuStrip)    return;                        /* Shouldn't ever happen    */
  165. item_ptr = HostMenuStrip->FirstItem;
  166.  
  167. while ( (item_ptr->NextItem != L_MenuItems) && item_ptr)
  168.     item_ptr = item_ptr->NextItem;
  169.  
  170. /* menu_ptr = NULL if there's no first item or Leach wasn't in first menu.    */
  171. if (item_ptr)
  172. {
  173.     ClearMenuStrip(HostWind);
  174.     item_ptr->NextItem = NULL;
  175.     SetMenuStrip(HostWind, HostMenuStrip);
  176. }
  177.  
  178. return;
  179.  
  180. } /*  End of remove_menu()  */
  181.