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
)
52 m_printData
= printdata
;
53 m_printData
.ConvertToNative() ;
55 #if TARGET_CARBON && PM_USE_SESSION_APIS
56 err
= UMAPrOpen(&m_macPrintSessionPort
) ;
57 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoData
)
59 err
= UMAPrOpen(NULL
) ;
63 message
.Printf( "Print Error %ld", err
) ;
64 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
66 #if TARGET_CARBON && PM_USE_SESSION_APIS
67 UMAPrClose(&m_macPrintSessionPort
) ;
76 if ( ::PrValidate( (THPrint
) m_printData
.m_macPrintSettings
) )
78 ::PrStlDialog( (THPrint
) m_printData
.m_macPrintSettings
) ;
79 // the driver has changed in the mean time, should we pop up a page setup dialog ?
84 message
.Printf( "Print Error %ld", err
) ;
85 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
91 ::GetPort( &macPrintFormerPort
) ;
92 m_macPrintSessionPort
= ::PrOpenDoc( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
) ;
96 message
.Printf( "Print Error %ld", err
) ;
97 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
104 m_macPort
= (GrafPtr
) m_macPrintSessionPort
;
106 #if PM_USE_SESSION_APIS
107 err
= PMSessionBeginDocument((PMPrintSession
)m_macPrintSessionPort
,
108 (PMPrintSettings
)m_printData
.m_macPrintSettings
,
109 (PMPageFormat
)m_printData
.m_macPageFormat
);
112 m_macPrintSessionPort
= kPMNoReference
;
113 err
= PMBeginDocument(
114 m_printData
.m_macPrintSettings
,
115 m_printData
.m_macPageFormat
,
116 &m_macPrintSessionPort
);
117 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoReference
)
120 message
.Printf( "Print Error %ld", err
) ;
121 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
123 #if TARGET_CARBON && PM_USE_SESSION_APIS
124 UMAPrClose(&m_macPrintSessionPort
) ;
132 ::GetPort( (GrafPtr
*)&m_macPort
) ;
135 m_minY
= m_minX
= 0 ;
139 err
= PMGetAdjustedPaperRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPaper
);
142 message
.Printf( "Print Error %ld", err
) ;
143 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
145 #if TARGET_CARBON && PM_USE_SESSION_APIS
146 UMAPrClose(&m_macPrintSessionPort
) ;
153 m_maxX
= wxCoord(rPaper
.right
- rPaper
.left
) ;
154 m_maxY
= wxCoord(rPaper
.bottom
- rPaper
.top
);
156 m_maxX
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.right
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
157 m_maxY
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.bottom
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
161 wxPrinterDC::~wxPrinterDC(void)
168 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
173 if ( (**(THPrint
)m_printData
.m_macPrintSettings
).prJob
.bJDocLoop
== bSpoolLoop
)
176 ::PrPicFile( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
, NULL
, &status
) ;
181 message
.Printf( "Print Error %ld", err
) ;
182 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
186 // ::SetPort( macPrintFormerPort ) ;
187 ::SetPort( LMGetWMgrPort() ) ;
192 #if PM_USE_SESSION_APIS
193 err
= PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
195 err
= PMEndDocument(m_macPrintSessionPort
);
199 message
.Printf( "Print Error %ld", err
) ;
200 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
203 #if TARGET_CARBON && PM_USE_SESSION_APIS
204 UMAPrClose(&m_macPrintSessionPort
) ;
212 bool wxPrinterDC::StartDoc( const wxString
& WXUNUSED(message
) )
217 void wxPrinterDC::EndDoc(void)
221 void wxPrinterDC::StartPage(void)
226 m_logicalFunction
= wxCOPY
;
227 // m_textAlignment = wxALIGN_TOP_LEFT;
228 m_backgroundMode
= wxTRANSPARENT
;
230 m_textForegroundColour
= *wxBLACK
;
231 m_textBackgroundColour
= *wxWHITE
;
232 m_pen
= *wxBLACK_PEN
;
233 m_font
= *wxNORMAL_FONT
;
234 m_brush
= *wxTRANSPARENT_BRUSH
;
235 m_backgroundBrush
= *wxWHITE_BRUSH
;
237 m_macFontInstalled
= false ;
238 m_macBrushInstalled
= false ;
239 m_macPenInstalled
= false ;
246 PrOpenPage( (TPPrPort
) m_macPrintSessionPort
, NULL
) ;
247 m_macLocalOrigin
.x
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
248 m_macLocalOrigin
.y
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
250 Rect clip
= { -32000 , -32000 , 32000 , 32000 } ;
251 ::ClipRect( &clip
) ;
255 message
.Printf( "Print Error %ld", err
) ;
256 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
258 ::PrClosePage( (TPPrPort
) m_macPrintSessionPort
) ;
259 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
261 ::SetPort( macPrintFormerPort
) ;
265 #if PM_USE_SESSION_APIS
266 err
= PMSessionBeginPage((PMPrintSession
)m_macPrintSessionPort
,
267 (PMPageFormat
)m_printData
.m_macPageFormat
,
270 err
= PMBeginPage(m_macPrintSessionPort
, nil
);
274 message
.Printf( "Print Error %ld", err
) ;
275 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
277 #if PM_USE_SESSION_APIS
278 PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
279 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
280 UMAPrClose(&m_macPrintSessionPort
) ;
282 PMEndPage(m_macPrintSessionPort
);
283 PMEndDocument(m_macPrintSessionPort
);
286 ::SetPort( macPrintFormerPort
) ;
292 void wxPrinterDC::EndPage(void)
301 PrClosePage( (TPPrPort
) m_macPort
) ;
305 message
.Printf( "Print Error %ld", err
) ;
306 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
308 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
310 ::SetPort( macPrintFormerPort
) ;
314 #if PM_USE_SESSION_APIS
315 err
= PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
317 err
= PMEndPage(m_macPrintSessionPort
);
321 message
.Printf( "Print Error %ld", err
) ;
322 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
324 #if PM_USE_SESSION_APIS
325 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
326 UMAPrClose(&m_macPrintSessionPort
) ;
328 PMEndDocument(m_macPrintSessionPort
);
331 ::SetPort( macPrintFormerPort
) ;