diff options
Diffstat (limited to 'eel')
43 files changed, 1426 insertions, 5054 deletions
diff --git a/eel/Makefile.am b/eel/Makefile.am index a973fee8..831ab7d5 100644 --- a/eel/Makefile.am +++ b/eel/Makefile.am @@ -4,15 +4,18 @@ noinst_LTLIBRARIES=libeel-2.la INCLUDES = \ -DG_LOG_DOMAIN=\"Eel\" \ - -I$(top_srcdir) \ + -I$(top_builddir) \ $(CORE_CFLAGS) \ $(WARNING_CFLAGS) \ + $(DISABLE_DEPRECATED_CFLAGS) \ -DDATADIR=\""$(datadir)"\" \ -DSOURCE_DATADIR=\""$(top_srcdir)/data"\" \ -DMATELOCALEDIR=\""$(prefix)/${DATADIRNAME}/locale"\" \ - -DG_DISABLE_DEPRECATED \ - -DGDK_PIXBUF_DISABLE_DEPRECATED \ - -DMATEMENU_I_KNOW_THIS_IS_UNSTABLE \ + $(NULL) + +BUILT_SOURCES = \ + eel-marshal.c \ + eel-marshal.h \ $(NULL) libeel_2_la_LDFLAGS = \ @@ -26,44 +29,8 @@ libeel_2_la_LIBADD = \ $(X_LIBS) \ $(NULL) -libeel_2_la_SOURCES = \ - eel-accessibility.c \ - eel-alert-dialog.c \ - eel-art-extensions.c \ - eel-art-gtk-extensions.c \ - eel-background.c \ - eel-background-box.c \ - eel-canvas.c \ - eel-canvas-util.c \ - eel-canvas-rect-ellipse.c \ - eel-debug-drawing.c \ - eel-debug.c \ - eel-editable-label.c \ - eel-gdk-extensions.c \ - eel-gdk-pixbuf-extensions.c \ - eel-glib-extensions.c \ - eel-mate-extensions.c \ - eel-graphic-effects.c \ - eel-gtk-container.c \ - eel-gtk-extensions.c \ - eel-i18n.c \ - eel-image-table.c \ - eel-labeled-image.c \ - eel-lib-self-check-functions.c \ - eel-pango-extensions.c \ - eel-self-checks.c \ - eel-stock-dialogs.c \ - eel-string.c \ - eel-types.c \ - eel-vfs-extensions.c \ - eel-wrap-table.c \ - eel-xml-extensions.c \ - eel-lib-self-check-functions.h \ - $(NULL) - eel_headers = \ eel-accessibility.h \ - eel-alert-dialog.h \ eel-art-extensions.h \ eel-art-gtk-extensions.h \ eel-background.h \ @@ -82,64 +49,69 @@ eel_headers = \ eel-gtk-container.h \ eel-gtk-extensions.h \ eel-gtk-macros.h \ - eel-i18n.h \ eel-image-table.h \ eel-labeled-image.h \ - eel-pango-extensions.h \ eel-self-checks.h \ eel-stock-dialogs.h \ eel-string.h \ - eel-types.h \ eel-vfs-extensions.h \ eel-wrap-table.h \ eel-xml-extensions.h \ eel.h \ $(NULL) -marshal_sources = \ - eel-marshal.h \ - eel-marshal.c \ - $(NULL) - -eel-marshal.h: eelmarshal.list $(GLIB_GENMARSHAL) - $(AM_V_GEN)$(GLIB_GENMARSHAL) $< --header --prefix=eel_marshal > $@ -eel-marshal.c: eelmarshal.list $(GLIB_GENMARSHAL) - $(AM_V_GEN)$(GLIB_GENMARSHAL) $< --body --prefix=eel_marshal > $@ - -stamp_sources = \ - eel-enums.defs \ - eel-type-builtins-evals.c \ +libeel_2_la_SOURCES = \ + eel-accessibility.c \ + eel-art-extensions.c \ + eel-art-gtk-extensions.c \ + eel-background.c \ + eel-background-box.c \ + eel-canvas.c \ + eel-canvas-util.c \ + eel-canvas-rect-ellipse.c \ + eel-debug-drawing.c \ + eel-debug.c \ + eel-editable-label.c \ + eel-gdk-extensions.c \ + eel-gdk-pixbuf-extensions.c \ + eel-glib-extensions.c \ + eel-mate-extensions.c \ + eel-graphic-effects.c \ + eel-gtk-container.c \ + eel-gtk-extensions.c \ + eel-image-table.c \ + eel-labeled-image.c \ + eel-lib-self-check-functions.c \ + eel-self-checks.c \ + eel-stock-dialogs.c \ + eel-string.c \ + eel-vfs-extensions.c \ + eel-wrap-table.c \ + eel-xml-extensions.c \ + eel-lib-self-check-functions.h \ $(NULL) -stamps = \ - eel-makeenums-stamp \ - eel-stamp \ +nodist_libeel_2_la_SOURCES = \ + $(BUILT_SOURCES) \ $(NULL) -eel-makeenums-stamp: makeenums.pl $(eel_headers) - $(AM_V_GEN)$(PERL) $< defs $(filter-out $<,$^) > xgen-eed \ - && (cmp -s xgen-eed eel-enums.defs || mv -f xgen-eed eel-enums.defs) \ - && rm -f xgen-eed \ - && $(PERL) $< arrays $(filter-out $<,$^) > xgen-etbe \ - && (cmp -s xgen-etbe eel-type-builtins-evals.c || mv -f xgen-etbe eel-type-builtins-evals.c) \ - && rm -f xgen-etbe \ - && echo timestamp > $@ - -maketypes_sources = \ - eel-type-builtins.h \ - eel-type-builtins-ids.c \ - eel-type-builtins-vars.c \ - $(NULL) +eel-marshal.list: $(libeel_2_la_SOURCES) Makefile.am + $(AM_V_GEN)( cd $(srcdir) && \ + sed -n -e 's/.*eel_marshal_\([[:upper:][:digit:]]*__[[:upper:][:digit:]_]*\).*/\1/p' \ + $(libeel_2_la_SOURCES) ) \ + | sed -e 's/__/:/' -e 'y/_/,/' | sort -u > [email protected] + @if cmp -s [email protected] $@; then \ + rm [email protected]; \ + else \ + mv [email protected] $@; \ + fi -eel-stamp: eel-makeenums-stamp $(maketypes_sources) - echo timestamp > $@ +%-marshal.c: %-marshal.list Makefile + $(AM_V_GEN)echo "#include \"eel-marshal.h\"" > $@ && \ + $(GLIB_GENMARSHAL) --body --prefix=$(subst -,_,$*)_marshal $< >> $*-marshal.c -eel-type-builtins.h: eel-enums.defs maketypes.awk eel-makeenums-stamp - LC_ALL=C $(AWK) -f $(srcdir)/maketypes.awk $< macros > $@ -eel-type-builtins-vars.c: eel-enums.defs maketypes.awk eel-makeenums-stamp - LC_ALL=C $(AWK) -f $(srcdir)/maketypes.awk $< variables > $@ -eel-type-builtins-ids.c: eel-enums.defs maketypes.awk eel-makeenums-stamp - LC_ALL=C $(AWK) -f $(srcdir)/maketypes.awk $< entries > $@ +%-marshal.h: %-marshal.list Makefile + $(AM_V_GEN)$(GLIB_GENMARSHAL) --header --prefix=$(subst -,_,$*)_marshal $< > $*-marshal.h noinst_PROGRAMS = check-program @@ -151,29 +123,11 @@ check_program_LDFLAGS = $(check_program_DEPENDENCIES) -lm TESTS = check-eel EXTRA_DIST = \ - $(eel_headers) \ - eel-type-builtins.h \ - eel-marshal.h \ check-eel \ - eelmarshal.list \ - makeenums.pl \ - maketypes.awk \ + eel-marshal.list \ $(NULL) -$(libeel_2_la_OBJECTS): $(marshal_sources) - -# This trick causes the stamp file to be built first. -Makefile: eel-stamp - -# This trick causes the generated files to be built the first time. -$(stamp_sources): # never add any dependencies - test -f $@ || touch $@ - -built_sources = $(stamps) $(stamp_sources) $(maketypes_sources) $(marshal_sources) -CLEANFILES = $(built_sources) -DONT_DIST_FILES = $(built_sources) - -dist-hook: - for file in $(DONT_DIST_FILES) ; do \ - rm -f $(distdir)/$$file ; \ - done +CLEANFILES = \ + eel-marshal.list \ + $(BUILT_SOURCES) \ + $(NULL) diff --git a/eel/eel-alert-dialog.c b/eel/eel-alert-dialog.c deleted file mode 100644 index 726e4c67..00000000 --- a/eel/eel-alert-dialog.c +++ /dev/null @@ -1,490 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* eel-alert-dialog.c: An HIG compliant alert dialog. - - The Mate Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Mate Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Mate Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ -#include <config.h> - -#include "eel-alert-dialog.h" -#include "eel-i18n.h" -#include "eel-gtk-macros.h" -#include <gtk/gtk.h> -#include <string.h> - -enum -{ - PROP_0, - PROP_ALERT_TYPE, - PROP_BUTTONS -}; - -struct _EelAlertDialogDetails -{ - GtkWidget *image; - GtkWidget *primary_label; - GtkWidget *secondary_label; - GtkWidget *details_expander; - GtkWidget *details_label; - GtkMessageType type; -}; - - -static gpointer parent_class; - -static void eel_alert_dialog_finalize (GObject *object); -static void eel_alert_dialog_class_init (EelAlertDialogClass *klass); -static void eel_alert_dialog_init (EelAlertDialog *dialog); -static void eel_alert_dialog_style_set (GtkWidget *widget, - GtkStyle *prev_style); -static void eel_alert_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void eel_alert_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void eel_alert_dialog_add_buttons (EelAlertDialog *alert_dialog, - GtkButtonsType buttons); - -GType -eel_alert_dialog_get_type (void) -{ - static GType dialog_type = 0; - - if (!dialog_type) - { - - const GTypeInfo dialog_info = - { - sizeof (EelAlertDialogClass), - NULL, - NULL, - (GClassInitFunc) eel_alert_dialog_class_init, - NULL, - NULL, - sizeof (EelAlertDialog), - 0, - (GInstanceInitFunc) eel_alert_dialog_init, - }; - - dialog_type = g_type_register_static (GTK_TYPE_DIALOG, "EelAlertDialog", - &dialog_info, 0); - } - return dialog_type; -} - -static void -eel_alert_dialog_class_init (EelAlertDialogClass *class) -{ - GtkWidgetClass *widget_class; - GObjectClass *gobject_class; - - widget_class = GTK_WIDGET_CLASS (class); - gobject_class = G_OBJECT_CLASS (class); - - parent_class = g_type_class_peek_parent (class); - - G_OBJECT_CLASS (class)->finalize = eel_alert_dialog_finalize; - - widget_class->style_set = eel_alert_dialog_style_set; - - gobject_class->set_property = eel_alert_dialog_set_property; - gobject_class->get_property = eel_alert_dialog_get_property; - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_int ("alert_border", - _("Image/label border"), - _("Width of border around the label and image in the alert dialog"), - 0, - G_MAXINT, - 5, - G_PARAM_READABLE)); - - g_object_class_install_property (gobject_class, - PROP_ALERT_TYPE, - g_param_spec_enum ("alert_type", - _("Alert Type"), - _("The type of alert"), - GTK_TYPE_MESSAGE_TYPE, - GTK_MESSAGE_INFO, - G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property (gobject_class, - PROP_BUTTONS, - g_param_spec_enum ("buttons", - _("Alert Buttons"), - _("The buttons shown in the alert dialog"), - GTK_TYPE_BUTTONS_TYPE, - GTK_BUTTONS_NONE, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); -} - -static void -eel_alert_dialog_finalize (GObject *object) -{ - EelAlertDialog *dialog; - - dialog = EEL_ALERT_DIALOG (object); - - g_free (dialog->details); - - EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); -} - - -static void -eel_alert_dialog_init (EelAlertDialog *dialog) -{ - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *expander; - - dialog->details = g_new0 (EelAlertDialogDetails, 1); - - dialog->details->primary_label = gtk_label_new (NULL); - dialog->details->secondary_label = gtk_label_new (NULL); - dialog->details->details_label = gtk_label_new (NULL); - dialog->details->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (dialog->details->image), 0.5, 0.0); - - gtk_label_set_line_wrap (GTK_LABEL (dialog->details->primary_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (dialog->details->primary_label), TRUE); - gtk_label_set_use_markup (GTK_LABEL (dialog->details->primary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (dialog->details->primary_label), 0.0, 0.5); - - gtk_label_set_line_wrap (GTK_LABEL (dialog->details->secondary_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (dialog->details->secondary_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (dialog->details->secondary_label), 0.0, 0.5); - - gtk_label_set_line_wrap (GTK_LABEL (dialog->details->details_label), TRUE); - gtk_label_set_selectable (GTK_LABEL (dialog->details->details_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (dialog->details->details_label), 0.0, 0.5); - - hbox = gtk_hbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); - - gtk_box_pack_start (GTK_BOX (hbox), dialog->details->image, - FALSE, FALSE, 0); - - vbox = gtk_vbox_new (FALSE, 12); - - gtk_box_pack_start (GTK_BOX (hbox), vbox, - FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (vbox), dialog->details->primary_label, - FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (vbox), dialog->details->secondary_label, - FALSE, FALSE, 0); - - expander = gtk_expander_new_with_mnemonic (_("Show more _details")); - dialog->details->details_expander = expander; - gtk_expander_set_spacing (GTK_EXPANDER (expander), 6); - gtk_container_add (GTK_CONTAINER (expander), dialog->details->details_label); - - gtk_box_pack_start (GTK_BOX (vbox), expander, - FALSE, FALSE, 0); - - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, - FALSE, FALSE, 0); - - gtk_widget_show_all (hbox); - gtk_widget_hide (expander); - -} - -static void -setup_type (EelAlertDialog *dialog, - GtkMessageType type) -{ - const gchar *stock_id = NULL; - GtkStockItem item; - - switch (type) - { - case GTK_MESSAGE_INFO: - stock_id = GTK_STOCK_DIALOG_INFO; - break; - case GTK_MESSAGE_QUESTION: - stock_id = GTK_STOCK_DIALOG_QUESTION; - break; - case GTK_MESSAGE_WARNING: - stock_id = GTK_STOCK_DIALOG_WARNING; - break; - case GTK_MESSAGE_ERROR: - stock_id = GTK_STOCK_DIALOG_ERROR; - break; - default: - g_warning ("Unknown GtkMessageType %d", type); - break; - } - - if (stock_id == NULL) - { - stock_id = GTK_STOCK_DIALOG_INFO; - } - - if (gtk_stock_lookup (stock_id, &item)) - { - gtk_image_set_from_stock (GTK_IMAGE (dialog->details->image), stock_id, - GTK_ICON_SIZE_DIALOG); - } - else - { - g_warning ("Stock dialog ID doesn't exist?"); - } -} - -static void -eel_alert_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EelAlertDialog *dialog; - - dialog = EEL_ALERT_DIALOG (object); - - switch (prop_id) - { - case PROP_ALERT_TYPE: - dialog->details->type = g_value_get_enum (value); - setup_type (dialog, dialog->details->type); - break; - case PROP_BUTTONS: - eel_alert_dialog_add_buttons (dialog, g_value_get_enum (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -eel_alert_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EelAlertDialog *dialog; - - dialog = EEL_ALERT_DIALOG (object); - - switch (prop_id) - { - case PROP_ALERT_TYPE: - g_value_set_enum (value, dialog->details->type); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -void -eel_alert_dialog_set_primary_label (EelAlertDialog *dialog, - const gchar *message) -{ - gchar *markup_str; - char *escaped_message; - - if (message != NULL) - { - escaped_message = g_markup_escape_text (message, -1); - markup_str = g_strconcat ("<span weight=\"bold\" size=\"larger\">", escaped_message, "</span>", NULL); - gtk_label_set_markup (GTK_LABEL (EEL_ALERT_DIALOG (dialog)->details->primary_label), - markup_str); - g_free (markup_str); - g_free (escaped_message); - } -} - -void -eel_alert_dialog_set_secondary_label (EelAlertDialog *dialog, - const gchar *message) -{ - if (message != NULL) - { - gtk_label_set_text (GTK_LABEL (EEL_ALERT_DIALOG (dialog)->details->secondary_label), - message); - } - else - { - gtk_widget_hide (EEL_ALERT_DIALOG (dialog)->details->secondary_label); - } -} - -void -eel_alert_dialog_set_details_label (EelAlertDialog *dialog, - const gchar *message) -{ - if (message != NULL) - { - gtk_widget_show (dialog->details->details_expander); - gtk_label_set_text (GTK_LABEL (dialog->details->details_label), message); - } - else - { - gtk_widget_hide (dialog->details->details_expander); - } -} - - -GtkWidget* -eel_alert_dialog_new (GtkWindow *parent, - GtkDialogFlags flags, - GtkMessageType type, - GtkButtonsType buttons, - const gchar *primary_message, - const gchar *secondary_message) -{ - GtkWidget *widget; - GtkDialog *dialog; - - g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL); - - widget = g_object_new (EEL_TYPE_ALERT_DIALOG, - "alert_type", type, - "buttons", buttons, - NULL); - atk_object_set_role (gtk_widget_get_accessible (widget), ATK_ROLE_ALERT); - - dialog = GTK_DIALOG (widget); - - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 14); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_dialog_set_has_separator (dialog, FALSE); - - /* Make sure we don't get a window title. - * HIG says that alert dialogs should not have window title - */ - gtk_window_set_title (GTK_WINDOW (dialog), ""); - gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE); - - eel_alert_dialog_set_primary_label (EEL_ALERT_DIALOG (dialog), - primary_message); - - eel_alert_dialog_set_secondary_label (EEL_ALERT_DIALOG (dialog), - secondary_message); - - if (parent != NULL) - { - gtk_window_set_transient_for (GTK_WINDOW (widget), - GTK_WINDOW (parent)); - } - - if (flags & GTK_DIALOG_MODAL) - { - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - } - - if (flags & GTK_DIALOG_DESTROY_WITH_PARENT) - { - gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); - } - return widget; -} - -static void -eel_alert_dialog_add_buttons (EelAlertDialog* alert_dialog, - GtkButtonsType buttons) -{ - GtkDialog* dialog; - - dialog = GTK_DIALOG (alert_dialog); - - switch (buttons) - { - case GTK_BUTTONS_NONE: - break; - case GTK_BUTTONS_OK: - gtk_dialog_add_button (dialog, - GTK_STOCK_OK, - GTK_RESPONSE_OK); - gtk_dialog_set_default_response (dialog, - GTK_RESPONSE_OK); - break; - case GTK_BUTTONS_CLOSE: - gtk_dialog_add_button (dialog, - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE); - gtk_dialog_set_default_response (dialog, - GTK_RESPONSE_CLOSE); - break; - case GTK_BUTTONS_CANCEL: - gtk_dialog_add_button (dialog, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - gtk_dialog_set_default_response (dialog, - GTK_RESPONSE_CANCEL); - break; - case GTK_BUTTONS_YES_NO: - gtk_dialog_add_button (dialog, - GTK_STOCK_NO, - GTK_RESPONSE_NO); - gtk_dialog_add_button (dialog, - GTK_STOCK_YES, - GTK_RESPONSE_YES); - gtk_dialog_set_default_response (dialog, - GTK_RESPONSE_YES); - break; - case GTK_BUTTONS_OK_CANCEL: - gtk_dialog_add_button (dialog, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (dialog, - GTK_STOCK_OK, - GTK_RESPONSE_OK); - gtk_dialog_set_default_response (dialog, - GTK_RESPONSE_OK); - break; - default: - g_warning ("Unknown GtkButtonsType"); - break; - } - g_object_notify (G_OBJECT (alert_dialog), "buttons"); -} - -static void -eel_alert_dialog_style_set (GtkWidget *widget, - GtkStyle *prev_style) -{ - GtkWidget *parent; - gint border_width; - - border_width = 0; - - parent = GTK_WIDGET (gtk_widget_get_parent (EEL_ALERT_DIALOG (widget)->details->image)); - - if (parent != NULL) - { - gtk_widget_style_get (widget, "alert_border", - &border_width, NULL); - - gtk_container_set_border_width (GTK_CONTAINER (parent), - border_width); - } - - if (GTK_WIDGET_CLASS (parent_class)->style_set) - { - (GTK_WIDGET_CLASS (parent_class)->style_set) (widget, prev_style); - } -} diff --git a/eel/eel-alert-dialog.h b/eel/eel-alert-dialog.h deleted file mode 100644 index b1bbebe0..00000000 --- a/eel/eel-alert-dialog.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* eel-alert-dialog.h: An HIG compliant alert dialog. - - The Mate Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Mate Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Mate Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef EEL_ALERT_DIALOG_H -#define EEL_ALERT_DIALOG_H - -#include <gtk/gtk.h> - -#define EEL_TYPE_ALERT_DIALOG (eel_alert_dialog_get_type ()) -#define EEL_ALERT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEL_TYPE_ALERT_DIALOG, EelAlertDialog)) - -typedef struct _EelAlertDialog EelAlertDialog; -typedef struct _EelAlertDialogClass EelAlertDialogClass; -typedef struct _EelAlertDialogDetails EelAlertDialogDetails; - -struct _EelAlertDialog -{ - GtkDialog parent_instance; - EelAlertDialogDetails *details; -}; - -struct _EelAlertDialogClass -{ - GtkDialogClass parent_class; -}; - -GType eel_alert_dialog_get_type (void); - -GtkWidget* eel_alert_dialog_new (GtkWindow *parent, - GtkDialogFlags flags, - GtkMessageType type, - GtkButtonsType buttons, - const gchar *primary_message, - const gchar *secondary_message); -void eel_alert_dialog_set_primary_label (EelAlertDialog *dialog, - const gchar *message); -void eel_alert_dialog_set_secondary_label (EelAlertDialog *dialog, - const gchar *message); -void eel_alert_dialog_set_details_label (EelAlertDialog *dialog, - const gchar *message); - -#endif /* EEL_ALERT_DIALOG_H */ diff --git a/eel/eel-background-box.c b/eel/eel-background-box.c index a3e98ed1..6e25cc62 100644 --- a/eel/eel-background-box.c +++ b/eel/eel-background-box.c @@ -25,13 +25,12 @@ #include <config.h> #include "eel-background-box.h" -#include "eel-gtk-macros.h" #include "eel-background.h" static void eel_background_box_class_init (EelBackgroundBoxClass *background_box_class); static void eel_background_box_init (EelBackgroundBox *background); -EEL_CLASS_BOILERPLATE (EelBackgroundBox, eel_background_box, GTK_TYPE_EVENT_BOX) +G_DEFINE_TYPE (EelBackgroundBox, eel_background_box, GTK_TYPE_EVENT_BOX) static gboolean eel_background_box_expose_event (GtkWidget *widget, diff --git a/eel/eel-background.c b/eel/eel-background.c index 33803f58..bc2be2f1 100644 --- a/eel/eel-background.c +++ b/eel/eel-background.c @@ -25,15 +25,8 @@ #include <config.h> #include "eel-background.h" #include "eel-gdk-extensions.h" -#include "eel-gdk-pixbuf-extensions.h" #include "eel-glib-extensions.h" -#include "eel-mate-extensions.h" -#include "eel-gtk-macros.h" #include "eel-lib-self-check-functions.h" -#include "eel-string.h" -#include "eel-marshal.h" -#include "eel-types.h" -#include "eel-type-builtins.h" #include <gtk/gtk.h> #include <eel/eel-canvas.h> #include <eel/eel-canvas-util.h> @@ -44,10 +37,6 @@ #define MATE_DESKTOP_USE_UNSTABLE_API #include <libmateui/mate-bg.h> -static void eel_background_class_init (gpointer klass); -static void eel_background_init (gpointer object, - gpointer klass); -static void eel_background_finalize (GObject *object); static GdkPixmap *eel_background_get_pixmap_and_color (EelBackground *background, GdkWindow *window, GdkColor *color); @@ -57,7 +46,7 @@ static void set_image_properties (EelBackground *background); static void init_fade (EelBackground *background, GtkWidget *widget); static void free_fade (EelBackground *background); -EEL_CLASS_BOILERPLATE (EelBackground, eel_background, GTK_TYPE_OBJECT) +G_DEFINE_TYPE (EelBackground, eel_background, G_TYPE_OBJECT); enum { @@ -106,49 +95,6 @@ struct EelBackgroundDetails }; static void -eel_background_class_init (gpointer klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - eel_type_init (); - - signals[APPEARANCE_CHANGED] = - g_signal_new ("appearance_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (EelBackgroundClass, - appearance_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - signals[SETTINGS_CHANGED] = - g_signal_new ("settings_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (EelBackgroundClass, - settings_changed), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, - 1, G_TYPE_INT); - signals[RESET] = - g_signal_new ("reset", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (EelBackgroundClass, - reset), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - object_class->finalize = eel_background_finalize; -} - -static void on_bg_changed (MateBG *bg, EelBackground *background) { init_fade (background, background->details->widget); @@ -165,13 +111,13 @@ on_bg_transitioned (MateBG *bg, EelBackground *background) } static void -eel_background_init (gpointer object, gpointer klass) +eel_background_init (EelBackground *background) { - EelBackground *background; - - background = EEL_BACKGROUND (object); + background->details = + G_TYPE_INSTANCE_GET_PRIVATE (background, + EEL_TYPE_BACKGROUND, + EelBackgroundDetails); - background->details = g_new0 (EelBackgroundDetails, 1); background->details->default_color.red = 0xffff; background->details->default_color.green = 0xffff; background->details->default_color.blue = 0xffff; @@ -235,25 +181,6 @@ free_background_pixmap (EelBackground *background) } -static void -eel_background_finalize (GObject *object) -{ - EelBackground *background; - - background = EEL_BACKGROUND (object); - - g_free (background->details->color); - eel_background_remove_current_image (background); - - free_background_pixmap (background); - - free_fade (background); - - g_free (background->details); - - EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); -} - static EelBackgroundImagePlacement placement_mate_to_eel (MateBGPlacement p) { @@ -316,6 +243,67 @@ eel_background_set_image_placement (EelBackground *background, placement_eel_to_mate (new_placement)); } + +static void +eel_background_finalize (GObject *object) +{ + EelBackground *background; + + background = EEL_BACKGROUND (object); + + g_free (background->details->color); + eel_background_remove_current_image (background); + + free_background_pixmap (background); + + free_fade (background); + + G_OBJECT_CLASS (eel_background_parent_class)->finalize (object); +} + +static void +eel_background_class_init (EelBackgroundClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + + signals[APPEARANCE_CHANGED] = + g_signal_new ("appearance_changed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (EelBackgroundClass, + appearance_changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + signals[SETTINGS_CHANGED] = + g_signal_new ("settings_changed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (EelBackgroundClass, + settings_changed), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, + 1, G_TYPE_INT); + signals[RESET] = + g_signal_new ("reset", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (EelBackgroundClass, + reset), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + object_class->finalize = eel_background_finalize; + + g_type_class_add_private (klass, sizeof (EelBackgroundDetails)); +} + EelBackground * eel_background_new (void) { @@ -390,7 +378,6 @@ eel_background_ensure_realized (EelBackground *background, GdkWindow *window) background->details->default_color = style->bg[GTK_STATE_NORMAL]; } - gdk_rgb_find_color (style->colormap, &(background->details->default_color)); } /* If the window size is the same as last time, don't update */ @@ -491,10 +478,8 @@ eel_background_expose (GtkWidget *widget, int window_width; int window_height; GdkPixmap *pixmap; - GdkGC *gc; - GdkGCValues gc_values; - GdkGCValuesMask value_mask; GdkWindow *widget_window; + cairo_t *cr; EelBackground *background; @@ -511,30 +496,22 @@ eel_background_expose (GtkWidget *widget, pixmap = eel_background_get_pixmap_and_color (background, widget_window, &color); + cr = gdk_cairo_create (widget_window); - if (pixmap) - { - gc_values.tile = pixmap; - gc_values.ts_x_origin = 0; - gc_values.ts_y_origin = 0; - gc_values.fill = GDK_TILED; - value_mask = GDK_GC_FILL | GDK_GC_TILE | GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN; - } - else - { - gdk_rgb_find_color (gtk_widget_get_colormap (widget), &color); - gc_values.foreground = color; - gc_values.fill = GDK_SOLID; - value_mask = GDK_GC_FILL | GDK_GC_FOREGROUND; + if (pixmap) { + gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0); + cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); + } else { + gdk_cairo_set_source_color (cr, &color); } - gc = gdk_gc_new_with_values (widget_window, &gc_values, value_mask); + gdk_cairo_rectangle (cr, &event->area); + cairo_clip (cr); - gdk_gc_set_clip_rectangle (gc, &event->area); + cairo_rectangle (cr, 0, 0, window_width, window_height); + cairo_fill (cr); - gdk_draw_rectangle (widget_window, gc, TRUE, 0, 0, window_width, window_height); - - g_object_unref (gc); + cairo_destroy (cr); if (pixmap) { @@ -618,7 +595,7 @@ void eel_background_set_color (EelBackground *background, const char *color) { - if (eel_strcmp (background->details->color, color) != 0) + if (g_strcmp0 (background->details->color, color) != 0) { g_free (background->details->color); background->details->color = g_strdup (color); @@ -647,7 +624,7 @@ eel_background_set_image_uri_helper (EelBackground *background, if (emit_signal) { - g_signal_emit (GTK_OBJECT (background), signals[SETTINGS_CHANGED], 0, GDK_ACTION_COPY); + g_signal_emit (background, signals[SETTINGS_CHANGED], 0, GDK_ACTION_COPY); } set_image_properties (background); @@ -722,7 +699,7 @@ eel_background_reset (EelBackground *background) { g_return_if_fail (EEL_IS_BACKGROUND (background)); - g_signal_emit (GTK_OBJECT (background), signals[RESET], 0); + g_signal_emit (background, signals[RESET], 0); } static void @@ -814,8 +791,6 @@ eel_background_set_up_widget (EelBackground *background, GtkWidget *widget) style = gtk_widget_get_style (widget); - gdk_rgb_find_color (style->colormap, &color); - if (EEL_IS_CANVAS (widget)) { window = gtk_layout_get_bin_window (GTK_LAYOUT (widget)); @@ -1118,7 +1093,6 @@ eel_get_widget_background (GtkWidget *widget) /* Store the background in the widget's data. */ background = eel_background_new (); - g_object_ref_sink (background); g_object_set_data_full (G_OBJECT (widget), "eel_background", background, g_object_unref); background->details->widget = widget; diff --git a/eel/eel-background.h b/eel/eel-background.h index 1604b537..cfccf2a1 100644 --- a/eel/eel-background.h +++ b/eel/eel-background.h @@ -128,13 +128,13 @@ typedef struct EelBackgroundDetails EelBackgroundDetails; struct EelBackground { - GtkObject object; + GObject object; EelBackgroundDetails *details; }; struct EelBackgroundClass { - GtkObjectClass parent_class; + GObjectClass parent_class; /* This signal is emitted whenever the background settings are * changed. diff --git a/eel/eel-canvas-rect-ellipse.c b/eel/eel-canvas-rect-ellipse.c index c637769d..d0e4a592 100644 --- a/eel/eel-canvas-rect-ellipse.c +++ b/eel/eel-canvas-rect-ellipse.c @@ -60,8 +60,7 @@ enum PROP_OUTLINE_COLOR, PROP_OUTLINE_COLOR_GDK, PROP_OUTLINE_COLOR_RGBA, - PROP_FILL_STIPPLE, - PROP_OUTLINE_STIPPLE, + PROP_OUTLINE_STIPPLING, PROP_WIDTH_PIXELS, PROP_WIDTH_UNITS }; @@ -69,7 +68,6 @@ enum static void eel_canvas_re_class_init (EelCanvasREClass *klass); static void eel_canvas_re_init (EelCanvasRE *re); -static void eel_canvas_re_destroy (GtkObject *object); static void eel_canvas_re_set_property (GObject *object, guint param_id, const GValue *value, @@ -134,11 +132,9 @@ static void eel_canvas_re_class_init (EelCanvasREClass *klass) { GObjectClass *gobject_class; - GtkObjectClass *object_class; EelCanvasItemClass *item_class; gobject_class = (GObjectClass *) klass; - object_class = (GtkObjectClass *) klass; item_class = (EelCanvasItemClass *) klass; re_parent_class = g_type_class_peek_parent (klass); @@ -190,12 +186,6 @@ eel_canvas_re_class_init (EelCanvasREClass *klass) G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, - PROP_FILL_STIPPLE, - g_param_spec_object ("fill-stipple", NULL, NULL, - GDK_TYPE_DRAWABLE, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_OUTLINE_COLOR, g_param_spec_string ("outline-color", NULL, NULL, NULL, @@ -212,12 +202,11 @@ eel_canvas_re_class_init (EelCanvasREClass *klass) g_param_spec_uint ("outline-color-rgba", NULL, NULL, 0, G_MAXUINT, 0, G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_OUTLINE_STIPPLE, - g_param_spec_object ("outline-stipple", NULL, NULL, - GDK_TYPE_DRAWABLE, - G_PARAM_READWRITE)); + g_object_class_install_property + (gobject_class, + PROP_OUTLINE_STIPPLING, + g_param_spec_boolean ("outline-stippling", NULL, NULL, + FALSE, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_WIDTH_PIXELS, @@ -231,8 +220,6 @@ eel_canvas_re_class_init (EelCanvasREClass *klass) 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); - object_class->destroy = eel_canvas_re_destroy; - item_class->realize = eel_canvas_re_realize; item_class->unrealize = eel_canvas_re_unrealize; item_class->translate = eel_canvas_re_translate; @@ -249,30 +236,6 @@ eel_canvas_re_init (EelCanvasRE *re) re->width = 0.0; } -static void -eel_canvas_re_destroy (GtkObject *object) -{ - EelCanvasRE *re; - - g_return_if_fail (object != NULL); - g_return_if_fail (EEL_IS_CANVAS_RE (object)); - - re = EEL_CANVAS_RE (object); - - /* remember, destroy can be run multiple times! */ - - if (re->fill_stipple) - g_object_unref (re->fill_stipple); - re->fill_stipple = NULL; - - if (re->outline_stipple) - g_object_unref (re->outline_stipple); - re->outline_stipple = NULL; - - if (GTK_OBJECT_CLASS (re_parent_class)->destroy) - (* GTK_OBJECT_CLASS (re_parent_class)->destroy) (object); -} - static void get_bounds (EelCanvasRE *re, double *px1, double *py1, double *px2, double *py2) { EelCanvasItem *item; @@ -312,60 +275,6 @@ static void get_bounds (EelCanvasRE *re, double *px1, double *py1, double *px2, *py2 += 2; } -/* Convenience function to set a GC's foreground color to the specified pixel value */ -static void -set_gc_foreground (GdkGC *gc, gulong pixel) -{ - GdkColor c; - - if (!gc) - return; - - c.pixel = pixel; - gdk_gc_set_foreground (gc, &c); -} - -/* Sets the stipple pattern for the specified gc */ -static void -set_stipple (GdkGC *gc, GdkBitmap **internal_stipple, GdkBitmap *stipple, int reconfigure) -{ - if (*internal_stipple && !reconfigure) - g_object_unref (*internal_stipple); - - *internal_stipple = stipple; - if (stipple && !reconfigure) - g_object_ref (stipple); - - if (gc) - { - if (stipple) - { - gdk_gc_set_stipple (gc, stipple); - gdk_gc_set_fill (gc, GDK_STIPPLED); - } - else - gdk_gc_set_fill (gc, GDK_SOLID); - } -} - -/* Recalculate the outline width of the rectangle/ellipse and set it in its GC */ -static void -set_outline_gc_width (EelCanvasRE *re) -{ - int width; - - if (!re->outline_gc) - return; - - if (re->width_pixels) - width = (int) re->width; - else - width = (int) (re->width * re->item.canvas->pixels_per_unit + 0.5); - - gdk_gc_set_line_attributes (re->outline_gc, width, - GDK_LINE_SOLID, GDK_CAP_PROJECTING, GDK_JOIN_MITER); -} - static void eel_canvas_re_set_fill (EelCanvasRE *re, gboolean fill_set) { @@ -396,14 +305,12 @@ eel_canvas_re_set_property (GObject *object, EelCanvasRE *re; GdkColor color = { 0, 0, 0, 0, }; GdkColor *pcolor; - int have_pixel; g_return_if_fail (object != NULL); g_return_if_fail (EEL_IS_CANVAS_RE (object)); item = EEL_CANVAS_ITEM (object); re = EEL_CANVAS_RE (object); - have_pixel = FALSE; switch (param_id) { @@ -455,12 +362,7 @@ eel_canvas_re_set_property (GObject *object, if (pcolor) { - GdkColormap *colormap; - color = *pcolor; - colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas)); - gdk_rgb_find_color (colormap, &color); - have_pixel = TRUE; } re->fill_color = ((color.red & 0xff00) << 16 | @@ -477,13 +379,6 @@ eel_canvas_re_set_property (GObject *object, #ifdef VERBOSE g_print ("re fill color = %08x\n", re->fill_color); #endif - if (have_pixel) - re->fill_pixel = color.pixel; - else - re->fill_pixel = eel_canvas_get_color_pixel (item->canvas, re->fill_color); - - set_gc_foreground (re->fill_gc, re->fill_pixel); - eel_canvas_item_request_redraw (item); break; @@ -511,13 +406,7 @@ eel_canvas_re_set_property (GObject *object, if (pcolor) { - GdkColormap *colormap; - color = *pcolor; - colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas)); - gdk_rgb_find_color (colormap, &color); - - have_pixel = TRUE; } re->outline_color = ((color.red & 0xff00) << 16 | @@ -534,30 +423,18 @@ eel_canvas_re_set_property (GObject *object, #ifdef VERBOSE g_print ("re outline color %x %x %x\n", color.red, color.green, color.blue); #endif - if (have_pixel) - re->outline_pixel = color.pixel; - else - re->outline_pixel = eel_canvas_get_color_pixel (item->canvas, - re->outline_color); - - set_gc_foreground (re->outline_gc, re->outline_pixel); - eel_canvas_item_request_redraw (item); break; - case PROP_FILL_STIPPLE: - set_stipple (re->fill_gc, &re->fill_stipple, (GdkBitmap *) g_value_get_object (value), FALSE); + case PROP_OUTLINE_STIPPLING: + re->outline_stippling = g_value_get_boolean (value); - break; - - case PROP_OUTLINE_STIPPLE: - set_stipple (re->outline_gc, &re->outline_stipple, (GdkBitmap *) g_value_get_object (value), FALSE); - break; + eel_canvas_item_request_redraw (item); + break; case PROP_WIDTH_PIXELS: re->width = g_value_get_uint (value); re->width_pixels = TRUE; - set_outline_gc_width (re); eel_canvas_item_request_update (item); break; @@ -565,7 +442,6 @@ eel_canvas_re_set_property (GObject *object, case PROP_WIDTH_UNITS: re->width = fabs (g_value_get_double (value)); re->width_pixels = FALSE; - set_outline_gc_width (re); eel_canvas_item_request_update (item); break; @@ -583,10 +459,14 @@ static void get_color_value (EelCanvasRE *re, gulong pixel, GValue *value) { GdkColor color; - EelCanvasItem *item = (EelCanvasItem *) re; - GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas)); - gdk_colormap_query_color (colormap, pixel, &color); + color.red = (pixel >> 16) & 0xFF; + color.green = (pixel >> 8) & 0xFF; + color.blue = pixel & 0xFF; + color.red |= color.red << 8; + color.green |= color.green << 8; + color.blue |= color.blue << 8; + g_value_set_boxed (value, &color); } @@ -622,11 +502,11 @@ eel_canvas_re_get_property (GObject *object, break; case PROP_FILL_COLOR_GDK: - get_color_value (re, re->fill_pixel, value); + get_color_value (re, re->fill_color, value); break; case PROP_OUTLINE_COLOR_GDK: - get_color_value (re, re->outline_pixel, value); + get_color_value (re, re->outline_color, value); break; case PROP_FILL_COLOR_RGBA: @@ -637,13 +517,9 @@ eel_canvas_re_get_property (GObject *object, g_value_set_uint (value, re->outline_color); break; - case PROP_FILL_STIPPLE: - g_value_set_object (value, (GObject *) re->fill_stipple); - break; - - case PROP_OUTLINE_STIPPLE: - g_value_set_object (value, (GObject *) re->outline_stipple); - break; + case PROP_OUTLINE_STIPPLING: + g_value_set_boolean (value, re->outline_stippling); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -652,16 +528,6 @@ eel_canvas_re_get_property (GObject *object, } static void -set_colors_and_stipples (EelCanvasRE *re) -{ - set_gc_foreground (re->fill_gc, re->fill_pixel); - set_gc_foreground (re->outline_gc, re->outline_pixel); - set_stipple (re->fill_gc, &re->fill_stipple, re->fill_stipple, TRUE); - set_stipple (re->outline_gc, &re->outline_stipple, re->outline_stipple, TRUE); - set_outline_gc_width (re); -} - -static void eel_canvas_re_update_shared (EelCanvasItem *item, double i2w_dx, double i2w_dy, int flags) { EelCanvasRE *re; @@ -674,8 +540,6 @@ eel_canvas_re_update_shared (EelCanvasItem *item, double i2w_dx, double i2w_dy, if (re_parent_class->update) (* re_parent_class->update) (item, i2w_dx, i2w_dy, flags); - set_colors_and_stipples (re); - #ifdef OLD_XFORM recalc_bounds (re); #endif @@ -694,12 +558,6 @@ eel_canvas_re_realize (EelCanvasItem *item) if (re_parent_class->realize) (* re_parent_class->realize) (item); - re->fill_gc = gdk_gc_new (gtk_layout_get_bin_window (&item->canvas->layout)); - re->fill_pixel = eel_canvas_get_color_pixel (item->canvas, re->fill_color); - re->outline_gc = gdk_gc_new (gtk_layout_get_bin_window (&item->canvas->layout)); - re->outline_pixel = eel_canvas_get_color_pixel (item->canvas, re->outline_color); - set_colors_and_stipples (re); - #ifdef OLD_XFORM (* EEL_CANVAS_ITEM_CLASS (item->object.klass)->update) (item, NULL, NULL, 0); #endif @@ -712,11 +570,6 @@ eel_canvas_re_unrealize (EelCanvasItem *item) re = EEL_CANVAS_RE (item); - g_object_unref (re->fill_gc); - re->fill_gc = NULL; - g_object_unref (re->outline_gc); - re->outline_gc = NULL; - if (re_parent_class->unrealize) (* re_parent_class->unrealize) (item); } @@ -768,7 +621,11 @@ static void eel_canvas_rect_init (EelCanvasRect *rect); static void eel_canvas_rect_finalize (GObject *object); static void eel_canvas_rect_realize (EelCanvasItem *item); +#if GTK_CHECK_VERSION(3,0,0) +static void eel_canvas_rect_draw (EelCanvasItem *item, cairo_t *cr, cairo_region_t *region); +#else static void eel_canvas_rect_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose); +#endif static double eel_canvas_rect_point (EelCanvasItem *item, double x, double y, int cx, int cy, EelCanvasItem **actual_item); @@ -883,110 +740,24 @@ eel_canvas_rect_realize (EelCanvasItem *item) static void -render_rect_alpha (EelCanvasRect *rect, - GdkDrawable *drawable, - int x, int y, - int width, int height, - guint32 rgba) +eel_canvas_set_source_color (cairo_t *cr, + guint rgba) { - GdkPixbuf *pixbuf; - guchar *data; - int rowstride, i; - guchar r, g, b, a; - EelCanvasRectPrivate *priv; - - if (width <= 0 || height <= 0 ) - { - return; - } - - priv = rect->priv; - - r = (rgba >> 24) & 0xff; - g = (rgba >> 16) & 0xff; - b = (rgba >> 8) & 0xff; - a = (rgba >> 0) & 0xff; - -#ifdef HAVE_RENDER - /* Every visual is not guaranteed to have a matching - * XRenderPictFormat. So make sure that format is not null before - * trying to render using Xrender calls. - */ - if (priv->use_render && (priv->format != NULL)) - { - GdkDrawable *real_drawable; - int x_offset, y_offset; - - Display *dpy; - Picture pict; - XRenderPictureAttributes attributes; - XRenderColor color; - - gdk_window_get_internal_paint_info (drawable, &real_drawable, - &x_offset, &y_offset); - - dpy = gdk_x11_drawable_get_xdisplay (real_drawable); - - pict = XRenderCreatePicture (dpy, - gdk_x11_drawable_get_xid (real_drawable), - priv->format, - 0, - &attributes); - - - /* Convert to premultiplied alpha: */ - r = r * a / 255; - g = g * a / 255; - b = b * a / 255; - - color.red = (r << 8) + r; - color.green = (g << 8) + g; - color.blue = (b << 8) + b; - color.alpha = (a << 8) + a; - - XRenderFillRectangle (dpy, - PictOpOver, - pict, - &color, - x - x_offset, y - y_offset, - width, height); - - XRenderFreePicture (dpy, pict); - - return; - } -#endif - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); - data = gdk_pixbuf_get_pixels (pixbuf); - rowstride = gdk_pixbuf_get_rowstride (pixbuf); - - r = (rgba >> 24) & 0xff; - g = (rgba >> 16) & 0xff; - b = (rgba >> 8) & 0xff; - a = (rgba >> 0) & 0xff; - - for (i = 0; i < width*4; ) - { - data[i++] = r; - data[i++] = g; - data[i++] = b; - data[i++] = a; - } - - for (i = 1; i < height; i++) - { - memcpy (data + i*rowstride, data, width*4); - } - - gdk_draw_pixbuf (drawable, NULL, pixbuf, - 0, 0, x, y, width, height, - GDK_RGB_DITHER_NONE, 0, 0); - g_object_unref (pixbuf); + cairo_set_source_rgba (cr, + ((rgba >> 24) & 0xff) / 255., + ((rgba >> 16) & 0xff) / 255., + ((rgba >> 8) & 0xff) / 255., + ((rgba >> 0) & 0xff) / 255.); } - +#define DASH_ON 0.8 +#define DASH_OFF 1.7 static void +#if GTK_CHECK_VERSION(3,0,0) +eel_canvas_rect_draw (EelCanvasItem *item, cairo_t *cr, cairo_region_t *region) +#else eel_canvas_rect_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose) +#endif { EelCanvasRE *re; double x1, y1, x2, y2; @@ -1008,69 +779,55 @@ eel_canvas_rect_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose eel_canvas_w2c (item->canvas, x1, y1, &cx1, &cy1); eel_canvas_w2c (item->canvas, x2, y2, &cx2, &cy2); + if (cx2 <= cx1 || cy2 <= cy1 ) { + return; + } + +#if GTK_CHECK_VERSION(3,0,0) + cairo_save (cr); +#else + cairo_t *cr = gdk_cairo_create (drawable); + gdk_cairo_region (cr, expose->region); + cairo_clip (cr); +#endif + if (re->fill_set) { - if ((re->fill_color & 0xff) != 255) - { - GdkRectangle *rectangles; - gint i, n_rectangles; - GdkRectangle draw_rect; - GdkRectangle part; - - draw_rect.x = cx1; - draw_rect.y = cy1; - draw_rect.width = cx2 - cx1 + 1; - draw_rect.height = cy2 - cy1 + 1; - - /* For alpha mode, only render the parts of the region - that are actually exposed */ - gdk_region_get_rectangles (expose->region, - &rectangles, - &n_rectangles); - - for (i = 0; i < n_rectangles; i++) - { - if (gdk_rectangle_intersect (&rectangles[i], - &draw_rect, - &part)) - { - render_rect_alpha (EEL_CANVAS_RECT (item), - drawable, - part.x, part.y, - part.width, part.height, - re->fill_color); - } - } - - g_free (rectangles); - } - else - { - if (re->fill_stipple) - eel_canvas_set_stipple_origin (item->canvas, re->fill_gc); - - gdk_draw_rectangle (drawable, - re->fill_gc, - TRUE, - cx1, cy1, - cx2 - cx1 + 1, - cy2 - cy1 + 1); - } + eel_canvas_set_source_color (cr, re->fill_color); + cairo_rectangle (cr, + cx1, cy1, + cx2 - cx1 + 1, + cy2 - cy1 + 1); + cairo_fill (cr); } if (re->outline_set) { - if (re->outline_stipple) - eel_canvas_set_stipple_origin (item->canvas, re->outline_gc); - - gdk_draw_rectangle (drawable, - re->outline_gc, - FALSE, - cx1, - cy1, - cx2 - cx1, - cy2 - cy1); + eel_canvas_set_source_color (cr, re->outline_color); + if (re->width_pixels) { + cairo_set_line_width (cr, (int) re->width); + } else { + cairo_set_line_width (cr, (int) (re->width * re->item.canvas->pixels_per_unit + 0.5)); + } + + if (re->outline_stippling) { + double dash[2] = { DASH_ON, DASH_OFF }; + + cairo_set_dash (cr, dash, G_N_ELEMENTS (dash), 0); + } + + cairo_rectangle (cr, + cx1 + 0.5, cy1 + 0.5, + cx2 - cx1, + cy2 - cy1); + cairo_stroke (cr); } + +#if GTK_CHECK_VERSION(3,0,0) + cairo_restore (cr); +#else + cairo_destroy (cr); +#endif } static double @@ -1266,7 +1023,11 @@ eel_canvas_rect_update (EelCanvasItem *item, double i2w_dx, double i2w_dy, gint static void eel_canvas_ellipse_class_init (EelCanvasEllipseClass *klass); +#if GTK_CHECK_VERSION(3,0,0) +static void eel_canvas_ellipse_draw (EelCanvasItem *item, cairo_t *cr, cairo_region_t *region); +#else static void eel_canvas_ellipse_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose); +#endif static double eel_canvas_ellipse_point (EelCanvasItem *item, double x, double y, int cx, int cy, EelCanvasItem **actual_item); @@ -1314,7 +1075,11 @@ eel_canvas_ellipse_class_init (EelCanvasEllipseClass *klass) } static void +#if GTK_CHECK_VERSION(3,0,0) +eel_canvas_ellipse_draw (EelCanvasItem *item, cairo_t *cr, cairo_region_t *region) +#else eel_canvas_ellipse_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose) +#endif { EelCanvasRE *re; int x1, y1, x2, y2; @@ -1337,37 +1102,43 @@ eel_canvas_ellipse_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExp re->y2 + i2w_dy, &x2, &y2); +#if GTK_CHECK_VERSION(3,0,0) + cairo_save (cr); +#else + cairo_t *cr = gdk_cairo_create (drawable); + gdk_cairo_region (cr, expose->region); + cairo_clip (cr); +#endif + + cairo_save (cr); + cairo_translate (cr, (x1 + x2) / 2., (y1 + y2) / 2.); + cairo_scale (cr, (x2 - x1), (y2 - y1)); + cairo_arc (cr, 0, 0, 1, 0, 2 * G_PI); + cairo_restore (cr); + if (re->fill_set) { - if (re->fill_stipple) - eel_canvas_set_stipple_origin (item->canvas, re->fill_gc); - - gdk_draw_arc (drawable, - re->fill_gc, - TRUE, - x1, - y1, - x2 - x1, - y2 - y1, - 0 * 64, - 360 * 64); + eel_canvas_set_source_color (cr, re->fill_color); + cairo_fill_preserve (cr); } if (re->outline_set) { - if (re->outline_stipple) - eel_canvas_set_stipple_origin (item->canvas, re->outline_gc); - - gdk_draw_arc (drawable, - re->outline_gc, - FALSE, - x1, - y1, - x2 - x1, - y2 - y1, - 0 * 64, - 360 * 64); + eel_canvas_set_source_color (cr, re->outline_color); + if (re->width_pixels) { + cairo_set_line_width (cr, (int) re->width); + } else { + cairo_set_line_width (cr, (int) (re->width * re->item.canvas->pixels_per_unit + 0.5)); + } + + cairo_stroke_preserve (cr); } + +#if GTK_CHECK_VERSION(3,0,0) + cairo_restore (cr); +#else + cairo_destroy (cr); +#endif } static double diff --git a/eel/eel-canvas-rect-ellipse.h b/eel/eel-canvas-rect-ellipse.h index eb78bf1a..aaccf560 100644 --- a/eel/eel-canvas-rect-ellipse.h +++ b/eel/eel-canvas-rect-ellipse.h @@ -81,21 +81,14 @@ extern "C" { { EelCanvasItem item; - GdkBitmap *fill_stipple; /* Stipple for fill */ - GdkBitmap *outline_stipple; /* Stipple for outline */ - - GdkGC *fill_gc; /* GC for filling */ - GdkGC *outline_gc; /* GC for outline */ - - gulong fill_pixel; /* Fill color */ - gulong outline_pixel; /* Outline color */ - double x1, y1, x2, y2; /* Corners of item */ double width; /* Outline width */ guint fill_color; /* Fill color, RGBA */ guint outline_color; /* Outline color, RGBA */ + gboolean outline_stippling; + /* Configuration flags */ unsigned int fill_set : 1; /* Is fill color set? */ diff --git a/eel/eel-canvas.c b/eel/eel-canvas.c index a4d6612d..b3b4c482 100644 --- a/eel/eel-canvas.c +++ b/eel/eel-canvas.c @@ -68,11 +68,22 @@ #include <stdio.h> #include <gdk/gdkprivate.h> #include <gtk/gtk.h> +#include <glib/gi18n-lib.h> +#if GTK_CHECK_VERSION(3,0,0) +# include <cairo/cairo-gobject.h> +#endif #include "eel-canvas.h" -#include "eel-i18n.h" #include "eel-marshal.h" +#if !GTK_CHECK_VERSION(3, 0, 0) +#define gtk_scrollable_get_hadjustment gtk_layout_get_hadjustment +#define gtk_scrollable_get_vadjustment gtk_layout_get_vadjustment +#define gtk_scrollable_set_hadjustment gtk_layout_set_hadjustment +#define gtk_scrollable_set_vadjustment gtk_layout_set_vadjustment +#define GTK_SCROLLABLE GTK_LAYOUT +#endif + static void eel_canvas_request_update (EelCanvas *canvas); static void group_add (EelCanvasGroup *group, EelCanvasItem *item); @@ -95,6 +106,7 @@ enum enum { + ITEM_DESTROY, ITEM_EVENT, ITEM_LAST_SIGNAL }; @@ -105,7 +117,7 @@ static int emit_event (EelCanvas *canvas, GdkEvent *event static guint item_signals[ITEM_LAST_SIGNAL]; -static GtkObjectClass *item_parent_class; +static GObjectClass *item_parent_class; static gpointer accessible_item_parent_class; static gpointer accessible_parent_class; @@ -139,10 +151,10 @@ eel_canvas_item_get_type (void) (GInstanceInitFunc) eel_canvas_item_init }; - canvas_item_type = g_type_register_static (gtk_object_get_type (), - "EelCanvasItem", - &canvas_item_info, - 0); + canvas_item_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, + "EelCanvasItem", + &canvas_item_info, + 0); } return canvas_item_type; @@ -353,9 +365,21 @@ eel_canvas_item_dispose (GObject *object) item->canvas = NULL; } + g_object_set_data (object, "in-destruction", GINT_TO_POINTER (1)); + g_signal_emit (object, item_signals[ITEM_DESTROY], 0); + + g_object_set_data (object, "in-destruction", NULL); + G_OBJECT_CLASS (item_parent_class)->dispose (object); } +void +eel_canvas_item_destroy (EelCanvasItem *item) +{ + if (g_object_get_data (G_OBJECT (item), "in-destruction") == NULL) { + g_object_run_dispose (G_OBJECT (item)); + } +} /* Realize handler for canvas items */ static void @@ -1194,7 +1218,7 @@ static void eel_canvas_group_get_property(GObject *object, GValue *value, GParamSpec *pspec); -static void eel_canvas_group_destroy (GtkObject *object); +static void eel_canvas_group_destroy (EelCanvasItem *object); static void eel_canvas_group_update (EelCanvasItem *item, double i2w_dx, @@ -1203,8 +1227,14 @@ static void eel_canvas_group_update (EelCanvasItem *item, static void eel_canvas_group_unrealize (EelCanvasItem *item); static void eel_canvas_group_map (EelCanvasItem *item); static void eel_canvas_group_unmap (EelCanvasItem *item); +#if GTK_CHECK_VERSION(3,0,0) +static void eel_canvas_group_draw (EelCanvasItem *item, + cairo_t *cr, + cairo_region_t *region); +#else static void eel_canvas_group_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose); +#endif static double eel_canvas_group_point (EelCanvasItem *item, double x, double y, int cx, int cy, EelCanvasItem **actual_item); @@ -1260,11 +1290,9 @@ static void eel_canvas_group_class_init (EelCanvasGroupClass *klass) { GObjectClass *gobject_class; - GtkObjectClass *object_class; EelCanvasItemClass *item_class; gobject_class = (GObjectClass *) klass; - object_class = (GtkObjectClass *) klass; item_class = (EelCanvasItemClass *) klass; group_parent_class = g_type_class_peek_parent (klass); @@ -1287,8 +1315,7 @@ eel_canvas_group_class_init (EelCanvasGroupClass *klass) -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); - object_class->destroy = eel_canvas_group_destroy; - + item_class->destroy = eel_canvas_group_destroy; item_class->update = eel_canvas_group_update; item_class->unrealize = eel_canvas_group_unrealize; item_class->map = eel_canvas_group_map; @@ -1385,7 +1412,7 @@ eel_canvas_group_get_property (GObject *gobject, guint param_id, /* Destroy handler for canvas groups */ static void -eel_canvas_group_destroy (GtkObject *object) +eel_canvas_group_destroy (EelCanvasItem *object) { EelCanvasGroup *group; EelCanvasItem *child; @@ -1401,11 +1428,11 @@ eel_canvas_group_destroy (GtkObject *object) child = list->data; list = list->next; - gtk_object_destroy (GTK_OBJECT (child)); + eel_canvas_item_destroy (child); } - if (GTK_OBJECT_CLASS (group_parent_class)->destroy) - (* GTK_OBJECT_CLASS (group_parent_class)->destroy) (object); + if (EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy) + (* EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy) (object); } /* Update handler for canvas groups */ @@ -1530,8 +1557,14 @@ eel_canvas_group_unmap (EelCanvasItem *item) /* Draw handler for canvas groups */ static void +#if GTK_CHECK_VERSION(3,0,0) +eel_canvas_group_draw (EelCanvasItem *item, + cairo_t *cr, + cairo_region_t *region) +#else eel_canvas_group_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose) +#endif { EelCanvasGroup *group; GList *list; @@ -1553,8 +1586,13 @@ eel_canvas_group_draw (EelCanvasItem *item, GdkDrawable *drawable, child_rect.width = child->x2 - child->x1 + 1; child_rect.height = child->y2 - child->y1 + 1; +#if GTK_CHECK_VERSION (3, 0, 0) + if (cairo_region_contains_rectangle (region, &child_rect) != CAIRO_REGION_OVERLAP_OUT) + EEL_CANVAS_ITEM_GET_CLASS (child)->draw (child, cr, region); +#else if (gdk_region_rect_in (expose->region, &child_rect) != GDK_OVERLAP_RECTANGLE_OUT) (* EEL_CANVAS_ITEM_GET_CLASS (child)->draw) (child, drawable, expose); +#endif } } } @@ -1714,12 +1752,7 @@ eel_canvas_group_bounds (EelCanvasItem *item, double *x1, double *y1, double *x2 static void group_add (EelCanvasGroup *group, EelCanvasItem *item) { -#if GLIB_CHECK_VERSION(2,10,0) && GTK_CHECK_VERSION(2,8,14) g_object_ref_sink (item); -#else - g_object_ref (item); - gtk_object_sink (GTK_OBJECT (item)); -#endif if (!group->item_list) { @@ -1787,7 +1820,11 @@ enum static void eel_canvas_class_init (EelCanvasClass *klass); static void eel_canvas_init (EelCanvas *canvas); +#if GTK_CHECK_VERSION (3, 0, 0) +static void eel_canvas_destroy (GtkWidget *object); +#else static void eel_canvas_destroy (GtkObject *object); +#endif static void eel_canvas_map (GtkWidget *widget); static void eel_canvas_unmap (GtkWidget *widget); static void eel_canvas_realize (GtkWidget *widget); @@ -1798,8 +1835,13 @@ static gint eel_canvas_button (GtkWidget *widget, GdkEventButton *event); static gint eel_canvas_motion (GtkWidget *widget, GdkEventMotion *event); +#if GTK_CHECK_VERSION (3, 0, 0) +static gint eel_canvas_draw (GtkWidget *widget, + cairo_t *cr); +#else static gint eel_canvas_expose (GtkWidget *widget, GdkEventExpose *event); +#endif static gint eel_canvas_key (GtkWidget *widget, GdkEventKey *event); static gint eel_canvas_crossing (GtkWidget *widget, @@ -1810,11 +1852,14 @@ static gint eel_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event); static void eel_canvas_request_update_real (EelCanvas *canvas); static void eel_canvas_draw_background (EelCanvas *canvas, +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_t *cr); +#else int x, int y, int width, int height); - +#endif static GtkLayoutClass *canvas_parent_class; @@ -1907,11 +1952,11 @@ eel_canvas_accessible_initialize (AtkObject *obj, ATK_OBJECT_CLASS (accessible_parent_class)->initialize (obj, data); canvas = EEL_CANVAS (data); - g_signal_connect (gtk_layout_get_hadjustment (&canvas->layout), + g_signal_connect (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)), "value_changed", G_CALLBACK (eel_canvas_accessible_adjustment_changed), obj); - g_signal_connect (gtk_layout_get_vadjustment (&canvas->layout), + g_signal_connect (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)), "value_changed", G_CALLBACK (eel_canvas_accessible_adjustment_changed), obj); @@ -2102,11 +2147,9 @@ static void eel_canvas_class_init (EelCanvasClass *klass) { GObjectClass *gobject_class; - GtkObjectClass *object_class; GtkWidgetClass *widget_class; gobject_class = (GObjectClass *)klass; - object_class = (GtkObjectClass *) klass; widget_class = (GtkWidgetClass *) klass; canvas_parent_class = g_type_class_peek_parent (klass); @@ -2114,8 +2157,11 @@ eel_canvas_class_init (EelCanvasClass *klass) gobject_class->set_property = eel_canvas_set_property; gobject_class->get_property = eel_canvas_get_property; - object_class->destroy = eel_canvas_destroy; - +#if !GTK_CHECK_VERSION (3, 0, 0) + GTK_OBJECT_CLASS (klass)->destroy = eel_canvas_destroy; +#else + widget_class->destroy = eel_canvas_destroy; +#endif widget_class->map = eel_canvas_map; widget_class->unmap = eel_canvas_unmap; widget_class->realize = eel_canvas_realize; @@ -2124,7 +2170,11 @@ eel_canvas_class_init (EelCanvasClass *klass) widget_class->button_press_event = eel_canvas_button; widget_class->button_release_event = eel_canvas_button; widget_class->motion_notify_event = eel_canvas_motion; +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->draw = eel_canvas_draw; +#else widget_class->expose_event = eel_canvas_expose; +#endif widget_class->key_press_event = eel_canvas_key; widget_class->key_release_event = eel_canvas_key; widget_class->enter_notify_event = eel_canvas_crossing; @@ -2137,13 +2187,19 @@ eel_canvas_class_init (EelCanvasClass *klass) canvas_signals[DRAW_BACKGROUND] = g_signal_new ("draw_background", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (EelCanvasClass, draw_background), NULL, NULL, +#if GTK_CHECK_VERSION (3, 0, 0) + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + CAIRO_GOBJECT_TYPE_CONTEXT); +#else eel_marshal_VOID__INT_INT_INT_INT, G_TYPE_NONE, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); +#endif atk_registry_set_factory_type (atk_get_default_registry (), EEL_TYPE_CANVAS, @@ -2154,7 +2210,7 @@ eel_canvas_class_init (EelCanvasClass *klass) * never ever do this, so we panic if this happens. */ static void -panic_root_destroyed (GtkObject *object, gpointer data) +panic_root_destroyed (GtkWidget *object, gpointer data) { g_error ("Eeeek, root item %p of canvas %p was destroyed!", object, data); } @@ -2170,7 +2226,7 @@ eel_canvas_init (EelCanvas *canvas) canvas->scroll_x1 = 0.0; canvas->scroll_y1 = 0.0; - gtk_layout_get_size (&canvas->layout, + gtk_layout_get_size (GTK_LAYOUT (canvas), &width, &height); canvas->scroll_x2 = width; canvas->scroll_y2 = height; @@ -2181,20 +2237,15 @@ eel_canvas_init (EelCanvas *canvas) canvas->pick_event.crossing.x = 0; canvas->pick_event.crossing.y = 0; - gtk_layout_set_hadjustment (GTK_LAYOUT (canvas), NULL); - gtk_layout_set_vadjustment (GTK_LAYOUT (canvas), NULL); + gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL); + gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL); /* Create the root item as a special case */ canvas->root = EEL_CANVAS_ITEM (g_object_new (eel_canvas_group_get_type (), NULL)); canvas->root->canvas = canvas; -#if GLIB_CHECK_VERSION(2,10,0) && GTK_CHECK_VERSION(2,8,14) g_object_ref_sink (canvas->root); -#else - g_object_ref (canvas->root); - gtk_object_sink (GTK_OBJECT (canvas->root)); -#endif canvas->root_destroy_id = g_signal_connect (G_OBJECT (canvas->root), "destroy", G_CALLBACK (panic_root_destroyed), canvas); @@ -2240,7 +2291,11 @@ shutdown_transients (EelCanvas *canvas) /* Destroy handler for EelCanvas */ static void +#if GTK_CHECK_VERSION (3, 0, 0) +eel_canvas_destroy (GtkWidget *object) +#else eel_canvas_destroy (GtkObject *object) +#endif { EelCanvas *canvas; @@ -2259,14 +2314,19 @@ eel_canvas_destroy (GtkObject *object) { EelCanvasItem *root = canvas->root; canvas->root = NULL; - gtk_object_destroy (GTK_OBJECT (root)); + eel_canvas_item_destroy (root); g_object_unref (root); } shutdown_transients (canvas); +#if GTK_CHECK_VERSION (3, 0, 0) + if (GTK_WIDGET_CLASS (canvas_parent_class)->destroy) + (* GTK_WIDGET_CLASS (canvas_parent_class)->destroy) (object); +#else if (GTK_OBJECT_CLASS (canvas_parent_class)->destroy) (* GTK_OBJECT_CLASS (canvas_parent_class)->destroy) (object); +#endif } /** @@ -2347,8 +2407,8 @@ eel_canvas_realize (GtkWidget *widget) canvas = EEL_CANVAS (widget); - gdk_window_set_events (gtk_layout_get_bin_window (&canvas->layout), - (gdk_window_get_events (gtk_layout_get_bin_window (&canvas->layout)) + gdk_window_set_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)), + (gdk_window_get_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas))) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -2361,8 +2421,6 @@ eel_canvas_realize (GtkWidget *widget) /* Create our own temporary pixmap gc and realize all the items */ - canvas->pixmap_gc = gdk_gc_new (gtk_layout_get_bin_window (&canvas->layout)); - (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->realize) (canvas->root); } @@ -2382,9 +2440,6 @@ eel_canvas_unrealize (GtkWidget *widget) (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unrealize) (canvas->root); - g_object_unref (canvas->pixmap_gc); - canvas->pixmap_gc = NULL; - if (GTK_WIDGET_CLASS (canvas_parent_class)->unrealize) (* GTK_WIDGET_CLASS (canvas_parent_class)->unrealize) (widget); } @@ -2482,8 +2537,8 @@ scroll_to (EelCanvas *canvas, int cx, int cy) gtk_widget_queue_draw (GTK_WIDGET (canvas)); } - hadjustment = gtk_layout_get_hadjustment (&canvas->layout); - vadjustment = gtk_layout_get_vadjustment (&canvas->layout); + hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)); + vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)); if (((int) gtk_adjustment_get_value (hadjustment)) != cx) { @@ -2527,8 +2582,8 @@ eel_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation) /* Recenter the view, if appropriate */ - hadjustment = gtk_layout_get_hadjustment (&canvas->layout); - vadjustment = gtk_layout_get_vadjustment (&canvas->layout); + hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)); + vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)); gtk_adjustment_set_page_size (hadjustment, allocation->width); gtk_adjustment_set_page_increment (hadjustment, allocation->width / 2); @@ -2672,14 +2727,14 @@ emit_event (EelCanvas *canvas, GdkEvent *event) while (item && !finished) { - g_object_ref (GTK_OBJECT (item)); + g_object_ref (item); g_signal_emit ( G_OBJECT (item), item_signals[ITEM_EVENT], 0, &ev, &finished); parent = item->parent; - g_object_unref (GTK_OBJECT (item)); + g_object_unref (item); item = parent; } @@ -2861,7 +2916,7 @@ eel_canvas_button (GtkWidget *widget, GdkEventButton *event) * dispatch normally regardless of the event's window if an item has * has a pointer grab in effect */ - if (!canvas->grabbed_item && event->window != gtk_layout_get_bin_window (&canvas->layout)) + if (!canvas->grabbed_item && event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas))) return retval; switch (event->button) @@ -2929,7 +2984,7 @@ eel_canvas_motion (GtkWidget *widget, GdkEventMotion *event) canvas = EEL_CANVAS (widget); - if (event->window != gtk_layout_get_bin_window (&canvas->layout)) + if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas))) return FALSE; canvas->state = event->state; @@ -2968,7 +3023,7 @@ eel_canvas_crossing (GtkWidget *widget, GdkEventCrossing *event) canvas = EEL_CANVAS (widget); - if (event->window != gtk_layout_get_bin_window (&canvas->layout)) + if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas))) return FALSE; canvas->state = event->state; @@ -3003,18 +3058,80 @@ eel_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event) return FALSE; } + +#if GTK_CHECK_VERSION(3,0,0) +static cairo_region_t * +eel_cairo_get_clip_region (cairo_t *cr) +{ + cairo_rectangle_list_t *list; + cairo_region_t *region; + int i; + + list = cairo_copy_clip_rectangle_list (cr); + if (list->status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) { + cairo_rectangle_int_t clip_rect; + + cairo_rectangle_list_destroy (list); + + if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect)) + return NULL; + return cairo_region_create_rectangle (&clip_rect); + } + + + region = cairo_region_create (); + for (i = list->num_rectangles - 1; i >= 0; --i) { + cairo_rectangle_t *rect = &list->rectangles[i]; + cairo_rectangle_int_t clip_rect; + + clip_rect.x = floor (rect->x); + clip_rect.y = floor (rect->y); + clip_rect.width = ceil (rect->x + rect->width) - clip_rect.x; + clip_rect.height = ceil (rect->y + rect->height) - clip_rect.y; + + if (cairo_region_union_rectangle (region, &clip_rect) != CAIRO_STATUS_SUCCESS) { + cairo_region_destroy (region); + region = NULL; + break; + } + } + + cairo_rectangle_list_destroy (list); + return region; +} +#endif + /* Expose handler for the canvas */ +#if GTK_CHECK_VERSION(3,0,0) +static gboolean +eel_canvas_draw (GtkWidget *widget, cairo_t *cr) +#else static gint eel_canvas_expose (GtkWidget *widget, GdkEventExpose *event) +#endif { - EelCanvas *canvas; + EelCanvas *canvas = EEL_CANVAS (widget); +#if GTK_CHECK_VERSION(3,0,0) + GdkWindow *bin_window; + cairo_region_t *region; - canvas = EEL_CANVAS (widget); + if (!gdk_cairo_get_clip_rectangle (cr, NULL)) + return FALSE; + + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget)); + gtk_cairo_transform_to_window (cr, widget, bin_window); + region = eel_cairo_get_clip_region (cr); + if (region == NULL) + return FALSE; +#else if (!gtk_widget_is_drawable (widget) || (event->window != gtk_layout_get_bin_window (&canvas->layout))) return FALSE; +#endif -#ifdef VERBOSE - g_print ("Expose\n"); +#if defined VERBOSE && GTK_CHECK_VERSION(3,0,0) + g_print ("Draw\n"); +#elif defined VERBOSE + g_print ("Expose\n"); #endif /* If there are any outstanding items that need updating, do them now */ if (canvas->idle_id) @@ -3039,37 +3156,68 @@ eel_canvas_expose (GtkWidget *widget, GdkEventExpose *event) /* Hmmm. Would like to queue antiexposes if the update marked anything that is gonna get redrawn as invalid */ - g_signal_emit (G_OBJECT (canvas), canvas_signals[DRAW_BACKGROUND], 0, +#if GTK_CHECK_VERSION(3,0,0) + cr); +#else event->area.x, event->area.y, event->area.width, event->area.height); +#endif if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED) - (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->draw) (canvas->root, - gtk_layout_get_bin_window (&canvas->layout), - event); - - + EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->draw (canvas->root, +#if GTK_CHECK_VERSION(3,0,0) + cr, region); +#else + gtk_layout_get_bin_window (&canvas->layout), + event); +#endif /* Chain up to get exposes on child widgets */ +#if !GTK_CHECK_VERSION(3,0,0) GTK_WIDGET_CLASS (canvas_parent_class)->expose_event (widget, event); +#else + if (GTK_WIDGET_CLASS (canvas_parent_class)->draw) + GTK_WIDGET_CLASS (canvas_parent_class)->draw (widget, cr); + cairo_region_destroy (region); +#endif return FALSE; } + +#if GTK_CHECK_VERSION(3,0,0) +static void +eel_canvas_draw_background (EelCanvas *canvas, + cairo_t *cr) +{ + cairo_rectangle_int_t rect; + + if (!gdk_cairo_get_clip_rectangle (cr, &rect)) + return; + + cairo_save (cr); + /* By default, we use the style background. */ + gdk_cairo_set_source_color (cr, >k_widget_get_style (GTK_WIDGET (canvas))->bg[GTK_STATE_NORMAL]); + gdk_cairo_rectangle (cr, &rect); + cairo_fill (cr); + cairo_restore (cr); +} +#else /* GTK_CHECK_VERSION(3,0,0) */ static void eel_canvas_draw_background (EelCanvas *canvas, int x, int y, int width, int height) { + cairo_t *cr = gdk_cairo_create (gtk_layout_get_bin_window (&canvas->layout)); + /* By default, we use the style background. */ - gdk_gc_set_foreground (canvas->pixmap_gc, - >k_widget_get_style (GTK_WIDGET (canvas))->bg[GTK_STATE_NORMAL]); - gdk_draw_rectangle (gtk_layout_get_bin_window (&canvas->layout), - canvas->pixmap_gc, - TRUE, - x, y, - width, height); + gdk_cairo_set_source_color (cr, >k_widget_get_style (GTK_WIDGET (canvas))->bg[GTK_STATE_NORMAL]); + cairo_rectangle (cr, x, y, width, height); + cairo_fill (cr); + + cairo_destroy (cr); } +#endif /* GTK_CHECK_VERSION(3,0,0) */ static void do_update (EelCanvas *canvas) @@ -3193,8 +3341,8 @@ eel_canvas_set_scroll_region (EelCanvas *canvas, double x1, double y1, double x2 * Set the new scrolling region. If possible, do not move the visible contents of the * canvas. */ - hadjustment = gtk_layout_get_hadjustment (GTK_LAYOUT (canvas)); - vadjustment = gtk_layout_get_vadjustment (GTK_LAYOUT (canvas)); + hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)); + vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)); eel_canvas_c2w (canvas, gtk_adjustment_get_value (hadjustment) + canvas->zoom_xofs, @@ -3260,8 +3408,8 @@ eel_canvas_set_center_scroll_region (EelCanvas *canvas, canvas->center_scroll_region = center_scroll_region != 0; - hadjustment = gtk_layout_get_hadjustment (&canvas->layout); - vadjustment = gtk_layout_get_vadjustment (&canvas->layout); + hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (&canvas->layout)); + vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (&canvas->layout)); scroll_to (canvas, gtk_adjustment_get_value (hadjustment), @@ -3300,8 +3448,8 @@ eel_canvas_set_pixels_per_unit (EelCanvas *canvas, double n) center_y = allocation.height / 2; /* Find the coordinates of the screen center in units. */ - hadjustment = gtk_layout_get_hadjustment (&canvas->layout); - vadjustment = gtk_layout_get_vadjustment (&canvas->layout); + hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)); + vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)); cx = (gtk_adjustment_get_value (hadjustment) + center_x) / canvas->pixels_per_unit + canvas->scroll_x1 + canvas->zoom_xofs; cy = (gtk_adjustment_get_value (vadjustment) + center_y) / canvas->pixels_per_unit + canvas->scroll_y1 + canvas->zoom_yofs; @@ -3332,14 +3480,20 @@ eel_canvas_set_pixels_per_unit (EelCanvas *canvas, double n) attributes.height = allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; +#if GTK_CHECK_VERSION(3,0,0) + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; +#else + attributes.colormap = gtk_widget_get_colormap (widget); attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; +#endif window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); +#if !GTK_CHECK_VERSION(3,0,0) gdk_window_set_back_pixmap (window, NULL, FALSE); +#endif gdk_window_set_user_data (window, widget); gdk_window_show (window); @@ -3399,8 +3553,8 @@ eel_canvas_get_scroll_offsets (EelCanvas *canvas, int *cx, int *cy) g_return_if_fail (EEL_IS_CANVAS (canvas)); - hadjustment = gtk_layout_get_hadjustment (&canvas->layout); - vadjustment = gtk_layout_get_vadjustment (&canvas->layout); + hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)); + vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)); if (cx) *cx = gtk_adjustment_get_value (hadjustment); @@ -3500,7 +3654,7 @@ eel_canvas_request_redraw (EelCanvas *canvas, int x1, int y1, int x2, int y2) bbox.width = x2 - x1; bbox.height = y2 - y1; - gdk_window_invalidate_rect (gtk_layout_get_bin_window (&canvas->layout), + gdk_window_invalidate_rect (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)), &bbox, FALSE); } @@ -3679,8 +3833,6 @@ eel_canvas_world_to_window (EelCanvas *canvas, double worldx, double worldy, int eel_canvas_get_color (EelCanvas *canvas, const char *spec, GdkColor *color) { - GdkColormap *colormap; - g_return_val_if_fail (EEL_IS_CANVAS (canvas), FALSE); g_return_val_if_fail (color != NULL, FALSE); @@ -3695,63 +3847,9 @@ eel_canvas_get_color (EelCanvas *canvas, const char *spec, GdkColor *color) gdk_color_parse (spec, color); - colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas)); - - gdk_rgb_find_color (colormap, color); - return TRUE; } -/** - * eel_canvas_get_color_pixel: - * @canvas: A canvas. - * @rgba: RGBA color specification. - * - * Allocates a color from the RGBA value passed into this function. The alpha - * opacity value is discarded, since normal X colors do not support it. - * - * Return value: Allocated pixel value corresponding to the specified color. - **/ -gulong -eel_canvas_get_color_pixel (EelCanvas *canvas, guint rgba) -{ - GdkColormap *colormap; - GdkColor color; - - g_return_val_if_fail (EEL_IS_CANVAS (canvas), 0); - - color.red = ((rgba & 0xff000000) >> 16) + ((rgba & 0xff000000) >> 24); - color.green = ((rgba & 0x00ff0000) >> 8) + ((rgba & 0x00ff0000) >> 16); - color.blue = (rgba & 0x0000ff00) + ((rgba & 0x0000ff00) >> 8); - color.pixel = 0; - - colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas)); - - gdk_rgb_find_color (colormap, &color); - - return color.pixel; -} - - -/* FIXME: This function is not useful anymore */ -/** - * eel_canvas_set_stipple_origin: - * @canvas: A canvas. - * @gc: GC on which to set the stipple origin. - * - * Sets the stipple origin of the specified GC as is appropriate for the canvas, - * so that it will be aligned with other stipple patterns used by canvas items. - * This is typically only needed by item implementations. - **/ -void -eel_canvas_set_stipple_origin (EelCanvas *canvas, GdkGC *gc) -{ - g_return_if_fail (EEL_IS_CANVAS (canvas)); - g_return_if_fail (GDK_IS_GC (gc)); - - gdk_gc_set_ts_origin (gc, 0, 0); -} - static gboolean boolean_handled_accumulator (GSignalInvocationHint *ihint, GValue *return_accu, @@ -4068,7 +4166,7 @@ eel_canvas_item_accessible_get_type (void) GTypeInfo tinfo = { 0 }; factory = atk_registry_get_factory (atk_get_default_registry(), - GTK_TYPE_OBJECT); + G_TYPE_INITIALLY_UNOWNED); if (!factory) { return G_TYPE_INVALID; @@ -4201,6 +4299,15 @@ eel_canvas_item_class_init (EelCanvasItemClass *klass) G_TYPE_BOOLEAN, 1, GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + item_signals[ITEM_DESTROY] = + g_signal_new ("destroy", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, + G_STRUCT_OFFSET (EelCanvasItemClass, destroy), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + klass->realize = eel_canvas_item_realize; klass->unrealize = eel_canvas_item_unrealize; klass->map = eel_canvas_item_map; diff --git a/eel/eel-canvas.h b/eel/eel-canvas.h index 2f799c39..8f49141a 100644 --- a/eel/eel-canvas.h +++ b/eel/eel-canvas.h @@ -115,7 +115,7 @@ extern "C" { struct _EelCanvasItem { - GtkObject object; + GInitiallyUnowned object; /* Parent canvas for this item */ EelCanvas *canvas; @@ -132,7 +132,9 @@ extern "C" { struct _EelCanvasItemClass { - GtkObjectClass parent_class; + GInitiallyUnownedClass parent_class; + + void (* destroy) (EelCanvasItem *item); /* Tell the item to update itself. The flags are from the update flags * defined above. The item should update its internal state from its @@ -157,7 +159,11 @@ extern "C" { * coordinates of the drawable, a temporary pixmap, where things get * drawn. (width, height) are the dimensions of the drawable. */ +#if GTK_CHECK_VERSION(3,0,0) + void (* draw) (EelCanvasItem *item, cairo_t *cr, cairo_region_t *region); +#else void (* draw) (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose); +#endif /* Calculate the distance from an item to the specified point. It also * returns a canvas item which is the item itself in the case of the @@ -195,6 +201,8 @@ extern "C" { EelCanvasItem *eel_canvas_item_new (EelCanvasGroup *parent, GType type, const gchar *first_arg_name, ...); + void eel_canvas_item_destroy (EelCanvasItem *item); + /* Constructors for use in derived classes and language wrappers */ void eel_canvas_item_construct (EelCanvasItem *item, EelCanvasGroup *parent, const gchar *first_arg_name, va_list args); @@ -372,9 +380,6 @@ extern "C" { /* If non-NULL, the currently focused item */ EelCanvasItem *focused_item; - /* GC for temporary draw pixmap */ - GdkGC *pixmap_gc; - /* Event on which selection of current item is based */ GdkEvent pick_event; @@ -433,7 +438,11 @@ extern "C" { /* Draw the background for the area given. */ void (* draw_background) (EelCanvas *canvas, +#if GTK_CHECK_VERSION(3,0,0) + cairo_t *cr); +#else int x, int y, int width, int height); +#endif /* Private Virtual methods for groping the canvas inside matecomponent */ void (* request_update) (EelCanvas *canvas); @@ -527,16 +536,6 @@ extern "C" { */ int eel_canvas_get_color (EelCanvas *canvas, const char *spec, GdkColor *color); - /* Allocates a color from the RGB value passed into this function. */ - gulong eel_canvas_get_color_pixel (EelCanvas *canvas, - guint rgba); - - - /* Sets the stipple origin of the specified gc so that it will be aligned with - * all the stipples used in the specified canvas. This is intended for use only - * by canvas item implementations. - */ - void eel_canvas_set_stipple_origin (EelCanvas *canvas, GdkGC *gc); #ifdef __cplusplus } diff --git a/eel/eel-debug-drawing.c b/eel/eel-debug-drawing.c index 50ea70a4..63706829 100644 --- a/eel/eel-debug-drawing.c +++ b/eel/eel-debug-drawing.c @@ -32,7 +32,6 @@ #include "eel-gdk-pixbuf-extensions.h" #include "eel-gtk-extensions.h" #include "eel-gtk-extensions.h" -#include "eel-gtk-macros.h" #include <gtk/gtk.h> @@ -73,29 +72,7 @@ struct DebugPixbufViewerClass GtkWidgetClass parent_class; }; -/* GtkObjectClass methods */ -static void debug_pixbuf_viewer_class_init (DebugPixbufViewerClass *pixbuf_viewer_class); -static void debug_pixbuf_viewer_init (DebugPixbufViewer *pixbuf_viewer); -static void debug_pixbuf_viewer_finalize (GObject *object); - -/* GtkWidgetClass methods */ -static void debug_pixbuf_viewer_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int debug_pixbuf_viewer_expose_event (GtkWidget *widget, - GdkEventExpose *event); - -EEL_CLASS_BOILERPLATE (DebugPixbufViewer, debug_pixbuf_viewer, GTK_TYPE_WIDGET) - -static void -debug_pixbuf_viewer_class_init (DebugPixbufViewerClass *pixbuf_viewer_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (pixbuf_viewer_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (pixbuf_viewer_class); - - object_class->finalize = debug_pixbuf_viewer_finalize; - widget_class->size_request = debug_pixbuf_viewer_size_request; - widget_class->expose_event = debug_pixbuf_viewer_expose_event; -} +G_DEFINE_TYPE (DebugPixbufViewer, debug_pixbuf_viewer, GTK_TYPE_WIDGET) static void debug_pixbuf_viewer_init (DebugPixbufViewer *viewer) @@ -113,7 +90,7 @@ debug_pixbuf_viewer_finalize (GObject *object) eel_gdk_pixbuf_unref_if_not_null (viewer->pixbuf); viewer->pixbuf = NULL; - EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); + G_OBJECT_CLASS (debug_pixbuf_viewer_parent_class)->finalize (object); } static void @@ -184,13 +161,9 @@ debug_pixbuf_viewer_expose_event (GtkWidget *widget, GdkEventExpose *event) eel_gdk_pixbuf_draw_to_drawable (viewer->pixbuf, event->window, - gtk_widget_get_style (widget)->white_gc, clipped_bounds.x0 - bounds.x0, clipped_bounds.y0 - bounds.y0, - clipped_bounds, - GDK_RGB_DITHER_NONE, - GDK_PIXBUF_ALPHA_BILEVEL, - EEL_STANDARD_ALPHA_THRESHHOLD); + clipped_bounds); } } @@ -203,6 +176,17 @@ debug_pixbuf_viewer_expose_event (GtkWidget *widget, GdkEventExpose *event) } static void +debug_pixbuf_viewer_class_init (DebugPixbufViewerClass *pixbuf_viewer_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (pixbuf_viewer_class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (pixbuf_viewer_class); + + object_class->finalize = debug_pixbuf_viewer_finalize; + widget_class->size_request = debug_pixbuf_viewer_size_request; + widget_class->expose_event = debug_pixbuf_viewer_expose_event; +} + +static void debug_pixbuf_viewer_set_pixbuf (DebugPixbufViewer *viewer, GdkPixbuf *pixbuf) { g_assert (DEBUG_IS_PIXBUF_VIEWER (viewer)); @@ -229,7 +213,7 @@ eel_debug_draw_rectangle_and_cross (GdkDrawable *drawable, guint32 color, gboolean draw_cross) { - GdkGC *gc; + cairo_t *cr; GdkColor color_gdk = { 0 }; int width; @@ -241,43 +225,32 @@ eel_debug_draw_rectangle_and_cross (GdkDrawable *drawable, width = rectangle.x1 - rectangle.x0; height = rectangle.y1 - rectangle.y0; - gc = gdk_gc_new (drawable); - gdk_gc_set_function (gc, GDK_COPY); + cr = gdk_cairo_create (drawable); color_gdk.red = ((color >> 16) & 0xff) << 8; color_gdk.green = ((color >> 8) & 0xff) << 8; color_gdk.blue = ((color ) & 0xff) << 8; - gdk_colormap_alloc_color ( - gdk_drawable_get_colormap (drawable), - &color_gdk, FALSE, FALSE); - gdk_gc_set_rgb_fg_color (gc, &color_gdk); - - gdk_draw_rectangle (drawable, - gc, - FALSE, - rectangle.x0, - rectangle.y0, - width - 1, - height - 1); + gdk_cairo_set_source_color (cr, &color_gdk); + cairo_set_line_width (cr, 1.0); + + cairo_rectangle (cr, + rectangle.x0 + 0.5, + rectangle.y0 + 0.5, + width, + height); if (draw_cross) { - gdk_draw_line (drawable, - gc, - rectangle.x0, - rectangle.y0, - rectangle.x0 + width - 1, - rectangle.y0 + height - 1); - - gdk_draw_line (drawable, - gc, - rectangle.x0 + width - 1, - rectangle.y0, - rectangle.x0, - rectangle.y0 + height - 1); + cairo_move_to (cr, rectangle.x0, rectangle.y0); + cairo_line_to (cr, rectangle.x0 + width, rectangle.y0 + height); + + cairo_move_to (cr, rectangle.x0 + width, rectangle.y0); + cairo_line_to (cr, rectangle.x0, rectangle.y0 + height); } - g_object_unref (gc); + cairo_stroke (cr); + + cairo_destroy (cr); } /** @@ -377,8 +350,6 @@ eel_debug_show_pixbuf (GdkPixbuf *pixbuf) gtk_box_pack_start (GTK_BOX (vbox), debug_image, TRUE, TRUE, 0); - eel_gtk_widget_set_background_color (debug_window, "white"); - eel_debug_call_at_shutdown (destroy_debug_window); gtk_widget_show (debug_image); diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 7780fe7f..f7ec2d41 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -28,15 +28,22 @@ #include <string.h> #include "eel-editable-label.h" -#include "eel-i18n.h" #include "eel-marshal.h" #include "eel-accessibility.h" #include <libgail-util/gailmisc.h> +#include <glib/gi18n-lib.h> #include <pango/pango.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> +/* Some compatibility defines to let us build on both Gtk2 and Gtk3 */ +#if !GTK_CHECK_VERSION (3, 0, 0) +#define cairo_region_t GdkRegion +#define cairo_region_destroy gdk_region_destroy +#define GtkEditableInterface GtkEditableClass +#endif + enum { MOVE_CURSOR, @@ -61,7 +68,7 @@ enum static guint signals[LAST_SIGNAL] = { 0 }; -static void eel_editable_label_editable_init (GtkEditableClass *iface); +static void eel_editable_label_editable_init (GtkEditableInterface *iface); static void eel_editable_label_class_init (EelEditableLabelClass *klass); static void eel_editable_label_init (EelEditableLabel *label); static void eel_editable_label_set_property (GObject *object, @@ -73,8 +80,17 @@ static void eel_editable_label_get_property (GObject GValue *value, GParamSpec *pspec); static void eel_editable_label_finalize (GObject *object); +#if GTK_CHECK_VERSION(3,0,0) +static void eel_editable_label_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural); +static void eel_editable_label_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural); +#else static void eel_editable_label_size_request (GtkWidget *widget, - GtkRequisition *requisition); + GtkRequisition *requisition); +#endif static void eel_editable_label_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static void eel_editable_label_state_changed (GtkWidget *widget, @@ -83,8 +99,13 @@ static void eel_editable_label_style_set (GtkWidget GtkStyle *previous_style); static void eel_editable_label_direction_changed (GtkWidget *widget, GtkTextDirection previous_dir); +#if GTK_CHECK_VERSION(3,0,0) +static gint eel_editable_label_draw (GtkWidget *widget, + cairo_t *cr); +#else static gint eel_editable_label_expose (GtkWidget *widget, - GdkEventExpose *event); + GdkEventExpose *event); +#endif static void eel_editable_label_realize (GtkWidget *widget); static void eel_editable_label_unrealize (GtkWidget *widget); static void eel_editable_label_map (GtkWidget *widget); @@ -176,10 +197,6 @@ static void editable_real_set_position (GtkEditable *editable, gint position); static gint editable_get_position (GtkEditable *editable); -static GdkGC * make_cursor_gc (GtkWidget *widget, - const gchar *property_name, - GdkColor *fallback); - G_DEFINE_TYPE_WITH_CODE (EelEditableLabel, eel_editable_label, GTK_TYPE_MISC, G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, eel_editable_label_editable_init)); @@ -210,7 +227,6 @@ static void eel_editable_label_class_init (EelEditableLabelClass *class) { GObjectClass *gobject_class = G_OBJECT_CLASS (class); - GtkObjectClass *object_class = GTK_OBJECT_CLASS (class); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); GtkBindingSet *binding_set; @@ -218,12 +234,21 @@ eel_editable_label_class_init (EelEditableLabelClass *class) gobject_class->get_property = eel_editable_label_get_property; gobject_class->finalize = eel_editable_label_finalize; +#if GTK_CHECK_VERSION(3,0,0) + widget_class->get_preferred_width = eel_editable_label_get_preferred_width; + widget_class->get_preferred_height = eel_editable_label_get_preferred_height; +#else widget_class->size_request = eel_editable_label_size_request; +#endif widget_class->size_allocate = eel_editable_label_size_allocate; widget_class->state_changed = eel_editable_label_state_changed; widget_class->style_set = eel_editable_label_style_set; widget_class->direction_changed = eel_editable_label_direction_changed; +#if GTK_CHECK_VERSION(3,0,0) + widget_class->draw = eel_editable_label_draw; +#else widget_class->expose_event = eel_editable_label_expose; +#endif widget_class->realize = eel_editable_label_realize; widget_class->unrealize = eel_editable_label_unrealize; widget_class->map = eel_editable_label_map; @@ -247,7 +272,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) signals[MOVE_CURSOR] = g_signal_new ("move_cursor", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (EelEditableLabelClass, move_cursor), NULL, NULL, @@ -256,7 +281,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) signals[COPY_CLIPBOARD] = g_signal_new ("copy_clipboard", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (EelEditableLabelClass, copy_clipboard), NULL, NULL, @@ -265,7 +290,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) signals[POPULATE_POPUP] = g_signal_new ("populate_popup", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (EelEditableLabelClass, populate_popup), NULL, NULL, @@ -274,7 +299,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) signals[DELETE_FROM_CURSOR] = g_signal_new ("delete_from_cursor", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (EelEditableLabelClass, delete_from_cursor), NULL, NULL, @@ -283,7 +308,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) signals[CUT_CLIPBOARD] = g_signal_new ("cut_clipboard", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (EelEditableLabelClass, cut_clipboard), NULL, NULL, @@ -292,7 +317,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) signals[PASTE_CLIPBOARD] = g_signal_new ("paste_clipboard", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (EelEditableLabelClass, paste_clipboard), NULL, NULL, @@ -301,7 +326,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) signals[TOGGLE_OVERWRITE] = g_signal_new ("toggle_overwrite", - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (EelEditableLabelClass, toggle_overwrite), NULL, NULL, @@ -309,7 +334,7 @@ eel_editable_label_class_init (EelEditableLabelClass *class) G_TYPE_NONE, 0); - g_object_class_install_property (G_OBJECT_CLASS(object_class), + g_object_class_install_property (gobject_class, PROP_TEXT, g_param_spec_string ("text", _("Text"), @@ -360,159 +385,159 @@ eel_editable_label_class_init (EelEditableLabelClass *class) binding_set = gtk_binding_set_by_class (class); /* Moving the insertion point */ - add_move_binding (binding_set, GDK_Right, 0, + add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_MOVEMENT_VISUAL_POSITIONS, 1); - add_move_binding (binding_set, GDK_Left, 0, + add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_MOVEMENT_VISUAL_POSITIONS, -1); - add_move_binding (binding_set, GDK_KP_Right, 0, + add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_MOVEMENT_VISUAL_POSITIONS, 1); - add_move_binding (binding_set, GDK_KP_Left, 0, + add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_MOVEMENT_VISUAL_POSITIONS, -1); - add_move_binding (binding_set, GDK_f, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_f, GDK_CONTROL_MASK, GTK_MOVEMENT_LOGICAL_POSITIONS, 1); - add_move_binding (binding_set, GDK_b, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_b, GDK_CONTROL_MASK, GTK_MOVEMENT_LOGICAL_POSITIONS, -1); - add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_MOVEMENT_WORDS, 1); - add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_MOVEMENT_WORDS, -1); - add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_MOVEMENT_WORDS, 1); - add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_MOVEMENT_WORDS, -1); - add_move_binding (binding_set, GDK_a, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_a, GDK_CONTROL_MASK, GTK_MOVEMENT_PARAGRAPH_ENDS, -1); - add_move_binding (binding_set, GDK_e, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_e, GDK_CONTROL_MASK, GTK_MOVEMENT_PARAGRAPH_ENDS, 1); - add_move_binding (binding_set, GDK_f, GDK_MOD1_MASK, + add_move_binding (binding_set, GDK_KEY_f, GDK_MOD1_MASK, GTK_MOVEMENT_WORDS, 1); - add_move_binding (binding_set, GDK_b, GDK_MOD1_MASK, + add_move_binding (binding_set, GDK_KEY_b, GDK_MOD1_MASK, GTK_MOVEMENT_WORDS, -1); - add_move_binding (binding_set, GDK_Home, 0, + add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1); - add_move_binding (binding_set, GDK_End, 0, + add_move_binding (binding_set, GDK_KEY_End, 0, GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1); - add_move_binding (binding_set, GDK_KP_Home, 0, + add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1); - add_move_binding (binding_set, GDK_KP_End, 0, + add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1); - add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_MOVEMENT_BUFFER_ENDS, -1); - add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_MOVEMENT_BUFFER_ENDS, 1); - add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK, GTK_MOVEMENT_BUFFER_ENDS, -1); - add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK, + add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK, GTK_MOVEMENT_BUFFER_ENDS, 1); - add_move_binding (binding_set, GDK_Up, 0, + add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_MOVEMENT_DISPLAY_LINES, -1); - add_move_binding (binding_set, GDK_KP_Up, 0, + add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_MOVEMENT_DISPLAY_LINES, -1); - add_move_binding (binding_set, GDK_Down, 0, + add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_MOVEMENT_DISPLAY_LINES, 1); - add_move_binding (binding_set, GDK_KP_Down, 0, + add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_MOVEMENT_DISPLAY_LINES, 1); /* Select all */ - gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK, "move_cursor", 3, GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS, G_TYPE_INT, -1, G_TYPE_BOOLEAN, FALSE); - gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK, "move_cursor", 3, GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS, G_TYPE_INT, 1, G_TYPE_BOOLEAN, TRUE); /* Deleting text */ - gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_CHARS, G_TYPE_INT, 1); - gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_CHARS, G_TYPE_INT, 1); - gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_CHARS, G_TYPE_INT, -1); /* Make this do the same as Backspace, to help with mis-typing */ - gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_CHARS, G_TYPE_INT, -1); - gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_WORD_ENDS, G_TYPE_INT, 1); - gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_WORD_ENDS, G_TYPE_INT, 1); - gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK, "delete_from_cursor", 2, G_TYPE_ENUM, GTK_DELETE_WORD_ENDS, G_TYPE_INT, -1); /* Cut/copy/paste */ - gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK, "cut_clipboard", 0); - gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK, "copy_clipboard", 0); - gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK, "paste_clipboard", 0); - gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK, "cut_clipboard", 0); - gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK, "copy_clipboard", 0); - gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK, "paste_clipboard", 0); /* Overwrite */ - gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0, "toggle_overwrite", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0, "toggle_overwrite", 0); } static void -eel_editable_label_editable_init (GtkEditableClass *iface) +eel_editable_label_editable_init (GtkEditableInterface *iface) { iface->do_insert_text = editable_insert_text_emit; iface->do_delete_text = editable_delete_text_emit; @@ -1137,6 +1162,32 @@ eel_editable_label_size_request (GtkWidget *widget, requisition->height = height; } +#if GTK_CHECK_VERSION(3,0,0) +static void +eel_editable_label_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + GtkRequisition requisition; + + eel_editable_label_size_request (widget, &requisition); + + *minimum = *natural = requisition.width; +} + +static void +eel_editable_label_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + GtkRequisition requisition; + + eel_editable_label_size_request (widget, &requisition); + + *minimum = *natural = requisition.height; +} +#endif + static void eel_editable_label_size_allocate (GtkWidget *widget, GtkAllocation *allocation) @@ -1163,7 +1214,6 @@ eel_editable_label_style_set (GtkWidget *widget, GtkStyle *previous_style) { EelEditableLabel *label; - static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 }; g_assert (EEL_IS_EDITABLE_LABEL (widget)); @@ -1181,26 +1231,6 @@ eel_editable_label_style_set (GtkWidget *widget, style = gtk_widget_get_style (widget); gdk_window_set_background (gtk_widget_get_window (widget), &style->base[gtk_widget_get_state (widget)]); - - if (label->primary_cursor_gc != NULL) - { - gtk_gc_release (label->primary_cursor_gc); - label->primary_cursor_gc = NULL; - } - - if (label->secondary_cursor_gc != NULL) - { - gtk_gc_release (label->secondary_cursor_gc); - label->secondary_cursor_gc = NULL; - } - - label->primary_cursor_gc = make_cursor_gc (widget, - "cursor-color", - &style->black); - - label->secondary_cursor_gc = make_cursor_gc (widget, - "secondary-cursor-color", - &gray); } } @@ -1235,7 +1265,11 @@ get_layout_location (EelEditableLabel *label, if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) xalign = 1.0 - xalign; - gtk_widget_get_child_requisition (widget, &req); +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_get_preferred_size (widget, &req, NULL); +#else + gtk_widget_size_request (widget, &req); +#endif gtk_misc_get_padding (misc, &xpad, &ypad); gtk_widget_get_allocation (widget, &allocation); @@ -1403,98 +1437,12 @@ eel_editable_label_get_block_cursor_location (EelEditableLabel *label, /* These functions are copies from gtk+, as they are not exported from gtk+ */ -static GdkGC * -make_cursor_gc (GtkWidget *widget, - const gchar *property_name, - GdkColor *fallback) -{ - GdkGCValues gc_values; - GdkGCValuesMask gc_values_mask; - GdkColor *cursor_color; - GtkStyle *style; - - style = gtk_widget_get_style (widget); - gtk_widget_style_get (widget, property_name, &cursor_color, NULL); - - gc_values_mask = GDK_GC_FOREGROUND; - if (cursor_color) - { - gc_values.foreground = *cursor_color; - gdk_color_free (cursor_color); - } - else - gc_values.foreground = *fallback; - - gdk_rgb_find_color (style->colormap, &gc_values.foreground); - return gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); -} - -static void -_eel_draw_insertion_cursor (GtkWidget *widget, - GdkDrawable *drawable, - GdkGC *gc, - GdkRectangle *location, - GtkTextDirection direction, - gboolean draw_arrow) -{ - gint stem_width; - gint arrow_width; - gint x, y; - gint i; - gfloat cursor_aspect_ratio; - gint offset; - - g_assert (direction != GTK_TEXT_DIR_NONE); - - gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL); - - stem_width = location->height * cursor_aspect_ratio + 1; - arrow_width = stem_width + 1; - - /* put (stem_width % 2) on the proper side of the cursor */ - if (direction == GTK_TEXT_DIR_LTR) - offset = stem_width / 2; - else - offset = stem_width - stem_width / 2; - - for (i = 0; i < stem_width; i++) - gdk_draw_line (drawable, gc, - location->x + i - offset, location->y, - location->x + i - offset, location->y + location->height - 1); - - if (draw_arrow) - { - if (direction == GTK_TEXT_DIR_RTL) - { - x = location->x - offset - 1; - y = location->y + location->height - arrow_width * 2 - arrow_width + 1; - - for (i = 0; i < arrow_width; i++) - { - gdk_draw_line (drawable, gc, - x, y + i + 1, - x, y + 2 * arrow_width - i - 1); - x --; - } - } - else if (direction == GTK_TEXT_DIR_LTR) - { - x = location->x + stem_width - offset; - y = location->y + location->height - arrow_width * 2 - arrow_width + 1; - - for (i = 0; i < arrow_width; i++) - { - gdk_draw_line (drawable, gc, - x, y + i + 1, - x, y + 2 * arrow_width - i - 1); - x++; - } - } - } -} - static void +#if GTK_CHECK_VERSION(3,0,0) +eel_editable_label_draw_cursor (EelEditableLabel *label, cairo_t *cr, gint xoffset, gint yoffset) +#else eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yoffset) +#endif { if (gtk_widget_is_drawable (GTK_WIDGET (label))) { @@ -1561,10 +1509,15 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof cursor_location.width = 0; cursor_location.height = PANGO_PIXELS (cursor1->height); - _eel_draw_insertion_cursor (widget, gtk_widget_get_window (widget), - label->primary_cursor_gc, - &cursor_location, dir1, - dir2 != GTK_TEXT_DIR_NONE); + gtk_draw_insertion_cursor (widget, +#if GTK_CHECK_VERSION(3,0,0) + cr, + &cursor_location, +#else + gtk_widget_get_window (widget), + NULL, &cursor_location, +#endif + TRUE, dir1, dir2 != GTK_TEXT_DIR_NONE); if (dir2 != GTK_TEXT_DIR_NONE) { @@ -1573,58 +1526,80 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof cursor_location.width = 0; cursor_location.height = PANGO_PIXELS (cursor2->height); - _eel_draw_insertion_cursor (widget, gtk_widget_get_window (widget), - label->secondary_cursor_gc, - &cursor_location, dir2, TRUE); + gtk_draw_insertion_cursor (widget, +#if GTK_CHECK_VERSION(3,0,0) + cr, + &cursor_location, +#else + gtk_widget_get_window (widget), + NULL, &cursor_location, +#endif + FALSE, dir2, TRUE); } } else /* Block cursor */ { - GdkRegion *clip; - - gdk_draw_rectangle (gtk_widget_get_window (widget), label->primary_cursor_gc, TRUE, - xoffset + PANGO_PIXELS (strong_pos.x), - yoffset + PANGO_PIXELS (strong_pos.y), - PANGO_PIXELS (strong_pos.width), - PANGO_PIXELS (strong_pos.height)); + cairo_region_t *clip; + +#if GTK_CHECK_VERSION(3,0,0) + cairo_save (cr); +#else + cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); +#endif + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_rectangle (cr, + xoffset + PANGO_PIXELS (strong_pos.x), + yoffset + PANGO_PIXELS (strong_pos.y), + PANGO_PIXELS (strong_pos.width), + PANGO_PIXELS (strong_pos.height)); +#if GTK_CHECK_VERSION(3,0,0) + cairo_fill (cr); +#endif if (!block_at_line_end) { clip = gdk_pango_layout_get_clip_region (label->layout, - xoffset, yoffset, - range, 1); + xoffset, yoffset, + range, 1); - /* FIXME should use gtk_paint, but it can't use a clip - * region - */ + gdk_cairo_region (cr, clip); + cairo_clip (cr); + gdk_cairo_set_source_color (cr, + >k_widget_get_style (widget)->base[GTK_STATE_NORMAL]); + cairo_move_to (cr, xoffset, yoffset); + pango_cairo_show_layout (cr, label->layout); - gdk_gc_set_clip_region (label->primary_cursor_gc, clip); - - gdk_draw_layout_with_colors (gtk_widget_get_window (widget), - label->primary_cursor_gc, - xoffset, yoffset, - label->layout, - >k_widget_get_style (widget)->base[GTK_STATE_NORMAL], - NULL); - - gdk_gc_set_clip_region (label->primary_cursor_gc, NULL); - gdk_region_destroy (clip); + cairo_region_destroy (clip); } + +#if GTK_CHECK_VERSION(3,0,0) + cairo_restore (cr); +#else + cairo_destroy (cr); +#endif } } } static gint +#if GTK_CHECK_VERSION(3,0,0) +eel_editable_label_draw (GtkWidget *widget, + cairo_t *cr) +#else eel_editable_label_expose (GtkWidget *widget, GdkEventExpose *event) +#endif { EelEditableLabel *label; GtkStyle *style; gint x, y; g_assert (EEL_IS_EDITABLE_LABEL (widget)); +#if !GTK_CHECK_VERSION(3,0,0) g_assert (event != NULL); +#endif label = EEL_EDITABLE_LABEL (widget); style = gtk_widget_get_style (widget); @@ -1637,10 +1612,16 @@ eel_editable_label_expose (GtkWidget *widget, get_layout_location (label, &x, &y); gtk_paint_layout (style, +#if GTK_CHECK_VERSION(3,0,0) + cr, +#else gtk_widget_get_window (widget), +#endif gtk_widget_get_state (widget), TRUE, +#if !GTK_CHECK_VERSION(3,0,0) &event->area, +#endif widget, "label", x, y, @@ -1650,7 +1631,7 @@ eel_editable_label_expose (GtkWidget *widget, { gint range[2]; const char *text; - GdkRegion *clip; + cairo_region_t *clip; GtkStateType state; range[0] = label->selection_anchor; @@ -1658,7 +1639,7 @@ eel_editable_label_expose (GtkWidget *widget, /* Handle possible preedit string */ if (label->preedit_length > 0 && - range[1] > label->selection_anchor) + range[1] > label->selection_anchor) { text = pango_layout_get_text (label->layout) + label->selection_anchor; range[1] += g_utf8_offset_to_pointer (text, label->preedit_length) - text; @@ -1672,44 +1653,60 @@ eel_editable_label_expose (GtkWidget *widget, } clip = gdk_pango_layout_get_clip_region (label->layout, - x, y, - range, - 1); - - /* FIXME should use gtk_paint, but it can't use a clip - * region - */ - - gdk_gc_set_clip_region (style->black_gc, clip); - + x, y, + range, + 1); +#if GTK_CHECK_VERSION(3,0,0) + cairo_save (cr); +#else + cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); +#endif + gdk_cairo_region (cr, clip); + cairo_clip (cr); state = GTK_STATE_SELECTED; if (!gtk_widget_has_focus (widget)) state = GTK_STATE_ACTIVE; - gdk_draw_layout_with_colors (gtk_widget_get_window (widget), - style->black_gc, - x, y, - label->layout, - &style->text[state], - &style->base[state]); + gdk_cairo_set_source_color (cr, &style->base[state]); + cairo_paint (cr); - gdk_gc_set_clip_region (style->black_gc, NULL); - gdk_region_destroy (clip); + gdk_cairo_set_source_color (cr, &style->text[state]); + cairo_move_to (cr, x, y); + pango_cairo_show_layout (cr, label->layout); + +#if GTK_CHECK_VERSION(3,0,0) + cairo_restore (cr); +#else + cairo_destroy (cr); +#endif + cairo_region_destroy (clip); } else if (gtk_widget_has_focus (widget)) +#if GTK_CHECK_VERSION(3,0,0) + eel_editable_label_draw_cursor (label, cr, x, y); +#else eel_editable_label_draw_cursor (label, x, y); +#endif if (label->draw_outline) { GtkAllocation allocation; + gtk_widget_get_allocation (widget, &allocation); - gdk_draw_rectangle (gtk_widget_get_window (widget), - style->text_gc [gtk_widget_get_state (widget)], - FALSE, - 0, 0, - allocation.width - 1, - allocation.height - 1); +#if !GTK_CHECK_VERSION(3,0,0) + cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); +#endif + gdk_cairo_set_source_color (cr, &style->text [gtk_widget_get_state (widget)]); + cairo_set_line_width (cr, 1.0); + cairo_rectangle (cr, 0.5, 0.5, + allocation.width - 1, + allocation.height - 1); + cairo_stroke (cr); + +#if !GTK_CHECK_VERSION(3,0,0) + cairo_destroy (cr); +#endif } } @@ -1722,7 +1719,6 @@ eel_editable_label_realize (GtkWidget *widget) EelEditableLabel *label; GdkWindowAttr attributes; gint attributes_mask; - static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 }; GtkAllocation allocation; GdkWindow *window; GtkStyle *style; @@ -1738,7 +1734,9 @@ eel_editable_label_realize (GtkWidget *widget) attributes.width = allocation.width; attributes.height = allocation.height; attributes.visual = gtk_widget_get_visual (widget); +#if !GTK_CHECK_VERSION(3,0,0) attributes.colormap = gtk_widget_get_colormap (widget); +#endif attributes.cursor = gdk_cursor_new (GDK_XTERM); attributes.event_mask = gtk_widget_get_events (widget) | (GDK_EXPOSURE_MASK | @@ -1751,7 +1749,11 @@ eel_editable_label_realize (GtkWidget *widget) GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); +#if GTK_CHECK_VERSION(3,0,0) + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_CURSOR; +#else attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR; +#endif window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); @@ -1766,14 +1768,6 @@ eel_editable_label_realize (GtkWidget *widget) gdk_window_set_background (gtk_widget_get_window (widget), &style->base[gtk_widget_get_state (widget)]); gtk_im_context_set_client_window (label->im_context, gtk_widget_get_window (widget)); - - label->primary_cursor_gc = make_cursor_gc (widget, - "cursor-color", - &style->black); - - label->secondary_cursor_gc = make_cursor_gc (widget, - "secondary-cursor-color", - &gray); } static void @@ -1783,12 +1777,6 @@ eel_editable_label_unrealize (GtkWidget *widget) label = EEL_EDITABLE_LABEL (widget); - gtk_gc_release (label->primary_cursor_gc); - label->primary_cursor_gc = NULL; - - gtk_gc_release (label->secondary_cursor_gc); - label->secondary_cursor_gc = NULL; - /* Strange. Copied from GtkEntry, should be NULL? */ gtk_im_context_set_client_window (label->im_context, NULL); @@ -3087,7 +3075,7 @@ activate_cb (GtkWidget *menuitem, EelEditableLabel *label) { const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal"); - g_signal_emit_by_name (GTK_OBJECT (label), signal); + g_signal_emit_by_name (label, signal); } static void @@ -3221,7 +3209,7 @@ popup_targets_received (GtkClipboard *clipboard, gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (label->im_context), GTK_MENU_SHELL (submenu)); - g_signal_emit (GTK_OBJECT (label), + g_signal_emit (label, signals[POPULATE_POPUP], 0, label->popup_menu); diff --git a/eel/eel-editable-label.h b/eel/eel-editable-label.h index 249a3367..b19c2417 100644 --- a/eel/eel-editable-label.h +++ b/eel/eel-editable-label.h @@ -79,9 +79,6 @@ extern "C" { int preedit_length; /* length of preedit string, in bytes */ int preedit_cursor; /* offset of cursor within preedit string, in chars */ - GdkGC *primary_cursor_gc; - GdkGC *secondary_cursor_gc; - PangoFontDescription *font_desc; }; diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c index 86a8600e..ed694277 100644 --- a/eel/eel-gdk-extensions.c +++ b/eel/eel-gdk-extensions.c @@ -40,48 +40,6 @@ #define GRADIENT_BAND_SIZE 4 /** - * eel_gdk_rectangle_contains_rectangle: - * @outer: Rectangle possibly containing another rectangle. - * @inner: Rectangle that might be inside. - * - * Retun TRUE if inner rectangle is contained inside outer rectangle - */ -gboolean -eel_gdk_rectangle_contains_rectangle (GdkRectangle outer, GdkRectangle inner) -{ - return outer.x <= inner.x && outer.x + outer.width >= inner.x + inner.width - && outer.y <= inner.y && outer.y + outer.height >= inner.y + inner.height; -} - -/** - * eel_interpolate_color: - * @ratio: Place on line between colors to interpolate. - * @start_color: Color for one end. - * @end_color: Color for the other end - * @interpolated_color: Result. - * - * Compute a color between @start_color and @end_color in color space. - * Currently, the color space used is RGB, but a future version could - * instead do the interpolation in the best color space for expressing - * human perception. - */ -guint32 -eel_interpolate_color (gdouble ratio, - guint32 start_rgb, - guint32 end_rgb) -{ - guchar red, green, blue; - - g_return_val_if_fail (ratio >= 0.0, 0); - g_return_val_if_fail (ratio <= 1.0, 0); - - red = ((start_rgb >> 16) & 0xFF) * (1.0 - ratio) + ((end_rgb >> 16) & 0xFF) * ratio; - green = ((start_rgb >> 8) & 0xFF) * (1.0 - ratio) + ((end_rgb >> 8) & 0xFF) * ratio; - blue = (start_rgb & 0xFF) * (1.0 - ratio) + (end_rgb & 0xFF) * ratio; - return (((red << 8) | green) << 8) | blue; -} - -/** * eel_gradient_new * @start_color: Color for the top or left. * @end_color: Color for the bottom or right. @@ -387,26 +345,6 @@ eel_gdk_color_parse_with_white_default (const char *color_spec, } } -/** - * eel_parse_rgb_with_white_default - * @color_spec: A color spec, or NULL. - * Returns: An rgb value. - * - * The same as gdk_color_parse, except sets the color to white if - * the spec. can't be parsed instead of returning a boolean flag - * and returns a guint32 rgb value instead of a GdkColor. - */ -guint32 -eel_parse_rgb_with_white_default (const char *color_spec) -{ - GdkColor color; - - eel_gdk_color_parse_with_white_default (color_spec, &color); - return ((color.red << 8) & EEL_RGB_COLOR_RED) - | (color.green & EEL_RGB_COLOR_GREEN) - | ((color.blue >> 8) & EEL_RGB_COLOR_BLUE); -} - guint32 eel_rgb16_to_rgb (gushort r, gushort g, gushort b) { @@ -476,51 +414,6 @@ eel_gdk_rgb_to_color_spec (const guint32 color) return g_strdup_printf ("#%06X", (guint) (color & 0xFFFFFF)); } -static guint32 -eel_shift_color_component (guchar component, float shift_by) -{ - guint32 result; - if (shift_by > 1.0) - { - result = component * (2 - shift_by); - } - else - { - result = 0xff - shift_by * (0xff - component); - } - - return result & 0xff; -} - -/** - * eel_rgb_shift_color - * @color: A color. - * @shift_by: darken or lighten factor. - * Returns: An darkened or lightened rgb value. - * - * Darkens (@shift_by > 1) or lightens (@shift_by < 1) - * @color. - */ -guint32 -eel_rgb_shift_color (guint32 color, float shift_by) -{ - guint32 result; - - /* shift red by shift_by */ - result = eel_shift_color_component((color & 0x00ff0000) >> 16, shift_by); - result <<= 8; - /* shift green by shift_by */ - result |= eel_shift_color_component((color & 0x0000ff00) >> 8, shift_by); - result <<= 8; - /* shift blue by shift_by */ - result |= eel_shift_color_component((color & 0x000000ff), shift_by); - - /* alpha doesn't change */ - result |= (0xff000000 & color); - - return result; -} - /** * eel_gdk_color_is_dark: * @@ -538,169 +431,6 @@ eel_gdk_color_is_dark (GdkColor *color) return intensity < 128; } -/** - * eel_stipple_bitmap_for_screen: - * - * Get pointer to 50% stippled bitmap suitable for use - * on @screen. This is a global object; do not free. - */ -GdkBitmap * -eel_stipple_bitmap_for_screen (GdkScreen *screen) -{ - static char stipple_bits[] = { 0x02, 0x01 }; - static GPtrArray *stipples = NULL; - int screen_num, n_screens, i; - - if (stipples == NULL) - { - n_screens = gdk_display_get_n_screens ( - gdk_screen_get_display (screen)); - stipples = g_ptr_array_sized_new (n_screens); - - for (i = 0; i < n_screens; i++) - { - g_ptr_array_index (stipples, i) = NULL; - } - } - - screen_num = gdk_screen_get_number (screen); - - if (g_ptr_array_index (stipples, screen_num) == NULL) - { - g_ptr_array_index (stipples, screen_num) = - gdk_bitmap_create_from_data ( - gdk_screen_get_root_window (screen), - stipple_bits, 2, 2); - } - - return g_ptr_array_index (stipples, screen_num); -} - -/** - * eel_stipple_bitmap: - * - * Get pointer to 50% stippled bitmap suitable for use - * on the default screen. This is a global object; do - * not free. - * - * This method is not multiscreen safe. Do not use it. - */ -GdkBitmap * -eel_stipple_bitmap (void) -{ - return eel_stipple_bitmap_for_screen (gdk_screen_get_default ()); -} - -/** - * eel_gdk_window_bring_to_front: - * - * Raise window and give it focus. - */ -void -eel_gdk_window_bring_to_front (GdkWindow *window) -{ - /* This takes care of un-iconifying the window and - * raising it if needed. - */ - gdk_window_show (window); - - /* If the window was already showing, it would not have - * the focus at this point. Do a little X trickery to - * ensure it is focused. - */ - eel_gdk_window_focus (window, GDK_CURRENT_TIME); -} - -void -eel_gdk_window_focus (GdkWindow *window, guint32 timestamp) -{ - gdk_error_trap_push (); - XSetInputFocus (GDK_DISPLAY (), - GDK_WINDOW_XWINDOW (window), - RevertToParent, - timestamp); - gdk_flush(); - gdk_error_trap_pop (); -} - -void -eel_gdk_window_set_wm_protocols (GdkWindow *window, - GdkAtom *protocols, - int nprotocols) -{ - Atom *atoms; - int i; - - atoms = g_new (Atom, nprotocols); - for (i = 0; i < nprotocols; i++) - { - atoms[i] = gdk_x11_atom_to_xatom (protocols[i]); - } - - XSetWMProtocols (GDK_WINDOW_XDISPLAY (window), - GDK_WINDOW_XWINDOW (window), - atoms, nprotocols); - - g_free (atoms); -} - -/** - * eel_gdk_window_set_wm_hints_input: - * - * Set the WM_HINTS.input flag to the passed in value - */ -void -eel_gdk_window_set_wm_hints_input (GdkWindow *window, gboolean status) -{ - Display *dpy; - Window id; - XWMHints *wm_hints; - - g_return_if_fail (window != NULL); - - dpy = GDK_WINDOW_XDISPLAY (window); - id = GDK_WINDOW_XWINDOW (window); - - wm_hints = XGetWMHints (dpy, id); - if (wm_hints == 0) - { - wm_hints = XAllocWMHints (); - } - - wm_hints->flags |= InputHint; - wm_hints->input = (status == FALSE) ? False : True; - - XSetWMHints (dpy, id, wm_hints); - XFree (wm_hints); -} - -void -eel_gdk_window_set_invisible_cursor (GdkWindow *window) -{ - GdkBitmap *empty_bitmap; - GdkCursor *cursor; - GdkColor useless; - char invisible_cursor_bits[] = { 0x0 }; - - useless.red = useless.green = useless.blue = 0; - useless.pixel = 0; - - empty_bitmap = gdk_bitmap_create_from_data (window, - invisible_cursor_bits, - 1, 1); - - cursor = gdk_cursor_new_from_pixmap (empty_bitmap, - empty_bitmap, - &useless, - &useless, 0, 0); - - gdk_window_set_cursor (window, cursor); - - gdk_cursor_unref (cursor); - - g_object_unref (empty_bitmap); -} - EelGdkGeometryFlags eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return, guint *width_return, guint *height_return) @@ -747,23 +477,37 @@ eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return, } void +#if GTK_CHECK_VERSION(3,0,0) +eel_cairo_draw_layout_with_drop_shadow (cairo_t *cr, +#else eel_gdk_draw_layout_with_drop_shadow (GdkDrawable *drawable, - GdkGC *gc, +#endif GdkColor *text_color, GdkColor *shadow_color, int x, int y, PangoLayout *layout) { - gdk_draw_layout_with_colors (drawable, gc, - x+1, y+1, - layout, - shadow_color, NULL); - - gdk_draw_layout_with_colors (drawable, gc, - x, y, - layout, - text_color, NULL); +#if GTK_CHECK_VERSION(3,0,0) + cairo_save (cr); +#else + cairo_t *cr; + cr = gdk_cairo_create (drawable); +#endif + + gdk_cairo_set_source_color (cr, shadow_color); + cairo_move_to (cr, x+1, y+1); + pango_cairo_show_layout (cr, layout); + + gdk_cairo_set_source_color (cr, text_color); + cairo_move_to (cr, x, y); + pango_cairo_show_layout (cr, layout); + +#if GTK_CHECK_VERSION(3,0,0) + cairo_restore +#else + cairo_destroy (cr); +#endif } #if ! defined (EEL_OMIT_SELF_CHECK) @@ -797,12 +541,6 @@ eel_self_check_gdk_rgb_to_color (guint32 color) void eel_self_check_gdk_extensions (void) { - /* eel_interpolate_color */ - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (0.0, 0, 0), 0); - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (0.0, 0, 0xFFFFFF), 0); - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (0.5, 0, 0xFFFFFF), 0x7F7F7F); - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (1.0, 0, 0xFFFFFF), 0xFFFFFF); - /* eel_gradient_new */ EEL_CHECK_STRING_RESULT (eel_gradient_new ("", "", FALSE), ""); EEL_CHECK_STRING_RESULT (eel_gradient_new ("a", "b", FALSE), "a-b"); diff --git a/eel/eel-gdk-extensions.h b/eel/eel-gdk-extensions.h index 91518186..2036eec4 100644 --- a/eel/eel-gdk-extensions.h +++ b/eel/eel-gdk-extensions.h @@ -28,6 +28,10 @@ #include <gdk/gdk.h> +#ifndef GTK_CHECK_VERSION +#include <gtk/gtk.h> +#endif + #define EEL_RGB_COLOR_RED 0xFF0000 #define EEL_RGB_COLOR_GREEN 0x00FF00 #define EEL_RGB_COLOR_BLUE 0x0000FF @@ -98,16 +102,8 @@ char * eel_gradient_set_bottom_color_spec (const char /* A version of parse_color that substitutes a default color instead of returning a boolean to indicate it cannot be parsed. */ -void eel_gdk_color_parse_with_default (const char *color_spec, - const GdkColor *default_color, - GdkColor *parsed_color); void eel_gdk_color_parse_with_white_default (const char *color_spec, GdkColor *parsed_color); -guint32 eel_parse_rgb_with_default (const char *color_spec, - guint32 default_rgb); -guint32 eel_parse_rgb_with_white_default (const char *color_spec); -guint32 eel_rgb_shift_color (guint32 color, - float shift_by); guint32 eel_rgb16_to_rgb (gushort r, gushort g, gushort b); @@ -120,45 +116,20 @@ char * eel_gdk_rgb_to_color_spec (guint32 gboolean eel_gdk_color_is_dark (GdkColor *color); -/* A routine to get a 50% gray stippled bitmap for use in some types of highlighting. */ -GdkBitmap * eel_stipple_bitmap_for_screen (GdkScreen *screen); -GdkBitmap * eel_stipple_bitmap (void); - - -/* Misc GdkRectangle helper functions */ -gboolean eel_gdk_rectangle_contains_rectangle (GdkRectangle outer, - GdkRectangle inner); - - -/* A basic operation we use for drawing gradients is interpolating two colors.*/ -guint32 eel_interpolate_color (gdouble ratio, - guint32 start_rgb, - guint32 end_rgb); - -/* Misc GdkWindow helper functions */ -void eel_gdk_window_bring_to_front (GdkWindow *window); -void eel_gdk_window_set_invisible_cursor (GdkWindow *window); -void eel_gdk_window_focus (GdkWindow *window, - guint32 timestamp); -void eel_gdk_window_set_wm_protocols (GdkWindow *window, - GdkAtom *protocols, - int nprotocols); - - -void eel_gdk_window_set_wm_hints_input (GdkWindow *w, - gboolean status); - /* Wrapper for XParseGeometry */ EelGdkGeometryFlags eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return, guint *width_return, guint *height_return); +#if GTK_CHECK_VERSION(3,0,0) +void eel_cairo_draw_layout_with_drop_shadow (cairo_t *cr, +#else void eel_gdk_draw_layout_with_drop_shadow (GdkDrawable *drawable, - GdkGC *gc, - GdkColor *text_color, - GdkColor *shadow_color, - int x, - int y, - PangoLayout *layout); +#endif + GdkColor *text_color, + GdkColor *shadow_color, + int x, + int y, + PangoLayout *layout); #endif /* EEL_GDK_EXTENSIONS_H */ diff --git a/eel/eel-gdk-pixbuf-extensions.c b/eel/eel-gdk-pixbuf-extensions.c index a75158db..c913cb10 100644 --- a/eel/eel-gdk-pixbuf-extensions.c +++ b/eel/eel-gdk-pixbuf-extensions.c @@ -26,8 +26,6 @@ #include <config.h> #include "eel-gdk-pixbuf-extensions.h" -#include "eel-art-gtk-extensions.h" -#include "eel-debug-drawing.h" #include "eel-debug.h" #include "eel-gdk-extensions.h" #include "eel-glib-extensions.h" @@ -56,30 +54,6 @@ struct EelPixbufLoadHandle char buffer[LOAD_BUFFER_SIZE]; }; -/** - * eel_gdk_pixbuf_list_ref - * @pixbuf_list: A list of GdkPixbuf objects. - * - * Refs all the pixbufs. - **/ -void -eel_gdk_pixbuf_list_ref (GList *pixbuf_list) -{ - g_list_foreach (pixbuf_list, (GFunc) g_object_ref, NULL); -} - -/** - * eel_gdk_pixbuf_list_free - * @pixbuf_list: A list of GdkPixbuf objects. - * - * Unrefs all the pixbufs, then frees the list. - **/ -void -eel_gdk_pixbuf_list_free (GList *pixbuf_list) -{ - eel_g_list_free_deep_custom (pixbuf_list, (GFunc) g_object_unref, NULL); -} - GdkPixbuf * eel_gdk_pixbuf_load (const char *uri) { @@ -649,13 +623,9 @@ eel_gdk_pixbuf_unref_if_not_null (GdkPixbuf *pixbuf_or_null) void eel_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, GdkDrawable *drawable, - GdkGC *gc, int source_x, int source_y, - EelIRect destination_area, - GdkRgbDither dither, - GdkPixbufAlphaMode alpha_compositing_mode, - int alpha_threshold) + EelIRect destination_area) { EelDimensions dimensions; EelIRect target; @@ -664,15 +634,11 @@ eel_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, int target_height; int source_width; int source_height; + cairo_t *cr; g_return_if_fail (eel_gdk_pixbuf_is_valid (pixbuf)); g_return_if_fail (drawable != NULL); - g_return_if_fail (gc != NULL); g_return_if_fail (!eel_irect_is_empty (&destination_area)); - g_return_if_fail (alpha_threshold > EEL_OPACITY_FULLY_TRANSPARENT); - g_return_if_fail (alpha_threshold <= EEL_OPACITY_FULLY_OPAQUE); - g_return_if_fail (alpha_compositing_mode >= GDK_PIXBUF_ALPHA_BILEVEL); - g_return_if_fail (alpha_compositing_mode <= GDK_PIXBUF_ALPHA_FULL); dimensions = eel_gdk_pixbuf_get_dimensions (pixbuf); @@ -707,16 +673,14 @@ eel_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, target.x1 = target.x0 + MIN (target_width, source_width); target.y1 = target.y0 + MIN (target_height, source_height); - gdk_draw_pixbuf (drawable, gc, (GdkPixbuf *) pixbuf, - source.x0, - source.y0, - target.x0, - target.y0, + cr = gdk_cairo_create (drawable); + gdk_cairo_set_source_pixbuf (cr, (GdkPixbuf *) pixbuf, + source.x0 - target.x0, source.y0 - target.y0); + cairo_rectangle (cr, target.x0, target.y0, target.x1 - target.x0, - target.y1 - target.y0, - dither, - 0, - 0); + target.y1 - target.y0); + cairo_fill (cr); + cairo_destroy (cr); } /** diff --git a/eel/eel-gdk-pixbuf-extensions.h b/eel/eel-gdk-pixbuf-extensions.h index 7d7956e4..382cd6cd 100644 --- a/eel/eel-gdk-pixbuf-extensions.h +++ b/eel/eel-gdk-pixbuf-extensions.h @@ -31,7 +31,6 @@ #include <gdk/gdk.h> #include <gio/gio.h> -#define EEL_STANDARD_ALPHA_THRESHHOLD 128 #define EEL_OPACITY_FULLY_TRANSPARENT 0 #define EEL_OPACITY_FULLY_OPAQUE 255 @@ -42,12 +41,6 @@ typedef void (* EelPixbufLoadCallback) (GError *error, GdkPixbuf *pixbuf, gpointer callback_data); -/* Convenience functions for lists of GdkPixbuf objects. */ -void eel_gdk_pixbuf_list_ref (GList *pixbuf_list); -void eel_gdk_pixbuf_list_unref (GList *pixbuf_list); -void eel_gdk_pixbuf_list_free (GList *pixbuf_list); - - /* Loading a GdkPixbuf with a URI. */ GdkPixbuf * eel_gdk_pixbuf_load (const char *uri); GdkPixbuf * eel_gdk_pixbuf_load_from_stream (GInputStream *stream); @@ -100,13 +93,9 @@ void eel_gdk_pixbuf_unref_if_not_null (GdkPixbuf /* Copy a pixbuf to an area of a GdkDrawable */ void eel_gdk_pixbuf_draw_to_drawable (const GdkPixbuf *pixbuf, GdkDrawable *drawable, - GdkGC *gc, int source_x, int source_y, - EelIRect destination_area, - GdkRgbDither dither, - GdkPixbufAlphaMode alpha_compositing_mode, - int alpha_threshold); + EelIRect destination_area); /* Copy a pixbuf to an area of another pixbuf */ void eel_gdk_pixbuf_draw_to_pixbuf (const GdkPixbuf *pixbuf, diff --git a/eel/eel-glib-extensions.c b/eel/eel-glib-extensions.c index 67986b32..5b016aad 100644 --- a/eel/eel-glib-extensions.c +++ b/eel/eel-glib-extensions.c @@ -30,7 +30,6 @@ #include "eel-debug.h" #include "eel-lib-self-check-functions.h" #include "eel-string.h" -#include "eel-i18n.h" #include <glib-object.h> #include <math.h> #include <stdlib.h> @@ -377,63 +376,6 @@ eel_g_str_list_index (GList *str_list, } /** - * eel_g_list_free_deep_custom - * - * Frees the elements of a list and then the list, using a custom free function. - * - * @list: List of elements that can be freed with the provided free function. - * @element_free_func: function to call with the data pointer and user_data to free it. - * @user_data: User data to pass to element_free_func - **/ -void -eel_g_list_free_deep_custom (GList *list, GFunc element_free_func, gpointer user_data) -{ - g_list_foreach (list, element_free_func, user_data); - g_list_free (list); -} - -/** - * eel_g_list_free_deep - * - * Frees the elements of a list and then the list. - * @list: List of elements that can be freed with g_free. - **/ -void -eel_g_list_free_deep (GList *list) -{ - eel_g_list_free_deep_custom (list, (GFunc) g_free, NULL); -} - -/** - * eel_g_list_free_deep_custom - * - * Frees the elements of a list and then the list, using a custom free function. - * - * @list: List of elements that can be freed with the provided free function. - * @element_free_func: function to call with the data pointer and user_data to free it. - * @user_data: User data to pass to element_free_func - **/ -void -eel_g_slist_free_deep_custom (GSList *list, GFunc element_free_func, gpointer user_data) -{ - g_slist_foreach (list, element_free_func, user_data); - g_slist_free (list); -} - -/** - * eel_g_slist_free_deep - * - * Frees the elements of a list and then the list. - * @list: List of elements that can be freed with g_free. - **/ -void -eel_g_slist_free_deep (GSList *list) -{ - eel_g_slist_free_deep_custom (list, (GFunc) g_free, NULL); -} - - -/** * eel_g_strv_find * * Get index of string in array of strings. @@ -749,74 +691,6 @@ eel_round (double d) return val; } -GList * -eel_g_list_from_g_slist (GSList *slist) -{ - GList *list; - GSList *node; - - list = NULL; - for (node = slist; node != NULL; node = node->next) - { - list = g_list_prepend (list, node->data); - } - return g_list_reverse (list); -} - -GSList * -eel_g_slist_from_g_list (GList *list) -{ - GSList *slist; - GList *node; - - slist = NULL; - for (node = list; node != NULL; node = node->next) - { - slist = g_slist_prepend (slist, node->data); - } - return g_slist_reverse (slist); -} - -/* Return the operating system name: Linux, Solaris, etc. */ -char * -eel_get_operating_system_name (void) -{ - struct utsname buffer; - - if (uname (&buffer) != -1) - { - /* Check for special sysnames for which there is - * more accepted names. - */ - if (eel_str_is_equal (buffer.sysname, "SunOS")) - { - return g_strdup ("Solaris"); - } - - return g_strdup (buffer.sysname); - } - - return g_strdup ("Unix"); -} - -int -eel_compare_integer (gconstpointer a, - gconstpointer b) -{ - int int_a; - int int_b; - - int_a = GPOINTER_TO_INT (a); - int_b = GPOINTER_TO_INT (b); - - if (int_a == int_b) - { - return 0; - } - - return int_a < int_b ? -1 : 1; -} - /** * eel_g_object_list_ref * @@ -831,31 +705,6 @@ eel_g_object_list_ref (GList *list) } /** - * eel_g_object_list_unref - * - * Unref all the objects in a list. - * @list: GList of objects. - **/ -void -eel_g_object_list_unref (GList *list) -{ - g_list_foreach (list, (GFunc) g_object_unref, NULL); -} - -/** - * eel_g_object_list_free - * - * Free a list of objects after unrefing them. - * @list: GList of objects. - **/ -void -eel_g_object_list_free (GList *list) -{ - eel_g_object_list_unref (list); - g_list_free (list); -} - -/** * eel_g_object_list_copy * * Copy the list of objects, ref'ing each one. @@ -926,104 +775,6 @@ eel_remove_weak_pointer (gpointer pointer_location) *object_location = NULL; } -/* Get the filename encoding, returns TRUE if utf8 */ - -typedef struct _EelFilenameCharsetCache EelFilenameCharsetCache; - -struct _EelFilenameCharsetCache -{ - gboolean is_utf8; - gchar *charset; - gchar *filename_charset; -}; - -static void -filename_charset_cache_free (gpointer data) -{ - EelFilenameCharsetCache *cache = data; - g_free (cache->charset); - g_free (cache->filename_charset); - g_free (cache); -} - -/* - * eel_get_filename_charset: - * @charset: return location for the name of the filename encoding - * - * Determines the character set used for filenames by consulting the - * environment variables G_FILENAME_ENCODING and G_BROKEN_FILENAMES. - * - * G_FILENAME_ENCODING may be set to a comma-separated list of character - * set names. The special token "@locale" is taken to mean the character set - * for the current locale. The first character set from the list is taken - * as the filename encoding. - * If G_FILENAME_ENCODING is not set, but G_BROKEN_FILENAMES is, the - * character set of the current locale is taken as the filename encoding. - * - * The returned @charset belongs to Eel and must not be freed. - * - * Return value: %TRUE if the charset used for filename is UTF-8. - */ -gboolean -eel_get_filename_charset (const gchar **filename_charset) -{ - static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT; - EelFilenameCharsetCache *cache = g_static_private_get (&cache_private); - const gchar *charset; - - if (!cache) - { - cache = g_new0 (EelFilenameCharsetCache, 1); - g_static_private_set (&cache_private, cache, filename_charset_cache_free); - } - - g_get_charset (&charset); - - if (!(cache->charset && strcmp (cache->charset, charset) == 0)) - { - const gchar *new_charset; - gchar *p, *q; - - g_free (cache->charset); - g_free (cache->filename_charset); - cache->charset = g_strdup (charset); - - p = getenv ("G_FILENAME_ENCODING"); - if (p != NULL) - { - q = strchr (p, ','); - if (!q) - q = p + strlen (p); - - if (strncmp ("@locale", p, q - p) == 0) - { - cache->is_utf8 = g_get_charset (&new_charset); - cache->filename_charset = g_strdup (new_charset); - } - else - { - cache->filename_charset = g_strndup (p, q - p); - cache->is_utf8 = (strcmp (cache->filename_charset, "UTF-8") == 0); - } - } - else if (getenv ("G_BROKEN_FILENAMES") != NULL) - { - cache->is_utf8 = g_get_charset (&new_charset); - cache->filename_charset = g_strdup (new_charset); - } - else - { - cache->filename_charset = g_strdup ("UTF-8"); - cache->is_utf8 = TRUE; - } - } - - if (filename_charset) - *filename_charset = cache->filename_charset; - - return cache->is_utf8; -} - static void update_auto_boolean (GSettings *settings, const gchar *key, @@ -1283,11 +1034,16 @@ eel_self_check_glib_extensions (void) EEL_CHECK_BOOLEAN_RESULT (eel_g_str_list_equal (compare_list_1, compare_list_4), FALSE); EEL_CHECK_BOOLEAN_RESULT (eel_g_str_list_equal (compare_list_1, compare_list_5), FALSE); - eel_g_list_free_deep (compare_list_1); - eel_g_list_free_deep (compare_list_2); - eel_g_list_free_deep (compare_list_3); - eel_g_list_free_deep (compare_list_4); - eel_g_list_free_deep (compare_list_5); + g_list_foreach (compare_list_1, (GFunc) g_free, NULL); + g_list_free(compare_list_1); + g_list_foreach (compare_list_2, (GFunc) g_free, NULL); + g_list_free(compare_list_2); + g_list_foreach (compare_list_3, (GFunc) g_free, NULL); + g_list_free(compare_list_3); + g_list_foreach (compare_list_4, (GFunc) g_free, NULL); + g_list_free(compare_list_4); + g_list_foreach (compare_list_5, (GFunc) g_free, NULL); + g_list_free(compare_list_5); /* eel_g_list_partition */ @@ -1340,27 +1096,6 @@ eel_self_check_glib_extensions (void) setlocale (LC_TIME, ""); g_free (huge_string); - - /* eel_shell_quote */ - EEL_CHECK_STRING_RESULT (g_shell_quote (""), "''"); - EEL_CHECK_STRING_RESULT (g_shell_quote ("a"), "'a'"); - EEL_CHECK_STRING_RESULT (g_shell_quote ("("), "'('"); - EEL_CHECK_STRING_RESULT (g_shell_quote ("'"), "''\\'''"); - EEL_CHECK_STRING_RESULT (g_shell_quote ("'a"), "''\\''a'"); - EEL_CHECK_STRING_RESULT (g_shell_quote ("a'"), "'a'\\'''"); - EEL_CHECK_STRING_RESULT (g_shell_quote ("a'a"), "'a'\\''a'"); - - /* eel_compare_integer */ - EEL_CHECK_INTEGER_RESULT (eel_compare_integer (GINT_TO_POINTER (0), GINT_TO_POINTER (0)), 0); - EEL_CHECK_INTEGER_RESULT (eel_compare_integer (GINT_TO_POINTER (0), GINT_TO_POINTER (1)), -1); - EEL_CHECK_INTEGER_RESULT (eel_compare_integer (GINT_TO_POINTER (1), GINT_TO_POINTER (0)), 1); - EEL_CHECK_INTEGER_RESULT (eel_compare_integer (GINT_TO_POINTER (-1), GINT_TO_POINTER (0)), -1); - EEL_CHECK_INTEGER_RESULT (eel_compare_integer (GINT_TO_POINTER (0), GINT_TO_POINTER (-1)), 1); - EEL_CHECK_INTEGER_RESULT (eel_compare_integer (GINT_TO_POINTER (-1), GINT_TO_POINTER (-1)), 0); - -#ifdef __linux__ - EEL_CHECK_STRING_RESULT (eel_get_operating_system_name (), "Linux"); -#endif } #endif /* !EEL_OMIT_SELF_CHECK */ diff --git a/eel/eel-glib-extensions.h b/eel/eel-glib-extensions.h index 1093e319..907a1ec9 100644 --- a/eel/eel-glib-extensions.h +++ b/eel/eel-glib-extensions.h @@ -33,13 +33,6 @@ /* A gboolean variant for bit fields. */ typedef guint eel_boolean_bit; -/* Callback functions that have user data. */ -typedef int (* EelCompareFunction) (gconstpointer a, - gconstpointer b, - gpointer callback_data); -typedef int (* EelSearchFunction) (gconstpointer item, - gpointer callback_data); - /* Predicate. */ typedef gboolean (* EelPredicateFunction) (gpointer data, gpointer callback_data); @@ -61,22 +54,6 @@ GList * eel_g_list_partition (GList * gpointer user_data, GList **removed); -/* List functions for lists of g_free'able objects. */ -void eel_g_list_free_deep (GList *list); -void eel_g_list_free_deep_custom (GList *list, - GFunc element_free_func, - gpointer user_data); - -/* GSList functions. */ -GList * eel_g_list_from_g_slist (GSList *list); -GSList * eel_g_slist_from_g_list (GList *list); - -/* List functions for slists of g_free'able objects. */ -void eel_g_slist_free_deep (GSList *list); -void eel_g_slist_free_deep_custom (GSList *list, - GFunc element_free_func, - gpointer user_data); - /* List functions for lists of C strings. */ gboolean eel_g_str_list_equal (GList *str_list_a, GList *str_list_b); @@ -87,8 +64,6 @@ int eel_g_str_list_index (GList * /* List functions for lists of objects */ GList * eel_g_object_list_ref (GList *list); -void eel_g_object_list_unref (GList *list); -void eel_g_object_list_free (GList *list); GList * eel_g_object_list_copy (GList *list); /* GHashTable functions */ @@ -111,20 +86,10 @@ gint64 eel_get_system_time (void); /* math */ int eel_round (double d); -/* A GCompareFunc for integers */ -int eel_compare_integer (gconstpointer a, - gconstpointer b); - -/* Return the operating system name: Linux, Solaris, etc. */ -char * eel_get_operating_system_name (void); - /* Better weak pointer functions */ void eel_add_weak_pointer (gpointer pointer_location); void eel_remove_weak_pointer (gpointer pointer_location); -/* Get the filename encoding, returns TRUE if utf8 */ -gboolean eel_get_filename_charset (const gchar **filename_charset); - void eel_g_settings_add_auto_enum (GSettings *settings, const char *key, int *storage); diff --git a/eel/eel-graphic-effects.c b/eel/eel-graphic-effects.c index b234b914..ffb5beba 100644 --- a/eel/eel-graphic-effects.c +++ b/eel/eel-graphic-effects.c @@ -47,22 +47,6 @@ create_new_pixbuf (GdkPixbuf *src) gdk_pixbuf_get_height (src)); } -static GdkPixbuf * -create_new_pixbuf_with_alpha (GdkPixbuf *src) -{ - g_assert (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB); - g_assert ((!gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 3) - || (gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 4)); - - return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src), - TRUE, - gdk_pixbuf_get_bits_per_sample (src), - gdk_pixbuf_get_width (src), - gdk_pixbuf_get_height (src)); -} - /* utility routine to bump the level of a color component with pinning */ static guchar @@ -351,71 +335,3 @@ eel_embed_image_in_frame (GdkPixbuf *source_image, GdkPixbuf *frame_image, int l return result_pixbuf; } - -/* this routine takes the source pixbuf and returns a new one that's semi-transparent, by - clearing every other pixel's alpha value in a checkerboard grip. We have to do the - checkerboard instead of reducing the alpha since it will be turned into an alpha-less - gdkpixmap and mask for the actual dragging */ - -GdkPixbuf * -eel_make_semi_transparent (GdkPixbuf *src) -{ - gint i, j, temp_alpha; - gint width, height, has_alpha, src_row_stride, dst_row_stride; - guchar *target_pixels, *original_pixels; - guchar *pixsrc, *pixdest; - guchar alpha_value; - GdkPixbuf *dest_pixbuf; - guchar start_alpha_value; - - g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL); - g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 3) - || (gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 4), NULL); - g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL); - - dest_pixbuf = create_new_pixbuf_with_alpha (src); - - has_alpha = gdk_pixbuf_get_has_alpha (src); - width = gdk_pixbuf_get_width (src); - height = gdk_pixbuf_get_height (src); - src_row_stride = gdk_pixbuf_get_rowstride (src); - dst_row_stride = gdk_pixbuf_get_rowstride (dest_pixbuf); - - /* set up pointers to the actual pixels */ - target_pixels = gdk_pixbuf_get_pixels (dest_pixbuf); - original_pixels = gdk_pixbuf_get_pixels (src); - - /* loop through the pixels to do the actual work, copying from the source to the destination */ - start_alpha_value = ~0; - for (i = 0; i < height; i++) - { - pixdest = target_pixels + i * dst_row_stride; - pixsrc = original_pixels + i * src_row_stride; - alpha_value = start_alpha_value; - for (j = 0; j < width; j++) - { - *pixdest++ = *pixsrc++; /* red */ - *pixdest++ = *pixsrc++; /* green */ - *pixdest++ = *pixsrc++; /* blue */ - - if (has_alpha) - { - temp_alpha = *pixsrc++; - } - else - { - temp_alpha = ~0; - } - *pixdest++ = temp_alpha & alpha_value; - - alpha_value = ~alpha_value; - } - - start_alpha_value = ~start_alpha_value; - } - - return dest_pixbuf; -} - diff --git a/eel/eel-graphic-effects.h b/eel/eel-graphic-effects.h index 7ac627f1..6ae00421 100644 --- a/eel/eel-graphic-effects.h +++ b/eel/eel-graphic-effects.h @@ -59,8 +59,4 @@ GdkPixbuf *eel_embed_image_in_frame (GdkPixbuf *source_image, int right_offset, int bottom_offset); -/* return a semi-transparent pixbuf from the source pixbuf using a checkboard - stipple in the alpha channel (so it can be converted to an alpha-less pixmap) */ -GdkPixbuf *eel_make_semi_transparent (GdkPixbuf *source_pixbuf); - #endif /* EEL_GRAPHIC_EFFECTS_H */ diff --git a/eel/eel-gtk-extensions.c b/eel/eel-gtk-extensions.c index 94c4987d..5b8121b6 100644 --- a/eel/eel-gtk-extensions.c +++ b/eel/eel-gtk-extensions.c @@ -32,17 +32,17 @@ #include "eel-gdk-pixbuf-extensions.h" #include "eel-glib-extensions.h" #include "eel-mate-extensions.h" -#include "eel-pango-extensions.h" +#include "eel-marshal.h" #include "eel-string.h" + #include <X11/Xlib.h> #include <X11/Xatom.h> #include <gdk/gdk.h> #include <gdk/gdkprivate.h> #include <gdk/gdkx.h> #include <gtk/gtk.h> +#include <glib/gi18n-lib.h> #include <math.h> -#include "eel-marshal.h" -#include "eel-marshal.c" /* This number is fairly arbitrary. Long enough to show a pretty long * menu title, but not so long to make a menu grotesquely wide. @@ -84,103 +84,6 @@ eel_gtk_window_get_geometry_string (GtkWindow *window) } static void -send_delete_event (GtkWindow *window) -{ - /* Synthesize delete_event to close window. */ - - GdkEvent event; - GtkWidget *widget; - - widget = GTK_WIDGET (window); - - event.any.type = GDK_DELETE; - event.any.window = gtk_widget_get_window (widget); - event.any.send_event = TRUE; - - g_object_ref (event.any.window); - gtk_main_do_event (&event); - g_object_unref (event.any.window); -} - -static int -handle_standard_close_accelerator (GtkWindow *window, - GdkEventKey *event, - gpointer user_data) -{ - g_assert (GTK_IS_WINDOW (window)); - g_assert (event != NULL); - g_assert (user_data == NULL); - - if (eel_gtk_window_event_is_close_accelerator (window, event)) - { - send_delete_event (window); - g_signal_stop_emission_by_name ( - G_OBJECT (window), "key_press_event"); - return TRUE; - } - - return FALSE; -} - -/** - * eel_gtk_window_event_is_close_accelerator: - * - * Tests whether a key event is a standard window close accelerator. - * Not needed for clients that use eel_gtk_window_set_up_close_accelerator; - * use only if you must set up your own key_event handler for your own reasons. - **/ -gboolean -eel_gtk_window_event_is_close_accelerator (GtkWindow *window, GdkEventKey *event) -{ - g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (event->state & GDK_CONTROL_MASK) - { - /* Note: menu item equivalents are case-sensitive, so we will - * be case-sensitive here too. - */ - if (event->keyval == EEL_STANDARD_CLOSE_WINDOW_CONTROL_KEY) - { - return TRUE; - } - } - - - return FALSE; -} - -/** - * eel_gtk_window_set_up_close_accelerator: - * - * Sets up the standard keyboard equivalent to close the window. - * Call this for windows that don't set up a keyboard equivalent to - * close the window some other way, e.g. via a menu item accelerator. - * - * NOTE: do not use for GtkDialog, it already sets up the right - * stuff here. - * - * @window: The GtkWindow that should be hidden when the standard - * keyboard equivalent is typed. - **/ -void -eel_gtk_window_set_up_close_accelerator (GtkWindow *window) -{ - g_return_if_fail (GTK_IS_WINDOW (window)); - - if (GTK_IS_DIALOG (window)) - { - g_warning ("eel_gtk_window_set_up_close_accelerator: Should not mess with close accelerator on GtkDialogs"); - return; - } - - g_signal_connect (window, - "key_press_event", - G_CALLBACK (handle_standard_close_accelerator), - NULL); -} - -static void sanity_check_window_position (int *left, int *top) { g_assert (left != NULL); @@ -430,30 +333,6 @@ eel_gtk_menu_insert_separator (GtkMenu *menu, int index) return GTK_MENU_ITEM (menu_item); } -void -eel_gtk_menu_set_item_visibility (GtkMenu *menu, int index, gboolean visible) -{ - GList *children; - GtkWidget *menu_item; - - g_return_if_fail (GTK_IS_MENU (menu)); - - children = gtk_container_get_children (GTK_CONTAINER (menu)); - g_return_if_fail (index >= 0 && index < (int) g_list_length (children)); - - menu_item = GTK_WIDGET (g_list_nth_data (children, index)); - if (visible) - { - gtk_widget_show (menu_item); - } - else - { - gtk_widget_hide (menu_item); - } - - g_list_free (children); -} - GtkWidget * eel_gtk_menu_tool_button_get_button (GtkMenuToolButton *tool_button) { @@ -474,296 +353,6 @@ eel_gtk_menu_tool_button_get_button (GtkMenuToolButton *tool_button) return button; } -gboolean -eel_point_in_allocation (const GtkAllocation *allocation, - int x, int y) -{ - g_return_val_if_fail (allocation != NULL, FALSE); - return x >= allocation->x - && y >= allocation->y - && x < allocation->x + allocation->width - && y < allocation->y + allocation->height; -} - -/* FIXME this function is dangerous, because gtk_widget_get_window (widget) coords (or - * other window-belonging-to-widget coords) do not need to be in the - * same coordinate system as widget->allocation. - * If you use this function, be aware of that. Someone should probably - * audit all uses, too. - */ -gboolean -eel_point_in_widget (GtkWidget *widget, - int x, int y) -{ - GtkAllocation allocation; - if (widget == NULL) - { - return FALSE; - } - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - gtk_widget_get_allocation (widget, &allocation); - return eel_point_in_allocation (&allocation, x, y); -} - -/** - * eel_gtk_widget_set_shown - * - * Show or hide a widget. - * @widget: The widget. - * @shown: Boolean value indicating whether the widget should be shown or hidden. - **/ -void -eel_gtk_widget_set_shown (GtkWidget *widget, gboolean shown) -{ - g_return_if_fail (GTK_IS_WIDGET (widget)); - - if (shown) - { - gtk_widget_show (widget); - } - else - { - gtk_widget_hide (widget); - } -} - -/* This stuff is stolen from Gtk. */ - -typedef struct DisconnectInfo -{ - GtkObject *object1; - guint disconnect_handler1; - guint signal_handler; - GtkObject *object2; - guint disconnect_handler2; -} DisconnectInfo; - -static void -alive_disconnecter (GtkObject *object, DisconnectInfo *info) -{ - g_assert (info != NULL); - g_assert (GTK_IS_OBJECT (info->object1)); - g_assert (info->disconnect_handler1 != 0); - g_assert (info->signal_handler != 0); - g_assert (GTK_IS_OBJECT (info->object2)); - g_assert (info->disconnect_handler2 != 0); - g_assert (object == info->object1 || object == info->object2); - - g_signal_handler_disconnect (info->object1, info->disconnect_handler1); - g_signal_handler_disconnect (info->object1, info->signal_handler); - g_signal_handler_disconnect (info->object2, info->disconnect_handler2); - - g_free (info); -} - -/** - * eel_gtk_signal_connect_full_while_alive - * - * Like gtk_signal_connect_while_alive, but works with full parameters. - **/ -void -eel_gtk_signal_connect_full_while_alive (GtkObject *object, - const gchar *name, - GCallback func, - GtkCallbackMarshal marshal, - gpointer data, - GDestroyNotify destroy_func, - gboolean object_signal, - gboolean after, - GtkObject *alive_object) -{ - DisconnectInfo *info; - - g_return_if_fail (GTK_IS_OBJECT (object)); - g_return_if_fail (name != NULL); - g_return_if_fail (func != NULL || marshal != NULL); - g_return_if_fail (object_signal == FALSE || object_signal == TRUE); - g_return_if_fail (after == FALSE || after == TRUE); - g_return_if_fail (GTK_IS_OBJECT (alive_object)); - - info = g_new (DisconnectInfo, 1); - info->object1 = object; - info->object2 = alive_object; - - - info->signal_handler = g_signal_connect_closure ( - object, name, - (object_signal - ? g_cclosure_new_swap - : g_cclosure_new) (func, data, (GClosureNotify) destroy_func), - after); - - info->disconnect_handler1 = g_signal_connect (G_OBJECT (object), - "destroy", - G_CALLBACK (alive_disconnecter), - info); - info->disconnect_handler2 = g_signal_connect (G_OBJECT (alive_object), - "destroy", - G_CALLBACK (alive_disconnecter), - info); -} - -typedef struct -{ - GtkObject *object; - guint object_destroy_handler; - - GtkWidget *realized_widget; - guint realized_widget_destroy_handler; - guint realized_widget_unrealized_handler; - - guint signal_handler; -} RealizeDisconnectInfo; - -static void -while_realized_disconnecter (GtkObject *object, - RealizeDisconnectInfo *info) -{ - g_assert (GTK_IS_OBJECT (object)); - g_assert (info != NULL); - g_assert (GTK_IS_OBJECT (info->object)); - g_assert (info->object_destroy_handler != 0); - g_assert (info->object_destroy_handler != 0); - g_assert (info->realized_widget_destroy_handler != 0); - g_assert (info->realized_widget_unrealized_handler != 0); - - g_signal_handler_disconnect (info->object, info->object_destroy_handler); - g_signal_handler_disconnect (info->object, info->signal_handler); - g_signal_handler_disconnect (info->realized_widget, info->realized_widget_destroy_handler); - g_signal_handler_disconnect (info->realized_widget, info->realized_widget_unrealized_handler); - g_free (info); -} - -/** - * eel_gtk_signal_connect_while_realized: - * - * @object: Object to connect to. - * @name: Name of signal to connect to. - * @callback: Caller's callback. - * @callback_data: Caller's callback_data. - * @realized_widget: Widget to monitor for realized state. Signal is connected - * while this wigget is realized. - * - * Connect to a signal of an object while another widget is realized. This is - * useful for non windowed widgets that need to monitor events in their ancestored - * windowed widget. The signal is automatically disconnected when &widget is - * unrealized. Also, the signal is automatically disconnected when either &object - * or &widget are destroyed. - **/ -void -eel_gtk_signal_connect_while_realized (GtkObject *object, - const char *name, - GCallback callback, - gpointer callback_data, - GtkWidget *realized_widget) -{ - RealizeDisconnectInfo *info; - - g_return_if_fail (GTK_IS_OBJECT (object)); - g_return_if_fail (name != NULL); - g_return_if_fail (name[0] != '\0'); - g_return_if_fail (callback != NULL); - g_return_if_fail (GTK_IS_WIDGET (realized_widget)); - g_return_if_fail (gtk_widget_get_realized (realized_widget)); - - info = g_new0 (RealizeDisconnectInfo, 1); - - info->object = object; - info->object_destroy_handler = - g_signal_connect (G_OBJECT (info->object), - "destroy", - G_CALLBACK (while_realized_disconnecter), - info); - - info->realized_widget = realized_widget; - info->realized_widget_destroy_handler = - g_signal_connect (G_OBJECT (info->realized_widget), - "destroy", - G_CALLBACK (while_realized_disconnecter), - info); - info->realized_widget_unrealized_handler = - g_signal_connect_after (G_OBJECT (info->realized_widget), - "unrealize", - G_CALLBACK (while_realized_disconnecter), - info); - - info->signal_handler = g_signal_connect (G_OBJECT (info->object), - name, callback, callback_data); -} - -/** - * eel_gtk_container_get_first_child. - * - * Returns the first child of a container. - * @container: The container. - **/ - -static void -get_first_callback (GtkWidget *widget, gpointer callback_data) -{ - GtkWidget **first_child_slot; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (callback_data != NULL); - - first_child_slot = callback_data; - - if (*first_child_slot == NULL) - { - *first_child_slot = widget; - /* We'd stop the iterating now if we could. */ - } - else - { - g_assert (GTK_IS_WIDGET (*first_child_slot)); - } -} - -GtkWidget * -eel_gtk_container_get_first_child (GtkContainer *container) -{ - GtkWidget *first_child; - - g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL); - - first_child = NULL; - gtk_container_foreach (container, get_first_callback, &first_child); - g_assert (first_child == NULL || GTK_IS_WIDGET (first_child)); - return first_child; -} - -typedef struct -{ - GtkCallback callback; - gpointer callback_data; -} container_foreach_deep_callback_data; - -static void -container_foreach_deep_callback (GtkWidget *child, gpointer data) -{ - container_foreach_deep_callback_data *deep_data; - - deep_data = (container_foreach_deep_callback_data *) data; - - deep_data->callback (child, deep_data->callback_data); - - if (GTK_IS_CONTAINER (child)) - { - gtk_container_foreach (GTK_CONTAINER (child), container_foreach_deep_callback, data); - } -} - -void -eel_gtk_container_foreach_deep (GtkContainer *container, - GtkCallback callback, - gpointer callback_data) -{ - container_foreach_deep_callback_data deep_data; - deep_data.callback = callback; - deep_data.callback_data = callback_data; - gtk_container_foreach (container, container_foreach_deep_callback, &deep_data); -} - /* The standard gtk_adjustment_set_value ignores page size, which * disagrees with the logic used by scroll bars, for example. */ @@ -822,276 +411,6 @@ eel_gtk_label_make_bold (GtkLabel *label) pango_font_description_free (font_desc); } -/** - * eel_gtk_label_set_scale: - * @label: - * @num_steps: - * - * Function is broken, see eel_gtk_label_make_larger() for explanation - * - **/ -void -eel_gtk_label_set_scale (GtkLabel *label, - double scale_factor) -{ - PangoAttrList *old_attr_list; - PangoAttrList *attr_list; - - g_return_if_fail (GTK_IS_LABEL (label)); - g_return_if_fail (scale_factor > 0); - - old_attr_list = gtk_label_get_attributes (label); - attr_list = eel_pango_attr_list_apply_global_attribute (old_attr_list, - pango_attr_scale_new (scale_factor)); - gtk_label_set_attributes (label, attr_list); - pango_attr_list_unref (attr_list); -} - -static void -get_layout_location (GtkLabel *label, - gint *xp, - gint *yp) -{ - GtkMisc *misc; - GtkWidget *widget; - float xalign, yalign; - int x, y, xpad, ypad; - int shadow_offset; - GtkAllocation allocation; - GtkRequisition req; - - shadow_offset = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), - "eel-label-shadow-offset")); - - misc = GTK_MISC (label); - widget = GTK_WIDGET (label); - gtk_misc_get_alignment (misc, &xalign, &yalign); - gtk_misc_get_padding (misc, &xpad, &ypad); - - if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) - xalign = 1.0 - xalign; - - gtk_widget_get_allocation (widget, &allocation); - gtk_widget_get_requisition (widget, &req); - x = floor (allocation.x + xpad - + ((allocation.width - req.width - shadow_offset) * xalign) - + 0.5); - - y = floor (allocation.y + ypad - + ((allocation.height - req.height - shadow_offset) * yalign) - + 0.5); - - - if (xp) - *xp = x; - - if (yp) - *yp = y; -} - -static gboolean -eel_gtk_label_expose_event (GtkLabel *label, GdkEventExpose *event, gpointer user_data) -{ - int x, y; - GdkColor color; - GtkWidget *widget; - GdkGC *gc; - guint32 shadow_color; - int shadow_offset; - - shadow_color = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), - "eel-label-shadow-color")); - shadow_offset = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), - "eel-label-shadow-offset")); - - color = eel_gdk_rgb_to_color (shadow_color); - - get_layout_location (label, &x, &y); - - widget = GTK_WIDGET (label); - if (shadow_offset > 0) - { - gc = gdk_gc_new (gtk_widget_get_window (widget)); - gdk_gc_set_rgb_fg_color (gc, &color); - gdk_gc_set_clip_rectangle (gc, &event->area); - - gdk_draw_layout (gtk_widget_get_window (widget), - gc, - x + shadow_offset, y + shadow_offset, - gtk_label_get_layout (label)); - g_object_unref (gc); - } - - gtk_paint_layout (gtk_widget_get_style (widget), - gtk_widget_get_window (widget), - gtk_widget_get_state (widget), - FALSE, - &event->area, - widget, - "label", - x, y, - gtk_label_get_layout (label)); - - return TRUE; -} - -static void -eel_gtk_label_size_request (GtkLabel *label, GtkRequisition *requisition, gpointer user_data) -{ - gint shadow_offset; - - shadow_offset = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), - "eel-label-shadow-offset")); - - requisition->width += shadow_offset; - requisition->height += shadow_offset; -} - -static void -set_up_label (GtkLabel *label) -{ - - if (g_object_get_data (G_OBJECT (label), "eel-label-set-up") != NULL) - { - return; - } - - g_signal_connect (label, "expose_event", - G_CALLBACK (eel_gtk_label_expose_event), NULL); - g_signal_connect_after (label, "size_request", - G_CALLBACK (eel_gtk_label_size_request), NULL); - - g_object_set_data (G_OBJECT (label), "eel-label-set-up", "eel-label-set-up"); -} - -void -eel_gtk_label_set_drop_shadow_color (GtkLabel *label, - guint32 color) -{ - set_up_label (label); - - g_object_set_data (G_OBJECT (label), "eel-label-shadow-color", - GINT_TO_POINTER (color)); - - gtk_widget_queue_draw (GTK_WIDGET (label)); -} - -void -eel_gtk_label_set_drop_shadow_offset (GtkLabel *label, - gint offset) -{ - set_up_label (label); - - g_object_set_data (G_OBJECT (label), "eel-label-shadow-offset", - GINT_TO_POINTER (offset)); - - gtk_widget_queue_draw (GTK_WIDGET (label)); -} - -void -eel_gtk_widget_set_background_color (GtkWidget *widget, - const char *color_spec) -{ - GdkColor color; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - eel_gdk_color_parse_with_white_default (color_spec, &color); - - gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color); - gtk_widget_modify_base (widget, GTK_STATE_NORMAL, &color); - gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &color); - gtk_widget_modify_base (widget, GTK_STATE_ACTIVE, &color); -} - -void -eel_gtk_widget_set_foreground_color (GtkWidget *widget, - const char *color_spec) -{ - GdkColor color; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - eel_gdk_color_parse_with_white_default (color_spec, &color); - - gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, &color); - gtk_widget_modify_text (widget, GTK_STATE_NORMAL, &color); - gtk_widget_modify_fg (widget, GTK_STATE_ACTIVE, &color); - gtk_widget_modify_text (widget, GTK_STATE_ACTIVE, &color); -} - -GtkWidget * -eel_gtk_widget_find_windowed_ancestor (GtkWidget *widget) -{ - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - while (widget && !gtk_widget_get_has_window (widget)) - { - widget = gtk_widget_get_parent (widget); - } - - return widget; -} - -/* eel_gtk_get_system_font: - * - * Return the system font as selected in the control center. Need to - * g_object_unref() the result when done with it. - * - * Perhaps there is a better way to figure out what that font is, but - * the following is simple enough and it works. - */ -PangoFontDescription * -eel_gtk_get_system_font (void) -{ - GtkWidget *label; - PangoFontDescription *font; - - label = gtk_label_new (""); - - gtk_widget_ensure_style (label); - - font = pango_font_description_copy (gtk_widget_get_style (label)->font_desc); - - g_object_ref_sink (label); - g_object_unref (label); - - return font; -} - -void -eel_gtk_widget_get_button_event_location (GtkWidget *widget, - const GdkEventButton *event, - int *x, - int *y) -{ - int window_x, window_y; - GtkAllocation allocation; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (event != NULL); - - gdk_window_get_position (event->window, &window_x, &window_y); - gtk_widget_get_allocation (widget, &allocation); - if (x != NULL) - { - *x = event->x + window_x - allocation.x; - } - if (y != NULL) - { - *y = event->y + window_y - allocation.y; - } -} - -void -eel_gtk_widget_get_motion_event_location (GtkWidget *widget, - const GdkEventMotion *event, - int *x, - int *y) -{ - eel_gtk_widget_get_button_event_location (widget, (const GdkEventButton *) event, x, y); -} - static gboolean tree_view_button_press_callback (GtkWidget *tree_view, GdkEventButton *event, @@ -1147,101 +466,24 @@ eel_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view, } } -gboolean -eel_gtk_viewport_get_visible_rect (GtkViewport *viewport, - GdkRectangle *rect) -{ - GdkRectangle viewport_rect; - GdkRectangle child_rect; - gboolean return_val; - - g_return_val_if_fail (GTK_IS_VIEWPORT (viewport), FALSE); - g_return_val_if_fail (rect != NULL, FALSE); - - if (gtk_widget_get_realized (GTK_WIDGET (viewport))) - { - viewport_rect.x = 0; - viewport_rect.y = 0; - -#if GTK_CHECK_VERSION(3, 0, 0) - viewport_rect.width = gdk_window_get_width(GDK_WINDOW(gtk_viewport_get_view_window(viewport))); - viewport_rect.height = gdk_window_get_height(GDK_WINDOW(gtk_viewport_get_view_window(viewport))); -#else - gdk_drawable_get_size(gtk_viewport_get_view_window(viewport), &viewport_rect.width, &viewport_rect.height); -#endif - - gdk_window_get_position (gtk_viewport_get_bin_window (viewport), - &child_rect.x, - &child_rect.y); - -#if GTK_CHECK_VERSION(3, 0, 0) - child_rect.width = gdk_window_get_width(GDK_WINDOW(gtk_viewport_get_view_window(viewport))); - child_rect.height = gdk_window_get_height(GDK_WINDOW(gtk_viewport_get_view_window(viewport))); -#else - gdk_drawable_get_size(gtk_viewport_get_bin_window(viewport), &child_rect.width, &child_rect.height); -#endif - - return_val = gdk_rectangle_intersect (&viewport_rect, - &child_rect, - rect); - rect->x -= child_rect.x; - rect->y -= child_rect.y; - - return return_val; - } - - rect->x = rect->y = rect->width = rect->height = 0; - return FALSE; -} - void -eel_gtk_viewport_scroll_to_rect (GtkViewport *viewport, - GdkRectangle *rect) +eel_gtk_message_dialog_set_details_label (GtkMessageDialog *dialog, + const gchar *details_text) { - GdkRectangle visible_rect; - int scroll_x; - int scroll_y; - GtkAdjustment *adjustment; + GtkWidget *content_area, *expander, *label; - g_return_if_fail (GTK_IS_VIEWPORT (viewport)); - g_return_if_fail (rect != NULL); + content_area = gtk_message_dialog_get_message_area (dialog); + expander = gtk_expander_new_with_mnemonic (_("Show more _details")); + gtk_expander_set_spacing (GTK_EXPANDER (expander), 6); - if (eel_gtk_viewport_get_visible_rect (viewport, &visible_rect)) - { - scroll_x = -1; - scroll_y = -1; + label = gtk_label_new (details_text); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_selectable (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - if (rect->x + rect->width > visible_rect.x + visible_rect.width) - { - scroll_x = rect->x - (visible_rect.width - rect->width); - } - if (rect->y + rect->height > visible_rect.y + visible_rect.height) - { - scroll_y = rect->y - (visible_rect.height - rect->height); - } + gtk_container_add (GTK_CONTAINER (expander), label); + gtk_box_pack_start (GTK_BOX (content_area), expander, FALSE, FALSE, 0); - if (rect->x < visible_rect.x) - { - scroll_x = rect->x; - } - - if (rect->y < visible_rect.y) - { - scroll_y = rect->y; - } - - adjustment = gtk_viewport_get_hadjustment (viewport); - if (adjustment && scroll_x != -1) - { - eel_gtk_adjustment_set_value (adjustment, - (double)scroll_x); - } - - adjustment = gtk_viewport_get_vadjustment (viewport); - if (adjustment && scroll_y != -1) - { - eel_gtk_adjustment_set_value (adjustment, - (double)scroll_y); - } - } + gtk_widget_show (label); + gtk_widget_show (expander); } diff --git a/eel/eel-gtk-extensions.h b/eel/eel-gtk-extensions.h index e286bf74..a5d8e60a 100644 --- a/eel/eel-gtk-extensions.h +++ b/eel/eel-gtk-extensions.h @@ -35,51 +35,6 @@ #define EEL_DEFAULT_POPUP_MENU_DISPLACEMENT 2 #define EEL_STANDARD_CLOSE_WINDOW_CONTROL_KEY 'w' -/* signals */ -void eel_gtk_signal_connect_full_while_alive (GtkObject *object, - const gchar *name, - GCallback func, - GtkCallbackMarshal marshal, - gpointer data, - GDestroyNotify destroy_func, - gboolean object_signal, - gboolean after, - GtkObject *alive_object); -void eel_gtk_signal_connect_while_realized (GtkObject *object, - const char *name, - GCallback callback, - gpointer callback_data, - GtkWidget *realized_widget); - -/* GtkWidget */ -void eel_gtk_widget_set_shown (GtkWidget *widget, - gboolean shown); -gboolean eel_point_in_allocation (const GtkAllocation *allocation, - int x, - int y); -gboolean eel_point_in_widget (GtkWidget *widget, - int x, - int y); -void eel_gtk_widget_set_background_color (GtkWidget *widget, - const char *color_spec); -void eel_gtk_widget_set_foreground_color (GtkWidget *widget, - const char *color_spec); -GtkWidget * eel_gtk_widget_find_windowed_ancestor (GtkWidget *widget); -PangoFontDescription *eel_gtk_get_system_font (void); -void eel_gtk_widget_get_button_event_location (GtkWidget *widget, - const GdkEventButton *event, - int *x, - int *y); -void eel_gtk_widget_get_motion_event_location (GtkWidget *widget, - const GdkEventMotion *event, - int *x, - int *y); - -/* GtkContainer */ -GtkWidget * eel_gtk_container_get_first_child (GtkContainer *container); -void eel_gtk_container_foreach_deep (GtkContainer *container, - GtkCallback callback, - gpointer callback_data); /* GtkWindow */ void eel_gtk_window_set_initial_geometry (GtkWindow *window, @@ -93,9 +48,6 @@ void eel_gtk_window_set_initial_geometry_from_string (GtkWindow guint minimum_width, guint minimum_height, gboolean ignore_position); -void eel_gtk_window_set_up_close_accelerator (GtkWindow *window); -gboolean eel_gtk_window_event_is_close_accelerator (GtkWindow *window, - GdkEventKey *event); char * eel_gtk_window_get_geometry_string (GtkWindow *window); @@ -107,21 +59,12 @@ void eel_pop_up_context_menu (GtkMenu GtkMenuItem * eel_gtk_menu_append_separator (GtkMenu *menu); GtkMenuItem * eel_gtk_menu_insert_separator (GtkMenu *menu, int index); -void eel_gtk_menu_set_item_visibility (GtkMenu *menu, - int index, - gboolean visible); /* GtkMenuToolButton */ GtkWidget * eel_gtk_menu_tool_button_get_button (GtkMenuToolButton *tool_button); /* GtkLabel */ void eel_gtk_label_make_bold (GtkLabel *label); -void eel_gtk_label_set_scale (GtkLabel *label, - double scale_factor); -void eel_gtk_label_set_drop_shadow_color (GtkLabel *label, - guint32 color); -void eel_gtk_label_set_drop_shadow_offset (GtkLabel *label, - gint offset); /* GtkAdjustment */ void eel_gtk_adjustment_set_value (GtkAdjustment *adjustment, float value); @@ -131,11 +74,8 @@ void eel_gtk_adjustment_clamp_value (GtkAdjust void eel_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view, gboolean should_activate); -/* GtkViewport */ -gboolean eel_gtk_viewport_get_visible_rect (GtkViewport *viewport, - GdkRectangle *rect); - -void eel_gtk_viewport_scroll_to_rect (GtkViewport *viewport, - GdkRectangle *rect); +/* GtkMessageDialog */ +void eel_gtk_message_dialog_set_details_label (GtkMessageDialog *dialog, + const gchar *details_text); #endif /* EEL_GTK_EXTENSIONS_H */ diff --git a/eel/eel-i18n.c b/eel/eel-i18n.c deleted file mode 100644 index 9e7ef29b..00000000 --- a/eel/eel-i18n.c +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* eel-i18n.c: I18n stuff for Eel. - - Copyright (C) 2002 MandrakeSoft. - - The Mate Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Mate Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Mate Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - - Authors: Frederic Crozat <[email protected]> -*/ - -#include <config.h> -#include <glib.h> - -#include "eel-i18n.h" - -#ifdef ENABLE_NLS - -#include <libintl.h> - -const char* _eel_gettext(const char* str) -{ - static gboolean _eel_gettext_initialized = FALSE; - - if (!_eel_gettext_initialized) - { - bindtextdomain(GETTEXT_PACKAGE, MATELOCALEDIR); - -#ifdef HAVE_BIND_TEXTDOMAIN_CODESET - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); -#endif - - _eel_gettext_initialized = TRUE; - } - - return dgettext(GETTEXT_PACKAGE, str); -} - -#endif /* ENABLE_NLS */ diff --git a/eel/eel-i18n.h b/eel/eel-i18n.h deleted file mode 100644 index 68b71f11..00000000 --- a/eel/eel-i18n.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* eel-i18n.h: I18n stuff for Eel. - - Copyright (C) 2002 MandrakeSoft - - The Mate Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Mate Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Mate Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - - Authors: Frederic Crozat <[email protected]> -*/ - -#ifndef EEL_I18N_H -#define EEL_I18N_H - -#ifdef ENABLE_NLS - -#include <glib.h> - - -const char* _eel_gettext(const char* str) G_GNUC_FORMAT(1); - -#include <libintl.h> -#define _(String) _eel_gettext(String) - -#ifdef gettext_noop -#define N_(String) gettext_noop(String) -#else -#define N_(String) (String) -#endif - -#else /* NLS is disabled */ -#define _(String) (String) -#define N_(String) (String) -#define textdomain(String) (String) -#define gettext(String) (String) -#define dgettext(Domain,String) (String) -#define dcgettext(Domain,String,Type) (String) -#define bindtextdomain(Domain,Directory) (Domain) -#endif - - -#endif /* EEL_I18N_H */ diff --git a/eel/eel-image-table.c b/eel/eel-image-table.c index 8f87660b..205fc70a 100644 --- a/eel/eel-image-table.c +++ b/eel/eel-image-table.c @@ -29,7 +29,6 @@ #include "eel-art-gtk-extensions.h" #include "eel-debug-drawing.h" #include "eel-gtk-extensions.h" -#include "eel-gtk-macros.h" #include "eel-labeled-image.h" #include "eel-marshal.h" #include <gtk/gtk.h> @@ -46,7 +45,6 @@ struct EelImageTableDetails { GtkWidget *child_under_pointer; GtkWidget *child_being_pressed; - GdkGC *clear_gc; }; /* Signals */ @@ -63,31 +61,17 @@ typedef enum /* Signals */ static guint image_table_signals[LAST_SIGNAL] = { 0 }; -static void eel_image_table_class_init (EelImageTableClass *image_table_class); -static void eel_image_table_init (EelImageTable *image); - -/* GObjectClass methods */ -static void eel_image_table_finalize (GObject *object); - -/* GtkWidgetClass methods */ -static void eel_image_table_realize (GtkWidget *widget); -static void eel_image_table_unrealize (GtkWidget *widget); - -/* GtkContainerClass methods */ -static void eel_image_table_remove (GtkContainer *container, - GtkWidget *widget); -static GType eel_image_table_child_type (GtkContainer *container); - -/* Private EelImageTable methods */ -static void image_table_emit_signal (EelImageTable *image_table, - GtkWidget *child, - guint signal_index, - int x, - int y, - int button, - guint state, - GdkEvent *event); - +/* Ancestor methods */ +GtkWidget * find_windowed_ancestor (GtkWidget *widget); +#if GTK_CHECK_VERSION (3, 0, 0) +static void signal_connect_while_realized (GtkWidget *object, +#else +static void signal_connect_while_realized (GtkObject *object, +#endif + const char *name, + GCallback callback, + gpointer callback_data, + GtkWidget *realized_widget); /* Ancestor callbacks */ static int ancestor_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event, @@ -105,85 +89,16 @@ static int ancestor_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer event_data); -EEL_CLASS_BOILERPLATE (EelImageTable, eel_image_table, EEL_TYPE_WRAP_TABLE) - -static void -eel_image_table_class_init (EelImageTableClass *image_table_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (image_table_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (image_table_class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (image_table_class); - - /* GObjectClass */ - object_class->finalize = eel_image_table_finalize; - - /* GtkWidgetClass */ - widget_class->realize = eel_image_table_realize; - widget_class->unrealize = eel_image_table_unrealize; - - /* GtkContainerClass */ - container_class->remove = eel_image_table_remove; - container_class->child_type = eel_image_table_child_type; - - /* Signals */ - image_table_signals[CHILD_ENTER] = g_signal_new ("child_enter", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EelImageTableClass, child_enter), - NULL, NULL, - eel_marshal_VOID__OBJECT_POINTER, - G_TYPE_NONE, - 2, - GTK_TYPE_WIDGET, - G_TYPE_POINTER); - image_table_signals[CHILD_LEAVE] = g_signal_new ("child_leave", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EelImageTableClass, child_leave), - NULL, NULL, - eel_marshal_VOID__OBJECT_POINTER, - G_TYPE_NONE, - 2, - GTK_TYPE_WIDGET, - G_TYPE_POINTER); - image_table_signals[CHILD_PRESSED] = g_signal_new ("child_pressed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EelImageTableClass, child_pressed), - NULL, NULL, - eel_marshal_VOID__OBJECT_POINTER, - G_TYPE_NONE, - 2, - GTK_TYPE_WIDGET, - G_TYPE_POINTER); - image_table_signals[CHILD_RELEASED] = g_signal_new ("child_released", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EelImageTableClass, child_released), - NULL, NULL, - eel_marshal_VOID__OBJECT_POINTER, - G_TYPE_NONE, - 2, - GTK_TYPE_WIDGET, - G_TYPE_POINTER); - image_table_signals[CHILD_CLICKED] = g_signal_new ("child_clicked", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EelImageTableClass, child_clicked), - NULL, NULL, - eel_marshal_VOID__OBJECT_POINTER, - G_TYPE_NONE, - 2, - GTK_TYPE_WIDGET, - G_TYPE_POINTER); -} +G_DEFINE_TYPE (EelImageTable, eel_image_table, EEL_TYPE_WRAP_TABLE) static void eel_image_table_init (EelImageTable *image_table) { gtk_widget_set_has_window (GTK_WIDGET (image_table), FALSE); - image_table->details = g_new0 (EelImageTableDetails, 1); + image_table->details = G_TYPE_INSTANCE_GET_PRIVATE (image_table, + EEL_TYPE_IMAGE_TABLE, + EelImageTableDetails); } /* GObjectClass methods */ @@ -194,9 +109,7 @@ eel_image_table_finalize (GObject *object) image_table = EEL_IMAGE_TABLE (object); - g_free (image_table->details); - - EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); + G_OBJECT_CLASS (eel_image_table_parent_class)->finalize (object); } static void @@ -207,9 +120,9 @@ eel_image_table_realize (GtkWidget *widget) g_assert (EEL_IS_IMAGE_TABLE (widget)); /* Chain realize */ - EEL_CALL_PARENT (GTK_WIDGET_CLASS, realize, (widget)); + GTK_WIDGET_CLASS (eel_image_table_parent_class)->realize (widget); - windowed_ancestor = eel_gtk_widget_find_windowed_ancestor (widget); + windowed_ancestor = find_windowed_ancestor (widget); g_assert (GTK_IS_WIDGET (windowed_ancestor)); gtk_widget_add_events (windowed_ancestor, @@ -220,54 +133,39 @@ eel_image_table_realize (GtkWidget *widget) | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); - eel_gtk_signal_connect_while_realized (GTK_OBJECT (windowed_ancestor), - "enter_notify_event", - G_CALLBACK (ancestor_enter_notify_event), - widget, - widget); - - eel_gtk_signal_connect_while_realized (GTK_OBJECT (windowed_ancestor), - "leave_notify_event", - G_CALLBACK (ancestor_leave_notify_event), - widget, - widget); - - eel_gtk_signal_connect_while_realized (GTK_OBJECT (windowed_ancestor), - "motion_notify_event", - G_CALLBACK (ancestor_motion_notify_event), - widget, - widget); - - eel_gtk_signal_connect_while_realized (GTK_OBJECT (windowed_ancestor), - "button_press_event", - G_CALLBACK (ancestor_button_press_event), - widget, - widget); - - eel_gtk_signal_connect_while_realized (GTK_OBJECT (windowed_ancestor), - "button_release_event", - G_CALLBACK (ancestor_button_release_event), - widget, - widget); -} - -static void -eel_image_table_unrealize (GtkWidget *widget) -{ - EelImageTable *image_table; - - g_assert (EEL_IS_IMAGE_TABLE (widget)); - - image_table = EEL_IMAGE_TABLE (widget); - - if (image_table->details->clear_gc != NULL) - { - g_object_unref (image_table->details->clear_gc); - image_table->details->clear_gc = NULL; - } - - /* Chain unrealize */ - EEL_CALL_PARENT (GTK_WIDGET_CLASS, unrealize, (widget)); +#if !GTK_CHECK_VERSION (3, 0, 0) +#define windowed_ancestor GTK_OBJECT(windowed_ancestor) +#endif + + signal_connect_while_realized (windowed_ancestor, + "enter_notify_event", + G_CALLBACK (ancestor_enter_notify_event), + widget, + widget); + + signal_connect_while_realized (windowed_ancestor, + "leave_notify_event", + G_CALLBACK (ancestor_leave_notify_event), + widget, + widget); + + signal_connect_while_realized (windowed_ancestor, + "motion_notify_event", + G_CALLBACK (ancestor_motion_notify_event), + widget, + widget); + + signal_connect_while_realized (windowed_ancestor, + "button_press_event", + G_CALLBACK (ancestor_button_press_event), + widget, + widget); + + signal_connect_while_realized (windowed_ancestor, + "button_release_event", + G_CALLBACK (ancestor_button_release_event), + widget, + widget); } /* GtkContainerClass methods */ @@ -292,7 +190,7 @@ eel_image_table_remove (GtkContainer *container, image_table->details->child_being_pressed = NULL; } - EEL_CALL_PARENT (GTK_CONTAINER_CLASS, remove, (container, child)); + GTK_CONTAINER_CLASS (eel_image_table_parent_class)->remove (container, child); } static GType @@ -333,6 +231,78 @@ image_table_emit_signal (EelImageTable *image_table, } static void +eel_image_table_class_init (EelImageTableClass *image_table_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (image_table_class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (image_table_class); + GtkContainerClass *container_class = GTK_CONTAINER_CLASS (image_table_class); + + /* GObjectClass */ + object_class->finalize = eel_image_table_finalize; + + /* GtkWidgetClass */ + widget_class->realize = eel_image_table_realize; + + /* GtkContainerClass */ + container_class->remove = eel_image_table_remove; + container_class->child_type = eel_image_table_child_type; + + /* Signals */ + image_table_signals[CHILD_ENTER] = g_signal_new ("child_enter", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EelImageTableClass, child_enter), + NULL, NULL, + eel_marshal_VOID__OBJECT_POINTER, + G_TYPE_NONE, + 2, + GTK_TYPE_WIDGET, + G_TYPE_POINTER); + image_table_signals[CHILD_LEAVE] = g_signal_new ("child_leave", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EelImageTableClass, child_leave), + NULL, NULL, + eel_marshal_VOID__OBJECT_POINTER, + G_TYPE_NONE, + 2, + GTK_TYPE_WIDGET, + G_TYPE_POINTER); + image_table_signals[CHILD_PRESSED] = g_signal_new ("child_pressed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EelImageTableClass, child_pressed), + NULL, NULL, + eel_marshal_VOID__OBJECT_POINTER, + G_TYPE_NONE, + 2, + GTK_TYPE_WIDGET, + G_TYPE_POINTER); + image_table_signals[CHILD_RELEASED] = g_signal_new ("child_released", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EelImageTableClass, child_released), + NULL, NULL, + eel_marshal_VOID__OBJECT_POINTER, + G_TYPE_NONE, + 2, + GTK_TYPE_WIDGET, + G_TYPE_POINTER); + image_table_signals[CHILD_CLICKED] = g_signal_new ("child_clicked", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EelImageTableClass, child_clicked), + NULL, NULL, + eel_marshal_VOID__OBJECT_POINTER, + G_TYPE_NONE, + 2, + GTK_TYPE_WIDGET, + G_TYPE_POINTER); + + g_type_class_add_private (image_table_class, sizeof (EelImageTableDetails)); +} + +static void image_table_handle_motion (EelImageTable *image_table, int x, int y, @@ -401,6 +371,115 @@ image_table_handle_motion (EelImageTable *image_table, } } +GtkWidget * +find_windowed_ancestor (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + + while (widget && !gtk_widget_get_has_window (widget)) + { + widget = gtk_widget_get_parent (widget); + } + + return widget; +} + +typedef struct +{ + GObject *object; + guint object_destroy_handler; + + GtkWidget *realized_widget; + guint realized_widget_destroy_handler; + guint realized_widget_unrealized_handler; + + guint signal_handler; +} RealizeDisconnectInfo; + +static void +while_realized_disconnecter (GObject *object, + RealizeDisconnectInfo *info) +{ + g_assert (G_IS_OBJECT (object)); + g_assert (info != NULL); + g_assert (G_IS_OBJECT (info->object)); + g_assert (info->object_destroy_handler != 0); + g_assert (info->object_destroy_handler != 0); + g_assert (info->realized_widget_destroy_handler != 0); + g_assert (info->realized_widget_unrealized_handler != 0); + + g_signal_handler_disconnect (info->object, info->object_destroy_handler); + g_signal_handler_disconnect (info->object, info->signal_handler); + g_signal_handler_disconnect (info->realized_widget, info->realized_widget_destroy_handler); + g_signal_handler_disconnect (info->realized_widget, info->realized_widget_unrealized_handler); + g_free (info); +} + +/** + * signal_connect_while_realized: + * + * @object: Object to connect to. + * @name: Name of signal to connect to. + * @callback: Caller's callback. + * @callback_data: Caller's callback_data. + * @realized_widget: Widget to monitor for realized state. Signal is connected + * while this wigget is realized. + * + * Connect to a signal of an object while another widget is realized. This is + * useful for non windowed widgets that need to monitor events in their ancestored + * windowed widget. The signal is automatically disconnected when &widget is + * unrealized. Also, the signal is automatically disconnected when either &object + * or &widget are destroyed. + **/ +static void +#if GTK_CHECK_VERSION (3, 0, 0) +signal_connect_while_realized (GtkWidget *object, +#else +signal_connect_while_realized (GtkObject *object, +#endif + const char *name, + GCallback callback, + gpointer callback_data, + GtkWidget *realized_widget) +{ + RealizeDisconnectInfo *info; + +#if GTK_CHECK_VERSION (3, 0, 0) + g_return_if_fail (GTK_IS_WIDGET (object)); +#else + g_return_if_fail (GTK_IS_OBJECT (object)); +#endif + g_return_if_fail (name != NULL); + g_return_if_fail (name[0] != '\0'); + g_return_if_fail (callback != NULL); + g_return_if_fail (GTK_IS_WIDGET (realized_widget)); + g_return_if_fail (gtk_widget_get_realized (realized_widget)); + + info = g_new0 (RealizeDisconnectInfo, 1); + + info->object = object; + info->object_destroy_handler = + g_signal_connect (G_OBJECT (info->object), + "destroy", + G_CALLBACK (while_realized_disconnecter), + info); + + info->realized_widget = realized_widget; + info->realized_widget_destroy_handler = + g_signal_connect (G_OBJECT (info->realized_widget), + "destroy", + G_CALLBACK (while_realized_disconnecter), + info); + info->realized_widget_unrealized_handler = + g_signal_connect_after (G_OBJECT (info->realized_widget), + "unrealize", + G_CALLBACK (while_realized_disconnecter), + info); + + info->signal_handler = g_signal_connect (G_OBJECT (info->object), + name, callback, callback_data); +} + static int ancestor_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event, diff --git a/eel/eel-labeled-image.c b/eel/eel-labeled-image.c index c1e51070..12dad9c1 100644 --- a/eel/eel-labeled-image.c +++ b/eel/eel-labeled-image.c @@ -30,7 +30,6 @@ #include "eel-debug-drawing.h" #include "eel-gtk-container.h" #include "eel-gtk-extensions.h" -#include "eel-gtk-macros.h" #include "eel-accessibility.h" #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> @@ -89,47 +88,9 @@ static GType eel_labeled_image_check_button_get_type (void); static GType eel_labeled_image_radio_button_get_type (void); static GType eel_labeled_image_toggle_button_get_type (void); - -static void eel_labeled_image_class_init (EelLabeledImageClass *labeled_image_class); -static void eel_labeled_image_init (EelLabeledImage *image); -static void eel_labeled_image_finalize (GObject *object); - - - -/* GObjectClass methods */ -static void eel_labeled_image_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void eel_labeled_image_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -/* GtkObjectClass methods */ -static void eel_labeled_image_destroy (GtkObject *object); - /* GtkWidgetClass methods */ -static void eel_labeled_image_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int eel_labeled_image_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void eel_labeled_image_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void eel_labeled_image_map (GtkWidget *widget); -static void eel_labeled_image_unmap (GtkWidget *widget); static AtkObject *eel_labeled_image_get_accessible (GtkWidget *widget); -/* GtkContainerClass methods */ -static void eel_labeled_image_add (GtkContainer *container, - GtkWidget *widget); -static void eel_labeled_image_remove (GtkContainer *container, - GtkWidget *widget); -static void eel_labeled_image_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - /* Private EelLabeledImage methods */ static EelDimensions labeled_image_get_image_dimensions (const EelLabeledImage *labeled_image); static EelDimensions labeled_image_get_label_dimensions (const EelLabeledImage *labeled_image); @@ -143,158 +104,16 @@ static gboolean labeled_image_show_image (const EelLabeledImage static guint labeled_image_signals[LAST_SIGNAL] = { 0 }; -EEL_CLASS_BOILERPLATE (EelLabeledImage, eel_labeled_image, GTK_TYPE_CONTAINER) - -/* Class init methods */ -static void -eel_labeled_image_class_init (EelLabeledImageClass *labeled_image_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (labeled_image_class); - GtkObjectClass *object_class = GTK_OBJECT_CLASS (labeled_image_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (labeled_image_class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (labeled_image_class); - GtkBindingSet *binding_set; - - gobject_class->finalize = eel_labeled_image_finalize; - - /* GObjectClass */ - gobject_class->set_property = eel_labeled_image_set_property; - gobject_class->get_property = eel_labeled_image_get_property; - - /* GtkObjectClass */ - object_class->destroy = eel_labeled_image_destroy; - - /* GtkWidgetClass */ - widget_class->size_request = eel_labeled_image_size_request; - widget_class->size_allocate = eel_labeled_image_size_allocate; - widget_class->expose_event = eel_labeled_image_expose_event; - widget_class->map = eel_labeled_image_map; - widget_class->unmap = eel_labeled_image_unmap; - widget_class->get_accessible = eel_labeled_image_get_accessible; - - /* GtkContainerClass */ - container_class->add = eel_labeled_image_add; - container_class->remove = eel_labeled_image_remove; - container_class->forall = eel_labeled_image_forall; - - labeled_image_signals[ACTIVATE] = - g_signal_new ("activate", - G_TYPE_FROM_CLASS (labeled_image_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EelLabeledImageClass, - activate), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - widget_class->activate_signal = labeled_image_signals[ACTIVATE]; - - binding_set = gtk_binding_set_by_class (gobject_class); - - gtk_binding_entry_add_signal (binding_set, - GDK_Return, 0, - "activate", 0); - gtk_binding_entry_add_signal (binding_set, - GDK_KP_Enter, 0, - "activate", 0); - gtk_binding_entry_add_signal (binding_set, - GDK_space, 0, - "activate", 0); - - - /* Properties */ - g_object_class_install_property ( - gobject_class, - PROP_PIXBUF, - g_param_spec_object ("pixbuf", NULL, NULL, - GDK_TYPE_PIXBUF, G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_LABEL, - g_param_spec_string ("label", NULL, NULL, - "", G_PARAM_READWRITE)); - - - g_object_class_install_property ( - gobject_class, - PROP_LABEL_POSITION, - g_param_spec_enum ("label_position", NULL, NULL, - GTK_TYPE_POSITION_TYPE, - GTK_POS_BOTTOM, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_SHOW_LABEL, - g_param_spec_boolean ("show_label", NULL, NULL, - TRUE, G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_SHOW_IMAGE, - g_param_spec_boolean ("show_image", NULL, NULL, - TRUE, G_PARAM_READWRITE)); - - - g_object_class_install_property ( - gobject_class, - PROP_SPACING, - g_param_spec_uint ("spacing", NULL, NULL, - 0, - G_MAXINT, - DEFAULT_SPACING, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_X_PADDING, - g_param_spec_int ("x_padding", NULL, NULL, - 0, - G_MAXINT, - DEFAULT_X_PADDING, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_Y_PADDING, - g_param_spec_int ("y_padding", NULL, NULL, - 0, - G_MAXINT, - DEFAULT_Y_PADDING, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_X_ALIGNMENT, - g_param_spec_float ("x_alignment", NULL, NULL, - 0.0, - 1.0, - DEFAULT_X_ALIGNMENT, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_Y_ALIGNMENT, - g_param_spec_float ("y_alignment", NULL, NULL, - 0.0, - 1.0, - DEFAULT_Y_ALIGNMENT, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_FILL, - g_param_spec_boolean ("fill", NULL, NULL, - FALSE, - G_PARAM_READWRITE)); -} +G_DEFINE_TYPE (EelLabeledImage, eel_labeled_image, GTK_TYPE_CONTAINER) static void eel_labeled_image_init (EelLabeledImage *labeled_image) { gtk_widget_set_has_window (GTK_WIDGET (labeled_image), FALSE); - labeled_image->details = g_new0 (EelLabeledImageDetails, 1); + labeled_image->details = G_TYPE_INSTANCE_GET_PRIVATE (labeled_image, + EEL_TYPE_LABELED_IMAGE, + EelLabeledImageDetails); labeled_image->details->show_label = TRUE; labeled_image->details->show_image = TRUE; labeled_image->details->label_position = GTK_POS_BOTTOM; @@ -309,20 +128,11 @@ eel_labeled_image_init (EelLabeledImage *labeled_image) } static void -eel_labeled_image_finalize (GObject *object) -{ - EelLabeledImage *labeled_image; - - labeled_image = EEL_LABELED_IMAGE (object); - - g_free (labeled_image->details); - - EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); -} - - -static void +#if GTK_CHECK_VERSION (3, 0, 0) +eel_labeled_image_destroy (GtkWidget *object) +#else eel_labeled_image_destroy (GtkObject *object) +#endif { EelLabeledImage *labeled_image; @@ -338,7 +148,11 @@ eel_labeled_image_destroy (GtkObject *object) gtk_widget_destroy (labeled_image->details->label); } - EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object)); +#if GTK_CHECK_VERSION (3, 0, 0) + GTK_WIDGET_CLASS (eel_labeled_image_parent_class)->destroy (object); +#else + GTK_OBJECT_CLASS (eel_labeled_image_parent_class)->destroy (object); +#endif } /* GObjectClass methods */ @@ -694,6 +508,152 @@ eel_labeled_image_forall (GtkContainer *container, } } +/* Class init methods */ +static void +eel_labeled_image_class_init (EelLabeledImageClass *labeled_image_class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (labeled_image_class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (labeled_image_class); + GtkContainerClass *container_class = GTK_CONTAINER_CLASS (labeled_image_class); + GtkBindingSet *binding_set; + + /* GObjectClass */ + gobject_class->set_property = eel_labeled_image_set_property; + gobject_class->get_property = eel_labeled_image_get_property; + +#if !GTK_CHECK_VERSION (3, 0, 0) + GTK_OBJECT_CLASS (labeled_image_class)->destroy = eel_labeled_image_destroy; +#else + widget_class->destroy = eel_labeled_image_destroy; +#endif + + /* GtkWidgetClass */ + widget_class->size_request = eel_labeled_image_size_request; + widget_class->size_allocate = eel_labeled_image_size_allocate; + widget_class->expose_event = eel_labeled_image_expose_event; + widget_class->map = eel_labeled_image_map; + widget_class->unmap = eel_labeled_image_unmap; + widget_class->get_accessible = eel_labeled_image_get_accessible; + + /* GtkContainerClass */ + container_class->add = eel_labeled_image_add; + container_class->remove = eel_labeled_image_remove; + container_class->forall = eel_labeled_image_forall; + + labeled_image_signals[ACTIVATE] = + g_signal_new ("activate", + G_TYPE_FROM_CLASS (labeled_image_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EelLabeledImageClass, + activate), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + widget_class->activate_signal = labeled_image_signals[ACTIVATE]; + + binding_set = gtk_binding_set_by_class (gobject_class); + + gtk_binding_entry_add_signal (binding_set, + GDK_KEY_Return, 0, + "activate", 0); + gtk_binding_entry_add_signal (binding_set, + GDK_KEY_KP_Enter, 0, + "activate", 0); + gtk_binding_entry_add_signal (binding_set, + GDK_KEY_space, 0, + "activate", 0); + + + /* Properties */ + g_object_class_install_property ( + gobject_class, + PROP_PIXBUF, + g_param_spec_object ("pixbuf", NULL, NULL, + GDK_TYPE_PIXBUF, G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_LABEL, + g_param_spec_string ("label", NULL, NULL, + "", G_PARAM_READWRITE)); + + + g_object_class_install_property ( + gobject_class, + PROP_LABEL_POSITION, + g_param_spec_enum ("label_position", NULL, NULL, + GTK_TYPE_POSITION_TYPE, + GTK_POS_BOTTOM, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_SHOW_LABEL, + g_param_spec_boolean ("show_label", NULL, NULL, + TRUE, G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_SHOW_IMAGE, + g_param_spec_boolean ("show_image", NULL, NULL, + TRUE, G_PARAM_READWRITE)); + + + g_object_class_install_property ( + gobject_class, + PROP_SPACING, + g_param_spec_uint ("spacing", NULL, NULL, + 0, + G_MAXINT, + DEFAULT_SPACING, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_X_PADDING, + g_param_spec_int ("x_padding", NULL, NULL, + 0, + G_MAXINT, + DEFAULT_X_PADDING, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_Y_PADDING, + g_param_spec_int ("y_padding", NULL, NULL, + 0, + G_MAXINT, + DEFAULT_Y_PADDING, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_X_ALIGNMENT, + g_param_spec_float ("x_alignment", NULL, NULL, + 0.0, + 1.0, + DEFAULT_X_ALIGNMENT, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_Y_ALIGNMENT, + g_param_spec_float ("y_alignment", NULL, NULL, + 0.0, + 1.0, + DEFAULT_Y_ALIGNMENT, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + gobject_class, + PROP_FILL, + g_param_spec_boolean ("fill", NULL, NULL, + FALSE, + G_PARAM_READWRITE)); + + g_type_class_add_private (labeled_image_class, sizeof (EelLabeledImageDetails)); +} + /* Private EelLabeledImage methods */ static gboolean is_fixed_height (const EelLabeledImage *labeled_image) @@ -1308,7 +1268,7 @@ labeled_image_show_label (const EelLabeledImage *labeled_image) * be created as neeeded. * * Thus, using this widget in place of EelImage or EelLabel is "free" with - * only the GtkObject and function call overhead. + * only the GtkWidget and function call overhead. * */ GtkWidget* diff --git a/eel/eel-lib-self-check-functions.h b/eel/eel-lib-self-check-functions.h index 6c3e07d1..d14aa99e 100644 --- a/eel/eel-lib-self-check-functions.h +++ b/eel/eel-lib-self-check-functions.h @@ -43,7 +43,6 @@ void eel_run_lib_self_checks (void); macro (eel_self_check_gdk_extensions) \ macro (eel_self_check_gdk_pixbuf_extensions) \ macro (eel_self_check_glib_extensions) \ - macro (eel_self_check_pango_extensions) \ macro (eel_self_check_string) \ /* Add new self-check functions to the list above this line. */ diff --git a/eel/eel-mate-extensions.c b/eel/eel-mate-extensions.c index aca3cddf..2af5a941 100644 --- a/eel/eel-mate-extensions.c +++ b/eel/eel-mate-extensions.c @@ -29,26 +29,10 @@ #define MATE_DESKTOP_USE_UNSTABLE_API #include "eel-mate-extensions.h" -#include "eel-art-extensions.h" -#include "eel-gdk-extensions.h" -#include "eel-glib-extensions.h" -#include "eel-gtk-extensions.h" -#include "eel-stock-dialogs.h" -#include "eel-i18n.h" -#include <X11/Xatom.h> -#include <errno.h> -#include <fcntl.h> -#include <gdk/gdkx.h> + #include <gtk/gtk.h> #include <libmate/mate-desktop-utils.h> -#include <limits.h> -#include <signal.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <unistd.h> + /* Return a command string containing the path to a terminal on this system. */ diff --git a/eel/eel-mate-extensions.h b/eel/eel-mate-extensions.h index cabd4380..cb97e55b 100644 --- a/eel/eel-mate-extensions.h +++ b/eel/eel-mate-extensions.h @@ -29,10 +29,6 @@ #include <gtk/gtk.h> -/* icon selection callback function. */ -typedef void (* EelIconSelectionFunction) (const char *icon_path, gpointer callback_data); - - /* Return a command string containing the path to a terminal on this system. */ char * eel_mate_make_terminal_command (const char *command); diff --git a/eel/eel-pango-extensions.c b/eel/eel-pango-extensions.c deleted file mode 100644 index 68a9b08e..00000000 --- a/eel/eel-pango-extensions.c +++ /dev/null @@ -1,615 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* eel-pango-extensions.h - interface for new functions that conceptually - belong in pango. Perhaps some of these will be - actually rolled into pango someday. - - Copyright (C) 2001 Anders Carlsson - - The Eel Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Eel Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Eel Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - - Authors: Anders Carlsson <[email protected]> -*/ - -#include <config.h> -#include "eel-pango-extensions.h" - -#if !defined (EEL_OMIT_SELF_CHECK) -#include "eel-lib-self-check-functions.h" -#endif - -#include <gtk/gtk.h> -#include <pango/pango.h> -#include <string.h> - -PangoAttrList * -eel_pango_attr_list_copy_or_create (PangoAttrList *attr_list) -{ - if (attr_list != NULL) - { - return pango_attr_list_copy (attr_list); - } - return pango_attr_list_new (); -} - -PangoAttrList * -eel_pango_attr_list_apply_global_attribute (PangoAttrList *attr_list, - PangoAttribute *attr) -{ - PangoAttrList *new_attr_list; - - g_return_val_if_fail (attr != NULL, NULL); - - attr->start_index = 0; - attr->end_index = G_MAXINT; - - new_attr_list = eel_pango_attr_list_copy_or_create (attr_list); - pango_attr_list_change (new_attr_list, attr); - return new_attr_list; -} - -#define ELLIPSIS "..." - -/* Caution: this is an _expensive_ function */ -static int -measure_string_width (const char *string, - PangoLayout *layout) -{ - int width; - - pango_layout_set_text (layout, string, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - - return width; -} - -/* this is also plenty slow */ -static void -compute_character_widths (const char *string, - PangoLayout *layout, - int *char_len_return, - int **widths_return, - int **cuts_return) -{ - int *widths; - int *offsets; - int *cuts; - int char_len; - int byte_len; - const char *p; - int i; - PangoLayoutIter *iter; - PangoLogAttr *attrs; - -#define BEGINS_UTF8_CHAR(x) (((x) & 0xc0) != 0x80) - - char_len = g_utf8_strlen (string, -1); - byte_len = strlen (string); - - widths = g_new (int, char_len); - offsets = g_new (int, byte_len); - - /* Create a translation table from byte index to char offset */ - p = string; - i = 0; - while (*p) - { - int byte_index = p - string; - - if (BEGINS_UTF8_CHAR (*p)) - { - offsets[byte_index] = i; - ++i; - } - else - { - offsets[byte_index] = G_MAXINT; /* segv if we try to use this */ - } - - ++p; - } - - /* Now fill in the widths array */ - pango_layout_set_text (layout, string, -1); - - iter = pango_layout_get_iter (layout); - - do - { - PangoRectangle extents; - int byte_index; - - byte_index = pango_layout_iter_get_index (iter); - - if (byte_index < byte_len) - { - pango_layout_iter_get_char_extents (iter, &extents); - - g_assert (BEGINS_UTF8_CHAR (string[byte_index])); - g_assert (offsets[byte_index] < char_len); - - widths[offsets[byte_index]] = PANGO_PIXELS (extents.width); - } - - } - while (pango_layout_iter_next_char (iter)); - - pango_layout_iter_free (iter); - - g_free (offsets); - - *widths_return = widths; - - /* Now compute character offsets that are legitimate places to - * chop the string - */ - attrs = g_new (PangoLogAttr, char_len + 1); - - pango_get_log_attrs (string, byte_len, -1, - pango_context_get_language ( - pango_layout_get_context (layout)), - attrs, - char_len + 1); - - cuts = g_new (int, char_len); - i = 0; - while (i < char_len) - { - cuts[i] = attrs[i].is_cursor_position; - - ++i; - } - - g_free (attrs); - - *cuts_return = cuts; - - *char_len_return = char_len; -} - - -static char * -eel_string_ellipsize_start (const char *string, PangoLayout *layout, int width) -{ - int resulting_width; - int *cuts; - int *widths; - int char_len; - const char *p; - int truncate_offset; - - /* Zero-length string can't get shorter - catch this here to - * avoid expensive calculations - */ - if (*string == '\0') - return g_strdup (""); - - /* I'm not sure if this short-circuit is a net win; it might be better - * to just dump this, and always do the compute_character_widths() etc. - * down below. - */ - resulting_width = measure_string_width (string, layout); - - if (resulting_width <= width) - { - /* String is already short enough. */ - return g_strdup (string); - } - - /* Remove width of an ellipsis */ - width -= measure_string_width (ELLIPSIS, layout); - - if (width < 0) - { - /* No room even for an ellipsis. */ - return g_strdup (""); - } - - /* Our algorithm involves removing enough chars from the string to bring - * the width to the required small size. However, due to ligatures, - * combining characters, etc., it's not guaranteed that the algorithm - * always works 100%. It's sort of a heuristic thing. It should work - * nearly all the time... but I wouldn't put in - * g_assert (width of resulting string < width). - * - * Hmm, another thing that this breaks with is explicit line breaks - * in "string" - */ - - compute_character_widths (string, layout, &char_len, &widths, &cuts); - - for (truncate_offset = 1; truncate_offset < char_len; truncate_offset++) - { - - resulting_width -= widths[truncate_offset]; - - if (resulting_width <= width && - cuts[truncate_offset]) - { - break; - } - } - - g_free (cuts); - g_free (widths); - - p = g_utf8_offset_to_pointer (string, truncate_offset); - - return g_strconcat (ELLIPSIS, p, NULL); -} - -static char * -eel_string_ellipsize_end (const char *string, PangoLayout *layout, int width) -{ - int resulting_width; - int *cuts; - int *widths; - int char_len; - const char *p; - int truncate_offset; - char *result; - - /* See explanatory comments in ellipsize_start */ - - if (*string == '\0') - return g_strdup (""); - - resulting_width = measure_string_width (string, layout); - - if (resulting_width <= width) - { - return g_strdup (string); - } - - width -= measure_string_width (ELLIPSIS, layout); - - if (width < 0) - { - return g_strdup (""); - } - - compute_character_widths (string, layout, &char_len, &widths, &cuts); - - for (truncate_offset = char_len - 1; truncate_offset > 0; truncate_offset--) - { - resulting_width -= widths[truncate_offset]; - if (resulting_width <= width && - cuts[truncate_offset]) - { - break; - } - } - - g_free (cuts); - g_free (widths); - - p = g_utf8_offset_to_pointer (string, truncate_offset); - - result = g_malloc ((p - string) + strlen (ELLIPSIS) + 1); - memcpy (result, string, (p - string)); - strcpy (result + (p - string), ELLIPSIS); - - return result; -} - -static char * -eel_string_ellipsize_middle (const char *string, PangoLayout *layout, int width) -{ - int resulting_width; - int *cuts; - int *widths; - int char_len; - int starting_fragment_byte_len; - int ending_fragment_byte_index; - int starting_fragment_length; - int ending_fragment_offset; - char *result; - - /* See explanatory comments in ellipsize_start */ - - if (*string == '\0') - return g_strdup (""); - - resulting_width = measure_string_width (string, layout); - - if (resulting_width <= width) - { - return g_strdup (string); - } - - width -= measure_string_width (ELLIPSIS, layout); - - if (width < 0) - { - return g_strdup (""); - } - - compute_character_widths (string, layout, &char_len, &widths, &cuts); - - starting_fragment_length = char_len / 2; - ending_fragment_offset = starting_fragment_length + 1; - - /* Shave off a character at a time from the first and the second half - * until we can fit - */ - resulting_width -= widths[ending_fragment_offset - 1]; - - /* depending on whether the original string length is odd or even, start by - * shaving off the characters from the starting or ending fragment - */ - if (char_len % 2) - { - goto shave_end; - } - - while (starting_fragment_length > 0 || ending_fragment_offset < char_len) - { - if (resulting_width <= width && - cuts[ending_fragment_offset] && - cuts[starting_fragment_length]) - { - break; - } - - if (starting_fragment_length > 0) - { - resulting_width -= widths[starting_fragment_length]; - starting_fragment_length--; - } - -shave_end: - if (resulting_width <= width && - cuts[ending_fragment_offset] && - cuts[starting_fragment_length]) - { - break; - } - - if (ending_fragment_offset < char_len) - { - resulting_width -= widths[ending_fragment_offset]; - ending_fragment_offset++; - } - } - - g_free (cuts); - g_free (widths); - - /* patch the two fragments together with an ellipsis */ - result = g_malloc (strlen (string) + strlen (ELLIPSIS) + 1); /* a bit wasteful, no biggie */ - - starting_fragment_byte_len = g_utf8_offset_to_pointer (string, starting_fragment_length) - string; - ending_fragment_byte_index = g_utf8_offset_to_pointer (string, ending_fragment_offset) - string; - - memcpy (result, string, starting_fragment_byte_len); - strcpy (result + starting_fragment_byte_len, ELLIPSIS); - strcpy (result + starting_fragment_byte_len + strlen (ELLIPSIS), string + ending_fragment_byte_index); - - return result; -} - - -/** - * eel_pango_layout_set_text_ellipsized - * - * @layout: a pango layout - * @string: A a string to be ellipsized. - * @width: Desired maximum width in points. - * @mode: The desired ellipsizing mode. - * - * Truncates a string if required to fit in @width and sets it on the - * layout. Truncation involves removing characters from the start, middle or end - * respectively and replacing them with "...". Algorithm is a bit - * fuzzy, won't work 100%. - * - */ -void -eel_pango_layout_set_text_ellipsized (PangoLayout *layout, - const char *string, - int width, - EelEllipsizeMode mode) -{ - char *s; - - g_return_if_fail (PANGO_IS_LAYOUT (layout)); - g_return_if_fail (string != NULL); - g_return_if_fail (width >= 0); - - switch (mode) - { - case EEL_ELLIPSIZE_START: - s = eel_string_ellipsize_start (string, layout, width); - break; - case EEL_ELLIPSIZE_MIDDLE: - s = eel_string_ellipsize_middle (string, layout, width); - break; - case EEL_ELLIPSIZE_END: - s = eel_string_ellipsize_end (string, layout, width); - break; - default: - g_return_if_reached (); - } - - pango_layout_set_text (layout, s, -1); - - g_free (s); -} - - -int -eel_pango_font_description_get_largest_fitting_font_size (const PangoFontDescription *font_desc, - PangoContext *context, - const char *text, - int available_width, - int minimum_acceptable_font_size, - int maximum_acceptable_font_size) -{ - int i; - int width; - PangoLayout *layout; - PangoFontDescription *font; - - g_return_val_if_fail (text != NULL, 0); - g_return_val_if_fail (text[0] != '\0', 0); - g_return_val_if_fail (available_width > 0, 0); - g_return_val_if_fail (minimum_acceptable_font_size > 0, 0); - g_return_val_if_fail (maximum_acceptable_font_size > 0, 0); - g_return_val_if_fail (maximum_acceptable_font_size > minimum_acceptable_font_size, 0); - - layout = pango_layout_new (context); - pango_layout_set_text (layout, text, -1); - pango_layout_set_font_description (layout, font_desc); - - font = pango_font_description_new (); - - for (i = maximum_acceptable_font_size; i >= minimum_acceptable_font_size; i--) - { - - pango_font_description_set_size (font, i * PANGO_SCALE); - pango_layout_set_font_description (layout, font); - pango_layout_get_pixel_size (layout, &width, NULL); - - if (width <= available_width) - { - pango_font_description_free (font); - g_object_unref (layout); - return i; - } - } - - pango_font_description_free (font); - g_object_unref (layout); - return i; -} - - -#if !defined (EEL_OMIT_SELF_CHECK) - -static PangoContext * -eel_create_bogus_test_pango_context (void) -{ - PangoContext *context; - - context = gdk_pango_context_get (); - pango_context_set_language (context, gtk_get_default_language ()); - - return context; -} - -/* Testing string truncation is tough because we do not know what font/ - * font metrics to expect on a given system. To work around this we use - * a substring of the original, measure it's length using the given font, - * add the length of the "..." string and use that for truncation. - * The result should then be the substring prepended with a "..." - */ -static char * -eel_self_check_ellipsize (const char *string, const char *truncate_to_length_string, EelEllipsizeMode mode) -{ - PangoContext *context; - int truncation_length; - char *result; - PangoLayout *layout; - - context = eel_create_bogus_test_pango_context (); - layout = pango_layout_new (context); - - /* measure the length we want to truncate to */ - truncation_length = measure_string_width (truncate_to_length_string, layout); - - eel_pango_layout_set_text_ellipsized (layout, string, truncation_length, mode); - - result = g_strdup (pango_layout_get_text (layout)); - - g_object_unref (G_OBJECT (context)); - g_object_unref (G_OBJECT (layout)); - - return result; -} - -static char * -eel_self_check_ellipsize_start (const char *string, const char *truncate_to_length_string) -{ - return eel_self_check_ellipsize (string, truncate_to_length_string, EEL_ELLIPSIZE_START); -} - -static char * -eel_self_check_ellipsize_middle (const char *string, const char *truncate_to_length_string) -{ - return eel_self_check_ellipsize (string, truncate_to_length_string, EEL_ELLIPSIZE_MIDDLE); -} - -static char * -eel_self_check_ellipsize_end (const char *string, const char *truncate_to_length_string) -{ - return eel_self_check_ellipsize (string, truncate_to_length_string, EEL_ELLIPSIZE_END); -} - -void -eel_self_check_pango_extensions (void) -{ - PangoContext *context; - - /* used to test ellipsize routines */ - context = eel_create_bogus_test_pango_context (); - - /* Turned off these tests because they are failing for me and I - * want the release to be able to pass "make check". We'll have - * to revisit this at some point. The failures started because - * I changed my default font and enabled Xft support. I presume - * this is simply the "fuzziness" Havoc mentions in his comments - * above. - * - Darin - */ - - if (0) - { - /* eel_string_ellipsize_start */ - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_start ("012345678", "0012345678"), "012345678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_start ("012345678", "012345678"), "012345678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_start ("012345678", "...45678"), "...45678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_start ("012345678", "...5678"), "...5678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_start ("012345678", "...678"), "...678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_start ("012345678", "...78"), "...78"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_start ("012345678", "...8"), "...8"); - - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("012345678", "0123456789"), "012345678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("012345678", "012345678"), "012345678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("012345678", "012...78"), "012...78"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("012345678", "01...78"), "01...78"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("012345678", "01...8"), "01...8"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("012345678", "0...8"), "0...8"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("012345678", "0..."), "0..."); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("0123456789", "0123456789"), "0123456789"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("0123456789", "012...789"), "012...789"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("0123456789", "012...89"), "012...89"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("0123456789", "01...89"), "01...89"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("0123456789", "01...9"), "01...9"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("0123456789", "0...9"), "0...9"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_middle ("0123456789", "0..."), "0..."); - - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_end ("012345678", "0123456789"), "012345678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_end ("012345678", "012345678"), "012345678"); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_end ("012345678", "01234..."), "01234..."); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_end ("012345678", "0123..."), "0123..."); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_end ("012345678", "012..."), "012..."); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_end ("012345678", "01..."), "01..."); - EEL_CHECK_STRING_RESULT (eel_self_check_ellipsize_end ("012345678", "0..."), "0..."); - } - - g_object_unref (context); -} - -#endif /* !EEL_OMIT_SELF_CHECK */ diff --git a/eel/eel-pango-extensions.h b/eel/eel-pango-extensions.h deleted file mode 100644 index 2be3a965..00000000 --- a/eel/eel-pango-extensions.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* eel-pango-extensions.h - interface for new functions that conceptually - belong in pango. Perhaps some of these will be - actually rolled into pango someday. - - Copyright (C) 2001 Anders Carlsson - - The Eel Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Eel Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Eel Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - - Authors: Anders Carlsson <[email protected]> -*/ - -#ifndef EEL_PANGO_EXTENSIONS_H -#define EEL_PANGO_EXTENSIONS_H - -#include <pango/pango.h> - -typedef enum -{ - EEL_ELLIPSIZE_START, - EEL_ELLIPSIZE_MIDDLE, - EEL_ELLIPSIZE_END -} EelEllipsizeMode; - -PangoAttrList *eel_pango_attr_list_copy_or_create (PangoAttrList *attr_list); -PangoAttrList *eel_pango_attr_list_apply_global_attribute (PangoAttrList *attr_list, - PangoAttribute *attr); -int eel_pango_font_description_get_largest_fitting_font_size (const PangoFontDescription *font_desc, - PangoContext *context, - const char *text, - int available_width, - int minimum_acceptable_font_size, - int maximum_acceptable_font_size); - -/* caution: this function is expensive. */ -void eel_pango_layout_set_text_ellipsized (PangoLayout *layout, - const char *string, - int width, - EelEllipsizeMode mode); - -#endif /* EEL_PANGO_EXTENSIONS_H */ diff --git a/eel/eel-stock-dialogs.c b/eel/eel-stock-dialogs.c index c9cadfb3..7f83476e 100644 --- a/eel/eel-stock-dialogs.c +++ b/eel/eel-stock-dialogs.c @@ -25,11 +25,10 @@ #include <config.h> #include "eel-stock-dialogs.h" -#include "eel-alert-dialog.h" #include "eel-glib-extensions.h" -#include "eel-mate-extensions.h" -#include "eel-string.h" -#include "eel-i18n.h" +#include "eel-gtk-extensions.h" + +#include <glib/gi18n-lib.h> #include <gtk/gtk.h> #define TIMED_WAIT_STANDARD_DURATION 2000 @@ -61,7 +60,7 @@ typedef struct static GHashTable *timed_wait_hash_table; -static void timed_wait_dialog_destroy_callback (GtkObject *object, gpointer callback_data); +static void timed_wait_dialog_destroy_callback (GtkWidget *object, gpointer callback_data); static guint timed_wait_hash (gconstpointer value) @@ -87,7 +86,7 @@ timed_wait_hash_equal (gconstpointer value1, gconstpointer value2) } static void -timed_wait_delayed_close_destroy_dialog_callback (GtkObject *object, gpointer callback_data) +timed_wait_delayed_close_destroy_dialog_callback (GtkWidget *object, gpointer callback_data) { g_source_remove (GPOINTER_TO_UINT (callback_data)); } @@ -104,7 +103,7 @@ timed_wait_delayed_close_timeout_callback (gpointer callback_data) G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback), GUINT_TO_POINTER (handler_id)); - gtk_object_destroy (GTK_OBJECT (callback_data)); + gtk_widget_destroy (GTK_WIDGET (callback_data)); return FALSE; } @@ -154,7 +153,7 @@ timed_wait_free (TimedWait *wait) } else { - gtk_object_destroy (GTK_OBJECT (wait->dialog)); + gtk_widget_destroy (GTK_WIDGET (wait->dialog)); } } @@ -163,7 +162,7 @@ timed_wait_free (TimedWait *wait) } static void -timed_wait_dialog_destroy_callback (GtkObject *object, gpointer callback_data) +timed_wait_dialog_destroy_callback (GtkWidget *object, gpointer callback_data) { TimedWait *wait; @@ -203,12 +202,16 @@ timed_wait_callback (gpointer callback_data) /* Put up the timed wait window. */ button = wait->cancel_callback != NULL ? GTK_STOCK_CANCEL : GTK_STOCK_OK; - dialog = GTK_DIALOG (eel_alert_dialog_new (wait->parent_window, - 0, - GTK_MESSAGE_INFO, - GTK_BUTTONS_NONE, - wait->wait_message, - _("You can stop this operation by clicking cancel."))); + dialog = GTK_DIALOG (gtk_message_dialog_new (wait->parent_window, + 0, + GTK_MESSAGE_INFO, + GTK_BUTTONS_NONE, + NULL)); + + g_object_set (dialog, + "text", wait->wait_message, + "secondary-text", _("You can stop this operation by clicking cancel."), + NULL); gtk_dialog_add_button (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); @@ -340,12 +343,16 @@ eel_run_simple_dialog (GtkWidget *parent, gboolean ignore_close_box, } /* Create the dialog. */ - dialog = eel_alert_dialog_new (GTK_WINDOW (chosen_parent), - 0, - message_type, - GTK_BUTTONS_NONE, - primary_text, - secondary_text); + dialog = gtk_message_dialog_new (GTK_WINDOW (chosen_parent), + 0, + message_type, + GTK_BUTTONS_NONE, + NULL); + + g_object_set (dialog, + "text", primary_text, + "secondary-text", secondary_text, + NULL); va_start (button_title_args, secondary_text); response_id = 0; @@ -370,7 +377,7 @@ eel_run_simple_dialog (GtkWidget *parent, gboolean ignore_close_box, gtk_widget_show (GTK_WIDGET (dialog)); result = gtk_dialog_run (GTK_DIALOG (dialog)); } - gtk_object_destroy (GTK_OBJECT (dialog)); + gtk_widget_destroy (dialog); return result; } @@ -384,12 +391,17 @@ create_message_dialog (const char *primary_text, { GtkWidget *dialog; - dialog = eel_alert_dialog_new (parent, - 0, - type, - buttons_type, - primary_text, - secondary_text); + dialog = gtk_message_dialog_new (parent, + 0, + type, + buttons_type, + NULL); + + g_object_set (dialog, + "text", primary_text, + "secondary-text", secondary_text, + NULL); + return GTK_DIALOG (dialog); } @@ -405,14 +417,14 @@ show_message_dialog (const char *primary_text, dialog = create_message_dialog (primary_text, secondary_text, type, buttons_type, parent); - if (details_text != NULL) - { - eel_alert_dialog_set_details_label (EEL_ALERT_DIALOG (dialog), details_text); + if (details_text != NULL) { + eel_gtk_message_dialog_set_details_label (GTK_MESSAGE_DIALOG (dialog), + details_text); } gtk_widget_show (GTK_WIDGET (dialog)); g_signal_connect (dialog, "response", - G_CALLBACK (gtk_object_destroy), NULL); + G_CALLBACK (gtk_widget_destroy), NULL); return dialog; } diff --git a/eel/eel-types.c b/eel/eel-types.c deleted file mode 100644 index 4b5ae176..00000000 --- a/eel/eel-types.c +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* eel-types.h - - - Copyright (C) 2000 Eazel, Inc. - - The Mate Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Mate Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Mate Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - - Authors: Maciej Stachowiak <[email protected]> -*/ - - -#include <config.h> -#include <gtk/gtk.h> - -#define EEL_COMPILATION 1 -#include <eel/eel.h> - -#include "eel-type-builtins-vars.c" -#include "eel-type-builtins-evals.c" - -void -eel_type_init (void) -{ - int i; - GType type_id; - static gboolean initialized = FALSE; - - static struct - { - const gchar *type_name; - GType *type_id; - GType parent; - gconstpointer pointer1; - gpointer pointer2; - } builtin_info[EEL_TYPE_N_BUILTINS] = - { -#include "eel-type-builtins-ids.c" - }; - - if (initialized) - { - return; - } - initialized = TRUE; - - for (i = 0; i < EEL_TYPE_N_BUILTINS; i++) - { - type_id = G_TYPE_INVALID; - - if (builtin_info[i].parent == G_TYPE_ENUM) - { - type_id = g_enum_register_static (builtin_info[i].type_name, - builtin_info[i].pointer1); - } - else if (builtin_info[i].parent == G_TYPE_FLAGS) - { - type_id = g_flags_register_static (builtin_info[i].type_name, - builtin_info[i].pointer1); - } - else - { - g_assert_not_reached (); - } - - g_assert (type_id != G_TYPE_INVALID); - *builtin_info[i].type_id = type_id; - } -} - diff --git a/eel/eel-types.h b/eel/eel-types.h deleted file mode 100644 index ff25087d..00000000 --- a/eel/eel-types.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* eel-types.h - - - Copyright (C) 2000 Eazel, Inc. - - The Mate Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The Mate Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the Mate Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. - - Authors: Maciej Stachowiak <[email protected]> -*/ - -#ifndef EEL_TYPES_H -#define EEL_TYPES_H - -#include <eel/eel-type-builtins.h> - -void eel_type_init (void); - -#endif /* EEL_TYPES_H */ - diff --git a/eel/eel-vfs-extensions.c b/eel/eel-vfs-extensions.c index 27db2a46..9c786965 100644 --- a/eel/eel-vfs-extensions.c +++ b/eel/eel-vfs-extensions.c @@ -27,11 +27,11 @@ */ #include <config.h> -#include "eel-i18n.h" #include "eel-vfs-extensions.h" #include "eel-glib-extensions.h" #include "eel-lib-self-check-functions.h" #include <glib.h> +#include <glib/gi18n-lib.h> #include <gio/gio.h> #include "eel-string.h" @@ -99,34 +99,6 @@ eel_make_valid_utf8 (const char *name) return g_string_free (string, FALSE); } -/** - * eel_format_uri_for_display: - * - * Filter, modify, unescape and change URIs to make them appropriate - * to display to users. The conversion is done such that the roundtrip - * to UTf8 is reversible. - * - * Rules: - * file: URI's without fragments should appear as local paths - * file: URI's with fragments should appear as file: URI's - * All other URI's appear as expected - * - * @uri: a URI - * - * returns a g_malloc'd UTF8 string - **/ -char * -eel_format_uri_for_display (const char *uri) -{ - GFile *file; - char *res; - - file = g_file_new_for_uri (uri); - res = g_file_get_parse_name (file); - g_object_unref (file); - return res; -} - char * eel_filename_strip_extension (const char * filename_with_extension) { diff --git a/eel/eel-vfs-extensions.h b/eel/eel-vfs-extensions.h index a79df1c3..e564ca15 100644 --- a/eel/eel-vfs-extensions.h +++ b/eel/eel-vfs-extensions.h @@ -46,7 +46,6 @@ extern "C" { gboolean eel_uri_is_search(const char* uri); - char* eel_format_uri_for_display(const char* uri); char* eel_make_valid_utf8(const char* name); char* eel_filename_strip_extension(const char* filename); diff --git a/eel/eel-wrap-table.c b/eel/eel-wrap-table.c index f7e8a6ad..42253acd 100644 --- a/eel/eel-wrap-table.c +++ b/eel/eel-wrap-table.c @@ -28,8 +28,6 @@ #include "eel-art-extensions.h" #include "eel-art-gtk-extensions.h" #include "eel-gtk-extensions.h" -#include "eel-gtk-macros.h" -#include "eel-types.h" #include <gtk/gtk.h> /* Arguments */ @@ -57,127 +55,30 @@ struct EelWrapTableDetails guint cols; }; -static void eel_wrap_table_class_init (EelWrapTableClass *wrap_table_class); -static void eel_wrap_table_init (EelWrapTable *wrap); -/* GObjectClass methods */ -static void eel_wrap_table_finalize (GObject *object); -static void eel_wrap_table_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void eel_wrap_table_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); -/* GtkWidgetClass methods */ -static void eel_wrap_table_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static int eel_wrap_table_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void eel_wrap_table_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void eel_wrap_table_map (GtkWidget *widget); -static void eel_wrap_table_unmap (GtkWidget *widget); -static void eel_wrap_table_realize (GtkWidget *widget); - -/* GtkContainerClass methods */ -static void eel_wrap_table_add (GtkContainer *container, - GtkWidget *widget); -static void eel_wrap_table_remove (GtkContainer *container, - GtkWidget *widget); -static void eel_wrap_table_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static GType eel_wrap_table_child_type (GtkContainer *container); - - /* Private EelWrapTable methods */ static EelDimensions wrap_table_irect_max_dimensions (const EelDimensions *one, const EelDimensions *two); static EelDimensions wrap_table_get_max_child_dimensions (const EelWrapTable *wrap_table); static EelDimensions wrap_table_get_content_dimensions (const EelWrapTable *wrap_table); static EelIRect wrap_table_get_content_bounds (const EelWrapTable *wrap_table); +static gboolean wrap_table_child_visible_in (GtkWidget *child, + GtkWidget *scrolled); static gboolean wrap_table_child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data); static void wrap_table_layout (EelWrapTable *wrap_table); -EEL_CLASS_BOILERPLATE (EelWrapTable, eel_wrap_table, GTK_TYPE_CONTAINER) - -/* Class init methods */ -static void -eel_wrap_table_class_init (EelWrapTableClass *wrap_table_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (wrap_table_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (wrap_table_class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (wrap_table_class); - - /* GObjectClass */ - gobject_class->finalize = eel_wrap_table_finalize; - gobject_class->set_property = eel_wrap_table_set_property; - gobject_class->get_property = eel_wrap_table_get_property; - - /* GtkWidgetClass */ - widget_class->size_request = eel_wrap_table_size_request; - widget_class->size_allocate = eel_wrap_table_size_allocate; - widget_class->expose_event = eel_wrap_table_expose_event; - widget_class->map = eel_wrap_table_map; - widget_class->unmap = eel_wrap_table_unmap; - widget_class->realize = eel_wrap_table_realize; - - /* GtkContainerClass */ - container_class->add = eel_wrap_table_add; - container_class->remove = eel_wrap_table_remove; - container_class->forall = eel_wrap_table_forall; - container_class->child_type = eel_wrap_table_child_type; - - /* Register some the enum types we need */ - eel_type_init (); - - /* Arguments */ - g_object_class_install_property - (gobject_class, - PROP_X_SPACING, - g_param_spec_uint ("x_spacing", NULL, NULL, - 0, G_MAXINT, 0, G_PARAM_READWRITE)); - - g_object_class_install_property - (gobject_class, - PROP_Y_SPACING, - g_param_spec_uint ("y_spacing", NULL, NULL, - 0, G_MAXINT, 0, G_PARAM_READWRITE)); - - g_object_class_install_property - (gobject_class, - PROP_X_JUSTIFICATION, - g_param_spec_enum ("x_justification", NULL, NULL, - EEL_TYPE_JUSTIFICATION, - EEL_JUSTIFICATION_BEGINNING, - G_PARAM_READWRITE)); - - g_object_class_install_property - (gobject_class, - PROP_Y_JUSTIFICATION, - g_param_spec_enum ("y_justification", NULL, NULL, - EEL_TYPE_JUSTIFICATION, - EEL_JUSTIFICATION_BEGINNING, - G_PARAM_READWRITE)); - - g_object_class_install_property - (gobject_class, - PROP_HOMOGENEOUS, - g_param_spec_boolean ("homogenous", NULL, NULL, - FALSE, G_PARAM_READWRITE)); -} +G_DEFINE_TYPE (EelWrapTable, eel_wrap_table, GTK_TYPE_CONTAINER) static void eel_wrap_table_init (EelWrapTable *wrap_table) { gtk_widget_set_has_window (GTK_WIDGET (wrap_table), FALSE); - wrap_table->details = g_new0 (EelWrapTableDetails, 1); + wrap_table->details = G_TYPE_INSTANCE_GET_PRIVATE (wrap_table, + EEL_TYPE_WRAP_TABLE, + EelWrapTableDetails); wrap_table->details->x_justification = EEL_JUSTIFICATION_BEGINNING; wrap_table->details->y_justification = EEL_JUSTIFICATION_END; wrap_table->details->cols = 1; @@ -191,9 +92,8 @@ eel_wrap_table_finalize (GObject *object) wrap_table = EEL_WRAP_TABLE (object); g_list_free (wrap_table->details->children); - g_free (wrap_table->details); - EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); + G_OBJECT_CLASS (eel_wrap_table_parent_class)->finalize (object); } /* GObjectClass methods */ @@ -391,7 +291,7 @@ eel_wrap_table_realize (GtkWidget *widget) { g_assert (EEL_IS_WRAP_TABLE (widget)); - GTK_WIDGET_CLASS (parent_class)->realize (widget); + GTK_WIDGET_CLASS (eel_wrap_table_parent_class)->realize (widget); gtk_widget_queue_resize (widget); } @@ -497,6 +397,71 @@ eel_wrap_table_child_type (GtkContainer *container) return GTK_TYPE_WIDGET; } +/* Class init methods */ +static void +eel_wrap_table_class_init (EelWrapTableClass *wrap_table_class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (wrap_table_class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (wrap_table_class); + GtkContainerClass *container_class = GTK_CONTAINER_CLASS (wrap_table_class); + + /* GObjectClass */ + gobject_class->finalize = eel_wrap_table_finalize; + gobject_class->set_property = eel_wrap_table_set_property; + gobject_class->get_property = eel_wrap_table_get_property; + + /* GtkWidgetClass */ + widget_class->size_request = eel_wrap_table_size_request; + widget_class->size_allocate = eel_wrap_table_size_allocate; + widget_class->expose_event = eel_wrap_table_expose_event; + widget_class->map = eel_wrap_table_map; + widget_class->unmap = eel_wrap_table_unmap; + widget_class->realize = eel_wrap_table_realize; + + /* GtkContainerClass */ + container_class->add = eel_wrap_table_add; + container_class->remove = eel_wrap_table_remove; + container_class->forall = eel_wrap_table_forall; + container_class->child_type = eel_wrap_table_child_type; + + /* Arguments */ + g_object_class_install_property + (gobject_class, + PROP_X_SPACING, + g_param_spec_uint ("x_spacing", NULL, NULL, + 0, G_MAXINT, 0, G_PARAM_READWRITE)); + + g_object_class_install_property + (gobject_class, + PROP_Y_SPACING, + g_param_spec_uint ("y_spacing", NULL, NULL, + 0, G_MAXINT, 0, G_PARAM_READWRITE)); + + g_object_class_install_property + (gobject_class, + PROP_X_JUSTIFICATION, + g_param_spec_enum ("x_justification", NULL, NULL, + GTK_TYPE_JUSTIFICATION, + GTK_JUSTIFY_LEFT, + G_PARAM_READWRITE)); + + g_object_class_install_property + (gobject_class, + PROP_Y_JUSTIFICATION, + g_param_spec_enum ("y_justification", NULL, NULL, + GTK_TYPE_JUSTIFICATION, + GTK_JUSTIFY_LEFT, + G_PARAM_READWRITE)); + + g_object_class_install_property + (gobject_class, + PROP_HOMOGENEOUS, + g_param_spec_boolean ("homogenous", NULL, NULL, + FALSE, G_PARAM_READWRITE)); + + g_type_class_add_private (wrap_table_class, sizeof (EelWrapTableDetails)); +} + /* Private EelWrapTable methods */ static int wrap_table_get_num_fitting (int available, @@ -744,23 +709,55 @@ wrap_table_get_content_bounds (const EelWrapTable *wrap_table) return content_bounds; } +/** + * wrap_table_child_visible_in + * + * Get child position relative to parent, then determine whether + * the whole child rectangle is visible in the scrolled window + **/ +static gboolean +wrap_table_child_visible_in (GtkWidget *child, GtkWidget *scrolled) +{ + gint x, y; + GtkAllocation child_alloc, scroll_alloc; + + gtk_widget_translate_coordinates (child, scrolled, 0, 0, &x, &y); + gtk_widget_get_allocation(child, &child_alloc); + gtk_widget_get_allocation(scrolled, &scroll_alloc); + + return (x >= 0 && y >= 0) + && x + child_alloc.width <= scroll_alloc.width + && y + child_alloc.height <= scroll_alloc.height; +} + static gboolean wrap_table_child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data) { - GtkWidget *parent, *pparent; - GtkAllocation allocation; + gint x, y; + GtkWidget *container, *viewport; + GtkAdjustment *hadj, *vadj; + + container = gtk_widget_get_parent (widget); + if (container) + { + viewport = gtk_widget_get_parent (container); + } + g_assert (container && viewport); + g_assert (GTK_IS_VIEWPORT (viewport)); + g_return_val_if_fail (gtk_widget_get_realized (viewport), FALSE); + + if (!wrap_table_child_visible_in (widget, viewport)) + { + hadj = gtk_viewport_get_hadjustment (GTK_VIEWPORT (viewport)); + vadj = gtk_viewport_get_vadjustment (GTK_VIEWPORT (viewport)); - parent = gtk_widget_get_parent (widget); - if (parent) - pparent = gtk_widget_get_parent (parent); - g_assert (parent && pparent); - g_assert (GTK_IS_VIEWPORT (pparent)); + gtk_widget_translate_coordinates (widget, container, 0, 0, &x, &y); - gtk_widget_get_allocation (widget, &allocation); - eel_gtk_viewport_scroll_to_rect (GTK_VIEWPORT (pparent), - &allocation); + gtk_adjustment_set_value (hadj, MIN (x, hadj->upper - hadj->page_size)); + gtk_adjustment_set_value (vadj, MIN (y, vadj->upper - vadj->page_size)); + } return FALSE; } @@ -977,16 +974,12 @@ void eel_wrap_table_set_homogeneous (EelWrapTable *wrap_table, gboolean homogeneous) { - g_return_if_fail (EEL_IS_WRAP_TABLE (wrap_table)); - - if (wrap_table->details->homogeneous == homogeneous) + if (EEL_IS_WRAP_TABLE (wrap_table) && + wrap_table->details->homogeneous != homogeneous) { - return; + wrap_table->details->homogeneous = homogeneous; + gtk_widget_queue_resize (GTK_WIDGET (wrap_table)); } - - wrap_table->details->homogeneous = homogeneous; - - gtk_widget_queue_resize (GTK_WIDGET (wrap_table)); } /** diff --git a/eel/eel-xml-extensions.c b/eel/eel-xml-extensions.c index fe4a91a4..2bcd4477 100644 --- a/eel/eel-xml-extensions.c +++ b/eel/eel-xml-extensions.c @@ -26,8 +26,8 @@ #include "eel-xml-extensions.h" #include "eel-string.h" -#include "eel-i18n.h" #include <glib.h> +#include <glib/gi18n-lib.h> #include <libxml/parser.h> #include <stdlib.h> @@ -38,11 +38,9 @@ #include <eel/eel-gtk-macros.h> #include <eel/eel-image-table.h> #include <eel/eel-labeled-image.h> -#include <eel/eel-pango-extensions.h> #include <eel/eel-self-checks.h> #include <eel/eel-stock-dialogs.h> #include <eel/eel-string.h> -#include <eel/eel-types.h> #include <eel/eel-vfs-extensions.h> #include <eel/eel-wrap-table.h> #include <eel/eel-xml-extensions.h> diff --git a/eel/eelmarshal.list b/eel/eelmarshal.list deleted file mode 100644 index 3974c4b7..00000000 --- a/eel/eelmarshal.list +++ /dev/null @@ -1,13 +0,0 @@ -BOOLEAN:BOOLEAN -BOOLEAN:BOXED -BOOLEAN:POINTER,POINTER -BOOLEAN:VOID -ENUM:INT,INT -INT:INT -INT:POINTER,STRING -STRING:POINTER -STRING:VOID -VOID:ENUM,INT -VOID:ENUM,INT,BOOLEAN -VOID:INT,INT,INT,INT -VOID:OBJECT,POINTER diff --git a/eel/makeenums.pl b/eel/makeenums.pl deleted file mode 100755 index 50402ed2..00000000 --- a/eel/makeenums.pl +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/perl -w - -# This script snarfs the enums from header files and writes them out into -# a .defs file (mate.defs, for example). From there, the sister script -# maketypes.awk converts the defs into a *typebuiltins.h, as well as -# *typebuiltins_vals.c, *typebuiltins_ids.c and *typebuiltins_evals.c. - -# Information about the current enumeration - -my $flags; # Is enumeration a bitmask -my $seenbitshift; # Have we seen bitshift operators? -my $prefix; # Prefix for this enumeration -my $enumname; # Name for this enumeration -my $firstenum = 1; # Is this the first enumeration in file? -my @entries; # [ $name, $val ] for each entry - -sub parse_options { - my $opts = shift; - my @opts; - - for $opt (split /\s*,\s*/, $opts) { - my ($key,$val) = $opt =~ /\s*(\w+)(?:=(\S+))?/; - defined $val or $val = 1; - push @opts, $key, $val; - } - @opts; -} -sub parse_entries { - my $file = shift; - - while (<$file>) { - # Read lines until we have no open comments - while (m@/\* - ([^*]|\*(?!/))*$ - @x) { - my $new; - defined ($new = <$file>) || die "Unmatched comment"; - $_ .= $new; - } - # Now strip comments - s@/\*(?!<) - ([^*]+|\*(?!/))* - \*/@@gx; - - s@\n@ @; - - next if m@^\s*$@; - - # Handle include files - if (/^\#include\s*<([^>]*)>/ ) { - my $file= "../$1"; - open NEWFILE, $file or die "Cannot open include file $file: $!\n"; - - if (parse_entries (\*NEWFILE)) { - return 1; - } else { - next; - } - } - - if (/^\s*\}\s*(\w+)/) { - $enumname = $1; - return 1; - } - - if (m@^\s* - (\w+)\s* # name - (?:=( # value - (?:[^,/]|/(?!\*))* - ))?,?\s* - (?:/\*< # options - (([^*]|\*(?!/))*) - >\*/)? - \s*$ - @x) { - my ($name, $value, $options) = ($1,$2,$3); - - if (!defined $flags && defined $value && $value =~ /<</) { - $seenbitshift = 1; - } - if (defined $options) { - my %options = parse_options($options); - if (!defined $options{skip}) { - push @entries, [ $name, $options{nick} ]; - } - } else { - push @entries, [ $name ]; - } - } else { - print STDERR "Can't understand: $_\n"; - } - } - return 0; -} - - -my $gen_arrays = 0; -my $gen_defs = 0; - -# Parse arguments - -if (@ARGV) { - if ($ARGV[0] eq "arrays") { - shift @ARGV; - $gen_arrays = 1; - } elsif ($ARGV[0] eq "defs") { - shift @ARGV; - $gen_defs = 1; - } else { - $gen_defs = 1; - } - -} - -if ($gen_defs) { - print ";; generated by makeenums.pl ; -*- scheme -*-\n\n"; -} else { - print "/* Generated by makeenums.pl */\n\n"; -} - -ENUMERATION: -while (<>) { - if (eof) { - close (ARGV); # reset line numbering - $firstenum = 1; # Flag to print filename at next enum - } - - if (m@^\s*typedef\s+enum\s* - ({)?\s* - (?:/\*< - (([^*]|\*(?!/))*) - >\*/)? - @x) { - if (defined $2) { - my %options = parse_options($2); - $prefix = $options{prefix}; - $flags = $options{flags}; - } else { - $prefix = undef; - $flags = undef; - } - # Didn't have trailing '{' look on next lines - if (!defined $1) { - while (<>) { - if (s/^\s*\{//) { - last; - } - } - } - - $seenbitshift = 0; - @entries = (); - - # Now parse the entries - parse_entries (\*ARGV); - - # figure out if this was a flags or enums enumeration - - if (!defined $flags) { - $flags = $seenbitshift; - } - - # Autogenerate a prefix - - if (!defined $prefix) { - for (@entries) { - my $name = $_->[0]; - if (defined $prefix) { - my $tmp = ~ ($name ^ $prefix); - ($tmp) = $tmp =~ /(^\xff*)/; - $prefix = $prefix & $tmp; - } else { - $prefix = $name; - } - } - # Trim so that it ends in an underscore - $prefix =~ s/_[^_]*$/_/; - } - - for $entry (@entries) { - my ($name,$nick) = @{$entry}; - if (!defined $nick) { - ($nick = $name) =~ s/^$prefix//; - $nick =~ tr/_/-/; - $nick = lc($nick); - @{$entry} = ($name, $nick); - } - } - - # Spit out the output - - if ($gen_defs) { - if ($firstenum) { - print qq(\n; enumerations from "$ARGV"\n); - $firstenum = 0; - } - - print "\n(define-".($flags ? "flags" : "enum")." $enumname"; - - for (@entries) { - my ($name,$nick) = @{$_}; - print "\n ($nick $name)"; - } - print ")\n"; - - } else { - ($valuename = $enumname) =~ s/([A-Z][a-z])/_$1/g; - $valuename =~ s/([a-z])([A-Z])/$1_$2/g; - $valuename = lc($valuename); - - print "static const GEnumValue $ {valuename}_values[] = {\n"; - for (@entries) { - my ($name,$nick) = @{$_}; - print qq( { $name, "$name", "$nick" },\n); - } - print " { 0, NULL, NULL }\n"; - print "};\n"; - } - } -} diff --git a/eel/maketypes.awk b/eel/maketypes.awk deleted file mode 100755 index 4284eddd..00000000 --- a/eel/maketypes.awk +++ /dev/null @@ -1,155 +0,0 @@ - -BEGIN { - type_name = ""; # GtkEnumType - type_macro = ""; # GTK_TYPE_ENUM_TYPE - type_ident = ""; # _gtk_enum_type - type_counter = 0; - gen_macros = 0; - gen_entries = 0; - gen_vars = 0; - boxed_copy = ""; - boxed_free = ""; - - for (i = 2; i < ARGC; i++) - { - if (ARGV[i] == "macros") - gen_macros = 1; - else if (ARGV[i] == "entries") - gen_entries = 1; - else if (ARGV[i] == "variables") - gen_vars = 1; - ARGV[i] = ""; - } - - if (gen_macros) - { - printf ("/* type macros, generated by maketypes.awk */\n"); - printf ("\n"); - printf ("#ifdef G_OS_WIN32\n"); - printf ("# ifdef EEL_COMPILATION\n"); - printf ("# define EELTYPEBUILTINS_VAR __declspec(dllexport)\n"); - printf ("# else\n"); - printf ("# define EELTYPEBUILTINS_VAR extern __declspec(dllimport)\n"); - printf ("# endif\n"); - printf ("#else\n"); - printf ("# ifdef EEL_COMPILATION\n"); - printf ("# define EELTYPEBUILTINS_VAR\n"); - printf ("# else\n"); - printf ("# define EELTYPEBUILTINS_VAR extern\n"); - printf ("# endif\n"); - printf ("#endif\n"); - printf ("\n"); - } - else if (gen_entries) - printf ("/* type entries, generated by maketypes.awk */\n\n"); - else if (gen_vars) - printf ("/* type variables, generated by maketypes.awk */\n\n"); - else - { - printf ("hm? what do you want me to do?\n") > "/dev/stderr"; - exit 1; - } -} - -function set_type (set_type_1) -{ - type_counter += 1; - type_name = set_type_1; - type_macro = "EEL_TYPE_"; - - tmp = type_name; -# OK, the following is ridiculous, and sed s///g would be far easier - gsub ("[A-Z]", "@&", tmp); - gsub ("[^A-Z]@", "&_", tmp); - gsub ("@", "", tmp); - gsub ("[A-Z][A-Z][A-Z][0-9a-z]", "@&", tmp); - gsub ("@..", "&_", tmp); - gsub ("@", "", tmp); - type_macro = type_macro toupper (tmp); - type_ident = "_" tolower (tmp); - - sub ("^EEL_TYPE_EEL_", "EEL_TYPE_", type_macro); -} - -function generate (generate_what) -{ - if (gen_macros) - { - printf ("EELTYPEBUILTINS_VAR GType %s;\n", type_macro); - } - if (gen_entries) - { - printf (" { \"%s\", &%s,\n", type_name, type_macro); - if (generate_what == "BOXED") - printf (" G_TYPE_%s, %s, %s, },\n", generate_what, boxed_copy, boxed_free); - else - printf (" G_TYPE_%s, %s_values },\n", generate_what, type_ident); - } - if (gen_vars) - { - printf ("EELTYPEBUILTINS_VAR GType %s = 0;\n", type_macro); - } -} - -# skip scheme comments -";" { - sub (";.*", ""); -} - -# parse keywords - -/\(define-enum/ { - if ($2 == "") - printf ("huh? define-enum keyword without arg?\n") > "/dev/stderr"; - else - { - set_type($2); - generate("ENUM"); - } -} - -/\(define-flags/ { - if ($2 == "") - printf ("huh? define-flags keyword without arg?\n") > "/dev/stderr"; - else - { - set_type($2); - generate("FLAGS"); - } -} - -/\(define-boxed/ { - if ($2 == "") - printf ("huh? define-boxed keyword without arg?\n") > "/dev/stderr"; - else - { - boxed_copy = "NULL"; - boxed_free = "NULL"; - set_type($2); - do { - getline; - sub (";.*", "", $0); - } while ($0 ~ /^[ \t]*$/); - tmp_var1 = $1; - if ($0 ~ /\)/) { generate("BOXED"); next; } - do { - getline; - sub (";.*", "", $0); - } while ($0 ~ /^[ \t]*$/); - tmp_var2 = $1; - sub (/\).*/, "", tmp_var2); - if (tmp_var1 ~ /^[_A-Za-z][_A-Za-z0-9]*$/ && - tmp_var2 ~ /^[_A-Za-z][_A-Za-z0-9]*$/) - { - boxed_copy = tmp_var1; - boxed_free = tmp_var2; - # printf ("read boxed funcs: %s %s\n", boxed_copy, boxed_free) > "/dev/stderr"; - } - generate("BOXED"); - } -} - -END { - if (gen_macros) - printf("\n#define\tEEL_TYPE_N_BUILTINS\t(%u)\n", type_counter); -} |