Introduce zathura_annotation_is_markup_annotation function

This commit is contained in:
Moritz Lipp 2012-05-04 02:29:47 +02:00
parent 312392acc8
commit 724ecbd966
3 changed files with 75 additions and 51 deletions

View file

@ -16,18 +16,19 @@ struct zathura_annotation_s {
void* user_data; /**< Custom data */ void* user_data; /**< Custom data */
union { union {
struct {
char* label; /**< Label */
char* subject; /**< Subject of the annotation */
zathura_annotation_popup_t* popup; /**< Optional popup */
time_t creation_date; /**< Creation date */
} markup;
struct { struct {
zathura_annotation_text_icon_t icon; /**< The icon of the text annotation */ zathura_annotation_text_icon_t icon; /**< The icon of the text annotation */
zathura_annotation_text_state_t state; /**< The state of the text annotation */ zathura_annotation_text_state_t state; /**< The state of the text annotation */
bool opened; /**< Open status of the text annotation */ bool opened; /**< Open status of the text annotation */
} text; } text;
} data; } data;
struct {
char* label; /**< Label */
char* subject; /**< Subject of the annotation */
zathura_annotation_popup_t* popup; /**< Optional popup */
time_t creation_date; /**< Creation date */
} markup;
}; };
struct zathura_annotation_popup_s { struct zathura_annotation_popup_s {
@ -47,19 +48,18 @@ zathura_annotation_new(zathura_annotation_type_t type)
} }
switch (type) { switch (type) {
case ZATHURA_ANNOTATION_MARKUP:
annotation->data.markup.creation_date = (time_t) -1;
break;
case ZATHURA_ANNOTATION_TEXT: case ZATHURA_ANNOTATION_TEXT:
annotation->data.text.icon = ZATHURA_ANNOTATION_TEXT_ICON_UNKNOWN; break;
annotation->data.text.state = ZATHURA_ANNOTATION_TEXT_STATE_UNKNOWN;
default: default:
free(annotation); free(annotation);
return NULL; return NULL;
} }
annotation->type = type; annotation->type = type;
annotation->modification_date = (time_t) -1; annotation->modification_date = (time_t) -1;
annotation->markup.creation_date = (time_t) -1;
annotation->data.text.icon = ZATHURA_ANNOTATION_TEXT_ICON_UNKNOWN;
annotation->data.text.state = ZATHURA_ANNOTATION_TEXT_STATE_UNKNOWN;
return annotation; return annotation;
} }
@ -79,22 +79,16 @@ zathura_annotation_free(zathura_annotation_t* annotation)
free(annotation->content); free(annotation->content);
} }
switch (annotation->type) { if (annotation->markup.label != NULL) {
case ZATHURA_ANNOTATION_MARKUP: free(annotation->markup.label);
if (annotation->data.markup.label != NULL) { }
free(annotation->data.markup.label);
}
if (annotation->data.markup.subject != NULL) { if (annotation->markup.subject != NULL) {
free(annotation->data.markup.subject); free(annotation->markup.subject);
} }
if (annotation->data.markup.popup != NULL) { if (annotation->markup.popup != NULL) {
zathura_annotation_popup_free(annotation->data.markup.popup); zathura_annotation_popup_free(annotation->markup.popup);
}
break;
default:
break;
} }
free(annotation); free(annotation);
@ -130,6 +124,29 @@ zathura_annotation_get_type(zathura_annotation_t* annotation)
return annotation->type; return annotation->type;
} }
bool
zathura_annotation_is_markup_annotation(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return false;
}
switch (annotation->type) {
case ZATHURA_ANNOTATION_TEXT:
case ZATHURA_ANNOTATION_FREE_TEXT:
case ZATHURA_ANNOTATION_LINE:
case ZATHURA_ANNOTATION_STAMP:
case ZATHURA_ANNOTATION_POLYGON:
case ZATHURA_ANNOTATION_CARET:
case ZATHURA_ANNOTATION_INK:
case ZATHURA_ANNOTATION_FILE_ATTACHMENT:
case ZATHURA_ANNOTATION_SOUND:
return true;
default:
return false;
}
}
zathura_annotation_flag_t zathura_annotation_flag_t
zathura_annotation_get_flags(zathura_annotation_t* annotation) zathura_annotation_get_flags(zathura_annotation_t* annotation)
{ {
@ -270,96 +287,96 @@ zathura_annotation_set_position(zathura_annotation_t* annotation,
char* char*
zathura_annotation_markup_get_label(zathura_annotation_t* annotation) zathura_annotation_markup_get_label(zathura_annotation_t* annotation)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
return NULL; return NULL;
} }
return annotation->data.markup.label; return annotation->markup.label;
} }
void void
zathura_annotation_markup_set_label(zathura_annotation_t* annotation, const char* label) zathura_annotation_markup_set_label(zathura_annotation_t* annotation, const char* label)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
return; return;
} }
if (annotation->data.markup.label != NULL) { if (annotation->markup.label != NULL) {
free(annotation->data.markup.label); free(annotation->markup.label);
} }
if (label != NULL) { if (label != NULL) {
annotation->data.markup.label = __strdup(label); annotation->markup.label = __strdup(label);
} else { } else {
annotation->data.markup.label = NULL; annotation->markup.label = NULL;
} }
} }
char* char*
zathura_annotation_markup_get_subject(zathura_annotation_t* annotation) zathura_annotation_markup_get_subject(zathura_annotation_t* annotation)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
return NULL; return NULL;
} }
return annotation->data.markup.subject; return annotation->markup.subject;
} }
void void
zathura_annotation_markup_set_subject(zathura_annotation_t* annotation, const char* subject) zathura_annotation_markup_set_subject(zathura_annotation_t* annotation, const char* subject)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
return; return;
} }
if (annotation->data.markup.subject != NULL) { if (annotation->markup.subject != NULL) {
free(annotation->data.markup.subject); free(annotation->markup.subject);
} }
if (subject != NULL) { if (subject != NULL) {
annotation->data.markup.subject = __strdup(subject); annotation->markup.subject = __strdup(subject);
} else { } else {
annotation->data.markup.subject = NULL; annotation->markup.subject = NULL;
} }
} }
zathura_annotation_popup_t* zathura_annotation_popup_t*
zathura_annotation_markup_get_popup(zathura_annotation_t* annotation) zathura_annotation_markup_get_popup(zathura_annotation_t* annotation)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
return NULL; return NULL;
} }
return annotation->data.markup.popup; return annotation->markup.popup;
} }
void void
zathura_annotation_markup_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup) zathura_annotation_markup_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP || popup == NULL) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false || popup == NULL) {
return; return;
} }
annotation->data.markup.popup = popup; annotation->markup.popup = popup;
} }
time_t time_t
zathura_annotation_markup_get_creation_date(zathura_annotation_t* annotation) zathura_annotation_markup_get_creation_date(zathura_annotation_t* annotation)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
return (time_t) -1; return (time_t) -1;
} }
return annotation->data.markup.creation_date; return annotation->markup.creation_date;
} }
void void
zathura_annotation_markup_set_creation_date(zathura_annotation_t* annotation, time_t creation_date) zathura_annotation_markup_set_creation_date(zathura_annotation_t* annotation, time_t creation_date)
{ {
if (annotation == NULL || annotation->type != ZATHURA_ANNOTATION_MARKUP) { if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
return; return;
} }
annotation->data.markup.creation_date = creation_date; annotation->markup.creation_date = creation_date;
} }
zathura_annotation_text_icon_t zathura_annotation_text_icon_t

