Changeset 561 for trunk/src/gui/kernel/qmime_win.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/kernel/qmime_win.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 171 171 char szBuffer[4096]; 172 172 ULONG actualRead = 0; 173 LARGE_INTEGER pos = { 0, 0};173 LARGE_INTEGER pos = {{0, 0}}; 174 174 //Move to front (can fail depending on the data model implemented) 175 175 HRESULT hr = s.pstm->Seek(pos, STREAM_SEEK_SET, NULL); … … 220 220 \class QWindowsMime 221 221 \brief The QWindowsMime class maps open-standard MIME to Window Clipboard formats. 222 \ingroup io223 222 \ingroup draganddrop 224 \ingroup misc225 223 226 224 Qt's drag-and-drop and clipboard facilities use the MIME standard. … … 282 280 int QWindowsMime::registerMimeType(const QString &mime) 283 281 { 284 #ifdef Q_OS_WINCE285 282 int f = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (mime.utf16())); 286 #else287 int f = RegisterClipboardFormatA(mime.toLocal8Bit());288 #endif289 283 if (!f) 290 284 qErrnoWarning("QWindowsMime::registerMimeType: Failed to register clipboard format"); … … 402 396 #if defined(QMIME_DEBUG) && !defined(Q_OS_WINCE) 403 397 qDebug("QWindowsMime::allMimesForFormats()"); 404 charbuf[256] = {0};405 GetClipboardFormatName A(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)); 407 401 #endif 408 402 for (int i=mimes.size()-1; i>=0; --i) { … … 505 499 } 506 500 res.truncate(ri); 507 const int byteLength = res.length() *2;501 const int byteLength = res.length() * sizeof(ushort); 508 502 QByteArray r(byteLength + 2, '\0'); 509 503 memcpy(r.data(), res.unicode(), byteLength); … … 550 544 QByteArray data = getData(CF_UNICODETEXT, pDataObj); 551 545 if (!data.isEmpty()) { 552 str = QString::from Utf16((const unsigned short *)data.data());546 str = QString::fromWCharArray((const wchar_t *)data.data()); 553 547 str.replace(QLatin1String("\r\n"), QLatin1String("\n")); 554 548 } else { … … 621 615 QString fn = QDir::toNativeSeparators(urls.at(i).toLocalFile()); 622 616 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); 628 618 fileNames.append(fn); 629 619 } … … 637 627 char* files = ((char*)d) + d->pFiles; 638 628 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 663 639 return setData(result, pmedium); 664 640 } else if (getCf(formatetc) == CF_INETURL_W) { … … 666 642 QByteArray result; 667 643 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)); 669 645 result.append('\0'); 670 646 result.append('\0'); … … 721 697 LPDROPFILES hdrop = (LPDROPFILES)data.data(); 722 698 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; 725 701 while (filesw[i]) { 726 QString fileurl = QString::from Utf16(filesw+i);702 QString fileurl = QString::fromWCharArray(filesw + i); 727 703 urls += QUrl::fromLocalFile(fileurl); 728 704 i += fileurl.length()+1; 729 705 } 730 706 } else { 731 const char* files = (const char *)data.data() + hdrop->pFiles;707 const char* files = (const char *)data.data() + hdrop->pFiles; 732 708 int i=0; 733 709 while (files[i]) { … … 745 721 if (data.isEmpty()) 746 722 return QVariant(); 747 return QUrl(QString::from Utf16((const unsigned short *)data.constData()));723 return QUrl(QString::fromWCharArray((const wchar_t *)data.constData())); 748 724 } else if (canGetData(CF_INETURL, pDataObj)) { 749 725 QByteArray data = getData(CF_INETURL, pDataObj); … … 853 829 html = "<!--StartFragment-->" + html.mid(start, end - start); 854 830 html += "<!--EndFragment-->"; 855 html.replace( "\r", "");831 html.replace('\r', ""); 856 832 result = QString::fromUtf8(html); 857 833 } … … 914 890 QWindowsMimeImage::QWindowsMimeImage() 915 891 { 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"); 921 893 } 922 894 … … 1115 1087 } 1116 1088 res.truncate(ri); 1117 const int byteLength = res.length() *2;1089 const int byteLength = res.length() * sizeof(ushort); 1118 1090 QByteArray r(byteLength + 2, '\0'); 1119 1091 memcpy(r.data(), res.unicode(), byteLength); … … 1155 1127 #endif 1156 1128 if (mimeType == QLatin1String("text/html") && preferredType == QVariant::String) { 1157 // text/html is in wide chars on windows (compatible with mozillia)1158 val = QString::from Utf16((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()); 1159 1131 } else { 1160 1132 val = data; // it should be enough to return the data and let QMimeData do the rest. … … 1263 1235 return formatetcs; 1264 1236 } 1265 static const char *x_qt_windows_mime= "application/x-qt-windows-mime;value=\"";1266 1267 bool isCustomMimeType(const QString &mimeType)1237 static const char x_qt_windows_mime[] = "application/x-qt-windows-mime;value=\""; 1238 1239 static bool isCustomMimeType(const QString &mimeType) 1268 1240 { 1269 1241 return mimeType.startsWith(QLatin1String(x_qt_windows_mime), Qt::CaseInsensitive); 1270 1242 } 1271 1243 1272 QString customMimeType(const QString &mimeType)1273 { 1274 int len = QString(QLatin1String(x_qt_windows_mime)).length();1244 static QString customMimeType(const QString &mimeType) 1245 { 1246 int len = sizeof(x_qt_windows_mime) - 1; 1275 1247 int n = mimeType.lastIndexOf(QLatin1Char('\"'))-len; 1276 1248 return mimeType.mid(len, n); … … 1281 1253 if (isCustomMimeType(mimeType)) { 1282 1254 QString clipFormat = customMimeType(mimeType); 1283 #ifdef Q_OS_WINCE1284 1255 int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16())); 1285 #else1286 int cf = RegisterClipboardFormatA(clipFormat.toLocal8Bit());1287 #endif1288 1256 return canGetData(cf, pDataObj); 1289 1257 } else if (formats.keys(mimeType).isEmpty()) { … … 1305 1273 if (isCustomMimeType(mimeType)) { 1306 1274 QString clipFormat = customMimeType(mimeType); 1307 #ifdef Q_OS_WINCE1308 1275 int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16())); 1309 #else1310 int cf = RegisterClipboardFormatA(clipFormat.toLocal8Bit());1311 #endif1312 1276 data = getData(cf, pDataObj); 1313 1277 } else if (formats.keys(mimeType).isEmpty()) { … … 1326 1290 { 1327 1291 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); 1344 1300 #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; 1358 1313 } 1359 if (!ianaType)1360 format = QLatin1String(x_qt_windows_mime) + clipFormat + QLatin1Char('\"');1361 else1362 format = clipFormat;1363 1314 } 1315 if (!ianaType) 1316 format = QLatin1String(x_qt_windows_mime) + clipFormat + QLatin1Char('\"'); 1317 else 1318 format = clipFormat; 1364 1319 } 1320 } 1365 1321 #endif //QT_NO_DRAGANDDROP 1366 1367 } 1322 } 1323 1368 1324 return format; 1369 1325 }
Note:
See TracChangeset
for help on using the changeset viewer.