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