]> www.fi.muni.cz Git - evince.git/blobdiff - libdocument/ev-annotation.c
[libdocument] Use G_DEFINE_INTERFACE() macro to define EvAnnotationMarkup iface
[evince.git] / libdocument / ev-annotation.c
index 7d2810fe8c9f6f12aacdc6661939e0a1efa69ca8..21ffc0a138ea618783cb74281fd4d2cfc0d32117 100644 (file)
@@ -16,7 +16,7 @@
  *
  * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #include "config.h"
 #include "ev-annotation.h"
 
 
-static void ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface);
-static void ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface);
+static void ev_annotation_markup_default_init          (EvAnnotationMarkupInterface *iface);
+static void ev_annotation_text_markup_iface_init       (EvAnnotationMarkupInterface *iface);
+static void ev_annotation_attachment_markup_iface_init (EvAnnotationMarkupInterface *iface);
 
 enum {
        PROP_0,
        PROP_LABEL,
        PROP_OPACITY,
+       PROP_HAS_POPUP,
        PROP_RECTANGLE,
        PROP_IS_OPEN
 };
 
 G_DEFINE_ABSTRACT_TYPE (EvAnnotation, ev_annotation, G_TYPE_OBJECT)
-GType
-ev_annotation_markup_get_type (void)
-{
-       static volatile gsize g_define_type_id__volatile = 0;
-
-       if (g_once_init_enter (&g_define_type_id__volatile)) {
-               GType g_define_type_id;
-               const GTypeInfo our_info = {
-                       sizeof (EvAnnotationMarkupIface),
-                       (GBaseInitFunc) ev_annotation_markup_iface_base_init,
-                       NULL,
-               };
-
-               g_define_type_id = g_type_register_static (G_TYPE_INTERFACE,
-                                                          "EvAnnotationMarkup",
-                                                          &our_info, (GTypeFlags)0);
-               g_type_interface_add_prerequisite (g_define_type_id, EV_TYPE_ANNOTATION);
-
-               g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
-       }
-
-       return g_define_type_id__volatile;
-}
-
+G_DEFINE_INTERFACE (EvAnnotationMarkup, ev_annotation_markup, EV_TYPE_ANNOTATION)
 G_DEFINE_TYPE_WITH_CODE (EvAnnotationText, ev_annotation_text, EV_TYPE_ANNOTATION,
         {
                 G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
                                        ev_annotation_text_markup_iface_init);
         });
+G_DEFINE_TYPE_WITH_CODE (EvAnnotationAttachment, ev_annotation_attachment, EV_TYPE_ANNOTATION,
+        {
+                G_IMPLEMENT_INTERFACE (EV_TYPE_ANNOTATION_MARKUP,
+                                       ev_annotation_attachment_markup_iface_init);
+        });
 
 /* EvAnnotation */
 static void
@@ -108,27 +92,17 @@ ev_annotation_class_init (EvAnnotationClass *klass)
        g_object_class->finalize = ev_annotation_finalize;
 }
 
-EvAnnotation *
-ev_annotation_text_new (EvPage *page)
-{
-       EvAnnotation *annot;
-
-       annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_TEXT, NULL));
-       annot->page = g_object_ref (page);
-
-       return annot;
-}
-
 /* EvAnnotationMarkup */
 typedef struct {
        gchar   *label;
        gdouble  opacity;
+       gboolean has_popup;
        gboolean is_open;
        EvRectangle *rectangle;
 } EvAnnotationMarkupProps;
 
 static void
-ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface)
+ev_annotation_markup_default_init (EvAnnotationMarkupInterface *iface)
 {
        static gboolean initialized = FALSE;
 
@@ -147,6 +121,13 @@ ev_annotation_markup_iface_base_init (EvAnnotationMarkupIface *iface)
                                                                          G_MAXDOUBLE,
                                                                          0,
                                                                          G_PARAM_READWRITE));
