Blame gtksourceview/gtksourcetag.c

Packit a7d494
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
Packit a7d494
/* gtksourcetag.c
Packit a7d494
 * This file is part of GtkSourceView
Packit a7d494
 *
Packit a7d494
 * Copyright (C) 2015 - Université Catholique de Louvain
Packit a7d494
 *
Packit a7d494
 * GtkSourceView is free software; you can redistribute it and/or
Packit a7d494
 * modify it under the terms of the GNU Lesser General Public
Packit a7d494
 * License as published by the Free Software Foundation; either
Packit a7d494
 * version 2.1 of the License, or (at your option) any later version.
Packit a7d494
 *
Packit a7d494
 * GtkSourceView is distributed in the hope that it will be useful,
Packit a7d494
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a7d494
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a7d494
 * Lesser General Public License for more details.
Packit a7d494
 *
Packit a7d494
 * You should have received a copy of the GNU Lesser General Public
Packit a7d494
 * License along with this library; if not, write to the Free Software
Packit a7d494
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit a7d494
 *
Packit a7d494
 * Author: Sébastien Wilmet
Packit a7d494
 */
Packit a7d494
Packit a7d494
#ifdef HAVE_CONFIG_H
Packit a7d494
#include <config.h>
Packit a7d494
#endif
Packit a7d494
Packit a7d494
#include "gtksourcetag.h"
Packit a7d494
Packit a7d494
/**
Packit a7d494
 * SECTION:tag
Packit a7d494
 * @Short_description: A tag that can be applied to text in a GtkSourceBuffer
Packit a7d494
 * @Title: GtkSourceTag
Packit a7d494
 * @See_also: #GtkSourceBuffer
Packit a7d494
 *
Packit a7d494
 * #GtkSourceTag is a subclass of #GtkTextTag that adds properties useful for
Packit a7d494
 * the GtkSourceView library.
Packit a7d494
 *
Packit a7d494
 * If, for a certain tag, #GtkTextTag is sufficient, it's better that you create
Packit a7d494
 * a #GtkTextTag, not a #GtkSourceTag.
Packit a7d494
 */
Packit a7d494
Packit a7d494
typedef struct _GtkSourceTagPrivate GtkSourceTagPrivate;
Packit a7d494
Packit a7d494
struct _GtkSourceTagPrivate
Packit a7d494
{
Packit a7d494
	guint draw_spaces : 1;
Packit a7d494
	guint draw_spaces_set : 1;
Packit a7d494
};
Packit a7d494
Packit a7d494
enum
Packit a7d494
{
Packit a7d494
	PROP_0,
Packit a7d494
	PROP_DRAW_SPACES,
Packit a7d494
	PROP_DRAW_SPACES_SET,
Packit a7d494
};
Packit a7d494
Packit a7d494
G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceTag, gtk_source_tag, GTK_TYPE_TEXT_TAG)
Packit a7d494
Packit a7d494
static void
Packit a7d494
gtk_source_tag_get_property (GObject    *object,
Packit a7d494
			     guint       prop_id,
Packit a7d494
			     GValue     *value,
Packit a7d494
			     GParamSpec *pspec)
Packit a7d494
{
Packit a7d494
	GtkSourceTagPrivate *priv;
Packit a7d494
Packit a7d494
	priv = gtk_source_tag_get_instance_private (GTK_SOURCE_TAG (object));
Packit a7d494
Packit a7d494
	switch (prop_id)
Packit a7d494
	{
Packit a7d494
		case PROP_DRAW_SPACES:
Packit a7d494
			g_value_set_boolean (value, priv->draw_spaces);
Packit a7d494
			break;
Packit a7d494
Packit a7d494
		case PROP_DRAW_SPACES_SET:
Packit a7d494
			g_value_set_boolean (value, priv->draw_spaces_set);
Packit a7d494
			break;
Packit a7d494
Packit a7d494
		default:
Packit a7d494
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit a7d494
			break;
Packit a7d494
	}
Packit a7d494
}
Packit a7d494
Packit a7d494
static void
Packit a7d494
gtk_source_tag_set_property (GObject      *object,
Packit a7d494
			     guint         prop_id,
Packit a7d494
			     const GValue *value,
Packit a7d494
			     GParamSpec   *pspec)
