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