]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcprint.cpp
Added some missing copyright lines
[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
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 #ifndef __DARWIN__
31 #include "Printing.h"
32 #endif
33
34 #if defined(TARGET_CARBON) && !defined(__DARWIN__)
35 # if PM_USE_SESSION_APIS
36 # include <PMCore.h>
37 # endif
38 # include <PMApplication.h>
39 #endif
40
41 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_CLASS(wxPrinterDC, wxDC)
43 #endif
44
45 GrafPtr macPrintFormerPort = NULL ;
46
47 wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
48 {
49 OSStatus err = noErr ;
50 wxString message ;
51
52 m_printData = printdata ;
53 m_printData.ConvertToNative() ;
54
55 #if TARGET_CARBON && PM_USE_SESSION_APIS
56 m_macPrintSessionPort = printdata.m_macPrintSession ;
57 PMRetain( m_macPrintSessionPort ) ;
58
59 if ( err != noErr || m_macPrintSessionPort == kPMNoData )
60 #else
61 err = UMAPrOpen(NULL) ;
62 if ( err != noErr )
63 #endif
64 {
65 message.Printf( wxT("Print Error %ld"), err ) ;
66 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
67 dialog.ShowModal();
68 #if TARGET_CARBON && PM_USE_SESSION_APIS
69 PMRelease( m_macPrintSessionPort ) ;
70 #else
71 UMAPrClose(NULL) ;
72 #endif
73 m_ok = FALSE;
74 return;
75 }
76
77 #if !TARGET_CARBON
78 if ( ::PrValidate( (THPrint) m_printData.m_macPrintSettings ) )
79 {
80 // the driver has changed in the mean time, should we pop up a page setup dialog ?
81 if ( !::PrStlDialog( (THPrint) m_printData.m_macPrintSettings ) )
82 {
83 UMAPrClose(NULL) ;
84 m_ok = FALSE;
85 return;
86 }
87 }
88 err = PrError() ;
89 if ( err != noErr )
90 {
91 message.Printf( wxT("Print Error %ld"), err ) ;
92 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
93 dialog.ShowModal();
94 UMAPrClose(NULL) ;
95 m_ok = FALSE;
96 return;
97 }
98 ::GetPort( &macPrintFormerPort ) ;
99 #endif
100 m_ok = TRUE ;
101 m_minY = m_minX = 0 ;
102 #if TARGET_CARBON
103 PMRect rPage;
104
105 err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
106 if ( err != noErr )
107 {
108 message.Printf( wxT("Print Error %ld"), err ) ;
109 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
110 dialog.ShowModal();
111 #if TARGET_CARBON && PM_USE_SESSION_APIS
112 PMRelease(&m_macPrintSessionPort) ;
113 #else
114 UMAPrClose(NULL) ;
115 #endif
116 m_ok = FALSE;
117 return;
118 }
119 m_maxX = wxCoord(rPage.right - rPage.left) ;
120 m_maxY = wxCoord(rPage.bottom - rPage.top);
121 #else
122 m_maxX = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.left ;
123 m_maxY = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.top ;
124 #endif
125 }
126
127 wxPrinterDC::~wxPrinterDC(void)
128 {
129 OSStatus err ;
130 wxString message ;
131 #if !TARGET_CARBON
132 if ( m_ok )
133 {
134 ::UMAPrClose(NULL) ;
135 ::SetPort( LMGetWMgrPort() ) ;
136 }
137 #else
138 if ( m_ok )
139 {
140 #if TARGET_CARBON && PM_USE_SESSION_APIS
141 PMRelease(&m_macPrintSessionPort) ;
142 #else
143 UMAPrClose(NULL) ;
144 #endif
145 }
146 #endif
147 }
148
149 bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
150 {
151 OSStatus err = noErr ;
152 wxString message ;
153
154 #if !TARGET_CARBON
155 m_macPrintSessionPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintSettings , NULL , NULL ) ;
156 err = PrError() ;
157 if ( err )
158 {
159 message.Printf( wxT("Print Error %d"), err ) ;
160 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
161 dialog.ShowModal();
162 UMAPrClose(NULL) ;
163 m_ok = FALSE;
164 return false ;
165 }
166 // sets current port
167 m_macPort = (GrafPtr ) m_macPrintSessionPort ;
168 #else
169 #if PM_USE_SESSION_APIS
170 err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort,
171 (PMPrintSettings)m_printData.m_macPrintSettings,
172 (PMPageFormat)m_printData.m_macPageFormat);
173 if ( err != noErr )
174 #else
175 m_macPrintSessionPort = kPMNoReference ;
176 err = PMBeginDocument(
177 m_printData.m_macPrintSettings,
178 m_printData.m_macPageFormat,
179 &m_macPrintSessionPort);
180 if ( err != noErr || m_macPrintSessionPort == kPMNoReference )
181 #endif
182 {
183 message.Printf( wxT("Print Error %d"), err ) ;
184 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
185 dialog.ShowModal();
186 #if TARGET_CARBON && PM_USE_SESSION_APIS
187 PMRelease(&m_macPrintSessionPort) ;
188 #else
189 UMAPrClose(NULL) ;
190 #endif
191 m_ok = FALSE;
192 return m_ok;
193 }
194 // sets current port
195 ::GetPort( (GrafPtr *)&m_macPort ) ;
196 #endif
197 m_ok = TRUE ;
198 m_minY = m_minX = 0 ;
199 #if TARGET_CARBON
200 PMRect rPage;
201
202 err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
203 if ( err != noErr )
204 {
205 message.Printf( wxT("Print Error %d"), err ) ;
206 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
207 dialog.ShowModal();
208 #if TARGET_CARBON && PM_USE_SESSION_APIS
209 PMRelease(&m_macPrintSessionPort) ;
210 #else
211 UMAPrClose(NULL) ;
212 #endif
213 m_ok = FALSE;
214 return m_ok;
215 }
216 m_maxX = rPage.right - rPage.left ;
217 m_maxY = rPage.bottom - rPage.top ;
218 #else
219 m_maxX = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.left ;
220 m_maxY = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.top ;
221 #endif
222 return m_ok ;
223 }
224
225 void wxPrinterDC::EndDoc(void)
226 {
227 OSStatus err ;
228 wxString message ;
229 #if !TARGET_CARBON
230 if ( m_ok )
231 {
232 ::UMAPrClose(NULL) ;
233 // ::SetPort( macPrintFormerPort ) ;
234 ::SetPort( LMGetWMgrPort() ) ;
235 }
236 #else
237 if ( m_ok )
238 {
239 #if PM_USE_SESSION_APIS
240 err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
241 #else
242 err = PMEndDocument(m_macPrintSessionPort);
243 #endif
244 if ( err != noErr )
245 {
246 message.Printf( wxT("Print Error %d"), err ) ;
247 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
248 dialog.ShowModal();
249 }
250 }
251 #endif
252 }
253
254 void wxPrinterDC::StartPage(void)
255 {
256 if ( !m_ok )
257 return ;
258
259 m_logicalFunction = wxCOPY;
260 // m_textAlignment = wxALIGN_TOP_LEFT;
261 m_backgroundMode = wxTRANSPARENT;
262
263 m_textForegroundColour = *wxBLACK;
264 m_textBackgroundColour = *wxWHITE;
265 m_pen = *wxBLACK_PEN;
266 m_font = *wxNORMAL_FONT;
267 m_brush = *wxTRANSPARENT_BRUSH;
268 m_backgroundBrush = *wxWHITE_BRUSH;
269
270 m_macFontInstalled = false ;
271 m_macBrushInstalled = false ;
272 m_macPenInstalled = false ;
273
274
275 OSStatus err ;
276 wxString message ;
277
278 #if !TARGET_CARBON
279 PrOpenPage( (TPPrPort) m_macPrintSessionPort , NULL ) ;
280 m_macLocalOrigin.x = (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ;
281 m_macLocalOrigin.y = (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ;
282
283 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
284 ::ClipRect( &clip ) ;
285 err = PrError() ;
286 if ( err != noErr )
287 {
288 message.Printf( wxT("Print Error %ld"), err ) ;
289 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
290 dialog.ShowModal();
291 ::PrClosePage( (TPPrPort) m_macPrintSessionPort ) ;
292 ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
293 ::UMAPrClose(NULL) ;
294 ::SetPort( macPrintFormerPort ) ;
295 m_ok = FALSE ;
296 }
297 #else
298 #if PM_USE_SESSION_APIS
299 err = PMSessionBeginPage((PMPrintSession)m_macPrintSessionPort,
300 (PMPageFormat)m_printData.m_macPageFormat,
301 nil);
302 #else
303 err = PMBeginPage(m_macPrintSessionPort, nil);
304 #endif
305 if ( err != noErr )
306 {
307 message.Printf( wxT("Print Error %ld"), err ) ;
308 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
309 dialog.ShowModal();
310 #if PM_USE_SESSION_APIS
311 PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
312 PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
313 UMAPrClose(&m_macPrintSessionPort) ;
314 #else
315 PMEndPage(m_macPrintSessionPort);
316 PMEndDocument(m_macPrintSessionPort);
317 UMAPrClose(NULL) ;
318 #endif
319 ::SetPort( macPrintFormerPort ) ;
320 m_ok = FALSE ;
321 }
322 PMRect rPage;
323
324 err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
325 if ( !err )
326 {
327 m_macLocalOrigin.x = rPage.left ;
328 m_macLocalOrigin.y = rPage.top ;
329 }
330 #endif
331 }
332
333 void wxPrinterDC::EndPage(void)
334 {
335 if ( !m_ok )
336 return ;
337
338 OSStatus err ;
339 wxString message ;
340
341 #if !TARGET_CARBON
342 PrClosePage( (TPPrPort) m_macPort ) ;
343 err = PrError() ;
344 if ( err != noErr )
345 {
346 message.Printf( wxT("Print Error %ld") , err ) ;
347 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
348 dialog.ShowModal();
349 ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
350 ::UMAPrClose(NULL) ;
351 ::SetPort( macPrintFormerPort ) ;
352 m_ok = FALSE ;
353 }
354 #else
355 #if PM_USE_SESSION_APIS
356 err = PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
357 #else
358 err = PMEndPage(m_macPrintSessionPort);
359 #endif
360 if ( err != noErr )
361 {
362 message.Printf( wxT("Print Error %ld"), err ) ;
363 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
364 dialog.ShowModal();
365 #if PM_USE_SESSION_APIS
366 PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
367 UMAPrClose(&m_macPrintSessionPort) ;
368 #else
369 PMEndDocument(m_macPrintSessionPort);
370 UMAPrClose(NULL) ;
371 #endif
372 ::SetPort( macPrintFormerPort ) ;
373 m_ok = FALSE ;
374 }
375 #endif
376
377 }