]>
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
101 wxPrintDialog
dialog(parent
, & m_printDialogData
);
102 if (dialog
.ShowModal() == wxID_OK
)
104 dc
= dialog
.GetPrintDC();
105 m_printDialogData
= dialog
.GetPrintData();
110 dc
= new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
114 // May have pressed cancel.
115 if (!dc
|| !dc
->Ok())
121 // on the mac we have always pixels as addressing mode with 72 dpi
123 printout
->SetPPIScreen(72, 72);
124 printout
->SetPPIPrinter(72, 72);
126 // Set printout parameters
132 printout
->SetPageSizePixels((int)w
, (int)h
);
133 dc
->GetSizeMM(&ww
, &hh
);
134 printout
->SetPageSizeMM((int)ww
, (int)hh
);
136 // Create an abort window
139 wxWindow
*win
= CreateAbortWindow(parent
, printout
);
145 wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK
, parent
);
148 sm_abortWindow
= win
;
149 sm_abortWindow
->Show(TRUE
);
152 printout
->OnBeginPrinting();
154 bool keepGoing
= TRUE
;
157 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
159 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
162 wxMessageBox("Could not start printing.", "Print Error", wxOK
, parent
);
169 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
180 GetPort( &thePort
) ;
185 keepGoing
= printout
->OnPrintPage(pn
);
189 printout
->OnEndDocument();
192 printout
->OnEndPrinting();
196 sm_abortWindow
->Show(FALSE
);
197 delete sm_abortWindow
;
198 sm_abortWindow
= NULL
;
208 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
210 wxDC
* dc
= (wxDC
*) NULL
;
212 wxPrintDialog
dialog(parent
, & m_printDialogData
);
213 int ret
= dialog
.ShowModal();
217 dc
= dialog
.GetPrintDC();
218 m_printDialogData
= dialog
.GetPrintDialogData();
224 bool wxMacPrinter::Setup(wxWindow
*parent
)
226 wxPrintDialog
dialog(parent
, & m_printDialogData
);
227 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
229 int ret
= dialog
.ShowModal();
233 m_printDialogData
= dialog
.GetPrintDialogData();
236 return (ret
== wxID_OK
);
243 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
244 wxPrintout
*printoutForPrinting
,
245 wxPrintDialogData
*data
)
246 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
251 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
252 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
257 wxMacPrintPreview::~wxMacPrintPreview(void)
261 bool wxMacPrintPreview::Print(bool interactive
)
263 if (!m_printPrintout
)
265 wxMacPrinter
printer(&m_printDialogData
);
266 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
269 void wxMacPrintPreview::DetermineScaling(void)
271 int screenWidth
, screenHeight
;
272 wxDisplaySize( &screenWidth
, &screenHeight
) ;
274 m_previewPrintout
->SetPPIScreen( 72 , 72 ) ;
275 m_previewPrintout
->SetPPIPrinter( 72 , 72 ) ;
276 m_previewPrintout
->SetPageSizeMM( 8 * 25.6 , 11 * 25.6 ) ;
277 m_previewPrintout
->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
278 m_pageWidth
= 8 * 72 ;
279 m_pageHeight
= 11 * 72 ;
282 // Get a device context for the currently selected printer
283 wxPrinterDC
printerDC(m_printDialogData
.GetPrintData());
288 printerDC
.GetSizeMM(&ww
, &hh
);
289 printerDC
.GetSize( &x
, &y
) ;
290 m_previewPrintout
->SetPageSizeMM((int)ww
, (int)hh
);
291 m_previewPrintout
->SetPageSizePixels( x
, y
) ;
297 // At 100%, the page should look about page-size on the screen.
298 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
299 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);