]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcprint.cpp
corrected hatched brushes emulation
[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 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
241 ::ClipRect( &clip ) ;
242 err = PrError() ;
243 if ( err != noErr )
244 {
245 message.Printf( "Print Error %d", err ) ;
246 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
247 dialog.ShowModal();
248 ::PrClosePage( m_macPrintPort ) ;
249 ::PrCloseDoc( m_macPrintPort ) ;
250 ::UMAPrClose() ;
251 ::SetPort( macPrintFormerPort ) ;
252 m_ok = FALSE ;
253 }
254 #else
255 #if PM_USE_SESSION_APIS
256 err = PMSessionBeginPage(m_macPrintSession,
257 m_printData.m_macPageFormat,
258 nil);
259 #else
260 err = PMBeginPage(m_macPrintPort, nil);
261 #endif
262 if ( err != noErr )
263 {
264 message.Printf( "Print Error %d", err ) ;
265 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
266 dialog.ShowModal();
267 #if PM_USE_SESSION_APIS
268 PMSessionEndPage(m_macPrintSession);
269 PMSessionEndDocument(m_macPrintSession);
270 UMAPrClose(&m_macPrintSession) ;
271 #else
272 PMEndPage(m_macPrintPort);
273 PMEndDocument(m_macPrintPort);
274 UMAPrClose() ;
275 #endif
276 ::SetPort( macPrintFormerPort ) ;
277 m_ok = FALSE ;
278 }
279 #endif
280 }
281
282 void wxPrinterDC::EndPage(void)
283 {
284 if ( !m_ok )
285 return ;
286
287 OSStatus err ;
288 wxString message ;
289
290 #if !TARGET_CARBON
291 PrClosePage( (TPrPort*) m_macPort ) ;
292 err = PrError() ;
293 if ( err != noErr )
294 {
295 message.Printf( "Print Error %d", err ) ;
296 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
297 dialog.ShowModal();
298 ::PrCloseDoc( m_macPrintPort ) ;
299 ::UMAPrClose() ;
300 ::SetPort( macPrintFormerPort ) ;
301 m_ok = FALSE ;
302 }
303 #else
304 #if PM_USE_SESSION_APIS
305 err = PMSessionEndPage(m_macPrintSession);
306 #else
307 err = PMEndPage(m_macPrintPort);
308 #endif
309 if ( err != noErr )
310 {
311 message.Printf( "Print Error %d", err ) ;
312 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
313 dialog.ShowModal();
314 #if PM_USE_SESSION_APIS
315 PMSessionEndDocument(m_macPrintSession);
316 UMAPrClose(&m_macPrintSession) ;
317 #else
318 PMEndDocument(m_macPrintPort);
319 UMAPrClose() ;
320 #endif
321 ::SetPort( macPrintFormerPort ) ;
322 m_ok = FALSE ;
323 }
324 #endif
325
326 }