CTask *tour_put, *tour_task;
Bool tour_okay_pressed;

U0 TourPutTask()
{
        CDoc *doc;
        I64   ch;

        DocTermNew;
        WinHorz(TEXT_COLS / 2, TEXT_COLS - 2);
        WinVert(TEXT_ROWS / 2 + 5, TEXT_ROWS - 7);
        LBts(&Fs->display_flags, DISPLAYf_WIN_ON_TOP);
        WinToTop;
        Fs->border_src  = BDS_CONST;
        Fs->border_attr = LTGRAY << 4 + DriveTextAttrGet(':') & 15;
        Fs->text_attr   = LTGRAY << 4 + BLUE;
        Fs->win_inhibit = WIG_NO_FOCUS_TASK_DEFAULT;
        doc = DocPut;
        doc->flags |= DOCF_FORM;
        DocCursor(FALSE, doc);
        "$WW+H,1$";
        while (TRUE)
        {
                Refresh;
                if (MessageScan(&ch,, 1 << MESSAGE_KEY_DOWN) && (ch == CH_ESC || ch == CH_SHIFT_ESC))
                {
                        Kill(tour_task->parent_task, FALSE);
                        break;
                }
                DocLock(doc);
                if (ch == CH_SPACE && doc->cur_entry != doc) {
                        if (doc->cur_entry->de_flags & DOCEF_LINK)
                                '' CH_SPACE;
                        else if (doc->cur_entry->type_u8 == DOCT_BTTN)
                                tour_okay_pressed = TRUE;
                }
                DocUnlock(doc);
                if (tour_okay_pressed)
                {
                        Fs->win_inhibit = WIG_NO_FOCUS_TASK_DEFAULT;
                        if (sys_focus_task == Fs)
                                WinRefocus;
                }
                else
                {
                        Fs->win_inhibit = 0;
                        WinFocus;
                }
        }
        tour_put = NULL;
}

U0 TourPut(U8 *st,Bool wait_okay=FALSE)
{
        CDoc  *doc;
        CTask *old_focus_task;

        if (TaskValidate(tour_put))
        {
                doc = DocPut(tour_put);
                DocClear(doc);
                DocPrint(doc, "%s", st);
                if (!wait_okay)
                        tour_okay_pressed = TRUE;
                else
                {
                        DocPrint(doc, "\n\n$CM-RE+CX,LE=-2$$BT,\"Okay\",LM=\"b\"$\n\n");
                        DocFormBwd(doc);
                        old_focus_task = sys_focus_task;
                        tour_okay_pressed = FALSE;
                        do Refresh;
                        while (!tour_okay_pressed);
                        WinFocus(old_focus_task);
                        DocClear(doc);
                }
        }
        else
                Kill(tour_task,, TRUE);
}

public I64 PopUpTourPart()
{
        I64   i;
        CDoc *doc = DocNew;

        DocPrint(doc,   "$PURPLE$ZealOS Tours$FG$\n\n"
                                        "$CM+LX,4,4$$BT,\"Part  1: The help system\",LE=1$"
                                        "$CM+LX,4,4$$BT,\"Part  2: The basics\",LE=2$"
                                        "$CM+LX,4,4$$BT,\"Part  3: Editing and running programs\",LE=3$"
                                        "$CM+LX,4,4$$BT,\"Part  4: Adding macros to PersonalMenu\",LE=4$"
                                        "$CM+LX,4,4$$BT,\"Part  5: Choose filename, choose dir\",LE=5$"
                                        "$CM+LX,4,4$$BT,\"Part  6: AutoComplete\",LE=6$"
                                        "$CM+LX,4,4$$BT,\"Part  7: Search (Find)\",LE=7$"
                                        "$CM+LX,4,4$$BT,\"Part  8: ZealOS file masks\",LE=8$"
                                        "$CM+LX,4,4$$BT,\"Part  9: Editor filter\",LE=9$"
                                        "$CM+LX,4,4$$BT,\"Part 10: Debugging\",LE=10$"
                                        "$CM+LX,4,4$$BT,\"Part 11: Wow!!\",LE=11$"
                                        "$CM+LX,4,4$$BT,\"Part 12: Test Suite\",LE=12$"
                                        "$CM+LX,4,4$$BT,\"Done\",LE=DOCM_CANCEL$\n");
        doc->flags |= DOCF_FORM;
        i = PopUpPrint("WinMax;DocMenu(0x%X,0);", doc);
        DocDel(doc);

        return i;
}

U0 TourMenu()
{
        U8  buf[STR_LEN];
        I64 i;

        tour_task = Fs;
        tour_okay_pressed = TRUE;
        tour_put = Spawn(&TourPutTask, NULL, "TourPut",, Fs);
        TaskWait(tour_put);
        while (TRUE)
        {
                Cd(__DIR__);
                AutoComplete;
                if (LBtr(&tour_put->display_flags, DISPLAYf_SHOW))
                        WinZBufUpdate;
                i = PopUpTourPart;
                if (i > 0)
                {
                        if (!LBts(&tour_put->display_flags, DISPLAYf_SHOW))
                                WinZBufUpdate;
                        StrPrint(buf, "Tour%X.IN", i);
                        ExeFile(buf);
                }
                else
                        break;
        }
        Kill(tour_put);
}

"DocClear;WinMax;\n";
Refresh(2);
TourMenu;
Message(MESSAGE_KEY_DOWN, 0, SC_CURSOR_DOWN | SCF_CTRL);
"Cd;Dir;\n";