Changeset 846 for trunk/src/gui/styles/qgtkstyle_p.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/styles/qgtkstyle_p.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 61 61 #include <QtCore/QUrl> 62 62 #include <QtCore/QLibrary> 63 #include <QtCore/QDebug> 63 64 64 65 #include <private/qapplication_p.h> … … 234 235 } 235 236 236 static Q StringclassPath(GtkWidget *widget)237 { 238 char *class_path;237 static QHashableLatin1Literal classPath(GtkWidget *widget) 238 { 239 char *class_path; 239 240 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 241 250 g_free(class_path); 242 251 243 // Remove the prefixes 244 path.remove(QLS("GtkWindow.")); 245 path.remove(QLS("GtkFixed.")); 246 return path; 252 return QHashableLatin1Literal::fromData(copy); 247 253 } 248 254 … … 262 268 263 269 QList<QGtkStylePrivate *> QGtkStylePrivate::instances; 270 QGtkStylePrivate::WidgetMap *QGtkStylePrivate::widgetMap = 0; 264 271 265 272 QGtkStylePrivate::QGtkStylePrivate() … … 279 286 resolveGtk(); 280 287 initGtkWidgets(); 281 if (isThemeAvailable()) 282 qApp->installEventFilter(&filter); 283 } 284 285 GtkWidget* QGtkStylePrivate::gtkWidget(const QString &path) 288 } 289 290 GtkWidget* QGtkStylePrivate::gtkWidget(const QHashableLatin1Literal &path) 286 291 { 287 292 GtkWidget *widget = gtkWidgetMap()->value(path); … … 293 298 } 294 299 295 GtkStyle* QGtkStylePrivate::gtkStyle(const Q String&path)296 { 297 if ( gtkWidgetMap()->contains(path))298 return gtkWidgetMap()->value(path)->style;300 GtkStyle* QGtkStylePrivate::gtkStyle(const QHashableLatin1Literal &path) 301 { 302 if (GtkWidget *w = gtkWidgetMap()->value(path)) 303 return w->style; 299 304 return 0; 300 305 } … … 495 500 496 501 static QString themeName; 497 if (!gtkWidgetMap()->contains( QLS("GtkWindow")) && themeName.isEmpty()) {502 if (!gtkWidgetMap()->contains("GtkWindow") && themeName.isEmpty()) { 498 503 themeName = getThemeName(); 499 504 … … 520 525 if (displayDepth == -1) 521 526 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); 523 530 524 531 … … 527 534 QGtkStylePrivate::gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); 528 535 529 if (!gtkWidgetMap()->contains( QLS("GtkButton"))) {536 if (!gtkWidgetMap()->contains("GtkButton")) { 530 537 GtkWidget *gtkButton = QGtkStylePrivate::gtk_button_new(); 531 538 addWidget(gtkButton); … … 564 571 // as with the combo box. We need to update the widget map 565 572 // to reflect this; 566 QHash<Q String, GtkWidget*> oldMap = *gtkWidgetMap();573 QHash<QHashableLatin1Literal, GtkWidget*> oldMap = *gtkWidgetMap(); 567 574 gtkWidgetMap()->clear(); 568 QHashIterator<Q String, GtkWidget*> it(oldMap);575 QHashIterator<QHashableLatin1Literal, GtkWidget*> it(oldMap); 569 576 while (it.hasNext()) { 570 577 it.next(); 571 if (! it.key().contains(QLatin1Char('.'))) {578 if (!strchr(it.key().data(), '.')) { 572 579 addAllSubWidgets(it.value()); 573 580 } 581 free(const_cast<char *>(it.key().data())); 574 582 } 575 583 } … … 584 592 void QGtkStylePrivate::cleanupGtkWidgets() 585 593 { 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())); 588 601 } 589 602 … … 676 689 { 677 690 const int MIN_ARROW_WIDTH = 6; 678 GtkWidget *spinButton = gtkWidget( QLS("GtkSpinButton"));691 GtkWidget *spinButton = gtkWidget("GtkSpinButton"); 679 692 GtkStyle *style = spinButton->style; 680 693 gint size = pango_font_description_get_size (style->font_desc); … … 696 709 void QGtkStylePrivate::applyCustomPaletteHash() 697 710 { 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]; 700 713 QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); 701 714 menuPal.setBrush(QPalette::Base, bgColor); … … 703 716 qApp->setPalette(menuPal, "QMenu"); 704 717 705 QPalette toolbarPal = gtkWidgetPalette( QLS("GtkToolbar"));718 QPalette toolbarPal = gtkWidgetPalette("GtkToolbar"); 706 719 qApp->setPalette(toolbarPal, "QToolBar"); 707 720 708 QPalette menuBarPal = gtkWidgetPalette( QLS("GtkMenuBar"));721 QPalette menuBarPal = gtkWidgetPalette("GtkMenuBar"); 709 722 qApp->setPalette(menuBarPal, "QMenuBar"); 710 723 } … … 715 728 GtkWidget* QGtkStylePrivate::getTextColorWidget() const 716 729 { 717 return gtkWidget( QLS("GtkEntry"));730 return gtkWidget("GtkEntry"); 718 731 } 719 732 … … 724 737 if (!protoLayout) { 725 738 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); 727 740 } 728 741 Q_ASSERT(protoLayout); … … 734 747 } 735 748 749 void 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 736 759 void QGtkStylePrivate::addWidgetToMap(GtkWidget *widget) 737 760 { 738 761 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 741 770 } 742 771 } … … 751 780 752 781 // Updates window/windowtext palette based on the indicated gtk widget 753 QPalette QGtkStylePrivate::gtkWidgetPalette(const Q String>kWidgetName) const782 QPalette QGtkStylePrivate::gtkWidgetPalette(const QHashableLatin1Literal >kWidgetName) const 754 783 { 755 784 GtkWidget *gtkWidget = QGtkStylePrivate::gtkWidget(gtkWidgetName); … … 1087 1116 } 1088 1117 1118 bool 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 1124 uint 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 1089 1140 QT_END_NAMESPACE 1090 1141
Note:
See TracChangeset
for help on using the changeset viewer.