home *** CD-ROM | disk | FTP | other *** search
- // ActivePage.cpp
- //
- // Copyright 2000 Sander van der Wal. All rights reserved.
- //
- // $Id: activepage.cpp 1.3 2000-09-24 21:09:54+02 svdwal Exp svdwal $
- //
- // $Log: activepage.cpp $
- // Revision 1.3 2000-09-24 21:09:54+02 svdwal
- // Memory leak fixed
- //
- // Revision 1.2 2000-09-21 14:52:44+02 svdwal
- // Set iGfx after constructing a gfx is completed, otherwise the active object is not active and iGfx isn't destroyed
- //
- // Revision 1.1 2000-09-17 13:39:33+02 svdwal
- // Initial checkin
- //
-
- #include "ActivePage.h"
-
- // --o Pdf
- #include "Page.h"
- #include "PDFDoc.h"
- #include "Gfx.h"
-
-
- CActivePage::CActivePage(TInt aPriority, MActivePageObserver* aObserver)
- : CActive(aPriority), iObserver(aObserver)
- {}
-
-
- void CActivePage::ConstructL()
- {
- CActiveScheduler::Add(this);
- }
-
-
- CActivePage* CActivePage::NewL(TInt aPriority, MActivePageObserver* aObserver)
- {
- CActivePage* self = new(ELeave) CActivePage(aPriority, aObserver);
- CleanupStack::PushL(self);
- self->ConstructL();
- CleanupStack::Pop(); // self
- return self;
- }
-
-
- CActivePage::~CActivePage()
- {
- Cancel();
- iObj.free();
- delete iGfx;
- }
-
-
- void CActivePage::StartRenderingL(OutputDev *aOut, PDFDoc* aDoc, TInt aPage, int aDpi, int aRotate)
- {
- StopRendering();
-
- Page* p = aDoc->getCatalog()->getPage(aPage);
-
- aRotate += p->getRotate();
- if (aRotate >= 360)
- aRotate -= 360;
- else if (aRotate < 0)
- aRotate += 360;
-
- TInt err = KErrNone;
-
- RAutoObject obj;
- Gfx* gfx = new(ELeave) Gfx();
- CleanupStack::PushL(gfx);
- gfx->ConstructL(aOut, p->getNum(), p->getResourceDict(),
- aDpi,
- p->getX1(), p->getY1(), p->getX2(), p->getY2(),
- p->isCropped(),
- p->getCropX1(), p->getCropY1(), p->getCropX2(), p->getCropY2(),
- aRotate);
-
- p->getContentsL(&obj);
- if (!obj.isNull())
- gfx->StartDisplayL(&obj);
- else
- err = KErrGeneral;
-
- //
- // now the active object can be safely made active
- //
-
- // move the object to the active page
- iObj = obj;
- obj.initNull();
-
- CleanupStack::Pop(); // gfx
- iGfx = gfx;
- iNumCmds = 0;
-
- // send an event to ourselves to start running
- TRequestStatus* status = &iStatus;
- User::RequestComplete(status, err);
- SetActive();
- }
-
-
- // --o CActive
- void CActivePage::RunL()
- {
- if (iStatus != KErrNone) {
- // fault opening?
- StopRendering();
- iObserver->NotifyPageFinishedL(iStatus.Int()); // return error
- return;
- }
-
- TBool running = iGfx->StepL(iNumCmds);
- if (running) {
- TRequestStatus* status = &iStatus;
- User::RequestComplete(status, KErrNone);
- SetActive();
- }
- else {
- StopRendering();
- iObserver->NotifyPageFinishedL(KErrNone);
- }
- }
-
-
- void CActivePage::DoCancel()
- {
- StopRendering();
- }
-
-
- void CActivePage::StopRendering()
- {
- if (iGfx) {
- iGfx->StopDisplay();
- iNumCmds = 0;
- iObj.free();
- delete iGfx;
- iGfx = 0;
- }
- }
-