]> git.saurik.com Git - wxWidgets.git/blame - src/mac/dcprint.cpp
OS/2 fix in setdrive.
[wxWidgets.git] / src / mac / dcprint.cpp
CommitLineData
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 32IMPLEMENT_CLASS(wxPrinterDC, wxDC)
2f1ae414 33#endif
72e7876b
SC
34
35GrafPtr macPrintFormerPort = NULL ;
36
37wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
38{
5b781a67 39 OSStatus err ;
72e7876b
SC
40 wxString message ;
41
42 m_printData = printdata ;
43 m_printData.ConvertToNative() ;
44
5b781a67 45 err = UMAPrOpen() ;
72e7876b
SC
46 if ( err )
47 {
48 message.Printf( "Print Error %d", err ) ;
49 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
2f1ae414 50 UMAPrClose() ;
72e7876b
SC
51 }
52
5b781a67 53#if !TARGET_CARBON
72e7876b
SC
54 if ( ::PrValidate( m_printData.m_macPrintInfo ) )
55 {
2f1ae414 56 ::PrStlDialog( m_printData.m_macPrintInfo ) ;
72e7876b
SC
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) ;
2f1ae414 64 UMAPrClose() ;
72e7876b
SC
65 }
66 ::GetPort( &macPrintFormerPort ) ;
67 m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
2f1ae414
SC
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 }
72e7876b
SC
75 // sets current port
76 m_macPort = (GrafPtr ) m_macPrintPort ;
5b781a67
SC
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
72e7876b
SC
92 m_ok = TRUE ;
93 m_minY = m_minX = 0 ;
5b781a67
SC
94#if TARGET_CARBON
95#else
72e7876b
SC
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 ;
2f1ae414 98#endif
72e7876b
SC
99}
100
101wxPrinterDC::~wxPrinterDC(void)
102{
5b781a67
SC
103 OSStatus err ;
104 wxString message ;
2f1ae414 105#if !TARGET_CARBON
72e7876b
SC
106 if ( m_ok )
107 {
72e7876b
SC
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) ;
2f1ae414 123 UMAPrClose() ;
72e7876b 124 }
2f1ae414
SC
125 ::UMAPrClose() ;
126// ::SetPort( macPrintFormerPort ) ;
127 ::SetPort( LMGetWMgrPort() ) ;
128 m_macPortHelper.Clear() ;
72e7876b 129 }
2f1ae414 130#else
5b781a67
SC
131 if ( m_ok )
132 {
133 err = PMEndDocument(m_macPrintPort);
134 if ( !err )
135 {
136 message.Printf( "Print Error %d", err ) ;
137 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
138 UMAPrClose() ;
139 }
140 UMAPrClose() ;
141 }
2f1ae414 142#endif
72e7876b
SC
143}
144
145bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
146{
147 return m_ok ;
148}
149
150void wxPrinterDC::EndDoc(void)
151{
152}
153
154void wxPrinterDC::StartPage(void)
155{
156 if ( !m_ok )
157 return ;
2f1ae414
SC
158
159 m_logicalFunction = wxCOPY;
160// m_textAlignment = wxALIGN_TOP_LEFT;
161 m_backgroundMode = wxTRANSPARENT;
162
163 m_textForegroundColour = *wxBLACK;
164 m_textBackgroundColour = *wxWHITE;
165 m_pen = *wxBLACK_PEN;
166 m_font = *wxNORMAL_FONT;
167 m_brush = *wxTRANSPARENT_BRUSH;
168 m_backgroundBrush = *wxWHITE_BRUSH;
169
170 m_macFontInstalled = false ;
171 m_macBrushInstalled = false ;
172 m_macPenInstalled = false ;
173
72e7876b 174
5b781a67 175 OSStatus err ;
72e7876b
SC
176 wxString message ;
177
5b781a67 178#if !TARGET_CARBON
2f1ae414 179 PrOpenPage( m_macPrintPort , NULL ) ;
5b781a67
SC
180 m_macLocalOrigin.h = (**m_printData.m_macPrintInfo).rPaper.left ;
181 m_macLocalOrigin.v = (**m_printData.m_macPrintInfo).rPaper.top ;
182
183 SetOrigin( - m_macLocalOrigin.h , - m_macLocalOrigin.v ) ;
72e7876b
SC
184 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
185 ::ClipRect( &clip ) ;
186 err = PrError() ;
187 if ( err )
188 {
189 message.Printf( "Print Error %d", err ) ;
190 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
191 ::PrClosePage( m_macPrintPort) ;
192 ::PrCloseDoc( m_macPrintPort ) ;
2f1ae414 193 ::UMAPrClose() ;
72e7876b
SC
194 ::SetPort( macPrintFormerPort ) ;
195 m_ok = FALSE ;
196 }
2f1ae414 197#else
5b781a67
SC
198 err = PMBeginPage(m_macPrintPort, nil);
199 if ( err )
200 {
201 message.Printf( "Print Error %d", err ) ;
202 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
203 PMEndPage(m_macPrintPort);
204 PMEndDocument(m_macPrintPort);
205 UMAPrClose() ;
206 ::SetPort( macPrintFormerPort ) ;
207 m_ok = FALSE ;
208 }
2f1ae414 209#endif
72e7876b
SC
210}
211
212void wxPrinterDC::EndPage(void)
213{
214 if ( !m_ok )
215 return ;
216
5b781a67 217 OSStatus err ;
72e7876b
SC
218 wxString message ;
219
5b781a67 220#if !TARGET_CARBON
72e7876b
SC
221 PrClosePage( (TPrPort*) m_macPort ) ;
222 err = PrError() ;
223 if ( err )
224 {
225 message.Printf( "Print Error %d", err ) ;
226 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
227 ::PrCloseDoc( m_macPrintPort ) ;
2f1ae414 228 ::UMAPrClose() ;
72e7876b
SC
229 ::SetPort( macPrintFormerPort ) ;
230 m_ok = FALSE ;
231 }
2f1ae414 232#else
5b781a67
SC
233 err = PMEndPage(m_macPrintPort);
234 if ( err )
235 {
236 message.Printf( "Print Error %d", err ) ;
237 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
238 PMEndDocument(m_macPrintPort);
239 UMAPrClose() ;
240 ::SetPort( macPrintFormerPort ) ;
241 m_ok = FALSE ;
242 }
2f1ae414
SC
243#endif
244
72e7876b 245}