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