+               g_object_interface_install_property (iface,
+                                                    g_param_spec_boolean ("has_popup",
+                                                                          "Has popup",
+                                                                          "Whether the markup annotation has "
+                                                                          "a popup window associated",
+                                                                          TRUE,
+                                                                          G_PARAM_READWRITE));
                g_object_interface_install_property (iface,
                                                     g_param_spec_boxed ("rectangle",
                                                                         "Rectangle",
@@ -211,6 +192,9 @@ ev_annotation_markup_set_property (GObject      *object,
        case PROP_OPACITY:
                props->opacity = g_value_get_double (value);
                break;
+       case PROP_HAS_POPUP:
+               props->has_popup = g_value_get_boolean (value);
+               break;
        case PROP_RECTANGLE:
                ev_rectangle_free (props->rectangle);
                props->rectangle = g_value_dup_boxed (value);
@@ -240,6 +224,9 @@ ev_annotation_markup_get_property (GObject    *object,
        case PROP_OPACITY:
                g_value_set_double (value, props->opacity);
                break;
+       case PROP_HAS_POPUP:
+               g_value_set_boolean (value, props->has_popup);
+               break;
        case PROP_RECTANGLE:
                g_value_set_boxed (value, props->rectangle);
                break;
@@ -259,6 +246,7 @@ ev_annotation_markup_class_install_properties (GObjectClass *klass)
 
        g_object_class_override_property (klass, PROP_LABEL, "label");
        g_object_class_override_property (klass, PROP_OPACITY, "opacity");
+       g_object_class_override_property (klass, PROP_HAS_POPUP, "has_popup");
        g_object_class_override_property (klass, PROP_RECTANGLE, "rectangle");
        g_object_class_override_property (klass, PROP_IS_OPEN, "is_open");
 }
@@ -306,6 +294,18 @@ ev_annotation_markup_set_opacity (EvAnnotationMarkup *markup,
        g_object_set (G_OBJECT (markup), "opacity", opacity, NULL);
 }
 
+gboolean
+ev_annotation_markup_has_popup (EvAnnotationMarkup *markup)
+{
+       gboolean retval;
+
+       g_return_val_if_fail (EV_IS_ANNOTATION_MARKUP (markup), FALSE);
+
+       g_object_get (G_OBJECT (markup), "has_popup", &retval, NULL);
+
+       return retval;
+}
+
 void
 ev_annotation_markup_get_rectangle (EvAnnotationMarkup *markup,
                                    EvRectangle        *ev_rect)
@@ -355,7 +355,66 @@ ev_annotation_text_class_init (EvAnnotationTextClass *klass)
 }
 
 static void
-ev_annotation_text_markup_iface_init (EvAnnotationMarkupIface *iface)
+ev_annotation_text_markup_iface_init (EvAnnotationMarkupInterface *iface)
+{
+}
+
+EvAnnotation *
+ev_annotation_text_new (EvPage *page)
+{
+       EvAnnotation *annot;
+
+       annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_TEXT, NULL));
+       annot->page = g_object_ref (page);
+
+       return annot;
+}
+
+/* EvAnnotationAttachment */
+static void
+ev_annotation_attachment_finalize (GObject *object)
+{
+       EvAnnotationAttachment *annot = EV_ANNOTATION_ATTACHMENT (object);
+
+       if (annot->attachment) {
+               g_object_unref (annot->attachment);
+               annot->attachment = NULL;
+       }
+
+       G_OBJECT_CLASS (ev_annotation_attachment_parent_class)->finalize (object);
+}
+
+static void
+ev_annotation_attachment_init (EvAnnotationAttachment *annot)
+{
+}
+
+static void
+ev_annotation_attachment_class_init (EvAnnotationAttachmentClass *klass)
+{
+       GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+       ev_annotation_markup_class_install_properties (g_object_class);
+
+       g_object_class->finalize = ev_annotation_attachment_finalize;
+}
+
+static void
+ev_annotation_attachment_markup_iface_init (EvAnnotationMarkupInterface *iface)
 {
 }
 
+EvAnnotation *
+ev_annotation_attachment_new (EvPage       *page,
+                             EvAttachment *attachment)
+{
+       EvAnnotation *annot;
+
+       g_return_val_if_fail (EV_IS_ATTACHMENT (attachment), NULL);
+
+       annot = EV_ANNOTATION (g_object_new (EV_TYPE_ANNOTATION_ATTACHMENT, NULL));
+       annot->page = g_object_ref (page);
+       EV_ANNOTATION_ATTACHMENT (annot)->attachment = g_object_ref (attachment);
+
+       return annot;
+}