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/kernel/qmime_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**
     
    171171            char szBuffer[4096];
    172172            ULONG actualRead = 0;
    173             LARGE_INTEGER pos = {0, 0};
     173            LARGE_INTEGER pos = {{0, 0}};
    174174            //Move to front (can fail depending on the data model implemented)
    175175            HRESULT hr = s.pstm->Seek(pos, STREAM_SEEK_SET, NULL);
     
    220220    \class QWindowsMime
    221221    \brief The QWindowsMime class maps open-standard MIME to Window Clipboard formats.
    222     \ingroup io
    223222    \ingroup draganddrop
    224     \ingroup misc
    225223
    226224    Qt's drag-and-drop and clipboard facilities use the MIME standard.
     
    282280int QWindowsMime::registerMimeType(const QString &mime)
    283281{
    284 #ifdef Q_OS_WINCE
    285282    int f = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (mime.utf16()));
    286 #else
    287     int f = RegisterClipboardFormatA(mime.toLocal8Bit());
    288 #endif
    289283    if (!f)
    290284        qErrnoWarning("QWindowsMime::registerMimeType: Failed to register clipboard format");
     
    402396#if defined(QMIME_DEBUG) && !defined(Q_OS_WINCE)
    403397            qDebug("QWindowsMime::allMimesForFormats()");
    404             char buf[256] = {0};
    405             GetClipboardFormatNameA(fmtetc.cfFormat, buf, 255);
    406             qDebug("CF = %d : %s", fmtetc.cfFormat, buf);
     398            wchar_t buf[256] = {0};
     399            GetClipboardFormatName(fmtetc.cfFormat, buf, 255);
     400            qDebug("CF = %d : %s", fmtetc.cfFormat, QString::fromWCharArray(buf));
    407401#endif
    408402            for (int i=mimes.size()-1; i>=0; --i) {
     
    505499            }
    506500            res.truncate(ri);
    507             const int byteLength = res.length()*2;
     501            const int byteLength = res.length() * sizeof(ushort);
    508502            QByteArray r(byteLength + 2, '\0');
    509503            memcpy(r.data(), res.unicode(), byteLength);
     
    550544        QByteArray data = getData(CF_UNICODETEXT, pDataObj);
    551545        if (!data.isEmpty()) {
    552             str = QString::fromUtf16((const unsigned short *)data.data());
     546            str = QString::fromWCharArray((const wchar_t *)data.data());
    553547            str.replace(QLatin1String("\r\n"), QLatin1String("\n"));
    554548        } else {
     
    621615                QString fn = QDir::toNativeSeparators(urls.at(i).toLocalFile());
    622616                if (!fn.isEmpty()) {
    623                     QT_WA({
    624                         size += sizeof(TCHAR)*(fn.length()+1);
    625                     } , {
    626                         size += fn.toLocal8Bit().length()+1;
    627                     });
     617                    size += sizeof(ushort) * (fn.length() + 1);
    628618                    fileNames.append(fn);
    629619                }
     
    637627            char* files = ((char*)d) + d->pFiles;
    638628
    639             QT_WA({
    640                 d->fWide = true;
    641                 TCHAR* f = (TCHAR*)files;
    642                 for (int i=0; i<fileNames.size(); i++) {
    643                     int l = fileNames.at(i).length();
    644                     memcpy(f, fileNames.at(i).utf16(), l*sizeof(TCHAR));
    645                     f += l;
    646                     *f++ = 0;
    647                 }
    648                 *f = 0;
    649             } , {
    650                 d->fWide = false;
    651                 char* f = files;
    652                 for (int i=0; i<fileNames.size(); i++) {
    653                     QByteArray c = fileNames.at(i).toLocal8Bit();
    654                     if (!c.isEmpty()) {
    655                         int l = c.length();
    656                         memcpy(f, c.constData(), l);
    657                         f += l;
    658                         *f++ = 0;
    659                     }
    660                 }
    661                 *f = 0;
    662             });
     629            d->fWide = true;
     630            wchar_t* f = (wchar_t*)files;
     631            for (int i=0; i<fileNames.size(); i++) {
     632                int l = fileNames.at(i).length();
     633                memcpy(f, fileNames.at(i).utf16(), l * sizeof(ushort));
     634                f += l;
     635                *f++ = 0;
     636            }
     637            *f = 0;
     638
    663639            return setData(result, pmedium);
    664640        } else if (getCf(formatetc) == CF_INETURL_W) {
     
    666642            QByteArray result;
    667643            QString url = urls.at(0).toString();
    668             result = QByteArray((const char *)url.utf16(), url.length() * 2);
     644            result = QByteArray((const char *)url.utf16(), url.length() * sizeof(ushort));
    669645            result.append('\0');
    670646            result.append('\0');
     
    721697            LPDROPFILES hdrop = (LPDROPFILES)data.data();
    722698            if (hdrop->fWide) {
    723                 const ushort* filesw = (const ushort*)(data.data() + hdrop->pFiles);
    724                 int i=0;
     699                const wchar_t* filesw = (const wchar_t *)(data.data() + hdrop->pFiles);
     700                int i = 0;
    725701                while (filesw[i]) {
    726                     QString fileurl = QString::fromUtf16(filesw+i);
     702                    QString fileurl = QString::fromWCharArray(filesw + i);
    727703                    urls += QUrl::fromLocalFile(fileurl);
    728704                    i += fileurl.length()+1;
    729705                }
    730706            } else {
    731                 const char* files = (const char*)data.data() + hdrop->pFiles;
     707                const char* files = (const char *)data.data() + hdrop->pFiles;
    732708                int i=0;
    733709                while (files[i]) {
     
    745721            if (data.isEmpty())
    746722                return QVariant();
    747             return QUrl(QString::fromUtf16((const unsigned short *)data.constData()));
     723            return QUrl(QString::fromWCharArray((const wchar_t *)data.constData()));
    748724         } else if (canGetData(CF_INETURL, pDataObj)) {
    749725            QByteArray data = getData(CF_INETURL, pDataObj);
     
    853829            html = "<!--StartFragment-->" + html.mid(start, end - start);
    854830            html += "<!--EndFragment-->";
    855             html.replace("\r", "");
     831            html.replace('\r', "");
    856832            result = QString::fromUtf8(html);
    857833        }
     
    914890QWindowsMimeImage::QWindowsMimeImage()
    915891{
    916 #ifdef Q_OS_WINCE
    917     CF_PNG = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (QString::fromLatin1("PNG").utf16()));
    918 #else
    919     CF_PNG = RegisterClipboardFormatA("PNG");
    920 #endif
     892    CF_PNG = RegisterClipboardFormat(L"PNG");
    921893}
    922894
     
    11151087            }
    11161088            res.truncate(ri);
    1117             const int byteLength = res.length()*2;
     1089            const int byteLength = res.length() * sizeof(ushort);
    11181090            QByteArray r(byteLength + 2, '\0');
    11191091            memcpy(r.data(), res.unicode(), byteLength);
     
    11551127#endif
    11561128            if (mimeType == QLatin1String("text/html") && preferredType == QVariant::String) {
    1157                 // text/html is in wide chars on windows (compatible with mozillia)
    1158                 val = QString::fromUtf16((const unsigned short *)data.data());
     1129                // text/html is in wide chars on windows (compatible with Mozilla)
     1130                val = QString::fromWCharArray((const wchar_t *)data.data());
    11591131            } else {
    11601132                val = data; // it should be enough to return the data and let QMimeData do the rest.
     
    12631235    return formatetcs;
    12641236}
    1265 static const char *x_qt_windows_mime = "application/x-qt-windows-mime;value=\"";
    1266 
    1267 bool isCustomMimeType(const QString &mimeType)
     1237static const char x_qt_windows_mime[] = "application/x-qt-windows-mime;value=\"";
     1238
     1239static bool isCustomMimeType(const QString &mimeType)
    12681240{
    12691241    return mimeType.startsWith(QLatin1String(x_qt_windows_mime), Qt::CaseInsensitive);
    12701242}
    12711243
    1272 QString customMimeType(const QString &mimeType)
    1273 {
    1274     int len = QString(QLatin1String(x_qt_windows_mime)).length();
     1244static QString customMimeType(const QString &mimeType)
     1245{
     1246    int len = sizeof(x_qt_windows_mime) - 1;
    12751247    int n = mimeType.lastIndexOf(QLatin1Char('\"'))-len;
    12761248    return mimeType.mid(len, n);
     
    12811253    if (isCustomMimeType(mimeType)) {
    12821254        QString clipFormat = customMimeType(mimeType);
    1283 #ifdef Q_OS_WINCE
    12841255        int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
    1285 #else
    1286         int cf = RegisterClipboardFormatA(clipFormat.toLocal8Bit());
    1287 #endif
    12881256        return canGetData(cf, pDataObj);
    12891257    } else if (formats.keys(mimeType).isEmpty()) {
     
    13051273        if (isCustomMimeType(mimeType)) {
    13061274            QString clipFormat = customMimeType(mimeType);
    1307 #ifdef Q_OS_WINCE
    13081275            int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
    1309 #else
    1310             int cf = RegisterClipboardFormatA(clipFormat.toLocal8Bit());
    1311 #endif
    13121276            data = getData(cf, pDataObj);
    13131277        } else if (formats.keys(mimeType).isEmpty()) {
     
    13261290{
    13271291    QString format = formats.value(getCf(formatetc));
    1328     if (format.isEmpty()) {
    1329         QByteArray ba;
    1330         QString clipFormat;
    1331         int len;
    1332         QT_WA({
    1333             ba.resize(256*2);
    1334             len = GetClipboardFormatNameW(getCf(formatetc), (TCHAR*)ba.data(), 255);
    1335             if (len)
    1336                 clipFormat = QString::fromUtf16((ushort *)ba.data(), len);
    1337         } , {
    1338             ba.resize(256);
    1339             len = GetClipboardFormatNameA(getCf(formatetc), ba.data(), 255);
    1340             if (len)
    1341                 clipFormat = QString::fromLocal8Bit(ba.data(), len);
    1342        });
    1343         if (len) {
     1292    if (!format.isEmpty())
     1293        return format;
     1294
     1295    wchar_t buffer[256];
     1296    int len = GetClipboardFormatName(getCf(formatetc), buffer, 256);
     1297
     1298    if (len) {
     1299        QString clipFormat = QString::fromWCharArray(buffer, len);
    13441300#ifndef QT_NO_DRAGANDDROP
    1345             if (QInternalMimeData::canReadData(clipFormat))
    1346                 format = clipFormat;
    1347             else if((formatetc.cfFormat >= 0xC000)){
    1348                 //create the mime as custom. not registered.
    1349                 if (!excludeList.contains(clipFormat, Qt::CaseInsensitive)) {
    1350                     //check if this is a mime type
    1351                     bool ianaType = false;
    1352                     int sz = ianaTypes.size();
    1353                     for (int i = 0; i < sz; i++) {
    1354                         if (clipFormat.startsWith(ianaTypes[i], Qt::CaseInsensitive)) {
    1355                             ianaType =  true;
    1356                             break;
    1357                         }
     1301        if (QInternalMimeData::canReadData(clipFormat))
     1302            format = clipFormat;
     1303        else if((formatetc.cfFormat >= 0xC000)){
     1304            //create the mime as custom. not registered.
     1305            if (!excludeList.contains(clipFormat, Qt::CaseInsensitive)) {
     1306                //check if this is a mime type
     1307                bool ianaType = false;
     1308                int sz = ianaTypes.size();
     1309                for (int i = 0; i < sz; i++) {
     1310                    if (clipFormat.startsWith(ianaTypes[i], Qt::CaseInsensitive)) {
     1311                        ianaType =  true;
     1312                        break;
    13581313                    }
    1359                     if (!ianaType)
    1360                         format = QLatin1String(x_qt_windows_mime) + clipFormat + QLatin1Char('\"');
    1361                     else
    1362                         format = clipFormat;
    13631314                }
     1315                if (!ianaType)
     1316                    format = QLatin1String(x_qt_windows_mime) + clipFormat + QLatin1Char('\"');
     1317                else
     1318                    format = clipFormat;
    13641319            }
     1320        }
    13651321#endif //QT_NO_DRAGANDDROP
    1366         }
    1367     }
     1322    }
     1323
    13681324    return format;
    13691325}
Note: See TracChangeset for help on using the changeset viewer.