Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/dialogs/qprintdialog_win.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5252#include <private/qprintengine_win_p.h>
    5353#include <private/qprinter_p.h>
     54
     55#if defined(Q_CC_MINGW) && !defined(PD_NOCURRENTPAGE)
     56#define PD_NOCURRENTPAGE    0x00800000
     57#define PD_RESULT_PRINT 1
     58#define PD_RESULT_APPLY 2
     59#define START_PAGE_GENERAL  0XFFFFFFFF
     60#endif
    5461
    5562QT_BEGIN_NAMESPACE
     
    7885};
    7986
    80 #ifndef Q_OS_WINCE
    81 // If you change this function, make sure you also change the unicode equivalent
    82 template <class PrintDialog, class DeviceMode>
    83 static PrintDialog *qt_win_make_PRINTDLG(QWidget *parent,
    84                                          QPrintDialog *pdlg,
    85                                          QPrintDialogPrivate *d, HGLOBAL *tempDevNames)
    86 {
    87     PrintDialog *pd = new PrintDialog;
    88     memset(pd, 0, sizeof(PrintDialog));
    89     pd->lStructSize = sizeof(PrintDialog);
    90 
    91     void *devMode = sizeof(DeviceMode) == sizeof(DEVMODEA)
    92                     ? (void *) d->ep->devModeA()
    93                     : (void *) d->ep->devModeW();
     87static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent,
     88                                    QPrintDialog *pdlg,
     89                                    QPrintDialogPrivate *d, HGLOBAL *tempDevNames)
     90{
     91    DEVMODE *devMode = d->ep->devMode;
    9492
    9593    if (devMode) {
    96         int size = sizeof(DeviceMode) + ((DeviceMode *) devMode)->dmDriverExtra;
     94        int size = sizeof(DEVMODE) + devMode->dmDriverExtra;
    9795        pd->hDevMode = GlobalAlloc(GHND, size);
    9896        {
    9997            void *dest = GlobalLock(pd->hDevMode);
    100             memcpy(dest, d->ep->devMode, size);
     98            memcpy(dest, devMode, size);
    10199            GlobalUnlock(pd->hDevMode);
    102100        }
     
    131129        pd->Flags |= PD_NOPAGENUMS;
    132130
     131    // we don't have a 'current page' notion in the QPrinter API yet.
     132    // Neither do we support more than one page range, so limit those
     133    // options
     134    pd->Flags |= PD_NOCURRENTPAGE;
     135    pd->nStartPage = START_PAGE_GENERAL;
     136    pd->nPageRanges = 1;
     137    pd->nMaxPageRanges = 1;
     138
    133139    if (d->ep->printToFile)
    134140        pd->Flags |= PD_PRINTTOFILE;
    135     Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
    136     pd->hwndOwner = parent ? parent->winId() : 0;
    137     pd->nFromPage = qMax(pdlg->fromPage(), pdlg->minPage());
    138     pd->nToPage   = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1;
     141    Q_ASSERT(parent != 0 && parent->testAttribute(Qt::WA_WState_Created));
     142    pd->hwndOwner = parent->window()->winId();
     143    pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage());
     144    pd->lpPageRanges[0].nToPage   = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1;
    139145    pd->nCopies = d->ep->num_copies;
    140 
    141     return pd;
    142 }
    143 #endif // Q_OS_WINCE
    144 
    145 // If you change this function, make sure you also change the ansi equivalent
    146 template <typename T>
    147 static void qt_win_clean_up_PRINTDLG(T **pd)
    148 {
    149     delete *pd;
    150     *pd = 0;
    151 }
    152 
    153 
    154 // If you change this function, make sure you also change the ansi equivalent
    155 template <typename T>
    156 static void qt_win_read_back_PRINTDLG(T *pd, QPrintDialog *pdlg, QPrintDialogPrivate *d)
     146}
     147
     148static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPrintDialogPrivate *d)
    157149{
    158150    if (pd->Flags & PD_SELECTION) {
     
    161153    } else if (pd->Flags & PD_PAGENUMS) {
    162154        pdlg->setPrintRange(QPrintDialog::PageRange);
    163         pdlg->setFromTo(pd->nFromPage, pd->nToPage);
     155        pdlg->setFromTo(pd->lpPageRanges[0].nFromPage, pd->lpPageRanges[0].nToPage);
    164156    } else {
    165157        pdlg->setPrintRange(QPrintDialog::AllPages);
     
    226218        parent = parent->window();
    227219    else
    228         parent = qApp->activeWindow();
     220        parent = QApplication::activeWindow();
     221
     222    // If there is no window, fall back to the print dialog itself
     223    if (parent == 0)
     224        parent = q;
    229225
    230226    QWidget modal_widget;
     
    235231    HGLOBAL *tempDevNames = ep->createDevNames();
    236232
     233    bool done;
    237234    bool result;
    238     bool done;
    239     void *pd = QT_WA_INLINE(
    240         (void*)(qt_win_make_PRINTDLG<PRINTDLGW, DEVMODEW>(parent, q, this, tempDevNames)),
    241         (void*)(qt_win_make_PRINTDLG<PRINTDLGA, DEVMODEA>(parent, q, this, tempDevNames))
    242         );
     235    bool doPrinting;
     236
     237    PRINTPAGERANGE pageRange;
     238    PRINTDLGEX pd;
     239    memset(&pd, 0, sizeof(PRINTDLGEX));
     240    pd.lStructSize = sizeof(PRINTDLGEX);
     241    pd.lpPageRanges = &pageRange;
     242    qt_win_setup_PRINTDLGEX(&pd, parent, q, this, tempDevNames);
    243243
    244244    do {
    245245        done = true;
    246         QT_WA({
    247             PRINTDLGW *pdw = reinterpret_cast<PRINTDLGW *>(pd);
    248             result = PrintDlgW(pdw);
    249             if ((pdw->Flags & PD_PAGENUMS) && (pdw->nFromPage > pdw->nToPage))
     246        doPrinting = false;
     247        result = (PrintDlgEx(&pd) == S_OK);
     248        if (result && (pd.dwResultAction == PD_RESULT_PRINT
     249                       || pd.dwResultAction == PD_RESULT_APPLY))
     250        {
     251            doPrinting = (pd.dwResultAction == PD_RESULT_PRINT);
     252            if ((pd.Flags & PD_PAGENUMS)
     253                && (pd.lpPageRanges[0].nFromPage > pd.lpPageRanges[0].nToPage))
     254            {
     255                pd.lpPageRanges[0].nFromPage = 1;
     256                pd.lpPageRanges[0].nToPage = 1;
    250257                done = false;
    251             if (result && pdw->hDC == 0)
     258            }
     259            if (pd.hDC == 0)
    252260                result = false;
    253             else if (!result)
    254                 done = true;
    255         }, {
    256             PRINTDLGA *pda = reinterpret_cast<PRINTDLGA *>(pd);
    257             result = PrintDlgA(pda);
    258             if ((pda->Flags & PD_PAGENUMS) && (pda->nFromPage > pda->nToPage))
    259                 done = false;
    260             if (result && pda->hDC == 0)
    261                 result = false;
    262             else if (!result)
    263                 done = true;
    264         });
     261        }
     262
    265263        if (!done) {
    266264            QMessageBox::warning(0, QPrintDialog::tr("Print"),
     
    275273
    276274    // write values back...
    277     if (result) {
    278         QT_WA({
    279             PRINTDLGW *pdw = reinterpret_cast<PRINTDLGW *>(pd);
    280             qt_win_read_back_PRINTDLG(pdw, q, this);
    281             qt_win_clean_up_PRINTDLG(&pdw);
    282         }, {
    283             PRINTDLGA *pda = reinterpret_cast<PRINTDLGA *>(pd);
    284             qt_win_read_back_PRINTDLG(pda, q, this);
    285             qt_win_clean_up_PRINTDLG(&pda);
    286         });
     275    if (result && (pd.dwResultAction == PD_RESULT_PRINT
     276                   || pd.dwResultAction == PD_RESULT_APPLY))
     277    {
     278        qt_win_read_back_PRINTDLGEX(&pd, q, this);
    287279        // update printer validity
    288280        printer->d_func()->validPrinter = !ep->name.isEmpty();
     
    292284    GlobalFree(tempDevNames);
    293285
    294     q->done(result);
    295 
    296     return result;
     286    q->done(result && doPrinting);
     287
     288    return result && doPrinting;
    297289}
    298290
Note: See TracChangeset for help on using the changeset viewer.