diff options
author | Morten Sorvig <morten.sorvig@nokia.com> | 2011-09-29 14:29:05 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-10 07:47:58 +0200 |
commit | 9fa6e8f627d0c61fd5a3b993903a362dc04bf707 (patch) | |
tree | 56858ef0994ef4b300d5f6928fa51b0844bf1861 /src/printsupport/dialogs | |
parent | 33233ca3e3d79152744eedd353106c5d95737e00 (diff) |
Clean-up a macro for Cocoa
Remove the usage of Q_MAC_USE_COCOA and Carbon code paths.
Change-Id: Ib569ad8c6d9ffe258f454b3c3b06e95294a10112
Reviewed-on: http://codereview.qt-project.org/5100
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Sanity-Review: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/printsupport/dialogs')
-rw-r--r-- | src/printsupport/dialogs/qpagesetupdialog_mac.mm | 110 | ||||
-rw-r--r-- | src/printsupport/dialogs/qprintdialog_mac.mm | 124 | ||||
-rw-r--r-- | src/printsupport/dialogs/qprintpreviewdialog.cpp | 10 |
3 files changed, 0 insertions, 244 deletions
diff --git a/src/printsupport/dialogs/qpagesetupdialog_mac.mm b/src/printsupport/dialogs/qpagesetupdialog_mac.mm index 725520116a..0bbdbcc242 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_mac.mm +++ b/src/printsupport/dialogs/qpagesetupdialog_mac.mm @@ -96,110 +96,19 @@ class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate public: QPageSetupDialogPrivate() : ep(0) -#ifndef QT_MAC_USE_COCOA - ,upp(0) -#else ,pageLayout(0) -#endif {} ~QPageSetupDialogPrivate() { -#ifndef QT_MAC_USE_COCOA - if (upp) { - DisposePMSheetDoneUPP(upp); - upp = 0; - } - QHash<PMPrintSession, QPageSetupDialogPrivate *>::iterator it = sheetCallbackMap.begin(); - while (it != sheetCallbackMap.end()) { - if (it.value() == this) { - it = sheetCallbackMap.erase(it); - } else { - ++it; - } - } -#endif } -#ifndef QT_MAC_USE_COCOA - void openCarbonPageLayout(Qt::WindowModality modality); - void closeCarbonPageLayout(); - static void pageSetupDialogSheetDoneCallback(PMPrintSession printSession, WindowRef /*documentWindow*/, Boolean accepted) { - QPageSetupDialogPrivate *priv = sheetCallbackMap.value(printSession); - if (!priv) { - qWarning("%s:%d: QPageSetupDialog::exec: Could not retrieve data structure, " - "you most likely now have an infinite modal loop", __FILE__, __LINE__); - return; - } - priv->q_func()->done(accepted ? QDialog::Accepted : QDialog::Rejected); - } -#else void openCocoaPageLayout(Qt::WindowModality modality); void closeCocoaPageLayout(); -#endif QMacPrintEnginePrivate *ep; -#ifndef QT_MAC_USE_COCOA - PMSheetDoneUPP upp; - static QHash<PMPrintSession, QPageSetupDialogPrivate*> sheetCallbackMap; -#else NSPageLayout *pageLayout; -#endif }; -#ifndef QT_MAC_USE_COCOA -QHash<PMPrintSession, QPageSetupDialogPrivate*> QPageSetupDialogPrivate::sheetCallbackMap; -void QPageSetupDialogPrivate::openCarbonPageLayout(Qt::WindowModality modality) -{ - Q_Q(QPageSetupDialog); - // If someone is reusing a QPrinter object, the end released all our old - // information. In this case, we must reinitialize. - if (ep->session == 0) - ep->initialize(); - - sheetCallbackMap.insert(ep->session, this); - if (modality == Qt::ApplicationModal) { - QWidget modal_widg(0, Qt::Window); - modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg")); - modal_widg.createWinId(); - QApplicationPrivate::enterModal(&modal_widg); - QApplicationPrivate::native_modal_dialog_active = true; - Boolean accepted; - PMSessionPageSetupDialog(ep->session, ep->format, &accepted); - QApplicationPrivate::leaveModal(&modal_widg); - QApplicationPrivate::native_modal_dialog_active = false; - pageSetupDialogSheetDoneCallback(ep->session, 0, accepted); - } else { - // Window Modal means that we use a sheet at the moment, there's no other way to do it correctly. - if (!upp) - upp = NewPMSheetDoneUPP(QPageSetupDialogPrivate::pageSetupDialogSheetDoneCallback); - PMSessionUseSheets(ep->session, qt_mac_window_for(q->parentWidget()), upp); - Boolean unused; - PMSessionPageSetupDialog(ep->session, ep->format, &unused); - } -} - -void QPageSetupDialogPrivate::closeCarbonPageLayout() -{ - // if the margins have changed, we have to use the margins from the new - // PMFormat object - if (q_func()->result() == QDialog::Accepted) { - PMPaper paper; - PMPaperMargins margins; - PMGetPageFormatPaper(ep->format, &paper); - PMPaperGetMargins(paper, &margins); - ep->leftMargin = margins.left; - ep->topMargin = margins.top; - ep->rightMargin = margins.right; - ep->bottomMargin = margins.bottom; - - PMRect paperRect; - PMGetUnadjustedPaperRect(ep->format, &paperRect); - ep->customSize = QSizeF(paperRect.right - paperRect.left, - paperRect.bottom - paperRect.top); - } - sheetCallbackMap.remove(ep->session); -} -#else void QPageSetupDialogPrivate::openCocoaPageLayout(Qt::WindowModality modality) { Q_Q(QPageSetupDialog); @@ -240,7 +149,6 @@ void QPageSetupDialogPrivate::closeCocoaPageLayout() [pageLayout release]; pageLayout = 0; } -#endif QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent) : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent) @@ -263,32 +171,19 @@ void QPageSetupDialog::setVisible(bool visible) if (d->printer->outputFormat() != QPrinter::NativeFormat) return; -#ifndef QT_MAC_USE_COCOA - bool isCurrentlyVisible = d->sheetCallbackMap.contains(d->ep->session); -#else bool isCurrentlyVisible = (d->pageLayout != 0); -#endif if (!visible == !isCurrentlyVisible) return; if (visible) { -#ifndef QT_MAC_USE_COCOA - d->openCarbonPageLayout(parentWidget() ? Qt::WindowModal - : Qt::ApplicationModal); -#else d->openCocoaPageLayout(parentWidget() ? Qt::WindowModal : Qt::ApplicationModal); -#endif return; } else { -#ifndef QT_MAC_USE_COCOA - d->closeCarbonPageLayout(); -#else if (d->pageLayout) { d->closeCocoaPageLayout(); return; } -#endif } } @@ -299,14 +194,9 @@ int QPageSetupDialog::exec() if (d->printer->outputFormat() != QPrinter::NativeFormat) return Rejected; -#ifndef QT_MAC_USE_COCOA - d->openCarbonPageLayout(Qt::ApplicationModal); - d->closeCarbonPageLayout(); -#else QMacCocoaAutoReleasePool pool; d->openCocoaPageLayout(Qt::ApplicationModal); d->closeCocoaPageLayout(); -#endif return result(); } diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm index cb95f6b98d..b1f211ffb3 100644 --- a/src/printsupport/dialogs/qprintdialog_mac.mm +++ b/src/printsupport/dialogs/qprintdialog_mac.mm @@ -57,44 +57,10 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate public: QPrintDialogPrivate() : ep(0), printPanel(0) -#ifndef QT_MAC_USE_COCOA - ,upp(0) -#endif {} -#ifndef QT_MAC_USE_COCOA - ~QPrintDialogPrivate() { - if (upp) { - DisposePMSheetDoneUPP(upp); - upp = 0; - } - QHash<PMPrintSession, QPrintDialogPrivate *>::iterator it = sheetCallbackMap.begin(); - while (it != sheetCallbackMap.end()) { - if (it.value() == this) { - it = sheetCallbackMap.erase(it); - } else { - ++it; - } - } - } -#endif -#ifndef QT_MAC_USE_COCOA - void openCarbonPrintPanel(Qt::WindowModality modality); - void closeCarbonPrintPanel(); - static void printDialogSheetDoneCallback(PMPrintSession printSession, WindowRef /*documentWindow*/, Boolean accepted) { - QPrintDialogPrivate *priv = sheetCallbackMap.value(printSession); - if (!priv) { - qWarning("%s:%d: QPrintDialog::exec: Could not retrieve data structure, " - "you most likely now have an infinite loop", __FILE__, __LINE__); - return; - } - priv->q_func()->done(accepted ? QDialog::Accepted : QDialog::Rejected); - priv->closeCarbonPrintPanel(); - } -#else void openCocoaPrintPanel(Qt::WindowModality modality); void closeCocoaPrintPanel(); -#endif void initBeforeRun(); inline QPrintDialog *printDialog() { return q_func(); } @@ -112,17 +78,12 @@ public: QMacPrintEnginePrivate *ep; NSPrintPanel *printPanel; -#ifndef QT_MAC_USE_COCOA - PMSheetDoneUPP upp; - static QHash<PMPrintSession, QPrintDialogPrivate *> sheetCallbackMap; -#endif }; QT_END_NAMESPACE QT_USE_NAMESPACE -#ifdef QT_MAC_USE_COCOA @class QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate); @@ -190,7 +151,6 @@ QT_USE_NAMESPACE } @end -#endif QT_BEGIN_NAMESPACE @@ -218,76 +178,6 @@ void QPrintDialogPrivate::initBeforeRun() } } -#ifndef QT_MAC_USE_COCOA -QHash<PMPrintSession, QPrintDialogPrivate *> QPrintDialogPrivate::sheetCallbackMap; -void QPrintDialogPrivate::openCarbonPrintPanel(Qt::WindowModality modality) -{ - Q_Q(QPrintDialog); - initBeforeRun(); - sheetCallbackMap.insert(ep->session, this); - if (modality == Qt::ApplicationModal) { - QWidget modal_widg(0, Qt::Window); - modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg")); - modal_widg.createWinId(); - QApplicationPrivate::enterModal(&modal_widg); - QApplicationPrivate::native_modal_dialog_active = true; - Boolean acceptStatus; - PMSessionPrintDialog(ep->session, ep->settings, ep->format, &acceptStatus); - QApplicationPrivate::leaveModal(&modal_widg); - QApplicationPrivate::native_modal_dialog_active = false; - printDialogSheetDoneCallback(ep->session, 0, acceptStatus); - } else { - // Window Modal means that we use a sheet at the moment, there's no other way to do it correctly. - if (!upp) - upp = NewPMSheetDoneUPP(QPrintDialogPrivate::printDialogSheetDoneCallback); - PMSessionUseSheets(ep->session, qt_mac_window_for(q->parentWidget()), upp); - QApplicationPrivate::native_modal_dialog_active = true; - Boolean unused; - PMSessionPrintDialog(ep->session, ep->settings, ep->format, &unused); - } -} - -void QPrintDialogPrivate::closeCarbonPrintPanel() -{ - Q_Q(QPrintDialog); - QApplicationPrivate::native_modal_dialog_active = false; - if (q->result() == QDialog::Accepted) { - UInt32 frompage, topage; - PMGetFirstPage(ep->settings, &frompage); - PMGetLastPage(ep->settings, &topage); - topage = qMin(UInt32(INT_MAX), topage); - q->setFromTo(frompage, topage); - - // OK, I need to map these values back let's see - // If from is 1 and to is INT_MAX, then print it all - // (Apologies to the folks with more than INT_MAX pages) - // ...that's a joke. - if (q->fromPage() == 1 && q->toPage() == INT_MAX) { - q->setPrintRange(QAbstractPrintDialog::AllPages); - q->setFromTo(0,0); - } else { - q->setPrintRange(QAbstractPrintDialog::PageRange); // In a way a lie, but it shouldn't hurt. - // Carbon hands us back a very large number here even for ALL, set it to max - // in that case to follow the behavior of the other print dialogs. - if (q->maxPage() < q->toPage()) - q->setFromTo(q->fromPage(), q->maxPage()); - } - // Keep us in sync with file output - PMDestinationType dest; - PMSessionGetDestinationType(ep->session, ep->settings, &dest); - if (dest == kPMDestinationFile) { - QCFType<CFURLRef> file; - PMSessionCopyDestinationLocation(ep->session, ep->settings, &file); - UInt8 localFile[2048]; // Assuming there's a POSIX file system here. - CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile)); - ep->outputFilename = QString::fromUtf8(reinterpret_cast<const char *>(localFile)); - } else { - ep->outputFilename = QString(); - } - } - sheetCallbackMap.remove(ep->session); -} -#else void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality) { Q_Q(QPrintDialog); @@ -327,7 +217,6 @@ void QPrintDialogPrivate::closeCocoaPrintPanel() { // ### } -#endif static bool warnIfNotNative(QPrinter *printer) { @@ -367,14 +256,10 @@ int QPrintDialog::exec() if (!warnIfNotNative(d->printer)) return QDialog::Rejected; -#ifndef QT_MAC_USE_COCOA - d->openCarbonPrintPanel(Qt::ApplicationModal); -#else QMacCocoaAutoReleasePool pool; d->openCocoaPrintPanel(Qt::ApplicationModal); d->closeCocoaPrintPanel(); -#endif return result(); } @@ -395,21 +280,12 @@ void QPrintDialog::setVisible(bool visible) return; if (visible) { -#ifndef QT_MAC_USE_COCOA - d->openCarbonPrintPanel(parentWidget() ? Qt::WindowModal - : Qt::ApplicationModal); -#else d->openCocoaPrintPanel(parentWidget() ? Qt::WindowModal : Qt::ApplicationModal); -#endif return; } else { if (d->printPanel) { -#ifndef QT_MAC_USE_COCOA - d->closeCarbonPrintPanel(); -#else d->closeCocoaPrintPanel(); -#endif return; } } diff --git a/src/printsupport/dialogs/qprintpreviewdialog.cpp b/src/printsupport/dialogs/qprintpreviewdialog.cpp index 886ba84413..90e29ac7ca 100644 --- a/src/printsupport/dialogs/qprintpreviewdialog.cpp +++ b/src/printsupport/dialogs/qprintpreviewdialog.cpp @@ -208,9 +208,6 @@ public: QActionGroup *printerGroup; QAction *printAction; QAction *pageSetupAction; -#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) - QAction *closeAction; -#endif QPointer<QObject> receiverToDisconnectOnClose; QByteArray memberToDisconnectOnClose; @@ -304,9 +301,6 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer) toolbar->addSeparator(); toolbar->addAction(pageSetupAction); toolbar->addAction(printAction); -#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) - toolbar->addAction(closeAction); -#endif // Cannot use the actions' triggered signal here, since it doesn't autorepeat QToolButton *zoomInButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomInAction)); @@ -426,10 +420,6 @@ void QPrintPreviewDialogPrivate::setupActions() qt_setupActionIcon(pageSetupAction, QLatin1String("page-setup")); QObject::connect(printAction, SIGNAL(triggered(bool)), q, SLOT(_q_print())); QObject::connect(pageSetupAction, SIGNAL(triggered(bool)), q, SLOT(_q_pageSetup())); -#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) - closeAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Close")); - QObject::connect(closeAction, SIGNAL(triggered(bool)), q, SLOT(reject())); -#endif // Initial state: fitPageAction->setChecked(true); |