home *** CD-ROM | disk | FTP | other *** search
- (* ------------------------------------------------------ *)
- (* MENU.INC *)
- (* Dynamische Pulldown Menueverwaltung *)
- (* (c) 1988 Bernd Ott & TOOLBOX *)
- (* ------------------------------------------------------ *)
-
- TYPE OptionTyp = (init, drop, hide, show);
- ParamTyp = STRING[12];
-
- FUNCTION Menu(name : ParamTyp; option : OptionTyp): ParamTyp;
-
- CONST highlighton = 7;
- highlightoff = 15;
- kbdexit = #252;
- kbdnext = #32;
- kbdselect = #13;
-
- TYPE ItemPointerTyp = ^ItemTyp;
- SubItemPointerTyp = ^SubItemTyp;
-
- ItemTyp = RECORD
- name : ParamTyp;
- next : ItemPointerTyp;
- first : SubItemPointerTyp;
- END;
-
- SubItemTyp = RECORD
- xpos, ypos : INTEGER;
- line : STRING[80];
- return : ParamTyp;
- next : SubItemPointerTyp;
- END;
-
- ItemFileTyp = TEXT;
-
- VAR rootpointer,
- hpointer1 : ItemPointerTyp;
- hpointer2 : SubItemPointerTyp;
- itemfile : ItemFileTyp;
- inchar : CHAR;
-
- PROCEDURE UnchainItem(VAR pointer : ItemPointerTyp);
- { entferne Menuename aus Hauptliste, falls vorhanden }
-
- PROCEDURE UnchainSubItem(VAR first : SubItemPointerTyp);
- { entferne Menuepunkte aus Unterliste }
- BEGIN
- IF first^.next <> hpointer2 THEN
- UnchainSubItem(first^.next);
- Dispose(first);
- END;
-
- BEGIN
- IF pointer <> NIL THEN
- IF pointer^.name = name THEN BEGIN
- hpointer1 := pointer;
- hpointer2 := pointer^.first;
- UnchainSubItem(pointer^.first);
- pointer := pointer^.next;
- Dispose(hpointer1);
- END ELSE
- UnchainItem(pointer^.next);
- END;
-
- FUNCTION ChainItem(VAR pointer : ItemPointerTyp) : ItemPointerTyp;
-
- FUNCTION ChainSubItem(VAR first : SubItemPointerTyp) : BOOLEAN;
-
- VAR count, error : INTEGER;
- BEGIN
- IF NOT (Eof(ItemFile)) THEN BEGIN
- IF first = NIL THEN BEGIN
- New(first);
- first^.next := NIL;
- count := 0;
- REPEAT
- first^.line := '';
- Read(ItemFile, inchar);
- REPEAT
- first^.line := first^.line + inchar;
- Read(ItemFile, inchar);
- UNTIL inchar = ',';
- count := Succ(count);
- CASE count OF
- 1: Val(first^.line, first^.xpos, error);
- 2: Val(first^.line, first^.ypos, error);
- 3: first^.return := first^.line;
- END;
- UNTIL EoLn(ItemFile);
- ReadLn(ItemFile);
- hpointer2 := first;
- ChainSubItem := TRUE;
- END ELSE
- ChainSubItem := ChainSubItem(first^.next);
- END ELSE
- ChainSubItem := FALSE;
- END;
-
- BEGIN
- IF pointer = NIL THEN BEGIN
- {$I-}
- Assign(ItemFile, name);
- Reset(ItemFile);
- {$I+}
- IF IOResult = 0 THEN BEGIN
- New(pointer);
- pointer^.name := name;
- pointer^.next := NIL;
- pointer^.first := NIL;
- WHILE ChainSubItem(pointer^.first) DO;
- hpointer2^.next := pointer^.first;
- Close(ItemFile);
- ChainItem := pointer;
- END ELSE
- ChainItem := NIL;
- END ELSE
- IF pointer^.name = name THEN
- ChainItem := pointer
- ELSE
- ChainItem := ChainItem(pointer^.next);
- END;
-
- BEGIN
- menu := '';
- CASE option OF
- init : RootPointer := NIL;
- drop : UnchainItem(RootPointer);
- hide : hpointer1 := ChainItem(RootPointer);
- show : BEGIN
- hpointer1 := ChainItem(RootPointer);
- IF hpointer1 <> NIL THEN
- WITH hpointer1^ DO BEGIN
- hpointer2 := first;
- REPEAT
- hpointer2 := hpointer2^.next;
- GotoXY(hpointer2^.xpos, hpointer2^.ypos);
- Write(hpointer2^.line);
- UNTIL hpointer2 = first;
- REPEAT
- GotoXY(first^.xpos, first^.ypos);
- TextColor(highlighton);
- Write(first^.line);
- TextColor(highlightoff);
- Read(KBD, inchar);
- CASE inchar OF
- kbdnext : BEGIN
- GotoXY(first^.xpos, first^.ypos);
- Write(first^.line);
- first := first^.next;
- END;
- kbdselect : menu := first^.return;
- kbdexit : menu := 'exit';
- END;
- UNTIL inchar IN [kbdselect, kbdexit];
- END;
- END;
- END;
- END;
-