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