src/gui/dialogs/qpagesetupdialog_mac.mm
changeset 30 5dc02b23752f
parent 18 2f34d5167611
--- a/src/gui/dialogs/qpagesetupdialog_mac.mm	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/gui/dialogs/qpagesetupdialog_mac.mm	Tue Jul 06 15:10:48 2010 +0300
@@ -50,9 +50,9 @@
 
 QT_USE_NAMESPACE
 
-@class QCocoaPageLayoutDelegate;
+@class QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate);
 
-@interface QCocoaPageLayoutDelegate : NSObject {
+@interface QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) : NSObject {
     QMacPrintEnginePrivate *pe;
 }
 - (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine;
@@ -60,7 +60,7 @@
         returnCode:(int)returnCode contextInfo:(void *)contextInfo;
 @end
 
-@implementation QCocoaPageLayoutDelegate
+@implementation QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate)
 - (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine;
 {
     self = [super init];
@@ -213,7 +213,7 @@
     pageLayout = [NSPageLayout pageLayout];
     // Keep a copy to this since we plan on using it for a bit.
     [pageLayout retain];
-    QCocoaPageLayoutDelegate *delegate = [[QCocoaPageLayoutDelegate alloc] initWithMacPrintEngine:ep];
+    QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) alloc] initWithMacPrintEngine:ep];
 
     if (modality == Qt::ApplicationModal) {
         int rval = [pageLayout runModalWithPrintInfo:ep->printInfo];
@@ -232,6 +232,11 @@
 
 void QPageSetupDialogPrivate::closeCocoaPageLayout()
 {
+    // NSPageLayout can change the session behind our back and then our
+    // d->ep->session object will become a dangling pointer. Update it
+    // based on the "current" session
+    ep->session = static_cast<PMPrintSession>([ep->printInfo PMPrintSession]);
+
     [pageLayout release];
     pageLayout = 0;
 }