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