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