]> git.saurik.com Git - wxWidgets.git/blame - src/mac/dcprint.cpp
* Fix logical error in m_overflow attribute merging
[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$
6aa89a22 8// Copyright: (c) Julian Smart
e40298d5 9// Licence: wxWindows licence
72e7876b
SC
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{
75411508 49 OSStatus err = noErr ;
e40298d5
JS
50 wxString message ;
51
52 m_printData = printdata ;
53 m_printData.ConvertToNative() ;
a689a4d0 54
f520d381 55#if TARGET_CARBON && PM_USE_SESSION_APIS
75411508
SC
56 m_macPrintSessionPort = printdata.m_macPrintSession ;
57 PMRetain( m_macPrintSessionPort ) ;
58
e40298d5 59 if ( err != noErr || m_macPrintSessionPort == kPMNoData )
87df17a1 60#else
e40298d5
JS
61 err = UMAPrOpen(NULL) ;
62 if ( err != noErr )
a689a4d0 63#endif
e40298d5 64 {
427ff662
SC
65 message.Printf( wxT("Print Error %ld"), err ) ;
66 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
e40298d5 67 dialog.ShowModal();
f520d381 68#if TARGET_CARBON && PM_USE_SESSION_APIS
75411508 69 PMRelease( m_macPrintSessionPort ) ;
87df17a1 70#else
e40298d5 71 UMAPrClose(NULL) ;
a689a4d0 72#endif
e40298d5
JS
73 m_ok = FALSE;
74 return;
75 }
76
5b781a67 77#if !TARGET_CARBON
e40298d5
JS
78 if ( ::PrValidate( (THPrint) m_printData.m_macPrintSettings ) )
79 {
e40298d5 80 // the driver has changed in the mean time, should we pop up a page setup dialog ?
75411508
SC
81 if ( !::PrStlDialog( (THPrint) m_printData.m_macPrintSettings ) )
82 {
83 UMAPrClose(NULL) ;
84 m_ok = FALSE;
85 return;
86 }
e40298d5
JS
87 }
88 err = PrError() ;
89 if ( err != noErr )
90 {
427ff662
SC
91 message.Printf( wxT("Print Error %ld"), err ) ;
92 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
e40298d5
JS
93 dialog.ShowModal();
94 UMAPrClose(NULL) ;
95 m_ok = FALSE;
96 return;
97 }
98 ::GetPort( &macPrintFormerPort ) ;
5b781a67 99#endif
e40298d5
JS
100 m_ok = TRUE ;
101 m_minY = m_minX = 0 ;
5b781a67 102#if TARGET_CARBON
aa812de0 103 PMRect rPage;
e40298d5 104
aa812de0 105 err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
f520d381
GD
106 if ( err != noErr )
107 {
427ff662
SC
108 message.Printf( wxT("Print Error %ld"), err ) ;
109 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
e40298d5 110 dialog.ShowModal();
f520d381 111 #if TARGET_CARBON && PM_USE_SESSION_APIS
75411508 112 PMRelease(&m_macPrintSessionPort) ;
f520d381 113 #else
e40298d5 114 UMAPrClose(NULL) ;
f520d381 115 #endif
e40298d5
JS
116 m_ok = FALSE;
117 return;
f520d381 118 }
aa812de0
SC
119 m_maxX = wxCoord(rPage.right - rPage.left) ;
120 m_maxY = wxCoord(rPage.bottom - rPage.top);
5b781a67 121#else
2cee82b7
SC
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 ;
2f1ae414 124#endif
72e7876b
SC
125}
126
127wxPrinterDC::~wxPrinterDC(void)
128{
e40298d5
JS
129 OSStatus err ;
130 wxString message ;
2f1ae414 131#if !TARGET_CARBON
e40298d5
JS
132 if ( m_ok )
133 {
e40298d5 134 ::UMAPrClose(NULL) ;
e40298d5
JS
135 ::SetPort( LMGetWMgrPort() ) ;
136 }
2f1ae414 137#else
e40298d5
JS
138 if ( m_ok )
139 {
f520d381 140 #if TARGET_CARBON && PM_USE_SESSION_APIS
75411508 141 PMRelease(&m_macPrintSessionPort) ;
a689a4d0 142 #else
e40298d5 143 UMAPrClose(NULL) ;
a689a4d0 144 #endif
e40298d5 145 }
2f1ae414 146#endif
72e7876b
SC
147}
148
149bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
150{
75411508
SC
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 {
427ff662
SC
159 message.Printf( wxT("Print Error %d"), err ) ;
160 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
75411508
SC
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 {
427ff662
SC
183 message.Printf( wxT("Print Error %d"), err ) ;
184 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
75411508
SC
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
aa812de0 200 PMRect rPage;
75411508 201
aa812de0 202 err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
75411508
SC
203 if ( err != noErr )
204 {
427ff662
SC
205 message.Printf( wxT("Print Error %d"), err ) ;
206 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
75411508
SC
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 }
aa812de0
SC
216 m_maxX = rPage.right - rPage.left ;
217 m_maxY = rPage.bottom - rPage.top ;
75411508 218#else
2cee82b7
SC
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 ;
75411508 221#endif
e40298d5 222 return m_ok ;
72e7876b
SC
223}
224
225void wxPrinterDC::EndDoc(void)
226{
75411508
SC
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 {
427ff662
SC
246 message.Printf( wxT("Print Error %d"), err ) ;
247 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
75411508
SC
248 dialog.ShowModal();
249 }
250 }
251#endif
72e7876b
SC
252}
253
254void wxPrinterDC::StartPage(void)
255{
e40298d5
JS
256 if ( !m_ok )
257 return ;
2f1ae414 258
e40298d5 259 m_logicalFunction = wxCOPY;
2f1ae414 260// m_textAlignment = wxALIGN_TOP_LEFT;
e40298d5 261 m_backgroundMode = wxTRANSPARENT;
2f1ae414 262
e40298d5
JS
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;
2f1ae414 269
e40298d5
JS
270 m_macFontInstalled = false ;
271 m_macBrushInstalled = false ;
272 m_macPenInstalled = false ;
2f1ae414 273
e40298d5
JS
274
275 OSStatus err ;
276 wxString message ;
72e7876b 277
5b781a67 278#if !TARGET_CARBON
e40298d5
JS
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 {
427ff662
SC
288 message.Printf( wxT("Print Error %ld"), err ) ;
289 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
e40298d5
JS
290 dialog.ShowModal();
291 ::PrClosePage( (TPPrPort) m_macPrintSessionPort ) ;
292 ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
293 ::UMAPrClose(NULL) ;
294 ::SetPort( macPrintFormerPort ) ;
295 m_ok = FALSE ;
296 }
2f1ae414 297#else
a689a4d0 298 #if PM_USE_SESSION_APIS
e40298d5
JS
299 err = PMSessionBeginPage((PMPrintSession)m_macPrintSessionPort,
300 (PMPageFormat)m_printData.m_macPageFormat,
301 nil);
a689a4d0 302 #else
e40298d5 303 err = PMBeginPage(m_macPrintSessionPort, nil);
a689a4d0 304 #endif
e40298d5
JS
305 if ( err != noErr )
306 {
427ff662
SC
307 message.Printf( wxT("Print Error %ld"), err ) ;
308 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
e40298d5 309 dialog.ShowModal();
a689a4d0 310 #if PM_USE_SESSION_APIS
e40298d5
JS
311 PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
312 PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
313 UMAPrClose(&m_macPrintSessionPort) ;
a689a4d0 314 #else
e40298d5
JS
315 PMEndPage(m_macPrintSessionPort);
316 PMEndDocument(m_macPrintSessionPort);
317 UMAPrClose(NULL) ;
a689a4d0 318 #endif
e40298d5
JS
319 ::SetPort( macPrintFormerPort ) ;
320 m_ok = FALSE ;
321 }
aa812de0 322 PMRect rPage;
75411508 323
aa812de0 324 err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
75411508
SC
325 if ( !err )
326 {
aa812de0
SC
327 m_macLocalOrigin.x = rPage.left ;
328 m_macLocalOrigin.y = rPage.top ;
75411508 329 }
2f1ae414 330#endif
72e7876b
SC
331}
332
333void wxPrinterDC::EndPage(void)
334{
e40298d5
JS
335 if ( !m_ok )
336 return ;
72e7876b 337
e40298d5
JS
338 OSStatus err ;
339 wxString message ;
72e7876b 340
5b781a67 341#if !TARGET_CARBON
75411508 342 PrClosePage( (TPPrPort) m_macPort ) ;
e40298d5
JS
343 err = PrError() ;
344 if ( err != noErr )
345 {
427ff662
SC
346 message.Printf( wxT("Print Error %ld") , err ) ;
347 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
e40298d5
JS
348 dialog.ShowModal();
349 ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
350 ::UMAPrClose(NULL) ;
351 ::SetPort( macPrintFormerPort ) ;
352 m_ok = FALSE ;
353 }
2f1ae414 354#else
a689a4d0 355 #if PM_USE_SESSION_APIS
e40298d5 356 err = PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
a689a4d0 357 #else
e40298d5 358 err = PMEndPage(m_macPrintSessionPort);
a689a4d0 359 #endif
e40298d5
JS
360 if ( err != noErr )
361 {
427ff662
SC
362 message.Printf( wxT("Print Error %ld"), err ) ;
363 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
e40298d5 364 dialog.ShowModal();
a689a4d0 365 #if PM_USE_SESSION_APIS
e40298d5
JS
366 PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
367 UMAPrClose(&m_macPrintSessionPort) ;
a689a4d0 368 #else
e40298d5
JS
369 PMEndDocument(m_macPrintSessionPort);
370 UMAPrClose(NULL) ;
a689a4d0 371 #endif
e40298d5
JS
372 ::SetPort( macPrintFormerPort ) ;
373 m_ok = FALSE ;
374 }
2f1ae414
SC
375#endif
376
72e7876b 377}