Blame src/ibusattribute.c

Packit Service 1d8f1c
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
Packit Service 1d8f1c
/* vim:set et sts=4: */
Packit Service 1d8f1c
/* IBus - The Input Bus
Packit Service 1d8f1c
 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
Packit Service 1d8f1c
 * Copyright (C) 2008-2010 Red Hat, Inc.
Packit Service 1d8f1c
 *
Packit Service 1d8f1c
 * This library is free software; you can redistribute it and/or
Packit Service 1d8f1c
 * modify it under the terms of the GNU Lesser General Public
Packit Service 1d8f1c
 * License as published by the Free Software Foundation; either
Packit Service 1d8f1c
 * version 2.1 of the License, or (at your option) any later version.
Packit Service 1d8f1c
 *
Packit Service 1d8f1c
 * This library is distributed in the hope that it will be useful,
Packit Service 1d8f1c
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 1d8f1c
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 1d8f1c
 * Lesser General Public License for more details.
Packit Service 1d8f1c
 *
Packit Service 1d8f1c
 * You should have received a copy of the GNU Lesser General Public
Packit Service 1d8f1c
 * License along with this library; if not, write to the Free Software
Packit Service 1d8f1c
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
Packit Service 1d8f1c
 * USA
Packit Service 1d8f1c
 */
Packit Service 1d8f1c
#include "ibusattribute.h"
Packit Service 1d8f1c
Packit Service 1d8f1c
/* functions prototype */
Packit Service 1d8f1c
// static void         ibus_attribute_destroy      (IBusAttribute          *attr);
Packit Service 1d8f1c
static gboolean     ibus_attribute_serialize    (IBusAttribute          *attr,
Packit Service 1d8f1c
                                                 GVariantBuilder        *builder);
Packit Service 1d8f1c
static gint         ibus_attribute_deserialize  (IBusAttribute          *attr,
Packit Service 1d8f1c
                                                 GVariant               *variant);
Packit Service 1d8f1c
static gboolean     ibus_attribute_copy         (IBusAttribute          *dest,
Packit Service 1d8f1c
                                                 const IBusAttribute    *src);
Packit Service 1d8f1c
Packit Service 1d8f1c
G_DEFINE_TYPE (IBusAttribute, ibus_attribute, IBUS_TYPE_SERIALIZABLE)
Packit Service 1d8f1c
Packit Service 1d8f1c
static void
Packit Service 1d8f1c
ibus_attribute_class_init (IBusAttributeClass *class)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class);
Packit Service 1d8f1c
Packit Service 1d8f1c
    serializable_class->serialize   = (IBusSerializableSerializeFunc) ibus_attribute_serialize;
Packit Service 1d8f1c
    serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_attribute_deserialize;
Packit Service 1d8f1c
    serializable_class->copy        = (IBusSerializableCopyFunc) ibus_attribute_copy;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
static void
Packit Service 1d8f1c
ibus_attribute_init (IBusAttribute *attr)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
static gboolean
Packit Service 1d8f1c
ibus_attribute_serialize (IBusAttribute   *attr,
Packit Service 1d8f1c
                          GVariantBuilder *builder)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    gboolean retval;
Packit Service 1d8f1c
Packit Service 1d8f1c
    retval = IBUS_SERIALIZABLE_CLASS (ibus_attribute_parent_class)->serialize ((IBusSerializable *) attr, builder);
Packit Service 1d8f1c
    g_return_val_if_fail (retval, FALSE);
Packit Service 1d8f1c
Packit Service 1d8f1c
    g_variant_builder_add (builder, "u", attr->type);
Packit Service 1d8f1c
    g_variant_builder_add (builder, "u", attr->value);
Packit Service 1d8f1c
    g_variant_builder_add (builder, "u", attr->start_index);
Packit Service 1d8f1c
    g_variant_builder_add (builder, "u", attr->end_index);
Packit Service 1d8f1c
Packit Service 1d8f1c
    return TRUE;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
static gint
Packit Service 1d8f1c
ibus_attribute_deserialize (IBusAttribute *attr,
Packit Service 1d8f1c
                            GVariant      *variant)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    gint retval;
Packit Service 1d8f1c
Packit Service 1d8f1c
    retval = IBUS_SERIALIZABLE_CLASS (ibus_attribute_parent_class)->deserialize ((IBusSerializable *) attr, variant);
Packit Service 1d8f1c
    g_return_val_if_fail (retval, 0);
Packit Service 1d8f1c
Packit Service 1d8f1c
    g_variant_get_child (variant, retval++, "u", &attr->type);
Packit Service 1d8f1c
    g_variant_get_child (variant, retval++, "u", &attr->value);
Packit Service 1d8f1c
    g_variant_get_child (variant, retval++, "u", &attr->start_index);
Packit Service 1d8f1c
    g_variant_get_child (variant, retval++, "u", &attr->end_index);
Packit Service 1d8f1c
Packit Service 1d8f1c
    return retval;
