]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/printdlg.mm
simplifying modal event loop handling
[wxWidgets.git] / src / osx / cocoa / printdlg.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id: printdlg.cpp 55419 2008-09-02 16:53:23Z SC $
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 // TODO add 10.4 code
37 m_macPageFormat = (PMPageFormat) [m_macPrintInfo PMPageFormat];
38 m_macPrintSettings = (PMPrintSettings) [m_macPrintInfo PMPrintSettings];
39 m_macPrintSession = (PMPrintSession) [m_macPrintInfo PMPrintSession] ;
40 }
41
42 wxOSXCocoaPrintData::~wxOSXCocoaPrintData()
43 {
44 [m_macPrintInfo release];
45 }
46
47 void wxOSXCocoaPrintData::UpdateFromPMState()
48 {
49 // TODO add 10.4 code
50 [m_macPrintInfo updateFromPMPageFormat];
51 [m_macPrintInfo updateFromPMPrintSettings];
52 }
53
54 void wxOSXCocoaPrintData::UpdateToPMState()
55 {
56 // TODO add 10.4 code
57 m_macPageFormat = (PMPageFormat) [m_macPrintInfo PMPageFormat];
58 m_macPrintSettings = (PMPrintSettings) [m_macPrintInfo PMPrintSettings];
59 m_macPrintSession = (PMPrintSession) [m_macPrintInfo PMPrintSession] ;
60 }
61
62 int wxMacPrintDialog::ShowModal()
63 {
64 m_printDialogData.GetPrintData().ConvertToNative();
65
66 int result = wxID_CANCEL;
67
68 NSPrintPanel* panel = [NSPrintPanel printPanel];
69 NSPrintInfo* printInfo = ((wxOSXCocoaPrintData*)m_printDialogData.GetPrintData().GetNativeData())->GetNSPrintInfo();
70 if ( (NSInteger)[panel runModalWithPrintInfo:printInfo] == NSOKButton )
71 {
72 result = wxID_OK;
73 m_printDialogData.GetPrintData().ConvertFromNative();
74 ((wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData );
75 }
76
77 return result;
78 }
79
80 int wxMacPageSetupDialog::ShowModal()
81 {
82 m_pageSetupData.GetPrintData().ConvertToNative();
83 ((wxOSXCocoaPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferFrom( &m_pageSetupData );
84
85 int result = wxID_CANCEL;
86
87 NSPageLayout *pageLayout = [NSPageLayout pageLayout];
88 NSPrintInfo* printInfo = ((wxOSXCocoaPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->GetNSPrintInfo();
89 if ( [pageLayout runModalWithPrintInfo:printInfo] == NSOKButton )
90 {
91 result = wxID_OK;
92 m_pageSetupData.GetPrintData().ConvertFromNative();
93 m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() );
94 }
95
96 return result;
97 }
98
99 #endif