]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/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 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter
, wxPrinterBase
)
40 IMPLEMENT_CLASS(wxMacPrintPreview
, wxPrintPreviewBase
)
47 wxMacPrinter::wxMacPrinter(wxPrintDialogData
*data
):
52 wxMacPrinter::~wxMacPrinter(void)
56 bool wxMacPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
59 sm_abortWindow
= NULL
;
64 printout
->SetIsPreview(FALSE
);
65 printout
->OnPreparePrinting();
67 // Get some parameters from the printout, if defined
70 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
75 m_printDialogData
.SetMinPage(minPage
);
76 m_printDialogData
.SetMaxPage(maxPage
);
78 m_printDialogData
.SetFromPage(fromPage
);
80 m_printDialogData
.SetToPage(toPage
);
84 m_printDialogData
.EnablePageNumbers(TRUE
);
85 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
86 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
87 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
88 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
89 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
90 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
91 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
92 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
95 m_printDialogData
.EnablePageNumbers(FALSE
);
97 // Create a suitable device context
98 // Create a suitable device context
103 m_printDialogData
.ConvertToNative() ; // make sure we have a valid handle
104 if ( m_printDialogData
.m_macPrintInfo
)
106 // todo incorporate the changes from a global page setup
107 if ( ::PrStlDialog( m_printDialogData
.m_macPrintInfo
) ) // we should have the page setup dialog
110 wxPrintDialog
dialog(parent
, & m_printDialogData
);
111 if (dialog
.ShowModal() == wxID_OK
)
113 dc
= dialog
.GetPrintDC();
114 m_printDialogData
= dialog
.GetPrintData();
125 dc
= new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
129 // May have pressed cancel.
130 if (!dc
|| !dc
->Ok())
136 // on the mac we have always pixels as addressing mode with 72 dpi
138 printout
->SetPPIScreen(72, 72);
139 printout
->SetPPIPrinter(72, 72);
141 // Set printout parameters
147 printout
->SetPageSizePixels((int)w
, (int)h
);
148 dc
->GetSizeMM(&ww
, &hh
);
149 printout
->SetPageSizeMM((int)ww
, (int)hh
);
151 // Create an abort window
155 wxWindow *win = CreateAbortWindow(parent, printout);
161 wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent);
164 sm_abortWindow = win;
165 sm_abortWindow->Show(TRUE);
169 printout
->OnBeginPrinting();
171 bool keepGoing
= TRUE
;
174 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
176 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
179 wxMessageBox("Could not start printing.", "Print Error", wxOK
, parent
);
186 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
197 keepGoing
= printout
->OnPrintPage(pn
);
201 printout
->OnEndDocument();
204 printout
->OnEndPrinting();
208 sm_abortWindow
->Show(FALSE
);
209 delete sm_abortWindow
;
210 sm_abortWindow
= NULL
;
220 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
222 wxDC
* dc
= (wxDC
*) NULL
;
224 wxPrintDialog
dialog(parent
, & m_printDialogData
);
225 int ret
= dialog
.ShowModal();
229 dc
= dialog
.GetPrintDC();
230 m_printDialogData
= dialog
.GetPrintDialogData();
236 bool wxMacPrinter::Setup(wxWindow
*parent
)
238 wxPrintDialog
dialog(parent
, & m_printDialogData
);
239 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
241 int ret
= dialog
.ShowModal();
245 m_printDialogData
= dialog
.GetPrintDialogData();
248 return (ret
== wxID_OK
);
255 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
256 wxPrintout
*printoutForPrinting
,
257 wxPrintDialogData
*data
)
258 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
263 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
264 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
269 wxMacPrintPreview::~wxMacPrintPreview(void)
273 bool wxMacPrintPreview::Print(bool interactive
)
275 if (!m_printPrintout
)
277 wxMacPrinter
printer(&m_printDialogData
);
278 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
281 void wxMacPrintPreview::DetermineScaling(void)
284 HDC dc = ::GetDC(NULL);
285 int screenWidth = ::GetDeviceCaps(dc, HORZSIZE);
286 // int screenHeight = ::GetDeviceCaps(dc, VERTSIZE);
287 int screenXRes = ::GetDeviceCaps(dc, HORZRES);
288 // int screenYRes = ::GetDeviceCaps(dc, VERTRES);
289 int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX);
290 int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY);
291 m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
293 ::ReleaseDC(NULL, dc);
295 // Get a device context for the currently selected printer
296 wxPrinterDC printerDC("", "", "", FALSE, m_printDialogData.GetOrientation());
298 int printerWidth = 150;
299 int printerHeight = 250;
300 int printerXRes = 1500;
301 int printerYRes = 2500;
303 if (printerDC.GetHDC())
305 printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE);
306 printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE);
307 printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES);
308 printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES);
310 int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX);
311 int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY);
313 m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
314 m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight);
316 if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0)
322 m_pageWidth = printerXRes;
323 m_pageHeight = printerYRes;
325 // At 100%, the page should look about page-size on the screen.
326 m_previewScale = (float)((float)screenWidth/(float)printerWidth);
327 m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerYRes);