]> git.saurik.com Git - wxWidgets.git/blame - src/mac/dcprint.cpp
compilation fixes for Watcom+MGL+MS-DOS
[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
GD
45#if TARGET_CARBON && PM_USE_SESSION_APIS
46 err = UMAPrOpen(&m_macPrintSession) ;
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
57 UMAPrClose(&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
72e7876b
SC
66 if ( ::PrValidate( m_printData.m_macPrintInfo ) )
67 {
2f1ae414 68 ::PrStlDialog( 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 ) ;
82 m_macPrintPort = ::PrOpenDoc( 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
f520d381
GD
97 err = PMSessionBeginDocument(m_macPrintSession,
98 m_printData.m_macPrintSettings,
99 m_printData.m_macPageFormat);
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
114 UMAPrClose(&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
122 ::GetPort( &m_macPort ) ;
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
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 ;
5b781a67 145#else
72e7876b
SC
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 ;
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 {
72e7876b
SC
158 ::PrCloseDoc( m_macPrintPort ) ;
159 err = PrError() ;
160
f520d381 161 if ( err == noErr )
72e7876b
SC
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) ;
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
f520d381 183 err = PMSessionEndDocument(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
GD
193 #if TARGET_CARBON && PM_USE_SESSION_APIS
194 UMAPrClose(&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
2f1ae414 236 PrOpenPage( m_macPrintPort , NULL ) ;
5b781a67
SC
237 m_macLocalOrigin.h = (**m_printData.m_macPrintInfo).rPaper.left ;
238 m_macLocalOrigin.v = (**m_printData.m_macPrintInfo).rPaper.top ;
239
240 SetOrigin( - m_macLocalOrigin.h , - m_macLocalOrigin.v ) ;
72e7876b
SC
241 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
242 ::ClipRect( &clip ) ;
243 err = PrError() ;
f520d381 244 if ( err != noErr )
72e7876b
SC
245 {
246 message.Printf( "Print Error %d", err ) ;
247 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381
GD
248 dialog.ShowModal();
249 ::PrClosePage( m_macPrintPort ) ;
250 ::PrCloseDoc( m_macPrintPort ) ;
2f1ae414 251 ::UMAPrClose() ;
72e7876b
SC
252 ::SetPort( macPrintFormerPort ) ;
253 m_ok = FALSE ;
254 }
2f1ae414 255#else
a689a4d0 256 #if PM_USE_SESSION_APIS
f520d381 257 err = PMSessionBeginPage(m_macPrintSession,
a689a4d0
GD
258 m_printData.m_macPageFormat,
259 nil);
260 #else
261 err = PMBeginPage(m_macPrintPort, nil);
262 #endif
f520d381 263 if ( err != noErr )
5b781a67
SC
264 {
265 message.Printf( "Print Error %d", err ) ;
266 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 267 dialog.ShowModal();
a689a4d0 268 #if PM_USE_SESSION_APIS
f520d381
GD
269 PMSessionEndPage(m_macPrintSession);
270 PMSessionEndDocument(m_macPrintSession);
271 UMAPrClose(&m_macPrintSession) ;
a689a4d0 272 #else
5b781a67
SC
273 PMEndPage(m_macPrintPort);
274 PMEndDocument(m_macPrintPort);
87df17a1 275 UMAPrClose() ;
a689a4d0 276 #endif
5b781a67
SC
277 ::SetPort( macPrintFormerPort ) ;
278 m_ok = FALSE ;
279 }
2f1ae414 280#endif
72e7876b
SC
281}
282
283void wxPrinterDC::EndPage(void)
284{
285 if ( !m_ok )
286 return ;
287
5b781a67 288 OSStatus err ;
72e7876b
SC
289 wxString message ;
290
5b781a67 291#if !TARGET_CARBON
72e7876b
SC
292 PrClosePage( (TPrPort*) m_macPort ) ;
293 err = PrError() ;
f520d381 294 if ( err != noErr )
72e7876b
SC
295 {
296 message.Printf( "Print Error %d", err ) ;
297 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 298 dialog.ShowModal();
72e7876b 299 ::PrCloseDoc( m_macPrintPort ) ;
2f1ae414 300 ::UMAPrClose() ;
72e7876b
SC
301 ::SetPort( macPrintFormerPort ) ;
302 m_ok = FALSE ;
303 }
2f1ae414 304#else
a689a4d0 305 #if PM_USE_SESSION_APIS
f520d381 306 err = PMSessionEndPage(m_macPrintSession);
a689a4d0 307 #else
5b781a67 308 err = PMEndPage(m_macPrintPort);
a689a4d0 309 #endif
f520d381 310 if ( err != noErr )
5b781a67
SC
311 {
312 message.Printf( "Print Error %d", err ) ;
313 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
f520d381 314 dialog.ShowModal();
a689a4d0 315 #if PM_USE_SESSION_APIS
f520d381
GD
316 PMSessionEndDocument(m_macPrintSession);
317 UMAPrClose(&m_macPrintSession) ;
a689a4d0 318 #else
5b781a67 319 PMEndDocument(m_macPrintPort);
87df17a1 320 UMAPrClose() ;
a689a4d0 321 #endif
5b781a67
SC
322 ::SetPort( macPrintFormerPort ) ;
323 m_ok = FALSE ;
324 }
2f1ae414
SC
325#endif
326
72e7876b 327}