diff -Nur skipstone-bak/src/bookmarks.c skipstone/src/bookmarks.c --- skipstone-bak/src/bookmarks.c Fri Jun 22 12:51:36 2001 +++ skipstone/src/bookmarks.c Mon Jul 16 16:28:01 2001 @@ -59,7 +59,7 @@ } url = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(skipstone->combo)->entry)); - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed); if (g_strcasecmp(url,"") == 0) { return; diff -Nur skipstone-bak/src/go.c skipstone/src/go.c --- skipstone-bak/src/go.c Sun Apr 15 14:05:27 2001 +++ skipstone/src/go.c Mon Jul 16 16:28:01 2001 @@ -31,7 +31,7 @@ gint list_length; g_return_if_fail(go_menu != NULL); - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed); if (!strcmp(location,"about:blank")) return; /* dont add that! */ if (!title || !strcmp(title,"")) title = location; /* no title? use the url */ add_it = check_for_dupe(go_menu,title); diff -Nur skipstone-bak/src/interface-notebook.c skipstone/src/interface-notebook.c --- skipstone-bak/src/interface-notebook.c Fri Jul 6 03:34:23 2001 +++ skipstone/src/interface-notebook.c Mon Jul 16 16:28:01 2001 @@ -264,7 +264,7 @@ gtk_widget_hide(skipstone->vbox); - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed); skipstone->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_policy(GTK_WINDOW(skipstone->window), TRUE, TRUE, FALSE); if (title) diff -Nur skipstone-bak/src/moz_callbacks.c skipstone/src/moz_callbacks.c --- skipstone-bak/src/moz_callbacks.c Fri Jul 6 03:34:23 2001 +++ skipstone/src/moz_callbacks.c Mon Jul 16 16:28:01 2001 @@ -127,7 +127,7 @@ if (skipstone->is_notebook) { - title = gtk_moz_embed_get_title(skipstone->embed); + title = mozilla_get_document_title (skipstone->embed); if (!title || !strcmp(title,"")) title = _("Untitled Document"); if (!config.show_tabs && g_slist_length(window_count) == 1) { @@ -151,7 +151,8 @@ return; } - title = g_strdup_printf("SkipStone - %s", gtk_moz_embed_get_title(skipstone->embed)); + title = g_strdup_printf(_("SkipStone - %s"), mozilla_get_document_title (skipstone->embed)); + gtk_window_set_title(GTK_WINDOW(skipstone->window), title); g_free(title); diff -Nur skipstone-bak/src/mozilla.cpp skipstone/src/mozilla.cpp --- skipstone-bak/src/mozilla.cpp Sun Jul 8 01:54:44 2001 +++ skipstone/src/mozilla.cpp Mon Jul 16 16:28:11 2001 @@ -72,7 +72,6 @@ #define CONTEXT_OTHER 128 #define CONTEXT_XUL 256 - static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); @@ -83,6 +82,12 @@ static nsIDOMDocument *mozilla_get_dom_document(nsIPresShell *presShell); static gchar *mozilla_get_attribute (nsIDOMNode *node, gchar *attribute); +extern "C" +{ +gchar *mozilla_unicode_to_locale (const PRUnichar *uniStr); +PRUnichar *mozilla_locale_to_unicode (const gchar *locStr); +} + #define PREF_ID NS_PREF_CONTRACTID class SkipNsHistory @@ -364,17 +369,20 @@ extern "C" gboolean mozilla_find(GtkMozEmbed *b, const char *exp, PRBool IgnoreCase, PRBool SearchBackWards, PRBool DidFind) { + PRUnichar *search_string; + g_return_val_if_fail(b != NULL, FALSE); nsresult result = 0; nsIWebBrowser *wb = nsnull; gtk_moz_embed_get_nsIWebBrowser(b,&wb); nsCOMPtr finder(do_GetInterface(wb)); - nsString searchString; - searchString.AssignWithConversion(exp); - finder->SetSearchString(searchString.get()); + search_string = mozilla_locale_to_unicode (exp); + finder->SetSearchString(search_string); finder->SetFindBackwards(SearchBackWards); finder->SetMatchCase(IgnoreCase); result = finder->FindNext(&DidFind); + g_free (search_string); + return DidFind; } @@ -617,6 +625,127 @@ if (NS_FAILED(result)) return NS_ERROR_FAILURE; result = io->SetOffline(offline); return NS_SUCCEEDED (result) ? TRUE : FALSE; +} + +/** + * mozilla_get_document_title: get the document title in a locale specific + * NULL terminated C string, using the private UniCode interface. + */ +extern "C" gchar * +mozilla_get_document_title (GtkMozEmbed *embed) +{ + PRUnichar *unicode_title; + gchar *title; + + /* get the title in unicode */ + unicode_title = gtk_moz_embed_get_title_unichar (embed); + + /* attempt conversion */ + title = mozilla_unicode_to_locale (unicode_title); + + /* free unicode version */ + g_free (unicode_title); + + /* return it */ + return title; +} + +/** + * mozilla_unicode_to_locale: Encodes unicode string to something + * valid for the current locale (which can then be used in GTK+ labels). + * @uniStr: The unicode string to encode + */ +extern "C" gchar * +mozilla_unicode_to_locale (const PRUnichar *uniStr) +{ + PRInt32 sSize; + wchar_t *wide; + gchar *output; + gint i, count; + + /* sanity */ + if (uniStr == NULL) + { + return NULL; + } + + const nsString str (uniStr); + sSize = str.Length (); + + /* allocate a wide string big enough to hold the unicode string, + * this is necessary since wchar_t is 32-bits with glibc */ + wide = g_new0 (wchar_t, sSize + 1); + for (i = 0; i < sSize + 1; i++) + { + wide[i] = uniStr[i]; + } + + /* use glibc function to determine the size of this string once + * encoded to a locale specfic multibyte string */ + count = wcstombs (NULL, wide, 0); + + /* check for success */ + if (count == -1) + { + /* let Mozilla do a (lossy) conversion then */ + nsCString str; + str.AssignWithConversion(uniStr); + g_free (wide); + return g_strdup (str.get()); /* FIXME strdup needed? */ + } + + /* allocate a string big enough and do the actual conversion */ + output = g_new0 (gchar, count + 1); + count = wcstombs (output, wide, count + 1); + g_assert (count != -1); + + /* free wide version and return */ + g_free (wide); + return output; +} + +/** + * mozilla_locale_to_unicode: Decodes a string encoded for the current + * locale into unicode. Used for getting text entered in a GTK+ entry + * into a form which mozilla can use. + * @locStr: The unicode string to encode + */ +extern "C" PRUnichar * +mozilla_locale_to_unicode (const gchar *locStr) +{ + PRUnichar *uniStr; + wchar_t *wide; + gint i, count; + + /* sanity */ + if (locStr == NULL) + { + return NULL; + } + + /* count the number of wide characters which will be produced */ + count = mbstowcs (NULL, locStr, 0); + if (count == -1) + { + /* hmm, shouldnt happen */ + g_warning ("unusual locale string: [%s]\n", locStr); + return NULL; + } + + /* allocate and decode */ + wide = g_new0 (wchar_t, count + 1); + mbstowcs (wide, locStr, count + 1); + + /* make a unicode string and copy into it */ + uniStr = g_new0 (PRUnichar, count + 1); + for (i = 0; i < count + 1; i++) + { + uniStr[i] = wide[i]; + } + + /* free wide string and return the unicode one */ + g_free (wide); + return uniStr; } extern "C" diff -Nur skipstone-bak/src/skipstone.h skipstone/src/skipstone.h --- skipstone-bak/src/skipstone.h Sun Jul 1 01:16:07 2001 +++ skipstone/src/skipstone.h Mon Jul 16 16:28:01 2001 @@ -170,6 +170,7 @@ extern gpointer mozilla_history_init(GtkMozEmbed *b); extern void mozilla_save_image(GtkMozEmbed *b,gchar *location,gchar *FullPath); extern void mozilla_destroy_history(gpointer SkipNsHistory); +extern gchar * mozilla_get_document_title (GtkMozEmbed *embed); /* go */