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