NetSurf
compat.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 Rob Kendrick <rjek@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * Compatibility functions for older GTK versions (interface)
22 */
23
24#ifndef NETSURF_GTK_COMPAT_H_
25#define NETSURF_GTK_COMPAT_H_
26
27#include <stdint.h>
28
29#include <gtk/gtk.h>
30
31/* gtk 3.10 depricated the use of stock names */
32#if GTK_CHECK_VERSION(3,10,0)
33#define NSGTK_USE_ICON_NAME
34#else
35#undef NSGTK_USE_ICON_NAME
36#endif
37
38/* icon names instead of stock */
39#ifdef NSGTK_USE_ICON_NAME
40#define NSGTK_STOCK_ADD "list-add"
41#define NSGTK_STOCK_CANCEL "_Cancel"
42#define NSGTK_STOCK_CLEAR "edit-clear"
43#define NSGTK_STOCK_CLOSE "window-close"
44#define NSGTK_STOCK_HOME "go-home"
45#define NSGTK_STOCK_INFO "dialog-information"
46#define NSGTK_STOCK_REFRESH "view-refresh"
47#define NSGTK_STOCK_SAVE "document-save"
48#define NSGTK_STOCK_SAVE_AS "document-save-as"
49#define NSGTK_STOCK_STOP "process-stop"
50#define NSGTK_STOCK_OK "_OK"
51#define NSGTK_STOCK_OPEN "_Open"
52#define NSGTK_STOCK_OPEN_MENU "open-menu"
53#else
54#define NSGTK_STOCK_ADD GTK_STOCK_ADD
55#define NSGTK_STOCK_CANCEL GTK_STOCK_CANCEL
56#define NSGTK_STOCK_CLEAR GTK_STOCK_CLEAR
57#define NSGTK_STOCK_CLOSE GTK_STOCK_CLOSE
58#define NSGTK_STOCK_HOME GTK_STOCK_HOME
59#define NSGTK_STOCK_INFO GTK_STOCK_INFO
60#define NSGTK_STOCK_REFRESH GTK_STOCK_REFRESH
61#define NSGTK_STOCK_SAVE GTK_STOCK_SAVE
62#define NSGTK_STOCK_SAVE_AS GTK_STOCK_SAVE_AS
63#define NSGTK_STOCK_STOP GTK_STOCK_STOP
64#define NSGTK_STOCK_OK GTK_STOCK_OK
65#define NSGTK_STOCK_OPEN GTK_STOCK_OPEN
66#define NSGTK_STOCK_OPEN_MENU GTK_STOCK_JUSTIFY_FILL
67#endif
68
69/* widget alignment only available since 3.0 */
70#if !GTK_CHECK_VERSION(3,0,0)
71typedef enum {
78#endif
79
80/* value init since gtk 2.30 */
81#ifndef G_VALUE_INIT
82#define G_VALUE_INIT { 0, { { 0 } } }
83#endif
84
85
86/**
87 * Set the alignment of a widget.
88 *
89 * sets both the horizontal and vertical alignement of a widget
90 *
91 * @note this type of alignemnt was not available prior to GTK 3.0 so
92 * we emulate it using gtk_misc_set_alignment.
93 *
94 * \param widget The widget to set alignent on.
95 * \param halign The horizontal alignment to set.
96 * \param valign The vertical alignment to set
97 */
98void nsgtk_widget_set_alignment(GtkWidget *widget, GtkAlign halign, GtkAlign valign);
99
100/**
101 * Set the margins of a widget
102 *
103 * Sets the margin all round a widget.
104 *
105 * @note this type of margin was not available prior to GTK 3.0 so
106 * we emulate it using gtk_misc_set_padding.
107 *
108 * \param widget The widget to set alignent on.
109 * \param hmargin The horizontal margin.
110 * \param vmargin The vertical margin.
111 */
112void nsgtk_widget_set_margins(GtkWidget *widget, gint hmargin, gint vmargin);
113
114void nsgtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus);
115gboolean nsgtk_widget_has_focus(GtkWidget *widget);
116gboolean nsgtk_widget_get_visible(GtkWidget *widget);
117gboolean nsgtk_widget_get_realized(GtkWidget *widget);
118gboolean nsgtk_widget_get_mapped(GtkWidget *widget);
119gboolean nsgtk_widget_is_drawable(GtkWidget *widget);
120void nsgtk_dialog_set_has_separator(GtkDialog *dialog, gboolean setting);
121GtkWidget *nsgtk_combo_box_text_new(void);
122void nsgtk_combo_box_text_append_text(GtkWidget *combo_box, const gchar *text);
123gchar *nsgtk_combo_box_text_get_active_text(GtkWidget *combo_box);
124
125/**
126 * creates a new image widget of an appropriate icon size from a pixbuf.
127 *
128 * \param pixbuf The pixbuf to use as a source.
129 * \param size The size of icon to create
130 * \return An image widget.
131 */
132GtkWidget *nsgtk_image_new_from_pixbuf_icon(GdkPixbuf *pixbuf, GtkIconSize size);
133
134/* GTK prior to 2.16 needs the sexy interface for icons */
135#if !GTK_CHECK_VERSION(2,16,0)
136
137#include "gtk/sexy_icon_entry.h"
138
139typedef enum {
143
144GtkStateType nsgtk_widget_get_state(GtkWidget *widget);
145
146#endif
147
148#if GTK_CHECK_VERSION (2, 90, 7)
149#define GDK_KEY(symbol) GDK_KEY_##symbol
150#else
151#include <gdk/gdkkeysyms.h>
152#define GDK_KEY(symbol) GDK_##symbol
153#endif
154
155#if !GTK_CHECK_VERSION(3,0,0)
156typedef GtkStateType GtkStateFlags;
157typedef GtkStyle GtkStyleContext;
158
159/* gtk 3 changed the enum name for the state flags */
160#define GTK_STATE_FLAG_NORMAL GTK_STATE_NORMAL
161
162#if GTK_CHECK_VERSION(2,22,0)
163enum {
164 GTK_IN_DESTRUCTION = 1 << 0,
165};
166#define GTK_OBJECT_FLAGS(obj) (GTK_OBJECT (obj)->flags)
167#endif
168
169#define gtk_widget_in_destruction(widget) \
170 (GTK_OBJECT_FLAGS(GTK_OBJECT(widget)) & GTK_IN_DESTRUCTION)
171
172#endif
173
174
175/**
176 * Sets the icon shown in the entry at the specified position from an
177 * icon name.
178 *
179 * Compatability interface for original introduced in 2.16
180 *
181 * \param entry The entry widget to set the icon on.
182 * \param icon_pos The position of the icon.
183 * \param stock_id the name of the stock item.
184 */
185void nsgtk_entry_set_icon_from_icon_name(GtkWidget *entry, GtkEntryIconPosition icon_pos, const gchar *stock_id);
186
187/**
188 * Creates a GtkImage displaying a stock icon.
189 *
190 * Compatability interface for original deprecated in GTK 3.10
191 *
192 * \param stock_id the name of the stock item.
193 * \param size The size of icon to create.
194 * \return The created image widget or NULL on error
195 */
196GtkWidget *nsgtk_image_new_from_stock(const gchar *stock_id, GtkIconSize size);
197
198/**
199 * Creates a new GtkButton containing the image and text from a stock item.
200 *
201 * Compatability interface for original deprecated in GTK 3.10
202 *
203 * \param stock_id the name of the stock item
204 */
205GtkWidget *nsgtk_button_new_from_stock(const gchar *stock_id);
206
207/**
208 * Fills item with the registered values for stock_id.
209 *
210 * Compatability interface for original deprecated in GTK 3.10
211 *
212 * \param stock_id the name of the stock item.
213 * \param item The structure to update if the stock_id was known.
214 * \return TRUE if stock_id was known.
215 */
216gboolean nsgtk_stock_lookup(const gchar *stock_id, GtkStockItem *item);
217
218/**
219 * Sets whether the button will grab focus when it is clicked with the mouse.
220 *
221 * Compatability interface for original deprecated in GTK 3.20
222 *
223 * \param button The button alter
224 * \param focus_on_click whether the button grabs focus when clicked with the mouse
225 */
226void nsgtk_button_set_focus_on_click(GtkButton *button, gboolean focus_on_click);
227
228void nsgtk_window_set_opacity(GtkWindow *window, gdouble opacity);
229
230void nsgtk_scrolled_window_add_with_viewport(GtkScrolledWindow *window, GtkWidget *child);
231
232GtkWidget *nsgtk_entry_new(void);
233
234void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry, GtkEntryIconPosition icon_pos, GdkPixbuf *pixbuf);
235
236void nsgtk_widget_override_background_color(GtkWidget *widget, GtkStateFlags state, uint16_t a, uint16_t r, uint16_t g, uint16_t b);
237GtkWidget* nsgtk_hbox_new(gboolean homogeneous, gint spacing);
238GtkWidget* nsgtk_vbox_new(gboolean homogeneous, gint spacing);
241const PangoFontDescription* nsgtk_style_context_get_font(GtkStyleContext *style, GtkStateFlags state);
242gulong nsgtk_connect_draw_event(GtkWidget *widget, GCallback callback, gpointer g);
243void nsgdk_cursor_unref(GdkCursor *cursor);
244void nsgtk_widget_modify_font(GtkWidget *widget, PangoFontDescription *font_desc);
245GdkWindow *nsgtk_widget_get_window(GtkWidget *widget);
246GtkWidget *nsgtk_dialog_get_content_area(GtkDialog *dialog);
247gboolean nsgtk_show_uri(GdkScreen *screen, const gchar *uri, guint32 timestamp, GError **error);
248GdkWindow *nsgtk_layout_get_bin_window(GtkLayout *layout);
249void nsgtk_widget_get_allocation(GtkWidget *widget, GtkAllocation *allocation);
250
251gboolean nsgtk_icon_size_lookup_for_settings (GtkSettings *settings, GtkIconSize size, gint *width, gint *height);
252
253GtkAdjustment *nsgtk_layout_get_vadjustment(GtkLayout *layout);
254GtkAdjustment *nsgtk_layout_get_hadjustment(GtkLayout *layout);
255void nsgtk_layout_set_hadjustment(GtkLayout *layout, GtkAdjustment *adj);
256void nsgtk_layout_set_vadjustment(GtkLayout *layout, GtkAdjustment *adj);
257gdouble nsgtk_adjustment_get_step_increment(GtkAdjustment *adjustment);
258gdouble nsgtk_adjustment_get_upper(GtkAdjustment *adjustment);
259gdouble nsgtk_adjustment_get_lower(GtkAdjustment *adjustment);
260gdouble nsgtk_adjustment_get_page_increment(GtkAdjustment *adjustment);
261
262/* menu compatability */
263
264/**
265 * Creates a new GtkImageMenuItem containing a label.
266 *
267 * Compatability interface for original deprecated in GTK 3.10.
268 * @note post 3.10 this creates a GtkMenuItem.
269 *
270 * \param label The text of the button, with an underscore in front of
271 * the mnemonic character.
272 * \return a new GtkMenuItem
273 */
274GtkWidget *nsgtk_image_menu_item_new_with_mnemonic(const gchar *label);
275
276/**
277 * Sets the image of image_menu_item to the given widget.
278 *
279 * Compatability interface for original deprecated in GTK 3.10.
280 * @note post 3.10 this is empty as menu creation generates GtkMenuItem.
281 *
282 * \param image_menu_item The image menu entry item.
283 * \param image The image to set.
284 */
285void nsgtk_image_menu_item_set_image(GtkWidget *image_menu_item, GtkWidget *image);
286
287/**
288 * Displays menu and makes it available for selection
289 *
290 * Compatability interface for gtk_menu_popup deprecated in GTK 3.22.
291 *
292 * \param image_menu_item The image menu entry item.
293 * \param trigger_event the GdkEvent that initiated this request or NULL if it's the current event.
294 */
295void nsgtk_menu_popup_at_pointer(GtkMenu *menu, const GdkEvent *trigger_event);
296
297/**
298 * Parses a resource file containing a GtkBuilder UI definition and
299 * merges it with the current contents of builder.
300 *
301 * Compatability interface as this did not exist prior to GTK 3.4
302 *
303 * GTK prior to 3.4 can have the resources in a GResource but
304 * gtk_builder cannot directly instantiate from them
305 *
306 * GTK 3.4 onwards can use gtk_builder_add_from_resource() to add
307 * directly from resources. The gtk_builder_new_ type operations
308 * cannot be used because they are only available post 3.10 and handle
309 * all errors by aborting the application
310 *
311 * @note prior to GLIB 2.32 resources did not exist and this wrapper
312 * returns the error code.
313 *
314 * \param builder a GtkBuilder
315 * \param resource_path the path of the resource file to parse
316 * \param error return location for an error, or NULL.
317 * \return A positive value on success, 0 if an error occurred.
318 */
319guint nsgtk_builder_add_from_resource(GtkBuilder *builder, const gchar *resource_path, GError **error);
320
321#endif /* NETSURF_GTK_COMPAT_H */
GtkEntryIconPosition
Definition: compat.h:139
@ GTK_ENTRY_ICON_PRIMARY
Definition: compat.h:140
@ GTK_ENTRY_ICON_SECONDARY
Definition: compat.h:141
GtkWidget * nsgtk_image_new_from_stock(const gchar *stock_id, GtkIconSize size)
Creates a GtkImage displaying a stock icon.
Definition: compat.c:198
void nsgtk_layout_set_vadjustment(GtkLayout *layout, GtkAdjustment *adj)
Definition: compat.c:307
void nsgtk_window_set_opacity(GtkWindow *window, gdouble opacity)
Definition: compat.c:522
GtkStateFlags nsgtk_widget_get_state_flags(GtkWidget *widget)
Definition: compat.c:335
void nsgtk_widget_get_allocation(GtkWidget *widget, GtkAllocation *allocation)
Definition: compat.c:489
void nsgtk_button_set_focus_on_click(GtkButton *button, gboolean focus_on_click)
Sets whether the button will grab focus when it is clicked with the mouse.
Definition: compat.c:219
void nsgtk_widget_override_background_color(GtkWidget *widget, GtkStateFlags state, uint16_t a, uint16_t r, uint16_t g, uint16_t b)
Definition: compat.c:240
gboolean nsgtk_show_uri(GdkScreen *screen, const gchar *uri, guint32 timestamp, GError **error)
Definition: compat.c:426
gboolean nsgtk_widget_is_drawable(GtkWidget *widget)
Definition: compat.c:96
gchar * nsgtk_combo_box_text_get_active_text(GtkWidget *combo_box)
Definition: compat.c:133
void nsgtk_combo_box_text_append_text(GtkWidget *combo_box, const gchar *text)
Definition: compat.c:123
void nsgtk_dialog_set_has_separator(GtkDialog *dialog, gboolean setting)
Definition: compat.c:105
GtkStyle GtkStyleContext
Definition: compat.h:157
GtkWidget * nsgtk_image_new_from_pixbuf_icon(GdkPixbuf *pixbuf, GtkIconSize size)
creates a new image widget of an appropriate icon size from a pixbuf.
Definition: compat.c:502
void nsgtk_widget_set_margins(GtkWidget *widget, gint hmargin, gint vmargin)
Set the margins of a widget.
Definition: compat.c:625
gboolean nsgtk_stock_lookup(const gchar *stock_id, GtkStockItem *item)
Fills item with the registered values for stock_id.
Definition: compat.c:230
gboolean nsgtk_widget_get_visible(GtkWidget *widget)
Definition: compat.c:69
const PangoFontDescription * nsgtk_style_context_get_font(GtkStyleContext *style, GtkStateFlags state)
Definition: compat.c:357
void nsgtk_layout_set_hadjustment(GtkLayout *layout, GtkAdjustment *adj)
Definition: compat.c:297
GdkWindow * nsgtk_widget_get_window(GtkWidget *widget)
Definition: compat.c:404
GtkWidget * nsgtk_hbox_new(gboolean homogeneous, gint spacing)
Definition: compat.c:317
GtkStyleContext * nsgtk_widget_get_style_context(GtkWidget *widget)
Definition: compat.c:348
gulong nsgtk_connect_draw_event(GtkWidget *widget, GCallback callback, gpointer g)
Definition: compat.c:373
GtkAlign
Definition: compat.h:71
@ GTK_ALIGN_END
Definition: compat.h:74
@ GTK_ALIGN_FILL
Definition: compat.h:72
@ GTK_ALIGN_CENTER
Definition: compat.h:75
@ GTK_ALIGN_START
Definition: compat.h:73
@ GTK_ALIGN_BASELINE
Definition: compat.h:76
void nsgdk_cursor_unref(GdkCursor *cursor)
Definition: compat.c:384
GtkStateType GtkStateFlags
Definition: compat.h:156
gdouble nsgtk_adjustment_get_page_increment(GtkAdjustment *adjustment)
Definition: compat.c:480
void nsgtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus)
Definition: compat.c:48
guint nsgtk_builder_add_from_resource(GtkBuilder *builder, const gchar *resource_path, GError **error)
Parses a resource file containing a GtkBuilder UI definition and merges it with the current contents ...
Definition: compat.c:646
void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry, GtkEntryIconPosition icon_pos, GdkPixbuf *pixbuf)
Definition: compat.c:151
GtkStateType nsgtk_widget_get_state(GtkWidget *widget)
void nsgtk_widget_set_alignment(GtkWidget *widget, GtkAlign halign, GtkAlign valign)
Set the alignment of a widget.
Definition: compat.c:585
GtkWidget * nsgtk_dialog_get_content_area(GtkDialog *dialog)
Definition: compat.c:413
GtkWidget * nsgtk_entry_new(void)
Definition: compat.c:142
gboolean nsgtk_icon_size_lookup_for_settings(GtkSettings *settings, GtkIconSize size, gint *width, gint *height)
Definition: compat.c:572
void nsgtk_entry_set_icon_from_icon_name(GtkWidget *entry, GtkEntryIconPosition icon_pos, const gchar *stock_id)
Sets the icon shown in the entry at the specified position from an icon name.
Definition: compat.c:173
gdouble nsgtk_adjustment_get_upper(GtkAdjustment *adjustment)
Definition: compat.c:462
gboolean nsgtk_widget_has_focus(GtkWidget *widget)
Definition: compat.c:60
gdouble nsgtk_adjustment_get_lower(GtkAdjustment *adjustment)
Definition: compat.c:471
GtkWidget * nsgtk_vbox_new(gboolean homogeneous, gint spacing)
Definition: compat.c:326
GtkWidget * nsgtk_button_new_from_stock(const gchar *stock_id)
Creates a new GtkButton containing the image and text from a stock item.
Definition: compat.c:209
GtkWidget * nsgtk_image_menu_item_new_with_mnemonic(const gchar *label)
Creates a new GtkImageMenuItem containing a label.
Definition: compat.c:543
GtkAdjustment * nsgtk_layout_get_vadjustment(GtkLayout *layout)
Definition: compat.c:269
void nsgtk_image_menu_item_set_image(GtkWidget *image_menu_item, GtkWidget *image)
Sets the image of image_menu_item to the given widget.
Definition: compat.c:553
GtkWidget * nsgtk_combo_box_text_new(void)
Definition: compat.c:114
gboolean nsgtk_widget_get_mapped(GtkWidget *widget)
Definition: compat.c:87
void nsgtk_scrolled_window_add_with_viewport(GtkScrolledWindow *window, GtkWidget *child)
Definition: compat.c:532
GtkAdjustment * nsgtk_layout_get_hadjustment(GtkLayout *layout)
Definition: compat.c:278
GdkWindow * nsgtk_layout_get_bin_window(GtkLayout *layout)
Definition: compat.c:444
gdouble nsgtk_adjustment_get_step_increment(GtkAdjustment *adjustment)
Definition: compat.c:453
void nsgtk_widget_modify_font(GtkWidget *widget, PangoFontDescription *font_desc)
Definition: compat.c:393
void nsgtk_menu_popup_at_pointer(GtkMenu *menu, const GdkEvent *trigger_event)
Displays menu and makes it available for selection.
Definition: compat.c:561
gboolean nsgtk_widget_get_realized(GtkWidget *widget)
Definition: compat.c:78
wimp_w dialog
Definition: dialog.c:87
static struct print_settings * settings
Definition: print.c:50
int width
Definition: gui.c:159
int height
Definition: gui.c:160
@ SEXY_ICON_ENTRY_SECONDARY
@ SEXY_ICON_ENTRY_PRIMARY
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978