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( m_printData
.m_macPrintInfo
) )
68 ::PrStlDialog( 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( 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
= (**m_printData
.m_macPrintInfo
).rPaper
.right
- (**m_printData
.m_macPrintInfo
).rPaper
.left
;
147 m_maxY
= (**m_printData
.m_macPrintInfo
).rPaper
.bottom
- (**m_printData
.m_macPrintInfo
).rPaper
.top
;
151 wxPrinterDC::~wxPrinterDC(void)
158 ::PrCloseDoc( m_macPrintPort
) ;
163 if ( (**m_printData
.m_macPrintInfo
).prJob
.bJDocLoop
== bSpoolLoop
)
166 ::PrPicFile( 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( m_macPrintPort
, NULL
) ;
237 m_macLocalOrigin
.h
= (**m_printData
.m_macPrintInfo
).rPaper
.left
;
238 m_macLocalOrigin
.v
= (**m_printData
.m_macPrintInfo
).rPaper
.top
;
240 SetOrigin( - m_macLocalOrigin
.h
, - m_macLocalOrigin
.v
) ;
241 Rect clip
= { -32000 , -32000 , 32000 , 32000 } ;
242 ::ClipRect( &clip
) ;
246 message
.Printf( "Print Error %d", err
) ;
247 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
249 ::PrClosePage( m_macPrintPort
) ;
250 ::PrCloseDoc( m_macPrintPort
) ;
252 ::SetPort( macPrintFormerPort
) ;
256 #if PM_USE_SESSION_APIS
257 err
= PMSessionBeginPage(m_macPrintSession
,
258 m_printData
.m_macPageFormat
,
261 err
= PMBeginPage(m_macPrintPort
, nil
);
265 message
.Printf( "Print Error %d", err
) ;
266 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
268 #if PM_USE_SESSION_APIS
269 PMSessionEndPage(m_macPrintSession
);
270 PMSessionEndDocument(m_macPrintSession
);
271 UMAPrClose(&m_macPrintSession
) ;
273 PMEndPage(m_macPrintPort
);
274 PMEndDocument(m_macPrintPort
);
277 ::SetPort( macPrintFormerPort
) ;
283 void wxPrinterDC::EndPage(void)
292 PrClosePage( (TPrPort
*) m_macPort
) ;
296 message
.Printf( "Print Error %d", err
) ;
297 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
299 ::PrCloseDoc( m_macPrintPort
) ;
301 ::SetPort( macPrintFormerPort
) ;
305 #if PM_USE_SESSION_APIS
306 err
= PMSessionEndPage(m_macPrintSession
);
308 err
= PMEndPage(m_macPrintPort
);
312 message
.Printf( "Print Error %d", err
) ;
313 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
315 #if PM_USE_SESSION_APIS
316 PMSessionEndDocument(m_macPrintSession
);
317 UMAPrClose(&m_macPrintSession
) ;
319 PMEndDocument(m_macPrintPort
);
322 ::SetPort( macPrintFormerPort
) ;