home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / stv_427.lzh / STV / source / menu.c < prev    next >
C/C++ Source or Header  |  1991-01-09  |  9KB  |  265 lines

  1. /*********************************
  2. *  MENU  09/29/90
  3. *  Source file for STV
  4. *  © Copyright 1990 Timm Martin
  5. *  All Rights Reserved Worldwide
  6. **********************************/
  7.  
  8. #include <exec/types.h>
  9. #include <functions.h>
  10. #include <intuition/intuition.h>
  11. #include "func.h"
  12. #include "main.h"
  13.  
  14. /*******************
  15. *  MENU STRUCTURES
  16. ********************/
  17.  
  18. /* left edge of text             */  #define MENU_TEXT_LEFT 4
  19. /* top edge of text              */  #define MENU_TEXT_TOP 1
  20. /* how long is each text string? */  #define MENU_TEXT_LENGTH 18
  21.  
  22. struct IntuiText prev_mtext =
  23. {
  24.   /* UBYTE              FrontPen  */ BLACK,
  25.   /* UBYTE              BackPen   */ WHITE,
  26.   /* UBYTE              DrawMode  */ JAM1,
  27.   /* SHORT              LeftEdge  */ MENU_TEXT_LEFT,
  28.   /* SHORT              TopEdge   */ MENU_TEXT_TOP,
  29.   /* struct TextAttr *  ITextFont */ &text_attr,
  30.   /* UBYTE *            IText     */ (STRPTR)"Previous File    P",
  31.   /* struct IntuiText * NextText  */ NULL,
  32. };
  33. struct IntuiText next_mtext =
  34. {
  35.   /* UBYTE              FrontPen  */ BLACK,
  36.   /* UBYTE              BackPen   */ WHITE,
  37.   /* UBYTE              DrawMode  */ JAM1,
  38.   /* SHORT              LeftEdge  */ MENU_TEXT_LEFT,
  39.   /* SHORT              TopEdge   */ MENU_TEXT_TOP,
  40.   /* struct TextAttr *  ITextFont */ &text_attr,
  41.   /* UBYTE *            IText     */ (STRPTR)"Next File        N",
  42.   /* struct IntuiText * NextText  */ NULL,
  43. };
  44. struct IntuiText search_mtext =
  45. {
  46.   /* UBYTE              FrontPen  */ BLACK,
  47.   /* UBYTE              BackPen   */ WHITE,
  48.   /* UBYTE              DrawMode  */ JAM1,
  49.   /* SHORT              LeftEdge  */ MENU_TEXT_LEFT,
  50.   /* SHORT              TopEdge   */ MENU_TEXT_TOP,
  51.   /* struct TextAttr *  ITextFont */ &text_attr,
  52.   /* UBYTE *            IText     */ (STRPTR)"Search           S",
  53.   /* struct IntuiText * NextText  */ NULL,
  54. };
  55. struct IntuiText again_mtext =
  56. {
  57.   /* UBYTE              FrontPen  */ BLACK,
  58.   /* UBYTE              BackPen   */ WHITE,
  59.   /* UBYTE              DrawMode  */ JAM1,
  60.   /* SHORT              LeftEdge  */ MENU_TEXT_LEFT,
  61.   /* SHORT              TopEdge   */ MENU_TEXT_TOP,
  62.   /* struct TextAttr *  ITextFont */ &text_attr,
  63.   /* UBYTE *            IText     */ (STRPTR)"Search Again     A",
  64.   /* struct IntuiText * NextText  */ NULL,
  65. };
  66. struct IntuiText quit_mtext =
  67. {
  68.   /* UBYTE              FrontPen  */ BLACK,
  69.   /* UBYTE              BackPen   */ WHITE,
  70.   /* UBYTE              DrawMode  */ JAM1,
  71.   /* SHORT              LeftEdge  */ MENU_TEXT_LEFT,
  72.   /* SHORT              TopEdge   */ MENU_TEXT_TOP,
  73.   /* struct TextAttr *  ITextFont */ &text_attr,
  74.   /* UBYTE *            IText     */ (STRPTR)"Quit             Q",
  75.   /* struct IntuiText * NextText  */ NULL,
  76. };
  77.  
  78. /* left edge of each menu item */
  79. #define MENU_LEFT 0
  80.  
  81. struct MenuItem quit_item =
  82. {
  83.   /* struct MenuItem * NextItem      */ NULL,
  84.   /* SHORT             LeftEdge      */ MENU_LEFT,
  85.   /* SHORT             TopEdge       */ LATER,
  86.   /* SHORT             Width         */ LATER,
  87.   /* SHORT             Height        */ LATER,
  88.   /* USHORT            Flags         */ HIGHCOMP|ITEMENABLED|ITEMTEXT,
  89.   /* LONG              MutualExclude */ NULL,
  90.   /* APTR              ItemFill      */ (APTR)&quit_mtext,
  91.   /* APTR              SelectFill    */ NULL,
  92.   /* BYTE              Command       */ NULL,
  93.   /* struct MenuItem * SubItem       */ NULL,
  94.   /* USHORT            NextSelect    */ MENUNULL,
  95. };
  96. struct MenuItem again_item =
  97. {
  98.   /* struct MenuItem * NextItem      */ &quit_item,
  99.   /* SHORT             LeftEdge      */ MENU_LEFT,
  100.   /* SHORT             TopEdge       */ LATER,
  101.   /* SHORT             Width         */ LATER,
  102.   /* SHORT             Height        */ LATER,
  103.   /* USHORT            Flags         */ HIGHCOMP|ITEMENABLED|ITEMTEXT,
  104.   /* LONG              MutualExclude */ NULL,
  105.   /* APTR              ItemFill      */ (APTR)&again_mtext,
  106.   /* APTR              SelectFill    */ NULL,
  107.   /* BYTE              Command       */ NULL,
  108.   /* struct MenuItem * SubItem       */ NULL,
  109.   /* USHORT            NextSelect    */ MENUNULL,
  110. };
  111. struct MenuItem search_item =
  112. {
  113.   /* struct MenuItem * NextItem      */ &again_item,
  114.   /* SHORT             LeftEdge      */ MENU_LEFT,
  115.   /* SHORT             TopEdge       */ LATER,
  116.   /* SHORT             Width         */ LATER,
  117.   /* SHORT             Height        */ LATER,
  118.   /* USHORT            Flags         */ HIGHCOMP|ITEMENABLED|ITEMTEXT,
  119.   /* LONG              MutualExclude */ NULL,
  120.   /* APTR              ItemFill      */ (APTR)&search_mtext,
  121.   /* APTR              SelectFill    */ NULL,
  122.   /* BYTE              Command       */ NULL,
  123.   /* struct MenuItem * SubItem       */ NULL,
  124.   /* USHORT            NextSelect    */ MENUNULL,
  125. };
  126. struct MenuItem next_item =
  127. {
  128.   /* struct MenuItem * NextItem      */ &search_item,
  129.   /* SHORT             LeftEdge      */ MENU_LEFT,
  130.   /* SHORT             TopEdge       */ LATER,
  131.   /* SHORT             Width         */ LATER,
  132.   /* SHORT             Height        */ LATER,
  133.   /* USHORT            Flags         */ HIGHCOMP|ITEMENABLED|ITEMTEXT,
  134.   /* LONG              MutualExclude */ NULL,
  135.   /* APTR              ItemFill      */ (APTR)&next_mtext,
  136.   /* APTR              SelectFill    */ NULL,
  137.   /* BYTE              Command       */ NULL,
  138.   /* struct MenuItem * SubItem       */ NULL,
  139.   /* USHORT            NextSelect    */ MENUNULL,
  140. };
  141. struct MenuItem prev_item =
  142. {
  143.   /* struct MenuItem * NextItem      */ &next_item,
  144.   /* SHORT             LeftEdge      */ MENU_LEFT,
  145.   /* SHORT             TopEdge       */ LATER,
  146.   /* SHORT             Width         */ LATER,
  147.   /* SHORT             Height        */ LATER,
  148.   /* USHORT            Flags         */ HIGHCOMP|ITEMENABLED|ITEMTEXT,
  149.   /* LONG              MutualExclude */ NULL,
  150.   /* APTR              ItemFill      */ (APTR)&prev_mtext,
  151.   /* APTR              SelectFill    */ NULL,
  152.   /* BYTE              Command       */ NULL,
  153.   /* struct MenuItem * SubItem       */ NULL,
  154.   /* USHORT            NextSelect    */ MENUNULL,
  155. };
  156. #define FIRST_ITEM prev_item
  157.  
  158. /* menu item numbers */
  159. #define STV_PREV   0
  160. #define STV_NEXT   1
  161. #define STV_SEARCH 2
  162. #define STV_AGAIN  3
  163. #define STV_QUIT   4
  164. /* menu number */
  165. #define STV_MENU 0
  166.  
  167. /* length of the menu name */
  168. #define MENU_NAME_LENGTH 18
  169.  
  170. struct Menu stv_menu =
  171. {
  172.   /* struct Menu *     NextMenu  */ NULL,
  173.   /* SHORT             LeftEdge  */ 0,
  174.   /* SHORT             TopEdge   */ 0,
  175.   /* SHORT             Width     */ LATER,
  176.   /* SHORT             Height    */ 10,
  177.   /* USHORT            Flags     */ MENUENABLED,
  178.   /* BYTE *            MenuName  */ "STV by Timm Martin",
  179.   /* struct MenuItem * FirstItem */ &FIRST_ITEM,
  180. };
  181. #define FIRST_MENU stv_menu
  182.  
  183. /* menu item ordinal numbers for enabling/disabling them */
  184. #define PREV_MENU MENUNUMBER(STV_MENU,STV_PREV,0)
  185. #define NEXT_MENU MENUNUMBER(STV_MENU,STV_NEXT,0)
  186.  
  187. /************
  188. *  MENU ADD
  189. *************/
  190.  
  191. /*
  192. This procedure calculates the TopEdge, Width, and Height of each menu item
  193. and adds the menus to the window.
  194. */
  195.  
  196. void menu_add( void )
  197. {
  198.   int height;             /* height of each menu item */
  199.   struct MenuItem *item;  /* pointer to current menu item */
  200.   int top;                /* top edge of current menu item */
  201.   int width;              /* width of each menu item */
  202.  
  203.   height = stats.TextHeight + MENU_TEXT_TOP * 2;
  204.   width  = stats.TextWidth * MENU_TEXT_LENGTH + MENU_TEXT_LEFT * 2;
  205.  
  206.   /* calculate TopEdge, Width, and Height of each menu item */
  207.   for (item = &FIRST_ITEM, top = 0; item; item = item->NextItem, top += height)
  208.   {
  209.     item->TopEdge = top;
  210.     item->Width   = width;
  211.     item->Height  = height;
  212.   }
  213.   stv_menu.Width = stats.TextWidth * MENU_NAME_LENGTH + 8;
  214.  
  215.   /* add menus to window */
  216.   SetMenuStrip( win, &FIRST_MENU );
  217. }
  218.  
  219. /*************
  220. *  MENU PICK
  221. **************/
  222.  
  223. /*
  224. This function handles menu selections.  The 'menu' number was provided for
  225. future expansion.
  226. */
  227.  
  228. SELECT menu_pick( int menu, int item )
  229. {
  230.   SELECT file = SELECT_SOME;
  231.  
  232.   switch (item)
  233.   {
  234.     case STV_PREV:   file = SELECT_PREV; break;
  235.     case STV_NEXT:   file = SELECT_NEXT; break;
  236.     case STV_QUIT:   file = SELECT_STOP; break;
  237.     case STV_SEARCH: search();           break;
  238.     case STV_AGAIN:  search_again();     break;
  239.   }
  240.  
  241.   return (file);
  242. }
  243.  
  244. /*****************
  245. *  MENU PREVNEXT
  246. ******************/
  247.  
  248. /*
  249. This procedure enables/disables the menu items based on whether a previous or
  250. next file exists.
  251. */
  252.  
  253. void menu_prevnext( SELECT prev, SELECT next )
  254. {
  255.   if (prev == SELECT_NONE)
  256.     OffMenu( win, PREV_MENU );
  257.   else
  258.     OnMenu( win, PREV_MENU );
  259.  
  260.   if (next == SELECT_NONE)
  261.     OffMenu( win, NEXT_MENU );
  262.   else
  263.     OnMenu( win, NEXT_MENU );
  264. }
  265.