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