]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/printdlg.cpp
Remove my binary compatibility stuff from HEAD. Patch #1367014 used for reference.
[wxWidgets.git] / src / mac / carbon / printdlg.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: printdlg.cpp
3// Purpose: wxPrintDialog, wxPageSetupDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
179e085f
RN
14#if wxUSE_PRINTING_ARCHITECTURE
15
e9576ca5 16#include "wx/object.h"
e7549107 17#include "wx/printdlg.h"
08680429 18#include "wx/mac/printdlg.h"
e9576ca5 19#include "wx/dcprint.h"
0bec761d 20#include "wx/msgdlg.h"
746d7582 21#include "wx/mac/private/print.h"
a3d3d3bf 22
e9576ca5 23// Use generic page setup dialog: use your own native one if one exists.
e9576ca5 24
c061373d 25IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog, wxPrintDialogBase)
e9576ca5 26
c061373d 27wxMacPrintDialog::wxMacPrintDialog()
e9576ca5
SC
28{
29 m_dialogParent = NULL;
e7549107
SC
30 m_printerDC = NULL;
31 m_destroyDC = TRUE;
e9576ca5
SC
32}
33
c061373d 34wxMacPrintDialog::wxMacPrintDialog(wxWindow *p, wxPrintDialogData* data)
e9576ca5
SC
35{
36 Create(p, data);
37}
38
c061373d 39wxMacPrintDialog::wxMacPrintDialog(wxWindow *p, wxPrintData* data)
e7549107
SC
40{
41 wxPrintDialogData data2;
42 if ( data )
43 data2 = *data;
e40298d5 44
e7549107
SC
45 Create(p, &data2);
46}
47
c061373d 48bool wxMacPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
e9576ca5
SC
49{
50 m_dialogParent = p;
e7549107
SC
51 m_printerDC = NULL;
52 m_destroyDC = TRUE;
e40298d5 53
e9576ca5 54 if ( data )
e7549107 55 m_printDialogData = *data;
e40298d5 56
e9576ca5
SC
57 return TRUE;
58}
59
c061373d 60wxMacPrintDialog::~wxMacPrintDialog()
e9576ca5 61{
f5bb2251 62 if (m_destroyDC && m_printerDC) {
e7549107 63 delete m_printerDC;
f5bb2251
GD
64 m_printerDC = NULL;
65 }
e9576ca5
SC
66}
67
c061373d 68int wxMacPrintDialog::ShowModal()
e9576ca5 69{
dc7ccb9c
SC
70 m_printDialogData.GetPrintData().ConvertToNative();
71 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferFrom( &m_printDialogData ) ;
72
73 int result = wxID_CANCEL ;
74 OSErr err = noErr ;
75 wxString message ;
76
77 Boolean accepted;
78
79 err = PMSessionPrintDialog( ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPrintSession,
80 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPrintSettings,
81 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPageFormat,
82 &accepted);
83 if ((err == noErr) && !accepted)
84 {
85 err = kPMCancel; // user clicked Cancel button
86 }
87
88 if ( err == noErr )
89 {
90 result = wxID_OK ;
91 }
92
93 if ((err != noErr) && (err != kPMCancel))
94 {
95 message.Printf( wxT("Print Error %d"), err ) ;
96 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
97 dialog.ShowModal();
98 }
99
746d7582 100 if ( result == wxID_OK )
dc7ccb9c
SC
101 {
102 m_printDialogData.GetPrintData().ConvertFromNative();
103 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData ) ;
104 }
0bec761d 105
e40298d5 106 return result ;
e9576ca5
SC
107}
108
c061373d 109wxDC *wxMacPrintDialog::GetPrintDC()
e9576ca5 110{
e7549107 111 return new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
e9576ca5
SC
112}
113
114/*
08680429 115* wxMacPageSetupDialog
e40298d5 116*/
e9576ca5 117
08680429 118IMPLEMENT_CLASS(wxMacPageSetupDialog, wxPageSetupDialogBase)
e9576ca5 119
08680429
RR
120wxMacPageSetupDialog::wxMacPageSetupDialog(wxWindow *p, wxPageSetupDialogData *data) :
121wxPageSetupDialogBase()
e9576ca5
SC
122{
123 Create(p, data);
124}
125
08680429 126bool wxMacPageSetupDialog::Create(wxWindow *p, wxPageSetupDialogData *data)
e9576ca5
SC
127{
128 m_dialogParent = p;
e40298d5 129
e9576ca5
SC
130 if (data)
131 m_pageSetupData = (*data);
e40298d5 132
e9576ca5
SC
133 return TRUE;
134}
135
08680429 136wxMacPageSetupDialog::~wxMacPageSetupDialog()
e9576ca5
SC
137{
138}
139
08680429
RR
140wxPageSetupData& wxMacPageSetupDialog::GetPageSetupDialogData()
141{
142 return m_pageSetupData;
143}
144
145int wxMacPageSetupDialog::ShowModal()
e9576ca5 146{
dc7ccb9c
SC
147 m_pageSetupData.GetPrintData().ConvertToNative();
148 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferFrom( &m_pageSetupData ) ;
149
150 int result = wxID_CANCEL ;
151 OSErr err = noErr ;
152 wxString message ;
08680429 153
dc7ccb9c
SC
154 Boolean accepted;
155
156 err = PMSessionPageSetupDialog( ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->m_macPrintSession,
157 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->m_macPageFormat,
158 &accepted);
159 if ((err == noErr) && !accepted)
160 {
161 err = kPMCancel; // user clicked Cancel button
162 }
163
164 // If the user did not cancel, flatten and save the PageFormat object
165 // with our document.
166 if (err == noErr)
167 {
168 result = wxID_OK ;
169 }
170 if ((err != noErr) && (err != kPMCancel))
171 {
172 message.Printf( wxT("Print Error %d"), err ) ;
173 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
174 dialog.ShowModal();
175 }
176
746d7582 177 if (result == wxID_OK )
dc7ccb9c
SC
178 {
179 m_pageSetupData.GetPrintData().ConvertFromNative();
180 m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() ) ;
181 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferTo( &m_pageSetupData ) ;
182 }
08680429 183 return result;
e9576ca5
SC
184}
185
179e085f
RN
186#endif
187