Packit Service 1d8f1c
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
static gboolean
Packit Service 1d8f1c
ibus_attribute_copy (IBusAttribute       *dest,
Packit Service 1d8f1c
                     const IBusAttribute *src)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    gboolean retval;
Packit Service 1d8f1c
Packit Service 1d8f1c
    retval = IBUS_SERIALIZABLE_CLASS (ibus_attribute_parent_class)->copy ((IBusSerializable *)dest,
Packit Service 1d8f1c
                                 (IBusSerializable *)src);
Packit Service 1d8f1c
    g_return_val_if_fail (retval, FALSE);
Packit Service 1d8f1c
Packit Service 1d8f1c
    g_return_val_if_fail (IBUS_IS_ATTRIBUTE (dest), FALSE);
Packit Service 1d8f1c
    g_return_val_if_fail (IBUS_IS_ATTRIBUTE (src), FALSE);
Packit Service 1d8f1c
Packit Service 1d8f1c
    dest->type  = src->type;
Packit Service 1d8f1c
    dest->value = src->value;
Packit Service 1d8f1c
    dest->start_index = src->start_index;
Packit Service 1d8f1c
    dest->end_index = src->end_index;
Packit Service 1d8f1c
Packit Service 1d8f1c
    return TRUE;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
IBusAttribute *
Packit Service 1d8f1c
ibus_attribute_new (guint type,
Packit Service 1d8f1c
                    guint value,
Packit Service 1d8f1c
                    guint start_index,
Packit Service 1d8f1c
                    guint end_index)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    g_return_val_if_fail (
Packit Service 1d8f1c
        type == IBUS_ATTR_TYPE_UNDERLINE  ||
Packit Service 1d8f1c
        type == IBUS_ATTR_TYPE_FOREGROUND ||
Packit Service 1d8f1c
        type == IBUS_ATTR_TYPE_BACKGROUND, NULL);
Packit Service 1d8f1c
Packit Service 1d8f1c
    IBusAttribute *attr = IBUS_ATTRIBUTE (g_object_new (IBUS_TYPE_ATTRIBUTE, NULL));
Packit Service 1d8f1c
Packit Service 1d8f1c
    attr->type = type;
Packit Service 1d8f1c
    attr->value = value;
Packit Service 1d8f1c
    attr->start_index = start_index;
Packit Service 1d8f1c
    attr->end_index = end_index;
Packit Service 1d8f1c
Packit Service 1d8f1c
    return attr;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
guint
Packit Service 1d8f1c
ibus_attribute_get_attr_type (IBusAttribute *attr)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    return attr->type;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
guint
Packit Service 1d8f1c
ibus_attribute_get_value (IBusAttribute *attr)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    return attr->value;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
guint
Packit Service 1d8f1c
ibus_attribute_get_start_index (IBusAttribute *attr)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    return attr->start_index;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
guint
Packit Service 1d8f1c
ibus_attribute_get_end_index (IBusAttribute *attr)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    return attr->end_index;
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
IBusAttribute *
Packit Service 1d8f1c
ibus_attr_underline_new (guint underline_type,
Packit Service 1d8f1c
                         guint start_index,
Packit Service 1d8f1c
                         guint end_index)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    g_return_val_if_fail (
Packit Service 1d8f1c
        underline_type == IBUS_ATTR_UNDERLINE_NONE   ||
Packit Service 1d8f1c
        underline_type == IBUS_ATTR_UNDERLINE_SINGLE ||
Packit Service 1d8f1c
        underline_type == IBUS_ATTR_UNDERLINE_DOUBLE ||
Packit Service 1d8f1c
        underline_type == IBUS_ATTR_UNDERLINE_LOW, NULL);
Packit Service 1d8f1c
Packit Service 1d8f1c
    return ibus_attribute_new (IBUS_ATTR_TYPE_UNDERLINE,
Packit Service 1d8f1c
                               underline_type,
Packit Service 1d8f1c
                               start_index,
Packit Service 1d8f1c
                               end_index);
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
IBusAttribute *
Packit Service 1d8f1c
ibus_attr_foreground_new (guint color,
Packit Service 1d8f1c
                          guint start_index,
Packit Service 1d8f1c
                          guint end_index)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    return ibus_attribute_new (IBUS_ATTR_TYPE_FOREGROUND,
Packit Service 1d8f1c
                               color,
Packit Service 1d8f1c
                               start_index,
Packit Service 1d8f1c
                               end_index);
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
IBusAttribute *
Packit Service 1d8f1c
ibus_attr_background_new (guint color,
Packit Service 1d8f1c
                          guint start_index,
Packit Service 1d8f1c
                          guint end_index)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    return ibus_attribute_new (IBUS_ATTR_TYPE_BACKGROUND,
Packit Service 1d8f1c
                               color,
Packit Service 1d8f1c
                               start_index,
Packit Service 1d8f1c
                               end_index);
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c