src/gui/styles/qgtkstyle_p.h
changeset 30 5dc02b23752f
parent 19 fcece45ef507
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    54 //
    54 //
    55 
    55 
    56 #include <QtCore/qglobal.h>
    56 #include <QtCore/qglobal.h>
    57 #if !defined(QT_NO_STYLE_GTK)
    57 #if !defined(QT_NO_STYLE_GTK)
    58 
    58 
       
    59 #include <QtCore/qstring.h>
       
    60 #include <QtCore/qstringbuilder.h>
       
    61 #include <QtCore/qcoreapplication.h>
       
    62 
    59 #include <QtGui/QFileDialog>
    63 #include <QtGui/QFileDialog>
    60 
    64 
    61 #include <QtGui/QGtkStyle>
    65 #include <QtGui/QGtkStyle>
    62 #include <private/qcleanlooksstyle_p.h>
    66 #include <private/qcleanlooksstyle_p.h>
    63 
    67 
    69 #undef GTK_OBJECT_FLAGS
    73 #undef GTK_OBJECT_FLAGS
    70 #define GTK_OBJECT_FLAGS(obj)(((GtkObject*)(obj))->flags)
    74 #define GTK_OBJECT_FLAGS(obj)(((GtkObject*)(obj))->flags)
    71 #define Q_GTK_IS_WIDGET(widget) widget && GTK_CHECK_TYPE ((widget), QGtkStylePrivate::gtk_widget_get_type())
    75 #define Q_GTK_IS_WIDGET(widget) widget && GTK_CHECK_TYPE ((widget), QGtkStylePrivate::gtk_widget_get_type())
    72 
    76 
    73 #define QLS(x) QLatin1String(x)
    77 #define QLS(x) QLatin1String(x)
       
    78 
       
    79 QT_BEGIN_NAMESPACE
       
    80 
       
    81 // ### Qt 4.7 - merge with QLatin1Literal
       
    82 class QHashableLatin1Literal
       
    83 {
       
    84 public:
       
    85     int size() const { return m_size; }
       
    86     const char *data() const { return m_data; }
       
    87 
       
    88 #ifdef __SUNPRO_CC
       
    89         QHashableLatin1Literal(const char* str)
       
    90         : m_size(strlen(str)), m_data(str) {}
       
    91 #else
       
    92     template <int N>
       
    93         QHashableLatin1Literal(const char (&str)[N])
       
    94         : m_size(N - 1), m_data(str) {}
       
    95 #endif
       
    96 
       
    97     QHashableLatin1Literal(const QHashableLatin1Literal &other)
       
    98         : m_size(other.m_size), m_data(other.m_data)
       
    99     {}
       
   100 
       
   101     QHashableLatin1Literal &operator=(const QHashableLatin1Literal &other)
       
   102     {
       
   103         if (this == &other)
       
   104             return *this;
       
   105         *const_cast<int *>(&m_size) = other.m_size;
       
   106         *const_cast<char **>(&m_data) = const_cast<char *>(other.m_data);
       
   107         return *this;
       
   108     }
       
   109 
       
   110     QString toString() const { return QString::fromLatin1(m_data, m_size); }
       
   111 
       
   112     static QHashableLatin1Literal fromData(const char *str)
       
   113     {
       
   114         return QHashableLatin1Literal(str, qstrlen(str));
       
   115     }
       
   116 
       
   117 private:
       
   118     QHashableLatin1Literal(const char *str, int length)
       
   119         : m_size(length), m_data(str)
       
   120     {}
       
   121 
       
   122     const int m_size;
       
   123     const char *m_data;
       
   124 };
       
   125 
       
   126 bool operator==(const QHashableLatin1Literal &l1, const QHashableLatin1Literal &l2);
       
   127 inline bool operator!=(const QHashableLatin1Literal &l1, const QHashableLatin1Literal &l2) { return !operator==(l1, l2); }
       
   128 uint qHash(const QHashableLatin1Literal &key);
       
   129 
       
   130 QT_END_NAMESPACE
    74 
   131 
    75 class GConf;
   132 class GConf;
    76 class GConfClient;
   133 class GConfClient;
    77 
   134 
    78 typedef GConfClient* (*Ptr_gconf_client_get_default)();
   135 typedef GConfClient* (*Ptr_gconf_client_get_default)();
   250         const char *file_uri,
   307         const char *file_uri,
   251         const char *custom_icon,
   308         const char *custom_icon,
   252         GnomeIconLookupFlags flags,
   309         GnomeIconLookupFlags flags,
   253         GnomeIconLookupResultFlags *result);
   310         GnomeIconLookupResultFlags *result);
   254 
   311 
   255 
       
   256 class QGtkStylePrivate : public QCleanlooksStylePrivate
   312 class QGtkStylePrivate : public QCleanlooksStylePrivate
   257 {
   313 {
   258     Q_DECLARE_PUBLIC(QGtkStyle)
   314     Q_DECLARE_PUBLIC(QGtkStyle)
   259 public:
   315 public:
   260     QGtkStylePrivate();
   316     QGtkStylePrivate();
   261     ~QGtkStylePrivate();
   317     ~QGtkStylePrivate();
   262 
   318 
   263     QGtkStyleFilter filter;
   319     QGtkStyleFilter filter;
   264 
   320 
   265     static GtkWidget* gtkWidget(const QString &path);
   321     static GtkWidget* gtkWidget(const QHashableLatin1Literal &path);
   266     static GtkStyle* gtkStyle(const QString &path = QLatin1String("GtkWindow"));
   322     static GtkStyle* gtkStyle(const QHashableLatin1Literal &path = QHashableLatin1Literal("GtkWindow"));
   267 
   323 
   268     virtual void resolveGtk() const;
   324     virtual void resolveGtk() const;
   269     virtual void initGtkMenu() const;
   325     virtual void initGtkMenu() const;
   270     virtual void initGtkTreeview() const;
   326     virtual void initGtkTreeview() const;
   271     virtual void initGtkWidgets() const;
   327     virtual void initGtkWidgets() const;
   416     static Ptr_gconf_client_get_bool gconf_client_get_bool;
   472     static Ptr_gconf_client_get_bool gconf_client_get_bool;
   417 
   473 
   418     static Ptr_gnome_icon_lookup_sync gnome_icon_lookup_sync;
   474     static Ptr_gnome_icon_lookup_sync gnome_icon_lookup_sync;
   419     static Ptr_gnome_vfs_init gnome_vfs_init;
   475     static Ptr_gnome_vfs_init gnome_vfs_init;
   420 
   476 
   421     virtual QPalette gtkWidgetPalette(const QString &gtkWidgetName) const;
   477     virtual QPalette gtkWidgetPalette(const QHashableLatin1Literal &gtkWidgetName) const;
   422 
   478 
   423 protected:
   479 protected:
   424     typedef QHash<QString, GtkWidget*> WidgetMap;
   480     typedef QHash<QHashableLatin1Literal, GtkWidget*> WidgetMap;
       
   481 
       
   482     static inline void destroyWidgetMap()
       
   483     {
       
   484         cleanupGtkWidgets();
       
   485         delete widgetMap;
       
   486         widgetMap = 0;
       
   487     }
   425 
   488 
   426     static inline WidgetMap *gtkWidgetMap()
   489     static inline WidgetMap *gtkWidgetMap()
   427     {
   490     {
   428         static WidgetMap *map = 0;
   491         if (!widgetMap) {
   429         if (!map)
   492             widgetMap = new WidgetMap();
   430             map = new WidgetMap();
   493             qAddPostRoutine(destroyWidgetMap);
   431         return map;
   494         }
       
   495         return widgetMap;
   432     }
   496     }
   433 
   497 
   434     static QStringList extract_filter(const QString &rawFilter);
   498     static QStringList extract_filter(const QString &rawFilter);
   435 
   499 
   436     virtual GtkWidget* getTextColorWidget() const;
   500     virtual GtkWidget* getTextColorWidget() const;
   441 
   505 
   442     virtual void init();
   506     virtual void init();
   443 
   507 
   444 private:
   508 private:
   445     static QList<QGtkStylePrivate *> instances;
   509     static QList<QGtkStylePrivate *> instances;
       
   510     static WidgetMap *widgetMap;
   446     friend class QGtkStyleUpdateScheduler;
   511     friend class QGtkStyleUpdateScheduler;
   447 };
   512 };
   448 
   513 
   449 // Helper to ensure that we have polished all our gtk widgets
   514 // Helper to ensure that we have polished all our gtk widgets
   450 // before updating our own palettes
   515 // before updating our own palettes