Blame src/ibustext.h

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-2013 Peng Huang <shawn.p.huang@gmail.com>
Packit 3ff832
 * Copyright (C) 2008-2013 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
Packit 3ff832
#if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION)
Packit 3ff832
#error "Only <ibus.h> can be included directly"
Packit 3ff832
#endif
Packit 3ff832
Packit 3ff832
#ifndef __IBUS_TEXT_H_
Packit 3ff832
#define __IBUS_TEXT_H_
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * SECTION: ibustext
Packit 3ff832
 * @short_description: Text with decorating information.
Packit 3ff832
 *
Packit 3ff832
 * An IBusText is the main text object in IBus.
Packit 3ff832
 * The text is decorated according to associated IBusAttribute,
Packit 3ff832
 * e.g. the foreground/background color, underline, and
Packit 3ff832
 * applied scope.
Packit 3ff832
 *
Packit 3ff832
 * see_also: #IBusAttribute
Packit 3ff832
 */
Packit 3ff832
Packit 3ff832
#include "ibusserializable.h"
Packit 3ff832
#include "ibusattrlist.h"
Packit 3ff832
Packit 3ff832
/*
Packit 3ff832
 * Type macros.
Packit 3ff832
 */
Packit 3ff832
/* define IBusText macros */
Packit 3ff832
#define IBUS_TYPE_TEXT             \
Packit 3ff832
    (ibus_text_get_type ())
Packit 3ff832
#define IBUS_TEXT(obj)             \
Packit 3ff832
    (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_TEXT, IBusText))
Packit 3ff832
#define IBUS_TEXT_CLASS(klass)     \
Packit 3ff832
    (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_TEXT, IBusTextClass))
Packit 3ff832
#define IBUS_IS_TEXT(obj)          \
Packit 3ff832
    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_TEXT))
Packit 3ff832
#define IBUS_IS_TEXT_CLASS(klass)  \
Packit 3ff832
    (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_TEXT))
Packit 3ff832
#define IBUS_TEXT_GET_CLASS(obj)   \
Packit 3ff832
    (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_TEXT, IBusTextClass))
Packit 3ff832
Packit 3ff832
G_BEGIN_DECLS
Packit 3ff832
Packit 3ff832
typedef struct _IBusText IBusText;
Packit 3ff832
typedef struct _IBusTextClass IBusTextClass;
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * IBusText:
Packit 3ff832
 * @is_static: Whether @text is static, i.e., no need and will not be freed. Only TRUE if IBusText is newed from ibus_text_new_from_static_string().
Packit 3ff832
 * @text: The string content of IBusText in UTF-8.
Packit 3ff832
 * @attrs: Associated IBusAttributes.
Packit 3ff832
 *
Packit 3ff832
 * A text object in IBus.
Packit 3ff832
 */
Packit 3ff832
struct _IBusText {
Packit 3ff832
    IBusSerializable parent;
Packit 3ff832
Packit 3ff832
    /* members */
Packit 3ff832
    /*< public >*/
Packit 3ff832
    gboolean is_static;
Packit 3ff832
    gchar  *text;
Packit 3ff832
    IBusAttrList *attrs;
Packit 3ff832
};
Packit 3ff832
Packit 3ff832
struct _IBusTextClass {
Packit 3ff832
    IBusSerializableClass parent;
Packit 3ff832
};
Packit 3ff832
Packit 3ff832
GType            ibus_text_get_type                 (void);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_new_from_string:
Packit 3ff832
 * @str: An text string to be set.
Packit 3ff832
 *
Packit 3ff832
 * Creates a new #IBusText from a string.
Packit 3ff832
 * @str will be duplicated in #IBusText, so feel free to free @str after this
Packit 3ff832
 * function.
Packit 3ff832
 *
Packit 3ff832
 * Returns: A newly allocated #IBusText.
Packit 3ff832
 */
Packit 3ff832
IBusText        *ibus_text_new_from_string          (const gchar    *str);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_new_from_ucs4:
Packit 3ff832
 * @str: An text string to be set.
Packit 3ff832
 *
Packit 3ff832
 * Creates a new #IBusText from an UCS-4 encoded string.
Packit 3ff832
 * @str will be duplicated in IBusText, so feel free to free @str after this
Packit 3ff832
 * function.
Packit 3ff832
 *
Packit 3ff832
 * Returns: A newly allocated #IBusText.
Packit 3ff832
 */
Packit 3ff832
IBusText        *ibus_text_new_from_ucs4            (const gunichar *str);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_new_from_static_string: (skip)
Packit 3ff832
 * @str: An text string to be set.
