315 lines
8.3 KiB
Plaintext
315 lines
8.3 KiB
Plaintext
|
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<i> = 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<i> = 1
|
||
|
else submenu.flag<i> = 0
|
||
|
end
|
||
|
else submenu.flag<i> = 0
|
||
|
|
||
|
menu.items<i> = downcase(trim(menu.record<2,i>))
|
||
|
|
||
|
* strip off cursor control stuff for formatted menus
|
||
|
|
||
|
if menu.items<i>[1,2] = '@('
|
||
|
then
|
||
|
j = index(menu.items<i>,')',1)+1
|
||
|
menu.items<i> = menu.items<i>[j,999]
|
||
|
end
|
||
|
|
||
|
if max.item.len < lendp(menu.items<i>)
|
||
|
then max.item.len = lendp(menu.items<i>)
|
||
|
|
||
|
menu.help<i> = menu.record<4,i>[1,COLUMNS-2]
|
||
|
menu.mnemonic<i> = 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<i> = ''
|
||
|
then
|
||
|
menu.mnemonic<i> = menu.items<i>[1,1]
|
||
|
nextchar = 2
|
||
|
end
|
||
|
else
|
||
|
nextchar = 1
|
||
|
end
|
||
|
|
||
|
for j = 1 to i - 1
|
||
|
if menu.mnemonic<i> = menu.mnemonic<j>
|
||
|
then
|
||
|
if nextchar < 0
|
||
|
then
|
||
|
menu.mnemonic<i>=char(seq(menu.mnemonic<i>)+1)
|
||
|
end
|
||
|
else
|
||
|
if nextchar > lendp(menu.items<i>)
|
||
|
then
|
||
|
menu.mnemonic<i> = 'a'
|
||
|
nextchar = -1
|
||
|
end
|
||
|
else
|
||
|
if nextchar > menu.item.len
|
||
|
then menu.item.len += 1
|
||
|
menu.mnemonic<i> = menu.items<i>[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<i> = menu.items<i>[1,menu.item.len]
|
||
|
mnem.pos = index(menu.items<i>,menu.mnemonic<i>,1)
|
||
|
menu.mnemonic<i> = upcase(menu.mnemonic<i>)
|
||
|
|
||
|
if orientation = HORIZONTAL
|
||
|
then
|
||
|
menu.width<i,1> = xcur
|
||
|
if mnem.pos
|
||
|
then
|
||
|
menu.items<i> = menu.items<i>[1,mnem.pos-1]:menu.mnemonic<i>:menu.items<i>[mnem.pos+1,999]
|
||
|
xcur += menu.item.len + 2
|
||
|
end
|
||
|
else
|
||
|
menu.items<i> = menu.items<i>:' (':menu.mnemonic<i>:')'
|
||
|
xcur += menu.item.len + 6
|
||
|
end
|
||
|
menu.width<i,2> = xcur - 1
|
||
|
end
|
||
|
else
|
||
|
if mnem.pos
|
||
|
then
|
||
|
menu.items<i> = menu.items<i>[1,mnem.pos-1]:menu.mnemonic<i>:menu.items<i>[mnem.pos+1,999]
|
||
|
end
|
||
|
else
|
||
|
menu.items<i> = menu.items<i>:' (':menu.mnemonic<i>:')'
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if orientation = VERTICAL
|
||
|
then
|
||
|
menu.items<i> = fmtdp(menu.items<i>,'L#':(menu.item.len+vpad))
|
||
|
if sum(submenu.flag)
|
||
|
then
|
||
|
if submenu.flag<i>
|
||
|
then menu.items<i> = v.line:" ":menu.items<i>:" => ":v.line
|
||
|
else menu.items<i> = v.line:" ":menu.items<i>:" ":v.line
|
||
|
end
|
||
|
else
|
||
|
menu.items<i> = v.line:" ":menu.items<i>:" ":v.line
|
||
|
end
|
||
|
end
|
||
|
else
|
||
|
menu.items<i> = fmtdp(' ':menu.items<i>,'L#':(menu.width<i,2>-menu.width<i,1>+1))
|
||
|
end
|
||
|
next i
|
||
|
|
||
|
menu.flag = 1
|
||
|
return
|
||
|
|
||
|
end
|