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/painting/qprinterinfo_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**
     
    4444#include <qstringlist.h>
    4545
    46 #include <windows.h>
     46#include <qt_windows.h>
    4747
    4848QT_BEGIN_NAMESPACE
     
    7070static QPrinterInfoPrivate nullQPrinterInfoPrivate;
    7171
     72class QPrinterInfoPrivateDeleter
     73{
     74public:
     75    static inline void cleanup(QPrinterInfoPrivate *d)
     76    {
     77        if (d != &nullQPrinterInfoPrivate)
     78            delete d;
     79    }
     80};
     81
    7282/////////////////////////////////////////////////////////////////////////////
    7383/////////////////////////////////////////////////////////////////////////////
     
    8090    DWORD returned = 0;
    8191
    82     QT_WA({
    83             if (!EnumPrintersW(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL,
    84                                4, 0, 0, &needed, &returned))
    85             {
    86                 buffer = new BYTE[needed];
    87                 if (!EnumPrintersW(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS , NULL,
    88                                    4, buffer, needed, &needed, &returned))
    89                 {
    90                     delete [] buffer;
    91                     return printers;
    92                 }
    93                 PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer);
    94                 QPrinterInfo defPrn = defaultPrinter();
    95                 for (uint i = 0; i < returned; ++i) {
    96                     printers.append(QPrinterInfo(QString::fromUtf16(reinterpret_cast<const ushort*>(infoList[i].pPrinterName))));
    97                     if (printers.at(i).printerName() == defPrn.printerName())
    98                         printers[i].d_ptr->m_default = true;
    99                 }
    100                 delete [] buffer;
    101             }
    102         }, {
    103             // In Windows 98 networked printers are served through the local connection
    104             if (!EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 5, 0, 0, &needed, &returned)) {
    105                 buffer = new BYTE[needed];
    106                 if (!EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 5, buffer, needed, &needed, &returned)) {
    107                     delete [] buffer;
    108                     return printers;
    109                 }
    110 
    111                 PPRINTER_INFO_5 infoList = reinterpret_cast<PPRINTER_INFO_5>(buffer);
    112                 QPrinterInfo defPrn = defaultPrinter();
    113                 for (uint i = 0; i < returned; ++i) {
    114                     printers.append(QPrinterInfo(QString::fromLocal8Bit(reinterpret_cast<const char*>(infoList[i].pPrinterName))));
    115                     if (printers.at(i).printerName() == defPrn.printerName())
    116                         printers[i].d_ptr->m_default = true;
    117                 }
    118                 delete [] buffer;
    119             }
    120         });
     92    if ( !EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned))
     93    {
     94        buffer = new BYTE[needed];
     95        if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS , NULL,
     96                           4, buffer, needed, &needed, &returned))
     97        {
     98            delete [] buffer;
     99            return printers;
     100        }
     101        PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer);
     102        QPrinterInfo defPrn = defaultPrinter();
     103        for (uint i = 0; i < returned; ++i) {
     104            printers.append(QPrinterInfo(QString::fromWCharArray(infoList[i].pPrinterName)));
     105            if (printers.at(i).printerName() == defPrn.printerName())
     106                printers[i].d_ptr->m_default = true;
     107        }
     108        delete [] buffer;
     109    }
    121110
    122111    return printers;
     
    126115{
    127116    QString noPrinters(QLatin1String("qt_no_printers"));
    128     QString output;
    129     QT_WA({
    130         ushort buffer[256];
    131         GetProfileStringW(L"windows", L"device",
    132                           reinterpret_cast<const wchar_t *>(noPrinters.utf16()),
    133                           reinterpret_cast<wchar_t *>(buffer), 256);
    134         output = QString::fromUtf16(buffer);
    135     }, {
    136         char buffer[256];
    137         GetProfileStringA("windows", "device", noPrinters.toLatin1(), buffer, 256);
    138         output = QString::fromLocal8Bit(buffer);
    139     });
     117    wchar_t buffer[256];
     118    GetProfileString(L"windows", L"device", (wchar_t*)noPrinters.utf16(), buffer, 256);
     119    QString output = QString::fromWCharArray(buffer);
    140120
    141121    // Filter out the name of the printer, which should be everything
     
    156136
    157137QPrinterInfo::QPrinterInfo()
    158 {
    159     d_ptr = &nullQPrinterInfoPrivate;
     138    : d_ptr(&nullQPrinterInfoPrivate)
     139{
    160140}
    161141
    162142QPrinterInfo::QPrinterInfo(const QString& name)
    163 {
    164     d_ptr = new QPrinterInfoPrivate(name);
     143    : d_ptr(new QPrinterInfoPrivate(name))
     144{
    165145    d_ptr->q_ptr = this;
    166146}
    167147
    168148QPrinterInfo::QPrinterInfo(const QPrinterInfo& src)
    169 {
    170     d_ptr = &nullQPrinterInfoPrivate;
     149    : d_ptr(&nullQPrinterInfoPrivate)
     150{
    171151    *this = src;
    172152}
    173153
    174154QPrinterInfo::QPrinterInfo(const QPrinter& prn)
    175 {
    176     d_ptr = &nullQPrinterInfoPrivate;
     155    : d_ptr(&nullQPrinterInfoPrivate)
     156{
    177157    QList<QPrinterInfo> list = availablePrinters();
    178158    for (int c = 0; c < list.size(); ++c) {
     
    188168QPrinterInfo::~QPrinterInfo()
    189169{
    190     if (d_ptr != &nullQPrinterInfoPrivate)
    191         delete d_ptr;
    192170}
    193171
     
    195173{
    196174    Q_ASSERT(d_ptr);
    197     if (d_ptr != &nullQPrinterInfoPrivate)
    198         delete d_ptr;
    199     d_ptr = new QPrinterInfoPrivate(*src.d_ptr);
     175    d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr));
    200176    d_ptr->q_ptr = this;
    201177    return *this;
     
    223199{
    224200    const Q_D(QPrinterInfo);
    225     DWORD size;
    226     WORD* papers;
    227201    QList<QPrinter::PaperSize> paperList;
    228202
    229     QT_WA({
    230         size = DeviceCapabilitiesW(reinterpret_cast<const WCHAR*>(d->m_name.utf16()),
    231                 NULL, DC_PAPERS, NULL, NULL);
    232         if ((int)size == -1)
    233             return paperList;
    234         papers = new WORD[size];
    235         size = DeviceCapabilitiesW(reinterpret_cast<const WCHAR*>(d->m_name.utf16()),
    236                 NULL, DC_PAPERS, reinterpret_cast<WCHAR*>(papers), NULL);
    237     }, {
    238         size = DeviceCapabilitiesA(d->m_name.toLatin1().data(), NULL, DC_PAPERS, NULL, NULL);
    239         if ((int)size == -1)
    240             return paperList;
    241         papers = new WORD[size];
    242         size = DeviceCapabilitiesA(d->m_name.toLatin1().data(), NULL, DC_PAPERS,
    243                 reinterpret_cast<char*>(papers), NULL);
    244     });
     203    DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->m_name.utf16()),
     204                                    NULL, DC_PAPERS, NULL, NULL);
     205    if ((int)size == -1)
     206        return paperList;
     207
     208    wchar_t *papers = new wchar_t[size];
     209    size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->m_name.utf16()),
     210                              NULL, DC_PAPERS, papers, NULL);
    245211
    246212    for (int c = 0; c < (int)size; ++c) {
Note: See TracChangeset for help on using the changeset viewer.