Packit 3ff832
 *
Packit 3ff832
 * Creates a new #IBusText from a static string.
Packit 3ff832
 *
Packit 3ff832
 * Since @str is a static string which won't be freed.
Packit 3ff832
 * This function will NOT duplicate @str.
Packit 3ff832
 *
Packit 3ff832
 * Returns: A newly allocated #IBusText.
Packit 3ff832
 */
Packit 3ff832
IBusText        *ibus_text_new_from_static_string   (const gchar    *str);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_new_from_printf:
Packit 3ff832
 * @fmt: printf format string.
Packit 3ff832
 * @...: arguments for @fmt.
Packit 3ff832
 *
Packit 3ff832
 * Creates a new #IBusText from a printf expression.
Packit 3ff832
 *
Packit 3ff832
 * The result of printf expression is stored in the new IBusText instance.
Packit 3ff832
 *
Packit 3ff832
 * Returns: A newly allocated #IBusText.
Packit 3ff832
 */
Packit 3ff832
IBusText        *ibus_text_new_from_printf          (const gchar    *fmt,
Packit 3ff832
                                                     ...) G_GNUC_PRINTF (1, 2);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_new_from_unichar:
Packit 3ff832
 * @c: A single UCS4-encoded character.
Packit 3ff832
 *
Packit 3ff832
 * Creates a new #IBusText from a single UCS4-encoded character.
Packit 3ff832
 *
Packit 3ff832
 * Returns: A newly allocated #IBusText.
Packit 3ff832
 */
Packit 3ff832
IBusText        *ibus_text_new_from_unichar         (gunichar        c);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_append_attribute:
Packit 3ff832
 * @text: an IBusText
Packit 3ff832
 * @type: IBusAttributeType for @text.
Packit 3ff832
 * @value: Value for the type.
Packit 3ff832
 * @start_index: The starting index, inclusive.
Packit 3ff832
 * @end_index: The ending index, exclusive.
Packit 3ff832
 *
Packit 3ff832
 * Append an IBusAttribute for IBusText.
Packit 3ff832
 */
Packit 3ff832
void             ibus_text_append_attribute         (IBusText       *text,
Packit 3ff832
                                                     guint           type,
Packit 3ff832
                                                     guint           value,
Packit 3ff832
                                                     guint           start_index,
Packit 3ff832
                                                     gint            end_index);
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_get_length:
Packit 3ff832
 * @text: An #IBusText.
Packit 3ff832
 *
Packit 3ff832
 * Return number of characters in an #IBusText.
Packit 3ff832
 * This function is based on g_utf8_strlen(), so unlike strlen(),
Packit 3ff832
 * it does not count by bytes but characters instead.
Packit 3ff832
 *
Packit 3ff832
 * Returns: Number of character in @text, not counted by bytes.
Packit 3ff832
 */
Packit 3ff832
guint            ibus_text_get_length               (IBusText       *text);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_get_is_static: (skip)
Packit 3ff832
 * @text: An #IBusText.
Packit 3ff832
 *
Packit 3ff832
 * Return the is_static in an #IBusText.
Packit 3ff832
 *
Packit 3ff832
 * Returns: the is_static in @text.
Packit 3ff832
 */
Packit 3ff832
gboolean         ibus_text_get_is_static            (IBusText       *text);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_get_text:
Packit 3ff832
 * @text: An #IBusText.
Packit 3ff832
 *
Packit 3ff832
 * Return the text in an #IBusText. Should not be freed.
Packit 3ff832
 *
Packit 3ff832
 * Returns: the text in @text.
Packit 3ff832
 */
Packit 3ff832
const gchar *    ibus_text_get_text                 (IBusText       *text);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_get_attributes:
Packit 3ff832
 * @text: An #IBusText.
Packit 3ff832
 *
Packit 3ff832
 * Return the attributes in an #IBusText. Should not be freed.
Packit 3ff832
 *
Packit 3ff832
 * Returns: (transfer none): the attrs in @text.
Packit 3ff832
 */
Packit 3ff832
IBusAttrList *   ibus_text_get_attributes           (IBusText       *text);
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * ibus_text_set_attributes:
Packit 3ff832
 * @text: An IBusText.
Packit 3ff832
 * @attrs: An IBusAttrList
Packit 3ff832
 */
Packit 3ff832
void             ibus_text_set_attributes           (IBusText       *text,
Packit 3ff832
                                                     IBusAttrList   *attrs);
Packit 3ff832
Packit 3ff832
Packit 3ff832
G_END_DECLS
Packit 3ff832
#endif
Packit 3ff832