void CLabelView::OnDraw(PrintContext* pc) { CPmwDoc* pDoc = GetDocument(); DWORD dwPage = pDoc->CurrentPageIndex(); // Verify we are doing a normal page. if (dwPage != 0 && dwPage != 1) { // Non-standard page (like the "key" page). Defer to the base class. CPmwView::OnDraw(pc); return; } /* // Save the scaled_source x0 and y0 in the printer rc since we will be // changing them. */ PBOX SourcePbox = printer_rc.source_pbox; PPNT SourceOrigin; SourceOrigin.x = printer_rc.scaled_source_x0; SourceOrigin.y = printer_rc.scaled_source_y0; /* Get the document to work with. */ int nPrintOrientation = pDoc->get_orientation(); BOOL fLandscape = (nPrintOrientation == LANDSCAPE); /* Get the App and its info. */ CPmwApp* pApp = GET_PMWAPP(); CPaperInfo* pPaperInfo = pApp->GetPaperInfo(nPrintOrientation); CPrinterInfo* pPrinterInfo = pApp->GetPrinterInfo(nPrintOrientation); CFixedRect PaperPhysicalMargins = pPaperInfo->PhysicalMargins(); /* Get the paper info. */ CPaperInfo* pLabelInfo = pDoc->GetPaperInfo(); CFixedRect Margins = pLabelInfo->Margins(); // If this is landscape, rotate the margins correctly. pPrinterInfo->OrientRect(&Margins); /* Get the label print dialog. */ CLabelPrintDialog* pDialog = (CLabelPrintDialog*)pc->m_pPD; /* Get the name list. */ CStdMacroServer* pMacroServer = pDoc->GetMacroServer(); NameListRecord* pNameList = pMacroServer->GetNameList(); /* Compute the number of slots we need to print. */ int nSlot = pc->m_nStartingLabel; int nSlots = pLabelInfo->Slots(); /* Run through all the slots. */ while (nSlot < nSlots && !UserAbort) { /* // See if the name we want is the one that's bound. */ if (pc->m_nBoundName != pc->m_nCurrentName) { pc->m_nBoundName = pc->m_nCurrentName; ASSERT(pc->m_pCursor != NULL); if (pc->m_pCursor != NULL) { pMacroServer->BindToRecord(pc->m_pCursor, pNameList->Name(pc->m_nBoundName)); pDoc->ReflowMacros(); } } /* // Setup the parameters for this slot so that we will draw in the correct // spot on the page. */ ASSERT(dwPage == 0 || dwPage == 1); CFixedRect SlotBounds = pLabelInfo->SlotBounds(nSlot); BOOL fBack = (dwPage == 1); CFixedPoint Dims = pLabelInfo->PaperDims(); CFixed lLeft = SlotBounds.Left; CFixed lTop = SlotBounds.Top; CFixed lWidth = SlotBounds.Width(); CFixed lHeight = SlotBounds.Height(); if (fLandscape) { switch (pPrinterInfo->Orientation()) { case 90: { // 90 degree rotation (like lasers) SlotBounds.Left = Dims.y - (lTop + lHeight); SlotBounds.Top = lLeft; break; } // case -1: // case 270: default: { // 270 degree rotation (like dot-matrix) SlotBounds.Left = lTop; SlotBounds.Top = Dims.x - (lLeft + lWidth); break; } } if (fBack) { // We are printing the back side. Reverse the slot. SlotBounds.Left = Dims.y - (SlotBounds.Left + lHeight); } SlotBounds.Right = SlotBounds.Left + lHeight; SlotBounds.Bottom = SlotBounds.Top + lWidth; } else { // Portrait. if (fBack) { // We are printing the back side. Reverse the slot. SlotBounds.Left = Dims.x - SlotBounds.Right; SlotBounds.Right = SlotBounds.Left + lWidth; } } CFixedPoint Org; Org.x = Margins.Left-PaperPhysicalMargins.Left; Org.y = Margins.Top-PaperPhysicalMargins.Top; if (fLandscape) { /* Printout is landscape. Reverse the origins. */ CFixed t = Org.x; Org.x = Org.y; Org.y = t; } PPNT Delta; Delta.x = MulFixed(SlotBounds.Left + Org.x, PAGE_RESOLUTION); Delta.y = MulFixed(SlotBounds.Top + Org.y, PAGE_RESOLUTION); printer_rc.source_pbox.x0 = SourcePbox.x0 - Delta.x; printer_rc.source_pbox.y0 = SourcePbox.y0 - Delta.y; printer_rc.source_pbox.x1 = SourcePbox.x1 - Delta.x; printer_rc.source_pbox.y1 = SourcePbox.y1 - Delta.y; printer_rc.scaled_source_x0 = /*SourceOrigin.x*/ - Delta.x*printer_rc.x_resolution; printer_rc.scaled_source_y0 = /*SourceOrigin.y*/ - Delta.y*printer_rc.y_resolution; /* // Do the draw. */ CPmwView::OnDraw(&pc->m_dcPrint); /* // Update the parameters for the next label to draw. */ if (pDialog->m_fCollate) { if (++pc->m_nCurrentName == pNameList->Names()) { /* Reset the name index. */ pc->m_nCurrentName = (pNameList->Names() == 0) ? -1 : 0; /* Advance to the next copy. */ pc->m_nCurrentCopy++; if (pc->m_nCurrentCopy == pDialog->m_nLabelCopies) { /* All done! */ break; } /* // Finished another set. // If we need to stop here, do so now. */ if (pDialog->m_fPageBreak) { /* Move to the next page. */ break; } } } else { /* We want to do the next copy. */ if (++pc->m_nCurrentCopy == pDialog->m_nLabelCopies) { /* Reset the copy count. */ pc->m_nCurrentCopy = 0; /* Advance to the next name. */ pc->m_nCurrentName++; if (pc->m_nCurrentName == pNameList->Names()) { /* All done! */ break; } /* // Finished another set. // If we need to stop here, do so now. */ if (pDialog->m_fPageBreak) { /* Move to the next page. */ break; } } } nSlot++; } /* // Restore the scaled source x0 from the saved values. */ printer_rc.source_pbox = SourcePbox; printer_rc.scaled_source_x0 = SourceOrigin.x; printer_rc.scaled_source_y0 = SourceOrigin.y; }
int CLabelView::GrindOutPrintJob(PrintContext& pc) { /* // Print our document(s). */ CLabelPrintDialog* pDialog = (CLabelPrintDialog*)pc.m_pPD; CPmwDoc* pDoc = GetDocument(); pDialog->ComputeTotals(); /* Extract the name list. */ CStdMacroServer* pMacroServer = pDoc->GetMacroServer(); NameListRecord* pNameList = pMacroServer->GetNameList(); BOOL fMergePrint = FALSE; int nNames = pNameList->Names(); int nTotalPages = pDialog->m_nTotalPages; int nError = FALSE; BOOL fOldShow = pMacroServer->ShowMacroValues(); StorageFile* pDatabaseFile = NULL; CFlatFileDatabase* pDatabase = NULL; CFlatFileDatabaseCursor* pCursor = NULL; if (GetConfiguration()->SupportsAddressBook(FALSE)) { // get sender values for address book. pMacroServer->BindSender(); } if (!fOldShow) { pMacroServer->ShowMacroValues(TRUE); pDoc->ReflowMacros(); } pc.m_pCursor = NULL; PPNT dims = pDoc->get_dimensions(); pc.m_source.x0 = 0; pc.m_source.y0 = 0; pc.m_source.x1 = dims.x; pc.m_source.y1 = dims.y; /* // Set the printing conditions. */ pc.m_nBoundName = -1; pc.m_nCurrentName = (nNames == 0) ? -1 : 0; pc.m_nCurrentCopy = 0; CString csFullName; TRY { csFullName = pDoc->GetPathManager()->LocatePath(pNameList->AddressBookName()); TRACE("Open database %s for data!\r\n", (LPCSTR)csFullName); if (nNames != 0) { ERRORCODE Error = CAddressBook::OpenAddressBookDatabase(csFullName, pDatabaseFile, pDatabase, FALSE); if (Error != ERRORCODE_None) { ThrowErrorcodeException(Error); } // Create a cursor on the database. pCursor = new CFlatFileDatabaseCursor; pCursor->Attach(pDatabase); pc.m_pCursor = pCursor; } int nFromPage = pc.m_pInfo->GetFromPage(); int nToPage = pc.m_pInfo->GetToPage(); int nError = 0; pc.SaveStartOfBand(); for (;;) { if (pc.m_fDoubleSided && (nFromPage != nToPage)) { // // 1. Put up the dialog telling the user we are about to begin. // CPmwDialog BeginDialog(IDD_DOUBLE_SIDED_BEGIN); if (BeginDialog.DoModal() != IDOK) { nError = -1; break; } // We need to do the double-sided thing. // // 2. Print the first half of the document. // // Print the key sheet now if it goes first. if ((pc.m_wDoubleSidedType & DBLPRN_FRONTKEYMASK) == DBLPRN_FrontKeyFirst) { if ((nError = PrintKeySheetFront(pc)) != 0) { break; } } // Print the document pages. pc.ToStartOfBand(); if ((nError = PrintLabelsFront(pc)) != 0) { break; } // Print the key sheet now if it goes last. if ((pc.m_wDoubleSidedType & DBLPRN_FRONTKEYMASK) == DBLPRN_FrontKeyLast) { if ((nError = PrintKeySheetFront(pc)) != 0) { break; } } // End the first print job. EndPrintDoc(pc, 0); // // 3. Put up the dialog telling the user to re-insert the stack. // CPmwDialog NotifyDialog(IDD_DOUBLE_SIDED_NOTIFY); if (NotifyDialog.DoModal() != IDOK) { nError = -1; break; } // // 4. Print the second half of the document. // // Start up the second print job. if ((nError = StartPrintDoc(pc)) != 0) { break; } // Print the key sheet now if it goes first. if ((pc.m_wDoubleSidedType & DBLPRN_BACKKEYMASK) == DBLPRN_BackKeyFirst) { if ((nError = PrintKeySheetBack(pc)) != 0) { break; } } // Print the document pages. pc.ToStartOfBand(); if ((nError = PrintLabelsBack(pc)) != 0) { break; } // Print the key sheet now if it goes last. if ((pc.m_wDoubleSidedType & DBLPRN_BACKKEYMASK) == DBLPRN_BackKeyLast) { if ((nError = PrintKeySheetBack(pc)) != 0) { break; } } } else { // Not double-sided. See what page(s) to print. // // Here are the cases: // From == 1, To == 1 (Front only) // From == 2, To == 2 (Back only) // From == 1, To == 2 (Both pages) // // So, we print page 1 if "from" is 1, and we print page 2 if "to" is 2. if (nFromPage == 1) { // Print the fronts in forward order. pc.ToStartOfBand(); if ((nError = PrintLabelsForward(pc, 0)) != 0) { break; } } if (nToPage == 2) { // Print the backs in forward order. pc.ToStartOfBand(); if ((nError = PrintLabelsForward(pc, 1)) != 0) { break; } } } // Done. Always leave! break; } } END_TRY BOOL fReflow = !fOldShow; pMacroServer->ShowMacroValues(fOldShow); if (nNames != 0 && pc.m_nCurrentName > 0) { /* Go back to the first name. */ if (pCursor != NULL) { pMacroServer->BindToRecord(pCursor, pNameList->Name(0)); } fReflow = TRUE; } if (fReflow) { pDoc->ReflowMacros(); } delete pCursor; pCursor = NULL; CAddressBook::CloseAddressBookDatabase(pDatabaseFile, pDatabase); return nError; }