Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/styles/qgtkstyle_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6161#include <QtCore/QUrl>
    6262#include <QtCore/QLibrary>
     63#include <QtCore/QDebug>
    6364
    6465#include <private/qapplication_p.h>
     
    234235}
    235236
    236 static QString classPath(GtkWidget *widget)
    237 {
    238     char* class_path;
     237static QHashableLatin1Literal classPath(GtkWidget *widget)
     238{
     239    char *class_path;
    239240    QGtkStylePrivate::gtk_widget_path (widget, NULL, &class_path, NULL);
    240     QString path = QLS(class_path);
     241
     242    char *copy = class_path;
     243    if (strncmp(copy, "GtkWindow.", 10) == 0)
     244        copy += 10;
     245    if (strncmp(copy, "GtkFixed.", 9) == 0)
     246        copy += 9;
     247
     248    copy = strdup(copy);
     249
    241250    g_free(class_path);
    242251
    243     // Remove the prefixes
    244     path.remove(QLS("GtkWindow."));
    245     path.remove(QLS("GtkFixed."));
    246     return path;
     252    return QHashableLatin1Literal::fromData(copy);
    247253}
    248254
     
    262268
    263269QList<QGtkStylePrivate *> QGtkStylePrivate::instances;
     270QGtkStylePrivate::WidgetMap *QGtkStylePrivate::widgetMap = 0;
    264271
    265272QGtkStylePrivate::QGtkStylePrivate()
     
    279286    resolveGtk();
    280287    initGtkWidgets();
    281     if (isThemeAvailable())
    282         qApp->installEventFilter(&filter);
    283 }
    284 
    285 GtkWidget* QGtkStylePrivate::gtkWidget(const QString &path)
     288}
     289
     290GtkWidget* QGtkStylePrivate::gtkWidget(const QHashableLatin1Literal &path)
    286291{
    287292    GtkWidget *widget = gtkWidgetMap()->value(path);
     
    293298}
    294299
    295 GtkStyle* QGtkStylePrivate::gtkStyle(const QString &path)
    296 {
    297     if (gtkWidgetMap()->contains(path))
    298         return gtkWidgetMap()->value(path)->style;
     300GtkStyle* QGtkStylePrivate::gtkStyle(const QHashableLatin1Literal &path)
     301{
     302    if (GtkWidget *w = gtkWidgetMap()->value(path))
     303        return w->style;
    299304    return 0;
    300305}
     
    495500
    496501    static QString themeName;
    497     if (!gtkWidgetMap()->contains(QLS("GtkWindow")) && themeName.isEmpty()) {
     502    if (!gtkWidgetMap()->contains("GtkWindow") && themeName.isEmpty()) {
    498503        themeName = getThemeName();
    499504
     
    520525        if (displayDepth == -1)
    521526            displayDepth = QGtkStylePrivate::gdk_drawable_get_depth(gtkWindow->window);
    522         gtkWidgetMap()->insert(QLS("GtkWindow"), gtkWindow);
     527        QHashableLatin1Literal widgetPath = QHashableLatin1Literal::fromData(strdup("GtkWindow"));
     528        removeWidgetFromMap(widgetPath);
     529        gtkWidgetMap()->insert(widgetPath, gtkWindow);
    523530
    524531
     
    527534            QGtkStylePrivate::gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL);
    528535
    529         if (!gtkWidgetMap()->contains(QLS("GtkButton"))) {
     536        if (!gtkWidgetMap()->contains("GtkButton")) {
    530537            GtkWidget *gtkButton = QGtkStylePrivate::gtk_button_new();
    531538            addWidget(gtkButton);
     
    564571            // as with the combo box. We need to update the widget map
    565572            // to reflect this;
    566             QHash<QString, GtkWidget*> oldMap = *gtkWidgetMap();
     573            QHash<QHashableLatin1Literal, GtkWidget*> oldMap = *gtkWidgetMap();
    567574            gtkWidgetMap()->clear();
    568             QHashIterator<QString, GtkWidget*> it(oldMap);
     575            QHashIterator<QHashableLatin1Literal, GtkWidget*> it(oldMap);
    569576            while (it.hasNext()) {
    570577                it.next();
    571                 if (!it.key().contains(QLatin1Char('.'))) {
     578                if (!strchr(it.key().data(), '.')) {
    572579                    addAllSubWidgets(it.value());
    573580                }
     581                free(const_cast<char *>(it.key().data()));
    574582            }
    575583        }
     
    584592void QGtkStylePrivate::cleanupGtkWidgets()
    585593{
    586     if (gtkWidgetMap()->contains(QLS("GtkWindow"))) // Gtk will destroy all children
    587         gtk_widget_destroy(gtkWidgetMap()->value(QLS("GtkWindow")));
     594    if (!widgetMap)
     595        return;
     596    if (widgetMap->contains("GtkWindow")) // Gtk will destroy all children
     597        gtk_widget_destroy(widgetMap->value("GtkWindow"));
     598    for (QHash<QHashableLatin1Literal, GtkWidget *>::const_iterator it = widgetMap->constBegin();
     599         it != widgetMap->constEnd(); ++it)
     600        free(const_cast<char *>(it.key().data()));
    588601}
    589602
     
    676689{
    677690    const int MIN_ARROW_WIDTH = 6;
    678     GtkWidget *spinButton = gtkWidget(QLS("GtkSpinButton"));
     691    GtkWidget *spinButton = gtkWidget("GtkSpinButton");
    679692    GtkStyle *style = spinButton->style;
    680693    gint size = pango_font_description_get_size (style->font_desc);
     
    696709void QGtkStylePrivate::applyCustomPaletteHash()
    697710{
    698     QPalette menuPal = gtkWidgetPalette(QLS("GtkMenu"));
    699     GdkColor gdkBg = gtkWidget(QLS("GtkMenu"))->style->bg[GTK_STATE_NORMAL];
     711    QPalette menuPal = gtkWidgetPalette("GtkMenu");
     712    GdkColor gdkBg = gtkWidget("GtkMenu")->style->bg[GTK_STATE_NORMAL];
    700713    QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
    701714    menuPal.setBrush(QPalette::Base, bgColor);
     
    703716    qApp->setPalette(menuPal, "QMenu");
    704717
    705     QPalette toolbarPal = gtkWidgetPalette(QLS("GtkToolbar"));
     718    QPalette toolbarPal = gtkWidgetPalette("GtkToolbar");
    706719    qApp->setPalette(toolbarPal, "QToolBar");
    707720
    708     QPalette menuBarPal = gtkWidgetPalette(QLS("GtkMenuBar"));
     721    QPalette menuBarPal = gtkWidgetPalette("GtkMenuBar");
    709722    qApp->setPalette(menuBarPal, "QMenuBar");
    710723}
     
    715728GtkWidget* QGtkStylePrivate::getTextColorWidget() const
    716729{
    717     return  gtkWidget(QLS("GtkEntry"));
     730    return  gtkWidget("GtkEntry");
    718731}
    719732
     
    724737        if (!protoLayout) {
    725738            protoLayout = QGtkStylePrivate::gtk_fixed_new();
    726             QGtkStylePrivate::gtk_container_add((GtkContainer*)(gtkWidgetMap()->value(QLS("GtkWindow"))), protoLayout);
     739            QGtkStylePrivate::gtk_container_add((GtkContainer*)(gtkWidgetMap()->value("GtkWindow")), protoLayout);
    727740        }
    728741        Q_ASSERT(protoLayout);
     
    734747}
    735748
     749void QGtkStylePrivate::removeWidgetFromMap(const QHashableLatin1Literal &path)
     750{
     751    WidgetMap *map = gtkWidgetMap();
     752    WidgetMap::iterator it = map->find(path);
     753    if (it != map->end()) {
     754        free(const_cast<char *>(it.key().data()));
     755        map->erase(it);
     756    }
     757}
     758
    736759void QGtkStylePrivate::addWidgetToMap(GtkWidget *widget)
    737760{
    738761    if (Q_GTK_IS_WIDGET(widget)) {
    739        gtk_widget_realize(widget);
    740        gtkWidgetMap()->insert(classPath(widget), widget);
     762        gtk_widget_realize(widget);
     763        QHashableLatin1Literal widgetPath = classPath(widget);
     764
     765        removeWidgetFromMap(widgetPath);
     766        gtkWidgetMap()->insert(widgetPath, widget);
     767#ifdef DUMP_GTK_WIDGET_TREE
     768        qWarning("Inserted Gtk Widget: %s", widgetPath.data());
     769#endif
    741770    }
    742771 }
     
    751780
    752781// Updates window/windowtext palette based on the indicated gtk widget
    753 QPalette QGtkStylePrivate::gtkWidgetPalette(const QString &gtkWidgetName) const
     782QPalette QGtkStylePrivate::gtkWidgetPalette(const QHashableLatin1Literal &gtkWidgetName) const
    754783{
    755784    GtkWidget *gtkWidget = QGtkStylePrivate::gtkWidget(gtkWidgetName);
     
    10871116}
    10881117
     1118bool operator==(const QHashableLatin1Literal &l1, const QHashableLatin1Literal &l2)
     1119{
     1120    return l1.size() == l2.size() || qstrcmp(l1.data(), l2.data()) == 0;
     1121}
     1122
     1123// copied from qHash.cpp
     1124uint qHash(const QHashableLatin1Literal &key)
     1125{
     1126    int n = key.size();
     1127    const uchar *p = reinterpret_cast<const uchar *>(key.data());
     1128    uint h = 0;
     1129    uint g;
     1130
     1131    while (n--) {
     1132        h = (h << 4) + *p++;
     1133        if ((g = (h & 0xf0000000)) != 0)
     1134            h ^= g >> 23;
     1135        h &= ~g;
     1136    }
     1137    return h;
     1138}
     1139
    10891140QT_END_NAMESPACE
    10901141
Note: See TracChangeset for help on using the changeset viewer.