View file

@ -39,7 +39,6 @@ typedef enum zathura_annotation_type_s {
ZATHURA_ANNOTATION_TRAP_NET, ZATHURA_ANNOTATION_TRAP_NET,
ZATHURA_ANNOTATION_WATERMARK, ZATHURA_ANNOTATION_WATERMARK,
ZATHURA_ANNOTATION_3D, ZATHURA_ANNOTATION_3D,
ZATHURA_ANNOTATION_MARKUP
} zathura_annotation_type_t; } zathura_annotation_type_t;
typedef enum zathura_annotation_flag_s { typedef enum zathura_annotation_flag_s {
@ -119,6 +118,14 @@ void zathura_annotation_set_data(zathura_annotation_t* annotation, void* data);
*/ */
zathura_annotation_type_t zathura_annotation_get_type(zathura_annotation_t* annotation); zathura_annotation_type_t zathura_annotation_get_type(zathura_annotation_t* annotation);
/**
* True if the given annotation is a markup annotation
*
* @param annotation The annotation
* @return true whether the annotation is a markup annotation otherwise false
*/
bool zathura_annotation_is_markup_annotation(zathura_annotation_t* annotation);
/** /**
* Returns the flags of the annotation * Returns the flags of the annotation
* *

View file

@ -772,7 +772,7 @@ cb_menu_annotation_add(GtkMenuItem* item, ZathuraPage* page)
/* create new annotation */ /* create new annotation */
zathura_annotation_t* annotation = zathura_annotation_t* annotation =
zathura_annotation_new(ZATHURA_ANNOTATION_MARKUP); zathura_annotation_new(ZATHURA_ANNOTATION_TEXT);
if (annotation == NULL) { if (annotation == NULL) {
return; return;
} }