1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrinterDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcprint.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dcprint.h"
27 #include "wx/msgdlg.h"
29 #include "wx/mac/uma.h"
34 #if defined(TARGET_CARBON) && !defined(__DARWIN__)
35 # if PM_USE_SESSION_APIS
38 # include <PMApplication.h>
41 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
45 GrafPtr macPrintFormerPort
= NULL
;
47 wxPrinterDC::wxPrinterDC(const wxPrintData
& printdata
)
49 OSStatus err
= noErr
;
52 m_printData
= printdata
;
53 m_printData
.ConvertToNative() ;
55 #if TARGET_CARBON && PM_USE_SESSION_APIS
56 m_macPrintSessionPort
= printdata
.m_macPrintSession
;
57 PMRetain( m_macPrintSessionPort
) ;
59 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoData
)
61 err
= UMAPrOpen(NULL
) ;
65 message
.Printf( "Print Error %ld", err
) ;
66 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
68 #if TARGET_CARBON && PM_USE_SESSION_APIS
69 PMRelease( m_macPrintSessionPort
) ;
78 if ( ::PrValidate( (THPrint
) m_printData
.m_macPrintSettings
) )
80 // the driver has changed in the mean time, should we pop up a page setup dialog ?
81 if ( !::PrStlDialog( (THPrint
) m_printData
.m_macPrintSettings
) )
91 message
.Printf( "Print Error %ld", err
) ;
92 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
98 ::GetPort( &macPrintFormerPort
) ;
100 m_macPrintSessionPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintSettings , NULL , NULL ) ;
104 message.Printf( "Print Error %ld", err ) ;
105 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
112 m_macPort = (GrafPtr ) m_macPrintSessionPort ;
116 #if PM_USE_SESSION_APIS
117 err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort,
118 (PMPrintSettings)m_printData.m_macPrintSettings,
119 (PMPageFormat)m_printData.m_macPageFormat);
122 m_macPrintSessionPort = kPMNoReference ;
123 err = PMBeginDocument(
124 m_printData.m_macPrintSettings,
125 m_printData.m_macPageFormat,
126 &m_macPrintSessionPort);
127 if ( err != noErr || m_macPrintSessionPort == kPMNoReference )
130 message.Printf( "Print Error %ld", err ) ;
131 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
133 #if TARGET_CARBON && PM_USE_SESSION_APIS
134 PMRelease(&m_macPrintSessionPort) ;
142 ::GetPort( (GrafPtr *)&m_macPort ) ;
146 m_minY
= m_minX
= 0 ;
150 err
= PMGetAdjustedPaperRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPaper
);
153 message
.Printf( "Print Error %ld", err
) ;
154 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
156 #if TARGET_CARBON && PM_USE_SESSION_APIS
157 PMRelease(&m_macPrintSessionPort
) ;
164 m_maxX
= wxCoord(rPaper
.right
- rPaper
.left
) ;
165 m_maxY
= wxCoord(rPaper
.bottom
- rPaper
.top
);
167 m_maxX
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.right
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
168 m_maxY
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.bottom
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
172 wxPrinterDC::~wxPrinterDC(void)
180 ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
185 if ( (**(THPrint)m_printData.m_macPrintSettings).prJob.bJDocLoop == bSpoolLoop )
188 ::PrPicFile( (THPrint) m_printData.m_macPrintSettings , NULL , NULL , NULL , &status ) ;
193 message.Printf( "Print Error %ld", err ) ;
194 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
199 // ::SetPort( macPrintFormerPort ) ;
200 ::SetPort( LMGetWMgrPort() ) ;
206 #if PM_USE_SESSION_APIS
207 err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
209 err = PMEndDocument(m_macPrintSessionPort);
213 message.Printf( "Print Error %ld", err ) ;
214 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
218 #if TARGET_CARBON && PM_USE_SESSION_APIS
219 PMRelease(&m_macPrintSessionPort
) ;
227 bool wxPrinterDC::StartDoc( const wxString
& WXUNUSED(message
) )
229 OSStatus err
= noErr
;
233 m_macPrintSessionPort
= ::PrOpenDoc( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
) ;
237 message
.Printf( "Print Error %d", err
) ;
238 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
245 m_macPort
= (GrafPtr
) m_macPrintSessionPort
;
247 #if PM_USE_SESSION_APIS
248 err
= PMSessionBeginDocument((PMPrintSession
)m_macPrintSessionPort
,
249 (PMPrintSettings
)m_printData
.m_macPrintSettings
,
250 (PMPageFormat
)m_printData
.m_macPageFormat
);
253 m_macPrintSessionPort
= kPMNoReference
;
254 err
= PMBeginDocument(
255 m_printData
.m_macPrintSettings
,
256 m_printData
.m_macPageFormat
,
257 &m_macPrintSessionPort
);
258 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoReference
)
261 message
.Printf( "Print Error %d", err
) ;
262 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
264 #if TARGET_CARBON && PM_USE_SESSION_APIS
265 PMRelease(&m_macPrintSessionPort
) ;
273 ::GetPort( (GrafPtr
*)&m_macPort
) ;
276 m_minY
= m_minX
= 0 ;
280 err
= PMGetAdjustedPaperRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPaper
);
283 message
.Printf( "Print Error %d", err
) ;
284 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
286 #if TARGET_CARBON && PM_USE_SESSION_APIS
287 PMRelease(&m_macPrintSessionPort
) ;
294 m_maxX
= rPaper
.right
- rPaper
.left
;
295 m_maxY
= rPaper
.bottom
- rPaper
.top
;
297 m_maxX
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.right
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
298 m_maxY
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.bottom
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
303 void wxPrinterDC::EndDoc(void)
311 // ::SetPort( macPrintFormerPort ) ;
312 ::SetPort( LMGetWMgrPort() ) ;
317 #if PM_USE_SESSION_APIS
318 err
= PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
320 err
= PMEndDocument(m_macPrintSessionPort
);
324 message
.Printf( "Print Error %d", err
) ;
325 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
332 void wxPrinterDC::StartPage(void)
337 m_logicalFunction
= wxCOPY
;
338 // m_textAlignment = wxALIGN_TOP_LEFT;
339 m_backgroundMode
= wxTRANSPARENT
;
341 m_textForegroundColour
= *wxBLACK
;
342 m_textBackgroundColour
= *wxWHITE
;
343 m_pen
= *wxBLACK_PEN
;
344 m_font
= *wxNORMAL_FONT
;
345 m_brush
= *wxTRANSPARENT_BRUSH
;
346 m_backgroundBrush
= *wxWHITE_BRUSH
;
348 m_macFontInstalled
= false ;
349 m_macBrushInstalled
= false ;
350 m_macPenInstalled
= false ;
357 PrOpenPage( (TPPrPort
) m_macPrintSessionPort
, NULL
) ;
358 m_macLocalOrigin
.x
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
359 m_macLocalOrigin
.y
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
361 Rect clip
= { -32000 , -32000 , 32000 , 32000 } ;
362 ::ClipRect( &clip
) ;
366 message
.Printf( "Print Error %ld", err
) ;
367 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
369 ::PrClosePage( (TPPrPort
) m_macPrintSessionPort
) ;
370 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
372 ::SetPort( macPrintFormerPort
) ;
376 #if PM_USE_SESSION_APIS
377 err
= PMSessionBeginPage((PMPrintSession
)m_macPrintSessionPort
,
378 (PMPageFormat
)m_printData
.m_macPageFormat
,
381 err
= PMBeginPage(m_macPrintSessionPort
, nil
);
385 message
.Printf( "Print Error %ld", err
) ;
386 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
388 #if PM_USE_SESSION_APIS
389 PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
390 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
391 UMAPrClose(&m_macPrintSessionPort
) ;
393 PMEndPage(m_macPrintSessionPort
);
394 PMEndDocument(m_macPrintSessionPort
);
397 ::SetPort( macPrintFormerPort
) ;
402 err
= PMGetAdjustedPaperRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPaper
);
405 m_macLocalOrigin
.x
= rPaper
.left
;
406 m_macLocalOrigin
.y
= rPaper
.top
;
411 void wxPrinterDC::EndPage(void)
420 PrClosePage( (TPPrPort
) m_macPort
) ;
424 message
.Printf( "Print Error %ld", err
) ;
425 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
427 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
429 ::SetPort( macPrintFormerPort
) ;
433 #if PM_USE_SESSION_APIS
434 err
= PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
436 err
= PMEndPage(m_macPrintSessionPort
);
440 message
.Printf( "Print Error %ld", err
) ;
441 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
443 #if PM_USE_SESSION_APIS
444 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
445 UMAPrClose(&m_macPrintSessionPort
) ;
447 PMEndDocument(m_macPrintSessionPort
);
450 ::SetPort( macPrintFormerPort
) ;