Subroutine MTF.LOAD.B(menu.id, orientation, x, y, menu.flag, menu.title, menu.items, menu.help, menu.mnemonic, menu.x.orig, menu.y.orig, menu.width, menu.choices, menu.actions, submenu.flag) ****************************************************************************** * * Subroutine to load MOTIF like menu definition * * Module %M% Version %I% Date %H% * * (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved * This is unpublished proprietary source code of Ardent Software Inc. * The copyright notice above does not evidence any actual or intended * publication of such source code. * ******************************************************************************* * * Maintenence log - insert most recent change descriptions at top * * Date.... GTAR# WHO Description......................................... * 10/14/98 23801 SAP Change copyrights. * 05/15/96 18330 LDG Changed LEN/FMT() funcs to LEN/FMTDP() for NLS DBCS. * 02/7/91 7673 DTM Added final changes for FCS * ******************************************************************************* * * This routine loads a MOTIF menu definition. * * Input parameters are: * menu.id - the name of the menu item to read out of the VOC * * orientation - flag indicating if menu is a horizontal menubar * or a vertical menu box * * x - suggested x (horizontal) anchor point * * y - suggested y (vertical) anchor point * * Output parameters are: * * menu.flag - set to 1 on exit if we successfully load the menu, set to * 0 if requested is either not in the VOC or not defined to be a * menu, and set to the text of a descriptive error message if a * processing error occured while loading the menu. * * menu.title - menu title from field 1 of menu definition * * menu.items - dynamic array containing formated menu item captions, text * for the captions is extracted from field 1 of menu definition. * Captions that are too long will be truncated. Short captions * will be padded with spaces. * * menu.help - dynamic array of help text from field 4 of menu definition * * menu.mnemonic - dynamic array menu mnemonics, these are read from field * 8 of the menu record. Mnemonics are automatically generated for * menu items that do not have an explicit menmonic. All mnemonics, * explicit or generated, are checked for uniqueness and changed * whenever a conflict is found. * * menu.x.orig - menu x (horizontal) anchor point, this is usually the same * as the input x value, but may be moved to the left if this is * needed to make the menu box fit on the screen. * * menu.y.orig - menu y (vertical) anchor point, this is usually the same * as the input y value, but may be moved to up if this is * needed to make the menu box fit on the screen. * * menu.width - menu width if vertical; dynamic array of x * start and end points for each caption if horizontal * * menu.choices - menu number of captions on menu * * menu.actions - dynamic array of menu dispatch actions from field 3 * of menu definition * * submenu.flag - dynamic array indicating that each menu action either * is or is not a submenu. id = "%W%" $include UNIVERSE.INCLUDE MTF.INCL.H * Initialize output values menu.flag = 0 menu.title = '' menu.items = '' menu.help = '' menu.mnemonic = '' menu.x.orig = 0 menu.y.orig = 0 menu.width = 0 menu.choices = 0 menu.actions = '' submenu.flag = '' * find menu name in VOC file and read in menu desc if it is a menu read menu.desc from voc.file, menu.id else return if upcase(menu.desc<1>[1,1]) # 'M' then return open menu.desc<2> to menu.file else menu.flag = UVREADMSG(075020,menu.desc<2>) return end read menu.record from menu.file, menu.desc<3> else menu.flag = UVREADMSG(075021,menu.desc<3>) return end * set menu title to menu id if not title if menu.record<1> = '' then menu.record<1> = upcase(menu.desc<3>) * make sure the menu has selections menu.choices = dcount(menu.record<2>,@vm) if menu.choices = 0 then menu.flag = UVREADMSG(075022,menu.id); return * first pass at menu parts - check for submenus, set up help, init mnemonics max.item.len = 0 for i = 1 to menu.choices * get menu action and check if it is a submenu menu.actions = menu.record<3,i> read submenu.record from voc.file, menu.record<3,i> then if upcase(submenu.record<1>[1,1]) = 'M' then submenu.flag = 1 else submenu.flag = 0 end else submenu.flag = 0 menu.items = downcase(trim(menu.record<2,i>)) * strip off cursor control stuff for formatted menus if menu.items[1,2] = '@(' then j = index(menu.items,')',1)+1 menu.items = menu.items[j,999] end if max.item.len < lendp(menu.items) then max.item.len = lendp(menu.items) menu.help = menu.record<4,i>[1,COLUMNS-2] menu.mnemonic = downcase(menu.record<8,i>[1,1]) next i * check for mnemonic conflicts and generate auto mnemonics as needed menu.item.len = 1 non.mnemonics = 0 vpad = 0 if sum(submenu.flag) then size.adjustment = 7 else size.adjustment = 4 for i = 1 to menu.choices if menu.mnemonic = '' then menu.mnemonic = menu.items[1,1] nextchar = 2 end else nextchar = 1 end for j = 1 to i - 1 if menu.mnemonic = menu.mnemonic then if nextchar < 0 then menu.mnemonic=char(seq(menu.mnemonic)+1) end else if nextchar > lendp(menu.items) then menu.mnemonic = 'a' nextchar = -1 end else if nextchar > menu.item.len then menu.item.len += 1 menu.mnemonic = menu.items[nextchar,1] nextchar += 1 end end j = 0 end next j if nextchar < 0 then if vpad = 0 then size.adjustment += 4 vpad = 4 end non.mnemonics += 1 end if orientation = HORIZONTAL then if menu.choices*(menu.item.len+2) + (non.mnemonics*4) >COLUMNS then menu.flag = 'Sorry, the ':menu.id:' MENU will not fit on this terminal.'; return end else if menu.item.len + size.adjustment > COLUMNS then menu.flag = 'Sorry, the ':menu.id:' MENU will not fit on this terminal.'; return end next i * make sure the menu can fit if orientation = HORIZONTAL then * main menu, horizontal loop while menu.choices*(menu.item.len+3) + (non.mnemonics*4) < COLUMNS do menu.item.len += 1 repeat menu.x.orig = 0 menu.y.orig = 1 end else * submenu, vertical menu.item.len = COLUMNS - size.adjustment if menu.item.len > max.item.len then menu.item.len = max.item.len menu.x.orig = x loop while menu.x.orig + menu.item.len + size.adjustment > COLUMNS - 1 do menu.x.orig -= 1 repeat if menu.choices > LINES - 5 then menu.flag = UVREADMSG(075023,menu.id);return menu.y.orig = y loop while menu.y.orig + menu.choices + 1 >= LINES - 1 do menu.y.orig -= 1 repeat menu.width = menu.item.len + size.adjustment end if menu.item.len < 5 ;* arbitrary choice for minimum size of menu choice then menu.flag = UVREADMSG(075023,menu.id) * now preformat menu display, and setup mnemonics menu.title = trim(menu.record<1>)[1,COLUMNS-2] xcur = menu.x.orig for i = 1 to menu.choices menu.items = menu.items[1,menu.item.len] mnem.pos = index(menu.items,menu.mnemonic,1) menu.mnemonic = upcase(menu.mnemonic) if orientation = HORIZONTAL then menu.width = xcur if mnem.pos then menu.items = menu.items[1,mnem.pos-1]:menu.mnemonic:menu.items[mnem.pos+1,999] xcur += menu.item.len + 2 end else menu.items = menu.items:' (':menu.mnemonic:')' xcur += menu.item.len + 6 end menu.width = xcur - 1 end else if mnem.pos then menu.items = menu.items[1,mnem.pos-1]:menu.mnemonic:menu.items[mnem.pos+1,999] end else menu.items = menu.items:' (':menu.mnemonic:')' end end if orientation = VERTICAL then menu.items = fmtdp(menu.items,'L#':(menu.item.len+vpad)) if sum(submenu.flag) then if submenu.flag then menu.items = v.line:" ":menu.items:" => ":v.line else menu.items = v.line:" ":menu.items:" ":v.line end else menu.items = v.line:" ":menu.items:" ":v.line end end else menu.items = fmtdp(' ':menu.items,'L#':(menu.width-menu.width+1)) end next i menu.flag = 1 return end