31bda752c375f2081e319a613b24bed1c2138bf9
[profile/ivi/qtbase.git] / src / widgets / styles / qgtkstyle.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include "qgtkstyle.h"
42
43 #if !defined(QT_NO_STYLE_GTK)
44
45 #include <private/qapplication_p.h>
46 #include <QtCore/QLibrary>
47 #include <QtCore/QSettings>
48 #include <QtWidgets/QDialogButtonBox>
49 #include <QtWidgets/QStatusBar>
50 #include <QtWidgets/QLineEdit>
51 #include <QtWidgets/QWidget>
52 #include <QtWidgets/QListView>
53 #include <QtWidgets/QApplication>
54 #include <QtWidgets/QStyleOption>
55 #include <QtWidgets/QPushButton>
56 #include <QtGui/QPainter>
57 #include <QtWidgets/QMainWindow>
58 #include <QtWidgets/QToolBar>
59 #include <QtWidgets/QHeaderView>
60 #include <QtWidgets/QMenuBar>
61 #include <QtWidgets/QComboBox>
62 #include <QtWidgets/QSpinBox>
63 #include <QtWidgets/QScrollBar>
64 #include <QtWidgets/QAbstractButton>
65 #include <QtWidgets/QToolButton>
66 #include <QtWidgets/QGroupBox>
67 #include <QtWidgets/QRadioButton>
68 #include <QtWidgets/QCheckBox>
69 #include <QtWidgets/QTreeView>
70 #include <QtWidgets/QStyledItemDelegate>
71 #include <QtWidgets/QWizard>
72
73 #include <qpixmapcache.h>
74 #undef signals // Collides with GTK stymbols
75 #include <private/qgtkpainter_p.h>
76 #include <private/qstylehelper_p.h>
77 #include <private/qgtkstyle_p.h>
78
79 QT_BEGIN_NAMESPACE
80
81 static void qt_gtk_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
82 {
83     QColor dark;
84     dark.setHsv(option->palette.button().color().hue(),
85                 qMin(255, (int)(option->palette.button().color().saturation()*1.9)),
86                 qMin(255, (int)(option->palette.button().color().value()*0.7)));
87
88     QColor highlight = option->palette.highlight().color();
89
90     bool active = (option->titleBarState & QStyle::State_Active);
91     QColor titleBarHighlight(255, 255, 255, 60);
92
93     if (sunken)
94         painter->fillRect(tmp.adjusted(1, 1, -1, -1), option->palette.highlight().color().darker(120));
95     else if (hover)
96         painter->fillRect(tmp.adjusted(1, 1, -1, -1), QColor(255, 255, 255, 20));
97
98     QColor mdiButtonGradientStartColor;
99     QColor mdiButtonGradientStopColor;
100
101     mdiButtonGradientStartColor = QColor(0, 0, 0, 40);
102     mdiButtonGradientStopColor = QColor(255, 255, 255, 60);
103
104     if (sunken)
105         titleBarHighlight = highlight.darker(130);
106
107     QLinearGradient gradient(tmp.center().x(), tmp.top(), tmp.center().x(), tmp.bottom());
108     gradient.setColorAt(0, mdiButtonGradientStartColor);
109     gradient.setColorAt(1, mdiButtonGradientStopColor);
110     QColor mdiButtonBorderColor(active ? option->palette.highlight().color().darker(180): dark.darker(110));
111
112     painter->setPen(QPen(mdiButtonBorderColor, 1));
113     const QLine lines[4] = {
114         QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()),
115         QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()),
116         QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2),
117         QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2)
118     };
119     painter->drawLines(lines, 4);
120     const QPoint points[4] = {
121         QPoint(tmp.left() + 1, tmp.top() + 1),
122         QPoint(tmp.right() - 1, tmp.top() + 1),
123         QPoint(tmp.left() + 1, tmp.bottom() - 1),
124         QPoint(tmp.right() - 1, tmp.bottom() - 1)
125     };
126     painter->drawPoints(points, 4);
127
128     painter->setPen(titleBarHighlight);
129     painter->drawLine(tmp.left() + 2, tmp.top() + 1, tmp.right() - 2, tmp.top() + 1);
130     painter->drawLine(tmp.left() + 1, tmp.top() + 2, tmp.left() + 1, tmp.bottom() - 2);
131
132     painter->setPen(QPen(gradient, 1));
133     painter->drawLine(tmp.right() + 1, tmp.top() + 2, tmp.right() + 1, tmp.bottom() - 2);
134     painter->drawPoint(tmp.right() , tmp.top() + 1);
135
136     painter->drawLine(tmp.left() + 2, tmp.bottom() + 1, tmp.right() - 2, tmp.bottom() + 1);
137     painter->drawPoint(tmp.left() + 1, tmp.bottom());
138     painter->drawPoint(tmp.right() - 1, tmp.bottom());
139     painter->drawPoint(tmp.right() , tmp.bottom() - 1);
140 }
141
142 static const char * const dock_widget_close_xpm[] =
143     {
144         "11 13 5 1",
145         "  c None",
146         ". c #D5CFCB",
147         "+ c #6C6A67",
148         "@ c #6C6A67",
149         "$ c #B5B0AC",
150         "           ",
151         " @@@@@@@@@ ",
152         "@+       +@",
153         "@ +@   @+ @",
154         "@ @@@ @@@ @",
155         "@  @@@@@  @",
156         "@   @@@   @",
157         "@  @@@@@  @",
158         "@ @@@ @@@ @",
159         "@ +@   @+ @",
160         "@+       +@",
161         " @@@@@@@@@ ",
162         "           "
163     };
164
165 static const char * const dock_widget_restore_xpm[] =
166     {
167         "11 13 5 1",
168         "  c None",
169         ". c #D5CFCB",
170         "+ c #6C6A67",
171         "@ c #6C6A67",
172         "# c #6C6A67",
173         "           ",
174         " @@@@@@@@@ ",
175         "@+       +@",
176         "@   #@@@# @",
177         "@   @   @ @",
178         "@ #@@@# @ @",
179         "@ @   @ @ @",
180         "@ @   @@@ @",
181         "@ @   @   @",
182         "@ #@@@@   @",
183         "@+       +@",
184         " @@@@@@@@@ ",
185         "           "
186     };
187
188 static const char * const qt_titlebar_context_help[] = {
189     "10 10 3 1",
190     "  c None",
191     "# c #000000",
192     "+ c #444444",
193     "  +####+  ",
194     " ###  ### ",
195     " ##    ## ",
196     "     +##+ ",
197     "    +##   ",
198     "    ##    ",
199     "    ##    ",
200     "          ",
201     "    ##    ",
202     "    ##    "};
203
204 static const char * const qt_scrollbar_button_arrow_up[] = {
205     "7 4 2 1",
206     "   c None",
207     "*  c #BFBFBF",
208     "   *   ",
209     "  ***  ",
210     " ***** ",
211     "*******"};
212
213 static const char * const qt_scrollbar_button_arrow_down[] = {
214     "7 4 2 1",
215     "   c None",
216     "*  c #BFBFBF",
217     "*******",
218     " ***** ",
219     "  ***  ",
220     "   *   "};
221
222 static const int groupBoxBottomMargin    =  2;  // space below the groupbox
223 static const int groupBoxTitleMargin     =  6;  // space between contents and title
224 static const int groupBoxTopMargin       =  2;
225
226 /*!
227   Returns the configuration string for \a value.
228   Returns \a fallback if \a value is not found.
229  */
230 QString QGtkStyle::getGConfString(const QString &value, const QString &fallback)
231 {
232     return QGtkStylePrivate::getGConfString(value, fallback);
233 }
234
235 /*!
236   Returns the configuration boolean for \a key.
237   Returns \a fallback if \a key is not found.
238  */
239 bool QGtkStyle::getGConfBool(const QString &key, bool fallback)
240 {
241     return QGtkStylePrivate::getGConfBool(key, fallback);
242 }
243
244 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
245 {
246     const int maxFactor = 100;
247     QColor tmp = colorA;
248     tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
249     tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
250     tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
251     return tmp;
252 }
253
254 static GdkColor fromQColor(const QColor &color)
255 {
256     GdkColor retval;
257     retval.red = color.red() * 255;
258     retval.green = color.green() * 255;
259     retval.blue = color.blue() * 255;
260     return retval;
261 }
262
263 /*!
264     \class QGtkStyle
265     \brief The QGtkStyle class provides a widget style rendered by GTK+
266     \since 4.5
267
268     \inmodule QtWidgets
269  
270     The QGtkStyle style provides a look and feel that integrates well
271     into GTK-based desktop environments such as the XFCe and GNOME.
272
273     It does this by making use of the GTK+ theme engine, ensuring
274     that Qt applications look and feel native on these platforms.
275
276     Note: The style requires GTK+ version 2.10 or later.
277           The Qt3-based "Qt" GTK+ theme engine will not work with QGtkStyle.
278
279     \sa {Cleanlooks Style Widget Gallery}, QWindowsXPStyle, QMacStyle, QWindowsStyle,
280         QPlastiqueStyle, QCleanlooksStyle
281 */
282
283 /*!
284     Constructs a QGtkStyle object.
285 */
286 QGtkStyle::QGtkStyle()
287     : QWindowsStyle(*new QGtkStylePrivate)
288 {
289     Q_D(QGtkStyle);
290     d->init();
291 }
292
293 /*!
294     \internal
295
296     Constructs a QGtkStyle object.
297 */
298 QGtkStyle::QGtkStyle(QGtkStylePrivate &dd)
299      : QWindowsStyle(dd)
300 {
301     Q_D(QGtkStyle);
302     d->init();
303 }
304
305
306 /*!
307     Destroys the QGtkStyle object.
308 */
309 QGtkStyle::~QGtkStyle()
310 {
311 }
312
313 /*!
314     \reimp
315 */
316 QPalette QGtkStyle::standardPalette() const
317 {
318     Q_D(const QGtkStyle);
319
320     QPalette palette = QWindowsStyle::standardPalette();
321     if (d->isThemeAvailable()) {
322         GtkStyle *style = d->gtkStyle();
323         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
324         GtkWidget *gtkEntry = d->getTextColorWidget();
325         GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg, gdkaSbg, gdkaSfg;
326         QColor bg, base, text, fg, highlight, highlightText, inactiveHighlight, inactiveHighlightedTExt;
327         gdkBg = style->bg[GTK_STATE_NORMAL];
328         gdkForeground = gtkButton->style->fg[GTK_STATE_NORMAL];
329
330         // Our base and selected color is primarily used for text
331         // so we assume a gtkEntry will have the most correct value
332         gdkBase = gtkEntry->style->base[GTK_STATE_NORMAL];
333         gdkText = gtkEntry->style->text[GTK_STATE_NORMAL];
334         gdkSbg = gtkEntry->style->base[GTK_STATE_SELECTED];
335         gdkSfg = gtkEntry->style->text[GTK_STATE_SELECTED];
336
337         // The ACTIVE base color is really used for inactive windows
338         gdkaSbg = gtkEntry->style->base[GTK_STATE_ACTIVE];
339         gdkaSfg = gtkEntry->style->text[GTK_STATE_ACTIVE];
340
341         bg = QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
342         text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
343         fg = QColor(gdkForeground.red>>8, gdkForeground.green>>8, gdkForeground.blue>>8);
344         base = QColor(gdkBase.red>>8, gdkBase.green>>8, gdkBase.blue>>8);
345         highlight = QColor(gdkSbg.red>>8, gdkSbg.green>>8, gdkSbg.blue>>8);
346         highlightText = QColor(gdkSfg.red>>8, gdkSfg.green>>8, gdkSfg.blue>>8);
347         inactiveHighlight = QColor(gdkaSbg.red>>8, gdkaSbg.green>>8, gdkaSbg.blue>>8);
348         inactiveHighlightedTExt = QColor(gdkaSfg.red>>8, gdkaSfg.green>>8, gdkaSfg.blue>>8);
349
350         palette.setColor(QPalette::HighlightedText, highlightText);
351
352
353         palette.setColor(QPalette::Light, bg.lighter(125));
354         palette.setColor(QPalette::Shadow, bg.darker(130));
355         palette.setColor(QPalette::Dark, bg.darker(120));
356         palette.setColor(QPalette::Text, text);
357         palette.setColor(QPalette::WindowText, fg);
358         palette.setColor(QPalette::ButtonText, fg);
359         palette.setColor(QPalette::Base, base);
360
361         QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box
362         GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
363         GdkColor *gtkAltBase = NULL;
364         d->gtk_widget_style_get(gtkTreeView, "odd-row-color", &gtkAltBase, NULL);
365         if (gtkAltBase) {
366             alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8);
367             d->gdk_color_free(gtkAltBase);
368         }
369         palette.setColor(QPalette::AlternateBase, alternateRowColor);
370
371         palette.setColor(QPalette::Window, bg);
372         palette.setColor(QPalette::Button, bg);
373         palette.setColor(QPalette::Background, bg);
374         QColor disabled((fg.red()   + bg.red())  / 2,
375                         (fg.green() + bg.green())/ 2,
376                         (fg.blue()  + bg.blue()) / 2);
377         palette.setColor(QPalette::Disabled, QPalette::Text, disabled);
378         palette.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
379         palette.setColor(QPalette::Disabled, QPalette::Foreground, disabled);
380         palette.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
381         palette.setColor(QPalette::Highlight, highlight);
382         // calculate disabled colors by removing saturation
383         highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha());
384         highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha());
385         palette.setColor(QPalette::Disabled, QPalette::Highlight, highlight);
386         palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText);
387
388         palette.setColor(QPalette::Inactive, QPalette::HighlightedText, inactiveHighlightedTExt);
389         palette.setColor(QPalette::Inactive, QPalette::Highlight, inactiveHighlight);
390
391         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
392                 d->gtk_window_get_type());
393         if (style) {
394             gdkText = style->fg[GTK_STATE_NORMAL];
395             text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
396             palette.setColor(QPalette::ToolTipText, text);
397         }
398     }
399     return palette;
400 }
401
402 /*!
403     \reimp
404 */
405 void QGtkStyle::polish(QPalette &palette)
406 {
407     Q_D(QGtkStyle);
408
409     if (!d->isThemeAvailable())
410         QWindowsStyle::polish(palette);
411     else
412         palette = palette.resolve(standardPalette());
413 }
414
415 /*!
416     \reimp
417 */
418 void QGtkStyle::polish(QApplication *app)
419 {
420     Q_D(QGtkStyle);
421
422     QWindowsStyle::polish(app);
423     // Custom fonts and palettes with QtConfig are intentionally 
424     // not supported as these should be entirely determined by
425     // current Gtk settings
426     if (app->desktopSettingsAware() && d->isThemeAvailable()) {
427         QApplicationPrivate::setSystemPalette(standardPalette());
428         QApplicationPrivate::setSystemFont(d->getThemeFont());
429         d->applyCustomPaletteHash();
430         if (!d->isKDE4Session()) {
431 #ifndef QT_NO_FILEDIALOG
432             qt_filedialog_open_filename_hook = &QGtkStylePrivate::openFilename;
433             qt_filedialog_save_filename_hook = &QGtkStylePrivate::saveFilename;
434             qt_filedialog_open_filenames_hook = &QGtkStylePrivate::openFilenames;
435             qt_filedialog_existing_directory_hook = &QGtkStylePrivate::openDirectory;
436 #endif
437             qApp->installEventFilter(&d->filter);
438         }
439     }
440 }
441
442 /*!
443     \reimp
444 */
445 void QGtkStyle::unpolish(QApplication *app)
446 {
447     Q_D(QGtkStyle);
448
449     QWindowsStyle::unpolish(app);
450     QPixmapCache::clear();
451
452     if (app->desktopSettingsAware() && d->isThemeAvailable()
453         && !d->isKDE4Session()) {
454 #ifndef QT_NO_FILEDIALOG
455         qt_filedialog_open_filename_hook = 0;
456         qt_filedialog_save_filename_hook = 0;
457         qt_filedialog_open_filenames_hook = 0;
458         qt_filedialog_existing_directory_hook = 0;
459 #endif
460         qApp->removeEventFilter(&d->filter);
461     }
462 }
463
464 /*!
465     \reimp
466 */
467
468 void QGtkStyle::polish(QWidget *widget)
469 {
470     Q_D(QGtkStyle);
471
472     QWindowsStyle::polish(widget);
473     if (!d->isThemeAvailable())
474         return;
475     if (qobject_cast<QAbstractButton*>(widget)
476             || qobject_cast<QToolButton*>(widget)
477             || qobject_cast<QComboBox*>(widget)
478             || qobject_cast<QGroupBox*>(widget)
479             || qobject_cast<QScrollBar*>(widget)
480             || qobject_cast<QSlider*>(widget)
481             || qobject_cast<QAbstractSpinBox*>(widget)
482             || qobject_cast<QSpinBox*>(widget)
483             || qobject_cast<QHeaderView*>(widget))
484         widget->setAttribute(Qt::WA_Hover);
485 #ifndef QT_NO_TREEVIEW
486     else if (QTreeView *tree = qobject_cast<QTreeView *> (widget))
487         tree->viewport()->setAttribute(Qt::WA_Hover);
488 #endif
489 }
490
491 /*!
492     \reimp
493 */
494 void QGtkStyle::unpolish(QWidget *widget)
495 {
496     QWindowsStyle::unpolish(widget);
497 }
498
499 /*!
500     \reimp
501 */
502 int QGtkStyle::pixelMetric(PixelMetric metric,
503                            const QStyleOption *option,
504                            const QWidget *widget) const
505 {
506     Q_D(const QGtkStyle);
507
508     if (!d->isThemeAvailable())
509         return QWindowsStyle::pixelMetric(metric, option, widget);
510
511     switch (metric) {
512     case PM_DefaultFrameWidth:
513         if (qobject_cast<const QFrame*>(widget)) {
514             if (GtkStyle *style =
515                 d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
516                                                 "*.GtkScrolledWindow",
517                                                 "*.GtkScrolledWindow",
518                                                 d->gtk_window_get_type()))
519                 return qMax(style->xthickness, style->ythickness);
520         }
521         return 2;
522
523     case PM_MenuButtonIndicator:
524         return 20;
525
526     case PM_TabBarBaseOverlap:
527         return 1;
528
529     case PM_ToolBarSeparatorExtent:
530         return 11;
531
532     case PM_ToolBarFrameWidth:
533         return 1;
534
535     case PM_ToolBarItemSpacing:
536         return 0;
537
538     case PM_ButtonShiftHorizontal: {
539         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
540         guint horizontal_shift;
541         d->gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
542         return horizontal_shift;
543     }
544
545     case PM_ButtonShiftVertical: {
546         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
547         guint vertical_shift;
548         d->gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
549         return vertical_shift;
550     }
551
552     case PM_MenuBarPanelWidth:
553         return 0;
554
555     case PM_MenuPanelWidth: {
556         GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
557         guint horizontal_padding = 0;
558         // horizontal-padding is used by Maemo to get thicker borders
559         if (!d->gtk_check_version(2, 10, 0))
560             d->gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL);
561         int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding);
562         return padding;
563     }
564
565     case PM_ButtonIconSize: {
566         int retVal = 24;
567         GtkSettings *settings = d->gtk_settings_get_default();
568         gchararray icon_sizes;
569         g_object_get(settings, "gtk-icon-sizes", &icon_sizes, NULL);
570         QStringList values = QString(QLS(icon_sizes)).split(QLatin1Char(':'));
571         g_free(icon_sizes);
572         QChar splitChar(QLatin1Char(','));
573         foreach (const QString &value, values) {
574             if (value.startsWith(QLS("gtk-button="))) {
575                 QString iconSize = value.right(value.size() - 11);
576
577                 if (iconSize.contains(splitChar))
578                     retVal = iconSize.split(splitChar)[0].toInt();
579                 break;
580             }
581         }
582         return retVal;
583     }
584
585     case PM_MenuVMargin:
586
587     case PM_MenuHMargin:
588         return 0;
589
590     case PM_DockWidgetTitleMargin:
591         return 0;
592
593     case PM_DockWidgetTitleBarButtonMargin:
594         return 5;
595
596     case PM_TabBarTabVSpace:
597         return 12;
598
599     case PM_TabBarTabHSpace:
600         return 14;
601
602     case PM_TabBarTabShiftVertical:
603         return 2;
604
605     case PM_ToolBarHandleExtent:
606         return 9;
607
608     case PM_SplitterWidth:
609         return 6;
610
611     case PM_SliderThickness:
612     case PM_SliderControlThickness: {
613         GtkWidget *gtkScale = d->gtkWidget("GtkHScale");
614         gint val;
615         d->gtk_widget_style_get(gtkScale, "slider-width", &val, NULL);
616         if (metric == PM_SliderControlThickness)
617             return val + 2*gtkScale->style->ythickness;
618         return val;
619     }
620
621     case PM_ScrollBarExtent: {
622         gint sliderLength;
623         gint trough_border;
624         GtkWidget *hScrollbar = d->gtkWidget("GtkHScrollbar");
625         d->gtk_widget_style_get(hScrollbar,
626                                "trough-border",   &trough_border,
627                                "slider-width",    &sliderLength,
628                                NULL);
629         return sliderLength + trough_border*2;
630     }
631
632     case PM_ScrollBarSliderMin:
633         return 34;
634
635     case PM_SliderLength:
636         gint val;
637         d->gtk_widget_style_get(d->gtkWidget("GtkHScale"), "slider-length", &val, NULL);
638         return val;
639
640     case PM_ExclusiveIndicatorWidth:
641     case PM_ExclusiveIndicatorHeight:
642     case PM_IndicatorWidth:
643     case PM_IndicatorHeight: {
644         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
645         gint size, spacing;
646         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL);
647         return size + 2 * spacing;
648     }
649
650     case PM_MenuBarVMargin: {
651         GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
652         return  qMax(0, gtkMenubar->style->ythickness);
653     }
654     case PM_ScrollView_ScrollBarSpacing:
655     {
656         gint spacing = 3;
657         GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
658         Q_ASSERT(gtkScrollWindow);
659         d->gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL);
660         return spacing;
661     }
662     case PM_SubMenuOverlap: {
663         gint offset = 0;
664         GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
665         d->gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL);
666         return offset;
667     }
668     case PM_ToolTipLabelFrameWidth:
669         return 2;
670     case PM_ButtonDefaultIndicator:
671         return 0;
672     case PM_ListViewIconSize:
673         return 24;
674     case PM_DialogButtonsSeparator:
675         return 6;
676     case PM_TitleBarHeight:
677         return 24;
678     case PM_SpinBoxFrameWidth:
679         return 3;
680     case PM_MenuBarItemSpacing:
681         return 6;
682     case PM_MenuBarHMargin:
683         return 0;
684     case PM_ToolBarItemMargin:
685         return 1;
686     case PM_SmallIconSize:
687         return 16;
688     case PM_MaximumDragDistance:
689         return -1;
690     case PM_TabCloseIndicatorWidth:
691     case PM_TabCloseIndicatorHeight:
692         return 20;
693     default:
694         return QWindowsStyle::pixelMetric(metric, option, widget);
695     }
696 }
697
698 /*!
699     \reimp
700 */
701 int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
702
703                          QStyleHintReturn *returnData = 0) const
704 {
705     Q_D(const QGtkStyle);
706
707     if (!d->isThemeAvailable())
708         return QWindowsStyle::styleHint(hint, option, widget, returnData);
709
710     switch (hint) {
711     case SH_ScrollBar_MiddleClickAbsolutePosition:
712         return true;
713     case SH_Menu_AllowActiveAndDisabled:
714         return false;
715     case SH_MainWindow_SpaceBelowMenuBar:
716         return 0;
717     case SH_MenuBar_MouseTracking:
718         return true;
719     case SH_TitleBar_AutoRaise:
720         return true;
721     case SH_TitleBar_NoBorder:
722         return true;
723     case SH_ItemView_ShowDecorationSelected:
724         return true;
725     case SH_Table_GridLineColor:
726         if (option)
727             return option->palette.background().color().darker(120).rgb();
728         break;
729     case SH_WindowFrame_Mask:
730         if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData)) {
731             //left rounded corner
732             mask->region = option->rect;
733             mask->region -= QRect(option->rect.left(), option->rect.top(), 5, 1);
734             mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 3, 1);
735             mask->region -= QRect(option->rect.left(), option->rect.top() + 2, 2, 1);
736             mask->region -= QRect(option->rect.left(), option->rect.top() + 3, 1, 2);
737
738             //right rounded corner
739             mask->region -= QRect(option->rect.right() - 4, option->rect.top(), 5, 1);
740             mask->region -= QRect(option->rect.right() - 2, option->rect.top() + 1, 3, 1);
741             mask->region -= QRect(option->rect.right() - 1, option->rect.top() + 2, 2, 1);
742             mask->region -= QRect(option->rect.right() , option->rect.top() + 3, 1, 2);
743         }
744         return QWindowsStyle::styleHint(hint, option, widget, returnData);
745     case SH_MessageBox_TextInteractionFlags:
746         return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
747     case SH_MessageBox_CenterButtons:
748         return false;
749     case SH_WizardStyle:
750         return  QWizard::ClassicStyle;
751     case SH_ItemView_ArrowKeysNavigateIntoChildren:
752         return false;
753     case SH_DialogButtonLayout: {
754         int ret = QDialogButtonBox::GnomeLayout;
755         gboolean alternateOrder = 0;
756         GtkSettings *settings = d->gtk_settings_get_default();
757         g_object_get(settings, "gtk-alternative-button-order", &alternateOrder, NULL);
758
759         if (alternateOrder)
760             ret = QDialogButtonBox::WinLayout;
761
762         return ret;
763     }
764     break;
765
766     case SH_ToolButtonStyle:
767     {
768         if (d->isKDE4Session())
769             return QWindowsStyle::styleHint(hint, option, widget, returnData);
770         GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
771         GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
772         g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
773         switch (toolbar_style) {
774         case GTK_TOOLBAR_TEXT:
775             return Qt::ToolButtonTextOnly;
776         case GTK_TOOLBAR_BOTH:
777             return Qt::ToolButtonTextUnderIcon;
778         case GTK_TOOLBAR_BOTH_HORIZ:
779             return Qt::ToolButtonTextBesideIcon;
780         case GTK_TOOLBAR_ICONS:
781         default:
782             return Qt::ToolButtonIconOnly;
783         }
784     }
785     break;
786     case SH_SpinControls_DisableOnBounds:
787         return int(true);
788
789     case SH_DitherDisabledText:
790         return int(false);
791
792     case SH_ComboBox_Popup: {
793         GtkWidget *gtkComboBox = d->gtkWidget("GtkComboBox");
794         gboolean appears_as_list;
795         d->gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL);
796         return appears_as_list ? 0 : 1;
797     }
798
799     case SH_MenuBar_AltKeyNavigation:
800         return int(false);
801
802     case SH_EtchDisabledText:
803         return int(false);
804
805     case SH_Menu_SubMenuPopupDelay: {
806         gint delay = 225;
807         GtkSettings *settings = d->gtk_settings_get_default();
808         g_object_get(settings, "gtk-menu-popup-delay", &delay, NULL);
809         return delay;
810     }
811
812     case SH_ScrollView_FrameOnlyAroundContents: {
813         gboolean scrollbars_within_bevel = false;
814         if (widget && widget->isWindow())
815             scrollbars_within_bevel = true;
816         else if (!d->gtk_check_version(2, 12, 0)) {
817             GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
818             d->gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
819         }
820         return !scrollbars_within_bevel;
821     }
822
823     case SH_DialogButtonBox_ButtonsHaveIcons: {
824         static bool buttonsHaveIcons = d->getGConfBool(QLS("/desktop/gnome/interface/buttons_have_icons"));
825         return buttonsHaveIcons;
826     }
827
828     case SH_UnderlineShortcut: {
829         gboolean underlineShortcut = true;
830         if (!d->gtk_check_version(2, 12, 0)) {
831             GtkSettings *settings = d->gtk_settings_get_default();
832             g_object_get(settings, "gtk-enable-mnemonics", &underlineShortcut, NULL);
833         }
834         return underlineShortcut;
835     }
836
837     default:
838         break;
839     }
840     return QWindowsStyle::styleHint(hint, option, widget, returnData);
841 }
842
843 /*!
844     \reimp
845 */
846 void QGtkStyle::drawPrimitive(PrimitiveElement element,
847                               const QStyleOption *option,
848                               QPainter *painter,
849                               const QWidget *widget) const
850 {
851     Q_D(const QGtkStyle);
852
853     if (!d->isThemeAvailable()) {
854         QWindowsStyle::drawPrimitive(element, option, painter, widget);
855         return;
856     }
857
858     GtkStyle* style = d->gtkStyle();
859     QGtkPainter gtkPainter(painter);
860
861     switch (element) {
862       case PE_Frame: {
863         if (widget && widget->inherits("QComboBoxPrivateContainer")){
864             QStyleOption copy = *option;
865             copy.state |= State_Raised;
866             proxy()->drawPrimitive(PE_PanelMenu, &copy, painter, widget);
867             break;
868         }
869         // Drawing the entire itemview frame is very expensive, especially on the native X11 engine
870         // Instead we cheat a bit and draw a border image without the center part, hence only scaling
871         // thin rectangular images
872         const int pmSize = 64;
873         const int border = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
874         const QString pmKey = QLatin1String("windowframe") % HexString<uint>(option->state);
875
876         QPixmap pixmap;
877         QRect pmRect(QPoint(0,0), QSize(pmSize, pmSize));
878
879         // Only draw through style once
880         if (!QPixmapCache::find(pmKey, pixmap)) {
881             pixmap = QPixmap(pmSize, pmSize);
882             pixmap.fill(Qt::transparent);
883             QPainter pmPainter(&pixmap);
884             QGtkPainter gtkFramePainter(&pmPainter);
885             gtkFramePainter.setUsePixmapCache(false); // Don't cache twice
886
887             GtkShadowType shadow_type = GTK_SHADOW_NONE;
888             if (option->state & State_Sunken)
889                 shadow_type = GTK_SHADOW_IN;
890             else if (option->state & State_Raised)
891                 shadow_type = GTK_SHADOW_OUT;
892
893             GtkStyle *style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
894                                      "*.GtkScrolledWindow", "*.GtkScrolledWindow", d->gtk_window_get_type());
895             if (style)
896                 gtkFramePainter.paintShadow(d->gtkWidget("GtkFrame"), "viewport", pmRect,
897                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
898                                          shadow_type, style);
899             QPixmapCache::insert(pmKey, pixmap);
900         }
901
902         QRect rect = option->rect;
903         const int rw = rect.width() - border;
904         const int rh = rect.height() - border;
905         const int pw = pmRect.width() - border;
906         const int ph = pmRect.height() - border;
907
908         // Sidelines
909         painter->drawPixmap(rect.adjusted(border, 0, -border, -rh), pixmap, pmRect.adjusted(border, 0, -border,-ph));
910         painter->drawPixmap(rect.adjusted(border, rh, -border, 0), pixmap, pmRect.adjusted(border, ph,-border,0));
911         painter->drawPixmap(rect.adjusted(0, border, -rw, -border), pixmap, pmRect.adjusted(0, border, -pw, -border));
912         painter->drawPixmap(rect.adjusted(rw, border, 0, -border), pixmap, pmRect.adjusted(pw, border, 0, -border));
913
914         // Corners
915         painter->drawPixmap(rect.adjusted(0, 0, -rw, -rh), pixmap, pmRect.adjusted(0, 0, -pw,-ph));
916         painter->drawPixmap(rect.adjusted(rw, 0, 0, -rh), pixmap, pmRect.adjusted(pw, 0, 0,-ph));
917         painter->drawPixmap(rect.adjusted(0, rh, -rw, 0), pixmap, pmRect.adjusted(0, ph, -pw,0));
918         painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0));
919     }
920     break;
921     case PE_FrameWindow:
922         painter->save();
923         {
924             QRect rect= option->rect;
925             painter->setPen(QPen(option->palette.dark().color().darker(150), 0));
926             painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
927             painter->setPen(QPen(option->palette.light(), 0));
928             painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
929                               QPoint(rect.left() + 1, rect.bottom() - 1));
930             painter->setPen(QPen(option->palette.background().color().darker(120), 0));
931             painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1),
932                               QPoint(rect.right() - 2, rect.bottom() - 1));
933             painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1),
934                               QPoint(rect.right() - 1, rect.bottom() - 1));
935         }
936         painter->restore();
937         break;
938
939     case PE_PanelTipLabel: {
940         GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
941         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
942                 d->gtk_window_get_type());
943         gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style);
944     }
945     break;
946
947     case PE_PanelStatusBar: {
948         if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
949             option->palette.resolve() & (1 << QPalette::Window)) {
950             // Respect custom palette
951             painter->fillRect(option->rect, option->palette.window());
952             break;
953         }
954         GtkShadowType shadow_type;
955         GtkWidget *gtkStatusbarFrame = d->gtkWidget("GtkStatusbar.GtkFrame");
956         d->gtk_widget_style_get(d->gtk_widget_get_parent(gtkStatusbarFrame), "shadow-type", &shadow_type, NULL);
957         gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL,
958                                shadow_type, gtkStatusbarFrame->style);
959     }
960     break;
961
962     case PE_IndicatorHeaderArrow:
963         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
964             GtkWidget *gtkTreeHeader = d->gtkWidget("GtkTreeView.GtkButton");
965             GtkStateType state = gtkPainter.gtkState(option);
966             style = gtkTreeHeader->style;
967             GtkArrowType type = GTK_ARROW_UP;
968             // This sorting indicator inversion is intentional, and follows the GNOME HIG.
969             // See http://library.gnome.org/devel/hig-book/stable/controls-lists.html.en#controls-lists-sortable
970             if (header->sortIndicator & QStyleOptionHeader::SortUp)
971                 type = GTK_ARROW_UP;
972             else if (header->sortIndicator & QStyleOptionHeader::SortDown)
973                 type = GTK_ARROW_DOWN;
974
975             gtkPainter.paintArrow(gtkTreeHeader, "button", option->rect.adjusted(1, 1, -1, -1), type, state,
976                                   GTK_SHADOW_NONE, false, style);
977         }
978         break;
979
980     case PE_FrameDefaultButton: // fall through
981     case PE_FrameFocusRect:
982         if ((widget && qobject_cast<const QAbstractItemView*>(widget))) {
983             if (option->state & State_KeyboardFocusChange)
984                 QWindowsStyle::drawPrimitive(element, option, painter, widget);
985         } else {
986             // ### this mess should move to subcontrolrect
987             QRect frameRect = option->rect.adjusted(1, 1, -2, -2);
988             if ( qobject_cast<const QTabBar*>(widget)) {
989                 GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
990                 style = gtkPainter.getStyle(gtkNotebook);
991                 gtkPainter.paintFocus(gtkNotebook, "tab", frameRect.adjusted(-1, 1, 1, 1), GTK_STATE_ACTIVE, style);
992             } else {
993                 GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
994                 gtkPainter.paintFocus(gtkRadioButton, "radiobutton", frameRect, GTK_STATE_ACTIVE, style);
995             }
996         }
997         break;
998
999     case PE_IndicatorBranch:
1000         if (option->state & State_Children) {
1001             QRect rect = option->rect;
1002             rect = QRect(0, 0, 12, 12);
1003             rect.moveCenter(option->rect.center());
1004             rect.translate(2, 0);
1005             GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED;
1006             GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED;
1007             GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
1008
1009             GtkStateType state = GTK_STATE_NORMAL;
1010             if (!(option->state & State_Enabled))
1011                 state = GTK_STATE_INSENSITIVE;
1012             else if (option->state & State_MouseOver)
1013                 state = GTK_STATE_PRELIGHT;
1014
1015             gtkPainter.paintExpander(gtkTreeView, "treeview", rect, state,
1016                                      option->state & State_Open ? openState : closedState , gtkTreeView->style);
1017         }
1018         break;
1019
1020     case PE_PanelItemViewRow:
1021         // This primitive is only used to draw selection behind selected expander arrows.
1022         // We try not to decorate the tree branch background unless you inherit from StyledItemDelegate
1023         // The reason for this is that a lot of code that relies on custom item delegates will look odd having
1024         // a gradient on the branch but a flat shaded color on the item itself.
1025         QCommonStyle::drawPrimitive(element, option, painter, widget);
1026         if (!option->state & State_Selected) {
1027             break;
1028         } else {
1029             if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(widget)) {
1030                 if (!qobject_cast<QStyledItemDelegate*>(view->itemDelegate()))
1031                     break;
1032             }
1033         } // fall through
1034
1035     case PE_PanelItemViewItem:
1036         if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) {
1037             uint resolve_mask = vopt->palette.resolve();
1038             if (vopt->backgroundBrush.style() != Qt::NoBrush
1039                     || (resolve_mask & (1 << QPalette::Base)))
1040             {
1041                 QPointF oldBO = painter->brushOrigin();
1042                 painter->setBrushOrigin(vopt->rect.topLeft());
1043                 painter->fillRect(vopt->rect, vopt->backgroundBrush);
1044                 painter->setBrushOrigin(oldBO);
1045                 if (!(option->state & State_Selected))
1046                     break;
1047             }
1048             if (GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView")) {
1049                 const char *detail = "cell_even_ruled";
1050                 if (vopt && vopt->features & QStyleOptionViewItem::Alternate)
1051                     detail = "cell_odd_ruled";
1052                 bool isActive = option->state & State_Active;
1053                 QString key;
1054                 if (isActive ) {
1055                     // Required for active/non-active window appearance
1056                     key = QLS("a");
1057                     GTK_WIDGET_SET_FLAGS(gtkTreeView, GTK_HAS_FOCUS);
1058                 }
1059                 bool isEnabled = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled));
1060                 gtkPainter.paintFlatBox(gtkTreeView, detail, option->rect,
1061                                         option->state & State_Selected ? GTK_STATE_SELECTED :
1062                                         isEnabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
1063                                         GTK_SHADOW_OUT, gtkTreeView->style, key);
1064                 if (isActive )
1065                     GTK_WIDGET_UNSET_FLAGS(gtkTreeView, GTK_HAS_FOCUS);
1066             }
1067         }
1068         break;
1069     case PE_IndicatorToolBarSeparator:
1070         {
1071             const int margin = 6;
1072             GtkWidget *gtkSeparator = d->gtkWidget("GtkToolbar.GtkSeparatorToolItem");
1073             if (option->state & State_Horizontal) {
1074                 const int offset = option->rect.width()/2;
1075                 QRect rect = option->rect.adjusted(offset, margin, 0, -margin);
1076                 painter->setPen(QPen(option->palette.background().color().darker(110)));
1077                 gtkPainter.paintVline( gtkSeparator, "vseparator",
1078                                        rect, GTK_STATE_NORMAL, gtkSeparator->style,
1079                                        0, rect.height(), 0);
1080             } else { //Draw vertical separator
1081                 const int offset = option->rect.height()/2;
1082                 QRect rect = option->rect.adjusted(margin, offset, -margin, 0);
1083                 painter->setPen(QPen(option->palette.background().color().darker(110)));
1084                 gtkPainter.paintHline( gtkSeparator, "hseparator",
1085                                        rect, GTK_STATE_NORMAL, gtkSeparator->style,
1086                                        0, rect.width(), 0);
1087             }
1088        }
1089        break;
1090
1091     case PE_IndicatorToolBarHandle: {
1092         GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
1093         GtkShadowType shadow_type;
1094         d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
1095         //Note when the toolbar is horizontal, the handle is vertical
1096         painter->setClipRect(option->rect);
1097         gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1),
1098                                GTK_STATE_NORMAL, shadow_type, !(option->state & State_Horizontal) ?
1099                                GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, gtkToolbar->style);
1100     }
1101     break;
1102
1103     case PE_IndicatorArrowUp:
1104     case PE_IndicatorArrowDown:
1105     case PE_IndicatorArrowLeft:
1106     case PE_IndicatorArrowRight: {
1107
1108
1109         GtkArrowType type = GTK_ARROW_UP;
1110
1111         switch (element) {
1112
1113         case PE_IndicatorArrowDown:
1114             type = GTK_ARROW_DOWN;
1115             break;
1116
1117         case PE_IndicatorArrowLeft:
1118             type = GTK_ARROW_LEFT;
1119             break;
1120
1121         case PE_IndicatorArrowRight:
1122             type = GTK_ARROW_RIGHT;
1123             break;
1124
1125         default:
1126             break;
1127         }
1128         int size = qMin(option->rect.height(), option->rect.width());
1129         int border = (size > 9) ? (size/4) : 0; //Allow small arrows to have exact dimensions
1130         int bsx = 0, bsy = 0;
1131         if (option->state & State_Sunken) {
1132             bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal);
1133             bsy = proxy()->pixelMetric(PM_ButtonShiftVertical);
1134         }
1135         QRect arrowRect = option->rect.adjusted(border + bsx, border + bsy, -border + bsx, -border + bsy);
1136         GtkShadowType shadow = option->state & State_Sunken ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
1137         GtkStateType state = gtkPainter.gtkState(option);
1138
1139         QColor arrowColor = option->palette.buttonText().color();
1140         GtkWidget *gtkArrow = d->gtkWidget("GtkArrow");
1141         GdkColor color = fromQColor(arrowColor);
1142         d->gtk_widget_modify_fg (gtkArrow, state, &color);
1143         gtkPainter.paintArrow(gtkArrow, "button", arrowRect,
1144                               type, state, shadow, false, gtkArrow->style,
1145                               QString::number(arrowColor.rgba(), 16));
1146         // Passing NULL will revert the color change
1147         d->gtk_widget_modify_fg (gtkArrow, state, NULL);
1148     }
1149     break;
1150
1151     case PE_FrameGroupBox:
1152         // Do nothing here, the GNOME groupboxes are flat
1153         break;
1154
1155     case PE_PanelMenu: {
1156             GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
1157             gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons
1158             gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString());
1159         }
1160         break;
1161
1162     case PE_FrameMenu:
1163         //This is actually done by PE_Widget due to a clipping issue
1164         //Otherwise Menu items will not be able to span the entire menu width
1165
1166         // This is only used by floating tool bars
1167         if (qobject_cast<const QToolBar *>(widget)) {
1168             GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
1169             gtkPainter.paintBox( gtkMenubar, "toolbar",  option->rect,
1170                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
1171             gtkPainter.paintBox( gtkMenubar, "menu",  option->rect,
1172                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
1173         }
1174         break;
1175
1176     case PE_FrameLineEdit: {
1177         GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
1178
1179
1180         gboolean interior_focus;
1181         gint focus_line_width;
1182         QRect rect = option->rect;
1183         d->gtk_widget_style_get(gtkEntry,
1184                                "interior-focus", &interior_focus,
1185                                "focus-line-width", &focus_line_width, NULL);
1186
1187         // See https://bugzilla.mozilla.org/show_bug.cgi?id=405421 for info about this hack
1188         g_object_set_data(G_OBJECT(gtkEntry), "transparent-bg-hint", GINT_TO_POINTER(true));
1189
1190         if (!interior_focus && option->state & State_HasFocus)
1191             rect.adjust(focus_line_width, focus_line_width, -focus_line_width, -focus_line_width);
1192
1193         if (option->state & State_HasFocus)
1194             GTK_WIDGET_SET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1195         gtkPainter.paintShadow(gtkEntry, "entry", rect, option->state & State_Enabled ? 
1196                                GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, 
1197                                GTK_SHADOW_IN, gtkEntry->style,
1198                                option->state & State_HasFocus ? QLS("focus") : QString());
1199         if (!interior_focus && option->state & State_HasFocus)
1200             gtkPainter.paintShadow(gtkEntry, "entry", option->rect, option->state & State_Enabled ? 
1201                                    GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1202                                    GTK_SHADOW_IN, gtkEntry->style, QLS("GtkEntryShadowIn"));
1203
1204         if (option->state & State_HasFocus)
1205             GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1206     }
1207     break;
1208
1209     case PE_PanelLineEdit:
1210         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1211             GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
1212             if (panel->lineWidth > 0)
1213                 proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
1214             uint resolve_mask = option->palette.resolve();
1215             QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
1216                                                    -gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
1217
1218             if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
1219                 resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
1220                 painter->fillRect(textRect, option->palette.base());
1221             else
1222                 gtkPainter.paintFlatBox( gtkEntry, "entry_bg", textRect,
1223                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, gtkEntry->style);
1224         }
1225         break;
1226
1227     case PE_FrameTabWidget:
1228         if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) {
1229             GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
1230             style = gtkPainter.getStyle(gtkNotebook);
1231             gtkPainter.setAlphaSupport(false);
1232             GtkShadowType shadow = GTK_SHADOW_OUT;
1233             GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook
1234             bool reverse = (option->direction == Qt::RightToLeft);
1235             QGtkStylePrivate::gtk_widget_set_direction(gtkNotebook, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1236             if (const QStyleOptionTabWidgetFrameV2 *tabframe = qstyleoption_cast<const QStyleOptionTabWidgetFrameV2*>(option)) {
1237                 GtkPositionType frameType = GTK_POS_TOP;
1238                 QTabBar::Shape shape = frame->shape;
1239                 int gapStart = 0;
1240                 int gapSize = 0;
1241                 if (shape == QTabBar::RoundedNorth || shape == QTabBar::RoundedSouth) {
1242                     frameType = (shape == QTabBar::RoundedNorth) ? GTK_POS_TOP : GTK_POS_BOTTOM;
1243                     gapStart = tabframe->selectedTabRect.left();
1244                     gapSize = tabframe->selectedTabRect.width();
1245                 } else {
1246                     frameType = (shape == QTabBar::RoundedWest) ? GTK_POS_LEFT : GTK_POS_RIGHT;
1247                     gapStart = tabframe->selectedTabRect.y();
1248                     gapSize = tabframe->selectedTabRect.height();
1249                 }
1250                 gtkPainter.paintBoxGap(gtkNotebook, "notebook",  option->rect, state, shadow, frameType,
1251                                         gapStart, gapSize, style);
1252                 break; // done
1253             }
1254
1255             // Note this is only the fallback option
1256             gtkPainter.paintBox(gtkNotebook, "notebook",  option->rect, state, shadow, style);
1257         }
1258         break;
1259
1260     case PE_PanelButtonCommand:
1261     case PE_PanelButtonTool: {
1262         bool isDefault = false;
1263         bool isTool = (element == PE_PanelButtonTool);
1264         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton*>(option))
1265             isDefault = btn->features & QStyleOptionButton::DefaultButton;
1266
1267         // don't draw a frame for tool buttons that have the autoRaise flag and are not enabled or on
1268         if (isTool && !(option->state & State_Enabled || option->state & State_On) && (option->state & State_AutoRaise))
1269             break;
1270         // don't draw a frame for dock widget buttons, unless we are hovering
1271         if (widget && widget->inherits("QDockWidgetTitleButton") && !(option->state & State_MouseOver))
1272             break;
1273
1274         GtkStateType state = gtkPainter.gtkState(option);
1275         if (option->state & State_On || option->state & State_Sunken)
1276             state = GTK_STATE_ACTIVE;
1277         GtkWidget *gtkButton = isTool ? d->gtkWidget("GtkToolButton.GtkButton") : d->gtkWidget("GtkButton");
1278         gint focusWidth, focusPad;
1279         gboolean interiorFocus = false;
1280         d->gtk_widget_style_get (gtkButton,
1281                                 "focus-line-width", &focusWidth,
1282                                 "focus-padding", &focusPad,
1283                                 "interior-focus", &interiorFocus, NULL);
1284
1285         style = gtkButton->style;
1286
1287         QRect buttonRect = option->rect;
1288
1289         QString key;
1290         if (isDefault) {
1291             key += QLS("def");
1292             GTK_WIDGET_SET_FLAGS(gtkButton, GTK_HAS_DEFAULT);
1293             gtkPainter.paintBox(gtkButton, "buttondefault", buttonRect, state, GTK_SHADOW_IN,
1294                                 style, isDefault ? QLS("d") : QString());
1295         }
1296
1297         bool hasFocus = option->state & State_HasFocus;
1298
1299         if (hasFocus) {
1300             key += QLS("def");
1301             GTK_WIDGET_SET_FLAGS(gtkButton, GTK_HAS_FOCUS);
1302         }
1303
1304         if (!interiorFocus)
1305             buttonRect = buttonRect.adjusted(focusWidth, focusWidth, -focusWidth, -focusWidth);
1306
1307         GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
1308                                GTK_SHADOW_IN : GTK_SHADOW_OUT;
1309
1310         gtkPainter.paintBox(gtkButton, "button", buttonRect, state, shadow,
1311                             style, key);
1312         if (isDefault)
1313             GTK_WIDGET_UNSET_FLAGS(gtkButton, GTK_HAS_DEFAULT);
1314         if (hasFocus)
1315             GTK_WIDGET_UNSET_FLAGS(gtkButton, GTK_HAS_FOCUS);
1316     }
1317     break;
1318
1319     case PE_IndicatorRadioButton: {
1320         GtkShadowType shadow = GTK_SHADOW_OUT;
1321         GtkStateType state = gtkPainter.gtkState(option);
1322
1323         if (option->state & State_Sunken)
1324             state = GTK_STATE_ACTIVE;
1325
1326         if (option->state & State_NoChange)
1327             shadow = GTK_SHADOW_ETCHED_IN;
1328         else if (option->state & State_On)
1329             shadow = GTK_SHADOW_IN;
1330         else
1331             shadow = GTK_SHADOW_OUT;
1332
1333         GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
1334         gint spacing;
1335         d->gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL);
1336         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
1337         gtkPainter.setClipRect(option->rect);
1338         // ### Note: Ubuntulooks breaks when the proper widget is passed
1339         //           Murrine engine requires a widget not to get RGBA check - warnings
1340         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1341         QString key(QLS("radiobutton"));
1342         if (option->state & State_HasFocus) { // Themes such as Nodoka check this flag
1343             key += QLatin1Char('f');
1344             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1345         }
1346         gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, key);
1347         if (option->state & State_HasFocus)
1348             GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1349     }
1350     break;
1351
1352     case PE_IndicatorCheckBox: {
1353         GtkShadowType shadow = GTK_SHADOW_OUT;
1354         GtkStateType state = gtkPainter.gtkState(option);
1355
1356         if (option->state & State_Sunken)
1357             state = GTK_STATE_ACTIVE;
1358
1359         if (option->state & State_NoChange)
1360             shadow = GTK_SHADOW_ETCHED_IN;
1361         else if (option->state & State_On)
1362             shadow = GTK_SHADOW_IN;
1363         else
1364             shadow = GTK_SHADOW_OUT;
1365
1366         int spacing;
1367
1368         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1369         QString key(QLS("checkbutton"));
1370         if (option->state & State_HasFocus) { // Themes such as Nodoka checks this flag
1371             key += QLatin1Char('f');
1372             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1373         }
1374
1375         // Some styles such as aero-clone assume they can paint in the spacing area
1376         gtkPainter.setClipRect(option->rect);
1377
1378         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL);
1379
1380         QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
1381
1382         gtkPainter.paintCheckbox(gtkCheckButton, checkRect, state, shadow, gtkCheckButton->style,
1383                                  key);
1384         if (option->state & State_HasFocus)
1385             GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1386
1387     }
1388     break;
1389
1390 #ifndef QT_NO_TABBAR
1391
1392     case PE_FrameTabBarBase:
1393         if (const QStyleOptionTabBarBase *tbb
1394                 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
1395             QRect tabRect = tbb->rect;
1396             painter->save();
1397             painter->setPen(QPen(option->palette.dark().color().dark(110), 0));
1398             switch (tbb->shape) {
1399
1400             case QTabBar::RoundedNorth:
1401                 painter->drawLine(tabRect.topLeft(), tabRect.topRight());
1402                 break;
1403
1404             case QTabBar::RoundedWest:
1405                 painter->drawLine(tabRect.left(), tabRect.top(), tabRect.left(), tabRect.bottom());
1406                 break;
1407
1408             case QTabBar::RoundedSouth:
1409                 painter->drawLine(tbb->rect.left(), tbb->rect.bottom(),
1410                                   tabRect.right(), tabRect.bottom());
1411                 break;
1412
1413             case QTabBar::RoundedEast:
1414                 painter->drawLine(tabRect.topRight(), tabRect.bottomRight());
1415                 break;
1416
1417             case QTabBar::TriangularNorth:
1418             case QTabBar::TriangularEast:
1419             case QTabBar::TriangularWest:
1420             case QTabBar::TriangularSouth:
1421                 painter->restore();
1422                 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1423                 return;
1424             }
1425
1426             painter->restore();
1427         }
1428         return;
1429
1430 #endif // QT_NO_TABBAR
1431
1432     case PE_Widget:
1433         break;
1434
1435     default:
1436         QWindowsStyle::drawPrimitive(element, option, painter, widget);
1437     }
1438 }
1439
1440 /*!
1441     \reimp
1442 */
1443 void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
1444
1445                                    QPainter *painter, const QWidget *widget) const
1446 {
1447     Q_D(const QGtkStyle);
1448
1449     if (!d->isThemeAvailable()) {
1450         QWindowsStyle::drawComplexControl(control, option, painter, widget);
1451         return;
1452     }
1453
1454     GtkStyle* style = d->gtkStyle();
1455     QGtkPainter gtkPainter(painter);
1456     QColor button = option->palette.button().color();
1457     QColor dark;
1458     QColor grooveColor;
1459     QColor darkOutline;
1460     dark.setHsv(button.hue(),
1461                 qMin(255, (int)(button.saturation()*1.9)),
1462                 qMin(255, (int)(button.value()*0.7)));
1463     grooveColor.setHsv(button.hue(),
1464                        qMin(255, (int)(button.saturation()*2.6)),
1465                        qMin(255, (int)(button.value()*0.9)));
1466     darkOutline.setHsv(button.hue(),
1467                        qMin(255, (int)(button.saturation()*3.0)),
1468                        qMin(255, (int)(button.value()*0.6)));
1469
1470     QColor alphaCornerColor;
1471
1472     if (widget)
1473         alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), darkOutline);
1474     else
1475         alphaCornerColor = mergedColors(option->palette.background().color(), darkOutline);
1476
1477     switch (control) {
1478
1479     case CC_TitleBar:
1480         painter->save();
1481         if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
1482             // Since this is drawn by metacity and not Gtk we
1483             // have to do custom drawing
1484
1485             GdkColor gdkBg = style->bg[GTK_STATE_SELECTED];
1486             QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
1487
1488             const int buttonMargin = 5;
1489             bool active = (titleBar->titleBarState & State_Active);
1490             QRect fullRect = titleBar->rect;
1491             QPalette palette = option->palette;
1492             QColor highlight = bgColor;
1493
1494             QColor titleBarFrameBorder(active ? highlight.darker(180): dark.darker(110));
1495             QColor titleBarHighlight(active ? highlight.lighter(120): palette.background().color().lighter(120));
1496             QColor textColor(active ? 0xffffff : 0xff000000);
1497             QColor textAlphaColor(active ? 0xffffff : 0xff000000 );
1498
1499             {
1500                 // Fill title bar gradient
1501                 QColor titlebarColor = QColor(active ? highlight: palette.background().color());
1502                 QLinearGradient gradient(option->rect.center().x(), option->rect.top(),
1503                                          option->rect.center().x(), option->rect.bottom());
1504
1505                 gradient.setColorAt(0, titlebarColor.lighter(114));
1506                 gradient.setColorAt(0.5, titlebarColor.lighter(102));
1507                 gradient.setColorAt(0.51, titlebarColor.darker(104));
1508                 gradient.setColorAt(1, titlebarColor);
1509                 painter->fillRect(option->rect.adjusted(1, 1, -1, 0), gradient);
1510
1511                 // Frame and rounded corners
1512                 painter->setPen(titleBarFrameBorder);
1513
1514                 // top outline
1515                 painter->drawLine(fullRect.left() + 5, fullRect.top(), fullRect.right() - 5, fullRect.top());
1516                 painter->drawLine(fullRect.left(), fullRect.top() + 4, fullRect.left(), fullRect.bottom());
1517                 const QPoint points[5] = {
1518                     QPoint(fullRect.left() + 4, fullRect.top() + 1),
1519                     QPoint(fullRect.left() + 3, fullRect.top() + 1),
1520                     QPoint(fullRect.left() + 2, fullRect.top() + 2),
1521                     QPoint(fullRect.left() + 1, fullRect.top() + 3),
1522                     QPoint(fullRect.left() + 1, fullRect.top() + 4)
1523                 };
1524                 painter->drawPoints(points, 5);
1525
1526                 painter->drawLine(fullRect.right(), fullRect.top() + 4, fullRect.right(), fullRect.bottom());
1527                 const QPoint points2[5] = {
1528                     QPoint(fullRect.right() - 3, fullRect.top() + 1),
1529                     QPoint(fullRect.right() - 4, fullRect.top() + 1),
1530                     QPoint(fullRect.right() - 2, fullRect.top() + 2),
1531                     QPoint(fullRect.right() - 1, fullRect.top() + 3),
1532                     QPoint(fullRect.right() - 1, fullRect.top() + 4)
1533                 };
1534                 painter->drawPoints(points2, 5);
1535
1536                 // draw bottomline
1537                 painter->drawLine(fullRect.right(), fullRect.bottom(), fullRect.left(), fullRect.bottom());
1538
1539                 // top highlight
1540                 painter->setPen(titleBarHighlight);
1541                 painter->drawLine(fullRect.left() + 6, fullRect.top() + 1, fullRect.right() - 6, fullRect.top() + 1);
1542             }
1543             // draw title
1544             QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);
1545             QFont font = painter->font();
1546             font.setBold(true);
1547             painter->setFont(font);
1548             painter->setPen(active? (titleBar->palette.text().color().lighter(120)) :
1549                                      titleBar->palette.text().color() );
1550             // Note workspace also does elliding but it does not use the correct font
1551             QString title = QFontMetrics(font).elidedText(titleBar->text, Qt::ElideRight, textRect.width() - 14);
1552             painter->drawText(textRect.adjusted(1, 1, 1, 1), title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
1553             painter->setPen(Qt::white);
1554             if (active)
1555                 painter->drawText(textRect, title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
1556             // min button
1557             if ((titleBar->subControls & SC_TitleBarMinButton) && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
1558                 !(titleBar->titleBarState& Qt::WindowMinimized)) {
1559                 QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
1560                 if (minButtonRect.isValid()) {
1561                     bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
1562                     bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);
1563                     qt_gtk_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);
1564                     QRect minButtonIconRect = minButtonRect.adjusted(buttonMargin ,buttonMargin , -buttonMargin, -buttonMargin);
1565                     painter->setPen(textColor);
1566                     painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 3,
1567                                     minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 3);
1568                     painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 4,
1569                                     minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 4);
1570                     painter->setPen(textAlphaColor);
1571                     painter->drawLine(minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 3,
1572                                     minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 4);
1573                     painter->drawLine(minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 3,
1574                                     minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 4);
1575                 }
1576             }
1577             // max button
1578             if ((titleBar->subControls & SC_TitleBarMaxButton) && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
1579                 !(titleBar->titleBarState & Qt::WindowMaximized)) {
1580                 QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
1581                 if (maxButtonRect.isValid()) {
1582                     bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
1583                     bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
1584                     qt_gtk_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
1585
1586                     QRect maxButtonIconRect = maxButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
1587
1588                     painter->setPen(textColor);
1589                     painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
1590                     painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
1591                                     maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
1592                     painter->setPen(textAlphaColor);
1593                     const QPoint points[4] = {
1594                         maxButtonIconRect.topLeft(),
1595                         maxButtonIconRect.topRight(),
1596                         maxButtonIconRect.bottomLeft(),
1597                         maxButtonIconRect.bottomRight()
1598                     };
1599                     painter->drawPoints(points, 4);
1600                 }
1601             }
1602
1603             // close button
1604             if ((titleBar->subControls & SC_TitleBarCloseButton) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
1605                 QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
1606                 if (closeButtonRect.isValid()) {
1607                     bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
1608                     bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
1609                     qt_gtk_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
1610                     QRect closeIconRect = closeButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
1611                     painter->setPen(textAlphaColor);
1612                     const QLine lines[4] = {
1613                         QLine(closeIconRect.left() + 1, closeIconRect.top(),
1614                               closeIconRect.right(), closeIconRect.bottom() - 1),
1615                         QLine(closeIconRect.left(), closeIconRect.top() + 1,
1616                               closeIconRect.right() - 1, closeIconRect.bottom()),
1617                         QLine(closeIconRect.right() - 1, closeIconRect.top(),
1618                               closeIconRect.left(), closeIconRect.bottom() - 1),
1619                         QLine(closeIconRect.right(), closeIconRect.top() + 1,
1620                               closeIconRect.left() + 1, closeIconRect.bottom())
1621                     };
1622                     painter->drawLines(lines, 4);
1623                     const QPoint points[4] = {
1624                         closeIconRect.topLeft(),
1625                         closeIconRect.topRight(),
1626                         closeIconRect.bottomLeft(),
1627                         closeIconRect.bottomRight()
1628                     };
1629                     painter->drawPoints(points, 4);
1630
1631                     painter->setPen(textColor);
1632                     painter->drawLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
1633                                     closeIconRect.right() - 1, closeIconRect.bottom() - 1);
1634                     painter->drawLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
1635                                     closeIconRect.right() - 1, closeIconRect.top() + 1);
1636                 }
1637             }
1638
1639             // normalize button
1640             if ((titleBar->subControls & SC_TitleBarNormalButton) &&
1641                (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
1642                (titleBar->titleBarState & Qt::WindowMinimized)) ||
1643                ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
1644                (titleBar->titleBarState & Qt::WindowMaximized)))) {
1645                 QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
1646                 if (normalButtonRect.isValid()) {
1647
1648                     bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
1649                     bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);
1650                     QRect normalButtonIconRect = normalButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
1651                     qt_gtk_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
1652
1653                     QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
1654                     painter->setPen(textColor);
1655                     painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
1656                     painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
1657                                     frontWindowRect.right() - 1, frontWindowRect.top() + 1);
1658                     painter->setPen(textAlphaColor);
1659                     const QPoint points[4] = {
1660                         frontWindowRect.topLeft(),
1661                         frontWindowRect.topRight(),
1662                         frontWindowRect.bottomLeft(),
1663                         frontWindowRect.bottomRight()
1664                     };
1665                     painter->drawPoints(points, 4);
1666
1667                     QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
1668                     QRegion clipRegion = backWindowRect;
1669                     clipRegion -= frontWindowRect;
1670                     painter->save();
1671                     painter->setClipRegion(clipRegion);
1672                     painter->setPen(textColor);
1673                     painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
1674                     painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
1675                                     backWindowRect.right() - 1, backWindowRect.top() + 1);
1676                     painter->setPen(textAlphaColor);
1677                     const QPoint points2[4] = {
1678                         backWindowRect.topLeft(),
1679                         backWindowRect.topRight(),
1680                         backWindowRect.bottomLeft(),
1681                         backWindowRect.bottomRight()
1682                     };
1683                     painter->drawPoints(points2, 4);
1684                     painter->restore();
1685                 }
1686             }
1687
1688             // context help button
1689             if (titleBar->subControls & SC_TitleBarContextHelpButton
1690                 && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint)) {
1691                 QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);
1692                 if (contextHelpButtonRect.isValid()) {
1693                     bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
1694                     bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);
1695                     qt_gtk_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);
1696
1697                     QColor blend;
1698                     QImage image(qt_titlebar_context_help);
1699                     QColor alpha = textColor;
1700                     alpha.setAlpha(128);
1701                     image.setColor(1, textColor.rgba());
1702                     image.setColor(2, alpha.rgba());
1703                     painter->setRenderHint(QPainter::SmoothPixmapTransform);
1704                     painter->drawImage(contextHelpButtonRect.adjusted(4, 4, -4, -4), image);
1705                 }
1706             }
1707
1708             // shade button
1709             if (titleBar->subControls & SC_TitleBarShadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
1710                 QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
1711                 if (shadeButtonRect.isValid()) {
1712                     bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
1713                     bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);
1714                     qt_gtk_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);
1715                     QImage image(qt_scrollbar_button_arrow_up);
1716                     image.setColor(1, textColor.rgba());
1717                     painter->drawImage(shadeButtonRect.adjusted(5, 7, -5, -7), image);
1718                 }
1719             }
1720
1721             // unshade button
1722             if (titleBar->subControls & SC_TitleBarUnshadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
1723                 QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
1724                 if (unshadeButtonRect.isValid()) {
1725                     bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
1726                     bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);
1727                     qt_gtk_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);
1728                     QImage image(qt_scrollbar_button_arrow_down);
1729                     image.setColor(1, textColor.rgba());
1730                     painter->drawImage(unshadeButtonRect.adjusted(5, 7, -5, -7), image);
1731                 }
1732             }
1733
1734             if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
1735                 QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
1736                 if (iconRect.isValid()) {
1737                     if (!titleBar->icon.isNull()) {
1738                         titleBar->icon.paint(painter, iconRect);
1739                     } else {
1740                         QStyleOption tool(0);
1741                         tool.palette = titleBar->palette;
1742                         QPixmap pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(16, 16);
1743                         tool.rect = iconRect;
1744                         painter->save();
1745                         proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
1746                         painter->restore();
1747                     }
1748                 }
1749             }
1750         }
1751         painter->restore();
1752         break;
1753
1754 #ifndef QT_NO_GROUPBOX
1755
1756     case CC_GroupBox:
1757         painter->save();
1758
1759         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
1760             QRect textRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget);
1761             QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
1762             // Draw title
1763
1764             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
1765                 // Draw prelight background
1766                 GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1767
1768                 if (option->state & State_MouseOver) {
1769                     QRect bgRect = textRect | checkBoxRect;
1770                     gtkPainter.paintFlatBox(gtkCheckButton, "checkbutton", bgRect.adjusted(0, 0, 0, -2),
1771                                             GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkCheckButton->style);
1772                 }
1773
1774                 if (!groupBox->text.isEmpty()) {
1775                     int alignment = int(groupBox->textAlignment);
1776                     if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, option, widget))
1777                         alignment |= Qt::TextHideMnemonic;
1778                     QColor textColor = groupBox->textColor; // Note: custom textColor is currently ignored
1779                     int labelState = GTK_STATE_INSENSITIVE;
1780
1781                     if (option->state & State_Enabled)
1782                         labelState = (option->state & State_MouseOver) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
1783
1784                     GdkColor gdkText = gtkCheckButton->style->fg[labelState];
1785                     textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
1786                     painter->setPen(textColor);
1787                     QFont font = painter->font();
1788                     font.setBold(true);
1789                     painter->setFont(font);
1790                     painter->drawText(textRect, Qt::TextShowMnemonic | Qt::AlignLeft| alignment, groupBox->text);
1791
1792                     if (option->state & State_HasFocus)
1793                         gtkPainter.paintFocus(gtkCheckButton, "checkbutton", textRect.adjusted(-4, -1, 0, -3), GTK_STATE_ACTIVE, style);
1794                 }
1795             }
1796
1797             if (groupBox->subControls & SC_GroupBoxCheckBox) {
1798                 QStyleOptionButton box;
1799                 box.QStyleOption::operator=(*groupBox);
1800                 box.rect = checkBoxRect;
1801                 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
1802             }
1803         }
1804
1805         painter->restore();
1806         break;
1807 #endif // QT_NO_GROUPBOX
1808
1809 #ifndef QT_NO_COMBOBOX
1810
1811     case CC_ComboBox:
1812         // See: http://live.gnome.org/GnomeArt/Tutorials/GtkThemes/GtkComboBox
1813         // and http://live.gnome.org/GnomeArt/Tutorials/GtkThemes/GtkComboBoxEntry
1814         if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1815             bool sunken = comboBox->state & State_On; // play dead, if combobox has no items
1816             BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("cb-%0-%1").arg(sunken).arg(comboBox->editable));
1817             QGtkPainter gtkCachedPainter(p);
1818             gtkCachedPainter.setUsePixmapCache(false); // cached externally
1819
1820             bool isEnabled = (comboBox->state & State_Enabled);
1821             bool focus = isEnabled && (comboBox->state & State_HasFocus);
1822             GtkStateType state = gtkPainter.gtkState(option);
1823             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, comboBox, widget);
1824             QStyleOptionComboBox comboBoxCopy = *comboBox;
1825             comboBoxCopy.rect = option->rect;
1826
1827             bool reverse = (option->direction == Qt::RightToLeft);
1828             QRect rect = option->rect;
1829             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
1830                                                    SC_ComboBoxArrow, widget);
1831
1832             GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
1833                                    GTK_SHADOW_IN : GTK_SHADOW_OUT;
1834             const QHashableLatin1Literal comboBoxPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry") : QHashableLatin1Literal("GtkComboBox");
1835
1836             // We use the gtk widget to position arrows and separators for us
1837             GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
1838             GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()};
1839             d->gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1840             d->gtk_widget_size_allocate(gtkCombo, &geometry);
1841
1842             QHashableLatin1Literal buttonPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
1843                                 : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
1844             GtkWidget *gtkToggleButton = d->gtkWidget(buttonPath);
1845             d->gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1846             if (gtkToggleButton && (appears_as_list || comboBox->editable)) {
1847                 if (focus)
1848                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1849                 // Draw the combo box as a line edit with a button next to it
1850                 if (comboBox->editable || appears_as_list) {
1851                     GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state;
1852                     QHashableLatin1Literal entryPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkEntry") : QHashableLatin1Literal("GtkComboBox.GtkFrame");
1853                     GtkWidget *gtkEntry = d->gtkWidget(entryPath);
1854                     d->gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1855                     QRect frameRect = option->rect;
1856
1857                     if (reverse)
1858                         frameRect.setLeft(arrowButtonRect.right());
1859                     else
1860                         frameRect.setRight(arrowButtonRect.left());
1861
1862                     // Fill the line edit background
1863                     // We could have used flat_box with "entry_bg" but that is probably not worth the overhead
1864                     uint resolve_mask = option->palette.resolve();
1865                     int xt = gtkEntry->style->xthickness;
1866                     int yt = gtkEntry->style->ythickness;
1867                     QRect contentRect = frameRect.adjusted(xt, yt, -xt, -yt);
1868                     // Required for inner blue highlight with clearlooks
1869                     if (focus)
1870                         GTK_WIDGET_SET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1871
1872                     if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
1873                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
1874                         p->fillRect(contentRect, option->palette.base().color());
1875                     else {
1876                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
1877                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
1878                                                 GTK_SHADOW_NONE, gtkEntry->style, entryPath.toString() + QString::number(focus));
1879                     }
1880
1881                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
1882                                            GTK_SHADOW_IN, gtkEntry->style, entryPath.toString() +
1883                                            QString::number(focus) + QString::number(comboBox->editable) +
1884                                            QString::number(option->direction));
1885                     if (focus)
1886                         GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1887                 }
1888
1889                 GtkStateType buttonState = GTK_STATE_NORMAL;
1890
1891                 if (!(option->state & State_Enabled))
1892                     buttonState = GTK_STATE_INSENSITIVE;
1893                 else if (option->state & State_Sunken || option->state & State_On)
1894                     buttonState = GTK_STATE_ACTIVE;
1895                 else if (option->state & State_MouseOver && comboBox->activeSubControls & SC_ComboBoxArrow)
1896                     buttonState = GTK_STATE_PRELIGHT;
1897
1898                 Q_ASSERT(gtkToggleButton);
1899                 gtkCachedPainter.paintBox( gtkToggleButton, "button", arrowButtonRect, buttonState,
1900                                      shadow, gtkToggleButton->style, buttonPath.toString() +
1901                                      QString::number(focus) + QString::number(option->direction));
1902                 if (focus)
1903                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1904             } else {
1905                 // Draw combo box as a button
1906                 QRect buttonRect = option->rect;
1907
1908                 if (focus) // Clearlooks actually check the widget for the default state
1909                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1910                 gtkCachedPainter.paintBox(gtkToggleButton, "button",
1911                                     buttonRect, state,
1912                                     shadow, gtkToggleButton->style,
1913                                     buttonPath.toString() + QString::number(focus));
1914                 if (focus)
1915                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1916
1917
1918                 // Draw the separator between label and arrows
1919                 QHashableLatin1Literal vSeparatorPath = comboBox->editable
1920                     ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkVSeparator")
1921                     : QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkVSeparator");
1922
1923                 if (GtkWidget *gtkVSeparator = d->gtkWidget(vSeparatorPath)) {
1924                     GtkAllocation allocation;
1925                     d->gtk_widget_get_allocation(gtkVSeparator, &allocation);
1926                     QRect vLineRect(allocation.x, allocation.y, allocation.width, allocation.height);
1927
1928                     gtkCachedPainter.paintVline( gtkVSeparator, "vseparator",
1929                                            vLineRect, state, gtkVSeparator->style,
1930                                            0, vLineRect.height(), 0,  vSeparatorPath.toString());
1931
1932
1933                     gint interiorFocus = true;
1934                     d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL);
1935                     int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0;
1936                     int yt = interiorFocus ? gtkToggleButton->style->ythickness : 0;
1937                     if (focus && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget)))
1938                         gtkCachedPainter.paintFocus(gtkToggleButton, "button",
1939                                               option->rect.adjusted(xt, yt, -xt, -yt),
1940                                               option->state & State_Sunken ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL,
1941                                               gtkToggleButton->style);
1942                 }
1943             }
1944
1945             if (comboBox->subControls & SC_ComboBoxArrow) {
1946                 if (!isEnabled)
1947                     state = GTK_STATE_INSENSITIVE;
1948                 else if (sunken)
1949                     state = GTK_STATE_ACTIVE;
1950                 else if (option->state & State_MouseOver)
1951                     state = GTK_STATE_PRELIGHT;
1952                 else
1953                     state = GTK_STATE_NORMAL;
1954
1955                 QHashableLatin1Literal arrowPath("");
1956                 if (comboBox->editable) {
1957                     if (appears_as_list)
1958                         arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkArrow");
1959                     else
1960                         arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkArrow");
1961                 } else {
1962                     if (appears_as_list)
1963                         arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkArrow");
1964                     else
1965                         arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow");
1966                 }
1967
1968                 GtkWidget *gtkArrow = d->gtkWidget(arrowPath);
1969                 gfloat scale = 0.7;
1970                 gint minSize = 15;
1971                 QRect arrowWidgetRect;
1972
1973                 if (gtkArrow && !d->gtk_check_version(2, 12, 0)) {
1974                     d->gtk_widget_style_get(gtkArrow, "arrow-scaling", &scale, NULL);
1975                     d->gtk_widget_style_get(gtkCombo, "arrow-size", &minSize, NULL);
1976                 }
1977                 if (gtkArrow) {
1978                     GtkAllocation allocation;
1979                     d->gtk_widget_get_allocation(gtkArrow, &allocation);
1980                     arrowWidgetRect = QRect(allocation.x, allocation.y, allocation.width, allocation.height);
1981                     style = gtkArrow->style;
1982                 }
1983
1984                 // Note that for some reason the arrow-size is not properly respected with Hildon
1985                 // Hence we enforce the minimum "arrow-size" ourselves
1986                 int arrowSize = qMax(qMin(rect.height() - gtkCombo->style->ythickness * 2, minSize),
1987                                      qMin(arrowWidgetRect.width(), arrowWidgetRect.height()));
1988                 QRect arrowRect(0, 0, static_cast<int>(arrowSize * scale), static_cast<int>(arrowSize * scale));
1989
1990                 arrowRect.moveCenter(arrowWidgetRect.center());
1991
1992                 if (sunken) {
1993                     int xoff, yoff;
1994                     const QHashableLatin1Literal toggleButtonPath = comboBox->editable
1995                             ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
1996                             : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
1997
1998                     GtkWidget *gtkButton = d->gtkWidget(toggleButtonPath);
1999                     d->gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL);
2000                     d->gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL);
2001                     arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff);
2002                 }
2003
2004                 // Some styles such as Nimbus paint outside the arrowRect
2005                 // hence we have provide the whole widget as the cliprect
2006                 if (gtkArrow) {
2007                     gtkCachedPainter.setClipRect(option->rect);
2008                     gtkCachedPainter.paintArrow( gtkArrow, "arrow", arrowRect,
2009                                            GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, true,
2010                                            style, arrowPath.toString() + QString::number(option->direction));
2011                 }
2012             }
2013             END_STYLE_PIXMAPCACHE;
2014         }
2015         break;
2016 #endif // QT_NO_COMBOBOX
2017 #ifndef QT_NO_TOOLBUTTON
2018
2019     case CC_ToolButton:
2020         if (const QStyleOptionToolButton *toolbutton
2021                 = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
2022             QRect button, menuarea;
2023             button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
2024             menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
2025             State bflags = toolbutton->state & ~(State_Sunken | State_MouseOver);
2026
2027             if (bflags & State_AutoRaise)
2028                 if (!(bflags & State_MouseOver))
2029                     bflags &= ~State_Raised;
2030
2031             State mflags = bflags;
2032
2033             if (toolbutton->state & State_Sunken) {
2034                 if (toolbutton->activeSubControls & SC_ToolButton)
2035                     bflags |= State_Sunken;
2036                 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
2037                     mflags |= State_Sunken;
2038             } else if (toolbutton->state & State_MouseOver) {
2039                 if (toolbutton->activeSubControls & SC_ToolButton)
2040                     bflags |= State_MouseOver;
2041                 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
2042                     mflags |= State_MouseOver;
2043             }
2044
2045             QStyleOption tool(0);
2046
2047             tool.palette = toolbutton->palette;
2048
2049             if (toolbutton->subControls & SC_ToolButton) {
2050                 if (bflags & (State_Sunken | State_On | State_Raised | State_MouseOver)) {
2051                     tool.rect = button;
2052                     tool.state = bflags;
2053                     proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
2054                 }
2055             }
2056
2057             bool drawMenuArrow = toolbutton->features & QStyleOptionToolButton::HasMenu &&
2058                                  !(toolbutton->features & QStyleOptionToolButton::MenuButtonPopup);
2059             int popupArrowSize = drawMenuArrow ? 7 : 0;
2060
2061             if (toolbutton->state & State_HasFocus) {
2062                 QStyleOptionFocusRect fr;
2063                 fr.QStyleOption::operator=(*toolbutton);
2064                 fr.rect = proxy()->subControlRect(CC_ToolButton, toolbutton, SC_ToolButton, widget);
2065                 fr.rect.adjust(1, 1, -1, -1);
2066                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
2067             }
2068
2069             QStyleOptionToolButton label = *toolbutton;
2070             label.state = bflags;
2071             GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
2072             QPalette pal = toolbutton->palette;
2073             if (option->state & State_Enabled && 
2074                 option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) {
2075                 GdkColor gdkText = gtkButton->style->fg[GTK_STATE_PRELIGHT];
2076                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2077                 pal.setBrush(QPalette::All, QPalette::ButtonText, textColor);
2078                 label.palette = pal;
2079             }
2080             label.rect = button.adjusted(style->xthickness, style->ythickness,
2081                                         -style->xthickness - popupArrowSize, -style->ythickness);
2082             proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
2083
2084             if (toolbutton->subControls & SC_ToolButtonMenu) {
2085                 tool.rect = menuarea;
2086                 tool.state = mflags;
2087                 if ((mflags & State_Enabled && (mflags & (State_Sunken | State_Raised | State_MouseOver))) || !(mflags & State_AutoRaise))
2088                     proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
2089
2090                 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
2091
2092             } else if (drawMenuArrow) {
2093                 QRect ir = toolbutton->rect;
2094                 QStyleOptionToolButton newBtn = *toolbutton;
2095                 newBtn.rect = QRect(ir.right() - popupArrowSize - style->xthickness - 3, ir.height()/2 - 1, popupArrowSize, popupArrowSize);
2096                 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2097             }
2098         }
2099         break;
2100
2101 #endif // QT_NO_TOOLBUTTON
2102 #ifndef QT_NO_SCROLLBAR
2103
2104     case CC_ScrollBar:
2105         if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2106             GtkWidget *gtkHScrollBar = d->gtkWidget("GtkHScrollbar");
2107             GtkWidget *gtkVScrollBar = d->gtkWidget("GtkVScrollbar");
2108
2109             // Fill background in case the scrollbar is partially transparent
2110             painter->fillRect(option->rect, option->palette.background());
2111
2112             QRect rect = scrollBar->rect;
2113             QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
2114             QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
2115             QRect scrollBarSlider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
2116             QRect grooveRect = proxy()->subControlRect(control, scrollBar, SC_ScrollBarGroove, widget);
2117             bool horizontal = scrollBar->orientation == Qt::Horizontal;
2118             GtkWidget * scrollbarWidget = horizontal ? gtkHScrollBar : gtkVScrollBar;
2119             style = scrollbarWidget->style;
2120             gboolean trough_under_steppers = true;
2121             gboolean trough_side_details = false;
2122             gboolean activate_slider = false;
2123             gboolean stepper_size = 14;
2124             gint trough_border = 1;
2125             if (!d->gtk_check_version(2, 10, 0)) {
2126                 d->gtk_widget_style_get((GtkWidget*)(scrollbarWidget),
2127                                            "trough-border",   &trough_border,
2128                                            "trough-side-details",   &trough_side_details,
2129                                            "trough-under-steppers", &trough_under_steppers,
2130                                            "activate-slider",       &activate_slider,
2131                                            "stepper-size",          &stepper_size, NULL);
2132             }
2133             if (trough_under_steppers) {
2134                 scrollBarAddLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
2135                 scrollBarSubLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
2136                 scrollBarSlider.adjust(horizontal ? -trough_border : 0, horizontal ? 0 : -trough_border,
2137                                        horizontal ? trough_border : 0, horizontal ? 0 : trough_border);
2138             }
2139
2140             // Some styles check the position of scrollbars in order to determine
2141             // if lines should be painted when the scrollbar is in max or min positions.
2142             int maximum = 2;
2143             int fakePos = 0;
2144             bool reverse = (option->direction == Qt::RightToLeft);
2145             if (scrollBar->minimum == scrollBar->maximum)
2146                 maximum = 0;
2147             if (scrollBar->sliderPosition == scrollBar->maximum)
2148                 fakePos = maximum;
2149             else if (scrollBar->sliderPosition > scrollBar->minimum)
2150                 fakePos = maximum - 1;
2151
2152
2153             GtkRange *range = (GtkRange*)(horizontal ? gtkHScrollBar : gtkVScrollBar);
2154             GtkAdjustment *adjustment = d->gtk_range_get_adjustment(range);
2155
2156             if (adjustment) {
2157                 d->gtk_adjustment_configure(adjustment, fakePos, 0, maximum, 0, 0, 0);
2158             } else {
2159                 adjustment = (GtkAdjustment*)d->gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0);
2160                 d->gtk_range_set_adjustment(range, adjustment);
2161             }
2162
2163             if (scrollBar->subControls & SC_ScrollBarGroove) {
2164                 GtkStateType state = GTK_STATE_ACTIVE;
2165
2166                 if (!(option->state & State_Enabled))
2167                     state = GTK_STATE_INSENSITIVE;
2168
2169                 if (trough_under_steppers)
2170                     grooveRect = option->rect;
2171
2172                 gtkPainter.paintBox( scrollbarWidget, "trough", grooveRect, state, GTK_SHADOW_IN, style);
2173             }
2174
2175             //paint slider
2176             if (scrollBar->subControls & SC_ScrollBarSlider) {
2177                 GtkStateType state = GTK_STATE_NORMAL;
2178
2179                 if (!(option->state & State_Enabled))
2180                     state = GTK_STATE_INSENSITIVE;
2181                 else if (activate_slider &&
2182                          option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarSlider))
2183                     state = GTK_STATE_ACTIVE;
2184                 else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSlider))
2185                     state = GTK_STATE_PRELIGHT;
2186
2187                 GtkShadowType shadow = GTK_SHADOW_OUT;
2188
2189                 if (trough_under_steppers) {
2190                     if (!horizontal)
2191                         scrollBarSlider.adjust(trough_border, 0, -trough_border, 0);
2192                     else
2193                         scrollBarSlider.adjust(0, trough_border, 0, -trough_border);
2194                 }
2195
2196                 gtkPainter.paintSlider( scrollbarWidget, "slider", scrollBarSlider, state, shadow, style,
2197
2198                                         horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, QString(QLS("%0%1")).arg(fakePos).arg(maximum));
2199             }
2200
2201             if (scrollBar->subControls & SC_ScrollBarAddLine) {
2202                 GtkAllocation vAllocation;
2203                 vAllocation.y = scrollBarAddLine.top();
2204                 vAllocation.height = scrollBarAddLine.height() - rect.height() + 6;
2205                 d->gtk_widget_set_allocation(gtkVScrollBar, &vAllocation);
2206
2207                 GtkAllocation hAllocation;
2208                 hAllocation.x = scrollBarAddLine.right();
2209                 hAllocation.width = scrollBarAddLine.width() - rect.width();
2210                 d->gtk_widget_set_allocation(gtkHScrollBar, &hAllocation);
2211
2212                 GtkShadowType shadow = GTK_SHADOW_OUT;
2213                 GtkStateType state = GTK_STATE_NORMAL;
2214
2215                 if (!(option->state & State_Enabled) || (fakePos == maximum))
2216                     state = GTK_STATE_INSENSITIVE;
2217                 else if (option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarAddLine)) {
2218                     state = GTK_STATE_ACTIVE;
2219                     shadow = GTK_SHADOW_IN;
2220
2221                 } else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarAddLine))
2222                     state = GTK_STATE_PRELIGHT;
2223
2224                 gtkPainter.paintBox( scrollbarWidget,
2225                                      horizontal ? "hscrollbar" : "vscrollbar", scrollBarAddLine,
2226                                      state, shadow, style, QLS("add"));
2227
2228                 gtkPainter.paintArrow( scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarAddLine.adjusted(4, 4, -4, -4),
2229                                        horizontal ? (reverse ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT) :
2230                                        GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, false, style);
2231             }
2232
2233             if (scrollBar->subControls & SC_ScrollBarSubLine) {
2234                 GtkAllocation vAllocation;
2235                 vAllocation.y = 0;
2236                 vAllocation.height = scrollBarSubLine.height();
2237                 d->gtk_widget_set_allocation(gtkVScrollBar, &vAllocation);
2238
2239                 GtkAllocation hAllocation;
2240                 hAllocation.x = 0;
2241                 hAllocation.width = scrollBarSubLine.width();
2242                 d->gtk_widget_set_allocation(gtkHScrollBar, &hAllocation);
2243
2244                 GtkShadowType shadow = GTK_SHADOW_OUT;
2245                 GtkStateType state = GTK_STATE_NORMAL;
2246
2247                 if (!(option->state & State_Enabled) || (fakePos == 0))
2248                     state = GTK_STATE_INSENSITIVE;
2249                 else if (option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarSubLine)) {
2250                     shadow = GTK_SHADOW_IN;
2251                     state = GTK_STATE_ACTIVE;
2252
2253                 } else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSubLine))
2254                     state = GTK_STATE_PRELIGHT;
2255
2256                 gtkPainter.paintBox(scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarSubLine,
2257                                     state, shadow, style, QLS("sub"));
2258
2259                 gtkPainter.paintArrow(scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarSubLine.adjusted(4, 4, -4, -4),
2260                                       horizontal ? (reverse ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT) :
2261                                       GTK_ARROW_UP, state, GTK_SHADOW_NONE, false, style);
2262             }
2263         }
2264         break;
2265
2266 #endif //QT_NO_SCROLLBAR
2267 #ifndef QT_NO_SPINBOX
2268
2269     case CC_SpinBox:
2270         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
2271
2272             GtkWidget *gtkSpinButton = spinBox->buttonSymbols == QAbstractSpinBox::NoButtons
2273                         ? d->gtkWidget("GtkEntry")
2274                         : d->gtkWidget("GtkSpinButton");
2275             bool isEnabled = (spinBox->state & State_Enabled);
2276             bool hover = isEnabled && (spinBox->state & State_MouseOver);
2277             bool sunken = (spinBox->state & State_Sunken);
2278             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
2279             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
2280             bool reverse = (spinBox->direction == Qt::RightToLeft);
2281
2282             QRect editArea = option->rect;
2283             QRect editRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxEditField, widget);
2284             QRect upRect, downRect, buttonRect;
2285             if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
2286                 upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
2287                 downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
2288
2289                 //### Move this to subControlRect
2290                 upRect.setTop(option->rect.top());
2291
2292                 if (reverse)
2293                     upRect.setLeft(option->rect.left());
2294                 else
2295                     upRect.setRight(option->rect.right());
2296
2297                 downRect.setBottom(option->rect.bottom());
2298
2299                 if (reverse)
2300                     downRect.setLeft(option->rect.left());
2301                 else
2302                     downRect.setRight(option->rect.right());
2303
2304                 buttonRect = upRect | downRect;
2305
2306                 if (reverse)
2307                     editArea.setLeft(upRect.right());
2308                 else
2309                     editArea.setRight(upRect.left());
2310             }
2311             if (spinBox->frame) {
2312                 GtkStateType state = gtkPainter.gtkState(option);
2313
2314                 if (!(option->state & State_Enabled))
2315                     state = GTK_STATE_INSENSITIVE;
2316                 else if (option->state & State_HasFocus)
2317                     state = GTK_STATE_NORMAL;
2318                 else if (state == GTK_STATE_PRELIGHT)
2319                     state = GTK_STATE_NORMAL;
2320
2321                 style = gtkPainter.getStyle(gtkSpinButton);
2322
2323
2324                 QString key;
2325
2326                 if (option->state & State_HasFocus) {
2327                     key += QLatin1Char('f');
2328                     GTK_WIDGET_SET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
2329                 }
2330
2331                 uint resolve_mask = option->palette.resolve();
2332
2333                 if (resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
2334                     painter->fillRect(editRect, option->palette.base().color());
2335                 else
2336                     gtkPainter.paintFlatBox(gtkSpinButton, "entry_bg", editArea.adjusted(style->xthickness, style->ythickness,
2337                                             -style->xthickness, -style->ythickness),
2338                                             option->state & State_Enabled ?
2339                                             GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, style, key);
2340
2341                 gtkPainter.paintShadow(gtkSpinButton, "entry", editArea, state, GTK_SHADOW_IN, gtkSpinButton->style, key);
2342                 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
2343                     gtkPainter.paintBox(gtkSpinButton, "spinbutton", buttonRect, state, GTK_SHADOW_IN, style, key);
2344
2345                     upRect.setSize(downRect.size());
2346                     if (!(option->state & State_Enabled))
2347                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
2348                     else if (upIsActive && sunken)
2349                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
2350                     else if (upIsActive && hover)
2351                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
2352                     else
2353                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
2354
2355                     if (!(option->state & State_Enabled))
2356                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
2357                     else if (downIsActive && sunken)
2358                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
2359                     else if (downIsActive && hover)
2360                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
2361                     else
2362                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
2363
2364                     if (option->state & State_HasFocus)
2365                         GTK_WIDGET_UNSET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
2366                 }
2367             }
2368
2369             if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
2370                 int centerX = upRect.center().x();
2371                 int centerY = upRect.center().y();
2372                 // plus/minus
2373
2374                 if (spinBox->activeSubControls == SC_SpinBoxUp && sunken) {
2375                     painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
2376                     painter->drawLine(1 + centerX, 1 + centerY - 2, 1 + centerX, 1 + centerY + 2);
2377
2378                 } else {
2379                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
2380                     painter->drawLine(centerX, centerY - 2, centerX, centerY + 2);
2381                 }
2382                 centerX = downRect.center().x();
2383                 centerY = downRect.center().y();
2384
2385                 if (spinBox->activeSubControls == SC_SpinBoxDown && sunken) {
2386                     painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
2387                 } else {
2388                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
2389                 }
2390
2391             } else if (spinBox->buttonSymbols == QAbstractSpinBox::UpDownArrows) {
2392                 int size = d->getSpinboxArrowSize();
2393                 int w = size / 2 - 1;
2394                 w -= w % 2 - 1; // force odd
2395                 int h = (w + 1)/2;
2396                 QRect arrowRect(0, 0, w, h);
2397                 arrowRect.moveCenter(upRect.center());
2398                 // arrows
2399                 GtkStateType state = GTK_STATE_NORMAL;
2400
2401                 if (!(option->state & State_Enabled) || !(spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2402                     state = GTK_STATE_INSENSITIVE;
2403
2404                 gtkPainter.paintArrow( gtkSpinButton, "spinbutton", arrowRect, GTK_ARROW_UP, state,
2405                                        GTK_SHADOW_NONE, false, style);
2406
2407                 arrowRect.moveCenter(downRect.center());
2408
2409                 if (!(option->state & State_Enabled) || !(spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2410                     state = GTK_STATE_INSENSITIVE;
2411
2412                 gtkPainter.paintArrow( gtkSpinButton, "spinbutton", arrowRect, GTK_ARROW_DOWN, state,
2413                                        GTK_SHADOW_NONE, false, style);
2414             }
2415         }
2416         break;
2417
2418 #endif // QT_NO_SPINBOX
2419
2420 #ifndef QT_NO_SLIDER
2421
2422     case CC_Slider:
2423         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2424             GtkWidget *hScaleWidget = d->gtkWidget("GtkHScale");
2425             GtkWidget *vScaleWidget = d->gtkWidget("GtkVScale");
2426
2427             QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
2428             QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
2429
2430             bool horizontal = slider->orientation == Qt::Horizontal;
2431             bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
2432             bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
2433
2434             QBrush oldBrush = painter->brush();
2435             QPen oldPen = painter->pen();
2436
2437             QColor shadowAlpha(Qt::black);
2438             shadowAlpha.setAlpha(10);
2439             QColor highlightAlpha(Qt::white);
2440             highlightAlpha.setAlpha(80);
2441
2442             QGtkStylePrivate::gtk_widget_set_direction(hScaleWidget, slider->upsideDown ?
2443                                                        GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
2444             GtkWidget *scaleWidget = horizontal ? hScaleWidget : vScaleWidget;
2445             style = scaleWidget->style;
2446
2447             if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
2448
2449                 GtkRange *range = (GtkRange*)scaleWidget;
2450                 GtkAdjustment *adjustment = d->gtk_range_get_adjustment(range);
2451                 if (adjustment) {
2452                     d->gtk_adjustment_configure(adjustment,
2453                                                 slider->sliderPosition,
2454                                                 slider->minimum,
2455                                                 slider->maximum,
2456                                                 slider->singleStep,
2457                                                 slider->singleStep,
2458                                                 slider->pageStep);
2459                 } else {
2460                     adjustment = (GtkAdjustment*)d->gtk_adjustment_new(slider->sliderPosition,
2461                                                                        slider->minimum,
2462                                                                        slider->maximum,
2463                                                                        slider->singleStep,
2464                                                                        slider->singleStep,
2465                                                                        slider->pageStep);
2466                     d->gtk_range_set_adjustment(range, adjustment);
2467                 }
2468
2469                 int outerSize;
2470                 d->gtk_range_set_inverted(range, !horizontal);
2471                 d->gtk_widget_style_get(scaleWidget, "trough-border", &outerSize, NULL);
2472                 outerSize++;
2473
2474                 GtkStateType state = gtkPainter.gtkState(option);
2475                 int focusFrameMargin = 2;
2476                 QRect grooveRect = option->rect.adjusted(focusFrameMargin, outerSize + focusFrameMargin,
2477                                    -focusFrameMargin, -outerSize - focusFrameMargin);
2478
2479                 gboolean trough_side_details = false; // Indicates if the upper or lower scale background differs
2480                 if (!d->gtk_check_version(2, 10, 0))
2481                     d->gtk_widget_style_get((GtkWidget*)(scaleWidget), "trough-side-details",   &trough_side_details, NULL);
2482
2483                 if (!trough_side_details) {
2484                     gtkPainter.paintBox( scaleWidget, "trough", grooveRect, state,
2485                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2486                 } else {
2487                     QRect upperGroove = grooveRect;
2488                     QRect lowerGroove = grooveRect;
2489
2490                     if (horizontal) {
2491                         if (slider->upsideDown) {
2492                             lowerGroove.setLeft(handle.center().x());
2493                             upperGroove.setRight(handle.center().x());
2494                         } else {
2495                             upperGroove.setLeft(handle.center().x());
2496                             lowerGroove.setRight(handle.center().x());
2497                         }
2498                     } else {
2499                         if (!slider->upsideDown) {
2500                             lowerGroove.setBottom(handle.center().y());
2501                             upperGroove.setTop(handle.center().y());
2502                         } else {
2503                             upperGroove.setBottom(handle.center().y());
2504                             lowerGroove.setTop(handle.center().y());
2505                         }
2506                     }
2507
2508                     gtkPainter.paintBox( scaleWidget, "trough-upper", upperGroove, state,
2509                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2510                     gtkPainter.paintBox( scaleWidget, "trough-lower", lowerGroove, state,
2511                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2512                 }
2513             }
2514
2515             if (option->subControls & SC_SliderTickmarks) {
2516                 painter->setPen(darkOutline);
2517                 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
2518                 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
2519                 int interval = slider->tickInterval;
2520
2521                 if (interval <= 0) {
2522                     interval = slider->singleStep;
2523
2524                     if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
2525                                                         available)
2526                             - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
2527                                                               0, available) < 3)
2528                         interval = slider->pageStep;
2529                 }
2530
2531                 if (interval <= 0)
2532                     interval = 1;
2533
2534                 int v = slider->minimum;
2535                 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
2536                 while (v <= slider->maximum + 1) {
2537                     if (v == slider->maximum + 1 && interval == 1)
2538                         break;
2539                     const int v_ = qMin(v, slider->maximum);
2540                     int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
2541                                                       v_, (horizontal
2542                                                            ? slider->rect.width()
2543                                                            : slider->rect.height()) - len,
2544                                                       slider->upsideDown) + len / 2;
2545                     int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
2546                     if (horizontal) {
2547                         if (ticksAbove)
2548                             painter->drawLine(pos, slider->rect.top() + extra,
2549                                               pos, slider->rect.top() + tickSize);
2550                         if (ticksBelow)
2551                             painter->drawLine(pos, slider->rect.bottom() - extra,
2552                                               pos, slider->rect.bottom() - tickSize);
2553
2554                     } else {
2555                         if (ticksAbove)
2556                             painter->drawLine(slider->rect.left() + extra, pos,
2557                                               slider->rect.left() + tickSize, pos);
2558                         if (ticksBelow)
2559                             painter->drawLine(slider->rect.right() - extra, pos,
2560                                               slider->rect.right() - tickSize, pos);
2561                     }
2562
2563                     // In the case where maximum is max int
2564                     int nextInterval = v + interval;
2565                     if (nextInterval < v)
2566                         break;
2567                     v = nextInterval;
2568                 }
2569             }
2570
2571             // Draw slider handle
2572             if (option->subControls & SC_SliderHandle) {
2573                 GtkShadowType shadow =  GTK_SHADOW_OUT;
2574                 GtkStateType state = GTK_STATE_NORMAL;
2575
2576                 if (!(option->state & State_Enabled))
2577                     state = GTK_STATE_INSENSITIVE;
2578                 else if (option->state & State_MouseOver && option->activeSubControls & SC_SliderHandle)
2579                     state = GTK_STATE_PRELIGHT;
2580
2581                 bool horizontal = option->state & State_Horizontal;
2582
2583                 if (slider->state & State_HasFocus) {
2584                     QStyleOptionFocusRect fropt;
2585                     fropt.QStyleOption::operator=(*slider);
2586                     fropt.rect = slider->rect.adjusted(-1, -1 ,1, 1);
2587
2588                     if (horizontal) {
2589                         fropt.rect.setTop(handle.top() - 3);
2590                         fropt.rect.setBottom(handle.bottom() + 4);
2591
2592                     } else {
2593                         fropt.rect.setLeft(handle.left() - 3);
2594                         fropt.rect.setRight(handle.right() + 3);
2595                     }
2596                     proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
2597                 }
2598                 gtkPainter.paintSlider( scaleWidget, horizontal ? "hscale" : "vscale", handle, state, shadow, style,
2599
2600                                         horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL);
2601             }
2602             painter->setBrush(oldBrush);
2603             painter->setPen(oldPen);
2604         }
2605         break;
2606     case CC_Dial:
2607         if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
2608             QStyleHelper::drawDial(dial, painter);
2609         break;
2610
2611 #endif // QT_NO_SLIDER
2612
2613     default:
2614         QWindowsStyle::drawComplexControl(control, option, painter, widget);
2615
2616         break;
2617     }
2618 }
2619
2620
2621 /*!
2622     \reimp
2623 */
2624 void QGtkStyle::drawControl(ControlElement element,
2625                             const QStyleOption *option,
2626                             QPainter *painter,
2627                             const QWidget *widget) const
2628 {
2629     Q_D(const QGtkStyle);
2630
2631     if (!d->isThemeAvailable()) {
2632         QWindowsStyle::drawControl(element, option, painter, widget);
2633         return;
2634     }
2635
2636     GtkStyle* style = d->gtkStyle();
2637     QGtkPainter gtkPainter(painter);
2638
2639     switch (element) {
2640     case CE_ProgressBarLabel:
2641         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2642             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
2643             if (!gtkProgressBar)
2644                 return;
2645
2646             QRect leftRect;
2647             QRect rect = bar->rect;
2648             GdkColor gdkText = gtkProgressBar->style->fg[GTK_STATE_NORMAL];
2649             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2650             gdkText = gtkProgressBar->style->fg[GTK_STATE_PRELIGHT];
2651             QColor alternateTextColor= QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2652
2653             painter->save();
2654             bool vertical = false, inverted = false;
2655             if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2656                 vertical = (bar2->orientation == Qt::Vertical);
2657                 inverted = bar2->invertedAppearance;
2658             }
2659             if (vertical)
2660                 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
2661             const int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) * rect.width() /
2662                                               qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
2663             if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width())
2664                 leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
2665             if (vertical)
2666                 leftRect.translate(rect.width() - progressIndicatorPos, 0);
2667
2668             bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted) ||
2669                                        ((bar->direction == Qt::LeftToRight) && inverted)));
2670
2671             QRegion rightRect = rect;
2672             rightRect = rightRect.subtracted(leftRect);
2673             painter->setClipRegion(rightRect);
2674             painter->setPen(flip ? alternateTextColor : textColor);
2675             painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2676             if (!leftRect.isNull()) {
2677                 painter->setPen(flip ? textColor : alternateTextColor);
2678                 painter->setClipRect(leftRect);
2679                 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2680             }
2681             painter->restore();
2682         }
2683         break;
2684     case CE_PushButtonLabel:
2685         if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2686             QRect ir = button->rect;
2687             uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
2688             QPoint buttonShift;
2689
2690             if (option->state & State_Sunken)
2691                 buttonShift = QPoint(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
2692                                      proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
2693
2694             if (proxy()->styleHint(SH_UnderlineShortcut, button, widget))
2695                 tf |= Qt::TextShowMnemonic;
2696             else
2697                 tf |= Qt::TextHideMnemonic;
2698
2699             if (!button->icon.isNull()) {
2700                 //Center both icon and text
2701                 QPoint point;
2702
2703                 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
2704                 if (mode == QIcon::Normal && button->state & State_HasFocus)
2705                     mode = QIcon::Active;
2706
2707                 QIcon::State state = QIcon::Off;
2708
2709                 if (button->state & State_On)
2710                     state = QIcon::On;
2711
2712                 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
2713                 int w = pixmap.width();
2714                 int h = pixmap.height();
2715
2716                 if (!button->text.isEmpty())
2717                     w += button->fontMetrics.boundingRect(option->rect, tf, button->text).width() + 4;
2718
2719                 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
2720                                ir.y() + ir.height() / 2 - h / 2);
2721
2722                 if (button->direction == Qt::RightToLeft)
2723                     point.rx() += pixmap.width();
2724
2725                 painter->drawPixmap(visualPos(button->direction, button->rect, point + buttonShift), pixmap);
2726
2727                 if (button->direction == Qt::RightToLeft)
2728                     ir.translate(-point.x() - 2, 0);
2729                 else
2730                     ir.translate(point.x() + pixmap.width() + 2, 0);
2731
2732                 // left-align text if there is
2733                 if (!button->text.isEmpty())
2734                     tf |= Qt::AlignLeft;
2735
2736             } else {
2737                 tf |= Qt::AlignHCenter;
2738             }
2739
2740             ir.translate(buttonShift);
2741
2742             if (button->features & QStyleOptionButton::HasMenu)
2743                 ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
2744
2745             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
2746             QPalette pal = button->palette;
2747             int labelState = GTK_STATE_INSENSITIVE;
2748             if (option->state & State_Enabled)
2749                 labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
2750                              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2751
2752             GdkColor gdkText = gtkButton->style->fg[labelState];
2753             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2754             pal.setBrush(QPalette::ButtonText, textColor);
2755             proxy()->drawItemText(painter, ir, tf, pal, (button->state & State_Enabled),
2756                          button->text, QPalette::ButtonText);
2757         }
2758         break;
2759
2760     case CE_RadioButton: // Fall through
2761     case CE_CheckBox:
2762         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2763             bool isRadio = (element == CE_RadioButton);
2764
2765             // Draw prelight background
2766             GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
2767
2768             if (option->state & State_MouseOver) {
2769                 gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect,
2770                                         GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkRadioButton->style);
2771             }
2772
2773             QStyleOptionButton subopt = *btn;
2774             subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
2775                                          : SE_CheckBoxIndicator, btn, widget);
2776             proxy()->drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
2777                           &subopt, painter, widget);
2778             subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
2779                                          : SE_CheckBoxContents, btn, widget);
2780             // Get label text color
2781             QPalette pal = subopt.palette;
2782             int labelState = GTK_STATE_INSENSITIVE;
2783             if (option->state & State_Enabled)
2784                 labelState = (option->state & State_MouseOver) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2785
2786             GdkColor gdkText = gtkRadioButton->style->fg[labelState];
2787             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2788             pal.setBrush(QPalette::WindowText, textColor);
2789             subopt.palette = pal;
2790             proxy()->drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, painter, widget);
2791
2792             if (btn->state & State_HasFocus) {
2793                 QStyleOptionFocusRect fropt;
2794                 fropt.QStyleOption::operator=(*btn);
2795                 fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
2796                                             : SE_CheckBoxFocusRect, btn, widget);
2797                 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
2798             }
2799         }
2800         break;
2801
2802 #ifndef QT_NO_COMBOBOX
2803
2804     case CE_ComboBoxLabel:
2805         if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
2806             QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
2807             bool appearsAsList = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, cb, widget);
2808             painter->save();
2809             painter->setClipRect(editRect);
2810
2811             if (!cb->currentIcon.isNull()) {
2812                 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
2813                                    : QIcon::Disabled;
2814                 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
2815                 QRect iconRect(editRect);
2816                 iconRect.setWidth(cb->iconSize.width() + 4);
2817
2818                 iconRect = alignedRect(cb->direction,
2819                                        Qt::AlignLeft | Qt::AlignVCenter,
2820                                        iconRect.size(), editRect);
2821
2822                 if (cb->editable)
2823                     painter->fillRect(iconRect, option->palette.brush(QPalette::Base));
2824
2825                 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
2826
2827                 if (cb->direction == Qt::RightToLeft)
2828                     editRect.translate(-4 - cb->iconSize.width(), 0);
2829                 else
2830                     editRect.translate(cb->iconSize.width() + 4, 0);
2831             }
2832
2833             if (!cb->currentText.isEmpty() && !cb->editable) {
2834                 GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
2835                 QPalette pal = cb->palette;
2836                 int labelState = GTK_STATE_INSENSITIVE;
2837
2838                 if (option->state & State_Enabled)
2839                     labelState = (option->state & State_MouseOver && !appearsAsList) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2840
2841                 GdkColor gdkText = gtkCombo->style->fg[labelState];
2842
2843                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2844
2845                 pal.setBrush(QPalette::ButtonText, textColor);
2846
2847                 proxy()->drawItemText(painter, editRect.adjusted(1, 0, -1, 0),
2848                              visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter),
2849                              pal, cb->state & State_Enabled, cb->currentText, QPalette::ButtonText);
2850             }
2851
2852             painter->restore();
2853         }
2854         break;
2855
2856 #endif // QT_NO_COMBOBOX
2857
2858     case CE_DockWidgetTitle:
2859         painter->save();
2860         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
2861             const QStyleOptionDockWidgetV2 *v2
2862                 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dwOpt);
2863             bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2864
2865             QRect rect = dwOpt->rect;
2866             QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget).adjusted(-2, 0, -2, 0);
2867             QRect r = rect.adjusted(0, 0, -1, -1);
2868             if (verticalTitleBar)
2869                 r.adjust(0, 0, 0, -1);
2870
2871             if (verticalTitleBar) {
2872                 QRect r = rect;
2873                 QSize s = r.size();
2874                 s.transpose();
2875                 r.setSize(s);
2876
2877                 titleRect = QRect(r.left() + rect.bottom()
2878                                     - titleRect.bottom(),
2879                                 r.top() + titleRect.left() - rect.left(),
2880                                 titleRect.height(), titleRect.width());
2881
2882                 painter->translate(r.left(), r.top() + r.width());
2883                 painter->rotate(-90);
2884                 painter->translate(-r.left(), -r.top());
2885
2886                 rect = r;
2887             }
2888
2889             if (!dwOpt->title.isEmpty()) {
2890                 QString titleText
2891                     = painter->fontMetrics().elidedText(dwOpt->title,
2892                                             Qt::ElideRight, titleRect.width());
2893                 proxy()->drawItemText(painter,
2894                              titleRect,
2895                              Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
2896                              dwOpt->state & State_Enabled, titleText,
2897                              QPalette::WindowText);
2898                 }
2899         }
2900         painter->restore();
2901         break;
2902
2903
2904
2905     case CE_HeaderSection:
2906         painter->save();
2907
2908         // Draws the header in tables.
2909         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2910             Q_UNUSED(header);
2911             GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
2912             // Get the middle column
2913             GtkTreeViewColumn *column = d->gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1);
2914             Q_ASSERT(column);
2915
2916             GtkWidget *gtkTreeHeader = column->button;
2917             GtkStateType state = gtkPainter.gtkState(option);
2918             GtkShadowType shadow = GTK_SHADOW_OUT;
2919
2920             if (option->state & State_Sunken)
2921                 shadow = GTK_SHADOW_IN;
2922             
2923             gtkPainter.paintBox(gtkTreeHeader, "button",  option->rect.adjusted(-1, 0, 0, 0), state, shadow, gtkTreeHeader->style);
2924         }
2925
2926         painter->restore();
2927         break;
2928
2929 #ifndef QT_NO_SIZEGRIP
2930
2931     case CE_SizeGrip: {
2932         GtkWidget *gtkStatusbar = d->gtkWidget("GtkStatusbar.GtkFrame");
2933         QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness);
2934         gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL,
2935                                     GTK_SHADOW_OUT, QApplication::isRightToLeft() ?
2936                                         GDK_WINDOW_EDGE_SOUTH_WEST : GDK_WINDOW_EDGE_SOUTH_EAST,
2937                                     gtkStatusbar->style);
2938     }
2939     break;
2940
2941 #endif // QT_NO_SIZEGRIP
2942
2943     case CE_MenuBarEmptyArea: {
2944         GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
2945         GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
2946         painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
2947         if (widget) { // See CE_MenuBarItem
2948             QRect menuBarRect = widget->rect();
2949             QPixmap pixmap(menuBarRect.size());
2950             pixmap.fill(Qt::transparent);
2951             QPainter pmPainter(&pixmap);
2952             QGtkPainter gtkMenuBarPainter(&pmPainter);
2953             GtkShadowType shadow_type;
2954             d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
2955             gtkMenuBarPainter.paintBox( gtkMenubar, "menubar",  menuBarRect,
2956                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
2957             pmPainter.end();
2958             painter->drawPixmap(option->rect, pixmap, option->rect);
2959         }
2960     }
2961     break;
2962
2963     case CE_MenuBarItem:
2964         painter->save();
2965
2966         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
2967             GtkWidget *gtkMenubarItem = d->gtkWidget("GtkMenuBar.GtkMenuItem");
2968             GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
2969
2970             style = gtkMenubarItem->style;
2971
2972             if (widget) {
2973                 // Since Qt does not currently allow filling the entire background
2974                 // we use a hack for this by making a complete menubar each time and
2975                 // paint with the correct offset inside it. Pixmap caching should resolve
2976                 // most of the performance penalty.
2977                 QRect menuBarRect = widget->rect();
2978                 QPixmap pixmap(menuBarRect.size());
2979                 pixmap.fill(Qt::transparent);
2980                 QPainter pmPainter(&pixmap);
2981                 QGtkPainter menubarPainter(&pmPainter);
2982                 GtkShadowType shadow_type;
2983                 d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
2984                 GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
2985                 painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
2986                 menubarPainter.paintBox(gtkMenubar, "menubar",  menuBarRect,
2987                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
2988                 pmPainter.end();
2989                 painter->drawPixmap(option->rect, pixmap, option->rect);
2990             }
2991
2992             QStyleOptionMenuItem item = *mbi;
2993             bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
2994             bool dis = !(mbi->state & State_Enabled);
2995             item.rect = mbi->rect;
2996             GdkColor gdkText = gtkMenubarItem->style->fg[dis ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL];
2997             GdkColor gdkHText = gtkMenubarItem->style->fg[GTK_STATE_PRELIGHT];
2998             QColor normalTextColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2999             QColor highlightedTextColor = QColor(gdkHText.red>>8, gdkHText.green>>8, gdkHText.blue>>8);
3000             item.palette.setBrush(QPalette::HighlightedText, highlightedTextColor);
3001             item.palette.setBrush(QPalette::Text, normalTextColor);
3002             item.palette.setBrush(QPalette::ButtonText, normalTextColor);
3003             QCommonStyle::drawControl(element, &item, painter, widget);
3004
3005             if (act) {
3006                 GtkShadowType shadowType = GTK_SHADOW_NONE;
3007                 d->gtk_widget_style_get (gtkMenubarItem, "selected-shadow-type", &shadowType, NULL);
3008                 gtkPainter.paintBox(gtkMenubarItem, "menuitem",  option->rect.adjusted(0, 0, 0, 3),
3009                                     GTK_STATE_PRELIGHT, shadowType, gtkMenubarItem->style);
3010                 //draw text
3011                 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
3012                 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
3013
3014                 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
3015                     alignment |= Qt::TextHideMnemonic;
3016
3017                 proxy()->drawItemText(painter, item.rect, alignment, item.palette, mbi->state & State_Enabled, mbi->text, textRole);
3018             }
3019         }
3020         painter->restore();
3021         break;
3022
3023     case CE_Splitter: {
3024         GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
3025         gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE,
3026                                 !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
3027                                 style);
3028     }
3029     break;
3030
3031 #ifndef QT_NO_TOOLBAR
3032
3033     case CE_ToolBar:
3034         if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
3035             // Reserve the beveled appearance only for mainwindow toolbars
3036             if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
3037                 break;
3038
3039             QRect rect = option->rect;
3040             // There is a 1 pixel gap between toolbar lines in some styles (i.e Human)
3041             if (toolbar->positionWithinLine != QStyleOptionToolBar::End)
3042                 rect.adjust(0, 0, 1, 0);
3043
3044             GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
3045             GtkShadowType shadow_type = GTK_SHADOW_NONE;
3046             d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
3047             gtkPainter.paintBox( gtkToolbar, "toolbar",  rect,
3048                                  GTK_STATE_NORMAL, shadow_type, gtkToolbar->style);
3049         }
3050         break;
3051
3052 #endif // QT_NO_TOOLBAR
3053
3054     case CE_MenuItem:
3055         painter->save();
3056
3057         // Draws one item in a popup menu.
3058         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3059             const int windowsItemFrame        =  2; // menu item frame width
3060             const int windowsItemHMargin      =  3; // menu item hor text margin
3061             const int windowsItemVMargin      = 26; // menu item ver text margin
3062             const int windowsRightBorder      = 15; // right border on windows
3063             GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget("GtkMenu.GtkCheckMenuItem") :
3064                                      d->gtkWidget("GtkMenu.GtkMenuItem");
3065
3066             style = gtkPainter.getStyle(gtkMenuItem);
3067             QColor shadow = option->palette.dark().color();
3068
3069             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
3070                 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
3071                 painter->setPen(shadow.lighter(106));
3072                 gboolean wide_separators = 0;
3073                 gint     separator_height = 0;
3074                 guint    horizontal_padding = 3;
3075                 QRect separatorRect = option->rect;
3076                 if (!d->gtk_check_version(2, 10, 0)) {
3077                     d->gtk_widget_style_get(gtkMenuSeparator,
3078                                            "wide-separators",    &wide_separators,
3079                                            "separator-height",   &separator_height,
3080                                            "horizontal-padding", &horizontal_padding,
3081                                            NULL);
3082                 }
3083                 separatorRect.setHeight(option->rect.height() - 2 * gtkMenuSeparator->style->ythickness);
3084                 separatorRect.setWidth(option->rect.width() - 2 * (horizontal_padding + gtkMenuSeparator->style->xthickness));
3085                 separatorRect.moveCenter(option->rect.center());
3086                 if (wide_separators)
3087                    gtkPainter.paintBox( gtkMenuSeparator, "hseparator",
3088                                         separatorRect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, gtkMenuSeparator->style);
3089                 else
3090                     gtkPainter.paintHline( gtkMenuSeparator, "hseparator",
3091                                            separatorRect, GTK_STATE_NORMAL, gtkMenuSeparator->style,
3092                                            0, option->rect.right() - 1, 1);
3093                 painter->restore();
3094                 break;
3095             }
3096
3097             bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
3098
3099             if (selected) {
3100                 QRect rect = option->rect;
3101 #ifndef QT_NO_COMBOBOX
3102                 if (qobject_cast<const QComboBox*>(widget))
3103                     rect = option->rect;
3104 #endif
3105                 gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style);
3106             }
3107
3108             bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
3109             bool checked = menuItem->checked;
3110             bool enabled = menuItem->state & State_Enabled;
3111             bool ignoreCheckMark = false;
3112
3113             gint checkSize;
3114             d->gtk_widget_style_get(d->gtkWidget("GtkMenu.GtkCheckMenuItem"), "indicator-size", &checkSize, NULL);
3115
3116             int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize));
3117
3118 #ifndef QT_NO_COMBOBOX
3119
3120             if (qobject_cast<const QComboBox*>(widget))
3121                 ignoreCheckMark = true; // Ignore the checkmarks provided by the QComboMenuDelegate
3122
3123 #endif
3124             if (!ignoreCheckMark) {
3125                 // Check
3126                 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - checkSize/2 + 1, checkSize, checkSize);
3127                 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
3128
3129                 if (checkable && menuItem->icon.isNull()) {
3130                     // Some themes such as aero-clone draw slightly outside the paint rect
3131                     int spacing = 1; // ### Consider using gtkCheckBox : "indicator-spacing" instead
3132
3133                     if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
3134                         // Radio button
3135                         GtkShadowType shadow = GTK_SHADOW_OUT;
3136                         GtkStateType state = gtkPainter.gtkState(option);
3137
3138                         if (selected)
3139                             state = GTK_STATE_PRELIGHT;
3140                         if (checked)
3141                             shadow = GTK_SHADOW_IN;
3142
3143                         gtkPainter.setClipRect(checkRect.adjusted(-spacing, -spacing, spacing, spacing));
3144                         gtkPainter.paintOption(gtkMenuItem, checkRect.translated(-spacing, -spacing), state, shadow,
3145                                                gtkMenuItem->style, QLS("option"));
3146                         gtkPainter.setClipRect(QRect());
3147
3148                     } else {
3149                         // Check box
3150                         if (menuItem->icon.isNull()) {
3151                             GtkShadowType shadow = GTK_SHADOW_OUT;
3152                             GtkStateType state = gtkPainter.gtkState(option);
3153
3154                             if (selected)
3155                                 state = GTK_STATE_PRELIGHT;
3156                             if (checked)
3157                                 shadow = GTK_SHADOW_IN;
3158
3159                             gtkPainter.setClipRect(checkRect.adjusted(-spacing, -spacing, -spacing, -spacing));
3160                             gtkPainter.paintCheckbox(gtkMenuItem, checkRect.translated(-spacing, -spacing), state, shadow,
3161                                                      gtkMenuItem->style, QLS("check"));
3162                            gtkPainter.setClipRect(QRect());
3163                         }
3164                     }
3165                 }
3166
3167             } else {
3168                 // Ignore checkmark
3169                 if (menuItem->icon.isNull())
3170                     checkcol = 0;
3171                 else
3172                     checkcol = menuItem->maxIconWidth;
3173             }
3174
3175             bool dis = !(menuItem->state & State_Enabled);
3176             bool act = menuItem->state & State_Selected;
3177             const QStyleOption *opt = option;
3178             const QStyleOptionMenuItem *menuitem = menuItem;
3179             QPainter *p = painter;
3180             QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
3181                                           QRect(menuitem->rect.x() + 3, menuitem->rect.y(),
3182                                                 checkcol, menuitem->rect.height()));
3183
3184             if (!menuItem->icon.isNull()) {
3185                 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
3186
3187                 if (act && !dis)
3188                     mode = QIcon::Active;
3189
3190                 QPixmap pixmap;
3191                 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
3192                 QSize iconSize(smallIconSize, smallIconSize);
3193
3194 #ifndef QT_NO_COMBOBOX
3195                 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
3196                     iconSize = combo->iconSize();
3197
3198 #endif // QT_NO_COMBOBOX
3199                 if (checked)
3200                     pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
3201                 else
3202                     pixmap = menuItem->icon.pixmap(iconSize, mode);
3203
3204                 int pixw = pixmap.width();
3205                 int pixh = pixmap.height();
3206                 QRect pmr(0, 0, pixw, pixh);
3207                 pmr.moveCenter(vCheckRect.center() - QPoint(0, 1));
3208                 painter->setPen(menuItem->palette.text().color());
3209                 if (!ignoreCheckMark && checkable && checked) {
3210                     QStyleOption opt = *option;
3211
3212                     if (act) {
3213                         QColor activeColor = mergedColors(option->palette.background().color(),
3214                                                           option->palette.highlight().color());
3215                         opt.palette.setBrush(QPalette::Button, activeColor);
3216                     }
3217                     opt.state |= State_Sunken;
3218                     opt.rect = vCheckRect;
3219                     proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
3220                 }
3221                 painter->drawPixmap(pmr.topLeft(), pixmap);
3222             }
3223
3224             GdkColor gdkText = gtkMenuItem->style->fg[GTK_STATE_NORMAL];
3225             GdkColor gdkDText = gtkMenuItem->style->fg[GTK_STATE_INSENSITIVE];
3226             GdkColor gdkHText = gtkMenuItem->style->fg[GTK_STATE_PRELIGHT];
3227             uint resolve_mask = option->palette.resolve();
3228             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
3229             QColor disabledTextColor = QColor(gdkDText.red>>8, gdkDText.green>>8, gdkDText.blue>>8);
3230             if (resolve_mask & (1 << QPalette::ButtonText)) {
3231                 textColor = option->palette.buttonText().color();
3232                 disabledTextColor = option->palette.brush(QPalette::Disabled, QPalette::ButtonText).color();
3233             }
3234
3235             QColor highlightedTextColor = QColor(gdkHText.red>>8, gdkHText.green>>8, gdkHText.blue>>8);
3236             if (resolve_mask & (1 << QPalette::HighlightedText)) {
3237                 highlightedTextColor = option->palette.highlightedText().color();
3238             }
3239
3240             if (selected)
3241                 painter->setPen(highlightedTextColor);
3242             else
3243                 painter->setPen(textColor);
3244
3245             int x, y, w, h;
3246             menuitem->rect.getRect(&x, &y, &w, &h);
3247             int tab = menuitem->tabWidth;
3248             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
3249             int xpos = menuitem->rect.x() + xm + 1;
3250             QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
3251             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
3252             QString s = menuitem->text;
3253
3254             if (!s.isEmpty()) { // Draw text
3255                 p->save();
3256                 int t = s.indexOf(QLatin1Char('\t'));
3257                 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
3258
3259                 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
3260                     text_flags |= Qt::TextHideMnemonic;
3261
3262                 // Draw shortcut right aligned
3263                 text_flags |= Qt::AlignRight;
3264
3265                 if (t >= 0) {
3266                     int rightMargin = 12; // Hardcode for now
3267                     QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
3268                                                      QRect(textRect.topRight(), QPoint(menuitem->rect.right() - rightMargin, textRect.bottom())));
3269
3270                     if (dis)
3271                         p->setPen(disabledTextColor);
3272                     p->drawText(vShortcutRect, text_flags , s.mid(t + 1));
3273                     s = s.left(t);
3274                 }
3275
3276                 text_flags &= ~Qt::AlignRight;
3277                 text_flags |= Qt::AlignLeft;
3278                 QFont font = menuitem->font;
3279                 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
3280                     font.setBold(true);
3281                 p->setFont(font);
3282
3283                 if (dis)
3284                     p->setPen(disabledTextColor);
3285                 p->drawText(vTextRect, text_flags, s.left(t));
3286                 p->restore();
3287             }
3288
3289             // Arrow
3290             if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
3291
3292                 QFontMetrics fm(menuitem->font);
3293                 int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
3294                 gfloat arrow_scaling = 0.8;
3295                 int extra = 0;
3296                 if (!d->gtk_check_version(2, 16, 0)) {
3297                     // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c)
3298                     // though the current documentation states otherwise
3299                     d->gtk_widget_style_get(gtkMenuItem, "arrow-scaling", &arrow_scaling, NULL);
3300                     // in versions < 2.16 ythickness was previously subtracted from the arrow_size
3301                     extra = 2 * gtkMenuItem->style->ythickness;
3302                 }
3303
3304                 int horizontal_padding;
3305                 d->gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL);
3306
3307                 const int dim = static_cast<int>(arrow_size * arrow_scaling) + extra;
3308                 int xpos = menuItem->rect.left() + menuItem->rect.width() - horizontal_padding - dim;
3309                 QRect  vSubMenuRect = visualRect(option->direction, menuItem->rect,
3310                                                  QRect(xpos, menuItem->rect.top() +
3311                                                        menuItem->rect.height() / 2 - dim / 2, dim, dim));
3312                 GtkStateType state = enabled ? (act ? GTK_STATE_PRELIGHT: GTK_STATE_NORMAL) : GTK_STATE_INSENSITIVE;
3313                 GtkShadowType shadowType = (state == GTK_STATE_PRELIGHT) ? GTK_SHADOW_OUT : GTK_SHADOW_IN;
3314                 gtkPainter.paintArrow(gtkMenuItem, "menuitem", vSubMenuRect, QApplication::isRightToLeft() ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT, state,
3315                                       shadowType, false, style);
3316             }
3317         }
3318         painter->restore();
3319         break;
3320
3321     case CE_PushButton:
3322         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
3323             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
3324             proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
3325             QStyleOptionButton subopt = *btn;
3326             subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
3327             gint interiorFocus = true;
3328             d->gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL);
3329             int xt = interiorFocus ? gtkButton->style->xthickness : 0;
3330             int yt = interiorFocus ? gtkButton->style->ythickness : 0;
3331
3332             if (btn->features & QStyleOptionButton::Flat && btn->state & State_HasFocus)
3333                 // The normal button focus rect does not work well for flat buttons in Clearlooks
3334                 proxy()->drawPrimitive(PE_FrameFocusRect, option, painter, widget);
3335             else if (btn->state & State_HasFocus)
3336                 gtkPainter.paintFocus(gtkButton, "button",
3337                                       option->rect.adjusted(xt, yt, -xt, -yt),
3338                                       btn->state & State_Sunken ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL,
3339                                       gtkButton->style);
3340
3341             proxy()->drawControl(CE_PushButtonLabel, &subopt, painter, widget);
3342         }
3343         break;
3344
3345 #ifndef QT_NO_TABBAR
3346
3347     case CE_TabBarTabShape:
3348         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
3349             GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
3350             style = gtkPainter.getStyle(gtkNotebook);
3351
3352             QRect rect = option->rect;
3353             GtkShadowType shadow = GTK_SHADOW_OUT;
3354             GtkStateType state = GTK_STATE_ACTIVE;
3355             if (tab->state & State_Selected)
3356                 state = GTK_STATE_NORMAL;
3357
3358             bool selected = (tab->state & State_Selected);
3359             bool first = false, last = false;
3360             if (widget) {
3361                 // This is most accurate and avoids resizing tabs while moving
3362                 first = tab->rect.left() == widget->rect().left();
3363                 last = tab->rect.right() == widget->rect().right();
3364             } else if (option->direction == Qt::RightToLeft) {
3365                 bool tmp = first;
3366                 first = last;
3367                 last = tmp;
3368             }
3369             int topIndent = 3;
3370             int bottomIndent = 1;
3371             int tabOverlap = 1;
3372             painter->save();
3373
3374             switch (tab->shape) {
3375             case QTabBar::RoundedNorth:
3376                 if (!selected)
3377                     rect.adjust(first ? 0 : -tabOverlap, topIndent, last ? 0 : tabOverlap, -bottomIndent);
3378                 gtkPainter.paintExtention( gtkNotebook, "tab", rect,
3379                                            state, shadow, GTK_POS_BOTTOM, style);
3380                 break;
3381
3382             case QTabBar::RoundedSouth:
3383                 if (!selected)
3384                     rect.adjust(first ? 0 : -tabOverlap, 0, last ? 0 : tabOverlap, -topIndent);
3385                 gtkPainter.paintExtention( gtkNotebook, "tab", rect.adjusted(0, 1, 0, 0),
3386                                            state, shadow, GTK_POS_TOP, style);
3387                 break;
3388
3389             case QTabBar::RoundedWest:
3390                 if (!selected)
3391                     rect.adjust(topIndent, 0, -bottomIndent, 0);
3392                 gtkPainter.paintExtention( gtkNotebook, "tab", rect, state, shadow, GTK_POS_RIGHT, style);
3393                 break;
3394
3395             case QTabBar::RoundedEast:
3396                 if (!selected)
3397                     rect.adjust(bottomIndent, 0, -topIndent, 0);
3398                 gtkPainter.paintExtention( gtkNotebook, "tab", rect, state, shadow, GTK_POS_LEFT, style);
3399                 break;
3400
3401             default:
3402                 QWindowsStyle::drawControl(element, option, painter, widget);
3403                 break;
3404             }
3405
3406             painter->restore();
3407         }
3408
3409         break;
3410
3411 #endif //QT_NO_TABBAR
3412
3413     case CE_ProgressBarGroove:
3414         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
3415             Q_UNUSED(bar);
3416             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
3417             GtkStateType state = gtkPainter.gtkState(option);
3418             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style);
3419         }
3420
3421         break;
3422
3423     case CE_ProgressBarContents:
3424         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
3425             GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE;
3426             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
3427             style = gtkProgressBar->style;
3428             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, style);
3429             int xt = style->xthickness;
3430             int yt = style->ythickness;
3431             QRect rect = bar->rect.adjusted(xt, yt, -xt, -yt);
3432             bool vertical = false;
3433             bool inverted = false;
3434             bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
3435             // Get extra style options if version 2
3436
3437             if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
3438                 vertical = (bar2->orientation == Qt::Vertical);
3439                 inverted = bar2->invertedAppearance;
3440             }
3441
3442             // If the orientation is vertical, we use a transform to rotate
3443             // the progress bar 90 degrees clockwise.  This way we can use the
3444             // same rendering code for both orientations.
3445             if (vertical) {
3446                 rect.translate(xt, -yt * 2);
3447                 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // Flip width and height
3448                 QTransform m = QTransform::fromTranslate(rect.height(), 0);
3449                 m.rotate(90.0);
3450                 painter->setTransform(m);
3451             }
3452
3453             int maxWidth = rect.width();
3454             int minWidth = 4;
3455
3456             qint64 progress = (qint64)qMax(bar->progress, bar->minimum); // Workaround for bug in QProgressBar
3457             double vc6_workaround = ((progress - qint64(bar->minimum)) / double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth;
3458             int progressBarWidth = (int(vc6_workaround) > minWidth ) ? int(vc6_workaround) : minWidth;
3459             int width = indeterminate ? maxWidth : progressBarWidth;
3460             bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
3461
3462             if (inverted)
3463                 reverse = !reverse;
3464
3465             int maximum = 2;
3466             int fakePos = 0;
3467             if (bar->minimum == bar->maximum)
3468                 maximum = 0;
3469             if (bar->progress == bar->maximum)
3470                 fakePos = maximum;
3471             else if (bar->progress > bar->minimum)
3472                 fakePos = maximum - 1;
3473
3474             d->gtk_progress_configure((GtkProgress*)gtkProgressBar, fakePos, 0, maximum);
3475
3476             QRect progressBar;
3477
3478             if (!indeterminate) {
3479                 if (!reverse)
3480                     progressBar.setRect(rect.left(), rect.top(), width, rect.height());
3481                 else
3482                     progressBar.setRect(rect.right() - width, rect.top(), width, rect.height());
3483
3484             } else {
3485                 Q_D(const QGtkStyle);
3486                 int slideWidth = ((rect.width() - 4) * 2) / 3;
3487                 int step = ((d->animateStep * slideWidth) / d->animationFps) % slideWidth;
3488                 if ((((d->animateStep * slideWidth) / d->animationFps) % (2 * slideWidth)) >= slideWidth)
3489                     step = slideWidth - step;
3490                 progressBar.setRect(rect.left() + step, rect.top(), slideWidth / 2, rect.height());
3491             }
3492
3493             QString key = QString(QLS("%0")).arg(fakePos);
3494             if (inverted) {
3495                 key += QLatin1String("inv");
3496                 gtkPainter.setFlipHorizontal(true);
3497             }
3498             gtkPainter.paintBox( gtkProgressBar, "bar",  progressBar, GTK_STATE_SELECTED, GTK_SHADOW_OUT, style, key);
3499         }
3500
3501         break;
3502
3503     default:
3504         QWindowsStyle::drawControl(element, option, painter, widget);
3505     }
3506 }
3507
3508 /*!
3509   \reimp
3510 */
3511 QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
3512                                 SubControl subControl, const QWidget *widget) const
3513 {
3514     Q_D(const QGtkStyle);
3515
3516     QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
3517     if (!d->isThemeAvailable())
3518         return QWindowsStyle::subControlRect(control, option, subControl, widget);
3519
3520     switch (control) {
3521     case CC_ScrollBar:
3522         break;
3523     case CC_Slider:
3524         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3525             int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3526             switch (subControl) {
3527             case SC_SliderHandle: {
3528                 if (slider->orientation == Qt::Horizontal) {
3529                     rect.setHeight(proxy()->pixelMetric(PM_SliderThickness));
3530                     rect.setWidth(proxy()->pixelMetric(PM_SliderLength));
3531                     int centerY = slider->rect.center().y() - rect.height() / 2;
3532                     if (slider->tickPosition & QSlider::TicksAbove)
3533                         centerY += tickSize;
3534                     if (slider->tickPosition & QSlider::TicksBelow)
3535                         centerY -= tickSize;
3536                     rect.moveTop(centerY);
3537                 } else {
3538                     rect.setWidth(proxy()->pixelMetric(PM_SliderThickness));
3539                     rect.setHeight(proxy()->pixelMetric(PM_SliderLength));
3540                     int centerX = slider->rect.center().x() - rect.width() / 2;
3541                     if (slider->tickPosition & QSlider::TicksAbove)
3542                         centerX += tickSize;
3543                     if (slider->tickPosition & QSlider::TicksBelow)
3544                         centerX -= tickSize;
3545                     rect.moveLeft(centerX);
3546                 }
3547             }
3548                 break;
3549             case SC_SliderGroove: {
3550                 QPoint grooveCenter = slider->rect.center();
3551                 if (slider->orientation == Qt::Horizontal) {
3552                     rect.setHeight(7);
3553                     if (slider->tickPosition & QSlider::TicksAbove)
3554                         grooveCenter.ry() += tickSize;
3555                     if (slider->tickPosition & QSlider::TicksBelow)
3556                         grooveCenter.ry() -= tickSize;
3557                 } else {
3558                     rect.setWidth(7);
3559                     if (slider->tickPosition & QSlider::TicksAbove)
3560                         grooveCenter.rx() += tickSize;
3561                     if (slider->tickPosition & QSlider::TicksBelow)
3562                         grooveCenter.rx() -= tickSize;
3563                 }
3564                 rect.moveCenter(grooveCenter);
3565                 break;
3566             }
3567             default:
3568                 break;
3569             }
3570         }
3571         break;
3572
3573 #ifndef QT_NO_GROUPBOX
3574
3575     case CC_GroupBox:
3576         if (qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
3577             rect = option->rect.adjusted(0, groupBoxTopMargin, 0, -groupBoxBottomMargin);
3578             int topMargin = 0;
3579             int topHeight = 0;
3580             topHeight = 10;
3581             QRect frameRect = rect;
3582             frameRect.setTop(topMargin);
3583
3584             if (subControl == SC_GroupBoxFrame)
3585                 return rect;
3586             else if (subControl == SC_GroupBoxContents) {
3587                 int margin = 0;
3588                 int leftMarginExtension = 8;
3589                 return frameRect.adjusted(leftMarginExtension + margin, margin + topHeight + groupBoxTitleMargin, -margin, -margin);
3590             }
3591
3592             if (const QGroupBox *groupBoxWidget = qobject_cast<const QGroupBox *>(widget)) {
3593                 //Prepare metrics for a bold font
3594                 QFont font = widget->font();
3595                 font.setBold(true);
3596                 QFontMetrics fontMetrics(font);
3597                 QSize textRect = fontMetrics.boundingRect(groupBoxWidget->title()).size() + QSize(4, 4);
3598                 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
3599                 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget);
3600
3601                 if (subControl == SC_GroupBoxCheckBox) {
3602                     rect.setWidth(indicatorWidth);
3603                     rect.setHeight(indicatorHeight);
3604                     rect.moveTop((textRect.height() - indicatorHeight) / 2);
3605
3606                 } else if (subControl == SC_GroupBoxLabel) {
3607                     if (groupBoxWidget->isCheckable())
3608                         rect.adjust(indicatorWidth + 4, 0, 0, 0);
3609                     rect.setSize(textRect);
3610                 }
3611                 rect = visualRect(option->direction, option->rect, rect);
3612             }
3613         }
3614
3615         return rect;
3616
3617 #endif
3618 #ifndef QT_NO_SPINBOX
3619
3620     case CC_SpinBox:
3621         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
3622             GtkWidget *gtkSpinButton = d->gtkWidget("GtkSpinButton");
3623             int center = spinbox->rect.height() / 2;
3624             int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0;
3625             int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0;
3626             int y = yt;
3627
3628             QSize bs;
3629             bs.setHeight(qMax(8, spinbox->rect.height()/2 - y));
3630             bs.setWidth(d->getSpinboxArrowSize());
3631             int x, lx, rx;
3632             x = spinbox->rect.width() - y - bs.width() + 2;
3633             lx = xt;
3634             rx = x - xt;
3635
3636             switch (subControl) {
3637
3638             case SC_SpinBoxUp:
3639                 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3640                     return QRect();
3641                 rect = QRect(x, xt, bs.width(), center - yt);
3642                 break;
3643
3644             case SC_SpinBoxDown:
3645                 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3646                     return QRect();
3647                 rect = QRect(x, center, bs.width(), spinbox->rect.bottom() - center - yt + 1);
3648                 break;
3649
3650             case SC_SpinBoxEditField:
3651                 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3652                     rect = QRect(lx, yt, spinbox->rect.width() - 2*xt, spinbox->rect.height() - 2*yt);
3653                 else
3654                     rect = QRect(lx, yt, rx - qMax(xt - 1, 0), spinbox->rect.height() - 2*yt);
3655                 break;
3656
3657             case SC_SpinBoxFrame:
3658                 rect = spinbox->rect;
3659
3660             default:
3661                 break;
3662             }
3663
3664             rect = visualRect(spinbox->direction, spinbox->rect, rect);
3665         }
3666
3667         break;
3668
3669 #endif // Qt_NO_SPINBOX
3670 #ifndef QT_NO_COMBOBOX
3671
3672     case CC_TitleBar:
3673     if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
3674         SubControl sc = subControl;
3675         QRect &ret = rect;
3676         const int indent = 3;
3677         const int controlTopMargin = 3;
3678         const int controlBottomMargin = 3;
3679         const int controlWidthMargin = 2;
3680         const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin ;
3681         const int delta = controlHeight + controlWidthMargin;
3682         int offset = 0;
3683
3684         bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
3685         bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
3686
3687         switch (sc) {
3688         case SC_TitleBarLabel:
3689             if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
3690                 ret = tb->rect;
3691                 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3692                     ret.adjust(delta, 0, -delta, 0);
3693                 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3694                     ret.adjust(0, 0, -delta, 0);
3695                 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3696                     ret.adjust(0, 0, -delta, 0);
3697                 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
3698                     ret.adjust(0, 0, -delta, 0);
3699                 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3700                     ret.adjust(0, 0, -delta, 0);
3701             }
3702             break;
3703         case SC_TitleBarContextHelpButton:
3704             if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3705                 offset += delta;
3706         case SC_TitleBarMinButton:
3707             if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3708                 offset += delta;
3709             else if (sc == SC_TitleBarMinButton)
3710                 break;
3711         case SC_TitleBarNormalButton:
3712             if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3713                 offset += delta;
3714             else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3715                 offset += delta;
3716             else if (sc == SC_TitleBarNormalButton)
3717                 break;
3718         case SC_TitleBarMaxButton:
3719             if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3720                 offset += delta;
3721             else if (sc == SC_TitleBarMaxButton)
3722                 break;
3723         case SC_TitleBarShadeButton:
3724             if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3725                 offset += delta;
3726             else if (sc == SC_TitleBarShadeButton)
3727                 break;
3728         case SC_TitleBarUnshadeButton:
3729             if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3730                 offset += delta;
3731             else if (sc == SC_TitleBarUnshadeButton)
3732                 break;
3733         case SC_TitleBarCloseButton:
3734             if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3735                 offset += delta;
3736             else if (sc == SC_TitleBarCloseButton)
3737                 break;
3738             ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
3739                         controlHeight, controlHeight);
3740             break;
3741         case SC_TitleBarSysMenu:
3742             if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3743                 ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
3744                             controlHeight, controlHeight);
3745             }
3746             break;
3747         default:
3748             break;
3749         }
3750         ret = visualRect(tb->direction, tb->rect, ret);
3751     }
3752     break;
3753     case CC_ComboBox:
3754         if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3755             // We employ the gtk widget to position arrows and separators for us
3756             GtkWidget *gtkCombo = box->editable ? d->gtkWidget("GtkComboBoxEntry")
3757                                                 : d->gtkWidget("GtkComboBox");
3758             d->gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
3759             GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())};
3760             d->gtk_widget_size_allocate(gtkCombo, &geometry);
3761             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget);
3762             QHashableLatin1Literal arrowPath("GtkComboBoxEntry.GtkToggleButton");
3763             if (!box->editable) {
3764                 if (appears_as_list)
3765                     arrowPath = "GtkComboBox.GtkToggleButton";
3766                 else
3767                     arrowPath = "GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow";
3768             }
3769
3770             GtkWidget *arrowWidget = d->gtkWidget(arrowPath);
3771             if (!arrowWidget)
3772                 return QWindowsStyle::subControlRect(control, option, subControl, widget);
3773
3774             GtkAllocation allocation;
3775             d->gtk_widget_get_allocation(arrowWidget, &allocation);
3776             QRect buttonRect(option->rect.left() + allocation.x,
3777                              option->rect.top() + allocation.y,
3778                              allocation.width, allocation.height);
3779
3780             switch (subControl) {
3781
3782             case SC_ComboBoxArrow: // Note: this indicates the arrowbutton for editable combos
3783                 rect = buttonRect;
3784                 break;
3785
3786             case SC_ComboBoxEditField: {
3787                 rect = visualRect(option->direction, option->rect, rect);
3788                 int xMargin = box->editable ? 1 : 4, yMargin = 2;
3789                 rect.setRect(option->rect.left() + gtkCombo->style->xthickness + xMargin,
3790                              option->rect.top()  + gtkCombo->style->ythickness + yMargin,
3791                              option->rect.width() - buttonRect.width() - 2*(gtkCombo->style->xthickness + xMargin),
3792                              option->rect.height() - 2*(gtkCombo->style->ythickness + yMargin));
3793                 rect = visualRect(option->direction, option->rect, rect);
3794                 break;
3795             }
3796
3797             default:
3798                 break;
3799             }
3800         }
3801
3802         break;
3803 #endif // QT_NO_COMBOBOX
3804
3805     default:
3806         break;
3807     }
3808
3809     return rect;
3810 }
3811
3812 /*!
3813   \reimp
3814 */
3815 QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
3816                                   const QSize &size, const QWidget *widget) const
3817 {
3818     Q_D(const QGtkStyle);
3819
3820     QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
3821     if (!d->isThemeAvailable())
3822         return newSize;
3823
3824     switch (type) {
3825     case CT_GroupBox:
3826         // Since we use a bold font we have to recalculate base width
3827         if (const QGroupBox *gb = qobject_cast<const QGroupBox*>(widget)) {
3828             QFont font = gb->font();
3829             font.setBold(true);
3830             QFontMetrics metrics(font);
3831             int baseWidth = metrics.width(gb->title()) + metrics.width(QLatin1Char(' '));
3832             if (gb->isCheckable()) {
3833                 baseWidth += proxy()->pixelMetric(QStyle::PM_IndicatorWidth, option, widget);
3834                 baseWidth += proxy()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, option, widget);
3835             }
3836             newSize.setWidth(qMax(baseWidth, newSize.width()));
3837         }
3838         newSize += QSize(4, 1 + groupBoxBottomMargin + groupBoxTopMargin + groupBoxTitleMargin); // Add some space below the groupbox
3839         break;
3840     case CT_ToolButton:
3841         if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
3842             GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
3843             newSize = size + QSize(2 * gtkButton->style->xthickness, 2 + 2 * gtkButton->style->ythickness);
3844             if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
3845                 QSize minSize(0, 25);
3846                 if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
3847                     minSize = toolbutton->iconSize + QSize(12, 12);
3848                 newSize = newSize.expandedTo(minSize);
3849             }
3850
3851             if (toolbutton->features & QStyleOptionToolButton::HasMenu)
3852                 newSize += QSize(6, 0);
3853         }
3854         break;
3855     case CT_MenuItem:
3856         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3857             int textMargin = 8;
3858
3859             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
3860                 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
3861                 GtkRequisition sizeReq = {0, 0};
3862                 d->gtk_widget_size_request(gtkMenuSeparator, &sizeReq);
3863                 newSize = QSize(size.width(), sizeReq.height);
3864                 break;
3865             }
3866
3867             GtkWidget *gtkMenuItem = d->gtkWidget("GtkMenu.GtkCheckMenuItem");
3868             GtkStyle* style = gtkMenuItem->style;
3869
3870             // Note we get the perfect height for the default font since we
3871             // set a fake text label on the gtkMenuItem
3872             // But if custom fonts are used on the widget we need a minimum size
3873             GtkRequisition sizeReq = {0, 0};
3874             d->gtk_widget_size_request(gtkMenuItem, &sizeReq);
3875             newSize.setHeight(qMax(newSize.height() - 4, sizeReq.height));
3876             newSize += QSize(textMargin + style->xthickness - 1, 0);
3877
3878             gint checkSize;
3879             d->gtk_widget_style_get(gtkMenuItem, "indicator-size", &checkSize, NULL);
3880             newSize.setWidth(newSize.width() + qMax(0, checkSize - 20));
3881         }
3882         break;
3883     case CT_SpinBox:
3884         // QSpinBox does some nasty things that depends on CT_LineEdit
3885         newSize = size + QSize(0, -d->gtkWidget("GtkSpinButton")->style->ythickness * 2);
3886         break;
3887     case CT_RadioButton:
3888     case CT_CheckBox:
3889         newSize += QSize(0, 1);
3890         break;
3891     case CT_PushButton:
3892         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
3893             if (!btn->icon.isNull() && btn->iconSize.height() > 16)
3894                 newSize -= QSize(0, 2); // From cleanlooksstyle
3895             newSize += QSize(0, 1);
3896             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
3897             gint focusPadding, focusWidth;
3898             d->gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL);
3899             d->gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL);
3900             newSize = size;
3901             newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness);
3902             newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding));
3903
3904             GtkWidget *gtkButtonBox = d->gtkWidget("GtkHButtonBox");
3905             gint minWidth = 85, minHeight = 0;
3906             d->gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth,
3907                                    "child-min-height", &minHeight, NULL);
3908             if (!btn->text.isEmpty() && newSize.width() < minWidth)
3909                 newSize.setWidth(minWidth);
3910             if (newSize.height() < minHeight)
3911                 newSize.setHeight(minHeight);
3912         }
3913         break;
3914     case CT_Slider: {
3915         GtkWidget *gtkSlider = d->gtkWidget("GtkHScale");
3916         newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness); }
3917         break;
3918     case CT_LineEdit: {
3919         GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
3920         newSize = size + QSize(2*gtkEntry->style->xthickness, 2 + 2*gtkEntry->style->ythickness); }
3921         break;
3922     case CT_ItemViewItem:
3923         newSize += QSize(0, 2);
3924         break;
3925     case CT_ComboBox:
3926         if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3927             GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
3928             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget);
3929             newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
3930
3931             if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
3932                 newSize += QSize(0, 2);
3933         }
3934         break;
3935     case CT_TabBarTab:
3936         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
3937             if (!tab->icon.isNull())
3938                 newSize += QSize(6, 0);
3939         }
3940         newSize += QSize(1, 1);
3941         break;
3942     case CT_MenuBarItem:
3943         newSize += QSize(0, 2);
3944         break;
3945     case CT_SizeGrip:
3946         newSize += QSize(4, 4);
3947         break;
3948     case CT_MdiControls:
3949         if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(option)) {
3950             int width = 0;
3951             if (styleOpt->subControls & SC_MdiMinButton)
3952                 width += 19 + 1;
3953             if (styleOpt->subControls & SC_MdiNormalButton)
3954                 width += 19 + 1;
3955             if (styleOpt->subControls & SC_MdiCloseButton)
3956                 width += 19 + 1;
3957             newSize = QSize(width, 19);
3958         } else {
3959             newSize = QSize(60, 19);
3960         }
3961     break;
3962     default:
3963         break;
3964     }
3965
3966     return newSize;
3967 }
3968
3969
3970 /*! \reimp */
3971 QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
3972                                   const QWidget *widget) const
3973 {
3974     Q_D(const QGtkStyle);
3975
3976     if (!d->isThemeAvailable())
3977         return QWindowsStyle::standardPixmap(sp, option, widget);
3978
3979     QPixmap pixmap;
3980     switch (sp) {
3981
3982     case SP_TitleBarNormalButton: {
3983         QImage restoreButton((const char **)dock_widget_restore_xpm);
3984         QColor alphaCorner = restoreButton.color(2);
3985         alphaCorner.setAlpha(80);
3986         restoreButton.setColor(2, alphaCorner.rgba());
3987         alphaCorner.setAlpha(180);
3988         restoreButton.setColor(4, alphaCorner.rgba());
3989         return QPixmap::fromImage(restoreButton);
3990     }
3991     break;
3992
3993     case SP_TitleBarCloseButton: // Fall through
3994     case SP_DockWidgetCloseButton: {
3995
3996         QImage closeButton((const char **)dock_widget_close_xpm);
3997         QColor alphaCorner = closeButton.color(2);
3998         alphaCorner.setAlpha(80);
3999         closeButton.setColor(2, alphaCorner.rgba());
4000         return QPixmap::fromImage(closeButton);
4001     }
4002     break;
4003
4004     case SP_DialogDiscardButton:
4005         return QGtkPainter::getIcon(GTK_STOCK_DELETE);
4006     case SP_DialogOkButton:
4007         return QGtkPainter::getIcon(GTK_STOCK_OK);
4008     case SP_DialogCancelButton:
4009         return QGtkPainter::getIcon(GTK_STOCK_CANCEL);
4010     case SP_DialogYesButton:
4011         return QGtkPainter::getIcon(GTK_STOCK_YES);
4012     case SP_DialogNoButton:
4013         return QGtkPainter::getIcon(GTK_STOCK_NO);
4014     case SP_DialogOpenButton:
4015         return QGtkPainter::getIcon(GTK_STOCK_OPEN);
4016     case SP_DialogCloseButton:
4017         return QGtkPainter::getIcon(GTK_STOCK_CLOSE);
4018     case SP_DialogApplyButton:
4019         return QGtkPainter::getIcon(GTK_STOCK_APPLY);
4020     case SP_DialogSaveButton:
4021         return QGtkPainter::getIcon(GTK_STOCK_SAVE);
4022     case SP_MessageBoxWarning:
4023         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
4024     case SP_MessageBoxQuestion:
4025         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
4026     case SP_MessageBoxInformation:
4027         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
4028     case SP_MessageBoxCritical:
4029         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
4030     default:
4031         return QWindowsStyle::standardPixmap(sp, option, widget);
4032     }
4033     return pixmap;
4034 }
4035
4036 /*!
4037     \reimp
4038 */
4039 QIcon QGtkStyle::standardIcon(StandardPixmap standardIcon,
4040                               const QStyleOption *option,
4041                               const QWidget *widget) const
4042 {
4043     Q_D(const QGtkStyle);
4044
4045     if (!d->isThemeAvailable())
4046         return QWindowsStyle::standardIcon(standardIcon, option, widget);
4047     switch (standardIcon) {
4048     case SP_DialogDiscardButton:
4049         return QGtkPainter::getIcon(GTK_STOCK_DELETE);
4050     case SP_DialogOkButton:
4051         return QGtkPainter::getIcon(GTK_STOCK_OK);
4052     case SP_DialogCancelButton:
4053         return QGtkPainter::getIcon(GTK_STOCK_CANCEL);
4054     case SP_DialogYesButton:
4055         return QGtkPainter::getIcon(GTK_STOCK_YES);
4056     case SP_DialogNoButton:
4057         return QGtkPainter::getIcon(GTK_STOCK_NO);
4058     case SP_DialogOpenButton:
4059         return QGtkPainter::getIcon(GTK_STOCK_OPEN);
4060     case SP_DialogCloseButton:
4061         return QGtkPainter::getIcon(GTK_STOCK_CLOSE);
4062     case SP_DialogApplyButton:
4063         return QGtkPainter::getIcon(GTK_STOCK_APPLY);
4064     case SP_DialogSaveButton:
4065         return QGtkPainter::getIcon(GTK_STOCK_SAVE);
4066     case SP_MessageBoxWarning:
4067         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
4068     case SP_MessageBoxQuestion:
4069         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
4070     case SP_MessageBoxInformation:
4071         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
4072     case SP_MessageBoxCritical:
4073         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
4074     default:
4075         return QWindowsStyle::standardIcon(standardIcon, option, widget);
4076     }
4077 }
4078
4079
4080 /*! \reimp */
4081 QRect QGtkStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
4082 {
4083     Q_D(const QGtkStyle);
4084
4085     QRect r = QWindowsStyle::subElementRect(element, option, widget);
4086     if (!d->isThemeAvailable())
4087         return r;
4088
4089     switch (element) {
4090     case SE_PushButtonFocusRect:
4091         r.adjust(0, 1, 0, -1);
4092         break;
4093     case SE_DockWidgetTitleBarText: {
4094         const QStyleOptionDockWidgetV2 *v2
4095             = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(option);
4096         bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
4097         if (verticalTitleBar) {
4098             r.adjust(0, 0, 0, -4);
4099         } else {
4100             if (option->direction == Qt::LeftToRight)
4101                 r.adjust(4, 0, 0, 0);
4102             else
4103                 r.adjust(0, 0, -4, 0);
4104         }
4105
4106         break;
4107     }
4108     case SE_ProgressBarLabel:
4109     case SE_ProgressBarContents:
4110     case SE_ProgressBarGroove:
4111         return option->rect;
4112     case SE_PushButtonContents:
4113         if (!d->gtk_check_version(2, 10, 0)) {
4114             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
4115             GtkBorder *border = 0;
4116             d->gtk_widget_style_get(gtkButton, "inner-border", &border, NULL);
4117             if (border) {
4118                 r = option->rect.adjusted(border->left, border->top, -border->right, -border->bottom);
4119                 d->gtk_border_free(border);
4120             } else {
4121                 r = option->rect.adjusted(1, 1, -1, -1);
4122             }
4123             r = visualRect(option->direction, option->rect, r);
4124         }
4125         break;
4126     default:
4127         break;
4128     }
4129
4130     return r;
4131 }
4132
4133 /*!
4134   \reimp
4135 */
4136 QRect QGtkStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
4137 {
4138     return QWindowsStyle::itemPixmapRect(r, flags, pixmap);
4139 }
4140
4141 /*!
4142   \reimp
4143 */
4144 void QGtkStyle::drawItemPixmap(QPainter *painter, const QRect &rect,
4145                             int alignment, const QPixmap &pixmap) const
4146 {
4147     QWindowsStyle::drawItemPixmap(painter, rect, alignment, pixmap);
4148 }
4149
4150 /*!
4151   \reimp
4152 */
4153 QStyle::SubControl QGtkStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
4154                               const QPoint &pt, const QWidget *w) const
4155 {
4156     return QWindowsStyle::hitTestComplexControl(cc, opt, pt, w);
4157 }
4158
4159 /*!
4160   \reimp
4161 */
4162 QPixmap QGtkStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
4163                                         const QStyleOption *opt) const
4164 {
4165     return QWindowsStyle::generatedIconPixmap(iconMode, pixmap, opt);
4166 }
4167
4168 /*!
4169   \reimp
4170 */
4171 void QGtkStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
4172                                     bool enabled, const QString& text, QPalette::ColorRole textRole) const
4173 {
4174     return QWindowsStyle::drawItemText(painter, rect, alignment, pal, enabled, text, textRole);
4175 }
4176
4177 QT_END_NAMESPACE
4178
4179 #endif //!defined(QT_NO_STYLE_QGTK)