You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1127 lines
25 KiB
1127 lines
25 KiB
/*
|
|
* Copyright 2010 Rob Kendrick <rjek@netsurf-browser.org>
|
|
*
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
*
|
|
* NetSurf 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; version 2 of the License.
|
|
*
|
|
* NetSurf 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, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* \file
|
|
* Compatibility functions for older GTK versions implementation
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "gtk/compat.h"
|
|
|
|
#if GTK_CHECK_VERSION(3,22,0)
|
|
#include "gtk/scaffolding.h"
|
|
#endif
|
|
|
|
#ifdef _SEXY_ICON_ENTRY_H_
|
|
#include "gtk/sexy_icon_entry.c"
|
|
|
|
/*
|
|
* exported interface documented in gtk/compat.h
|
|
*
|
|
* Only required for the lib sexy interface before 2.16
|
|
*/
|
|
GtkStateType nsgtk_widget_get_state(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,18,0)
|
|
return gtk_widget_get_state(widget);
|
|
#else
|
|
return GTK_WIDGET_STATE(widget);
|
|
#endif
|
|
}
|
|
|
|
#endif /* _SEXY_ICON_ENTRY_H_ */
|
|
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
GdkScreen* gdk_screen_get_default(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
gdouble gdk_screen_get_resolution(GdkScreen* screen) {
|
|
return 180;
|
|
}
|
|
|
|
PangoContext* gdk_pango_context_get()
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
|
|
GtkWidget* gtk_menu_new(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
GtkWidget* gtk_check_menu_item_new_with_label(const gchar* label)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void gtk_check_menu_item_set_active(GtkCheckMenuItem* check_menu_item, gboolean is_active)
|
|
{
|
|
}
|
|
|
|
void gtk_menu_shell_append(GtkMenuShell* menu_shell, GtkWidget* child)
|
|
{
|
|
}
|
|
|
|
void gtk_widget_show_all(GtkWidget *widget)
|
|
{
|
|
}
|
|
|
|
void gtk_widget_destroy(GtkWidget* widget)
|
|
{
|
|
g_object_unref(widget);
|
|
}
|
|
|
|
gboolean gtk_check_menu_item_get_active(GtkCheckMenuItem* check_menu_item)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
void gtk_menu_item_set_submenu(GtkMenuItem* menu_item, GtkWidget* submenu)
|
|
{
|
|
}
|
|
|
|
GtkWidget*gtk_menu_item_new_with_mnemonic(const gchar* label)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
GtkWidget *gtk_separator_menu_item_new (void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void gtk_widget_add_accelerator (GtkWidget* widget, const gchar* accel_signal, GtkAccelGroup* accel_group, guint accel_key, GdkModifierType accel_mods, GtkAccelFlags accel_flags)
|
|
{
|
|
}
|
|
|
|
void gtk_box_pack_start(GtkBox* box, GtkWidget* child, gboolean expand, gboolean fill, guint padding)
|
|
{
|
|
}
|
|
|
|
void gtk_label_set_line_wrap(GtkLabel* label, gboolean wrap)
|
|
{
|
|
}
|
|
|
|
gboolean gtk_show_uri_on_window(GtkWindow* parent, const char* uri, guint32 timestamp, GError** error)
|
|
{
|
|
}
|
|
|
|
void gtk_menu_popup_at_pointer(GtkMenu* menu, const GdkEvent* trigger_event)
|
|
{
|
|
}
|
|
|
|
void gtk_container_add(GtkContainer* container, GtkWidget* widget)
|
|
{
|
|
}
|
|
|
|
gint gtk_dialog_run(GtkDialog* dialog)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
gboolean gtk_icon_size_lookup(GtkIconSize size, gint* width, gint* height)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
void gtk_builder_connect_signals(GtkBuilder* builder, gpointer user_data)
|
|
{
|
|
}
|
|
|
|
const gchar*gtk_entry_get_text(GtkEntry* entry)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void gtk_widget_queue_draw_area(GtkWidget* widget, gint x, gint y, gint width, gint height)
|
|
{
|
|
}
|
|
|
|
GdkWindow*gtk_widget_get_parent_window(GtkWidget* widget)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void gtk_im_context_set_client_window(GtkIMContext *context, GdkWindow *window)
|
|
{
|
|
}
|
|
|
|
void gtk_file_chooser_set_do_overwrite_confirmation(GtkFileChooser* chooser, gboolean do_overwrite_confirmation)
|
|
{
|
|
}
|
|
|
|
gchar* gtk_file_chooser_get_filename(GtkFileChooser* chooser)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void gtk_button_set_image(GtkButton* button, GtkWidget* image)
|
|
{
|
|
}
|
|
|
|
GtkIconTheme* gtk_icon_theme_get_default(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void gtk_window_set_default_icon (GdkPixbuf* icon)
|
|
{
|
|
}
|
|
|
|
gboolean gtk_main_iteration_do ( gboolean blocking )
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
gboolean gtk_main_iteration ( void)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
gboolean gtk_events_pending(void)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
void gtk_window_set_type_hint(GtkWindow* window, GdkWindowTypeHint hint)
|
|
{
|
|
}
|
|
|
|
GtkWidget* gtk_check_menu_item_new_with_mnemonic(const gchar* label)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void gtk_menu_set_accel_group (GtkMenu *menu, GtkAccelGroup *accel_group)
|
|
{
|
|
}
|
|
|
|
void gtk_entry_set_text (GtkEntry* entry, const gchar* text )
|
|
{
|
|
}
|
|
GtkWidget* gtk_widget_get_toplevel ( GtkWidget* widget )
|
|
{
|
|
return NULL;
|
|
}
|
|
GdkScreen* gtk_widget_get_screen ( GtkWidget* widget )
|
|
{
|
|
return NULL;
|
|
}
|
|
void gtk_window_set_screen ( GtkWindow* window, GdkScreen* screen )
|
|
{
|
|
}
|
|
void gtk_window_get_size ( GtkWindow* window, gint* width, gint* height )
|
|
{
|
|
}
|
|
void gtk_window_resize ( GtkWindow* window, gint width, gint height )
|
|
{
|
|
}
|
|
void gtk_window_move ( GtkWindow* window, gint x, gint y )
|
|
{
|
|
}
|
|
void gtk_window_get_position ( GtkWindow* window, gint* root_x, gint* root_y )
|
|
{
|
|
}
|
|
void gtk_toolbar_set_icon_size ( GtkToolbar* toolbar, GtkIconSize icon_size )
|
|
{
|
|
}
|
|
void gtk_toolbar_set_style ( GtkToolbar* toolbar, GtkToolbarStyle style )
|
|
{
|
|
}
|
|
GtkWidget* gtk_bin_get_child ( GtkBin* bin )
|
|
{
|
|
return NULL;
|
|
}
|
|
GdkCursor* gdk_cursor_new_from_pixbuf(GdkDisplay* display, GdkPixbuf* pixbuf, gint x, gint y)
|
|
{
|
|
return NULL;
|
|
}
|
|
GtkClipboard* gtk_clipboard_get(GdkAtom selection)
|
|
{
|
|
return NULL;
|
|
}
|
|
void gtk_clipboard_set_text(GtkClipboard* clipboard, const gchar* text, gint len)
|
|
{
|
|
}
|
|
void gtk_window_add_accel_group(GtkWindow* window, GtkAccelGroup* accel_group)
|
|
{
|
|
}
|
|
gchar* gtk_clipboard_wait_for_text(GtkClipboard* clipboard)
|
|
{
|
|
return NULL;
|
|
}
|
|
void gtk_widget_set_events(GtkWidget* widget, gint events)
|
|
{
|
|
}
|
|
void gtk_button_set_relief(GtkButton* button, GtkReliefStyle relief)
|
|
{
|
|
}
|
|
gboolean gdk_event_get_scroll_deltas(const GdkEvent* event, gdouble* delta_x, gdouble* delta_y)
|
|
{
|
|
return FALSE;
|
|
}
|
|
void gtk_entry_set_width_chars(GtkEntry* entry,gint n_chars)
|
|
{
|
|
}
|
|
GtkAccelGroup* gtk_accel_group_new(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
GtkWidget* gtk_event_box_new(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
GtkWidget* gtk_toolbar_new(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
void gtk_toolbar_set_show_arrow(GtkToolbar* toolbar, gboolean show_arrow)
|
|
{
|
|
}
|
|
GtkToolItem* gtk_tool_button_new(GtkWidget* icon_widget, const gchar* label)
|
|
{
|
|
return NULL;
|
|
}
|
|
GtkToolItem* gtk_tool_item_new(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
void gtk_tool_button_set_icon_widget(GtkToolButton* button, GtkWidget* icon_widget)
|
|
{
|
|
}
|
|
void gtk_tool_item_set_expand (GtkToolItem *tool_item, gboolean expand)
|
|
{
|
|
}
|
|
void gtk_editable_cut_clipboard(GtkEditable* editable)
|
|
{
|
|
}
|
|
void gtk_editable_copy_clipboard(GtkEditable* editable)
|
|
{
|
|
}
|
|
void gtk_editable_paste_clipboard(GtkEditable *editable)
|
|
{
|
|
}
|
|
void gtk_widget_add_events(GtkWidget* widget, gint events)
|
|
{
|
|
}
|
|
void gtk_layout_set_size(GtkLayout* layout, guint width, guint height)
|
|
{
|
|
}
|
|
GdkCursor* gdk_cursor_new_for_display(GdkDisplay* display, GdkCursorType cursor_type)
|
|
{
|
|
return NULL;
|
|
}
|
|
void gtk_tool_button_set_icon_name(GtkToolButton* button, const gchar* icon_name)
|
|
{
|
|
}
|
|
void gtk_tool_item_set_use_drag_window(GtkToolItem *tool_item, gboolean use_drag_window)
|
|
{
|
|
}
|
|
void gtk_drag_source_set(GtkWidget* widget, GdkModifierType start_button_mask, const GtkTargetEntry* targets, gint n_targets, GdkDragAction actions)
|
|
{
|
|
}
|
|
void gtk_drag_finish(GdkDragContext* context, gboolean success, gboolean del, guint32 time_)
|
|
{
|
|
}
|
|
void gtk_container_remove(GtkContainer* container, GtkWidget* widget)
|
|
{
|
|
}
|
|
gint gtk_toolbar_get_drop_index(GtkToolbar* toolbar, gint x, gint y)
|
|
{
|
|
return 0;
|
|
}
|
|
void gtk_toolbar_insert(GtkToolbar* toolbar, GtkToolItem* item, gint pos)
|
|
{
|
|
}
|
|
void gtk_toolbar_set_drop_highlight_item(GtkToolbar* toolbar, GtkToolItem* tool_item, gint index_)
|
|
{
|
|
}
|
|
void gtk_container_foreach(GtkContainer* container, GtkCallback callback, gpointer callback_data)
|
|
{
|
|
}
|
|
void gtk_tool_button_set_label(GtkToolButton *button, const gchar *label)
|
|
{
|
|
}
|
|
void gtk_drag_dest_set(GtkWidget* widget, GtkDestDefaults flags, const GtkTargetEntry* targets, gint n_targets, GdkDragAction actions)
|
|
{
|
|
}
|
|
void gtk_widget_set_allocation(GtkWidget* widget, const GtkAllocation* allocation)
|
|
{
|
|
}
|
|
|
|
#endif /* GTK_CHECK_VERSION(4,0,0) */
|
|
|
|
void nsgtk_init(int* argc, char*** argv)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
gtk_init();
|
|
/* TODO: handle command line parameters */
|
|
#else
|
|
gtk_init(argc,argv);
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_widget_size_allocate(GtkWidget* widget, const GtkAllocation* allocation, int baseline)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
gtk_widget_size_allocate(widget, allocation,baseline);
|
|
#else
|
|
gtk_widget_size_allocate(widget, allocation);
|
|
#endif
|
|
}
|
|
|
|
|
|
gboolean nsgtk_file_chooser_set_current_folder(GtkFileChooser* chooser, GFile* file)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
return gtk_file_chooser_set_current_folder(chooser,file, NULL);
|
|
#else
|
|
return gtk_file_chooser_set_current_folder(chooser,file);
|
|
#endif
|
|
}
|
|
|
|
void
|
|
nsgtk_box_pack_start(GtkBox* box, GtkWidget* child, gboolean expand, gboolean fill, guint padding)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
/* TODO: implement properly */
|
|
gtk_box_append(box, child);
|
|
#else
|
|
gtk_box_pack_start(box, child, expand, fill, padding);
|
|
#endif
|
|
}
|
|
|
|
GList *nsgtk_window_get_default_icon_list(void) {
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
/* TODO: implement properly */
|
|
return NULL;
|
|
#else
|
|
return gtk_window_get_default_icon_list();
|
|
#endif
|
|
}
|
|
|
|
|
|
void nsgtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,22,0)
|
|
gtk_widget_set_can_focus(widget, can_focus);
|
|
#else
|
|
if (can_focus == TRUE)
|
|
GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);
|
|
else
|
|
GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_FOCUS);
|
|
#endif
|
|
}
|
|
|
|
gboolean nsgtk_widget_has_focus(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,20,0)
|
|
return gtk_widget_has_focus(widget);
|
|
#else
|
|
return GTK_WIDGET_HAS_FOCUS(widget);
|
|
#endif
|
|
}
|
|
|
|
gboolean nsgtk_widget_get_visible(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,20,0)
|
|
return gtk_widget_get_visible(widget);
|
|
#else
|
|
return GTK_WIDGET_VISIBLE(widget);
|
|
#endif
|
|
}
|
|
|
|
gboolean nsgtk_widget_get_realized(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,20,0)
|
|
return gtk_widget_get_realized(widget);
|
|
#else
|
|
return GTK_WIDGET_REALIZED(widget);
|
|
#endif
|
|
}
|
|
|
|
gboolean nsgtk_widget_get_mapped(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,20,0)
|
|
return gtk_widget_get_mapped(widget);
|
|
#else
|
|
return GTK_WIDGET_MAPPED(widget);
|
|
#endif
|
|
}
|
|
|
|
gboolean nsgtk_widget_is_drawable(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,18,0)
|
|
return gtk_widget_is_drawable(widget);
|
|
#else
|
|
return GTK_WIDGET_DRAWABLE(widget);
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_dialog_set_has_separator(GtkDialog *dialog, gboolean setting)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,21,8)
|
|
/* Deprecated */
|
|
#else
|
|
gtk_dialog_set_has_separator(dialog, setting);
|
|
#endif
|
|
}
|
|
|
|
GtkWidget *nsgtk_combo_box_text_new(void)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,24,0)
|
|
return gtk_combo_box_text_new();
|
|
#else
|
|
return gtk_combo_box_new_text();
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_combo_box_text_append_text(GtkWidget *combo_box, const gchar *text)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,24,0)
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), text);
|
|
#else
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), text);
|
|
#endif
|
|
|
|
}
|
|
|
|
gchar *nsgtk_combo_box_text_get_active_text(GtkWidget *combo_box)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,24,0)
|
|
return gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box));
|
|
#else
|
|
return gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo_box));
|
|
#endif
|
|
}
|
|
|
|
GtkWidget *nsgtk_entry_new(void)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,16,0)
|
|
return gtk_entry_new();
|
|
#else
|
|
return GTK_WIDGET(sexy_icon_entry_new());
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry,
|
|
GtkEntryIconPosition icon_pos,
|
|
GdkPixbuf *pixbuf)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
/* TODO:Implement*/
|
|
#elif GTK_CHECK_VERSION(2,16,0)
|
|
gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(entry), icon_pos, pixbuf);
|
|
#else
|
|
GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf));
|
|
|
|
if (image != NULL) {
|
|
sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
|
|
(SexyIconEntryPosition)icon_pos,
|
|
image);
|
|
|
|
g_object_unref(image);
|
|
}
|
|
|
|
#endif
|
|
}
|
|
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_entry_set_icon_from_icon_name(GtkWidget *entry,
|
|
GtkEntryIconPosition icon_pos,
|
|
const gchar *id)
|
|
{
|
|
#ifdef NSGTK_USE_ICON_NAME
|
|
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry), icon_pos, id);
|
|
#else
|
|
#if GTK_CHECK_VERSION(2,16,0)
|
|
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry), icon_pos, id);
|
|
#else
|
|
GtkImage *image;
|
|
image = GTK_IMAGE(gtk_image_new_from_stock(id, GTK_ICON_SIZE_LARGE_TOOLBAR));
|
|
|
|
if (image != NULL) {
|
|
sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry),
|
|
(SexyIconEntryPosition)icon_pos,
|
|
image);
|
|
g_object_unref(image);
|
|
}
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
GtkWidget* nsgtk_image_new_from_icon_name(const gchar* icon_name, GtkIconSize size)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
return gtk_image_new_from_icon_name(icon_name);
|
|
#else
|
|
return gtk_image_new_from_icon_name(icon_name, size);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
GtkWidget *nsgtk_image_new_from_stock(const gchar *icon_name, GtkIconSize size)
|
|
{
|
|
#ifdef NSGTK_USE_ICON_NAME
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
return gtk_image_new_from_icon_name(icon_name);
|
|
#else
|
|
return gtk_image_new_from_icon_name(icon_name, size);
|
|
#endif
|
|
#else
|
|
return gtk_image_new_from_stock(icon_name, size);
|
|
#endif
|
|
}
|
|
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
GtkWidget *nsgtk_button_new_from_stock(const gchar *stock_id)
|
|
{
|
|
#ifdef NSGTK_USE_ICON_NAME
|
|
return gtk_button_new_with_label(stock_id);
|
|
#else
|
|
return gtk_button_new_from_stock(stock_id);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_button_set_focus_on_click(GtkButton *button, gboolean focus_on_click)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,20,0)
|
|
gtk_widget_set_focus_on_click(GTK_WIDGET(button), focus_on_click);
|
|
#else
|
|
gtk_button_set_focus_on_click(button, focus_on_click);
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
|
|
void nsgtk_widget_override_background_color(GtkWidget *widget,
|
|
GtkStateFlags state,
|
|
uint16_t a,
|
|
uint16_t r,
|
|
uint16_t g,
|
|
uint16_t b)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
#if GTK_CHECK_VERSION(3,16,0)
|
|
/* do nothing - deprecated - must use css styling */
|
|
return;
|
|
#else
|
|
GdkRGBA colour;
|
|
colour.alpha = (double)a / 0xffff;
|
|
colour.red = (double)r / 0xffff;
|
|
colour.green = (double)g / 0xffff;
|
|
colour.blue = (double)b / 0xffff;
|
|
gtk_widget_override_background_color(widget, state, &colour);
|
|
#endif
|
|
#else
|
|
GdkColor colour;
|
|
colour.pixel = a;
|
|
colour.red = r;
|
|
colour.green = g;
|
|
colour.blue = b;
|
|
gtk_widget_modify_bg(widget, state, &colour );
|
|
#endif
|
|
}
|
|
|
|
GtkAdjustment *nsgtk_layout_get_vadjustment(GtkLayout *layout)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
return gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(layout));
|
|
#else
|
|
return gtk_layout_get_vadjustment(layout);
|
|
#endif
|
|
}
|
|
|
|
GtkAdjustment *nsgtk_layout_get_hadjustment(GtkLayout *layout)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
return gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(layout));
|
|
#else
|
|
return gtk_layout_get_hadjustment(layout);
|
|
#endif
|
|
}
|
|
|
|
static void nsgtk_layout_set_adjustment_step_increment(GtkAdjustment *adj,
|
|
int value)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
gtk_adjustment_set_step_increment(adj, value);
|
|
#else
|
|
adj->step_increment = value;
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_layout_set_hadjustment(GtkLayout *layout, GtkAdjustment *adj)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
gtk_scrollable_set_hadjustment(GTK_SCROLLABLE(layout), adj);
|
|
#else
|
|
gtk_layout_set_hadjustment(layout, adj);
|
|
#endif
|
|
nsgtk_layout_set_adjustment_step_increment(adj, 8);
|
|
}
|
|
|
|
void nsgtk_layout_set_vadjustment(GtkLayout *layout, GtkAdjustment *adj)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
gtk_scrollable_set_vadjustment(GTK_SCROLLABLE(layout), adj);
|
|
#else
|
|
gtk_layout_set_vadjustment(layout, adj);
|
|
#endif
|
|
nsgtk_layout_set_adjustment_step_increment(adj, 8);
|
|
}
|
|
|
|
GtkWidget *nsgtk_hbox_new(gboolean homogeneous, gint spacing)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, spacing);
|
|
#else
|
|
return gtk_hbox_new(homogeneous, spacing);
|
|
#endif
|
|
}
|
|
|
|
GtkWidget *nsgtk_vbox_new(gboolean homogeneous, gint spacing)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
return gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing);
|
|
#else
|
|
return gtk_vbox_new(homogeneous, spacing);
|
|
#endif
|
|
}
|
|
|
|
GtkStateFlags nsgtk_widget_get_state_flags(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
return gtk_widget_get_state_flags(widget);
|
|
#else
|
|
#if GTK_CHECK_VERSION(2,18,0)
|
|
return gtk_widget_get_state(widget);
|
|
#else
|
|
return 0; /* FIXME */
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
GtkStyleContext *nsgtk_widget_get_style_context(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
return gtk_widget_get_style_context(widget);
|
|
#else
|
|
return widget->style;
|
|
#endif
|
|
}
|
|
|
|
const PangoFontDescription* nsgtk_style_context_get_font(GtkStyleContext *style,
|
|
GtkStateFlags state)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
/* TODO: implement */
|
|
return NULL;
|
|
#elif GTK_CHECK_VERSION(3,8,0)
|
|
const PangoFontDescription* fontdesc = NULL;
|
|
gtk_style_context_get(style, state, GTK_STYLE_PROPERTY_FONT, &fontdesc, NULL);
|
|
return fontdesc;
|
|
#elif GTK_CHECK_VERSION(3,0,0)
|
|
return gtk_style_context_get_font(style, state);
|
|
#else
|
|
return style->font_desc;
|
|
#endif
|
|
}
|
|
|
|
gulong nsgtk_connect_draw_event(GtkWidget *widget,
|
|
GCallback callback,
|
|
gpointer g)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
return g_signal_connect(G_OBJECT(widget), "draw", callback, g);
|
|
#else
|
|
return g_signal_connect(G_OBJECT(widget), "expose_event", callback, g);
|
|
#endif
|
|
}
|
|
|
|
void nsgdk_cursor_unref(GdkCursor *cursor)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
g_object_unref(cursor);
|
|
#else
|
|
gdk_cursor_unref(cursor);
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_widget_modify_font(GtkWidget *widget,
|
|
PangoFontDescription *font_desc)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
/* FIXME */
|
|
return;
|
|
#else
|
|
gtk_widget_modify_font(widget, font_desc);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_widget_set_cursor(GtkWidget *widget, GdkCursor *cursor)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
gdk_surface_set_cursor(
|
|
gtk_native_get_surface(
|
|
gtk_widget_get_native(widget)),
|
|
cursor);
|
|
#else
|
|
GdkWindow *window;
|
|
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
window = gtk_widget_get_window(widget);
|
|
#else
|
|
window = widget->window;
|
|
#endif
|
|
gdk_window_set_cursor(window, cursor);
|
|
#endif
|
|
}
|
|
|
|
|
|
GtkWidget *nsgtk_dialog_get_content_area(GtkDialog *dialog)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
return gtk_dialog_get_content_area(dialog);
|
|
#else
|
|
return dialog->vbox;
|
|
#endif
|
|
}
|
|
|
|
|
|
gboolean nsgtk_show_uri(GdkScreen *screen,
|
|
const gchar *uri,
|
|
guint32 timestamp,
|
|
GError **error)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
#if GTK_CHECK_VERSION(3,22,0)
|
|
GtkWindow *parent;
|
|
parent = nsgtk_scaffolding_window(nsgtk_current_scaffolding());
|
|
return gtk_show_uri_on_window(parent, uri, timestamp,error);
|
|
#else
|
|
return gtk_show_uri(screen, uri, timestamp, error);
|
|
#endif
|
|
#else
|
|
return FALSE; /** \todo add uri opening for before gtk 2.14 */
|
|
#endif
|
|
}
|
|
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
/* not required */
|
|
#else
|
|
GdkWindow *nsgtk_widget_get_window(GtkWidget *widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
return gtk_widget_get_window(widget);
|
|
#else
|
|
return widget->window;
|
|
#endif
|
|
}
|
|
|
|
GdkWindow *nsgtk_layout_get_bin_window(GtkLayout *layout)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
return gtk_layout_get_bin_window(layout);
|
|
#else
|
|
return layout->bin_window;
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
void nsgtk_im_context_set_client_widget(GtkIMContext* context, GtkWidget* widget)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
gtk_im_context_set_client_widget(context, widget);
|
|
#else
|
|
GdkWindow *window;
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
window = gtk_layout_get_bin_window(GTK_LAYOUT(widget));
|
|
#else
|
|
window = layout->bin_window;
|
|
#endif
|
|
|
|
gtk_im_context_set_client_window(context, window);
|
|
#endif
|
|
}
|
|
|
|
gdouble nsgtk_adjustment_get_step_increment(GtkAdjustment *adjustment)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
return gtk_adjustment_get_step_increment(adjustment);
|
|
#else
|
|
return adjustment->step_increment;
|
|
#endif
|
|
}
|
|
|
|
gdouble nsgtk_adjustment_get_upper(GtkAdjustment *adjustment)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
return gtk_adjustment_get_upper(adjustment);
|
|
#else
|
|
return adjustment->upper;
|
|
#endif
|
|
}
|
|
|
|
gdouble nsgtk_adjustment_get_lower(GtkAdjustment *adjustment)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
return gtk_adjustment_get_lower(adjustment);
|
|
#else
|
|
return adjustment->lower;
|
|
#endif
|
|
}
|
|
|
|
gdouble nsgtk_adjustment_get_page_increment(GtkAdjustment *adjustment)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,14,0)
|
|
return gtk_adjustment_get_page_increment(adjustment);
|
|
#else
|
|
return adjustment->page_increment;
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_widget_get_allocation(GtkWidget *widget, GtkAllocation *allocation)
|
|
{
|
|
#if GTK_CHECK_VERSION(2,18,0)
|
|
gtk_widget_get_allocation(widget, allocation);
|
|
#else
|
|
allocation->x = widget->allocation.x;
|
|
allocation->y = widget->allocation.y;
|
|
allocation->width = widget->allocation.width;
|
|
allocation->height = widget->allocation.height;
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
GtkWidget *nsgtk_image_new_from_pixbuf_icon(GdkPixbuf *pixbuf, GtkIconSize size)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,10,0)
|
|
return gtk_image_new_from_pixbuf(pixbuf);
|
|
#else
|
|
GtkIconSet *icon_set;
|
|
GtkWidget *image;
|
|
|
|
icon_set = gtk_icon_set_new_from_pixbuf(pixbuf);
|
|
|
|
image = gtk_image_new_from_icon_set(icon_set, size);
|
|
|
|
gtk_icon_set_unref(icon_set);
|
|
|
|
return image;
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_window_destroy(GtkWindow *window)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
gtk_window_destroy(window);
|
|
#else
|
|
gtk_widget_destroy(GTK_WIDGET(window));
|
|
#endif
|
|
}
|
|
|
|
void nsgtk_window_set_hide_on_close(GtkWindow *window, gboolean setting)
|
|
{
|
|
#if GTK_CHECK_VERSION(4,0,0)
|
|
gtk_window_set_hide_on_close(window, setting);
|
|
#else
|
|
if (setting) {
|
|
g_signal_connect(G_OBJECT(window),
|
|
"delete_event",
|
|
G_CALLBACK(gtk_widget_hide_on_delete),
|
|
NULL);
|
|
} else {
|
|
g_signal_handlers_disconnect_by_func(G_OBJECT(window),
|
|
G_CALLBACK(gtk_widget_hide_on_delete),
|
|
NULL);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_window_set_opacity(GtkWindow *window, gdouble opacity)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,8,0)
|
|
gtk_widget_set_opacity(GTK_WIDGET(window), opacity);
|
|
#else
|
|
gtk_window_set_opacity(window, opacity);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_scrolled_window_add_with_viewport(GtkScrolledWindow *window,
|
|
GtkWidget *child)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,8,0)
|
|
gtk_container_add(GTK_CONTAINER(window), child);
|
|
#else
|
|
gtk_scrolled_window_add_with_viewport(window, child);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
GtkWidget *nsgtk_image_menu_item_new_with_mnemonic(const gchar *label)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,10,0)
|
|
return gtk_menu_item_new_with_mnemonic(label);
|
|
#else
|
|
return gtk_image_menu_item_new_with_mnemonic(label);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_image_menu_item_set_image(GtkWidget *image_menu_item, GtkWidget *image)
|
|
{
|
|
#if !GTK_CHECK_VERSION(3,10,0)
|
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(image_menu_item), image);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_menu_popup_at_pointer(GtkMenu *menu, const GdkEvent *trigger_event)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,22,0)
|
|
gtk_menu_popup_at_pointer(menu, trigger_event);
|
|
#else
|
|
gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 0,
|
|
gtk_get_current_event_time());
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
gboolean nsgtk_icon_size_lookup_for_settings(GtkSettings *settings,
|
|
GtkIconSize size,
|
|
gint *width,
|
|
gint *height)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,10,0)
|
|
return gtk_icon_size_lookup(size, width, height);
|
|
#else
|
|
return gtk_icon_size_lookup_for_settings(settings, size, width, height);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_widget_set_alignment(GtkWidget *widget, GtkAlign halign, GtkAlign valign)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
gtk_widget_set_halign(widget, halign);
|
|
gtk_widget_set_valign(widget, valign);
|
|
#else
|
|
gfloat x, y;
|
|
switch(halign) {
|
|
case GTK_ALIGN_START:
|
|
x = 0.0;
|
|
break;
|
|
|
|
case GTK_ALIGN_END:
|
|
x = 1.0;
|
|
break;
|
|
|
|
default:
|
|
x = 0.5;
|
|
break;
|
|
}
|
|
|
|
switch(valign) {
|
|
case GTK_ALIGN_START:
|
|
y = 0.0;
|
|
break;
|
|
|
|
case GTK_ALIGN_END:
|
|
y = 1.0;
|
|
break;
|
|
|
|
default:
|
|
y = 0.5;
|
|
break;
|
|
}
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(widget), x, y);
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
void nsgtk_widget_set_margins(GtkWidget *widget, gint hmargin, gint vmargin)
|
|
{
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
#if GTK_CHECK_VERSION(3,12,0)
|
|
gtk_widget_set_margin_start(widget, hmargin);
|
|
gtk_widget_set_margin_end(widget, hmargin);
|
|
#else
|
|
gtk_widget_set_margin_left(widget, hmargin);
|
|
gtk_widget_set_margin_right(widget, hmargin);
|
|
#endif
|
|
gtk_widget_set_margin_top(widget, vmargin);
|
|
gtk_widget_set_margin_bottom(widget, vmargin);
|
|
#else
|
|
if (GTK_IS_MISC(widget)) {
|
|
gtk_misc_set_padding(GTK_MISC(widget), hmargin, vmargin);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/* exported interface documented in gtk/compat.h */
|
|
guint
|
|
nsgtk_builder_add_from_resource(GtkBuilder *builder,
|
|
const gchar *resource_path,
|
|
GError **error)
|
|
{
|
|
guint ret;
|
|
|
|
#ifdef WITH_GRESOURCE
|
|
#if GTK_CHECK_VERSION(3,4,0)
|
|
ret = gtk_builder_add_from_resource(builder, resource_path, error);
|
|
#else
|
|
GBytes *data;
|
|
const gchar *buffer;
|
|
gsize buffer_length;
|
|
|
|
g_assert(error && *error == NULL);
|
|
|
|
data = g_resources_lookup_data(resource_path, 0, error);
|
|
if (data == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
buffer_length = 0;
|
|
buffer = g_bytes_get_data(data, &buffer_length);
|
|
g_assert(buffer != NULL);
|
|
|
|
ret = gtk_builder_add_from_string(builder, buffer, buffer_length, error);
|
|
|
|
g_bytes_unref(data);
|
|
#endif
|
|
#else
|
|
ret = 0; /* return an error as GResource not supported before GLIB 2.32 */
|
|
#endif
|
|
return ret;
|
|
}
|