| 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-2013 Peng Huang <shawn.p.huang@gmail.com> |
| 5 | * Copyright (C) 2008-2013 Red Hat, Inc. |
| 6 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | * USA |
| 21 | */ |
| 22 | |
| 23 | #if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION) |
| 24 | #error "Only <ibus.h> can be included directly" |
| 25 | #endif |
| 26 | |
| 27 | #ifndef __IBUS_ATTRIBUTE_H_ |
| 28 | #define __IBUS_ATTRIBUTE_H_ |
| 29 | |
| 30 | /** |
| 31 | * SECTION: ibusattribute |
| 32 | * @short_description: Attributes of IBusText. |
| 33 | * @see_also: #IBusText |
| 34 | * @stability: Stable |
| 35 | * |
| 36 | * An IBusAttribute represents an attribute that associate to IBusText. |
| 37 | * It decorates preedit buffer and auxiliary text with underline, foreground |
| 38 | * and background colors. |
| 39 | */ |
| 40 | |
| 41 | #include "ibusserializable.h" |
| 42 | |
| 43 | G_BEGIN_DECLS |
| 44 | |
| 45 | /* |
| 46 | * Type macros. |
| 47 | */ |
| 48 | /* define IBusAttribute macros */ |
| 49 | #define IBUS_TYPE_ATTRIBUTE \ |
| 50 | (ibus_attribute_get_type ()) |
| 51 | #define IBUS_ATTRIBUTE(obj) \ |
| 52 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_ATTRIBUTE, IBusAttribute)) |
| 53 | #define IBUS_ATTRIBUTE_CLASS(klass) \ |
| 54 | (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_ATTRIBUTE, IBusAttributeClass)) |
| 55 | #define IBUS_IS_ATTRIBUTE(obj) \ |
| 56 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_ATTRIBUTE)) |
| 57 | #define IBUS_IS_ATTRIBUTE_CLASS(klass) \ |
| 58 | (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_ATTRIBUTE)) |
| 59 | #define IBUS_ATTRIBUTE_GET_CLASS(obj) \ |
| 60 | (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_ATTRIBUTE, IBusAttributeClass)) |
| 61 | |
| 62 | /** |
| 63 | * IBusAttrType: |
| 64 | * @IBUS_ATTR_TYPE_UNDERLINE: Decorate with underline. |
| 65 | * @IBUS_ATTR_TYPE_FOREGROUND: Foreground color. |
| 66 | * @IBUS_ATTR_TYPE_BACKGROUND: Background color. |
| 67 | * |
| 68 | * Type enumeration of IBusText attribute. |
| 69 | */ |
| 70 | typedef enum { |
| 71 | IBUS_ATTR_TYPE_UNDERLINE = 1, |
| 72 | IBUS_ATTR_TYPE_FOREGROUND = 2, |
| 73 | IBUS_ATTR_TYPE_BACKGROUND = 3, |
| 74 | } IBusAttrType; |
| 75 | |
| 76 | /** |
| 77 | * IBusAttrUnderline: |
| 78 | * @IBUS_ATTR_UNDERLINE_NONE: No underline. |
| 79 | * @IBUS_ATTR_UNDERLINE_SINGLE: Single underline. |
| 80 | * @IBUS_ATTR_UNDERLINE_DOUBLE: Double underline. |
| 81 | * @IBUS_ATTR_UNDERLINE_LOW: Low underline ? FIXME |
| 82 | * @IBUS_ATTR_UNDERLINE_ERROR: Error underline |
| 83 | * |
| 84 | * Type of IBusText attribute. |
| 85 | */ |
| 86 | typedef enum { |
| 87 | IBUS_ATTR_UNDERLINE_NONE = 0, |
| 88 | IBUS_ATTR_UNDERLINE_SINGLE = 1, |
| 89 | IBUS_ATTR_UNDERLINE_DOUBLE = 2, |
| 90 | IBUS_ATTR_UNDERLINE_LOW = 3, |
| 91 | IBUS_ATTR_UNDERLINE_ERROR = 4, |
| 92 | } IBusAttrUnderline; |
| 93 | |
| 94 | typedef struct _IBusAttribute IBusAttribute; |
| 95 | typedef struct _IBusAttributeClass IBusAttributeClass; |
| 96 | |
| 97 | /** |
| 98 | * IBusAttribute: |
| 99 | * @type: IBusAttributeType |
| 100 | * @value: Value for the type. |
| 101 | * @start_index: The starting index, inclusive. |
| 102 | * @end_index: The ending index, exclusive. |
| 103 | * |
| 104 | * Signify the type, value and scope of the attribute. |
| 105 | * The scope starts from @start_index till the @end_index-1. |
| 106 | */ |
| 107 | struct _IBusAttribute { |
| 108 | IBusSerializable parent; |
| 109 | |
| 110 | /*< public >*/ |
| 111 | guint type; |
| 112 | guint value; |
| 113 | guint start_index; |
| 114 | guint end_index; |
| 115 | }; |
| 116 | |
| 117 | struct _IBusAttributeClass { |
| 118 | IBusSerializableClass parent; |
| 119 | }; |
| 120 | |
| 121 | /** |
| 122 | * ibus_attribute_get_type: |
| 123 | * @returns: GType of IBusAttribute. |
| 124 | * |
| 125 | * Returns GType of IBusAttribute. |
| 126 | */ |
| 127 | GType ibus_attribute_get_type (); |
| 128 | |
| 129 | /** |
| 130 | * ibus_attribute_new: |
| 131 | * @type: Type of the attribute. |
| 132 | * @value: Value of the attribute. |
| 133 | * @start_index: Where attribute starts. |
| 134 | * @end_index: Where attribute ends. |
| 135 | * |
| 136 | * Creates a new IBusAttribute. |
| 137 | * |
| 138 | * Returns: (transfer none): A newly allocated IBusAttribute. |
| 139 | */ |
| 140 | IBusAttribute *ibus_attribute_new (guint type, |
| 141 | guint value, |
| 142 | guint start_index, |
| 143 | guint end_index); |
| 144 | |
| 145 | /** |
| 146 | * ibus_attribute_get_attr_type: |
| 147 | * @attr: An #IBusAttribute |
| 148 | * |
| 149 | * Gets an enum of #IBusAttrType. |
| 150 | * |
| 151 | * Returns: An enum of #IBusAttrType. |
| 152 | */ |
| 153 | guint ibus_attribute_get_attr_type |
| 154 | (IBusAttribute *attr); |
| 155 | |
| 156 | /** |
| 157 | * ibus_attribute_get_value: |
| 158 | * @attr: An #IBusAttribute |
| 159 | * |
| 160 | * Gets an unsigned int value relative with #IBusAttrType. |
| 161 | * If the type is %IBUS_ATTR_TYPE_UNDERLINE, the return value is |
| 162 | * #IBusAttrUnderline. If the type is %IBUS_ATTR_TYPE_FOREGROUND, |
| 163 | * the return value is the color RGB. |
| 164 | * |
| 165 | * Returns: An unsigned int value relative with #IBusAttrType. |
| 166 | */ |
| 167 | guint ibus_attribute_get_value (IBusAttribute *attr); |
| 168 | |
| 169 | /** |
| 170 | * ibus_attribute_get_start_index: |
| 171 | * @attr: An #IBusAttribute |
| 172 | * |
| 173 | * Gets a start unsigned index |
| 174 | * |
| 175 | * Returns: A start unsigned index |
| 176 | */ |
| 177 | guint ibus_attribute_get_start_index |
| 178 | (IBusAttribute *attr); |
| 179 | |
| 180 | /** |
| 181 | * ibus_attribute_get_end_index: |
| 182 | * @attr: An #IBusAttribute |
| 183 | * |
| 184 | * Gets an end unsigned index |
| 185 | * |
| 186 | * Returns: A end unsigned index |
| 187 | */ |
| 188 | guint ibus_attribute_get_end_index |
| 189 | (IBusAttribute *attr); |
| 190 | |
| 191 | /** |
| 192 | * ibus_attr_underline_new: |
| 193 | * @underline_type: Type of underline. |
| 194 | * @start_index: Where attribute starts. |
| 195 | * @end_index: Where attribute ends. |
| 196 | * |
| 197 | * Creates a new underline #IBusAttribute. |
| 198 | * |
| 199 | * Returns: (transfer none): A newly allocated #IBusAttribute. |
| 200 | */ |
| 201 | IBusAttribute *ibus_attr_underline_new (guint underline_type, |
| 202 | guint start_index, |
| 203 | guint end_index); |
| 204 | /** |
| 205 | * ibus_attr_foreground_new: |
| 206 | * @color: Color in RGB. |
| 207 | * @start_index: Where attribute starts. |
| 208 | * @end_index: Where attribute ends. |
| 209 | * |
| 210 | * Creates a new foreground #IBusAttribute. |
| 211 | * |
| 212 | * Returns: (transfer none): A newly allocated #IBusAttribute. |
| 213 | */ |
| 214 | IBusAttribute *ibus_attr_foreground_new (guint color, |
| 215 | guint start_index, |
| 216 | guint end_index); |
| 217 | /** |
| 218 | * ibus_attr_background_new: |
| 219 | * @color: Color in RGB. |
| 220 | * @start_index: Where attribute starts. |
| 221 | * @end_index: Where attribute ends. |
| 222 | * |
| 223 | * Creates a new background #IBusAttribute. |
| 224 | * |
| 225 | * Returns: (transfer none): A newly allocated #IBusAttribute. |
| 226 | */ |
| 227 | IBusAttribute *ibus_attr_background_new (guint color, |
| 228 | guint start_index, |
| 229 | guint end_index); |
| 230 | |
| 231 | G_END_DECLS |
| 232 | #endif |
| 233 | |
| 234 | |