1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4
* Copyright (C) Philip Withnall 2011 <philip@tecnocode.co.uk>
6
* Almanah is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Almanah is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Almanah. If not, see <http://www.gnu.org/licenses/>.
23
#include "hyperlink-tag.h"
25
static void constructed (GObject *object);
26
static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
27
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
28
static void finalize (GObject *object);
30
struct _AlmanahHyperlinkTagPrivate {
38
G_DEFINE_TYPE (AlmanahHyperlinkTag, almanah_hyperlink_tag, GTK_TYPE_TEXT_TAG)
41
almanah_hyperlink_tag_class_init (AlmanahHyperlinkTagClass *klass)
43
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
45
g_type_class_add_private (klass, sizeof (AlmanahHyperlinkTagPrivate));
47
gobject_class->constructed = constructed;
48
gobject_class->get_property = get_property;
49
gobject_class->set_property = set_property;
50
gobject_class->finalize = finalize;
52
g_object_class_install_property (gobject_class, PROP_URI,
53
g_param_spec_string ("uri",
54
"URI", "The URI which this hyperlink points to.",
56
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
60
almanah_hyperlink_tag_init (AlmanahHyperlinkTag *self)
62
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_HYPERLINK_TAG, AlmanahHyperlinkTagPrivate);
63
self->priv->uri = NULL;
67
constructed (GObject *object)
69
/* Chain up to the parent class */
70
G_OBJECT_CLASS (almanah_hyperlink_tag_parent_class)->constructed (object);
72
/* Set our default appearance */
75
"underline", PANGO_UNDERLINE_SINGLE,
80
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
82
AlmanahHyperlinkTagPrivate *priv = ALMANAH_HYPERLINK_TAG (object)->priv;
84
switch (property_id) {
86
g_value_set_string (value, priv->uri);
89
/* We don't have any other property... */
90
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
96
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
98
switch (property_id) {
100
almanah_hyperlink_tag_set_uri (ALMANAH_HYPERLINK_TAG (object), g_value_get_string (value));
103
/* We don't have any other property... */
104
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
110
finalize (GObject *object)
112
AlmanahHyperlinkTagPrivate *priv = ALMANAH_HYPERLINK_TAG (object)->priv;
116
/* Chain up to the parent class */
117
G_OBJECT_CLASS (almanah_hyperlink_tag_parent_class)->finalize (object);
120
AlmanahHyperlinkTag *
121
almanah_hyperlink_tag_new (const gchar *uri)
123
return g_object_new (ALMANAH_TYPE_HYPERLINK_TAG,
129
almanah_hyperlink_tag_get_uri (AlmanahHyperlinkTag *self)
131
g_return_val_if_fail (ALMANAH_IS_HYPERLINK_TAG (self), NULL);
133
return self->priv->uri;
137
almanah_hyperlink_tag_set_uri (AlmanahHyperlinkTag *self, const gchar *uri)
139
g_return_if_fail (ALMANAH_IS_HYPERLINK_TAG (self));
140
g_return_if_fail (uri != NULL && *uri != '\0');
142
g_free (self->priv->uri);
143
self->priv->uri = g_strdup (uri);;
144
g_object_notify (G_OBJECT (self), "uri");