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 !USE_SHARED_LIBRARY
32 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
35 GrafPtr macPrintFormerPort
= NULL
;
37 wxPrinterDC::wxPrinterDC(const wxPrintData
& printdata
)
42 m_printData
= printdata
;
43 m_printData
.ConvertToNative() ;
45 #if TARGET_CARBON && PM_USE_SESSION_APIS
46 err
= UMAPrOpen((PMPrintSession
*)&m_macPrintSessionPort
) ;
47 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoData
)
53 message
.Printf( "Print Error %d", err
) ;
54 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
56 #if TARGET_CARBON && PM_USE_SESSION_APIS
57 UMAPrClose((PMPrintSession
*)&m_macPrintSessionPort
) ;
66 if ( ::PrValidate( (THPrint
) m_printData
.m_macPrintSettings
) )
68 ::PrStlDialog( (THPrint
) m_printData
.m_macPrintSettings
) ;
69 // the driver has changed in the mean time, should we pop up a page setup dialog ?
74 message
.Printf( "Print Error %d", err
) ;
75 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
81 ::GetPort( &macPrintFormerPort
) ;
82 m_macPrintSessionPort
= ::PrOpenDoc( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
) ;
86 message
.Printf( "Print Error %d", err
) ;
87 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
94 m_macPort
= (GrafPtr
) m_macPrintSessionPort
;
96 #if PM_USE_SESSION_APIS
97 err
= PMSessionBeginDocument((PMPrintSession
)m_macPrintSessionPort
,
98 (PMPrintSettings
)m_printData
.m_macPrintSettings
,
99 (PMPageFormat
)m_printData
.m_macPageFormat
);
102 m_macPrintSessionPort
= kPMNoReference
;
103 err
= PMBeginDocument(
104 m_printData
.m_macPrintSettings
,
105 m_printData
.m_macPageFormat
,
106 &m_macPrintSessionPort
);
107 if ( err
!= noErr
|| m_macPrintSessionPort
== kPMNoReference
)
110 message
.Printf( "Print Error %d", err
) ;
111 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
113 #if TARGET_CARBON && PM_USE_SESSION_APIS
114 UMAPrClose((PMPrintSession
*)&m_macPrintSessionPort
) ;
122 ::GetPort( (GrafPtr
*)&m_macPort
) ;
125 m_minY
= m_minX
= 0 ;
129 err
= PMGetAdjustedPaperRect((PMPageFormat
)m_printData
.m_macPageFormat
, &rPaper
);
132 message
.Printf( "Print Error %d", err
) ;
133 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
135 #if TARGET_CARBON && PM_USE_SESSION_APIS
136 UMAPrClose((PMPrintSession
*)&m_macPrintSessionPort
) ;
143 m_maxX
= rPaper
.right
- rPaper
.left
;
144 m_maxY
= rPaper
.bottom
- rPaper
.top
;
146 m_maxX
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.right
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
147 m_maxY
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.bottom
- (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
151 wxPrinterDC::~wxPrinterDC(void)
158 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
163 if ( (**(THPrint
)m_printData
.m_macPrintSettings
).prJob
.bJDocLoop
== bSpoolLoop
)
166 ::PrPicFile( (THPrint
) m_printData
.m_macPrintSettings
, NULL
, NULL
, NULL
, &status
) ;
171 message
.Printf( "Print Error %d", err
) ;
172 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
176 // ::SetPort( macPrintFormerPort ) ;
177 ::SetPort( LMGetWMgrPort() ) ;
182 #if PM_USE_SESSION_APIS
183 err
= PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
185 err
= PMEndDocument(m_macPrintSessionPort
);
189 message
.Printf( "Print Error %d", err
) ;
190 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
193 #if TARGET_CARBON && PM_USE_SESSION_APIS
194 UMAPrClose((PMPrintSession
*)&m_macPrintSessionPort
) ;
202 bool wxPrinterDC::StartDoc( const wxString
& WXUNUSED(message
) )
207 void wxPrinterDC::EndDoc(void)
211 void wxPrinterDC::StartPage(void)
216 m_logicalFunction
= wxCOPY
;
217 // m_textAlignment = wxALIGN_TOP_LEFT;
218 m_backgroundMode
= wxTRANSPARENT
;
220 m_textForegroundColour
= *wxBLACK
;
221 m_textBackgroundColour
= *wxWHITE
;
222 m_pen
= *wxBLACK_PEN
;
223 m_font
= *wxNORMAL_FONT
;
224 m_brush
= *wxTRANSPARENT_BRUSH
;
225 m_backgroundBrush
= *wxWHITE_BRUSH
;
227 m_macFontInstalled
= false ;
228 m_macBrushInstalled
= false ;
229 m_macPenInstalled
= false ;
236 PrOpenPage( (TPPrPort
) m_macPrintSessionPort
, NULL
) ;
237 m_macLocalOrigin
.x
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.left
;
238 m_macLocalOrigin
.y
= (**(THPrint
)m_printData
.m_macPrintSettings
).rPaper
.top
;
240 Rect clip
= { -32000 , -32000 , 32000 , 32000 } ;
241 ::ClipRect( &clip
) ;
245 message
.Printf( "Print Error %d", err
) ;
246 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
248 ::PrClosePage( (TPPrPort
) m_macPrintSessionPort
) ;
249 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
251 ::SetPort( macPrintFormerPort
) ;
255 #if PM_USE_SESSION_APIS
256 err
= PMSessionBeginPage((PMPrintSession
)m_macPrintSessionPort
,
257 (PMPageFormat
)m_printData
.m_macPageFormat
,
260 err
= PMBeginPage(m_macPrintSessionPort
, nil
);
264 message
.Printf( "Print Error %d", err
) ;
265 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
267 #if PM_USE_SESSION_APIS
268 PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
269 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
270 UMAPrClose((PMPrintSession
*)&m_macPrintSessionPort
) ;
272 PMEndPage(m_macPrintSessionPort
);
273 PMEndDocument(m_macPrintSessionPort
);
276 ::SetPort( macPrintFormerPort
) ;
282 void wxPrinterDC::EndPage(void)
291 PrClosePage( (TPPrPort
) m_macPort
) ;
295 message
.Printf( "Print Error %d", err
) ;
296 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
298 ::PrCloseDoc( (TPPrPort
) m_macPrintSessionPort
) ;
300 ::SetPort( macPrintFormerPort
) ;
304 #if PM_USE_SESSION_APIS
305 err
= PMSessionEndPage((PMPrintSession
)m_macPrintSessionPort
);
307 err
= PMEndPage(m_macPrintSessionPort
);
311 message
.Printf( "Print Error %d", err
) ;
312 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
314 #if PM_USE_SESSION_APIS
315 PMSessionEndDocument((PMPrintSession
)m_macPrintSessionPort
);
316 UMAPrClose((PMPrintSession
*)&m_macPrintSessionPort
) ;
318 PMEndDocument(m_macPrintSessionPort
);
321 ::SetPort( macPrintFormerPort
) ;