]>
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 #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
);
149 sm_abortWindow
= win
;
150 sm_abortWindow
->Show(TRUE
);
153 printout
->OnBeginPrinting();
155 bool keepGoing
= TRUE
;
158 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
160 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
163 wxMessageBox("Could not start printing.", "Print Error", wxOK
, parent
);
170 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
181 GetPort( &thePort
) ;
186 keepGoing
= printout
->OnPrintPage(pn
);
190 printout
->OnEndDocument();
193 printout
->OnEndPrinting();
197 sm_abortWindow
->Show(FALSE
);
198 delete sm_abortWindow
;
199 sm_abortWindow
= NULL
;
209 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
211 wxDC
* dc
= (wxDC
*) NULL
;
213 wxPrintDialog
dialog(parent
, & m_printDialogData
);
214 int ret
= dialog
.ShowModal();
218 dc
= dialog
.GetPrintDC();
219 m_printDialogData
= dialog
.GetPrintDialogData();
225 bool wxMacPrinter::Setup(wxWindow
*parent
)
227 wxPrintDialog
dialog(parent
, & m_printDialogData
);
228 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
230 int ret
= dialog
.ShowModal();
234 m_printDialogData
= dialog
.GetPrintDialogData();
237 return (ret
== wxID_OK
);
244 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
245 wxPrintout
*printoutForPrinting
,
246 wxPrintDialogData
*data
)
247 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
252 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
253 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
258 wxMacPrintPreview::~wxMacPrintPreview(void)
262 bool wxMacPrintPreview::Print(bool interactive
)
264 if (!m_printPrintout
)
266 wxMacPrinter
printer(&m_printDialogData
);
267 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
270 void wxMacPrintPreview::DetermineScaling(void)
272 int screenWidth
, screenHeight
;
273 wxDisplaySize( &screenWidth
, &screenHeight
) ;
275 m_previewPrintout
->SetPPIScreen( 72 , 72 ) ;
276 m_previewPrintout
->SetPPIPrinter( 72 , 72 ) ;
277 m_previewPrintout
->SetPageSizeMM( 8 * 25.6 , 11 * 25.6 ) ;
278 m_previewPrintout
->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
279 m_pageWidth
= 8 * 72 ;
280 m_pageHeight
= 11 * 72 ;
283 // Get a device context for the currently selected printer
284 wxPrinterDC
printerDC(m_printDialogData
.GetPrintData());
289 printerDC
.GetSizeMM(&ww
, &hh
);
290 printerDC
.GetSize( &x
, &y
) ;
291 m_previewPrintout
->SetPageSizeMM((int)ww
, (int)hh
);
292 m_previewPrintout
->SetPageSizePixels( x
, y
) ;
298 // At 100%, the page should look about page-size on the screen.
299 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
300 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);