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(&m_macPrintSession
) ;
47 if ( err
!= noErr
|| m_macPrintSession
== 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(&m_macPrintSession
) ;
66 if ( ::PrValidate( (THPrint
) m_printData
.m_macPrintInfo
) )
68 ::PrStlDialog( (THPrint
) m_printData
.m_macPrintInfo
) ;
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_macPrintPort
= ::PrOpenDoc( (THPrint
) m_printData
.m_macPrintInfo
, NULL
, NULL
) ;
86 message
.Printf( "Print Error %d", err
) ;
87 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
94 m_macPort
= (GrafPtr
) m_macPrintPort
;
96 #if PM_USE_SESSION_APIS
97 err
= PMSessionBeginDocument(m_macPrintSession
,
98 m_printData
.m_macPrintSettings
,
99 m_printData
.m_macPageFormat
);
102 m_macPrintPort
= kPMNoReference
;
103 err
= PMBeginDocument(
104 m_printData
.m_macPrintSettings
,
105 m_printData
.m_macPageFormat
,
107 if ( err
!= noErr
|| m_macPrintPort
== 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(&m_macPrintSession
) ;
122 ::GetPort( &m_macPort
) ;
125 m_minY
= m_minX
= 0 ;
129 err
= PMGetAdjustedPaperRect(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(&m_macPrintSession
) ;
143 m_maxX
= rPaper
.right
- rPaper
.left
;
144 m_maxY
= rPaper
.bottom
- rPaper
.top
;
146 m_maxX
= (**(THPrint
)m_printData
.m_macPrintInfo
).rPaper
.right
- (**(THPrint
)m_printData
.m_macPrintInfo
).rPaper
.left
;
147 m_maxY
= (**(THPrint
)m_printData
.m_macPrintInfo
).rPaper
.bottom
- (**(THPrint
)m_printData
.m_macPrintInfo
).rPaper
.top
;
151 wxPrinterDC::~wxPrinterDC(void)
158 ::PrCloseDoc( (TPPrPort
) m_macPrintPort
) ;
163 if ( (**(THPrint
)m_printData
.m_macPrintInfo
).prJob
.bJDocLoop
== bSpoolLoop
)
166 ::PrPicFile( (THPrint
) m_printData
.m_macPrintInfo
, 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(m_macPrintSession
);
185 err
= PMEndDocument(m_macPrintPort
);
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(&m_macPrintSession
) ;
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_macPrintPort
, NULL
) ;
237 m_macLocalOrigin
.x
= (**(THPrint
)m_printData
.m_macPrintInfo
).rPaper
.left
;
238 m_macLocalOrigin
.y
= (**(THPrint
)m_printData
.m_macPrintInfo
).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_macPrintPort
) ;
249 ::PrCloseDoc( (TPPrPort
) m_macPrintPort
) ;
251 ::SetPort( macPrintFormerPort
) ;
255 #if PM_USE_SESSION_APIS
256 err
= PMSessionBeginPage(m_macPrintSession
,
257 m_printData
.m_macPageFormat
,
260 err
= PMBeginPage(m_macPrintPort
, nil
);
264 message
.Printf( "Print Error %d", err
) ;
265 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
267 #if PM_USE_SESSION_APIS
268 PMSessionEndPage(m_macPrintSession
);
269 PMSessionEndDocument(m_macPrintSession
);
270 UMAPrClose(&m_macPrintSession
) ;
272 PMEndPage(m_macPrintPort
);
273 PMEndDocument(m_macPrintPort
);
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_macPrintPort
) ;
300 ::SetPort( macPrintFormerPort
) ;
304 #if PM_USE_SESSION_APIS
305 err
= PMSessionEndPage(m_macPrintSession
);
307 err
= PMEndPage(m_macPrintPort
);
311 message
.Printf( "Print Error %d", err
) ;
312 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
314 #if PM_USE_SESSION_APIS
315 PMSessionEndDocument(m_macPrintSession
);
316 UMAPrClose(&m_macPrintSession
) ;
318 PMEndDocument(m_macPrintPort
);
321 ::SetPort( macPrintFormerPort
) ;