+
+float
+wxLayoutPrintout::ScaleDC(wxDC *dc)
+{
+ // The following bit is taken from the printing sample, let's see
+ // whether it works for us.
+
+ /* 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.
+ */
+ // Get the logical pixels per inch of screen and printer
+ int ppiScreenX, ppiScreenY;
+ GetPPIScreen(&ppiScreenX, &ppiScreenY);
+ int ppiPrinterX, ppiPrinterY;
+ GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
+
+ if(ppiScreenX == 0) // not yet set, need to guess
+ {
+ ppiScreenX = 100;
+ ppiScreenY = 100;
+ }
+ if(ppiPrinterX == 0) // not yet set, need to guess
+ {
+ ppiPrinterX = 72;
+ ppiPrinterY = 72;
+ }
+
+ // This scales the DC so that the printout roughly represents the
+ // 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(pageWidth != 0) // doesn't work always
+ {
+ // If printer pageWidth == current DC width, then this doesn't
+ // change. But w might be the preview bitmap width, so scale down.
+ scale = scale * (float)(w/(float)pageWidth);
+ }
+ dc->SetUserScale(scale, scale);
+ return scale;
+}
+
+bool wxLayoutPrintout::OnPrintPage(int page)
+{
+ wxDC *dc = GetDC();
+
+ ScaleDC(dc);
+
+ if (dc)
+ {
+ int top, bottom;
+ top = (page - 1)*m_PrintoutHeight;
+ bottom = top + m_PrintoutHeight;
+ // SetDeviceOrigin() doesn't work here, so we need to manually
+ // translate all coordinates.
+ wxPoint translate(m_Offset.x,m_Offset.y-top);
+ m_llist->Draw(*dc, translate, top, bottom);
+ return true;
+ }
+ else
+ return false;
+}
+
+void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
+{
+ /* We allocate a temporary wxDC for printing, so that we can
+ determine the correct paper size and scaling. We don't actually
+ print anything on it. */
+#ifdef __WXMSW__
+ wxPrinterDC psdc("","",WXLLIST_TEMPFILE,false);
+#else
+ wxPostScriptDC psdc(WXLLIST_TEMPFILE,false);
+#endif
+
+ float scale = ScaleDC(&psdc);
+
+ psdc.GetSize(&m_PageWidth, &m_PageHeight);
+ // This sets a left/top origin of 15% and 20%:
+ m_Offset = wxPoint((15*m_PageWidth)/100, m_PageHeight/20);
+
+ // This is the length of the printable area.
+ m_PrintoutHeight = m_PageHeight - (int) (m_PageHeight * 0.15);
+ m_PrintoutHeight = (int)( m_PrintoutHeight / scale); // we want to use the real paper height
+
+
+ m_NumOfPages = 1 +
+ (int)( m_llist->GetSize().y / (float)(m_PrintoutHeight));
+
+ *minPage = 1;
+ *maxPage = m_NumOfPages;
+
+ *selPageFrom = 1;
+ *selPageTo = m_NumOfPages;
+ wxRemoveFile(WXLLIST_TEMPFILE);
+}
+
+bool wxLayoutPrintout::HasPage(int pageNum)
+{
+ return pageNum <= m_NumOfPages;
+}
+
+/*
+ Stupid wxWindows doesn't draw proper ellipses, so we comment this
+ out. It's a waste of paper anyway.
+*/
+#if 0
+void
+wxLayoutPrintout::DrawHeader(wxDC &dc,
+ wxPoint topleft, wxPoint bottomright,
+ int pageno)
+{
+ // make backups of all essential parameters
+ const wxBrush& brush = dc.GetBrush();
+ const wxPen& pen = dc.GetPen();
+ const wxFont& font = dc.GetFont();
+
+ dc.SetBrush(*wxWHITE_BRUSH);
+ dc.SetPen(wxPen(*wxBLACK,0,wxSOLID));
+ dc.DrawRoundedRectangle(topleft.x,
+ topleft.y,bottomright.x-topleft.x,
+ bottomright.y-topleft.y);
+ dc.SetBrush(*wxBLACK_BRUSH);
+ wxFont myfont = wxFont((WXLO_DEFAULTFONTSIZE*12)/10,
+ wxSWISS,wxNORMAL,wxBOLD,false,"Helvetica");
+ dc.SetFont(myfont);
+
+ wxString page;
+ page = "9999/9999 "; // many pages...
+ long w,h;
+ dc.GetTextExtent(page,&w,&h);
+ page.Printf("%d/%d", pageno, (int) m_NumOfPages);
+ dc.DrawText(page,bottomright.x-w,topleft.y+h/2);
+ dc.GetTextExtent("XXXX", &w,&h);
+ dc.DrawText(m_title, topleft.x+w,topleft.y+h/2);
+
+ // restore settings
+ dc.SetPen(pen);
+ dc.SetBrush(brush);
+ dc.SetFont(font);
+}
+#endif
+
+