home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 180.lha / Files_v1.2 / src / menu.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  2KB  |  107 lines

  1.  
  2. /*
  3.  *  MENU.C
  4.  *
  5.  *  (c)Copyright 1987 Matthew Dillon, All Rights Reserved.
  6.  *
  7.  */
  8.  
  9. #include "files.h"
  10.  
  11. #define NI  0        /*    means 'not initialized' */
  12.  
  13. static ITEXT IText[] = {
  14.     { 0, 1, JAM2, 0, 0, NULL, (ubyte *)"Save"        },
  15.     { 0, 1, JAM2, 0, 0, NULL, (ubyte *)"SaveAs"      },
  16.     { 0, 1, JAM2, 0, 0, NULL, (ubyte *)"Load"        },
  17.     { 0, 1, JAM2, 0, 0, NULL, (ubyte *)"LoadDefault" },
  18.     { 0, 1, JAM2, 0, 0, NULL, (ubyte *)"Quit"        },
  19.     { 0, 1, JAM2, 0, 0, NULL, (ubyte *)"AddKillPat"  },
  20. };
  21.  
  22. static ITEM Item[] = {
  23.     { &Item[1], 0, NI, NI, NI, 0, 0, (APTR)&IText[0], NULL },
  24.     { &Item[2], 0, NI, NI, NI, 0, 0, (APTR)&IText[1], NULL },
  25.     { &Item[3], 0, NI, NI, NI, 0, 0, (APTR)&IText[2], NULL },
  26.     { &Item[4], 0, NI, NI, NI, 0, 0, (APTR)&IText[3], NULL },
  27.     { NULL    , 0, NI, NI, NI, 0, 0, (APTR)&IText[4], NULL },
  28.     { NULL    , 0, NI, NI, NI, 0, 0, (APTR)&IText[5], NULL },
  29. };
  30.  
  31. static MENU Menu[] = {
  32.     { &Menu[1], NI, 0, NI, NI, NI, "Project" , NI },
  33.     { NULL    , NI, 0, NI, NI, NI, "Control", NI  }
  34. };
  35.  
  36.  
  37. addmenus()
  38. {
  39.     MENU *menu;
  40.     ITEM *item, *nit;
  41.     short left = 5;
  42.     short height;
  43.     short width;
  44.  
  45.     for (menu = Menu, item = Item; menu; menu = menu->NextMenu) {
  46.     height = 0;
  47.     width  = strlen(menu->MenuName);
  48.     menu->FirstItem = item;
  49.     for (item = menu->FirstItem; item; item = item->NextItem) {
  50.         if (width < strlen(((ITEXT *)item->ItemFill)->IText))
  51.         width = strlen(((ITEXT *)item->ItemFill)->IText);
  52.     }
  53.     width *= Win->RPort->TxWidth;
  54.     for (item = menu->FirstItem; item; nit = item, item = item->NextItem) {
  55.         item->Width   = width;
  56.         item->Height  = Win->RPort->TxHeight + 2;
  57.         item->TopEdge = height;
  58.         item->Flags  |= ITEMTEXT|ITEMENABLED|HIGHCOMP;
  59.         height += item->Height;
  60.     }
  61.     menu->LeftEdge = left;
  62.     menu->Width    = width;
  63.     menu->Height   = height;
  64.     menu->Flags    = MENUENABLED;
  65.     item = nit + 1;
  66.     left += width + 4;
  67.     }
  68.     SetMenuStrip(Win, Menu);
  69. }
  70.  
  71. remmenus()
  72. {
  73.     ClearMenuStrip(Win);
  74. }
  75.  
  76. getmenu(im)
  77. IMESS *im;
  78. {
  79.     register short mn = MENUNUM(im->Code);
  80.     register short in = ITEMNUM(im->Code);
  81.  
  82.     switch(mn) {
  83.     case 0:
  84.     switch(in) {
  85.     case 0:
  86.         return(MEN_SAVE);
  87.     case 1:
  88.         return(MEN_SAVEAS);
  89.     case 2:
  90.         return(MEN_LOAD);
  91.     case 3:
  92.         return(MEN_LOADEF);
  93.     case 4:
  94.         return(MEN_QUIT);
  95.     }
  96.     break;
  97.     case 1:
  98.     switch(in) {
  99.     case 0:
  100.         return(MEN_KILLPAT);
  101.     }
  102.     break;
  103.     }
  104.     return(0);
  105. }
  106.  
  107.