1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 /* vim:set et sts=4: */
3 /* IBus - The Input Bus
4 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
5 * Copyright (C) 2008-2010 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
23 #if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION)
24 #error "Only <ibus.h> can be included directly"
29 * @short_description: Text with decorating information.
30 * @see_also: #IBusAttribute
32 * An IBusText is the main text object in IBus.
33 * The text is decorated according to associated IBusAttribute,
34 * e.g. the foreground/background color, underline, and
38 #ifndef __IBUS_TEXT_H_
39 #define __IBUS_TEXT_H_
41 #include "ibusserializable.h"
42 #include "ibusattrlist.h"
47 /* define IBusText macros */
48 #define IBUS_TYPE_TEXT \
49 (ibus_text_get_type ())
50 #define IBUS_TEXT(obj) \
51 (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_TEXT, IBusText))
52 #define IBUS_TEXT_CLASS(klass) \
53 (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_TEXT, IBusTextClass))
54 #define IBUS_IS_TEXT(obj) \
55 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_TEXT))
56 #define IBUS_IS_TEXT_CLASS(klass) \
57 (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_TEXT))
58 #define IBUS_TEXT_GET_CLASS(obj) \
59 (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_TEXT, IBusTextClass))
63 typedef struct _IBusText IBusText;
64 typedef struct _IBusTextClass IBusTextClass;
68 * @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().
69 * @text: The string content of IBusText in UTF-8.
70 * @attrs: Associated IBusAttributes.
72 * A text object in IBus.
75 IBusSerializable parent;
84 struct _IBusTextClass {
85 IBusSerializableClass parent;
88 GType ibus_text_get_type (void);
91 * ibus_text_new_from_string:
92 * @str: An text string to be set.
93 * @returns: A newly allocated IBusText.
95 * New an IBusText from a string.
97 * @str will be duplicated in IBusText, so feel free to free @str after this function.
99 IBusText *ibus_text_new_from_string (const gchar *str);
102 * ibus_text_new_from_ucs4:
103 * @str: An text string to be set.
104 * @returns: A newly allocated IBusText.
106 * New an IBusText from an UCS-4 encoded string.
108 * @str will be duplicated in IBusText, so feel free to free @str after this function.
110 IBusText *ibus_text_new_from_ucs4 (const gunichar *str);
113 * ibus_text_new_from_static_string: (skip)
114 * @str: An text string to be set.
115 * @returns: A newly allocated IBusText.
117 * New an IBusText from a static string.
119 * Since @str is a static string which won't be freed.
120 * This function will NOT duplicate @str.
122 IBusText *ibus_text_new_from_static_string (const gchar *str);
125 * ibus_text_new_from_printf:
126 * @fmt: printf format string.
127 * @...: arguments for @fmt.
128 * @returns: A newly allocated IBusText.
130 * New an IBusText from a printf expression.
132 * The result of printf expression is stored in the new IBusText instance.
134 IBusText *ibus_text_new_from_printf (const gchar *fmt,
135 ...) G_GNUC_PRINTF (1, 2);
138 * ibus_text_new_from_unichar:
139 * @c: A single UCS4-encoded character.
140 * @returns: A newly allocated IBusText.
142 * New an IBusText from a single UCS4-encoded character.
144 IBusText *ibus_text_new_from_unichar (gunichar c);
147 * ibus_text_append_attribute:
149 * @type: IBusAttributeType for @text.
150 * @value: Value for the type.
151 * @start_index: The starting index, inclusive.
152 * @end_index: The ending index, exclusive.
154 * Append an IBusAttribute for IBusText.
156 void ibus_text_append_attribute (IBusText *text,
162 * ibus_text_get_length:
163 * @text: An IBusText.
164 * @returns: Number of character in @text, not counted by bytes.
166 * Return number of characters in an IBusText.
167 * This function is based on g_utf8_strlen(), so unlike strlen(),
168 * it does not count by bytes but characters instead.
170 guint ibus_text_get_length (IBusText *text);
173 * ibus_text_get_is_static: (skip)
174 * @text: An IBusText.
175 * @returns: the is_static in @text.
177 * Return the is_static in an IBusText.
179 gboolean ibus_text_get_is_static (IBusText *text);
182 * ibus_text_get_text:
183 * @text: An IBusText.
184 * @returns: the text in @text.
186 * Return the text in an IBusText. Should not be freed.
188 const gchar * ibus_text_get_text (IBusText *text);
191 * ibus_text_get_attributes:
192 * @text: An IBusText.
193 * @returns: (transfer none): the attrs in @text.
195 * Return the attributes in an IBusText. Should not be freed.
197 IBusAttrList * ibus_text_get_attributes (IBusText *text);
200 * ibus_text_set_attributes:
201 * @text: An IBusText.
202 * @attrs: An IBusAttrList
204 void ibus_text_set_attributes (IBusText *text,
205 IBusAttrList *attrs);