Introduced page_add_annotation / page_remove_annotation

This commit is contained in:
Moritz Lipp 2012-05-20 13:10:31 +02:00
parent d02d49c79b
commit 7f8f8969ef
5 changed files with 52 additions and 17 deletions

View file

@ -6,12 +6,12 @@
#include <time.h> #include <time.h>
#include <stdbool.h> #include <stdbool.h>
#include "page.h"
#include "types.h"
typedef struct zathura_annotation_s zathura_annotation_t; typedef struct zathura_annotation_s zathura_annotation_t;
typedef struct zathura_annotation_popup_s zathura_annotation_popup_t; typedef struct zathura_annotation_popup_s zathura_annotation_popup_t;
#include "page.h"
#include "types.h"
typedef enum zathura_annotation_type_s { typedef enum zathura_annotation_type_s {
ZATHURA_ANNOTATION_UNKNOWN, ZATHURA_ANNOTATION_UNKNOWN,
ZATHURA_ANNOTATION_TEXT, ZATHURA_ANNOTATION_TEXT,

View file

@ -807,9 +807,8 @@ cb_menu_annotation_add(GtkMenuItem* item, ZathuraPage* page)
} }
} }
/* save to current list */ /* add annotation */
girara_list_append(priv->annotations.list, annotation); zathura_page_add_annotation(priv->page, annotation);
zathura_page_set_annotations(priv->page, priv->annotations.list);
/* retrieve new list */ /* retrieve new list */
girara_list_free(priv->annotations.list); girara_list_free(priv->annotations.list);

23
page.c
View file

@ -356,18 +356,33 @@ zathura_page_get_annotations(zathura_page_t* page, zathura_error_t* error)
} }
zathura_error_t 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; return ZATHURA_ERROR_INVALID_ARGUMENTS;
} }
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document); 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 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 zathura_error_t

17
page.h
View file

@ -6,6 +6,7 @@
#include <girara/datastructures.h> #include <girara/datastructures.h>
#include <cairo.h> #include <cairo.h>
#include "annotations.h"
#include "types.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); 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 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 * @return ZATHURA_ERROR_OK when no error occured, otherwise see
* zathura_error_t * 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 * Render page

View file

@ -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); 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 * Renders the page
@ -245,9 +250,14 @@ struct zathura_plugin_functions_s
zathura_plugin_page_get_annotations_t page_get_annotations; 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 * Renders the page