]>
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
140 wxWindow *win = CreateAbortWindow(parent, printout);
146 wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent);
149 sm_abortWindow = win;
150 sm_abortWindow->Show(TRUE);
154 printout
->OnBeginPrinting();
156 bool keepGoing
= TRUE
;
159 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
161 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
164 wxMessageBox("Could not start printing.", "Print Error", wxOK
, parent
);
171 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
182 keepGoing
= printout
->OnPrintPage(pn
);
186 printout
->OnEndDocument();
189 printout
->OnEndPrinting();
193 sm_abortWindow
->Show(FALSE
);
194 delete sm_abortWindow
;
195 sm_abortWindow
= NULL
;
205 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
207 wxDC
* dc
= (wxDC
*) NULL
;
209 wxPrintDialog
dialog(parent
, & m_printDialogData
);
210 int ret
= dialog
.ShowModal();
214 dc
= dialog
.GetPrintDC();
215 m_printDialogData
= dialog
.GetPrintDialogData();
221 bool wxMacPrinter::Setup(wxWindow
*parent
)
223 wxPrintDialog
dialog(parent
, & m_printDialogData
);
224 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
226 int ret
= dialog
.ShowModal();
230 m_printDialogData
= dialog
.GetPrintDialogData();
233 return (ret
== wxID_OK
);
240 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
241 wxPrintout
*printoutForPrinting
,
242 wxPrintDialogData
*data
)
243 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
248 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
249 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
254 wxMacPrintPreview::~wxMacPrintPreview(void)
258 bool wxMacPrintPreview::Print(bool interactive
)
260 if (!m_printPrintout
)
262 wxMacPrinter
printer(&m_printDialogData
);
263 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
266 void wxMacPrintPreview::DetermineScaling(void)
268 int screenWidth
, screenHeight
;
269 wxDisplaySize( &screenWidth
, &screenHeight
) ;
271 m_previewPrintout
->SetPPIScreen( 72 , 72 ) ;
272 m_previewPrintout
->SetPPIPrinter( 72 , 72 ) ;
273 m_previewPrintout
->SetPageSizeMM( 8 * 25.6 , 11 * 25.6 ) ;
274 m_previewPrintout
->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
275 m_pageWidth
= 8 * 72 ;
276 m_pageHeight
= 11 * 72 ;
279 // Get a device context for the currently selected printer
280 wxPrinterDC
printerDC(m_printDialogData
.GetPrintData());
285 printerDC
.GetSizeMM(&ww
, &hh
);
286 printerDC
.GetSize( &x
, &y
) ;
287 m_previewPrintout
->SetPageSizeMM((int)ww
, (int)hh
);
288 m_previewPrintout
->SetPageSizePixels( x
, y
) ;
294 // At 100%, the page should look about page-size on the screen.
295 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
296 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);