]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/printmac.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMacPrinter framework
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "printwin.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/msgdlg.h"
32 #include "wx/mac/printmac.h"
33 #include "wx/dcprint.h"
34 #include "wx/printdlg.h"
38 IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter
, wxPrinterBase
)
39 IMPLEMENT_CLASS(wxMacPrintPreview
, wxPrintPreviewBase
)
45 wxMacPrinter::wxMacPrinter(wxPrintDialogData
*data
):
50 wxMacPrinter::~wxMacPrinter(void)
54 bool wxMacPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
57 sm_abortWindow
= NULL
;
62 printout
->SetIsPreview(FALSE
);
63 printout
->OnPreparePrinting();
65 // Get some parameters from the printout, if defined
68 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
73 m_printDialogData
.SetMinPage(minPage
);
74 m_printDialogData
.SetMaxPage(maxPage
);
76 m_printDialogData
.SetFromPage(fromPage
);
78 m_printDialogData
.SetToPage(toPage
);
82 m_printDialogData
.EnablePageNumbers(TRUE
);
83 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
84 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
85 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
86 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
87 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
88 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
89 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
90 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
93 m_printDialogData
.EnablePageNumbers(FALSE
);
95 // Create a suitable device context
96 // Create a suitable device context
101 m_printDialogData
.ConvertToNative() ; // make sure we have a valid handle
102 if ( m_printDialogData
.m_macPrintInfo
)
104 // todo incorporate the changes from a global page setup
105 if ( ::PrStlDialog( m_printDialogData
.m_macPrintInfo
) ) // we should have the page setup dialog
108 wxPrintDialog
dialog(parent
, & m_printDialogData
);
109 if (dialog
.ShowModal() == wxID_OK
)
111 dc
= dialog
.GetPrintDC();
112 m_printDialogData
= dialog
.GetPrintData();
123 dc
= new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
127 // May have pressed cancel.
128 if (!dc
|| !dc
->Ok())
134 // on the mac we have always pixels as addressing mode with 72 dpi
136 printout
->SetPPIScreen(72, 72);
137 printout
->SetPPIPrinter(72, 72);
139 // Set printout parameters
145 printout
->SetPageSizePixels((int)w
, (int)h
);
146 dc
->GetSizeMM(&ww
, &hh
);
147 printout
->SetPageSizeMM((int)ww
, (int)hh
);
149 // Create an abort window
153 wxWindow *win = CreateAbortWindow(parent, printout);
159 wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent);
162 sm_abortWindow = win;
163 sm_abortWindow->Show(TRUE);
167 printout
->OnBeginPrinting();
169 bool keepGoing
= TRUE
;
172 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
174 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
177 wxMessageBox("Could not start printing.", "Print Error", wxOK
, parent
);
184 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
195 keepGoing
= printout
->OnPrintPage(pn
);
199 printout
->OnEndDocument();
202 printout
->OnEndPrinting();
206 sm_abortWindow
->Show(FALSE
);
207 delete sm_abortWindow
;
208 sm_abortWindow
= NULL
;
218 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
220 wxDC
* dc
= (wxDC
*) NULL
;
222 wxPrintDialog
dialog(parent
, & m_printDialogData
);
223 int ret
= dialog
.ShowModal();
227 dc
= dialog
.GetPrintDC();
228 m_printDialogData
= dialog
.GetPrintDialogData();
234 bool wxMacPrinter::Setup(wxWindow
*parent
)
236 wxPrintDialog
dialog(parent
, & m_printDialogData
);
237 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
239 int ret
= dialog
.ShowModal();
243 m_printDialogData
= dialog
.GetPrintDialogData();
246 return (ret
== wxID_OK
);
253 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
254 wxPrintout
*printoutForPrinting
,
255 wxPrintDialogData
*data
)
256 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
261 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
262 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
267 wxMacPrintPreview::~wxMacPrintPreview(void)
271 bool wxMacPrintPreview::Print(bool interactive
)
273 if (!m_printPrintout
)
275 wxMacPrinter
printer(&m_printDialogData
);
276 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
279 void wxMacPrintPreview::DetermineScaling(void)
282 HDC dc = ::GetDC(NULL);
283 int screenWidth = ::GetDeviceCaps(dc, HORZSIZE);
284 // int screenHeight = ::GetDeviceCaps(dc, VERTSIZE);
285 int screenXRes = ::GetDeviceCaps(dc, HORZRES);
286 // int screenYRes = ::GetDeviceCaps(dc, VERTRES);
287 int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX);
288 int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY);
289 m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
291 ::ReleaseDC(NULL, dc);
293 // Get a device context for the currently selected printer
294 wxPrinterDC printerDC("", "", "", FALSE, m_printDialogData.GetOrientation());
296 int printerWidth = 150;
297 int printerHeight = 250;
298 int printerXRes = 1500;
299 int printerYRes = 2500;
301 if (printerDC.GetHDC())
303 printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE);
304 printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE);
305 printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES);
306 printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES);
308 int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX);
309 int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY);
311 m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
312 m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight);
314 if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0)
320 m_pageWidth = printerXRes;
321 m_pageHeight = printerYRes;
323 // At 100%, the page should look about page-size on the screen.
324 m_previewScale = (float)((float)screenWidth/(float)printerWidth);
325 m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerYRes);