home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / gadtools / gadtoolsmenu.e < prev    next >
Text File  |  1977-12-31  |  4KB  |  98 lines

  1. -> gadtoolsmenu.e
  2. -> Example showing the basic usage of the menu system with a window.
  3. -> Menu layout is done with GadTools, as is recommended for applications.
  4.  
  5. OPT PREPROCESS
  6.  
  7. MODULE 'gadtools',
  8.        'intuition/intuition',
  9.        'libraries/gadtools'
  10.  
  11. ENUM ERR_NONE, ERR_LIB, ERR_MENU, ERR_VIS, ERR_WIN
  12.  
  13. RAISE ERR_LIB  IF OpenLibrary()=NIL,
  14.       ERR_MENU IF CreateMenusA()=NIL,
  15.       ERR_VIS  IF GetVisualInfoA()=NIL,
  16.       ERR_WIN  IF OpenWindowTagList()=NIL
  17.  
  18. -> E-Note: used to convert an INT to unsigned
  19. #define UNSIGNED(x) ((x) AND $FFFF)
  20.  
  21. -> Watch the menus and wait for the user to select the close gadget or quit
  22. -> from the menus.
  23. PROC handle_window_events(win, menuStrip)
  24.   DEF done=FALSE, menuNumber, menuNum, itemNum, subNum,
  25.       item:PTR TO menuitem, class
  26.   REPEAT
  27.     -> E-Note: we can use WaitIMessage in this example
  28.     class:=WaitIMessage(win)
  29.     SELECT class
  30.     CASE IDCMP_CLOSEWINDOW
  31.       done:=TRUE
  32.     CASE IDCMP_MENUPICK
  33.       -> E-Note: convert message code to an unsigned INT
  34.       menuNumber:=UNSIGNED(MsgCode())
  35.       WHILE (menuNumber<>MENUNULL) AND (done=FALSE)
  36.         item:=ItemAddress(menuStrip, menuNumber)
  37.  
  38.         -> Process the item here!
  39.         menuNum:=MENUNUM(menuNumber)
  40.         itemNum:=ITEMNUM(menuNumber)
  41.         subNum:=SUBNUM(menuNumber)
  42.  
  43.         -> Stop if quit is selected
  44.         IF (menuNum=0) AND (itemNum=5) THEN done:=TRUE
  45.  
  46.         -> E-Note: convert item.nextselect to an unsigned INT
  47.         menuNumber:=UNSIGNED(item.nextselect)
  48.       ENDWHILE
  49.     ENDSELECT
  50.   UNTIL done
  51. ENDPROC
  52.  
  53. -> Open all of the required libraries and set-up the menus
  54. PROC main() HANDLE
  55.   DEF win=NIL:PTR TO window, my_VisualInfo=NIL, menuStrip=NIL
  56.   gadtoolsbase:=OpenLibrary('gadtools.library', 37)
  57.   win:=OpenWindowTagList(NIL, [WA_WIDTH,  400, WA_ACTIVATE,    TRUE,
  58.                                WA_HEIGHT, 100, WA_CLOSEGADGET, TRUE,
  59.                                WA_TITLE,  'Menu Test Window',
  60.                                WA_IDCMP,  IDCMP_CLOSEWINDOW OR IDCMP_MENUPICK,
  61.                                NIL])
  62.   my_VisualInfo:=GetVisualInfoA(win.wscreen, [NIL])
  63.   menuStrip:=CreateMenusA([NM_TITLE, 0, 'Project',     0, 0, 0, 0,
  64.                             NM_ITEM, 0, 'Open...',   'O', 0, 0, 0,
  65.                             NM_ITEM, 0, 'Save',      'S', 0, 0, 0,
  66.                             NM_ITEM, 0, NM_BARLABEL,   0, 0, 0, 0,
  67.                             NM_ITEM, 0, 'Print',       0, 0, 0, 0,
  68.                              NM_SUB, 0, 'Draft',       0, 0, 0, 0,
  69.                              NM_SUB, 0, 'NLQ',         0, 0, 0, 0,
  70.                             NM_ITEM, 0, NM_BARLABEL,   0, 0, 0, 0,
  71.                             NM_ITEM, 0, 'Quit...',   'Q', 0, 0, 0,
  72.                            NM_TITLE, 0, 'Edit',        0, 0, 0, 0,
  73.                             NM_ITEM, 0, 'Cut',       'X', 0, 0, 0,
  74.                             NM_ITEM, 0, 'Copy',      'C', 0, 0, 0,
  75.                             NM_ITEM, 0, 'Paste',     'V', 0, 0, 0,
  76.                             NM_ITEM, 0, NM_BARLABEL,   0, 0, 0, 0,
  77.                             NM_ITEM, 0, 'Undo',      'Z', 0, 0, 0,
  78.                              NM_END, 0, NIL,           0, 0, 0, 0]:newmenu,
  79.                           [NIL])
  80.   IF LayoutMenusA(menuStrip, my_VisualInfo, [NIL])
  81.     IF SetMenuStrip(win, menuStrip)
  82.       handle_window_events(win, menuStrip)
  83.  
  84.       ClearMenuStrip(win)
  85.     ENDIF
  86.     FreeMenus(menuStrip)
  87.   ENDIF
  88. EXCEPT DO
  89.   IF my_VisualInfo THEN FreeVisualInfo(my_VisualInfo)
  90.   IF win THEN CloseWindow(win)
  91.   IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
  92.   SELECT exception
  93.   CASE ERR_LIB;  WriteF('Error: Could not open gadtools.library\n')
  94.   CASE ERR_MENU; WriteF('Error: Could not create menu\n')
  95.   CASE ERR_VIS;  WriteF('Error: Could not get visual info\n')
  96.   CASE ERR_WIN;  WriteF('Error: Could not open window\n')
  97.   ENDSELECT
  98. ENDPROC