home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / eikon / pdfpageview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  18.2 KB  |  698 lines

  1. // CPdfPageView.cpp
  2. //
  3. // Copyright 1999 Sander van der Wal
  4. //
  5. // $Id: pdfpageview.cpp 1.2 2000-09-25 21:00:59+02 svdwal Exp svdwal $
  6. //
  7. // $Log: pdfpageview.cpp $
  8. // Revision 1.2  2000-09-25 21:00:59+02  svdwal
  9. // Profile macro's removed
  10. //
  11. // Revision 1.1  2000-09-17 13:18:13+02  svdwal
  12. // Initial checkin
  13. //
  14.  
  15. #include "PdfPageView.h"
  16.  
  17. // CONE
  18. #ifndef __COEMAIN_H__
  19. #include <coemain.h>
  20. #endif
  21.  
  22. // EIKON
  23. #ifndef __EIKENV_H__
  24. #include <eikenv.h>
  25. #endif
  26. #ifndef __EIKMSG_H__
  27. #include <eikmsg.h>
  28. #endif
  29.  
  30. // PDF
  31. #include "Object.h"
  32. #include "Catalog.h"
  33. #include "Page.h"
  34. #include "XRef.h"
  35. #include "PDFDoc.h"
  36. #include "FontEncoding.h"
  37.  
  38. #include "PdfPageControl.h"
  39.  
  40. #include "Pdf.hrh"
  41. #include "Pdf.rsg"
  42.  
  43.  
  44. // PROFILING
  45. #include "PROFILE.h"
  46.  
  47. // Locals
  48.  
  49. // zoom factors
  50. const TInt CPdfPageView::KZoomPage = -1;
  51. const TInt CPdfPageView::KZoomWidth= -2;
  52.  
  53. static inline TInt round(double x) { return TInt(x+0.5); }
  54.  
  55.  
  56. //////////////////////////////////////////////////////////////////////////////
  57. //
  58. // TPdfPageViewLayout
  59. //
  60. // Calculates and contains the positions and sizes of the control and scrolbars
  61. //
  62. //////////////////////////////////////////////////////////////////////////////
  63. TPdfPageViewLayout::TPdfPageViewLayout()
  64. : iControlRect()
  65. {}
  66.  
  67.  
  68. TPdfPageViewLayout::TPdfPageViewLayout(const TRect& aParentRect, const TSize& aChildSize, TInt aShowHBar, TInt aShowVBar)
  69. {
  70.   iVisArea = aParentRect.Size();
  71.   
  72.   // first determine which scrollbars we need.
  73.   TInt hBarHeight = 0;
  74.   TInt vBarWidth = 0;
  75.  
  76.   if (aShowHBar == 0)
  77.     iShowHBar = EFalse;
  78.   else if (aShowHBar == 1)
  79.     iShowHBar = ETrue;
  80.   else // auto: we need a horizontal bar if the bitmap does not fit the view width
  81.     iShowHBar = (aChildSize.iWidth > iVisArea.iWidth);
  82.   if (iShowHBar)
  83.     hBarHeight = CEikScrollBar::EScrollbarWidth;
  84.  
  85.   if (aShowVBar == 0)
  86.     iShowVBar = EFalse;
  87.   else if (aShowHBar == 1)
  88.     iShowVBar = ETrue;
  89.   else // auto: we need a vertical bar if the bitmap does not fit the view height
  90.     iShowVBar = (aChildSize.iHeight > iVisArea.iHeight);
  91.   if (iShowVBar)
  92.     vBarWidth = CEikScrollBar::EScrollbarWidth;
  93.   
  94.   iVisArea.iWidth -= vBarWidth;
  95.   iVisArea.iHeight-= hBarHeight;
  96.  
  97.   // calculate position and size of the control
  98.  
  99.   // if the width of the bitmap is small enough to fit, center it
  100.   if (aChildSize.iWidth < iVisArea.iWidth) {
  101.     iControlRect.iTl.iX =(iVisArea.iWidth - aChildSize.iWidth)/2;
  102.     iControlRect.SetWidth(aChildSize.iWidth);
  103.   }
  104.   else {
  105.     iControlRect.iTl.iX = 0;
  106.     iControlRect.SetWidth(iVisArea.iWidth);
  107.   }
  108.  
  109.   // if the height of the bitmap is small enough to fit, center it
  110.   if (aChildSize.iHeight < iVisArea.iHeight) {
  111.     iControlRect.iTl.iY =(iVisArea.iHeight - aChildSize.iHeight)/2;
  112.     iControlRect.SetHeight(aChildSize.iHeight);
  113.   }
  114.   else {
  115.     iControlRect.iTl.iY = 0;
  116.     iControlRect.SetHeight(iVisArea.iHeight);
  117.   }
  118.  
  119.   iHBarPos = iVisArea.AsPoint();
  120.   iHBarPos.iX  = 0; 
  121.   iHBarLength  = Max(iControlRect.Size().iWidth, iVisArea.iWidth);
  122.  
  123.   iVBarPos = iVisArea.AsPoint();
  124.   iVBarPos.iY  = 0;
  125.   iVBarLength  = Max(iControlRect.Size().iHeight, iVisArea.iHeight);
  126. }
  127.  
  128.  
  129. TPdfPageViewLayout::TPdfPageViewLayout(const TPdfPageViewLayout& aLayout)
  130. : iControlRect(aLayout.iControlRect), iShowHBar(aLayout.iShowHBar), iShowVBar(aLayout.iShowVBar)
  131. {}
  132.  
  133.  
  134. TBool operator!=(const TPdfPageViewLayout& x, const TPdfPageViewLayout& y)
  135. {
  136.   return (x.iControlRect!=y.iControlRect ||
  137.           x.iShowHBar!=y.iShowHBar ||
  138.           x.iShowVBar!=y.iShowVBar); 
  139. }
  140.  
  141.  
  142. //////////////////////////////////////////////////////////////////////////////
  143. //
  144. // CPdfPageView
  145. //
  146. //////////////////////////////////////////////////////////////////////////////
  147. void CPdfPageView::ConstructL(const TRect& aRect)
  148. {
  149.   CreateWindowL();
  150.   Window().SetShadowDisabled(ETrue);
  151.   EnableDragEvents();
  152.  
  153.   iContext=this;
  154.   iBrushStyle=CGraphicsContext::ESolidBrush;
  155.   iBrushColor=KRgbGray;
  156.   
  157.   SetRectL(aRect);
  158.  
  159.   ActivateL();
  160. }
  161.  
  162.  
  163. CPdfPageView::~CPdfPageView()
  164. {
  165.   delete iControl;
  166.   delete iHBar;
  167.   delete iVBar;
  168. }
  169.  
  170.  
  171. void CPdfPageView::SetCmdHandler(MPdfPageViewCmdHandler* aCmdHandler)
  172. {
  173.   iCmdHandler = aCmdHandler;
  174. }
  175.  
  176.  
  177. void CPdfPageView::SetModelL(PDFDoc* aDoc)
  178. {
  179.   // clear up old model stuff
  180.   DeleteComponentControls();
  181.   
  182.   // create new model stuff
  183.   iDoc=aDoc;
  184.   if (iDoc)
  185.     CreateComponentControlsL();
  186.   else
  187.     DrawNow();
  188. }
  189.  
  190.  
  191. void CPdfPageView::SetModelSize(TSize aSizeInPixels)
  192. {
  193.   iHBarModel.iScrollSpan = aSizeInPixels.iWidth;
  194.   iVBarModel.iScrollSpan = aSizeInPixels.iHeight;
  195.  
  196.   SetSpanSize();
  197. }
  198.  
  199.  
  200. void CPdfPageView::SetSpanSize()
  201. {
  202.   TSize vwSize = iLayout.ControlRect().Size();
  203.  
  204.   iHBarModel.iThumbSpan = Min(vwSize.iWidth, iHBarModel.iScrollSpan);
  205.   iHBarModel.CheckBounds();
  206.  
  207.   iVBarModel.iThumbSpan =  Min(vwSize.iHeight, iVBarModel.iScrollSpan);
  208.   iVBarModel.CheckBounds();
  209.  
  210.   if (iControl)
  211.     iControl->SetVisAreaOffset(ScrollOffset());
  212. }
  213.  
  214.  
  215. void CPdfPageView::SetScrollOffset(const TPoint& aScrollOffset)
  216. {
  217.   TBool doHBar = iHBarModel.iThumbPosition != aScrollOffset.iX;
  218.   if (doHBar) {
  219.     iHBarModel.iThumbPosition = aScrollOffset.iX;
  220.     iHBarModel.CheckBounds();
  221.     if (iHBar)
  222.       iHBar->SetModelThumbPosition(iHBarModel.iThumbPosition);
  223.   }
  224.  
  225.   TBool doVBar = iVBarModel.iThumbPosition != aScrollOffset.iY;
  226.   if (doVBar)  {
  227.     iVBarModel.iThumbPosition = aScrollOffset.iY;
  228.     iVBarModel.CheckBounds();
  229.     if (iVBar)
  230.       iVBar->SetModelThumbPosition(iVBarModel.iThumbPosition);
  231.   }
  232.  
  233.   if (iControl && (doHBar || doVBar)) {
  234.     iControl->SetVisAreaOffset(ScrollOffset());
  235.     iControl->DrawNow();
  236.   }
  237. }
  238.  
  239.  
  240. TPoint CPdfPageView::ScrollOffset() const
  241. {
  242.   return TPoint(iHBarModel.iThumbPosition, iVBarModel.iThumbPosition);
  243. }
  244.  
  245.  
  246. void CPdfPageView::CreateComponentControlsL()
  247. {
  248.   iControl=new(ELeave) CPdfPageControl(iDoc);
  249.   iControl->ConstructL();
  250.   iControl->SetContainerWindowL(*this);
  251.  
  252.   iLayout = TPdfPageViewLayout(Size(), iControl->PageSizeInPixels(), iHBarVisibility, iVBarVisibility);
  253.   iHBarModel.iThumbPosition = 0;
  254.   iVBarModel.iThumbPosition = 0;
  255.   SetSpanSize();
  256.   iControl->SetRectL(iLayout.ControlRect());
  257.   iControl->ActivateL();
  258.   
  259.   if (iLayout.ShowHBar())
  260.     iHBar = CreateScrollBarL(CEikScrollBar::EHorizontal, iLayout.HBarPos(), iLayout.HBarLength(), &iHBarModel);
  261.  
  262.   if (iLayout.ShowVBar())
  263.     iVBar = CreateScrollBarL(CEikScrollBar::EVertical, iLayout.VBarPos(), iLayout.VBarLength(), &iVBarModel);
  264.  
  265.   DrawNow();
  266. }
  267.  
  268.  
  269. void CPdfPageView::UpdateComponentControlsL()
  270. {
  271.   // set the controls to the (possibly) new layout
  272.   SetModelSize(iControl->PageSizeInPixels());
  273.  
  274.   // remember the current layout
  275.   TPdfPageViewLayout oldLayout = iLayout;
  276.   
  277.   iLayout = TPdfPageViewLayout(Size(), iControl->PageSizeInPixels(), iHBarVisibility, iVBarVisibility);
  278.   SetSpanSize();
  279.   iControl->SetRectL(iLayout.ControlRect());
  280.  
  281.   // place the scrollbars
  282.  
  283.   if ((!iHBar && iLayout.ShowHBar()) || 
  284.       oldLayout.HBarLength()!= iLayout.HBarLength()||
  285.       oldLayout.HBarPos()   != iLayout.HBarPos()   ) {
  286.     if (!iLayout.ShowHBar()){
  287.       delete iHBar;
  288.       iHBar = 0;
  289.     }
  290.     else if (!iHBar)
  291.       iHBar = CreateScrollBarL(CEikScrollBar::EHorizontal, iLayout.HBarPos(), iLayout.HBarLength(), &iHBarModel);
  292.     else {
  293.       if (oldLayout.HBarPos() != iLayout.HBarPos())
  294.         iHBar->SetPosition(iLayout.HBarPos());
  295.       if (oldLayout.HBarLength()!= iLayout.HBarLength())
  296.         iHBar->SetLengthAndModelL(iLayout.HBarLength(), &iHBarModel);
  297.     }   
  298.   }
  299.   if ((!iVBar && iLayout.ShowVBar()) || 
  300.       oldLayout.VBarLength()!= iLayout.VBarLength()||
  301.       oldLayout.VBarPos()   != iLayout.VBarPos()   ) {
  302.     if (!iLayout.ShowVBar()) {
  303.       delete iVBar;
  304.       iVBar = 0;
  305.     }
  306.     else if (!iVBar)
  307.       iVBar = CreateScrollBarL(CEikScrollBar::EVertical, iLayout.VBarPos(), iLayout.VBarLength(), &iVBarModel);
  308.     else {
  309.       if (oldLayout.VBarPos() != iLayout.VBarPos())
  310.         iVBar->SetPosition(iLayout.VBarPos());
  311.       if (oldLayout.VBarLength()!= iLayout.VBarLength())
  312.         iVBar->SetLengthAndModelL(iLayout.VBarLength(), &iVBarModel);
  313.     }
  314.   }
  315.   
  316.   if (oldLayout.ControlRect() != iLayout.ControlRect())
  317.     DrawDeferred(); // to clear up old parts of the bitmap and/or scrollbars
  318. }
  319.  
  320.  
  321. void CPdfPageView::DeleteComponentControls()
  322. {
  323.   delete iControl;
  324.   iControl = 0;
  325.  
  326.   delete iHBar;
  327.   iHBar = 0;
  328.   
  329.   delete iVBar;
  330.   iVBar = 0;
  331. }
  332.  
  333.  
  334. CEikScrollBar* CPdfPageView::CreateScrollBarL(CEikScrollBar::TOrientation aOrientation, const TPoint& aPos, TInt aLength, TEikScrollBarModel* aModel)
  335. {
  336.   TInt flags = 0;
  337.     
  338.   CEikScrollBar* bar = new(ELeave) CEikScrollBar;
  339.   CleanupStack::PushL(bar);
  340.   bar->ConstructL(this, this, aOrientation, 0, flags);
  341.   bar->SetPosition(aPos);
  342.   bar->SetLengthAndModelL(aLength, aModel);
  343.   bar->ActivateL();
  344.   CleanupStack::Pop();
  345.   return bar;
  346. }
  347.  
  348.  
  349. void CPdfPageView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
  350. {
  351.   if (aPointerEvent.iType == TPointerEvent::EButton1Down &&
  352.       iControl &&
  353.       iControl->Rect().Contains(aPointerEvent.iPosition)) {
  354.     
  355.     TReal usrX, usrY;
  356.     iControl->CvtDevToUser(aPointerEvent.iPosition + ScrollOffset(), usrX, usrY);
  357.  
  358.     iCmdHandler->CmdTapL(TPoint(round(usrX*KTwipsPerPoint), round(usrY*KTwipsPerPoint)));
  359.   }
  360. }
  361.  
  362.  
  363. TKeyResponse CPdfPageView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
  364. {
  365.   TKeyResponse res = EKeyWasConsumed;
  366.   if (aType == EEventKey) {
  367.     switch (aKeyEvent.iCode) {
  368.     case EKeyEscape:
  369.       iCmdHandler->CmdCancelL();
  370.       break;
  371.  
  372.     case EKeyHome:
  373.       if (aKeyEvent.iModifiers & EModifierCtrl)
  374.         iCmdHandler->CmdFirstPageL();
  375.       else
  376.         HandleLeftRightMove(-3);
  377.       break;
  378.       
  379.     case EKeyEnd:
  380.       if (aKeyEvent.iModifiers & EModifierCtrl)
  381.         iCmdHandler->CmdLastPageL();
  382.       else
  383.         HandleLeftRightMove(3);
  384.       break;
  385.       
  386.     case EKeyPageUp:
  387.       if ((aKeyEvent.iModifiers & EModifierCtrl) ||
  388.           (iRotate ==   0 && iVBarModel.iThumbPosition==0) ||
  389.           (iRotate ==  90 && iHBarModel.iThumbPosition>=iHBarModel.MaxThumbPos()) ||
  390.           (iRotate == 180 && iVBarModel.iThumbPosition>=iVBarModel.MaxThumbPos()) ||
  391.           (iRotate == 270 && iHBarModel.iThumbPosition==0))
  392.         iCmdHandler->CmdPrevPageL(EFalse); 
  393.       else
  394.         HandlePrevNextMove(-2);
  395.       break;
  396.       
  397.     case ' ':
  398.     case EKeyPageDown:
  399.       if ((aKeyEvent.iCode == EKeyPageDown) && (aKeyEvent.iModifiers & EModifierCtrl) ||
  400.           (iRotate ==   0 && iVBarModel.iThumbPosition>=iVBarModel.MaxThumbPos()) ||
  401.           (iRotate ==  90 && iHBarModel.iThumbPosition==0) ||
  402.           (iRotate == 180 && iVBarModel.iThumbPosition==0) ||
  403.           (iRotate == 270 && iHBarModel.iThumbPosition>=iHBarModel.MaxThumbPos()))
  404.         iCmdHandler->CmdNextPageL();
  405.       else
  406.         HandlePrevNextMove(2);        
  407.       break;
  408.     
  409.     case EKeyLeftArrow: 
  410.       HandleLeftRightMove(aKeyEvent.iModifiers & EModifierCtrl? -2:-1);
  411.       break;
  412.     
  413.     case EKeyRightArrow:
  414.       HandleLeftRightMove(aKeyEvent.iModifiers & EModifierCtrl? 2: 1);
  415.       break;
  416.     
  417.     case EKeyUpArrow:
  418.       HandleUpDownMove(aKeyEvent.iModifiers & EModifierCtrl ? -2:-1);
  419.       break;
  420.     
  421.     case EKeyDownArrow:
  422.       HandleUpDownMove(aKeyEvent.iModifiers & EModifierCtrl ? 2: 1);
  423.       break;
  424.     
  425.     default:
  426.       res = EKeyWasNotConsumed;
  427.       break;
  428.     } // switch
  429.   }
  430.   else
  431.     res = EKeyWasNotConsumed;
  432.   return res;
  433. }
  434.  
  435.  
  436. void CPdfPageView::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEvent)
  437. {
  438.   switch (aEvent) {
  439.   case EEikScrollEnd:       HandleLeftRightMove( 3); break;
  440.   case EEikScrollPageRight: HandleLeftRightMove( 2); break;
  441.   case EEikScrollRight:     HandleLeftRightMove( 1); break;
  442.   case EEikScrollLeft:      HandleLeftRightMove(-1); break;
  443.   case EEikScrollPageLeft:  HandleLeftRightMove(-2); break;
  444.   case EEikScrollHome:      HandleLeftRightMove(-3); break;
  445.  
  446.   case EEikScrollBottom:    HandleUpDownMove( 3); break;  
  447.   case EEikScrollPageDown:  HandleUpDownMove( 2); break;
  448.   case EEikScrollDown:      HandleUpDownMove( 1); break;
  449.   case EEikScrollUp:        HandleUpDownMove(-1); break;
  450.   case EEikScrollPageUp:    HandleUpDownMove(-2); break;
  451.   case EEikScrollTop:       HandleUpDownMove(-3); break;
  452.   
  453.   default:
  454.     if (aEvent & KEikScrollEventBarMask==KEikScrollEventFromHBar) {
  455.       iHBarModel = *(aScrollBar->Model());
  456.       iHBarModel.CheckBounds();
  457.     }
  458.     else  {
  459.       iVBarModel = *(aScrollBar->Model());
  460.       iVBarModel.CheckBounds();
  461.     }
  462.     if (iControl) {
  463.       iControl->SetVisAreaOffset(ScrollOffset());
  464.       iControl->DrawNow();
  465.     }
  466.     break;
  467.   }  
  468. }
  469.  
  470.  
  471. void CPdfPageView::HandlePrevNextMove(TInt aDir)
  472. {
  473.   switch (iRotate) {
  474.   case 180: aDir = -aDir; 
  475.     // falltrough
  476.   case   0: HandleUpDownMove(aDir); 
  477.     break;
  478.  
  479.   case  90: aDir = -aDir;
  480.     // fallthrough
  481.   case 270: HandleLeftRightMove(aDir); 
  482.     break;
  483.     
  484.   default:
  485.     break;  
  486.   }
  487. }
  488.  
  489.  
  490. void CPdfPageView::HandleUpDownMove(TInt aDir)
  491. {
  492.   switch (aDir) {
  493.   case -3: // top of page
  494.   case  3: // bottom of page
  495.     iVBarModel.iThumbPosition  = aDir < 0 ? 0 : iVBarModel.MaxThumbPos();
  496.     break;
  497.  
  498.   case -2: // prev part
  499.   case  2: // next part
  500.     iVBarModel.iThumbPosition += aDir * iVBarModel.iThumbSpan*9/20;
  501.     break;
  502.  
  503.   case -1: // prev line
  504.   case  1: // next line
  505.     iVBarModel.iThumbPosition += aDir * iVBarModel.iThumbSpan/20;
  506.     break;
  507.  
  508.   default:
  509.     break;
  510.   }
  511.  
  512.   iVBarModel.CheckBounds();
  513.   if (iVBar)
  514.     iVBar->SetModelThumbPosition(iVBarModel.iThumbPosition);
  515.   if (iControl) {
  516.     iControl->SetVisAreaOffset(ScrollOffset());
  517.     iControl->DrawNow();
  518.   }
  519. }
  520.  
  521.  
  522. void CPdfPageView::HandleLeftRightMove(TInt aDir)
  523. {
  524.   switch (aDir) {
  525.   case -3: // top of page
  526.   case  3: // bottom of page
  527.     iHBarModel.iThumbPosition  = aDir < 0 ? 0 : iHBarModel.MaxThumbPos();
  528.     break;
  529.  
  530.   case -2: // prev part
  531.   case  2: // next part
  532.     iHBarModel.iThumbPosition += aDir * iHBarModel.iThumbSpan/10;
  533.     break;
  534.  
  535.   case -1: // prev line
  536.   case  1: // next line
  537.     iHBarModel.iThumbPosition += aDir * iHBarModel.iThumbSpan/40;
  538.     break;
  539.  
  540.   default:
  541.     break;
  542.   }
  543.   
  544.   iHBarModel.CheckBounds();
  545.   if (iHBar) 
  546.     iHBar->SetModelThumbPosition(iHBarModel.iThumbPosition);
  547.   if (iControl) {
  548.     iControl->SetVisAreaOffset(ScrollOffset());
  549.     iControl->DrawNow();
  550.   }
  551. }
  552.  
  553.  
  554. TInt CPdfPageView::CountComponentControls() const
  555. {
  556.   return (iControl ? 1 : 0);
  557. }
  558.  
  559.  
  560. CCoeControl* CPdfPageView::ComponentControl(TInt aIndex) const
  561. {
  562.   return (aIndex == 0 ? iControl : 0);
  563. }
  564.  
  565.  
  566. void CPdfPageView::Draw(const TRect& /* aRect */) const
  567. {
  568.   CWindowGc& gc=SystemGc();
  569.   gc.SetPenStyle(CGraphicsContext::ENullPen);
  570.   gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
  571.   gc.DrawRect(Rect());
  572. }
  573.  
  574.  
  575. void CPdfPageView::SizeChangedL()
  576. {
  577.   if (iControl)
  578.     UpdateComponentControlsL();
  579. }
  580.  
  581.  
  582. void CPdfPageView::ScrollToTop()
  583. {
  584.   if (iRotate == 0 || iRotate == 180)
  585.     HandleUpDownMove(iRotate == 180 ? 3: -3);
  586.   else
  587.     HandleLeftRightMove(iRotate == 90 ? 3: -3);
  588. }
  589.  
  590.  
  591. void CPdfPageView::ScrollToBottom()
  592. {
  593.   if (iRotate == 0 || iRotate == 180)
  594.     HandleUpDownMove(iRotate == 180 ? -3 : 3);
  595.   else
  596.     HandleLeftRightMove(iRotate == 90 ? -3 : 3);
  597. }
  598.  
  599.  
  600. void CPdfPageView::StartRenderingL(TInt aPage, const TPdfPageViewMemento& aMemento)
  601. {  
  602.   SetDpi(aPage, aMemento.iZoom, aMemento.iRotate);
  603.   
  604.   iControl->StartRenderingL(aPage, iDpi, aMemento);
  605.   
  606.   // if we get here, we can update the display
  607.   iRotate = aMemento.iRotate;
  608.   UpdateComponentControlsL();
  609. }
  610.  
  611.  
  612. void CPdfPageView::CancelRendering()
  613. {
  614.   if (iControl)
  615.     iControl->CancelRendering();
  616. }
  617.  
  618.  
  619. void CPdfPageView::SetScrollBarVisibility(TInt aHBarVisibility, TInt aVBarVisibility)
  620. {
  621.   TInt oldH = iHBarVisibility;
  622.   TInt oldV = iVBarVisibility;
  623.   iHBarVisibility = aHBarVisibility;
  624.   iVBarVisibility = aVBarVisibility;
  625.   if (iHBarVisibility != oldH || iVBarVisibility != oldV)
  626.     SizeChangedL();
  627. }
  628.  
  629.  
  630. TPoint CPdfPageView::Center() const
  631. {
  632.   TPoint devCenter(ScrollOffset().iX+iLayout.HBarLength()/2,
  633.                    ScrollOffset().iY+iLayout.VBarLength()/2);
  634.  
  635.   TReal usrX, usrY;
  636.   iControl->CvtDevToUser(devCenter, usrX, usrY);
  637.  
  638.   TPoint usrPos(round(usrX*KTwipsPerPoint), round(usrY*KTwipsPerPoint));
  639.   return usrPos;
  640. }
  641.  
  642.  
  643. void CPdfPageView::SetCenter(TPoint aPosition)
  644. {
  645.   TPoint devPos;
  646.   iControl->CvtUserToDev(aPosition.iX/KTwipsPerPoint, aPosition.iY/KTwipsPerPoint, devPos);
  647.  
  648.   SetScrollOffset(TPoint(devPos.iX-iLayout.HBarLength()/2,
  649.                          devPos.iY-iLayout.VBarLength()/2));
  650. }
  651.  
  652.  
  653. void CPdfPageView::SetSelection(const TRect& aSelection)
  654. {
  655.   if (iControl) {
  656.     TRect devSel;
  657.     iControl->CvtUserToDev(aSelection.iTl.iX/KTwipsPerPoint, aSelection.iTl.iY/KTwipsPerPoint, devSel.iTl);
  658.     iControl->CvtUserToDev(aSelection.iBr.iX/KTwipsPerPoint, aSelection.iBr.iY/KTwipsPerPoint, devSel.iBr);
  659.     devSel.Normalize();
  660.     iControl->SetSelection(devSel);
  661.  
  662.     if (!devSel.IsEmpty())
  663.       SetScrollOffset(TPoint(devSel.Center().iX-iLayout.HBarLength()/2,
  664.                            devSel.Center().iY-iLayout.VBarLength()/2));
  665.   }
  666. }
  667.  
  668.  
  669. void CPdfPageView::SetDpi(TInt aPage, TInt aZoom, TInt aRotate)
  670.   // calculate the page size in dots per inch
  671.   if (aZoom == KZoomPage) {
  672.     TInt hDpi, vDpi;
  673.     if (aRotate == 90 || aRotate == 270) {
  674.       hDpi = TInt((iLayout.VisAreaWidth() /iDoc->getPageHeight(aPage))*KPointsPerInch);
  675.       vDpi = TInt((iLayout.VisAreaHeight()/iDoc->getPageWidth(aPage)) *KPointsPerInch);
  676.     } 
  677.     else {
  678.       hDpi = round((iLayout.VisAreaWidth() /iDoc->getPageWidth(aPage)) *KPointsPerInch);
  679.       vDpi = round((iLayout.VisAreaHeight()/iDoc->getPageHeight(aPage))*KPointsPerInch);
  680.     }
  681.     iDpi = (hDpi < vDpi) ? hDpi : vDpi;
  682.   }
  683.   else if (aZoom == KZoomWidth) {
  684.     if (aRotate == 90 || aRotate == 270)
  685.       iDpi = TInt(iLayout.VisAreaWidth()/iDoc->getPageHeight(aPage)*KPointsPerInch);
  686.     else
  687.       iDpi = TInt(iLayout.VisAreaWidth()/iDoc->getPageWidth(aPage) *KPointsPerInch);
  688.   } 
  689.   else
  690.     iDpi = aZoom * 72 /100;
  691. }
  692.  
  693.  
  694. TInt CPdfPageView::RealZoom()
  695.   return iDpi * 100 / 72;
  696. }