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