]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/printmac.cpp
33506c4548f02f6ddc0a364edcbb096cb5feedae
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/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
);
147 wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK
, parent
);
151 sm_abortWindow
= win
;
152 sm_abortWindow
->Show(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("Could not start printing.", "Print Error", wxOK
, parent
);
172 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
183 GetPort( &thePort
) ;
188 keepGoing
= printout
->OnPrintPage(pn
);
192 printout
->OnEndDocument();
195 printout
->OnEndPrinting();
199 sm_abortWindow
->Show(FALSE
);
200 delete sm_abortWindow
;
201 sm_abortWindow
= NULL
;
211 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
213 wxDC
* dc
= (wxDC
*) NULL
;
215 wxPrintDialog
dialog(parent
, & m_printDialogData
);
216 int ret
= dialog
.ShowModal();
220 dc
= dialog
.GetPrintDC();
221 m_printDialogData
= dialog
.GetPrintDialogData();
227 bool wxMacPrinter::Setup(wxWindow
*parent
)
229 wxPrintDialog
dialog(parent
, & m_printDialogData
);
230 dialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
232 int ret
= dialog
.ShowModal();
236 m_printDialogData
= dialog
.GetPrintDialogData();
239 return (ret
== wxID_OK
);
246 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
247 wxPrintout
*printoutForPrinting
,
248 wxPrintDialogData
*data
)
249 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
254 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
255 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
260 wxMacPrintPreview::~wxMacPrintPreview(void)
264 bool wxMacPrintPreview::Print(bool interactive
)
266 if (!m_printPrintout
)
268 wxMacPrinter
printer(&m_printDialogData
);
269 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
272 void wxMacPrintPreview::DetermineScaling(void)
274 int screenWidth
, screenHeight
;
275 wxDisplaySize( &screenWidth
, &screenHeight
) ;
277 m_previewPrintout
->SetPPIScreen( 72 , 72 ) ;
278 m_previewPrintout
->SetPPIPrinter( 72 , 72 ) ;
279 m_previewPrintout
->SetPageSizeMM( 8 * 25.6 , 11 * 25.6 ) ;
280 m_previewPrintout
->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
281 m_pageWidth
= 8 * 72 ;
282 m_pageHeight
= 11 * 72 ;
285 // Get a device context for the currently selected printer
286 wxPrinterDC
printerDC(m_printDialogData
.GetPrintData());
291 printerDC
.GetSizeMM(&ww
, &hh
);
292 printerDC
.GetSize( &x
, &y
) ;
293 m_previewPrintout
->SetPageSizeMM((int)ww
, (int)hh
);
294 m_previewPrintout
->SetPageSizePixels( x
, y
) ;
300 // At 100%, the page should look about page-size on the screen.
301 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
302 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);