summaryrefslogtreecommitdiffstats
path: root/lib/gtk2
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2008-10-02 19:00:55 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2008-10-02 19:00:55 +0800
commit8647538dd30ee392d9ac093b088019abcd0a656f (patch)
treeae64745ea8f0e7fb009172920c358f7ff217b7f0 /lib/gtk2
parent0394896c4eaed931eaba4c444cb3a3c58a23271a (diff)
downloadibus-8647538dd30ee392d9ac093b088019abcd0a656f.tar.gz
ibus-8647538dd30ee392d9ac093b088019abcd0a656f.tar.xz
ibus-8647538dd30ee392d9ac093b088019abcd0a656f.zip
Implement IBusAttribute & IBusAttrList.
Diffstat (limited to 'lib/gtk2')
-rw-r--r--lib/gtk2/Makefile.am2
-rw-r--r--lib/gtk2/ibusattribute.c169
-rw-r--r--lib/gtk2/ibusattribute.h37
3 files changed, 191 insertions, 17 deletions
diff --git a/lib/gtk2/Makefile.am b/lib/gtk2/Makefile.am
index dc46812..e4b1cd1 100644
--- a/lib/gtk2/Makefile.am
+++ b/lib/gtk2/Makefile.am
@@ -34,6 +34,8 @@ libibus_gtk_la_SOURCES = \
ibusmarshalers.c \
ibusimclient.h \
ibusimclient.c \
+ ibusattribute.h \
+ ibusattribute.c \
$(NULL)
libibus_gtk_la_CFLAGS = \
@X11_CFLAGS@ \
diff --git a/lib/gtk2/ibusattribute.c b/lib/gtk2/ibusattribute.c
new file mode 100644
index 0000000..c693d65
--- /dev/null
+++ b/lib/gtk2/ibusattribute.c
@@ -0,0 +1,169 @@
+/* vim:set et ts=4: */
+/* IBus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <glib.h>
+#include "ibusattribute.h"
+
+GType
+ibus_attribute_get_type ()
+{
+ static GType type = 0;
+ if (type == 0) {
+ type = g_boxed_type_register_static ("IBusAttribute",
+ (GBoxedCopyFunc)ibus_attribute_copy,
+ (GBoxedFreeFunc)ibus_attribute_free);
+ }
+ return type;
+}
+
+IBusAttribute *
+ibus_attribute_new (guint type, guint value, guint start_index, guint end_index)
+{
+ g_return_val_if_fail (type == IBUS_ATTR_TYPE_UNDERLINE ||
+ type == IBUS_ATTR_TYPE_FOREGROUND ||
+ type == IBUS_ATTR_TYPE_BACKGROUND, NULL);
+ IBusAttribute *attr = g_slice_new (IBusAttribute);
+ attr->type = type;
+ attr->value = value;
+ attr->start_index = start_index;
+ attr->end_index = end_index;
+ return attr;
+}
+
+IBusAttribute *
+ibus_attribute_copy (IBusAttribute * attr)
+{
+ g_assert (attr != NULL);
+ return ibus_attribute_new (attr->type, attr->value, attr->start_index, attr->end_index);
+}
+
+void
+ibus_attribute_free (IBusAttribute *attr)
+{
+ g_assert (attr != NULL);
+ g_slice_free (IBusAttribute, attr);
+}
+
+IBusAttribute *
+ibus_attr_underline_new (guint underline_type, guint start_index, guint end_index)
+{
+ g_return_val_if_fail (underline_type == IBUS_ATTR_UNDERLINE_NONE ||
+ underline_type == IBUS_ATTR_UNDERLINE_SINGLE ||
+ underline_type == IBUS_ATTR_UNDERLINE_DOUBLE ||
+ underline_type == IBUS_ATTR_UNDERLINE_LOW, NULL);
+ return ibus_attribute_new (IBUS_ATTR_TYPE_UNDERLINE, underline_type, start_index, end_index);
+}
+
+IBusAttribute *
+ibus_attr_foreground_new (guint color, guint start_index, guint end_index)
+{
+ return ibus_attribute_new (IBUS_ATTR_TYPE_FOREGROUND, color, start_index, end_index);
+}
+
+IBusAttribute *
+ibus_attr_background_new (guint color, guint start_index, guint end_index)
+{
+ return ibus_attribute_new (IBUS_ATTR_TYPE_BACKGROUND, color, start_index, end_index);
+}
+
+GType
+ibus_attr_list_get_type ()
+{
+ static GType type = 0;
+ if (type == 0) {
+ type = g_boxed_type_register_static ("IBusAttrList",
+ (GBoxedCopyFunc)ibus_attr_list_copy,
+ (GBoxedFreeFunc)ibus_attr_list_unref);
+ }
+ return type;
+}
+
+IBusAttrList *
+ibus_attr_list_new ()
+{
+ IBusAttrList *attr_list = g_slice_new(IBusAttrList);
+ attr_list->refcount = 1;
+ attr_list->attributes = g_array_new (TRUE, TRUE, sizeof (IBusAttribute *));
+ return attr_list;
+}
+
+IBusAttrList *
+ibus_attr_list_copy (IBusAttrList *attr_list)
+{
+ IBusAttrList *new_list = ibus_attr_list_new ();
+ guint i;
+ for (i = 0;; i++) {
+ IBusAttribute *attr = ibus_attr_list_get (attr_list, i);
+ if (attr == NULL) {
+ break;
+ }
+ ibus_attr_list_append (new_list, attr);
+ }
+ return new_list;
+}
+
+IBusAttrList *
+ibus_attr_list_ref (IBusAttrList *attr_list)
+{
+ if (attr_list == NULL) {
+ return NULL;
+ }
+ attr_list->refcount ++;
+ return attr_list;
+}
+
+void
+ibus_attr_list_unref (IBusAttrList *attr_list)
+{
+ if (attr_list == NULL) {
+ return;
+ }
+ attr_list->refcount --;
+ if (attr_list->refcount <= 0) {
+ guint i;
+ for (i = 0; i < attr_list->attributes->len; i++) {
+ IBusAttribute *attr = g_array_index (attr_list->attributes,
+ IBusAttribute *, i);
+ if (attr != NULL) {
+ ibus_attribute_free (attr);
+ }
+ }
+ g_array_free (attr_list->attributes, TRUE);
+ g_slice_free (IBusAttrList, attr_list);
+ }
+}
+
+void
+ibus_attr_list_append (IBusAttrList *attr_list, IBusAttribute *attr)
+{
+ g_return_if_fail (attr_list != NULL);
+ g_return_if_fail (attr != NULL);
+ g_array_append_val (attr_list->attributes, attr);
+}
+
+IBusAttribute *
+ibus_attr_list_get (IBusAttrList *attr_list, guint index)
+{
+ g_return_val_if_fail (attr_list != NULL, NULL);
+ IBusAttribute *attr = NULL;
+ if (index < attr_list->attributes->len) {
+ attr = g_array_index (attr_list->attributes, IBusAttribute *, index);
+ }
+ return attr;
+}
diff --git a/lib/gtk2/ibusattribute.h b/lib/gtk2/ibusattribute.h
index 0914227..8ed1b09 100644
--- a/lib/gtk2/ibusattribute.h
+++ b/lib/gtk2/ibusattribute.h
@@ -20,25 +20,15 @@
#ifndef __IBUS_ATTRIBUTE_H_
#define __IBUS_ATTRIBUTE_H_
-#include <gtk/gtk.h>
+#include <glib-object.h>
+
/*
* Type macros.
*/
+#define IBUS_TYPE_ATTRIBUTE (ibus_attribute_get_type ())
+#define IBUS_TYPE_ATTR_LIST (ibus_attr_list_get_type ())
/* define GOBJECT macros */
-#define IBUS_TYPE_IM_CLIENT \
- (ibus_im_client_get_type ())
-#define IBUS_IM_CLIENT(obj) \
- (GTK_CHECK_CAST ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClient))
-#define IBUS_IM_CLIENT_CLASS(klass) \
- (GTK_CHECK_CLASS_CAST ((klass), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
-#define IBUS_IS_IM_CLIENT(obj) \
- (GTK_CHECK_TYPE ((obj), IBUS_TYPE_IM_CLIENT))
-#define IBUS_IS_IM_CLIENT_CLASS(klass) \
- (GTK_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_IM_CLIENT))
-#define IBUS_IM_CLIENT_GET_CLASS(obj) \
- (GTK_CHECK_GET_CLASS ((obj), IBUS_TYPE_IM_CLIENT, IBusIMClientClass))
-
#define IBUS_ATTR_TYPE_UNDERLINE 1
#define IBUS_ATTR_TYPE_FOREGROUND 2
@@ -60,16 +50,19 @@ struct _IBusAttribute {
guint end_index;
};
-struct _IBusAttribute {
-
+struct _IBusAttrList {
+ gint refcount;
GArray *attributes;
};
+GType ibus_attribute_get_type ();
IBusAttribute *ibus_attribute_new (guint type,
guint value,
guint start_index,
guint end_index);
-void *ibus_attribute_free (IBusAttribute
+IBusAttribute *ibus_attribute_copy (IBusAttribute
+ *attr);
+void ibus_attribute_free (IBusAttribute
*attr);
IBusAttribute *ibus_attr_underline_new (guint underline_type,
guint start_index,
@@ -81,6 +74,16 @@ IBusAttribute *ibus_attr_background_new (guint color,
guint start_index,
guint end_index);
+GType ibus_attr_list_get_type ();
+IBusAttrList *ibus_attr_list_new ();
+IBusAttrList *ibus_attr_list_copy (IBusAttrList *attr_list);
+IBusAttrList *ibus_attr_list_ref (IBusAttrList *attr_list);
+void ibus_attr_list_unref (IBusAttrList *attr_list);
+void ibus_attr_list_append (IBusAttrList *attr_list,
+ IBusAttribute *attr);
+IBusAttribute *ibus_attr_list_get (IBusAttrList *attr_list,
+ guint index);
+
G_END_DECLS
#endif