OSDN Git Service

Added Qt5 support, contributed by John Buonagurio <jbuonagurio@exponent.com>.
authorjbuonagurio <jbuonagurio@exponent.com>
Thu, 5 Jan 2017 20:59:36 +0000 (15:59 -0500)
committerLoRd_MuldeR <mulder2@gmx.de>
Fri, 6 Jan 2017 22:10:01 +0000 (23:10 +0100)
README.html
README.md
include/MUtils/OSSupport.h
src/GUI.cpp
src/GUI_Win32.cpp
src/OSSupport_Win32.cpp
src/Startup.cpp
src/Taskbar7_Win32.cpp
src/Terminal_Win32.cpp
src/Utils_Win32.cpp
src/Utils_Win32.h

index 3deda24..cb8483e 100644 (file)
@@ -102,18 +102,28 @@ You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.</code></pre>
 <h1 id="acknowledgement"><span class="header-section-number">6</span> Acknowledgement</h1>
+<p>The following people have contributed in the development of the MUtilities library:</p>
+<ul>
+<li><strong>John Buonagurio &lt;<script type="text/javascript">
+<!--
+h='&#x65;&#120;&#112;&#x6f;&#110;&#x65;&#110;&#116;&#46;&#x63;&#x6f;&#x6d;';a='&#64;';n='&#106;&#98;&#x75;&#x6f;&#110;&#x61;&#x67;&#x75;&#114;&#x69;&#x6f;';e=n+a+h;
+document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>');
+// -->
+</script><noscript>&#106;&#98;&#x75;&#x6f;&#110;&#x61;&#x67;&#x75;&#114;&#x69;&#x6f;&#32;&#x61;&#116;&#32;&#x65;&#120;&#112;&#x6f;&#110;&#x65;&#110;&#116;&#32;&#100;&#x6f;&#116;&#32;&#x63;&#x6f;&#x6d;</noscript>&gt;</strong><br />
+Support for Qt5</li>
+</ul>
 <p>The following third-party code is used in the MUtilities library:</p>
 <ul>
 <li><p><strong>Keccak/SHA-3 Reference Implementation</strong><br />
 Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, MichaĆ«l Peeters, Gilles Van Assche and Ronny Van Keer<br />
 No Copyright / Dedicated to the Public Domain</p></li>
 <li><p><strong>Natural Order String Comparison</strong><br />
-Copyright (C) 2000, 2004 by Martin Pool <script type="text/javascript">
+Copyright (C) 2000, 2004 by Martin Pool &lt;<script type="text/javascript">
 <!--
 h='&#x73;&#x6f;&#x75;&#114;&#x63;&#x65;&#102;&#114;&#x6f;&#x67;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#x6d;&#98;&#112;';e=n+a+h;
 document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>');
 // -->
-</script><noscript>&#x6d;&#98;&#112;&#32;&#x61;&#116;&#32;&#x73;&#x6f;&#x75;&#114;&#x63;&#x65;&#102;&#114;&#x6f;&#x67;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript><br />
+</script><noscript>&#x6d;&#98;&#112;&#32;&#x61;&#116;&#32;&#x73;&#x6f;&#x75;&#114;&#x63;&#x65;&#102;&#114;&#x6f;&#x67;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript>&gt;<br />
 Released under the zlib License</p></li>
 <li><p><strong>Adler-32 Checksum Algorithm (from zlib)</strong><br />
 Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler<br />
index bd3dd48..848219d 100644 (file)
--- 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 &lt;<jbuonagurio@exponent.com>&gt;**  
+  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 <mbp@sourcefrog.net>  
+  Copyright (C) 2000, 2004 by Martin Pool &lt;<mbp@sourcefrog.net>&gt;  
   Released under the zlib License
 
 * **Adler-32 Checksum Algorithm (from zlib)**  
index 1b95b0b..671b96f 100644 (file)
@@ -28,6 +28,7 @@
 #include <QString>
 #include <QMap>
 #include <QDate>
+#include <QWidget>
 
 //Forward declaration
 class QFile;
index 6e0bbd1..c3cbafc 100644 (file)
@@ -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<HWND>(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;
index 9670826..68bb5e2 100644 (file)
@@ -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<HWND>(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<HWND>(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<HWND>(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<HWND>(window->winId())) != FALSE);
+                       SwitchToThisWindow(reinterpret_cast<HWND>(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<HWND>(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<HWND>(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<HWND>(window->winId()), &bb))
        {
                qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
                return false;
index 088e5f1..1ad78cd 100644 (file)
@@ -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 &parameters, 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<HWND>(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)
index faecafc..e5765c9 100644 (file)
@@ -37,6 +37,9 @@
 #include <QFont>
 #include <QMessageBox>
 #include <QtPlugin>
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
+#include <QAbstractNativeEventFilter>
+#endif
 
 //CRT
 #include <string.h>
@@ -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))
+}
+#else
+#define qInstallMsgHandler(X) qInstallMessageHandler((X))
+static void qt_message_handler(QtMsgType type, const QMessageLogContext&, const QString &msg)
+{
+       if (!msg.isEmpty())
        {
-               MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg)));
+               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<MUtils::Startup::Internal::NativeEventFilter> 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<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
index 10f93a1..81a4e5a 100644 (file)
 #include <MUtils/OSSupport.h>
 #include <MUtils/Exception.h>
 
+//Internal
+#include "Utils_Win32.h"
+
 //Qt
 #include <QWidget>
 #include <QIcon>
+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
+#include <QtWinExtras>
+#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<HWND>(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<HWND>(m_window->winId()), NULL, MUTILS_WCHR(info));
        }
        return SUCCEEDED(result);
 }
index dc142fd..a5b2462 100644 (file)
@@ -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;
index 7be2757..d87e097 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef _INC_WINDOWS
 #define WIN32_LEAN_AND_MEAN 1
 #include <Windows.h>
+#include <ObjIdl.h>  // required by QWinMime in QtWinExtras
 #endif //_INC_WINDOWS
 
 //Qt
 #include <QReadWriteLock>
 #include <QLibrary>
 #include <QHash>
+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
+#include <QtWinExtras>
+#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;
index 689d698..37eebdc 100644 (file)
@@ -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<class T>