Esempio n. 1
0
/*****************************************************************
 * 
 * method :void	CEasyReport::Start(void)
 *
 * parameters : none
 *
 * returns : 
 *
 * description: Start the report generation. Create all the fonts, etc
 * Try and get the printer device context, If no printer is set up as 
 * the default printer on the system, create a screen device context. 
 *
 ****************************************************************/
void	CEasyReport::Start()
{

	ASSERT( m_PrinterDC == NULL );
	DoCleanup();
	
	// set up a print date ..
	CTime		aNow = CTime::GetCurrentTime();
	m_ReportDate.Format("Date: %2d/%2d/%4d", aNow.GetMonth(), aNow.GetDay(), aNow.GetYear());

	// NOTE: The following is most certainly not correct if there is 
	// no default printer defined ! If you do not have ANY printer, then
	// you might install a Fax printer (eg Microsoft Fax or Bitware etc)
	CPrintDialog	aPD(false);

	if(aPD.GetDefaults())
	{
		m_PrinterDC = aPD.m_pd.hDC;
	}
	else
	{
		m_PrinterDC = ::GetDC(NULL);	// get the screen device context
	}

	//::SetMapMode(m_PrinterDC, MM_ANISOTROPIC);
	//::SetWindowExtEx( m_PrinterDC, 254,254,NULL);
	//::SetViewportExtEx(m_PrinterDC, GetDeviceCaps(m_PrinterDC,LOGPIXELSX),GetDeviceCaps(m_PrinterDC,LOGPIXELSY),NULL);
	SetMapMode( m_PrinterDC, MM_LOMETRIC);
	SetupTextStyles( m_PrinterDC );

	m_DataTop = m_TopMargin;
	m_PageCount = 0;
	m_CurPage = 0;

	CRect		aRect;

	// Write the report header...
	if( m_ReportHdrHt > 0 )
	{
		aRect.SetRect(m_LeftMargin, m_TopMargin, m_PageWidth - m_RightMargin,m_TopMargin + m_ReportHdrHt );

		aRect.bottom = aRect.top + m_ReportHdrHt;
		WriteReportHeader(aRect);
		m_DataTop += m_ReportHdrHt;
	}

	if( m_PageHdrHt > 0)
	{
		aRect.SetRect(m_LeftMargin, m_DataTop, m_PageWidth - m_RightMargin, m_DataTop + m_PageHdrHt);
		WritePageHeader(aRect);
		m_DataTop += m_PageHdrHt;
	}
}
Esempio n. 2
0
void appCopyPaste::CopyPages(const MenuPageArray& pageData)
{
    if (pageData.IsEmpty())
        return;

    try
        {
            appConfigFile::OpenAsClipboard(false);
            WritePageHeader();

            // get counts
            int nPages = pageData.Size();
            int ntotalPages  = nPages;
            int ntotalObjects  = 0;
            for (int i = 0; i < nPages; i++)
                {
                    const MenuPageC& currPage = pageData.GetRef(i);
                    ntotalPages += GetChildPageCount(currPage);
                    ntotalObjects += GetChildObjectCount(currPage);
                }

            // write counts
            WriteInt(nPages);
            WriteInt(ntotalPages);
            WriteInt(ntotalObjects);
            WriteLine();

            // page types
            for (int i = 0; i < nPages; i++)
                WritePageType(pageData.GetRef(i));

            // object types
            for (int i = 0; i < nPages; i++)
                WriteObjectType(pageData.GetRef(i));

            // object list -- this has to include all objects to avoid problems on read
            WriteAppGlobals();

            // and finally pages
            for (int i = 0; i < nPages; i++)
                pageData[i]->WriteToFile();

        }
    catch (TextC::TextError re)
        {
            GenAppErrorMsg("CopyPages", re.errMsg);
        }

    appConfigFile::Close();
}
Esempio n. 3
0
void MyPrintout::DrawPageTwo()
{
    // You might use THIS code to set the printer DC to ROUGHLY reflect
    // the screen text size. This page also draws lines of actual length
    // 5cm on the page.

    // Compare this to DrawPageOne(), which uses the really convenient routines
    // from wxPrintout to fit the screen image onto the printed page. This page
    // illustrates how to do all the scaling calculations yourself, if you're so
    // inclined.

    wxDC *dc = GetDC();

    // Get the logical pixels per inch of screen and printer
    int ppiScreenX, ppiScreenY;
    GetPPIScreen(&ppiScreenX, &ppiScreenY);
    int ppiPrinterX, ppiPrinterY;
    GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);

    // This scales the DC so that the printout roughly represents the screen
    // scaling. The text point size _should_ be the right size but in fact is
    // too small for some reason. This is a detail that will need to be
    // addressed at some point but can be fudged for the moment.
    float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);

    // Now we have to check in case our real page size is reduced (e.g. because
    // we're drawing to a print preview memory DC)
    int pageWidth, pageHeight;
    int w, h;
    dc->GetSize(&w, &h);
    GetPageSizePixels(&pageWidth, &pageHeight);

    // If printer pageWidth == current DC width, then this doesn't change. But w
    // might be the preview bitmap width, so scale down.
    float overallScale = scale * (float)(w/(float)pageWidth);
    dc->SetUserScale(overallScale, overallScale);

    // Calculate conversion factor for converting millimetres into logical
    // units. There are approx. 25.4 mm to the inch. There are ppi device units
    // to the inch. Therefore 1 mm corresponds to ppi/25.4 device units. We also
    // divide by the screen-to-printer scaling factor, because we need to
    // unscale to pass logical units to DrawLine.

    // Draw 50 mm by 50 mm L shape
    float logUnitsFactor = (float)(ppiPrinterX/(scale*25.4));
    float logUnits = (float)(50*logUnitsFactor);
    dc->SetPen(* wxBLACK_PEN);
    dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250);
    dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits));

    dc->SetBackgroundMode(wxTRANSPARENT);
    dc->SetBrush(*wxTRANSPARENT_BRUSH);

    { // GetTextExtent demo:
        wxString words[7] = { wxT("This "), wxT("is "), wxT("GetTextExtent "),
                             wxT("testing "), wxT("string. "), wxT("Enjoy "), wxT("it!") };
        wxCoord w, h;
        long x = 200, y= 250;
        wxFont fnt(15, wxSWISS, wxNORMAL, wxNORMAL);

        dc->SetFont(fnt);

        for (int i = 0; i < 7; i++)
        {
            wxString word = words[i];
            word.Remove( word.Len()-1, 1 );
            dc->GetTextExtent(word, &w, &h);
            dc->DrawRectangle(x, y, w, h);
            dc->GetTextExtent(words[i], &w, &h);
            dc->DrawText(words[i], x, y);
            x += w;
        }

    }

    dc->SetFont(wxGetApp().GetTestFont());

    dc->DrawText(wxT("Some test text"), 200, 300 );

    // TESTING

    int leftMargin = 20;
    int rightMargin = 20;
    int topMargin = 20;
    int bottomMargin = 20;

    int pageWidthMM, pageHeightMM;
    GetPageSizeMM(&pageWidthMM, &pageHeightMM);

    float leftMarginLogical = (float)(logUnitsFactor*leftMargin);
    float topMarginLogical = (float)(logUnitsFactor*topMargin);
    float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin));
    float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin));

    dc->SetPen(* wxRED_PEN);
    dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical,
        (long)rightMarginLogical, (long)topMarginLogical);
    dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical,
        (long)rightMarginLogical,  (long)bottomMarginLogical);

    WritePageHeader(this, dc, wxT("A header"), logUnitsFactor);
}
Esempio n. 4
0
/*****************************************************************
 * 
 * method :void	CEasyReport::EjectPage(bool inIsLastPage)
 *
 * parameters : inIsLastPage : true if this is the last page
 * of the report.
 *
 * returns : nothing
 *
 * description: Call this function to eject the current page. if this
 * is the last page, we print the report footer. If there
 * is a page footer defined, it will be printed before starting the 
 * new page. 
 *
 ****************************************************************/
