MUtilities development repository
修订版 | c7a859c64cc0e87f694ca8663f4fe86de1aafabb (tree) |
---|---|
时间 | 2017-01-07 07:10:01 |
作者 | jbuonagurio <jbuonagurio@expo...> |
Commiter | LoRd_MuldeR |
Added Qt5 support, contributed by John Buonagurio <jbuonagurio@exponent.com>.
@@ -102,18 +102,28 @@ You should have received a copy of the GNU Lesser General Public | ||
102 | 102 | License along with this library; if not, write to the Free Software |
103 | 103 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</code></pre> |
104 | 104 | <h1 id="acknowledgement"><span class="header-section-number">6</span> Acknowledgement</h1> |
105 | +<p>The following people have contributed in the development of the MUtilities library:</p> | |
106 | +<ul> | |
107 | +<li><strong>John Buonagurio <<script type="text/javascript"> | |
108 | +<!-- | |
109 | +h='exponent.com';a='@';n='jbuonagurio';e=n+a+h; | |
110 | +document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>'); | |
111 | +// --> | |
112 | +</script><noscript>jbuonagurio at exponent dot com</noscript>></strong><br /> | |
113 | +Support for Qt5</li> | |
114 | +</ul> | |
105 | 115 | <p>The following third-party code is used in the MUtilities library:</p> |
106 | 116 | <ul> |
107 | 117 | <li><p><strong>Keccak/SHA-3 Reference Implementation</strong><br /> |
108 | 118 | Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer<br /> |
109 | 119 | No Copyright / Dedicated to the Public Domain</p></li> |
110 | 120 | <li><p><strong>Natural Order String Comparison</strong><br /> |
111 | -Copyright (C) 2000, 2004 by Martin Pool <script type="text/javascript"> | |
121 | +Copyright (C) 2000, 2004 by Martin Pool <<script type="text/javascript"> | |
112 | 122 | <!-- |
113 | 123 | h='sourcefrog.net';a='@';n='mbp';e=n+a+h; |
114 | 124 | document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>'); |
115 | 125 | // --> |
116 | -</script><noscript>mbp at sourcefrog dot net</noscript><br /> | |
126 | +</script><noscript>mbp at sourcefrog dot net</noscript>><br /> | |
117 | 127 | Released under the zlib License</p></li> |
118 | 128 | <li><p><strong>Adler-32 Checksum Algorithm (from zlib)</strong><br /> |
119 | 129 | Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler<br /> |
@@ -70,6 +70,11 @@ This library is free software. It is released under the terms of the [*GNU Lesse | ||
70 | 70 | |
71 | 71 | # Acknowledgement |
72 | 72 | |
73 | +The following people have contributed in the development of the MUtilities library: | |
74 | + | |
75 | +* **John Buonagurio <<jbuonagurio@exponent.com>>** | |
76 | + Support for Qt5 | |
77 | + | |
73 | 78 | The following third-party code is used in the MUtilities library: |
74 | 79 | |
75 | 80 | * **Keccak/SHA-3 Reference Implementation** |
@@ -77,7 +82,7 @@ The following third-party code is used in the MUtilities library: | ||
77 | 82 | No Copyright / Dedicated to the Public Domain |
78 | 83 | |
79 | 84 | * **Natural Order String Comparison** |
80 | - Copyright (C) 2000, 2004 by Martin Pool <mbp@sourcefrog.net> | |
85 | + Copyright (C) 2000, 2004 by Martin Pool <<mbp@sourcefrog.net>> | |
81 | 86 | Released under the zlib License |
82 | 87 | |
83 | 88 | * **Adler-32 Checksum Algorithm (from zlib)** |
@@ -28,6 +28,7 @@ | ||
28 | 28 | #include <QString> |
29 | 29 | #include <QMap> |
30 | 30 | #include <QDate> |
31 | +#include <QWidget> | |
31 | 32 | |
32 | 33 | //Forward declaration |
33 | 34 | class QFile; |
@@ -92,7 +92,7 @@ namespace MUtils | ||
92 | 92 | QObject(parent), |
93 | 93 | m_hIcon(hIcon) |
94 | 94 | { |
95 | - SendMessage(parent->winId(), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon)); | |
95 | + SendMessage(reinterpret_cast<HWND>(parent->winId()), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon)); | |
96 | 96 | } |
97 | 97 | |
98 | 98 | virtual ~WindowIconHelper(void) |
@@ -115,7 +115,7 @@ bool MUtils::GUI::set_window_icon(QWidget *const window, const QIcon &icon, cons | ||
115 | 115 | if((!icon.isNull()) && window->winId()) |
116 | 116 | { |
117 | 117 | const int extend = (bIsBigIcon ? 32 : 16); |
118 | - if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, extend, extend)) | |
118 | + if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(&icon, extend, extend)) | |
119 | 119 | { |
120 | 120 | new Internal::WindowIconHelper(window, hIcon, bIsBigIcon); /*will be free'd using QObject parent mechanism*/ |
121 | 121 | return true; |
@@ -88,7 +88,7 @@ bool MUtils::GUI::sysmenu_append(const QWidget *win, const unsigned int identifi | ||
88 | 88 | { |
89 | 89 | bool ok = false; |
90 | 90 | |
91 | - if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE)) | |
91 | + if(HMENU hMenu = GetSystemMenu(reinterpret_cast<HWND>(win->winId()), FALSE)) | |
92 | 92 | { |
93 | 93 | ok = (AppendMenuW(hMenu, MF_SEPARATOR, 0, 0) == TRUE); |
94 | 94 | 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 | ||
101 | 101 | { |
102 | 102 | bool ok = false; |
103 | 103 | |
104 | - if(HMENU hMenu = ::GetSystemMenu(win->winId(), FALSE)) | |
104 | + if(HMENU hMenu = ::GetSystemMenu(reinterpret_cast<HWND>(win->winId()), FALSE)) | |
105 | 105 | { |
106 | 106 | ok = (ModifyMenu(hMenu, identifier, MF_STRING | MF_BYCOMMAND, identifier, MUTILS_WCHR(text)) == TRUE); |
107 | 107 | } |
@@ -121,7 +121,7 @@ bool MUtils::GUI::enable_close_button(const QWidget *win, const bool &bEnable) | ||
121 | 121 | { |
122 | 122 | bool ok = false; |
123 | 123 | |
124 | - if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE)) | |
124 | + if(HMENU hMenu = GetSystemMenu(reinterpret_cast<HWND>(win->winId()), FALSE)) | |
125 | 125 | { |
126 | 126 | ok = (EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (bEnable ? MF_ENABLED : MF_GRAYED)) == TRUE); |
127 | 127 | } |
@@ -156,8 +156,8 @@ bool MUtils::GUI::bring_to_front(const QWidget *window) | ||
156 | 156 | { |
157 | 157 | for(int i = 0; (i < 5) && (!ret); i++) |
158 | 158 | { |
159 | - ret = (SetForegroundWindow(window->winId()) != FALSE); | |
160 | - SwitchToThisWindow(window->winId(), TRUE); | |
159 | + ret = (SetForegroundWindow(reinterpret_cast<HWND>(window->winId())) != FALSE); | |
160 | + SwitchToThisWindow(reinterpret_cast<HWND>(window->winId()), TRUE); | |
161 | 161 | } |
162 | 162 | LockSetForegroundWindow(LSFW_LOCK); |
163 | 163 | } |
@@ -204,7 +204,7 @@ bool MUtils::GUI::sheet_of_glass(QWidget *const window) | ||
204 | 204 | |
205 | 205 | //Enable the "sheet of glass" effect on this window |
206 | 206 | MARGINS margins = {-1, -1, -1, -1}; |
207 | - if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(window->winId(), &margins)) | |
207 | + if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(reinterpret_cast<HWND>(window->winId()), &margins)) | |
208 | 208 | { |
209 | 209 | qWarning("DwmExtendFrameIntoClientArea function has failed! (error %d)", hr); |
210 | 210 | return false; |
@@ -215,7 +215,7 @@ bool MUtils::GUI::sheet_of_glass(QWidget *const window) | ||
215 | 215 | memset(&bb, 0, sizeof(DWM_BLURBEHIND)); |
216 | 216 | bb.fEnable = TRUE; |
217 | 217 | bb.dwFlags = DWM_BB_ENABLE; |
218 | - if(HRESULT hr = dwmEnableBlurBehindWindowFun(window->winId(), &bb)) | |
218 | + if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast<HWND>(window->winId()), &bb)) | |
219 | 219 | { |
220 | 220 | qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr); |
221 | 221 | return false; |
@@ -258,7 +258,7 @@ bool MUtils::GUI::sheet_of_glass_update(QWidget *const window) | ||
258 | 258 | memset(&bb, 0, sizeof(DWM_BLURBEHIND)); |
259 | 259 | bb.fEnable = TRUE; |
260 | 260 | bb.dwFlags = DWM_BB_ENABLE; |
261 | - if(HRESULT hr = dwmEnableBlurBehindWindowFun(window->winId(), &bb)) | |
261 | + if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast<HWND>(window->winId()), &bb)) | |
262 | 262 | { |
263 | 263 | qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr); |
264 | 264 | return false; |
@@ -1236,7 +1236,7 @@ bool MUtils::OS::free_diskspace(const QString &path, quint64 &freeSpace) | ||
1236 | 1236 | |
1237 | 1237 | bool MUtils::OS::shell_open(const QWidget *parent, const QString &url, const QString ¶meters, const QString &directory, const bool explore) |
1238 | 1238 | { |
1239 | - 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; | |
1239 | + 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; | |
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | bool MUtils::OS::shell_open(const QWidget *parent, const QString &url, const bool explore) |
@@ -37,6 +37,9 @@ | ||
37 | 37 | #include <QFont> |
38 | 38 | #include <QMessageBox> |
39 | 39 | #include <QtPlugin> |
40 | +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) | |
41 | +#include <QAbstractNativeEventFilter> | |
42 | +#endif | |
40 | 43 | |
41 | 44 | //CRT |
42 | 45 | #include <string.h> |
@@ -96,25 +99,58 @@ namespace MUtils | ||
96 | 99 | // MESSAGE HANDLER |
97 | 100 | /////////////////////////////////////////////////////////////////////////////// |
98 | 101 | |
102 | +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) | |
99 | 103 | static void qt_message_handler(QtMsgType type, const char *const msg) |
100 | 104 | { |
101 | - if((!msg) || (!(msg[0]))) | |
105 | + if (msg && msg[0]) | |
102 | 106 | { |
103 | - return; | |
107 | + MUtils::Terminal::write(type, msg); | |
108 | + if ((type == QtCriticalMsg) || (type == QtFatalMsg)) | |
109 | + { | |
110 | + MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg))); | |
111 | + } | |
104 | 112 | } |
105 | - | |
106 | - MUtils::Terminal::write(type, msg); | |
107 | - | |
108 | - if((type == QtCriticalMsg) || (type == QtFatalMsg)) | |
113 | +} | |
114 | +#else | |
115 | +#define qInstallMsgHandler(X) qInstallMessageHandler((X)) | |
116 | +static void qt_message_handler(QtMsgType type, const QMessageLogContext&, const QString &msg) | |
117 | +{ | |
118 | + if (!msg.isEmpty()) | |
109 | 119 | { |
110 | - MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg))); | |
120 | + MUtils::Terminal::write(type, msg.toUtf8().constData()); | |
121 | + if ((type == QtCriticalMsg) || (type == QtFatalMsg)) | |
122 | + { | |
123 | + MUtils::OS::fatal_exit(MUTILS_WCHR(msg)); | |
124 | + } | |
111 | 125 | } |
112 | 126 | } |
127 | +#endif | |
113 | 128 | |
129 | +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) | |
114 | 130 | static bool qt_event_filter(void *message, long *result) |
115 | 131 | { |
116 | 132 | return MUtils::OS::handle_os_message(message, result); |
117 | 133 | } |
134 | +#else | |
135 | +namespace MUtils | |
136 | +{ | |
137 | + namespace Startup | |
138 | + { | |
139 | + namespace Internal | |
140 | + { | |
141 | + class NativeEventFilter : public QAbstractNativeEventFilter | |
142 | + { | |
143 | + public: | |
144 | + bool nativeEventFilter(const QByteArray&, void *message, long *result) Q_DECL_OVERRIDE | |
145 | + { | |
146 | + return MUtils::OS::handle_os_message(message, result); | |
147 | + }; | |
148 | + }; | |
149 | + } | |
150 | + } | |
151 | +} | |
152 | +static QScopedPointer<MUtils::Startup::Internal::NativeEventFilter> qt_event_filter; | |
153 | +#endif | |
118 | 154 | |
119 | 155 | /////////////////////////////////////////////////////////////////////////////// |
120 | 156 | // STARTUP FUNCTION |
@@ -229,7 +265,7 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString & | ||
229 | 265 | //Check Qt version |
230 | 266 | #ifdef QT_BUILD_KEY |
231 | 267 | qDebug("Using Qt v%s [%s], %s, %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"), QLibraryInfo::buildKey().toLatin1().constData()); |
232 | - qDebug("Compiled with Qt v%s [%s], %s\n", QT_VERSION_STR, QT_PACKAGEDATE_STR, QT_BUILD_KEY); | |
268 | + qDebug("Compiled with Qt v%s, %s\n", QT_VERSION_STR, QT_BUILD_KEY); | |
233 | 269 | if(_stricmp(qVersion(), QT_VERSION_STR)) |
234 | 270 | { |
235 | 271 | 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 & | ||
242 | 278 | } |
243 | 279 | #else |
244 | 280 | qDebug("Using Qt v%s [%s], %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static")); |
245 | - qDebug("Compiled with Qt v%s [%s]\n", QT_VERSION_STR, QT_PACKAGEDATE_STR); | |
281 | + qDebug("Compiled with Qt v%s\n", QT_VERSION_STR); | |
246 | 282 | #endif |
247 | 283 | |
248 | 284 | //Check the Windows version |
@@ -298,7 +334,12 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString & | ||
298 | 334 | application->setApplicationName(appName); |
299 | 335 | application->setOrganizationName("LoRd_MuldeR"); |
300 | 336 | application->setOrganizationDomain("mulder.at.gg"); |
337 | +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) | |
301 | 338 | application->setEventFilter(qt_event_filter); |
339 | +#else | |
340 | + qt_event_filter.reset(new Internal::NativeEventFilter); | |
341 | + application->installNativeEventFilter(qt_event_filter.data()); | |
342 | +#endif | |
302 | 343 | |
303 | 344 | //Check for supported image formats |
304 | 345 | QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats(); |
@@ -25,9 +25,15 @@ | ||
25 | 25 | #include <MUtils/OSSupport.h> |
26 | 26 | #include <MUtils/Exception.h> |
27 | 27 | |
28 | +//Internal | |
29 | +#include "Utils_Win32.h" | |
30 | + | |
28 | 31 | //Qt |
29 | 32 | #include <QWidget> |
30 | 33 | #include <QIcon> |
34 | +#if QT_VERSION > QT_VERSION_CHECK(5,0,0) | |
35 | +#include <QtWinExtras> | |
36 | +#endif | |
31 | 37 | |
32 | 38 | //Windows includes |
33 | 39 | #define NOMINMAX |
@@ -153,15 +159,15 @@ bool MUtils::Taskbar7::setOverlayIcon(const QIcon *const icon, const QString &in | ||
153 | 159 | HRESULT result = HRESULT(-1); |
154 | 160 | if(icon) |
155 | 161 | { |
156 | - if(const HICON hIcon = icon->pixmap(16,16).toWinHICON()) | |
162 | + if(const HICON hIcon = (HICON)MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16)) | |
157 | 163 | { |
158 | - result = p->taskbarList->SetOverlayIcon(m_window->winId(), hIcon, MUTILS_WCHR(info)); | |
164 | + result = p->taskbarList->SetOverlayIcon(reinterpret_cast<HWND>(m_window->winId()), hIcon, MUTILS_WCHR(info)); | |
159 | 165 | DestroyIcon(hIcon); |
160 | 166 | } |
161 | 167 | } |
162 | 168 | else |
163 | 169 | { |
164 | - result = p->taskbarList->SetOverlayIcon(m_window->winId(), NULL, MUTILS_WCHR(info)); | |
170 | + result = p->taskbarList->SetOverlayIcon(reinterpret_cast<HWND>(m_window->winId()), NULL, MUTILS_WCHR(info)); | |
165 | 171 | } |
166 | 172 | return SUCCEEDED(result); |
167 | 173 | } |
@@ -419,7 +419,7 @@ void MUtils::Terminal::set_icon(const QIcon &icon) | ||
419 | 419 | |
420 | 420 | if(g_terminal_attached && (!(icon.isNull() || MUtils::OS::running_on_wine()))) |
421 | 421 | { |
422 | - if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16)) | |
422 | + if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(&icon, 16, 16)) | |
423 | 423 | { |
424 | 424 | typedef BOOL(__stdcall *SetConsoleIconFun)(HICON); |
425 | 425 | bool success = false; |
@@ -25,6 +25,7 @@ | ||
25 | 25 | #ifndef _INC_WINDOWS |
26 | 26 | #define WIN32_LEAN_AND_MEAN 1 |
27 | 27 | #include <Windows.h> |
28 | +#include <ObjIdl.h> // required by QWinMime in QtWinExtras | |
28 | 29 | #endif //_INC_WINDOWS |
29 | 30 | |
30 | 31 | //Qt |
@@ -33,19 +34,29 @@ | ||
33 | 34 | #include <QReadWriteLock> |
34 | 35 | #include <QLibrary> |
35 | 36 | #include <QHash> |
37 | +#if QT_VERSION > QT_VERSION_CHECK(5,0,0) | |
38 | +#include <QtWinExtras> | |
39 | +#endif | |
40 | + | |
41 | +//Qt5 support | |
42 | +#if QT_VERSION > QT_VERSION_CHECK(5,0,0) | |
43 | +#define PIXMAP2HICON(X) QtWin::toHICON((X)) | |
44 | +#else | |
45 | +#define PIXMAP2HICON(X) (X).toWinHICON() | |
46 | +#endif | |
36 | 47 | |
37 | 48 | /////////////////////////////////////////////////////////////////////////////// |
38 | 49 | // QICON TO HICON |
39 | 50 | /////////////////////////////////////////////////////////////////////////////// |
40 | 51 | |
41 | -uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon &icon, const int w, const int h) | |
52 | +uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon *const icon, const int w, const int h) | |
42 | 53 | { |
43 | - if(!icon.isNull()) | |
54 | + if(!icon->isNull()) | |
44 | 55 | { |
45 | - QPixmap pixmap = icon.pixmap(w, h); | |
56 | + QPixmap pixmap = icon->pixmap(w, h); | |
46 | 57 | if(!pixmap.isNull()) |
47 | 58 | { |
48 | - return (uintptr_t) pixmap.toWinHICON(); | |
59 | + return (uintptr_t) PIXMAP2HICON(pixmap); | |
49 | 60 | } |
50 | 61 | } |
51 | 62 | return NULL; |
@@ -29,7 +29,7 @@ namespace MUtils | ||
29 | 29 | { |
30 | 30 | namespace Win32Utils |
31 | 31 | { |
32 | - uintptr_t qicon_to_hicon(const QIcon &icon, const int w, const int h); | |
32 | + uintptr_t qicon_to_hicon(const QIcon *const icon, const int w, const int h); | |
33 | 33 | const uintptr_t &resolve_helper(const QString &libraryName, const QString &functionName); |
34 | 34 | |
35 | 35 | template<class T> |