]>
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 | |
87df17a1 | 45 | #if PM_USE_SESSION_APIS |
a689a4d0 | 46 | err = UMAPrOpen(&m_macPrintPort) ; |
87df17a1 GD |
47 | #else |
48 | err = UMAPrOpen() ; | |
a689a4d0 | 49 | #endif |
72e7876b SC |
50 | if ( err ) |
51 | { | |
52 | message.Printf( "Print Error %d", err ) ; | |
53 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
87df17a1 | 54 | #if PM_USE_SESSION_APIS |
a689a4d0 | 55 | UMAPrClose(&m_macPrintPort) ; |
87df17a1 GD |
56 | #else |
57 | UMAPrClose() ; | |
a689a4d0 | 58 | #endif |
72e7876b SC |
59 | } |
60 | ||
5b781a67 | 61 | #if !TARGET_CARBON |
72e7876b SC |
62 | if ( ::PrValidate( m_printData.m_macPrintInfo ) ) |
63 | { | |
2f1ae414 | 64 | ::PrStlDialog( m_printData.m_macPrintInfo ) ; |
72e7876b SC |
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) ; | |
2f1ae414 | 72 | UMAPrClose() ; |
72e7876b SC |
73 | } |
74 | ::GetPort( &macPrintFormerPort ) ; | |
75 | m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ; | |
2f1ae414 SC |
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 | } | |
72e7876b SC |
83 | // sets current port |
84 | m_macPort = (GrafPtr ) m_macPrintPort ; | |
5b781a67 SC |
85 | #else |
86 | m_macPrintPort = kPMNoReference ; | |
a689a4d0 GD |
87 | #if PM_USE_SESSION_APIS |
88 | err = PMSessionBeginDocument( | |
89 | m_macPrintPort, | |
90 | m_printData.m_macPrintSettings, | |
91 | m_printData.m_macPageFormat); | |
92 | #else | |
5b781a67 SC |
93 | err = PMBeginDocument( |
94 | m_printData.m_macPrintSettings, | |
95 | m_printData.m_macPageFormat, | |
96 | &m_macPrintPort); | |
a689a4d0 | 97 | #endif |
5b781a67 SC |
98 | if ( err != noErr || m_macPrintPort == kPMNoReference ) |
99 | { | |
100 | message.Printf( "Print Error %d", err ) ; | |
101 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
87df17a1 | 102 | #if PM_USE_SESSION_APIS |
a689a4d0 | 103 | UMAPrClose(&m_macPrintPort) ; |
87df17a1 GD |
104 | #else |
105 | UMAPrClose() ; | |
106 | #endif | |
5b781a67 SC |
107 | } |
108 | // sets current port | |
109 | ::GetPort( &m_macPort ) ; | |
110 | #endif | |
72e7876b SC |
111 | m_ok = TRUE ; |
112 | m_minY = m_minX = 0 ; | |
5b781a67 SC |
113 | #if TARGET_CARBON |
114 | #else | |
72e7876b SC |
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 ; | |
2f1ae414 | 117 | #endif |
72e7876b SC |
118 | } |
119 | ||
120 | wxPrinterDC::~wxPrinterDC(void) | |
121 | { | |
5b781a67 SC |
122 | OSStatus err ; |
123 | wxString message ; | |
2f1ae414 | 124 | #if !TARGET_CARBON |
72e7876b SC |
125 | if ( m_ok ) |
126 | { | |
72e7876b SC |
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) ; | |
2f1ae414 | 142 | UMAPrClose() ; |
72e7876b | 143 | } |
2f1ae414 SC |
144 | ::UMAPrClose() ; |
145 | // ::SetPort( macPrintFormerPort ) ; | |
146 | ::SetPort( LMGetWMgrPort() ) ; | |
72e7876b | 147 | } |
2f1ae414 | 148 | #else |
5b781a67 SC |
149 | if ( m_ok ) |
150 | { | |
a689a4d0 GD |
151 | #if PM_USE_SESSION_APIS |
152 | err = PMSessionEndDocument(m_macPrintPort); | |
153 | #else | |
154 | err = PMEndDocument(m_macPrintPort); | |
155 | #endif | |
5b781a67 SC |
156 | if ( !err ) |
157 | { | |
158 | message.Printf( "Print Error %d", err ) ; | |
159 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
87df17a1 | 160 | #if PM_USE_SESSION_APIS |
a689a4d0 | 161 | UMAPrClose(&m_macPrintPort) ; |
87df17a1 GD |
162 | #else |
163 | UMAPrClose() ; | |
a689a4d0 | 164 | #endif |
5b781a67 | 165 | } |
87df17a1 GD |
166 | #if PM_USE_SESSION_APIS |
167 | UMAPrClose(&m_macPrintPort) ; | |
a689a4d0 | 168 | #else |
87df17a1 | 169 | UMAPrClose() ; |
a689a4d0 | 170 | #endif |
5b781a67 | 171 | } |
2f1ae414 | 172 | #endif |
72e7876b SC |
173 | } |
174 | ||
175 | bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) ) | |
176 | { | |
177 | return m_ok ; | |
178 | } | |
179 | ||
180 | void wxPrinterDC::EndDoc(void) | |
181 | { | |
182 | } | |
183 | ||
184 | void wxPrinterDC::StartPage(void) | |
185 | { | |
186 | if ( !m_ok ) | |
187 | return ; | |
2f1ae414 SC |
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 | ||
72e7876b | 204 | |
5b781a67 | 205 | OSStatus err ; |
72e7876b SC |
206 | wxString message ; |
207 | ||
5b781a67 | 208 | #if !TARGET_CARBON |
2f1ae414 | 209 | PrOpenPage( m_macPrintPort , NULL ) ; |
5b781a67 SC |
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 ) ; | |
72e7876b SC |
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 ) ; | |
2f1ae414 | 223 | ::UMAPrClose() ; |
72e7876b SC |
224 | ::SetPort( macPrintFormerPort ) ; |
225 | m_ok = FALSE ; | |
226 | } | |
2f1ae414 | 227 | #else |
a689a4d0 GD |
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 | |
5b781a67 SC |
235 | if ( err ) |
236 | { | |
237 | message.Printf( "Print Error %d", err ) ; | |
238 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
a689a4d0 GD |
239 | #if PM_USE_SESSION_APIS |
240 | PMSessionEndPage(m_macPrintPort); | |
241 | PMSessionEndDocument(m_macPrintPort); | |
87df17a1 | 242 | UMAPrClose(&m_macPrintPort) ; |
a689a4d0 | 243 | #else |
5b781a67 SC |
244 | PMEndPage(m_macPrintPort); |
245 | PMEndDocument(m_macPrintPort); | |
87df17a1 | 246 | UMAPrClose() ; |
a689a4d0 | 247 | #endif |
5b781a67 SC |
248 | ::SetPort( macPrintFormerPort ) ; |
249 | m_ok = FALSE ; | |
250 | } | |
2f1ae414 | 251 | #endif |
72e7876b SC |
252 | } |
253 | ||
254 | void wxPrinterDC::EndPage(void) | |
255 | { | |
256 | if ( !m_ok ) | |
257 | return ; | |
258 | ||
5b781a67 | 259 | OSStatus err ; |
72e7876b SC |
260 | wxString message ; |
261 | ||
5b781a67 | 262 | #if !TARGET_CARBON |
72e7876b SC |
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 ) ; | |
2f1ae414 | 270 | ::UMAPrClose() ; |
72e7876b SC |
271 | ::SetPort( macPrintFormerPort ) ; |
272 | m_ok = FALSE ; | |
273 | } | |
2f1ae414 | 274 | #else |
a689a4d0 GD |
275 | #if PM_USE_SESSION_APIS |
276 | err = PMSessionEndPage(m_macPrintPort); | |
277 | #else | |
5b781a67 | 278 | err = PMEndPage(m_macPrintPort); |
a689a4d0 | 279 | #endif |
5b781a67 SC |
280 | if ( err ) |
281 | { | |
282 | message.Printf( "Print Error %d", err ) ; | |
283 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
a689a4d0 GD |
284 | #if PM_USE_SESSION_APIS |
285 | PMSessionEndDocument(m_macPrintPort); | |
87df17a1 | 286 | UMAPrClose(&m_macPrintPort) ; |
a689a4d0 | 287 | #else |
5b781a67 | 288 | PMEndDocument(m_macPrintPort); |
87df17a1 | 289 | UMAPrClose() ; |
a689a4d0 | 290 | #endif |
5b781a67 SC |
291 | ::SetPort( macPrintFormerPort ) ; |
292 | m_ok = FALSE ; | |
293 | } | |
2f1ae414 SC |
294 | #endif |
295 | ||
72e7876b | 296 | } |