]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/printdlg.mm
f7301dc70a0d255c699fab3332f15dcf54f7814d
[wxWidgets.git] / src / osx / cocoa / printdlg.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/printdlg.mm
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 #include "wx/printdlg.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/object.h"
20 #include "wx/dcprint.h"
21 #include "wx/msgdlg.h"
22 #include "wx/textctrl.h"
23 #include "wx/sizer.h"
24 #include "wx/stattext.h"
25 #endif
26
27 #include "wx/osx/printdlg.h"
28 #include "wx/osx/private/print.h"
29 #include "wx/osx/private.h"
30
31 IMPLEMENT_CLASS(wxOSXCocoaPrintData, wxOSXPrintData)
32
33 wxOSXCocoaPrintData::wxOSXCocoaPrintData()
34 {
35 m_macPrintInfo = [[NSPrintInfo alloc] init];
36 m_macPageFormat = (PMPageFormat) [m_macPrintInfo PMPageFormat];
37 m_macPrintSettings = (PMPrintSettings) [m_macPrintInfo PMPrintSettings];
38 m_macPrintSession = (PMPrintSession) [m_macPrintInfo PMPrintSession] ;
39 PMGetPageFormatPaper(m_macPageFormat, &m_macPaper);
40 }
41
42 wxOSXCocoaPrintData::~wxOSXCocoaPrintData()
43 {
44 [m_macPrintInfo release];
45 }
46
47 void wxOSXCocoaPrintData::UpdateFromPMState()
48 {
49 [m_macPrintInfo updateFromPMPageFormat];
50 [m_macPrintInfo updateFromPMPrintSettings];
51 }
52
53 void wxOSXCocoaPrintData::UpdateToPMState()
54 {
55 m_macPageFormat = (PMPageFormat) [m_macPrintInfo PMPageFormat];
56 m_macPrintSettings = (PMPrintSettings) [m_macPrintInfo PMPrintSettings];
57 m_macPrintSession = (PMPrintSession) [m_macPrintInfo PMPrintSession] ;
58 }
59
60 int wxMacPrintDialog::ShowModal()
61 {
62 m_printDialogData.GetPrintData().ConvertToNative();
63
64 int result = wxID_CANCEL;
65
66 NSPrintPanel* panel = [NSPrintPanel printPanel];
67 NSPrintInfo* printInfo = ((wxOSXCocoaPrintData*)m_printDialogData.GetPrintData().GetNativeData())->GetNSPrintInfo();
68
69 NSMutableDictionary* dict = [printInfo printSettings];
70 [dict setValue:[NSNumber numberWithInt:m_printDialogData.GetMinPage()] forKey:@"com_apple_print_PrintSettings_PMFirstPage"];
71 [dict setValue:[NSNumber numberWithInt:m_printDialogData.GetMaxPage()] forKey:@"com_apple_print_PrintSettings_PMLastPage"];
72
73 if ( (NSInteger)[panel runModalWithPrintInfo:printInfo] == NSOKButton )
74 {
75 result = wxID_OK;
76 m_printDialogData.GetPrintData().ConvertFromNative();
77 ((wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData );
78 }
79
80 return result;
81 }
82
83 int wxMacPageSetupDialog::ShowModal()
84 {
85 m_pageSetupData.GetPrintData().ConvertToNative();
86 ((wxOSXCocoaPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferFrom( &m_pageSetupData );
87
88 int result = wxID_CANCEL;
89
90 NSPageLayout *pageLayout = [NSPageLayout pageLayout];
91 NSPrintInfo* printInfo = ((wxOSXCocoaPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->GetNSPrintInfo();
92 if ( [pageLayout runModalWithPrintInfo:printInfo] == NSOKButton )
93 {
94 result = wxID_OK;
95 m_pageSetupData.GetPrintData().ConvertFromNative();
96 m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() );
97 }
98
99 return result;
100 }
101
102 #endif