From 842a0b094befeb6f023782da02e1ee649490091e Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Tue, 24 Apr 2012 14:23:02 +0200 Subject: [PATCH] Make QGtkStyle work on Qt 5. Mostly straightforward porting: Add configure test from Qt 4. Add X11 include to qgtkstyle_p.cpp. Use renamed QGuiApplicationPrivate::showModalWindow. Change-Id: I83020e13ec00b49f3fe346814f881bce19a6f602 Reviewed-by: Friedemann Kleint --- configure | 26 ++++++++++++++++++++++++ src/widgets/styles/qgtkstyle_p.cpp | 32 +++++++++++++++++++++--------- src/widgets/styles/qgtkstyle_p.h | 1 + src/widgets/styles/styles.pri | 2 +- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/configure b/configure index b4b57c608d..38d460f2d7 100755 --- a/configure +++ b/configure @@ -4245,6 +4245,32 @@ if [ "$CFG_GLIB" != "no" ]; then fi fi +# auto-detect GTK style support +if [ "$CFG_GLIB" = "yes" -a "$CFG_QGTKSTYLE" != "no" ]; then + if [ -n "$PKG_CONFIG" ]; then + QT_CFLAGS_QGTKSTYLE=`$PKG_CONFIG --cflags gtk+-2.0 ">=" 2.10 atk 2>/dev/null` + QT_LIBS_QGTKSTYLE=`$PKG_CONFIG --libs gobject-2.0 2>/dev/null` + fi + if [ -n "$QT_CFLAGS_QGTKSTYLE" ] ; then + CFG_QGTKSTYLE=yes + QT_CONFIG="$QT_CONFIG gtkstyle" + QMakeVar set QT_CFLAGS_QGTKSTYLE "$QT_CFLAGS_QGTKSTYLE" + QMakeVar set QT_LIBS_QGTKSTYLE "$QT_LIBS_QGTKSTYLE" + else + if [ "$CFG_QGTKSTYLE" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then + echo "Gtk theme support cannot be enabled due to functionality tests!" + echo " Turn on verbose messaging (-v) to $0 to see the fin al report." + echo " If you believe this message is in error you may use the continue" + echo " switch (-continue) to $0 to continue." + exit 101 + else + CFG_QGTKSTYLE=no + fi + fi +elif [ "$CFG_GLIB" = "no" ]; then + CFG_QGTKSTYLE=no +fi + # ### Vestige if [ "$CFG_GLIB" = "yes" -a "$CFG_GSTREAMER" != "no" ]; then if [ -n "$PKG_CONFIG" ]; then diff --git a/src/widgets/styles/qgtkstyle_p.cpp b/src/widgets/styles/qgtkstyle_p.cpp index 0402859e31..37edf5d786 100644 --- a/src/widgets/styles/qgtkstyle_p.cpp +++ b/src/widgets/styles/qgtkstyle_p.cpp @@ -74,7 +74,21 @@ #include #include -#include +// X11 Includes: + +// the following is necessary to work around breakage in many versions +// of XFree86's Xlib.h still in use +// ### which versions? +#if defined(_XLIB_H_) // crude hack, but... +#error "cannot include before this file" +#endif +#define XRegisterIMInstantiateCallback qt_XRegisterIMInstantiateCallback +#define XUnregisterIMInstantiateCallback qt_XUnregisterIMInstantiateCallback +#define XSetIMValues qt_XSetIMValues +#include +#undef XRegisterIMInstantiateCallback +#undef XUnregisterIMInstantiateCallback +#undef XSetIMValues QT_BEGIN_NAMESPACE @@ -982,7 +996,7 @@ QString QGtkStylePrivate::openFilename(QWidget *parent, const QString &caption, QWidget modal_widget; modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); + QGuiApplicationPrivate::showModalWindow(modal_widget.windowHandle()); QString filename; if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { @@ -995,7 +1009,7 @@ QString QGtkStylePrivate::openFilename(QWidget *parent, const QString &caption, } } - QApplicationPrivate::leaveModal(&modal_widget); + QApplicationPrivate::hideModalWindow(modal_widget.windowHandle()); gtk_widget_destroy (gtkFileChooser); return filename; } @@ -1015,7 +1029,7 @@ QString QGtkStylePrivate::openDirectory(QWidget *parent, const QString &caption, QWidget modal_widget; modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); + QGuiApplicationPrivate::showModalWindow(modal_widget.windowHandle()); QString filename; if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { @@ -1024,7 +1038,7 @@ QString QGtkStylePrivate::openDirectory(QWidget *parent, const QString &caption, g_free (gtk_filename); } - QApplicationPrivate::leaveModal(&modal_widget); + QApplicationPrivate::hideModalWindow(modal_widget.windowHandle()); gtk_widget_destroy (gtkFileChooser); return filename; } @@ -1047,7 +1061,7 @@ QStringList QGtkStylePrivate::openFilenames(QWidget *parent, const QString &capt QWidget modal_widget; modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); + QGuiApplicationPrivate::showModalWindow(modal_widget.windowHandle()); if (gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { GSList *gtk_file_names = QGtkStylePrivate::gtk_file_chooser_get_filenames((GtkFileChooser*)gtkFileChooser); @@ -1060,7 +1074,7 @@ QStringList QGtkStylePrivate::openFilenames(QWidget *parent, const QString &capt } } - QApplicationPrivate::leaveModal(&modal_widget); + QApplicationPrivate::hideModalWindow(modal_widget.windowHandle()); gtk_widget_destroy (gtkFileChooser); return filenames; } @@ -1080,7 +1094,7 @@ QString QGtkStylePrivate::saveFilename(QWidget *parent, const QString &caption, QWidget modal_widget; modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); modal_widget.setParent(parent, Qt::Window); - QApplicationPrivate::enterModal(&modal_widget); + QGuiApplicationPrivate::showModalWindow(modal_widget.windowHandle()); QString filename; if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { @@ -1093,7 +1107,7 @@ QString QGtkStylePrivate::saveFilename(QWidget *parent, const QString &caption, } } - QApplicationPrivate::leaveModal(&modal_widget); + QApplicationPrivate::hideModalWindow(modal_widget.windowHandle()); gtk_widget_destroy (gtkFileChooser); return filename; } diff --git a/src/widgets/styles/qgtkstyle_p.h b/src/widgets/styles/qgtkstyle_p.h index 02d659c1e4..b095820626 100644 --- a/src/widgets/styles/qgtkstyle_p.h +++ b/src/widgets/styles/qgtkstyle_p.h @@ -131,6 +131,7 @@ QT_END_NAMESPACE class GConf; class GConfClient; +typedef struct _XDisplay Display; typedef GConfClient* (*Ptr_gconf_client_get_default)(); typedef char* (*Ptr_gconf_client_get_string)(GConfClient*, const char*, GError **); diff --git a/src/widgets/styles/styles.pri b/src/widgets/styles/styles.pri index 2ae9664230..91212f0178 100644 --- a/src/widgets/styles/styles.pri +++ b/src/widgets/styles/styles.pri @@ -39,7 +39,7 @@ contains( styles, all ) { !macx-*|ios:styles -= mac -x11{ +contains(QT_CONFIG, gtkstyle) { QMAKE_CXXFLAGS += $$QT_CFLAGS_QGTKSTYLE LIBS_PRIVATE += $$QT_LIBS_QGTKSTYLE styles += gtk