bool	CEasyReport::EjectPage(bool inIsLastPage)
{
	CRect	aRect;
	int		aRequiredHt, aAbsBottom;
	bool	aAllPrinted = true;


	aRect.left = m_LeftMargin;
	aRect.right = m_PageWidth - m_RightMargin;
	aAbsBottom = m_PageHeight - m_BottomMargin;

	if(inIsLastPage)
	{
		// check to see if the PageFooter and the ReportFooter 
		// will fit on to the remaining area on this page. If so, 
		// print the page footer and the report footer. 
		aRequiredHt = m_PageFtrHt + m_ReportFtrHt;
		if( m_DataTop + aRequiredHt <= aAbsBottom )
		{
			aRect.top = aAbsBottom - (m_PageFtrHt+ m_ReportFtrHt);
			aRect.bottom = aRect.top + m_PageFtrHt;
			WritePageFooter(aRect);
			if( m_ReportFtrHt)
			{
				aRect.top = aRect.bottom;
				aRect.bottom += m_ReportFtrHt;
				WriteReportFooter(aRect);
			}
		}
		else
		{
			aRect.top = aAbsBottom - m_PageFtrHt;
			aRect.bottom = aRect.top + m_PageFtrHt;
			WritePageFooter(aRect);
			aAllPrinted = (m_ReportFtrHt >0 ? false : true);
		}
	}
	else
	{
		// not the last page of the report. Simply draw the page 
		// footer bottom aligned on the page
		if(m_PageFtrHt > 0 )
		{
			// bottom align the page footer on the page
			aRect.top = aAbsBottom - m_PageFtrHt;
			aRect.bottom = aRect.top + m_PageFtrHt;
			WritePageFooter(aRect);
		}
	}

	m_PageItems.Add(m_ReportItems.GetSize());
	++m_PageCount;

	m_DataTop = m_TopMargin;

	// If not the last page, then print the page header if there
	// is a page header.
	if( !inIsLastPage && m_PageHdrHt > 0 )
	{
		aRect.top = m_DataTop;
		aRect.bottom = aRect.top + m_PageHdrHt;
		WritePageHeader(aRect);
		m_DataTop += m_PageHdrHt;
	}

	// Print the table header only if needed
	// m_RedrawTblHdr = false;	
	if( !inIsLastPage && m_RepeatTblHdr && m_NumDataCols != 0 )
	{
		if( !m_SuppressBlankTbl )
			WriteTableHeader();
		else
			m_RedrawTblHdr = true;
	}
	return aAllPrinted;
}