diff options
Diffstat (limited to 'libdocument')
-rw-r--r-- | libdocument/Makefile.am | 4 | ||||
-rw-r--r-- | libdocument/ev-document-annotations.c | 2 | ||||
-rw-r--r-- | libdocument/ev-document-annotations.h | 23 | ||||
-rw-r--r-- | libdocument/ev-document-forms.c | 2 | ||||
-rw-r--r-- | libdocument/ev-document-forms.h | 135 | ||||
-rw-r--r-- | libdocument/ev-document-images.c | 2 | ||||
-rw-r--r-- | libdocument/ev-document-images.h | 19 | ||||
-rw-r--r-- | libdocument/ev-document-links.c | 7 | ||||
-rw-r--r-- | libdocument/ev-document-links.h | 35 | ||||
-rw-r--r-- | libdocument/ev-mapping-list.c | 146 | ||||
-rw-r--r-- | libdocument/ev-mapping-list.h (renamed from libdocument/ev-mapping.h) | 34 | ||||
-rw-r--r-- | libdocument/ev-mapping.c | 93 |
12 files changed, 282 insertions, 220 deletions
diff --git a/libdocument/Makefile.am b/libdocument/Makefile.am index dae6953..facf17c 100644 --- a/libdocument/Makefile.am +++ b/libdocument/Makefile.am @@ -35,7 +35,7 @@ INST_H_SRC_FILES = \ ev-link-action.h \ ev-link-dest.h \ ev-link.h \ - ev-mapping.h \ + ev-mapping-list.h \ ev-page.h \ ev-render-context.h \ ev-selection.h \ @@ -80,7 +80,7 @@ libevdocument_la_SOURCES= \ ev-debug.c \ ev-file-exporter.c \ ev-file-helpers.c \ - ev-mapping.c \ + ev-mapping-list.c \ ev-module.c \ ev-page.c \ ev-render-context.c \ diff --git a/libdocument/ev-document-annotations.c b/libdocument/ev-document-annotations.c index 4523fb4..6ccdd57 100644 --- a/libdocument/ev-document-annotations.c +++ b/libdocument/ev-document-annotations.c @@ -28,7 +28,7 @@ ev_document_annotations_default_init (EvDocumentAnnotationsInterface *klass) { } -GList * +EvMappingList * ev_document_annotations_get_annotations (EvDocumentAnnotations *document_annots, EvPage *page) { diff --git a/libdocument/ev-document-annotations.h b/libdocument/ev-document-annotations.h index 8f06b11..6da49d9 100644 --- a/libdocument/ev-document-annotations.h +++ b/libdocument/ev-document-annotations.h @@ -29,6 +29,7 @@ #include "ev-document.h" #include "ev-annotation.h" +#include "ev-mapping-list.h" G_BEGIN_DECLS @@ -47,20 +48,20 @@ struct _EvDocumentAnnotationsInterface GTypeInterface base_iface; /* Methods */ - GList *(* get_annotations) (EvDocumentAnnotations *document_annots, - EvPage *page); - void (* annotation_set_contents) (EvDocumentAnnotations *document_annots, - EvAnnotation *annot, - const gchar *contents); + EvMappingList *(* get_annotations) (EvDocumentAnnotations *document_annots, + EvPage *page); + void (* annotation_set_contents) (EvDocumentAnnotations *document_annots, + EvAnnotation *annot, + const gchar *contents); }; -GType ev_document_annotations_get_type (void) G_GNUC_CONST; -GList *ev_document_annotations_get_annotations (EvDocumentAnnotations *document_annots, - EvPage *page); +GType ev_document_annotations_get_type (void) G_GNUC_CONST; +EvMappingList *ev_document_annotations_get_annotations (EvDocumentAnnotations *document_annots, + EvPage *page); -void ev_document_annotations_annotation_set_contents (EvDocumentAnnotations *document_annots, - EvAnnotation *annot, - const gchar *contents); +void ev_document_annotations_annotation_set_contents (EvDocumentAnnotations *document_annots, + EvAnnotation *annot, + const gchar *contents); G_END_DECLS diff --git a/libdocument/ev-document-forms.c b/libdocument/ev-document-forms.c index 9e8fb0e..c6d558b 100644 --- a/libdocument/ev-document-forms.c +++ b/libdocument/ev-document-forms.c @@ -28,7 +28,7 @@ ev_document_forms_default_init (EvDocumentFormsInterface *klass) { } -GList * +EvMappingList * ev_document_forms_get_form_fields (EvDocumentForms *document_forms, EvPage *page) { diff --git a/libdocument/ev-document-forms.h b/libdocument/ev-document-forms.h index 3552467..32ec6a1 100644 --- a/libdocument/ev-document-forms.h +++ b/libdocument/ev-document-forms.h @@ -29,6 +29,7 @@ #include "ev-document.h" #include "ev-form-field.h" +#include "ev-mapping-list.h" G_BEGIN_DECLS @@ -47,78 +48,78 @@ struct _EvDocumentFormsInterface GTypeInterface base_iface; /* Methods */ - GList *(* get_form_fields) (EvDocumentForms *document_forms, - EvPage *page); - gchar *(* form_field_text_get_text) (EvDocumentForms *document_forms, - EvFormField *field); - void (* form_field_text_set_text) (EvDocumentForms *document_forms, - EvFormField *field, - const gchar *text); - gboolean (* form_field_button_get_state) (EvDocumentForms *document_forms, - EvFormField *field); - void (* form_field_button_set_state) (EvDocumentForms *document_forms, - EvFormField *field, - gboolean state); - gchar *(* form_field_choice_get_item) (EvDocumentForms *document_forms, - EvFormField *field, - gint index); - gint (* form_field_choice_get_n_items) (EvDocumentForms *document_forms, - EvFormField *field); - gboolean (* form_field_choice_is_item_selected) (EvDocumentForms *document_forms, - EvFormField *field, - gint index); - void (* form_field_choice_select_item) (EvDocumentForms *document_forms, - EvFormField *field, - gint index); - void (* form_field_choice_toggle_item) (EvDocumentForms *document_forms, - EvFormField *field, - gint index); - void (* form_field_choice_unselect_all) (EvDocumentForms *document_forms, - EvFormField *field); - void (* form_field_choice_set_text) (EvDocumentForms *document_forms, - EvFormField *field, - const gchar *text); - gchar *(* form_field_choice_get_text) (EvDocumentForms *document_forms, - EvFormField *field); + EvMappingList *(* get_form_fields) (EvDocumentForms *document_forms, + EvPage *page); + gchar *(* form_field_text_get_text) (EvDocumentForms *document_forms, + EvFormField *field); + void (* form_field_text_set_text) (EvDocumentForms *document_forms, + EvFormField *field, + const gchar *text); + gboolean (* form_field_button_get_state) (EvDocumentForms *document_forms, + EvFormField *field); + void (* form_field_button_set_state) (EvDocumentForms *document_forms, + EvFormField *field, + gboolean state); + gchar *(* form_field_choice_get_item) (EvDocumentForms *document_forms, + EvFormField *field, + gint index); + gint (* form_field_choice_get_n_items) (EvDocumentForms *document_forms, + EvFormField *field); + gboolean (* form_field_choice_is_item_selected) (EvDocumentForms *document_forms, + EvFormField *field, + gint index); + void (* form_field_choice_select_item) (EvDocumentForms *document_forms, + EvFormField *field, + gint index); + void (* form_field_choice_toggle_item) (EvDocumentForms *document_forms, + EvFormField *field, + gint index); + void (* form_field_choice_unselect_all) (EvDocumentForms *document_forms, + EvFormField *field); + void (* form_field_choice_set_text) (EvDocumentForms *document_forms, + EvFormField *field, + const gchar *text); + gchar *(* form_field_choice_get_text) (EvDocumentForms *document_forms, + EvFormField *field); }; -GType ev_document_forms_get_type (void) G_GNUC_CONST; -GList *ev_document_forms_get_form_fields (EvDocumentForms *document_forms, - EvPage *page); +GType ev_document_forms_get_type (void) G_GNUC_CONST; +EvMappingList *ev_document_forms_get_form_fields (EvDocumentForms *document_forms, + EvPage *page); -gchar *ev_document_forms_form_field_text_get_text (EvDocumentForms *document_forms, - EvFormField *field); -void ev_document_forms_form_field_text_set_text (EvDocumentForms *document_forms, - EvFormField *field, - const gchar *text); +gchar *ev_document_forms_form_field_text_get_text (EvDocumentForms *document_forms, + EvFormField *field); +void ev_document_forms_form_field_text_set_text (EvDocumentForms *document_forms, + EvFormField *field, + const gchar *text); -gboolean ev_document_forms_form_field_button_get_state (EvDocumentForms *document_forms, - EvFormField *field); -void ev_document_forms_form_field_button_set_state (EvDocumentForms *document_forms, - EvFormField *field, - gboolean state); +gboolean ev_document_forms_form_field_button_get_state (EvDocumentForms *document_forms, + EvFormField *field); +void ev_document_forms_form_field_button_set_state (EvDocumentForms *document_forms, + EvFormField *field, + gboolean state); -gchar *ev_document_forms_form_field_choice_get_item (EvDocumentForms *document_forms, - EvFormField *field, - gint index); -gint ev_document_forms_form_field_choice_get_n_items (EvDocumentForms *document_forms, - EvFormField *field); -gboolean ev_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document_forms, - EvFormField *field, - gint index); -void ev_document_forms_form_field_choice_select_item (EvDocumentForms *document_forms, - EvFormField *field, - gint index); -void ev_document_forms_form_field_choice_toggle_item (EvDocumentForms *document_forms, - EvFormField *field, - gint index); -void ev_document_forms_form_field_choice_unselect_all (EvDocumentForms *document_forms, - EvFormField *field); -void ev_document_forms_form_field_choice_set_text (EvDocumentForms *document_forms, - EvFormField *field, - const gchar *text); -gchar *ev_document_forms_form_field_choice_get_text (EvDocumentForms *document_forms, - EvFormField *field); +gchar *ev_document_forms_form_field_choice_get_item (EvDocumentForms *document_forms, + EvFormField *field, + gint index); +gint ev_document_forms_form_field_choice_get_n_items (EvDocumentForms *document_forms, + EvFormField *field); +gboolean ev_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document_forms, + EvFormField *field, + gint index); +void ev_document_forms_form_field_choice_select_item (EvDocumentForms *document_forms, + EvFormField *field, + gint index); +void ev_document_forms_form_field_choice_toggle_item (EvDocumentForms *document_forms, + EvFormField *field, + gint index); +void ev_document_forms_form_field_choice_unselect_all (EvDocumentForms *document_forms, + EvFormField *field); +void ev_document_forms_form_field_choice_set_text (EvDocumentForms *document_forms, + EvFormField *field, + const gchar *text); +gchar *ev_document_forms_form_field_choice_get_text (EvDocumentForms *document_forms, + EvFormField *field); G_END_DECLS diff --git a/libdocument/ev-document-images.c b/libdocument/ev-document-images.c index c03b8f9..a312bc7 100644 --- a/libdocument/ev-document-images.c +++ b/libdocument/ev-document-images.c @@ -28,7 +28,7 @@ ev_document_images_default_init (EvDocumentImagesInterface *klass) { } -GList * +EvMappingList * ev_document_images_get_image_mapping (EvDocumentImages *document_images, EvPage *page) { diff --git a/libdocument/ev-document-images.h b/libdocument/ev-document-images.h index d9f6b02..8a02869 100644 --- a/libdocument/ev-document-images.h +++ b/libdocument/ev-document-images.h @@ -30,6 +30,7 @@ #include "ev-document.h" #include "ev-image.h" +#include "ev-mapping-list.h" G_BEGIN_DECLS @@ -47,17 +48,17 @@ struct _EvDocumentImagesInterface { GTypeInterface base_iface; /* Methods */ - GList *(* get_image_mapping) (EvDocumentImages *document_images, - EvPage *page); - GdkPixbuf *(* get_image) (EvDocumentImages *document_images, - EvImage *image); + EvMappingList *(* get_image_mapping) (EvDocumentImages *document_images, + EvPage *page); + GdkPixbuf *(* get_image) (EvDocumentImages *document_images, + EvImage *image); }; -GType ev_document_images_get_type (void) G_GNUC_CONST; -GList *ev_document_images_get_image_mapping (EvDocumentImages *document_images, - EvPage *page); -GdkPixbuf *ev_document_images_get_image (EvDocumentImages *document_images, - EvImage *image); +GType ev_document_images_get_type (void) G_GNUC_CONST; +EvMappingList *ev_document_images_get_image_mapping (EvDocumentImages *document_images, + EvPage *page); +GdkPixbuf *ev_document_images_get_image (EvDocumentImages *document_images, + EvImage *image); G_END_DECLS diff --git a/libdocument/ev-document-links.c b/libdocument/ev-document-links.c index 7b31c4d..b8aae5d 100644 --- a/libdocument/ev-document-links.c +++ b/libdocument/ev-document-links.c @@ -54,16 +54,13 @@ ev_document_links_get_links_model (EvDocumentLinks *document_links) return retval; } -GList * +EvMappingList * ev_document_links_get_links (EvDocumentLinks *document_links, EvPage *page) { EvDocumentLinksInterface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links); - GList *retval; - retval = iface->get_links (document_links, page); - - return retval; + return iface->get_links (document_links, page); } EvLinkDest * diff --git a/libdocument/ev-document-links.h b/libdocument/ev-document-links.h index e6d9020..3614840 100644 --- a/libdocument/ev-document-links.h +++ b/libdocument/ev-document-links.h @@ -34,6 +34,7 @@ #include "ev-document.h" #include "ev-link.h" +#include "ev-mapping-list.h" G_BEGIN_DECLS @@ -60,26 +61,26 @@ struct _EvDocumentLinksInterface GTypeInterface base_iface; /* Methods */ - gboolean (* has_document_links) (EvDocumentLinks *document_links); - GtkTreeModel *(* get_links_model) (EvDocumentLinks *document_links); - GList *(* get_links) (EvDocumentLinks *document_links, - EvPage *page); - EvLinkDest *(* find_link_dest) (EvDocumentLinks *document_links, - const gchar *link_name); + gboolean (* has_document_links) (EvDocumentLinks *document_links); + GtkTreeModel *(* get_links_model) (EvDocumentLinks *document_links); + EvMappingList *(* get_links) (EvDocumentLinks *document_links, + EvPage *page); + EvLinkDest *(* find_link_dest) (EvDocumentLinks *document_links, + const gchar *link_name); }; -GType ev_document_links_get_type (void); -gboolean ev_document_links_has_document_links (EvDocumentLinks *document_links); -GtkTreeModel *ev_document_links_get_links_model (EvDocumentLinks *document_links); +GType ev_document_links_get_type (void) G_GNUC_CONST; +gboolean ev_document_links_has_document_links (EvDocumentLinks *document_links); +GtkTreeModel *ev_document_links_get_links_model (EvDocumentLinks *document_links); -GList *ev_document_links_get_links (EvDocumentLinks *document_links, - EvPage *page); -EvLinkDest *ev_document_links_find_link_dest (EvDocumentLinks *document_links, - const gchar *link_name); -gint ev_document_links_get_dest_page (EvDocumentLinks *document_links, - EvLinkDest *dest); -gchar *ev_document_links_get_dest_page_label(EvDocumentLinks *document_links, - EvLinkDest *dest); +EvMappingList *ev_document_links_get_links (EvDocumentLinks *document_links, + EvPage *page); +EvLinkDest *ev_document_links_find_link_dest (EvDocumentLinks *document_links, + const gchar *link_name); +gint ev_document_links_get_dest_page (EvDocumentLinks *document_links, + EvLinkDest *dest); +gchar *ev_document_links_get_dest_page_label (EvDocumentLinks *document_links, + EvLinkDest *dest); G_END_DECLS diff --git a/libdocument/ev-mapping-list.c b/libdocument/ev-mapping-list.c new file mode 100644 index 0000000..024cb49 --- /dev/null +++ b/libdocument/ev-mapping-list.c @@ -0,0 +1,146 @@ +/* ev-mapping.c + * this file is part of evince, a gnome document viewer + * + * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org> + * + * Evince 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. + * + * Evince is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "ev-mapping-list.h" + +struct _EvMappingList { + guint page; + GList *list; + GDestroyNotify data_destroy_func; + volatile gint ref_count; +}; + +EvMapping * +ev_mapping_list_find (EvMappingList *mapping_list, + gconstpointer data) +{ + GList *list; + + for (list = mapping_list->list; list; list = list->next) { + EvMapping *mapping = list->data; + + if (mapping->data == data) + return mapping; + } + + return NULL; +} + +EvMapping * +ev_mapping_list_find_custom (EvMappingList *mapping_list, + gconstpointer data, + GCompareFunc func) +{ + GList *list; + + for (list = mapping_list->list; list; list = list->next) { + EvMapping *mapping = list->data; + + if (!func (mapping->data, data)) + return mapping; + } + + return NULL; +} + +gpointer +ev_mapping_list_get_data (EvMappingList *mapping_list, + gdouble x, + gdouble y) +{ + GList *list; + + for (list = mapping_list->list; list; list = list->next) { + EvMapping *mapping = list->data; + + if ((x >= mapping->area.x1) && + (y >= mapping->area.y1) && + (x <= mapping->area.x2) && + (y <= mapping->area.y2)) { + return mapping->data; + } + } + + return NULL; +} + +GList * +ev_mapping_list_get_list (EvMappingList *mapping_list) +{ + return mapping_list ? mapping_list->list : NULL; +} + +guint +ev_mapping_list_get_page (EvMappingList *mapping_list) +{ + return mapping_list->page; +} + +EvMappingList * +ev_mapping_list_new (guint page, + GList *list, + GDestroyNotify data_destroy_func) +{ + EvMappingList *mapping_list; + + g_return_val_if_fail (data_destroy_func != NULL, NULL); + + mapping_list = g_slice_new (EvMappingList); + mapping_list->page = page; + mapping_list->list = list; + mapping_list->data_destroy_func = data_destroy_func; + mapping_list->ref_count = 1; + + return mapping_list; +} + +EvMappingList * +ev_mapping_list_ref (EvMappingList *mapping_list) +{ + g_return_val_if_fail (mapping_list != NULL, NULL); + g_return_val_if_fail (mapping_list->ref_count > 0, mapping_list); + + g_atomic_int_add (&mapping_list->ref_count, 1); + + return mapping_list; +} + +static void +mapping_list_free_foreach (EvMapping *mapping, + GDestroyNotify destroy_func) +{ + destroy_func (mapping->data); + g_free (mapping); +} + +void +ev_mapping_list_unref (EvMappingList *mapping_list) +{ + g_return_if_fail (mapping_list != NULL); + g_return_if_fail (mapping_list->ref_count > 0); + + if (g_atomic_int_exchange_and_add (&mapping_list->ref_count, -1) - 1 == 0) { + g_list_foreach (mapping_list->list, + (GFunc)mapping_list_free_foreach, + mapping_list->data_destroy_func); + g_list_free (mapping_list->list); + g_slice_free (EvMappingList, mapping_list); + } +} diff --git a/libdocument/ev-mapping.h b/libdocument/ev-mapping-list.h index b6024c5..b207736 100644 --- a/libdocument/ev-mapping.h +++ b/libdocument/ev-mapping-list.h @@ -22,24 +22,32 @@ #error "Only <evince-document.h> can be included directly." #endif -#ifndef EV_MAPPING_H -#define EV_MAPPING_H +#ifndef EV_MAPPING_LIST_H +#define EV_MAPPING_LIST_H #include "ev-document.h" G_BEGIN_DECLS -EvMapping *ev_mapping_list_find (GList *mapping_list, - gconstpointer data); -EvMapping *ev_mapping_list_find_custom (GList *mapping_list, - gconstpointer data, - GCompareFunc func); -gpointer ev_mapping_list_get_data (GList *mapping_list, - gdouble x, - gdouble y); -void ev_mapping_list_free (GList *mapping_list, - GDestroyNotify destroy_func); +typedef struct _EvMappingList EvMappingList; + +EvMappingList *ev_mapping_list_new (guint page, + GList *list, + GDestroyNotify data_destroy_func); +EvMappingList *ev_mapping_list_ref (EvMappingList *mapping_list); +void ev_mapping_list_unref (EvMappingList *mapping_list); + +guint ev_mapping_list_get_page (EvMappingList *mapping_list); +GList *ev_mapping_list_get_list (EvMappingList *mapping_list); +EvMapping *ev_mapping_list_find (EvMappingList *mapping_list, + gconstpointer data); +EvMapping *ev_mapping_list_find_custom (EvMappingList *mapping_list, + gconstpointer data, + GCompareFunc func); +gpointer ev_mapping_list_get_data (EvMappingList *mapping_list, + gdouble x, + gdouble y); G_END_DECLS -#endif /* EV_MAPPING_H */ +#endif /* EV_MAPPING_LIST_H */ diff --git a/libdocument/ev-mapping.c b/libdocument/ev-mapping.c deleted file mode 100644 index 2b2c653..0000000 --- a/libdocument/ev-mapping.c +++ /dev/null @@ -1,93 +0,0 @@ -/* ev-mapping.c - * this file is part of evince, a gnome document viewer - * - * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org> - * - * Evince 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. - * - * Evince is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "ev-mapping.h" - -EvMapping * -ev_mapping_list_find (GList *mapping_list, - gconstpointer data) -{ - GList *list; - - for (list = mapping_list; list; list = list->next) { - EvMapping *mapping = list->data; - - if (mapping->data == data) - return mapping; - } - - return NULL; -} - -EvMapping * -ev_mapping_list_find_custom (GList *mapping_list, - gconstpointer data, - GCompareFunc func) -{ - GList *list; - - for (list = mapping_list; list; list = list->next) { - EvMapping *mapping = list->data; - - if (!func (mapping->data, data)) - return mapping; - } - - return NULL; -} - -gpointer -ev_mapping_list_get_data (GList *mapping_list, - gdouble x, - gdouble y) -{ - GList *list; - - for (list = mapping_list; list; list = list->next) { - EvMapping *mapping = list->data; - - if ((x >= mapping->area.x1) && - (y >= mapping->area.y1) && - (x <= mapping->area.x2) && - (y <= mapping->area.y2)) { - return mapping->data; - } - } - - return NULL; -} - -static void -mapping_list_free_foreach (EvMapping *mapping, - GDestroyNotify destroy_func) -{ - destroy_func (mapping->data); - g_free (mapping); -} - -void -ev_mapping_list_free (GList *mapping_list, - GDestroyNotify destroy_func) -{ - g_list_foreach (mapping_list, - (GFunc)mapping_list_free_foreach, - destroy_func); - g_list_free (mapping_list); -} |