[evince/wip/gpoo/make-struct-priv] pdf: Reimplement 'de facto' tooltip feature keeping the ABI
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/make-struct-priv] pdf: Reimplement 'de facto' tooltip feature keeping the ABI
- Date: Thu, 9 Jul 2020 03:09:00 +0000 (UTC)
commit 1c341bd1847e9a7a879d44b2efa58a9d36cb04a3
Author: Germán Poo-Caamaño <gpoo gnome org>
Date: Mon Jul 6 10:32:15 2020 -0400
pdf: Reimplement 'de facto' tooltip feature keeping the ABI
Structs in EvForm are not opaque, and
Commit e2ad8611a4c introduced a ABI change
backend/pdf/ev-poppler.cc | 3 +-
libdocument/ev-form-field.c | 68 +++++++++++++++++++++++++++++++++++++++++++--
libdocument/ev-form-field.h | 1 -
libdocument/meson.build | 1 +
libview/ev-view.c | 19 ++++++++-----
5 files changed, 80 insertions(+), 12 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 216052a3..ee9a5c9f 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -52,6 +52,7 @@
#include "ev-document-annotations.h"
#include "ev-document-attachments.h"
#include "ev-document-text.h"
+#include "ev-form-field-private.h"
#include "ev-selection.h"
#include "ev-transition-effect.h"
#include "ev-attachment.h"
@@ -2780,7 +2781,7 @@ ev_form_field_from_poppler_field (PdfDocument *pdf_document,
ev_field->font_size = font_size;
ev_field->is_read_only = is_read_only;
- ev_field->alt_ui_name = alt_ui_name;
+ ev_form_field_set_alternate_name (ev_field, alt_ui_name);
if (action)
ev_field->activation_link = ev_link_from_action (pdf_document, action);
diff --git a/libdocument/ev-form-field.c b/libdocument/ev-form-field.c
index 7e0169ad..d735cbee 100644
--- a/libdocument/ev-form-field.c
+++ b/libdocument/ev-form-field.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of evince, a gnome document viewer
*
+ * Copyright (C) 2020 Germán Poo-Caamaño <gpoo gnome org>
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc gnome org>
* Copyright (C) 2006 Julien Rebetez
*
@@ -21,6 +22,12 @@
#include <config.h>
#include "ev-form-field.h"
+#include "ev-form-field-private.h"
+
+typedef struct
+{
+ gchar *alt_ui_name;
+} EvFormFieldPrivate;
static void ev_form_field_init (EvFormField *field);
static void ev_form_field_class_init (EvFormFieldClass *klass);
@@ -33,31 +40,35 @@ static void ev_form_field_choice_class_init (EvFormFieldChoiceClass *klass
static void ev_form_field_signature_init (EvFormFieldSignature *field_choice);
static void ev_form_field_signature_class_init (EvFormFieldSignatureClass *klass);
-G_DEFINE_ABSTRACT_TYPE (EvFormField, ev_form_field, G_TYPE_OBJECT)
G_DEFINE_TYPE (EvFormFieldText, ev_form_field_text, EV_TYPE_FORM_FIELD)
G_DEFINE_TYPE (EvFormFieldButton, ev_form_field_button, EV_TYPE_FORM_FIELD)
G_DEFINE_TYPE (EvFormFieldChoice, ev_form_field_choice, EV_TYPE_FORM_FIELD)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (EvFormField, ev_form_field, G_TYPE_OBJECT)
G_DEFINE_TYPE (EvFormFieldSignature, ev_form_field_signature, EV_TYPE_FORM_FIELD)
+#define GET_FIELD_PRIVATE(o) ev_form_field_get_instance_private (o)
static void
ev_form_field_init (EvFormField *field)
{
+ EvFormFieldPrivate *priv = GET_FIELD_PRIVATE (field);
+
field->page = NULL;
field->changed = FALSE;
field->is_read_only = FALSE;
- field->alt_ui_name = NULL;
+ priv->alt_ui_name = NULL;
}
static void
ev_form_field_finalize (GObject *object)
{
EvFormField *field = EV_FORM_FIELD (object);
+ EvFormFieldPrivate *priv = GET_FIELD_PRIVATE (field);
g_object_unref (field->page);
field->page = NULL;
g_clear_object (&field->activation_link);
- g_clear_pointer (&field->alt_ui_name, g_free);
+ g_clear_pointer (&priv->alt_ui_name, g_free);
(* G_OBJECT_CLASS (ev_form_field_parent_class)->finalize) (object);
}
@@ -70,6 +81,57 @@ ev_form_field_class_init (EvFormFieldClass *klass)
object_class->finalize = ev_form_field_finalize;
}
+/**
+ * ev_form_field_get_alternate_name
+ * @field: a #EvFormField
+ *
+ * Gets the alternate ui name of @field. This name is also commonly
+ * used by pdf producers/readers to show it as a tooltip when @field area
+ * is hovered by a pointing device (eg. mouse).
+ *
+ * Returns: (transfer full): a string.
+ *
+ * Since: 3.38
+ **/
+gchar *
+ev_form_field_get_alternate_name (EvFormField *field)
+{
+ EvFormFieldPrivate *priv;
+
+ g_return_val_if_fail (EV_IS_FORM_FIELD (field), NULL);
+
+ priv = GET_FIELD_PRIVATE (field);
+
+ return priv->alt_ui_name;
+}
+
+/**
+ * ev_form_field_set_alternate_name
+ * @field: a #EvFormField
+ * @alternatative_text:
+ *
+ * Sets the alternate ui name of @field. This name is also commonly
+ * used by pdf producers/readers to show it as a tooltip when @field area
+ * is hovered by a pointing device (eg. mouse).
+ *
+ * Since: 3.38
+ **/
+void
+ev_form_field_set_alternate_name (EvFormField *field,
+ gchar *alternative_text)
+{
+ EvFormFieldPrivate *priv;
+
+ g_return_if_fail (EV_IS_FORM_FIELD (field));
+
+ priv = GET_FIELD_PRIVATE (field);
+
+ if (priv->alt_ui_name)
+ g_clear_pointer (&priv->alt_ui_name, g_free);
+
+ priv->alt_ui_name = alternative_text;
+}
+
static void
ev_form_field_text_finalize (GObject *object)
{
diff --git a/libdocument/ev-form-field.h b/libdocument/ev-form-field.h
index 84344504..d0571a2a 100644
--- a/libdocument/ev-form-field.h
+++ b/libdocument/ev-form-field.h
@@ -113,7 +113,6 @@ struct _EvFormField
EvPage *page;
gboolean changed;
- gchar *alt_ui_name;
};
struct _EvFormFieldClass
diff --git a/libdocument/meson.build b/libdocument/meson.build
index 914815df..6b81c429 100644
--- a/libdocument/meson.build
+++ b/libdocument/meson.build
@@ -27,6 +27,7 @@ headers = files(
'ev-file-exporter.h',
'ev-file-helpers.h',
'ev-form-field.h',
+ 'ev-form-field-private.h',
'ev-image.h',
'ev-init.h',
'ev-layer.h',
diff --git a/libview/ev-view.c b/libview/ev-view.c
index e0171b4d..c52ecaf3 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -35,6 +35,7 @@
#include "ev-document-layers.h"
#include "ev-document-media.h"
#include "ev-document-misc.h"
+#include "ev-form-field-private.h"
#include "ev-pixbuf-cache.h"
#include "ev-page-cache.h"
#include "ev-view-marshal.h"
@@ -2331,7 +2332,7 @@ ev_view_handle_cursor_over_xy (EvView *view, gint x, gint y)
}
}
- if (link || annot || (field && field->alt_ui_name))
+ if (link || annot || (field && ev_form_field_get_alternate_name (field)))
g_object_set (view, "has-tooltip", TRUE, NULL);
}
@@ -5320,14 +5321,18 @@ ev_view_query_tooltip (GtkWidget *widget,
}
field = ev_view_get_form_field_at_location (view, x, y);
- if (field && field->alt_ui_name && *(field->alt_ui_name) != '\0') {
- GdkRectangle field_area;
+ if (field != NULL) {
+ gchar *alt_ui_name = ev_form_field_get_alternate_name (field);
- get_field_area (view, x, y, field, &field_area);
- gtk_tooltip_set_text (tooltip, field->alt_ui_name);
- gtk_tooltip_set_tip_area (tooltip, &field_area);
+ if (alt_ui_name && *(alt_ui_name) != '\0') {
+ GdkRectangle field_area;
- return TRUE;
+ get_field_area (view, x, y, field, &field_area);
+ gtk_tooltip_set_text (tooltip, alt_ui_name);
+ gtk_tooltip_set_tip_area (tooltip, &field_area);
+
+ return TRUE;
+ }
}
link = ev_view_get_link_at_location (view, x, y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]