summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-04-22 09:31:58 +0200
committerLiang Qi <liang.qi@qt.io>2016-04-25 14:03:45 +0200
commitbb4b86618dc930e0035c5829e336f2606d140ada (patch)
tree6e36808ca46244373bc70aabbb926cc114538beb /src/widgets/styles
parent276adc5a09914fd89d976bb90cc0cd67de9d3d6e (diff)
parentbbd1228b17ee3f3a5483f88b0a581d6a60c41cad (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: config.tests/unix/compile.test configure src/android/jar/src/org/qtproject/qt5/android/QtMessageDialogHelper.java src/corelib/global/qglobal.cpp src/widgets/kernel/qapplication.cpp src/widgets/styles/qwindowsvistastyle.cpp tests/auto/corelib/kernel/qobject/tst_qobject.cpp Change-Id: I067083f34e5290aa5f7565e40c30a069cc37b83a
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp71
-rw-r--r--src/widgets/styles/qwindowsvistastyle_p_p.h8
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp70
-rw-r--r--src/widgets/styles/qwindowsxpstyle_p_p.h7
4 files changed, 77 insertions, 79 deletions
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index 2b2b919818..a0bc924dd9 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -426,9 +426,9 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
case PE_IndicatorBranch:
{
- XPThemeData theme(widget, painter, QWindowsXPStylePrivate::TreeViewTheme);
+ XPThemeData theme(widget, painter, QWindowsXPStylePrivate::VistaTreeViewTheme);
static int decoration_size = 0;
- if (!decoration_size && d->initTreeViewTheming() && theme.isValid()) {
+ if (!decoration_size && theme.isValid()) {
XPThemeData themeSize = theme;
themeSize.partId = TVP_HOTGLYPH;
themeSize.stateId = GLPS_OPENED;
@@ -728,9 +728,9 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
QPainter pixmapPainter(&pixmap);
XPThemeData theme(widget, &pixmapPainter,
- QWindowsXPStylePrivate::TreeViewTheme,
+ QWindowsXPStylePrivate::VistaTreeViewTheme,
LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
- if (d->initTreeViewTheming() && theme.isValid()) {
+ if (theme.isValid()) {
d->drawBackground(theme);
} else {
QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget);
@@ -2357,10 +2357,6 @@ void QWindowsVistaStyle::unpolish(QWidget *widget)
QWindowsXPStyle::unpolish(widget);
QWindowsVistaStylePrivate *d = d_func();
- // Delete the tree view helper in case the XP style cleaned the
- // theme handle map due to a theme or QStyle change (QProxyStyle).
- if (!QWindowsXPStylePrivate::hasTheme(QWindowsXPStylePrivate::TreeViewTheme))
- d->cleanupTreeViewTheming();
d->stopAnimation(widget);
@@ -2426,15 +2422,10 @@ QPixmap QWindowsVistaStyle::standardPixmap(StandardPixmap standardPixmap, const
}
QWindowsVistaStylePrivate::QWindowsVistaStylePrivate() :
- QWindowsXPStylePrivate(), m_treeViewHelper(0)
+ QWindowsXPStylePrivate()
{
}
-QWindowsVistaStylePrivate::~QWindowsVistaStylePrivate()
-{
- cleanupTreeViewTheming();
-}
-
bool QWindowsVistaStylePrivate::transitionsEnabled() const
{
BOOL animEnabled = false;
@@ -2446,58 +2437,6 @@ bool QWindowsVistaStylePrivate::transitionsEnabled() const
return false;
}
-/*
- * We need to set the windows "explorer" theme explicitly on a native
- * window and open the "TREEVIEW" theme handle passing its window handle
- * in order to get Vista-style item view themes (particulary drawBackground()
- * for selected items needs this).
- * We invoke a service of the native Windows interface to create
- * a non-visible window handle, open the theme on it and insert it into
- * the cache so that it is found by XPThemeData::handle() first.
- */
-
-static inline HWND createTreeViewHelperWindow()
-{
- if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) {
- void *hwnd = 0;
- void *wndProc = reinterpret_cast<void *>(DefWindowProc);
- if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection,
- Q_RETURN_ARG(void *, hwnd),
- Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindowClass")),
- Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindow")),
- Q_ARG(void *, wndProc)) && hwnd) {
- return reinterpret_cast<HWND>(hwnd);
- }
- }
- return 0;
-}
-
-bool QWindowsVistaStylePrivate::initTreeViewTheming()
-{
- if (m_treeViewHelper)
- return true;
-
- m_treeViewHelper = createTreeViewHelperWindow();
- if (Q_UNLIKELY(!m_treeViewHelper)) {
- qWarning("Unable to create the treeview helper window.");
- return false;
- }
- const HRESULT hr = QWindowsXPStylePrivate::pSetWindowTheme(m_treeViewHelper, L"explorer", NULL);
- if (Q_UNLIKELY(hr != S_OK)) {
- qErrnoWarning("SetWindowTheme() failed.");
- return false;
- }
- return QWindowsXPStylePrivate::createTheme(QWindowsXPStylePrivate::TreeViewTheme, m_treeViewHelper);
-}
-
-void QWindowsVistaStylePrivate::cleanupTreeViewTheming()
-{
- if (m_treeViewHelper) {
- DestroyWindow(m_treeViewHelper);
- m_treeViewHelper = 0;
- }
-}
-
/*!
\reimp
*/
diff --git a/src/widgets/styles/qwindowsvistastyle_p_p.h b/src/widgets/styles/qwindowsvistastyle_p_p.h
index 7adfbb08ec..e207a27a66 100644
--- a/src/widgets/styles/qwindowsvistastyle_p_p.h
+++ b/src/widgets/styles/qwindowsvistastyle_p_p.h
@@ -168,16 +168,10 @@ class QWindowsVistaStylePrivate : public QWindowsXPStylePrivate
public:
QWindowsVistaStylePrivate();
- ~QWindowsVistaStylePrivate();
+
static int fixedPixelMetric(QStyle::PixelMetric pm);
static inline bool useVista();
bool transitionsEnabled() const;
-
-private:
- bool initTreeViewTheming();
- void cleanupTreeViewTheming();
-
- HWND m_treeViewHelper;
};
QT_END_NAMESPACE
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index 661c1f7a88..3f38164c01 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -54,6 +54,8 @@
#include <qbackingstore.h>
#include <qapplication.h>
#include <qpixmapcache.h>
+#include <private/qapplication_p.h>
+#include <qpa/qplatformnativeinterface.h>
#include <qdesktopwidget.h>
#include <qtoolbutton.h>
@@ -163,7 +165,7 @@ static const wchar_t *themeNames[QWindowsXPStylePrivate::NThemes] =
L"BUTTON", L"COMBOBOX", L"EDIT", L"HEADER", L"LISTVIEW",
L"MENU", L"PROGRESS", L"REBAR", L"SCROLLBAR", L"SPIN",
L"TAB", L"TASKDIALOG", L"TOOLBAR", L"TOOLTIP", L"TRACKBAR",
- L"TREEVIEW", L"WINDOW", L"STATUS"
+ L"TREEVIEW", L"WINDOW", L"STATUS", L"TREEVIEW"
};
static inline QBackingStore *backingStoreForWidget(const QWidget *widget)
@@ -244,6 +246,7 @@ HRGN XPThemeData::mask(QWidget *widget)
// QWindowsXPStylePrivate -------------------------------------------------------------------------
// Static initializations
QPixmap *QWindowsXPStylePrivate::tabbody = 0;
+HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = 0;
HTHEME QWindowsXPStylePrivate::m_themes[NThemes];
bool QWindowsXPStylePrivate::use_xp = false;
QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting
@@ -327,6 +330,58 @@ void QWindowsXPStylePrivate::cleanup(bool force)
tabbody = 0;
}
+/* In order to obtain the correct VistaTreeViewTheme (arrows for PE_IndicatorBranch),
+ * we need to set the windows "explorer" theme explicitly on a native
+ * window and open the "TREEVIEW" theme handle passing its window handle
+ * in order to get Vista-style item view themes (particulary drawBackground()
+ * for selected items needs this).
+ * We invoke a service of the native Windows interface to create
+ * a non-visible window handle, open the theme on it and insert it into
+ * the cache so that it is found by XPThemeData::handle() first.
+ */
+
+static inline HWND createTreeViewHelperWindow()
+{
+ if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) {
+ void *hwnd = 0;
+ void *wndProc = reinterpret_cast<void *>(DefWindowProc);
+ if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection,
+ Q_RETURN_ARG(void *, hwnd),
+ Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindowClass")),
+ Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindow")),
+ Q_ARG(void *, wndProc)) && hwnd) {
+ return reinterpret_cast<HWND>(hwnd);
+ }
+ }
+ return 0;
+}
+
+bool QWindowsXPStylePrivate::initVistaTreeViewTheming()
+{
+ if (m_vistaTreeViewHelper)
+ return true;
+
+ m_vistaTreeViewHelper = createTreeViewHelperWindow();
+ if (!m_vistaTreeViewHelper) {
+ qWarning("Unable to create the treeview helper window.");
+ return false;
+ }
+ if (FAILED(QWindowsXPStylePrivate::pSetWindowTheme(m_vistaTreeViewHelper, L"explorer", NULL))) {
+ qErrnoWarning("SetWindowTheme() failed.");
+ cleanupVistaTreeViewTheming();
+ return false;
+ }
+ return true;
+}
+
+void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming()
+{
+ if (m_vistaTreeViewHelper) {
+ DestroyWindow(m_vistaTreeViewHelper);
+ m_vistaTreeViewHelper = 0;
+ }
+}
+
/* \internal
Closes all open theme data handles to ensure that we don't leak
resources, and that we don't refere to old handles when for
@@ -339,6 +394,7 @@ void QWindowsXPStylePrivate::cleanupHandleMap()
pCloseThemeData(m_themes[i]);
m_themes[i] = 0;
}
+ QWindowsXPStylePrivate::cleanupVistaTreeViewTheming();
}
HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd)
@@ -349,6 +405,8 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd)
}
if (!m_themes[theme]) {
const wchar_t *name = themeNames[theme];
+ if (theme == VistaTreeViewTheme && QWindowsXPStylePrivate::initVistaTreeViewTheming())
+ hwnd = QWindowsXPStylePrivate::m_vistaTreeViewHelper;
m_themes[theme] = pOpenThemeData(hwnd, name);
if (Q_UNLIKELY(!m_themes[theme]))
qErrnoWarning("OpenThemeData() failed for theme %d (%s).",
@@ -1955,7 +2013,7 @@ case PE_Frame:
bef_v -= delta;
aft_h += delta;
aft_v += delta;
- XPThemeData theme(0, p, QWindowsXPStylePrivate::TreeViewTheme);
+ XPThemeData theme(0, p, QWindowsXPStylePrivate::XpTreeViewTheme);
theme.rect = QRect(bef_h, bef_v, decoration_size, decoration_size);
theme.partId = TVP_GLYPH;
theme.stateId = flags & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED;
@@ -3743,10 +3801,12 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt
{
XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL);
if (buttontheme.isValid()) {
- const QMarginsF borderSize = buttontheme.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const qreal devicePixelRatio = QWindowsXPStylePrivate::devicePixelRatio(widget);
+ const QMarginsF borderSize = buttontheme.margins() / devicePixelRatio;
if (!borderSize.isNull()) {
- sz.rwidth() += qRound(borderSize.left() + borderSize.right() - 2);
- sz.rheight() += qRound(borderSize.bottom() + borderSize.top() - 2);
+ const qreal margin = qreal(2) / devicePixelRatio;
+ sz.rwidth() += qRound(borderSize.left() + borderSize.right() - margin);
+ sz.rheight() += int(borderSize.bottom() + borderSize.top() - margin + devicePixelRatio - 1);
}
const int textMargins = 2*(proxy()->pixelMetric(PM_FocusFrameHMargin) + 1);
sz += QSize(qMax(pixelMetric(QStyle::PM_ScrollBarExtent, option, widget)
diff --git a/src/widgets/styles/qwindowsxpstyle_p_p.h b/src/widgets/styles/qwindowsxpstyle_p_p.h
index 68aa10e12a..8ee4d1a641 100644
--- a/src/widgets/styles/qwindowsxpstyle_p_p.h
+++ b/src/widgets/styles/qwindowsxpstyle_p_p.h
@@ -356,9 +356,10 @@ public:
ToolBarTheme,
ToolTipTheme,
TrackBarTheme,
- TreeViewTheme,
+ XpTreeViewTheme, // '+'/'-' shape treeview indicators (XP)
WindowTheme,
StatusTheme,
+ VistaTreeViewTheme, // arrow shape treeview indicators (Vista) obtained from "explorer" theme.
NThemes
};
@@ -419,6 +420,9 @@ private:
void showProperties(XPThemeData &themeData);
#endif
+ static bool initVistaTreeViewTheming();
+ static void cleanupVistaTreeViewTheming();
+
static QBasicAtomicInt ref;
static bool use_xp;
static QPixmap *tabbody;
@@ -430,6 +434,7 @@ private:
uchar *bufferPixels;
int bufferW, bufferH;
+ static HWND m_vistaTreeViewHelper;
static HTHEME m_themes[NThemes];
};