*     A demonstration program to illustrate the dynamic creation of
*     a menu bar from Prospero Fortran
*
*     Author : R K Chapman
*     Date   : 5 August 1987
*
      PROGRAM tmenu
      IMPLICIT none
      
      INTEGER*4 menu_create, menu_title, menu_item, AESret, form_alert

      INTEGER*4 my_menu_bar, title_1, title_2
      INTEGER*4 opt1, opt2, opt3, opt4, opt5, dummy
      INTEGER*4 title, item
      INTEGER*2 buffer(0:7)
      CHARACTER*4 quote

      INCLUDE 'gemconst'

      CALL appl_init
      IF (AESret() .lt. 0) GOTO 999
      my_menu_bar = menu_create(5, 5, '  Desk '//char(0))
      title_1 = menu_title(my_menu_bar, ' File '//char(0))
      title_2 = menu_title(my_menu_bar, ' Test '//char(0))
      opt1 = menu_item(my_menu_bar, title_1,' Open   '//char(0))
      opt2 = menu_item(my_menu_bar, title_1,' Quit'//char(0))
      opt3 = menu_item(my_menu_bar, title_2,' Test   '//char(0))
      opt4 = menu_item(my_menu_bar, title_2,'-----------'//char(0))
      opt5 = menu_item(my_menu_bar, title_2,' Mode ... '//char(0))
      CALL menu_ienable(my_menu_bar, opt4, .FALSE.)
      CALL menu_bar(my_menu_bar, .TRUE.)

10    CONTINUE
        CALL evnt_mesag(buffer)
        title = buffer(3)
        item = buffer(4)
        IF (buffer(0) .eq. MN_SELECTED) THEN
          IF (item .eq. opt2) THEN
            GOTO 20
          ELSE IF (item .eq. opt1) THEN
            quote = 'Open'
          ELSE IF (item .eq. opt3) THEN
            quote = 'Test'
          ELSE IF (item .eq. opt5) THEN
            quote = 'Mode'
          ELSE IF (title .eq. 3) THEN
            quote = 'Desk'
          END IF 
          dummy = form_alert(1, '[1][You selected ' // quote //
     -                       '][ OK ]' // char(0))
20        CONTINUE
          CALL menu_tnormal(my_menu_bar, title, .TRUE.)
          IF (item .ne. opt2) GOTO 10
        END IF
      CALL appl_exit
999   CONTINUE
      END