Packit a7d494
{
Packit a7d494
	GtkSourceTag *tag;
Packit a7d494
	GtkSourceTagPrivate *priv;
Packit a7d494
	gboolean size_changed = FALSE;
Packit a7d494
Packit a7d494
	tag = GTK_SOURCE_TAG (object);
Packit a7d494
	priv = gtk_source_tag_get_instance_private (tag);
Packit a7d494
Packit a7d494
	switch (prop_id)
Packit a7d494
	{
Packit a7d494
		case PROP_DRAW_SPACES:
Packit a7d494
			priv->draw_spaces = g_value_get_boolean (value);
Packit a7d494
			priv->draw_spaces_set = TRUE;
Packit a7d494
			g_object_notify (object, "draw-spaces-set");
Packit a7d494
			break;
Packit a7d494
Packit a7d494
		case PROP_DRAW_SPACES_SET:
Packit a7d494
			priv->draw_spaces_set = g_value_get_boolean (value);
Packit a7d494
			break;
Packit a7d494
Packit a7d494
		default:
Packit a7d494
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit a7d494
			break;
Packit a7d494
	}
Packit a7d494
Packit a7d494
	gtk_text_tag_changed (GTK_TEXT_TAG (tag), size_changed);
Packit a7d494
}
Packit a7d494
Packit a7d494
static void
Packit a7d494
gtk_source_tag_class_init (GtkSourceTagClass *klass)
Packit a7d494
{
Packit a7d494
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
Packit a7d494
Packit a7d494
	object_class->get_property = gtk_source_tag_get_property;
Packit a7d494
	object_class->set_property = gtk_source_tag_set_property;
Packit a7d494
Packit a7d494
	/**
Packit a7d494
	 * GtkSourceTag:draw-spaces:
Packit a7d494
	 *
Packit a7d494
	 * Whether to draw white spaces. This property takes precedence over the value
Packit a7d494
	 * defined by the GtkSourceSpaceDrawer's #GtkSourceSpaceDrawer:matrix property
Packit a7d494
	 * (only where the tag is applied).
Packit a7d494
	 *
Packit a7d494
	 * Setting this property also changes #GtkSourceTag:draw-spaces-set to
Packit a7d494
	 * %TRUE.
Packit a7d494
	 *
Packit a7d494
	 * Since: 3.20
Packit a7d494
	 */
Packit a7d494
	g_object_class_install_property (object_class,
Packit a7d494
					 PROP_DRAW_SPACES,
Packit a7d494
					 g_param_spec_boolean ("draw-spaces",
Packit a7d494
							       "Draw Spaces",
Packit a7d494
							       "",
Packit a7d494
							       FALSE,
Packit a7d494
							       G_PARAM_READWRITE |
Packit a7d494
							       G_PARAM_STATIC_STRINGS));
Packit a7d494
Packit a7d494
	/**
Packit a7d494
	 * GtkSourceTag:draw-spaces-set:
Packit a7d494
	 *
Packit a7d494
	 * Whether the #GtkSourceTag:draw-spaces property is set and must be
Packit a7d494
	 * taken into account.
Packit a7d494
	 *
Packit a7d494
	 * Since: 3.20
Packit a7d494
	 */
Packit a7d494
	g_object_class_install_property (object_class,
Packit a7d494
					 PROP_DRAW_SPACES_SET,
Packit a7d494
					 g_param_spec_boolean ("draw-spaces-set",
Packit a7d494
							       "Draw Spaces Set",
Packit a7d494
							       "",
Packit a7d494
							       FALSE,
Packit a7d494
							       G_PARAM_READWRITE |
Packit a7d494
							       G_PARAM_STATIC_STRINGS));
Packit a7d494
}
Packit a7d494
Packit a7d494
static void
Packit a7d494
gtk_source_tag_init (GtkSourceTag *tag)
Packit a7d494
{
Packit a7d494
}
Packit a7d494
Packit a7d494
/**
Packit a7d494
 * gtk_source_tag_new:
Packit a7d494
 * @name: (nullable): tag name, or %NULL.
Packit a7d494
 *
Packit a7d494
 * Creates a #GtkSourceTag. Configure the tag using object arguments,
Packit a7d494
 * i.e. using g_object_set().
Packit a7d494
 *
Packit a7d494
 * For usual cases, gtk_source_buffer_create_source_tag() is more convenient to
Packit a7d494
 * use.
Packit a7d494
 *
Packit a7d494
 * Returns: a new #GtkSourceTag.
Packit a7d494
 * Since: 3.20
Packit a7d494
 */
Packit a7d494
GtkTextTag *
Packit a7d494
gtk_source_tag_new (const gchar *name)
Packit a7d494
{
Packit a7d494
	return g_object_new (GTK_SOURCE_TYPE_TAG,
Packit a7d494
			     "name", name,
Packit a7d494
			     NULL);
Packit a7d494
}