{***********************************************************************}
{									}
{ __MakeMnu   Create a menu descriptor					}
{									}
{ function  __MakeMnu(	WindowPtr : _WindowPtr; 			}
{		      BFore,BBack,					}
{		      LFore,LBack,					}
{		      PFore,PBack : byte) : _MenuPtr;			}
{									}
{	      WindowPtr Pointer to the window descriptor returned by	}
{			__MakeWin.  The menu is initially attached to	}
{			this window.					}
{	      BFore	Foreground attribute of highlight bar		}
{	      BBack	Background attribute of highlight bar		}
{	      LFore	Foreground attribute of Lotus-style description }
{	      LBack	Background attribute of Lotus-style description }
{	      PFore	Foreground attribute of protected items 	}
{	      PBack	Background attribute of protected itesm 	}
{									}
{ Description This function creates a menu structure, associates the	}
{	      menu structure with a previously created window struc	}
{	      ture, and returns a pointer to the menu structure.	}
{	      The function also loads the default key definitions	}
{	      pointed to by DefaultKeyPtr_ into the linked list of _Key }
{	      records pointed to by the _MKeysPtr field of the returned }
{	      _Menu record.  If the menu cannot be created, the 	}
{	      function returns NIL.					}
{									}
{	      On error _MenuError may be set to:  _InvalidWindow	}
{						  _InvalidKey		}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

function __MakeMnu(  WindowPtr : _WindowPtr;
		   BFore,BBack,
		   LFore,LBack,
		   PFore,PBack : byte) : _MenuPtr;

  var
    NewMenuPtr	: _MenuPtr;
    DKeyPtr	: _KeyPtr;
    NewKeyPtr	: _KeyPtr;
    LastKeyPtr	: _KeyPtr;

  begin {__MakeMnu}

    __MakeMnu := NIL;

    { First determine that WindowPtr points to a valid window.		}

    if (not ValidWindow(WindowPtr)) then
       begin
	 SetMenuError(_InvalidWindow);
	 Exit			       { No record found, so return.	}
      end;

    { Now allocate a new menu structure.				}

    GetMem(NewMenuPtr,SizeOf(_Menu));
    with NewMenuPtr^ do
      begin
	_MSig	   := 'M';
	_MItemsPtr := NIL;	       { No items yet			}
	_MITailPtr := NIL;
	_MKeysPtr  := NIL;	       { No keys yet			}
	_MLastPtr  := NIL;
	_MWinPtr   := WindowPtr;
	_BarFore   := BFore;
	_BarBack   := BBack;
	_LDescFore := LFore;
	_LDescBack := LBack;
	_ProtFore  := PFore;
	_ProtBack  := PBack
      end;

    { Now load the default key definitions into the _MKeysPtr list.	}

    DKeyPtr   := DefaultKeyPtr_;       { Set to default key list	}
    NewKeyPtr := NIL;
    while (DKeyPtr <> NIL) do	       { Load defaults if any		}
      begin
	with DKeyPtr^ do
	  begin
	    if (not ValidSig(DKeyPtr,KEYSIG_)) then
	       Exit
	    else
	       LastKeyPtr := NewKeyPtr;
	    NewKeyPtr := AddKey(NIL,_KChSc,_Action,_Motion);
	    if (NewMenuPtr^._MKeysPtr = NIL) then
	       NewMenuPtr^._MKeysPtr := NewKeyPtr
	    else
	       LastKeyPtr^._NextKey := NewKeyPtr
	  end;
	DKeyPtr := DKeyPtr^._NextKey
      end;

    __MakeMnu := NewMenuPtr

  end;	{__MakeMnu}
