]>
Commit | Line | Data |
---|---|---|
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 | 32 | IMPLEMENT_CLASS(wxPrinterDC, wxDC) |
2f1ae414 | 33 | #endif |
72e7876b SC |
34 | |
35 | GrafPtr macPrintFormerPort = NULL ; | |
36 | ||
37 | wxPrinterDC::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 | 45 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
1d78308f GD |
46 | err = UMAPrOpen((PMPrintSession *)&m_macPrintSessionPort) ; |
47 | if ( err != noErr || m_macPrintSessionPort == 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 | |
1d78308f | 57 | UMAPrClose((PMPrintSession *)&m_macPrintSessionPort) ; |
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 |
1d78308f | 66 | if ( ::PrValidate( (THPrint) m_printData.m_macPrintSettings ) ) |
72e7876b | 67 | { |
1d78308f | 68 | ::PrStlDialog( (THPrint) m_printData.m_macPrintSettings ) ; |
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 ) ; | |
1d78308f | 82 | m_macPrintSessionPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintSettings , 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 | 93 | // sets current port |
1d78308f | 94 | m_macPort = (GrafPtr ) m_macPrintSessionPort ; |
5b781a67 | 95 | #else |
a689a4d0 | 96 | #if PM_USE_SESSION_APIS |
1d78308f | 97 | err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort, |
962cbf2e GD |
98 | (PMPrintSettings)m_printData.m_macPrintSettings, |
99 | (PMPageFormat)m_printData.m_macPageFormat); | |
f520d381 | 100 | if ( err != noErr ) |
a689a4d0 | 101 | #else |
1d78308f | 102 | m_macPrintSessionPort = kPMNoReference ; |
5b781a67 | 103 | err = PMBeginDocument( |
f520d381 GD |
104 | m_printData.m_macPrintSettings, |
105 | m_printData.m_macPageFormat, | |
1d78308f GD |
106 | &m_macPrintSessionPort); |
107 | if ( err != noErr || m_macPrintSessionPort == 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 | |
1d78308f | 114 | UMAPrClose((PMPrintSession *)&m_macPrintSessionPort) ; |
87df17a1 GD |
115 | #else |
116 | UMAPrClose() ; | |
117 | #endif | |
f520d381 GD |
118 | m_ok = FALSE; |
119 | return; | |
5b781a67 SC |
120 | } |
121 | // sets current port | |
962cbf2e | 122 | ::GetPort( (GrafPtr *)&m_macPort ) ; |
5b781a67 | 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 | ||
962cbf2e | 129 | err = PMGetAdjustedPaperRect((PMPageFormat)m_printData.m_macPageFormat, &rPaper); |
f520d381 GD |
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 | |
1d78308f | 136 | UMAPrClose((PMPrintSession *)&m_macPrintSessionPort) ; |
f520d381 GD |
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 |
1d78308f GD |
146 | m_maxX = (**(THPrint)m_printData.m_macPrintSettings).rPaper.right - (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ; |
147 | m_maxY = (**(THPrint)m_printData.m_macPrintSettings).rPaper.bottom - (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ; | |
2f1ae414 | 148 | #endif |
72e7876b SC |
149 | } |
150 | ||
151 | wxPrinterDC::~wxPrinterDC(void) | |
152 | { | |
5b781a67 SC |
153 | OSStatus err ; |
154 | wxString message ; | |
2f1ae414 | 155 | #if !TARGET_CARBON |
72e7876b SC |
156 | if ( m_ok ) |
157 | { | |
1d78308f | 158 | ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ; |
72e7876b SC |
159 | err = PrError() ; |
160 | ||
f520d381 | 161 | if ( err == noErr ) |
72e7876b | 162 | { |
1d78308f | 163 | if ( (**(THPrint)m_printData.m_macPrintSettings).prJob.bJDocLoop == bSpoolLoop ) |
72e7876b SC |
164 | { |
165 | TPrStatus status ; | |
1d78308f | 166 | ::PrPicFile( (THPrint) m_printData.m_macPrintSettings , NULL , NULL , NULL , &status ) ; |
72e7876b SC |
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 |
1d78308f | 183 | err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); |
a689a4d0 | 184 | #else |
1d78308f | 185 | err = PMEndDocument(m_macPrintSessionPort); |
a689a4d0 | 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 | 193 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
1d78308f | 194 | UMAPrClose((PMPrintSession *)&m_macPrintSessionPort) ; |
a689a4d0 | 195 | #else |
87df17a1 | 196 | UMAPrClose() ; |
a689a4d0 | 197 | #endif |
5b781a67 | 198 | } |
2f1ae414 | 199 | #endif |
72e7876b SC |
200 | } |
201 | ||
202 | bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) ) | |
203 | { | |
204 | return m_ok ; | |
205 | } | |
206 | ||
207 | void wxPrinterDC::EndDoc(void) | |
208 | { | |
209 | } | |
210 | ||
211 | void 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 |
1d78308f GD |
236 | PrOpenPage( (TPPrPort) m_macPrintSessionPort , NULL ) ; |
237 | m_macLocalOrigin.x = (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ; | |
238 | m_macLocalOrigin.y = (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ; | |
5b781a67 | 239 | |
72e7876b SC |
240 | Rect clip = { -32000 , -32000 , 32000 , 32000 } ; |
241 | ::ClipRect( &clip ) ; | |
242 | err = PrError() ; | |
f520d381 | 243 | if ( err != noErr ) |
72e7876b SC |
244 | { |
245 | message.Printf( "Print Error %d", err ) ; | |
246 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 247 | dialog.ShowModal(); |
1d78308f GD |
248 | ::PrClosePage( (TPPrPort) m_macPrintSessionPort ) ; |
249 | ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ; | |
2f1ae414 | 250 | ::UMAPrClose() ; |
72e7876b SC |
251 | ::SetPort( macPrintFormerPort ) ; |
252 | m_ok = FALSE ; | |
253 | } | |
2f1ae414 | 254 | #else |
a689a4d0 | 255 | #if PM_USE_SESSION_APIS |
1d78308f | 256 | err = PMSessionBeginPage((PMPrintSession)m_macPrintSessionPort, |
962cbf2e | 257 | (PMPageFormat)m_printData.m_macPageFormat, |
a689a4d0 GD |
258 | nil); |
259 | #else | |
1d78308f | 260 | err = PMBeginPage(m_macPrintSessionPort, nil); |
a689a4d0 | 261 | #endif |
f520d381 | 262 | if ( err != noErr ) |
5b781a67 SC |
263 | { |
264 | message.Printf( "Print Error %d", err ) ; | |
265 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 266 | dialog.ShowModal(); |
a689a4d0 | 267 | #if PM_USE_SESSION_APIS |
1d78308f GD |
268 | PMSessionEndPage((PMPrintSession)m_macPrintSessionPort); |
269 | PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); | |
270 | UMAPrClose((PMPrintSession *)&m_macPrintSessionPort) ; | |
a689a4d0 | 271 | #else |
1d78308f GD |
272 | PMEndPage(m_macPrintSessionPort); |
273 | PMEndDocument(m_macPrintSessionPort); | |
87df17a1 | 274 | UMAPrClose() ; |
a689a4d0 | 275 | #endif |
5b781a67 SC |
276 | ::SetPort( macPrintFormerPort ) ; |
277 | m_ok = FALSE ; | |
278 | } | |
2f1ae414 | 279 | #endif |
72e7876b SC |
280 | } |
281 | ||
282 | void wxPrinterDC::EndPage(void) | |
283 | { | |
284 | if ( !m_ok ) | |
285 | return ; | |
286 | ||
5b781a67 | 287 | OSStatus err ; |
72e7876b SC |
288 | wxString message ; |
289 | ||
5b781a67 | 290 | #if !TARGET_CARBON |
76a5e5d2 | 291 | PrClosePage( (TPPrPort) m_macPort ) ; |
72e7876b | 292 | err = PrError() ; |
f520d381 | 293 | if ( err != noErr ) |
72e7876b SC |
294 | { |
295 | message.Printf( "Print Error %d", err ) ; | |
296 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 297 | dialog.ShowModal(); |
1d78308f | 298 | ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ; |
2f1ae414 | 299 | ::UMAPrClose() ; |
72e7876b SC |
300 | ::SetPort( macPrintFormerPort ) ; |
301 | m_ok = FALSE ; | |
302 | } | |
2f1ae414 | 303 | #else |
a689a4d0 | 304 | #if PM_USE_SESSION_APIS |
1d78308f | 305 | err = PMSessionEndPage((PMPrintSession)m_macPrintSessionPort); |
a689a4d0 | 306 | #else |
1d78308f | 307 | err = PMEndPage(m_macPrintSessionPort); |
a689a4d0 | 308 | #endif |
f520d381 | 309 | if ( err != noErr ) |
5b781a67 SC |
310 | { |
311 | message.Printf( "Print Error %d", err ) ; | |
312 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 313 | dialog.ShowModal(); |
a689a4d0 | 314 | #if PM_USE_SESSION_APIS |
1d78308f GD |
315 | PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); |
316 | UMAPrClose((PMPrintSession *)&m_macPrintSessionPort) ; | |
a689a4d0 | 317 | #else |
1d78308f | 318 | PMEndDocument(m_macPrintSessionPort); |
87df17a1 | 319 | UMAPrClose() ; |
a689a4d0 | 320 | #endif |
5b781a67 SC |
321 | ::SetPort( macPrintFormerPort ) ; |
322 | m_ok = FALSE ; | |
323 | } | |
2f1ae414 SC |
324 | #endif |
325 | ||
72e7876b | 326 | } |