Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - menutoprow() return the topmost screen row of a menu http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 menutoprow()        Return the topmost screen row of a menu
------------------------------------------------------------------------------
 Declaration
   menu.hdr

 Syntax
   func int menutoprow extern
   param value _MENU pMenu

 Arguments
   pMenu is the pointer to a previously created menu system. If 0, the
         default menu will be used.

 Return
   The row value, or -1 if an invalid menu was specified.

 Description
   This is a utility function that might be called from within menu handlers,
   e.g. to determine the screen area that will be occupied by a submenu in
   order to save that screen area before displaying the menu.

 Example
   #define EXAMPLE_MENU
   #include example.hdr

   #define ID_NEW       1
   #define ID_OPEN      2
   #define ID_OPEN_AS   3
   #define ID_SAVE      4
   #define ID_SAVE_AS   5
   #define ID_QUIT      6
   #define ID_SUB_ASCII 1
   #define ID_SUB_DBF   2
   
   // ----- "Dummy" functions -----
   //
   func logical NewFile
      param value _MENU pMenu, value uint uId
      @ 10, 0 ?? "The new file function     "
      return .t.
   endfunc
   
   func logical OpenFile
      param value _MENU pMenu, value uint uId
      @ 10, 0 ?? "The open file function    "
      return .t.
   endfunc
   
   func logical SaveFile
      param value _MENU pMenu, value uint uId
      @ 10, 0 ?? "The save file function    "
      return .t.
   endfunc
   
   func logical SaveASCII
      param value _MENU pMenu, value uint uId
      @ 10, 0 ?? "The ASCII format function "
      return .t.
   endfunc
   
   func logical SaveDBF
      param value _MENU pMenu, value uint uId
      @ 10, 0 ?? "The DBF format function   "
      return .t.
   endfunc
   
   func logical Terminate
      param value _MENU pMenu, value uint uId
      return .f.
   endfunc
   //
   // ----- End of "dummy" functions -----
   
   // This function handles "generic" vertical menus, i.e. it positions the
   // menus on the screen according to the current offset values.
   //
   proc MyPullDown
   param value _MENU pMenu
   
   vardef
      uint    uKey, uTop, uLeft, uBottom, uRight
      _HSCR   hScreen
   enddef
   
   // Determine the screen area occupied by the sub-menu, and save that
   // area for later restore.
   //
   uTop    := menutoprow( pMenu ) + menurowoffset( pMenu )
   uLeft   := menuleftcol( pMenu ) + menucoloffset( pMenu )
   uBottom := uTop + menuitemcount( pMenu ) - 1
   uRight  := uLeft + menupromptlen( pMenu ) - 1
   hScreen := savescrn( uTop, uLeft, uBottom, uRight )
   
   // Display the menu, and handle the keystrokes...
   //
   menudispall( pMenu )
   do while .t.
      uKey := getkey()
      do case
         case uKey == K_UP
            menusetprev( pMenu )
         case uKey == K_DOWN
            menusetnext( pMenu )
         case uKey == K_RIGHT .or. uKey == K_LEFT
            keyint( uKey )
            exit
         case uKey == K_ENTER
            menuexecfunc( pMenu )
            exit
      endcase
   enddo
   restorescrn( hScreen )
   endfunc
   
   // This procedure handles the horizontal main menu.
   //
   proc MyMainMenu
      param value _MENU pMenu
   
      vardef
        _MENU pSubMenu
        uint  uKey
      enddef
   
      // Display the menu, and handle the keystrokes...
      //
      menudispall( pMenu )
      do while .t.
         uKey := getkey()
         do case
            case uKey == K_LEFT
               menusetprev( pMenu )
            case uKey == K_RIGHT
               menusetnext( pMenu )
            case uKey == K_ENTER
               pSubMenu := menugetsub( pMenu, menucurrentid( pMenu ) )
   
               // There is no sub-menu, so we execute the assigned function.
               //
               if pSubMenu == 0
                  if .not. menuexecfunc( pMenu )
                     exit
                  endif
   
               // There is a sub-menu - so we set the screen offset and
               // execute the sub-menu.
               //
               else
                  menusetoffset( pSubMenu,                                ;
                         menugetrow( pMenu, menucurrentid( pMenu ) ) + 1, ;
                         menugetcol( pMenu, menucurrentid( pMenu ) ) )
                  MyPullDown( pSubMenu )
               endif
         endcase
      enddo
   
   endproc
   
   proc Test_menutoprow
   vardef
      _MENU pMenu, pSubMenu
   enddef
   
   clear
   cursor( .f. )
   menusethot( .t. )
   
   // The main menu (origin is 0, 0)
   //
   pMenu := menunew()
   menupromptnew( pMenu, 0,  0, " New ",     ID_NEW, .t., .f. )
   menupromptnew( pMenu, 0,  6, " Open ",    ID_OPEN, .t., .f. )
   menupromptnew( pMenu, 0, 13, " Open as ", ID_OPEN_AS, .t., .f. )
   menupromptnew( pMenu, 0, 23, " Save ",    ID_SAVE, .t., .f. )
   menupromptnew( pMenu, 0, 30, " Save as ", ID_SAVE_AS, .t., .f. )
   menupromptnew( pMenu, 0, 40, " Quit ",    ID_QUIT, .t., .f. )
   
   // A sub-menu (origin is 0, 0)
   //
   pSubMenu := menunew()
   menupromptnew( pSubMenu, 0, 0, " ASCII ", ID_SUB_ASCII, .t., .f. )
   menupromptnew( pSubMenu, 1, 0, " DBF   ", ID_SUB_DBF,   .t., .f. )
   
   // Link "one select" functions to some items in the main menu
   //
   menusetfunc( pMenu, ID_NEW,  &NewFile )
   menusetfunc( pMenu, ID_OPEN, &OpenFile )
   menusetfunc( pMenu, ID_SAVE, &SaveFile )
   menusetfunc( pMenu, ID_QUIT, &Terminate )
   
   // Link "one select" functions to some items in the sub-menu
   //
   menusetfunc( pSubMenu, ID_SUB_ASCII, &SaveASCII )
   menusetfunc( pSubMenu, ID_SUB_DBF,   &SaveDBF )
   
   // Link the sub-menu to the main menu's "Open as" and "Save as" items
   //
   // Note that the same sub-menu is linked to two different prompts - the
   // main menu handler takes care of setting the screen offset values in
   // order to display the sub-menu at the correct screen coordinates.
   //
   menusetsub( pMenu, ID_OPEN_AS, pSubMenu )
   menusetsub( pMenu, ID_SAVE_AS, pSubMenu )
   
   MyMainMenu( pMenu )
   
   menuclear( pMenu )        // Clears the menu and the sub-menu
   clear
   cursor( .t. )
   
   endproc

   proc main
   Test_menutoprow()
   endproc

See Also: menuleftcol()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson