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"
31 #if defined(TARGET_CARBON) && !defined(__DARWIN__)
32 # if PM_USE_SESSION_APIS
35 # include <PMApplication.h>
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
42 GrafPtr macPrintFormerPort
= NULL
;
44 wxPrinterDC::wxPrinterDC(const wxPrintData
& printdata
)
49 m_printData
= printdata
;
50 m_printData
.ConvertToNative() ;
52 #if TARGET_CARBON && PM_USE_SESSION_APIS
53 err
= UMAPrOpen(&m_macPrintSessionPort
) ;
54 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoData
)
56 err
= UMAPrOpen(NULL
) ;
60 message
.Printf( "Print Error %d", err
) ;
61 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
63 #if TARGET_CARBON && PM_USE_SESSION_APIS
64 UMAPrClose(&m_macPrintSessionPort
) ;
73 if ( ::PrValidate( (THPrint
) m_printData
.m_macPrintSettings
) )
75 ::PrStlDialog( (THPrint
) m_printData
.m_macPrintSettings
) ;
76 // the driver has changed in the mean time, should we pop up a page setup dialog ?
81 message
.Printf( "Print Error %d", err
) ;
82 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
88 ::GetPort( &macPrintFormerPort
) ;
89 m_macPrintSessionPort
= ::PrOpenDoc( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
) ;
93 message
.Printf( "Print Error %d", err
) ;
94 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
101 m_macPort
= (GrafPtr
) m_macPrintSessionPort
;
103 #if PM_USE_SESSION_APIS
104 err
= PMSessionBeginDocument((PMPrintSession
)m_macPrintSessionPort
,
105 (PMPrintSettings
)m_printData
.m_macPrintSettings
,
106 (PMPageFormat
)m_printData
.m_macPageFormat
);
109 m_macPrintSessionPort
= kPMNoReference
;
110 err
= PMBeginDocument(
111 m_printData
.m_macPrintSettings
,
112 m_printData
.m_macPageFormat
,
113 &m_macPrintSessionPort
);
114 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoReference
)
117 message
.Printf( "Print Error %d", err
) ;
118 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
120 #if TARGET_CARBON && PM_USE_SESSION_APIS
121 UMAPrClose(&m_macPrintSessionPort
) ;
129 ::GetPort( (GrafPtr
*)&m_macPort
) ;
132 m_minY
= m_minX
= 0 ;
136 err
= PMGetAdjustedPaperRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPaper
);
139 message
.Printf( "Print Error %d", err
) ;
140 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
142 #if TARGET_CARBON && PM_USE_SESSION_APIS
143 UMAPrClose(&m_macPrintSessionPort
) ;
150 m_maxX
= rPaper
.right
- rPaper
.left
;
151 m_maxY
= rPaper
.bottom
- rPaper
.top
;
153 m_maxX
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.right
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
154 m_maxY
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.bottom
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
158 wxPrinterDC::~wxPrinterDC(void)
165 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
170 if ( (**(THPrint
)m_printData
.m_macPrintSettings
).prJob
.bJDocLoop
== bSpoolLoop
)
173 ::PrPicFile( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
, NULL
, &status
) ;
178 message
.Printf( "Print Error %d", err
) ;
179 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
183 // ::SetPort( macPrintFormerPort ) ;
184 ::SetPort( LMGetWMgrPort() ) ;
189 #if PM_USE_SESSION_APIS
190 err
= PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
192 err
= PMEndDocument(m_macPrintSessionPort
);
196 message
.Printf( "Print Error %d", err
) ;
197 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
200 #if TARGET_CARBON && PM_USE_SESSION_APIS
201 UMAPrClose(&m_macPrintSessionPort
) ;
209 bool wxPrinterDC::StartDoc( const wxString
& WXUNUSED(message
) )
214 void wxPrinterDC::EndDoc(void)
218 void wxPrinterDC::StartPage(void)
223 m_logicalFunction
= wxCOPY
;
224 // m_textAlignment = wxALIGN_TOP_LEFT;
225 m_backgroundMode
= wxTRANSPARENT
;
227 m_textForegroundColour
= *wxBLACK
;
228 m_textBackgroundColour
= *wxWHITE
;
229 m_pen
= *wxBLACK_PEN
;
230 m_font
= *wxNORMAL_FONT
;
231 m_brush
= *wxTRANSPARENT_BRUSH
;
232 m_backgroundBrush
= *wxWHITE_BRUSH
;
234 m_macFontInstalled
= false ;
235 m_macBrushInstalled
= false ;
236 m_macPenInstalled
= false ;
243 PrOpenPage( (TPPrPort
) m_macPrintSessionPort
, NULL
) ;
244 m_macLocalOrigin
.x
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
245 m_macLocalOrigin
.y
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
247 Rect clip
= { -32000 , -32000 , 32000 , 32000 } ;
248 ::ClipRect( &clip
) ;
252 message
.Printf( "Print Error %d", err
) ;
253 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
255 ::PrClosePage( (TPPrPort
) m_macPrintSessionPort
) ;
256 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
258 ::SetPort( macPrintFormerPort
) ;
262 #if PM_USE_SESSION_APIS
263 err
= PMSessionBeginPage((PMPrintSession
)m_macPrintSessionPort
,
264 (PMPageFormat
)m_printData
.m_macPageFormat
,
267 err
= PMBeginPage(m_macPrintSessionPort
, nil
);
271 message
.Printf( "Print Error %d", err
) ;
272 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
274 #if PM_USE_SESSION_APIS
275 PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
276 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
277 UMAPrClose(&m_macPrintSessionPort
) ;
279 PMEndPage(m_macPrintSessionPort
);
280 PMEndDocument(m_macPrintSessionPort
);
283 ::SetPort( macPrintFormerPort
) ;
289 void wxPrinterDC::EndPage(void)
298 PrClosePage( (TPPrPort
) m_macPort
) ;
302 message
.Printf( "Print Error %d", err
) ;
303 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
305 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
307 ::SetPort( macPrintFormerPort
) ;
311 #if PM_USE_SESSION_APIS
312 err
= PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
314 err
= PMEndPage(m_macPrintSessionPort
);
318 message
.Printf( "Print Error %d", err
) ;
319 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
321 #if PM_USE_SESSION_APIS
322 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
323 UMAPrClose(&m_macPrintSessionPort
) ;
325 PMEndDocument(m_macPrintSessionPort
);
328 ::SetPort( macPrintFormerPort
) ;