NS_ASSERTION(aPresContext, "Pointer is null!"); NS_ASSERTION(aPrintSettings, "Pointer is null!"); NS_ASSERTION(aPO, "Pointer is null!");
NS_ASSERTION(aPresContext,   "aPresContext is null!"); NS_ASSERTION(aPrintSettings, "aPrintSettings is null!"); NS_ASSERTION(aPO,            "aPO is null!"); NS_ASSERTION(mPageSeqFrame,  "mPageSeqFrame is null!"); NS_ASSERTION(mPrt,           "mPrt is null!");    if (!mPrt || !aPresContext || !aPrintSettings || !aPO || !mPageSeqFrame) { ShowPrintErrorDialog(NS_ERROR_FAILURE); return PR_TRUE; }
DocumentViewerImpl::PrintPage(nsIPresContext*   aPresContext,                              nsIPrintSettings* aPrintSettings,                              PrintObject*      aPO,                              PRBool&           aInRange){  NS_ASSERTION(aPresContext, "Pointer is null!");  NS_ASSERTION(aPrintSettings, "Pointer is null!");  NS_ASSERTION(aPO, "Pointer is null!");  PRINT_DEBUG_MSG1("-----------------------------------\n");  PRINT_DEBUG_MSG3("------ In DV::PrintPage PO: %p (%s)\n", aPO, gFrameTypesStr[aPO->mFrameType]);  PRBool isCancelled = PR_FALSE;  // Check setting to see if someone request it be cancelled (programatically)  aPrintSettings->GetIsCancelled(&isCancelled);  if (!isCancelled) {    // If not, see if the user has cancelled it    if (mPrt->mPrintProgress) {      mPrt->mPrintProgress->GetProcessCanceledByUser(&isCancelled);    }  }  // DO NOT allow the print job to be cancelled if it is Print FrameAsIs  // because it is only printing one page.  if (isCancelled) {    if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) {      aPrintSettings->SetIsCancelled(PR_FALSE);    } else {      aPrintSettings->SetIsCancelled(PR_TRUE);      return PR_TRUE;    }  }  PRInt32 pageNum;  PRInt32 curPage;  PRInt32 endPage;  mPageSeqFrame->GetCurrentPageNum(&pageNum);  PRBool donePrinting = PR_FALSE;  PRBool isDoingPrintRange;  mPageSeqFrame->IsDoingPrintRange(&isDoingPrintRange);  if (isDoingPrintRange) {    PRInt32 fromPage;    PRInt32 toPage;    PRInt32 numPages;    mPageSeqFrame->GetPrintRange(&fromPage, &toPage);    mPageSeqFrame->GetNumPages(&numPages);    if (fromPage > numPages) {      return PR_TRUE;    }    if (toPage > numPages) {      toPage = numPages;    }    PRINT_DEBUG_MSG4("****** Printing Page %d printing from %d to page %d\n", pageNum, fromPage, toPage);    donePrinting = pageNum >= toPage;    aInRange = pageNum >= fromPage && pageNum <= toPage;    PRInt32 pageInc = pageNum - fromPage + 1;    curPage = pageInc >= 0?pageInc+1:0;    endPage = (toPage - fromPage)+1;  } else {    PRInt32 numPages;    mPageSeqFrame->GetNumPages(&numPages);    PRINT_DEBUG_MSG3("****** Printing Page %d of %d page(s)\n", pageNum, numPages);    donePrinting = pageNum >= numPages;    curPage = pageNum+1;    endPage = numPages;    aInRange = PR_TRUE;  }  // NOTE: mPrt->mPrintFrameType gets set to  "kFramesAsIs" when a  // plain document contains IFrames, so we need to override that case here  if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {    DoProgressForSeparateFrames();  } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs ||              mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintObject) {    PrintData::DoOnProgressChange(mPrt->mPrintProgressListeners, curPage, endPage);  }  // Set Clip when Printing "AsIs" or   // when printing an IFrame for SelectedFrame or EachFrame  PRBool setClip = PR_FALSE;  switch (mPrt->mPrintFrameType) {    case nsIPrintSettings::kFramesAsIs:      setClip = PR_TRUE;      break;    case nsIPrintSettings::kSelectedFrame:      if (aPO->mPrintAsIs) {        if (aPO->mFrameType == eIFrame) {          setClip = aPO != mPrt->mSelectedPO;        }      }      break;    case nsIPrintSettings::kEachFrameSep:      if (aPO->mPrintAsIs) {        if (aPO->mFrameType == eIFrame) {          setClip = PR_TRUE;        }      }      break;  } //switch   if (setClip) {    // Always set the clip x,y to zero because it isn't going to have any margins    aPO->mClipRect.x = 0;    aPO->mClipRect.y = 0;    mPageSeqFrame->SetClipRect(aPO->mPresContext, &aPO->mClipRect);  }  // Print the Page  // if a print job was cancelled externally, an EndPage or BeginPage may  // fail and the failure is passed back here.  // Returning PR_TRUE means we are done printing.  //  // When rv == NS_ERROR_ABORT, it means we want out of the   // print job without displaying any error messages  nsresult rv = mPageSeqFrame->PrintNextPage(aPresContext);  if (NS_FAILED(rv)) {    if (rv != NS_ERROR_ABORT) {      ShowPrintErrorDialog(rv);      mPrt->mIsAborted = PR_TRUE;    }    return PR_TRUE;  }                  // Now see if any of the SubDocs are on this page  if (aPO->mPrintAsIs) {    nsIPageSequenceFrame * curPageSeq = mPageSeqFrame;    aPO->mHasBeenPrinted = PR_TRUE;    PRInt32 cnt = aPO->mKids.Count();    for (PRInt32 i=0;i<cnt;i++) {      PrintObject* po = (PrintObject*)aPO->mKids[i];      NS_ASSERTION(po, "PrintObject can't be null!");      if (po->IsPrintable()) {        // Now verify that SubDoc's PageNum matches the        // page num of it's parent doc        curPageSeq->GetCurrentPageNum(&pageNum);        nsIFrame* fr;        CallQueryInterface(curPageSeq, &fr);        if (fr == po->mSeqFrame && pageNum == po->mPageNum) {          PRBool donePrintingSubDoc;          DoPrint(po, PR_TRUE, donePrintingSubDoc); // synchronous printing, it changes the value mPageSeqFrame          po->mHasBeenPrinted = PR_TRUE;        }      }    } // while    mPageSeqFrame = curPageSeq;    if (aPO->mParent == nsnull ||        (aPO->mParent != nsnull && !aPO->mParent->mPrintAsIs && aPO->mPrintAsIs)) {      mPageSeqFrame->DoPageEnd(aPresContext);    }    // XXX this is because PrintAsIs for FrameSets reflows to two pages    // not sure why, but this needs to be fixed.    if (aPO->mFrameType == eFrameSet && mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) {      return PR_TRUE;    }  }  return donePrinting;}