]> git.saurik.com Git - wxWidgets.git/blame - src/mac/dcprint.cpp
removing dependancy on mac headers from public wx headers (eventually adding wx/
[wxWidgets.git] / src / mac / dcprint.cpp
CommitLineData
72e7876b
SC
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"
03e11df5
GD
27#include "wx/msgdlg.h"
28#include <math.h>
2f1ae414 29#include "wx/mac/uma.h"
72e7876b 30
2f1ae414 31#if !USE_SHARED_LIBRARY
72e7876b 32IMPLEMENT_CLASS(wxPrinterDC, wxDC)
2f1ae414 33#endif
72e7876b
SC
34
35GrafPtr macPrintFormerPort = NULL ;
36
37wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
38{
5b781a67 39 OSStatus err ;
72e7876b
SC
40 wxString message ;
41
42 m_printData = printdata ;
43 m_printData.ConvertToNative() ;
a689a4d0 44
f520d381 45#if TARGET_CARBON && PM_USE_SESSION_APIS
962cbf2e 46 err = UMAPrOpen((PMPrintSession *)&m_macPrintSession) ;
f520d381 47 if ( err != noErr || m_macPrintSession == kPMNoData )
87df17a1
GD
48#else
49 err = UMAPrOpen() ;
f520d381 50 if ( err != noErr )
a689a4d0 51#endif
72e7876b
SC
52 {
53 message.Printf( "Print Error %d", err ) ;
54 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381
GD
55 dialog.ShowModal();
56#if TARGET_CARBON && PM_USE_SESSION_APIS
962cbf2e 57 UMAPrClose((PMPrintSession *)&m_macPrintSession) ;
87df17a1
GD
58#else
59 UMAPrClose() ;
a689a4d0 60#endif
f520d381
GD
61 m_ok = FALSE;
62 return;
72e7876b
SC
63 }
64
5b781a67 65#if !TARGET_CARBON
76a5e5d2 66 if ( ::PrValidate( (THPrint) m_printData.m_macPrintInfo ) )
72e7876b 67 {
76a5e5d2 68 ::PrStlDialog( (THPrint) m_printData.m_macPrintInfo ) ;
72e7876b
SC
69 // the driver has changed in the mean time, should we pop up a page setup dialog ?
70 }
71 err = PrError() ;
f520d381 72 if ( err != noErr )
72e7876b
SC
73 {
74 message.Printf( "Print Error %d", err ) ;
75 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 76 dialog.ShowModal();
2f1ae414 77 UMAPrClose() ;
f520d381
GD
78 m_ok = FALSE;
79 return;
72e7876b
SC
80 }
81 ::GetPort( &macPrintFormerPort ) ;
76a5e5d2 82 m_macPrintPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintInfo , NULL , NULL ) ;
2f1ae414
SC
83 err = PrError() ;
84 if ( err )
85 {
86 message.Printf( "Print Error %d", err ) ;
87 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 88 dialog.ShowModal();
2f1ae414 89 UMAPrClose() ;
f520d381
GD
90 m_ok = FALSE;
91 return;
2f1ae414 92 }
72e7876b
SC
93 // sets current port
94 m_macPort = (GrafPtr ) m_macPrintPort ;
5b781a67 95#else
a689a4d0 96 #if PM_USE_SESSION_APIS
962cbf2e
GD
97 err = PMSessionBeginDocument((PMPrintSession)m_macPrintSession,
98 (PMPrintSettings)m_printData.m_macPrintSettings,
99 (PMPageFormat)m_printData.m_macPageFormat);
f520d381 100 if ( err != noErr )
a689a4d0 101 #else
f520d381 102 m_macPrintPort = kPMNoReference ;
5b781a67 103 err = PMBeginDocument(
f520d381
GD
104 m_printData.m_macPrintSettings,
105 m_printData.m_macPageFormat,
106 &m_macPrintPort);
5b781a67 107 if ( err != noErr || m_macPrintPort == kPMNoReference )
f520d381 108 #endif
5b781a67
SC
109 {
110 message.Printf( "Print Error %d", err ) ;
111 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381
GD
112 dialog.ShowModal();
113 #if TARGET_CARBON && PM_USE_SESSION_APIS
962cbf2e 114 UMAPrClose((PMPrintSession *)&m_macPrintSession) ;
87df17a1
GD
115 #else
116 UMAPrClose() ;
117 #endif
f520d381
GD
118 m_ok = FALSE;
119 return;
5b781a67
SC
120 }
121 // sets current port
962cbf2e 122 ::GetPort( (GrafPtr *)&m_macPort ) ;
5b781a67 123#endif
72e7876b
SC
124 m_ok = TRUE ;
125 m_minY = m_minX = 0 ;
5b781a67 126#if TARGET_CARBON
f520d381
GD
127 PMRect rPaper;
128
962cbf2e 129 err = PMGetAdjustedPaperRect((PMPageFormat)m_printData.m_macPageFormat, &rPaper);
f520d381
GD
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
962cbf2e 136 UMAPrClose((PMPrintSession *)&m_macPrintSession) ;
f520d381
GD
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 ;
5b781a67 145#else
76a5e5d2
SC
146 m_maxX = (**(THPrint)m_printData.m_macPrintInfo).rPaper.right - (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ;
147 m_maxY = (**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom - (**(THPrint)m_printData.m_macPrintInfo).rPaper.top ;
2f1ae414 148#endif
72e7876b
SC
149}
150
151wxPrinterDC::~wxPrinterDC(void)
152{
5b781a67
SC
153 OSStatus err ;
154 wxString message ;
2f1ae414 155#if !TARGET_CARBON
72e7876b
SC
156 if ( m_ok )
157 {
76a5e5d2 158 ::PrCloseDoc( (TPPrPort) m_macPrintPort ) ;
72e7876b
SC
159 err = PrError() ;
160
f520d381 161 if ( err == noErr )
72e7876b 162 {
76a5e5d2 163 if ( (**(THPrint)m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
72e7876b
SC
164 {
165 TPrStatus status ;
76a5e5d2 166 ::PrPicFile( (THPrint) m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
72e7876b
SC
167 }
168 }
169 else
170 {
171 message.Printf( "Print Error %d", err ) ;
172 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 173 dialog.ShowModal();
72e7876b 174 }
2f1ae414
SC
175 ::UMAPrClose() ;
176// ::SetPort( macPrintFormerPort ) ;
177 ::SetPort( LMGetWMgrPort() ) ;
72e7876b 178 }
2f1ae414 179#else
5b781a67
SC
180 if ( m_ok )
181 {
a689a4d0 182 #if PM_USE_SESSION_APIS
962cbf2e 183 err = PMSessionEndDocument((PMPrintSession)m_macPrintSession);
a689a4d0
GD
184 #else
185 err = PMEndDocument(m_macPrintPort);
186 #endif
f520d381 187 if ( err != noErr )
5b781a67
SC
188 {
189 message.Printf( "Print Error %d", err ) ;
190 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 191 dialog.ShowModal();
5b781a67 192 }
f520d381 193 #if TARGET_CARBON && PM_USE_SESSION_APIS
962cbf2e 194 UMAPrClose((PMPrintSession *)&m_macPrintSession) ;
a689a4d0 195 #else
87df17a1 196 UMAPrClose() ;
a689a4d0 197 #endif
5b781a67 198 }
2f1ae414 199#endif
72e7876b
SC
200}
201
202bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
203{
204 return m_ok ;
205}
206
207void wxPrinterDC::EndDoc(void)
208{
209}
210
211void wxPrinterDC::StartPage(void)
212{
213 if ( !m_ok )
214 return ;
2f1ae414
SC
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
72e7876b 231
5b781a67 232 OSStatus err ;
72e7876b
SC
233 wxString message ;
234
5b781a67 235#if !TARGET_CARBON
76a5e5d2
SC
236 PrOpenPage( (TPPrPort) m_macPrintPort , NULL ) ;
237 m_macLocalOrigin.x = (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ;
238 m_macLocalOrigin.y = (**(THPrint)m_printData.m_macPrintInfo).rPaper.top ;
5b781a67 239
72e7876b
SC
240 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
241 ::ClipRect( &clip ) ;
242 err = PrError() ;
f520d381 243 if ( err != noErr )
72e7876b
SC
244 {
245 message.Printf( "Print Error %d", err ) ;
246 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 247 dialog.ShowModal();
76a5e5d2
SC
248 ::PrClosePage( (TPPrPort) m_macPrintPort ) ;
249 ::PrCloseDoc( (TPPrPort) m_macPrintPort ) ;
2f1ae414 250 ::UMAPrClose() ;
72e7876b
SC
251 ::SetPort( macPrintFormerPort ) ;
252 m_ok = FALSE ;
253 }
2f1ae414 254#else
a689a4d0 255 #if PM_USE_SESSION_APIS
962cbf2e
GD
256 err = PMSessionBeginPage((PMPrintSession)m_macPrintSession,
257 (PMPageFormat)m_printData.m_macPageFormat,
a689a4d0
GD
258 nil);
259 #else
260 err = PMBeginPage(m_macPrintPort, nil);
261 #endif
f520d381 262 if ( err != noErr )
5b781a67
SC
263 {
264 message.Printf( "Print Error %d", err ) ;
265 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 266 dialog.ShowModal();
a689a4d0 267 #if PM_USE_SESSION_APIS
962cbf2e
GD
268 PMSessionEndPage((PMPrintSession)m_macPrintSession);
269 PMSessionEndDocument((PMPrintSession)m_macPrintSession);
270 UMAPrClose((PMPrintSession *)&m_macPrintSession) ;
a689a4d0 271 #else
5b781a67
SC
272 PMEndPage(m_macPrintPort);
273 PMEndDocument(m_macPrintPort);
87df17a1 274 UMAPrClose() ;
a689a4d0 275 #endif
5b781a67
SC
276 ::SetPort( macPrintFormerPort ) ;
277 m_ok = FALSE ;
278 }
2f1ae414 279#endif
72e7876b
SC
280}
281
282void wxPrinterDC::EndPage(void)
283{
284 if ( !m_ok )
285 return ;
286
5b781a67 287 OSStatus err ;
72e7876b
SC
288 wxString message ;
289
5b781a67 290#if !TARGET_CARBON
76a5e5d2 291 PrClosePage( (TPPrPort) m_macPort ) ;
72e7876b 292 err = PrError() ;
f520d381 293 if ( err != noErr )
72e7876b
SC
294 {
295 message.Printf( "Print Error %d", err ) ;
296 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 297 dialog.ShowModal();
76a5e5d2 298 ::PrCloseDoc( (TPPrPort) m_macPrintPort ) ;
2f1ae414 299 ::UMAPrClose() ;
72e7876b
SC
300 ::SetPort( macPrintFormerPort ) ;
301 m_ok = FALSE ;
302 }
2f1ae414 303#else
a689a4d0 304 #if PM_USE_SESSION_APIS
962cbf2e 305 err = PMSessionEndPage((PMPrintSession)m_macPrintSession);
a689a4d0 306 #else
5b781a67 307 err = PMEndPage(m_macPrintPort);
a689a4d0 308 #endif
f520d381 309 if ( err != noErr )
5b781a67
SC
310 {
311 message.Printf( "Print Error %d", err ) ;
312 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 313 dialog.ShowModal();
a689a4d0 314 #if PM_USE_SESSION_APIS
962cbf2e
GD
315 PMSessionEndDocument((PMPrintSession)m_macPrintSession);
316 UMAPrClose((PMPrintSession *)&m_macPrintSession) ;
a689a4d0 317 #else
5b781a67 318 PMEndDocument(m_macPrintPort);
87df17a1 319 UMAPrClose() ;
a689a4d0 320 #endif
5b781a67
SC
321 ::SetPort( macPrintFormerPort ) ;
322 m_ok = FALSE ;
323 }
2f1ae414
SC
324#endif
325
72e7876b 326}