mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-14 18:33:46 +01:00
Introduce new annotation functions
This commit is contained in:
parent
5954da8572
commit
caccf809fc
241
annotations.c
241
annotations.c
@ -13,7 +13,21 @@ struct zathura_annotation_s {
|
||||
time_t modification_date; /**< Modification date */
|
||||
zathura_page_t* page; /**< Zathura page */
|
||||
zathura_rectangle_t position; /**< Position of the annotation */
|
||||
void* data; /**< Custom data */
|
||||
void* user_data; /**< Custom data */
|
||||
|
||||
union {
|
||||
struct {
|
||||
char* label; /**< Label */
|
||||
char* subject; /**< Subject of the annotation */
|
||||
zathura_annotation_popup_t* popup; /**< Optional popup */
|
||||
} markup;
|
||||
} data;
|
||||
};
|
||||
|
||||
struct zathura_annotation_popup_s {
|
||||
double opacity; /**< The opacity of the popup */
|
||||
zathura_rectangle_t position; /**< Position of the annotation */
|
||||
bool opened; /**< true if popup is opened */
|
||||
};
|
||||
|
||||
static char* __strdup(const char* string);
|
||||
@ -54,6 +68,24 @@ zathura_annotation_free(zathura_annotation_t* annotation)
|
||||
free(annotation->content);
|
||||
}
|
||||
|
||||
switch (annotation->type) {
|
||||
case ZATHURA_ANNOTATION_MARKUP:
|
||||
if (annotation->data.markup.label != NULL) {
|
||||
free(annotation->data.markup.label);
|
||||
}
|
||||
|
||||
if (annotation->data.markup.subject != NULL) {
|
||||
free(annotation->data.markup.subject);
|
||||
}
|
||||
|
||||
if (annotation->data.markup.popup != NULL) {
|
||||
zathura_annotation_popup_free(annotation->data.markup.popup);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free(annotation);
|
||||
}
|
||||
|
||||
@ -64,7 +96,7 @@ zathura_annotation_get_data(zathura_annotation_t* annotation)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return annotation->data;
|
||||
return annotation->user_data;
|
||||
}
|
||||
|
||||
void
|
||||
@ -74,7 +106,7 @@ zathura_annotation_set_data(zathura_annotation_t* annotation, void* data)
|
||||
return;
|
||||
}
|
||||
|
||||
annotation->data = data;
|
||||
annotation->user_data = data;
|
||||
}
|
||||
|
||||
zathura_annotation_type_t
|
||||
@ -195,34 +227,205 @@ zathura_annotation_set_page(zathura_annotation_t* annotation, zathura_page_t* pa
|
||||
annotation->page = page;
|
||||
}
|
||||
|
||||
bool
|
||||
zathura_annotation_get_position(zathura_annotation_t* annotation,
|
||||
zathura_rectangle_t* rectangle)
|
||||
zathura_rectangle_t
|
||||
zathura_annotation_get_position(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL || rectangle == NULL) {
|
||||
return false;
|
||||
zathura_rectangle_t rectangle = { 0, 0, 0, 0 };
|
||||
|
||||
if (annotation != NULL) {
|
||||
rectangle.x1 = annotation->position.x1;
|
||||
rectangle.x2 = annotation->position.x2;
|
||||
rectangle.y1 = annotation->position.y1;
|
||||
rectangle.y2 = annotation->position.y2;
|
||||
}
|
||||
|
||||
rectangle->x1 = annotation->position.x1;
|
||||
rectangle->x2 = annotation->position.x2;
|
||||
rectangle->y1 = annotation->position.y1;
|
||||
rectangle->y2 = annotation->position.y2;
|
||||
|
||||
return true;
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_set_position(zathura_annotation_t* annotation,
|
||||
zathura_rectangle_t rectangle)
|
||||
zathura_rectangle_t position)
|
||||
{
|
||||
if (annotation == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
annotation->position.x1 = rectangle.x1;
|
||||
annotation->position.x2 = rectangle.x2;
|
||||
annotation->position.y1 = rectangle.y1;
|
||||
annotation->position.y2 = rectangle.y2;
|
||||
annotation->position.x1 = position.x1;
|
||||
annotation->position.x2 = position.x2;
|
||||
annotation->position.y1 = position.y1;
|
||||
annotation->position.y2 = position.y2;
|
||||
}
|
||||
|
||||
char*
|
||||
zathura_annotation_markup_get_label(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return annotation->data.markup.label;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_markup_set_label(zathura_annotation_t* annotation, const char* label)
|
||||
{
|
||||
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (annotation->data.markup.label != NULL) {
|
||||
free(annotation->data.markup.label);
|
||||
}
|
||||
|
||||
if (label != NULL) {
|
||||
annotation->data.markup.label = __strdup(label);
|
||||
} else {
|
||||
annotation->data.markup.label = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
zathura_annotation_markup_get_subject(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return annotation->data.markup.subject;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_markup_set_subject(zathura_annotation_t* annotation, const char* subject)
|
||||
{
|
||||
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) {
|
||||
return;
|
||||
}
|
||||
if (annotation->data.markup.subject != NULL) {
|
||||
free(annotation->data.markup.subject);
|
||||
}
|
||||
|
||||
if (subject != NULL) {
|
||||
annotation->data.markup.subject = __strdup(subject);
|
||||
} else {
|
||||
annotation->data.markup.subject = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
zathura_annotation_popup_t*
|
||||
zathura_annotation_markup_get_popup(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return annotation->data.markup.popup;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_markup_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP || popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
annotation->data.markup.popup = popup;
|
||||
}
|
||||
|
||||
zathura_annotation_popup_t*
|
||||
zathura_annotation_popup_new()
|
||||
{
|
||||
zathura_annotation_popup_t* popup = calloc(1, sizeof(zathura_annotation_popup_t));
|
||||
if (popup == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
popup->opacity = 1.0;
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_popup_free(zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(popup);
|
||||
}
|
||||
|
||||
zathura_rectangle_t
|
||||
zathura_annotation_popup_get_position(zathura_annotation_popup_t* popup)
|
||||
{
|
||||
zathura_rectangle_t rectangle = { 0, 0, 0, 0 };
|
||||
|
||||
if (popup != NULL) {
|
||||
rectangle.x1 = popup->position.x1;
|
||||
rectangle.x2 = popup->position.x2;
|
||||
rectangle.y1 = popup->position.y1;
|
||||
rectangle.y2 = popup->position.y2;
|
||||
}
|
||||
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_popup_set_position(zathura_annotation_popup_t* popup, zathura_rectangle_t position)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
popup->position.x1 = position.x1;
|
||||
popup->position.x2 = position.x2;
|
||||
popup->position.y1 = position.y1;
|
||||
popup->position.y2 = position.y2;
|
||||
}
|
||||
|
||||
double
|
||||
zathura_annotation_popup_get_opacity(zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return popup->opacity;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_popup_set_opacity(zathura_annotation_popup_t* popup, double opacity)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (opacity < 0) {
|
||||
popup->opacity = 0;
|
||||
} else if (opacity > 1) {
|
||||
popup->opacity = 1;
|
||||
} else {
|
||||
popup->opacity = opacity;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
zathura_annotation_popup_get_open_status(zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return popup->opened;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_popup_set_open_status(zathura_annotation_popup_t* popup, bool opened)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
popup->opened = opened;
|
||||
}
|
||||
|
||||
static char*
|
||||
|
116
annotations.h
116
annotations.h
@ -4,11 +4,13 @@
|
||||
#define ANNOTATION_H
|
||||
|
||||
#include <time.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "page.h"
|
||||
#include "types.h"
|
||||
|
||||
typedef struct zathura_annotation_s zathura_annotation_t;
|
||||
typedef struct zathura_annotation_popup_s zathura_annotation_popup_t;
|
||||
|
||||
typedef enum zathura_annotation_type_s {
|
||||
ZATHURA_ANNOTATION_UNKNOWN,
|
||||
@ -178,10 +180,9 @@ void zathura_annotation_set_page_index(zathura_annotation_t* annotation, zathura
|
||||
* rectangle
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param rectangle The coordinates of the annotation
|
||||
* @return true if the position could be retrieved otherwise false
|
||||
* @return The position of the annotation
|
||||
*/
|
||||
bool zathura_annotation_get_position(zathura_annotation_t* annotation, zathura_rectangle_t* rectangle);
|
||||
zathura_rectangle_t zathura_annotation_get_position(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the new position of the annotation
|
||||
@ -189,9 +190,116 @@ bool zathura_annotation_get_position(zathura_annotation_t* annotation, zathura_r
|
||||
* @param annotation The annotation
|
||||
* @param rectangle The rectangle containing the new position information
|
||||
*/
|
||||
void zathura_annotation_set_position(zathura_annotation_t* annotation, zathura_rectangle_t rectangle);
|
||||
void zathura_annotation_set_position(zathura_annotation_t* annotation, zathura_rectangle_t position);
|
||||
|
||||
/**
|
||||
* Gets the current label of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return The label or NULL
|
||||
*/
|
||||
char* zathura_annotation_markup_get_label(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the label of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param label The new label of the markup annotation
|
||||
*/
|
||||
void zathura_annotation_markup_set_label(zathura_annotation_t* annotation, const char* label);
|
||||
|
||||
/**
|
||||
* Returns the subject of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return The subject or NULL
|
||||
*/
|
||||
char* zathura_annotation_markup_get_subject(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the new subject of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param subject The new subject of the markup annotation
|
||||
*/
|
||||
void zathura_annotation_markup_set_subject(zathura_annotation_t* annotation, const char* subject);
|
||||
|
||||
/**
|
||||
* Sets the annotation popup of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return The popup (if available) from the markup annotation
|
||||
*/
|
||||
zathura_annotation_popup_t* zathura_annotation_markup_get_popup(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the new popup for the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param popup The new popup for the markup annotation
|
||||
*/
|
||||
void zathura_annotation_markup_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Creates a new annotation popup
|
||||
*
|
||||
* @return The popup or NULL if an error occured
|
||||
*/
|
||||
zathura_annotation_popup_t* zathura_annotation_popup_new();
|
||||
|
||||
/**
|
||||
* Frees the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
*/
|
||||
void zathura_annotation_popup_free(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Returns the position of the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @return The position of the annotation popup
|
||||
*/
|
||||
zathura_rectangle_t zathura_annotation_popup_get_position(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Sets the position of the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @param position The new position of the annotation popup
|
||||
*/
|
||||
void zathura_annotation_popup_set_position(zathura_annotation_popup_t* popup, zathura_rectangle_t position);
|
||||
|
||||
/**
|
||||
* Returns the opacity of the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @return The opacity of the annotation popup
|
||||
*/
|
||||
double zathura_annotation_popup_get_opacity(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Sets the opacity of the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @param opacity The new value for the opacity
|
||||
*/
|
||||
void zathura_annotation_popup_set_opacity(zathura_annotation_popup_t* popup, double opacity);
|
||||
|
||||
/**
|
||||
* Returns whether the popup is opened or not
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @return true if the popup is opened otherwise false
|
||||
*/
|
||||
bool zathura_annotation_popup_get_open_status(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Sets the open status of the popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @param opened The new status
|
||||
*/
|
||||
void zathura_annotation_popup_set_open_status(zathura_annotation_popup_t* popup, bool opened);
|
||||
|
||||
#endif // ANNOTATION_H
|
||||
|
@ -682,13 +682,10 @@ zathura_page_widget_popup_menu(GtkWidget* widget, GdkEventButton* event)
|
||||
|
||||
zathura_annotation_t* annotation = NULL;
|
||||
GIRARA_LIST_FOREACH(priv->annotations.list, zathura_annotation_t*, iter, annot)
|
||||
zathura_rectangle_t rect;
|
||||
if (zathura_annotation_get_position(annot, &rect) == true) {
|
||||
rect = recalc_rectangle(priv->page, rect);
|
||||
zathura_rectangle_t rect = recalc_rectangle(priv->page, zathura_annotation_get_position(annot));
|
||||
if (rect.x1 <= event->x && rect.x2 >= event->x && rect.y1 <= event->y && rect.y2 >= event->y) {
|
||||
annotation = annot;
|
||||
}
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(priv->annotations.list, zathura_annotation_t*, iter, annotation);
|
||||
|
||||
if (annotation != NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user