{***********************************************************************}
{									}
{ UTLMNU.IMP   Internal Unit_Mnu routines				}
{									}
{_______________________________________________________________________}

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{  SetMenuError    Set the error flag _MenuError to a value of the	}
{  type _MError.							}
{_______________________________________________________________________}

procedure SetMenuError(Error : _MError);

  begin {SetMenuError}

    _MenuError := Error

  end;	{SetMenuError}


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{  ValidWindow	   Check to see whether a _WindowPtr points to an	}
{  existing window.  Every menu must be attached to a valid window.	}
{_______________________________________________________________________}

function ValidWindow(WindowPtr: _WindowPtr) : boolean;

  var
    Found   : boolean;
    TempPtr : _WindowPtr;

  begin {ValidWindow}

    Found   := FALSE;
    TempPtr := _WinRoot;
    while ((not Found) and (TempPtr <> NIL)) do
      if (TempPtr = WindowPtr) then
	 Found := TRUE
      else
	 TempPtr := TempPtr^._WinTop;

    ValidWindow := Found

  end;	{ValidWindow}


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{  ValidSig	   Check a _Menu, _Key, or _Item structure for its	}
{ characteristic signature, returning TRUE if found, FALSE otherwise.	}
{_______________________________________________________________________}

function ValidSig(TempPtr : pointer; Sig : char): boolean;

  begin {ValidSig}

    ValidSig := FALSE;

    case Sig of
      MENUSIG_ : if (_MenuPtr(TempPtr)^._MSig <> MENUSIG_) then
		    SetMenuError(_InvalidMenu)
		 else
		    ValidSig := TRUE;
      KEYSIG_  : if (_KeyPtr(TempPtr)^._KSig <> KEYSIG_) then
		   SetMenuError(_InvalidKey)
		 else
		   ValidSig := TRUE;
      ITEMSIG_ : if (_ItemPtr(TempPtr)^._ISig <> ITEMSIG_) then
		    SetMenuError(_InvalidItem)
		 else
		    ValidSig := TRUE;
    end

  end;	{ValidSig}


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{  AddKey	   Add a _Key record to a linked list.	This function	}
{  is used by __MakeMnu, __KeyMnu and the initialization code. Initial	}
{  error handling is the responsibility of the calling procedure.	}
{_______________________________________________________________________}

function AddKey(ItemPtr: _ItemPtr; ChScan : _KeySeq;
				   Action : byte;
				   Motion : _MenuMotion) : _KeyPtr;

  var
    TempPtr : _KeyPtr;

  begin {AddKey}

    GetMem(TempPtr,SizeOf(_Key));      { Allocate the key		}
    with TempPtr^ do
      begin
	_KSig	 := 'K';
	_KChSc	 := ChScan;
	_Action  := Action;
	_Motion  := Motion;
	_KeyItem := ItemPtr;
	_NextKey := NIL 	       { End of list, for the moment	}
      end;
    AddKey := TempPtr

  end;	{AddKey}


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ BeepKnown	   Make a sound, defined by the variables _KnownPitch	}
{ and _KnownDelay, when a key is pressed which which has been defined	}
{ with an _Action that includes _KBEEP_MNU.				}
{_______________________________________________________________________}

procedure BeepKnown;

  begin {BeepKnown}

    Sound(_KnownPitch);
    Delay(_KnownDelay);
    Nosound

  end;	{BeepKnown}

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ BeepUnKnown	   Make a sound, defined by the variables _UnknownPitch }
{ and _UnknownDelay, when a key is pressed which which has not been	}
{ defined.  Called only if the menu option includes _MBEEP_UNKNOWN_MNU. }
{_______________________________________________________________________}

procedure BeepUnknown;

  begin {BeepUnknown}

    Sound(_UnknownPitch);
    Delay(_UnknownDelay);
    Nosound

  end;	{BeepUnknown}


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ BeepTransmit	   Make a sound defined by the variables _TransmitPitch }
{ and _TransmitDelay when a menu is transmitted. Called only if the	}
{ menu option includes _MBEEP_TRANSMIT_MNU.				}
{_______________________________________________________________________}

procedure BeepTransmit;

  begin {BeepTransmit}

    Sound(_TransmitPitch);
    Delay(_TransmitDelay);
    NoSound

  end;	{BeepTransmit}
