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