home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / pdf / activepage.cpp next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  3.0 KB  |  143 lines

  1. // ActivePage.cpp
  2. //
  3. // Copyright 2000 Sander van der Wal. All rights reserved.
  4. //
  5. // $Id: activepage.cpp 1.3 2000-09-24 21:09:54+02 svdwal Exp svdwal $
  6. //
  7. // $Log: activepage.cpp $
  8. // Revision 1.3  2000-09-24 21:09:54+02  svdwal
  9. // Memory leak fixed
  10. //
  11. // Revision 1.2  2000-09-21 14:52:44+02  svdwal
  12. // Set iGfx after constructing a gfx is completed, otherwise the active object is not active and iGfx isn't destroyed
  13. //
  14. // Revision 1.1  2000-09-17 13:39:33+02  svdwal
  15. // Initial checkin
  16. //
  17.  
  18. #include "ActivePage.h"
  19.  
  20. // --o Pdf
  21. #include "Page.h"
  22. #include "PDFDoc.h"
  23. #include "Gfx.h"
  24.  
  25.  
  26. CActivePage::CActivePage(TInt aPriority, MActivePageObserver* aObserver)
  27. : CActive(aPriority), iObserver(aObserver)
  28. {}
  29.  
  30.  
  31. void CActivePage::ConstructL()
  32. {
  33.   CActiveScheduler::Add(this);
  34. }
  35.  
  36.  
  37. CActivePage* CActivePage::NewL(TInt aPriority, MActivePageObserver* aObserver)
  38. {
  39.   CActivePage* self = new(ELeave) CActivePage(aPriority, aObserver);
  40.   CleanupStack::PushL(self);
  41.   self->ConstructL();
  42.   CleanupStack::Pop(); // self
  43.   return self;
  44. }
  45.  
  46.  
  47. CActivePage::~CActivePage()
  48. {
  49.   Cancel();
  50.   iObj.free();
  51.   delete iGfx;
  52. }
  53.  
  54.  
  55. void CActivePage::StartRenderingL(OutputDev *aOut, PDFDoc* aDoc, TInt aPage, int aDpi, int aRotate)
  56. {
  57.   StopRendering();
  58.  
  59.   Page* p = aDoc->getCatalog()->getPage(aPage);
  60.   
  61.   aRotate += p->getRotate();
  62.   if (aRotate >= 360)
  63.     aRotate -= 360;
  64.   else if (aRotate < 0)
  65.     aRotate += 360;
  66.  
  67.   TInt err = KErrNone;
  68.  
  69.   RAutoObject obj;
  70.   Gfx* gfx = new(ELeave) Gfx();
  71.   CleanupStack::PushL(gfx);
  72.   gfx->ConstructL(aOut, p->getNum(), p->getResourceDict(), 
  73.                   aDpi, 
  74.                   p->getX1(), p->getY1(), p->getX2(), p->getY2(), 
  75.                   p->isCropped(),
  76.                   p->getCropX1(), p->getCropY1(), p->getCropX2(), p->getCropY2(),
  77.                   aRotate);
  78.  
  79.   p->getContentsL(&obj);
  80.   if (!obj.isNull())  
  81.     gfx->StartDisplayL(&obj);
  82.   else
  83.     err = KErrGeneral;
  84.  
  85.   //
  86.   // now the active object can be safely made active
  87.   //
  88.  
  89.   // move the object to the active page
  90.   iObj = obj;
  91.   obj.initNull();
  92.   
  93.   CleanupStack::Pop(); // gfx
  94.   iGfx = gfx;
  95.   iNumCmds = 0;
  96.  
  97.   // send an event to ourselves to start running
  98.   TRequestStatus* status = &iStatus;
  99.   User::RequestComplete(status, err);
  100.   SetActive();
  101. }
  102.  
  103.  
  104. // --o CActive
  105. void CActivePage::RunL()
  106. {
  107.   if (iStatus != KErrNone) {
  108.     // fault opening?
  109.     StopRendering();
  110.     iObserver->NotifyPageFinishedL(iStatus.Int()); // return error
  111.     return;
  112.   }
  113.  
  114.   TBool running = iGfx->StepL(iNumCmds);
  115.   if (running) {
  116.     TRequestStatus* status = &iStatus;
  117.     User::RequestComplete(status, KErrNone);
  118.     SetActive();
  119.   }
  120.   else {
  121.     StopRendering();
  122.     iObserver->NotifyPageFinishedL(KErrNone);
  123.   }
  124. }
  125.  
  126.  
  127. void CActivePage::DoCancel()
  128. {
  129.   StopRendering();
  130. }
  131.  
  132.  
  133. void CActivePage::StopRendering()
  134. {
  135.   if (iGfx) {
  136.     iGfx->StopDisplay();
  137.     iNumCmds = 0;
  138.     iObj.free();
  139.     delete iGfx;
  140.     iGfx = 0;
  141.   }
  142. }
  143.