]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #if wxUSE_PRINTING_ARCHITECTURE
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"
24 // Use generic page setup dialog: use your own native one if one exists.
26 IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog
, wxPrintDialogBase
)
29 wxMacPrintDialog::wxMacPrintDialog()
31 m_dialogParent
= NULL
;
36 wxMacPrintDialog::wxMacPrintDialog( wxWindow
*p
, wxPrintDialogData
*data
)
41 wxMacPrintDialog::wxMacPrintDialog( wxWindow
*p
, wxPrintData
*data
)
43 wxPrintDialogData data2
;
50 bool wxMacPrintDialog::Create( wxWindow
*p
, wxPrintDialogData
*data
)
57 m_printDialogData
= *data
;
62 wxMacPrintDialog::~wxMacPrintDialog()
64 if (m_destroyDC
&& m_printerDC
)
71 int wxMacPrintDialog::ShowModal()
73 m_printDialogData
.GetPrintData().ConvertToNative();
74 ((wxMacCarbonPrintData
*)m_printDialogData
.GetPrintData().GetNativeData())->TransferFrom( &m_printDialogData
);
76 int result
= wxID_CANCEL
;
80 err
= PMSessionPrintDialog(
81 ((wxMacCarbonPrintData
*)m_printDialogData
.GetPrintData().GetNativeData())->m_macPrintSession
,
82 ((wxMacCarbonPrintData
*)m_printDialogData
.GetPrintData().GetNativeData())->m_macPrintSettings
,
83 ((wxMacCarbonPrintData
*)m_printDialogData
.GetPrintData().GetNativeData())->m_macPageFormat
,
86 if ((err
== noErr
) && !accepted
)
88 // user clicked Cancel button
97 if ((err
!= noErr
) && (err
!= kPMCancel
))
101 message
.Printf( wxT("Print Error %d"), err
);
102 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
106 if (result
== wxID_OK
)
108 m_printDialogData
.GetPrintData().ConvertFromNative();
109 ((wxMacCarbonPrintData
*)m_printDialogData
.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData
);
115 wxDC
* wxMacPrintDialog::GetPrintDC()
117 return new wxPrinterDC( m_printDialogData
.GetPrintData() );
120 IMPLEMENT_CLASS(wxMacPageSetupDialog
, wxPageSetupDialogBase
)
122 wxMacPageSetupDialog::wxMacPageSetupDialog( wxWindow
*p
, wxPageSetupDialogData
*data
)
123 : wxPageSetupDialogBase()
128 bool wxMacPageSetupDialog::Create( wxWindow
*p
, wxPageSetupDialogData
*data
)
133 m_pageSetupData
= (*data
);
138 wxMacPageSetupDialog::~wxMacPageSetupDialog()
142 wxPageSetupData
& wxMacPageSetupDialog::GetPageSetupDialogData()
144 return m_pageSetupData
;
147 int wxMacPageSetupDialog::ShowModal()
149 m_pageSetupData
.GetPrintData().ConvertToNative();
150 ((wxMacCarbonPrintData
*)m_pageSetupData
.GetPrintData().GetNativeData())->TransferFrom( &m_pageSetupData
);
152 int result
= wxID_CANCEL
;
156 err
= PMSessionPageSetupDialog(
157 ((wxMacCarbonPrintData
*)m_pageSetupData
.GetPrintData().GetNativeData())->m_macPrintSession
,
158 ((wxMacCarbonPrintData
*)m_pageSetupData
.GetPrintData().GetNativeData())->m_macPageFormat
,
161 if ((err
== noErr
) && !accepted
)
163 // user clicked Cancel button
167 // If the user did not cancel, flatten and save the PageFormat object
168 // with our document.
174 if ((err
!= noErr
) && (err
!= kPMCancel
))
178 message
.Printf( wxT("Print Error %d"), err
);
179 wxMessageDialog
dialog( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
183 if (result
== wxID_OK
)
185 m_pageSetupData
.GetPrintData().ConvertFromNative();
186 m_pageSetupData
.SetPaperSize( m_pageSetupData
.GetPrintData().GetPaperSize() );
187 ((wxMacCarbonPrintData
*)m_pageSetupData
.GetPrintData().GetNativeData())->TransferTo( &m_pageSetupData
);