]> git.saurik.com Git - wxWidgets.git/blob - src/mac/dcprint.cpp
compilation fix
[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 "math.h"
28
29
30 #if !USE_SHARED_LIBRARY
31 IMPLEMENT_CLASS(wxPrinterDC, wxDC)
32 #endif
33
34 GrafPtr macPrintFormerPort = NULL ;
35
36 wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
37 {
38 OSErr err ;
39 wxString message ;
40
41 m_printData = printdata ;
42 m_printData.ConvertToNative() ;
43
44 ::PrOpen() ;
45 err = PrError() ;
46 if ( err )
47 {
48 message.Printf( "Print Error %d", err ) ;
49 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
50 PrClose() ;
51 }
52
53 if ( ::PrValidate( m_printData.m_macPrintInfo ) )
54 {
55 // the driver has changed in the mean time, should we pop up a page setup dialog ?
56 }
57 err = PrError() ;
58 if ( err )
59 {
60 message.Printf( "Print Error %d", err ) ;
61 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
62 PrClose() ;
63 }
64 ::GetPort( &macPrintFormerPort ) ;
65 m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
66 // sets current port
67 m_macPort = (GrafPtr ) m_macPrintPort ;
68 m_ok = TRUE ;
69 m_minY = m_minX = 0 ;
70 m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ;
71 m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ;
72 }
73
74 wxPrinterDC::~wxPrinterDC(void)
75 {
76 if ( m_ok )
77 {
78 OSErr err ;
79 wxString message ;
80
81 ::PrCloseDoc( m_macPrintPort ) ;
82 err = PrError() ;
83
84 if ( !err )
85 {
86 if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
87 {
88 TPrStatus status ;
89 ::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
90 }
91 }
92 else
93 {
94 message.Printf( "Print Error %d", err ) ;
95 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
96 PrClose() ;
97 }
98 ::PrClose() ;
99 ::SetPort( macPrintFormerPort ) ;
100 }
101 }
102
103 bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
104 {
105 return m_ok ;
106 }
107
108 void wxPrinterDC::EndDoc(void)
109 {
110 }
111
112 void wxPrinterDC::StartPage(void)
113 {
114 if ( !m_ok )
115 return ;
116
117 OSErr err ;
118 wxString message ;
119
120 PrOpenPage( m_macPrintPort , NULL ) ;
121 SetOrigin( - (**m_printData.m_macPrintInfo).rPaper.left , - (**m_printData.m_macPrintInfo).rPaper.top ) ;
122 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
123 ::ClipRect( &clip ) ;
124 err = PrError() ;
125 if ( err )
126 {
127 message.Printf( "Print Error %d", err ) ;
128 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
129 ::PrClosePage( m_macPrintPort) ;
130 ::PrCloseDoc( m_macPrintPort ) ;
131 ::PrClose() ;
132 ::SetPort( macPrintFormerPort ) ;
133 m_ok = FALSE ;
134 }
135 }
136
137 void wxPrinterDC::EndPage(void)
138 {
139 if ( !m_ok )
140 return ;
141
142 OSErr err ;
143 wxString message ;
144
145 PrClosePage( (TPrPort*) m_macPort ) ;
146 err = PrError() ;
147 if ( err )
148 {
149 message.Printf( "Print Error %d", err ) ;
150 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
151 ::PrCloseDoc( m_macPrintPort ) ;
152 ::PrClose() ;
153 ::SetPort( macPrintFormerPort ) ;
154 m_ok = FALSE ;
155 }
156 }