Пример #1
0
void EbookController::TriggerLayout()
{
    Size s = ctrls->pagesLayout->GetPage1()->GetDrawableSize();
    SizeI size(s.Width, s.Height);
    if (size.IsEmpty()) {
        // we haven't been sized yet
        return;
    }
    // CrashIf(size.dx < 100 || size.dy < 40);
    if (!doc.IsDocLoaded())
        return;

    if (pageSize == size) {
        //lf("EbookController::TriggerLayout() - skipping layout because same as last size");
        return;
    }

    //lf("(%3d,%3d) EbookController::TriggerLayout",size.dx, size.dy);
    pageSize = size; // set it early to prevent re-doing layout at the same size

    StopFormattingThread();
    CrashIf(incomingPages);
    incomingPages = new Vec<HtmlPage*>(1024);

    HtmlFormatterArgs *args = CreateFormatterArgsDoc(doc, size.dx, size.dy, &textAllocator);
    formattingThread = new EbookFormattingThread(doc, args, this, currPageReparseIdx, cb);
    formattingThreadNo = formattingThread->GetNo();
    formattingThread->Start();
    UpdateStatus();
}
Пример #2
0
void EbookController::CloseCurrentDocument()
{
    ctrls->pagesLayout->GetPage1()->SetPage(nullptr);
    ctrls->pagesLayout->GetPage2()->SetPage(nullptr);
    StopFormattingThread();
    DeletePages(&pages);
    doc.Delete();
    pageSize = SizeI(0, 0);
}
EbookController::~EbookController()
{
    StopFormattingThread();
    EventMgr *evtMgr = ctrls->mainWnd->evtMgr;
    evtMgr->RemoveEventsForControl(ctrls->next);
    evtMgr->RemoveEventsForControl(ctrls->prev);
    evtMgr->RemoveEventsForControl(ctrls->progress);
    evtMgr->RemoveEventsForControl(ctrls->page);
    CloseCurrentDocument();
}
void EbookController::CloseCurrentDocument()
{
    ctrls->page->SetPage(NULL);
    StopFormattingThread();
    DeletePageShown();
    DeletePages(&pagesFromBeginning);
    DeletePages(&pagesFromPage);
    doc.Delete();
    formattingTemp.reparseIdx = 0; // mark as being laid out from the beginning
    pageSize = SizeI(0, 0);
}
Пример #5
0
EbookController::~EbookController()
{
    StopFormattingThread();
    EventMgr *evtMgr = ctrls->mainWnd->evtMgr;
    // we must manually disconnect all events becuase evtMgr is
    // destroyed after EbookController, and EbookController destructor
    // will disconnect slots without deleting them, causing leaks
    // TODO: this seems fragile
    evtMgr->DisconnectEvents(this);
    CloseCurrentDocument();
}
Пример #6
0
EbookController::~EbookController()
{
    StopFormattingThread();
    EventMgr *evtMgr = ctrls->mainWnd->evtMgr;
    // we must manually disconnect all events becuase evtMgr is
    // destroyed after EbookController, and EbookController destructor
    // will disconnect slots without deleting them, causing leaks
    // TODO: this seems fragile
    EnableMessageHandling(false);
    CloseCurrentDocument();
    DestroyEbookControls(ctrls);
    delete pageAnchorIds;
    delete pageAnchorIdxs;
}
void EbookController::TriggerBookFormatting()
{
    Size s = ctrls->page->GetDrawableSize();
    SizeI size(s.Width, s.Height);
    if (size.IsEmpty()) {
        // we haven't been sized yet
        return;
    }
    CrashIf(size.dx < 100 || size.dy < 40);
    if (!doc.IsEbook())
        return;

    if (pageSize == size) {
        //lf("EbookController::TriggerBookFormatting() - skipping layout because same as last size");
        return;
    }

    //lf("(%3d,%3d) EbookController::TriggerBookFormatting", dx, dy);
    pageSize = size; // set it early to prevent re-doing layout at the same size
    HtmlPage *newPage = PreserveTempPageShown();
    if (newPage) {
        CrashIf((formattingTemp.reparseIdx != 0) &&
                (formattingTemp.reparseIdx != newPage->reparseIdx));
    } else {
        CrashIf(formattingTemp.reparseIdx != 0);
    }

    StopFormattingThread();

    DeletePages(&pagesFromBeginning);
    DeletePages(&pagesFromPage);

    CrashIf(formattingTemp.pagesFromBeginning.Count() > 0);
    CrashIf(formattingTemp.pagesFromPage.Count() > 0);

    ShowPage(newPage, newPage != NULL);
    HtmlFormatterArgs *args = CreateFormatterArgsDoc(doc, size.dx, size.dy, &textAllocator);
    formattingThread = new EbookFormattingThread(doc, args, this);
    formattingThreadNo = formattingThread->GetNo();
    CrashIf(formattingTemp.reparseIdx < 0);
    CrashIf(formattingTemp.reparseIdx > (int)args->htmlStrLen);
    formattingThread->reparseIdx = formattingTemp.reparseIdx;
    formattingThread->Start();
    UpdateStatus();
}
Пример #8
0
void EbookController::HandlePagesFromEbookLayout(EbookFormattingData *ft)
{
    if (formattingThreadNo != ft->threadNo) {
        // this is a message from cancelled thread, we can disregard
        lf("EbookController::HandlePagesFromEbookLayout() thread msg discarded, curr thread: %d, sending thread: %d", formattingThreadNo, ft->threadNo);
        DeleteEbookFormattingData(ft);
        return;
    }
    //lf("EbookController::HandlePagesFromEbookLayout() %d pages, ft=0x%x", ft->pageCount, (int)ft);
    if (incomingPages) {
        for (size_t i = 0; i < ft->pageCount; i++) {
            incomingPages->Append(ft->pages[i]);
        }
        int pageNo = PageForReparsePoint(incomingPages, currPageReparseIdx);
        if (pageNo > 0) {
            Vec<HtmlPage*> *toDelete = pages;
            pages = incomingPages;
            incomingPages = nullptr;
            DeletePages(&toDelete);
            GoToPage(pageNo, false);
        }
    } else {
        CrashIf(!pages);
        for (size_t i = 0; i < ft->pageCount; i++) {
            pages->Append(ft->pages[i]);
        }
    }

    if (ft->finished) {
        CrashIf(!pages);
        StopFormattingThread();
    }
    UpdateStatus();
    // don't call DeleteEbookFormattingData since
    // ft->pages are now owned by incomingPages or pages
    delete ft;
}
void EbookController::HandleMobiLayoutDone(EbookFormattingTask *ld)
{
    if (formattingThreadNo != ld->threadNo) {
        // this is a message from cancelled thread, we can disregard
        //lf("EbookController::MobiLayout() thread msg discarded, curr thread: %d, sending thread: %d", layoutThreadNo, ld->threadNo);
        return;
    }
    //lf("EbookController::HandleMobiLayoutMsg() %d pages, ld=0x%x", ld->pageCount, (int)ld);
    HtmlPage *pageToShow = NULL;

    if (!ld->fromBeginning) {
        // if this is the first page sent, we're currently showing a page
        // formatted for old window size. Replace that page with new page
        if (0 == formattingTemp.pagesFromPage.Count()) {
            CrashIf(0 == ld->pageCount);
            pageToShow = ld->pages[0];
        }
        formattingTemp.pagesFromPage.Append(ld->pages, ld->pageCount);
        if (pageToShow) {
            CrashIf(pageToShow->reparseIdx != pageShown->reparseIdx);
            ShowPage(pageToShow, false);
        }
        //lf("Got %d pages from page, total %d", ld->pageCount, formattingTemp.pagesFromPage.Count());
        //UpdateStatus();
        return;
    }

    // we're showing pages from the beginning
    if (-1 != startReparseIdx) {
        // we're formatting a book for which we need to restore
        // page from previous session
        CrashIf(formattingTemp.reparseIdx != 0);
        for (size_t i = 0; i < ld->pageCount; i++) {
            HtmlPage *pd = ld->pages[i];
            if (pd->reparseIdx == startReparseIdx) {
                pageToShow = pd;
            } else if (pd->reparseIdx >= startReparseIdx) {
                // this is the first page whose reparseIdx is greater than
                // the one we're looking for, so previous page has the data
                if (i > 0) {
                    pageToShow = ld->pages[i];
                    //lf("showing page %d", i);
                } else {
                    if (0 == formattingTemp.pagesFromBeginning.Count()) {
                        pageToShow = ld->pages[0];
                    } else {
                        size_t pageNo = formattingTemp.pagesFromBeginning.Count() - 1;
                        //lf("showing page %d from formattingTemp.pagesFromBeginning", (int)pageNo);
                        pageToShow = formattingTemp.pagesFromBeginning.At(pageNo);
                    }
                }
            }
            if (pageToShow) {
                startReparseIdx = -1;
                break;
            }
        }
    } else {
        if (0 == formattingTemp.pagesFromBeginning.Count()) {
            CrashIf(0 == ld->pageCount);
            pageToShow = ld->pages[0];
            //lf("showing ld->pages[0], pageCount = %d", ld->pageCount);
        }
    }

    formattingTemp.pagesFromBeginning.Append(ld->pages, ld->pageCount);
    //lf("Got %d pages from beginning, total %d", ld->pageCount, formattingTemp.pagesFromBeginning.Count());

    if (0 == formattingTemp.reparseIdx) {
        // if we're starting from the beginning, show the first page as
        // quickly as we can
        if (pageToShow)
            ShowPage(pageToShow, false);
    }

    if (ld->finished) {
        CrashIf(pagesFromBeginning || pagesFromPage);
        pagesFromBeginning = new Vec<HtmlPage*>();
        HtmlPage **pages = formattingTemp.pagesFromBeginning.LendData();
        size_t pageCount =  formattingTemp.pagesFromBeginning.Count();
        pagesFromBeginning->Append(pages, pageCount);
        formattingTemp.pagesFromBeginning.Reset();

        pageCount =  formattingTemp.pagesFromPage.Count();
        if (pageCount > 0) {
            pages = formattingTemp.pagesFromPage.LendData();
            pagesFromPage = new Vec<HtmlPage*>();
            pagesFromPage->Append(pages, pageCount);
            formattingTemp.pagesFromPage.Reset();
        }
        StopFormattingThread();
    }
    UpdateStatus();
}