PageRenderTime 55ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/qtopiacore/qt/src/gui/dialogs/qpagesetupdialog_mac.cpp

https://github.com/FilipBE/qtextended
C++ | 158 lines | 101 code | 15 blank | 42 comment | 24 complexity | bc78f1bf9c27acd8e7202f2f425eacce MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the QtGui module of the Qt Toolkit.
  7. **
  8. ** Commercial Usage
  9. ** Licensees holding valid Qt Commercial licenses may use this file in
  10. ** accordance with the Qt Commercial License Agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Nokia.
  13. **
  14. **
  15. ** GNU General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU
  17. ** General Public License versions 2.0 or 3.0 as published by the Free
  18. ** Software Foundation and appearing in the file LICENSE.GPL included in
  19. ** the packaging of this file. Please review the following information
  20. ** to ensure GNU General Public Licensing requirements will be met:
  21. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
  22. ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
  23. ** exception, Nokia gives you certain additional rights. These rights
  24. ** are described in the Nokia Qt GPL Exception version 1.3, included in
  25. ** the file GPL_EXCEPTION.txt in this package.
  26. **
  27. ** Qt for Windows(R) Licensees
  28. ** As a special exception, Nokia, as the sole copyright holder for Qt
  29. ** Designer, grants users of the Qt/Eclipse Integration plug-in the
  30. ** right for the Qt/Eclipse Integration to link to functionality
  31. ** provided by Qt Designer and its related libraries.
  32. **
  33. ** If you are unsure which license is appropriate for your use, please
  34. ** contact the sales department at qt-sales@nokia.com.
  35. **
  36. ****************************************************************************/
  37. #include "qpagesetupdialog.h"
  38. #include <qhash.h>
  39. #include <private/qapplication_p.h>
  40. #include <private/qprintengine_mac_p.h>
  41. #include <private/qabstractpagesetupdialog_p.h>
  42. #ifndef QT_NO_PRINTDIALOG
  43. QT_BEGIN_NAMESPACE
  44. class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
  45. {
  46. Q_DECLARE_PUBLIC(QPageSetupDialog)
  47. public:
  48. QPageSetupDialogPrivate() : ep(0), upp(0), sheetBlocks(false), acceptStatus(false) {}
  49. ~QPageSetupDialogPrivate() {
  50. if (upp) {
  51. DisposePMSheetDoneUPP(upp);
  52. upp = 0;
  53. }
  54. QHash<PMPrintSession, QPageSetupDialogPrivate *>::iterator it = sheetCallbackMap.begin();
  55. while (it != sheetCallbackMap.end()) {
  56. if (it.value() == this) {
  57. it = sheetCallbackMap.erase(it);
  58. } else {
  59. ++it;
  60. }
  61. }
  62. }
  63. static void pageSetupDialogSheetDoneCallback(PMPrintSession printSession, WindowRef /*documentWindow*/, Boolean accepted) {
  64. QPageSetupDialogPrivate *priv = sheetCallbackMap.value(printSession);
  65. if (!priv) {
  66. qWarning("%s:%d: QPageSetupDialog::exec: Could not retrieve data structure, "
  67. "you most likely now have an infinite modal loop", __FILE__, __LINE__);
  68. return;
  69. }
  70. priv->sheetBlocks = false;
  71. priv->acceptStatus = accepted;
  72. }
  73. QMacPrintEnginePrivate *ep;
  74. PMSheetDoneUPP upp;
  75. bool sheetBlocks;
  76. Boolean acceptStatus;
  77. static QHash<PMPrintSession, QPageSetupDialogPrivate*> sheetCallbackMap;
  78. };
  79. QHash<PMPrintSession, QPageSetupDialogPrivate*> QPageSetupDialogPrivate::sheetCallbackMap;
  80. QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
  81. : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
  82. {
  83. Q_D(QPageSetupDialog);
  84. QMacPrintEngine *engine = static_cast<QMacPrintEngine *>(d->printer->paintEngine());
  85. d->ep = static_cast<QMacPrintEnginePrivate *>(engine->d_ptr);
  86. }
  87. int QPageSetupDialog::exec()
  88. {
  89. Q_D(QPageSetupDialog);
  90. if (d->printer->outputFormat() != QPrinter::NativeFormat)
  91. return Rejected;
  92. QMacPrintEngine *engine = static_cast<QMacPrintEngine *>(d->printer->paintEngine());
  93. QMacPrintEnginePrivate *ep = static_cast<QMacPrintEnginePrivate *>(engine->d_ptr);
  94. // If someone is reusing a QPrinter object, the end released all our old
  95. // information. In this case, we must reinitialize.
  96. if (ep->session == 0)
  97. ep->initialize();
  98. { //simulate modality
  99. // First, see if we should use a sheet.
  100. QWidget *parent = parentWidget();
  101. if (parent && parent->isVisible()) {
  102. WindowRef windowRef = qt_mac_window_for(parent);
  103. WindowClass wclass;
  104. GetWindowClass(windowRef, &wclass);
  105. if (!isOptionEnabled(QPageSetupDialog::DontUseSheet)
  106. && (wclass == kDocumentWindowClass || wclass == kFloatingWindowClass
  107. || wclass == kMovableModalWindowClass)) {
  108. // Yes, we can use a sheet
  109. if (!d->upp)
  110. d->upp = NewPMSheetDoneUPP(QPageSetupDialogPrivate::pageSetupDialogSheetDoneCallback);
  111. d->sheetCallbackMap.insert(d->ep->session, d);
  112. PMSessionUseSheets(d->ep->session, qt_mac_window_for(parentWidget()), d->upp);
  113. d->sheetBlocks = true;
  114. }
  115. }
  116. QWidget modal_widg(0, Qt::Window);
  117. modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg"));
  118. modal_widg.createWinId();
  119. QApplicationPrivate::enterModal(&modal_widg);
  120. QApplicationPrivate::native_modal_dialog_active = true;
  121. PMSessionPageSetupDialog(ep->session, ep->format, &d->acceptStatus);
  122. while (d->sheetBlocks) {
  123. qApp->processEvents(QEventLoop::WaitForMoreEvents);
  124. }
  125. QApplicationPrivate::leaveModal(&modal_widg);
  126. QApplicationPrivate::native_modal_dialog_active = false;
  127. // if the margins have changed, we have to use the margins from the new
  128. // PMFormat object
  129. if (d->acceptStatus == Accepted) {
  130. PMPaper paper;
  131. PMPaperMargins margins;
  132. PMGetPageFormatPaper(ep->format, &paper);
  133. PMPaperGetMargins(paper, &margins);
  134. ep->leftMargin = margins.left;
  135. ep->topMargin = margins.top;
  136. ep->rightMargin = margins.right;
  137. ep->bottomMargin = margins.bottom;
  138. }
  139. }
  140. return d->acceptStatus ? Accepted : Rejected;
  141. }
  142. QT_END_NAMESPACE
  143. #endif QT_NO_PRINTDIALOG