Adler-32 Checksum Algorithm (from zlib)
Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
diff --git a/README.md b/README.md
index bd3dd48..848219d 100644
--- a/README.md
+++ b/README.md
@@ -70,6 +70,11 @@ This library is free software. It is released under the terms of the [*GNU Lesse
# Acknowledgement
+The following people have contributed in the development of the MUtilities library:
+
+* **John Buonagurio <>**
+ Support for Qt5
+
The following third-party code is used in the MUtilities library:
* **Keccak/SHA-3 Reference Implementation**
@@ -77,7 +82,7 @@ The following third-party code is used in the MUtilities library:
No Copyright / Dedicated to the Public Domain
* **Natural Order String Comparison**
- Copyright (C) 2000, 2004 by Martin Pool
+ Copyright (C) 2000, 2004 by Martin Pool <>
Released under the zlib License
* **Adler-32 Checksum Algorithm (from zlib)**
diff --git a/include/MUtils/OSSupport.h b/include/MUtils/OSSupport.h
index 1b95b0b..671b96f 100644
--- a/include/MUtils/OSSupport.h
+++ b/include/MUtils/OSSupport.h
@@ -28,6 +28,7 @@
#include
#include
#include
+#include
//Forward declaration
class QFile;
diff --git a/src/GUI.cpp b/src/GUI.cpp
index 6e0bbd1..c3cbafc 100644
--- a/src/GUI.cpp
+++ b/src/GUI.cpp
@@ -92,7 +92,7 @@ namespace MUtils
QObject(parent),
m_hIcon(hIcon)
{
- SendMessage(parent->winId(), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon));
+ SendMessage(reinterpret_cast(parent->winId()), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon));
}
virtual ~WindowIconHelper(void)
@@ -115,7 +115,7 @@ bool MUtils::GUI::set_window_icon(QWidget *const window, const QIcon &icon, cons
if((!icon.isNull()) && window->winId())
{
const int extend = (bIsBigIcon ? 32 : 16);
- if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, extend, extend))
+ if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(&icon, extend, extend))
{
new Internal::WindowIconHelper(window, hIcon, bIsBigIcon); /*will be free'd using QObject parent mechanism*/
return true;
diff --git a/src/GUI_Win32.cpp b/src/GUI_Win32.cpp
index 9670826..68bb5e2 100644
--- a/src/GUI_Win32.cpp
+++ b/src/GUI_Win32.cpp
@@ -88,7 +88,7 @@ bool MUtils::GUI::sysmenu_append(const QWidget *win, const unsigned int identifi
{
bool ok = false;
- if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE))
+ if(HMENU hMenu = GetSystemMenu(reinterpret_cast(win->winId()), FALSE))
{
ok = (AppendMenuW(hMenu, MF_SEPARATOR, 0, 0) == TRUE);
ok = (AppendMenuW(hMenu, MF_STRING, identifier, MUTILS_WCHR(text)) == TRUE);
@@ -101,7 +101,7 @@ bool MUtils::GUI::sysmenu_update(const QWidget *win, const unsigned int identifi
{
bool ok = false;
- if(HMENU hMenu = ::GetSystemMenu(win->winId(), FALSE))
+ if(HMENU hMenu = ::GetSystemMenu(reinterpret_cast(win->winId()), FALSE))
{
ok = (ModifyMenu(hMenu, identifier, MF_STRING | MF_BYCOMMAND, identifier, MUTILS_WCHR(text)) == TRUE);
}
@@ -121,7 +121,7 @@ bool MUtils::GUI::enable_close_button(const QWidget *win, const bool &bEnable)
{
bool ok = false;
- if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE))
+ if(HMENU hMenu = GetSystemMenu(reinterpret_cast(win->winId()), FALSE))
{
ok = (EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (bEnable ? MF_ENABLED : MF_GRAYED)) == TRUE);
}
@@ -156,8 +156,8 @@ bool MUtils::GUI::bring_to_front(const QWidget *window)
{
for(int i = 0; (i < 5) && (!ret); i++)
{
- ret = (SetForegroundWindow(window->winId()) != FALSE);
- SwitchToThisWindow(window->winId(), TRUE);
+ ret = (SetForegroundWindow(reinterpret_cast(window->winId())) != FALSE);
+ SwitchToThisWindow(reinterpret_cast(window->winId()), TRUE);
}
LockSetForegroundWindow(LSFW_LOCK);
}
@@ -204,7 +204,7 @@ bool MUtils::GUI::sheet_of_glass(QWidget *const window)
//Enable the "sheet of glass" effect on this window
MARGINS margins = {-1, -1, -1, -1};
- if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(window->winId(), &margins))
+ if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(reinterpret_cast(window->winId()), &margins))
{
qWarning("DwmExtendFrameIntoClientArea function has failed! (error %d)", hr);
return false;
@@ -215,7 +215,7 @@ bool MUtils::GUI::sheet_of_glass(QWidget *const window)
memset(&bb, 0, sizeof(DWM_BLURBEHIND));
bb.fEnable = TRUE;
bb.dwFlags = DWM_BB_ENABLE;
- if(HRESULT hr = dwmEnableBlurBehindWindowFun(window->winId(), &bb))
+ if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast(window->winId()), &bb))
{
qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
return false;
@@ -258,7 +258,7 @@ bool MUtils::GUI::sheet_of_glass_update(QWidget *const window)
memset(&bb, 0, sizeof(DWM_BLURBEHIND));
bb.fEnable = TRUE;
bb.dwFlags = DWM_BB_ENABLE;
- if(HRESULT hr = dwmEnableBlurBehindWindowFun(window->winId(), &bb))
+ if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast(window->winId()), &bb))
{
qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
return false;
diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp
index 088e5f1..1ad78cd 100644
--- a/src/OSSupport_Win32.cpp
+++ b/src/OSSupport_Win32.cpp
@@ -1236,7 +1236,7 @@ bool MUtils::OS::free_diskspace(const QString &path, quint64 &freeSpace)
bool MUtils::OS::shell_open(const QWidget *parent, const QString &url, const QString ¶meters, const QString &directory, const bool explore)
{
- return ((int) ShellExecuteW((parent ? parent->winId() : NULL), (explore ? L"explore" : L"open"), MUTILS_WCHR(url), ((!parameters.isEmpty()) ? MUTILS_WCHR(parameters) : NULL), ((!directory.isEmpty()) ? MUTILS_WCHR(directory) : NULL), SW_SHOW)) > 32;
+ return ((int) ShellExecuteW((parent ? reinterpret_cast(parent->winId()) : NULL), (explore ? L"explore" : L"open"), MUTILS_WCHR(url), ((!parameters.isEmpty()) ? MUTILS_WCHR(parameters) : NULL), ((!directory.isEmpty()) ? MUTILS_WCHR(directory) : NULL), SW_SHOW)) > 32;
}
bool MUtils::OS::shell_open(const QWidget *parent, const QString &url, const bool explore)
diff --git a/src/Startup.cpp b/src/Startup.cpp
index faecafc..e5765c9 100644
--- a/src/Startup.cpp
+++ b/src/Startup.cpp
@@ -37,6 +37,9 @@
#include
#include
#include
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
+#include
+#endif
//CRT
#include
@@ -96,25 +99,58 @@ namespace MUtils
// MESSAGE HANDLER
///////////////////////////////////////////////////////////////////////////////
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
static void qt_message_handler(QtMsgType type, const char *const msg)
{
- if((!msg) || (!(msg[0])))
+ if (msg && msg[0])
{
- return;
- }
-
- MUtils::Terminal::write(type, msg);
-
- if((type == QtCriticalMsg) || (type == QtFatalMsg))
- {
- MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg)));
+ MUtils::Terminal::write(type, msg);
+ if ((type == QtCriticalMsg) || (type == QtFatalMsg))
+ {
+ MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg)));
+ }
}
}
+#else
+#define qInstallMsgHandler(X) qInstallMessageHandler((X))
+static void qt_message_handler(QtMsgType type, const QMessageLogContext&, const QString &msg)
+{
+ if (!msg.isEmpty())
+ {
+ MUtils::Terminal::write(type, msg.toUtf8().constData());
+ if ((type == QtCriticalMsg) || (type == QtFatalMsg))
+ {
+ MUtils::OS::fatal_exit(MUTILS_WCHR(msg));
+ }
+ }
+}
+#endif
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
static bool qt_event_filter(void *message, long *result)
{
return MUtils::OS::handle_os_message(message, result);
}
+#else
+namespace MUtils
+{
+ namespace Startup
+ {
+ namespace Internal
+ {
+ class NativeEventFilter : public QAbstractNativeEventFilter
+ {
+ public:
+ bool nativeEventFilter(const QByteArray&, void *message, long *result) Q_DECL_OVERRIDE
+ {
+ return MUtils::OS::handle_os_message(message, result);
+ };
+ };
+ }
+ }
+}
+static QScopedPointer qt_event_filter;
+#endif
///////////////////////////////////////////////////////////////////////////////
// STARTUP FUNCTION
@@ -229,7 +265,7 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &
//Check Qt version
#ifdef QT_BUILD_KEY
qDebug("Using Qt v%s [%s], %s, %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"), QLibraryInfo::buildKey().toLatin1().constData());
- qDebug("Compiled with Qt v%s [%s], %s\n", QT_VERSION_STR, QT_PACKAGEDATE_STR, QT_BUILD_KEY);
+ qDebug("Compiled with Qt v%s, %s\n", QT_VERSION_STR, QT_BUILD_KEY);
if(_stricmp(qVersion(), QT_VERSION_STR))
{
qFatal("%s", QApplication::tr("Executable '%1' requires Qt v%2, but found Qt v%3.").arg(executableName, QString::fromLatin1(QT_VERSION_STR), QString::fromLatin1(qVersion())).toLatin1().constData());
@@ -242,7 +278,7 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &
}
#else
qDebug("Using Qt v%s [%s], %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"));
- qDebug("Compiled with Qt v%s [%s]\n", QT_VERSION_STR, QT_PACKAGEDATE_STR);
+ qDebug("Compiled with Qt v%s\n", QT_VERSION_STR);
#endif
//Check the Windows version
@@ -298,7 +334,12 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &
application->setApplicationName(appName);
application->setOrganizationName("LoRd_MuldeR");
application->setOrganizationDomain("mulder.at.gg");
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
application->setEventFilter(qt_event_filter);
+#else
+ qt_event_filter.reset(new Internal::NativeEventFilter);
+ application->installNativeEventFilter(qt_event_filter.data());
+#endif
//Check for supported image formats
QList supportedFormats = QImageReader::supportedImageFormats();
diff --git a/src/Taskbar7_Win32.cpp b/src/Taskbar7_Win32.cpp
index 10f93a1..81a4e5a 100644
--- a/src/Taskbar7_Win32.cpp
+++ b/src/Taskbar7_Win32.cpp
@@ -25,9 +25,15 @@
#include
#include
+//Internal
+#include "Utils_Win32.h"
+
//Qt
#include
#include
+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
+#include
+#endif
//Windows includes
#define NOMINMAX
@@ -153,15 +159,15 @@ bool MUtils::Taskbar7::setOverlayIcon(const QIcon *const icon, const QString &in
HRESULT result = HRESULT(-1);
if(icon)
{
- if(const HICON hIcon = icon->pixmap(16,16).toWinHICON())
+ if(const HICON hIcon = (HICON)MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16))
{
- result = p->taskbarList->SetOverlayIcon(m_window->winId(), hIcon, MUTILS_WCHR(info));
+ result = p->taskbarList->SetOverlayIcon(reinterpret_cast(m_window->winId()), hIcon, MUTILS_WCHR(info));
DestroyIcon(hIcon);
}
}
else
{
- result = p->taskbarList->SetOverlayIcon(m_window->winId(), NULL, MUTILS_WCHR(info));
+ result = p->taskbarList->SetOverlayIcon(reinterpret_cast(m_window->winId()), NULL, MUTILS_WCHR(info));
}
return SUCCEEDED(result);
}
diff --git a/src/Terminal_Win32.cpp b/src/Terminal_Win32.cpp
index dc142fd..a5b2462 100644
--- a/src/Terminal_Win32.cpp
+++ b/src/Terminal_Win32.cpp
@@ -419,7 +419,7 @@ void MUtils::Terminal::set_icon(const QIcon &icon)
if(g_terminal_attached && (!(icon.isNull() || MUtils::OS::running_on_wine())))
{
- if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16))
+ if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(&icon, 16, 16))
{
typedef BOOL(__stdcall *SetConsoleIconFun)(HICON);
bool success = false;
diff --git a/src/Utils_Win32.cpp b/src/Utils_Win32.cpp
index 7be2757..d87e097 100644
--- a/src/Utils_Win32.cpp
+++ b/src/Utils_Win32.cpp
@@ -25,6 +25,7 @@
#ifndef _INC_WINDOWS
#define WIN32_LEAN_AND_MEAN 1
#include
+#include // required by QWinMime in QtWinExtras
#endif //_INC_WINDOWS
//Qt
@@ -33,19 +34,29 @@
#include
#include
#include
+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
+#include
+#endif
+
+//Qt5 support
+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
+#define PIXMAP2HICON(X) QtWin::toHICON((X))
+#else
+#define PIXMAP2HICON(X) (X).toWinHICON()
+#endif
///////////////////////////////////////////////////////////////////////////////
// QICON TO HICON
///////////////////////////////////////////////////////////////////////////////
-uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon &icon, const int w, const int h)
+uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon *const icon, const int w, const int h)
{
- if(!icon.isNull())
+ if(!icon->isNull())
{
- QPixmap pixmap = icon.pixmap(w, h);
+ QPixmap pixmap = icon->pixmap(w, h);
if(!pixmap.isNull())
{
- return (uintptr_t) pixmap.toWinHICON();
+ return (uintptr_t) PIXMAP2HICON(pixmap);
}
}
return NULL;
diff --git a/src/Utils_Win32.h b/src/Utils_Win32.h
index 689d698..37eebdc 100644
--- a/src/Utils_Win32.h
+++ b/src/Utils_Win32.h
@@ -29,7 +29,7 @@ namespace MUtils
{
namespace Win32Utils
{
- uintptr_t qicon_to_hicon(const QIcon &icon, const int w, const int h);
+ uintptr_t qicon_to_hicon(const QIcon *const icon, const int w, const int h);
const uintptr_t &resolve_helper(const QString &libraryName, const QString &functionName);
template