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