diff options
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | examples/winextras/musicplayer/main.cpp | 71 | ||||
-rw-r--r-- | examples/winextras/musicplayer/musicplayer.cpp | 110 | ||||
-rw-r--r-- | examples/winextras/musicplayer/musicplayer.h | 40 | ||||
-rw-r--r-- | examples/winextras/musicplayer/volumebutton.cpp | 2 | ||||
-rw-r--r-- | examples/winextras/musicplayer/volumebutton.h | 8 | ||||
-rw-r--r-- | src/winextras/qwinfunctions.cpp | 84 | ||||
-rw-r--r-- | src/winextras/qwinfunctions_p.cpp | 28 | ||||
-rw-r--r-- | src/winextras/qwinfunctions_p.h | 94 | ||||
-rw-r--r-- | src/winextras/qwinjumplist.cpp | 20 | ||||
-rw-r--r-- | src/winextras/qwinjumplistcategory.cpp | 15 | ||||
-rw-r--r-- | src/winextras/qwinthumbnailtoolbar.cpp | 9 | ||||
-rw-r--r-- | src/winextras/winextras.pro | 3 |
13 files changed, 237 insertions, 249 deletions
diff --git a/.qmake.conf b/.qmake.conf index a2a0d41..aefa1e7 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,3 @@ load(qt_build_config) -MODULE_VERSION = 5.7.1 +MODULE_VERSION = 5.8.0 diff --git a/examples/winextras/musicplayer/main.cpp b/examples/winextras/musicplayer/main.cpp index 5cace0d..0502015 100644 --- a/examples/winextras/musicplayer/main.cpp +++ b/examples/winextras/musicplayer/main.cpp @@ -41,50 +41,79 @@ #include "musicplayer.h" #include <QApplication> +#include <QCommandLineParser> +#include <QCommandLineOption> +#include <QDesktopWidget> #include <QFileInfo> +#include <QMimeDatabase> #include <QSettings> #include <QIcon> #include <QDir> +#include <QUrl> //! [0] -static void associateFileTypes(const QStringList &fileTypes) +static bool associateFileTypes() { QString displayName = QGuiApplication::applicationDisplayName(); QString filePath = QCoreApplication::applicationFilePath(); QString fileName = QFileInfo(filePath).fileName(); - QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\Applications\\" + fileName, QSettings::NativeFormat); - settings.setValue("FriendlyAppName", displayName); + const QString key = QStringLiteral("HKEY_CURRENT_USER\\Software\\Classes\\Applications\\") + fileName; + QSettings settings(key, QSettings::NativeFormat); + if (settings.status() != QSettings::NoError) { + qWarning() << "Cannot access registry key" << key; + return false; + } + settings.setValue(QStringLiteral("FriendlyAppName"), displayName); - settings.beginGroup("SupportedTypes"); - foreach (const QString& fileType, fileTypes) - settings.setValue(fileType, QString()); + settings.beginGroup(QStringLiteral("SupportedTypes")); + QMimeDatabase mimeDatabase; + foreach (const QString &fileType, MusicPlayer::supportedMimeTypes()) { + foreach (QString suffix, mimeDatabase.mimeTypeForName(fileType).suffixes()) { + suffix.prepend('.'); + settings.setValue(suffix, QString()); + } + } settings.endGroup(); - settings.beginGroup("shell"); - settings.beginGroup("open"); - settings.setValue("FriendlyAppName", displayName); - settings.beginGroup("Command"); - settings.setValue(".", QChar('"') + QDir::toNativeSeparators(filePath) + QString("\" \"%1\"")); + settings.beginGroup(QStringLiteral("shell")); + settings.beginGroup(QStringLiteral("open")); + settings.setValue(QStringLiteral("FriendlyAppName"), displayName); + settings.beginGroup(QStringLiteral("Command")); + settings.setValue(QStringLiteral("."), + QLatin1Char('"') + QDir::toNativeSeparators(filePath) + QStringLiteral("\" \"%1\"")); + + return true; } //! [0] int main(int argc, char *argv[]) { QApplication app(argc, argv); - app.setApplicationName("MusicPlayer"); - app.setOrganizationName("QtWinExtras"); - app.setOrganizationDomain("qt-project.org"); - app.setApplicationDisplayName("QtWinExtras Music Player"); - app.setWindowIcon(QIcon(":/logo.png")); + QCoreApplication::setApplicationName(QStringLiteral("MusicPlayer")); + QCoreApplication::setApplicationVersion( QLatin1String(QT_VERSION_STR)); + QCoreApplication::setOrganizationName(QStringLiteral("QtWinExtras")); + QCoreApplication::setOrganizationDomain("qt-project.org"); + QGuiApplication::setApplicationDisplayName(QStringLiteral("QtWinExtras Music Player")); + QApplication::setWindowIcon(QIcon(QStringLiteral(":/logo.png"))); + + if (!associateFileTypes()) + return -1; - associateFileTypes(QStringList(".mp3")); + QCommandLineParser parser; + parser.setApplicationDescription(QGuiApplication::applicationDisplayName()); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument(QStringLiteral("url"), MusicPlayer::tr("The URL to open.")); + parser.process(app); MusicPlayer player; - const QStringList arguments = QCoreApplication::arguments(); - if (arguments.size() > 1) - player.playFile(arguments.at(1)); - player.resize(300, 60); + + if (!parser.positionalArguments().isEmpty()) + player.playUrl(QUrl::fromUserInput(parser.positionalArguments().constFirst(), QDir::currentPath(), QUrl::AssumeLocalFile)); + + const QRect availableGeometry = QApplication::desktop()->availableGeometry(&player); + player.resize(availableGeometry.width() / 6, availableGeometry.height() / 17); player.show(); return app.exec(); diff --git a/examples/winextras/musicplayer/musicplayer.cpp b/examples/winextras/musicplayer/musicplayer.cpp index 26b6fa8..6093976 100644 --- a/examples/winextras/musicplayer/musicplayer.cpp +++ b/examples/winextras/musicplayer/musicplayer.cpp @@ -44,11 +44,7 @@ #include <QtWidgets> #include <QtWinExtras> -MusicPlayer::MusicPlayer(QWidget *parent) : QWidget(parent), - taskbarButton(0), taskbarProgress(0), thumbnailToolBar(0), - playToolButton(0), forwardToolButton(0), backwardToolButton(0), - mediaPlayer(0), playButton(0), volumeButton(0), - positionSlider(0), positionLabel(0), infoLabel(0) +MusicPlayer::MusicPlayer(QWidget *parent) : QWidget(parent) { createWidgets(); createShortcuts(); @@ -67,25 +63,42 @@ MusicPlayer::MusicPlayer(QWidget *parent) : QWidget(parent), this, &MusicPlayer::updateState); stylize(); + setAcceptDrops(true); +} + +QStringList MusicPlayer::supportedMimeTypes() +{ + QStringList result = QMediaPlayer::supportedMimeTypes(); + if (result.isEmpty()) + result.append(QStringLiteral("audio/mpeg")); + return result; } void MusicPlayer::openFile() { - const QStringList musicPaths = QStandardPaths::standardLocations(QStandardPaths::MusicLocation); - const QString filePath = - QFileDialog::getOpenFileName(this, tr("Open File"), - musicPaths.isEmpty() ? QDir::homePath() : musicPaths.first(), - tr("MP3 files (*.mp3);;All files (*.*)")); - if (!filePath.isEmpty()) - playFile(filePath); + QFileDialog fileDialog(this); + fileDialog.setAcceptMode(QFileDialog::AcceptOpen); + fileDialog.setWindowTitle(tr("Open File")); + fileDialog.setMimeTypeFilters(MusicPlayer::supportedMimeTypes()); + fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).value(0, QDir::homePath())); + if (fileDialog.exec() == QDialog::Accepted) + playUrl(fileDialog.selectedUrls().constFirst()); } -void MusicPlayer::playFile(const QString &filePath) +void MusicPlayer::playUrl(const QUrl &url) { playButton->setEnabled(true); - infoLabel->setText(QFileInfo(filePath).fileName()); - - mediaPlayer.setMedia(QUrl::fromLocalFile(filePath)); + if (url.isLocalFile()) { + const QString filePath = url.toLocalFile(); + setWindowFilePath(filePath); + infoLabel->setText(QDir::toNativeSeparators(filePath)); + fileName = QFileInfo(filePath).fileName(); + } else { + setWindowFilePath(QString()); + infoLabel->setText(url.toString()); + fileName.clear(); + } + mediaPlayer.setMedia(url); mediaPlayer.play(); } @@ -118,6 +131,27 @@ bool MusicPlayer::event(QEvent *event) } //! [0] +static bool canHandleDrop(const QDropEvent *event) +{ + const QList<QUrl> urls = event->mimeData()->urls(); + if (urls.size() != 1) + return false; + QMimeDatabase mimeDatabase; + return MusicPlayer::supportedMimeTypes(). + contains(mimeDatabase.mimeTypeForUrl(urls.constFirst()).name()); +} + +void MusicPlayer::dragEnterEvent(QDragEnterEvent *event) +{ + event->setAccepted(canHandleDrop(event)); +} + +void MusicPlayer::dropEvent(QDropEvent *event) +{ + event->accept(); + playUrl(event->mimeData()->urls().constFirst()); +} + void MusicPlayer::mousePressEvent(QMouseEvent *event) { offset = event->globalPos() - pos(); @@ -143,11 +177,11 @@ void MusicPlayer::stylize() QtWin::extendFrameIntoClientArea(this, -1, -1, -1, -1); setAttribute(Qt::WA_TranslucentBackground, true); setAttribute(Qt::WA_NoSystemBackground, false); - setStyleSheet("MusicPlayer { background: transparent; }"); + setStyleSheet(QStringLiteral("MusicPlayer { background: transparent; }")); } else { QtWin::resetExtendedFrame(this); setAttribute(Qt::WA_TranslucentBackground, false); - setStyleSheet(QString("MusicPlayer { background: %1; }").arg(QtWin::realColorizationColor().name())); + setStyleSheet(QStringLiteral("MusicPlayer { background: %1; }").arg(QtWin::realColorizationColor().name())); } volumeButton->stylize(); } @@ -164,12 +198,20 @@ void MusicPlayer::updateState(QMediaPlayer::State state) } } +static QString formatTime(qint64 timeMilliSeconds) +{ + qint64 seconds = timeMilliSeconds / 1000; + const qint64 minutes = seconds / 60; + seconds -= minutes * 60; + return QStringLiteral("%1:%2") + .arg(minutes, 2, 10, QLatin1Char('0')) + .arg(seconds, 2, 10, QLatin1Char('0')); +} + void MusicPlayer::updatePosition(qint64 position) { positionSlider->setValue(position); - - QTime duration(0, position / 60000, qRound((position % 60000) / 1000.0)); - positionLabel->setText(duration.toString(tr("mm:ss"))); + positionLabel->setText(formatTime(position)); } void MusicPlayer::updateDuration(qint64 duration) @@ -177,6 +219,7 @@ void MusicPlayer::updateDuration(qint64 duration) positionSlider->setRange(0, duration); positionSlider->setEnabled(duration > 0); positionSlider->setPageStep(duration / 10); + updateInfo(); } void MusicPlayer::setPosition(int position) @@ -189,20 +232,27 @@ void MusicPlayer::setPosition(int position) void MusicPlayer::updateInfo() { QStringList info; - QString author = mediaPlayer.metaData("Author").toString(); - if (!author.isEmpty()) - info += author; - QString title = mediaPlayer.metaData("Title").toString(); - if (!title.isEmpty()) - info += title; - if (!info.isEmpty()) - infoLabel->setText(info.join(tr(" - "))); + if (!fileName.isEmpty()) + info.append(fileName); + if (mediaPlayer.isMetaDataAvailable()) { + QString author = mediaPlayer.metaData(QStringLiteral("Author")).toString(); + if (!author.isEmpty()) + info.append(author); + QString title = mediaPlayer.metaData(QStringLiteral("Title")).toString(); + if (!title.isEmpty()) + info.append(title); + } + info.append(formatTime(mediaPlayer.duration())); + infoLabel->setText(info.join(tr(" - "))); } void MusicPlayer::handleError() { playButton->setEnabled(false); - infoLabel->setText(tr("Error: %1").arg(mediaPlayer.errorString())); + const QString errorString = mediaPlayer.errorString(); + infoLabel->setText(errorString.isEmpty() + ? tr("Unknown error #%1").arg(int(mediaPlayer.error())) + : tr("Error: %1").arg(errorString)); } //! [2] diff --git a/examples/winextras/musicplayer/musicplayer.h b/examples/winextras/musicplayer/musicplayer.h index b848840..567aeb7 100644 --- a/examples/winextras/musicplayer/musicplayer.h +++ b/examples/winextras/musicplayer/musicplayer.h @@ -58,20 +58,25 @@ class MusicPlayer : public QWidget { Q_OBJECT public: - MusicPlayer(QWidget *parent = 0); + explicit MusicPlayer(QWidget *parent = nullptr); + + static QStringList supportedMimeTypes(); + static QStringList supportedSuffixes(); public slots: void openFile(); - void playFile(const QString& filePath); + void playUrl(const QUrl& url); void togglePlayback(); void seekForward(); void seekBackward(); protected: - bool event(QEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); + bool event(QEvent *event) override; + void dragEnterEvent(QDragEnterEvent *event) override; + void dropEvent(QDropEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; private slots: void stylize(); @@ -92,20 +97,21 @@ private: void createTaskbar(); void createThumbnailToolBar(); - QWinTaskbarButton* taskbarButton; - QWinTaskbarProgress* taskbarProgress; - QWinThumbnailToolBar* thumbnailToolBar; - QWinThumbnailToolButton *playToolButton; - QWinThumbnailToolButton *forwardToolButton; - QWinThumbnailToolButton *backwardToolButton; + QWinTaskbarButton *taskbarButton = nullptr; + QWinTaskbarProgress *taskbarProgress = nullptr; + QWinThumbnailToolBar *thumbnailToolBar = nullptr; + QWinThumbnailToolButton *playToolButton = nullptr; + QWinThumbnailToolButton *forwardToolButton = nullptr; + QWinThumbnailToolButton *backwardToolButton = nullptr; QMediaPlayer mediaPlayer; - QAbstractButton *playButton; - VolumeButton *volumeButton; - QSlider *positionSlider; - QLabel *positionLabel; - QLabel *infoLabel; + QAbstractButton *playButton = nullptr; + VolumeButton *volumeButton = nullptr; + QSlider *positionSlider = nullptr; + QLabel *positionLabel = nullptr; + QLabel *infoLabel = nullptr; QPoint offset; + QString fileName; }; #endif // MUSICPLAYER_H diff --git a/examples/winextras/musicplayer/volumebutton.cpp b/examples/winextras/musicplayer/volumebutton.cpp index 37eb0c1..44be5cf 100644 --- a/examples/winextras/musicplayer/volumebutton.cpp +++ b/examples/winextras/musicplayer/volumebutton.cpp @@ -44,7 +44,7 @@ #include <QtWinExtras> VolumeButton::VolumeButton(QWidget *parent) : - QToolButton(parent), menu(0), label(0), slider(0) + QToolButton(parent) { setIcon(style()->standardIcon(QStyle::SP_MediaVolume)); setPopupMode(QToolButton::InstantPopup); diff --git a/examples/winextras/musicplayer/volumebutton.h b/examples/winextras/musicplayer/volumebutton.h index 99d6da9..3fc3c87 100644 --- a/examples/winextras/musicplayer/volumebutton.h +++ b/examples/winextras/musicplayer/volumebutton.h @@ -53,7 +53,7 @@ class VolumeButton : public QToolButton Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged) public: - VolumeButton(QWidget *parent = 0); + explicit VolumeButton(QWidget *parent = nullptr); int volume() const; @@ -67,9 +67,9 @@ signals: void volumeChanged(int volume); private: - QMenu *menu; - QLabel *label; - QSlider *slider; + QMenu *menu = nullptr; + QLabel *label = nullptr; + QSlider *slider = nullptr; }; #endif // VOLUMEBUTTON_H diff --git a/src/winextras/qwinfunctions.cpp b/src/winextras/qwinfunctions.cpp index 08650d6..692bcb0 100644 --- a/src/winextras/qwinfunctions.cpp +++ b/src/winextras/qwinfunctions.cpp @@ -214,25 +214,6 @@ QRegion QtWin::fromHRGN(HRGN hrgn) return region; } -// Re-engineered from the inline function _com_error::ErrorMessage(). -// We cannot use it directly since it uses swprintf_s(), which is not -// present in the MSVCRT.DLL found on Windows XP (QTBUG-35617). -static inline QString errorMessageFromComError(const _com_error &comError) -{ - TCHAR *message = Q_NULLPTR; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, DWORD(comError.Error()), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), - reinterpret_cast<LPWSTR>(&message), 0, NULL); - if (message) { - const QString result = QString::fromWCharArray(message).trimmed(); - LocalFree(message); - return result; - } - if (const WORD wCode = comError.WCode()) - return QStringLiteral("IDispatch error #") + QString::number(wCode); - return QStringLiteral("Unknown error HRESULT(0x0)") + QString::number(comError.Error(), 16); -} - /*! \since 5.2 @@ -242,7 +223,7 @@ static inline QString errorMessageFromComError(const _com_error &comError) QString QtWin::stringFromHresult(HRESULT hresult) { _com_error error(hresult); - return errorMessageFromComError(error); + return QString::fromWCharArray(error.ErrorMessage()); } /*! @@ -1449,9 +1430,7 @@ QColor QtWin::colorizationColor(bool *opaqueBlend) DWORD colorization = 0; BOOL dummy = false; - qtDwmApiDll.init(); - if (qtDwmApiDll.dwmGetColorizationColor) - qtDwmApiDll.dwmGetColorizationColor(&colorization, &dummy); + DwmGetColorizationColor(&colorization, &dummy); if (opaqueBlend) *opaqueBlend = dummy; return QColor::fromRgba(colorization); @@ -1571,8 +1550,8 @@ void QtWin::setWindowFlip3DPolicy(QWindow *window, QtWin::WindowFlip3DPolicy pol HWND handle = reinterpret_cast<HWND>(window->winId()); // Policy should be defaulted first, bug or smth. - DWORD value = qt_DWMFLIP3D_DEFAULT; - QtDwmApiDll::setWindowAttribute(handle, qt_DWMWA_FLIP3D_POLICY, value); + DWORD value = DWMFLIP3D_DEFAULT; + QtDwmApiDll::setWindowAttribute(handle, DWMWA_FLIP3D_POLICY, value); switch (policy) { default : @@ -1580,15 +1559,15 @@ void QtWin::setWindowFlip3DPolicy(QWindow *window, QtWin::WindowFlip3DPolicy pol value = -1; break; case FlipExcludeBelow : - value = qt_DWMFLIP3D_EXCLUDEBELOW; + value = DWMFLIP3D_EXCLUDEBELOW; break; case FlipExcludeAbove : - value = qt_DWMFLIP3D_EXCLUDEABOVE; + value = DWMFLIP3D_EXCLUDEABOVE; break; } - if (qt_DWMFLIP3D_DEFAULT != value) - QtDwmApiDll::setWindowAttribute(handle, qt_DWMWA_FLIP3D_POLICY, value); + if (DWMFLIP3D_DEFAULT != value) + QtDwmApiDll::setWindowAttribute(handle, DWMWA_FLIP3D_POLICY, value); } /*! @@ -1608,13 +1587,13 @@ QtWin::WindowFlip3DPolicy QtWin::windowFlip3DPolicy(QWindow *window) const DWORD value = QtDwmApiDll::windowAttribute<DWORD>(reinterpret_cast<HWND>(window->winId()), - qt_DWMWA_FLIP3D_POLICY, DWORD(qt_DWMFLIP3D_DEFAULT)); + DWMWA_FLIP3D_POLICY, DWORD(DWMFLIP3D_DEFAULT)); QtWin::WindowFlip3DPolicy policy = QtWin::FlipDefault; switch (value) { - case qt_DWMFLIP3D_EXCLUDEABOVE : + case DWMFLIP3D_EXCLUDEABOVE : policy = QtWin::FlipExcludeAbove; break; - case qt_DWMFLIP3D_EXCLUDEBELOW : + case DWMFLIP3D_EXCLUDEBELOW : policy = QtWin::FlipExcludeBelow; break; default : @@ -1626,12 +1605,8 @@ QtWin::WindowFlip3DPolicy QtWin::windowFlip3DPolicy(QWindow *window) void qt_ExtendFrameIntoClientArea(QWindow *window, int left, int top, int right, int bottom) { QWinEventFilter::setup(); - - qtDwmApiDll.init(); - if (qtDwmApiDll.dwmExtendFrameIntoClientArea) { - MARGINS margins = {left, right, top, bottom}; - qtDwmApiDll.dwmExtendFrameIntoClientArea(reinterpret_cast<HWND>(window->winId()), &margins); - } + MARGINS margins = {left, right, top, bottom}; + DwmExtendFrameIntoClientArea(reinterpret_cast<HWND>(window->winId()), &margins); } /*! \fn void QtWin::extendFrameIntoClientArea(QWidget *window, int left, int top, int right, int bottom) @@ -1725,22 +1700,18 @@ void QtWin::enableBlurBehindWindow(QWindow *window, const QRegion ®ion) { Q_ASSERT_X(window, Q_FUNC_INFO, "window is null"); - qtDwmApiDll.init(); - if (!qtDwmApiDll.dwmEnableBlurBehindWindow) - return; - - qt_DWM_BLURBEHIND dwmbb = {0, 0, 0, 0}; - dwmbb.dwFlags = qt_DWM_BB_ENABLE; + DWM_BLURBEHIND dwmbb = {0, 0, 0, 0}; + dwmbb.dwFlags = DWM_BB_ENABLE; dwmbb.fEnable = TRUE; HRGN rgn = 0; if (!region.isNull()) { rgn = toHRGN(region); if (rgn) { dwmbb.hRgnBlur = rgn; - dwmbb.dwFlags |= qt_DWM_BB_BLURREGION; + dwmbb.dwFlags |= DWM_BB_BLURREGION; } } - qtDwmApiDll.dwmEnableBlurBehindWindow(reinterpret_cast<HWND>(window->winId()), &dwmbb); + DwmEnableBlurBehindWindow(reinterpret_cast<HWND>(window->winId()), &dwmbb); if (rgn) DeleteObject(rgn); } @@ -1779,12 +1750,9 @@ void QtWin::enableBlurBehindWindow(QWindow *window) void QtWin::disableBlurBehindWindow(QWindow *window) { Q_ASSERT_X(window, Q_FUNC_INFO, "window is null"); - qt_DWM_BLURBEHIND dwmbb = {0, 0, 0, 0}; - dwmbb.dwFlags = qt_DWM_BB_ENABLE; - dwmbb.fEnable = FALSE; - qtDwmApiDll.init(); - if (qtDwmApiDll.dwmEnableBlurBehindWindow) - qtDwmApiDll.dwmEnableBlurBehindWindow(reinterpret_cast<HWND>(window->winId()), &dwmbb); + DWM_BLURBEHIND dwmbb = {0, 0, 0, 0}; + dwmbb.dwFlags = DWM_BB_ENABLE; + DwmEnableBlurBehindWindow(reinterpret_cast<HWND>(window->winId()), &dwmbb); } /*! @@ -1797,9 +1765,7 @@ bool QtWin::isCompositionEnabled() QWinEventFilter::setup(); BOOL enabled = FALSE; - qtDwmApiDll.init(); - if (qtDwmApiDll.dwmIsCompositionEnabled) - qtDwmApiDll.dwmIsCompositionEnabled(&enabled); + DwmIsCompositionEnabled(&enabled); return enabled; } @@ -1811,15 +1777,17 @@ bool QtWin::isCompositionEnabled() \note The underlying function was declared deprecated as of Windows 8 and takes no effect. */ + +QT_WARNING_PUSH +QT_WARNING_DISABLE_MSVC(4995) void QtWin::setCompositionEnabled(bool enabled) { QWinEventFilter::setup(); UINT compositionEnabled = enabled; - qtDwmApiDll.init(); - if (qtDwmApiDll.dwmEnableComposition) - qtDwmApiDll.dwmEnableComposition(compositionEnabled); + DwmEnableComposition(compositionEnabled); } +QT_WARNING_POP /*! \since 5.2 diff --git a/src/winextras/qwinfunctions_p.cpp b/src/winextras/qwinfunctions_p.cpp index e9e5dd9..ea9dcf9 100644 --- a/src/winextras/qwinfunctions_p.cpp +++ b/src/winextras/qwinfunctions_p.cpp @@ -49,22 +49,8 @@ QtShell32Dll qtShell32Dll; void QtDwmApiDll::resolve() { - if (const HMODULE dwmapi = LoadLibraryW(L"dwmapi.dll")) { - dwmExtendFrameIntoClientArea = - (DwmExtendFrameIntoClientArea) GetProcAddress(dwmapi, "DwmExtendFrameIntoClientArea"); - dwmEnableBlurBehindWindow = - (DwmEnableBlurBehindWindow) GetProcAddress(dwmapi, "DwmEnableBlurBehindWindow"); - dwmGetColorizationColor = - (DwmGetColorizationColor) GetProcAddress(dwmapi, "DwmGetColorizationColor"); - dwmSetWindowAttribute = - (DwmSetWindowAttribute) GetProcAddress(dwmapi, "DwmSetWindowAttribute"); - dwmGetWindowAttribute = - (DwmGetWindowAttribute) GetProcAddress(dwmapi, "DwmGetWindowAttribute"); - dwmIsCompositionEnabled = - (DwmIsCompositionEnabled) GetProcAddress(dwmapi, "DwmIsCompositionEnabled"); - dwmEnableComposition = - (DwmEnableComposition) GetProcAddress(dwmapi, "DwmEnableComposition"); - if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) { + if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) { + if (const HMODULE dwmapi = LoadLibraryW(L"dwmapi.dll")) { dwmSetIconicThumbnail = (DwmSetIconicThumbnail) GetProcAddress(dwmapi, "DwmSetIconicThumbnail"); dwmSetIconicLivePreviewBitmap = @@ -77,11 +63,11 @@ void QtDwmApiDll::resolve() void QtShell32Dll::resolve() { - if (const HMODULE shell32 = LoadLibraryW(L"shell32.dll")) { - sHCreateItemFromParsingName = - (SHCreateItemFromParsingName) GetProcAddress(shell32, "SHCreateItemFromParsingName"); - setCurrentProcessExplicitAppUserModelID = - (SetCurrentProcessExplicitAppUserModelID) GetProcAddress(shell32, "SetCurrentProcessExplicitAppUserModelID"); + if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) { + if (const HMODULE shell32 = LoadLibraryW(L"shell32.dll")) { + setCurrentProcessExplicitAppUserModelID = + (SetCurrentProcessExplicitAppUserModelID) GetProcAddress(shell32, "SetCurrentProcessExplicitAppUserModelID"); + } } } diff --git a/src/winextras/qwinfunctions_p.h b/src/winextras/qwinfunctions_p.h index 9f00e4c..6ea1598 100644 --- a/src/winextras/qwinfunctions_p.h +++ b/src/winextras/qwinfunctions_p.h @@ -54,74 +54,25 @@ #include <QString> #include <qt_windows.h> #include <uxtheme.h> +#include <dwmapi.h> QT_BEGIN_NAMESPACE -enum qt_DWMWINDOWATTRIBUTE +enum qt_DWMWINDOWATTRIBUTE // Not present in MinGW 4.9 { - qt_DWMWA_NCRENDERING_ENABLED = 1, - qt_DWMWA_NCRENDERING_POLICY, - qt_DWMWA_TRANSITIONS_FORCEDISABLED, - qt_DWMWA_ALLOW_NCPAINT, - qt_DWMWA_CAPTION_BUTTON_BOUNDS, - qt_DWMWA_NONCLIENT_RTL_LAYOUT, - qt_DWMWA_FORCE_ICONIC_REPRESENTATION, - qt_DWMWA_FLIP3D_POLICY, - qt_DWMWA_EXTENDED_FRAME_BOUNDS, - qt_DWMWA_HAS_ICONIC_BITMAP, - qt_DWMWA_DISALLOW_PEEK, - qt_DWMWA_EXCLUDED_FROM_PEEK, - qt_DWMWA_CLOAK, - qt_DWMWA_CLOAKED, - qt_DWMWA_FREEZE_REPRESENTATION, - qt_DWMWA_LAST + qt_DWMWA_DISALLOW_PEEK = 11, + qt_DWMWA_EXCLUDED_FROM_PEEK = 12, }; -enum qt_DWMFLIP3DWINDOWPOLICY { - qt_DWMFLIP3D_DEFAULT, - qt_DWMFLIP3D_EXCLUDEBELOW, - qt_DWMFLIP3D_EXCLUDEABOVE, - qt_DWMFLIP3D_LAST -}; - -#include <pshpack1.h> - -struct qt_DWM_BLURBEHIND { - DWORD dwFlags; - BOOL fEnable; - HRGN hRgnBlur; - BOOL fTransitionOnMaximized; -}; - -#include <poppack.h> - -const int qt_DWM_BB_ENABLE = 0x00000001; -const int qt_DWM_BB_BLURREGION = 0x00000002; -const int qt_DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004; - struct QtDwmApiDll { - typedef HRESULT (STDAPICALLTYPE *DwmGetColorizationColor)(DWORD *, BOOL *); - typedef HRESULT (STDAPICALLTYPE *DwmSetWindowAttribute)(HWND, DWORD, LPCVOID, DWORD); - typedef HRESULT (STDAPICALLTYPE *DwmGetWindowAttribute)(HWND, DWORD, PVOID, DWORD); - typedef HRESULT (STDAPICALLTYPE *DwmExtendFrameIntoClientArea)(HWND, const MARGINS *); - typedef HRESULT (STDAPICALLTYPE *DwmEnableBlurBehindWindow)(HWND, const qt_DWM_BLURBEHIND *); - typedef HRESULT (STDAPICALLTYPE *DwmIsCompositionEnabled)(BOOL *); - typedef HRESULT (STDAPICALLTYPE *DwmEnableComposition)(UINT); - typedef HRESULT (STDAPICALLTYPE *DwmSetIconicThumbnail)(HWND, HBITMAP, DWORD); + typedef HRESULT (STDAPICALLTYPE *DwmSetIconicThumbnail)(HWND, HBITMAP, DWORD); // Windows 7 typedef HRESULT (STDAPICALLTYPE *DwmSetIconicLivePreviewBitmap)(HWND, HBITMAP, POINT *, DWORD); typedef HRESULT (STDAPICALLTYPE *DwmInvalidateIconicBitmaps)(HWND); - QtDwmApiDll() - : dwmGetColorizationColor(0), dwmSetWindowAttribute(0), dwmGetWindowAttribute(0) - , dwmExtendFrameIntoClientArea(0), dwmEnableBlurBehindWindow(0) - , dwmIsCompositionEnabled(0), dwmEnableComposition(0) - , dwmSetIconicThumbnail(0), dwmSetIconicLivePreviewBitmap(0), dwmInvalidateIconicBitmaps(0) - {} - void init() { - if (!dwmSetWindowAttribute && QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) + if (!dwmSetIconicThumbnail) resolve(); } @@ -136,36 +87,24 @@ struct QtDwmApiDll static void setBooleanWindowAttribute(HWND hwnd, DWORD attribute, bool value) { setWindowAttribute<BOOL>(hwnd, attribute, BOOL(value ? TRUE : FALSE)); } - DwmGetColorizationColor dwmGetColorizationColor; - DwmSetWindowAttribute dwmSetWindowAttribute; - DwmGetWindowAttribute dwmGetWindowAttribute; - DwmExtendFrameIntoClientArea dwmExtendFrameIntoClientArea; - DwmEnableBlurBehindWindow dwmEnableBlurBehindWindow; - DwmIsCompositionEnabled dwmIsCompositionEnabled; - DwmEnableComposition dwmEnableComposition; - DwmSetIconicThumbnail dwmSetIconicThumbnail; - DwmSetIconicLivePreviewBitmap dwmSetIconicLivePreviewBitmap; - DwmInvalidateIconicBitmaps dwmInvalidateIconicBitmaps; + DwmSetIconicThumbnail dwmSetIconicThumbnail = nullptr; + DwmSetIconicLivePreviewBitmap dwmSetIconicLivePreviewBitmap = nullptr; + DwmInvalidateIconicBitmaps dwmInvalidateIconicBitmaps = nullptr; }; struct QtShell32Dll - { - typedef HRESULT (STDAPICALLTYPE *SHCreateItemFromParsingName)(PCWSTR, IBindCtx *, REFIID, void **); typedef HRESULT (STDAPICALLTYPE *SetCurrentProcessExplicitAppUserModelID)(PCWSTR); - QtShell32Dll() : sHCreateItemFromParsingName(0), setCurrentProcessExplicitAppUserModelID(0) {} - void init() { - if (!sHCreateItemFromParsingName && QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) + if (!setCurrentProcessExplicitAppUserModelID) resolve(); } void resolve(); - SHCreateItemFromParsingName sHCreateItemFromParsingName; // Vista - SetCurrentProcessExplicitAppUserModelID setCurrentProcessExplicitAppUserModelID; // Windows 7 + SetCurrentProcessExplicitAppUserModelID setCurrentProcessExplicitAppUserModelID = nullptr; // Windows 7 }; extern QtDwmApiDll qtDwmApiDll; @@ -186,19 +125,16 @@ inline wchar_t *qt_qstringToNullTerminated(const QString &src) template <class T> T QtDwmApiDll::windowAttribute(HWND hwnd, DWORD attribute, T defaultValue) { - qtDwmApiDll.init(); - T value = defaultValue; - if (qtDwmApiDll.dwmGetWindowAttribute) - qtDwmApiDll.dwmGetWindowAttribute(hwnd, attribute, &value, sizeof(value)); + T value; + if (FAILED(DwmGetWindowAttribute(hwnd, attribute, &value, sizeof(value)))) + value = defaultValue; return value; } template <class T> void QtDwmApiDll::setWindowAttribute(HWND hwnd, DWORD attribute, T value) { - qtDwmApiDll.init(); - if (qtDwmApiDll.dwmSetWindowAttribute) - qtDwmApiDll.dwmSetWindowAttribute(hwnd, attribute, &value, sizeof(value)); + DwmSetWindowAttribute(hwnd, attribute, &value, sizeof(value)); } QT_END_NAMESPACE diff --git a/src/winextras/qwinjumplist.cpp b/src/winextras/qwinjumplist.cpp index e3f7860..2e1b8ce 100644 --- a/src/winextras/qwinjumplist.cpp +++ b/src/winextras/qwinjumplist.cpp @@ -38,6 +38,17 @@ ** ****************************************************************************/ +#include <QtCore/QtGlobal> + +#ifdef Q_CC_MINGW // MinGW: Enable SHCreateItemFromParsingName() +# if defined(_WIN32_IE) && _WIN32_IE << 0x0700 // _WIN32_IE_IE70 +# undef _WIN32_IE +# endif +# ifndef _WIN32_IE +# define _WIN32_IE 0x0700 +# endif +#endif // Q_CC_MINGW + #include "qwinjumplist.h" #include "qwinjumplist_p.h" #include "qwinjumplistitem.h" @@ -56,6 +67,8 @@ #include "qwinfunctions_p.h" #include "winpropkey_p.h" +#include <shobjidl.h> + QT_BEGIN_NAMESPACE /*! @@ -387,11 +400,8 @@ IShellLinkW *QWinJumpListPrivate::toIShellLink(const QWinJumpListItem *item) IShellItem2 *QWinJumpListPrivate::toIShellItem(const QWinJumpListItem *item) { IShellItem2 *shellitem = 0; - qtShell32Dll.init(); - if (qtShell32Dll.sHCreateItemFromParsingName) { - QScopedArrayPointer<wchar_t> buffer(qt_qstringToNullTerminated(item->filePath())); - qtShell32Dll.sHCreateItemFromParsingName(buffer.data(), 0, qIID_IShellItem2, reinterpret_cast<void **>(&shellitem)); - } + QScopedArrayPointer<wchar_t> buffer(qt_qstringToNullTerminated(item->filePath())); + SHCreateItemFromParsingName(buffer.data(), 0, qIID_IShellItem2, reinterpret_cast<void **>(&shellitem)); return shellitem; } diff --git a/src/winextras/qwinjumplistcategory.cpp b/src/winextras/qwinjumplistcategory.cpp index 57cc8cc..5f53667 100644 --- a/src/winextras/qwinjumplistcategory.cpp +++ b/src/winextras/qwinjumplistcategory.cpp @@ -38,6 +38,17 @@ ** ****************************************************************************/ +#include <QtCore/QtGlobal> + +#ifdef Q_CC_MINGW // MinGW: Include the correct definition of SHARDAPPIDINFOLINK +# if defined(NTDDI_VERSION) && NTDDI_VERSION < 0x06010000 +# undef NTDDI_VERSION +# endif +# ifndef NTDDI_VERSION +# define NTDDI_VERSION 0x06010000 +# endif +#endif // Q_CC_MINGW + #include "qwinjumplistcategory.h" #include "qwinjumplistcategory_p.h" #include "qwinjumplistitem_p.h" @@ -50,10 +61,6 @@ #include <shlobj.h> -#if defined(_MSC_VER) && _MSC_VER < 1600 -# define SHARD_APPIDINFOLINK 0x7L -#endif - QT_BEGIN_NAMESPACE /*! diff --git a/src/winextras/qwinthumbnailtoolbar.cpp b/src/winextras/qwinthumbnailtoolbar.cpp index 0d83ef6..58978f9 100644 --- a/src/winextras/qwinthumbnailtoolbar.cpp +++ b/src/winextras/qwinthumbnailtoolbar.cpp @@ -321,11 +321,9 @@ bool QWinThumbnailToolBar::iconicPixmapNotificationsEnabled() const { Q_D(const QWinThumbnailToolBar); const HWND hwnd = d->handle(); - if (!hwnd || !qtDwmApiDll.dwmGetWindowAttribute) + if (!hwnd) return false; - qtDwmApiDll.init(); - return qtDwmApiDll.dwmGetWindowAttribute && hwnd - && QtDwmApiDll::booleanWindowAttribute(hwnd, dWMWA_FORCE_ICONIC_REPRESENTATION); + return QtDwmApiDll::booleanWindowAttribute(hwnd, dWMWA_FORCE_ICONIC_REPRESENTATION); } void QWinThumbnailToolBar::setIconicPixmapNotificationsEnabled(bool enabled) @@ -336,8 +334,7 @@ void QWinThumbnailToolBar::setIconicPixmapNotificationsEnabled(bool enabled) qWarning() << Q_FUNC_INFO << "invoked with hwnd=0"; return; } - qtDwmApiDll.init(); - if (!qtDwmApiDll.dwmSetWindowAttribute || iconicPixmapNotificationsEnabled() == enabled) + if (iconicPixmapNotificationsEnabled() == enabled) return; QtDwmApiDll::setBooleanWindowAttribute(hwnd, dWMWA_FORCE_ICONIC_REPRESENTATION, enabled); QtDwmApiDll::setBooleanWindowAttribute(hwnd, dWMWA_HAS_ICONIC_BITMAP, enabled); diff --git a/src/winextras/winextras.pro b/src/winextras/winextras.pro index 9968ba8..de4f9c8 100644 --- a/src/winextras/winextras.pro +++ b/src/winextras/winextras.pro @@ -43,8 +43,7 @@ HEADERS += \ QMAKE_DOCS = $$PWD/doc/qtwinextras.qdocconf -DEFINES += NTDDI_VERSION=0x06010000 _WIN32_WINNT=0x0601 -LIBS_PRIVATE += -lole32 -lshlwapi -lshell32 +LIBS_PRIVATE += -lole32 -lshlwapi -lshell32 -ldwmapi win32:!qtHaveModule(opengl)|contains(QT_CONFIG, dynamicgl):LIBS_PRIVATE += -lgdi32 OTHER_FILES += \ |