1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrinterDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
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( wxT("Print Error %ld"), err
) ;
66 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, 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( wxT("Print Error %ld"), err
) ;
92 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
98 ::GetPort( &macPrintFormerPort
) ;
101 m_minY
= m_minX
= 0 ;
105 err
= PMGetAdjustedPageRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPage
);
108 message
.Printf( wxT("Print Error %ld"), err
) ;
109 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
111 #if TARGET_CARBON && PM_USE_SESSION_APIS
112 PMRelease(&m_macPrintSessionPort
) ;
119 m_maxX
= wxCoord(rPage
.right
- rPage
.left
) ;
120 m_maxY
= wxCoord(rPage
.bottom
- rPage
.top
);
122 m_maxX
= (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.right
- (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.left
;
123 m_maxY
= (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.bottom
- (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.top
;
127 wxPrinterDC::~wxPrinterDC(void)
135 ::SetPort( LMGetWMgrPort() ) ;
140 #if TARGET_CARBON && PM_USE_SESSION_APIS
141 PMRelease(&m_macPrintSessionPort
) ;
149 bool wxPrinterDC::StartDoc( const wxString
& WXUNUSED(message
) )
151 OSStatus err
= noErr
;
155 m_macPrintSessionPort
= ::PrOpenDoc( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
) ;
159 message
.Printf( wxT("Print Error %d"), err
) ;
160 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
167 m_macPort
= (GrafPtr
) m_macPrintSessionPort
;
169 #if PM_USE_SESSION_APIS
170 err
= PMSessionBeginDocument((PMPrintSession
)m_macPrintSessionPort
,
171 (PMPrintSettings
)m_printData
.m_macPrintSettings
,
172 (PMPageFormat
)m_printData
.m_macPageFormat
);
175 m_macPrintSessionPort
= kPMNoReference
;
176 err
= PMBeginDocument(
177 m_printData
.m_macPrintSettings
,
178 m_printData
.m_macPageFormat
,
179 &m_macPrintSessionPort
);
180 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoReference
)
183 message
.Printf( wxT("Print Error %d"), err
) ;
184 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
186 #if TARGET_CARBON && PM_USE_SESSION_APIS
187 PMRelease(&m_macPrintSessionPort
) ;
195 ::GetPort( (GrafPtr
*)&m_macPort
) ;
198 m_minY
= m_minX
= 0 ;
202 err
= PMGetAdjustedPageRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPage
);
205 message
.Printf( wxT("Print Error %d"), err
) ;
206 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
208 #if TARGET_CARBON && PM_USE_SESSION_APIS
209 PMRelease(&m_macPrintSessionPort
) ;
216 m_maxX
= rPage
.right
- rPage
.left
;
217 m_maxY
= rPage
.bottom
- rPage
.top
;
219 m_maxX
= (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.right
- (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.left
;
220 m_maxY
= (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.bottom
- (**(THPrint
)m_printData
.m_macPrintSettings
).prInfo
.rPage
.top
;
225 void wxPrinterDC::EndDoc(void)
233 // ::SetPort( macPrintFormerPort ) ;
234 ::SetPort( LMGetWMgrPort() ) ;
239 #if PM_USE_SESSION_APIS
240 err
= PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
242 err
= PMEndDocument(m_macPrintSessionPort
);
246 message
.Printf( wxT("Print Error %d"), err
) ;
247 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
254 void wxPrinterDC::StartPage(void)
259 m_logicalFunction
= wxCOPY
;
260 // m_textAlignment = wxALIGN_TOP_LEFT;
261 m_backgroundMode
= wxTRANSPARENT
;
263 m_textForegroundColour
= *wxBLACK
;
264 m_textBackgroundColour
= *wxWHITE
;
265 m_pen
= *wxBLACK_PEN
;
266 m_font
= *wxNORMAL_FONT
;
267 m_brush
= *wxTRANSPARENT_BRUSH
;
268 m_backgroundBrush
= *wxWHITE_BRUSH
;
270 m_macFontInstalled
= false ;
271 m_macBrushInstalled
= false ;
272 m_macPenInstalled
= false ;
279 PrOpenPage( (TPPrPort
) m_macPrintSessionPort
, NULL
) ;
280 m_macLocalOrigin
.x
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
281 m_macLocalOrigin
.y
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
283 Rect clip
= { -32000 , -32000 , 32000 , 32000 } ;
284 ::ClipRect( &clip
) ;
288 message
.Printf( wxT("Print Error %ld"), err
) ;
289 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
291 ::PrClosePage( (TPPrPort
) m_macPrintSessionPort
) ;
292 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
294 ::SetPort( macPrintFormerPort
) ;
298 #if PM_USE_SESSION_APIS
299 err
= PMSessionBeginPage((PMPrintSession
)m_macPrintSessionPort
,
300 (PMPageFormat
)m_printData
.m_macPageFormat
,
303 err
= PMBeginPage(m_macPrintSessionPort
, nil
);
307 message
.Printf( wxT("Print Error %ld"), err
) ;
308 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
310 #if PM_USE_SESSION_APIS
311 PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
312 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
313 UMAPrClose(&m_macPrintSessionPort
) ;
315 PMEndPage(m_macPrintSessionPort
);
316 PMEndDocument(m_macPrintSessionPort
);
319 ::SetPort( macPrintFormerPort
) ;
324 err
= PMGetAdjustedPageRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPage
);
327 m_macLocalOrigin
.x
= rPage
.left
;
328 m_macLocalOrigin
.y
= rPage
.top
;
333 void wxPrinterDC::EndPage(void)
342 PrClosePage( (TPPrPort
) m_macPort
) ;
346 message
.Printf( wxT("Print Error %ld") , err
) ;
347 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
349 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
351 ::SetPort( macPrintFormerPort
) ;
355 #if PM_USE_SESSION_APIS
356 err
= PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
358 err
= PMEndPage(m_macPrintSessionPort
);
362 message
.Printf( wxT("Print Error %ld"), err
) ;
363 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
) ;
365 #if PM_USE_SESSION_APIS
366 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
367 UMAPrClose(&m_macPrintSessionPort
) ;
369 PMEndDocument(m_macPrintSessionPort
);
372 ::SetPort( macPrintFormerPort
) ;