aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauris Kaplinski <lauris@src.gnome.org>2000-08-23 11:15:10 +0800
committerLauris Kaplinski <lauris@src.gnome.org>2000-08-23 11:15:10 +0800
commit88d79b0d1a18ea5475d264f7e1ba1b537d233582 (patch)
tree2ec53f4c8dfc4cd0477967ddae11faf29435270e
parentb906c345f9c03db2c3786e6570d3728c12a00be9 (diff)
downloadgsoc2013-evolution-88d79b0d1a18ea5475d264f7e1ba1b537d233582.tar
gsoc2013-evolution-88d79b0d1a18ea5475d264f7e1ba1b537d233582.tar.gz
gsoc2013-evolution-88d79b0d1a18ea5475d264f7e1ba1b537d233582.tar.bz2
gsoc2013-evolution-88d79b0d1a18ea5475d264f7e1ba1b537d233582.tar.lz
gsoc2013-evolution-88d79b0d1a18ea5475d264f7e1ba1b537d233582.tar.xz
gsoc2013-evolution-88d79b0d1a18ea5475d264f7e1ba1b537d233582.tar.zst
gsoc2013-evolution-88d79b0d1a18ea5475d264f7e1ba1b537d233582.zip
Added missing e-unicode.h and e-unicode.c
svn path=/trunk/; revision=4977
-rw-r--r--e-util/e-unicode.c159
-rw-r--r--e-util/e-unicode.h27
-rw-r--r--widgets/misc/e-unicode.c159
-rw-r--r--widgets/misc/e-unicode.h27
4 files changed, 372 insertions, 0 deletions
diff --git a/e-util/e-unicode.c b/e-util/e-unicode.c
new file mode 100644
index 0000000000..a865a7d0fa
--- /dev/null
+++ b/e-util/e-unicode.c
@@ -0,0 +1,159 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Authors: Lauris Kaplinski <lauris@helixcode.com>
+ *
+ */
+
+#include <config.h>
+#include <unicode.h>
+#include "e-unicode.h"
+
+gchar *
+e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string)
+{
+ /* test it out with iso-8859-1 */
+
+ static gboolean uinit = FALSE;
+ static gboolean uerror = FALSE;
+ static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+ char *new, *ob;
+ size_t ibl, obl;
+
+ if (uerror) return NULL;
+
+ if (!string) return NULL;
+
+ if (!uinit) {
+ unicode_init ();
+ uiconv = unicode_iconv_open ("UTF-8", "iso-8859-1");
+ if (uiconv == (unicode_iconv_t) -1) {
+ uerror = TRUE;
+ return NULL;
+ } else {
+ uinit = TRUE;
+ }
+ }
+
+ ibl = strlen (string);
+ new = ob = g_new (gchar, ibl * 6 + 1);
+ obl = ibl * 6 + 1;
+
+ unicode_iconv (uiconv, &string, &ibl, &ob, &obl);
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string)
+{
+ /* test it out with iso-8859-1 */
+
+ static gboolean uinit = FALSE;
+ static gboolean uerror = FALSE;
+ static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+ char *new, *ob;
+ size_t ibl, obl;
+
+ if (uerror) return NULL;
+
+ if (!string) return NULL;
+
+ if (!uinit) {
+ unicode_init ();
+ uiconv = unicode_iconv_open ("UTF-8", "iso-8859-1");
+ if (uiconv == (unicode_iconv_t) -1) {
+ uerror = TRUE;
+ return NULL;
+ } else {
+ uinit = TRUE;
+ }
+ }
+
+ ibl = strlen (string);
+ new = ob = g_new (gchar, ibl * 6 + 1);
+ obl = ibl * 6 + 1;
+
+ unicode_iconv (uiconv, &string, &ibl, &ob, &obl);
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string)
+{
+ /* test it out with iso-8859-1 */
+
+ static gboolean uinit = FALSE;
+ static gboolean uerror = FALSE;
+ static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+ char *new, *ob;
+ size_t ibl, obl;
+
+ if (uerror) return NULL;
+
+ if (!string) return NULL;
+
+ if (!uinit) {
+ unicode_init ();
+ uiconv = unicode_iconv_open ("iso-8859-1", "UTF-8");
+ if (uiconv == (unicode_iconv_t) -1) {
+ uerror = TRUE;
+ return NULL;
+ } else {
+ uinit = TRUE;
+ }
+ }
+
+ ibl = strlen (string);
+ new = ob = g_new (gchar, ibl * 2 + 1);
+ obl = ibl * 2 + 1;
+
+ unicode_iconv (uiconv, &string, &ibl, &ob, &obl);
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_gtk_entry_get_text (GtkEntry *entry)
+{
+ gchar *s, *u;
+
+ s = gtk_entry_get_text (entry);
+ if (!s) return NULL;
+ u = e_utf8_from_gtk_string ((GtkWidget *) entry, s);
+ return u;
+}
+
+gchar *
+e_utf8_gtk_editable_get_chars (GtkEditable *editable, gint start, gint end)
+{
+ gchar *s, *u;
+
+ s = gtk_editable_get_chars (editable, start, end);
+ if (!s) return NULL;
+ u = e_utf8_from_gtk_string ((GtkWidget *) editable, s);
+ g_free (s);
+ return u;
+}
+
+void
+e_utf8_gtk_entry_set_text (GtkEntry *entry, const gchar *text)
+{
+ gchar *s;
+
+ if (!text) return;
+
+ s = e_utf8_to_gtk_string ((GtkWidget *) entry, text);
+ gtk_entry_set_text (entry, s);
+
+ if (s) g_free (s);
+}
+
diff --git a/e-util/e-unicode.h b/e-util/e-unicode.h
new file mode 100644
index 0000000000..7bfba7e532
--- /dev/null
+++ b/e-util/e-unicode.h
@@ -0,0 +1,27 @@
+#ifndef _E_UNICODE_H_
+#define _E_UNICODE_H_
+
+#include <sys/types.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+
+gchar *e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string);
+
+gchar *e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string);
+
+gchar * e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string);
+
+/*
+ * These are simple wrappers that save us some typing
+ */
+
+/* NB! This return newly allocated string, not const as gtk+ one */
+
+gchar *e_utf8_gtk_entry_get_text (GtkEntry *entry);
+
+void e_utf8_gtk_entry_set_text (GtkEntry *entry, const gchar *text);
+
+gchar *e_utf8_gtk_editable_get_chars (GtkEditable *editable, gint start, gint end);
+
+#endif
+
diff --git a/widgets/misc/e-unicode.c b/widgets/misc/e-unicode.c
new file mode 100644
index 0000000000..a865a7d0fa
--- /dev/null
+++ b/widgets/misc/e-unicode.c
@@ -0,0 +1,159 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * Authors: Lauris Kaplinski <lauris@helixcode.com>
+ *
+ */
+
+#include <config.h>
+#include <unicode.h>
+#include "e-unicode.h"
+
+gchar *
+e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string)
+{
+ /* test it out with iso-8859-1 */
+
+ static gboolean uinit = FALSE;
+ static gboolean uerror = FALSE;
+ static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+ char *new, *ob;
+ size_t ibl, obl;
+
+ if (uerror) return NULL;
+
+ if (!string) return NULL;
+
+ if (!uinit) {
+ unicode_init ();
+ uiconv = unicode_iconv_open ("UTF-8", "iso-8859-1");
+ if (uiconv == (unicode_iconv_t) -1) {
+ uerror = TRUE;
+ return NULL;
+ } else {
+ uinit = TRUE;
+ }
+ }
+
+ ibl = strlen (string);
+ new = ob = g_new (gchar, ibl * 6 + 1);
+ obl = ibl * 6 + 1;
+
+ unicode_iconv (uiconv, &string, &ibl, &ob, &obl);
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string)
+{
+ /* test it out with iso-8859-1 */
+
+ static gboolean uinit = FALSE;
+ static gboolean uerror = FALSE;
+ static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+ char *new, *ob;
+ size_t ibl, obl;
+
+ if (uerror) return NULL;
+
+ if (!string) return NULL;
+
+ if (!uinit) {
+ unicode_init ();
+ uiconv = unicode_iconv_open ("UTF-8", "iso-8859-1");
+ if (uiconv == (unicode_iconv_t) -1) {
+ uerror = TRUE;
+ return NULL;
+ } else {
+ uinit = TRUE;
+ }
+ }
+
+ ibl = strlen (string);
+ new = ob = g_new (gchar, ibl * 6 + 1);
+ obl = ibl * 6 + 1;
+
+ unicode_iconv (uiconv, &string, &ibl, &ob, &obl);
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string)
+{
+ /* test it out with iso-8859-1 */
+
+ static gboolean uinit = FALSE;
+ static gboolean uerror = FALSE;
+ static unicode_iconv_t uiconv = (unicode_iconv_t) -1;
+ char *new, *ob;
+ size_t ibl, obl;
+
+ if (uerror) return NULL;
+
+ if (!string) return NULL;
+
+ if (!uinit) {
+ unicode_init ();
+ uiconv = unicode_iconv_open ("iso-8859-1", "UTF-8");
+ if (uiconv == (unicode_iconv_t) -1) {
+ uerror = TRUE;
+ return NULL;
+ } else {
+ uinit = TRUE;
+ }
+ }
+
+ ibl = strlen (string);
+ new = ob = g_new (gchar, ibl * 2 + 1);
+ obl = ibl * 2 + 1;
+
+ unicode_iconv (uiconv, &string, &ibl, &ob, &obl);
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_gtk_entry_get_text (GtkEntry *entry)
+{
+ gchar *s, *u;
+
+ s = gtk_entry_get_text (entry);
+ if (!s) return NULL;
+ u = e_utf8_from_gtk_string ((GtkWidget *) entry, s);
+ return u;
+}
+
+gchar *
+e_utf8_gtk_editable_get_chars (GtkEditable *editable, gint start, gint end)
+{
+ gchar *s, *u;
+
+ s = gtk_editable_get_chars (editable, start, end);
+ if (!s) return NULL;
+ u = e_utf8_from_gtk_string ((GtkWidget *) editable, s);
+ g_free (s);
+ return u;
+}
+
+void
+e_utf8_gtk_entry_set_text (GtkEntry *entry, const gchar *text)
+{
+ gchar *s;
+
+ if (!text) return;
+
+ s = e_utf8_to_gtk_string ((GtkWidget *) entry, text);
+ gtk_entry_set_text (entry, s);
+
+ if (s) g_free (s);
+}
+
diff --git a/widgets/misc/e-unicode.h b/widgets/misc/e-unicode.h
new file mode 100644
index 0000000000..7bfba7e532
--- /dev/null
+++ b/widgets/misc/e-unicode.h
@@ -0,0 +1,27 @@
+#ifndef _E_UNICODE_H_
+#define _E_UNICODE_H_
+
+#include <sys/types.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+
+gchar *e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string);
+
+gchar *e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string);
+
+gchar * e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string);
+
+/*
+ * These are simple wrappers that save us some typing
+ */
+
+/* NB! This return newly allocated string, not const as gtk+ one */
+
+gchar *e_utf8_gtk_entry_get_text (GtkEntry *entry);
+
+void e_utf8_gtk_entry_set_text (GtkEntry *entry, const gchar *text);
+
+gchar *e_utf8_gtk_editable_get_chars (GtkEditable *editable, gint start, gint end);
+
+#endif
+