]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/printdlg.cpp
added ctor implementation from header + initialzation; more reformatting
[wxWidgets.git] / src / mac / carbon / printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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/object.h"
17 #include "wx/printdlg.h"
18 #include "wx/mac/printdlg.h"
19 #include "wx/dcprint.h"
20 #include "wx/msgdlg.h"
21 #include "wx/mac/private/print.h"
22
23 // Use generic page setup dialog: use your own native one if one exists.
24
25 IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog, wxPrintDialogBase)
26
27 wxMacPrintDialog::wxMacPrintDialog()
28 {
29 m_dialogParent = NULL;
30 m_printerDC = NULL;
31 m_destroyDC = TRUE;
32 }
33
34 wxMacPrintDialog::wxMacPrintDialog(wxWindow *p, wxPrintDialogData* data)
35 {
36 Create(p, data);
37 }
38
39 wxMacPrintDialog::wxMacPrintDialog(wxWindow *p, wxPrintData* data)
40 {
41 wxPrintDialogData data2;
42 if ( data )
43 data2 = *data;
44
45 Create(p, &data2);
46 }
47
48 bool wxMacPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
49 {
50 m_dialogParent = p;
51 m_printerDC = NULL;
52 m_destroyDC = TRUE;
53
54 if ( data )
55 m_printDialogData = *data;
56
57 return TRUE;
58 }
59
60 wxMacPrintDialog::~wxMacPrintDialog()
61 {
62 if (m_destroyDC && m_printerDC) {
63 delete m_printerDC;
64 m_printerDC = NULL;
65 }
66 }
67
68 int wxMacPrintDialog::ShowModal()
69 {
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
100 if ( result == wxID_OK )
101 {
102 m_printDialogData.GetPrintData().ConvertFromNative();
103 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData ) ;
104 }
105
106 return result ;
107 }
108
109 wxDC *wxMacPrintDialog::GetPrintDC()
110 {
111 return new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
112 }
113
114 /*
115 * wxMacPageSetupDialog
116 */
117
118 IMPLEMENT_CLASS(wxMacPageSetupDialog, wxPageSetupDialogBase)
119
120 wxMacPageSetupDialog::wxMacPageSetupDialog(wxWindow *p, wxPageSetupDialogData *data) :
121 wxPageSetupDialogBase()
122 {
123 Create(p, data);
124 }
125
126 bool wxMacPageSetupDialog::Create(wxWindow *p, wxPageSetupDialogData *data)
127 {
128 m_dialogParent = p;
129
130 if (data)
131 m_pageSetupData = (*data);
132
133 return TRUE;
134 }
135
136 wxMacPageSetupDialog::~wxMacPageSetupDialog()
137 {
138 }
139
140 wxPageSetupData& wxMacPageSetupDialog::GetPageSetupDialogData()
141 {
142 return m_pageSetupData;
143 }
144
145 int wxMacPageSetupDialog::ShowModal()
146 {
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 ;
153
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
177 if (result == wxID_OK )
178 {
179 m_pageSetupData.GetPrintData().ConvertFromNative();
180 m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() ) ;
181 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferTo( &m_pageSetupData ) ;
182 }
183 return result;
184 }
185
186 #endif
187