]>
Commit | Line | Data |
---|---|---|
72e7876b | 1 | ///////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/mac/carbon/printwin.cpp |
72e7876b SC |
3 | // Purpose: wxMacPrinter framework |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
670f9935 | 9 | // Licence: wxWindows licence |
72e7876b SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
72e7876b SC |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
179e085f RN |
15 | #if wxUSE_PRINTING_ARCHITECTURE |
16 | ||
72e7876b | 17 | #ifdef __BORLANDC__ |
670f9935 | 18 | #pragma hdrstop |
72e7876b SC |
19 | #endif |
20 | ||
72e7876b | 21 | #ifndef WX_PRECOMP |
670f9935 WS |
22 | #include "wx/utils.h" |
23 | #include "wx/dc.h" | |
24 | #include "wx/app.h" | |
25 | #include "wx/msgdlg.h" | |
6d50343d | 26 | #include "wx/dcprint.h" |
18680f86 | 27 | #include "wx/math.h" |
72e7876b SC |
28 | #endif |
29 | ||
746d7582 | 30 | #include "wx/mac/uma.h" |
76a5e5d2 | 31 | |
72e7876b | 32 | #include "wx/mac/printmac.h" |
746d7582 SC |
33 | #include "wx/mac/private/print.h" |
34 | ||
72e7876b | 35 | #include "wx/printdlg.h" |
08680429 | 36 | #include "wx/mac/printdlg.h" |
72e7876b SC |
37 | |
38 | #include <stdlib.h> | |
39 | ||
dc7ccb9c | 40 | IMPLEMENT_DYNAMIC_CLASS(wxMacCarbonPrintData, wxPrintNativeDataBase) |
72e7876b SC |
41 | IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase) |
42 | IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase) | |
72e7876b | 43 | |
b7cacb43 | 44 | bool wxMacCarbonPrintData::IsOk() const |
746d7582 | 45 | { |
dc7ccb9c | 46 | return (m_macPageFormat != kPMNoPageFormat) && (m_macPrintSettings != kPMNoPrintSettings) && (m_macPrintSession != kPMNoReference); |
746d7582 | 47 | } |
746d7582 SC |
48 | wxMacCarbonPrintData::wxMacCarbonPrintData() |
49 | { | |
50 | m_macPageFormat = kPMNoPageFormat; | |
51 | m_macPrintSettings = kPMNoPrintSettings; | |
52 | m_macPrintSession = kPMNoReference ; | |
53 | ValidateOrCreate() ; | |
54 | } | |
55 | ||
56 | wxMacCarbonPrintData::~wxMacCarbonPrintData() | |
57 | { | |
58 | if (m_macPageFormat != kPMNoPageFormat) | |
59 | { | |
60 | (void)PMRelease(m_macPageFormat); | |
61 | m_macPageFormat = kPMNoPageFormat; | |
62 | } | |
63 | ||
64 | if (m_macPrintSettings != kPMNoPrintSettings) | |
65 | { | |
66 | (void)PMRelease(m_macPrintSettings); | |
67 | m_macPrintSettings = kPMNoPrintSettings; | |
68 | } | |
670f9935 | 69 | |
746d7582 SC |
70 | if ( m_macPrintSession != kPMNoReference ) |
71 | { | |
72 | (void)PMRelease(m_macPrintSession); | |
73 | m_macPrintSession = kPMNoReference; | |
74 | } | |
75 | } | |
76 | ||
670f9935 | 77 | void wxMacCarbonPrintData::ValidateOrCreate() |
746d7582 SC |
78 | { |
79 | OSStatus err = noErr ; | |
80 | if ( m_macPrintSession == kPMNoReference ) | |
81 | { | |
82 | err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ; | |
83 | } | |
84 | // Set up a valid PageFormat object. | |
85 | if ( m_macPageFormat == kPMNoPageFormat) | |
86 | { | |
87 | err = PMCreatePageFormat((PMPageFormat *) &m_macPageFormat); | |
670f9935 | 88 | |
746d7582 SC |
89 | // Note that PMPageFormat is not session-specific, but calling |
90 | // PMSessionDefaultPageFormat assigns values specific to the printer | |
91 | // associated with the current printing session. | |
92 | if ((err == noErr) && | |
93 | ( m_macPageFormat != kPMNoPageFormat)) | |
94 | { | |
95 | err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession, | |
96 | (PMPageFormat) m_macPageFormat); | |
97 | } | |
98 | } | |
99 | else | |
100 | { | |
101 | err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession, | |
102 | (PMPageFormat) m_macPageFormat, | |
103 | kPMDontWantBoolean); | |
104 | } | |
670f9935 | 105 | |
746d7582 SC |
106 | // Set up a valid PrintSettings object. |
107 | if ( m_macPrintSettings == kPMNoPrintSettings) | |
108 | { | |
109 | err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings); | |
670f9935 | 110 | |
746d7582 SC |
111 | // Note that PMPrintSettings is not session-specific, but calling |
112 | // PMSessionDefaultPrintSettings assigns values specific to the printer | |
113 | // associated with the current printing session. | |
114 | if ((err == noErr) && | |
115 | ( m_macPrintSettings != kPMNoPrintSettings)) | |
116 | { | |
117 | err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession, | |
118 | (PMPrintSettings) m_macPrintSettings); | |
119 | } | |
120 | } | |
121 | else | |
122 | { | |
123 | err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession, | |
124 | (PMPrintSettings) m_macPrintSettings, | |
125 | kPMDontWantBoolean); | |
126 | } | |
127 | } | |
128 | ||
dc7ccb9c | 129 | bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data ) |
746d7582 SC |
130 | { |
131 | ValidateOrCreate() ; | |
dc7ccb9c SC |
132 | PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ; |
133 | PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? | |
746d7582 SC |
134 | kPMLandscape : kPMPortrait , false ) ; |
135 | // collate cannot be set | |
136 | #if 0 // not yet tested | |
670f9935 | 137 | if ( !m_printerName.empty() ) |
a9412f8f | 138 | PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ; |
746d7582 | 139 | #endif |
4f74e0d1 | 140 | #ifndef __LP64__ |
746d7582 SC |
141 | PMColorMode color ; |
142 | PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ; | |
dc7ccb9c | 143 | if ( data.GetColour() ) |
746d7582 SC |
144 | { |
145 | if ( color == kPMBlackAndWhite ) | |
146 | PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ; | |
147 | } | |
148 | else | |
149 | PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ; | |
4f74e0d1 | 150 | #endif |
670f9935 | 151 | |
746d7582 SC |
152 | // PMDuplexMode not yet accessible via API |
153 | // PMQualityMode not yet accessible via API | |
154 | // todo paperSize | |
4f74e0d1 | 155 | |
8b285841 SC |
156 | PMResolution res; |
157 | PMPrinter printer; | |
8b285841 | 158 | PMSessionGetCurrentPrinter(m_macPrintSession, &printer); |
4f74e0d1 SC |
159 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 |
160 | PMPrinterGetOutputResolution( printer, | |
161 | (PMPrintSettings) m_macPrintSettings, &res) ; | |
162 | // TODO transfer ? into page format ? | |
163 | #else | |
164 | PMTag tag = kPMMaxSquareResolution; | |
8b285841 SC |
165 | PMPrinterGetPrinterResolution(printer, tag, &res); |
166 | PMSetResolution((PMPageFormat) m_macPageFormat, &res); | |
4f74e0d1 | 167 | #endif |
aee23798 SC |
168 | // after setting the new resolution the format has to be updated, otherwise the page rect remains |
169 | // at the 'old' scaling | |
170 | PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession, | |
171 | (PMPageFormat) m_macPageFormat, | |
172 | kPMDontWantBoolean) ; | |
8b285841 | 173 | |
dc7ccb9c | 174 | return true ; |
746d7582 SC |
175 | } |
176 | ||
dc7ccb9c | 177 | bool wxMacCarbonPrintData::TransferTo( wxPrintData &data ) |
746d7582 SC |
178 | { |
179 | OSStatus err = noErr ; | |
670f9935 | 180 | |
746d7582 SC |
181 | UInt32 copies ; |
182 | err = PMGetCopies( m_macPrintSettings , &copies ) ; | |
183 | if ( err == noErr ) | |
670f9935 WS |
184 | data.SetNoCopies( copies ) ; |
185 | ||
746d7582 SC |
186 | PMOrientation orientation ; |
187 | err = PMGetOrientation( m_macPageFormat , &orientation ) ; | |
188 | if ( err == noErr ) | |
189 | { | |
190 | if ( orientation == kPMPortrait || orientation == kPMReversePortrait ) | |
dc7ccb9c | 191 | data.SetOrientation( wxPORTRAIT ); |
746d7582 | 192 | else |
dc7ccb9c | 193 | data.SetOrientation( wxLANDSCAPE ); |
746d7582 SC |
194 | } |
195 | ||
196 | // collate cannot be set | |
197 | #if 0 | |
198 | { | |
199 | wxMacCFStringHolder name ; | |
200 | PMPrinter printer ; | |
201 | PMSessionGetCurrentPrinter( m_macPrintSession , | |
202 | &printer ) ; | |
203 | m_printerName = name.AsString() ; | |
204 | } | |
205 | #endif | |
670f9935 | 206 | |
4f74e0d1 | 207 | #ifndef __LP64__ |
746d7582 SC |
208 | PMColorMode color ; |
209 | err = PMGetColorMode( m_macPrintSettings, &color ) ; | |
210 | if ( err == noErr ) | |
dc7ccb9c | 211 | data.SetColour( !(color == kPMBlackAndWhite) ) ; |
4f74e0d1 | 212 | #endif |
746d7582 SC |
213 | // PMDuplexMode not yet accessible via API |
214 | // PMQualityMode not yet accessible via API | |
215 | // todo paperSize | |
670f9935 | 216 | PMRect rPaper; |
746d7582 SC |
217 | err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper); |
218 | if ( err == noErr ) | |
219 | { | |
dc7ccb9c | 220 | data.SetPaperSize( wxSize ( |
746d7582 SC |
221 | (int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) , |
222 | (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) ) ); | |
223 | } | |
dc7ccb9c | 224 | return true ; |
746d7582 SC |
225 | } |
226 | ||
227 | void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *data ) | |
228 | { | |
229 | // should we setup the page rect here ? | |
230 | // since MacOS sometimes has two same paper rects with different | |
231 | // page rects we could make it roundtrip safe perhaps | |
746d7582 SC |
232 | } |
233 | ||
234 | void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data ) | |
235 | { | |
1aa7b427 | 236 | PMRect rPaper; |
746d7582 SC |
237 | OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper); |
238 | if ( err == noErr ) | |
239 | { | |
240 | PMRect rPage ; | |
241 | err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ; | |
242 | if ( err == noErr ) | |
243 | { | |
244 | data->SetMinMarginTopLeft( wxPoint ( | |
670f9935 WS |
245 | (int)(((double) rPage.left - rPaper.left ) * pt2mm) , |
246 | (int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ; | |
247 | ||
248 | data->SetMinMarginBottomRight( wxPoint ( | |
5be55d56 VZ |
249 | (wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm), |
250 | (wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ; | |
dc7ccb9c SC |
251 | |
252 | if ( data->GetMarginTopLeft().x < data->GetMinMarginTopLeft().x ) | |
253 | data->SetMarginTopLeft( wxPoint( data->GetMinMarginTopLeft().x , | |
254 | data->GetMarginTopLeft().y ) ) ; | |
255 | ||
256 | if ( data->GetMarginBottomRight().x < data->GetMinMarginBottomRight().x ) | |
257 | data->SetMarginBottomRight( wxPoint( data->GetMinMarginBottomRight().x , | |
258 | data->GetMarginBottomRight().y ) ); | |
259 | ||
260 | if ( data->GetMarginTopLeft().y < data->GetMinMarginTopLeft().y ) | |
261 | data->SetMarginTopLeft( wxPoint( data->GetMarginTopLeft().x , data->GetMinMarginTopLeft().y ) ); | |
262 | ||
263 | if ( data->GetMarginBottomRight().y < data->GetMinMarginBottomRight().y ) | |
264 | data->SetMarginBottomRight( wxPoint( data->GetMarginBottomRight().x , | |
265 | data->GetMinMarginBottomRight().y) ); | |
670f9935 WS |
266 | } |
267 | } | |
746d7582 SC |
268 | } |
269 | ||
270 | void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data ) | |
271 | { | |
272 | UInt32 minPage , maxPage ; | |
273 | PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ; | |
274 | data->SetMinPage( minPage ) ; | |
275 | data->SetMaxPage( maxPage ) ; | |
276 | UInt32 copies ; | |
277 | PMGetCopies( m_macPrintSettings , &copies ) ; | |
278 | data->SetNoCopies( copies ) ; | |
279 | UInt32 from , to ; | |
280 | PMGetFirstPage( m_macPrintSettings , &from ) ; | |
281 | PMGetLastPage( m_macPrintSettings , &to ) ; | |
34a4e912 SC |
282 | if ( to >= 0x7FFFFFFF ) // due to an OS Bug we don't get back kPMPrintAllPages |
283 | { | |
284 | data->SetAllPages( true ) ; | |
285 | // This means all pages, more or less | |
286 | data->SetFromPage(1); | |
287 | data->SetToPage(32000); | |
288 | } | |
289 | else | |
290 | { | |
291 | data->SetFromPage( from ) ; | |
292 | data->SetToPage( to ) ; | |
293 | data->SetAllPages( false ); | |
294 | } | |
746d7582 SC |
295 | } |
296 | ||
297 | void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data ) | |
298 | { | |
299 | PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ; | |
300 | PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ; | |
301 | PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ; | |
b386cd7a | 302 | |
34a4e912 | 303 | if (data->GetAllPages() || data->GetFromPage() == 0) |
1aa7b427 DS |
304 | PMSetLastPage( m_macPrintSettings , (UInt32) kPMPrintAllPages, true ) ; |
305 | else | |
306 | PMSetLastPage( m_macPrintSettings , (UInt32) data->GetToPage() , false ) ; | |
746d7582 SC |
307 | } |
308 | ||
72e7876b | 309 | /* |
e40298d5 JS |
310 | * Printer |
311 | */ | |
312 | ||
72e7876b | 313 | wxMacPrinter::wxMacPrinter(wxPrintDialogData *data): |
e40298d5 | 314 | wxPrinterBase(data) |
72e7876b SC |
315 | { |
316 | } | |
317 | ||
318 | wxMacPrinter::~wxMacPrinter(void) | |
319 | { | |
320 | } | |
321 | ||
322 | bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) | |
323 | { | |
1aa7b427 | 324 | sm_abortIt = false; |
e40298d5 | 325 | sm_abortWindow = NULL; |
1aa7b427 | 326 | |
e40298d5 | 327 | if (!printout) |
1aa7b427 DS |
328 | return false; |
329 | ||
330 | printout->SetIsPreview(false); | |
d2b354f9 JS |
331 | if (m_printDialogData.GetMinPage() < 1) |
332 | m_printDialogData.SetMinPage(1); | |
333 | if (m_printDialogData.GetMaxPage() < 1) | |
334 | m_printDialogData.SetMaxPage(9999); | |
335 | ||
670f9935 | 336 | // Create a suitable device context |
f415cab9 | 337 | wxPrinterDC *dc = NULL; |
e40298d5 JS |
338 | if (prompt) |
339 | { | |
f415cab9 | 340 | wxMacPrintDialog dialog(parent, & m_printDialogData); |
2f1ae414 | 341 | if (dialog.ShowModal() == wxID_OK) |
e40298d5 | 342 | { |
f415cab9 JS |
343 | dc = wxDynamicCast(dialog.GetPrintDC(), wxPrinterDC); |
344 | wxASSERT(dc); | |
ffcd5195 | 345 | m_printDialogData = dialog.GetPrintDialogData(); |
e40298d5 JS |
346 | } |
347 | } | |
348 | else | |
72e7876b | 349 | { |
e40298d5 | 350 | dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ; |
72e7876b | 351 | } |
1aa7b427 | 352 | |
e40298d5 JS |
353 | // May have pressed cancel. |
354 | if (!dc || !dc->Ok()) | |
72e7876b | 355 | { |
1aa7b427 DS |
356 | if (dc) |
357 | delete dc; | |
358 | return false; | |
72e7876b | 359 | } |
1aa7b427 | 360 | |
e40298d5 | 361 | // on the mac we have always pixels as addressing mode with 72 dpi |
e40298d5 | 362 | printout->SetPPIScreen(72, 72); |
8b285841 SC |
363 | PMResolution res; |
364 | wxMacCarbonPrintData* nativeData = (wxMacCarbonPrintData*) | |
365 | (m_printDialogData.GetPrintData().GetNativeData()); | |
4f74e0d1 SC |
366 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 |
367 | PMPrinter printer; | |
368 | PMSessionGetCurrentPrinter(nativeData->m_macPrintSession, &printer); | |
369 | PMPrinterGetOutputResolution( printer, nativeData->m_macPrintSettings, &res) ; | |
370 | #else | |
8b285841 | 371 | PMGetResolution((PMPageFormat) (nativeData->m_macPageFormat), &res); |
4f74e0d1 | 372 | #endif |
8b285841 | 373 | printout->SetPPIPrinter(int(res.hRes), int(res.vRes)); |
1aa7b427 DS |
374 | |
375 | // Set printout parameters | |
e40298d5 | 376 | printout->SetDC(dc); |
1aa7b427 | 377 | |
e40298d5 | 378 | int w, h; |
e40298d5 JS |
379 | dc->GetSize(&w, &h); |
380 | printout->SetPageSizePixels((int)w, (int)h); | |
f415cab9 JS |
381 | printout->SetPaperRectPixels(dc->GetPaperRect()); |
382 | wxCoord mw, mh; | |
383 | dc->GetSizeMM(&mw, &mh); | |
384 | printout->SetPageSizeMM((int)mw, (int)mh); | |
1aa7b427 | 385 | |
e40298d5 JS |
386 | // Create an abort window |
387 | wxBeginBusyCursor(); | |
1aa7b427 | 388 | |
d2b354f9 | 389 | printout->OnPreparePrinting(); |
1aa7b427 | 390 | |
d2b354f9 JS |
391 | // Get some parameters from the printout, if defined |
392 | int fromPage, toPage; | |
393 | int minPage, maxPage; | |
394 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
1aa7b427 | 395 | |
d2b354f9 JS |
396 | if (maxPage == 0) |
397 | { | |
398 | wxEndBusyCursor(); | |
1aa7b427 | 399 | return false; |
d2b354f9 | 400 | } |
1aa7b427 | 401 | |
d2b354f9 JS |
402 | // Only set min and max, because from and to have been |
403 | // set by the user | |
404 | m_printDialogData.SetMinPage(minPage); | |
405 | m_printDialogData.SetMaxPage(maxPage); | |
1aa7b427 | 406 | |
e40298d5 JS |
407 | wxWindow *win = CreateAbortWindow(parent, printout); |
408 | wxSafeYield(win,true); | |
1aa7b427 | 409 | |
e40298d5 JS |
410 | if (!win) |
411 | { | |
412 | wxEndBusyCursor(); | |
427ff662 | 413 | wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent); |
e40298d5 | 414 | delete dc; |
1aa7b427 DS |
415 | |
416 | return false; | |
e40298d5 | 417 | } |
1aa7b427 | 418 | |
e40298d5 | 419 | sm_abortWindow = win; |
1aa7b427 | 420 | sm_abortWindow->Show(true); |
e40298d5 | 421 | wxSafeYield(win,true); |
1aa7b427 | 422 | |
e40298d5 | 423 | printout->OnBeginPrinting(); |
1aa7b427 DS |
424 | |
425 | bool keepGoing = true; | |
426 | ||
e40298d5 JS |
427 | int copyCount; |
428 | for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++) | |
429 | { | |
430 | if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage())) | |
431 | { | |
432 | wxEndBusyCursor(); | |
427ff662 | 433 | wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent); |
e40298d5 JS |
434 | break; |
435 | } | |
436 | if (sm_abortIt) | |
437 | break; | |
1aa7b427 | 438 | |
e40298d5 | 439 | int pn; |
670f9935 | 440 | for (pn = m_printDialogData.GetFromPage(); |
1aa7b427 | 441 | keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn); |
e40298d5 JS |
442 | pn++) |
443 | { | |
444 | if (sm_abortIt) | |
445 | { | |
1aa7b427 | 446 | keepGoing = false; |
e40298d5 JS |
447 | break; |
448 | } | |
449 | else | |
450 | { | |
5c45e86b SC |
451 | #if TARGET_CARBON |
452 | if ( UMAGetSystemVersion() >= 0x1000 ) | |
453 | #endif | |
454 | { | |
4f74e0d1 | 455 | #if !wxMAC_USE_CORE_GRAPHICS |
5c45e86b SC |
456 | GrafPtr thePort ; |
457 | GetPort( &thePort ) ; | |
4f74e0d1 | 458 | #endif |
5c45e86b | 459 | wxSafeYield(win,true); |
4f74e0d1 | 460 | #if !wxMAC_USE_CORE_GRAPHICS |
5c45e86b | 461 | SetPort( thePort ) ; |
4f74e0d1 | 462 | #endif |
5c45e86b | 463 | } |
e40298d5 JS |
464 | dc->StartPage(); |
465 | keepGoing = printout->OnPrintPage(pn); | |
466 | dc->EndPage(); | |
467 | } | |
468 | } | |
469 | printout->OnEndDocument(); | |
470 | } | |
670f9935 | 471 | |
e40298d5 | 472 | printout->OnEndPrinting(); |
670f9935 | 473 | |
e40298d5 JS |
474 | if (sm_abortWindow) |
475 | { | |
1aa7b427 | 476 | sm_abortWindow->Show(false); |
e40298d5 JS |
477 | delete sm_abortWindow; |
478 | sm_abortWindow = NULL; | |
479 | } | |
670f9935 | 480 | |
e40298d5 | 481 | wxEndBusyCursor(); |
670f9935 | 482 | |
e40298d5 | 483 | delete dc; |
670f9935 | 484 | |
1aa7b427 | 485 | return true; |
72e7876b SC |
486 | } |
487 | ||
488 | wxDC* wxMacPrinter::PrintDialog(wxWindow *parent) | |
489 | { | |
490 | wxDC* dc = (wxDC*) NULL; | |
670f9935 | 491 | |
72e7876b SC |
492 | wxPrintDialog dialog(parent, & m_printDialogData); |
493 | int ret = dialog.ShowModal(); | |
670f9935 | 494 | |
72e7876b SC |
495 | if (ret == wxID_OK) |
496 | { | |
497 | dc = dialog.GetPrintDC(); | |
498 | m_printDialogData = dialog.GetPrintDialogData(); | |
499 | } | |
670f9935 | 500 | |
72e7876b SC |
501 | return dc; |
502 | } | |
503 | ||
504 | bool wxMacPrinter::Setup(wxWindow *parent) | |
505 | { | |
04a014a5 | 506 | #if 0 |
72e7876b | 507 | wxPrintDialog dialog(parent, & m_printDialogData); |
1aa7b427 | 508 | dialog.GetPrintDialogData().SetSetupDialog(true); |
670f9935 | 509 | |
72e7876b | 510 | int ret = dialog.ShowModal(); |
670f9935 | 511 | |
72e7876b | 512 | if (ret == wxID_OK) |
72e7876b | 513 | m_printDialogData = dialog.GetPrintDialogData(); |
670f9935 | 514 | |
72e7876b | 515 | return (ret == wxID_OK); |
04a014a5 | 516 | #endif |
1aa7b427 | 517 | |
04a014a5 | 518 | return wxID_CANCEL; |
72e7876b SC |
519 | } |
520 | ||
521 | /* | |
e40298d5 JS |
522 | * Print preview |
523 | */ | |
72e7876b SC |
524 | |
525 | wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, | |
e40298d5 JS |
526 | wxPrintout *printoutForPrinting, |
527 | wxPrintDialogData *data) | |
528 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
72e7876b SC |
529 | { |
530 | DetermineScaling(); | |
531 | } | |
532 | ||
533 | wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data): | |
e40298d5 | 534 | wxPrintPreviewBase(printout, printoutForPrinting, data) |
72e7876b | 535 | { |
e40298d5 | 536 | DetermineScaling(); |
72e7876b SC |
537 | } |
538 | ||
539 | wxMacPrintPreview::~wxMacPrintPreview(void) | |
540 | { | |
541 | } | |
542 | ||
543 | bool wxMacPrintPreview::Print(bool interactive) | |
544 | { | |
e40298d5 | 545 | if (!m_printPrintout) |
1aa7b427 DS |
546 | return false; |
547 | ||
e40298d5 JS |
548 | wxMacPrinter printer(&m_printDialogData); |
549 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
72e7876b SC |
550 | } |
551 | ||
552 | void wxMacPrintPreview::DetermineScaling(void) | |
553 | { | |
e40298d5 JS |
554 | int screenWidth , screenHeight ; |
555 | wxDisplaySize( &screenWidth , &screenHeight ) ; | |
670f9935 | 556 | |
aee23798 SC |
557 | wxSize ppiScreen( 72 , 72 ) ; |
558 | wxSize ppiPrinter( 72 , 72 ) ; | |
559 | ||
f415cab9 | 560 | // Note that with Leopard, screen dpi=72 is no longer a given |
aee23798 SC |
561 | m_previewPrintout->SetPPIScreen( ppiScreen.x , ppiScreen.y ) ; |
562 | ||
f415cab9 | 563 | wxCoord w , h ; |
aee23798 | 564 | wxCoord ww, hh; |
f415cab9 | 565 | wxRect paperRect; |
670f9935 | 566 | |
72e7876b | 567 | // Get a device context for the currently selected printer |
2f1ae414 SC |
568 | wxPrinterDC printerDC(m_printDialogData.GetPrintData()); |
569 | if (printerDC.Ok()) | |
72e7876b | 570 | { |
e40298d5 | 571 | printerDC.GetSizeMM(&ww, &hh); |
f415cab9 | 572 | printerDC.GetSize( &w , &h ) ; |
aee23798 | 573 | ppiPrinter = printerDC.GetPPI() ; |
f415cab9 | 574 | paperRect = printerDC.GetPaperRect(); |
e40298d5 JS |
575 | m_isOk = true ; |
576 | } | |
577 | else | |
578 | { | |
aee23798 | 579 | // use some defaults |
f415cab9 JS |
580 | w = 8 * 72 ; |
581 | h = 11 * 72 ; | |
582 | ww = (wxCoord) (w * 25.4 / ppiPrinter.x) ; | |
583 | hh = (wxCoord) (h * 25.4 / ppiPrinter.y) ; | |
584 | paperRect = wxRect(0, 0, w, h); | |
e40298d5 JS |
585 | m_isOk = false ; |
586 | } | |
f415cab9 JS |
587 | m_pageWidth = w; |
588 | m_pageHeight = h; | |
589 | ||
590 | m_previewPrintout->SetPageSizePixels(w , h) ; | |
591 | m_previewPrintout->SetPageSizeMM(ww, hh); | |
592 | m_previewPrintout->SetPaperRectPixels(paperRect); | |
aee23798 | 593 | m_previewPrintout->SetPPIPrinter( ppiPrinter.x , ppiPrinter.y ) ; |
1aa7b427 | 594 | |
f415cab9 JS |
595 | m_previewScaleX = float(ppiScreen.x) / ppiPrinter.x; |
596 | m_previewScaleY = float(ppiScreen.y) / ppiPrinter.y; | |
72e7876b | 597 | } |
179e085f RN |
598 | |
599 | #endif |