From 7f8f8969effbeed357d2ec6c0aa86e12339ad2eb Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 20 May 2012 13:10:31 +0200 Subject: [PATCH] Introduced page_add_annotation / page_remove_annotation --- annotations.h | 6 +++--- page-widget.c | 5 ++--- page.c | 23 +++++++++++++++++++---- page.h | 17 ++++++++++++++--- plugin-api.h | 18 ++++++++++++++---- 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/annotations.h b/annotations.h index 22c7ade..f465fc4 100644 --- a/annotations.h +++ b/annotations.h @@ -6,12 +6,12 @@ #include #include -#include "page.h" -#include "types.h" - typedef struct zathura_annotation_s zathura_annotation_t; typedef struct zathura_annotation_popup_s zathura_annotation_popup_t; +#include "page.h" +#include "types.h" + typedef enum zathura_annotation_type_s { ZATHURA_ANNOTATION_UNKNOWN, ZATHURA_ANNOTATION_TEXT, diff --git a/page-widget.c b/page-widget.c index 5e15fdb..f39af3a 100644 --- a/page-widget.c +++ b/page-widget.c @@ -807,9 +807,8 @@ cb_menu_annotation_add(GtkMenuItem* item, ZathuraPage* page) } } - /* save to current list */ - girara_list_append(priv->annotations.list, annotation); - zathura_page_set_annotations(priv->page, priv->annotations.list); + /* add annotation */ + zathura_page_add_annotation(priv->page, annotation); /* retrieve new list */ girara_list_free(priv->annotations.list); diff --git a/page.c b/page.c index 02abbbf..33b2f9c 100644 --- a/page.c +++ b/page.c @@ -356,18 +356,33 @@ zathura_page_get_annotations(zathura_page_t* page, zathura_error_t* error) } zathura_error_t -zathura_page_set_annotations(zathura_page_t* page, girara_list_t* annotations) +zathura_page_add_annotation(zathura_page_t* page, zathura_annotation_t* annotation) { - if (page == NULL || page->document == NULL ) { + if (page == NULL || page->document == NULL || annotation == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } zathura_plugin_t* plugin = zathura_document_get_plugin(page->document); - if (plugin->functions.page_set_annotations == NULL) { + if (plugin->functions.page_add_annotation == NULL) { return ZATHURA_ERROR_NOT_IMPLEMENTED; } - return plugin->functions.page_set_annotations(page, page->data, annotations); + return plugin->functions.page_add_annotation(page, page->data, annotation); +} + +zathura_error_t +zathura_page_remove_annotation(zathura_page_t* page, zathura_annotation_t* annotation) +{ + if (page == NULL || page->document == NULL || annotation == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + zathura_plugin_t* plugin = zathura_document_get_plugin(page->document); + if (plugin->functions.page_remove_annotation == NULL) { + return ZATHURA_ERROR_NOT_IMPLEMENTED; + } + + return plugin->functions.page_remove_annotation(page, page->data, annotation); } zathura_error_t diff --git a/page.h b/page.h index bde0a3a..8cab8c0 100644 --- a/page.h +++ b/page.h @@ -6,6 +6,7 @@ #include #include +#include "annotations.h" #include "types.h" /** @@ -203,14 +204,24 @@ char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, girara_list_t* zathura_page_get_annotations(zathura_page_t* page, zathura_error_t* error); /** - * Sets the list of annotations (see \ref zathura_annotation_t) + * Adds an annotation (see \ref zathura_annotation_t) to the page * * @param page Page - * @param annotations List of annotations + * @param annotation The annotation that should be added * @return ZATHURA_ERROR_OK when no error occured, otherwise see * zathura_error_t */ -zathura_error_t zathura_page_set_annotations(zathura_page_t* page, girara_list_t* annotations); +zathura_error_t zathura_page_add_annotation(zathura_page_t* page, zathura_annotation_t* annotation); + +/** + * Removes an annotation (see \ref zathura_annotation_t) to the page + * + * @param page Page + * @param annotation The annotation that should be removed + * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * zathura_error_t + */ +zathura_error_t zathura_page_remove_annotation(zathura_page_t* page, zathura_annotation_t* annotation); /** * Render page diff --git a/plugin-api.h b/plugin-api.h index 110989a..30c9323 100644 --- a/plugin-api.h +++ b/plugin-api.h @@ -147,9 +147,14 @@ typedef char* (*zathura_plugin_page_get_text_t)(zathura_page_t* page, void* data typedef girara_list_t* (*zathura_plugin_page_get_annotations_t)(zathura_page_t* page, void* data, zathura_error_t* error); /** - * Set list of annotations + * Add annotation */ -typedef zathura_error_t (*zathura_plugin_page_set_annotations_t)(zathura_page_t* page, void* data, girara_list_t* annotations); +typedef zathura_error_t (*zathura_plugin_page_add_annotation_t)(zathura_page_t* page, void* data, zathura_annotation_t* annotation); + +/** + * Remove annotation + */ +typedef zathura_error_t (*zathura_plugin_page_remove_annotation_t)(zathura_page_t* page, void* data, zathura_annotation_t* annotation); /** * Renders the page @@ -245,9 +250,14 @@ struct zathura_plugin_functions_s zathura_plugin_page_get_annotations_t page_get_annotations; /** - * Set list of annotations + * Add annotation */ - zathura_plugin_page_set_annotations_t page_set_annotations; + zathura_plugin_page_add_annotation_t page_add_annotation; + + /** + * Remove annotation + */ + zathura_plugin_page_remove_annotation_t page_remove_annotation; /** * Renders the page