]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcprint.cpp
adjusted for new visible region code
[wxWidgets.git] / src / mac / carbon / dcprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcprint.cpp
3 // Purpose: wxPrinterDC class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "dcprint.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #endif
25
26 #include "wx/dcprint.h"
27 #include "wx/msgdlg.h"
28 #include <math.h>
29 #include "wx/mac/uma.h"
30
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_CLASS(wxPrinterDC, wxDC)
33 #endif
34
35 GrafPtr macPrintFormerPort = NULL ;
36
37 wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
38 {
39 OSStatus err ;
40 wxString message ;
41
42 m_printData = printdata ;
43 m_printData.ConvertToNative() ;
44
45 #if TARGET_CARBON && PM_USE_SESSION_APIS
46 err = UMAPrOpen(&m_macPrintSession) ;
47 if ( err != noErr || m_macPrintSession == kPMNoData )
48 #else
49 err = UMAPrOpen() ;
50 if ( err != noErr )
51 #endif
52 {
53 message.Printf( "Print Error %d", err ) ;
54 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
55 dialog.ShowModal();
56 #if TARGET_CARBON && PM_USE_SESSION_APIS
57 UMAPrClose(&m_macPrintSession) ;
58 #else
59 UMAPrClose() ;
60 #endif
61 m_ok = FALSE;
62 return;
63 }
64
65 #if !TARGET_CARBON
66 if ( ::PrValidate( m_printData.m_macPrintInfo ) )
67 {
68 ::PrStlDialog( m_printData.m_macPrintInfo ) ;
69 // the driver has changed in the mean time, should we pop up a page setup dialog ?
70 }
71 err = PrError() ;
72 if ( err != noErr )
73 {
74 message.Printf( "Print Error %d", err ) ;
75 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
76 dialog.ShowModal();
77 UMAPrClose() ;
78 m_ok = FALSE;
79 return;
80 }
81 ::GetPort( &macPrintFormerPort ) ;
82 m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
83 err = PrError() ;
84 if ( err )
85 {
86 message.Printf( "Print Error %d", err ) ;
87 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
88 dialog.ShowModal();
89 UMAPrClose() ;
90 m_ok = FALSE;
91 return;
92 }
93 // sets current port
94 m_macPort = (GrafPtr ) m_macPrintPort ;
95 #else
96 #if PM_USE_SESSION_APIS
97 err = PMSessionBeginDocument(m_macPrintSession,
98 m_printData.m_macPrintSettings,
99 m_printData.m_macPageFormat);
100 if ( err != noErr )
101 #else
102 m_macPrintPort = kPMNoReference ;
103 err = PMBeginDocument(
104 m_printData.m_macPrintSettings,
105 m_printData.m_macPageFormat,
106 &m_macPrintPort);
107 if ( err != noErr || m_macPrintPort == kPMNoReference )
108 #endif
109 {
110 message.Printf( "Print Error %d", err ) ;
111 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
112 dialog.ShowModal();
113 #if TARGET_CARBON && PM_USE_SESSION_APIS
114 UMAPrClose(&m_macPrintSession) ;
115 #else
116 UMAPrClose() ;
117 #endif
118 m_ok = FALSE;
119 return;
120 }
121 // sets current port
122 ::GetPort( &m_macPort ) ;
123 #endif
124 m_ok = TRUE ;
125 m_minY = m_minX = 0 ;
126 #if TARGET_CARBON
127 PMRect rPaper;
128
129 err = PMGetAdjustedPaperRect(m_printData.m_macPageFormat, &rPaper);
130 if ( err != noErr )
131 {
132 message.Printf( "Print Error %d", err ) ;
133 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
134 dialog.ShowModal();
135 #if TARGET_CARBON && PM_USE_SESSION_APIS
136 UMAPrClose(&m_macPrintSession) ;
137 #else
138 UMAPrClose() ;
139 #endif
140 m_ok = FALSE;
141 return;
142 }
143 m_maxX = rPaper.right - rPaper.left ;
144 m_maxY = rPaper.bottom - rPaper.top ;
145 #else
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 ;
148 #endif
149 }
150
151 wxPrinterDC::~wxPrinterDC(void)
152 {
153 OSStatus err ;
154 wxString message ;
155 #if !TARGET_CARBON
156 if ( m_ok )
157 {
158 ::PrCloseDoc( m_macPrintPort ) ;
159 err = PrError() ;
160
161 if ( err == noErr )
162 {
163 if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
164 {
165 TPrStatus status ;
166 ::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
167 }
168 }
169 else
170 {
171 message.Printf( "Print Error %d", err ) ;
172 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
173 dialog.ShowModal();
174 }
175 ::UMAPrClose() ;
176 // ::SetPort( macPrintFormerPort ) ;
177 ::SetPort( LMGetWMgrPort() ) ;
178 }
179 #else
180 if ( m_ok )
181 {
182 #if PM_USE_SESSION_APIS
183 err = PMSessionEndDocument(m_macPrintSession);
184 #else
185 err = PMEndDocument(m_macPrintPort);
186 #endif
187 if ( err != noErr )
188 {
189 message.Printf( "Print Error %d", err ) ;
190 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
191 dialog.ShowModal();
192 }
193 #if TARGET_CARBON && PM_USE_SESSION_APIS
194 UMAPrClose(&m_macPrintSession) ;
195 #else
196 UMAPrClose() ;
197 #endif
198 }
199 #endif
200 }
201
202 bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
203 {
204 return m_ok ;
205 }
206
207 void wxPrinterDC::EndDoc(void)
208 {
209 }
210
211 void wxPrinterDC::StartPage(void)
212 {
213 if ( !m_ok )
214 return ;
215
216 m_logicalFunction = wxCOPY;
217 // m_textAlignment = wxALIGN_TOP_LEFT;
218 m_backgroundMode = wxTRANSPARENT;
219
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;
226
227 m_macFontInstalled = false ;
228 m_macBrushInstalled = false ;
229 m_macPenInstalled = false ;
230
231
232 OSStatus err ;
233 wxString message ;
234
235 #if !TARGET_CARBON
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 ;
239
240 SetOrigin( - m_macLocalOrigin.h , - m_macLocalOrigin.v ) ;
241 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
242 ::ClipRect( &clip ) ;
243 err = PrError() ;
244 if ( err != noErr )
245 {
246 message.Printf( "Print Error %d", err ) ;
247 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
248 dialog.ShowModal();
249 ::PrClosePage( m_macPrintPort ) ;
250 ::PrCloseDoc( m_macPrintPort ) ;
251 ::UMAPrClose() ;
252 ::SetPort( macPrintFormerPort ) ;
253 m_ok = FALSE ;
254 }
255 #else
256 #if PM_USE_SESSION_APIS
257 err = PMSessionBeginPage(m_macPrintSession,
258 m_printData.m_macPageFormat,
259 nil);
260 #else
261 err = PMBeginPage(m_macPrintPort, nil);
262 #endif
263 if ( err != noErr )
264 {
265 message.Printf( "Print Error %d", err ) ;
266 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
267 dialog.ShowModal();
268 #if PM_USE_SESSION_APIS
269 PMSessionEndPage(m_macPrintSession);
270 PMSessionEndDocument(m_macPrintSession);
271 UMAPrClose(&m_macPrintSession) ;
272 #else
273 PMEndPage(m_macPrintPort);
274 PMEndDocument(m_macPrintPort);
275 UMAPrClose() ;
276 #endif
277 ::SetPort( macPrintFormerPort ) ;
278 m_ok = FALSE ;
279 }
280 #endif
281 }
282
283 void wxPrinterDC::EndPage(void)
284 {
285 if ( !m_ok )
286 return ;
287
288 OSStatus err ;
289 wxString message ;
290
291 #if !TARGET_CARBON
292 PrClosePage( (TPrPort*) m_macPort ) ;
293 err = PrError() ;
294 if ( err != noErr )
295 {
296 message.Printf( "Print Error %d", err ) ;
297 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
298 dialog.ShowModal();
299 ::PrCloseDoc( m_macPrintPort ) ;
300 ::UMAPrClose() ;
301 ::SetPort( macPrintFormerPort ) ;
302 m_ok = FALSE ;
303 }
304 #else
305 #if PM_USE_SESSION_APIS
306 err = PMSessionEndPage(m_macPrintSession);
307 #else
308 err = PMEndPage(m_macPrintPort);
309 #endif
310 if ( err != noErr )
311 {
312 message.Printf( "Print Error %d", err ) ;
313 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
314 dialog.ShowModal();
315 #if PM_USE_SESSION_APIS
316 PMSessionEndDocument(m_macPrintSession);
317 UMAPrClose(&m_macPrintSession) ;
318 #else
319 PMEndDocument(m_macPrintPort);
320 UMAPrClose() ;
321 #endif
322 ::SetPort( macPrintFormerPort ) ;
323 m_ok = FALSE ;
324 }
325 #endif
326
327 }