]>
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
9 // Licence: wxWindows licence
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/private.h"
34 #include "wx/mac/printmac.h"
35 #include "wx/dcprint.h"
36 #include "wx/printdlg.h"
40 #if !USE_SHARED_LIBRARY
41 IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter
, wxPrinterBase
)
42 IMPLEMENT_CLASS(wxMacPrintPreview
, wxPrintPreviewBase
)
49 wxMacPrinter::wxMacPrinter(wxPrintDialogData
*data
):
54 wxMacPrinter::~wxMacPrinter(void)
58 bool wxMacPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
61 sm_abortWindow
= NULL
;
66 printout
->SetIsPreview(FALSE
);
67 printout
->OnPreparePrinting();
69 // Get some parameters from the printout, if defined
72 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
77 m_printDialogData
.SetMinPage(minPage
);
78 m_printDialogData
.SetMaxPage(maxPage
);
80 m_printDialogData
.SetFromPage(fromPage
);
82 m_printDialogData
.SetToPage(toPage
);
86 m_printDialogData
.EnablePageNumbers(TRUE
);
87 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
88 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
89 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
90 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
91 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
92 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
93 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
94 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
97 m_printDialogData
.EnablePageNumbers(FALSE
);
99 // Create a suitable device context
103 wxPrintDialog
dialog(parent
, & m_printDialogData
);
104 if (dialog
.ShowModal() == wxID_OK
)
106 dc
= dialog
.GetPrintDC();
107 m_printDialogData
= dialog
.GetPrintData();
112 dc
= new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
116 // May have pressed cancel.
117 if (!dc
|| !dc
->Ok())
123 // on the mac we have always pixels as addressing mode with 72 dpi
125 printout
->SetPPIScreen(72, 72);
126 printout
->SetPPIPrinter(72, 72);
128 // Set printout parameters
134 printout
->SetPageSizePixels((int)w
, (int)h
);
135 dc
->GetSizeMM(&ww
, &hh
);
136 printout
->SetPageSizeMM((int)ww
, (int)hh
);
138 // Create an abort window
141 wxWindow
*win
= CreateAbortWindow(parent
, printout
);
142 wxSafeYield(win
,true);
147 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK
, parent
);
151 sm_abortWindow
= win
;
152 sm_abortWindow
->Show(TRUE
);
153 wxSafeYield(win
,true);
155 printout
->OnBeginPrinting();
157 bool keepGoing
= TRUE
;
160 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
162 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
165 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK
, parent
);
172 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
184 GetPort( &thePort
) ;
185 wxSafeYield(win
,true);
189 keepGoing
= printout
->OnPrintPage(pn
);
193 printout
->OnEndDocument();
196 printout
->OnEndPrinting();
200 sm_abortWindow
->Show(FALSE
);
201 delete sm_abortWindow
;
202 sm_abortWindow
= NULL
;
212 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
214 wxDC
* dc
= (wxDC
*) NULL
;
216 wxPrintDialog
dialog(parent
, & m_printDialogData
);
217 int ret
= dialog
.ShowModal();
221 dc
= dialog
.GetPrintDC();
222 m_printDialogData
= dialog
.GetPrintDialogData();
228 bool wxMacPrinter::Setup(wxWindow
*parent
)
230 wxPrintDialog
dialog(parent
, & m_printDialogData
);
231 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
233 int ret
= dialog
.ShowModal();
237 m_printDialogData
= dialog
.GetPrintDialogData();
240 return (ret
== wxID_OK
);
247 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
248 wxPrintout
*printoutForPrinting
,
249 wxPrintDialogData
*data
)
250 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
255 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
256 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
261 wxMacPrintPreview::~wxMacPrintPreview(void)
265 bool wxMacPrintPreview::Print(bool interactive
)
267 if (!m_printPrintout
)
269 wxMacPrinter
printer(&m_printDialogData
);
270 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
273 void wxMacPrintPreview::DetermineScaling(void)
275 int screenWidth
, screenHeight
;
276 wxDisplaySize( &screenWidth
, &screenHeight
) ;
278 m_previewPrintout
->SetPPIScreen( 72 , 72 ) ;
279 m_previewPrintout
->SetPPIPrinter( 72 , 72 ) ;
280 m_previewPrintout
->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) );
281 m_previewPrintout
->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
282 m_pageWidth
= 8 * 72 ;
283 m_pageHeight
= 11 * 72 ;
286 // Get a device context for the currently selected printer
287 wxPrinterDC
printerDC(m_printDialogData
.GetPrintData());
292 printerDC
.GetSizeMM(&ww
, &hh
);
293 printerDC
.GetSize( &x
, &y
) ;
294 m_previewPrintout
->SetPageSizeMM((int)ww
, (int)hh
);
295 m_previewPrintout
->SetPageSizePixels( x
, y
) ;
304 // At 100%, the page should look about page-size on the screen.
305 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
306 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);