4#include <QtCore/qt_windows.h>
11#if QT_CONFIG(systemtrayicon)
18# include <commoncontrols.h>
22#include <QtCore/qvariant.h>
23#include <QtCore/qcoreapplication.h>
24#include <QtCore/qdebug.h>
25#include <QtCore/qsysinfo.h>
26#include <QtCore/qcache.h>
27#include <QtCore/qthread.h>
28#include <QtCore/qmutex.h>
29#include <QtCore/qwaitcondition.h>
30#include <QtGui/qcolor.h>
31#include <QtGui/qpalette.h>
32#include <QtGui/qguiapplication.h>
33#include <QtGui/qpainter.h>
34#include <QtGui/qpixmapcache.h>
35#include <qpa/qwindowsysteminterface.h>
36#include <QtGui/private/qabstractfileiconengine_p.h>
37#include <QtGui/private/qwindowsfontdatabase_p.h>
38#include <private/qhighdpiscaling_p.h>
39#include <private/qsystemlibrary_p.h>
40#include <private/qwinregistry_p.h>
41#include <QtCore/private/qfunctions_win_p.h>
45#if QT_CONFIG(cpp_winrt)
46# include <QtCore/private/qt_winrtbase_p.h>
48# include <winrt/Windows.UI.ViewManagement.h>
51#if defined(__IImageList_INTERFACE_DEFINED__) && defined(__IID_DEFINED__)
52# define USE_IIMAGELIST
62 if (SystemParametersInfo(what, 0, &
result, 0))
70 if (SystemParametersInfo(what, 0, &
result, 0))
77 return {(c1.
red() +
c2.red()) / 2,
79 (c1.
blue() +
c2.blue()) / 2};
84 COLORREF cr = GetSysColor(
index);
85 return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr));
88#if QT_CONFIG(cpp_winrt)
123 QComHelper comHelper(COINIT_MULTITHREADED);
134 const bool result = SHGetFileInfo(
reinterpret_cast<const wchar_t *
>(
fileName.utf16()),
140 memcpy(m_params->
info, &
info,
sizeof(SHFILEINFO));
180 qint64 timeOutMSecs = 5000)
183 if (!getFileInfoThread) {
185 getFileInfoThread->
start();
193 getFileInfoThread->
cancel();
194 getFileInfoThread =
nullptr;
204 QColor backgroundColor(0xd4, 0xd0, 0xc8);
207 const QBrush darkBrush(darkColor);
226 const QWinRegistryKey registry(HKEY_CURRENT_USER, LR
"(Software\Microsoft\Windows\DWM)");
230 if (!
value.isValid())
249#if QT_CONFIG(cpp_winrt)
251 using namespace winrt::Windows::UI::ViewManagement;
258 const QColor accentDarkest = accent.
darker(120 * 120 * 120);
261 const QColor linkColor = accent;
262 const QColor btnFace = background;
295#if QT_CONFIG(cpp_winrt)
296 using namespace winrt::Windows::UI::ViewManagement;
306 systemBackground =
QColor(0x1E, 0x1E, 0x1E);
307 return systemBackground;
328 const QColor linkColor = accent;
390 return systemPalette;
404 const QColor highlightColor =
getSysColor(isFlat ? COLOR_MENUHILIGHT : COLOR_HIGHLIGHT);
446 std::fill(m_fonts, m_fonts +
NFonts,
nullptr);
447 std::fill(m_palettes, m_palettes +
NPalettes,
nullptr);
449 refreshIconPixmapSizes();
456 m_instance =
nullptr;
516 if (scrollLines != DWORD(-1))
517 result = int(scrollLines);
521 return GetSystemMetrics(SM_CXDOUBLECLK);
535void QWindowsTheme::clearPalettes()
538 std::fill(m_palettes, m_palettes +
NPalettes,
nullptr);
541void QWindowsTheme::refreshPalettes()
554#if QT_CONFIG(cpp_winrt)
555 using namespace winrt::Windows::UI::ViewManagement;
563 const QColor accentDarkest = accent.
darker(120 * 120 * 120);
585 qFatal(
"Unknown color scheme");
614void QWindowsTheme::clearFonts()
617 std::fill(m_fonts, m_fonts +
NFonts,
nullptr);
626#ifndef QT_NO_DEBUG_STREAM
632 d <<
"NONCLIENTMETRICS(iMenu=" <<
m.iMenuWidth <<
'x' <<
m.iMenuHeight
633 <<
", lfCaptionFont=";
635 d <<
", lfSmCaptionFont=";
637 d <<
", lfMenuFont=";
639 d <<
", lfMessageFont=";
641 d <<
", lfStatusFont=";
655 NONCLIENTMETRICS ncm;
657 qCDebug(lcQpaWindow) << __FUNCTION__ << ncm;
666 LOGFONT lfIconTitleFont;
667 SystemParametersInfoForDpi(SPI_GETICONTITLELOGFONT,
sizeof(lfIconTitleFont), &lfIconTitleFont, 0, dpi);
701#if QT_CONFIG(systemtrayicon)
716void QWindowsTheme::refreshIconPixmapSizes()
731 qCDebug(lcQpaWindow) << __FUNCTION__ << m_fileIconSizes;
739 if (
const HMODULE hmod = QSystemLibrary::load(L
"shell32")) {
741 static_cast<HICON
>(LoadImage(hmod, MAKEINTRESOURCE(resourceId),
742 IMAGE_ICON,
int(
size.width()),
int(
size.height()), 0));
745 DestroyIcon(iconHandle);
755 SHSTOCKICONID stockId = SIID_INVALID;
757 LPCTSTR iconName =
nullptr;
760 stockId = SIID_DRIVECD;
764 stockId = SIID_DRIVEDVD;
768 stockId = SIID_DRIVENET;
772 stockId = SIID_DRIVEFIXED;
776 stockId = SIID_DRIVE35;
780 stockFlags = SHGSI_LINKOVERLAY;
783 stockId = SIID_DOCNOASSOC;
787 stockFlags = SHGSI_LINKOVERLAY;
791 stockId = SIID_FOLDER;
801 stockFlags = SHGSI_LINKOVERLAY;
804 stockId = SIID_FOLDEROPEN;
808 stockId = SIID_FOLDER;
815 stockId = SIID_RECYCLER;
820 iconName = IDI_INFORMATION;
823 stockId = SIID_WARNING;
824 iconName = IDI_WARNING;
827 stockId = SIID_ERROR;
828 iconName = IDI_ERROR;
832 iconName = IDI_QUESTION;
835 stockId = SIID_SHIELD;
841 if (stockId != SIID_INVALID) {
843 SHSTOCKICONINFO iconInfo;
844 memset(&iconInfo, 0,
sizeof(iconInfo));
845 iconInfo.cbSize =
sizeof(iconInfo);
846 stockFlags |= (pixmapSize.
width() > 16 ? SHGFI_LARGEICON : SHGFI_SMALLICON);
847 if (SHGetStockIconInfo(stockId, SHGFI_ICON | stockFlags, &iconInfo) == S_OK) {
849 DestroyIcon(iconInfo.hIcon);
854 if (resourceId != -1) {
867 HICON iconHandle = LoadIcon(
nullptr, iconName);
869 DestroyIcon(iconHandle);
887 switch (imageListSize) {
903 static_assert(
sizeof(T) <=
sizeof(
void *),
"FakePointers can only go that far.");
915 void operator delete (
void *) {}
925 static const IID iID_IImageList = {0x46eb5926, 0x582e, 0x4017, {0x9f, 0xdf, 0xe8, 0x99, 0x8d, 0xaa, 0x9, 0x50}};
927 IImageList *imageList =
nullptr;
928 HRESULT hr = SHGetImageList(iImageList, iID_IImageList,
reinterpret_cast<void **
>(&imageList));
932 hr = imageList->GetIcon(
info.iIcon, ILD_TRANSPARENT, &hIcon);
937 imageList->Release();
981 QComHelper comHelper;
984 Q_CONSTINIT
static QMutex mx;
985 static int defaultFolderIIcon = -1;
992 const int requestedImageListSize =
1001 if (cacheableDirIcon) {
1003 int iIcon = (useDefaultFolderIcon && defaultFolderIIcon >= 0) ? defaultFolderIIcon
1004 : **dirIconEntryCache.
object(filePath);
1009 dirIconEntryCache.
remove(filePath);
1016 unsigned int flags = SHGFI_ICON |
iconSize | SHGFI_SYSICONINDEX | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX;
1017 DWORD attributes = 0;
1019 if (cacheableDirIcon && useDefaultFolderIcon) {
1020 flags |= SHGFI_USEFILEATTRIBUTES;
1021 attributes |= FILE_ATTRIBUTE_DIRECTORY;
1024 flags |= SHGFI_USEFILEATTRIBUTES;
1025 attributes |= FILE_ATTRIBUTE_NORMAL;
1032 if (cacheableDirIcon) {
1033 if (useDefaultFolderIcon && defaultFolderIIcon < 0)
1034 defaultFolderIIcon =
info.iIcon;
1046 if (requestedImageListSize) {
1054 if (cacheableDirIcon) {
1060 qWarning(
"QWindowsTheme::fileIconPixmap() no icon found");
1063 DestroyIcon(
info.hIcon);
1085 for (
const QWindow *
t : topLevels) {
1086 if (
t->inherits(
"QQuickApplicationWindow"))
1103 const auto setting =
QWinRegistryKey(HKEY_CURRENT_USER, LR
"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)")
1105 return setting.second && setting.first == 0;
1115 qCDebug(lcQpaMenus) << __FUNCTION__;
1121 qCDebug(lcQpaMenus) << __FUNCTION__;
1131 qCDebug(lcQpaMenus) << __FUNCTION__;
1137 qCDebug(lcQpaMenus) << __FUNCTION__;
static FakePointer * create(T thing)
Helper base class for retrieving icons for files for usage by QFileIconProvider and related.
QFileInfo fileInfo() const
QPlatformTheme::IconOptions options() const
static QList< QSize > toSizeList(It i1, It i2)
void storeRelaxed(T newValue) noexcept
T loadRelaxed() const noexcept
const QColor & color() const
Returns the brush color.
bool remove(const Key &key) noexcept(std::is_nothrow_destructible_v< Node >)
T * object(const Key &key) const noexcept
bool insert(const Key &key, T *object, qsizetype cost=1)
The QColor class provides colors based on RGB, HSV or CMYK values.
QColor darker(int f=200) const noexcept
static QColor fromRgb(QRgb rgb) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgb.
int lightness() const noexcept
static QColor fromRgba(QRgb rgba) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgba.
int alpha() const noexcept
Returns the alpha color component of this color.
int red() const noexcept
Returns the red color component of this color.
int blue() const noexcept
Returns the blue color component of this color.
int green() const noexcept
Returns the green color component of this color.
void setAlpha(int alpha)
Sets the alpha of this color to alpha.
QColor lighter(int f=150) const noexcept
bool isValid() const noexcept
Returns true if the color is valid; otherwise returns false.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static QString applicationDirPath()
Returns the directory that contains the application executable.
static QString toNativeSeparators(const QString &pathName)
\inmodule QtCore \reentrant
QString suffix() const
Returns the suffix (extension) of the file.
bool isRoot() const
Returns true if the object points to a directory or to a symbolic link to a directory,...
QString fileName() const
Returns the name of the file, excluding the path.
QString absoluteFilePath() const
Returns an absolute path including the file name.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
int pointSize() const
Returns the point size of the font.
void setStyleHint(StyleHint, StyleStrategy=PreferDefault)
Sets the style hint and strategy to hint and strategy, respectively.
static QWindowList topLevelWindows()
Returns a list of the top-level windows in the application.
static bool desktopSettingsAware()
Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false.
The QIcon class provides scalable icons in different modes and states.
Mode
This enum type describes the mode for which a pixmap is intended to be used.
State
This enum describes the state for which a pixmap is intended to be used.
void unlock() noexcept
Unlocks the mutex.
void lock() noexcept
Locks the mutex.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void deleteLater()
\threadsafe
The QPainter class performs low-level painting on widgets and other paint devices.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
The QPalette class contains color groups for each widget state.
const QBrush & button() const
Returns the button brush of the current color group.
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
const QBrush & buttonText() const
Returns the button text foreground brush of the current color group.
static bool find(const QString &key, QPixmap *pixmap)
Looks for a cached pixmap associated with the given key in the cache.
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
QString key() const override
\variable QIconEngine::ScaledPixmapArgument::size
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
bool runWithParams(QShGetFileInfoParams *params, qint64 timeOutMSecs)
constexpr qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString toUpper() const &
void start(Priority=InheritPriority)
void finished(QPrivateSignal)
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
QPair< DWORD, bool > dwordValue(QStringView subKey) const
QVariant value(QStringView subKey) const
static void handleThemeChange(QWindow *window=nullptr)
DarkModeHandling darkModeHandling() const override
static bool nonClientMetrics(NONCLIENTMETRICS *ncm, unsigned dpi=0)
static QWindowsContext * instance()
QList< QSize > availableSizes(QIcon::Mode=QIcon::Normal, QIcon::State=QIcon::Off) override
QPixmap filePixmap(const QSize &size, QIcon::Mode mode, QIcon::State) override
QWindowsFileIconEngine(const QFileInfo &info, QPlatformTheme::IconOptions opts)
QString cacheKey() const override
static QFont systemDefaultFont()
static QFont LOGFONT_to_QFont(const LOGFONT &lf, int verticalDPI=0)
static void debugFormat(QDebug &d, const LOGFONT &lf)
static QWindowsIntegration * instance()
Windows native system tray icon.
static bool useNativeMenus()
void windowsThemeChanged(QWindow *window)
void showPlatformMenuBar() override
QPlatformMenuBar * createPlatformMenuBar() const override
bool usePlatformNativeDialog(DialogType type) const override
QList< QSize > availableFileIconSizes() const
QPlatformMenuItem * createPlatformMenuItem() const override
Qt::ColorScheme colorScheme() const override
static QPalette systemPalette(Qt::ColorScheme)
QVariant themeHint(ThemeHint) const override
~QWindowsTheme() override
static bool queryHighContrast()
static bool queryDarkMode()
QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions={}) const override
Return an icon for fileInfo, observing iconOptions.
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
static QWindowsTheme * instance()
QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override
QPlatformMenu * createPlatformMenu() const override
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
bool useHelper(QPlatformTheme::DialogType type)
QPlatformDialogHelper * createHelper(QPlatformTheme::DialogType type)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
#define qCDebug(category,...)
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar *const * path
QPixmap qt_pixmapFromWinHICON(HICON icon)
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define SPI_GETMENUANIMATION
#define SPI_GETTOOLTIPANIMATION
#define SPI_GETCOMBOBOXANIMATION
QDebug operator<<(QDebug d, const NONCLIENTMETRICS &m)
static QStringList styleNames()
static bool doUseNativeMenus()
static QPalette toolTipPalette(const QPalette &systemPalette, bool light)
static bool shGetFileInfoBackground(const QString &fileName, DWORD attributes, SHFILEINFO *info, UINT flags, qint64 timeOutMSecs=5000)
static QStringList iconThemeSearchPaths()
static QColor getSysColor(int index)
static QPalette standardPalette()
static QPixmap pixmapFromShellImageList(int iImageList, const SHFILEINFO &info)
static int fileIconSizes[FileIconSizeCount]
static QString dirIconPixmapCacheKey(int iIcon, int iconSize, int imageListSize)
static QColor qt_accentColor()
static void populateLightSystemBasePalette(QPalette &result)
static QColor mixColors(const QColor &c1, const QColor &c2)
static QColor placeHolderColor(QColor textColor)
static DWORD dWordSystemParametersInfo(UINT what, DWORD defaultValue)
static void populateDarkSystemBasePalette(QPalette &result)
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon)
static QPalette menuPalette(const QPalette &systemPalette, bool light)
static QPixmap loadIconFromShell32(int resourceId, QSizeF size)
static QPalette * menuBarPalette(const QPalette &menuPalette, bool light)
static bool booleanSystemParametersInfo(UINT what, bool defaultValue)
QFileInfo info(fileName)
[8]
QSettings settings("MySoft", "Star Runner")
[0]
QShGetFileInfoParams(const QString &fn, DWORD a, SHFILEINFO *i, UINT f, bool *r)