summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowsmime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsmime.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowsmime.cpp152
1 files changed, 72 insertions, 80 deletions
diff --git a/src/plugins/platforms/windows/qwindowsmime.cpp b/src/plugins/platforms/windows/qwindowsmime.cpp
index 79f627d458..cb112446fc 100644
--- a/src/plugins/platforms/windows/qwindowsmime.cpp
+++ b/src/plugins/platforms/windows/qwindowsmime.cpp
@@ -156,7 +156,7 @@ static bool qt_write_dibv5(QDataStream &s, QImage image)
bi.bV5Planes = 1;
bi.bV5BitCount = 32;
bi.bV5Compression = BI_BITFIELDS;
- bi.bV5SizeImage = bpl_bmp*image.height();
+ bi.bV5SizeImage = DWORD(bpl_bmp * image.height());
bi.bV5XPelsPerMeter = 0;
bi.bV5YPelsPerMeter = 0;
bi.bV5ClrUsed = 0;
@@ -176,30 +176,29 @@ static bool qt_write_dibv5(QDataStream &s, QImage image)
image = image.convertToFormat(QImage::Format_ARGB32);
uchar *buf = new uchar[bpl_bmp];
- uchar *b;
- memset(buf, 0, bpl_bmp);
+ memset(buf, 0, size_t(bpl_bmp));
for (int y=image.height()-1; y>=0; y--) {
// write the image bits
const QRgb *p = reinterpret_cast<const QRgb *>(image.constScanLine(y));
const QRgb *end = p + image.width();
- b = buf;
+ uchar *b = buf;
while (p < end) {
int alpha = qAlpha(*p);
if (alpha) {
- *b++ = qBlue(*p);
- *b++ = qGreen(*p);
- *b++ = qRed(*p);
+ *b++ = uchar(qBlue(*p));
+ *b++ = uchar(qGreen(*p));
+ *b++ = uchar(qRed(*p));
} else {
//white for fully transparent pixels.
*b++ = 0xff;
*b++ = 0xff;
*b++ = 0xff;
}
- *b++ = alpha;
+ *b++ = uchar(alpha);
p++;
}
- d->write((char*)buf, bpl_bmp);
+ d->write(reinterpret_cast<const char *>(buf), bpl_bmp);
if (s.status() != QDataStream::Ok) {
delete[] buf;
return false;
@@ -227,25 +226,22 @@ static bool qt_read_dibv5(QDataStream &s, QImage &image)
if (d->atEnd())
return false;
- d->read((char *)&bi, sizeof(bi)); // read BITMAPV5HEADER header
+ d->read(reinterpret_cast<char *>(&bi), sizeof(bi)); // read BITMAPV5HEADER header
if (s.status() != QDataStream::Ok)
return false;
- int nbits = bi.bV5BitCount;
- int comp = bi.bV5Compression;
- if (nbits != 32 || bi.bV5Planes != 1 || comp != BMP_BITFIELDS)
+ const int nbits = bi.bV5BitCount;
+ if (nbits != 32 || bi.bV5Planes != 1 || bi.bV5Compression != BMP_BITFIELDS)
return false; //Unsupported DIBV5 format
- int w = bi.bV5Width, h = bi.bV5Height;
- int red_mask = bi.bV5RedMask;
- int green_mask = bi.bV5GreenMask;
- int blue_mask = bi.bV5BlueMask;
- int alpha_mask = bi.bV5AlphaMask;
- int red_shift = 0;
- int green_shift = 0;
- int blue_shift = 0;
- int alpha_shift = 0;
- QImage::Format format = QImage::Format_ARGB32;
+ const int w = bi.bV5Width;
+ int h = bi.bV5Height;
+ const int red_mask = int(bi.bV5RedMask);
+ const int green_mask = int(bi.bV5GreenMask);
+ const int blue_mask = int(bi.bV5BlueMask);
+ const int alpha_mask = int(bi.bV5AlphaMask);
+
+ const QImage::Format format = QImage::Format_ARGB32;
if (bi.bV5Height < 0)
h = -h; // support images with negative height
@@ -257,30 +253,25 @@ static bool qt_read_dibv5(QDataStream &s, QImage &image)
image.setDotsPerMeterX(bi.bV5XPelsPerMeter);
image.setDotsPerMeterY(bi.bV5YPelsPerMeter);
- red_shift = calc_shift(red_mask);
- green_shift = calc_shift(green_mask);
- blue_shift = calc_shift(blue_mask);
- if (alpha_mask) {
- alpha_shift = calc_shift(alpha_mask);
- }
+ const int red_shift = calc_shift(red_mask);
+ const int green_shift = calc_shift(green_mask);
+ const int blue_shift = calc_shift(blue_mask);
+ const int alpha_shift = alpha_mask ? calc_shift(alpha_mask) : 0u;
- int bpl = image.bytesPerLine();
+ const int bpl = image.bytesPerLine();
uchar *data = image.bits();
- QRgb *p;
- QRgb *end;
+
uchar *buf24 = new uchar[bpl];
- int bpl24 = ((w*nbits+31)/32)*4;
- uchar *b;
- unsigned int c;
+ const int bpl24 = ((w * nbits + 31) / 32) * 4;
while (--h >= 0) {
- p = (QRgb *)(data + h*bpl);
- end = p + w;
- if (d->read((char *)buf24,bpl24) != bpl24)
+ QRgb *p = reinterpret_cast<QRgb *>(data + h * bpl);
+ QRgb *end = p + w;
+ if (d->read(reinterpret_cast<char *>(buf24), bpl24) != bpl24)
break;
- b = buf24;
+ const uchar *b = buf24;
while (p < end) {
- c = *b | (*(b+1))<<8 | (*(b+2))<<16 | (*(b+3))<<24;
+ const int c = *b | (*(b + 1)) << 8 | (*(b + 2)) << 16 | (*(b + 3)) << 24;
*p++ = qRgba(((c & red_mask) >> red_shift) ,
((c & green_mask) >> green_shift),
((c & blue_mask) >> blue_shift),
@@ -295,9 +286,9 @@ static bool qt_read_dibv5(QDataStream &s, QImage &image)
uchar *buf = new uchar[bpl];
h = -bi.bV5Height;
for (int y = 0; y < h/2; ++y) {
- memcpy(buf, data + y*bpl, bpl);
- memcpy(data + y*bpl, data + (h-y-1)*bpl, bpl);
- memcpy(data + (h-y-1)*bpl, buf, bpl);
+ memcpy(buf, data + y * bpl, size_t(bpl));
+ memcpy(data + y*bpl, data + (h - y -1) * bpl, size_t(bpl));
+ memcpy(data + (h - y -1 ) * bpl, buf, size_t(bpl));
}
delete [] buf;
}
@@ -315,7 +306,7 @@ static int getCf(const FORMATETC &formatetc)
static FORMATETC setCf(int cf)
{
FORMATETC formatetc;
- formatetc.cfFormat = cf;
+ formatetc.cfFormat = CLIPFORMAT(cf);
formatetc.dwAspect = DVASPECT_CONTENT;
formatetc.lindex = -1;
formatetc.ptd = NULL;
@@ -325,12 +316,12 @@ static FORMATETC setCf(int cf)
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
{
- HGLOBAL hData = GlobalAlloc(0, data.size());
+ HGLOBAL hData = GlobalAlloc(0, SIZE_T(data.size()));
if (!hData)
return false;
void *out = GlobalLock(hData);
- memcpy(out, data.data(), data.size());
+ memcpy(out, data.data(), size_t(data.size()));
GlobalUnlock(hData);
pmedium->tymed = TYMED_HGLOBAL;
pmedium->hGlobal = hData;
@@ -345,8 +336,8 @@ static QByteArray getData(int cf, IDataObject *pDataObj, int lindex = -1)
formatetc.lindex = lindex;
STGMEDIUM s;
if (pDataObj->GetData(&formatetc, &s) == S_OK) {
- DWORD * val = (DWORD*)GlobalLock(s.hGlobal);
- data = QByteArray::fromRawData((char*)val, GlobalSize(s.hGlobal));
+ const void *val = GlobalLock(s.hGlobal);
+ data = QByteArray::fromRawData(reinterpret_cast<const char *>(val), int(GlobalSize(s.hGlobal)));
data.detach();
GlobalUnlock(s.hGlobal);
ReleaseStgMedium(&s);
@@ -362,7 +353,7 @@ static QByteArray getData(int cf, IDataObject *pDataObj, int lindex = -1)
while(SUCCEEDED(hr)){
hr = s.pstm->Read(szBuffer, sizeof(szBuffer), &actualRead);
if (SUCCEEDED(hr) && actualRead > 0) {
- data += QByteArray::fromRawData(szBuffer, actualRead);
+ data += QByteArray::fromRawData(szBuffer, int(actualRead));
}
if (actualRead != sizeof(szBuffer))
break;
@@ -514,11 +505,11 @@ QWindowsMime::~QWindowsMime()
*/
int QWindowsMime::registerMimeType(const QString &mime)
{
- int f = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (mime.utf16()));
+ const UINT f = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (mime.utf16()));
if (!f)
qErrnoWarning("QWindowsMime::registerMimeType: Failed to register clipboard format");
- return f;
+ return int(f);
}
/*!
@@ -661,9 +652,9 @@ bool QWindowsMimeText::convertFromMime(const FORMATETC &formatetc, const QMimeDa
++u;
}
res.truncate(ri);
- const int byteLength = res.length() * sizeof(ushort);
+ const int byteLength = res.length() * int(sizeof(ushort));
QByteArray r(byteLength + 2, '\0');
- memcpy(r.data(), res.unicode(), byteLength);
+ memcpy(r.data(), res.unicode(), size_t(byteLength));
r[byteLength] = 0;
r[byteLength+1] = 0;
return setData(r, pmedium);
@@ -706,17 +697,17 @@ QVariant QWindowsMimeText::convertToMime(const QString &mime, LPDATAOBJECT pData
QString str;
QByteArray data = getData(CF_UNICODETEXT, pDataObj);
if (!data.isEmpty()) {
- str = QString::fromWCharArray((const wchar_t *)data.data());
+ str = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData()));
str.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
} else {
data = getData(CF_TEXT, pDataObj);
if (!data.isEmpty()) {
const char* d = data.data();
- const int s = qstrlen(d);
+ const unsigned s = qstrlen(d);
QByteArray r(data.size()+1, '\0');
char* o = r.data();
int j=0;
- for (int i=0; i<s; i++) {
+ for (unsigned i = 0; i < s; ++i) {
char c = d[i];
if (c!='\r')
o[j++]=c;
@@ -777,22 +768,22 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat
for (int i=0; i<urls.size(); i++) {
QString fn = QDir::toNativeSeparators(urls.at(i).toLocalFile());
if (!fn.isEmpty()) {
- size += sizeof(ushort) * (fn.length() + 1);
+ size += sizeof(ushort) * size_t(fn.length() + 1);
fileNames.append(fn);
}
}
QByteArray result(size, '\0');
- DROPFILES* d = (DROPFILES*)result.data();
+ DROPFILES* d = reinterpret_cast<DROPFILES *>(result.data());
d->pFiles = sizeof(DROPFILES);
GetCursorPos(&d->pt); // try
d->fNC = true;
- char* files = ((char*)d) + d->pFiles;
+ char *files = (reinterpret_cast<char*>(d)) + d->pFiles;
d->fWide = true;
- wchar_t* f = (wchar_t*)files;
+ wchar_t *f = reinterpret_cast<wchar_t *>(files);
for (int i=0; i<fileNames.size(); i++) {
- int l = fileNames.at(i).length();
+ const size_t l = size_t(fileNames.at(i).length());
memcpy(f, fileNames.at(i).utf16(), l * sizeof(ushort));
f += l;
*f++ = 0;
@@ -805,7 +796,8 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat
QByteArray result;
if (!urls.isEmpty()) {
QString url = urls.at(0).toString();
- result = QByteArray((const char *)url.utf16(), url.length() * sizeof(ushort));
+ result = QByteArray(reinterpret_cast<const char *>(url.utf16()),
+ url.length() * int(sizeof(ushort)));
}
result.append('\0');
result.append('\0');
@@ -860,9 +852,9 @@ QVariant QWindowsMimeURI::convertToMime(const QString &mimeType, LPDATAOBJECT pD
if (data.isEmpty())
return QVariant();
- LPDROPFILES hdrop = (LPDROPFILES)data.data();
+ const DROPFILES *hdrop = reinterpret_cast<const DROPFILES *>(data.constData());
if (hdrop->fWide) {
- const wchar_t* filesw = (const wchar_t *)(data.data() + hdrop->pFiles);
+ const wchar_t *filesw = reinterpret_cast<const wchar_t *>(data.constData() + hdrop->pFiles);
int i = 0;
while (filesw[i]) {
QString fileurl = QString::fromWCharArray(filesw + i);
@@ -870,7 +862,7 @@ QVariant QWindowsMimeURI::convertToMime(const QString &mimeType, LPDATAOBJECT pD
i += fileurl.length()+1;
}
} else {
- const char* files = (const char *)data.data() + hdrop->pFiles;
+ const char* files = reinterpret_cast<const char *>(data.constData() + hdrop->pFiles);
int i=0;
while (files[i]) {
urls += QUrl::fromLocalFile(QString::fromLocal8Bit(files+i));
@@ -886,7 +878,7 @@ QVariant QWindowsMimeURI::convertToMime(const QString &mimeType, LPDATAOBJECT pD
QByteArray data = getData(CF_INETURL_W, pDataObj);
if (data.isEmpty())
return QVariant();
- return QUrl(QString::fromWCharArray((const wchar_t *)data.constData()));
+ return QUrl(QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData())));
} else if (canGetData(CF_INETURL, pDataObj)) {
QByteArray data = getData(CF_INETURL, pDataObj);
if (data.isEmpty())
@@ -1014,14 +1006,14 @@ bool QWindowsMimeHtml::convertFromMime(const FORMATETC &formatetc, const QMimeDa
result += "<!--EndFragment-->";
// set the correct number for EndHTML
- QByteArray pos = QString::number(result.size()).toLatin1();
- memcpy((char *)(result.data() + 53 - pos.length()), pos.constData(), pos.length());
+ QByteArray pos = QByteArray::number(result.size());
+ memcpy(reinterpret_cast<char *>(result.data() + 53 - pos.length()), pos.constData(), size_t(pos.length()));
// set correct numbers for StartFragment and EndFragment
- pos = QString::number(result.indexOf("<!--StartFragment-->") + 20).toLatin1();
- memcpy((char *)(result.data() + 79 - pos.length()), pos.constData(), pos.length());
- pos = QString::number(result.indexOf("<!--EndFragment-->")).toLatin1();
- memcpy((char *)(result.data() + 103 - pos.length()), pos.constData(), pos.length());
+ pos = QByteArray::number(result.indexOf("<!--StartFragment-->") + 20);
+ memcpy(reinterpret_cast<char *>(result.data() + 79 - pos.length()), pos.constData(), size_t(pos.length()));
+ pos = QByteArray::number(result.indexOf("<!--EndFragment-->"));
+ memcpy(reinterpret_cast<char *>(result.data() + 103 - pos.length()), pos.constData(), size_t(pos.length()));
return setData(result, pmedium);
}
@@ -1249,9 +1241,9 @@ bool QBuiltInMimes::convertFromMime(const FORMATETC &formatetc, const QMimeData
++u;
}
res.truncate(ri);
- const int byteLength = res.length() * sizeof(ushort);
+ const int byteLength = res.length() * int(sizeof(ushort));
QByteArray r(byteLength + 2, '\0');
- memcpy(r.data(), res.unicode(), byteLength);
+ memcpy(r.data(), res.unicode(), size_t(byteLength));
r[byteLength] = 0;
r[byteLength+1] = 0;
data = r;
@@ -1288,7 +1280,7 @@ QVariant QBuiltInMimes::convertToMime(const QString &mimeType, IDataObject *pDat
qCDebug(lcQpaMime) << __FUNCTION__;
if (mimeType == QLatin1String("text/html") && preferredType == QVariant::String) {
// text/html is in wide chars on windows (compatible with Mozilla)
- val = QString::fromWCharArray((const wchar_t *)data.data());
+ val = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData()));
} else {
val = data; // it should be enough to return the data and let QMimeData do the rest.
}
@@ -1428,8 +1420,8 @@ bool QLastResortMimes::canConvertToMime(const QString &mimeType, IDataObject *pD
if (isCustomMimeType(mimeType)) {
// MSDN documentation for QueryGetData says only -1 is supported, so ignore lindex here.
QString clipFormat = customMimeType(mimeType);
- int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
- return canGetData(cf, pDataObj);
+ const UINT cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
+ return canGetData(int(cf), pDataObj);
} else if (formats.keys(mimeType).isEmpty()) {
// if it is not in there then register it and see if we can get it
int cf = QWindowsMime::registerMimeType(mimeType);
@@ -1449,8 +1441,8 @@ QVariant QLastResortMimes::convertToMime(const QString &mimeType, IDataObject *p
if (isCustomMimeType(mimeType)) {
int lindex;
QString clipFormat = customMimeType(mimeType, &lindex);
- int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
- data = getData(cf, pDataObj, lindex);
+ const UINT cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
+ data = getData(int(cf), pDataObj, lindex);
} else if (formats.keys(mimeType).isEmpty()) {
int cf = QWindowsMime::registerMimeType(mimeType);
data = getData(cf, pDataObj);
@@ -1599,7 +1591,7 @@ void QWindowsMimeConverter::ensureInitialized() const
QString QWindowsMimeConverter::clipboardFormatName(int cf)
{
wchar_t buf[256] = {0};
- return GetClipboardFormatName(cf, buf, 255)
+ return GetClipboardFormatName(UINT(cf), buf, 255)
? QString::fromWCharArray(buf) : QString();
}