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