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 PM_USE_SESSION_APIS
46 err
= UMAPrOpen(&m_macPrintPort
) ;
52 message
.Printf( "Print Error %d", err
) ;
53 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
54 #if PM_USE_SESSION_APIS
55 UMAPrClose(&m_macPrintPort
) ;
62 if ( ::PrValidate( m_printData
.m_macPrintInfo
) )
64 ::PrStlDialog( m_printData
.m_macPrintInfo
) ;
65 // the driver has changed in the mean time, should we pop up a page setup dialog ?
70 message
.Printf( "Print Error %d", err
) ;
71 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
74 ::GetPort( &macPrintFormerPort
) ;
75 m_macPrintPort
= ::PrOpenDoc( m_printData
.m_macPrintInfo
, NULL
, NULL
) ;
79 message
.Printf( "Print Error %d", err
) ;
80 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
84 m_macPort
= (GrafPtr
) m_macPrintPort
;
86 m_macPrintPort
= kPMNoReference
;
87 #if PM_USE_SESSION_APIS
88 err
= PMSessionBeginDocument(
90 m_printData
.m_macPrintSettings
,
91 m_printData
.m_macPageFormat
);
93 err
= PMBeginDocument(
94 m_printData
.m_macPrintSettings
,
95 m_printData
.m_macPageFormat
,
98 if ( err
!= noErr
|| m_macPrintPort
== kPMNoReference
)
100 message
.Printf( "Print Error %d", err
) ;
101 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
102 #if PM_USE_SESSION_APIS
103 UMAPrClose(&m_macPrintPort
) ;
109 ::GetPort( &m_macPort
) ;
112 m_minY
= m_minX
= 0 ;
115 m_maxX
= (**m_printData
.m_macPrintInfo
).rPaper
.right
- (**m_printData
.m_macPrintInfo
).rPaper
.left
;
116 m_maxY
= (**m_printData
.m_macPrintInfo
).rPaper
.bottom
- (**m_printData
.m_macPrintInfo
).rPaper
.top
;
120 wxPrinterDC::~wxPrinterDC(void)
127 ::PrCloseDoc( m_macPrintPort
) ;
132 if ( (**m_printData
.m_macPrintInfo
).prJob
.bJDocLoop
== bSpoolLoop
)
135 ::PrPicFile( m_printData
.m_macPrintInfo
, NULL
, NULL
, NULL
, &status
) ;
140 message
.Printf( "Print Error %d", err
) ;
141 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
145 // ::SetPort( macPrintFormerPort ) ;
146 ::SetPort( LMGetWMgrPort() ) ;
151 #if PM_USE_SESSION_APIS
152 err
= PMSessionEndDocument(m_macPrintPort
);
154 err
= PMEndDocument(m_macPrintPort
);
158 message
.Printf( "Print Error %d", err
) ;
159 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
160 #if PM_USE_SESSION_APIS
161 UMAPrClose(&m_macPrintPort
) ;
166 #if PM_USE_SESSION_APIS
167 UMAPrClose(&m_macPrintPort
) ;
175 bool wxPrinterDC::StartDoc( const wxString
& WXUNUSED(message
) )
180 void wxPrinterDC::EndDoc(void)
184 void wxPrinterDC::StartPage(void)
189 m_logicalFunction
= wxCOPY
;
190 // m_textAlignment = wxALIGN_TOP_LEFT;
191 m_backgroundMode
= wxTRANSPARENT
;
193 m_textForegroundColour
= *wxBLACK
;
194 m_textBackgroundColour
= *wxWHITE
;
195 m_pen
= *wxBLACK_PEN
;
196 m_font
= *wxNORMAL_FONT
;
197 m_brush
= *wxTRANSPARENT_BRUSH
;
198 m_backgroundBrush
= *wxWHITE_BRUSH
;
200 m_macFontInstalled
= false ;
201 m_macBrushInstalled
= false ;
202 m_macPenInstalled
= false ;
209 PrOpenPage( m_macPrintPort
, NULL
) ;
210 m_macLocalOrigin
.h
= (**m_printData
.m_macPrintInfo
).rPaper
.left
;
211 m_macLocalOrigin
.v
= (**m_printData
.m_macPrintInfo
).rPaper
.top
;
213 SetOrigin( - m_macLocalOrigin
.h
, - m_macLocalOrigin
.v
) ;
214 Rect clip
= { -32000 , -32000 , 32000 , 32000 } ;
215 ::ClipRect( &clip
) ;
219 message
.Printf( "Print Error %d", err
) ;
220 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
221 ::PrClosePage( m_macPrintPort
) ;
222 ::PrCloseDoc( m_macPrintPort
) ;
224 ::SetPort( macPrintFormerPort
) ;
228 #if PM_USE_SESSION_APIS
229 err
= PMSessionBeginPage(m_macPrintPort
,
230 m_printData
.m_macPageFormat
,
233 err
= PMBeginPage(m_macPrintPort
, nil
);
237 message
.Printf( "Print Error %d", err
) ;
238 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
239 #if PM_USE_SESSION_APIS
240 PMSessionEndPage(m_macPrintPort
);
241 PMSessionEndDocument(m_macPrintPort
);
242 UMAPrClose(&m_macPrintPort
) ;
244 PMEndPage(m_macPrintPort
);
245 PMEndDocument(m_macPrintPort
);
248 ::SetPort( macPrintFormerPort
) ;
254 void wxPrinterDC::EndPage(void)
263 PrClosePage( (TPrPort
*) m_macPort
) ;
267 message
.Printf( "Print Error %d", err
) ;
268 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
269 ::PrCloseDoc( m_macPrintPort
) ;
271 ::SetPort( macPrintFormerPort
) ;
275 #if PM_USE_SESSION_APIS
276 err
= PMSessionEndPage(m_macPrintPort
);
278 err
= PMEndPage(m_macPrintPort
);
282 message
.Printf( "Print Error %d", err
) ;
283 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
284 #if PM_USE_SESSION_APIS
285 PMSessionEndDocument(m_macPrintPort
);
286 UMAPrClose(&m_macPrintPort
) ;
288 PMEndDocument(m_macPrintPort
);
291 ::SetPort( macPrintFormerPort
) ;