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