예제 #1
0
int CLabelView::OnPrintLabels(PrintContext &pc, int nCurrentPage, int nNumPages)
{
	CPmwDoc* pDoc = GetDocument();
	PPNT dims = pDoc->get_dimensions();

	int nError = 0;

	int nPrintCopies = pc.m_copies;

	while (nError == 0 && nPrintCopies-- > 0)
	{
	// Source will always be all of the label.

		pc.m_source.x0 = 0;
		pc.m_source.y0 = 0;
		pc.m_source.x1 = dims.x;
		pc.m_source.y1 = dims.y;

		OnPrepareDC(&pc.m_dcPrint, pc.m_pInfo);

	// Set up drawing rect to entire page (in logical coordinates)

		pc.m_pInfo->m_rectDraw.SetRect(0, 0,
							pc.m_dcPrint.GetDeviceCaps(HORZRES),
							pc.m_dcPrint.GetDeviceCaps(VERTRES));
		pc.m_dcPrint.DPtoLP(&pc.m_pInfo->m_rectDraw);

		CString strFmt;
		TRY
			LoadConfigurationString(IDS_PRINTPAGENUM, strFmt);
		END_TRY
		char szBuf[80];
		wsprintf(szBuf, strFmt, (int32)nCurrentPage+1, (int32)nNumPages);
		pc.m_dlgstatus->SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);

		if (!pc.m_fBanding)
		{
			VERIFY(pc.m_dcPrint.StartPage());
		}
		nError = OnPrint(&pc, pc.m_pInfo) || UserAbort;
		if (!pc.m_fBanding)
		{
			if (pc.m_dcPrint.EndPage() < 0)
				nError = TRUE;
		}
	}
	return nError;
}
예제 #2
0
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;
}
예제 #3
0
SHORT CCatalogView::OnPrintDocument(PrintContext &pc,
												int32 aCurrentDocument, int32 aNumDocuments)
{
	CPmwDoc *pDoc = GetDocument();

	SHORT bError = FALSE;

	SHORT x, y;
	PCOORD grid_width, grid_height, step_width, step_height, text_height, new_x;
	PBOX pbox;
	int32 current_page, num_pages;
#ifdef SPECIAL_CATALOG
	PCOORD x0 = 0, y0 =  (PAGE_RESOLUTION*3)/4;
#endif

	CCatalogPrint *pdlg = (CCatalogPrint *)pc.m_pPD;

#ifdef OLD_CATALOG_STYLE
	CString csNameBuffer;
#endif

/* Compute the size of the grid and the step. */

	PPNT dims = pDoc->get_dimensions();
	PMGDatabasePtr const database = pDoc->get_database();
	CTextStyle Style(database);

#ifdef CATALOG_BACKGROUND
	PATTERN_CREATE_STRUCT pcs;

	pcs.bound.x0 = 0;
	pcs.bound.y0 = 0;
	pcs.bound.x1 = dims.x;
	pcs.bound.y1 = dims.y;
	pcs.pattern = 0;
	pcs.color = COLOR_WHITE;
	pcs.bcolor = MAKE_COLOR(0, 0, 0, 32);
#endif


#ifdef SPECIAL_CATALOG
	dims.x -= x0;
	dims.y -= y0;

	SHORT const across = 10;
	SHORT const down = 5;
#else
	SHORT const across = pdlg->m_x_count;
	SHORT const down = pdlg->m_y_count;
#endif

	grid_width = dims.x/across;
	grid_height = dims.y/down;

	step_width = scale_pcoord(grid_width, 9, 10);

	Style.SetDefault();
	SHORT base_size;

#ifdef DOUBLE_NAMES
	step_height = scale_pcoord(grid_height, 7, 10);
	text_height = (grid_height - step_height)/2;
	base_size = (SHORT)scale_pcoord(text_height, (72*6)/10, PAGE_RESOLUTION);
#else
	step_height = scale_pcoord(grid_height, 9, 10);
	text_height = grid_height - step_height;
	base_size = (SHORT)scale_pcoord(text_height, (72*2)/3, PAGE_RESOLUTION);
#endif

/* Set the text style. */

	if (base_size > 12)
	{
		base_size = 12;
	}

	Style.Size(MakeFixed(base_size));
	Style.BaseSize(MakeFixed(base_size));
#ifdef DOUBLE_NAMES
	Style.Bold(TRUE);
#endif

	Style.UpdateFontMetrics();

/* Figure out number of pages we will print. */
	num_pages = 
#ifdef SPACE_ON_FIRST
					across +
#endif
					m_picture_list.GetSize();
	{
		SHORT n;

		n = across * down;

		num_pages = (num_pages + n - 1) / n;
	}
	current_page = 0;

/* Run through all the graphics. */

	ObjectListPtr list = pDoc->object_list();

	int nMaxNames = m_picture_list.GetSize();
	BOOL broken;
	int nEntry;
	for (broken = FALSE, nEntry = 0; !broken && nEntry < nMaxNames ;)
	{
		// Tell the user what we're doing.
      printer_update_name(NULL, GET_PMWAPP()->GetResourceStringPointer (IDS_BUILDING_PAGE), (VOIDPTR)&pc);

		// Make sure the current page is blank.
		list->destroy_objects();

		// Build the next page.
		BeginWaitCursor();

#ifdef CATALOG_BACKGROUND
		PatternObjectPtr patobj;
		if ((patobj = database->create_pattern_object(&pcs)) != NULL)
		{
			pDoc->append_object(patobj);
		}
#endif

#ifdef SPECIAL_CATALOG
		for (pbox.y0 = y0, y = 0;
#else
		for (pbox.y0 = 0, y = 0;
#endif
						y < down && !broken;
						y++, pbox.y0 += grid_height)
		{
#ifdef SPACE_ON_FIRST
			if (current_page == 0 && y == 0)
			{
				continue;
			}
#endif

			pbox.y1 = pbox.y0 + step_height;

#ifdef SPECIAL_CATALOG
			for (pbox.x0 = x0, x = 0;
#else
			for (pbox.x0 = 0, x = 0;
#endif
					x < across;
					x++,
 					pbox.x0 += grid_width,
					nEntry++)
			{
				CFrameObject* pFrame;
				PPNT p;

				// Make sure we are on a good node.
				if (nEntry == nMaxNames)
				{
				/* All done! */
					y = down;
					break;
				}

				CString strName = m_picture_list.GetAt(nEntry);

			/* Show the name. */

//				multi_context.current_name = node->name;

			/* We have a selected node. Make a graphic for it. */

				pbox.x1 = pbox.x0 + step_width;

			/* Create the graphic object. */

#ifdef OLD_CATALOG_STYLE
				csNameBuffer = m_chosen_dir;
				csNameBuffer += strName;
#endif

				GraphicObjectPtr object;

				GRAPHIC_CREATE_STRUCT gcs;
#ifdef OLD_CATALOG_STYLE
				gcs.m_csFileName = csNameBuffer;
#else
				gcs.m_csFileName = strName;
#endif

				if ((object = database->create_graphic_object(&gcs)) != NULL)
				{
				/* Get the size of the graphic. */

					if (object->original_dims(&p))
					{
						pDoc->append_object(object);

						dims.x = (PCOORD)step_width;
						dims.y = (PCOORD)step_height;

					/* Fit the graphic to its box. */

						if ((new_x = scale_pcoord(dims.y, p.x, p.y)) > dims.x)
						{
							dims.y = scale_pcoord(dims.x, p.y, p.x);
						}
						else
						{
							dims.x = new_x;
						}

					/* Set the bound. */

						PBOX bound;

						bound.x0 = (pbox.x0 + pbox.x1 - dims.x)/2;
						bound.x1 = bound.x0 + dims.x;
						bound.y0 = (pbox.y0 + pbox.y1 - dims.y)/2;
						bound.y1 = bound.y0 + dims.y;
						object->set_bound(bound);

						object->calc();
					}
					else
					{
						delete object;
						object = NULL;
					}
				}

			/* Add a text frame for the name. */

				FRAMEOBJ_CREATE_STRUCT fcs;
				LPCSTR text = strName;

				fcs.bound.x0 = pbox.x0;
				fcs.bound.x1 = pbox.x1;
				fcs.bound.y0 = pbox.y1;

				fcs.alignment = ALIGN_center;
				fcs.vert_alignment = ALIGN_top;
//				fcs.text = NULL;
				fcs.flags = 0;
				fcs.pStyle = NULL;

#ifdef SPECIAL_CATALOG
				CHAR buffer[100];

				LPCSTR ptr;

				if ((ptr = strrchr(text, '\\')) == NULL)
				{
					ptr = text;
				}
				else
				{
				/* Move off of '\'. */
					ptr++;
				}

				strcpy(buffer, ptr);
				LPSTR foop;
				if ((foop = strrchr(buffer, '.')) != NULL)
				{
				/* Remove extension. */
					*foop = '\0';
				}

				fcs.bound.y1 = fcs.bound.y0+text_height;
				text = buffer;

#elif defined(DOUBLE_NAMES)

				fcs.bound.y1 = fcs.bound.y0+text_height*2;

				CHAR name[64];
				CHAR buffer[100];
				LPCSTR ptr;

				if ((ptr = strrchr(text, '\\')) == NULL)
				{
					ptr = text;
				}
				else
				{
				/* Move off of '\'. */
					ptr++;
				}

				BOOL blanket = FALSE;				/* porpoise-ly  (just for pun) */

				if (object == NULL)
				{
					blanket = TRUE;
				}
				else
				{
					object->get_name(name, sizeof(name), -1);
					if (stricmp(name, ptr) == 0)
					{
						blanket = TRUE;
						strcpy(name, " ");
					}
				}

				if (blanket)
				{
				/* Blank it. */
					strcpy(name, " ");
				}

//				sprintf(buffer, "%s\n%s", name, p);
				strcpy(buffer, name);
				strcat(buffer, "\n");
				strcat(buffer, ptr);

				text = buffer;
#else
				fcs.bound.y1 = fcs.bound.y0+text_height;
#endif
				if ((pFrame = pDoc->create_frame_object(&fcs)) == NULL)
				{
					broken = TRUE;
					break;
				}

				int nCharacters = strlen(text);
				if (nCharacters != 0)
				{
					CTxp Txp(database);
					Txp.Init(pFrame, 0);
					Txp.SetHorizontalAlignment(fcs.alignment);
					Txp.Style(Style);

					TRY
					{
						CHARACTER* pText = new CHARACTER[nCharacters];
						for (int n = 0; n < nCharacters; n++)
						{
							pText[n] = (CHARACTER)text[n];
						}
#ifdef DOUBLE_NAMES
						// First line is name + CR...
						int nLine1 = strlen(name)+1;
						// ...second line is the rest.
						int nLine2 = nCharacters - nLine1;

						// Insert line 1.
						Txp.InsertText(pText, nLine1);

						// Compute style for line 2:
						// no bold, and 8/10 the size.
						Txp.Style().Bold(FALSE);
						CFixed lSize = Txp.Style().BaseSize();
						lSize = MulDivFixed(lSize, MakeFixed(8), MakeFixed(10));
						Txp.Style().BaseSize(lSize);
						Txp.Style().Size(lSize);
						Txp.Style().UpdateFontMetrics();

						// Insert line 2.
						Txp.InsertText(pText+nLine1, nLine2);
#else
						Txp.InsertText(pText, nCharacters);
#endif
						delete [] pText;
					}
					END_TRY
				}

				pDoc->append_object(pFrame);
			}
		}

		EndWaitCursor();

	/* See if we broke! */

		if (broken)
		{
			break;
		}

	/* Print the page. */

		if (list->count() != 0)
		{
		/* We have objects! Print them. */
			++current_page;

			if (bError = CPmwView::OnPrintDocument(pc, current_page, num_pages))
			{
				break;
			}
		}
	}