|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "gtksymbols_p.h" |
|
43 |
|
44 // This file is responsible for resolving all GTK functions we use |
|
45 // dynamically. This is done to avoid link-time dependancy on GTK |
|
46 // as well as crashes occurring due to usage of the GTK_QT engines |
|
47 // |
|
48 // Additionally we create a map of common GTK widgets that we can pass |
|
49 // to the GTK theme engine as many engines resort to querying the |
|
50 // actual widget pointers for details that are not covered by the |
|
51 // state flags |
|
52 |
|
53 #include <QtCore/qglobal.h> |
|
54 #if !defined(QT_NO_STYLE_GTK) |
|
55 |
|
56 #include <QtCore/QEvent> |
|
57 #include <QtCore/QFile> |
|
58 #include <QtCore/QStringList> |
|
59 #include <QtCore/QTextStream> |
|
60 #include <QtCore/QHash> |
|
61 #include <QtCore/QUrl> |
|
62 |
|
63 #include <private/qapplication_p.h> |
|
64 #include <private/qiconloader_p.h> |
|
65 |
|
66 #include <QtGui/QMenu> |
|
67 #include <QtGui/QStyle> |
|
68 #include <QtGui/QApplication> |
|
69 #include <QtGui/QPixmapCache> |
|
70 #include <QtGui/QStatusBar> |
|
71 #include <QtGui/QMenuBar> |
|
72 #include <QtGui/QToolBar> |
|
73 #include <QtGui/QToolButton> |
|
74 #include <QtGui/QX11Info> |
|
75 |
|
76 #include <X11/Xlib.h> |
|
77 |
|
78 QT_BEGIN_NAMESPACE |
|
79 |
|
80 static bool displayDepth = -1; |
|
81 Q_GLOBAL_STATIC(QGtkStyleUpdateScheduler, styleScheduler) |
|
82 |
|
83 typedef QHash<QString, GtkWidget*> WidgetMap; |
|
84 Q_GLOBAL_STATIC(WidgetMap, gtkWidgetMap) |
|
85 |
|
86 Ptr_gtk_container_forall QGtk::gtk_container_forall = 0; |
|
87 Ptr_gtk_init QGtk::gtk_init = 0; |
|
88 Ptr_gtk_style_attach QGtk::gtk_style_attach = 0; |
|
89 Ptr_gtk_window_new QGtk::gtk_window_new = 0; |
|
90 Ptr_gtk_widget_destroy QGtk::gtk_widget_destroy = 0; |
|
91 Ptr_gtk_widget_realize QGtk::gtk_widget_realize = 0; |
|
92 Ptr_gtk_widget_set_default_direction QGtk::gtk_widget_set_default_direction = 0; |
|
93 Ptr_gtk_widget_modify_color QGtk::gtk_widget_modify_fg = 0; |
|
94 Ptr_gtk_widget_modify_color QGtk::gtk_widget_modify_bg = 0; |
|
95 Ptr_gtk_arrow_new QGtk::gtk_arrow_new = 0; |
|
96 Ptr_gtk_menu_item_new QGtk::gtk_menu_item_new = 0; |
|
97 Ptr_gtk_check_menu_item_new QGtk::gtk_check_menu_item_new = 0; |
|
98 Ptr_gtk_menu_bar_new QGtk::gtk_menu_bar_new = 0; |
|
99 Ptr_gtk_menu_new QGtk::gtk_menu_new = 0; |
|
100 Ptr_gtk_button_new QGtk::gtk_button_new = 0; |
|
101 Ptr_gtk_hbutton_box_new QGtk::gtk_hbutton_box_new = 0; |
|
102 Ptr_gtk_check_button_new QGtk::gtk_check_button_new = 0; |
|
103 Ptr_gtk_radio_button_new QGtk::gtk_radio_button_new = 0; |
|
104 Ptr_gtk_spin_button_new QGtk::gtk_spin_button_new = 0; |
|
105 Ptr_gtk_frame_new QGtk::gtk_frame_new = 0; |
|
106 Ptr_gtk_expander_new QGtk::gtk_expander_new = 0; |
|
107 Ptr_gtk_statusbar_new QGtk::gtk_statusbar_new = 0; |
|
108 Ptr_gtk_entry_new QGtk::gtk_entry_new = 0; |
|
109 Ptr_gtk_hscale_new QGtk::gtk_hscale_new = 0; |
|
110 Ptr_gtk_vscale_new QGtk::gtk_vscale_new = 0; |
|
111 Ptr_gtk_hscrollbar_new QGtk::gtk_hscrollbar_new = 0; |
|
112 Ptr_gtk_vscrollbar_new QGtk::gtk_vscrollbar_new = 0; |
|
113 Ptr_gtk_scrolled_window_new QGtk::gtk_scrolled_window_new = 0; |
|
114 Ptr_gtk_notebook_new QGtk::gtk_notebook_new = 0; |
|
115 Ptr_gtk_toolbar_new QGtk::gtk_toolbar_new = 0; |
|
116 Ptr_gtk_toolbar_insert QGtk::gtk_toolbar_insert = 0; |
|
117 Ptr_gtk_separator_tool_item_new QGtk::gtk_separator_tool_item_new = 0; |
|
118 Ptr_gtk_tree_view_new QGtk::gtk_tree_view_new = 0; |
|
119 Ptr_gtk_combo_box_new QGtk::gtk_combo_box_new = 0; |
|
120 Ptr_gtk_combo_box_entry_new QGtk::gtk_combo_box_entry_new = 0; |
|
121 Ptr_gtk_progress_bar_new QGtk::gtk_progress_bar_new = 0; |
|
122 Ptr_gtk_container_add QGtk::gtk_container_add = 0; |
|
123 Ptr_gtk_menu_shell_append QGtk::gtk_menu_shell_append = 0; |
|
124 Ptr_gtk_progress_set_adjustment QGtk::gtk_progress_set_adjustment = 0; |
|
125 Ptr_gtk_range_set_adjustment QGtk::gtk_range_set_adjustment = 0; |
|
126 Ptr_gtk_range_set_inverted QGtk::gtk_range_set_inverted = 0; |
|
127 Ptr_gtk_icon_factory_lookup_default QGtk::gtk_icon_factory_lookup_default = 0; |
|
128 Ptr_gtk_icon_theme_get_default QGtk::gtk_icon_theme_get_default = 0; |
|
129 Ptr_gtk_widget_style_get QGtk::gtk_widget_style_get = 0; |
|
130 Ptr_gtk_icon_set_render_icon QGtk::gtk_icon_set_render_icon = 0; |
|
131 Ptr_gtk_fixed_new QGtk::gtk_fixed_new = 0; |
|
132 Ptr_gtk_tree_view_column_new QGtk::gtk_tree_view_column_new = 0; |
|
133 Ptr_gtk_tree_view_get_column QGtk::gtk_tree_view_get_column = 0; |
|
134 Ptr_gtk_tree_view_append_column QGtk::gtk_tree_view_append_column = 0; |
|
135 Ptr_gtk_paint_check QGtk::gtk_paint_check = 0; |
|
136 Ptr_gtk_paint_box QGtk::gtk_paint_box = 0; |
|
137 Ptr_gtk_paint_box_gap QGtk::gtk_paint_box_gap = 0; |
|
138 Ptr_gtk_paint_flat_box QGtk::gtk_paint_flat_box = 0; |
|
139 Ptr_gtk_paint_option QGtk::gtk_paint_option = 0; |
|
140 Ptr_gtk_paint_extension QGtk::gtk_paint_extension = 0; |
|
141 Ptr_gtk_paint_slider QGtk::gtk_paint_slider = 0; |
|
142 Ptr_gtk_paint_shadow QGtk::gtk_paint_shadow = 0; |
|
143 Ptr_gtk_paint_resize_grip QGtk::gtk_paint_resize_grip = 0; |
|
144 Ptr_gtk_paint_focus QGtk::gtk_paint_focus = 0; |
|
145 Ptr_gtk_paint_arrow QGtk::gtk_paint_arrow = 0; |
|
146 Ptr_gtk_paint_handle QGtk::gtk_paint_handle = 0; |
|
147 Ptr_gtk_paint_expander QGtk::gtk_paint_expander = 0; |
|
148 Ptr_gtk_adjustment_new QGtk::gtk_adjustment_new = 0; |
|
149 Ptr_gtk_paint_hline QGtk::gtk_paint_hline = 0; |
|
150 Ptr_gtk_paint_vline QGtk::gtk_paint_vline = 0; |
|
151 Ptr_gtk_menu_item_set_submenu QGtk::gtk_menu_item_set_submenu = 0; |
|
152 Ptr_gtk_settings_get_default QGtk::gtk_settings_get_default = 0; |
|
153 Ptr_gtk_separator_menu_item_new QGtk::gtk_separator_menu_item_new = 0; |
|
154 Ptr_gtk_widget_size_allocate QGtk::gtk_widget_size_allocate = 0; |
|
155 Ptr_gtk_widget_set_direction QGtk::gtk_widget_set_direction = 0; |
|
156 Ptr_gtk_widget_path QGtk::gtk_widget_path = 0; |
|
157 Ptr_gtk_container_get_type QGtk::gtk_container_get_type = 0; |
|
158 Ptr_gtk_window_get_type QGtk::gtk_window_get_type = 0; |
|
159 Ptr_gtk_widget_get_type QGtk::gtk_widget_get_type = 0; |
|
160 Ptr_gtk_rc_get_style_by_paths QGtk::gtk_rc_get_style_by_paths = 0; |
|
161 Ptr_gtk_check_version QGtk::gtk_check_version = 0; |
|
162 |
|
163 Ptr_pango_font_description_get_size QGtk::pango_font_description_get_size = 0; |
|
164 Ptr_pango_font_description_get_weight QGtk::pango_font_description_get_weight = 0; |
|
165 Ptr_pango_font_description_get_family QGtk::pango_font_description_get_family = 0; |
|
166 Ptr_pango_font_description_get_style QGtk::pango_font_description_get_style = 0; |
|
167 |
|
168 Ptr_gtk_file_filter_new QGtk::gtk_file_filter_new = 0; |
|
169 Ptr_gtk_file_filter_set_name QGtk::gtk_file_filter_set_name = 0; |
|
170 Ptr_gtk_file_filter_add_pattern QGtk::gtk_file_filter_add_pattern = 0; |
|
171 Ptr_gtk_file_chooser_add_filter QGtk::gtk_file_chooser_add_filter = 0; |
|
172 Ptr_gtk_file_chooser_set_filter QGtk::gtk_file_chooser_set_filter = 0; |
|
173 Ptr_gtk_file_chooser_get_filter QGtk::gtk_file_chooser_get_filter = 0; |
|
174 Ptr_gtk_file_chooser_dialog_new QGtk::gtk_file_chooser_dialog_new = 0; |
|
175 Ptr_gtk_file_chooser_set_current_folder QGtk::gtk_file_chooser_set_current_folder = 0; |
|
176 Ptr_gtk_file_chooser_get_filename QGtk::gtk_file_chooser_get_filename = 0; |
|
177 Ptr_gtk_file_chooser_get_filenames QGtk::gtk_file_chooser_get_filenames = 0; |
|
178 Ptr_gtk_file_chooser_set_current_name QGtk::gtk_file_chooser_set_current_name = 0; |
|
179 Ptr_gtk_dialog_run QGtk::gtk_dialog_run = 0; |
|
180 Ptr_gtk_file_chooser_set_filename QGtk::gtk_file_chooser_set_filename = 0; |
|
181 |
|
182 Ptr_gdk_pixbuf_get_pixels QGtk::gdk_pixbuf_get_pixels = 0; |
|
183 Ptr_gdk_pixbuf_get_width QGtk::gdk_pixbuf_get_width = 0; |
|
184 Ptr_gdk_pixbuf_get_height QGtk::gdk_pixbuf_get_height = 0; |
|
185 Ptr_gdk_pixmap_new QGtk::gdk_pixmap_new = 0; |
|
186 Ptr_gdk_pixbuf_new QGtk::gdk_pixbuf_new = 0; |
|
187 Ptr_gdk_pixbuf_get_from_drawable QGtk::gdk_pixbuf_get_from_drawable = 0; |
|
188 Ptr_gdk_draw_rectangle QGtk::gdk_draw_rectangle = 0; |
|
189 Ptr_gdk_pixbuf_unref QGtk::gdk_pixbuf_unref = 0; |
|
190 Ptr_gdk_drawable_unref QGtk::gdk_drawable_unref = 0; |
|
191 Ptr_gdk_drawable_get_depth QGtk::gdk_drawable_get_depth = 0; |
|
192 Ptr_gdk_color_free QGtk::gdk_color_free = 0; |
|
193 Ptr_gdk_x11_window_set_user_time QGtk::gdk_x11_window_set_user_time = 0; |
|
194 Ptr_gdk_x11_drawable_get_xid QGtk::gdk_x11_drawable_get_xid = 0; |
|
195 Ptr_gdk_x11_drawable_get_xdisplay QGtk::gdk_x11_drawable_get_xdisplay = 0; |
|
196 |
|
197 Ptr_gconf_client_get_default QGtk::gconf_client_get_default = 0; |
|
198 Ptr_gconf_client_get_string QGtk::gconf_client_get_string = 0; |
|
199 Ptr_gconf_client_get_bool QGtk::gconf_client_get_bool = 0; |
|
200 |
|
201 Ptr_gnome_icon_lookup_sync QGtk::gnome_icon_lookup_sync = 0; |
|
202 Ptr_gnome_vfs_init QGtk::gnome_vfs_init = 0; |
|
203 |
|
204 static QString classPath(GtkWidget *widget) |
|
205 { |
|
206 char* class_path; |
|
207 QGtk::gtk_widget_path (widget, NULL, &class_path, NULL); |
|
208 QString path = QLS(class_path); |
|
209 g_free(class_path); |
|
210 |
|
211 // Remove the prefixes |
|
212 path.remove(QLS("GtkWindow.")); |
|
213 path.remove(QLS("GtkFixed.")); |
|
214 return path; |
|
215 } |
|
216 |
|
217 static void resolveGtk() |
|
218 { |
|
219 // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0 |
|
220 QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0); |
|
221 QGtk::gtk_init = (Ptr_gtk_init)libgtk.resolve("gtk_init"); |
|
222 QGtk::gtk_window_new = (Ptr_gtk_window_new)libgtk.resolve("gtk_window_new"); |
|
223 QGtk::gtk_style_attach = (Ptr_gtk_style_attach)libgtk.resolve("gtk_style_attach"); |
|
224 QGtk::gtk_widget_destroy = (Ptr_gtk_widget_destroy)libgtk.resolve("gtk_widget_destroy"); |
|
225 QGtk::gtk_widget_realize = (Ptr_gtk_widget_realize)libgtk.resolve("gtk_widget_realize"); |
|
226 |
|
227 QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder"); |
|
228 QGtk::gtk_file_filter_new = (Ptr_gtk_file_filter_new)libgtk.resolve("gtk_file_filter_new"); |
|
229 QGtk::gtk_file_filter_set_name = (Ptr_gtk_file_filter_set_name)libgtk.resolve("gtk_file_filter_set_name"); |
|
230 QGtk::gtk_file_filter_add_pattern = (Ptr_gtk_file_filter_add_pattern)libgtk.resolve("gtk_file_filter_add_pattern"); |
|
231 QGtk::gtk_file_chooser_add_filter = (Ptr_gtk_file_chooser_add_filter)libgtk.resolve("gtk_file_chooser_add_filter"); |
|
232 QGtk::gtk_file_chooser_set_filter = (Ptr_gtk_file_chooser_set_filter)libgtk.resolve("gtk_file_chooser_set_filter"); |
|
233 QGtk::gtk_file_chooser_get_filter = (Ptr_gtk_file_chooser_get_filter)libgtk.resolve("gtk_file_chooser_get_filter"); |
|
234 QGtk::gtk_file_chooser_dialog_new = (Ptr_gtk_file_chooser_dialog_new)libgtk.resolve("gtk_file_chooser_dialog_new"); |
|
235 QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder"); |
|
236 QGtk::gtk_file_chooser_get_filename = (Ptr_gtk_file_chooser_get_filename)libgtk.resolve("gtk_file_chooser_get_filename"); |
|
237 QGtk::gtk_file_chooser_get_filenames = (Ptr_gtk_file_chooser_get_filenames)libgtk.resolve("gtk_file_chooser_get_filenames"); |
|
238 QGtk::gtk_file_chooser_set_current_name = (Ptr_gtk_file_chooser_set_current_name)libgtk.resolve("gtk_file_chooser_set_current_name"); |
|
239 QGtk::gtk_dialog_run = (Ptr_gtk_dialog_run)libgtk.resolve("gtk_dialog_run"); |
|
240 QGtk::gtk_file_chooser_set_filename = (Ptr_gtk_file_chooser_set_filename)libgtk.resolve("gtk_file_chooser_set_filename"); |
|
241 |
|
242 QGtk::gdk_pixbuf_get_pixels = (Ptr_gdk_pixbuf_get_pixels)libgtk.resolve("gdk_pixbuf_get_pixels"); |
|
243 QGtk::gdk_pixbuf_get_width = (Ptr_gdk_pixbuf_get_width)libgtk.resolve("gdk_pixbuf_get_width"); |
|
244 QGtk::gdk_pixbuf_get_height = (Ptr_gdk_pixbuf_get_height)libgtk.resolve("gdk_pixbuf_get_height"); |
|
245 QGtk::gdk_pixmap_new = (Ptr_gdk_pixmap_new)libgtk.resolve("gdk_pixmap_new"); |
|
246 QGtk::gdk_pixbuf_new = (Ptr_gdk_pixbuf_new)libgtk.resolve("gdk_pixbuf_new"); |
|
247 QGtk::gdk_pixbuf_get_from_drawable = (Ptr_gdk_pixbuf_get_from_drawable)libgtk.resolve("gdk_pixbuf_get_from_drawable"); |
|
248 QGtk::gdk_draw_rectangle = (Ptr_gdk_draw_rectangle)libgtk.resolve("gdk_draw_rectangle"); |
|
249 QGtk::gdk_pixbuf_unref = (Ptr_gdk_pixbuf_unref)libgtk.resolve("gdk_pixbuf_unref"); |
|
250 QGtk::gdk_drawable_unref = (Ptr_gdk_drawable_unref)libgtk.resolve("gdk_drawable_unref"); |
|
251 QGtk::gdk_drawable_get_depth = (Ptr_gdk_drawable_get_depth)libgtk.resolve("gdk_drawable_get_depth"); |
|
252 QGtk::gdk_color_free = (Ptr_gdk_color_free)libgtk.resolve("gdk_color_free"); |
|
253 QGtk::gdk_x11_window_set_user_time = (Ptr_gdk_x11_window_set_user_time)libgtk.resolve("gdk_x11_window_set_user_time"); |
|
254 QGtk::gdk_x11_drawable_get_xid = (Ptr_gdk_x11_drawable_get_xid)libgtk.resolve("gdk_x11_drawable_get_xid"); |
|
255 QGtk::gdk_x11_drawable_get_xdisplay = (Ptr_gdk_x11_drawable_get_xdisplay)libgtk.resolve("gdk_x11_drawable_get_xdisplay"); |
|
256 |
|
257 QGtk::gtk_widget_set_default_direction = (Ptr_gtk_widget_set_default_direction)libgtk.resolve("gtk_widget_set_default_direction"); |
|
258 QGtk::gtk_widget_modify_fg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_fg"); |
|
259 QGtk::gtk_widget_modify_bg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_bg"); |
|
260 QGtk::gtk_arrow_new = (Ptr_gtk_arrow_new)libgtk.resolve("gtk_arrow_new"); |
|
261 QGtk::gtk_menu_item_new = (Ptr_gtk_menu_item_new)libgtk.resolve("gtk_menu_item_new"); |
|
262 QGtk::gtk_check_menu_item_new = (Ptr_gtk_check_menu_item_new)libgtk.resolve("gtk_check_menu_item_new"); |
|
263 QGtk::gtk_menu_bar_new = (Ptr_gtk_menu_bar_new)libgtk.resolve("gtk_menu_bar_new"); |
|
264 QGtk::gtk_menu_new = (Ptr_gtk_menu_new)libgtk.resolve("gtk_menu_new"); |
|
265 QGtk::gtk_toolbar_new = (Ptr_gtk_toolbar_new)libgtk.resolve("gtk_toolbar_new"); |
|
266 QGtk::gtk_separator_tool_item_new = (Ptr_gtk_separator_tool_item_new)libgtk.resolve("gtk_separator_tool_item_new"); |
|
267 QGtk::gtk_toolbar_insert = (Ptr_gtk_toolbar_insert)libgtk.resolve("gtk_toolbar_insert"); |
|
268 QGtk::gtk_button_new = (Ptr_gtk_button_new)libgtk.resolve("gtk_button_new"); |
|
269 QGtk::gtk_hbutton_box_new = (Ptr_gtk_hbutton_box_new)libgtk.resolve("gtk_hbutton_box_new"); |
|
270 QGtk::gtk_check_button_new = (Ptr_gtk_check_button_new)libgtk.resolve("gtk_check_button_new"); |
|
271 QGtk::gtk_radio_button_new = (Ptr_gtk_radio_button_new)libgtk.resolve("gtk_radio_button_new"); |
|
272 QGtk::gtk_notebook_new = (Ptr_gtk_notebook_new)libgtk.resolve("gtk_notebook_new"); |
|
273 QGtk::gtk_progress_bar_new = (Ptr_gtk_progress_bar_new)libgtk.resolve("gtk_progress_bar_new"); |
|
274 QGtk::gtk_spin_button_new = (Ptr_gtk_spin_button_new)libgtk.resolve("gtk_spin_button_new"); |
|
275 QGtk::gtk_hscale_new = (Ptr_gtk_hscale_new)libgtk.resolve("gtk_hscale_new"); |
|
276 QGtk::gtk_vscale_new = (Ptr_gtk_vscale_new)libgtk.resolve("gtk_vscale_new"); |
|
277 QGtk::gtk_hscrollbar_new = (Ptr_gtk_hscrollbar_new)libgtk.resolve("gtk_hscrollbar_new"); |
|
278 QGtk::gtk_vscrollbar_new = (Ptr_gtk_vscrollbar_new)libgtk.resolve("gtk_vscrollbar_new"); |
|
279 QGtk::gtk_scrolled_window_new = (Ptr_gtk_scrolled_window_new)libgtk.resolve("gtk_scrolled_window_new"); |
|
280 QGtk::gtk_menu_shell_append = (Ptr_gtk_menu_shell_append)libgtk.resolve("gtk_menu_shell_append"); |
|
281 QGtk::gtk_entry_new = (Ptr_gtk_entry_new)libgtk.resolve("gtk_entry_new"); |
|
282 QGtk::gtk_tree_view_new = (Ptr_gtk_tree_view_new)libgtk.resolve("gtk_tree_view_new"); |
|
283 QGtk::gtk_combo_box_new = (Ptr_gtk_combo_box_new)libgtk.resolve("gtk_combo_box_new"); |
|
284 QGtk::gtk_progress_set_adjustment = (Ptr_gtk_progress_set_adjustment)libgtk.resolve("gtk_progress_set_adjustment"); |
|
285 QGtk::gtk_range_set_adjustment = (Ptr_gtk_range_set_adjustment)libgtk.resolve("gtk_range_set_adjustment"); |
|
286 QGtk::gtk_range_set_inverted = (Ptr_gtk_range_set_inverted)libgtk.resolve("gtk_range_set_inverted"); |
|
287 QGtk::gtk_container_add = (Ptr_gtk_container_add)libgtk.resolve("gtk_container_add"); |
|
288 QGtk::gtk_icon_factory_lookup_default = (Ptr_gtk_icon_factory_lookup_default)libgtk.resolve("gtk_icon_factory_lookup_default"); |
|
289 QGtk::gtk_icon_theme_get_default = (Ptr_gtk_icon_theme_get_default)libgtk.resolve("gtk_icon_theme_get_default"); |
|
290 QGtk::gtk_widget_style_get = (Ptr_gtk_widget_style_get)libgtk.resolve("gtk_widget_style_get"); |
|
291 QGtk::gtk_icon_set_render_icon = (Ptr_gtk_icon_set_render_icon)libgtk.resolve("gtk_icon_set_render_icon"); |
|
292 QGtk::gtk_fixed_new = (Ptr_gtk_fixed_new)libgtk.resolve("gtk_fixed_new"); |
|
293 QGtk::gtk_tree_view_column_new = (Ptr_gtk_tree_view_column_new)libgtk.resolve("gtk_tree_view_column_new"); |
|
294 QGtk::gtk_tree_view_append_column= (Ptr_gtk_tree_view_append_column )libgtk.resolve("gtk_tree_view_append_column"); |
|
295 QGtk::gtk_tree_view_get_column = (Ptr_gtk_tree_view_get_column )libgtk.resolve("gtk_tree_view_get_column"); |
|
296 QGtk::gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check"); |
|
297 QGtk::gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box"); |
|
298 QGtk::gtk_paint_flat_box = (Ptr_gtk_paint_flat_box)libgtk.resolve("gtk_paint_flat_box"); |
|
299 QGtk::gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check"); |
|
300 QGtk::gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box"); |
|
301 QGtk::gtk_paint_resize_grip = (Ptr_gtk_paint_resize_grip)libgtk.resolve("gtk_paint_resize_grip"); |
|
302 QGtk::gtk_paint_focus = (Ptr_gtk_paint_focus)libgtk.resolve("gtk_paint_focus"); |
|
303 QGtk::gtk_paint_shadow = (Ptr_gtk_paint_shadow)libgtk.resolve("gtk_paint_shadow"); |
|
304 QGtk::gtk_paint_slider = (Ptr_gtk_paint_slider)libgtk.resolve("gtk_paint_slider"); |
|
305 QGtk::gtk_paint_expander = (Ptr_gtk_paint_expander)libgtk.resolve("gtk_paint_expander"); |
|
306 QGtk::gtk_paint_handle = (Ptr_gtk_paint_handle)libgtk.resolve("gtk_paint_handle"); |
|
307 QGtk::gtk_paint_option = (Ptr_gtk_paint_option)libgtk.resolve("gtk_paint_option"); |
|
308 QGtk::gtk_paint_arrow = (Ptr_gtk_paint_arrow)libgtk.resolve("gtk_paint_arrow"); |
|
309 QGtk::gtk_paint_box_gap = (Ptr_gtk_paint_box_gap)libgtk.resolve("gtk_paint_box_gap"); |
|
310 QGtk::gtk_paint_extension = (Ptr_gtk_paint_extension)libgtk.resolve("gtk_paint_extension"); |
|
311 QGtk::gtk_paint_hline = (Ptr_gtk_paint_hline)libgtk.resolve("gtk_paint_hline"); |
|
312 QGtk::gtk_paint_vline = (Ptr_gtk_paint_vline)libgtk.resolve("gtk_paint_vline"); |
|
313 QGtk::gtk_adjustment_new = (Ptr_gtk_adjustment_new)libgtk.resolve("gtk_adjustment_new"); |
|
314 QGtk::gtk_menu_item_set_submenu = (Ptr_gtk_menu_item_set_submenu)libgtk.resolve("gtk_menu_item_set_submenu"); |
|
315 QGtk::gtk_settings_get_default = (Ptr_gtk_settings_get_default)libgtk.resolve("gtk_settings_get_default"); |
|
316 QGtk::gtk_separator_menu_item_new = (Ptr_gtk_separator_menu_item_new)libgtk.resolve("gtk_separator_menu_item_new"); |
|
317 QGtk::gtk_frame_new = (Ptr_gtk_frame_new)libgtk.resolve("gtk_frame_new"); |
|
318 QGtk::gtk_expander_new = (Ptr_gtk_expander_new)libgtk.resolve("gtk_expander_new"); |
|
319 QGtk::gtk_statusbar_new = (Ptr_gtk_statusbar_new)libgtk.resolve("gtk_statusbar_new"); |
|
320 QGtk::gtk_combo_box_entry_new = (Ptr_gtk_combo_box_entry_new)libgtk.resolve("gtk_combo_box_entry_new"); |
|
321 QGtk::gtk_container_forall = (Ptr_gtk_container_forall)libgtk.resolve("gtk_container_forall"); |
|
322 QGtk::gtk_widget_size_allocate =(Ptr_gtk_widget_size_allocate)libgtk.resolve("gtk_widget_size_allocate"); |
|
323 QGtk::gtk_widget_set_direction =(Ptr_gtk_widget_set_direction)libgtk.resolve("gtk_widget_set_direction"); |
|
324 QGtk::gtk_widget_path =(Ptr_gtk_widget_path)libgtk.resolve("gtk_widget_path"); |
|
325 QGtk::gtk_container_get_type =(Ptr_gtk_container_get_type)libgtk.resolve("gtk_container_get_type"); |
|
326 QGtk::gtk_window_get_type =(Ptr_gtk_window_get_type)libgtk.resolve("gtk_window_get_type"); |
|
327 QGtk::gtk_widget_get_type =(Ptr_gtk_widget_get_type)libgtk.resolve("gtk_widget_get_type"); |
|
328 QGtk::gtk_rc_get_style_by_paths =(Ptr_gtk_rc_get_style_by_paths)libgtk.resolve("gtk_rc_get_style_by_paths"); |
|
329 QGtk::gtk_check_version =(Ptr_gtk_check_version)libgtk.resolve("gtk_check_version"); |
|
330 QGtk::pango_font_description_get_size = (Ptr_pango_font_description_get_size)libgtk.resolve("pango_font_description_get_size"); |
|
331 QGtk::pango_font_description_get_weight = (Ptr_pango_font_description_get_weight)libgtk.resolve("pango_font_description_get_weight"); |
|
332 QGtk::pango_font_description_get_family = (Ptr_pango_font_description_get_family)libgtk.resolve("pango_font_description_get_family"); |
|
333 QGtk::pango_font_description_get_style = (Ptr_pango_font_description_get_style)libgtk.resolve("pango_font_description_get_style"); |
|
334 |
|
335 QGtk::gnome_icon_lookup_sync = (Ptr_gnome_icon_lookup_sync)QLibrary::resolve( QLS("gnomeui-2"), 0, "gnome_icon_lookup_sync"); |
|
336 QGtk::gnome_vfs_init= (Ptr_gnome_vfs_init)QLibrary::resolve( QLS("gnomevfs-2"), 0, "gnome_vfs_init"); |
|
337 } |
|
338 |
|
339 void QGtk::cleanup_gtk_widgets() |
|
340 { |
|
341 if (gtkWidgetMap()->contains(QLS("GtkWindow"))) // Gtk will destroy all children |
|
342 QGtk::gtk_widget_destroy(gtkWidgetMap()->value(QLS("GtkWindow"))); |
|
343 } |
|
344 |
|
345 static bool resolveGConf() |
|
346 { |
|
347 if (!QGtk::gconf_client_get_default) { |
|
348 QGtk::gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_default"); |
|
349 QGtk::gconf_client_get_string = (Ptr_gconf_client_get_string)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_string"); |
|
350 QGtk::gconf_client_get_bool = (Ptr_gconf_client_get_bool)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_bool"); |
|
351 } |
|
352 return (QGtk::gconf_client_get_default !=0); |
|
353 } |
|
354 |
|
355 typedef int (*x11ErrorHandler)(Display*, XErrorEvent*); |
|
356 |
|
357 QString QGtk::getGConfString(const QString &value, const QString &fallback) |
|
358 { |
|
359 QString retVal = fallback; |
|
360 if (resolveGConf()) { |
|
361 g_type_init(); |
|
362 GConfClient* client = QGtk::gconf_client_get_default(); |
|
363 GError *err = 0; |
|
364 char *str = QGtk::gconf_client_get_string(client, qPrintable(value), &err); |
|
365 if (!err) { |
|
366 retVal = QString::fromUtf8(str); |
|
367 g_free(str); |
|
368 } |
|
369 g_object_unref(client); |
|
370 if (err) |
|
371 g_error_free (err); |
|
372 } |
|
373 return retVal; |
|
374 } |
|
375 |
|
376 bool QGtk::getGConfBool(const QString &key, bool fallback) |
|
377 { |
|
378 bool retVal = fallback; |
|
379 if (resolveGConf()) { |
|
380 g_type_init(); |
|
381 GConfClient* client = QGtk::gconf_client_get_default(); |
|
382 GError *err = 0; |
|
383 bool result = QGtk::gconf_client_get_bool(client, qPrintable(key), &err); |
|
384 g_object_unref(client); |
|
385 if (!err) |
|
386 retVal = result; |
|
387 else |
|
388 g_error_free (err); |
|
389 } |
|
390 return retVal; |
|
391 } |
|
392 |
|
393 static QString getThemeName() |
|
394 { |
|
395 QString themeName; |
|
396 // We try to parse the gtkrc file first |
|
397 // primarily to avoid resolving Gtk functions if |
|
398 // the KDE 3 "Qt" style is currently in use |
|
399 QString rcPaths = QString::fromLocal8Bit(qgetenv("GTK2_RC_FILES")); |
|
400 if (!rcPaths.isEmpty()) { |
|
401 QStringList paths = rcPaths.split(QLS(":")); |
|
402 foreach (const QString &rcPath, paths) { |
|
403 if (!rcPath.isEmpty()) { |
|
404 QFile rcFile(rcPath); |
|
405 if (rcFile.exists() && rcFile.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
406 QTextStream in(&rcFile); |
|
407 while(!in.atEnd()) { |
|
408 QString line = in.readLine(); |
|
409 if (line.contains(QLS("gtk-theme-name"))) { |
|
410 line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1); |
|
411 line.remove(QLatin1Char('\"')); |
|
412 line = line.trimmed(); |
|
413 themeName = line; |
|
414 break; |
|
415 } |
|
416 } |
|
417 } |
|
418 } |
|
419 if (!themeName.isEmpty()) |
|
420 break; |
|
421 } |
|
422 } |
|
423 |
|
424 // Fall back to gconf |
|
425 if (themeName.isEmpty() && resolveGConf()) |
|
426 themeName = QGtk::getGConfString(QLS("/desktop/gnome/interface/gtk_theme")); |
|
427 |
|
428 return themeName; |
|
429 } |
|
430 |
|
431 static void init_gtk_window() |
|
432 { |
|
433 static QString themeName; |
|
434 if (!gtkWidgetMap()->contains(QLS("GtkWindow")) && themeName.isEmpty()) { |
|
435 themeName = getThemeName(); |
|
436 |
|
437 if (themeName.isEmpty()) { |
|
438 qWarning("QGtkStyle was unable to detect the current GTK+ theme."); |
|
439 return; |
|
440 } else if (themeName == QLS("Qt") || themeName == QLS("Qt4")) { |
|
441 // Due to namespace conflicts with Qt3 and obvious recursion with Qt4, |
|
442 // we cannot support the GTK_Qt Gtk engine |
|
443 qWarning("QGtkStyle cannot be used together with the GTK_Qt engine."); |
|
444 return; |
|
445 } |
|
446 |
|
447 resolveGtk(); |
|
448 |
|
449 if (QGtk::gtk_init) { |
|
450 // Gtk will set the Qt error handler so we have to reset it afterwards |
|
451 x11ErrorHandler qt_x_errhandler = XSetErrorHandler(0); |
|
452 QGtk::gtk_init (NULL, NULL); |
|
453 XSetErrorHandler(qt_x_errhandler); |
|
454 |
|
455 GtkWidget* gtkWindow = QGtk::gtk_window_new(GTK_WINDOW_POPUP); |
|
456 QGtk::gtk_widget_realize(gtkWindow); |
|
457 if (displayDepth == -1) |
|
458 displayDepth = QGtk::gdk_drawable_get_depth(gtkWindow->window); |
|
459 gtkWidgetMap()->insert(QLS("GtkWindow"), gtkWindow); |
|
460 } else { |
|
461 qWarning("QGtkStyle could not resolve GTK. Make sure you have installed the proper libraries."); |
|
462 } |
|
463 } |
|
464 } |
|
465 |
|
466 static void setup_gtk_widget(GtkWidget* widget) |
|
467 { |
|
468 if (Q_GTK_IS_WIDGET(widget)) { |
|
469 static GtkWidget* protoLayout = 0; |
|
470 if (!protoLayout) { |
|
471 protoLayout = QGtk::gtk_fixed_new(); |
|
472 QGtk::gtk_container_add((GtkContainer*)(gtkWidgetMap()->value(QLS("GtkWindow"))), protoLayout); |
|
473 } |
|
474 Q_ASSERT(protoLayout); |
|
475 |
|
476 QGtk::gtk_container_add((GtkContainer*)(protoLayout), widget); |
|
477 QGtk::gtk_widget_realize(widget); |
|
478 } |
|
479 } |
|
480 |
|
481 static void add_widget_to_map(GtkWidget *widget) |
|
482 { |
|
483 if (Q_GTK_IS_WIDGET(widget)) { |
|
484 QGtk::gtk_widget_realize(widget); |
|
485 gtkWidgetMap()->insert(classPath(widget), widget); |
|
486 } |
|
487 } |
|
488 |
|
489 static void add_all_sub_widgets(GtkWidget *widget, gpointer v = 0) |
|
490 { |
|
491 Q_UNUSED(v); |
|
492 add_widget_to_map(widget); |
|
493 if (GTK_CHECK_TYPE ((widget), Q_GTK_TYPE_CONTAINER)) |
|
494 QGtk::gtk_container_forall((GtkContainer*)widget, add_all_sub_widgets, NULL); |
|
495 } |
|
496 |
|
497 static void init_gtk_menu() |
|
498 { |
|
499 // Create menubar |
|
500 GtkWidget *gtkMenuBar = QGtk::gtk_menu_bar_new(); |
|
501 setup_gtk_widget(gtkMenuBar); |
|
502 |
|
503 GtkWidget *gtkMenuBarItem = QGtk::gtk_menu_item_new(); |
|
504 QGtk::gtk_menu_shell_append((GtkMenuShell*)(gtkMenuBar), gtkMenuBarItem); |
|
505 QGtk::gtk_widget_realize(gtkMenuBarItem); |
|
506 |
|
507 // Create menu |
|
508 GtkWidget *gtkMenu = QGtk::gtk_menu_new(); |
|
509 QGtk::gtk_menu_item_set_submenu((GtkMenuItem*)(gtkMenuBarItem), gtkMenu); |
|
510 QGtk::gtk_widget_realize(gtkMenu); |
|
511 |
|
512 GtkWidget *gtkMenuItem = QGtk::gtk_menu_item_new(); |
|
513 QGtk::gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuItem); |
|
514 QGtk::gtk_widget_realize(gtkMenuItem); |
|
515 |
|
516 GtkWidget *gtkCheckMenuItem = QGtk::gtk_check_menu_item_new(); |
|
517 QGtk::gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkCheckMenuItem); |
|
518 QGtk::gtk_widget_realize(gtkCheckMenuItem); |
|
519 |
|
520 GtkWidget *gtkMenuSeparator = QGtk::gtk_separator_menu_item_new(); |
|
521 QGtk::gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuSeparator); |
|
522 |
|
523 add_all_sub_widgets(gtkMenuBar); |
|
524 add_all_sub_widgets(gtkMenu); |
|
525 } |
|
526 |
|
527 // Updates window/windowtext palette based on the indicated gtk widget |
|
528 static QPalette gtkWidgetPalette(const QString >kWidgetName) |
|
529 { |
|
530 GtkWidget *gtkWidget = QGtk::gtkWidget(gtkWidgetName); |
|
531 Q_ASSERT(gtkWidget); |
|
532 QPalette pal = QApplication::palette(); |
|
533 GdkColor gdkBg = gtkWidget->style->bg[GTK_STATE_NORMAL]; |
|
534 GdkColor gdkText = gtkWidget->style->fg[GTK_STATE_NORMAL]; |
|
535 GdkColor gdkDisabledText = gtkWidget->style->fg[GTK_STATE_INSENSITIVE]; |
|
536 QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); |
|
537 QColor textColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8); |
|
538 QColor disabledTextColor(gdkDisabledText.red>>8, gdkDisabledText.green>>8, gdkDisabledText.blue>>8); |
|
539 pal.setBrush(QPalette::Window, bgColor); |
|
540 pal.setBrush(QPalette::Button, bgColor); |
|
541 pal.setBrush(QPalette::All, QPalette::WindowText, textColor); |
|
542 pal.setBrush(QPalette::Disabled, QPalette::WindowText, disabledTextColor); |
|
543 pal.setBrush(QPalette::All, QPalette::ButtonText, textColor); |
|
544 pal.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledTextColor); |
|
545 return pal; |
|
546 } |
|
547 |
|
548 bool QGtk::isKDE4Session() |
|
549 { |
|
550 static int version = -1; |
|
551 if (version == -1) |
|
552 version = qgetenv("KDE_SESSION_VERSION").toInt(); |
|
553 return (version == 4); |
|
554 } |
|
555 |
|
556 void QGtk::applyCustomPaletteHash() |
|
557 { |
|
558 QPalette menuPal = gtkWidgetPalette(QLS("GtkMenu")); |
|
559 GdkColor gdkBg = QGtk::gtkWidget(QLS("GtkMenu"))->style->bg[GTK_STATE_NORMAL]; |
|
560 QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); |
|
561 menuPal.setBrush(QPalette::Base, bgColor); |
|
562 menuPal.setBrush(QPalette::Window, bgColor); |
|
563 qApp->setPalette(menuPal, "QMenu"); |
|
564 |
|
565 QPalette toolbarPal = gtkWidgetPalette(QLS("GtkToolbar")); |
|
566 qApp->setPalette(toolbarPal, "QToolBar"); |
|
567 |
|
568 QPalette menuBarPal = gtkWidgetPalette(QLS("GtkMenuBar")); |
|
569 qApp->setPalette(menuBarPal, "QMenuBar"); |
|
570 } |
|
571 |
|
572 static void gtkStyleSetCallback(GtkWidget*, GtkStyle*, void*) |
|
573 { |
|
574 // We have to let this function return and complete the event |
|
575 // loop to ensure that all gtk widgets have been styled before |
|
576 // updating |
|
577 QMetaObject::invokeMethod(styleScheduler(), "updateTheme", Qt::QueuedConnection); |
|
578 } |
|
579 |
|
580 void QGtkStyleUpdateScheduler::updateTheme() |
|
581 { |
|
582 static QString oldTheme(QLS("qt_not_set")); |
|
583 QPixmapCache::clear(); |
|
584 |
|
585 QFont font = QGtk::getThemeFont(); |
|
586 if (QApplication::font() != font) |
|
587 qApp->setFont(font); |
|
588 |
|
589 if (oldTheme != getThemeName()) { |
|
590 oldTheme = getThemeName(); |
|
591 QPalette newPalette = qApp->style()->standardPalette(); |
|
592 QApplicationPrivate::setSystemPalette(newPalette); |
|
593 QApplication::setPalette(newPalette); |
|
594 QGtk::initGtkWidgets(); |
|
595 QGtk::applyCustomPaletteHash(); |
|
596 QList<QWidget*> widgets = QApplication::allWidgets(); |
|
597 // Notify all widgets that size metrics might have changed |
|
598 foreach (QWidget *widget, widgets) { |
|
599 QEvent e(QEvent::StyleChange); |
|
600 QApplication::sendEvent(widget, &e); |
|
601 } |
|
602 } |
|
603 QIconLoader::instance()->updateSystemTheme(); |
|
604 } |
|
605 |
|
606 static void add_widget(GtkWidget *widget) |
|
607 { |
|
608 if (widget) { |
|
609 setup_gtk_widget(widget); |
|
610 add_all_sub_widgets(widget); |
|
611 } |
|
612 } |
|
613 |
|
614 static void init_gtk_treeview() |
|
615 { |
|
616 GtkWidget *gtkTreeView = QGtk::gtk_tree_view_new(); |
|
617 QGtk::gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, QGtk::gtk_tree_view_column_new()); |
|
618 QGtk::gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, QGtk::gtk_tree_view_column_new()); |
|
619 QGtk::gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, QGtk::gtk_tree_view_column_new()); |
|
620 add_widget(gtkTreeView); |
|
621 } |
|
622 |
|
623 |
|
624 // Fetch the application font from the pango font description |
|
625 // contained in the theme. |
|
626 QFont QGtk::getThemeFont() |
|
627 { |
|
628 QFont font; |
|
629 GtkStyle *style = gtkStyle(); |
|
630 if (style && qApp->desktopSettingsAware()) |
|
631 { |
|
632 PangoFontDescription *gtk_font = style->font_desc; |
|
633 font.setPointSizeF((float)(pango_font_description_get_size(gtk_font))/PANGO_SCALE); |
|
634 |
|
635 QString family = QString::fromLatin1(pango_font_description_get_family(gtk_font)); |
|
636 if (!family.isEmpty()) |
|
637 font.setFamily(family); |
|
638 |
|
639 int weight = pango_font_description_get_weight(gtk_font); |
|
640 if (weight >= PANGO_WEIGHT_HEAVY) |
|
641 font.setWeight(QFont::Black); |
|
642 else if (weight >= PANGO_WEIGHT_BOLD) |
|
643 font.setWeight(QFont::Bold); |
|
644 else if (weight >= PANGO_WEIGHT_SEMIBOLD) |
|
645 font.setWeight(QFont::DemiBold); |
|
646 else if (weight >= PANGO_WEIGHT_NORMAL) |
|
647 font.setWeight(QFont::Normal); |
|
648 else |
|
649 font.setWeight(QFont::Light); |
|
650 |
|
651 PangoStyle fontstyle = pango_font_description_get_style(gtk_font); |
|
652 if (fontstyle == PANGO_STYLE_ITALIC) |
|
653 font.setStyle(QFont::StyleItalic); |
|
654 else if (fontstyle == PANGO_STYLE_OBLIQUE) |
|
655 font.setStyle(QFont::StyleOblique); |
|
656 else |
|
657 font.setStyle(QFont::StyleNormal); |
|
658 } |
|
659 return font; |
|
660 } |
|
661 |
|
662 GtkWidget* QGtk::gtkWidget(const QString &path) |
|
663 { |
|
664 GtkWidget *widget = gtkWidgetMap()->value(path); |
|
665 if (!widget) { |
|
666 // Theme might have rearranged widget internals |
|
667 widget = gtkWidgetMap()->value(path); |
|
668 } |
|
669 return widget; |
|
670 } |
|
671 |
|
672 GtkStyle* QGtk::gtkStyle(const QString &path) |
|
673 { |
|
674 if (gtkWidgetMap()->contains(path)) |
|
675 return gtkWidgetMap()->value(path)->style; |
|
676 return 0; |
|
677 } |
|
678 |
|
679 static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *, gpointer) |
|
680 { |
|
681 GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS; |
|
682 g_object_get(gtkToolBar, "toolbar-style", &toolbar_style, NULL); |
|
683 QWidgetList widgets = QApplication::allWidgets(); |
|
684 for (int i = 0; i < widgets.size(); ++i) { |
|
685 QWidget *widget = widgets.at(i); |
|
686 if (qobject_cast<QToolButton*>(widget)) { |
|
687 QEvent event(QEvent::StyleChange); |
|
688 QApplication::sendEvent(widget, &event); |
|
689 } |
|
690 } |
|
691 } |
|
692 |
|
693 void QGtk::initGtkWidgets() |
|
694 { |
|
695 // From gtkmain.c |
|
696 uid_t ruid = getuid (); |
|
697 uid_t rgid = getgid (); |
|
698 uid_t euid = geteuid (); |
|
699 uid_t egid = getegid (); |
|
700 if (ruid != euid || rgid != egid) { |
|
701 qWarning("\nThis process is currently running setuid or setgid.\nGTK+ does not allow this " |
|
702 "therefore Qt cannot use the GTK+ integration.\nTry launching your app using \'gksudo\', " |
|
703 "\'kdesudo\' or a similar tool.\n\n" |
|
704 "See http://www.gtk.org/setuid.html for more information.\n"); |
|
705 return; |
|
706 } |
|
707 |
|
708 init_gtk_window(); |
|
709 |
|
710 if (QGtk::gtk_init) { |
|
711 |
|
712 // Make all widgets respect the text direction |
|
713 if (qApp->layoutDirection() == Qt::RightToLeft) |
|
714 QGtk::gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); |
|
715 |
|
716 if (!gtkWidgetMap()->contains(QLS("GtkButton"))) { |
|
717 GtkWidget *gtkButton = QGtk::gtk_button_new(); |
|
718 add_widget(gtkButton); |
|
719 g_signal_connect(gtkButton, "style-set", G_CALLBACK(gtkStyleSetCallback), NULL); |
|
720 add_widget(QGtk::gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE)); |
|
721 add_widget(QGtk::gtk_hbutton_box_new()); |
|
722 add_widget(QGtk::gtk_check_button_new()); |
|
723 add_widget(QGtk::gtk_radio_button_new(NULL)); |
|
724 add_widget(QGtk::gtk_combo_box_new()); |
|
725 add_widget(QGtk::gtk_combo_box_entry_new()); |
|
726 add_widget(QGtk::gtk_entry_new()); |
|
727 add_widget(QGtk::gtk_frame_new(NULL)); |
|
728 add_widget(QGtk::gtk_expander_new("")); |
|
729 add_widget(QGtk::gtk_statusbar_new()); |
|
730 add_widget(QGtk::gtk_hscale_new((GtkAdjustment*)(QGtk::gtk_adjustment_new(1, 0, 1, 0, 0, 0)))); |
|
731 add_widget(QGtk::gtk_hscrollbar_new(NULL)); |
|
732 add_widget(QGtk::gtk_scrolled_window_new(NULL, NULL)); |
|
733 init_gtk_menu(); |
|
734 add_widget(QGtk::gtk_notebook_new()); |
|
735 add_widget(QGtk::gtk_progress_bar_new()); |
|
736 add_widget(QGtk::gtk_spin_button_new((GtkAdjustment*) |
|
737 (QGtk::gtk_adjustment_new(1, 0, 1, 0, 0, 0)), 0.1, 3)); |
|
738 GtkWidget *toolbar = QGtk::gtk_toolbar_new(); |
|
739 g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (update_toolbar_style), toolbar); |
|
740 QGtk::gtk_toolbar_insert((GtkToolbar*)toolbar, QGtk::gtk_separator_tool_item_new(), -1); |
|
741 add_widget(toolbar); |
|
742 init_gtk_treeview(); |
|
743 add_widget(QGtk::gtk_vscale_new((GtkAdjustment*)(QGtk::gtk_adjustment_new(1, 0, 1, 0, 0, 0)))); |
|
744 add_widget(QGtk::gtk_vscrollbar_new(NULL)); |
|
745 } |
|
746 else // Rebuild map |
|
747 { |
|
748 // When styles change subwidgets can get rearranged |
|
749 // as with the combo box. We need to update the widget map |
|
750 // to reflect this; |
|
751 QHash<QString, GtkWidget*> oldMap = *gtkWidgetMap(); |
|
752 gtkWidgetMap()->clear(); |
|
753 QHashIterator<QString, GtkWidget*> it(oldMap); |
|
754 while (it.hasNext()) { |
|
755 it.next(); |
|
756 if (!it.key().contains(QLatin1Char('.'))) { |
|
757 add_all_sub_widgets(it.value()); |
|
758 } |
|
759 } |
|
760 } |
|
761 } |
|
762 } |
|
763 |
|
764 // ----------- Native file dialogs ----------- |
|
765 |
|
766 // Extract filter list from expressions of type: foo (*.a *.b *.c)" |
|
767 static QStringList extract_filter(const QString &rawFilter) |
|
768 { |
|
769 QString result = rawFilter; |
|
770 QRegExp r(QString::fromLatin1("^([^()]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$")); |
|
771 int index = r.indexIn(result); |
|
772 if (index >= 0) |
|
773 result = r.cap(2); |
|
774 return result.split(QLatin1Char(' ')); |
|
775 } |
|
776 |
|
777 extern QStringList qt_make_filter_list(const QString &filter); |
|
778 |
|
779 static void setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent, |
|
780 const QString &dir, const QString &filter, QString *selectedFilter, |
|
781 QFileDialog::Options options, bool isSaveDialog = false, |
|
782 QMap<GtkFileFilter *, QString> *filterMap = 0) |
|
783 { |
|
784 g_object_set(gtkFileChooser, "do-overwrite-confirmation", gboolean(!(options & QFileDialog::DontConfirmOverwrite)), NULL); |
|
785 g_object_set(gtkFileChooser, "local_only", gboolean(true), NULL); |
|
786 if (!filter.isEmpty()) { |
|
787 QStringList filters = qt_make_filter_list(filter); |
|
788 foreach (const QString &rawfilter, filters) { |
|
789 GtkFileFilter *gtkFilter = QGtk::gtk_file_filter_new (); |
|
790 QString name = rawfilter.left(rawfilter.indexOf(QLatin1Char('('))); |
|
791 QStringList extensions = extract_filter(rawfilter); |
|
792 QGtk::gtk_file_filter_set_name(gtkFilter, qPrintable(name.isEmpty() ? extensions.join(QLS(", ")) : name)); |
|
793 |
|
794 foreach (const QString &fileExtension, extensions) { |
|
795 // Note Gtk file dialogs are by default case sensitive |
|
796 // and only supports basic glob syntax so we |
|
797 // rewrite .xyz to .[xX][yY][zZ] |
|
798 QString caseInsensitive; |
|
799 for (int i = 0 ; i < fileExtension.length() ; ++i) { |
|
800 QChar ch = fileExtension.at(i); |
|
801 if (ch.isLetter()) { |
|
802 caseInsensitive.append( |
|
803 QLatin1Char('[') + |
|
804 ch.toLower() + |
|
805 ch.toUpper() + |
|
806 QLatin1Char(']')); |
|
807 } else { |
|
808 caseInsensitive.append(ch); |
|
809 } |
|
810 } |
|
811 QGtk::gtk_file_filter_add_pattern (gtkFilter, qPrintable(caseInsensitive)); |
|
812 |
|
813 } |
|
814 if (filterMap) |
|
815 filterMap->insert(gtkFilter, rawfilter); |
|
816 QGtk::gtk_file_chooser_add_filter((GtkFileChooser*)gtkFileChooser, gtkFilter); |
|
817 if (selectedFilter && (rawfilter == *selectedFilter)) |
|
818 QGtk::gtk_file_chooser_set_filter((GtkFileChooser*)gtkFileChooser, gtkFilter); |
|
819 } |
|
820 } |
|
821 |
|
822 // Using the currently active window is not entirely correct, however |
|
823 // it gives more sensible behavior for applications that do not provide a |
|
824 // parent |
|
825 QWidget *modalFor = parent ? parent->window() : qApp->activeWindow(); |
|
826 if (modalFor) { |
|
827 QGtk::gtk_widget_realize(gtkFileChooser); // Creates X window |
|
828 XSetTransientForHint(QGtk::gdk_x11_drawable_get_xdisplay(gtkFileChooser->window), |
|
829 QGtk::gdk_x11_drawable_get_xid(gtkFileChooser->window), |
|
830 modalFor->winId()); |
|
831 QGtk::gdk_x11_window_set_user_time (gtkFileChooser->window, QX11Info::appUserTime()); |
|
832 |
|
833 } |
|
834 |
|
835 QFileInfo fileinfo(dir); |
|
836 if (dir.isEmpty()) |
|
837 fileinfo.setFile(QDir::currentPath()); |
|
838 fileinfo.makeAbsolute(); |
|
839 if (fileinfo.isDir()) { |
|
840 QGtk::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(dir)); |
|
841 } else if (isSaveDialog) { |
|
842 QGtk::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.absolutePath())); |
|
843 QGtk::gtk_file_chooser_set_current_name((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.fileName())); |
|
844 } else { |
|
845 QGtk::gtk_file_chooser_set_filename((GtkFileChooser*)gtkFileChooser, qPrintable(dir)); |
|
846 } |
|
847 } |
|
848 |
|
849 QString QGtk::openFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, |
|
850 QString *selectedFilter, QFileDialog::Options options) |
|
851 { |
|
852 QMap<GtkFileFilter *, QString> filterMap; |
|
853 GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), |
|
854 NULL, |
|
855 GTK_FILE_CHOOSER_ACTION_OPEN, |
|
856 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
857 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
858 NULL); |
|
859 |
|
860 setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap); |
|
861 |
|
862 QWidget modal_widget; |
|
863 modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); |
|
864 modal_widget.setParent(parent, Qt::Window); |
|
865 QApplicationPrivate::enterModal(&modal_widget); |
|
866 |
|
867 QString filename; |
|
868 if (QGtk::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { |
|
869 char *gtk_filename = QGtk::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); |
|
870 filename = QString::fromUtf8(gtk_filename); |
|
871 g_free (gtk_filename); |
|
872 if (selectedFilter) { |
|
873 GtkFileFilter *gtkFilter = QGtk::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); |
|
874 *selectedFilter = filterMap.value(gtkFilter); |
|
875 } |
|
876 } |
|
877 |
|
878 QApplicationPrivate::leaveModal(&modal_widget); |
|
879 gtk_widget_destroy (gtkFileChooser); |
|
880 return filename; |
|
881 } |
|
882 |
|
883 |
|
884 QString QGtk::openDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options) |
|
885 { |
|
886 QMap<GtkFileFilter *, QString> filterMap; |
|
887 GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), |
|
888 NULL, |
|
889 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, |
|
890 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
891 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
892 NULL); |
|
893 |
|
894 setupGtkFileChooser(gtkFileChooser, parent, dir, QString(), 0, options); |
|
895 QWidget modal_widget; |
|
896 modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); |
|
897 modal_widget.setParent(parent, Qt::Window); |
|
898 QApplicationPrivate::enterModal(&modal_widget); |
|
899 |
|
900 QString filename; |
|
901 if (QGtk::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { |
|
902 char *gtk_filename = QGtk::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); |
|
903 filename = QString::fromUtf8(gtk_filename); |
|
904 g_free (gtk_filename); |
|
905 } |
|
906 |
|
907 QApplicationPrivate::leaveModal(&modal_widget); |
|
908 gtk_widget_destroy (gtkFileChooser); |
|
909 return filename; |
|
910 } |
|
911 |
|
912 QStringList QGtk::openFilenames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, |
|
913 QString *selectedFilter, QFileDialog::Options options) |
|
914 { |
|
915 QStringList filenames; |
|
916 QMap<GtkFileFilter *, QString> filterMap; |
|
917 GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), |
|
918 NULL, |
|
919 GTK_FILE_CHOOSER_ACTION_OPEN, |
|
920 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
921 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|
922 NULL); |
|
923 |
|
924 setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap); |
|
925 g_object_set(gtkFileChooser, "select-multiple", gboolean(true), NULL); |
|
926 |
|
927 QWidget modal_widget; |
|
928 modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); |
|
929 modal_widget.setParent(parent, Qt::Window); |
|
930 QApplicationPrivate::enterModal(&modal_widget); |
|
931 |
|
932 if (gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { |
|
933 GSList *gtk_file_names = QGtk::gtk_file_chooser_get_filenames((GtkFileChooser*)gtkFileChooser); |
|
934 for (GSList *iterator = gtk_file_names ; iterator; iterator = iterator->next) |
|
935 filenames << QString::fromUtf8((const char*)iterator->data); |
|
936 g_slist_free(gtk_file_names); |
|
937 if (selectedFilter) { |
|
938 GtkFileFilter *gtkFilter = QGtk::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); |
|
939 *selectedFilter = filterMap.value(gtkFilter); |
|
940 } |
|
941 } |
|
942 |
|
943 QApplicationPrivate::leaveModal(&modal_widget); |
|
944 gtk_widget_destroy (gtkFileChooser); |
|
945 return filenames; |
|
946 } |
|
947 |
|
948 QString QGtk::saveFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, |
|
949 QString *selectedFilter, QFileDialog::Options options) |
|
950 { |
|
951 QMap<GtkFileFilter *, QString> filterMap; |
|
952 GtkWidget *gtkFileChooser = QGtk::gtk_file_chooser_dialog_new (qPrintable(caption), |
|
953 NULL, |
|
954 GTK_FILE_CHOOSER_ACTION_SAVE, |
|
955 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
956 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
|
957 NULL); |
|
958 setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, true, &filterMap); |
|
959 |
|
960 QWidget modal_widget; |
|
961 modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); |
|
962 modal_widget.setParent(parent, Qt::Window); |
|
963 QApplicationPrivate::enterModal(&modal_widget); |
|
964 |
|
965 QString filename; |
|
966 if (QGtk::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) { |
|
967 char *gtk_filename = QGtk::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser); |
|
968 filename = QString::fromUtf8(gtk_filename); |
|
969 g_free (gtk_filename); |
|
970 if (selectedFilter) { |
|
971 GtkFileFilter *gtkFilter = QGtk::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser); |
|
972 *selectedFilter = filterMap.value(gtkFilter); |
|
973 } |
|
974 } |
|
975 |
|
976 QApplicationPrivate::leaveModal(&modal_widget); |
|
977 gtk_widget_destroy (gtkFileChooser); |
|
978 return filename; |
|
979 } |
|
980 |
|
981 QIcon QGtk::getFilesystemIcon(const QFileInfo &info) |
|
982 { |
|
983 QIcon icon; |
|
984 if (QGtk::gnome_vfs_init && QGtk::gnome_icon_lookup_sync) { |
|
985 QGtk::gnome_vfs_init(); |
|
986 GtkIconTheme *theme = QGtk::gtk_icon_theme_get_default(); |
|
987 QByteArray fileurl = QUrl::fromLocalFile(info.absoluteFilePath()).toEncoded(); |
|
988 char * icon_name = QGtk::gnome_icon_lookup_sync(theme, |
|
989 NULL, |
|
990 fileurl.data(), |
|
991 NULL, |
|
992 GNOME_ICON_LOOKUP_FLAGS_NONE, |
|
993 NULL); |
|
994 QString iconName = QString::fromUtf8(icon_name); |
|
995 g_free(icon_name); |
|
996 if (iconName.startsWith(QLatin1Char('/'))) |
|
997 return QIcon(iconName); |
|
998 return QIcon::fromTheme(iconName); |
|
999 } |
|
1000 return icon; |
|
1001 } |
|
1002 |
|
1003 QT_END_NAMESPACE |
|
1004 |
|
1005 #endif // !defined(QT_NO_STYLE_GTK) |