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