From abd802add388760345c74029be3b036f19f253be Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Sun, 12 Nov 2023 17:36:49 +0800 Subject: [PATCH 1/9] meson: disable all build target for now We disable all build target and enable them when the gtk4 port is considered finished. Signed-off-by: Qiu Wenbo --- help/meson.build | 1 - meson.build | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/help/meson.build b/help/meson.build index 18969cbbf..895ccfceb 100644 --- a/help/meson.build +++ b/help/meson.build @@ -1,4 +1,3 @@ -enable_user_doc = get_option('user_doc') if enable_gtk_doc glib_prefix = glib_dep.get_variable(pkgconfig: 'prefix') gtk_prefix = gtk_dep.get_variable(pkgconfig: 'prefix') diff --git a/meson.build b/meson.build index 662433701..930acab54 100644 --- a/meson.build +++ b/meson.build @@ -206,6 +206,7 @@ endif # *** GObject Introspection *** enable_introspection = get_option('introspection') +enable_user_doc = get_option('user_doc') enable_gtk_doc = get_option('gtk_doc') if enable_introspection dependency('gobject-introspection-1.0', version: '>= 1.0') @@ -430,31 +431,31 @@ mime_types_conf.set('EVINCE_MIME_TYPES', ';'.join(evince_mime_types)) mime_types_conf.set('PACKAGE_ICON_NAME', app_id) subdir('cut-n-paste') -subdir('libdocument') -subdir('backend') -subdir('libview') -subdir('libmisc') -subdir('properties') +#subdir('libdocument') +#subdir('backend') +#subdir('libview') +#subdir('libmisc') +#subdir('properties') # *** Document Viewer *** enable_viewer = get_option('viewer') if enable_viewer - subdir('shell') + #subdir('shell') endif subdir('po') -subdir('help') +#subdir('help') # *** Thumbnailer *** enable_thumbnailer = get_option('thumbnailer') if enable_thumbnailer - subdir('thumbnailer') + #subdir('thumbnailer') endif # Print Previewer enable_previewer = get_option('previewer') if enable_previewer - subdir('previewer') + #subdir('previewer') endif subdir('data') -- GitLab From 7628f58fee59c4078817c4ddcbea813f6bd86e0f Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Tue, 3 Aug 2021 10:04:44 +0800 Subject: [PATCH 2/9] meson: Move to gtk4 related dependecies Signed-off-by: Qiu Wenbo --- libdocument/meson.build | 4 ++-- libview/meson.build | 4 ++-- meson.build | 15 ++++++++------- previewer/meson.build | 2 +- shell/meson.build | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libdocument/meson.build b/libdocument/meson.build index 16e2c9182..5379a88dd 100644 --- a/libdocument/meson.build +++ b/libdocument/meson.build @@ -181,11 +181,11 @@ pkg.generate( # GObject Introspection if enable_introspection incs = [ - 'Gdk-3.0', + 'Gdk-4.0', 'GdkPixbuf-2.0', 'Gio-2.0', 'GLib-2.0', - 'Gtk-3.0', + 'Gtk-4.0', ] libevdocument_gir = gnome.generate_gir( diff --git a/libview/meson.build b/libview/meson.build index da9eb6a0b..53fc3f351 100644 --- a/libview/meson.build +++ b/libview/meson.build @@ -111,12 +111,12 @@ pkg.generate( # GObject Introspection if enable_introspection incs = [ - 'Gdk-3.0', + 'Gdk-4.0', 'GdkPixbuf-2.0', 'Gio-2.0', 'GLib-2.0', 'GObject-2.0', - 'Gtk-3.0', + 'Gtk-4.0', libevdocument_gir[0], ] diff --git a/meson.build b/meson.build index 930acab54..0bed24bd7 100644 --- a/meson.build +++ b/meson.build @@ -137,8 +137,9 @@ po_dir = join_paths(source_root, 'po') top_inc = include_directories('.') glib_req_version = '>= 2.75.0' -gtk_req_version = '>= 3.22.0' -hdy_req_version = '>= 1.5.0' +gtk_req_version = '>= 4.6.0' +libaw_req_version = '>= 1.2.0' +libxml_req_version = '>= 2.5.0' exempi_req_version = '>= 2.0' gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.40.0') @@ -148,9 +149,9 @@ config_h.set_quoted('EXTRA_GDK_PIXBUF_LOADERS_DIR', gio_dep = dependency('gio-2.0', version: glib_req_version) glib_dep = dependency('glib-2.0', version: glib_req_version) gmodule_dep = dependency('gmodule-2.0') -gtk_dep = dependency('gtk+-3.0', version: gtk_req_version) +gtk_dep = dependency('gtk4', version: gtk_req_version) gthread_dep = dependency('gthread-2.0', version: glib_req_version) -hdy_dep = dependency('libhandy-1', version: hdy_req_version) +libaw_dep = dependency('libadwaita-1', version: libaw_req_version) exempi_dep = dependency('exempi-2.0', version: exempi_req_version) m_dep = cc.find_library('m') @@ -167,7 +168,7 @@ if ev_platform == 'gnome' # *** Nautilus property page build *** enable_nautilus = get_option('nautilus') if enable_nautilus - libnautilus_extension_dep = dependency('libnautilus-extension', version: ['>= 3.28.0', '< 42.20']) + libnautilus_extension_dep = dependency('libnautilus-extension-4', version: ['>= 43']) nautilus_extension_dir = libnautilus_extension_dep.get_variable(pkgconfig: 'extensiondir', pkgconfig_define: ['libdir', ev_libdir]) endif @@ -185,7 +186,7 @@ if ev_platform == 'gnome' config_h.set('WITH_KEYRING', enable_keyring) # GKT+ Unix Printing - gtk_unix_print_dep = dependency('gtk+-unix-print-3.0', version: gtk_req_version, required: get_option('gtk_unix_print')) + gtk_unix_print_dep = dependency('gtk4-unix-print', version: gtk_req_version, required: get_option('gtk_unix_print')) enable_gtk_unix_print = gtk_unix_print_dep.found() config_h.set10('GTKUNIXPRINT_ENABLED', enable_gtk_unix_print) @@ -216,7 +217,7 @@ else endif # *** GNOME Desktop (Thumbnail cache) *** -gnome_desktop_dep = dependency('gnome-desktop-3.0', required: get_option('thumbnail_cache')) +gnome_desktop_dep = dependency('gnome-desktop-4', required: get_option('thumbnail_cache')) enable_thumbnail_cache = gdk_pixbuf_dep.found() and gnome_desktop_dep.found() config_h.set('HAVE_LIBGNOME_DESKTOP', enable_thumbnail_cache) diff --git a/previewer/meson.build b/previewer/meson.build index 4d8a8f81d..e0499361f 100644 --- a/previewer/meson.build +++ b/previewer/meson.build @@ -17,7 +17,7 @@ previewer_deps = [ libevdocument_dep, libevmisc_dep, libevview_dep, - hdy_dep + libaw_dep ] if enable_gtk_unix_print diff --git a/shell/meson.build b/shell/meson.build index 6497c8c2c..cc0464d88 100644 --- a/shell/meson.build +++ b/shell/meson.build @@ -43,7 +43,7 @@ evince_sources += gnome.compile_resources( evince_deps = [ gdk_pixbuf_dep, gnome_desktop_dep, - hdy_dep, + libaw_dep, libevmisc_dep, libevdocument_dep, libevview_dep, -- GitLab From a40865f6454b300c332d5c69e8774c813d694a8f Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Wed, 12 Jul 2023 15:27:50 +0800 Subject: [PATCH 3/9] cut-n-paste: Remove libgd The following GTK4 port simply don't use libgd. So we remove it before the actual port. Signed-off-by: Qiu Wenbo --- cut-n-paste/libgd/gd-icon-utils.c | 394 ------------- cut-n-paste/libgd/gd-icon-utils.h | 49 -- cut-n-paste/libgd/gd-two-lines-renderer.c | 643 ---------------------- cut-n-paste/libgd/gd-two-lines-renderer.h | 45 -- cut-n-paste/libgd/meson.build | 22 - cut-n-paste/meson.build | 1 - shell/meson.build | 1 - 7 files changed, 1155 deletions(-) delete mode 100644 cut-n-paste/libgd/gd-icon-utils.c delete mode 100644 cut-n-paste/libgd/gd-icon-utils.h delete mode 100644 cut-n-paste/libgd/gd-two-lines-renderer.c delete mode 100644 cut-n-paste/libgd/gd-two-lines-renderer.h delete mode 100644 cut-n-paste/libgd/meson.build diff --git a/cut-n-paste/libgd/gd-icon-utils.c b/cut-n-paste/libgd/gd-icon-utils.c deleted file mode 100644 index 6c9dd4015..000000000 --- a/cut-n-paste/libgd/gd-icon-utils.c +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Copyright (c) 2011, 2012, 2015, 2016 Red Hat, Inc. - * - * Gnome Documents is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * Gnome Documents is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with Gnome Documents; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#include "gd-icon-utils.h" - -#include -#include -#include - -#define _BG_MIN_SIZE 20 -#define _EMBLEM_MIN_SIZE 8 - -/** - * gd_copy_image_surface: - * @surface: - * - * Returns: (transfer full): - */ -cairo_surface_t * -gd_copy_image_surface (cairo_surface_t *surface) -{ - cairo_surface_t *copy = NULL; - cairo_t *cr; - gdouble scale_x; - gdouble scale_y; - - copy = cairo_surface_create_similar_image (surface, CAIRO_FORMAT_ARGB32, - cairo_image_surface_get_width (surface), - cairo_image_surface_get_height (surface)); - cairo_surface_get_device_scale (surface, &scale_x, &scale_y); - cairo_surface_set_device_scale (copy, scale_x, scale_y); - - cr = cairo_create (copy); - cairo_set_source_surface (cr, surface, 0, 0); - cairo_paint (cr); - cairo_destroy (cr); - - return copy; -} - -/** - * gd_create_surface_with_counter: - * @widget: - * @base: - * @number: - * - * Returns: (transfer full): - */ -cairo_surface_t * -gd_create_surface_with_counter (GtkWidget *widget, cairo_surface_t *base, gint number) -{ - GtkStyleContext *context; - cairo_t *cr, *emblem_cr; - cairo_surface_t *emblem_surface; - cairo_surface_t *surface; - gint height; - gint height_scaled; - gint width; - gint width_scaled; - gint layout_width, layout_height; - gint emblem_size; - gint emblem_size_scaled; - gdouble scale; - gdouble scale_x; - gdouble scale_y; - gchar *str; - PangoLayout *layout; - PangoAttrList *attr_list; - PangoAttribute *attr; - PangoFontDescription *desc; - GdkRGBA color; - - context = gtk_widget_get_style_context (GTK_WIDGET (widget)); - gtk_style_context_save (context); - gtk_style_context_add_class (context, "documents-counter"); - - width_scaled = cairo_image_surface_get_width (base); - height_scaled = cairo_image_surface_get_height (base); - cairo_surface_get_device_scale (base, &scale_x, &scale_y); - - width = width_scaled / (gint) floor (scale_x), - height = height_scaled / (gint) floor (scale_y); - - surface = cairo_surface_create_similar_image (base, CAIRO_FORMAT_ARGB32, - width_scaled, height_scaled); - cairo_surface_set_device_scale (surface, scale_x, scale_y); - - cr = cairo_create (surface); - cairo_set_source_surface (cr, base, 0, 0); - cairo_paint (cr); - - emblem_size_scaled = MIN (width_scaled / 2, height_scaled / 2); - emblem_size = MIN (width / 2, height / 2); - - emblem_surface = cairo_surface_create_similar_image (base, CAIRO_FORMAT_ARGB32, - emblem_size_scaled, emblem_size_scaled); - cairo_surface_set_device_scale (emblem_surface, scale_x, scale_y); - - emblem_cr = cairo_create (emblem_surface); - gtk_render_background (context, emblem_cr, - 0, 0, emblem_size, emblem_size); - - if (number > 99) - number = 99; - if (number < -99) - number = -99; - - str = g_strdup_printf ("%d", number); - layout = gtk_widget_create_pango_layout (GTK_WIDGET (widget), str); - g_free (str); - - pango_layout_get_pixel_size (layout, &layout_width, &layout_height); - - /* scale the layout to be 0.5 of the size still available for drawing */ - scale = (emblem_size * 0.50) / (MAX (layout_width, layout_height)); - attr_list = pango_attr_list_new (); - - attr = pango_attr_scale_new (scale); - pango_attr_list_insert (attr_list, attr); - pango_layout_set_attributes (layout, attr_list); - - gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font", &desc, NULL); - pango_layout_set_font_description (layout, desc); - pango_font_description_free (desc); - - gtk_style_context_get_color (context, 0, &color); - gdk_cairo_set_source_rgba (emblem_cr, &color); - - /* update these values */ - pango_layout_get_pixel_size (layout, &layout_width, &layout_height); - - cairo_move_to (emblem_cr, - emblem_size / 2 - layout_width / 2, - emblem_size / 2 - layout_height / 2); - - pango_cairo_show_layout (emblem_cr, layout); - - g_object_unref (layout); - pango_attr_list_unref (attr_list); - cairo_destroy (emblem_cr); - - cairo_set_source_surface (cr, emblem_surface, - width - emblem_size, height - emblem_size); - cairo_paint (cr); - cairo_destroy (cr); - - cairo_surface_destroy (emblem_surface); - gtk_style_context_restore (context); - - return surface; -} - -/** - * gd_create_symbolic_icon_for_scale: - * @name: - * @base_size: - * @scale: - * - * Returns: (transfer full): - */ -GIcon * -gd_create_symbolic_icon_for_scale (const gchar *name, - gint base_size, - gint scale) -{ - gchar *symbolic_name; - GIcon *icon, *retval = NULL; - cairo_surface_t *icon_surface; - cairo_surface_t *surface; - cairo_t *cr; - GtkStyleContext *style; - GtkWidgetPath *path; - GdkPixbuf *pixbuf; - GtkIconTheme *theme; - GtkIconInfo *info; - gint bg_size; - gint emblem_size; - gint total_size; - gint total_size_scaled; - - total_size = base_size / 2; - total_size_scaled = total_size * scale; - - bg_size = MAX (total_size / 2, _BG_MIN_SIZE); - emblem_size = MAX (bg_size - 8, _EMBLEM_MIN_SIZE); - - surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size_scaled, total_size_scaled); - cairo_surface_set_device_scale (surface, (gdouble) scale, (gdouble) scale); - cr = cairo_create (surface); - - style = gtk_style_context_new (); - - path = gtk_widget_path_new (); - gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW); - gtk_style_context_set_path (style, path); - gtk_widget_path_unref (path); - - gtk_style_context_add_class (style, "documents-icon-bg"); - - gtk_render_background (style, cr, (total_size - bg_size) / 2, (total_size - bg_size) / 2, bg_size, bg_size); - - symbolic_name = g_strconcat (name, "-symbolic", NULL); - icon = g_themed_icon_new_with_default_fallbacks (symbolic_name); - g_free (symbolic_name); - - theme = gtk_icon_theme_get_default(); - info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, emblem_size, scale, - GTK_ICON_LOOKUP_FORCE_SIZE); - g_object_unref (icon); - - if (info == NULL) - goto out; - - pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL); - g_object_unref (info); - - if (pixbuf == NULL) - goto out; - - icon_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL); - g_object_unref (pixbuf); - - gtk_render_icon_surface (style, cr, icon_surface, (total_size - emblem_size) / 2, (total_size - emblem_size) / 2); - cairo_surface_destroy (icon_surface); - - retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size_scaled, total_size_scaled)); - - out: - g_object_unref (style); - cairo_surface_destroy (surface); - cairo_destroy (cr); - - return retval; -} - -/** - * gd_create_symbolic_icon: - * @name: - * @base_size: - * - * Returns: (transfer full): - */ -GIcon * -gd_create_symbolic_icon (const gchar *name, - gint base_size) -{ - return gd_create_symbolic_icon_for_scale (name, base_size, 1); -} - -/** - * gd_embed_surface_in_frame: - * @source_image: - * @frame_image_url: - * @slice_width: - * @border_width: - * - * Returns: (transfer full): - */ -cairo_surface_t * -gd_embed_surface_in_frame (cairo_surface_t *source_image, - const gchar *frame_image_url, - GtkBorder *slice_width, - GtkBorder *border_width) -{ - cairo_surface_t *surface; - cairo_t *cr; - int source_width, source_height; - gchar *css_str; - GtkCssProvider *provider; - GtkStyleContext *context; - GError *error = NULL; - GtkWidgetPath *path; - gdouble scale_x, scale_y; - - cairo_surface_get_device_scale (source_image, &scale_x, &scale_y); - - source_width = cairo_image_surface_get_width (source_image) / (gint) floor (scale_x), - source_height = cairo_image_surface_get_height (source_image) / (gint) floor (scale_y); - - css_str = g_strdup_printf (".embedded-image { border-image: url(\"%s\") %d %d %d %d / %dpx %dpx %dpx %dpx }", - frame_image_url, - slice_width->top, slice_width->right, slice_width->bottom, slice_width->left, - border_width->top, border_width->right, border_width->bottom, border_width->left); - provider = gtk_css_provider_new (); - gtk_css_provider_load_from_data (provider, css_str, -1, &error); - - if (error != NULL) - { - g_warning ("Unable to create the thumbnail frame image: %s", error->message); - g_error_free (error); - g_free (css_str); - - return g_object_ref (source_image); - } - - surface = cairo_surface_create_similar (source_image, - CAIRO_CONTENT_COLOR_ALPHA, - source_width, source_height); - cr = cairo_create (surface); - - context = gtk_style_context_new (); - path = gtk_widget_path_new (); - gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW); - - gtk_style_context_set_path (context, path); - gtk_style_context_add_provider (context, - GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - - cairo_save (cr); - cairo_rectangle (cr, - border_width->left, - border_width->top, - source_width - border_width->left - border_width->right, - source_height - border_width->top - border_width->bottom); - cairo_clip (cr); - gtk_render_icon_surface (context, cr, - source_image, - 0, 0); - cairo_restore (cr); - - gtk_style_context_save (context); - gtk_style_context_add_class (context, "embedded-image"); - - gtk_render_frame (context, cr, - 0, 0, - source_width, source_height); - - gtk_style_context_restore (context); - cairo_destroy (cr); - - gtk_widget_path_unref (path); - g_object_unref (provider); - g_object_unref (context); - g_free (css_str); - - return surface; -} - -/** - * gd_embed_image_in_frame: - * @source_image: - * @frame_image_url: - * @slice_width: - * @border_width: - * - * Returns: (transfer full): - */ -GdkPixbuf * -gd_embed_image_in_frame (GdkPixbuf *source_image, - const gchar *frame_image_url, - GtkBorder *slice_width, - GtkBorder *border_width) -{ - cairo_surface_t *surface, *embedded_surface; - GdkPixbuf *retval; - - surface = gdk_cairo_surface_create_from_pixbuf (source_image, - 0, NULL); - - /* Force the device scale to 1.0, since pixbufs are always in unscaled - * dimensions. - */ - cairo_surface_set_device_scale (surface, 1.0, 1.0); - embedded_surface = gd_embed_surface_in_frame (surface, frame_image_url, - slice_width, border_width); - retval = gdk_pixbuf_get_from_surface (embedded_surface, - 0, 0, - cairo_image_surface_get_width (embedded_surface), - cairo_image_surface_get_height (embedded_surface)); - - cairo_surface_destroy (embedded_surface); - cairo_surface_destroy (surface); - - return retval; -} diff --git a/cut-n-paste/libgd/gd-icon-utils.h b/cut-n-paste/libgd/gd-icon-utils.h deleted file mode 100644 index 12f4f0682..000000000 --- a/cut-n-paste/libgd/gd-icon-utils.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2011, 2012, 2015, 2016 Red Hat, Inc. - * - * Gnome Documents is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * Gnome Documents is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with Gnome Documents; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#ifndef __GD_CREATE_SYMBOLIC_ICON_H__ -#define __GD_CREATE_SYMBOLIC_ICON_H__ - -#include -#include - -cairo_surface_t *gd_copy_image_surface (cairo_surface_t *surface); - -cairo_surface_t *gd_create_surface_with_counter (GtkWidget *widget, - cairo_surface_t *base, - gint number); - -GIcon *gd_create_symbolic_icon (const gchar *name, - gint base_size); -GIcon *gd_create_symbolic_icon_for_scale (const gchar *name, - gint base_size, - gint scale); - -GdkPixbuf *gd_embed_image_in_frame (GdkPixbuf *source_image, - const gchar *frame_image_url, - GtkBorder *slice_width, - GtkBorder *border_width); -cairo_surface_t *gd_embed_surface_in_frame (cairo_surface_t *source_image, - const gchar *frame_image_url, - GtkBorder *slice_width, - GtkBorder *border_width); - -#endif /* __GD_CREATE_SYMBOLIC_ICON_H__ */ diff --git a/cut-n-paste/libgd/gd-two-lines-renderer.c b/cut-n-paste/libgd/gd-two-lines-renderer.c deleted file mode 100644 index 57cb1eca5..000000000 --- a/cut-n-paste/libgd/gd-two-lines-renderer.c +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#include "gd-two-lines-renderer.h" -#include - -#define SUBTITLE_DIM_PERCENTAGE 0.55 -#define SUBTITLE_SIZE_PERCENTAGE 0.82 - -typedef struct _GdTwoLinesRendererPrivate GdTwoLinesRendererPrivate; - -struct _GdTwoLinesRendererPrivate { - gchar *line_two; - gint text_lines; -}; - -enum { - PROP_TEXT_LINES = 1, - PROP_LINE_TWO, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES] = { NULL, }; - -G_DEFINE_TYPE_WITH_PRIVATE (GdTwoLinesRenderer, gd_two_lines_renderer, GTK_TYPE_CELL_RENDERER_TEXT) - -static PangoLayout * -create_layout_with_attrs (GtkWidget *widget, - const GdkRectangle *cell_area, - GdTwoLinesRenderer *self, - PangoEllipsizeMode ellipsize) -{ - PangoLayout *layout; - gint wrap_width, xpad; - PangoWrapMode wrap_mode; - PangoAlignment alignment; - - g_object_get (self, - "wrap-width", &wrap_width, - "wrap-mode", &wrap_mode, - "alignment", &alignment, - "xpad", &xpad, - NULL); - - layout = pango_layout_new (gtk_widget_get_pango_context (widget)); - - pango_layout_set_ellipsize (layout, ellipsize); - pango_layout_set_alignment (layout, alignment); - - if (wrap_width != -1) - { - pango_layout_set_width (layout, wrap_width * PANGO_SCALE); - pango_layout_set_wrap (layout, wrap_mode); - } - else - { - if (cell_area != NULL) - pango_layout_set_width (layout, (cell_area->width - 2 * xpad) * PANGO_SCALE); - else - pango_layout_set_width (layout, -1); - - pango_layout_set_wrap (layout, PANGO_WRAP_CHAR); - } - -#if PANGO_VERSION_CHECK (1, 44, 0) - { - PangoAttrList *attr_list = pango_attr_list_new (); - - pango_attr_list_insert (attr_list, pango_attr_insert_hyphens_new (FALSE)); - pango_layout_set_attributes (layout, attr_list); - - pango_attr_list_unref (attr_list); - } -#endif - - return layout; -} - -static void -apply_subtitle_style_to_layout (GtkStyleContext *context, - PangoLayout *layout, - GtkStateFlags flags) -{ - PangoFontDescription *desc; - PangoAttrList *layout_attr; - PangoAttribute *attr_alpha; - - gtk_style_context_save (context); - gtk_style_context_set_state (context, flags); - gtk_style_context_get (context, gtk_style_context_get_state (context), - "font", &desc, - NULL); - gtk_style_context_restore (context); - - /* Set the font size */ - pango_font_description_set_size (desc, pango_font_description_get_size (desc) * SUBTITLE_SIZE_PERCENTAGE); - pango_layout_set_font_description (layout, desc); - pango_font_description_free (desc); - - /* Set the font alpha */ - layout_attr = pango_attr_list_new (); - attr_alpha = pango_attr_foreground_alpha_new (SUBTITLE_DIM_PERCENTAGE * 65535); - pango_attr_list_insert (layout_attr, attr_alpha); - - pango_layout_set_attributes (layout, layout_attr); - pango_attr_list_unref (layout_attr); -} - -static void -gd_two_lines_renderer_prepare_layouts (GdTwoLinesRenderer *self, - const GdkRectangle *cell_area, - GtkWidget *widget, - PangoLayout **layout_one, - PangoLayout **layout_two) -{ - GdTwoLinesRendererPrivate *priv; - PangoLayout *line_one; - PangoLayout *line_two = NULL; - gchar *text = NULL; - - priv = gd_two_lines_renderer_get_instance_private (self); - - g_object_get (self, - "text", &text, - NULL); - - line_one = create_layout_with_attrs (widget, cell_area, - self, PANGO_ELLIPSIZE_MIDDLE); - - if (priv->line_two == NULL || - g_strcmp0 (priv->line_two, "") == 0) - { - pango_layout_set_height (line_one, - (priv->text_lines)); - - if (text != NULL) - pango_layout_set_text (line_one, text, -1); - } - else - { - GtkStyleContext *context; - - line_two = create_layout_with_attrs (widget, cell_area, - self, PANGO_ELLIPSIZE_END); - - context = gtk_widget_get_style_context (widget); - gtk_style_context_save (context); - apply_subtitle_style_to_layout (context, line_two, GTK_STATE_FLAG_NORMAL); - gtk_style_context_restore (context); - - pango_layout_set_height (line_one, - (priv->text_lines - 1)); - pango_layout_set_height (line_two, -1); - pango_layout_set_text (line_two, priv->line_two, -1); - - if (text != NULL) - pango_layout_set_text (line_one, text, -1); - } - - if (layout_one) - *layout_one = line_one; - if (layout_two) - *layout_two = line_two; - - g_free (text); -} - -static void -gd_two_lines_renderer_get_size (GtkCellRenderer *cell, - GtkWidget *widget, - PangoLayout *layout_1, - PangoLayout *layout_2, - gint *width, - gint *height, - const GdkRectangle *cell_area, - gint *x_offset_1, - gint *x_offset_2, - gint *y_offset) -{ - GdTwoLinesRenderer *self = GD_TWO_LINES_RENDERER (cell); - gint xpad, ypad; - PangoLayout *layout_one, *layout_two; - GdkRectangle layout_one_rect, layout_two_rect, layout_union; - - if (layout_1 == NULL) - { - gd_two_lines_renderer_prepare_layouts (self, cell_area, widget, &layout_one, &layout_two); - } - else - { - layout_one = g_object_ref (layout_1); - - if (layout_2 != NULL) - layout_two = g_object_ref (layout_2); - else - layout_two = NULL; - } - - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - pango_layout_get_pixel_extents (layout_one, NULL, (PangoRectangle *) &layout_one_rect); - - if (layout_two != NULL) - { - pango_layout_get_pixel_extents (layout_two, NULL, (PangoRectangle *) &layout_two_rect); - - layout_union.width = MAX (layout_one_rect.width, layout_two_rect.width); - layout_union.height = layout_one_rect.height + layout_two_rect.height; - } - else - { - layout_union = layout_one_rect; - } - - if (cell_area) - { - gfloat xalign, yalign; - - gtk_cell_renderer_get_alignment (cell, &xalign, &yalign); - - layout_union.width = MIN (layout_union.width, cell_area->width - 2 * xpad); - layout_union.height = MIN (layout_union.height, cell_area->height - 2 * ypad); - - if (x_offset_1) - { - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) - *x_offset_1 = (1.0 - xalign) * (cell_area->width - (layout_one_rect.width + (2 * xpad))); - else - *x_offset_1 = xalign * (cell_area->width - (layout_one_rect.width + (2 * xpad))); - - *x_offset_1 = MAX (*x_offset_1, 0); - } - if (x_offset_2) - { - if (layout_two != NULL) - { - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) - *x_offset_2 = (1.0 - xalign) * (cell_area->width - (layout_two_rect.width + (2 * xpad))); - else - *x_offset_2 = xalign * (cell_area->width - (layout_two_rect.width + (2 * xpad))); - - *x_offset_2 = MAX (*x_offset_2, 0); - } - else - { - *x_offset_2 = 0; - } - } - - if (y_offset) - { - *y_offset = yalign * (cell_area->height - (layout_union.height + (2 * ypad))); - *y_offset = MAX (*y_offset, 0); - } - } - else - { - if (x_offset_1) *x_offset_1 = 0; - if (x_offset_2) *x_offset_2 = 0; - if (y_offset) *y_offset = 0; - } - - g_clear_object (&layout_one); - g_clear_object (&layout_two); - - if (height) - *height = ypad * 2 + layout_union.height; - - if (width) - *width = xpad * 2 + layout_union.width; -} - -static void -gd_two_lines_renderer_render (GtkCellRenderer *cell, - cairo_t *cr, - GtkWidget *widget, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags) -{ - GdTwoLinesRenderer *self = GD_TWO_LINES_RENDERER (cell); - GtkStyleContext *context; - gint line_one_height; - GtkStateFlags state; - GdkRectangle area, render_area = *cell_area; - gint xpad, ypad, x_offset_1, x_offset_2, y_offset; - PangoLayout *layout_one, *layout_two; - PangoRectangle layout_rect; - - /* fetch common information */ - context = gtk_widget_get_style_context (widget); - gd_two_lines_renderer_prepare_layouts (self, cell_area, widget, &layout_one, &layout_two); - gd_two_lines_renderer_get_size (cell, widget, - layout_one, layout_two, - NULL, NULL, - cell_area, - &x_offset_1, &x_offset_2, &y_offset); - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - - area = *cell_area; - area.x += xpad; - area.y += ypad; - - /* now render the first layout */ - pango_layout_get_pixel_extents (layout_one, NULL, &layout_rect); - - render_area = area; - render_area.x += x_offset_1 - layout_rect.x; - render_area.y += y_offset; - - gtk_render_layout (context, cr, - render_area.x, - render_area.y, - layout_one); - - /* render the second layout */ - if (layout_two != NULL) - { - pango_layout_get_pixel_size (layout_one, - NULL, &line_one_height); - - gtk_style_context_save (context); - - apply_subtitle_style_to_layout (context, layout_two, flags); - - state = gtk_cell_renderer_get_state (cell, widget, flags); - gtk_style_context_set_state (context, state); - - pango_layout_get_pixel_extents (layout_two, NULL, &layout_rect); - - render_area = area; - render_area.x += x_offset_2 - layout_rect.x; - render_area.y += y_offset + line_one_height; - - gtk_render_layout (context, cr, - render_area.x, - render_area.y, - layout_two); - - gtk_style_context_restore (context); - } - - g_clear_object (&layout_one); - g_clear_object (&layout_two); -} - -static void -gd_two_lines_renderer_get_preferred_width (GtkCellRenderer *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size) -{ - PangoContext *context; - PangoFontMetrics *metrics; - PangoFontDescription *font_desc; - GtkStyleContext *style_context; - gint nat_width, min_width; - gint xpad, char_width, wrap_width, text_width; - gint width_chars, ellipsize_chars; - - g_object_get (cell, - "xpad", &xpad, - "width-chars", &width_chars, - "wrap-width", &wrap_width, - NULL); - style_context = gtk_widget_get_style_context (widget); - gtk_cell_renderer_get_padding (cell, &xpad, NULL); - - gd_two_lines_renderer_get_size (cell, widget, - NULL, NULL, - &text_width, NULL, - NULL, - NULL, NULL, NULL); - - /* Fetch the average size of a character */ - context = gtk_widget_get_pango_context (widget); - gtk_style_context_save (style_context); - gtk_style_context_set_state (style_context, 0); - gtk_style_context_get (style_context, gtk_style_context_get_state (style_context), - "font", &font_desc, NULL); - gtk_style_context_restore (style_context); - metrics = pango_context_get_metrics (context, font_desc, - pango_context_get_language (context)); - - char_width = pango_font_metrics_get_approximate_char_width (metrics); - - pango_font_metrics_unref (metrics); - pango_font_description_free (font_desc); - - /* enforce minimum width for ellipsized labels at ~3 chars */ - ellipsize_chars = 3; - - /* If no width-chars set, minimum for wrapping text will be the wrap-width */ - if (wrap_width > -1) - min_width = xpad * 2 + MIN (text_width, wrap_width); - else - min_width = xpad * 2 + - MIN (text_width, - (PANGO_PIXELS (char_width) * MAX (width_chars, ellipsize_chars))); - - if (width_chars > 0) - nat_width = xpad * 2 + - MAX ((PANGO_PIXELS (char_width) * width_chars), text_width); - else - nat_width = xpad * 2 + text_width; - - nat_width = MAX (nat_width, min_width); - - if (minimum_size) - *minimum_size = min_width; - - if (natural_size) - *natural_size = nat_width; -} - -static void -gd_two_lines_renderer_get_preferred_height_for_width (GtkCellRenderer *cell, - GtkWidget *widget, - gint width, - gint *minimum_size, - gint *natural_size) -{ - GdTwoLinesRenderer *self = GD_TWO_LINES_RENDERER (cell); - PangoLayout *layout_one, *layout_two; - gint text_height, wrap_width; - gint xpad, ypad; - - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - g_object_get (cell, "wrap-width", &wrap_width, NULL); - gd_two_lines_renderer_prepare_layouts (self, NULL, widget, &layout_one, &layout_two); - - if (wrap_width != -1) - wrap_width = MIN (width - 2 * xpad, wrap_width); - else - wrap_width = width - 2 * xpad; - - pango_layout_set_width (layout_one, wrap_width); - if (layout_two != NULL) - pango_layout_set_width (layout_two, wrap_width); - - gd_two_lines_renderer_get_size (cell, widget, - layout_one, layout_two, - NULL, &text_height, - NULL, - NULL, NULL, NULL); - - text_height += 2 * ypad; - - if (minimum_size != NULL) - *minimum_size = text_height; - - if (natural_size != NULL) - *natural_size = text_height; - - g_clear_object (&layout_one); - g_clear_object (&layout_two); -} - -static void -gd_two_lines_renderer_get_preferred_height (GtkCellRenderer *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size) -{ - gint min_width; - - gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, NULL); - gd_two_lines_renderer_get_preferred_height_for_width (cell, widget, min_width, - minimum_size, natural_size); -} - -static void -gd_two_lines_renderer_get_aligned_area (GtkCellRenderer *cell, - GtkWidget *widget, - GtkCellRendererState flags, - const GdkRectangle *cell_area, - GdkRectangle *aligned_area) -{ - gint x_offset, x_offset_1, x_offset_2, y_offset; - - /* fetch common information */ - gd_two_lines_renderer_get_size (cell, widget, - NULL, NULL, - &aligned_area->width, &aligned_area->height, - cell_area, - &x_offset_1, &x_offset_2, &y_offset); - - x_offset = MIN (x_offset_1, x_offset_2); - - aligned_area->x = cell_area->x + x_offset; - aligned_area->y = cell_area->y + y_offset; -} - -static void -gd_two_lines_renderer_set_line_two (GdTwoLinesRenderer *self, - const gchar *line_two) -{ - GdTwoLinesRendererPrivate *priv; - - priv = gd_two_lines_renderer_get_instance_private (self); - - if (g_strcmp0 (priv->line_two, line_two) == 0) - return; - - g_free (priv->line_two); - priv->line_two = g_strdup (line_two); - - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LINE_TWO]); -} - -static void -gd_two_lines_renderer_set_text_lines (GdTwoLinesRenderer *self, - gint text_lines) -{ - GdTwoLinesRendererPrivate *priv; - - priv = gd_two_lines_renderer_get_instance_private (self); - - if (priv->text_lines == text_lines) - return; - - priv->text_lines = text_lines; - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TEXT_LINES]); -} - -static void -gd_two_lines_renderer_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GdTwoLinesRenderer *self = GD_TWO_LINES_RENDERER (object); - - switch (property_id) - { - case PROP_TEXT_LINES: - gd_two_lines_renderer_set_text_lines (self, g_value_get_int (value)); - break; - case PROP_LINE_TWO: - gd_two_lines_renderer_set_line_two (self, g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gd_two_lines_renderer_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GdTwoLinesRenderer *self = GD_TWO_LINES_RENDERER (object); - GdTwoLinesRendererPrivate *priv; - - priv = gd_two_lines_renderer_get_instance_private (self); - - switch (property_id) - { - case PROP_TEXT_LINES: - g_value_set_int (value, priv->text_lines); - break; - case PROP_LINE_TWO: - g_value_set_string (value, priv->line_two); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gd_two_lines_renderer_finalize (GObject *object) -{ - GdTwoLinesRenderer *self = GD_TWO_LINES_RENDERER (object); - GdTwoLinesRendererPrivate *priv; - - priv = gd_two_lines_renderer_get_instance_private (self); - - g_free (priv->line_two); - - G_OBJECT_CLASS (gd_two_lines_renderer_parent_class)->finalize (object); -} - -static void -gd_two_lines_renderer_class_init (GdTwoLinesRendererClass *klass) -{ - GtkCellRendererClass *cclass = GTK_CELL_RENDERER_CLASS (klass); - GObjectClass *oclass = G_OBJECT_CLASS (klass); - - cclass->render = gd_two_lines_renderer_render; - cclass->get_preferred_width = gd_two_lines_renderer_get_preferred_width; - cclass->get_preferred_height = gd_two_lines_renderer_get_preferred_height; - cclass->get_preferred_height_for_width = gd_two_lines_renderer_get_preferred_height_for_width; - cclass->get_aligned_area = gd_two_lines_renderer_get_aligned_area; - - oclass->set_property = gd_two_lines_renderer_set_property; - oclass->get_property = gd_two_lines_renderer_get_property; - oclass->finalize = gd_two_lines_renderer_finalize; - - properties[PROP_TEXT_LINES] = - g_param_spec_int ("text-lines", - "Lines of text", - "The total number of lines to be displayed", - 2, G_MAXINT, 2, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - properties[PROP_LINE_TWO] = - g_param_spec_string ("line-two", - "Second line", - "Second line", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (oclass, NUM_PROPERTIES, properties); -} - -static void -gd_two_lines_renderer_init (GdTwoLinesRenderer *self) -{ -} - -GtkCellRenderer * -gd_two_lines_renderer_new (void) -{ - return g_object_new (GD_TYPE_TWO_LINES_RENDERER, NULL); -} diff --git a/cut-n-paste/libgd/gd-two-lines-renderer.h b/cut-n-paste/libgd/gd-two-lines-renderer.h deleted file mode 100644 index b10ac8a43..000000000 --- a/cut-n-paste/libgd/gd-two-lines-renderer.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#ifndef _GD_TWO_LINES_RENDERER_H -#define _GD_TWO_LINES_RENDERER_H - -#include - -#include - -G_BEGIN_DECLS - -#define GD_TYPE_TWO_LINES_RENDERER gd_two_lines_renderer_get_type() -G_DECLARE_DERIVABLE_TYPE (GdTwoLinesRenderer, gd_two_lines_renderer, GD, TWO_LINES_RENDERER, GtkCellRendererText) - -struct _GdTwoLinesRendererClass -{ - GtkCellRendererTextClass parent_class; -}; - -GType gd_two_lines_renderer_get_type (void) G_GNUC_CONST; - -GtkCellRenderer *gd_two_lines_renderer_new (void); - -G_END_DECLS - -#endif /* _GD_TWO_LINES_RENDERER_H */ diff --git a/cut-n-paste/libgd/meson.build b/cut-n-paste/libgd/meson.build deleted file mode 100644 index efa50f6ab..000000000 --- a/cut-n-paste/libgd/meson.build +++ /dev/null @@ -1,22 +0,0 @@ -sources = files( - 'gd-icon-utils.c', - 'gd-two-lines-renderer.c', -) - -deps = [ - cairo_dep, - gtk_dep, -] - -libgd = static_library( - 'gd', - sources: sources, - include_directories: top_inc, - dependencies: deps, -) - -libgd_dep = declare_dependency( - include_directories: include_directories('.'), - dependencies: deps, - link_with: libgd, -) diff --git a/cut-n-paste/meson.build b/cut-n-paste/meson.build index 279061d20..207500182 100644 --- a/cut-n-paste/meson.build +++ b/cut-n-paste/meson.build @@ -2,7 +2,6 @@ cut_n_paste_inc = include_directories('.') subdir('gimpcellrenderertoggle') subdir('libdazzle') -subdir('libgd') if not external_synctex subdir('synctex') diff --git a/shell/meson.build b/shell/meson.build index cc0464d88..74df0af3f 100644 --- a/shell/meson.build +++ b/shell/meson.build @@ -49,7 +49,6 @@ evince_deps = [ libevview_dep, libevproperties_dep, libdazzle_dep, - libgd_dep, libgimpcellrenderertoggle_dep, m_dep, ] -- GitLab From 785e82d2198d989c26c69e1eb92be566ad3048a3 Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Wed, 12 Jul 2023 15:31:20 +0800 Subject: [PATCH 4/9] cut-n-paste: Remove gimprenderertoggle Removed due to the same reason as libgd. Signed-off-by: Qiu Wenbo --- .../gimpcellrenderertoggle.c | 562 ------------------ .../gimpcellrenderertoggle.h | 83 --- .../gimpcellrenderertoggle/meson.build | 12 - cut-n-paste/meson.build | 1 - shell/meson.build | 1 - 5 files changed, 659 deletions(-) delete mode 100644 cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.c delete mode 100644 cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.h delete mode 100644 cut-n-paste/gimpcellrenderertoggle/meson.build diff --git a/cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.c b/cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.c deleted file mode 100644 index eafad6320..000000000 --- a/cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.c +++ /dev/null @@ -1,562 +0,0 @@ -/* LIBGIMP - The GIMP Library - * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball - * - * gimpcellrenderertoggle.c - * Copyright (C) 2003-2004 Sven Neumann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This 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 Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include - -#include "gimpcellrenderertoggle.h" - - -/** - * SECTION: gimpcellrenderertoggle - * @title: GimpCellRendererToggle - * @short_description: A #GtkCellRendererToggle that displays icons instead - * of a checkbox. - * - * A #GtkCellRendererToggle that displays icons instead of a checkbox. - **/ - - -#define DEFAULT_ICON_SIZE 16 - - -enum -{ - CLICKED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_ICON_NAME, - PROP_ICON_SIZE, - PROP_OVERRIDE_BACKGROUND -}; - - -struct _GimpCellRendererTogglePrivate -{ - gchar *icon_name; - gint icon_size; - gboolean override_background; - - GdkPixbuf *pixbuf; -}; - - -#define GET_PRIVATE(obj) (((GimpCellRendererToggle *) (obj))->priv) - - -static void gimp_cell_renderer_toggle_finalize (GObject *object); -static void gimp_cell_renderer_toggle_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void gimp_cell_renderer_toggle_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void gimp_cell_renderer_toggle_get_size (GtkCellRenderer *cell, - GtkWidget *widget, - const GdkRectangle *rectangle, - gint *x_offset, - gint *y_offset, - gint *width, - gint *height); -static void gimp_cell_renderer_toggle_render (GtkCellRenderer *cell, - cairo_t *cr, - GtkWidget *widget, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags); -static gboolean gimp_cell_renderer_toggle_activate (GtkCellRenderer *cell, - GdkEvent *event, - GtkWidget *widget, - const gchar *path, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags); -static void gimp_cell_renderer_toggle_create_pixbuf (GimpCellRendererToggle *toggle, - GtkWidget *widget); - - -G_DEFINE_TYPE_WITH_PRIVATE (GimpCellRendererToggle, gimp_cell_renderer_toggle, - GTK_TYPE_CELL_RENDERER_TOGGLE) - -#define parent_class gimp_cell_renderer_toggle_parent_class - -static guint toggle_cell_signals[LAST_SIGNAL] = { 0 }; - - -static void -gimp_cell_renderer_toggle_class_init (GimpCellRendererToggleClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); - - toggle_cell_signals[CLICKED] = - g_signal_new ("clicked", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GimpCellRendererToggleClass, clicked), - NULL, NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, 2, - G_TYPE_STRING, - GDK_TYPE_MODIFIER_TYPE); - - object_class->finalize = gimp_cell_renderer_toggle_finalize; - object_class->get_property = gimp_cell_renderer_toggle_get_property; - object_class->set_property = gimp_cell_renderer_toggle_set_property; - - cell_class->get_size = gimp_cell_renderer_toggle_get_size; - cell_class->render = gimp_cell_renderer_toggle_render; - cell_class->activate = gimp_cell_renderer_toggle_activate; - - g_object_class_install_property (object_class, PROP_ICON_NAME, - g_param_spec_string ("icon-name", - "Icon Name", - "The icon to display", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, PROP_ICON_SIZE, - g_param_spec_int ("icon-size", - "Icon Size", - "The desired icon size to use in pixel (before applying scaling factor)", - 0, G_MAXINT, - DEFAULT_ICON_SIZE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, PROP_OVERRIDE_BACKGROUND, - g_param_spec_boolean ("override-background", - "Override Background", - "Draw the background if the row is selected", - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); -} - -static void -gimp_cell_renderer_toggle_init (GimpCellRendererToggle *toggle) -{ - toggle->priv = gimp_cell_renderer_toggle_get_instance_private (toggle); -} - -static void -gimp_cell_renderer_toggle_finalize (GObject *object) -{ - GimpCellRendererTogglePrivate *priv = GET_PRIVATE (object); - - g_clear_pointer (&priv->icon_name, g_free); - g_clear_object (&priv->pixbuf); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -gimp_cell_renderer_toggle_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - GimpCellRendererTogglePrivate *priv = GET_PRIVATE (object); - - switch (param_id) - { - case PROP_ICON_NAME: - g_value_set_string (value, priv->icon_name); - break; - - case PROP_ICON_SIZE: - g_value_set_int (value, priv->icon_size); - break; - - case PROP_OVERRIDE_BACKGROUND: - g_value_set_boolean (value, priv->override_background); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -gimp_cell_renderer_toggle_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - GimpCellRendererTogglePrivate *priv = GET_PRIVATE (object); - - switch (param_id) - { - case PROP_ICON_NAME: - if (priv->icon_name) - g_free (priv->icon_name); - priv->icon_name = g_value_dup_string (value); - break; - - case PROP_ICON_SIZE: - priv->icon_size = g_value_get_int (value); - break; - - case PROP_OVERRIDE_BACKGROUND: - priv->override_background = g_value_get_boolean (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } - - g_clear_object (&priv->pixbuf); -} - -static void -gimp_cell_renderer_toggle_get_size (GtkCellRenderer *cell, - GtkWidget *widget, - const GdkRectangle *cell_area, - gint *x_offset, - gint *y_offset, - gint *width, - gint *height) -{ - GimpCellRendererToggle *toggle = GIMP_CELL_RENDERER_TOGGLE (cell); - GimpCellRendererTogglePrivate *priv = GET_PRIVATE (cell); - GtkStyleContext *context = gtk_widget_get_style_context (widget); - GtkBorder border; - gint scale_factor; - gint calc_width; - gint calc_height; - gint pixbuf_width; - gint pixbuf_height; - gfloat xalign; - gfloat yalign; - gint xpad; - gint ypad; - - scale_factor = gtk_widget_get_scale_factor (widget); - - if (! priv->icon_name) - { - GTK_CELL_RENDERER_CLASS (parent_class)->get_size (cell, - widget, - cell_area, - x_offset, y_offset, - width, height); - return; - } - - gtk_style_context_save (context); - - gtk_cell_renderer_get_alignment (cell, &xalign, &yalign); - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - - if (! priv->pixbuf) - gimp_cell_renderer_toggle_create_pixbuf (toggle, widget); - - pixbuf_width = gdk_pixbuf_get_width (priv->pixbuf); - pixbuf_height = gdk_pixbuf_get_height (priv->pixbuf); - - /* The pixbuf size may be bigger than the logical size. */ - calc_width = pixbuf_width / scale_factor + (gint) xpad * 2; - calc_height = pixbuf_height / scale_factor + (gint) ypad * 2; - - gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON); - - gtk_style_context_get_border (context, 0, &border); - calc_width += border.left + border.right; - calc_height += border.top + border.bottom; - - if (width) - *width = calc_width; - - if (height) - *height = calc_height; - - if (cell_area) - { - if (x_offset) - { - *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? - (1.0 - xalign) : xalign) * - (cell_area->width - calc_width)); - *x_offset = MAX (*x_offset, 0); - } - - if (y_offset) - { - *y_offset = yalign * (cell_area->height - calc_height); - *y_offset = MAX (*y_offset, 0); - } - } - - gtk_style_context_restore (context); -} - -static void -gimp_cell_renderer_toggle_render (GtkCellRenderer *cell, - cairo_t *cr, - GtkWidget *widget, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags) -{ - GimpCellRendererTogglePrivate *priv = GET_PRIVATE (cell); - GtkStyleContext *context = gtk_widget_get_style_context (widget); - GdkRectangle toggle_rect; - GtkStateFlags state; - gboolean active; - gint scale_factor; - gint xpad; - gint ypad; - - scale_factor = gtk_widget_get_scale_factor (widget); - - if (! priv->icon_name) - { - GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, cr, widget, - background_area, - cell_area, - flags); - return; - } - - if ((flags & GTK_CELL_RENDERER_SELECTED) && - priv->override_background) - { - gboolean background_set; - - g_object_get (cell, - "cell-background-set", &background_set, - NULL); - - if (background_set) - { - GdkRGBA *color; - - g_object_get (cell, - "cell-background-rgba", &color, - NULL); - - gdk_cairo_rectangle (cr, background_area); - gdk_cairo_set_source_rgba (cr, color); - cairo_fill (cr); - - gdk_rgba_free (color); - } - } - - gimp_cell_renderer_toggle_get_size (cell, widget, cell_area, - &toggle_rect.x, - &toggle_rect.y, - &toggle_rect.width, - &toggle_rect.height); - gtk_style_context_save (context); - - gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON); - - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - - toggle_rect.x += cell_area->x + xpad; - toggle_rect.y += cell_area->y + ypad; - toggle_rect.width -= xpad * 2; - toggle_rect.height -= ypad * 2; - - if (toggle_rect.width <= 0 || toggle_rect.height <= 0) - return; - - state = gtk_cell_renderer_get_state (cell, widget, flags); - - active = - gtk_cell_renderer_toggle_get_active (GTK_CELL_RENDERER_TOGGLE (cell)); - - if (active) - state |= GTK_STATE_FLAG_ACTIVE; - - if (! gtk_cell_renderer_toggle_get_activatable (GTK_CELL_RENDERER_TOGGLE (cell))) - state |= GTK_STATE_FLAG_INSENSITIVE; - - gtk_style_context_set_state (context, state); - - if (state & GTK_STATE_FLAG_PRELIGHT) - gtk_render_frame (context, cr, - toggle_rect.x, toggle_rect.y, - toggle_rect.width, toggle_rect.height); - - if (active) - { - GtkBorder border; - gboolean inconsistent; - - gtk_style_context_get_border (context, 0, &border); - toggle_rect.x += border.left; - toggle_rect.x *= scale_factor; - toggle_rect.y += border.top; - toggle_rect.y *= scale_factor; - toggle_rect.width -= border.left + border.right; - toggle_rect.height -= border.top + border.bottom; - - /* For high DPI displays, pixbuf size is bigger than logical size. */ - cairo_scale (cr, (gdouble) 1.0 / scale_factor, (gdouble) 1.0 / scale_factor); - gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, - toggle_rect.x, toggle_rect.y); - cairo_paint (cr); - - g_object_get (cell, - "inconsistent", &inconsistent, - NULL); - - if (inconsistent) - { - GdkRGBA color; - - gtk_style_context_get_color (context, state, &color); - gdk_cairo_set_source_rgba (cr, &color); - cairo_set_line_width (cr, 1.5); - cairo_move_to (cr, - toggle_rect.x + toggle_rect.width - 1, - toggle_rect.y + 1); - cairo_line_to (cr, - toggle_rect.x + 1, - toggle_rect.y + toggle_rect.height - 1); - cairo_stroke (cr); - } - } - - gtk_style_context_restore (context); -} - -static gboolean -gimp_cell_renderer_toggle_activate (GtkCellRenderer *cell, - GdkEvent *event, - GtkWidget *widget, - const gchar *path, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags) -{ - GtkCellRendererToggle *toggle = GTK_CELL_RENDERER_TOGGLE (cell); - - if (gtk_cell_renderer_toggle_get_activatable (toggle)) - { - GdkModifierType state = 0; - - if (event && ((GdkEventAny *) event)->type == GDK_BUTTON_PRESS) - state = ((GdkEventButton *) event)->state; - - gimp_cell_renderer_toggle_clicked (GIMP_CELL_RENDERER_TOGGLE (cell), - path, state); - - return TRUE; - } - - return FALSE; -} - -static void -gimp_cell_renderer_toggle_create_pixbuf (GimpCellRendererToggle *toggle, - GtkWidget *widget) -{ - GimpCellRendererTogglePrivate *priv = GET_PRIVATE (toggle); - - g_clear_object (&priv->pixbuf); - - if (priv->icon_name) - { - GdkScreen *screen; - GtkIconTheme *icon_theme; - GtkIconInfo *icon_info; - gchar *icon_name; - gint scale_factor; - - scale_factor = gtk_widget_get_scale_factor (widget); - screen = gtk_widget_get_screen (widget); - icon_theme = gtk_icon_theme_get_for_screen (screen); - - /* Look for symbolic and fallback to color icon. */ - icon_name = g_strdup_printf ("%s-symbolic", priv->icon_name); - icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, icon_name, - priv->icon_size, scale_factor, - GTK_ICON_LOOKUP_GENERIC_FALLBACK); - - g_free (icon_name); - if (icon_info) - { - GdkPixbuf *pixbuf; - - pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, - gtk_widget_get_style_context (widget), - NULL, NULL); - priv->pixbuf = pixbuf; - g_object_unref (icon_info); - } - } -} - - -/** - * gimp_cell_renderer_toggle_new: - * @icon_name: the icon name of the icon to use for the active state - * - * Creates a custom version of the #GtkCellRendererToggle. Instead of - * showing the standard toggle button, it shows a named icon if the - * cell is active and no icon otherwise. This cell renderer is for - * example used in the Layers treeview to indicate and control the - * layer's visibility by showing %GIMP_STOCK_VISIBLE. - * - * Return value: a new #GimpCellRendererToggle - * - * Since: GIMP 2.2 - **/ -GtkCellRenderer * -gimp_cell_renderer_toggle_new (const gchar *icon_name) -{ - return g_object_new (GIMP_TYPE_CELL_RENDERER_TOGGLE, - "icon-name", icon_name, - NULL); -} - -/** - * gimp_cell_renderer_toggle_clicked: - * @cell: a #GimpCellRendererToggle - * @path: the path to the clicked row - * @state: the modifier state - * - * Emits the "clicked" signal from a #GimpCellRendererToggle. - * - * Since: GIMP 2.2 - **/ -void -gimp_cell_renderer_toggle_clicked (GimpCellRendererToggle *cell, - const gchar *path, - GdkModifierType state) -{ - g_return_if_fail (GIMP_IS_CELL_RENDERER_TOGGLE (cell)); - g_return_if_fail (path != NULL); - - g_signal_emit (cell, toggle_cell_signals[CLICKED], 0, path, state); -} diff --git a/cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.h b/cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.h deleted file mode 100644 index e94d11248..000000000 --- a/cut-n-paste/gimpcellrenderertoggle/gimpcellrenderertoggle.h +++ /dev/null @@ -1,83 +0,0 @@ -/* LIBGIMP - The GIMP Library - * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball - * - * gimpcellrenderertoggle.h - * Copyright (C) 2003-2004 Sven Neumann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This 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 Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __GIMP_CELL_RENDERER_TOGGLE_H__ -#define __GIMP_CELL_RENDERER_TOGGLE_H__ - -#include -#include - -G_BEGIN_DECLS - - -#define GIMP_TYPE_CELL_RENDERER_TOGGLE (gimp_cell_renderer_toggle_get_type ()) -#define GIMP_CELL_RENDERER_TOGGLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CELL_RENDERER_TOGGLE, GimpCellRendererToggle)) -#define GIMP_CELL_RENDERER_TOGGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CELL_RENDERER_TOGGLE, GimpCellRendererToggleClass)) -#define GIMP_IS_CELL_RENDERER_TOGGLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CELL_RENDERER_TOGGLE)) -#define GIMP_IS_CELL_RENDERER_TOGGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CELL_RENDERER_TOGGLE)) -#define GIMP_CELL_RENDERER_TOGGLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CELL_RENDERER_TOGGLE, GimpCellRendererToggleClass)) - - -typedef struct _GimpCellRendererTogglePrivate GimpCellRendererTogglePrivate; -typedef struct _GimpCellRendererToggleClass GimpCellRendererToggleClass; - -struct _GimpCellRendererToggle -{ - GtkCellRendererToggle parent_instance; - - GimpCellRendererTogglePrivate *priv; -}; - -typedef struct _GimpCellRendererToggle GimpCellRendererToggle; - -struct _GimpCellRendererToggleClass -{ - GtkCellRendererToggleClass parent_class; - - void (* clicked) (GimpCellRendererToggle *cell, - const gchar *path, - GdkModifierType state); - - /* Padding for future expansion */ - void (* _gimp_reserved1) (void); - void (* _gimp_reserved2) (void); - void (* _gimp_reserved3) (void); - void (* _gimp_reserved4) (void); - void (* _gimp_reserved5) (void); - void (* _gimp_reserved6) (void); - void (* _gimp_reserved7) (void); - void (* _gimp_reserved8) (void); -}; - - -GType gimp_cell_renderer_toggle_get_type (void) G_GNUC_CONST; - -GtkCellRenderer * gimp_cell_renderer_toggle_new (const gchar *icon_name); - -void gimp_cell_renderer_toggle_clicked (GimpCellRendererToggle *cell, - const gchar *path, - GdkModifierType state); - - -G_END_DECLS - -#endif /* __GIMP_CELL_RENDERER_TOGGLE_H__ */ diff --git a/cut-n-paste/gimpcellrenderertoggle/meson.build b/cut-n-paste/gimpcellrenderertoggle/meson.build deleted file mode 100644 index b08e8b663..000000000 --- a/cut-n-paste/gimpcellrenderertoggle/meson.build +++ /dev/null @@ -1,12 +0,0 @@ -libgimpcellrenderertoggle = static_library( - 'gimpcellrenderertoggle', - sources: 'gimpcellrenderertoggle.c', - include_directories: top_inc, - dependencies: gtk_dep, -) - -libgimpcellrenderertoggle_dep = declare_dependency( - include_directories: include_directories('.'), - dependencies: gtk_dep, - link_with: libgimpcellrenderertoggle, -) diff --git a/cut-n-paste/meson.build b/cut-n-paste/meson.build index 207500182..0dc7bca8e 100644 --- a/cut-n-paste/meson.build +++ b/cut-n-paste/meson.build @@ -1,6 +1,5 @@ cut_n_paste_inc = include_directories('.') -subdir('gimpcellrenderertoggle') subdir('libdazzle') if not external_synctex diff --git a/shell/meson.build b/shell/meson.build index 74df0af3f..fcb90f892 100644 --- a/shell/meson.build +++ b/shell/meson.build @@ -49,7 +49,6 @@ evince_deps = [ libevview_dep, libevproperties_dep, libdazzle_dep, - libgimpcellrenderertoggle_dep, m_dep, ] -- GitLab From d63d12ceb391292fd6d03e09b851565666b3d74d Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Sun, 12 Nov 2023 15:46:26 +0800 Subject: [PATCH 5/9] libdocument: Port EvAttachment to gtk4 GdkScreen has been removed in GTK4. Signed-off-by: Qiu Wenbo --- libdocument/ev-attachment.c | 3 +-- libdocument/ev-attachment.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libdocument/ev-attachment.c b/libdocument/ev-attachment.c index 131a87d71..9a317be27 100644 --- a/libdocument/ev-attachment.c +++ b/libdocument/ev-attachment.c @@ -387,14 +387,13 @@ ev_attachment_launch_app (EvAttachment *attachment, gboolean ev_attachment_open (EvAttachment *attachment, - GdkScreen *screen, + GdkDisplay *display, guint32 timestamp, GError **error) { GAppInfo *app_info; gboolean retval = FALSE; EvAttachmentPrivate *priv; - GdkDisplay *display = gdk_screen_get_display (screen); g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), FALSE); diff --git a/libdocument/ev-attachment.h b/libdocument/ev-attachment.h index 8c63c5658..4177a8952 100644 --- a/libdocument/ev-attachment.h +++ b/libdocument/ev-attachment.h @@ -70,7 +70,7 @@ gboolean ev_attachment_save (EvAttachment *attachment, GError **error); EV_PUBLIC gboolean ev_attachment_open (EvAttachment *attachment, - GdkScreen *screen, + GdkDisplay *display, guint32 timestamp, GError **error); -- GitLab From 424c41b04aa972c024e7331efbceed093d890cdd Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Sun, 12 Nov 2023 15:47:08 +0800 Subject: [PATCH 6/9] libdocument: Port EvDocumentMisc to gtk4 Signed-off-by: Qiu Wenbo --- libdocument/ev-document-misc.c | 92 +++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index c75572a58..bb7d50b8c 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -36,7 +36,6 @@ ev_document_misc_render_thumbnail_frame (GtkWidget *widget, cairo_surface_t *source_surface) { GtkStyleContext *context = gtk_widget_get_style_context (widget); - GtkStateFlags state = gtk_widget_get_state_flags (widget); double width_r, height_r; double width_f, height_f; cairo_surface_t *surface; @@ -70,7 +69,7 @@ ev_document_misc_render_thumbnail_frame (GtkWidget *widget, if (inverted_colors) gtk_style_context_add_class (context, "inverted"); - gtk_style_context_get_border (context, state, &border); + gtk_style_context_get_border (context, &border); width_f = width_r + border.left + border.right; height_f = height_r + border.top + border.bottom; @@ -261,20 +260,18 @@ ev_document_misc_invert_surface (cairo_surface_t *surface) { gdouble ev_document_misc_get_widget_dpi (GtkWidget *widget) { - GdkRectangle geometry; - GdkDisplay *display; - GdkMonitor *monitor; - GdkWindow *window; + GdkDisplay *display = gtk_widget_get_display (widget); + GtkNative *native = gtk_widget_get_native (widget); + GdkSurface *surface = NULL; + GdkMonitor *monitor = NULL; gboolean is_landscape; + GdkRectangle geometry; - display = gtk_widget_get_display (widget); - window = gtk_widget_get_window (widget); - if (window != NULL) { - monitor = gdk_display_get_monitor_at_window (display, window); - } else { - monitor = gdk_display_get_primary_monitor (display); - if (monitor == NULL) - monitor = gdk_display_get_monitor (display, 0); + if (native != NULL) + surface = gtk_native_get_surface (native); + + if (surface != NULL) { + monitor = gdk_display_get_monitor_at_surface (display, surface); } /* The only safe assumption you can make, on Unix-like/X11 and @@ -332,30 +329,45 @@ ev_document_misc_get_pointer_position (GtkWidget *widget, gint *x, gint *y) { - GdkSeat *seat; - GdkDevice *device_pointer; - GdkRectangle allocation; - - if (x) - *x = -1; - if (y) - *y = -1; - - if (!gtk_widget_get_realized (widget)) - return; - - seat = gdk_display_get_default_seat (gtk_widget_get_display (widget)); - device_pointer = gdk_seat_get_pointer (seat); - gdk_window_get_device_position (gtk_widget_get_window (widget), - device_pointer, - x, y, NULL); - - if (gtk_widget_get_has_window (widget)) - return; - - gtk_widget_get_allocation (widget, &allocation); - if (x) - *x -= allocation.x; - if (y) - *y -= allocation.y; + gdouble dx, dy; + GdkSeat *seat; + GtkNative *native; + GdkDevice *device_pointer; + GdkSurface *surface; + + if (x) + *x = -1; + if (y) + *y = -1; + + if (!gtk_widget_get_realized (widget)) + return; + + seat = gdk_display_get_default_seat (gtk_widget_get_display (widget)); + + device_pointer = gdk_seat_get_pointer (seat); + native = gtk_widget_get_native (widget); + + if (!native) + return; + + surface = gtk_native_get_surface (native); + if (!surface) + return; + + gdk_surface_get_device_position (surface, + device_pointer, + &dx, &dy, NULL); + + if (x) + *x = dx; + if (y) + *y = dy; + + gtk_widget_translate_coordinates (widget, GTK_WIDGET (native), 0, 0, &dx, &dy); + + if (x) + *x -= dx; + if (y) + *y -= dy; } -- GitLab From 0430677758b4a6df4edd6dbe694e0a6e25b53e98 Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Wed, 12 Jul 2023 16:25:08 +0800 Subject: [PATCH 7/9] properties: Port to new Nautilus extension API Signed-off-by: Qiu Wenbo --- properties/ev-properties-main.c | 130 ++++++++++++++++++++++++-------- properties/ev-properties-view.c | 68 +++-------------- properties/ev-properties-view.h | 46 +++++++++++ 3 files changed, 158 insertions(+), 86 deletions(-) diff --git a/properties/ev-properties-main.c b/properties/ev-properties-main.c index 7cc49da53..f415f9a80 100644 --- a/properties/ev-properties-main.c +++ b/properties/ev-properties-main.c @@ -41,9 +41,9 @@ static GType epp_type = 0; static void property_page_provider_iface_init - (NautilusPropertyPageProviderIface *iface); -static GList *ev_properties_get_pages - (NautilusPropertyPageProvider *provider, GList *files); + (NautilusPropertiesModelProviderInterface *iface); +static GList *ev_properties_get_models + (NautilusPropertiesModelProvider *provider, GList *files); static void ev_properties_plugin_register_type (GTypeModule *module) @@ -70,28 +70,109 @@ ev_properties_plugin_register_type (GTypeModule *module) &info, 0); g_type_module_add_interface (module, epp_type, - NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER, + NAUTILUS_TYPE_PROPERTIES_MODEL_PROVIDER, &property_page_provider_iface_info); } static void -property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface) +property_page_provider_iface_init (NautilusPropertiesModelProviderInterface *iface) { - iface->get_pages = ev_properties_get_pages; + iface->get_models = ev_properties_get_models; +} + +static GListModel * +build_properties (EvDocument *document) +{ + EvDocumentInfo *info = ev_document_get_info (document); + GListStore *model = g_list_store_new (NAUTILUS_TYPE_PROPERTIES_ITEM); + const char *uri = ev_document_get_uri (document); + GDateTime *datetime = NULL; + char *text; + +#define SET_PROPERTY(p, value) do { \ + g_list_store_append (model, \ + nautilus_properties_item_new (_(properties_info[p##_PROPERTY].label), value)); \ + } while (0) + +#define FIELD_SET_PROPERTY(p, value) \ + if (info->fields_mask & EV_DOCUMENT_INFO_##p) { \ + SET_PROPERTY (p, value); \ + } + + FIELD_SET_PROPERTY (TITLE, info->title); + SET_PROPERTY (URI, uri); + FIELD_SET_PROPERTY (SUBJECT, info->subject); + FIELD_SET_PROPERTY (AUTHOR, info->author); + FIELD_SET_PROPERTY (KEYWORDS, info->keywords); + FIELD_SET_PROPERTY (PRODUCER, info->producer); + FIELD_SET_PROPERTY (CREATOR, info->creator); + + datetime = ev_document_info_get_created_datetime(info); + if (datetime != NULL) { + text = ev_document_misc_format_datetime(datetime); + SET_PROPERTY(CREATION_DATE, text); + g_free(text); + } else { + SET_PROPERTY(CREATION_DATE, NULL); + } + datetime = ev_document_info_get_modified_datetime(info); + if (datetime != NULL) { + text = ev_document_misc_format_datetime(datetime); + SET_PROPERTY(MOD_DATE, text); + g_free(text); + } else { + SET_PROPERTY(MOD_DATE, NULL); + } + + FIELD_SET_PROPERTY (FORMAT, info->format); + + if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) { + text = g_strdup_printf ("%d", info->n_pages); + SET_PROPERTY (N_PAGES, text); + g_free (text); + } + FIELD_SET_PROPERTY (LINEARIZED, info->linearized); + FIELD_SET_PROPERTY (SECURITY, info->security); + + if (info->fields_mask & EV_DOCUMENT_INFO_PAPER_SIZE) { + text = ev_regular_paper_size (info); + SET_PROPERTY (PAPER_SIZE, text); + g_free (text); + } + + if (info->fields_mask & EV_DOCUMENT_INFO_CONTAINS_JS) { + if (info->contains_js == EV_DOCUMENT_CONTAINS_JS_YES) { + text = _("Yes"); + } else if (info->contains_js == EV_DOCUMENT_CONTAINS_JS_NO) { + text = _("No"); + } else { + text = _("Unknown"); + } + SET_PROPERTY (CONTAINS_JS, text); + } + + if (ev_document_get_size (document)) { + text = g_format_size (ev_document_get_size (document)); + SET_PROPERTY (FILE_SIZE, text); + g_free (text); + } + + return G_LIST_MODEL (model); +#undef SET_PROPERTY +#undef FIELD_SET_PROPERTY } static GList * -ev_properties_get_pages (NautilusPropertyPageProvider *provider, +ev_properties_get_models (NautilusPropertiesModelProvider *provider, GList *files) { GError *error = NULL; EvDocument *document = NULL; - GList *pages = NULL; + GList *models = NULL; NautilusFileInfo *file; gchar *uri = NULL; - GtkWidget *page, *label; - GtkWidget *scrolled; - NautilusPropertyPage *property_page; + gchar *mime_type = NULL; + NautilusPropertiesModel *properties_group; /* only add properties page if a single file is selected */ if (files == NULL || files->next != NULL) @@ -105,32 +186,21 @@ ev_properties_get_pages (NautilusPropertyPageProvider *provider, if (!document) goto end; - label = gtk_label_new (_("Document")); - page = ev_properties_view_new (document); - ev_properties_view_set_info (EV_PROPERTIES_VIEW (page), - ev_document_get_info (document)); - gtk_widget_show (page); - - scrolled = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (scrolled), - TRUE); - gtk_container_add (GTK_CONTAINER (scrolled), page); - gtk_widget_show (scrolled); - - property_page = nautilus_property_page_new ("document-properties", - label, scrolled); + ev_document_load (document, uri, &error); + if (error) { + g_error_free (error); + goto end; + } - pages = g_list_prepend (pages, property_page); + properties_group = nautilus_properties_model_new (_("Document"), build_properties (document)); + models = g_list_prepend (models, properties_group); end: g_free (uri); g_clear_pointer (&error, g_error_free); g_clear_object (&document); - return pages; + return models; } /* --- extension interface --- */ diff --git a/properties/ev-properties-view.c b/properties/ev-properties-view.c index 04aa656f2..cb30722b9 100644 --- a/properties/ev-properties-view.c +++ b/properties/ev-properties-view.c @@ -33,49 +33,6 @@ #include "ev-properties-view.h" -typedef enum { - TITLE_PROPERTY, - URI_PROPERTY, - SUBJECT_PROPERTY, - AUTHOR_PROPERTY, - KEYWORDS_PROPERTY, - PRODUCER_PROPERTY, - CREATOR_PROPERTY, - CREATION_DATE_PROPERTY, - MOD_DATE_PROPERTY, - N_PAGES_PROPERTY, - LINEARIZED_PROPERTY, - FORMAT_PROPERTY, - SECURITY_PROPERTY, - CONTAINS_JS_PROPERTY, - PAPER_SIZE_PROPERTY, - FILE_SIZE_PROPERTY, - N_PROPERTIES, -} Property; - -typedef struct { - Property property; - const char *label; -} PropertyInfo; - -static const PropertyInfo properties_info[] = { - { TITLE_PROPERTY, N_("Title:") }, - { URI_PROPERTY, N_("Location:") }, - { SUBJECT_PROPERTY, N_("Subject:") }, - { AUTHOR_PROPERTY, N_("Author:") }, - { KEYWORDS_PROPERTY, N_("Keywords:") }, - { PRODUCER_PROPERTY, N_("Producer:") }, - { CREATOR_PROPERTY, N_("Creator:") }, - { CREATION_DATE_PROPERTY, N_("Created:") }, - { MOD_DATE_PROPERTY, N_("Modified:") }, - { N_PAGES_PROPERTY, N_("Number of Pages:") }, - { LINEARIZED_PROPERTY, N_("Optimized:") }, - { FORMAT_PROPERTY, N_("Format:") }, - { SECURITY_PROPERTY, N_("Security:") }, - { CONTAINS_JS_PROPERTY, N_("Contains Javascript:") }, - { PAPER_SIZE_PROPERTY, N_("Paper Size:") }, - { FILE_SIZE_PROPERTY, N_("Size:") } -}; struct _EvPropertiesView { GtkBox base_instance; @@ -242,12 +199,9 @@ set_property (EvPropertiesView *properties, } if (property_label && value_label) { - atk_object_add_relationship (gtk_widget_get_accessible (property_label), - ATK_RELATION_LABEL_FOR, - gtk_widget_get_accessible (value_label)); - atk_object_add_relationship (gtk_widget_get_accessible (value_label), - ATK_RELATION_LABELLED_BY, - gtk_widget_get_accessible (property_label)); + gtk_accessible_update_relation (GTK_ACCESSIBLE (value_label), + GTK_ACCESSIBLE_RELATION_LABELLED_BY, property_label, + NULL, -1); } gtk_widget_show (value_label); @@ -297,7 +251,7 @@ get_tolerance (gdouble size) return 3.0f; } -static char * +char * ev_regular_paper_size (const EvDocumentInfo *info) { GList *paper_sizes, *l; @@ -444,15 +398,17 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo static void ev_properties_view_init (EvPropertiesView *properties) { + GtkWidget *widget = GTK_WIDGET (properties); + + gtk_widget_set_margin_bottom (widget, 12); + gtk_widget_set_margin_top (widget, 12); + gtk_widget_set_margin_start (widget, 12); + gtk_widget_set_margin_end (widget, 12); + properties->grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (properties->grid), 12); gtk_grid_set_row_spacing (GTK_GRID (properties->grid), 6); - gtk_box_pack_start (GTK_BOX (properties), properties->grid, TRUE, TRUE, 0); - gtk_widget_show (properties->grid); - gtk_widget_set_margin_bottom (properties->grid, 12); - gtk_widget_set_margin_top (properties->grid, 12); - gtk_widget_set_margin_start (properties->grid, 12); - gtk_widget_set_margin_end (properties->grid, 12); + gtk_box_prepend (GTK_BOX (properties), properties->grid); } void diff --git a/properties/ev-properties-view.h b/properties/ev-properties-view.h index 8d27d5b50..f620147b9 100644 --- a/properties/ev-properties-view.h +++ b/properties/ev-properties-view.h @@ -26,6 +26,50 @@ G_BEGIN_DECLS +typedef enum { + TITLE_PROPERTY, + URI_PROPERTY, + SUBJECT_PROPERTY, + AUTHOR_PROPERTY, + KEYWORDS_PROPERTY, + PRODUCER_PROPERTY, + CREATOR_PROPERTY, + CREATION_DATE_PROPERTY, + MOD_DATE_PROPERTY, + N_PAGES_PROPERTY, + LINEARIZED_PROPERTY, + FORMAT_PROPERTY, + SECURITY_PROPERTY, + CONTAINS_JS_PROPERTY, + PAPER_SIZE_PROPERTY, + FILE_SIZE_PROPERTY, + N_PROPERTIES, +} Property; + +typedef struct { + Property property; + const char *label; +} PropertyInfo; + +static const PropertyInfo properties_info[] = { + { TITLE_PROPERTY, N_("Title:") }, + { URI_PROPERTY, N_("Location:") }, + { SUBJECT_PROPERTY, N_("Subject:") }, + { AUTHOR_PROPERTY, N_("Author:") }, + { KEYWORDS_PROPERTY, N_("Keywords:") }, + { PRODUCER_PROPERTY, N_("Producer:") }, + { CREATOR_PROPERTY, N_("Creator:") }, + { CREATION_DATE_PROPERTY, N_("Created:") }, + { MOD_DATE_PROPERTY, N_("Modified:") }, + { N_PAGES_PROPERTY, N_("Number of Pages:") }, + { LINEARIZED_PROPERTY, N_("Optimized:") }, + { FORMAT_PROPERTY, N_("Format:") }, + { SECURITY_PROPERTY, N_("Security:") }, + { CONTAINS_JS_PROPERTY, N_("Contains Javascript:") }, + { PAPER_SIZE_PROPERTY, N_("Paper Size:") }, + { FILE_SIZE_PROPERTY, N_("Size:") } +}; + typedef struct _EvPropertiesView EvPropertiesView; typedef struct _EvPropertiesViewClass EvPropertiesViewClass; typedef struct _EvPropertiesViewPrivate EvPropertiesViewPrivate; @@ -44,4 +88,6 @@ GtkWidget *ev_properties_view_new (EvDocument *document); void ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo *info); +char * ev_regular_paper_size (const EvDocumentInfo *info); + G_END_DECLS -- GitLab From d9425708af0d1964914a08ec68ef485d90112335 Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Sun, 12 Nov 2023 17:48:25 +0800 Subject: [PATCH 8/9] meson: enable libdocument, backend, thumbnailer and properties Signed-off-by: Qiu Wenbo --- meson.build | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 0bed24bd7..b5de346c7 100644 --- a/meson.build +++ b/meson.build @@ -432,11 +432,11 @@ mime_types_conf.set('EVINCE_MIME_TYPES', ';'.join(evince_mime_types)) mime_types_conf.set('PACKAGE_ICON_NAME', app_id) subdir('cut-n-paste') -#subdir('libdocument') -#subdir('backend') +subdir('libdocument') +subdir('backend') #subdir('libview') #subdir('libmisc') -#subdir('properties') +subdir('properties') # *** Document Viewer *** enable_viewer = get_option('viewer') @@ -450,7 +450,7 @@ subdir('po') # *** Thumbnailer *** enable_thumbnailer = get_option('thumbnailer') if enable_thumbnailer - #subdir('thumbnailer') + subdir('thumbnailer') endif # Print Previewer -- GitLab From 0f4338165776c81e77de4549121e8935f7c4789d Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Sun, 12 Nov 2023 18:12:58 +0800 Subject: [PATCH 9/9] build: Disable flatpak build for CI Flatpak failed due to can't find evince command. We will enable it when the gtk4 port is finished. Signed-off-by: Qiu Wenbo --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4dafb13df..f82b8cbb1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,6 +52,7 @@ meson-internal-synctex: flatpak: extends: .flatpak stage: build + when: manual variables: MANIFEST_PATH: "build-aux/flatpak/org.gnome.Evince.json" -- GitLab