1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/***************************************************************************
* Copyright (C) 2015 The Qt Company Ltd. *
* Copyright (C) 2016-2025 Ilya Kotov, forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef QGTKSTYLE_P_P_H
#define QGTKSTYLE_P_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtGlobal>
#if !defined(QT_NO_STYLE_GTK)
#include <QString>
#include <QStringBuilder>
#include <QCoreApplication>
#include <QFileDialog>
#include <QCommonStyle>
#include <private/qcommonstyle_p.h>
#include "qgtkstyle_p.h"
#include "qgtkglobal_p.h"
#define Q_GTK_IS_WIDGET(widget) widget && G_TYPE_CHECK_INSTANCE_TYPE ((widget), gtk_widget_get_type())
QT_BEGIN_NAMESPACE
class QHashableLatin1Literal
{
public:
int size() const { return m_size; }
const char *data() const { return m_data; }
#ifdef __SUNPRO_CC
QHashableLatin1Literal(const char* str)
: m_size(strlen(str)), m_data(str) {}
#else
template <int N>
QHashableLatin1Literal(const char (&str)[N])
: m_size(N - 1), m_data(str) {}
#endif
QHashableLatin1Literal(const QHashableLatin1Literal &other)
: m_size(other.m_size), m_data(other.m_data)
{}
QHashableLatin1Literal &operator=(const QHashableLatin1Literal &other)
{
if (this == &other)
return *this;
*const_cast<int *>(&m_size) = other.m_size;
*const_cast<char **>(&m_data) = const_cast<char *>(other.m_data);
return *this;
}
QString toString() const { return QString::fromLatin1(m_data, m_size); }
static QHashableLatin1Literal fromData(const char *str)
{
return QHashableLatin1Literal(str, qstrlen(str));
}
private:
QHashableLatin1Literal(const char *str, int length)
: m_size(length), m_data(str)
{}
const int m_size;
const char *m_data;
};
bool operator==(const QHashableLatin1Literal &l1, const QHashableLatin1Literal &l2);
inline bool operator!=(const QHashableLatin1Literal &l1, const QHashableLatin1Literal &l2) { return !operator==(l1, l2); }
uint qHash(const QHashableLatin1Literal &key);
QT_END_NAMESPACE
typedef struct _XDisplay Display;
QT_BEGIN_NAMESPACE
class QGtkPainter;
class QGtkStylePrivate;
class QGtkStyleFilter : public QObject
{
public:
QGtkStyleFilter(QGtkStylePrivate* sp)
: stylePrivate(sp)
{}
private:
QGtkStylePrivate* stylePrivate;
bool eventFilter(QObject *obj, QEvent *e) override;
};
class QGtkStylePrivate : public QCommonStylePrivate
{
Q_DECLARE_PUBLIC(QGtkStyle)
public:
QGtkStylePrivate();
~QGtkStylePrivate();
QGtkStyleFilter filter;
static QGtkPainter* gtkPainter(QPainter *painter = nullptr);
static GtkWidget* gtkWidget(const QHashableLatin1Literal &path);
static GtkStyle* gtkStyle(const QHashableLatin1Literal &path = QHashableLatin1Literal("GtkWindow"));
static void gtkWidgetSetFocus(GtkWidget *widget, bool focus);
virtual void initGtkMenu() const;
virtual void initGtkTreeview() const;
virtual void initGtkWidgets() const;
static void cleanupGtkWidgets();
static bool isKDE4Session();
void applyCustomPaletteHash();
static QFont getThemeFont();
static bool isThemeAvailable() { return gtkStyle() != nullptr; }
static QString getThemeName();
virtual int getSpinboxArrowSize() const;
virtual QPalette gtkWidgetPalette(const QHashableLatin1Literal >kWidgetName) const;
protected:
typedef QHash<QHashableLatin1Literal, GtkWidget*> WidgetMap;
static inline void destroyWidgetMap()
{
cleanupGtkWidgets();
delete widgetMap;
widgetMap = nullptr;
}
static inline WidgetMap *gtkWidgetMap()
{
if (!widgetMap) {
widgetMap = new WidgetMap();
qAddPostRoutine(destroyWidgetMap);
}
return widgetMap;
}
static QStringList extract_filter(const QString &rawFilter);
virtual GtkWidget* getTextColorWidget() const;
static void setupGtkWidget(GtkWidget* widget);
static void addWidgetToMap(GtkWidget* widget);
static void addAllSubWidgets(GtkWidget *widget, gpointer v = nullptr);
static void addWidget(GtkWidget *widget);
static void removeWidgetFromMap(const QHashableLatin1Literal &path);
virtual void init();
enum {
menuItemFrame = 2, // menu item frame width
menuItemHMargin = 3, // menu item hor text margin
menuArrowHMargin = 6, // menu arrow horizontal margin
menuItemVMargin = 2, // menu item ver text margin
menuRightBorder = 15, // right border on menus
menuCheckMarkWidth = 12 // checkmarks width on menus
};
private:
static QList<QGtkStylePrivate *> instances;
static WidgetMap *widgetMap;
friend class QGtkStyleUpdateScheduler;
};
// Helper to ensure that we have polished all our gtk widgets
// before updating our own palettes
class QGtkStyleUpdateScheduler : public QObject
{
Q_OBJECT
public slots:
void updateTheme();
};
QT_END_NAMESPACE
#endif // !QT_NO_STYLE_GTK
#endif // QGTKSTYLE_P_P_H
|