From 0db696fa4205edb578c56cade278061b4bbe54f2 Mon Sep 17 00:00:00 2001 From: Lauris Kaplinski Date: Thu, 7 Sep 2000 18:30:30 +0000 Subject: Bunch of unicode related changes svn path=/trunk/; revision=5235 --- widgets/misc/e-unicode.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'widgets/misc/e-unicode.c') diff --git a/widgets/misc/e-unicode.c b/widgets/misc/e-unicode.c index 0946647fd8..8357977f8e 100644 --- a/widgets/misc/e-unicode.c +++ b/widgets/misc/e-unicode.c @@ -13,7 +13,7 @@ #include "e-unicode.h" #include "e-font.h" -#undef FONT_TESTING +#define FONT_TESTING void e_unicode_init (void) @@ -89,7 +89,7 @@ e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string) } gchar * -e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string) +e_utf8_from_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes) { #ifndef FONT_TESTING /* test it out with iso-8859-1 */ @@ -97,7 +97,6 @@ e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string) static gboolean uinit = FALSE; static gboolean uerror = FALSE; static unicode_iconv_t uiconv = (unicode_iconv_t) -1; - const gchar *encoding; #else unicode_iconv_t uiconv; #endif @@ -113,6 +112,8 @@ e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string) if (!string) return NULL; + g_return_val_if_fail (widget, NULL); + #ifndef FONT_TESTING if (!uinit) { e_unicode_init (); @@ -129,7 +130,7 @@ e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string) if (uiconv == (unicode_iconv_t) -1) return NULL; #endif - ibl = strlen (string); + ibl = bytes; new = ob = g_new (gchar, ibl * 6 + 1); obl = ibl * 6 + 1; @@ -141,7 +142,13 @@ e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string) } gchar * -e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string) +e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string) +{ + return e_utf8_from_gtk_string_sized (widget, string, strlen (string)); +} + +gchar * +e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes) { #ifndef FONT_TESTING /* test it out with iso-8859-1 */ @@ -161,6 +168,8 @@ e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string) if (!string) return NULL; + g_return_val_if_fail (widget, NULL); + #ifndef FONT_TESTING if (!uinit) { e_unicode_init (); @@ -177,7 +186,7 @@ e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string) if (uiconv == (unicode_iconv_t) -1) return NULL; #endif - ibl = strlen (string); + ibl = bytes; new = ob = g_new (gchar, ibl * 4 + 1); obl = ibl * 4 + 1; @@ -188,6 +197,11 @@ e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string) return new; } +gchar * +e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string) +{ + return e_utf8_to_gtk_string_sized (widget, string, strlen (string)); +} gchar * e_utf8_gtk_entry_get_text (GtkEntry *entry) { @@ -211,6 +225,18 @@ e_utf8_gtk_editable_get_chars (GtkEditable *editable, gint start, gint end) return u; } +void +e_utf8_gtk_editable_insert_text (GtkEditable *editable, const gchar *text, gint length, gint *position) +{ + gchar *s; + + s = e_utf8_to_gtk_string_sized ((GtkWidget *) editable, text, length); + + gtk_editable_insert_text (editable, s, length, position); + + g_free (s); +} + void e_utf8_gtk_entry_set_text (GtkEntry *entry, const gchar *text) { @@ -225,14 +251,14 @@ e_utf8_gtk_entry_set_text (GtkEntry *entry, const gchar *text) } GtkWidget * -e_utf8_gtk_menu_item_new_with_label (const gchar *label) +e_utf8_gtk_menu_item_new_with_label (GtkMenu *menu, const gchar *label) { GtkWidget *w; gchar *s; if (!label) return NULL; - s = e_utf8_to_gtk_string (NULL, label); + s = e_utf8_to_gtk_string ((GtkWidget *) menu, label); w = gtk_menu_item_new_with_label (s); if (s) g_free (s); -- cgit